From patchwork Wed Jun 5 10:02:18 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: 1943785 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=bZQ2uWiH; 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 4VvNMK26x9z20PW for ; Wed, 5 Jun 2024 20:03:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF85D8837B; Wed, 5 Jun 2024 12:02:46 +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="bZQ2uWiH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71AB688354; Wed, 5 Jun 2024 12:02:45 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20622.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::622]) (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 AC454883AA for ; Wed, 5 Jun 2024 12:02:42 +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=arcselector9901; d=microsoft.com; cv=none; b=dILykvzt37koilU6WGiPPyUTcqzQw1t0+G2DkzLJiBKx+gCzp08DmMTrzStKj6ZJZeYOeL1y578dWkAn1SEHZPE+LcutffWafb+F5c6tgl27ov40VURGHTqvyg4kdRfqzUgFeqzRsH3IfXHL54AqbCk/coS/h8Yehii8nCo4I0DIofZyQang2byKTgWpSUkpEzmeePxWtzmvPvgfDvHGrzBr2nOvF1y04eIRuJQ71GJZxTRi3Rd1iTQXMOdGOadBdvhlQUyw1S21cBtjGSvaGD4BTiG+CqujjmdkD8yQrdq5NtUNBJkHfnpe7jWGakDj6nhIyPLtWVFPpq3n5Airqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=gftsfgkrWpo96nbqqA/pZbx3IAwEvqmr+8ztp2om5v0=; b=ixkkVus39iM1czH/YcLIGugHMxAgAzEEtPR0/eKXU7WM0qVzyI3+jUmOY+/7elrXiN4sY+jng44jZ6de7PFKxzzh/aOTKnUOygO8EpZ1uzA3g1CyXMC0t9y0WMSmNgG5dNu0sxyt5uuFfEiSJqe+zHbUoggoh55y68V1g0astmAxXaTfWP26fQdwb2rl61MHNhcm+709XVfAk/EWpWJkV/RsPrldJSNbHda12+UKGRIliRFhbGqSrxoGLUKZE5sR+qgR29bGaJUaobeHiW8k8dfc0FJvRqiRRcd7jUGLhZIfLPCPg5B1+MzMKDDZNaUgJylz72zHmLKF8Frl3Yg7tg== 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=gftsfgkrWpo96nbqqA/pZbx3IAwEvqmr+8ztp2om5v0=; b=bZQ2uWiHS+sRVm7UO75v43lp7y5zmlwxIHVqnzFVafOOC8YlDS2jVvAQ+nnJC7yo2E8MIN/nJQkUsMPQuhhtAuqk8bDYCIx9Y3W+R5qTAKOeE0gE5fw4xUYI9E8sL3quJY4YWnVF9cgpEPde3RMNcP+9hi6MSrVkg14Na1K4pGA= Received: from CH0PR03CA0426.namprd03.prod.outlook.com (2603:10b6:610:10e::10) by DS0PR12MB9421.namprd12.prod.outlook.com (2603:10b6:8:1a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.26; Wed, 5 Jun 2024 10:02:39 +0000 Received: from DS2PEPF0000343D.namprd02.prod.outlook.com (2603:10b6:610:10e:cafe::dc) by CH0PR03CA0426.outlook.office365.com (2603:10b6:610:10e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.30 via Frontend Transport; Wed, 5 Jun 2024 10:02:39 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DS2PEPF0000343D.mail.protection.outlook.com (10.167.18.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Wed, 5 Jun 2024 10:02:39 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 5 Jun 2024 05:02:38 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.35; Wed, 5 Jun 2024 05:02:38 -0500 Received: from xhdvabbarap40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Wed, 5 Jun 2024 05:02:36 -0500 From: Venkatesh Yadav Abbarapu To: CC: , , , Subject: [PATCH 4/7] usb: onboard-hub: Add i2c initialization for usb5744 hub Date: Wed, 5 Jun 2024 15:32:18 +0530 Message-ID: <20240605100221.3571-5-venkatesh.abbarapu@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240605100221.3571-1-venkatesh.abbarapu@amd.com> References: <20240605100221.3571-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: DS2PEPF0000343D:EE_|DS0PR12MB9421:EE_ X-MS-Office365-Filtering-Correlation-Id: e7cb6b20-6785-4b70-b008-08dc8546a22e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|82310400017|1800799015|36860700004; X-Microsoft-Antispam-Message-Info: =?utf-8?q?+f2P/QyOy0I87Bo7/2hqGTlMHwTA8Mr?= =?utf-8?q?lSZteYOJUKEInp9qmKzR1UYyndtdEDAhFOGRcW8TV97mIRSCBTFptP3btIpgs2DWP?= =?utf-8?q?dW0lvTsEfi/poNotmOO8giuUjPe9Zz+Q+7+b7PgHMCm3VF0/RyUqgtczj9fcuZ8Y5?= =?utf-8?q?edpuaYe+4qDNKOXQRiI75XQzm6uOFHzNSRwKQLDgPUwyESmQxZ9SjXmXgx0zA5xYy?= =?utf-8?q?NCCfZNKvYi1RdfY6W2pyJJTpiTbP02CQnM7xsPvn9QtH/UBnqKRZn+K6RLEkELpDe?= =?utf-8?q?izFoWpQzjvmao4WuD0dXVo9rVWAM7RM6uwrrSbMxZOusv36QQLmQ9RH79pyyJfULi?= =?utf-8?q?lg4r26W3xUaErAm9sWEh+OOJkeSV+9615sInJi8dHFyILwxBSzeVroSbP1vjpG0dq?= =?utf-8?q?s4RUYmBcaLYxWFsRvPJjRVIj1d17MpoBvkBkq1y4+FGN8T9uH/1V977r1jhVazMG9?= =?utf-8?q?U6u/qtyYCYttzcjM4mWUyYf5B6a6+axn23Xx1iRIKqpLLX7yK9Pg2kacZ8ft98Qdy?= =?utf-8?q?Ojk5Dea1SjdPmtnLwEN/MRzB6R3As2cr36FhBUJ0PAnSPtUU4bgee5qpcmiFeKn8A?= =?utf-8?q?eVFOYH4ZtWz5PgZsf2jD9c77q0awfVE7d2Gn42BBeLXEh4FuYidI2OSRJg6qa96b+?= =?utf-8?q?8J2k/T3eMpE4Zqhm7/IHYUlT2j4V098U2bzL5fD+UwZ9ReKjLCVq5ztF9pdiejZiF?= =?utf-8?q?INeha6+UODogeISyGduGiQdRpPaUZwTOG7fhPiGxjpOCnl/KZrjkF8476l9dliV43?= =?utf-8?q?EZ745zGUYm5YszpR+tPP653B0UOWK41zZajDBYxC4N1RjnOdHbwiSe5+HiwQattQi?= =?utf-8?q?zeCIKdnUpxLsMVH8HW4hIiRUwAMoWcDboV62ZcFgdWAWkBPgaJlISfXStsGVQwEz7?= =?utf-8?q?RDuPSVLmXNpM/RkgYBGTlAY9ISMIULn58HovDEiOxtzCyWm5Azy95gjJGjNf8+/zs?= =?utf-8?q?p7nyfhuYdbIQfeDhQHk1m6FfSu4IZWaTopdJ4aTO7KkyTtweFgpKRnLgtCeN9ZP8h?= =?utf-8?q?Tb4D3vcBJQZnMVKi/tixsvnwPV3W51YgcYhlRt0cWLPAsluOcsX8AEcoA3zoQ+XGY?= =?utf-8?q?r1GtBYeOfpPUOqrPgR1fsMAOWHSsk9fYmNpKuOLEhQuOJEfFYKU418emYlseUSKOA?= =?utf-8?q?i4VFBoVu5kjdqDcy+gs1V5TN8jhll4+RysRIvKoJRYVMxhvtFenM+5c9aQE/Vdi0K?= =?utf-8?q?vyji62m5Dx6m6icJBZFn2YTG89tk3sAFOm/NMxD/PjplxT42L5gGtjMM4DL1oxVvv?= =?utf-8?q?e9ygexgCtj9rcoxBWRbkZJtb3NOByxIGb5e2yzn9TPzuuOHyik+WKX4s=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(376005)(82310400017)(1800799015)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2024 10:02:39.3847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e7cb6b20-6785-4b70-b008-08dc8546a22e 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF0000343D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9421 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 | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c index 50870285995..09ce452af1b 100644 --- a/common/usb_onboard_hub.c +++ b/common/usb_onboard_hub.c @@ -11,9 +11,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,80 @@ struct onboard_hub { struct onboard_hub_data { unsigned long reset_us; + int (*onboard_dev_i2c_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 + */ + char data_buf[8] = {0x0, 0x5, 0x0, 0x1, 0x41, 0x1D, 0x08}; + int ret, slave_addr; + u32 buf = USB5744_COMMAND_ATTACH; + u32 config_reg_access_buf = USB5744_CONFIG_REG_ACCESS; + struct dm_i2c_chip *i2c_chip; + struct ofnode_phandle_args phandle; + struct udevice *i2c_bus = NULL, *i2c_dev; + + if (!dev_read_phandle_with_args(dev, "i2c-bus", NULL, 0, 0, &phandle)) { + 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) { + debug("%s: can't find i2c chip device for addr %x\n", __func__, + slave_addr); + return ret; + } + + i2c_chip = dev_get_parent_plat(i2c_dev); + if (i2c_chip) { + 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, + (uint8_t *)&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, (uint8_t *)&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 = @@ -63,6 +141,13 @@ static int usb_onboard_hub_probe(struct udevice *dev) udelay(data->reset_us); } + if (data->onboard_dev_i2c_init) { + ret = data->onboard_dev_i2c_init(dev); + if (ret) { + dev_err(dev, "onboard i2c init failed: %d\n", ret); + return ret; + } + } return 0; } @@ -90,6 +175,7 @@ static const struct onboard_hub_data usb2514_data = { static const struct onboard_hub_data usb5744_data = { .reset_us = 10000, + .onboard_dev_i2c_init = usb5744_i2c_init, }; static const struct udevice_id usb_onboard_hub_ids[] = {