From patchwork Thu Dec 14 16:29:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13493240 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="F+05H9Mc" Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2082.outbound.protection.outlook.com [40.107.8.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F247112; Thu, 14 Dec 2023 08:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BaYnODPS5xUWoXI1a4DTIUpf7Z2rK28FYHWfBbt9bKbJzNsvdaJB4+/Zh0SSD0pgPN7wUsw/qT+NBN7evLGtu0qNc1eCyG/xh1L+53ClXKGQdnEP45omkCnn9xH1faKv8+lHMMrLg7caXkiNZ4NGfllXzYNyet33vB3rE0LH2ypBfdNN/Gl/Gu5ijwmWH8Kz2v7Ur2IEE0tqU7d2DfhjtW02XuDmlcm3zLkqa1XDY5ZOWhY0XyFhcKVCVBE63Uq36a46KsOxC00UNJbVHwAQqnk/LRW+TO6lZ/NLpCDHIA5z+ORKRlrNPOb/rUSJhHi6ZJYksplQ4ZN6X6lavVJNQw== 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=Cfnz/JgogGoqHnZ/PtMvlHqKqWdKHhhucVx4GLaQzVM=; b=KmXg1p+ysLO05n4NLaV/ntJ9gr0PMT5Y3VKGnvOx+4PqlGK2XfBkk9OZ8hqFRE103lol6m+HzNTZgNZXRRDi+YhbROFUuoTAwlqf1VQlhmJ+Gfv2murwzqnVky3qtkE7IfkJkhJ1+2sH80tbk0GjrM7jUANCz3Od3LyHRPlgUSqrAjockKu0pyEky0kiRk72B/sQ6fQqp56ZXqBmujvlJztdooOwzdxK+Xfm6E+srVqKf85LuQdkH0OfsTF+iZ/M6wZmhYyqNidO5cGU/GojQJQQgt8wShdyENvfySd5yjaRLOdLp2/Mra2Lt3x9pJu5dY+RqyFZQKLzD1i/I/HmCw== 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=Cfnz/JgogGoqHnZ/PtMvlHqKqWdKHhhucVx4GLaQzVM=; b=F+05H9McRvg64JGhNPjCDAihi7HjgxnelLBcFRnz1R+pqc9KyWss5zzHhsN1WxAAnL0oJl+plAemeRYLJGNRJ0eZ5zz3ooY959/D9LsGf7C2frYV52qq/yfT/ThVeeqdDG8o9m+KmGbmIp5mc+goLTRMk3DSxDcSYhpfXLDPa0s= 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 DU0PR08MB8302.eurprd08.prod.outlook.com (2603:10a6:10:40e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.28; Thu, 14 Dec 2023 16:29: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.7091.028; Thu, 14 Dec 2023 16:29:17 +0000 From: Javier Carrasco Date: Thu, 14 Dec 2023 17:29:12 +0100 Subject: [PATCH v2 4/4] usb: typec: tipd: add patch update support for tps6598x Message-Id: <20231207-tps6598x_update-v2-4-f3cfcde6d890@wolfvision.net> References: <20231207-tps6598x_update-v2-0-f3cfcde6d890@wolfvision.net> In-Reply-To: <20231207-tps6598x_update-v2-0-f3cfcde6d890@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=1702571354; l=4936; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=TVl+/n3421/aHLjJqCJvBtCJNcSNOeLZsG/G74/AoQA=; b=7PymAq/KTkfqBgqFa8DkBWDzirlTkCbae0Q0Pq2IZTw2G3DphN8F4xqr6zh9JgtkkBAAR7ktD fOBF/tDKrJmCkNyhpoQqYJASIrjK+htau5MxosQvpfUlQNB4Nf2jQWb X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1P191CA0011.EURP191.PROD.OUTLOOK.COM (2603:10a6:800:1ba::19) 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_|DU0PR08MB8302:EE_ X-MS-Office365-Filtering-Correlation-Id: 575e72e1-30ab-4b76-803c-08dbfcc1d134 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8QzJs+JqFTiaS3UQDE2Lf5T9MQqFbVOxq2djIVUuqVIi9GVYM1NmcB4CBoZDuH1i4DKp/80kciqbTssOeHjJTpsOMJs5LZ07Ayzji7EBJRZVFi5BWjafOnAbexMfRa+lXFxSM5Ol7duomlzvlXfNK3qD5KYayYnT02hWev9ZUkn81Mgwgvu4qJk04zY2XcWgWKyU1WSnjfPdt6gvanx/FLWIQ/zhugQym4YYSInQM7rHpNhSS3dfBbqV4rD7FkR55/x3+/El8UwmnQtRuIe1BKlfhrbKevIXS0wtRP1hE9XuvjJEqYiL94dtjN3bHzuc18jJ6ipCoSl3tlFiv/hxGnQQsIvO8Bb1ZOWHEqrWimKJq7dx+sJaR9+oE4u7ikc5AFBuo260n0sm3kuZ5S5WltVq1neTr4AFOYXS/LrOdPsd4vZVWP1GjLZh/vWPs0+3GUq0uFjKyHU4SY6T3HzSApip9mI8hvmjRRfZqkrxYjZDammGlKhSjCe2r0ZG6zeir4s2uHk+mkO9LLcZReDZnzLHA/sG/8Z3bIWB6HPzFvwnRg2gefcqRHKeDCgIt6Vyhfm+yZc24HVOCoxDY0DZrETEySwt1zqk9nFWBJbKiGInumzSRkrKoNeSqu+7IhwT2kH+h0hMOcpFfbqCCL0rWQ== 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)(346002)(136003)(396003)(39850400004)(376002)(366004)(230173577357003)(230922051799003)(230273577357003)(1800799012)(451199024)(64100799003)(186009)(52116002)(107886003)(2616005)(26005)(6666004)(6512007)(6506007)(66556008)(83380400001)(15650500001)(44832011)(2906002)(5660300002)(41300700001)(6486002)(478600001)(966005)(66946007)(8936002)(4326008)(66476007)(316002)(110136005)(8676002)(38350700005)(86362001)(38100700002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?MR2J0+4sidVfFybsMGMXRcvGA/Do?= =?utf-8?q?GjtqpgYxGTSkI9x7Kf4lXoHVUWUb7fYSLaC1Nim/qtGNuH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FXUVJCqsqkfyQin6IIqG4281?= =?utf-8?q?9ZSCg4VmTzlptQQ1M4jcR7kYnVTZm4n7fG88BDMCINMAfY6Ygy3xk+gm6lFtwnG6u?= =?utf-8?q?z63c0xOI4MamF0Ldm1M92CTFwPAlBYooi7fYrhTfR7uIy+kFO8QANDeoSkTw9i+ud?= =?utf-8?q?58xaMe2HsE6T5iRL67mRErzLVIAPpF9AgC75x4GKUu0Tx6Ra5Z7f0TjwW8AYdj+Rj?= =?utf-8?q?8cIAXQbZrk+IxWN+hsm3wRrlsGH4GfmhzFawtFbwU8zNNg0qZp0jbIwQO1ycW0c4w?= =?utf-8?q?1hV7k62OaoWux78ufTD58xJa0JEiqjs21xd/tD8LAsXAvMX0nuzUJSQ/dRwjop+2K?= =?utf-8?q?R4MOjOqBl4qkns6JIZ8xrjnGhGpFlIfFxDA6FI5zZnB3y0LcHkc/pPbwKjA/yz+y6?= =?utf-8?q?W5eAwPYQz1Fp/pb4xfN+I0sgLqB+jFrgw2wUT32nCdgh4F1mATFBJ6cHTu2q/2APl?= =?utf-8?q?be1elbJ2vJUwlL0yTMsaUJq29WAzWwByz4ZdhrH0lLCY8tDAcdSXbzaJN9Pf4jyH9?= =?utf-8?q?vhqg7r06nSq+SS0KgPTwamFynvF9gAPFmTJxewPnkICi/v9clL5aT4QSpfyVoWeTJ?= =?utf-8?q?w1QlbUAqTf5xHKNfBaShtIKthrcB3XDQIVhTWHLWmcS/Qlpb3AIK/04=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 575e72e1-30ab-4b76-803c-08dbfcc1d134 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2023 16:29:17.2890 (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: SRJ8HHRJx/+UAhYN9w/LsaFE+QI7qJeb4U4E6qMnEg0DUW5hWYQDLvUsUkXPOoZwncH1YnIVmd7b02bbhCdpxC1JbPofY+WqzuDBCtgRnfk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8302 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 Reviewed-by: Heikki Krogerus --- 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 7f4bbc0629b0..a956eb976906 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -1125,6 +1125,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; @@ -1150,7 +1215,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) @@ -1468,6 +1533,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__ */