From patchwork Tue Nov 12 05:07:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Venkatesh Yadav Abbarapu X-Patchwork-Id: 2010064 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=pS9MLSyU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XnZLx4jMLz1xw3 for ; Tue, 12 Nov 2024 16:13:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC126893B5; Tue, 12 Nov 2024 06:13:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="pS9MLSyU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CE7DE893AB; Tue, 12 Nov 2024 06:13:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2060e.outbound.protection.outlook.com [IPv6:2a01:111:f403:2414::60e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9E45D889D2 for ; Tue, 12 Nov 2024 06:13:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=venkatesh.abbarapu@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NNXkqs4zxtfJ8xC/BqbI6ym1EWQvLqQvTrkdR3EH/bym6XfneLmqWRh7jrLAN0rDgtNuvkvYf1V87FP6bfxSr/zlwvJLm0Trr3y0kmQl9QgMwbIHw8BAI5YwI9hB5vuc7vlF/ToowQUBTYlsv7r5FkpjKvwuBgSsKKkCeA6xMH2N2bFvAb4E5m2BxrmVMIS9XBXlNubuyi7ZlOcZFc+anbSusXZkDlKKLfqIGWxdPTXs3vmF6ZETv9f5Ohh+zp0qRg4FkL7R2wYTpqt3s1dxF8NgVDxZYAh9bat6iznnpiSGFKKvOB9Rq8DJAkCjBuqXAA7kK1zTCkgjER76S6iWBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k40IA2EFa7GRLDDDkFx0Ms+0tLqMjbW9/5P5w0rZr9Y=; b=i0vmipfWEE10gBYLPSiKh+S6Rk+9SMKk1lraORKlpgtMGpBpwScscDe+pN2YmneTtLPv5eQnEked2t5E3dUEq31yizNRXquzs6pGOulaTzgRco3vZLhm1W+XHVId5G9rwreqScF22szaymsj4mm0JbxxdJLZ34laQ33TYzle+KPSDwQqt/tNhY7Y880KCneDoMCJsuY1SROXK5z8pm6bT/p+D2nPI5M7nvIbBC9jZRn+BL0Z2S/wotrwFI76OyJY9Sb+iCAvIKK0KLXBHREb581myddERAAXIobkzDfnOT2YYEMPSoG2yQfLTkY3v5rcapOI2ywGfMYqGwan7AHMVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.denx.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k40IA2EFa7GRLDDDkFx0Ms+0tLqMjbW9/5P5w0rZr9Y=; b=pS9MLSyU2gKqjLbheYISOrhYtPPTxQmQtUS4lAE8qYNlLYEtbsZS0WIUMZ9U9c7PerICRTJljLr9hh+swMm8vBlx1jMjkQp4UXAtpEfdLQy8IL4tbYX6i3P8HAeCnGA1kgaex/erUcxrrOMZCAZMTb++q7lz6N/UB5kp55ueU3o= Received: from SN6PR05CA0032.namprd05.prod.outlook.com (2603:10b6:805:de::45) by BL1PR12MB5705.namprd12.prod.outlook.com (2603:10b6:208:384::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.27; Tue, 12 Nov 2024 05:13:05 +0000 Received: from SN1PEPF0002529D.namprd05.prod.outlook.com (2603:10b6:805:de:cafe::e6) by SN6PR05CA0032.outlook.office365.com (2603:10b6:805:de::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.15 via Frontend Transport; Tue, 12 Nov 2024 05:13:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002529D.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Tue, 12 Nov 2024 05:13:04 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 11 Nov 2024 23:10:13 -0600 Received: from xhdvabbarap40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Mon, 11 Nov 2024 23:10:12 -0600 From: Venkatesh Yadav Abbarapu To: CC: , , , Subject: [PATCH v11 4/7] usb: onboard-hub: Add i2c initialization for usb5744 hub Date: Tue, 12 Nov 2024 10:37:37 +0530 Message-ID: <20241112050740.15343-5-venkatesh.abbarapu@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241112050740.15343-1-venkatesh.abbarapu@amd.com> References: <20241112050740.15343-1-venkatesh.abbarapu@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: venkatesh.abbarapu@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529D:EE_|BL1PR12MB5705:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d4c16d7-7343-42b9-3121-08dd02d8b023 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IOGBNPVTZwFew0Wm+cK39+exj3Kz+rn?= =?utf-8?q?agMdCUYvtdAxZdo6Svj9iFNiRdEHh1Xcuw4e9mpt8CdZKxks8jpCJt8WJ5sFcutce?= =?utf-8?q?huNt4ChO3b7VvKoG+Oo4ZHh1JG49y/cIuBSxxs9zQ3lIC63FUXalOBhj3K5s2qGhh?= =?utf-8?q?Oeo/ftp3VekgYxN07fhn6Q3kUmT8LL+w92KUJ0TQuWM+qQhpjE1dXDeyWcXOuU1CH?= =?utf-8?q?E58WbhNxhJhrEs5NkBcBJir+T6ZOqgeNJcP/hvcVJH57JDUugKA3MK70VIKAQq//7?= =?utf-8?q?U9ohJLEbTjeuRbv+eQrZk/E7EXRMA1H/JtfHscYCTCDKZG77KckDIuHRPmFscUtKu?= =?utf-8?q?B76luFmEAwc+8HG7riTSN7DARxeWKq1084a29vP10TpP5gTL7EYyFvkUXY94EjQOd?= =?utf-8?q?Pmb1vifLqHYvFo88Yy3b8NaOAk+Pd7+6co1wvin26FmkMyoSGtgCTSpOJNQXXn8E+?= =?utf-8?q?T5g3abpSDqYkyd76WuCWi8c0ZtnfHZbd1x5wS4Rj9Gzr3KjBT6ZUuPK/i9Zb5lMYX?= =?utf-8?q?awtaNRaB5sJwo/MRNvvHi7IyXyzJkLmqXK9EuMlmqfdMaSL7NOWiG25fMw9hU6mxR?= =?utf-8?q?zJKMjUp+myQJogEsKTaCG6CBLbcaR7iFtY1OXogoz5P7hb5bKAXFRpqh6J7j4uBYG?= =?utf-8?q?gs+K6ywtJLFgHnTplWOwaqJ37vKPB3BXdY9ZfCGxZhf6YfrahUhI6y07XgxGjkH54?= =?utf-8?q?tGK0+HU5FZP+uxOuTyrhmM+Vr0lNB00aH+6O/E7UTuh4wkF38Ej4f2fzI9aD6PyiU?= =?utf-8?q?pvusJSFya6KnSaPNvYBa+RCL2KKUAvq1B38phx179kQJbslBu4Xtb+/l+6tT4mpRX?= =?utf-8?q?hpkD/5gHqQlcoDBGKybIrRahqqT+rajV2qw7ZG5fk1ZHAwAr/Pj+RtvUfLXAuETq5?= =?utf-8?q?ilZRQqNz1nPK7QxOMVtECdTUepoabzX+NPUT7s84vBb7UBLxVeVb83b6vdp6h1NyA?= =?utf-8?q?blJfeiDakN0Vx7PFZkNtu+0aHB8DVqrGCXDiGXfcHgEu2h3Ch7yminwvkST5gFS5F?= =?utf-8?q?fjvEmj1aRKzXsdzOqSfSWVYW6qWtFCXf+yHiWKO51leLDYmCyqUSpnpp+Dq2oG7Ad?= =?utf-8?q?aCBaEsruLaKVx122kC50D07Xxh+Ky73gBMv/7WDAX7VSxv2IwZJzmovMwV0G4w8sC?= =?utf-8?q?keASjpGQBRdXDFRp77NznX7jlqF8Mc1dkfUMxZcHZsDPTqru+zc2h2EPdJoy806HU?= =?utf-8?q?DuKyodSeo1C6KwrSO0IlBPpRKjyYGpIcH6dpVYlpmQY6G7CwEn0whG31GMclRis2b?= =?utf-8?q?m5B8fwCzBIi7qWF0zwiTMBvf5ljzxspFQ6jQ4nv6kxg2kScKlrz+WrQupx683wUXq?= =?utf-8?q?3o9kyPRfA0R+t7PWlifl41qnyeqhudEjRw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 05:13:04.6047 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d4c16d7-7343-42b9-3121-08dd02d8b023 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5705 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add i2c initialization hook and set usb5744 platform data with function having required i2c initialization sequence. Apart from the USB command attach, prevent the hub from suspend. when the “USB Attach with SMBUS (0xAA56)” command is issued to the hub, the hub is getting enumerated and then it puts in a suspend mode. This causes the hub to NAK any SMBUS access made by the SMBUS Master during this period and not able to see the hub's slave address while running the "i2c probe" command. Prevent the MCU from the putting the HUB in suspend mode through register write. The BYPASS_UDC_SUSPEND bit (Bit 3) of the RuntimeFlags2 register at address 0x411D controls this aspect of the hub. The BYPASS_UDC_SUSPEND bit in register 0x411Dh must be set to ensure that the MCU is always enabled and ready to respond to SMBus runtime commands. This register needs to be written before the USB attach command is issued. The byte sequence is as follows: Slave addr: 0x2d 00 00 05 00 01 41 1D 08 Slave addr: 0x2d 99 37 00 Slave addr: 0x2d AA 56 00 Signed-off-by: Venkatesh Yadav Abbarapu Reviewed-by: Marek Vasut --- common/usb_onboard_hub.c | 106 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c index 1d146eccee..e209964f17 100644 --- a/common/usb_onboard_hub.c +++ b/common/usb_onboard_hub.c @@ -10,9 +10,15 @@ #include #include #include +#include #include #include +#define USB5744_COMMAND_ATTACH 0x0056 +#define USB5744_COMMAND_ATTACH_LSB 0xAA +#define USB5744_CONFIG_REG_ACCESS 0x0037 +#define USB5744_CONFIG_REG_ACCESS_LSB 0x99 + struct onboard_hub { struct udevice *vdd; struct gpio_desc *reset_gpio; @@ -21,8 +27,89 @@ struct onboard_hub { struct onboard_hub_data { unsigned long reset_us; unsigned long power_on_delay_us; + int (*init)(struct udevice *dev); }; +static int usb5744_i2c_init(struct udevice *dev) +{ + /* + * Prevent the MCU from the putting the HUB in suspend mode through register write. + * The BYPASS_UDC_SUSPEND bit (Bit 3) of the RuntimeFlags2 register at address + * 0x411D controls this aspect of the hub. + * Format to write to hub registers via SMBus- 2D 00 00 05 00 01 41 1D 08 + * Byte 0: Address of slave 2D + * Byte 1: Memory address 00 + * Byte 2: Memory address 00 + * Byte 3: Number of bytes to write to memory + * Byte 4: Write configuration register (00) + * Byte 5: Write the number of data bytes (01- 1 data byte) + * Byte 6: LSB of register address 0x41 + * Byte 7: MSB of register address 0x1D + * Byte 8: value to be written to the register + */ + u8 data_buf[8] = {0x0, 0x5, 0x0, 0x1, 0x41, 0x1D, 0x08}; + u8 config_reg_access_buf = USB5744_CONFIG_REG_ACCESS; + struct udevice *i2c_bus = NULL, *i2c_dev; + struct ofnode_phandle_args phandle; + u8 buf = USB5744_COMMAND_ATTACH; + struct dm_i2c_chip *i2c_chip; + int ret, slave_addr; + + ret = dev_read_phandle_with_args(dev, "i2c-bus", NULL, 0, 0, &phandle); + if (ret) { + dev_err(dev, "i2c-bus not specified\n"); + return ret; + } + + ret = device_get_global_by_ofnode(ofnode_get_parent(phandle.node), &i2c_bus); + if (ret) { + dev_err(dev, "Failed to get i2c node, err: %d\n", ret); + return ret; + } + + ret = ofnode_read_u32(phandle.node, "reg", &slave_addr); + if (ret) + return ret; + + ret = i2c_get_chip(i2c_bus, slave_addr, 1, &i2c_dev); + if (ret) { + dev_err(dev, "%s: can't find i2c chip device for addr 0x%x\n", __func__, + slave_addr); + return ret; + } + + i2c_chip = dev_get_parent_plat(i2c_dev); + if (!i2c_chip) { + dev_err(dev, "parent platform data not found\n"); + return -EINVAL; + } + + i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS; + /* SMBus write command */ + ret = dm_i2c_write(i2c_dev, 0, (uint8_t *)&data_buf, 8); + if (ret) { + dev_err(dev, "data_buf i2c_write failed, err:%d\n", ret); + return ret; + } + + /* Configuration register access command */ + ret = dm_i2c_write(i2c_dev, USB5744_CONFIG_REG_ACCESS_LSB, + &config_reg_access_buf, 2); + if (ret) { + dev_err(dev, "config_reg_access i2c_write failed, err: %d\n", ret); + return ret; + } + + /* USB Attach with SMBus */ + ret = dm_i2c_write(i2c_dev, USB5744_COMMAND_ATTACH_LSB, &buf, 2); + if (ret) { + dev_err(dev, "usb_attach i2c_write failed, err: %d\n", ret); + return ret; + } + + return 0; +} + int usb_onboard_hub_reset(struct udevice *dev) { struct onboard_hub_data *data = @@ -53,6 +140,8 @@ int usb_onboard_hub_reset(struct udevice *dev) static int usb_onboard_hub_probe(struct udevice *dev) { + struct onboard_hub_data *data = + (struct onboard_hub_data *)dev_get_driver_data(dev); struct onboard_hub *hub = dev_get_priv(dev); int ret; @@ -70,7 +159,21 @@ static int usb_onboard_hub_probe(struct udevice *dev) } } - return usb_onboard_hub_reset(dev); + ret = usb_onboard_hub_reset(dev); + if (ret) + return ret; + + if (data->init) { + ret = data->init(dev); + if (ret) { + dev_err(dev, "onboard i2c init failed: %d\n", ret); + goto err; + } + } + return 0; +err: + dm_gpio_set_value(hub->reset_gpio, 0); + return ret; } static int usb_onboard_hub_remove(struct udevice *dev) @@ -93,6 +196,7 @@ static const struct onboard_hub_data usb2514_data = { }; static const struct onboard_hub_data usb5744_data = { + .init = usb5744_i2c_init, .power_on_delay_us = 10000, .reset_us = 10000, };