From patchwork Thu Dec 7 11:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13483192 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="yT73oPMJ" Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2064.outbound.protection.outlook.com [40.107.20.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51D13D4A; Thu, 7 Dec 2023 03:51:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EVAk7iX9ZdNiXQtln7jLgNqgGtb34MAO7F6OWMqOeG9EffhnmUORAQU073SKcRgCDEjGEuRSxFKnIz0qEc68tpo62XS/RpmfI+R90y/PlJOEjG4RM3sSw92zZuFB0/4N94SWFfLPiQJ1yLJ7P0eMK00CwntxNo86GVeF3b5Uy1Aqs7EWSPstiqRXWuM1c9M7Uupk46JQEnV8fymoHjWlNs9Y7Tul4H2jTJGDbITldIh5ykMKbRxWWzxgCHSOkuOSEHBynI4LDQMfVyogByQBIPF1g4uQDbsaiJ1IYH/tFMzvXGbqiATeCykykY27/YX0FxCeRPXCNRoMAGxss6hbeQ== 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=XOVUwsCdesOAxIwKuBpk7IheoIyYIMKYs3+/KWhnNw8=; b=J0FXJkGwiiq9hsNhDrxkipH/JVLJJDHAANLJAIiJv532WiYbsxFDt7JkyAhOLo6eOtf91Cg5fmHgcHOCNX8t74QnzdgvooHgoC5Q6+/CWzZrNaDdMFqCYv2GyxHLnCSXTg55bUCyEZjWA0s5oD00IBi0G7ztfhj018EJN6yfTb+dRAIKaehF483K2ojBEoyje6ARjYHYsrvtk8HFrc+FriL/LSy7e/L++2ohge1P+IRtefAuyZ6ghSAMFTSbeCXCxLgRIkTTIs3ugrpgIaBziv20ihE+zqNXrl37qISPC9ZE7NvygGqm0mC5atutFyOUrHeSE5gUDXhNi+z7B987Sw== 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=XOVUwsCdesOAxIwKuBpk7IheoIyYIMKYs3+/KWhnNw8=; b=yT73oPMJmwnzrlNd9y97Wo05beUTMeBsbGc9Gh9mgCS4I1vtgrko2uKoLr+skYQy/S0cXJhXA3eYjB4x5D4rsuAQKra0ljqjga2kNKOIBGYxug2y3zyqPTdO2WEZEo/IAHBTK/sZaSO/DN1iyzlZzyPRfh5I4YlwIX7Xpnp0WxI= 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 DB4PR08MB8054.eurprd08.prod.outlook.com (2603:10a6:10:389::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.34; Thu, 7 Dec 2023 11:51: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.7068.027; Thu, 7 Dec 2023 11:51:16 +0000 From: Javier Carrasco Date: Thu, 07 Dec 2023 12:51:07 +0100 Subject: [PATCH 2/4] usb: typec: tipd: add function to request firmware Message-Id: <20231207-tps6598x_update-v1-2-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=2038; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=IiE6db3v4YrX0nZYmhvzOKALUG0QQqEAuGZEbigpqME=; b=TrqZJpl0BlUS3GCONO2c/i7kZj3SUO5wEvD22r/kf6tYVFUoSEiJPOPzy+1Exxc2c/ga9xIVx PP2PCmGyGO9ClSBkFbO9YcDs4YxKGTSzxGDpIFKz8PXTDmpzCpcUX/5 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_|DB4PR08MB8054:EE_ X-MS-Office365-Filtering-Correlation-Id: b890cb81-ad2a-4f87-8d18-08dbf71ad02b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fw9m00jCwL73MpgX/9RSdUSaTWjpW4xNNUntMDtGmqvL5Hh6mcTRfN08FurIIOOZEUctP5mGApQvClHNVvrHsNAbZCXv57r0eQLgj531jnqqWmLMYRzXcQia8XZqWtlwBRTC2DRSm1jsY2EcgRfoVS+HGcMS89K64s1H+XVMYnW0aCQ7XN+Uz8NzFmIsJYS/jpEGHUVbjoskz1kWGrntg9YKCI4xiW8jfOUO4DBZc0c0o7u4OKrxW23PewrH9AE37z12Pew0xbEK2GIZGyG7peM0rp5WjF0lLjj6sZkqFGd32eaH9AKsIXfT7hhNb7kkKuv1lGasRBKFmEkFEWo/+BNfsh9e4CIAT9ZtJX51h8Vdx2n5ogotlRqe6O4RA6DxeC/mqQzlqESz+KYhM7/F2W5OosdevGIqC+u8SWTtDvYMUQJnW/pAfaOSpVu0D19UT35jk7p0mFT1Ta09r+JF4LY4pB1ciVoKDGhqW4oJ33u7l+7VjI7QYvnFOwxDfHfVm2UmxOXFHF7Ke4RDvjhLYX7j4VkCII7RLkTE3ASL7Ha+mzsM2pemVz96MzAWsth9ck2aEQbSz8dkjz+8NPVAdb8rpp7FQqPgZR/H90YhihIm2z1xjWF/wkqnGtHDfbeo 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)(39840400004)(136003)(396003)(376002)(366004)(346002)(230922051799003)(1800799012)(186009)(64100799003)(451199024)(52116002)(38100700002)(5660300002)(38350700005)(2906002)(2616005)(6512007)(83380400001)(6666004)(6506007)(107886003)(26005)(110136005)(36756003)(6486002)(478600001)(41300700001)(44832011)(66946007)(66556008)(66476007)(86362001)(8936002)(4326008)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?nUYz1UL4jzqfd5+EPfIzKUrb2c50?= =?utf-8?q?Q6j6mYiGMJRpev+EgTUsYJiprF2ogB+PI9dkNEjG6qO9rzrNzKDSbHouHUOWbHlYF?= =?utf-8?q?kXSxyrsmrPPdR5ee4mjyz9S2F9LlZghc3jQSOwON0Ih7Lknc36QPLlm0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JgQx?= =?utf-8?q?UdOeYkVoNlnf5yz19yVXDZqS8Zbf4DAdUed5tlyAO3KKf1KRax2Y5DDTSnUy4xasm?= =?utf-8?q?kQJxd6OwWfoQoBpXIYo5wgwGOSqelXEGvw7+pkW3+wUPwR4y0/mbDWPjdFgAT0d44?= =?utf-8?q?kOEUAhexjsR9iJeDhkyZogrTzcp3ZuVIABA0bPt9ac+bEwUt7bUpZpZGEgecZQse/?= =?utf-8?q?cmQN4V1tn4RTMx4HBkWv30aSKkmdhb/Eo9z9vJ1kOvCer5IMgxy6toHAkCnJtav3S?= =?utf-8?q?nfax10lXgUKrOBKJ9yPTSjdUx4icwpWIPYO9JAfZRgHNY7egSwzUaTpDX5WX5V7xG?= =?utf-8?q?c1Ol2vJjvc1Z5ykvchXK7hyetr4l26aBRz3z9PfAPKcljRebnfyeWbKIIynFjMw3c?= =?utf-8?q?TnhhaZZdjdBq8O5JgZ/Av5F6Fd/KeuH/ko2CJR7fXMJH4usHZZ2xN4xm+HePjx5+R?= =?utf-8?q?LO8nb8jlosUQcmw/2TaxgTar2zdEI19zYWfXFAGM2ux9P+Wrpae62FvMSCE0+tOWB?= =?utf-8?q?XLQUzet9VNhmuAaD4BEQ4Z+phb5O1omeaptzM4pqBtRTEiiWyJX4KQM=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: b890cb81-ad2a-4f87-8d18-08dbf71ad02b 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:13.7891 (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: HTCWi00nD4a625C3drVdZs+QXipLfrXZG8Jqk0hO6sQMiHj2PtMK2eekLddUGwWHSwW3iolWzy1jNv+xPxb0ZtowvgucvxWFrDx6rfJiUmI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB8054 The firmware request process is device agnostic and can be used for other parts. A probe deferring mechanism has been added in order to account for cases where the file system where the firmware resides is still not available when the probe function is triggered and no firmware is found. Signed-off-by: Javier Carrasco --- drivers/usb/typec/tipd/core.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index f0c4cd571a37..165a1391dc72 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -873,6 +873,31 @@ 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); + /* probe deferring in case the file system is not ready */ + return (ret == -ENOENT) ? -EPROBE_DEFER : 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 +986,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) {