Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6108275rdb; Thu, 14 Dec 2023 08:30:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFL5sj10JJckGp3E5i8apWhilv7WNJ5xLkMkgO3G6xnQzXJe4Dg0dYeSj8g7mU/jlHClmSc X-Received: by 2002:a05:6a21:19c:b0:187:8bd4:e1b6 with SMTP id le28-20020a056a21019c00b001878bd4e1b6mr6123857pzb.31.1702571401424; Thu, 14 Dec 2023 08:30:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702571401; cv=pass; d=google.com; s=arc-20160816; b=iq/crwIMjlXZUoHOiTmumlyXqoQpvWqoLu6cYgpnWZ80Qa6bF0JkUWMZ0QtzVtdNPB +gAv9yBtowj6mZNFmJJgWQZR4C/cyF/L/m2rkR6jiayEZQUscYL8+50g76Rwz+KoAq26 szeVitMntYl7AJ/BZ9/kE7h8iqjb1xmcIosXn4QBq2u9NPeU7QAgZR3NQqVH5id6d9Hn OgsoWysMbdYZNQLUPquVKVHRvxXLWRWIcP5slMVy4AHzAzTAfd+xDvuVYRCVjHQQ/sIJ RwK2IUPZtn+C21pKJxzzh3JiVaRAXwu28z1VDyD92lehUN5vfdSaSA7RfWo7FrSpyzLX j3wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:cc:to:in-reply-to:references :message-id:content-transfer-encoding:subject:date:from :dkim-signature; bh=Cfnz/JgogGoqHnZ/PtMvlHqKqWdKHhhucVx4GLaQzVM=; fh=skg4aWcIne/NkBvGBSxiPFt6u1LkY77F5jj9Umi9ZmE=; b=SFJ33sQ3ZdHCP/tIKe2W0grrOz4jUqI4JmAVMVN2s5nRdfyJcM2RJ8RoRq8uVoUshG dEECu1wXlpkUrXteUncFOQhxayYjVx6Gqx0h+OjNVF+XPCWqD/2jYrXoahYf5LG5ssQP sewoCzce5LsZrCR467IPigR8WuXR5xUrwhEayY6aZedSqi9ye1W4V5YwdvBUGfFLdtEw eMGiqv033rdW7Tkh0jDmwzCP+l+AjgskdOO3ZmINYWHZpV+qc/bw+EDDY+zeH4CEvt5z NIKbHOvAqWGa6gk90oniwU1npEbZ9xc3WU91RBS6opFjkcuK5mdPtdo8AOd+qMA9PrCh KWsg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=F+05H9Mc; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id n4-20020a056a0007c400b006ceb27ec02csi11456983pfu.366.2023.12.14.08.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 08:30:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@wolfvision.net header.s=selector2 header.b=F+05H9Mc; arc=pass (i=1 spf=pass spfdomain=wolfvision.net dkim=pass dkdomain=wolfvision.net dmarc=pass fromdomain=wolfvision.net); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wolfvision.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7AF028346DC7; Thu, 14 Dec 2023 08:29:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443593AbjLNQ31 (ORCPT + 99 others); Thu, 14 Dec 2023 11:29:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbjLNQ3T (ORCPT ); Thu, 14 Dec 2023 11:29:19 -0500 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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) 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?B?TVIySjArNHNpZFZmRnlic01HTVhSY3ZHQS9Eb0dqdHFwZ1l4R1RTa0k5eDdL?= =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Bid0tqQS95eit5Nlc1?= =?utf-8?B?ZUF3UFlRejFGcC9wYjR4Zk4rSTBzZ0xxQitqRnJndzJ3VVQzMm5DZGdoNEYx?= =?utf-8?B?bUFURkJKNmNIVHUycS8yQVBsYmUxZWxiSjJ2SlV3bEwweVRNc2FVSnEyOVdB?= =?utf-8?B?eld3Qnl6NFpkaHJIMGxMQ1k4dERBY2RTWGJ6YUpOOVBmNGp5SDl2aHFnN3Iw?= =?utf-8?B?Nm5TcStTUzBLZ1BUd2FtRnludkY5Z0FQRm1USnhld1Bua0lDaS92OWNsTDVh?= =?utf-8?B?VDRRU3BmeVZvV2VUSncxUWxiVUFxVGY1eEhLTmZCYVNodElLdGhyY0IzWERR?= =?utf-8?Q?IVhTWHLWmcS/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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 08:29:55 -0800 (PST) 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 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__ */ -- 2.39.2