From patchwork Fri Apr 5 01:59:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 786357 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2107.outbound.protection.outlook.com [40.107.247.107]) (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 A9C57168B7; Fri, 5 Apr 2024 01:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.107 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281903; cv=fail; b=qSlEBuUtalcGCCxQ8QYrhKTaAA5BMVbuV+29iaNMIsa452epfsuvM+9/b03+SPPZsCLOQE7L1/H3cPuuhhDED4lzNTKSgRI4Lf7jYtIX+3fdxWWRu6iRwohK50ULbKOw4i84BwDNe83BF5pjBTNRM+39g+j0X7JgC89YOyeceD8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281903; c=relaxed/simple; bh=VyUgp1uqg2sd9efaIWkIGYr2e4EYKfjV9z7DdHViSYo=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=uanjRVhdXii0ojLBq8j6/n/ipRWY1gSgT1+J7Xb2hwalcNcwxkA+Dqq107G9r0ObQn7/SJhRdy7J4cUWvZ9Y6UEPMN0v/bb69woxZQmIpcNMjVo1jGn9548jYx8k2KKhUUlCOWvdFkD7VVyJZgvrbO9nbmEi5f/J2fu0nRaSNkE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=Z6mF+gr7; arc=fail smtp.client-ip=40.107.247.107 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="Z6mF+gr7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxKpsBf0zWtVP97or+M8KJAfgSxLkTt26IKCnXDdu1HY/a0JUBzt/OTO3Ggmza4a4vfKxb3pl279WNINIPJ9ZM2J7oRZ+BuydxfO8DnxBV3edfXFn5WzDDMpmrKc4EUbY7/ua0sN/7mVsadTYRRvxSDqsjWeoWUgK+zJiARbU8MHBuPopM3+IWEglf5rkYJlrDwQhfxyQukS8OZ3q+GcqsVyU6+daITA8bIUhfp5uKeRWPLW3gyqyZygaOIXSRxgVrEVMYDgxUQt1YBkdpKfYkAg4qbmbGTqxBbVPfGDrG5KnDdjaMfHI0/MO2kCeNAUFKdTF6tOQ+IHrS0p3dt0Ww== 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=s/BzLovi5aKNOiOuw8s4YMGfV7RBPkidh8VfX3S2pYQ=; b=GDlMpZLsJJ3MZAi3PoTN6Udsa5cwOS4iCZE06htIl9Kg7zQNfPzh/uJEZhpLwCmOKtgRzdemwCO4ITA8ltQlZax+xgxazlqUBJfxBU9WlMeLdlmSNXzcofQrGTOoL6T2J9MMXdRA1vV3Xu07Q7ju1Twc/aBtSnSjEgCW+ydM2MQfvF3kzeHKIc5HgnNH1zZAEOT3XcvXW39r03YnOv4k/p844tt12YGwRQa+vaMHdy6Gw291J0mSDAyS0XqzlX2D1a4XPHtAf2QMpWCViE7U8KaRFMipdDJ9qUcMdZxfTKdyG9i6n2XPr/UjGS2VY0HPb6CvfoIera3/ahWy9OVM0A== 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=s/BzLovi5aKNOiOuw8s4YMGfV7RBPkidh8VfX3S2pYQ=; b=Z6mF+gr7BbXSr+H9yoNfUxdlplWIEpRY5Aq4ApNaNPY+t7ORnO4AanVjqKXGgiavhac/xuiSCI0bwxs2IYs3oO5PMeET9xNoc/3SWpNGu/oRCtns26wrHUPjiqcK04bB8WzlwlGECeMd0ZQ8DZuik+d8eYF/r7I6wx91t0azLFQ= Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AS1PR04MB9334.eurprd04.prod.outlook.com (2603:10a6:20b:4de::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 5 Apr 2024 01:51:38 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d%4]) with mapi id 15.20.7386.037; Fri, 5 Apr 2024 01:51:38 +0000 From: "Peng Fan (OSS)" Date: Fri, 05 Apr 2024 09:59:33 +0800 Subject: [PATCH v8 2/4] dt-bindings: firmware: arm,scmi: support pinctrl protocol Message-Id: <20240405-pinctrl-scmi-v8-2-5fc8e33871bf@nxp.com> References: <20240405-pinctrl-scmi-v8-0-5fc8e33871bf@nxp.com> In-Reply-To: <20240405-pinctrl-scmi-v8-0-5fc8e33871bf@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter Cc: Andy Shevchenko , 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=1712282385; l=2362; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=1H2rME0+2KWUaw0j7tYsXFokSaYx/bEPhCjn1uDoVYo=; b=BUg2Cj4WROOGS5yaciuXQoewxdfbg74i5cVScjfGO+Sj5vomm0JEOhabackVE8ZtBVN2UbgQv PU3CwxUabP1DXjMNnwwj8+2nYHZNcbdJv4mld2rtsaL5vzAsVWC3xLe X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR01CA0012.apcprd01.prod.exchangelabs.com (2603:1096:4:191::8) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: linux-gpio@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_|AS1PR04MB9334:EE_ 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: So1+PPKJB5KIPLEJc9gt1uj6emVSWX1IrxMf//nOK/mDfmFEyWm0O3YXxpcvE5EnOobm2qYLBiPqoRQ3DoHge7UeHQGEV25Rp6qRfxrCnmNF6aSBwZhwnsfpfAxEL2YUti3e0qxqfj0N5yS7sOWzQMw2kr/JamkFzdZG1+QIRr1gJP0v9yIahNHKbnD5b5VgHu9PPWiHvFk+WZTQDwfknhR2bCUq5eBg6LdZXTAb2WLi0h3K9PyaSNqtPro1lk5/xLR00suH0xbOPVi3qj9vJArCP2Dwq4ysHOrS1RusjT0KtnSF2c3gXp2mSkdRiCqT19rMyXqcJ9mKBuIcN2G935EWRlCxC4Hr9WptbgsiVu70y6LQIr2e3i/ML4+7ZU2Hy/Kj3+7pL82nVGxAjJTDo/eYLHPc+BtIhG0Z1dTYEVcFIYxZrBxvCMoQqa22BOgdyRx2NWGXBy8QrCBZPFNIg5hCtD27+GvzIh2fivKSNGxB4MrhLRes3JmBvV40Fh28eOPvSjtwSqPJY4SX4+qtADsMJtllFGrLww7IfXjiBqqb1IdmHg0Rz4mqHo0tbVxvlXNpAH3bw19mIlQhYz7aHsmQmOq8UfP9DETP0kHfeF8ZBLMeEPp8Uaz572W/RmdnRXTiGdegTqMm3kj2nrGB3L2ehGYuOK/jFmodTCk+r2A32a4X+EOQWuzY0r4uboMJpXi98Vbcrj9IBj5kDIfDka0URgR4axQ94dQOBmNipBM= 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)(1800799015)(366007)(7416005)(52116005)(376005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0taMi1Xz9vrh743Xory+WtI4WOuv?= =?utf-8?q?Yr/au1ZVSHUs/Zniyn62+xgY1X/XqvfH/feFf5e6tovp8g3EftqJtoZnwLDmFy6MK?= =?utf-8?q?hfDc25L0KfjJn7etTwEriSOTe3k+6Q6IKjEg9pc5sby8iIYfk9GrhIGuxu+XHHpUZ?= =?utf-8?q?ScJUuYUQXiwsejRJz7E7tImY7vd33Ggfu7Q9R+mte3jVE4ZufKBx6OHlsCvilTSkl?= =?utf-8?q?z22AOk79oRk4plE3sMy8gXY4WixEmHyZYNhNDnahjBjvK8uHOHLIuJc/Es+PqmZKI?= =?utf-8?q?6qw0zLWSOarycI82N8r0sUTrAIxguThGkiDtfmVGQnzlihOWgDIisY6yBVpcjqVAP?= =?utf-8?q?H/WggggA1aCzGCTWTf1ipG2k8V5Bmu5rTEfa2AtcWaZ7CV7TNE9iAUOawZVoBTXYE?= =?utf-8?q?A0lb8Ci1GLyDbQheOTX3Rj59o/48riW3OLww/VbhcFvyfjCmI9Hu3Eb9kJ5MkbJ6x?= =?utf-8?q?gZuR8gHkX5Gik01K2qA012e1T0tYx906oqMbgIK0dj/2BFaUi0lAbUieka8e/7Qhw?= =?utf-8?q?JIvzRNHaYVv0gj2f/HgWDSiBzUhQsZqnKRF2pLFY9IhexwqPeO6HiswEqOhIQhMmj?= =?utf-8?q?B8Ntp+Tp3eYB21ZdHPD86VYQ23nUeOPWDEWjLfT2lVpb0JCgLwYsWN24EU2UnRqyX?= =?utf-8?q?yvGcC83t46/dC5T35321kX2uDszY13bmAurUIrynF1/08DWcvsXddI23xDozMQ2/2?= =?utf-8?q?efPSUJCO3828/CQDQ7IUQsiKcwtM759A2UgrzDpD4F4omQ4xKtCEHKhg/rewyfy/z?= =?utf-8?q?tt5TmOULepaEGaHfI+QeKAVMvB0uhq8riQDLecqExtgO8z/Tc6WqKfVPfQqPJbTwy?= =?utf-8?q?zkLjmkg+5AbibAwODby55DZ9m92z4cT9SpoCvRsrLW8+wy1oopkelGK28N//wxWPt?= =?utf-8?q?NQEtpqn6GI3MYFjK21PCw2YXLpByycsFsIRrh+kPjbI32XX0hKrPLfYKvkAOk3j7H?= =?utf-8?q?V6CI0JVTuXkCwbDqG9rcHxgxMZHUjeqGrexPyT03W78zxmvfONcEzEobJ+4rKoIRa?= =?utf-8?q?V8qfw/TjXwc8/EorUtWQZMqyyV1oH3f9yjXcIJdlH0pEAEwE7mlO02k3RK7ulEVRW?= =?utf-8?q?nJ7tbnJ099PTEhMfgplNN/QSiqmzPVekJjWxdulCF7Pp0jOdhhVuHSN4eMQVcz7tQ?= =?utf-8?q?mvlo25luLNYq4LSU8aphy2uvVb7UlCrOebVHqBnn/gokA8kSThaWsv0/Uu2BXxHZp?= =?utf-8?q?4mZeQI5G8qBMDzNbdav/QsTl9B736U0a04+lY0/v5s9KKTmF4VVy6QPDsf7pXjL+B?= =?utf-8?q?5+46ZxDq9NuQCwMJRHra94vJ/xlO343CesxMgJJ8jpNwl8U0iQEVLu9mrEzO86c7f?= =?utf-8?q?8C7UZP+Er7lOEEt210jQc8XvC2NYrW/EW4ip+WBot8Lo7mr0g+1q6Ki8xCmx3QN5s?= =?utf-8?q?fF0h2USbB+EN6eAlD6Qmb61gx1Mxf4DMvT6XGJW22RZfWK0DWstJ/o2IE91apGGdD?= =?utf-8?q?AJHm1TiEnqzNZae/5HULYkWQy+s6dijxtDyo2GAnL/WiK+m3PDDYEObz9CDINPLLN?= =?utf-8?q?v+3ATuv/BsaG?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ec8c218-02d7-4604-1dba-08dc5512ee9d X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2024 01:51:38.1992 (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: UJ3b4LYDluYeInuQqhKy82ZqKige506KSpgIVjUSnaBUWmjQ/t26h6KUxbqrE9qI0XLItmqaxUfe6zf1ieF6LQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9334 From: Peng Fan Add SCMI v3.2 pinctrl protocol bindings and example. Reviewed-by: Rob Herring Reviewed-by: Linus Walleij Signed-off-by: Peng Fan --- .../devicetree/bindings/firmware/arm,scmi.yaml | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml index 4591523b51a0..e9d3f043c4ed 100644 --- a/Documentation/devicetree/bindings/firmware/arm,scmi.yaml +++ b/Documentation/devicetree/bindings/firmware/arm,scmi.yaml @@ -247,6 +247,37 @@ properties: reg: const: 0x18 + protocol@19: + type: object + allOf: + - $ref: '#/$defs/protocol-node' + - $ref: /schemas/pinctrl/pinctrl.yaml + + unevaluatedProperties: false + + properties: + reg: + const: 0x19 + + 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 describes how to configure a + set of pins in some desired function. + A single sub-node may define several pin configurations. + This sub-node is using the default pinctrl bindings to configure + pin multiplexing and using SCMI protocol to apply a specified + configuration. + + required: + - reg + additionalProperties: false $defs: @@ -401,6 +432,25 @@ examples: scmi_powercap: protocol@18 { reg = <0x18>; }; + + scmi_pinctrl: protocol@19 { + reg = <0x19>; + + i2c2-pins { + groups = "g_i2c2_a", "g_i2c2_b"; + function = "f_i2c2"; + }; + + mdio-pins { + groups = "g_avb_mdio"; + drive-strength = <24>; + }; + + keys_pins: keys-pins { + pins = "gpio_5_17", "gpio_5_20", "gpio_5_22", "gpio_2_1"; + bias-pull-up; + }; + }; }; }; From patchwork Fri Apr 5 01:59:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan \(OSS\)" X-Patchwork-Id: 786356 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2131.outbound.protection.outlook.com [40.107.247.131]) (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 1B379E574; Fri, 5 Apr 2024 01:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.247.131 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281911; cv=fail; b=Ifq1hRI9WfeRfb6ygE8hGrHwyqj1A16BvAJl+yxJtHzfAq8rqfSrGvMTkpOVpsHlYR6CCNi6Vuep7WxtiUCUwhemdyOHUZcFCAFH2HV+1XZ/HZnM0R+gVkoZ70HZ1ej6y7+GRhmpk5aofvha2WTDGQ4jLI0+xmipIaKVgTXwEU8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281911; c=relaxed/simple; bh=1ttx/K+ylZQ/pr5TJ+cDOsVLuXyiYxZzI5tgqGW/sCA=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=hF6kNbEmwYS8/ewEHLHd84i4mYb5OTS7KG8YMevDiQrC5HEpiLXCqOn9Hy3ex5AykCB/eHwb5MZQUAYHKt5czdqUpRaXvVAXySd9Aua6NcJsDoiSJh2EsrSgsQo7kUJPrbspwMVdhM0x1dBeYOeXELCBeEsDekmNf2qBt32pvgk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=IkKhv8iN; arc=fail smtp.client-ip=40.107.247.131 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="IkKhv8iN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hCBF/5QJY7FpawfVVAfJNFjHw+fE0u1R6BxsQ+eXWXRnBL2MFoA4bcTDT+dss2HQEwB5awhvhEFhaqsOrFFmI7IHEErvtcPb4uX/Snv1EBeKMWmxSf3wr9HfCtKAGVJXmj14qneVJxjBQN+WK90xrVxQhq9m9NpsLzx46ERIProjwvgzQ0cPEQyL/YJC85uHuZgCyVtXhvQ0X/wJ0AjvgI3rHmWBVP5Rwav8oXX1mO3j1SFTyxB0lfitSnpWpODjVFx9kaNOVSozb30AqSi335bgQCs3/hLgmPXnuPQB64PDaJOFccShAX9PsSiBCjMQ+08wJ7kEQswYLfIZBsYmdQ== 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=UZpY0FB4CcuIWdsXFpbNhSUGvrVt0Nr/jyeCFpYOnlU=; b=eWTcZDeQHUweCZDq39zaQUpD+FJlO5o+hkgDx5Fu2g+n/yop0Wyvgb8vkhRy/Ve18zf51jZlq7w3wHDMVkmNCJWPmC01iwAij8BFzSxTH4P0hjZI4Vb8xYH27UXfcMPPik9z3HWNggljTbf/vRE4Q5iUx9fZzTaQekPIzX4kb9zSso32fEG2O1SdRiy80mSchEBho7tEPbqHjKlVU2UqyhLI2HtzPL2A6QLfS4gOUNWUKpzu0krWjtCCfouzDgp2hAIwJq/TbgmpIlOfqkt4Iay1RFWbB2+EY0D9Aj35CltvZlKQzpS/QJg6DIKmHbnWePPKXiBw6sjycBmR5s8Vvw== 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=UZpY0FB4CcuIWdsXFpbNhSUGvrVt0Nr/jyeCFpYOnlU=; b=IkKhv8iNwoI7+0Z0B61oZZjYYL1/S9Df6IWgIaJZLhio45vgFYsEaYnXVc51KQ/QWxdAi5WnceYGVPO5j5xWQ1b4Z/qTo4kvhzM8hFuAj3it6f4BlQ+WkbmveOrvwJAljxSPshipJstvjEjmPymE/XEMoOvSrDuqiGmorxTMttY= Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AS1PR04MB9334.eurprd04.prod.outlook.com (2603:10a6:20b:4de::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 5 Apr 2024 01:51:46 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d%4]) with mapi id 15.20.7386.037; Fri, 5 Apr 2024 01:51:46 +0000 From: "Peng Fan (OSS)" Date: Fri, 05 Apr 2024 09:59:35 +0800 Subject: [PATCH v8 4/4] pinctrl: Implementation of the generic scmi-pinctrl driver Message-Id: <20240405-pinctrl-scmi-v8-4-5fc8e33871bf@nxp.com> References: <20240405-pinctrl-scmi-v8-0-5fc8e33871bf@nxp.com> In-Reply-To: <20240405-pinctrl-scmi-v8-0-5fc8e33871bf@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter Cc: Andy Shevchenko , 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=1712282385; l=18244; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=AbjpOrl7yBEnYMIcYlspNvfej90dVHj0Zx/z0qnvcvQ=; b=ppGhd76dTZEbiyARreRonhXafGAg20CJ4XP2TdkrqCVpeuwmYv61D36/rCLAhxy3FBvOFNBA3 vnmrWFGfFmpCRqkJI+GOjQYTbIRMxUqwOCZxX0mvw8EJf7SM7hNW1A7 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR01CA0012.apcprd01.prod.exchangelabs.com (2603:1096:4:191::8) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: linux-gpio@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_|AS1PR04MB9334:EE_ 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: oCkjkrW78NNUQeHAbYkoEh36bmn/Gc6Lc2Bm9sc23UEvlkBJ9J3AOR5Iw+c+0lyRweNAu05g+ihAjO9IoxeCL1MAWwrAtaryY8O3KdYqADe9wMz8DIZ4vd+ZRFjol+ICCcebRv0dqQIMJc8KQ+NjRgr/fT8gYK1o9vpaI44ne5Cv+r713RiVrH5Gn+7uIOF0j0lyYxHbAED3uEhmOkVN7/R8AAgvxWwFnVn6lDQ6WGII2lBom+KvPSy7wd/YARDJcIAiDYQhEDO1rlt4j2NCN1eM7cgNej+Ti3ckdKqlVF4VFUI0sqwVk2C0yeGXarcK9Ml4scO4Nl4ud2Lx1SmTKscaQz/xvxu14OHRq5Qmd8tstRp9bBPBEsF+17aWMGGtUxsekGnB9JzhfV7Y3mmHPwVRQw764BFzPqdRfD4+1iahaNpp4+X8weJTxaVnjl2Ewee6KvOpescdgPv16vFxVV3HfNyOR2FyiswzoBMk/m99uLOoZt7GN4s9daWmTvG1jG5FJ775cJVjs6I9orkwDyPeJfj/fV7DvJI2vdyyFgxVB4Ck16ikXg1et51AkHXpFihqkUdgfBeckTtcb+yXnreoV7TpwkbFZHjEiEM2foZhm/CXw6VNHsn4TiVpyWfzaTYROWk3E3WIttXqcsd/5XdGYGiZj8MI1kmLR5dk0EN0HIMod9wvvCH8oTbyUOvGp9nj4KMnS0J5M1J/R4taw1ceraoo2jzVb/F4LUH3AOg= 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)(1800799015)(366007)(7416005)(52116005)(376005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gPvCXjDXeIEA8LOoS/dyCCQPgL7H?= =?utf-8?q?60+oXrup4Iw3unhkmV9UZ3B9+t85m/MtZLk2ec0lngMUdZ6ZUbglkgXlxlha9D/7H?= =?utf-8?q?MbbEQJn+DNzqJ8anY/E7yI9hYk2h8PpLDyBF7aR9NMBiRh5L+qS4fyAunNS7fCG25?= =?utf-8?q?AVf4m0GTcCSpALuaXS4eSbVWf2B5A2J1U0KJWg1IczvdZahiwH5WVIlaqmTwfTmPe?= =?utf-8?q?x1d4RicuTntmS1LW80hH7fmkDZFRGvHBogzGOoJAeN48AU4IQxKOBQ4yICZz7JlYv?= =?utf-8?q?qR0aHN4zd3GgtIdddWg3AQdOl0BGNRJMg4RYSdc4sD2Uzwovz4PYW4rBwX2Al8+yR?= =?utf-8?q?LINoD0rDsjDtiw6PnWRKgitlfLp0DfED0bhEMdAND4bEsd8gW0ARysJ6QvNfIY442?= =?utf-8?q?rs45umPO6anNX+dqUOy27VDQlu1SeFhTaPE9b7TmnnMTui8/mFrKrenLMRFvn5Ke5?= =?utf-8?q?cCVYbgV0DuxLYidjpVLBw9/fqwGbuqRMfp9vVEPgFJeDBNxQTWsXoReNpM/izLGwR?= =?utf-8?q?Unh9SbeQKd1NqoEbep/3KMGZDvNQBKjxNxmetHBdncQVl0d2olfZ93tPlWMxY2w1j?= =?utf-8?q?ZrIPQR3Zuk39zHKgSsq7NOkigQ1zmzxESMN/TqhFVuIZeGGx1KfavKNkEaQbT7/s8?= =?utf-8?q?YbrlXBXJ4W+csFgRCOAWd6czuo1zG7enk32aaa6Jaf5fc53m1V/gMkhMdl9MVUZA4?= =?utf-8?q?tGxmJhE3iVGqMmBN6nGkFPEJisefjD+p/+w7mWMgxo24SjOEKkUQ6UV6lKVk84gQJ?= =?utf-8?q?wqGqpbLlb/alPnK/kVWuOYzH3dfExX3n8xq1HO4dfa2NfSlOYyR5W8BQ14OhxKefZ?= =?utf-8?q?FioJ9i+STfCZSQfhZNIF1HTRKh2NZXBOOWfOFlWSdeSw2nP3Ln8SfJGTVQMEIRLWH?= =?utf-8?q?5pz9pgQgh/5Ja++8fUCAv375JkONLHn913eQ6wUIdWMkBZOISAEpqqMK+s7wFGnBZ?= =?utf-8?q?wDb5zcxdtT1xAyenq4FOvvTUEs3niyDXzrdV3jC1wBDyYguNtbxGb3qqpbK0hxa0V?= =?utf-8?q?psbvG3358KcElz+8GmblBR19jC+J0Z21ztN9pBjTr1yWwidNMqIwMSAwlAoKzaHdw?= =?utf-8?q?UN9owcbNpIxX0ttefUMFFe4CJfoURwkqSn6HDKa1LItDgL6/JGz2rfEgmpZpwZDLn?= =?utf-8?q?qvXw804u/CNmgHV/BvkkzSu4zGbQcGilJq2I3D+eGFjxLe4+AyUXmeOHEynee1SQH?= =?utf-8?q?3Eco2XmINzVh4yYRdN+Z1yui5S7wVPdDIdUsuFJGqf998WOkJgEkSMmhixOQb825i?= =?utf-8?q?jjrmsKzgmv9h8edR9FbMUlsmCFk/uqt7gODdKuHVeLzAH89vhnbFs8MxNwFFvBYT0?= =?utf-8?q?2W/8m9WBPUsm8GO3x+ciyVPEntg8qZPU2mzhFbDTiDFTEluQTaKHNnVhq3Sb+dDE7?= =?utf-8?q?izi4jz12F8BcL49ZCJabwV5BCZq9mj6Bb63QYR44QKNytNakPEkhjLci5MoUORt+7?= =?utf-8?q?IP0bVHUobVPRHffrKuufVxgj7wFpM7LQkh2pVo+AeIWbPTcBduShftfj1Tlz4PONc?= =?utf-8?q?DAGzMr2i3DoM?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73bef76d-0b8b-4708-b218-08dc5512f3b6 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2024 01:51:46.8209 (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: w0MSOLuC7n7qalFSpMtYjkt1NeVI/0u+kUfyBbO9WduhCA2e6Luk4sZszMldsGlRcTqzup/v+HYkHMaOyn+41g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9334 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 Reviewed-by: Dhruva Gole --- MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-scmi.c | 564 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 577 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4b511a55101c..d8270ac6651a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21457,6 +21457,7 @@ F: drivers/cpufreq/sc[mp]i-cpufreq.c F: drivers/firmware/arm_scmi/ F: drivers/firmware/arm_scpi.c F: drivers/hwmon/scmi-hwmon.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 d45657aa986a..4e6f65cf0e76 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -450,6 +450,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 2152539b53d5..cc809669405a 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -45,6 +45,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..0f55f000a679 --- /dev/null +++ b/drivers/pinctrl/pinctrl-scmi.c @@ -0,0 +1,564 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Power Interface (SCMI) Protocol based pinctrl driver + * + * Copyright (C) 2024 EPAM + * Copyright 2024 NXP + */ + +#include +#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" + +/* Define num configs, if not large than 4 use stack, else use kcalloc */ +#define SCMI_NUM_CONFIGS 4 + +static const struct scmi_pinctrl_proto_ops *pinctrl_ops; + +struct scmi_pinctrl { + struct device *dev; + struct scmi_protocol_handle *ph; + struct pinctrl_dev *pctldev; + struct pinctrl_desc pctl_desc; + struct pinfunction *functions; + unsigned int nr_functions; + 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 **p_groups, + unsigned int * const p_num_groups) +{ + struct pinfunction *func; + const unsigned int *group_ids; + unsigned int num_groups; + const char **groups; + int ret, i; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + + if (!p_groups || !p_num_groups) + return -EINVAL; + + if (selector >= pmx->nr_functions) + return -EINVAL; + + func = &pmx->functions[selector]; + if (func->ngroups) + goto done; + + ret = pinctrl_ops->function_groups_get(pmx->ph, selector, &num_groups, + &group_ids); + if (ret) { + dev_err(pmx->dev, "Unable to get function groups, err %d", ret); + return ret; + } + if (!num_groups) + return -EINVAL; + + groups = kcalloc(num_groups, sizeof(*groups), GFP_KERNEL); + if (!groups) + return -ENOMEM; + + for (i = 0; i < num_groups; i++) { + groups[i] = pinctrl_scmi_get_group_name(pctldev, group_ids[i]); + if (!groups[i]) { + ret = -EINVAL; + goto err_free; + } + } + + func->ngroups = num_groups; + func->groups = groups; +done: + *p_groups = func->groups; + *p_num_groups = func->ngroups; + + return 0; + +err_free: + kfree(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_map_pinconf_type(enum pin_config_param param, + enum scmi_pinctrl_conf_type *type) +{ + u32 arg = param; + + switch (arg) { + case PIN_CONFIG_BIAS_BUS_HOLD: + *type = SCMI_PIN_BIAS_BUS_HOLD; + break; + case PIN_CONFIG_BIAS_DISABLE: + *type = SCMI_PIN_BIAS_DISABLE; + break; + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: + *type = SCMI_PIN_BIAS_HIGH_IMPEDANCE; + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + *type = SCMI_PIN_BIAS_PULL_DOWN; + break; + case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: + *type = SCMI_PIN_BIAS_PULL_DEFAULT; + break; + case PIN_CONFIG_BIAS_PULL_UP: + *type = SCMI_PIN_BIAS_PULL_UP; + break; + case PIN_CONFIG_DRIVE_OPEN_DRAIN: + *type = SCMI_PIN_DRIVE_OPEN_DRAIN; + break; + case PIN_CONFIG_DRIVE_OPEN_SOURCE: + *type = SCMI_PIN_DRIVE_OPEN_SOURCE; + break; + case PIN_CONFIG_DRIVE_PUSH_PULL: + *type = SCMI_PIN_DRIVE_PUSH_PULL; + break; + case PIN_CONFIG_DRIVE_STRENGTH: + *type = SCMI_PIN_DRIVE_STRENGTH; + break; + case PIN_CONFIG_DRIVE_STRENGTH_UA: + *type = SCMI_PIN_DRIVE_STRENGTH; + break; + case PIN_CONFIG_INPUT_DEBOUNCE: + *type = SCMI_PIN_INPUT_DEBOUNCE; + break; + case PIN_CONFIG_INPUT_ENABLE: + *type = SCMI_PIN_INPUT_MODE; + break; + case PIN_CONFIG_INPUT_SCHMITT: + *type = SCMI_PIN_INPUT_SCHMITT; + break; + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: + *type = SCMI_PIN_INPUT_MODE; + break; + case PIN_CONFIG_MODE_LOW_POWER: + *type = SCMI_PIN_LOW_POWER_MODE; + break; + case PIN_CONFIG_OUTPUT: + *type = SCMI_PIN_OUTPUT_VALUE; + break; + case PIN_CONFIG_OUTPUT_ENABLE: + *type = SCMI_PIN_OUTPUT_MODE; + break; + case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: + *type = SCMI_PIN_OUTPUT_VALUE; + break; + case PIN_CONFIG_POWER_SOURCE: + *type = SCMI_PIN_POWER_SOURCE; + break; + case PIN_CONFIG_SLEW_RATE: + *type = SCMI_PIN_SLEW_RATE; + break; + case SCMI_PIN_OEM_START ... SCMI_PIN_OEM_END: + *type = arg; + break; + default: + return -EINVAL; + } + + return 0; +} + +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; + enum scmi_pinctrl_conf_type type; + u32 config_value; + + if (!config) + return -EINVAL; + + config_type = pinconf_to_config_param(*config); + + ret = pinctrl_scmi_map_pinconf_type(config_type, &type); + if (ret) + return ret; + + ret = pinctrl_ops->settings_get_one(pmx->ph, pin, PIN_TYPE, type, + &config_value); + if (ret) + return ret; + + *config = pinconf_to_config_packed(config_type, config_value); + + return 0; +} + +static int +pinctrl_scmi_alloc_configs(struct pinctrl_dev *pctldev, u32 num_configs, + u32 **p_config_value, + enum scmi_pinctrl_conf_type **p_config_type) +{ + if (num_configs <= SCMI_NUM_CONFIGS) + return 0; + + *p_config_value = kcalloc(num_configs, sizeof(**p_config_value), GFP_KERNEL); + if (!*p_config_value) + return -ENOMEM; + + *p_config_type = kcalloc(num_configs, sizeof(**p_config_type), GFP_KERNEL); + if (!*p_config_type) { + kfree(*p_config_value); + return -ENOMEM; + } + + return 0; +} + +static void +pinctrl_scmi_free_configs(struct pinctrl_dev *pctldev, u32 num_configs, + u32 **p_config_value, + enum scmi_pinctrl_conf_type **p_config_type) +{ + if (num_configs <= SCMI_NUM_CONFIGS) + return; + + kfree(*p_config_value); + kfree(*p_config_type); +} + +static int pinctrl_scmi_pinconf_set(struct pinctrl_dev *pctldev, + unsigned int pin, + unsigned long *configs, + unsigned int num_configs) +{ + int i, ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + enum scmi_pinctrl_conf_type config_type[SCMI_NUM_CONFIGS]; + u32 config_value[SCMI_NUM_CONFIGS]; + enum scmi_pinctrl_conf_type *p_config_type = config_type; + u32 *p_config_value = config_value; + enum pin_config_param param; + + if (!configs || !num_configs) + return -EINVAL; + + ret = pinctrl_scmi_alloc_configs(pctldev, num_configs, &p_config_type, + &p_config_value); + if (ret) + return ret; + + for (i = 0; i < num_configs; i++) { + param = pinconf_to_config_param(configs[i]); + ret = pinctrl_scmi_map_pinconf_type(param, &p_config_type[i]); + if (ret) { + dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); + goto free_config; + } + p_config_value[i] = pinconf_to_config_argument(configs[i]); + } + + ret = pinctrl_ops->settings_conf(pmx->ph, pin, PIN_TYPE, num_configs, + p_config_type, p_config_value); + if (ret) + dev_err(pmx->dev, "Error parsing config %d\n", ret); + +free_config: + pinctrl_scmi_free_configs(pctldev, num_configs, &p_config_type, + &p_config_value); + return ret; +} + +static int pinctrl_scmi_pinconf_group_set(struct pinctrl_dev *pctldev, + unsigned int group, + unsigned long *configs, + unsigned int num_configs) +{ + int i, ret; + struct scmi_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); + enum scmi_pinctrl_conf_type config_type[SCMI_NUM_CONFIGS]; + u32 config_value[SCMI_NUM_CONFIGS]; + enum scmi_pinctrl_conf_type *p_config_type = config_type; + u32 *p_config_value = config_value; + enum pin_config_param param; + + if (!configs || !num_configs) + return -EINVAL; + + ret = pinctrl_scmi_alloc_configs(pctldev, num_configs, &p_config_type, + &p_config_value); + if (ret) + return ret; + + for (i = 0; i < num_configs; i++) { + param = pinconf_to_config_param(configs[i]); + ret = pinctrl_scmi_map_pinconf_type(param, &p_config_type[i]); + if (ret) { + dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); + goto free_config; + } + + p_config_value[i] = pinconf_to_config_argument(configs[i]); + } + + ret = pinctrl_ops->settings_conf(pmx->ph, group, GROUP_TYPE, + num_configs, p_config_type, + p_config_value); + if (ret) + dev_err(pmx->dev, "Error parsing config %d", ret); + +free_config: + pinctrl_scmi_free_configs(pctldev, num_configs, &p_config_type, + &p_config_value); + 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; + enum scmi_pinctrl_conf_type type; + u32 config_value; + + if (!config) + return -EINVAL; + + config_type = pinconf_to_config_param(*config); + ret = pinctrl_scmi_map_pinconf_type(config_type, &type); + if (ret) { + dev_err(pmx->dev, "Error map pinconf_type %d\n", ret); + return ret; + } + + ret = pinctrl_ops->settings_get_one(pmx->ph, group, GROUP_TYPE, 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, + struct pinctrl_desc *desc) +{ + struct pinctrl_pin_desc *pins; + unsigned int npins; + int ret, i; + + npins = pinctrl_ops->count_get(pmx->ph, PIN_TYPE); + /* + * npins will never be zero, the scmi pinctrl driver has bailed out + * if npins is zero. + */ + pins = devm_kmalloc_array(pmx->dev, npins, sizeof(*pins), GFP_KERNEL); + if (!pins) + return -ENOMEM; + + for (i = 0; i < npins; i++) { + pins[i].number = i; + /* + * The memory for name is handled by the scmi firmware driver, + * no need free here + */ + ret = pinctrl_ops->name_get(pmx->ph, i, PIN_TYPE, &pins[i].name); + if (ret) + return dev_err_probe(pmx->dev, ret, + "Can't get name for pin %d", i); + } + + desc->npins = npins; + desc->pins = pins; + dev_dbg(pmx->dev, "got pins %u", npins); + + return 0; +} + +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->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); + 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->functions = devm_kcalloc(dev, pmx->nr_functions, + sizeof(*pmx->functions), GFP_KERNEL); + if (!pmx->functions) + return -ENOMEM; + + return pinctrl_enable(pmx->pctldev); +} + +static const struct scmi_device_id scmi_id_table[] = { + { SCMI_PROTOCOL_PINCTRL, "pinctrl" }, + { } +}; +MODULE_DEVICE_TABLE(scmi, scmi_id_table); + +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_AUTHOR("Peng Fan "); +MODULE_DESCRIPTION("ARM SCMI pin controller driver"); +MODULE_LICENSE("GPL");