From patchwork Thu Dec 7 11:51:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13483194 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="PLF9Mv+a" Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2047.outbound.protection.outlook.com [40.107.21.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF97D7E; Thu, 7 Dec 2023 03:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IDd97ELvn/bRO0pbasXmFCyQoaUitjw5Jjv9w5vazop4tijCLG/KGfcKNbZ5JqLCGezF+Op63y2dCQVWq9P9Ddq8iu1xBhcHbZapLOSJVhqwiGo4gSHsNebnGR3Cxq0J9iuEDurHibuu+2VTSwovg74bdSXV5KJ2oAub5H5u+uoN5I9Da62/hvvC47CseX3M4wny6a+/JMkmbAUmWXEE7HBVXAELAMd2dkzNWtfPFsJU2GYKoA7xXXi9vwJCzMXrOZ7gLtHKgT0jE8NwIDM70umJqAVEWG4ercO1zs6tc69QGxG8ddZMYa1J/g4Tinoypz+P/fsHrudZlClyjPNacw== 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=cujQEzVlmkJFha8J9PhqlxbUa/4fk9ZOlxsXZrOBJeI=; b=Qxip92iUPITOJJMplLnw2e90byAeG9v8QGIkzI/xBSbCxIDAhN2BBnrgHgO+jURPe5Uyd17qjyhh/mI5+ITiknVEeiBruvP7fq5yMo1Egxw+CoZId1YEGdQ3y1OjfBQgSy0dxA8ViI6tqL2rHXQ6PWQ2Z27CnxefcOdY9ovhWODXH21kLCuP/zCVe3G+jQvTsHpjEnQ/5+C6xaK/PMvfBdOp1/877zaFi6pnUFI6arR8/ndG+m3OhT1OA+dcq7CJ8JGw27l/G80ygZTe0bkB+G6sdlJqTQne2Ia1iN1Ul42vBA1BeQtjE2GEB4ejJR76RbRDq3OTvk6mWOeZt7ST6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cujQEzVlmkJFha8J9PhqlxbUa/4fk9ZOlxsXZrOBJeI=; b=PLF9Mv+apyItWHLBikFpY5Nf4a4h2sb4NWYwZxebatFuK6nMDbTIWKTrNCp2tfM5jycrCFfTR/XOp9ZBuIneNrqvK+1Di4MJxqVNPx/C0D6mbXSj2qOAtnnUBkVOCVbh02be9mooIn7FQyqw6whQsAhEUCCWdRS+7Kwaz9j3WVg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) by AM0PR08MB5300.eurprd08.prod.outlook.com (2603:10a6:208:18e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.25; Thu, 7 Dec 2023 11:51:17 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::6b40:1e6f:7c94:71dc]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::6b40:1e6f:7c94:71dc%4]) with mapi id 15.20.7068.027; Thu, 7 Dec 2023 11:51:17 +0000 From: Javier Carrasco Date: Thu, 07 Dec 2023 12:51:09 +0100 Subject: [PATCH 4/4] usb: typec: tipd: add patch update support for tps6598x Message-Id: <20231207-tps6598x_update-v1-4-dc21b5301d91@wolfvision.net> References: <20231207-tps6598x_update-v1-0-dc21b5301d91@wolfvision.net> In-Reply-To: <20231207-tps6598x_update-v1-0-dc21b5301d91@wolfvision.net> To: Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1701949872; l=4936; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=8PtfpVXXJlDFboFn5Nrw8L2jU1tK9s2cmm7l3ScqDZc=; b=NK9f4hLXyN/Odj8cay2BgA+lhDxVk7Rld/H/LBDUvq/122FpQ3x6uiohnXpQkpttPO1H9/BtY 7kKfnEiuxP/BKgvLCJc9ggsUHXt0LK3mAVtPjsPnNv3xSKvJcafo2Y/ X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR08CA0248.eurprd08.prod.outlook.com (2603:10a6:803:dc::21) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|AM0PR08MB5300:EE_ X-MS-Office365-Filtering-Correlation-Id: 9cf6b13d-2e9e-44a6-9a05-08dbf71ad0ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qhSA5VwMMADqesAzpR5j5PaKRfEZ3IyG10KPdmLE0kF+PCkwNG2Ue6QhCG1WSmILdON/bSz+Q+hUUDHsIYXMoA+QQu5OTEMiNU6LYZ9m+ACvxilOINAXJIaa3EKgJIEqM/6ifBbQkKE5PSQ4QKFCfPPhmY8J1p6W8p137TlzTkf7pzzFu4lFj/Ml5iPBcl8OO+9Va3ZPpUIQOHZ7PplP0jZyT9ai2+fKYb1QxrMQCaFZJ+80jrow3iyiMhUtHzqpsfAbtI/TmpI6uZHx7pTglnuetd8kLEHjj6vEUQq8cUw0e1832iARJ0B13nI2b8tEpDfWtj5FPqRAqPUadSIsV7d+Ox+AlKQ3pk4/GaYI/SjNRBJE7kGq3bFwPt8Idbqc9gvoVngoekKVjtKt9EJtjrWRAy7UMg5DZJHA6WIoPdKSZi1IoQUSif/BZF6brQbZNe1cgM4s0sGKp5ZRtA2nDJpAZ7eFoJbYG/IuETOPSUVaMf8xCgw+KQkYl6T2izz/hR3PK9ZItj+VlSxCknYcmzEjsZH40yxBb5Qx72NsWt71R4MT8I9MNZPzGnflZ2RB+V6F5LHGsuqFX2kynv701W/uiivTvU4AoWI7AKcTU7aZpwNFgi1SsllD2VIPQV6FKOKU0buGzmhkUMR9QnLBYw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4974.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39850400004)(346002)(136003)(366004)(376002)(230173577357003)(230922051799003)(230273577357003)(451199024)(186009)(1800799012)(64100799003)(41300700001)(36756003)(38350700005)(15650500001)(2906002)(5660300002)(44832011)(6506007)(6512007)(6666004)(52116002)(107886003)(26005)(2616005)(6486002)(966005)(83380400001)(478600001)(38100700002)(8676002)(8936002)(4326008)(86362001)(110136005)(316002)(66946007)(66476007)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gObzfV4KBX0eLDwA8553DuCsiQw5?= =?utf-8?q?3kUcCye+fzfBZDLUGc20DuuaPeqdBRJ96ZFv9knrYOmft9qSNLYzY4w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ZN++e5UCR2gDgc?= =?utf-8?q?dy3VfGXuz2hZ1Df5LEE7eCpZa8JBTUmcc9seTf3sNCBI0kj/vJvSoUczAkEs6aJ1M?= =?utf-8?q?s7LULVJ39eXz3X/NMDHAt7l3IIB5GKuOoLZGSWm3cN1gtgHRmxxbcJt1u3ouOVzAM?= =?utf-8?q?u+7P+x2PXJz3Vn5PCq7w1Hu274/whNhlOTntKI+bNdRKqroQQ3FJtL6aIve7OnbOl?= =?utf-8?q?UbxCCHSZxSgeLEgCB0mf09qBtG1ziyzeWv/5OpwAQumq/GAjrF3H0bQxweVLgVihO?= =?utf-8?q?I4JX8LEXsSqJgcP7qXkcXmH4C72ajs+HvYjtyfavP3xjlzU/xrkmFhdhWp5JV0Wcm?= =?utf-8?q?V7TKunFiIcvAsFmlDWyUQKwUYHP/j5yyECiRremBoiSSeAteOauK0ymokWBzVMXke?= =?utf-8?q?rNbXT5aXsFr9hx966P2sC0GokKy0rxhjRyO4e0Vxr51fuhxdWZCbRSlLvb/WufCb3?= =?utf-8?q?7d3YT26DIQ6+GrC0gTkU3EtFP9g6fjyra7r9JFifK9vKZLvWTOQv+RD0NN5OvQIu3?= =?utf-8?q?MB8/rFMdaK3rRMQ/lyMuX+0aoDp2NEEuqPamFl19d6V9IruqxiW+UZeLULnxrVkqz?= =?utf-8?q?Xriv0Wwgpl5Cjf5M2Fq8qEnM6I7SiaXeUE71IRj/e7WYS+Mj9ZHteR4=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 9cf6b13d-2e9e-44a6-9a05-08dbf71ad0ba X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2023 11:51:14.7491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: k2yfNRbvqz1G0seD2Fw7I68G+Q9bgm89W9beT3QPT2sUnz42OJuhzbixntewoMNlHr4r+tVM2sMTdL8qiqNlTHloD7sLmIE7agnXFzzxICQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5300 The TPS6598x PD controller supports firmware updates that can be loaded either from an external flash memory or a host using the device's I2C host interface. This patch implements the second approach, which is especially relevant if no flash memory is available. In order to make patch bundle updates, a series of tasks (special commands) must be sent to the device as it is documented in the TPS65987DDH and TPS65988DH Host Interface Technical Reference Manual[1], section 4.11 (Patch Bundle Update Tasks). The update sequence is as follows: 1. PTCs - Start Patch Load Sequence: the proposed approach includes device and application configuration data. 2. PTCd - Patch Download: 64-byte data chunks must be sent until the end of the firmware file is reached (the last chunk may be shorter). 3. PTCc - Patch Data Transfer Complete: ends the patch loading sequence. After this sequence and if no errors occurred, the device will change its mode to 'APP' after SETUP_MS milliseconds, and then it will be ready for normal operation. [1] https://www.ti.com/lit/ug/slvubh2b/slvubh2b.pdf?ts=1697623299919&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FTPS65987D Signed-off-by: Javier Carrasco --- drivers/usb/typec/tipd/core.c | 68 ++++++++++++++++++++++++++++++++++++++- drivers/usb/typec/tipd/tps6598x.h | 18 +++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index cd5214c9799e..a4a50c52253d 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -1126,6 +1126,71 @@ static int tps25750_apply_patch(struct tps6598x *tps) return 0; }; +static int tps6598x_apply_patch(struct tps6598x *tps) +{ + u8 in = TPS_PTCS_CONTENT_DEV | TPS_PTCS_CONTENT_APP; + u8 out[TPS_MAX_LEN] = {0}; + size_t in_len = sizeof(in); + size_t copied_bytes = 0; + size_t bytes_left; + const struct firmware *fw; + const char *firmware_name; + int ret; + + ret = device_property_read_string(tps->dev, "firmware-name", + &firmware_name); + if (ret) + return ret; + + ret = tps_request_firmware(tps, &fw); + if (ret) + return ret; + + ret = tps6598x_exec_cmd(tps, "PTCs", in_len, &in, + TPS_PTCS_OUT_BYTES, out); + if (ret || out[TPS_PTCS_STATUS] == TPS_PTCS_STATUS_FAIL) { + if (!ret) + ret = -EBUSY; + dev_err(tps->dev, "Update start failed (%d)\n", ret); + goto release_fw; + } + + bytes_left = fw->size; + while (bytes_left) { + if (bytes_left < TPS_MAX_LEN) + in_len = bytes_left; + else + in_len = TPS_MAX_LEN; + ret = tps6598x_exec_cmd(tps, "PTCd", in_len, + fw->data + copied_bytes, + TPS_PTCD_OUT_BYTES, out); + if (ret || out[TPS_PTCD_TRANSFER_STATUS] || + out[TPS_PTCD_LOADING_STATE] == TPS_PTCD_LOAD_ERR) { + if (!ret) + ret = -EBUSY; + dev_err(tps->dev, "Patch download failed (%d)\n", ret); + goto release_fw; + } + copied_bytes += in_len; + bytes_left -= in_len; + } + + ret = tps6598x_exec_cmd(tps, "PTCc", 0, NULL, TPS_PTCC_OUT_BYTES, out); + if (ret || out[TPS_PTCC_DEV] || out[TPS_PTCC_APP]) { + if (!ret) + ret = -EBUSY; + dev_err(tps->dev, "Update completion failed (%d)\n", ret); + goto release_fw; + } + msleep(TPS_SETUP_MS); + dev_info(tps->dev, "Firmware update succeeded\n"); + +release_fw: + release_firmware(fw); + + return ret; +}; + static int cd321x_init(struct tps6598x *tps) { return 0; @@ -1151,7 +1216,7 @@ static int tps25750_init(struct tps6598x *tps) static int tps6598x_init(struct tps6598x *tps) { - return 0; + return tps->data->apply_patch(tps); } static int cd321x_reset(struct tps6598x *tps) @@ -1469,6 +1534,7 @@ static const struct tipd_data tps6598x_data = { .register_port = tps6598x_register_port, .trace_power_status = trace_tps6598x_power_status, .trace_status = trace_tps6598x_status, + .apply_patch = tps6598x_apply_patch, .init = tps6598x_init, .reset = tps6598x_reset, }; diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index 01609bf509e4..89b24519463a 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -235,4 +235,22 @@ /* SLEEP CONF REG */ #define TPS_SLEEP_CONF_SLEEP_MODE_ALLOWED BIT(0) +/* Start Patch Download Sequence */ +#define TPS_PTCS_CONTENT_APP BIT(0) +#define TPS_PTCS_CONTENT_DEV BIT(1) +#define TPS_PTCS_OUT_BYTES 4 +#define TPS_PTCS_STATUS 1 + +#define TPS_PTCS_STATUS_FAIL 0x80 +/* Patch Download */ +#define TPS_PTCD_OUT_BYTES 10 +#define TPS_PTCD_TRANSFER_STATUS 1 +#define TPS_PTCD_LOADING_STATE 2 + +#define TPS_PTCD_LOAD_ERR 0x09 +/* Patch Download Complete */ +#define TPS_PTCC_OUT_BYTES 4 +#define TPS_PTCC_DEV 2 +#define TPS_PTCC_APP 3 + #endif /* __TPS6598X_H__ */