From patchwork Thu Oct 3 06:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Abbarapu, Venkatesh" X-Patchwork-Id: 1992226 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=p0rnhjpR; 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 4XK1xT60D3z1xt7 for ; Thu, 3 Oct 2024 16:29:49 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E048889224; Thu, 3 Oct 2024 08:29:11 +0200 (CEST) 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="p0rnhjpR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D19EB891FB; Thu, 3 Oct 2024 08:29:10 +0200 (CEST) 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,SPF_HELO_PASS, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060c.outbound.protection.outlook.com [IPv6:2a01:111:f400:7ea9::60c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8918989187 for ; Thu, 3 Oct 2024 08:29:07 +0200 (CEST) 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=meU+/A9IZg566VVtGtZt0WPs1OKMDaS/SHklrBdZBR/xm3VaCPL0W0XTHRYxwDNtIDASSwyVz4HNUEg8HmY9U3USAKM84Sf45uL41tdgk3PWyy4rFWbPVJ3yhgWRQSHjynqEu2TAMCIGWtQNlvylJm2+KfW3/Ef+JnqiAkXcZb8iUePtF/6/sq7J2FrqHFRLbYXHuIXt+TDrK1S+qCp0qoJbYEsuP//+edbebXn5QPBd9woPNHtBTXlRBFMwq7hzf5rT9ylYVvb8l55lDH3wDkGAipTzLeDxA4GiktyMc+IbMA3YBGqezJxCMprPvzsmJbkb0E0IvTEJIZhvCQwL3g== 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=/jEqQwQjiu6Vmg+e6PD3ysf3my8Gtcj9bcDR/c3mFug=; b=G1kZaNV7nuHsKRut0I82bJI0nWmgpkB6G0ewPISBTTRT/3girkdrSWnxk0rXp1hQz73IdPo7DqCzIsOV0wWyLwHwSEPqutkaFlgIF4xU0urGCJyM1JKEjIRqIIBmtOgx+KaDEjPlHvVoroHdDnXuhk0OsMfXXfLVgMXSJ1AKOJp51uBGaQIfPuERCPgG4lT3CnzxIZh9X70CC1GlD70UQ9aNxsufhhRGhOFrMtsOJ8rxzfR98vUCMhOdzxngFr6lXWLkBYtDMJL2FfWHtXPmYzWwc+k+p4YKFKZ81h0MSSclNrEOjPEfasWvUwaZ8U4QzyjiJyG6O6m3becKEiIoqg== 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=/jEqQwQjiu6Vmg+e6PD3ysf3my8Gtcj9bcDR/c3mFug=; b=p0rnhjpRpq4BQxUObY0NOl62vOi3tfG7/zTYJL2587lUCTVrxvFxI3Y68nlvkjIBvfHmpJSgO+GN5pME/q/Ps8SBMZwGP43h8nUUegvgLr1kaU/TjlYC0k8mbn+bK8Xj0t/JKpj1b90S/uDlY6juKeYzmlB5neDrVW5DGvcQ+5Q= Received: from PH7PR02CA0026.namprd02.prod.outlook.com (2603:10b6:510:33d::35) by IA0PR12MB8839.namprd12.prod.outlook.com (2603:10b6:208:493::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Thu, 3 Oct 2024 06:29:04 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:510:33d:cafe::be) by PH7PR02CA0026.outlook.office365.com (2603:10b6:510:33d::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.17 via Frontend Transport; Thu, 3 Oct 2024 06:29:04 +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 CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Thu, 3 Oct 2024 06:29:03 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Thu, 3 Oct 2024 01:29:02 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 3 Oct 2024 01:29:01 -0500 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; Thu, 3 Oct 2024 01:28:59 -0500 From: Venkatesh Yadav Abbarapu To: CC: , , , Subject: [PATCH v4 4/7] usb: onboard-hub: Add i2c initialization for usb5744 hub Date: Thu, 3 Oct 2024 11:58:41 +0530 Message-ID: <20241003062844.15338-5-venkatesh.abbarapu@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241003062844.15338-1-venkatesh.abbarapu@amd.com> References: <20241003062844.15338-1-venkatesh.abbarapu@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: venkatesh.abbarapu@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CD:EE_|IA0PR12MB8839:EE_ X-MS-Office365-Filtering-Correlation-Id: 8fdb0d94-881c-4914-2e14-08dce374ad02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?GbcpCwjqhkj1cAtS3FeitjpWjq4fLig?= =?utf-8?q?xrduudlqmrRT0TQ6pzeIWxeqKnLgHYIdorfxy4tn+B6MZrs0KewYlY1w53t0NrqQ9?= =?utf-8?q?HnwCxqTR38wzHMinc0nrE6rgQZffTbyAjVphp3wQX+VtJDRErSJ5yIjKItvpIdLFs?= =?utf-8?q?nEjU2TIFK82VFPEGP3Roxrrbxa+2/1XddNg54yiVFl1CB9mhEKYUEqfIr3SAV6KZH?= =?utf-8?q?dLpORHTnqF8UUz+ITrOYIEqCt+Wg7+Xj/yY8iH7Vm6beQa9KoluMpsBRo19A+SNQ0?= =?utf-8?q?NZyTwYSzcudv2JNc9T9txEYLvP2irWpvohqCcsmHiF20M7uRCLaeWktKm/6orzGfW?= =?utf-8?q?fucHICp16yR6JvjVgVQ1bxoelvWTeYCkEFObHOh4dP45YXv+WNCK6cvnPqieXOPBs?= =?utf-8?q?OOqILjlFRiWWTrGg53FLNJ/KWOIB4c05tS6JKp0XcBqJYlJ58siHlHKMK/TNu+fZh?= =?utf-8?q?baiU7TcvwRjaeMcRURPwwM3NV9G/+/hjSnRAzqGrSXkNi+mMUx3fdYymn53S+N/NM?= =?utf-8?q?/wGkDwGn6fzCleKiYRuihtCvJeRjM+FKB0Q/Ma+knw225432QsYspM72cDCBNKOlT?= =?utf-8?q?lXtx3xrJltcJrXttZgMn2sQdpZOeJSX4yIHcW/wIkmszB8PTWkB2xCix5U4ccrffZ?= =?utf-8?q?XGlNVBrnzOOKfyebEZuudDJYppVhw3S3EvSCXbWgpywXcsgVgo9m8X2afQOW029Ft?= =?utf-8?q?y2Rjl2wHT2FjA/GLi+FObTH17rMj5CaTJQIHZqhf5MRnmVdF4rOkTND/yCz3atBza?= =?utf-8?q?0sUEFDNK43DRw+inmC3PYD9VuEiY1S5SdwHtDKrvyzluO9NtdNxW1LcuPp2ZFJr0D?= =?utf-8?q?Nu5eHJ3tcEKupPEr1QXmx1kDfm2hKg1B0UxEhre4Hahax7dSl8Cb78Y/bH8kjt9OY?= =?utf-8?q?PxMk+B6vPzKxC8bSkV7OglAzH8E/EFhm1EysE/D19GCqVjxUuuNnGkedHxtrlQw+k?= =?utf-8?q?m6KRvGmm9hYRrXcxgUYSN+KCjXPUFqcVhevNA8ct00KZesqlNQTp3LWkASHFP79cx?= =?utf-8?q?KqaMocW4RRDGDUxaaue5jpzDB6/QNR36JPUW9xj63VeQE87KUwXwIcdEOELq0xQ2k?= =?utf-8?q?CKr2REBaDoWwH3IQUmhZCXI9jB98OO7qJkbHdYq4BySzH1oBt85a54IJe+3wmGXJP?= =?utf-8?q?GodSlCIc0+M121ryRwrZvDDZgElFUTYXy4B6ELh0Tj1Xk5beJgkkptWyCc0ZdLUNi?= =?utf-8?q?iaeKYWcMyWxS+9NQnjr+Fp/yw7tD4UtAJUZfN67zc3seaebzucK1tjKJyuthAfgM2?= =?utf-8?q?RQKTd7BWsbiUnAeB5d2bFSU/CJSqB0j43+T4mVPKqaXbTI7WsF2pAvjg=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)(1800799024)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 06:29:03.6205 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8fdb0d94-881c-4914-2e14-08dce374ad02 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8839 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 --- common/usb_onboard_hub.c | 99 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c index 5caebf8574..94ea01a7b0 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; +} + static int usb_onboard_hub_probe(struct udevice *dev) { struct onboard_hub_data *data = @@ -61,7 +148,18 @@ static int usb_onboard_hub_probe(struct udevice *dev) udelay(data->power_on_delay_us); } + 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) @@ -85,6 +183,7 @@ static int usb_onboard_hub_remove(struct udevice *dev) static const struct onboard_hub_data usb5744_data = { .reset_us = 10000, .power_on_delay_us = 10000, + .init = usb5744_i2c_init, }; static const struct udevice_id usb_onboard_hub_ids[] = {