From patchwork Thu Dec 14 16:29:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13493239 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="VcEM6raC" 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 3D794125; Thu, 14 Dec 2023 08:29:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LC/GedQ0M8c3vvDrPd8WNx+gHBZq8WX8WUwlEimV0Yb2ZxGoz4sByLa0RY8HYBIz7LeRLBdTpAe25wEj6OCjpykbXo0lb7qjR9G/Lh6TUX0NYO7XXu4yYKWx2bIJjYEFJq1swnbl1HiXK3GqF0elx9bLJcvF32Fs/wfZiK0As/dnWtSYbFkCkOJ7s/AmZC4k9bRiI2Mn1RB7VOBSt+ax4evkAN482dwKYew9iHH2GAKpT1koz4Zz5Y/nqPKBHZ0k5n7a4DlQVxOyfHEt4FG2cKTSR7vvSz2/NKsWjbBfkxduZscM8q/EkFcoYCsEM1DrVkNiZdKLZbFkRc5MYmdfXA== 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=Alf3X77o95+4npf2Xmg3XH0mq/gq3JSYWbS2tW+Hm+4=; b=Rp8AfizAK/cFmUUaKp42wjlhfB/H2egD2pxtbmIUhsE0NH1sg8PzD229ESj5xVXaMSQMi72a0VTpC+v55m3kF/YmOgA6fv+/x+shFEVpOOQ+t3SKODPjqzbocg85Mx86y1N1U475VZBJRLUcBg7VXfqkXhQW5Wkt9kv4Pj+EZVKezp6UEvX6dSmOrSw248qnVUhbuMVtJCFvlbQpmDwt5JgWR1lfoBxVYfM7kVE33kkbHH0540EG5x4T8tefF+mYAMKnyDNlEgNR889azxTTo+MwgP+B524ityEpnLb6bGJTSvwCJv7+meYe/6DgDHWhsPgJA2F7zMSGTS535orZPA== 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=Alf3X77o95+4npf2Xmg3XH0mq/gq3JSYWbS2tW+Hm+4=; b=VcEM6raCuel7OKb81UHkq4EOYCdHt8dFlr7wCkX2UGqx6A+H/5QIZiP+BDt1EXocTHrPefDIPnlIUIjgD/R1cutyTffRmmLMZuqcGlo/vABJNtQ4UvqINqWEfRjaXD5kAXU2KvV43KRfBl6OQAKAX5xKV6OO1CH/l+j/mfLTSMg= 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:16 +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:16 +0000 From: Javier Carrasco Date: Thu, 14 Dec 2023 17:29:10 +0100 Subject: [PATCH v2 2/4] usb: typec: tipd: add function to request firmware Message-Id: <20231207-tps6598x_update-v2-2-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=1726; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=lu6STSMTUjxa+BhbXAPxJC7PhXobLmfFr1D/or+2rAI=; b=RSHvW9zwcGH7+aW/7UCIa4jd5kXjoEA2JuQNqkLNVXbd/4ps3mZSCh5/3he3xYYHGrzHA6FC+ O6qDgge+zLlDIhZ1O+DVsFsyx13IJIPJWke1FWYMnodeLUtSy+pvvEz 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: 48531cf0-c2f1-4d82-9c25-08dbfcc1d08d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mHBgiFvIdmh6ojZbOwIHJY/TuvJxE6JG+gYPXV6tPIJ23oDoBug1XGPSZtmZh1i6WZWKJAyM7gY/rzM+gMPhKggMarTtNciM3H0iD+JlfOmYnTCYzEjLvQOzQjkSPniHI7unFseOGE9IrAQZCZNQM0c1joZcmqPyPFDr48TKOxXLPHCHX7QX9BV5u2NcQD1MOtE9vVwuxC7J5xf0VvQ7yj4hBigCZ3Ec4cHHSipCd17zDw9YQ2gvZhjPb5dEkvPflPmxWyE83zxTOCNk0ZazB88m2KOAQjzMXI3W5P0IY9WBRJFVj9Buf1mccmU3e+c11eAGhArnMAOds9fvq7K3L8G3AwUn5P8Y30RoDj72f68aJxq/dtSeu4Gxse9hf92gpjnEcGiPz9IvIr8b549+Gj780itg5+60NSb9Jcucmu3RcCof83bOcrNpUzD5aDTLzPP/KdkrnzaOZXp9/33SYfGL/2AQmDFp5K7+915s/66Vs73bllSK/2Jb8UVa0JinWDnQ/TidYnVcoa2uILPGc4J7cUv/DrxKtHYk88BoKlNkEOYubZTHENF2f6XEqb9LW3Ohzu+mIeRzEvbsPSZf3glGkivog+vCIpTxH92jTQ5NYoUds7OjH5LVRIujf3Kr 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)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(52116002)(107886003)(2616005)(26005)(6666004)(6512007)(6506007)(66556008)(83380400001)(44832011)(2906002)(5660300002)(41300700001)(6486002)(478600001)(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?wdVxc1nWqRQVvTzBjIVQZ9H3cF4T?= =?utf-8?q?zfvY2cvtWY1sUqXO/U3bIIed99o5jQhuUqD4VREkGKwc91l+rzf9Ar5gjxOuyxL9F?= =?utf-8?q?6bhPv6YLTPGY5bCwj3TKtHQXQi/w8QypaLvrjbBcwNgF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c?= =?utf-8?q?OqXMRCGHcchxX9bC6UwJUp3cf8aQLLykHvKOGVID/D+utVZlxVTiRkHF9sxNcqT3Z?= =?utf-8?q?3185t9EXUd1qfWvUNrq8ScpN14ZRlp3XG6KaxSiwO3i1qft8iVYv2smWE6eoU0QeR?= =?utf-8?q?gramSBpgFwzScnqc/pSQC9nY5dqgMcXQseMFemhdwylbX4GTYQpFzERZ9QnAMUEmS?= =?utf-8?q?Ur+mZ3HcOO56a6Kfx4Trq9ytUHcqCQw11/KvRWgIvMdauTNwi6ypCylO8RFeAbh1z?= =?utf-8?q?xL9jQZ2McW0jGKMBF+sW7dpyh2X2iXvPZ62mKqliMJXLcdpo/9MNHQgkKu75csliH?= =?utf-8?q?FcpBmGm7THe0kzEUUNIpEUmh8QsyyDI130y48KmZpaB9Qc2ACexCFz5KJKf1NbvIi?= =?utf-8?q?HEIZqG7QBmCqGWztrwkE54qvRtT1esCuls++SI5wunpWQ2GpnuuPRzVW757I17gg3?= =?utf-8?q?YZ+T+hQ35bkY+GJrzKnPXpLervW8Ge0bzIcTYD8BLSPvBDh1NeHIxSCkm6PDxFm+H?= =?utf-8?q?VCOnH28nTKZGk/o+XF+kmNpKibMlSGjZkW0pCi6AiDJiUfadRBG0LTs=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 48531cf0-c2f1-4d82-9c25-08dbfcc1d08d 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:16.2077 (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: P6aWcS4NVFV9qzCNh6ULaQtrwrBgBZDIXjQ8nTTnsEpZTCIsfGaGjCMChrpCQjiXLeE3F+OexB+k1eDss9BT14SUw9zIBLxhWFOZg3BTAKY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8302 The firmware request process is device agnostic and can be used for other parts. Signed-off-by: Javier Carrasco Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tipd/core.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index f0c4cd571a37..83e5eeecdf5c 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -873,6 +873,30 @@ tps6598x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) return 0; } +static int tps_request_firmware(struct tps6598x *tps, 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 = request_firmware(fw, firmware_name, tps->dev); + if (ret) { + dev_err(tps->dev, "failed to retrieve \"%s\"\n", firmware_name); + return ret; + } + + if ((*fw)->size == 0) { + release_firmware(*fw); + ret = -EINVAL; + } + + return ret; +} + static int tps25750_write_firmware(struct tps6598x *tps, u8 bpms_addr, const u8 *data, size_t len) @@ -961,16 +985,9 @@ static int tps25750_start_patch_burst_mode(struct tps6598x *tps) if (ret) return ret; - ret = request_firmware(&fw, firmware_name, tps->dev); - if (ret) { - dev_err(tps->dev, "failed to retrieve \"%s\"\n", firmware_name); + ret = tps_request_firmware(tps, &fw); + if (ret) return ret; - } - - if (fw->size == 0) { - ret = -EINVAL; - goto release_fw; - } ret = of_property_match_string(np, "reg-names", "patch-address"); if (ret < 0) {