From patchwork Fri Dec 15 11:56:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 755308 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2077.outbound.protection.outlook.com [40.107.104.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289CB25567; Fri, 15 Dec 2023 11:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="K59q91KX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L+e+fMQ0oPEHlHSxhEGeZPw+q/r2dGEkaKcg1lOr/y8x4zLOqPCVM8huOmHyguirKvVT9Fbz4HaEeNvLIjmbsKqXvivNBfK5GYFh42KlhQhAphw44dpwYIjbKDtYgMuryhKPtuGpa74qSpKPRA/yIH/1OowH5qez8YrHCfb6NuKU7t1EboDzU7lJUJ/C078ioC+3nrvz6YZEFoBvH3p9OPCFtYBJ+3aCyUGDCkFDcSkyTk2C01B9jaQXZoRXshFP54rrRd0l101yMZOn6FctJorOgphEgaMzE5cU5mBWSpPymn7hfkPMOK8icz44cPt/djwDtaGqNt80/tvw3n+VGw== 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=cCEamUi09ubpPY5s7jSHmF6ugaLgEH+EYKTxHeEJHsU=; b=Od/pdyMNTkzhiM3NCZFegdPrcV0/h3OqWbrbvBgDoMZgUO4d1ff1cA9ZiMPo0rFLBISelnG01xaBh9pjl1ALTJ64lhWLl5jmgqakQvbQ4wORctVIlAZeL5pkq7YC1LrgOrl3CCLtnO4sVwqNCk3zOTw+1HDHO3Y/pGyUVlP9fpCCeCVZtVsJeCaWDVPIgLrysYkY44nkSsYj+qiNwiT3nN08e32BMHjQZEdU0J1KsTFoEUP/UwtaRuZj9sq33bQ5hVQxHfn+iI9P3Hh70SlX8zSv2HDsxGRudFH5H91ynGfigd5lhkcOZwW2KdE9DTqFXqquu3oh72603+fjXrLmAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cCEamUi09ubpPY5s7jSHmF6ugaLgEH+EYKTxHeEJHsU=; b=K59q91KXlZQEf0ayK2P7ZeTlaoRk66kQ8w/DNcQ7U+TJAaPq/vplNK400JLeQD4bIqXX+hM2NTQHXuj3KbU/T+FMs93CJRtLWEo7z+JqnKWNQwfm522ujxftQ0IjaW9qpv3A7hFqVqHcYrcZ3fJzgJAyMgzSyOffwcbyR8eOam8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:17 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:17 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:29 +0800 Subject: [PATCH 1/7] firmware: arm_scmi: introduce helper get_max_msg_size Message-Id: <20231215-pinctrl-scmi-v1-1-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=2166; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=68MbFg0oH740yCUj6NB45LS/NxU8ZebVwrXvl332/EQ=; b=rrzskCAyMB+F8eM/6WfbpA2eOAllulGxE/g/2vAyu4TpqHXYsVVA+ocBmH7A3gRgTJdiwg5vQ vCzmSpydIZ+Cen7mdbubch4pj6n25eF4f6zdvHaTfX3YnzRZBfyf0yC X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: 8356d424-362d-439c-ff48-08dbfd644919 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HDYo9SIkxS+D3SgYHfWTsCXEK2Nr1aw/b1HNCjaZRaW99l/wErg61a98T+Gte7/0ojHIzLDt6gnTqP9nvhE/J9mEwExDwAa5U57VO7sG89zHKg+mQ8UbnUY4R4OzrlSgotfCt7PWMUBHZqgrXpJgNCWnTrWMfRYBYdrhTu5g4vDyXhQmzvjXw3PE3jPqfbiU5wkvaZtx5Xi4dvEAF9/kTUYV2xoDBnMuYzT+zfsSwcizgXe56It6W9GxoLmwi4Zrcq27iEJum8JqRFMO5dT71fjiFnuNG8lgooPW+uLSXeckRwQoUlcxt/AHcbGJdCB+T/DO54B/vd7bzRIsO0YoD/FAIOqkVYGGdY+Ot7JsFDwJJ0L3Em8WaKm2b87YJP/5dHrZfprx+zVKELsPkTza4OoufL3Zp9f3BZ4Kxz+/gEh0Uvy8GhONzBlZy68jMXzjKwUayhMhyzk3csG2MVm/tyzHEWCintlUT6c+tFVckOiVGJ7GYJOLFhdPemstzXjaOXFNxPQMxdxau6vU9JyBTJHaSbBLXDT2ZdHUGlIaY8bIfnOpizArl+oDFAlPAtD5toTdijwmT4ZvS1aTzM3OaQ5HabpksDoAeRd7yV2oCTLvaWPiGzGELi39it/1QTPZi+WK7lXM5u/dYII4cN/uhw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?KrLQPOYmneE/q1dvR2wvCwFEDobm?= =?utf-8?q?GU1GjorBCrg8MqPnTFUXDbFx87IJL3ULo50aKpB5SxgiSnhNPYi/mw9OBF3TAvRwo?= =?utf-8?q?K14HtfggqzPBTm+FPf8ylqp8sI8DTnaatqBdF64o0WRcSPkYM0sEyWDg3pdjlpi4w?= =?utf-8?q?tL0ub6008qjd0U8YqMcPWWsQSK6m5lXvbrkS1U2qxUg1CVcf3u94hZtaKrQmiXpNn?= =?utf-8?q?oOAZtTfW7XmX+Ivnpr4n9z0EGhkQIZx1cy7wNm0Q7h7pnQ2yRLXQgTYgwL7zpzOTu?= =?utf-8?q?CqvFZ/4aTTX+nMppssPZkBoYUXKP3qZlrTVwq8Xdy5lxhvjMK1tEejwzS4HS0HboB?= =?utf-8?q?1GqrJYk+UaQGIO3JhSWGfUixoXf1b5kuXFVEFCrSk79H6EqfRav89oDYRfj697BTX?= =?utf-8?q?DQEJ5zFI//wMg0pxdRxMGdF0y5ogXu9XK9n3i/eh2l6mCcdtSSrvhpt9SLQuaYOQ+?= =?utf-8?q?xiyF1jek51hQqXrele80SlwM1Q6OkH9rsHMSwCsN/r+LpaT517hjShPgEXqnThblg?= =?utf-8?q?zZDKCcXv/165d6Lf0PMF2RL/8BOyY24nMxBKX0IAJsZIMlRClxM8pD7Zo6iTVI9F8?= =?utf-8?q?vWRLCLtbgPuLlhooLFOmoZB/gOX0f6KQh65WQ0cGIe/7TB8p+KTaY+BMn+MRJNkm9?= =?utf-8?q?Ul+0TkogQor37fdT7hG0acZSSiQtnnkmbrK7G+zLSrE5VqGFmHx/Sak8QpDnqq3ay?= =?utf-8?q?RUo5aGMYYhWkydiRN7P1nsFOuxyc5h21ChBOo/nFrOfd3cdIa2z+0Lb95dCiSMbZV?= =?utf-8?q?N+8/RR3aMUYPUuxsNkjrAXJqTtPudcXNlfevJVPqd6oIxRcfdBCWkB3NTuZG7DII+?= =?utf-8?q?ibGmrb1/0+cbbffUdi9+HB2VIkq3cFu/PBHYetAJ8Qy+vLQ3R2dYbhHAQoChh5JBA?= =?utf-8?q?pLaTRS9G4sWjl+rx18U2c3lwbMTwVtaRM7TIXWOAEZPuMhXH+fGD6bCTQoPNbFEoq?= =?utf-8?q?sxWPPeEuOMWgRsMFtQLOMb7GmIUtuPP2gqSIySsffU/VosBBlhMTVVxES5g2C997a?= =?utf-8?q?M5Rgs41dhWM5B9jpY8q/7xW+4349biVOPn7TE6/ZotES304/J5mDPVKlVwopYijdV?= =?utf-8?q?ZVdxn2KV0V3HeZLDMsRRpYTBxrbNIxNa7BnTLvBToxIzUXIhwCWzlBRa0uFoGDvRy?= =?utf-8?q?AD/xAtDi9vhKrv5jvjeltRmPL9xwKE0c/vGg2mG6JasbKy0EaUSbTVKmd1fNE/xzC?= =?utf-8?q?cOoLc5E4DbrT05YQTvjGYQtuVSysBNDVrRXUjqffQ1SDoli9WmgkeVlN+qvxGDL1i?= =?utf-8?q?l/XOe6P9QetlT+VjjBbCVLM6ddNKI94BEhJeQwSqnquedJ3hxUlo4lgcWSoVtHm00?= =?utf-8?q?qomV7P4a8y4CKIlcjGpsylmF6xhv1HO4WfErEYYWxBNIg/rNn4iSQD2YCNqXrMok+?= =?utf-8?q?trAGNvKo4t5mGSb9+b8soIukPwAvwt6ve5d520QfEafsoI+1N5Z/LAVgaYrSktmJI?= =?utf-8?q?Xh2X41RWFEaz86stjCYMu45bF/20OOZvKm+3Wj+jbbWgbEWG3AfmgHU3KPIdF5GWg?= =?utf-8?q?HcqCWyUa636U?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8356d424-362d-439c-ff48-08dbfd644919 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:16.9765 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l0+k/JnbLpTsUToWa1KuQqFFPNKwpmjGdyBab4nZa7ETXV9kNf05HE0iVwPx12l8Sh6Z4PtOoobx5kbZpsLo6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan When Agent sending data to SCMI server, the Agent driver could check the size to avoid protocol buffer overflow. So introduce the helper get_max_msg_size. Signed-off-by: Peng Fan Reviewed-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 15 +++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index a9f70e6e58ac..b4f8f190351b 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1481,6 +1481,20 @@ static int scmi_common_extended_name_get(const struct scmi_protocol_handle *ph, return ret; } +/** + * scmi_common_get_max_msg_size - Get maximum message size + * @ph: A protocol handle reference. + * + * Return: Maximum message size for the current protocol. + */ +static int scmi_common_get_max_msg_size(const struct scmi_protocol_handle *ph) +{ + const struct scmi_protocol_instance *pi = ph_to_pi(ph); + struct scmi_info *info = handle_to_scmi_info(pi->handle); + + return info->desc->max_msg_size; +} + /** * struct scmi_iterator - Iterator descriptor * @msg: A reference to the message TX buffer; filled by @prepare_message with @@ -1756,6 +1770,7 @@ static void scmi_common_fastchannel_db_ring(struct scmi_fc_db_info *db) static const struct scmi_proto_helpers_ops helpers_ops = { .extended_name_get = scmi_common_extended_name_get, + .get_max_msg_size = scmi_common_get_max_msg_size, .iter_response_init = scmi_iterator_init, .iter_response_run = scmi_iterator_run, .fastchannel_init = scmi_common_fastchannel_init, diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index e683c26f24eb..08de8dc064c1 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -270,6 +270,7 @@ struct scmi_proto_helpers_ops { void __iomem **p_addr, struct scmi_fc_db_info **p_db); void (*fastchannel_db_ring)(struct scmi_fc_db_info *db); + int (*get_max_msg_size)(const struct scmi_protocol_handle *ph); }; /** From patchwork Fri Dec 15 11:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 754502 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2089.outbound.protection.outlook.com [40.107.104.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EDB32C68F; Fri, 15 Dec 2023 11:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="BYXqA111" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J5garSyRhuQpbG2urg1VHWQErCyzfN7XmM+HTc9eJI1QC01IgbIFNhKmU+ln7Bs58eo42TTGl1DmM/Y3Af7yhvD7u0nNd7kEf3WafSRrs78uPQ5GfVljb9mOuCRtoavzeJ2LMwbZL1GlsZ8UHOzV36b5w28BaOEtIiT7zmLXuZj1QMphAarSraQwOAY++mYyFXDBdK4aShghGukS6cYkpwrDmz7BWeYoeJlkgAm7vVYYfqNzwYRbdRnKmFcEP8Zt1W/ACziU+0uQw/z4HZKcCKRGrkhovnoRsId8DQ0WDCEqCryL3I1xADPN5qbTKalv8FjcMlJnvf0De4qB88Xzyw== 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=3ttjgFeI5wJugBEIpLxKg6PFf4dnpcoUQA3Zo/09ZCs=; b=N/HGGEHiTUroWhTuK5Is5Z3sncaL6h/QZbtwLAJ9s3h4k/UjIh1voQaPmZx6ro+FFIWITk8wsjqBhmvIJ11Sr+24Wn2c1snA3UVOCPu+fBgcW4/GSIjipb7mO3rZno3pjvnFnl/oOwT+NZZqml1Y/MG1dpqiU3UucjbPhvBswjwRy5V+WcRH7uiemiiFwyw0yDbh1tu+lfgKlRDTIOz4380FFJcO+aYd6D54hViDKjG3Z98eams6HWu2xqauo04qxjuFdRuwWdjEAMzu4os29t/058QhK85oh17MJ4Cd0B5Jigpe2Rk0azBynNpaCjbrI0UFpryqL6Si4/EHpv1cqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3ttjgFeI5wJugBEIpLxKg6PFf4dnpcoUQA3Zo/09ZCs=; b=BYXqA1119WFfFkcsTDOCJCdpMVvD3/KpcqBJYx604WKj8EoJk9tXI/doJlnB6fvedtcoAaWf/3yQex/g+6uSbw1MK+fhDuxDijsfFpDyr3gu9+n/Q/Naos396+OjTgwSYLXxVoy93anj3wu+Cysf1xi+NCwmpP9zLso161usQng= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:22 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:22 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:30 +0800 Subject: [PATCH 2/7] firmware: scmi: support compatible string Message-Id: <20231215-pinctrl-scmi-v1-2-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=8215; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=octm0BA3uvc+p2ruS1Kv1VgICMJ0bEcK+On781/jDL4=; b=lmqXh2KUy/q9rVerANBN9wkNsOj0vSX5kfJ+J8WGmjEIqsADCuSMRHl4xtv/x7xzw3DQ7NC68 EILWd7AEo2lDKZpJRq8Fgc0sH8MoxWDYDn+/09U7YsyQcpO0eeZSCuo X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: f53e9504-8d76-4c42-562f-08dbfd644c17 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sx2Te6BOp6rRf2ivKBY4J7rvWBmt1uPtk2XR+a4NlIc35jek1uy4T9LnLPjicLyQTdAKxrg5aQp9iZLUKj1UZmk8dgl614TzcijjFmgLhbn9euRg87zkWHrx+6QY4pbfuJyaSzHojE2X34CudRDCcl4CWmqNQnuQcvqPBPvcbjouQevGNhqdje33ak7YLp7bq/RHCKGPb213rO7H+CaYbyKZEBXLjOe3zqudrWvnBEB8TQksmnsiU5R8hnlpbOgYBdn+NkUPlCDP+/HV3J0gdlSE9cI/uMcxi/NAZsyfztsvzS6G45SWgB31LJnTC3QF3Tyco8oOMo4jpUjJsFj6w9xvEI7fpuP6J8tU3zDLMtFES36NRr3xPf7UKvyMFokpiWrc4gU92aTlVDO23hPkW+cOTWGAz7UQx6s9mF9ZT8B6oFY/gw4T6pjth5fbDh3T9O3c87kE9QR1u3aFMYQCcaPYPad6qtVuWhyCTmgp3sRS6v8paXSNp6amcjSRS+KCemCwtREc0BMUBMsIK+7uWD04VuYLXtlU+xdaQGzzX4l93YBAfui8oiD8OsE9CCQcc84hRXocchmdLbxCp9UBANGOlr8CnGv7Bss5aYjoU1yCPiK78Oa3UtjH6wxUBFelqtoRTsN9TAAXbFK48x1YtQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?atfmSdFkrWSBrQuS1X4hRQbInQ68?= =?utf-8?q?rOaIQ4Pp2HXQEfnp1UhTJAs0m4QXvp0XzIfQeaNpyr39FRpbxrQ8BnTK7Ozqa917f?= =?utf-8?q?2QJzDVDHn9KUceu6VUlyS7Gx0ZcLG8oN3V31g7Od/Nrj/29i30BRhuuW+Rjdu6xoU?= =?utf-8?q?PG1cEiDuQt/O9nBVgQzsutFR5EkYjf75p/pQqAVpgOVsmy5fJoPbvAm+VcbMO9BFs?= =?utf-8?q?BmYJefQzXg1Go8H4VeWeLQOw370X/iiJISYjrxxgRznUBjoK5ylqlftwsTnJmlHZT?= =?utf-8?q?DQr4cax2S0lhDVpWRQrB7lYfkbQhsd8m3Oq8Eebt/ZQTckod7fEPCkZYFNQQO2oF9?= =?utf-8?q?Xmc5iuRx+PsWykXAq+BXPuh4hVM7/xtJXOuvKGYrWb7F9nMoai0HYFbNfWsLAwf4D?= =?utf-8?q?EFkdU+kH3BoOka+6oj0koMAzKpA3XOaWVc6UJB5GiXuRppjynCupBDi1AyIo+O1u5?= =?utf-8?q?nM/JIvf28M8BauILF1KQecsNlUI8Ww4SZeEOEc7lueIkMZDeK9kJGgXD2P+0HLOpH?= =?utf-8?q?Xoq1QaZTsqsllOV/9dMIQrHHB6EhB7HJ63oFsVbYAL+MZ+HvBtpiYRDUSo3RIq36m?= =?utf-8?q?KaE+34FLSuQupr+ywmiStGRvg/9KN6Z89B56lvRTYo8U8m5W5AZ6xjUUNtkj66Ttg?= =?utf-8?q?OT/7WmCuNHFU+QpnTfnT5264cbWiZSSlXMlxKPFWieyTg57VbbqvwOCgX9iDvfT+a?= =?utf-8?q?d0h0Rb56GFWKpNmfYVI1JsgC7hJf2LpTyaK2ORIN8W3VW8JO5IqJt/siaUEB2Wd7j?= =?utf-8?q?+oX7tKdyeytPqsC5fy7W3T8yiq57S4SAf2SPsOv9t0oooKrzt9h/F06whkd6VmPIw?= =?utf-8?q?fyu5e533voeDaBj+k98uWAvjgV3zndp2prjsiXchbVQ/vneILILxiefB340dveWgH?= =?utf-8?q?1/Uh5CUHqHVjH+Axnbtj+okBdF+P1IjJtYKoitUFT7mrkZuvTjxiA8f9wEtjF1Rwc?= =?utf-8?q?RqgSZyJKMipwVn/H47gBbhtABpvN+n0hV+PDaNGYyWRFpN4Y5czZBEENHZ9t1Ulfn?= =?utf-8?q?44vMlsxD9w06mq9EMftAcmP0iBaF29NPuwwJNmjur3Lvv0iGLcgm9UiqP8TXPGJLd?= =?utf-8?q?UhgUNq1nl9znclVmLsUWseXKFCyuhZkyWuZWeBCa9smkBTmUtWd74fYyRXVQxNp++?= =?utf-8?q?dpnLXGei+r468KQUy143Nt5K7teg9C21M6+3axtRsRBgMeTfOeviJI5/XF2qSsnnD?= =?utf-8?q?87TTA13MthuE/Ix+afRIV1ciWQaN6kJREnpmBq7SpatqtIGBu2w+DGkEM4YGUbst9?= =?utf-8?q?4qEgrNDPTs8s94tSVbzQujFjPEAftH5Y1b+qadaW/Fl5nMpGWJWGOtPqld7ksxRIz?= =?utf-8?q?47NM7RnlNI4mxhU82xJIxSSCstCJhWONTx0dcNW1p5sCbaGJdQbRnxMr2SjXWRpDy?= =?utf-8?q?HGH7S25HdvWCMxLcOruqNmRpQ6i3IGvoCmMAaGr8ZE9rM/qc+3+FhBu4xYZtu31XO?= =?utf-8?q?BqjbAKgwqH69bL5Sq/3qNfd98EzX6ozX0Loz8qu+M+9VXfZNrVkQ0gW2eGCaPKMlV?= =?utf-8?q?W2/NvADk4ABG?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f53e9504-8d76-4c42-562f-08dbfd644c17 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:21.9609 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jEmKK58xLoBU4lUE+TSssEgBE/p4cKq40r2a7Snhq1JA2FNAEu1DMbkykvBNYc155M/9cYbUYgF8jGkY54hlTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan i.MX95 use SCMI PINCTRL OEM config type, so it could not reuse pinctrl-scmi.c which use generic pinconf. Then need introduce saying pinctrl-imx-scmi.c to support i.MX95, however both pinctrl-scmi and pinctrl-imx-scmi driver will register a pinctrl device with the same of_node(protocl@19). This will introduce an issue, because the pinctrl subsystem will use of_node to find the exact pinctrl device. But with two pinctrl devices registered by two drivers, it is unknown which pinctrl device will be chosen. So introduce compatible string to support cases that Vendor SCMI driver which does almost same thing as generic SCMI driver, but has some specific Vendor settings to do. Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/bus.c | 39 ++++++++++++++++++++++++++++++-------- drivers/firmware/arm_scmi/common.h | 2 +- drivers/firmware/arm_scmi/driver.c | 15 ++++++++++----- include/linux/scmi_protocol.h | 2 ++ 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index c15928b8c5cc..c999edd18cd3 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -194,13 +194,21 @@ scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv) if (!id) return NULL; - for (; id->protocol_id; id++) - if (id->protocol_id == scmi_dev->protocol_id) { - if (!id->name) + for (; id->protocol_id; id++) { + if (id->protocol_id != scmi_dev->protocol_id) + continue; + if (!id->name) + return id; + + if (!strcmp(id->name, scmi_dev->name)) { + if (!id->compatible && + device_property_read_string(&scmi_dev->dev, "compatible", NULL)) return id; - else if (!strcmp(id->name, scmi_dev->name)) + + if (id->compatible && device_is_compatible(&scmi_dev->dev, id->compatible)) return id; } + } return NULL; } @@ -325,11 +333,14 @@ static void __scmi_device_destroy(struct scmi_device *scmi_dev) static struct scmi_device * __scmi_device_create(struct device_node *np, struct device *parent, - int protocol, const char *name) + int protocol, const char *name, const char *compatible) { int id, retval; struct scmi_device *scmi_dev; + if (compatible && !of_device_is_compatible(np, compatible)) + return NULL; + /* * If the same protocol/name device already exist under the same parent * (i.e. SCMI instance) just return the existent device. @@ -405,6 +416,7 @@ __scmi_device_create(struct device_node *np, struct device *parent, * @name: The requested-name of the device to be created; this is optional * and if no @name is provided, all the devices currently known to * be requested on the SCMI bus for @protocol will be created. + * @compatible: The compatible string * * This method can be invoked to create a single well-defined device (like * a transport device or a device requested by an SCMI driver loaded after @@ -421,14 +433,14 @@ __scmi_device_create(struct device_node *np, struct device *parent, */ struct scmi_device *scmi_device_create(struct device_node *np, struct device *parent, int protocol, - const char *name) + const char *name, const char *compatible) { struct list_head *phead; struct scmi_requested_dev *rdev; struct scmi_device *scmi_dev = NULL; if (name) - return __scmi_device_create(np, parent, protocol, name); + return __scmi_device_create(np, parent, protocol, name, compatible); mutex_lock(&scmi_requested_devices_mtx); phead = idr_find(&scmi_requested_devices, protocol); @@ -442,9 +454,20 @@ struct scmi_device *scmi_device_create(struct device_node *np, list_for_each_entry(rdev, phead, node) { struct scmi_device *sdev; + if (compatible) { + if (!rdev->id_table->compatible) + continue; + if (strcmp(compatible, rdev->id_table->compatible)) + continue; + } else { + if (rdev->id_table->compatible) + continue; + } + sdev = __scmi_device_create(np, parent, rdev->id_table->protocol_id, - rdev->id_table->name); + rdev->id_table->name, + rdev->id_table->compatible); /* Report errors and carry on... */ if (sdev) scmi_dev = sdev; diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index c46dc5215af7..930a24e0d712 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -149,7 +149,7 @@ extern struct blocking_notifier_head scmi_requested_devices_nh; struct scmi_device *scmi_device_create(struct device_node *np, struct device *parent, int protocol, - const char *name); + const char *name, const char *compatible); void scmi_device_destroy(struct device *parent, int protocol, const char *name); int scmi_protocol_acquire(const struct scmi_handle *handle, u8 protocol_id); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index b4f8f190351b..3174da57d832 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -261,15 +261,17 @@ EXPORT_SYMBOL_GPL(scmi_protocol_unregister); * @name: The optional name of the device to be created: if not provided this * call will lead to the creation of all the devices currently requested * for the specified protocol. + * @compatible: optional, the compatible string */ static void scmi_create_protocol_devices(struct device_node *np, struct scmi_info *info, - int prot_id, const char *name) + int prot_id, const char *name, + const char *compatible) { struct scmi_device *sdev; mutex_lock(&info->devreq_mtx); - sdev = scmi_device_create(np, info->dev, prot_id, name); + sdev = scmi_device_create(np, info->dev, prot_id, name, compatible); if (name && !sdev) dev_err(info->dev, "failed to create device for protocol 0x%X (%s)\n", @@ -2354,7 +2356,7 @@ static int scmi_chan_setup(struct scmi_info *info, struct device_node *of_node, snprintf(name, 32, "__scmi_transport_device_%s_%02X", idx ? "rx" : "tx", prot_id); /* Create a uniquely named, dedicated transport device for this chan */ - tdev = scmi_device_create(of_node, info->dev, prot_id, name); + tdev = scmi_device_create(of_node, info->dev, prot_id, name, NULL); if (!tdev) { dev_err(info->dev, "failed to create transport device (%s)\n", name); @@ -2550,7 +2552,7 @@ static int scmi_device_request_notifier(struct notifier_block *nb, switch (action) { case SCMI_BUS_NOTIFY_DEVICE_REQUEST: scmi_create_protocol_devices(np, info, id_table->protocol_id, - id_table->name); + id_table->name, id_table->compatible); break; case SCMI_BUS_NOTIFY_DEVICE_UNREQUEST: scmi_destroy_protocol_devices(info, id_table->protocol_id, @@ -2802,10 +2804,13 @@ static int scmi_probe(struct platform_device *pdev) for_each_available_child_of_node(np, child) { u32 prot_id; + const char *s = NULL; if (of_property_read_u32(child, "reg", &prot_id)) continue; + of_property_read_string(child, "compatible", &s); + if (!FIELD_FIT(MSG_PROTOCOL_ID_MASK, prot_id)) dev_err(dev, "Out of range protocol %d\n", prot_id); @@ -2828,7 +2833,7 @@ static int scmi_probe(struct platform_device *pdev) } of_node_get(child); - scmi_create_protocol_devices(child, info, prot_id, NULL); + scmi_create_protocol_devices(child, info, prot_id, NULL, s); } return 0; diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index f2f05fb42d28..19a06b872afe 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -839,6 +839,7 @@ struct scmi_device { u32 id; u8 protocol_id; const char *name; + const char *compatible; /* Optional */ struct device dev; struct scmi_handle *handle; }; @@ -848,6 +849,7 @@ struct scmi_device { struct scmi_device_id { u8 protocol_id; const char *name; + const char *compatible; /* Optional */ }; struct scmi_driver { From patchwork Fri Dec 15 11:56:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 755307 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2065.outbound.protection.outlook.com [40.107.104.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F7662D61E; Fri, 15 Dec 2023 11:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="OZg2jsXi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iQUkcpncIJaTS7w9Z4OqbGSYYLgjFNp0h8KS8KdEvKiAZLf1JlMB0oEKo8qPMxhEyMI13/iKRObitdK15uEAN/o675xyfTZvJcu1np4jeHkJAEhUfOSe1Qr1JBzHZoQGmallAcq3f1XMUTKs4EhEKcevxDkJAAz6Au84aljuZfQQLEKaPrOtS+ytqdtA6/bms2sN02jwxzBJPqWrJoyH3EmU59BGDpHDRjfAp/NKvr6pcxI5Ke/XdZT/0+PdgnUNMkMrV1LhlUUH4yagE+WaOoyZ5MVdpyEAKIKtnyaFpb1/lsbGijuQufhWlul8rb8qVXLZeIcAmKMCVieEYAINNQ== 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=CCB9GqT9L+fZJ0Zywsd9Jf44DP6UKAAsJwON0p3ppcA=; b=Ho718PEzie6tNYBFESjJuwVYu/OXKSarM/WapXiyBznTverfIu+S2Ul5fv/or29h15uKj3srbCxWAw5+659fbXC0AjiGismHcV6AwGDC+LzX4wt4RhOLODz8ByZ3EUo00vgiiXxyU0EofLRQSyfzKxEh+B4WELZodjhTPIVyBBTdSNjp21aAc+U1zpW31TL4itNU46DTsFHdR8mkFVpKXEv7k1VhHR5Y0+LaFxtnbUmgDjOSofjpmP//r5b9oQyrbQT8+MITg7iXdFiVcxAvj+mafTH/Tf/QOGCvYsFFSSZquAkQJGYjVHBDsFK9q+KgoShFmKYVIWrdBoE+Fv0IrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CCB9GqT9L+fZJ0Zywsd9Jf44DP6UKAAsJwON0p3ppcA=; b=OZg2jsXiPLOKUrWBz3ECSl/HXg6bEwIyJ7IO3ePgiMn9WlVU+KbweJs6+tAmxbwEFDvyD1yOMmn5wJjxLjvUnnYCbb75WVYkyXNSV3NQWujDf2r3BgmsddQCaUfuynjXOD+P2Vw/QPk2tTAUu+9hN0fZOatYSq7ZKSlVotvo4Ls= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:27 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:27 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:31 +0800 Subject: [PATCH 3/7] firmware: arm_scmi: bus: iterate the id_table Message-Id: <20231215-pinctrl-scmi-v1-3-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=1116; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=FRGxInB0b3KsSvsP0EAYnn4A4HfxHZyqmybMfTc2pqo=; b=08yi4PqS38l04uzUotv/HklHNJ5aXPKqCbaoSd3nOAZP9IaUiSURvnfL3v1k40inaoR86gsw8 Z63wwtifZ+7CfUStb0X39byjCJ8/T08jQ2/SM16XAijV2fvTpkC4I82 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: b64403a2-b8a8-480d-0f46-08dbfd644f17 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8/t5kQU3wGa38FmqBSI2rgRSEdF+zXACu7e9O4a0q6wAhCu32pMyk23hAIxgZX6smVtYuHqVUsyCD4wUy82gKZ2UOs/2oqq+H7EemAHTwNAgtrds734K3p3DZyTRGEqj78JKhccYMrYgsz/vSTM0OWdXSD8lAjmkJcE20sUcdzDoInPtP1X7ew80NT3FL827n1fBhxF2p2Yn8mLOgG6U8uEpWerR4J82BeGKy1hw2dZvNQuVbftWDEX44aGfYTLvS6yq12UxJPXumy7JHcYd0PJT/kRZxOEX2AkZ5O+vouig0vILEM0W1sKwXYDeq1OsIExC9E/YSWyO2jdyIDqhaIvI3URreBEsjG2GHzd52WapepC81XoW2pEa2kS70FMMV8iqqsDPV4zFrFFfrIf+9zIHWxHOstYTo3lTC2I/Yz4saTFWimSvLKmOX3x+tEnUYvkNlDgXdYMJscUe+atjj41FxWjuewDHCPoIwi9P5sfub+PZzcZpZVo1SYZI9y2h3sMGd+of5kylWPpaoIWdzSg4Axezmt5Qmqz+Gh5owWC17YyFcNZ2DvwmJCdjzPsd+RZFSJ8NzXLK/CFXc4ZzBoA5Al+bZW0pkujUAtIxb/mJcmooH514n8RTQwobHfT2VsBfV10TmG5p7n+5247gfw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hTp/CKBS7y0dhKH4r953dx4xl/FE?= =?utf-8?q?Wg3xFcu4wblsFQYRaf5fyPHJapEXUTfJh/h5zDdahLhj/zPgRV51asEkDsR6Qms2k?= =?utf-8?q?TtbdXUfbBA20C4izf3u93h8YMjDnAyjDoNBYjV/4gcqzT/HyxkNcz1qjA/H99hBbV?= =?utf-8?q?A4R/tGWgUYGsggk1pyoijMPd9wCeadHVkjbL/RpD/0asJGqLUpb3YQN3g1/gQ1ixS?= =?utf-8?q?2BGTn5rWdqrNjZjMJ5nFAy8eT3Jd8846tFAcDisA19QIacHxNBfV7ugONwENCHHqU?= =?utf-8?q?EoejXfnYQhe51LD9ZqiQxSLzUfv0/JEGwdKg4rFQ4Q1r+zEpP/FqjGzuqo8QnQ3OD?= =?utf-8?q?VUGIipGR1Tu8vmMQH4DbjRKnUmHjLNHepqhw9nRiQIbNFv0vKjFbLBgR2VtcAEXIM?= =?utf-8?q?v/hnmfOkrIT86LKU4AiJjhkpCqTkg0yTpzHfvny8wnLyAgkOqcaSHzi/AEx1wUWT4?= =?utf-8?q?2Vf4xMGEiVeAS1RB9NCc6IGnkH4+MuuDB2TizoZEKmo+Q7QqTaJIhNRZUTlzkm9vO?= =?utf-8?q?MX5InaLUlXJQKUnPYMp/BFPuWGWAmWkfaRCQK9tRwdEnM/3iAnGJKeFOs8TAUE5UZ?= =?utf-8?q?mbHzUjMVYgJaTZpNXz/TjA1AHIzmDbOAERNJ50bTUheyXQ7wwj7SpOhUK5eYusttM?= =?utf-8?q?5rDzOauOUDpwVVXA12p1nJLTaPRNZYMQFxOwmT53wH0Q0oP4UGZcVvBsZdXc3A3mI?= =?utf-8?q?gVAhtBQMc70s+KEGL2VuYtop57y2NyHuWD3QaOT3pU9bMIVVfK8KRxXHKT0hvCxMw?= =?utf-8?q?CAKgrgsJ6nKk/D3NC7qx6nTPnR8YvOT8sxdkCNxVi+FKFLIvW4opgxqR5b14PAdQD?= =?utf-8?q?AVTfn6n75ISJg1HxBOQT7m3YJNHJqNCu0IjoNMr6U5hUlr+aCPoFShV77ElWozRbo?= =?utf-8?q?IAshRvYPDl2pp81wJFYX7+dcnWNRsfEEe/ntCB4TTos2+jTG/cUDlTCjNqaH9GQmh?= =?utf-8?q?qmxjwM1PitnRHItYuAfcuktSaJzF40rWrdTd8LuprzGHe5BeYowXNm900VoBAMxk4?= =?utf-8?q?2pez+CFoy0dNN0Eyi17ZS6ZwLViYzMwxIktUGK5uRWxbMdTZnSjNg1ucGAWiGu6ak?= =?utf-8?q?Khsq43CS76MiS5V/niU2fyYWZZlOv19xnM2meJEzQck3ubYski6+HJRXBKSDRsm8T?= =?utf-8?q?uZ+yj9JnHL0T+hPd8m6Vv2RZHIbF9j5KzCZOS0kR2TnzV5XYVHwbQwuF4p/JeUQcH?= =?utf-8?q?w3x+NsB0lvyjOVTI9VW6UDWPNNvMv9h9kU2bfnq2hEzvmMNRhaGuoH7/F3HWuMTc7?= =?utf-8?q?RcVCpXXDd480Dh/VYCqOMEIe1fKUut4v96/ThNo6mB0pfB574H2y2jp0eIJeHJVuN?= =?utf-8?q?/t9N5nFvjlW1puFAlGgVmwh6ZBPCfUeMfnPL9w2MeVwADyERCdv+Rj0MSBJB9GJ/P?= =?utf-8?q?ckXfw5HwNgzFHSDr2mHC8PC4l8EE3XSG+ioqbBRGn8z1Fy+VeHVJA+06HlUo/upMd?= =?utf-8?q?ggkXwM9lFBtOl0ixOKJ460P3qPQ6OnZuDApg0Meyglq6S+4TFhWUDbWB4lRvrH/hi?= =?utf-8?q?efuG3+jtzvxG?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b64403a2-b8a8-480d-0f46-08dbfd644f17 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:27.0020 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Kp8AQTttAWOcsAcXXK9czwgED3CudeWUr4nhsDE7BxCjl+lRETPlU2aLnYld1cQMv3zpsaMCsDVOjMNjyUx59Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan There maybe more entries in driver->id_table, just like platform driver of_match_table. So iterate the id_table, not only use the 1st entry. Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/bus.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index c999edd18cd3..aeb7da841b9d 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -282,14 +282,18 @@ EXPORT_SYMBOL_GPL(scmi_bus_type); int scmi_driver_register(struct scmi_driver *driver, struct module *owner, const char *mod_name) { + const struct scmi_device_id *id_table = driver->id_table; int retval; if (!driver->probe) return -EINVAL; - retval = scmi_protocol_device_request(driver->id_table); - if (retval) - return retval; + while (id_table->name) { + retval = scmi_protocol_device_request(id_table); + if (retval) + return retval; + id_table++; + } driver->driver.bus = &scmi_bus_type; driver->driver.name = driver->name; From patchwork Fri Dec 15 11:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 754501 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2058.outbound.protection.outlook.com [40.107.104.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D93F2DB6A; Fri, 15 Dec 2023 11:52:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="DrUbT47e" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D4mev5+OvCSyds1KUaedJpyk9j2op9DjfdsEVspuoUIrsiPRRryOgnFCGPEvL32T4HMTbubWSJvv0NCP4xRiedBhQ29CcBj8k6GIHA405smfLVnxiN4OPsmhYucBCZRqtW2+lWTzZINDWu3FvlzPRRFn+JCEWS5uWy9O6jkOdRdGvK00Xql01ijaSIqG0YlVNZWxFSCNAW026JCSQLmSfiaflfJ9MfW0eIcjMgovjpM3FQYyFFsnTse1RPdZEHvAo/xtxiM7HXkzFrPQJTtcD0hpJaW5cmAbTUtaQnxvwMurnSc02yqqJSimXZvHS+akQzjdXQMxetz7knBdgDyEkg== 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=mayGoMU32z5Lhprj4vCaChRqNSIqBj4ti03V5M89934=; b=R+5s076OTPo3AwvwJeB9TyyUvI1r+8fhdUF1P4Um0xCs/s/eDie0/TGtQMoi6MM2yWt0CWfK5WEHLbo49LYyYF98Al5Ky39pokiDnZ7nsEx4dUPWHIB0q2s+uiApVsulNkeve31V0d7NVop/FOFuN0738IkLkYbHo9+xVFMNzJMM9UNBNsSToFex2JjcymqZ20lfojHDMLM66jDeGzDEY9rAHKBdEsSb3hi/eFNQvud3nZZDgvKMR9hqDoQj567Na+TntZBfulWRSsILJQ0nDl7ubuvD7gOJbSwHcgdYbBVkgnJjAum4ci8b45hAQH7d9lKokKUb3K6Eqw0fpMFETg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mayGoMU32z5Lhprj4vCaChRqNSIqBj4ti03V5M89934=; b=DrUbT47eSacAzFC9gl8WoELb+aSm+dtehCfcSLM3cEXO4krolRfOOhElfYnMP8J5pZzKERf46EMCp+Db3cMlUOnj18yi4Sv1YVFvZyPoBZZWPSEZ9mryBTMg//l0I4kvws7zNB/oJBE4TiH/j6dSrUP6zCrfx40PT3TPbdoz5WE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:32 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:32 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:32 +0800 Subject: [PATCH 4/7] dt-bindings: firmware: arm,scmi: support pinctrl protocol Message-Id: <20231215-pinctrl-scmi-v1-4-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=4331; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=aERjN+xM/kvXQQHZcTB8hrgs9oheX/AnqRYQ4guJAU0=; b=9lkchBROWbyDnD0gXjdJANzCarK8MuZe3dZza5Z2eVzVwD0tGcBf7rFhYppeLfYDGcpoiYqHz 9qggAYGoR/bCN6r6GbRnnGiontxTgxz+ZRKXul968gIiNS1dEbo9biu X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: e0d04d9d-d674-4c7c-51d8-08dbfd645220 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pyHIA+XuLQqmaODk/+HR8djV1Xgknvw9S+r7yfc9wk+47R1wnY7bnEYhFNJZ95ZMT5L325bOTpiyVtg/7STqdKOUO7YFnpdxyGNljRHPyfYZ7etmQmyrOduE7bBJg65jQqo9HN8A4saEy1tpKEyz2dK14kbSuvpfV3qL9Hrc01N/VdWcQ+J18lSDu18CAlXMwuZtfvs284jBWFAaFznpHfdbxr/uMReWxtmHKRegd/TmFbk9gB9+eXxZ0exMJcs3wF2xuOF/vbvXVZgMiqQE4JMefeQAKXvgSA/uNjRhyZfLCfD/VynShHxMXX9OPJZYFEy7jIyQu1PrC0ZMAcNoHaiETL/qA3s552dFPeXmNuXG3M0uaWlMf4T77NgZreif1LPS4/N8DEoWNt+GHw5E3skz7mUoOW/fyCODGkq17AirxXi83rw+y20zOyxYhpMCIlKahItrrn0YnShoS+zNAOxlwvGzzzkbobTdYZV9f4Fv3o2ss1IWIGrJW1ovCNYOR2Jzv6khl4wB0aCFmpK7uUlxJnR5AGiD5LULKz2e2mxynPARMHzQcB/6Kvcem9TPhrB46RFBNfYL5HPbdJCo0n632wsz4aSt+0o0VchgVpN6FqeNXI9Zhvfd54dXN8P8tPlipIqknaPACMsiVg1Xkw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(26005)(6512007)(9686003)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ZxJGmb8TBMTsRBBmATqM3z1O/7xg?= =?utf-8?q?J097sElgyH4HuGml1niyKiINQFEtaaa3wdZVxYNntVdMqgjqCcjTYgOaiGsOVlCdB?= =?utf-8?q?Ar0Z4Onwlaq1QSHM6l3O1R6koV4uKBK+4Z79uEZjry2wHe+tZGPizUwmZB3QsZGUH?= =?utf-8?q?nTvO09o+yPj3GcW5tomQFV2IIl8NVBHWJ6M6Y+xHFYLJFbcAaEThK0MFzByDDpB+M?= =?utf-8?q?LpptwR+BIDf7fDpgAt/d4q9R7ybYOonLq+0JwS8KL6F7K1mx1l3sXNeGlX7uvByFp?= =?utf-8?q?Xqg644lhZualVDUBerJ0BKiOc0vrEVMLg1rxJZnzhLFcp/lH8+FDcwFko/ZmnVAas?= =?utf-8?q?uxVwXavBvisqkeKGugoCu3YSiqqmB22X6ZX/fNZ8Lbez1teaRVGkQhBWjtE6cgVF2?= =?utf-8?q?+yX/uPOd/K213zrqm6nohvWF/0fqwJROOH55h10x7BeH6xOm4hN4xAunRLm/J1ll0?= =?utf-8?q?tddudyVkJ1rUqpatLnxdGhLBKXZeIDuuIiVAJu9yQwyRNNC0Ilo4MV7ZGSAWCFEyd?= =?utf-8?q?4aN7DAVmVc+aJrQRrpeFNQLtZT2FZSb6CMvcNHEWg2bjcrRif21K0bSNwpBNiglO3?= =?utf-8?q?7qz0NMLI6Wo5BBoT6QFH7yu8Z9zw2uBxoBNggKNhJe8iHOx2h87Bk5m+bqR6BsTOv?= =?utf-8?q?FMtgwu8dC+K4yAEI56CfC3YqYl0e1iik7UC/l7MEhWNTJxZ9J5QYM4a7GUysWWkCP?= =?utf-8?q?Eb/R0gTCTOBi4jZGdntRYldwNRnyW63bCyF38jV8ANPggJ3vw7BL9P3EFI15wFyBZ?= =?utf-8?q?iVydGePBlCggMFPH/x8pFPcAayq+9+YE3TEEpNd3CMF/HsoQPYYap+0apwZmAA+0N?= =?utf-8?q?yM/nDeNXv+AjDOix1RsKRjbrEJtTKr67T7Cv6+0lRUx8Z/DeYm7ePsIWYulH91GnC?= =?utf-8?q?RtOiBerzcPcMRFkDZYNk0ZCodwNsBGPC+a5gT9EdSI41OiEFnKU75jkSTF8l4WpvL?= =?utf-8?q?cj2N4BIqV6XlBHDsuEE0ljyxIS/BHG/bF1mf/bt10K8oPSRCACw3LXglkcbfeYI1/?= =?utf-8?q?BoUaFy/ceGJKKFV9E75550FskdUwuAuGlBBNIKs+Py2B/P4YJHnOQOye1LQ+a+WQC?= =?utf-8?q?GE5VOIFjrYREsqxTCFDZiW3FqU+dNtJaUCxC3y43TK2Jy5dfnG4+jeQjn43o29cZE?= =?utf-8?q?VCF4GxKsC6yQyYe60iZiqMqLRCNkUFthr3Q2qDFRzqo6KdgxYyoBL7gZU59WCko7C?= =?utf-8?q?Gw1dVXS4Nghh9JApd6zJEEXyhFL8a6Kp/6b5bn6MBxPjrgUBR1uXMF84Qyxa1WTPM?= =?utf-8?q?2T4ATGICZIjgaprzYrNpljV410x4956SBVmbvTHLfbwqNpFAr1knKFrAHtPbP8Z+k?= =?utf-8?q?ubBltClTkVIHRj+dluHhK32VOxJjWVnt6N9SXY1kLwa+BM4U0BPkpKgiY+zaSHdT7?= =?utf-8?q?eDped0aZi2hj58Pw6oi/2LUTrec1uQywge7D1p5dHuUnAWXNMYjUNOYee7f5v91KA?= =?utf-8?q?J0Z7cwwMvX0PhBwXxBXptH2WVtxDPURU5KUCNlkl/IINyNGchpHzWg2IoNfRz1fUk?= =?utf-8?q?4Q9GUi8TJjgS?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0d04d9d-d674-4c7c-51d8-08dbfd645220 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:32.0625 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1NkUEzibDXopGKvkuSYGAyfCpX90ZItCE58ZX/SzMzznG1ZH3gXtqT+6hr0N6b5WoePunpqxJeGrSWOyd2RBdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan Add SCMI v3.2 pinctrl protocol bindings and example. Signed-off-by: Peng Fan --- .../devicetree/bindings/firmware/arm,scmi.yaml | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml index 4591523b51a0..bfd2b6a89979 100644 --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml @@ -247,6 +247,85 @@ properties: reg: const: 0x18 + protocol@19: + type: object + allOf: + - $ref: '#/$defs/protocol-node' + - $ref: /schemas/pinctrl/pinctrl.yaml + - if: + properties: + compatible: + const: fsl,imx95-scmi-pinctrl + then: + patternProperties: + "grp$": false + "-pins$": true + else: + patternProperties: + "grp$": false + "-pins$": true + unevaluatedProperties: false + + properties: + reg: + const: 0x19 + + '#pinctrl-cells': + const: 0 + + compatible: + const: fsl,imx95-scmi-pinctrl + + patternProperties: + '-pins$': + type: object + allOf: + - $ref: /schemas/pinctrl/pincfg-node.yaml# + - $ref: /schemas/pinctrl/pinmux-node.yaml# + unevaluatedProperties: false + + description: + A pin multiplexing sub-node describe how to configure a + set of pins is some desired function. + A single sub-node may define several pin configurations. + This sub-node is using default pinctrl bindings to configure + pin multiplexing and using SCMI protocol to apply specified + configuration using SCMI protocol. + + 'grp$': + type: object + description: + Pinctrl node's client devices use subnodes for desired pin configuration. + Client device subnodes use below standard properties. + + properties: + fsl,pins: + description: + each entry consists of 6 integers and represents the mux and config + setting for one pin. The first 5 integers are specified using a PIN_FUNC_ID macro, which can + be found in . The last + integer CONFIG is the pad setting value like pull-up on this pin. Please + refer to i.MX95 Plus Reference Manual for detailed CONFIG settings. + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: | + "mux_reg" indicates the offset of mux register. + - description: | + "conf_reg" indicates the offset of pad configuration register. + - description: | + "input_reg" indicates the offset of select input register. + - description: | + "mux_val" indicates the mux value to be applied. + - description: | + "input_val" indicates the select input value to be applied. + - description: | + "pad_setting" indicates the pad configuration value to be applied. + + required: + - reg + additionalProperties: false $defs: @@ -401,6 +480,26 @@ examples: scmi_powercap: protocol@18 { reg = <0x18>; }; + + scmi_pinctrl: protocol@19 { + reg = <0x19>; + #pinctrl-cells = <0>; + + i2c2-pins { + groups = "i2c2_a", "i2c2_b"; + function = "i2c2"; + }; + + mdio-pins { + groups = "avb_mdio"; + drive-strength = <24>; + }; + + keys_pins: keys-pins { + pins = "GP_5_17", "GP_5_20", "GP_5_22", "GP_2_1"; + bias-pull-up; + }; + }; }; }; From patchwork Fri Dec 15 11:56:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 755306 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2089.outbound.protection.outlook.com [40.107.104.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 319142DB7D; Fri, 15 Dec 2023 11:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="WQGGrouA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LEQVQMfVfilFBoZB1zZBbYW4il0JJ6z3iRMPQgO6iNsKZeWF+dXRpFQUZCC2vSJXM4PcQ+nBBHVPl+EK2bHaSC4xILBZZXY/EZAC7N38kTXs58gvWMJAwAsnrWJr3Q1lYmozoITOb5I/ABfJRrRuAMDGcHlgJv1tIQIFMvH3wezwR7ZXyB9/BhFZfMow5CZssUeCioRcWpaF0WVpG1QRcOH8wO7PVQVQbe+vEpptZgE55H5SmBxnyT80ZKoknILbLrNbO76q3rQkhnBmtBEpgsvRQoBqSG2DcBZAW10WQFyFO/rVIyphwdfhqRew1IQaar0XNEdwQi6+6ns1xu3YUQ== 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=8hvCTZQ34ARoTcAEb9gi2pms+orD3tP1pF3608JG7T8=; b=ghlnCd+N1B5F3Au+1/lhvI1jv6Er1bfirTGoQPr9LVVQPlFrmt3JARxQQVkADixS2I7112eORTiaMaovreTDMwgdxHcOIs6JQa2PCWxcOU8yl0nJ5bCCNP1NeCpDhqKclMWgaaeYePK7L9/DU29gKGfvbG0HRWrAqLse70vpnh2bYU082tJ3kpInoN9338njRyD6Ry2LA7hYxttZwhEsMyKwsRCYgwQ5JSuZRSzuXnM/1wKuW95A1A7ir8J2iYI1fJDgweIHOveFVJZv8Qnm46tEUHhV39mE3I4Ioi9iWsNNDpq98mheDdhX/s8eXXR01j43qf+ZOvwTeDj+Ysu46A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8hvCTZQ34ARoTcAEb9gi2pms+orD3tP1pF3608JG7T8=; b=WQGGrouA/3s0Z9BiiQPB1qgzdb5fP36V5LF5t9lguXKZ5aBiDflCjRUKYOVOk0PSsSnOch+UDqJoA1btjg+GY8hhZmpOXfSjj3S3j4fmEnON86C4SNCOMEe8xpipYRVqU7GHnvpnPfdEgObgsXUiuUsjMazFPm6/ZJ2hPHOyZjI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:37 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:37 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:33 +0800 Subject: [PATCH 5/7] firmware: arm_scmi: Add SCMI v3.2 pincontrol protocol basic support Message-Id: <20231215-pinctrl-scmi-v1-5-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan , Oleksii Moisieiev X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=29494; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=+gcG9Afq0RuArFK++pu1kDCyeXltNy5uUPVCQqMnVe0=; b=0ZMN9Dkh265Bu7IgYx6YM6gbRAKMTgP92o/dWh4Jdx0btNolsg5x9LP8C31DfMFy422X6DN4i EGX55OXaOQyAfXvUfNHuLd9IcNPqps3+E0iBH+iT7VoCsAT2HkW4LUG X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: 21c601f7-3a14-4b60-2e14-08dbfd645584 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7frURO0flVLkKuQ1IzFH8LX1lWsgE6BeMRcYclxh/vhUrMno0/oeG5VmZN3Z9zO+apzzwTBac3yp95y7XNvhRxM6x8A/EPdC2HZAT+mXxgRc/ELfy6ng0Cur9rLDQwyANWuUeYPhGxTh48GrNxm8SKBl6DFzBk1ou3YCtCsq3PampupUwiZNFiWthQCnJHtWfLVq9fps+7SazmoYINv7f2CfaIPuRDKGdZvhqzjX9U141hX79/KB/zkRuWfwJ9POTn1HOrf3tat53OdWK1mcNPSZik2g4nCeuhGAaBJag8bngZCVyp7g7P0bfsrPwu3GldRJKYQGm6sqOTT7zfserau7nRmArtUNte1BOahzSOL4G4JYKLpDzlBxED+JaW2fGiUtIITxoenmMWGHvQQuv+Hxq9HjYRbnZfQIVLIom9a1vsIGsZA6zYMf2weumhGUm+sp9RNtcMiAEI9XylQnjlwoEntagJIccKkMGxHWbifLj3RkdXu/VEcoWEV/UAZpeI4bdQsmB1msve56c753xUH5ttORB1XSkxNZEaOayQl3dxsOzUxm334BE0lstwiEL/XRczvW7nsrwbA9CCQvG93SPQS4MzJlCXsynsNVaD5qfA3+gqXawF5JR3vWQXWJgMDOq8Z+An2+ksHCB+ZjEA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(30864003)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(54906003)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?c75RgZgBOBdKSvgteJQWB476Kyui?= =?utf-8?q?IEEduTPWEjDzdLuPahsXsIaib0ZPoSq98JAGNECAz7dITjpuY4sWI6yc2yu8IyNOH?= =?utf-8?q?Opb3tiQf/glthxjMBTeayy615kOkpqPH+9VaekXF1+jQjEbKFZf7uzDbUJF/aIBit?= =?utf-8?q?+251y8Njl49BLAS08jl/lakcXmLl3D4FainJ6S7k0rJF30+LwPD2Jvdfgp7wNRBcu?= =?utf-8?q?san/wWJu3qr0THyBfE5P9cJejuUf0kyWVSTntcdDQTRhanZ96pCvRLDGoEHpVmav2?= =?utf-8?q?q/WaMoprHw6Vwu9a5B4LYBwEbTvMQXgzq3BuGdQ3MX9Y2XzQLNPW6wpvZupm/MIwy?= =?utf-8?q?6zafaqMXIsYGK3pIsB0I5VXbmNF/6m0hWPfuxf/FpSbAskLnfxFnxwGZQPK3lsE1m?= =?utf-8?q?dtDj4m7DaVXbcj+GnkARTpzkD9yZ66CaGKyfMwRjE1aPu4X7bQfkU1L4G2giIwiJb?= =?utf-8?q?L6ZjOE1/U2I3WBUKnrPtlDSak2VdcC/jB1tdwcv3bQeRcrs1xFuhmaCllohW+Jl2d?= =?utf-8?q?Sh9G09F6VH1eodXKlggxrEnhhDPrBlw8t9k1K+3TnvUSnzbYbnRQ9bPb4O0RkctOG?= =?utf-8?q?JHDLpEBcLjBe8Vh+3aTVVamSD/f9hu3XEpvjjNX9bnkdnULVxR21tZdOGNrl+YRkG?= =?utf-8?q?wGKk26MDwoj+RwP2+pPibuO9ZPYROyKu+1l/ybaOLCtMKQS8Wt1GQXPtIS++/PsG4?= =?utf-8?q?3xGsc2SOSq7J1uRJvH2ypUpanusvyfT3yaOian64IBS104DEbWQXt8Rsqk5wE5Eyc?= =?utf-8?q?ufcPG/7vveZbXmCrGiY0M7/OcxtvIx0v+wpGY0ovYwJlGXzU8rII+RNOnHj5u+3b8?= =?utf-8?q?eaDgix7enXxQoYrH+Bb/8UvX1spDa4EIhusF+QBglATOV3BK74mC/yUkMEcNstWuK?= =?utf-8?q?FQY/Wqr/i63uq3RQ+//sHhLMuPArtmv9eDyDgJRbrVj2nU8eqv3l6grrSQlzvXQxV?= =?utf-8?q?zbrp+qXISDC2NXKWVsMCdcHCVdDX5+7wUdAWyIOWggFURt8OImk+2mK93sqRMhv8g?= =?utf-8?q?m710pZAyFbU7uh5qVSJ5QouuiywCaFAQQme/pC+K0/+dbOG3cA7VjcrBbPycl48Yu?= =?utf-8?q?595FBYINEcKBiBHgeCCMrD0P+T64tqhKNhl89pg6vkaiW7Ke1FdFUDDWx7/C883hi?= =?utf-8?q?Wsji0Mw0yHNnXE5U+J6RIJvNPlj+Tt1Br+Fbx0+Pzm3p/z068GCkQ3kDCbcafiaK2?= =?utf-8?q?/sM8V9nCigXtJ64wYMgFzGMEyrqo9PXfD0BuNpN/v27ddag/DKNoUO+GhFIjHTFRC?= =?utf-8?q?RG+DouIoDVHwRfj3nJOKdvqMVpFLF9wxG729+mx3Kn44nNqtSbjqI2D/oM9sdug0s?= =?utf-8?q?MuKMmJAewzQc3JwlC9phG8t0Yw40rO2XUu5vRoPIJSCqBgvdgyRwudQYOT/dKEZDj?= =?utf-8?q?QhlR95TKgPk0dapIqL26X5dQPZ2ME7k4Imq1kQpdRfl4waBp9wS9qxBTsPdRAOlZf?= =?utf-8?q?p35+TvS5udRiUH/mxnEKRKRMrtOrLPnKWEIOAWwfgFMcRADoHNtpE9VPcRTp7gw7A?= =?utf-8?q?LCzSpPN1Y0FI?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21c601f7-3a14-4b60-2e14-08dbfd645584 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:37.7767 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GBEsn28xk1R7A//DwG7rBEh4nIvSlz/s/7rvXifv5/P2ITFKnoC/oARKgIk0ZrooRz/KeKK7dUT0AiSLsTIuJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Oleksii Moisieiev Add basic implementation of the SCMI v3.2 pincontrol protocol. Signed-off-by: Oleksii Moisieiev Co-developed-by: Peng Fan Signed-off-by: Peng Fan --- MAINTAINERS | 6 + drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/driver.c | 2 + drivers/firmware/arm_scmi/pinctrl.c | 927 ++++++++++++++++++++++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 1 + include/linux/scmi_protocol.h | 46 ++ 6 files changed, 983 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b589218605b4..8d971adeee22 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21180,6 +21180,12 @@ F: include/linux/sc[mp]i_protocol.h F: include/trace/events/scmi.h F: include/uapi/linux/virtio_scmi.h +SYSTEM CONTROL MANAGEMENT INTERFACE (SCMI) PINCTRL DRIVER +M: Oleksii Moisieiev +L: linux-arm-kernel@lists.infradead.org +S: Maintained +F: drivers/firmware/arm_scmi/pinctrl.c + SYSTEM RESET/SHUTDOWN DRIVERS M: Sebastian Reichel L: linux-pm@vger.kernel.org diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index a7bc4796519c..8e3874ff1544 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -11,6 +11,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_HAVE_MSG) += msg.o scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o +scmi-protocols-y += pinctrl.o scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y) obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 3174da57d832..1cf9f5d4f7bd 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -3057,6 +3057,7 @@ static int __init scmi_driver_init(void) scmi_voltage_register(); scmi_system_register(); scmi_powercap_register(); + scmi_pinctrl_register(); return platform_driver_register(&scmi_driver); } @@ -3074,6 +3075,7 @@ static void __exit scmi_driver_exit(void) scmi_voltage_unregister(); scmi_system_unregister(); scmi_powercap_unregister(); + scmi_pinctrl_unregister(); scmi_transports_exit(); diff --git a/drivers/firmware/arm_scmi/pinctrl.c b/drivers/firmware/arm_scmi/pinctrl.c new file mode 100644 index 000000000000..a25c8edcedd2 --- /dev/null +++ b/drivers/firmware/arm_scmi/pinctrl.c @@ -0,0 +1,927 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Management Interface (SCMI) Pinctrl Protocol + * + * Copyright (C) 2023 EPAM + */ + +#include +#include +#include +#include + +#include "common.h" +#include "protocols.h" + +/* Updated only after ALL the mandatory features for that version are merged */ +#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x40000 + +#define REG_TYPE_BITS GENMASK(9, 8) +#define REG_CONFIG GENMASK(7, 0) + +#define GET_GROUPS_NR(x) le32_get_bits((x), GENMASK(31, 16)) +#define GET_PINS_NR(x) le32_get_bits((x), GENMASK(15, 0)) +#define GET_FUNCTIONS_NR(x) le32_get_bits((x), GENMASK(15, 0)) + +#define EXT_NAME_FLAG(x) le32_get_bits((x), BIT(31)) +#define NUM_ELEMS(x) le32_get_bits((x), GENMASK(15, 0)) + +#define REMAINING(x) le32_get_bits((x), GENMASK(31, 16)) +#define RETURNED(x) le32_get_bits((x), GENMASK(11, 0)) + +enum scmi_pinctrl_protocol_cmd { + PINCTRL_ATTRIBUTES = 0x3, + PINCTRL_LIST_ASSOCIATIONS = 0x4, + PINCTRL_CONFIG_GET = 0x5, + PINCTRL_CONFIG_SET = 0x6, + PINCTRL_FUNCTION_SELECT = 0x7, + PINCTRL_REQUEST = 0x8, + PINCTRL_RELEASE = 0x9, + PINCTRL_NAME_GET = 0xa, + PINCTRL_SET_PERMISSIONS = 0xb +}; + +struct scmi_msg_conf_set { + __le32 identifier; + __le32 attributes; + __le32 configs[]; +}; + +struct scmi_msg_conf_get { + __le32 identifier; + __le32 attributes; +}; + +struct scmi_resp_conf_get { + __le32 num_configs; + __le32 configs[]; +}; + +struct scmi_msg_pinctrl_protocol_attributes { + __le32 attributes_low; + __le32 attributes_high; +}; + +struct scmi_msg_pinctrl_attributes { + __le32 identifier; + __le32 flags; +}; + +struct scmi_resp_pinctrl_attributes { + __le32 attributes; + u8 name[SCMI_SHORT_NAME_MAX_SIZE]; +}; + +struct scmi_msg_pinctrl_list_assoc { + __le32 identifier; + __le32 flags; + __le32 index; +}; + +struct scmi_resp_pinctrl_list_assoc { + __le32 flags; + __le16 array[]; +}; + +struct scmi_msg_func_set { + __le32 identifier; + __le32 function_id; + __le32 flags; +}; + +struct scmi_msg_request { + __le32 identifier; + __le32 flags; +}; + +struct scmi_group_info { + char name[SCMI_MAX_STR_SIZE]; + bool present; + unsigned int *group_pins; + unsigned int nr_pins; +}; + +struct scmi_function_info { + char name[SCMI_MAX_STR_SIZE]; + bool present; + unsigned int *groups; + unsigned int nr_groups; +}; + +struct scmi_pin_info { + char name[SCMI_MAX_STR_SIZE]; + bool present; +}; + +struct scmi_pinctrl_info { + u32 version; + int nr_groups; + int nr_functions; + int nr_pins; + struct scmi_group_info *groups; + struct scmi_function_info *functions; + struct scmi_pin_info *pins; +}; + +static int scmi_pinctrl_attributes_get(const struct scmi_protocol_handle *ph, + struct scmi_pinctrl_info *pi) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_pinctrl_protocol_attributes *attr; + + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr), &t); + if (ret) + return ret; + + attr = t->rx.buf; + + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + pi->nr_functions = GET_FUNCTIONS_NR(attr->attributes_high); + pi->nr_groups = GET_GROUPS_NR(attr->attributes_low); + pi->nr_pins = GET_PINS_NR(attr->attributes_low); + } + + ph->xops->xfer_put(ph, t); + return ret; +} + +static int scmi_pinctrl_count_get(const struct scmi_protocol_handle *ph, + enum scmi_pinctrl_selector_type type) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + switch (type) { + case PIN_TYPE: + return pi->nr_pins; + case GROUP_TYPE: + return pi->nr_groups; + case FUNCTION_TYPE: + return pi->nr_functions; + default: + return -EINVAL; + } +} + +static int scmi_pinctrl_validate_id(const struct scmi_protocol_handle *ph, + u32 identifier, + enum scmi_pinctrl_selector_type type) +{ + int value; + + value = scmi_pinctrl_count_get(ph, type); + if (value < 0) + return value; + + if (identifier >= value) + return -EINVAL; + + return 0; +} + +static int scmi_pinctrl_attributes(const struct scmi_protocol_handle *ph, + enum scmi_pinctrl_selector_type type, + u32 selector, char *name, + unsigned int *n_elems) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_pinctrl_attributes *tx; + struct scmi_resp_pinctrl_attributes *rx; + + if (!name) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, selector, type); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_ATTRIBUTES, sizeof(*tx), sizeof(*rx), &t); + if (ret) + return ret; + + tx = t->tx.buf; + rx = t->rx.buf; + tx->identifier = cpu_to_le32(selector); + tx->flags = cpu_to_le32(type); + + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + if (n_elems) + *n_elems = NUM_ELEMS(rx->attributes); + + strscpy(name, rx->name, SCMI_SHORT_NAME_MAX_SIZE); + } + + ph->xops->xfer_put(ph, t); + + /* + * If supported overwrite short name with the extended one; + * on error just carry on and use already provided short name. + */ + if (!ret && EXT_NAME_FLAG(rx->attributes)) + ph->hops->extended_name_get(ph, PINCTRL_NAME_GET, selector, + (u32 *)&type, name, + SCMI_MAX_STR_SIZE); + return ret; +} + +struct scmi_pinctrl_ipriv { + u32 selector; + enum scmi_pinctrl_selector_type type; + unsigned int *array; +}; + +static void iter_pinctrl_assoc_prepare_message(void *message, + unsigned int desc_index, + const void *priv) +{ + struct scmi_msg_pinctrl_list_assoc *msg = message; + const struct scmi_pinctrl_ipriv *p = priv; + + msg->identifier = cpu_to_le32(p->selector); + msg->flags = cpu_to_le32(p->type); + /* Set the number of OPPs to be skipped/already read */ + msg->index = cpu_to_le32(desc_index); +} + +static int iter_pinctrl_assoc_update_state(struct scmi_iterator_state *st, + const void *response, void *priv) +{ + const struct scmi_resp_pinctrl_list_assoc *r = response; + + st->num_returned = RETURNED(r->flags); + st->num_remaining = REMAINING(r->flags); + + return 0; +} + +static int +iter_pinctrl_assoc_process_response(const struct scmi_protocol_handle *ph, + const void *response, + struct scmi_iterator_state *st, void *priv) +{ + const struct scmi_resp_pinctrl_list_assoc *r = response; + struct scmi_pinctrl_ipriv *p = priv; + + p->array[st->desc_index + st->loop_idx] = + le16_to_cpu(r->array[st->loop_idx]); + + return 0; +} + +static int scmi_pinctrl_list_associations(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + u16 size, unsigned int *array) +{ + int ret; + void *iter; + struct scmi_iterator_ops ops = { + .prepare_message = iter_pinctrl_assoc_prepare_message, + .update_state = iter_pinctrl_assoc_update_state, + .process_response = iter_pinctrl_assoc_process_response, + }; + struct scmi_pinctrl_ipriv ipriv = { + .selector = selector, + .type = type, + .array = array, + }; + + if (!array || !size || type == PIN_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, selector, type); + if (ret) + return ret; + + iter = ph->hops->iter_response_init(ph, &ops, size, + PINCTRL_LIST_ASSOCIATIONS, + sizeof(struct scmi_msg_pinctrl_list_assoc), + &ipriv); + + if (IS_ERR(iter)) + return PTR_ERR(iter); + + return ph->hops->iter_response_run(iter); +} + +struct scmi_conf_get_ipriv { + u32 selector; + enum scmi_pinctrl_selector_type type; + u8 all; + u8 *config_types; + unsigned long *config_values; +}; + +static void iter_pinctrl_conf_get_prepare_message(void *message, + unsigned int desc_index, + const void *priv) +{ + struct scmi_msg_conf_get *msg = message; + const struct scmi_conf_get_ipriv *p = priv; + u32 attributes; + + msg->identifier = cpu_to_le32(p->selector); + attributes = FIELD_PREP(BIT(18), p->all) | + FIELD_PREP(GENMASK(17, 16), p->type); + + if (p->all) + attributes |= FIELD_PREP(GENMASK(15, 8), desc_index); + else + attributes |= FIELD_PREP(GENMASK(7, 0), p->config_types[0]); + + msg->attributes = cpu_to_le32(attributes); + msg->identifier = cpu_to_le32(p->selector); +} + +static int iter_pinctrl_conf_get_update_state(struct scmi_iterator_state *st, + const void *response, void *priv) +{ + const struct scmi_resp_conf_get *r = response; + + st->num_returned = le32_get_bits(r->num_configs, GENMASK(7, 0)); + st->num_remaining = le32_get_bits(r->num_configs, GENMASK(31, 24)); + + return 0; +} + +static int iter_pinctrl_conf_get_process_response(const struct scmi_protocol_handle *ph, + const void *response, + struct scmi_iterator_state *st, void *priv) +{ + const struct scmi_resp_conf_get *r = response; + struct scmi_conf_get_ipriv *p = priv; + + if (!p->all) { + if (p->config_types[0] != + le32_get_bits(r->configs[st->loop_idx * 2], GENMASK(7, 0))) + return -EINVAL; + } else { + p->config_types[st->desc_index + st->loop_idx] = + le32_get_bits(r->configs[st->loop_idx * 2], GENMASK(7, 0)); + } + + p->config_values[st->desc_index + st->loop_idx] = + le32_to_cpu(r->configs[st->loop_idx * 2 + 1]); + + return 0; +} + +static int scmi_pinctrl_config_get(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + u8 config_type, unsigned long *config_value) +{ + int ret; + void *iter; + struct scmi_iterator_ops ops = { + .prepare_message = iter_pinctrl_conf_get_prepare_message, + .update_state = iter_pinctrl_conf_get_update_state, + .process_response = iter_pinctrl_conf_get_process_response, + }; + struct scmi_conf_get_ipriv ipriv = { + .selector = selector, + .type = type, + .all = 0, + .config_types = &config_type, + .config_values = config_value, + }; + + if (!config_value || type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, selector, type); + if (ret) + return ret; + + iter = ph->hops->iter_response_init(ph, &ops, 1, PINCTRL_CONFIG_GET, + sizeof(struct scmi_msg_conf_get), + &ipriv); + + if (IS_ERR(iter)) + return PTR_ERR(iter); + + return ph->hops->iter_response_run(iter); +} + +static int scmi_pinctrl_config_get_all(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + u16 size, u8 *config_types, + unsigned long *config_values) +{ + int ret; + void *iter; + struct scmi_iterator_ops ops = { + .prepare_message = iter_pinctrl_conf_get_prepare_message, + .update_state = iter_pinctrl_conf_get_update_state, + .process_response = iter_pinctrl_conf_get_process_response, + }; + struct scmi_conf_get_ipriv ipriv = { + .selector = selector, + .type = type, + .all = 1, + .config_types = config_types, + .config_values = config_values, + }; + + if (!config_values || !config_types || type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, selector, type); + if (ret) + return ret; + + iter = ph->hops->iter_response_init(ph, &ops, size, PINCTRL_CONFIG_GET, + sizeof(struct scmi_msg_conf_get), + &ipriv); + + if (IS_ERR(iter)) + return PTR_ERR(iter); + + return ph->hops->iter_response_run(iter); +} + +static int scmi_pinctrl_config_set(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + unsigned long *configs, unsigned int nr_configs) +{ + struct scmi_xfer *t; + struct scmi_msg_conf_set *tx; + u32 attributes; + int ret, i; + unsigned int configs_in_chunk, conf_num = 0; + unsigned int chunk; + int max_msg_size = ph->hops->get_max_msg_size(ph); + + if (!configs || type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, selector, type); + if (ret) + return ret; + + configs_in_chunk = (max_msg_size - sizeof(*tx)) / (sizeof(unsigned long) * 2); + while (conf_num < nr_configs) { + chunk = (nr_configs - conf_num > configs_in_chunk) ? configs_in_chunk : + nr_configs - conf_num; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_CONFIG_SET, + sizeof(*tx) + chunk * 2 * sizeof(unsigned long), + 0, &t); + if (ret) + return ret; + + tx = t->tx.buf; + tx->identifier = cpu_to_le32(selector); + attributes = FIELD_PREP(GENMASK(1, 0), type) | + FIELD_PREP(GENMASK(9, 2), chunk); + tx->attributes = cpu_to_le32(attributes); + + for (i = 0; i < chunk; i++) { + tx->configs[i * 2] = cpu_to_le32(pinconf_to_config_param(configs[i])); + tx->configs[i * 2 + 1] = + cpu_to_le32(pinconf_to_config_argument(configs[i])); + } + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + if (ret) + break; + + conf_num += chunk; + } + + return ret; +} + +static int scmi_pinctrl_function_select(const struct scmi_protocol_handle *ph, + u32 identifier, + enum scmi_pinctrl_selector_type type, + u32 function_id) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_func_set *tx; + + if (type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, identifier, type); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_FUNCTION_SELECT, sizeof(*tx), 0, &t); + if (ret) + return ret; + + tx = t->tx.buf; + tx->identifier = cpu_to_le32(identifier); + tx->function_id = cpu_to_le32(function_id); + tx->flags = cpu_to_le32(type); + + ret = ph->xops->do_xfer(ph, t); + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_pinctrl_request(const struct scmi_protocol_handle *ph, + u32 identifier, + enum scmi_pinctrl_selector_type type) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_request *tx; + + if (type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, identifier, type); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_REQUEST, sizeof(*tx), 0, &t); + + tx = t->tx.buf; + tx->identifier = cpu_to_le32(identifier); + tx->flags = cpu_to_le32(type); + + ret = ph->xops->do_xfer(ph, t); + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_pinctrl_pin_request(const struct scmi_protocol_handle *ph, + u32 pin) +{ + return scmi_pinctrl_request(ph, pin, PIN_TYPE); +} + +static int scmi_pinctrl_free(const struct scmi_protocol_handle *ph, + u32 identifier, + enum scmi_pinctrl_selector_type type) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_request *tx; + + if (type == FUNCTION_TYPE) + return -EINVAL; + + ret = scmi_pinctrl_validate_id(ph, identifier, type); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_RELEASE, sizeof(*tx), 0, &t); + + tx = t->tx.buf; + tx->identifier = cpu_to_le32(identifier); + tx->flags = cpu_to_le32(type); + + ret = ph->xops->do_xfer(ph, t); + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_pinctrl_pin_free(const struct scmi_protocol_handle *ph, u32 pin) +{ + return scmi_pinctrl_free(ph, pin, PIN_TYPE); +} + +static int scmi_pinctrl_get_group_info(const struct scmi_protocol_handle *ph, + u32 selector, + struct scmi_group_info *group) +{ + int ret; + + if (!group) + return -EINVAL; + + ret = scmi_pinctrl_attributes(ph, GROUP_TYPE, selector, + group->name, + &group->nr_pins); + if (ret) + return ret; + + if (!group->nr_pins) { + dev_err(ph->dev, "Group %d has 0 elements", selector); + return -ENODATA; + } + + group->group_pins = kmalloc_array(group->nr_pins, sizeof(*group->group_pins), GFP_KERNEL); + if (!group->group_pins) + return -ENOMEM; + + ret = scmi_pinctrl_list_associations(ph, selector, GROUP_TYPE, + group->nr_pins, group->group_pins); + if (ret) { + kfree(group->group_pins); + return ret; + } + + group->present = true; + return 0; +} + +static int scmi_pinctrl_get_group_name(const struct scmi_protocol_handle *ph, + u32 selector, const char **name) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + if (!name) + return -EINVAL; + + if (selector >= pi->nr_groups) + return -EINVAL; + + if (!pi->groups[selector].present) { + int ret; + + ret = scmi_pinctrl_get_group_info(ph, selector, + &pi->groups[selector]); + if (ret) + return ret; + } + + *name = pi->groups[selector].name; + + return 0; +} + +static int scmi_pinctrl_group_pins_get(const struct scmi_protocol_handle *ph, + u32 selector, const unsigned int **pins, + unsigned int *nr_pins) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + if (!pins || !nr_pins) + return -EINVAL; + + if (selector >= pi->nr_groups) + return -EINVAL; + + if (!pi->groups[selector].present) { + int ret; + + ret = scmi_pinctrl_get_group_info(ph, selector, + &pi->groups[selector]); + if (ret) + return ret; + } + + *pins = pi->groups[selector].group_pins; + *nr_pins = pi->groups[selector].nr_pins; + + return 0; +} + +static int scmi_pinctrl_get_function_info(const struct scmi_protocol_handle *ph, + u32 selector, + struct scmi_function_info *func) +{ + int ret; + + if (!func) + return -EINVAL; + + ret = scmi_pinctrl_attributes(ph, FUNCTION_TYPE, selector, + func->name, + &func->nr_groups); + if (ret) + return ret; + + if (!func->nr_groups) { + dev_err(ph->dev, "Function %d has 0 elements", selector); + return -ENODATA; + } + + func->groups = kmalloc_array(func->nr_groups, sizeof(*func->groups), GFP_KERNEL); + if (!func->groups) + return -ENOMEM; + + ret = scmi_pinctrl_list_associations(ph, selector, FUNCTION_TYPE, + func->nr_groups, func->groups); + if (ret) { + kfree(func->groups); + return ret; + } + + func->present = true; + return 0; +} + +static int scmi_pinctrl_get_function_name(const struct scmi_protocol_handle *ph, + u32 selector, const char **name) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + if (!name) + return -EINVAL; + + if (selector >= pi->nr_functions) + return -EINVAL; + + if (!pi->functions[selector].present) { + int ret; + + ret = scmi_pinctrl_get_function_info(ph, selector, + &pi->functions[selector]); + if (ret) + return ret; + } + + *name = pi->functions[selector].name; + return 0; +} + +static int scmi_pinctrl_function_groups_get(const struct scmi_protocol_handle *ph, + u32 selector, + unsigned int *nr_groups, + const unsigned int **groups) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + if (!groups || !nr_groups) + return -EINVAL; + + if (selector >= pi->nr_functions) + return -EINVAL; + + if (!pi->functions[selector].present) { + int ret; + + ret = scmi_pinctrl_get_function_info(ph, selector, + &pi->functions[selector]); + if (ret) + return ret; + } + + *groups = pi->functions[selector].groups; + *nr_groups = pi->functions[selector].nr_groups; + + return 0; +} + +static int scmi_pinctrl_mux_set(const struct scmi_protocol_handle *ph, + u32 selector, u32 group) +{ + return scmi_pinctrl_function_select(ph, group, GROUP_TYPE, + selector); +} + +static int scmi_pinctrl_get_pin_info(const struct scmi_protocol_handle *ph, + u32 selector, struct scmi_pin_info *pin) +{ + int ret; + + if (!pin) + return -EINVAL; + + ret = scmi_pinctrl_attributes(ph, PIN_TYPE, selector, + pin->name, NULL); + if (ret) + return ret; + + pin->present = true; + return 0; +} + +static int scmi_pinctrl_get_pin_name(const struct scmi_protocol_handle *ph, + u32 selector, const char **name) +{ + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + if (!name) + return -EINVAL; + + if (selector >= pi->nr_pins) + return -EINVAL; + + if (!pi->pins[selector].present) { + int ret; + + ret = scmi_pinctrl_get_pin_info(ph, selector, + &pi->pins[selector]); + if (ret) + return ret; + } + + *name = pi->pins[selector].name; + + return 0; +} + +static int scmi_pinctrl_name_get(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + const char **name) +{ + switch (type) { + case PIN_TYPE: + return scmi_pinctrl_get_pin_name(ph, selector, name); + case GROUP_TYPE: + return scmi_pinctrl_get_group_name(ph, selector, name); + case FUNCTION_TYPE: + return scmi_pinctrl_get_function_name(ph, selector, name); + default: + return -EINVAL; + } +} + +static const struct scmi_pinctrl_proto_ops pinctrl_proto_ops = { + .count_get = scmi_pinctrl_count_get, + .name_get = scmi_pinctrl_name_get, + .group_pins_get = scmi_pinctrl_group_pins_get, + .function_groups_get = scmi_pinctrl_function_groups_get, + .mux_set = scmi_pinctrl_mux_set, + .config_get = scmi_pinctrl_config_get, + .config_get_all = scmi_pinctrl_config_get_all, + .config_set = scmi_pinctrl_config_set, + .pin_request = scmi_pinctrl_pin_request, + .pin_free = scmi_pinctrl_pin_free, +}; + +static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph) +{ + int ret; + u32 version; + struct scmi_pinctrl_info *pinfo; + + ret = ph->xops->version_get(ph, &version); + if (ret) + return ret; + + dev_dbg(ph->dev, "Pinctrl Version %d.%d\n", + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); + + pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL); + if (!pinfo) + return -ENOMEM; + + ret = scmi_pinctrl_attributes_get(ph, pinfo); + if (ret) + return ret; + + pinfo->pins = devm_kcalloc(ph->dev, pinfo->nr_pins, + sizeof(*pinfo->pins), + GFP_KERNEL); + if (!pinfo->pins) + return -ENOMEM; + + pinfo->groups = devm_kcalloc(ph->dev, pinfo->nr_groups, + sizeof(*pinfo->groups), + GFP_KERNEL); + if (!pinfo->groups) + return -ENOMEM; + + pinfo->functions = devm_kcalloc(ph->dev, pinfo->nr_functions, + sizeof(*pinfo->functions), + GFP_KERNEL); + if (!pinfo->functions) + return -ENOMEM; + + pinfo->version = version; + + return ph->set_priv(ph, pinfo, version); +} + +static int scmi_pinctrl_protocol_deinit(const struct scmi_protocol_handle *ph) +{ + int i; + struct scmi_pinctrl_info *pi = ph->get_priv(ph); + + for (i = 0; i < pi->nr_groups; i++) { + if (pi->groups[i].present) { + kfree(pi->groups[i].group_pins); + pi->groups[i].present = false; + } + } + + for (i = 0; i < pi->nr_functions; i++) { + if (pi->functions[i].present) { + kfree(pi->functions[i].groups); + pi->functions[i].present = false; + } + } + + return 0; +} + +static const struct scmi_protocol scmi_pinctrl = { + .id = SCMI_PROTOCOL_PINCTRL, + .owner = THIS_MODULE, + .instance_init = &scmi_pinctrl_protocol_init, + .instance_deinit = &scmi_pinctrl_protocol_deinit, + .ops = &pinctrl_proto_ops, + .supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION, +}; + +DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(pinctrl, scmi_pinctrl) diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index 08de8dc064c1..e30f91ce53c8 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -347,6 +347,7 @@ void __exit scmi_##name##_unregister(void) \ DECLARE_SCMI_REGISTER_UNREGISTER(base); DECLARE_SCMI_REGISTER_UNREGISTER(clock); DECLARE_SCMI_REGISTER_UNREGISTER(perf); +DECLARE_SCMI_REGISTER_UNREGISTER(pinctrl); DECLARE_SCMI_REGISTER_UNREGISTER(power); DECLARE_SCMI_REGISTER_UNREGISTER(reset); DECLARE_SCMI_REGISTER_UNREGISTER(sensors); diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 19a06b872afe..516c98252732 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -717,6 +717,51 @@ struct scmi_powercap_proto_ops { u32 *power_thresh_high); }; +enum scmi_pinctrl_selector_type { + PIN_TYPE = 0, + GROUP_TYPE, + FUNCTION_TYPE, +}; + +/** + * struct scmi_pinctrl_proto_ops - represents the various operations provided + * by SCMI Pinctrl Protocol + * + * @count_get: returns count of the registered elements in given type + * @name_get: returns name by index of given type + * @group_pins_get: returns the set of pins, assigned to the specified group + * @function_groups_get: returns the set of groups, assigned to the specified + * function + * @mux_set: set muxing function for groups of pins + * @config_get: returns configuration parameter for pin or group + * @config_set: sets the configuration parameter for pin or group + * @pin_request: aquire pin before selecting mux setting + * @pin_free: frees pin, acquired by request_pin call + */ +struct scmi_pinctrl_proto_ops { + int (*count_get)(const struct scmi_protocol_handle *ph, + enum scmi_pinctrl_selector_type type); + int (*name_get)(const struct scmi_protocol_handle *ph, u32 selector, + enum scmi_pinctrl_selector_type type, const char **name); + int (*group_pins_get)(const struct scmi_protocol_handle *ph, u32 selector, + const unsigned int **pins, unsigned int *nr_pins); + int (*function_groups_get)(const struct scmi_protocol_handle *ph, u32 selector, + unsigned int *nr_groups, const unsigned int **groups); + int (*mux_set)(const struct scmi_protocol_handle *ph, u32 selector, u32 group); + int (*config_get)(const struct scmi_protocol_handle *ph, u32 selector, + enum scmi_pinctrl_selector_type type, + u8 config_type, unsigned long *config_value); + int (*config_get_all)(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, u16 size, + u8 *config_types, unsigned long *config_values); + int (*config_set)(const struct scmi_protocol_handle *ph, u32 selector, + enum scmi_pinctrl_selector_type type, + unsigned long *configs, unsigned int nr_configs); + int (*pin_request)(const struct scmi_protocol_handle *ph, u32 pin); + int (*pin_free)(const struct scmi_protocol_handle *ph, u32 pin); +}; + /** * struct scmi_notify_ops - represents notifications' operations provided by * SCMI core @@ -824,6 +869,7 @@ enum scmi_std_protocol { SCMI_PROTOCOL_RESET = 0x16, SCMI_PROTOCOL_VOLTAGE = 0x17, SCMI_PROTOCOL_POWERCAP = 0x18, + SCMI_PROTOCOL_PINCTRL = 0x19, }; enum scmi_system_events { From patchwork Fri Dec 15 11:56:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 754500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2089.outbound.protection.outlook.com [40.107.104.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B54B288DD; Fri, 15 Dec 2023 11:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="HN1R+7jO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O+f7/92zLz2Gy1qtWS2VOshMzNEDdRTnF/Y29FNwl3m6hjCX+U4+eBsCBZovgHBPtHGHiJOjaUHDOsRX3UbVWS6nKJswd0FtyknJIE3BKwSjUcSOo3uMTk0DaZGCxc1UqoWdBONWHR/iIgiyR+PVHJKYbsxRg1C3yc53OJfn6ENCIj0TFFK2chQaFbOuOivUlNuYS4tRNazQgOJ02hUDlFN2zRtbRSNte4y2be93XClQ++kbx9iFW/kevBSsUTi5YtqiRc9jjPRrTqzEt+yfrvGa1cSiAakQqRur5x4ZpTWuD3xFrEt57tWTXXtqwUMZShec+C7AuB7Pus6FLlUDhA== 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=w400vpSvNS+U5c73CplisVthuWRbvuufr2i2TaLWMM4=; b=iVnOcghg2Ofs+kgoQ8do0e5CUBa0E86IDG7PN6XZgA5uivJC03rRnRRz0ZyBv2WBkdtZZToLiG43D8HF9szRqkheCfdv/M0lkS7QWnvflFI+g8OEfvh57sXZj6LpfiQFFIL5n9fTGf6YhUq2+2EGYlqzkqpO87TNzQsG2jy1EJeaj7UZ00gmkhlIrXKy8CUy4eP/M+lEajMn/B7XbIjj/4z3P23VQHePH9GBFzkUtpNosFUqEkF0wbYQwGg/R2cTEXS4l9uqdsqpUSaVnsq7+aUcGzeHq1bBn8EjdpLijmZZQOLEsndl5nitv1sSj+ZmlFfVcaFWm/6vVI4Uf/eeug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w400vpSvNS+U5c73CplisVthuWRbvuufr2i2TaLWMM4=; b=HN1R+7jOU699yK16aZtFoMhep7as0JKFNw8cmSKU8SdsJSooaFd3LmxDM+pCuvWVCsNTjziDipXeoK9uCNlHuIScsU31CMJ4dNu5LJJI7s6g3G31p2j2VADbVgwtP5qT8lneSmGQAJX6q6GkHPDlk6Q7ZzgqFFmB7JroBrH2uFA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:43 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:42 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:34 +0800 Subject: [PATCH 6/7] pinctrl: Implementation of the generic scmi-pinctrl driver Message-Id: <20231215-pinctrl-scmi-v1-6-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=13845; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=bB/Yc1qeeyh55WgW/F1hUmthHXez0iet66z/QkZPgMw=; b=AMFE/XVx7opjmgpXLSvhu8DniyfTgtC5T+aeS/uT75MYK7zKyg1/aHc38+6A32ohm/OcHU1fB B5rMNWel198CnYFVPf/FEsy45GgAWdmtk0OCCd6PQIWpBWbE3ulsAY8 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: 34ffab1e-624e-49c8-fa4f-08dbfd645896 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TXzZAd8X2wKbJPYYUoSdL/TkUxxn5BCB5tlQzHUtjqv1Fwd64WDpmiS28JBD9igsa8kNO2Jd1YLrq9IqgBCl406m6F8Q7cX6SlMJDugV8iHwdE0coKmiKU7fzofY+pIeaCthTH0NSvlKAUZ77IAMh3BU0JBzI0kNlhMPp4HXDfcTMAWrieK6gNWzYfzPS9Uw4BERb7FTRTkMVMepe0aCOQYrZukhXcnbfzLoO1ihsH37lftm/eqjXdXJr6RbhFAeoDFwbW4TXKP2u2e8rmZkmMZECoO59+LYmN4yCFwooRu0TgtmMBzq6VzqzjdpWeDqrLMIFNNLiO/glNvqjkDeSLluyIRc9LhCkgl28L9vl6rL7Gco3SlMJ3NNr1Vt8azHGJ3RM3opJjL6rsmOmrmKEHdb+EnrTl0DnzlJ03aHd5uNi2FmYhDPJfCCCcQZEL71+s1SPFy7RiMCytR80fEvdznuIoGBbL/xyEqX5DxCtNMmRf/2K0ScB6JrCO1QsJJDZXQhRhYn0u9al9BRCGEhF0ShjhgFmrExedGLE3S7Q/Tpia6XDRw/HGRKqcFGw1Z8LupxmbYo2J+gIAOjUVlzA8tFPhq6QMGltbyzP8aTqZrpmAiCGhgmdIuvIaqY4tgkVtkShz5MZ0oUP7EDgQ3MsxY70dcNrLUWU/QTfCCsl34= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(30864003)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7BbmbPXdboTiRbh1KryKRzcSHq6m?= =?utf-8?q?1CwDvE4u8+JGaJb2HMEt5RErGOu1PUqJJj0FGUBqA/qnZGd7NpOANmfkm+58GPemr?= =?utf-8?q?GjcFol9Bsj4KWMqs9h7iV+FBBalyNECXFaxy2xmtN++FVmAJpyFsAvwd8Wq48eBbB?= =?utf-8?q?XeDgu7kOVZNEBzk4ptcM6NptbmtMlRPDwRHk2L2ZyXE/ySVSc/AHqf9VoVxdAIfs6?= =?utf-8?q?RMU1Lg6Afn1jyxaGMwDKyBc8is5auEVxcBNmozUJ39o6xBGRDyMjd0jO+XuU1Dzn3?= =?utf-8?q?qApddxS9dIWfd7eMJ0YtMWaSHeWGsO7aqrv8jPrlzHwJCuxk1yRiIOEOEsV3JVu6E?= =?utf-8?q?yHcZ/3NqknYDPoiudhQaOIy/DszVYF2XwsvoRWli7HH8TEBV423h3qglyPlwCJr2K?= =?utf-8?q?FrWL8cP19/Tdt5rKZimxOdoSaKjzQsvYtqrIYJs65S7E9JzoIyCZjUnc/u5Q7Mezq?= =?utf-8?q?O1z6nI1X9TUO3y748q4HOpdBstWyr3796SaTNPXnbYgU6hvL28LPRA+T9NQ2oOVTS?= =?utf-8?q?n33tadhFDVNUzNdlsHbHIbEfLGCjgT7QTb3jAVRt19mybniBoc5lOothnnUiZEWTG?= =?utf-8?q?LD8sOc+asjr2GBTIsTVWRnEH5VMbzEv4ycf90WApdm1JzKL+hcIqHem1ijwiVptTZ?= =?utf-8?q?y6pc4i0ye0O0gQkv4QE/mklogipxPPdkDypKUfU1LezOWRZm7DrUlnOzgTqt7nqEE?= =?utf-8?q?vkyRXAEaSmoz9+Dt9ki8xjc2/Uc9DTkji+C+4pFO45A9BroKvt1tog/LWkvqjr9wT?= =?utf-8?q?Nnkb0PWfZIWnD0JczQCdfZIHffX+zbrVPPsDmwYJdzEHdw/0mg/vOFG00oQCxyepL?= =?utf-8?q?bJeD2wVMNQ/CAVFQe4X4uBa4hpNmhM9UocAJUNq/vmoZokTt3h1TH1Bo6X2nM6JtU?= =?utf-8?q?Q67TD65SmtRAFEwms2KPqEjHwJt7Qh6P4tX+zawuWUK64il5p4914DvlapFSRbOw/?= =?utf-8?q?Es8hUJAT7ByJwcTatyfF8TfzMqAbMk+xQlgfeTaaYAwauPIee1baABr2dKxAn5fsU?= =?utf-8?q?CwOyUDCBCRnsqc4BHA14hjj7yt78bxUtljEtGasF3nHlPb+Hy9rV4IA86spYdKyKw?= =?utf-8?q?e7uXaixl+5tzKJtgaDktDo0mDW9iQbhJgbf5CbZoTqLTx++6gctsHDwwD9vfEbTv+?= =?utf-8?q?q2vIEQn+8aKkBut0z5QRW52P+f0yKeffwasno7Mlui07uwrSeDVOh9NLRhYVmnuWE?= =?utf-8?q?/y5kjAbWZL8Visac7DICjIIIGjGAY4DXmHxujX0KUCqakgT9mE6+LMpVpbqxBl1xK?= =?utf-8?q?9KQFTAZuOUj7r5IkN7nz1Uir69sLreDvOsfA3y0f4vIQL1S4GyWFfDgwEDzHG9rvs?= =?utf-8?q?Qlsas4At7Y5nl83RRg7pSoEsn25lQpULGjOoBIfswJr+esI6E7v6+WcNl+/Hw/7+v?= =?utf-8?q?0oqucfu86KW/dzi3JSs8M7EjD9xBD9HMayQwzePLL2We9Rvxqt/B2+nkB2HrKo0tE?= =?utf-8?q?uV9gUW/yCtBzVDyQ8sY4w8EscnVcFvjQ6EBPTkt8t3CEts0GUIUrIb74awOZDaNaI?= =?utf-8?q?53EWF7EEFQYQ?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34ffab1e-624e-49c8-fa4f-08dbfd645896 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:42.9078 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BhHI0iVMWh6wHdY6zQAw/H+Em9BV83dlxf7Yck2A5o8dirDC37gquPkeYyDFqVkxG93daZVQDbHQ/oISJpzRPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan scmi-pinctrl driver implements pinctrl driver interface and using SCMI protocol to redirect messages from pinctrl subsystem SDK to SCMI platform firmware, which does the changes in HW. Co-developed-by: Oleksii Moisieiev Signed-off-by: Oleksii Moisieiev Signed-off-by: Peng Fan --- MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 11 ++ drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-scmi.c | 403 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 416 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8d971adeee22..0ca47b9c9f55 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21172,6 +21172,7 @@ F: drivers/clk/clk-sc[mp]i.c F: drivers/cpufreq/sc[mp]i-cpufreq.c F: drivers/firmware/arm_scmi/ F: drivers/firmware/arm_scpi.c +F: drivers/pinctrl/pinctrl-scmi.c F: drivers/pmdomain/arm/ F: drivers/powercap/arm_scmi_powercap.c F: drivers/regulator/scmi-regulator.c diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index 8163a5983166..27b26e428f60 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -432,6 +432,17 @@ config PINCTRL_ROCKCHIP help This support pinctrl and GPIO driver for Rockchip SoCs. +config PINCTRL_SCMI + tristate "Pinctrl driver using SCMI protocol interface" + depends on ARM_SCMI_PROTOCOL || COMPILE_TEST + select PINMUX + select GENERIC_PINCONF + help + This driver provides support for pinctrl which is controlled + by firmware that implements the SCMI interface. + It uses SCMI Message Protocol to interact with the + firmware providing all the pinctrl controls. + config PINCTRL_SINGLE tristate "One-register-per-pin type device tree based pinctrl driver" depends on OF diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 1071f301cc70..ba755ed2d46c 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_PINCTRL_PIC32) += pinctrl-pic32.o obj-$(CONFIG_PINCTRL_PISTACHIO) += pinctrl-pistachio.o obj-$(CONFIG_PINCTRL_RK805) += pinctrl-rk805.o obj-$(CONFIG_PINCTRL_ROCKCHIP) += pinctrl-rockchip.o +obj-$(CONFIG_PINCTRL_SCMI) += pinctrl-scmi.o obj-$(CONFIG_PINCTRL_SINGLE) += pinctrl-single.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o obj-$(CONFIG_PINCTRL_STMFX) += pinctrl-stmfx.o diff --git a/drivers/pinctrl/pinctrl-scmi.c b/drivers/pinctrl/pinctrl-scmi.c new file mode 100644 index 000000000000..0710ce9a1b42 --- /dev/null +++ b/drivers/pinctrl/pinctrl-scmi.c @@ -0,0 +1,403 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Power Interface (SCMI) Protocol based pinctrl driver + * + * Copyright (C) 2023 EPAM + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "pinctrl-utils.h" +#include "core.h" +#include "pinconf.h" + +#define DRV_NAME "scmi-pinctrl" + +static const struct scmi_pinctrl_proto_ops *pinctrl_ops; + +struct scmi_pinctrl_funcs { + unsigned int num_groups; + const char **groups; +}; + +struct scmi_pinctrl { + struct device *dev; + struct scmi_protocol_handle *ph; + struct pinctrl_dev *pctldev; + struct pinctrl_desc pctl_desc; + struct scmi_pinctrl_funcs *functions; + unsigned int nr_functions; + char **groups; + unsigned int nr_groups; + struct pinctrl_pin_desc *pins; + unsigned int nr_pins; +}; + +static int pinctrl_scmi_get_groups_count(struct pinctrl_dev *pctldev) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->count_get(pmx->ph, GROUP_TYPE); +} + +static const char *pinctrl_scmi_get_group_name(struct pinctrl_dev *pctldev, unsigned int selector) +{ + int ret; + const char *name; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + ret = pinctrl_ops->name_get(pmx->ph, selector, GROUP_TYPE, &name); + if (ret) { + dev_err(pmx->dev, "get name failed with err %d", ret); + return NULL; + } + + return name; +} + +static int pinctrl_scmi_get_group_pins(struct pinctrl_dev *pctldev, + unsigned int selector, + const unsigned int **pins, + unsigned int *num_pins) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->group_pins_get(pmx->ph, selector, pins, num_pins); +} + +static const struct pinctrl_ops pinctrl_scmi_pinctrl_ops = { + .get_groups_count = pinctrl_scmi_get_groups_count, + .get_group_name = pinctrl_scmi_get_group_name, + .get_group_pins = pinctrl_scmi_get_group_pins, +#ifdef CONFIG_OF + .dt_node_to_map = pinconf_generic_dt_node_to_map_all, + .dt_free_map = pinconf_generic_dt_free_map, +#endif +}; + +static int pinctrl_scmi_get_functions_count(struct pinctrl_dev *pctldev) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->count_get(pmx->ph, FUNCTION_TYPE); +} + +static const char *pinctrl_scmi_get_function_name(struct pinctrl_dev *pctldev, + unsigned int selector) +{ + int ret; + const char *name; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + ret = pinctrl_ops->name_get(pmx->ph, selector, FUNCTION_TYPE, &name); + if (ret) { + dev_err(pmx->dev, "get name failed with err %d", ret); + return NULL; + } + + return name; +} + +static int pinctrl_scmi_get_function_groups(struct pinctrl_dev *pctldev, + unsigned int selector, + const char * const **groups, + unsigned int * const num_groups) +{ + const unsigned int *group_ids; + int ret, i; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + if (!groups || !num_groups) + return -EINVAL; + + if (selector < pmx->nr_functions && + pmx->functions[selector].num_groups) { + *groups = (const char * const *)pmx->functions[selector].groups; + *num_groups = pmx->functions[selector].num_groups; + return 0; + } + + ret = pinctrl_ops->function_groups_get(pmx->ph, selector, + &pmx->functions[selector].num_groups, + &group_ids); + if (ret) { + dev_err(pmx->dev, "Unable to get function groups, err %d", ret); + return ret; + } + + *num_groups = pmx->functions[selector].num_groups; + if (!*num_groups) + return -EINVAL; + + pmx->functions[selector].groups = + devm_kcalloc(pmx->dev, *num_groups, sizeof(*pmx->functions[selector].groups), + GFP_KERNEL); + if (!pmx->functions[selector].groups) + return -ENOMEM; + + for (i = 0; i < *num_groups; i++) { + pmx->functions[selector].groups[i] = + pinctrl_scmi_get_group_name(pmx->pctldev, + group_ids[i]); + if (!pmx->functions[selector].groups[i]) { + ret = -ENOMEM; + goto err_free; + } + } + + *groups = (const char * const *)pmx->functions[selector].groups; + + return 0; + +err_free: + devm_kfree(pmx->dev, pmx->functions[selector].groups); + + return ret; +} + +static int pinctrl_scmi_func_set_mux(struct pinctrl_dev *pctldev, unsigned int selector, + unsigned int group) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->mux_set(pmx->ph, selector, group); +} + +static int pinctrl_scmi_request(struct pinctrl_dev *pctldev, unsigned int offset) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->pin_request(pmx->ph, offset); +} + +static int pinctrl_scmi_free(struct pinctrl_dev *pctldev, unsigned int offset) +{ + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + return pinctrl_ops->pin_free(pmx->ph, offset); +} + +static const struct pinmux_ops pinctrl_scmi_pinmux_ops = { + .request = pinctrl_scmi_request, + .free = pinctrl_scmi_free, + .get_functions_count = pinctrl_scmi_get_functions_count, + .get_function_name = pinctrl_scmi_get_function_name, + .get_function_groups = pinctrl_scmi_get_function_groups, + .set_mux = pinctrl_scmi_func_set_mux, +}; + +static int pinctrl_scmi_pinconf_get(struct pinctrl_dev *pctldev, unsigned int _pin, + unsigned long *config) +{ + int ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + enum pin_config_param config_type; + unsigned long config_value; + + if (!config) + return -EINVAL; + + config_type = pinconf_to_config_param(*config); + + ret = pinctrl_ops->config_get(pmx->ph, _pin, PIN_TYPE, config_type, &config_value); + if (ret) + return ret; + + *config = pinconf_to_config_packed(config_type, config_value); + + return 0; +} + +static int pinctrl_scmi_pinconf_set(struct pinctrl_dev *pctldev, + unsigned int _pin, + unsigned long *configs, + unsigned int num_configs) +{ + int ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + if (!configs || !num_configs) + return -EINVAL; + + ret = pinctrl_ops->config_set(pmx->ph, _pin, PIN_TYPE, configs, num_configs); + if (ret) + dev_err(pmx->dev, "Error parsing config %d\n", ret); + + return ret; +} + +static int pinctrl_scmi_pinconf_group_set(struct pinctrl_dev *pctldev, + unsigned int group, + unsigned long *configs, + unsigned int num_configs) +{ + int ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + if (!configs || !num_configs) + return -EINVAL; + + ret = pinctrl_ops->config_set(pmx->ph, group, GROUP_TYPE, configs, num_configs); + if (ret) + dev_err(pmx->dev, "Error parsing config %d", ret); + + return ret; +}; + +static int pinctrl_scmi_pinconf_group_get(struct pinctrl_dev *pctldev, + unsigned int group, + unsigned long *config) +{ + int ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + enum pin_config_param config_type; + unsigned long config_value; + + if (!config) + return -EINVAL; + + config_type = pinconf_to_config_param(*config); + + ret = pinctrl_ops->config_get(pmx->ph, group, GROUP_TYPE, config_type, &config_value); + if (ret) + return ret; + + *config = pinconf_to_config_packed(config_type, config_value); + + return 0; +} + +static const struct pinconf_ops pinctrl_scmi_pinconf_ops = { + .is_generic = true, + .pin_config_get = pinctrl_scmi_pinconf_get, + .pin_config_set = pinctrl_scmi_pinconf_set, + .pin_config_group_set = pinctrl_scmi_pinconf_group_set, + .pin_config_group_get = pinctrl_scmi_pinconf_group_get, + .pin_config_config_dbg_show = pinconf_generic_dump_config, +}; + +static int pinctrl_scmi_get_pins(struct scmi_pinctrl *pmx, + unsigned int *nr_pins, + const struct pinctrl_pin_desc **pins) +{ + int ret, i; + + if (!pins || !nr_pins) + return -EINVAL; + + if (pmx->nr_pins) { + *pins = pmx->pins; + *nr_pins = pmx->nr_pins; + return 0; + } + + *nr_pins = pinctrl_ops->count_get(pmx->ph, PIN_TYPE); + + pmx->nr_pins = *nr_pins; + pmx->pins = devm_kmalloc_array(pmx->dev, *nr_pins, sizeof(*pmx->pins), GFP_KERNEL); + if (!pmx->pins) + return -ENOMEM; + + for (i = 0; i < *nr_pins; i++) { + pmx->pins[i].number = i; + ret = pinctrl_ops->name_get(pmx->ph, i, PIN_TYPE, &pmx->pins[i].name); + if (ret) { + dev_err(pmx->dev, "Can't get name for pin %d: rc %d", i, ret); + pmx->nr_pins = 0; + return ret; + } + } + + *pins = pmx->pins; + dev_dbg(pmx->dev, "got pins %d", *nr_pins); + + return 0; +} + +static const struct scmi_device_id scmi_id_table[] = { + { SCMI_PROTOCOL_PINCTRL, "pinctrl" }, + { } +}; +MODULE_DEVICE_TABLE(scmi, scmi_id_table); + +static int scmi_pinctrl_probe(struct scmi_device *sdev) +{ + int ret; + struct device *dev = &sdev->dev; + struct scmi_pinctrl *pmx; + const struct scmi_handle *handle; + struct scmi_protocol_handle *ph; + + if (!sdev || !sdev->handle) + return -EINVAL; + + handle = sdev->handle; + + pinctrl_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PINCTRL, &ph); + if (IS_ERR(pinctrl_ops)) + return PTR_ERR(pinctrl_ops); + + pmx = devm_kzalloc(dev, sizeof(*pmx), GFP_KERNEL); + if (!pmx) + return -ENOMEM; + + pmx->ph = ph; + + pmx->dev = dev; + pmx->pctl_desc.name = DRV_NAME; + pmx->pctl_desc.owner = THIS_MODULE; + pmx->pctl_desc.pctlops = &pinctrl_scmi_pinctrl_ops; + pmx->pctl_desc.pmxops = &pinctrl_scmi_pinmux_ops; + pmx->pctl_desc.confops = &pinctrl_scmi_pinconf_ops; + + ret = pinctrl_scmi_get_pins(pmx, &pmx->pctl_desc.npins, + &pmx->pctl_desc.pins); + if (ret) + return ret; + + ret = devm_pinctrl_register_and_init(dev, &pmx->pctl_desc, pmx, &pmx->pctldev); + if (ret) + return dev_err_probe(dev, ret, "Failed to register pinctrl\n"); + + pmx->nr_functions = pinctrl_scmi_get_functions_count(pmx->pctldev); + pmx->nr_groups = pinctrl_scmi_get_groups_count(pmx->pctldev); + + if (pmx->nr_functions) { + pmx->functions = + devm_kcalloc(dev, pmx->nr_functions, sizeof(*pmx->functions), + GFP_KERNEL); + if (!pmx->functions) + return -ENOMEM; + } + + if (pmx->nr_groups) { + pmx->groups = + devm_kcalloc(dev, pmx->nr_groups, sizeof(*pmx->groups), GFP_KERNEL); + if (!pmx->groups) + return -ENOMEM; + } + + return pinctrl_enable(pmx->pctldev); +} + +static struct scmi_driver scmi_pinctrl_driver = { + .name = DRV_NAME, + .probe = scmi_pinctrl_probe, + .id_table = scmi_id_table, +}; +module_scmi_driver(scmi_pinctrl_driver); + +MODULE_AUTHOR("Oleksii Moisieiev "); +MODULE_DESCRIPTION("ARM SCMI pin controller driver"); +MODULE_LICENSE("GPL"); From patchwork Fri Dec 15 11:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 755305 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2053.outbound.protection.outlook.com [40.107.104.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5370B2EB0C; Fri, 15 Dec 2023 11:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="NMk7+ohB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SDZRmnv3T5MoUQmsm2jAyyGBrP9J9vW40wgh7/QDhp+bmCBGudkne9b0urZ6mfQ7CR/p18dID7Rxefi/ppuX/X0iVHrMZup+FsdEFZn7/martqS94iYdWd46ToND4XetqCJ5m/s+oN4FWYpaFjKs/IaIGLKYazQRnDpoTHjklkCynryvCBtSCj/vb9Zr+9bSVvS/iR91gfr/uoI8mrM/DkVM1hfjuI16/XLkPF4fcy3t2Wa0fg/G9yYTU0zLAe3HL+Y48bUK4rUO/p7YDuPJ1wZaxnWRL1AmOtE2ZoN0rmnjNay86h9nVjUicpIN0tMYGZkR+tBTw/9vSxtv43CiAw== 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=cN96ildBqLDvq2WIcHAcgMwAIDICnlC+8rzVh+VDlEs=; b=d4yMxP4JEmiAlufrrzXh09rTvIcTiaDmdfhO/Bmx7bNO6B3Vmx9MDIVmIVE111izHcAaIFZ3YvouAe8mahLK+DwjdORNTdZ6ZfHP6sQQj6DLgD75SyMEmItMGK81F6yQqyK8dJ89uSBMfq1m9ZYenJLddBsoGt+Y3ytrD+UNYFyw3mP3sBh06xEZaHOGZVuRlm4P3UAoCKNp2ztqCsGEBZZAYbhi0UykBhxuIvADUZpEscfEWqmAxF2SZ5Ndra53gHyqo6aT/V2mnHEPbVNbvhsLz72j4I2SFXjt6X4dCp39UUFV1OaBCnrU+EEizihgDAbXaRxqbc4DUnF+I/tHgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cN96ildBqLDvq2WIcHAcgMwAIDICnlC+8rzVh+VDlEs=; b=NMk7+ohBSWsBgHh4ExJQiAZF4HqUVpfs8IuZVX+LvQwEd3ZWglV+TXXU40mKfM2duo6Ykls7yB0Dc4070ALcGJTkThHdT6Ou1q9h8t4OR3zqyzYveFYN1G6XARMn0O2meHaCaittzCFgYJnoAQdd0OCW+cUXbKCNrRu3bRGZ6cg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PR3PR04MB7435.eurprd04.prod.outlook.com (2603:10a6:102:88::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.31; Fri, 15 Dec 2023 11:52:48 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::ff06:bbb2:c068:5fb3%7]) with mapi id 15.20.7046.015; Fri, 15 Dec 2023 11:52:47 +0000 From: "Peng Fan (OSS)" Date: Fri, 15 Dec 2023 19:56:35 +0800 Subject: [PATCH 7/7] pinctrl: scmi: implement pinctrl_scmi_imx_dt_node_to_map Message-Id: <20231215-pinctrl-scmi-v1-7-0fe35e4611f7@nxp.com> References: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> In-Reply-To: <20231215-pinctrl-scmi-v1-0-0fe35e4611f7@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oleksii Moisieiev , Linus Walleij , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702641405; l=7141; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=hHLUTZKZuOlBWYtnb/Z3rmokfWbUliFbIfvqAASsy0Q=; b=oCn9VoADN77j6GAHDGjstgLp27M8V6n13TPAPV6a01H1gJvoe2qdcMUAQ+C6HVBV8RxA5WSxW KVvvFfgOqd3DngOPSzW/dKDap8204Dn5u9g3Y7VBrgnvBBvWwVYMdAq X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0138.apcprd02.prod.outlook.com (2603:1096:4:188::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PR3PR04MB7435:EE_ X-MS-Office365-Filtering-Correlation-Id: aecf0655-0225-4e05-ee95-08dbfd645b91 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wbosiIIDtRiUm+bc6G0OJWJDmyTZs1BFWu2tQ/OSqeQjFLemVkKsFNE4Nhoz9KvpXlg/Q1PFsQxgfBuMPTLJw2Re1rUto/EUdMGWhX+QuH7WNL/9m9yR9iba92p5Q0T86UFLRSQLF/5folLuSNsrVEbCAaDtsSMxdcYQpPPelctmAJTTa7aMbNEukeopSYA9zwmDEwcqXKxUgNOKJDbHEAj+zAFoUWcxLwtQSW+Au/IJW31jD90KtssX7J3xrE7RCaITtChYhJB5I14xuRnyqum3EWSe3C1JXO6dR6DLHopI4l+04XGIc44/4OBgpcTYNIlin9O8SDBth2IGK4mZ7eJ19zvqushAxN3r0iPfUjKrmHYgm33FZ2apPb2+xbXg6ekt3h/mRbGGPBr1FIlerr7EGSBGKT0iUlHAcJVIsMteto4P4GZlr2f/RZwzNFnpAWBX/E12/ggmvKrbZWEgBzqnsJdJj920axBXwn1caVtjmsNHHR1AMw9VXFyZXLjK+uM/Niv9KvFd3XNxQ+gmgzWfaU+iBbeOk99MZXOcDpK+jBku6KjgTQplcij4al5ikdlWufK6ij+tFAoL7Nz38cabXEizEFUHKA+7zELyMUPUxMxu7dFsKH9/GcVkjpoNALFXITieJewRfb1EQ1VVjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR04MB9417.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(376002)(39860400002)(366004)(396003)(136003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(2906002)(86362001)(4326008)(8676002)(8936002)(5660300002)(7416002)(921008)(38350700005)(41300700001)(36756003)(478600001)(6486002)(83380400001)(26005)(6512007)(9686003)(6666004)(52116002)(6506007)(110136005)(66946007)(38100700002)(66556008)(66476007)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wS7JQa3bpgNYrlFwkmzBmvxbfhvz?= =?utf-8?q?vWPuwETR2Mjz0Z9VGjK7TsJeg8TC6tbMzmH8BQbUtAlpRRgxD9Pt9Xin61zDtVpJZ?= =?utf-8?q?IcvvmvYQKoMHA3J/z/IFnFN1TKUu/UNCYY9Zu0/nI+GbLBZyd/rrJRFBFJNMcpGDu?= =?utf-8?q?e5krOI5AXgwO4jLqEHzz7OHszvUBzETSVtyfeIBYIlhLQnNV1RPMNxvgay3ADMWZt?= =?utf-8?q?WWimZ7BoVJHLJmZBZaGMt1x5Zs0A00YfVOD6zANNuB3TRrI5ZFQxa6rsPkmLncfcB?= =?utf-8?q?5xSiebPq14WZIgjXKt7DSY/zk44MilPRnA3Gcl1zIilu8Yo1qLABB7zFwKbSdhlkU?= =?utf-8?q?d9qpFZ8YH2ugMSP2JLh9U2USvTnTVNNUimHp3KOg+mPOWd/akEGSU/1jrr1ggB2l9?= =?utf-8?q?QZUllzPXLPUcTtL3Cln5gaBvFwkimVHg612QNl7jdY5t01ycn0a98/yC+24dloy9G?= =?utf-8?q?SuEJvOv80LFV4+SzlEPCkn7AfseQAzncbUzoWHF9xzv06QAwNR5yjC9cUPntSQQ4u?= =?utf-8?q?otfbpzyKgbTYqkWtbDcYqF0/OEdFsOR4/4T6ZV7Xh3mqnvAM7MkBM2UuezM1nCmUs?= =?utf-8?q?wzQxUf7cvDWH/OvmIdESUxF/slOfN3/uNpiFHi9xidsRSuULwXksUydO8DCLEhWBK?= =?utf-8?q?FAuQy2UDMwzKw1S9AtTETLRj7HEEBua5rfzkM9PrYg7QPc1jUZOoomTspKSDPca3/?= =?utf-8?q?gvFQGZqzI5m/uUquBFWGUHe47s6dsT37DruR2r3t+PxtNWmmsV0uHsGU9VWtD0V/7?= =?utf-8?q?ztzbtk6uv6ZVrd1FfSoX6xTWs4kI8Osqi7cIy+/EHwLLV/EsEGAMLPnbNnOScUEjP?= =?utf-8?q?Axl32NJWZfDEx7fznqHfDII44BbcBs9SQjcnRz+Cwgu9kYC9Z0Bf6T6RtkRqQI2xP?= =?utf-8?q?ZX0V80WLHXBh1sCimdy9UZ3yKkraBZXJ/4ujNoTis/B0yMI9vAQOlu8V6emT6hDCD?= =?utf-8?q?O4ioyyHzffpEjnM1TGhpekOwB7II6uCPQSRU45uin4v0NiOBqRwX2E4uN0GB7zfyb?= =?utf-8?q?9mpajQM1SKNFvJta7mbzJFILzUCYgVItwE2F6gevDIlegkvPqXeJzjno31MwR2WAv?= =?utf-8?q?c0N9tc13hi8qXxdZAvVpznFaMykTECQLqpJrvdcipHDzp8+gJcYqFybod03o+tb/1?= =?utf-8?q?J9Xy0R8L7QDLT+COuMgg//6LtJoPd1fUCql9uY26jIgoL9gze8gCkNMowLSsis/8c?= =?utf-8?q?XcKYN1d6ZtRrZSika5rIuSTR6yC19p/lfvrA6sCkNgZXuWsOjR3NF8jY9hzy2xy6H?= =?utf-8?q?xtkQORzBTLYwkeSvzohC+S9+/8iNdU/rgtToi85lbDoh/vGHoWskYf1AFsSDSHTWe?= =?utf-8?q?z8lwuezN0DHuW+0iUtOhyNLUuI9+mEP5EhDWZrXBvcP1V3q8LddMcf6sa9oqyXe0z?= =?utf-8?q?OIAHbuWjoH1o74mmqbfpbUuUs64HbEVwrkheM2vUKeWtj1YqmTWkCHi99B8jUxXpf?= =?utf-8?q?ZVPf0zt15MYAS0dML1gDjka7UYzO4G52zY6blvAyguMl7xojZ7cP2ZtUqMWeTsGT7?= =?utf-8?q?yUc1r++m1X7M?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aecf0655-0225-4e05-ee95-08dbfd645b91 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2023 11:52:47.9270 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hipEiVaEzZ50fs42xF4NPsroMZIV2A6eviArP/QUU+Lb/Swy2JTpZ/17qN31oA/Qu77lft51FtFLauMhT/+ADA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7435 From: Peng Fan i.MX95 System Manager FW supports SCMI PINCTRL protocol, but uses OEM Pin Configuration type, so need i.MX specific dt_node_to_map. Signed-off-by: Peng Fan --- drivers/pinctrl/Makefile | 2 +- drivers/pinctrl/pinctrl-scmi-imx.c | 117 +++++++++++++++++++++++++++++++++++++ drivers/pinctrl/pinctrl-scmi.c | 16 +++++ drivers/pinctrl/pinctrl-scmi.h | 12 ++++ 4 files changed, 146 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index ba755ed2d46c..d96b7ede1355 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -44,7 +44,7 @@ obj-$(CONFIG_PINCTRL_PIC32) += pinctrl-pic32.o obj-$(CONFIG_PINCTRL_PISTACHIO) += pinctrl-pistachio.o obj-$(CONFIG_PINCTRL_RK805) += pinctrl-rk805.o obj-$(CONFIG_PINCTRL_ROCKCHIP) += pinctrl-rockchip.o -obj-$(CONFIG_PINCTRL_SCMI) += pinctrl-scmi.o +obj-$(CONFIG_PINCTRL_SCMI) += pinctrl-scmi.o pinctrl-scmi-imx.o obj-$(CONFIG_PINCTRL_SINGLE) += pinctrl-single.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o obj-$(CONFIG_PINCTRL_STMFX) += pinctrl-stmfx.o diff --git a/drivers/pinctrl/pinctrl-scmi-imx.c b/drivers/pinctrl/pinctrl-scmi-imx.c new file mode 100644 index 000000000000..e9d02e4c2cc1 --- /dev/null +++ b/drivers/pinctrl/pinctrl-scmi-imx.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 NXP + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "pinctrl-scmi.h" +#include "pinctrl-utils.h" +#include "core.h" +#include "pinconf.h" + +/* SCMI pin control types, aligned with SCMI firmware */ +#define IMX_SCMI_PIN_TYPE_MUX 192 +#define IMX_SCMI_PIN_TYPE_CONFIG 193 +#define IMX_SCMI_PIN_TYPE_DAISY_ID 194 +#define IMX_SCMI_PIN_TYPE_DAISY_CFG 195 + +#define IMX_SCMI_NO_PAD_CTL BIT(31) +#define IMX_SCMI_PAD_SION BIT(30) +#define IMX_SCMI_IOMUXC_CONFIG_SION BIT(4) + +#define IMX_SCMI_NUM_CFG 4 +#define IMX_SCMI_PIN_SIZE 24 + +int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node *np, + struct pinctrl_map **map, unsigned int *num_maps) +{ + struct pinctrl_map *new_map; + const __be32 *list; + unsigned long *configs = NULL; + unsigned long cfg[IMX_SCMI_NUM_CFG]; + int map_num, size, pin_size, pin_id, num_pins; + int mux_reg, conf_reg, input_reg, mux_val, conf_val, input_val; + int i, j; + uint32_t ncfg; + static uint32_t daisy_off; + + if (!daisy_off) { + if (of_machine_is_compatible("fsl,imx95")) + daisy_off = 0x408; + else + dev_err(pctldev->dev, "platform not support scmi pinctrl\n"); + } + + list = of_get_property(np, "fsl,pins", &size); + if (!list) { + dev_err(pctldev->dev, "no fsl,pins property in node %pOF\n", np); + return -EINVAL; + } + + pin_size = IMX_SCMI_PIN_SIZE; + + if (!size || size % pin_size) { + dev_err(pctldev->dev, "Invalid fsl,pins or pins property in node %pOF\n", np); + return -EINVAL; + } + + num_pins = size / pin_size; + map_num = num_pins; + + new_map = kmalloc_array(map_num, sizeof(struct pinctrl_map), + GFP_KERNEL); + if (!new_map) + return -ENOMEM; + + *map = new_map; + *num_maps = map_num; + + /* create config map */ + for (i = 0; i < num_pins; i++) { + j = 0; + ncfg = IMX_SCMI_NUM_CFG; + mux_reg = be32_to_cpu(*list++); + conf_reg = be32_to_cpu(*list++); + input_reg = be32_to_cpu(*list++); + mux_val = be32_to_cpu(*list++); + input_val = be32_to_cpu(*list++); + conf_val = be32_to_cpu(*list++); + if (conf_val & IMX_SCMI_PAD_SION) + mux_val |= IMX_SCMI_IOMUXC_CONFIG_SION; + + pin_id = mux_reg / 4; + + cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_TYPE_MUX, mux_val); + + if (!conf_reg || (conf_val & IMX_SCMI_NO_PAD_CTL)) + ncfg--; + else + cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_TYPE_CONFIG, conf_val); + + if (!input_reg) { + ncfg -= 2; + } else { + cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_TYPE_DAISY_ID, + (input_reg - daisy_off) / 4); + cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_TYPE_DAISY_CFG, input_val); + } + + configs = kmemdup(cfg, ncfg * sizeof(unsigned long), GFP_KERNEL); + + new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN; + new_map[i].data.configs.group_or_pin = pin_get_name(pctldev, pin_id); + new_map[i].data.configs.configs = configs; + new_map[i].data.configs.num_configs = ncfg; + } + + return 0; +} diff --git a/drivers/pinctrl/pinctrl-scmi.c b/drivers/pinctrl/pinctrl-scmi.c index 0710ce9a1b42..e677e2064ba7 100644 --- a/drivers/pinctrl/pinctrl-scmi.c +++ b/drivers/pinctrl/pinctrl-scmi.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include +#include "pinctrl-scmi.h" #include "pinctrl-utils.h" #include "core.h" #include "pinconf.h" @@ -86,6 +88,16 @@ static const struct pinctrl_ops pinctrl_scmi_pinctrl_ops = { #endif }; +static const struct pinctrl_ops pinctrl_scmi_imx_pinctrl_ops = { + .get_groups_count = pinctrl_scmi_get_groups_count, + .get_group_name = pinctrl_scmi_get_group_name, + .get_group_pins = pinctrl_scmi_get_group_pins, +#ifdef CONFIG_OF + .dt_node_to_map = pinctrl_scmi_imx_dt_node_to_map, + .dt_free_map = pinconf_generic_dt_free_map, +#endif +}; + static int pinctrl_scmi_get_functions_count(struct pinctrl_dev *pctldev) { struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); @@ -327,6 +339,7 @@ static int pinctrl_scmi_get_pins(struct scmi_pinctrl *pmx, static const struct scmi_device_id scmi_id_table[] = { { SCMI_PROTOCOL_PINCTRL, "pinctrl" }, + { SCMI_PROTOCOL_PINCTRL, "pinctrl-scmi-imx", "fsl,imx95-scmi-pinctrl" }, { } }; MODULE_DEVICE_TABLE(scmi, scmi_id_table); @@ -361,6 +374,9 @@ static int scmi_pinctrl_probe(struct scmi_device *sdev) pmx->pctl_desc.pmxops = &pinctrl_scmi_pinmux_ops; pmx->pctl_desc.confops = &pinctrl_scmi_pinconf_ops; + if (device_is_compatible(dev, "fsl,imx95-scmi-pinctrl")) + pmx->pctl_desc.pctlops = &pinctrl_scmi_imx_pinctrl_ops; + ret = pinctrl_scmi_get_pins(pmx, &pmx->pctl_desc.npins, &pmx->pctl_desc.pins); if (ret) diff --git a/drivers/pinctrl/pinctrl-scmi.h b/drivers/pinctrl/pinctrl-scmi.h new file mode 100644 index 000000000000..25863b4428fe --- /dev/null +++ b/drivers/pinctrl/pinctrl-scmi.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2023 NXP + */ + +#ifndef __DRIVERS_PINCTRL_SCMI_H +#define __DRIVERS_PINCTRL_SCMI_H + +int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev, struct device_node *np, + struct pinctrl_map **map, unsigned int *num_maps); + +#endif /* __DRIVERS_PINCTRL_SCMI_H */