From patchwork Sat Mar 23 12:15:14 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: 13600601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99EEBC54E58 for ; Sat, 23 Mar 2024 12:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=tOafxq2pcJxBKhqf/S3S3gPGC2+bN17DMqGq3iQQm3A=; b=W9dhlPih5DaRfkKQfJHAolOcU+ lpuImCBjjPaGmBjEBgpfQ7lv1YTTgFYP3vtyDDT1ocZi7bBu5fS5o5LeCjQtXpNyigqYvcSvfLpbj wNCrSgfS8Xopgz5aEGCHQz5/EillD440PGVk6Hf8PWcUfxQw34uS7VpGpF8RNUX0aMnna//LUa+tt 70MPaenzTc7uu0fG5zLAdJi7yrmj03PXkfDx4JJxa/unVJrPSK5CwAlkAEjKr0n9llUOZzkD5jWxP f644Q3YRfJY06HgWqAoqRhumPM+3oJPtI/m+eaUI2cNoJC7DYkjUqnOms2h1V5JPBAgrvbCLiVd0G AcDoM1ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0AB-0000000AJTq-2NBK; Sat, 23 Mar 2024 12:07:51 +0000 Received: from mail-db3eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0c::62a] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0A3-0000000AJPj-2kLM for linux-arm-kernel@lists.infradead.org; Sat, 23 Mar 2024 12:07:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OWC8998d4/pI5kq4SLBi89Fowcqov7SDx290PK1xRJ+ubxWFoB/yWbH9QLZWRorGtqlHyLJYABqD5FXD/XkDKsQgUDYKimfXBAXlalPvZAIJrYvPNkCFsKXUdWEVWoDBKM3wNAukmLUfm9oTiU//Kl4flp/DqtwYr/5arhR3xf66KX4Y1KkFGf9DibP9ri2T7fikKVlOWZUJkGH9AHSh5DpCPwxGgje4ejTcw4BOhyGxvjXY2iFwAFSSw9TQ/RKxmtGJTP0vTSDvxapNhqC4fxf2YZ+DZh6tGkEnmqmxciRPzBTQ7wK/71kj2Cj1U6dqbwdU/8biTynWwJOA3vNDMg== 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=DkhFzy347CReKh8Y/3De5x5m9e7u839I/9k6SdaIf8U=; b=fysKkYRANQSw3cjTQ08aC23Horpog23LBV8n7PGmAFCHsl3uSn/8s40/VpzWQBPqPzXVOiX4aE6T13oTPZq5XO3PmQd614qdkyjGJO2G5Y9yPH6pDLxbAUupXI2uTYIVJFmGRQ2E939Ow1AzPQl5i1AlQOtEOkxi9XCu6k5d2Fp72E/NOEPLxM3CcRy8xl3JDTavP+1DNCzbEQio8UQU2ShMgY7cEeTlL5+qfm5Hpp2cOpZMcN34S23bbPOgCD8v3jFyzpGMq3gnAUwI6E5QrUkvBW9rJlsszR9lUdeedizlob9OhfNLhBIph9sgf9NRtotNisX4S+Iv/T+J9VvhwA== 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=DkhFzy347CReKh8Y/3De5x5m9e7u839I/9k6SdaIf8U=; b=EpaWgE1ax3yjyWdWeWjxGXD+Z1A8d+a06yy7Up25D72VYNqFBnx28vsqvkAiM4WYT2kEEuNq+E+mcGtUfuphf5B4z2/0p8j+bNPACrDV4/fMVxD9PjvYe40pohCdJikqZqrk68889as2DOMqeF2JuBKn23SPGGlYJyyDDADDLSQ= 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 DU0PR04MB9585.eurprd04.prod.outlook.com (2603:10a6:10:316::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.26; Sat, 23 Mar 2024 12:07:30 +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.017; Sat, 23 Mar 2024 12:07:30 +0000 From: "Peng Fan (OSS)" Date: Sat, 23 Mar 2024 20:15:14 +0800 Subject: [PATCH v6 1/4] firmware: arm_scmi: introduce helper get_max_msg_size Message-Id: <20240323-pinctrl-scmi-v6-1-a895243257c0@nxp.com> References: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> In-Reply-To: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter 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=1711196144; l=2653; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=dKDsMHnM+cuvfvX6K6tAU3ADCasBJe+OHaz6qBQ1Tuc=; b=YCMLoesvvEksAchrZiSgtAE6+ph9Er9HhKtwRJucNf2NYbKuXTtNL5fw03vZ1EUKko+Dj5oF9 68c+d636v0yB4NTZRKEkdkYAxtLIs/XfPY6xpneKjzqpHkKhh/k4oh2 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR06CA0016.apcprd06.prod.outlook.com (2603:1096:4:186::22) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|DU0PR04MB9585:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a1593e5-55f2-44ae-9d65-08dc4b31d0a2 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: Gy8CVQWIGLPp+K5HqbgaT9+ZowM1+AiyJWp18+tQBA1SClBtvHab2OknIQ+IzYNupCzj6riOq+C4ktWfHNicbeHsU+G/b5v4Bp8Afn+Ra7dqvSYCBkrxfPxZwVg0sYy4O/WySCIxHtfmmVLKDhSZcE7JrSDswDSJZ6NtwUHzHOW540JS+baZgSvnCBF4yxOsgkM3mQw9qsLgU7peynatI2GbwJJBKIXfo5u3DKoEzLmqwm87AoP7drT/yPa7BXb0ny+hFCXRkFqVa1eMXSzoYVyrpzCUc3ishRVbNo8SPTUQXhRrlcDmXr66usDvCtjuA2ycgUZmIPQneoyOxY1R2z2jvNI+89JINcZJu2hKTA7GKuSQoKDzeAoT2Oi/Rp6h45GN2/W7e98l78OBdANC20R9yUW/N+Kyj6W7v21+pW5unvJ0y9DW1lE+l97VPOmk+hRc/Y6nhEGQ4vg1HjClBkXlEv50XHtvIxYyQaw2Kcr7m4vJgOo6azUjqjIXgtZjeHb8669aT6KNN6Im9tDj1+KDMFzQxIrQ17WQqLKKGvpfTLbl8gtRclfGYjCPQiDtHBbupbFRm0bsn5EbqytBssWo3OXHLRTfHJLoqc3m366I3GBOLKZUWhuHfCLrUAe8OE3WTS14FELYmRJIClD86sS6qt9lZ6cYjk1NlkvcbPuZeOxWfQ4TNVprVXjqCl2jEgVMLDNaqtS2I9thg+GfI6nrwPo9eRfCobQHb7WHxVk= 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)(366007)(52116005)(7416005)(1800799015)(376005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?FAJWMlb9K2dgRqWN4GKLUE9lLOEa?= =?utf-8?q?blm0xH2Al8DSOkewdp5H+Jp3KKzkI1DMZXSw6e8d9uzFQVMest3K95Vuq+Bis2Qb8?= =?utf-8?q?Z0p0FYtdJwgs7dma62VRArlUd69cKp0R/9wVuMxDIAfMVVBuFVHCcZwEue9rpKb7M?= =?utf-8?q?W82l3jXV4b2hvGJ0UnK1Mx4wTlFWd+VIGlkN/iJ7KIuo5irXcSzkilhG8JIDRM9Ik?= =?utf-8?q?i1SvTgDIYD2hTQtFE05AVTD+W0naDxIodQiLiZaKTO1HEYY8wbQpC0u+qF+8zJIm+?= =?utf-8?q?fY3RYEXLCog6poC+5rvEuI6JfpclcgXQL/cLZ1xFUbQRpBXlC/ePxP5HobuovE7gj?= =?utf-8?q?fTDCJg9/B/C3FTxz+zUiwpAErc/0f92q+Bom2FEJKTZeCduhHvWpKMi7CD+Ou+98y?= =?utf-8?q?9QlUs0+/wPipuDrF/7jpsrDJHfJnOACqF6n91GCngqcQNqw1z1qMVojBwOmIsIChG?= =?utf-8?q?lvJhOrO7k1JzWjoNCtT2aPgqecIECSiov4lQmacZUpb1k9diz2MAitKqiapqkDyIP?= =?utf-8?q?iq1t20aGKPrjejjHHUbG8Z6/btbDl8ryTd++Cx+oZZTVpB6B9qHPsfwl3FHWzmGLV?= =?utf-8?q?/FfG7TCqVl/ZIsLsvgctwzb/DPJ5To4zDxfAAlwBIakF8JhEPaZRh/nRtQo18gz/7?= =?utf-8?q?kUeGFh2KJb4E4BaJd2o2FMl/Opgig/EnO7euNKgbN3yB6DXTLoR64rKkMJKKSUjoG?= =?utf-8?q?s7eejpdyqcDOoJ8ybG38IHr9N0tJjpljZG4m0m3Dw3yVeTu+13KuGgnroMD+g8Tgm?= =?utf-8?q?6wERLiEewa+uhzV1T/DOj4StqjucGBY66uGBXiGVj8z50M5gW35EX+eq8yctFjANd?= =?utf-8?q?hjL3s64MftSTfaiF8WJLwgyJqoP4jUfIwNL32E6ES8gSXKXQCADrh8/tCKIpggDNL?= =?utf-8?q?TVyqdn41asiYjsrIba5XVsIlmSGUGq17mgEoVVzVMBep42WOpLcBJMBhvRpPuqBOB?= =?utf-8?q?q0zJVjuzbY15dYUlLHUM/f39+3yKk0fJGZsc1pEGTHf+ka89faRipFC0CH77A5IVu?= =?utf-8?q?LnMnCP1v6NjHVmJGbiv7WA8mBs2EJRlNVVeY+wjJluefGsaDGEcJLaW+wLatKge5g?= =?utf-8?q?B0icl+ig1/LwG9e3WL+dQ/vmPycB7IE4Mi9UvU2Az++zO3gV6pCE2onGAOwmBEXE0?= =?utf-8?q?gfVLytSxQ+HdDquNJp/FzX9f6PV4hRQ5xXrOSFztk4LIiltnqPdpIWpji9MWJTzJ6?= =?utf-8?q?UTi9L2dXvHkt/rI9QIu3xyHdxjdisNqw04w06s/5S22zRc6yvrj90+t7b5OtkKiHO?= =?utf-8?q?9cwSA6Xm0Er2JT4ntkX7TMHZON3fK/dXgOzGYrXhd00le/1KU62aHi4HZHYQ1FxR5?= =?utf-8?q?NfrIjxXl2NINenD1WkhmhaRhqW2FtEZmU51RlHcOOcvUd6VJ3/JQOh4DaAwwEuB/j?= =?utf-8?q?jbw47PKnsuDHw41jqJXRk+pQmsQQWp2WXyfnVLrPvC4s16qG9MtvkEIo37lJ+aMem?= =?utf-8?q?ISj8u3mU5++1NwN89SOkyMH1D9ECRtZypQw1LmfBNCr0jsc1gZcsiLpNK45N6cXsu?= =?utf-8?q?2KQ6W+wFGVKW?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a1593e5-55f2-44ae-9d65-08dc4b31d0a2 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2024 12:07:30.6439 (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: 7ZuPV+Bz+eYK+f54PpwXR8xbVhMFaNBJ4YRpv5U84XZFM6RgtYYiz4nHvyGhQsy+oyo28PqPX+zqumoiHWiH3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9585 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240323_050743_740785_149EC083 X-CRM114-Status: GOOD ( 11.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Reviewed-by: Cristian Marussi Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/driver.c | 15 +++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 2709598f3008..415e6f510057 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1488,6 +1488,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 @@ -1799,6 +1813,7 @@ static int scmi_protocol_msg_check(const struct scmi_protocol_handle *ph, 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, .protocol_msg_check = scmi_protocol_msg_check, diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index 317d3fb32676..3e91536a77a3 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -258,6 +258,7 @@ struct scmi_fc_info { * @fastchannel_init: A common helper used to initialize FC descriptors by * gathering FC descriptions from the SCMI platform server. * @fastchannel_db_ring: A common helper to ring a FC doorbell. + * @get_max_msg_size: A common helper to get the maximum message size. */ struct scmi_proto_helpers_ops { int (*extended_name_get)(const struct scmi_protocol_handle *ph, @@ -277,6 +278,7 @@ struct scmi_proto_helpers_ops { struct scmi_fc_db_info **p_db, u32 *rate_limit); void (*fastchannel_db_ring)(struct scmi_fc_db_info *db); + int (*get_max_msg_size)(const struct scmi_protocol_handle *ph); }; /** From patchwork Sat Mar 23 12:15:15 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: 13600602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F64CCD11BF for ; Sat, 23 Mar 2024 12:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3uVMD2uWMLWGzrxF7ffD5s+x32h+1pK32sZCWgZEigc=; b=mUixE+Tet3CDR1gtTUmU4IqRm6 Hx5P0OtE5LFgEmKPl58dYaMWFEOUkU+EwVY+FJlG1yDkn8pHrJlJVypaghBXNyeBjurkfBf2BtNNx iE/I06haU11aSih5T/JELZ+odo+sbIvVR81cgk0GQy175L/0rjTZp/2Hr4NsGXYyEo1ax+9yuNMgw ZIz4JNfvelzffNcKDSbNRZqi/d/WyFBnpHvgC1E4c9A1FPkw9rm/ZCXu7gu5pWBKhMq3RJXKSIDGS sGo6B/j2RZMLlcGyEWPcvEoPWK0mIE2bGNGWN940fWgCbO16NN/lLdOwMd+tVONzrpXNPCFiEcC2P w4Fk+vhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0AC-0000000AJUN-1LHl; Sat, 23 Mar 2024 12:07:52 +0000 Received: from mail-db3eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0c::62a] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0A5-0000000AJPj-0zhg for linux-arm-kernel@lists.infradead.org; Sat, 23 Mar 2024 12:07:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OZrXoPV1Ox9YoUNPV725caJnTOGcm0bOjIXNPejxkEluYEq+0ZNLRXVZIlTSnoAU/1tnZLJXOOgNUsx029Y1v/7xtDyQt7XjS4SRz6P4fu92gCrv1kr7XkIwM/JsllnZdrpGZMNYmXf7glGcslV3MpJkfpY42QnpGHPBJZ0Wrx4MzJ6Wx/K8yOtcgJpb0wCc8XOkRF32slmKTB6DjV8e2lJMzlwlbpBtFUzrAHpXI4EShMYZSHxsSdicrqB5Ao2plqacNTBZoxVdAiAmX1pDn7TFh9SbXQbSYyHlBxZRuikHCaW/g4z3aUVDAKazPdlActTDP2pHCl6CRhdq41v16w== 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=RT8nJ9OjroTHzLo2WWiFNUtZxE8os0XutrbQkVPdFxwAfzSSLNXQ8sK3/e9e0YsR3EDYD11mBz6cZGMy4aFZR3u7subR1O2NGIeME00LvM5biCXyuuTAVIPhXpjlvwDYa160q6r6xTnEM2UschvzRcce7Xx5W8IIlmWqKtWOlMiQLQ5w1Ve62GBQCIoUuZ89E2xrqJi+aK4tJNLJi0+dZu8KGT26VDoZ1TiALIk9e7gaf1qlHIyQNL2xL8Ma2LNwgv9cw9nkKyA0uM27wyIJYMrg7ch4T9FAVSuVcvXEJA6docW4bgUuGjMCy0MZpczS7BW35IxXFy9R9RlUGZ08hw== 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=AWSgKFFnY7wAIwtFl8pq6kLxVbiYAbmXRJKKKjRGFu9LndmmpWa10axMFJzk8YVqjm8f5873GeZJQ/6yCTK0WNNPVOAIb7JaTkQxhAzg7yqq1hgoyH7yrbsX2ZRSFaeLKM/KFajJCfUh6EqHRPjJcQzm6BGesP37To6DgVsmfpw= 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 DU0PR04MB9585.eurprd04.prod.outlook.com (2603:10a6:10:316::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.26; Sat, 23 Mar 2024 12:07:34 +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.017; Sat, 23 Mar 2024 12:07:34 +0000 From: "Peng Fan (OSS)" Date: Sat, 23 Mar 2024 20:15:15 +0800 Subject: [PATCH v6 2/4] dt-bindings: firmware: arm,scmi: support pinctrl protocol Message-Id: <20240323-pinctrl-scmi-v6-2-a895243257c0@nxp.com> References: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> In-Reply-To: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter 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=1711196144; l=2362; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=1H2rME0+2KWUaw0j7tYsXFokSaYx/bEPhCjn1uDoVYo=; b=yXDqUmMho1q94CJjUWs/Y4/Ta6joF+KXkrSg9P6VrL7fy/5buXTzXtrHYb9IXsx7mpsvaJqLs IjtBKb32BO9DH3eS7YvmO+lBHr7TajyVxhAL5h5s1Ys5b+1CPFBANt9 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR06CA0016.apcprd06.prod.outlook.com (2603:1096:4:186::22) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|DU0PR04MB9585:EE_ X-MS-Office365-Filtering-Correlation-Id: 19f366a0-a17e-4275-119e-08dc4b31d2e2 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: peanjtGePulBqxLzrCc44P9/HoOJ0WD16nGAf9FrMsdt4AA4Hgk8w2F5RHlg9+KqKKgvMMVxYc52t+w/kME/P+ch9GH7IvKn/a3dm7UDAPINymLJDn6GR9JGdoTjOReWhJcZ8qmy6RaScfvRn25emu+iu/ZBgGY3atpJUBU/C/VZiHCCFLNv26AoLCVC5CWx/1GERkNatQ3wEtFRdbwiYBZhM72Up+Or4FbTcl55Kv+YyhPUI9S/EBl7JC0/zhvO3BlPLnp0XMSHkpLYB0VbSNGZ3h8LRioNk6Bzo+Dd5dxoduKHqMowFxXtjHwDtcQ3iHN9xxdirX4muWFyVEfPiN1ofbtl9UzmbXUWhlFj/vtAzHhk9xAPF2mcHV0R2pdCS82D0XPcd+p8fp6ot8YnavBtZ6ZniIns3RZK6Qd7EQZfEtFAEVtf1ljJb/KC+tYBFbIDjEv5vflNQ3nShZE1ujoT70e/PBRlAVMWIsIhYIKYt6jX3Owk77WBjH2f+/vtMBs54wfjeBle3kH98MZRAUUpQYGXc0pKoF/9MALvMKgVojgr1HNjAktCCa6Bs4TzMS+aKotIrQqyFqu5/OMpTL6Oq1N67IcG13LcJkyCEKeOP91/O3V2YItMLLf3Yb/XEMEhkenl+hnsGLeuWk8zA7vyl5cHfIqDvq2BTGoK1jUFKqbx5Z3PHbtfrvb9FoS5lkLc49ll30PGAkQvGt9aDG2L4gtlDsI7n0/dp00bMiw= 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)(366007)(52116005)(7416005)(1800799015)(376005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?p0vrQXU0mc/H/rpaDCN9OIJdOj/j?= =?utf-8?q?YkslSOpT3cnRM18NmVTez9CI3bHqD4b8FsWQUTDKv3JsPusSueSHJihXGqFfxcKIv?= =?utf-8?q?YbzuuT2YXgxd6Pi5j5p4WxHKjBaaOQkR739SlZe6H1B5gXnvXjTXdMufOM8bZsRu0?= =?utf-8?q?I7hv9LNw66g2O+WbrDzI5ohIdXVAwri9y7cRo8sVeZ/LC/A+8gZgi83UoJLqNgoGc?= =?utf-8?q?SDyGAKNZX8NPYEXJNy8FG5zZeJrNB1TzhaKA+B+OVlQUf0CDADqaoq30KAKHyvk5b?= =?utf-8?q?H+TNKvAh3ZumiqJmWCi7SkB2Qni/k+Iz6Phtjzh7JqigJt+aXXBYlV4CmqQgzrEpd?= =?utf-8?q?Y/jP8V/byJ/ChMXWhXoEfJXhsy10k7QYMx9pmuLHuoTJ304pVhv+LDenKpB6UlUCF?= =?utf-8?q?axbKVeFnz2XrJMCrk66FvbjF4u+Uekqi5WA4lxqwvHrq8rTwG++emIfVYEiSbi4rL?= =?utf-8?q?e6EAk+612qxuopsP1KpZBTESrDcRewhDi7EExcueLJi5Hm8SziE4l28dTD/3rMkjN?= =?utf-8?q?qKStyFB0SJ62kkQ4UeSAnzQu8nkrV3AkHvIUeLLnSEL16ZRy48S0LIrfNSAtN2dtC?= =?utf-8?q?IG6sNwy7+7PvDdjI4Xbv3Mm9TlQ3SVCkOMkfI66WSYnQkxlzrN9JqdD5OvB2MXfuq?= =?utf-8?q?TXyqtMLJed+CkGsL3AIDSrteug8Ks1yW1JqbDy06jgsA9ir+/oVzPhul6zaVrSkEI?= =?utf-8?q?20A3umZSneEAc5ajMLx2zBYaJU2gnjVwGOafc4rK/Av1q5pXS0KiSb0dGSidpgPp9?= =?utf-8?q?L38f1xJe3iRk/2U1uPyVYQN2bSvOler4BEWud3DdOVrojCo2lqIbogJTfNDnaaW12?= =?utf-8?q?21GS8TPJFbHkc74an63jTv0VGunvBy6c5Kt3H/vdPvKPXd2gG06Q1AIG9pm9LMz+/?= =?utf-8?q?V1ltAODJcMGWKFkcgIQzXKeyIEoPRlQJEeQVxQpE4SWLsgDGlillj0ulju3v0SotJ?= =?utf-8?q?pYU9XQu3a0NB0OAbA+GZEt2Se87zwvO8qOiI13SbvJfXxZZOLpO4wgg7eSQIffp94?= =?utf-8?q?aA1ktSdKUDf4MO+WPWGqZ+gpvvFOwHv+cRKIsdrig38JaanzJSjs34kNU2gdqqwe9?= =?utf-8?q?dYUGRKws2rk2y9jd8Hcyj/jA3SSOlPR5frlxpT0VRiP6O2+6Rgl5RMw8fZofMCfRO?= =?utf-8?q?r9CEaC5PasNgT0D+cBZgrHsdxnRe8SLwJjUNW5VwZyMtt61vmWNjMvjMjoAGqnVA8?= =?utf-8?q?AyiYkAEgfjRDYeDpv84tmXrG29p2PPdqAouW1r4T9Y5erShGRptLQAfb8aOg399V1?= =?utf-8?q?kabNCb87bmOiiuT6d1AHwamtBMB3QZZ9uaPLB3WxYSzvOfK/XmFy4fO5kbA0hwLyj?= =?utf-8?q?IvHnre6axVEJ6dhf9lCYwsxJbMWIzOJdkgzW3c5Mxff2NQEVp1uz2RdXJOqaCMTI3?= =?utf-8?q?3e9MFqNzaBdtdB2IjX4X5DQYkMjf/g0avi9OqVMSZysegMkoS7rSZAYr67WmLD5vr?= =?utf-8?q?8ejoAK3gq7OT7oyZynX4RtOLyCtR8EOtc3V1NakV7VPQ/DJjYuPPpz2QeTxTrbaFQ?= =?utf-8?q?kmI1O6v+V4vu?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19f366a0-a17e-4275-119e-08dc4b31d2e2 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2024 12:07:34.4095 (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: 6GrA2U0ozlBnF0LQ6brQRQgSBryX8T/khWWcJm4Vjwx30FCQPSZKUDEnjna25+S65UW57mJstrd3w3D3PsjADg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9585 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240323_050745_334000_AF33B5BB X-CRM114-Status: UNSURE ( 9.57 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Sat Mar 23 12:15:16 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: 13600603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0A58CD11DB for ; Sat, 23 Mar 2024 12:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/90qhxLp0ovly8unlwjmrhiwPvBS6k8YbMxJCq/CYbg=; b=j/xv4CWUDWf9ydhW/lzXfd2Hsr oO2xiPgv2M2R3jZBwBvhCXLRuNUuLW0uyue2nRiyQTzvuxQrDcWUpC66PpBBlg1S0yP8lzTAlinUw QCbtRBYFfHeIO/YI0P6uCXS2muP1NHmQsp8TnXtdU7CBM5rcSSfgUS07VHhl3GJzg+thHDjYytGY8 zTXruQUbxQ/Aav38KlT78PkH5ynrrD515TkgPkxW8ELkVccA7+CMKqiFkAH1kUfonqDMtIn4qFWJc TcGsyKwD9ea40N0M1r0BobGR4PDca49hOCF52OkCZc8b7pB08z3vGgw2ktnEnm6GyuJfL+LzY8V7h UWLX5oaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0AD-0000000AJUl-0QDF; Sat, 23 Mar 2024 12:07:53 +0000 Received: from mail-db3eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0c::62a] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0A6-0000000AJPj-3edB for linux-arm-kernel@lists.infradead.org; Sat, 23 Mar 2024 12:07:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DF+BuFG8KV/kRp0mScuUrc4ITUnD8Ph811M07N+NyDvRC+kk/l7pnGuEhc1f8iGWMOnFjzsCt/uDR3KfH2Uwpk4WKgwuME+Gq+ncfsAA7cOTvVxLJaH7Fv8DhR3LTlPbtdSMng3k7ariougHU/6VaGhRf/odP+IewKP1YdhxUGZkyfaWyZAMacolECqnez6jtZMZpgnyiGw2Rke3gsdpGH3QP4krMckiyRUs92x1hRNbvNL9d1ugN2cxEzYpE7TtWuebidwg2t+E0nDOYsxzhrw50ID0APWaeeZku7rAjWirIbV8f244FtIdW+3xlpAqnlYKA3eOXE5BtClq+EWFeQ== 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=0W27TpMhgY/YI6AuFaAnNekWgbykmCcfjtmlhPY/368=; b=gKzCPGZQ2CbelzJdzFmD6StkOEMr7ISoH/xt1qblvRxj2sniNVkXp3R9lioCHI4u3icXQBHkUDdkUV6nKq+NxjG9C3TGBSk7VpVNzG6Tq66wwNynSJwGvvC3By2BeTYwUqqAEUewL5Qeyx5KLAJchl+iEWPsgIKpUpdm/1QFG7mdJp0TW/sT9sF5TH8EzbYZXD+SUU1670q54F7moDndH4oP1B1qzYeslDg2CWmOXZO7S/nbaV3m5ysCeCXLQz6ka3WEHOJwuzOHA3PCPNyM6kp4iS+s19Oi9nF4DYOFHUgJUCaWo24LzORETGGRZMmXyeZKbW53btEFQM3izeblow== 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=0W27TpMhgY/YI6AuFaAnNekWgbykmCcfjtmlhPY/368=; b=Ym7wp2f08M5nwBljyShW2I2kHO/KfH5snE6JFYJ1kALza6PXy2fZSQM1H1HyT/RvYsFv/n5ztxVlEtMepNBFl3oafAgjBuMZHQERHV5VFsWpOgJl/UoBPzSx6JsCJXMf/TIqwshX4xl+JWbTz5AZ48NY3lxvZauJBlopWQoMoDw= 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 DU0PR04MB9585.eurprd04.prod.outlook.com (2603:10a6:10:316::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.26; Sat, 23 Mar 2024 12:07: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.017; Sat, 23 Mar 2024 12:07:38 +0000 From: "Peng Fan (OSS)" Date: Sat, 23 Mar 2024 20:15:16 +0800 Subject: [PATCH v6 3/4] firmware: arm_scmi: Add SCMI v3.2 pincontrol protocol basic support Message-Id: <20240323-pinctrl-scmi-v6-3-a895243257c0@nxp.com> References: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> In-Reply-To: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter 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=1711196144; l=29007; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=8G94Udew3uI9UTCk8ZfwJwD1xyZ3uGcFc7OVM/iwQbI=; b=XghEVGNguvdXINQQRvFSQPrOHG1PizjcsyW+OcQlIJhnhTfDXPdkCLMYhFmfnEH2DrZ9snD7h l2vAve4CcaqBPJJEAKJYgM9n3fIcOlQFd132iUOBxQjYdHwTbItS7Vv X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR06CA0016.apcprd06.prod.outlook.com (2603:1096:4:186::22) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|DU0PR04MB9585:EE_ X-MS-Office365-Filtering-Correlation-Id: d7d3b143-05cb-4841-89e9-08dc4b31d552 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: ddI1N/xtvdr8EZv8RtZoIU7Te4Mmq89ZK/RTAUGWxK/ZvstPCevqgkDciIWfWj/Ln0v71XzxHFNUhu8D1CgWSFcYIIwEshQk1tnATcsUBfjxp2hTpb+4jwv5M2+t5dfnjJ8KOxfYyNpwaugA8U87uPKxKkIiylWyoDvIZd0VEgLvOlHnKs2PYD2HvTnOliNVeknNPJu8LObcYP9I6bIWTd2FLtpXj7Q1iDv2TTdxM9jZ4gYtnJcMPQeP39FnyWEkCU5Urcvhv/gdXVAtvcKzVzMHbGuefQoV4LdlVwackE44UTnusiE5VlphbapzRDWyQMNwwUPmp6irJE1gwoOsHhn5V+xb87VeH1gjx/8wCd11KYTct0wu8VOslujhCyTGE1J9ums5/XWJqo78/rw6mLvMgsR2Ihc0Mm6pH/2EmN0DWQYfnJP3vyYqQY2BCl8rRbD3uDP0qahB1UsSzcxWz9Qo3KlreowzgmtWAhlUWOdF0IKJ0E5rrhpEdNUYa9Oi97ODXIFS+MwsUwDmiEDk9sYY3p5qSUX0Qg+7l7xHEeHSR9g2rGO+penUPU8Ms4HJ6ItXmgZHhwoxrgyKOTxUceav4s9XkneucRwFRNG8Y2+PVy9B2hOfNFv0NIHjQoGudG8NyOPyCvYEZPpel799SPFNTIZxo1kCpCNJGRKzk5KM2Jol7B2kyMIC/9NHF9jfT+oZbdoT4Q70r9ISo+zA5yKSOuF/CbeeivRMRmYvbLU= 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)(366007)(52116005)(7416005)(1800799015)(376005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+J7i/niYLq+bF/FDlTjNWcOcWSOG?= =?utf-8?q?h/rQJpVwNDTlRYdmHFh+SJ9dXW+JDgAx/Pz50MyUTjHqSEy8emoNfHdEH3BTzNjuJ?= =?utf-8?q?J4vyP3bp0gbkUDJqcO0LBXLnD4Y96wsntALWFybe0lin35LjOw+ED2hp8646xHylM?= =?utf-8?q?Fj3mroBlmEmV02oj/3yoCOyHOnoQltKp5bW94rUJAmmPvC2j54Y7CJonoIPfsFLUb?= =?utf-8?q?URICNNcPDTXhyH07XIu98RuDAymacMqqyISso7sJ/t8Dc2a3DVBnRbwAvRtv1jjXB?= =?utf-8?q?zpeUycBzkl3nL1+8ebTAfrHwDlq+NnbEi4nLCl1qscQy+EEcHdEsYLTmio4JwWUR0?= =?utf-8?q?1QqVVVGYtMDNskgaJzIebAGVLEB1misR++CUASW469r33/kCVnu960QtetuJr6kxe?= =?utf-8?q?M/QpAmFFiO1bHZb6aEsRwIq+o/29IolUQy8A2XvkubLnf8iyarce5JAbtxMAmFZXD?= =?utf-8?q?hUbqdtycFXEermLfU/yjepbouFteLxGQzBCvSaEKtRQ3m+UoB7x0V9ONJgmCI1N7Q?= =?utf-8?q?YCyHPP0Wc1DHcNkb+U4xeXXs7+9Y9Wj9sUoIRjFg8jeX+vLyh8OcHeJHm0f5XOoiP?= =?utf-8?q?YWwzX6r7l5HP8E+aUKNQKC76jlrn5+QD+VoDDbZObXPWojaegreAjYvSEgaqIS2Py?= =?utf-8?q?UrDAC28SDS9f7M5QlQT4DKnh3nKmExOo/49B+KK+ELw5qGHZG7neI04nwzobvw4KV?= =?utf-8?q?h1pQDq53KVSPz5YfWa9PPw8P2nOs9H83uC1CPz8K0X/iB9x5UeAXmgxkAjVKU+zxl?= =?utf-8?q?TN6jYmgA5yuhFCMPMpf+4OIBRx/5/2u1A1p0ns+ZXfQOzRXIy1kSm0NbUYDGYvVTN?= =?utf-8?q?ALplczUP0wGB3Nqlt2pI7VQiyQ3etwZU4QtTJrPiwfhtE47Z5EvAEzl8/9WkoRDgr?= =?utf-8?q?in9M3Fm4ZATPvS+0W0vBipuKxrDR/53FFxy9BmTgBoNrlhr85cUSQQkOMnhvi3Ka3?= =?utf-8?q?S7xCdgFYtZCojEHNggImgW8z7WPAXapnPPneEWnep3pO+QsmUDnKw3H7l+3udt/XR?= =?utf-8?q?3eHUBsP1zgu4NlesVu9MebcweeqdRhn4dX5o12mhr6TwZ+U3VV5YxO0gp8/67QHAt?= =?utf-8?q?wa9P+SOEBaZvGCirm2NW0RIVjN8ExitXjPnF9RM8bDxpkC3/LmgTAfsQ6UKY8MHTN?= =?utf-8?q?4phzfeDO5Qpd2QlEAahTYJADr6nNbofhJ+8qWGTGBDarBvZd1P1lUHjLv/gP7GqEy?= =?utf-8?q?wPs0gPWKTpfdp7n6OftFViphuNbm9b6zKMSLr1s0ENkU8geSZDXLc+yHHLIkyzaYf?= =?utf-8?q?Mo5nzngOks0V0JKsLODJvo+kAyxV4wFUbEP6Wbu4ExrPJGpQAdozSFs3ZjA7Cwxa1?= =?utf-8?q?mMYvJn9yjP/vNb60Lt338J8RHBwUowBNRozOY/l6NLMk7Wvc8jPTsWlbdGpIs5B2r?= =?utf-8?q?quvIeQjeghykzE+7Nkif5OD/FzO6fSFklgB3LVNILgcFxFuIbwwYrtZbw+gxp4HLf?= =?utf-8?q?cYkv6RWL07P1EAdgtjt1lA+rJUsPc/Out/FHz7KbWMjhUTOVEBo+/Uc0pDfpwEo4+?= =?utf-8?q?sC/85YChkG6O?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7d3b143-05cb-4841-89e9-08dc4b31d552 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2024 12:07:38.5232 (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: fskmtEzB/r3AvVawzJZufKiz6erBc1hosnIlhRg6IGJdiB8ygarRgbPeVQNHPU69G6O0IK95hI7KminAwCZZCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9585 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240323_050747_282521_26360C2E X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan Add basic implementation of the SCMI v3.2 pincontrol protocol. Co-developed-by: Oleksii Moisieiev Signed-off-by: Oleksii Moisieiev Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/driver.c | 2 + drivers/firmware/arm_scmi/pinctrl.c | 921 ++++++++++++++++++++++++++++++++++ drivers/firmware/arm_scmi/protocols.h | 1 + include/linux/scmi_protocol.h | 75 +++ 5 files changed, 1000 insertions(+) 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 415e6f510057..ac2d4b19727c 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -3142,6 +3142,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); } @@ -3159,6 +3160,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..87d9b89cab13 --- /dev/null +++ b/drivers/firmware/arm_scmi/pinctrl.c @@ -0,0 +1,921 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Management Interface (SCMI) Pinctrl Protocol + * + * Copyright (C) 2024 EPAM + * Copyright 2024 NXP + */ + +#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 0x0 + +#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)) + +#define CONFIG_FLAG_MASK GENMASK(19, 18) +#define SELECTOR_MASK GENMASK(17, 16) +#define SKIP_CONFIGS_MASK GENMASK(15, 8) +#define CONFIG_TYPE_MASK GENMASK(7, 0) + +enum scmi_pinctrl_protocol_cmd { + PINCTRL_ATTRIBUTES = 0x3, + PINCTRL_LIST_ASSOCIATIONS = 0x4, + PINCTRL_SETTINGS_GET = 0x5, + PINCTRL_SETTINGS_CONFIGURE = 0x6, + PINCTRL_REQUEST = 0x7, + PINCTRL_RELEASE = 0x8, + PINCTRL_NAME_GET = 0x9, + PINCTRL_SET_PERMISSIONS = 0xa +}; + +struct scmi_msg_settings_conf { + __le32 identifier; + __le32 function_id; + __le32 attributes; + __le32 configs[]; +}; + +struct scmi_msg_settings_get { + __le32 identifier; + __le32 attributes; +}; + +struct scmi_resp_settings_get { + __le32 function_selected; + __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; + u32 *group_pins; + u32 nr_pins; +}; + +struct scmi_function_info { + char name[SCMI_MAX_STR_SIZE]; + bool present; + u32 *groups; + u32 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, + u32 *n_elems) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_pinctrl_attributes *tx; + struct scmi_resp_pinctrl_attributes *rx; + u32 ext_name_flag; + + 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); + + ext_name_flag = EXT_NAME_FLAG(rx->attributes); + } else + ext_name_flag = 0; + + 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) + 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; + u32 *array; +}; + +static void iter_pinctrl_assoc_prepare_message(void *message, + u32 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, u32 *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_settings_get_ipriv { + u32 selector; + enum scmi_pinctrl_selector_type type; + u32 flag; + enum scmi_pinctrl_conf_type *config_types; + u32 *config_values; +}; + +static void +iter_pinctrl_settings_get_prepare_message(void *message, u32 desc_index, + const void *priv) +{ + struct scmi_msg_settings_get *msg = message; + const struct scmi_settings_get_ipriv *p = priv; + u32 attributes; + + attributes = FIELD_PREP(CONFIG_FLAG_MASK, p->flag) | + FIELD_PREP(SELECTOR_MASK, p->type); + + if (p->flag == 1) + attributes |= FIELD_PREP(SKIP_CONFIGS_MASK, desc_index); + else if (!p->flag) + attributes |= FIELD_PREP(CONFIG_TYPE_MASK, p->config_types[0]); + + msg->attributes = cpu_to_le32(attributes); + msg->identifier = cpu_to_le32(p->selector); +} + +static int +iter_pinctrl_settings_get_update_state(struct scmi_iterator_state *st, + const void *response, void *priv) +{ + const struct scmi_resp_settings_get *r = response; + struct scmi_settings_get_ipriv *p = priv; + + if (p->flag == 1) { + st->num_returned = le32_get_bits(r->num_configs, GENMASK(7, 0)); + st->num_remaining = le32_get_bits(r->num_configs, + GENMASK(31, 24)); + } else { + st->num_returned = 1; + st->num_remaining = 0; + } + + return 0; +} + +static int +iter_pinctrl_settings_get_process_response(const struct scmi_protocol_handle *ph, + const void *response, + struct scmi_iterator_state *st, + void *priv) +{ + const struct scmi_resp_settings_get *r = response; + struct scmi_settings_get_ipriv *p = priv; + + if (!p->flag) { + if (p->config_types[0] != + le32_get_bits(r->configs[st->loop_idx * 2], GENMASK(7, 0))) + return -EINVAL; + } else if (p->flag == 1) { + p->config_types[st->desc_index + st->loop_idx] = + le32_get_bits(r->configs[st->loop_idx * 2], + GENMASK(7, 0)); + } else if (p->flag == 2) { + return 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_settings_get(const struct scmi_protocol_handle *ph, u32 selector, + enum scmi_pinctrl_selector_type type, + enum scmi_pinctrl_conf_type config_type, + u32 *config_value) +{ + int ret; + void *iter; + struct scmi_iterator_ops ops = { + .prepare_message = iter_pinctrl_settings_get_prepare_message, + .update_state = iter_pinctrl_settings_get_update_state, + .process_response = iter_pinctrl_settings_get_process_response, + }; + struct scmi_settings_get_ipriv ipriv = { + .selector = selector, + .type = type, + .flag = 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_SETTINGS_GET, + sizeof(struct scmi_msg_settings_get), + &ipriv); + + if (IS_ERR(iter)) + return PTR_ERR(iter); + + return ph->hops->iter_response_run(iter); +} + +static int +scmi_pinctrl_settings_conf(const struct scmi_protocol_handle *ph, + u32 selector, + enum scmi_pinctrl_selector_type type, + u32 nr_configs, + enum scmi_pinctrl_conf_type *config_type, + u32 *config_value) +{ + struct scmi_xfer *t; + struct scmi_msg_settings_conf *tx; + u32 attributes; + int ret, i; + u32 configs_in_chunk, conf_num = 0; + u32 chunk; + int max_msg_size = ph->hops->get_max_msg_size(ph); + + if (!config_type || !config_value || 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(__le32) * 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_SETTINGS_CONFIGURE, + sizeof(*tx) + + chunk * 2 * sizeof(__le32), + 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(config_type[conf_num + i]); + tx->configs[i * 2 + 1] = + cpu_to_le32(config_value[conf_num + 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 group, + enum scmi_pinctrl_selector_type type, + u32 function_id) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_settings_conf *tx; + u32 attributes; + + ret = scmi_pinctrl_validate_id(ph, group, type); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, PINCTRL_SETTINGS_CONFIGURE, + sizeof(*tx), 0, &t); + if (ret) + return ret; + + tx = t->tx.buf; + tx->identifier = cpu_to_le32(group); + tx->function_id = cpu_to_le32(function_id); + attributes = FIELD_PREP(GENMASK(1, 0), type) | BIT(10); + tx->attributes = cpu_to_le32(attributes); + + 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); + if (ret) + return ret; + + 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); + if (ret) + return ret; + + 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 u32 **pins, + u32 *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, u32 *nr_groups, + const u32 **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, + .settings_get = scmi_pinctrl_settings_get, + .settings_conf = scmi_pinctrl_settings_conf, + .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 3e91536a77a3..c02cbfd2bb03 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -355,6 +355,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 b807141acc14..64043e269701 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -737,6 +737,80 @@ struct scmi_powercap_proto_ops { u32 *power_thresh_high); }; +enum scmi_pinctrl_selector_type { + PIN_TYPE = 0, + GROUP_TYPE, + FUNCTION_TYPE, +}; + +enum scmi_pinctrl_conf_type { + SCMI_PIN_DEFAULT = 0, + SCMI_PIN_BIAS_BUS_HOLD = 1, + SCMI_PIN_BIAS_DISABLE = 2, + SCMI_PIN_BIAS_HIGH_IMPEDANCE = 3, + SCMI_PIN_BIAS_PULL_UP = 4, + SCMI_PIN_BIAS_PULL_DEFAULT = 5, + SCMI_PIN_BIAS_PULL_DOWN = 6, + SCMI_PIN_DRIVE_OPEN_DRAIN = 7, + SCMI_PIN_DRIVE_OPEN_SOURCE = 8, + SCMI_PIN_DRIVE_PUSH_PULL = 9, + SCMI_PIN_DRIVE_STRENGTH = 10, + SCMI_PIN_INPUT_DEBOUNCE = 11, + SCMI_PIN_INPUT_MODE = 12, + SCMI_PIN_PULL_MODE = 13, + SCMI_PIN_INPUT_VALUE = 14, + SCMI_PIN_INPUT_SCHMITT = 15, + SCMI_PIN_LOW_POWER_MODE = 16, + SCMI_PIN_OUTPUT_MODE = 17, + SCMI_PIN_OUTPUT_VALUE = 18, + SCMI_PIN_POWER_SOURCE = 19, + SCMI_PIN_SLEW_RATE = 20, + SCMI_PIN_OEM_START = 192, + SCMI_PIN_OEM_END = 255, +}; + +/** + * 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 (*settings_get)(const struct scmi_protocol_handle *ph, u32 selector, + enum scmi_pinctrl_selector_type type, + enum scmi_pinctrl_conf_type config_type, + u32 *config_value); + int (*settings_conf)(const struct scmi_protocol_handle *ph, + u32 selector, enum scmi_pinctrl_selector_type type, + unsigned int nr_configs, + enum scmi_pinctrl_conf_type *config_type, + u32 *config_value); + 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 @@ -844,6 +918,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 Sat Mar 23 12:15:17 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: 13600604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB59BC54E58 for ; Sat, 23 Mar 2024 12:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rWbZtNpzwRlSj717/EAJPLQXh2SK9lJkTejMllV1D4c=; b=NTmu3Dxs70f9zRu6Yl963y427r sV3nJFk7z//jiGXJCoKYkfS83rq9h2TrjICQo9cqq0v3m18idoBVVaPP0OsNSW/igxDNgzQu8sx52 6BGTRejaknv3tR6X4Fx4ZUlrOOU1l9evh0db0Szt4NMg0bExLjl957HrOB9A5Ebj63O/Zf8uVj791 XZrWe2/WVaZXNdozxTCODJgNQD6fWXk88O5HHN8bkn1VG5Q+/9mJyY0KpC9gxNtqmtgOVAYHnSGiu TymVMOjhGZ6IU4w61+UKfntvRy/dt2h8dRpyWRPw4owtIdGnGguwvTV58XAlsA3QLUThVtYOlsqcl Kb1SAYLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0Ac-0000000AJiq-332J; Sat, 23 Mar 2024 12:08:18 +0000 Received: from mail-db3eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0c::62a] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ro0AA-0000000AJPj-1uSA for linux-arm-kernel@lists.infradead.org; Sat, 23 Mar 2024 12:07:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U+Kdy+q/UhTCbpuSKdf5IZ83UTKEaj8O2nmgPz9V77HS2vm/LJ1phTLbFeO/XiMprOupIs9YXfaBBXHeNEPyXyK1VqkAaxX2JRWnOa6sRr6UfX+5zFsz4BAiEiaeFpjNbulXEyA+o7xMWeOMALPqAR+/OFCJYee0yFVQ1IiYKTA/eHnmSMdfS49UPxv6cyTayHglBpo0318dyn2q1jVoOiJEx07SQFiHcndKM1Yxq7cE3fkUNTY0kAovPGa7T1U+EdsSx7imiIxDxKjgUBFI3Y+X6zANVIs+BQQDPvGPDnrBu1ey1Z6tP5BJwHMT7bfEHKP2nOC7SZjRBvL3T8MEnQ== 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=nHNPcWftLWLkAPGzxEJd0Ra+N8iCWeIB6WzKxpGVt0E=; b=Et6eHrD2l6McztzjnX5iqurfuEWnsxTbN53F/EV1w/Xxb7MZkjJOYM58QFXUVtsmn9LFmkSCkYiSOPkwdUEdk7VQC8MCXfk6SB77BiD+25LwaWpjD/nL8jNaLC9Kw7SUdPl/SK6j9Akl/NUJsEzHudoRY9xbU5ZhNnt2TPcdciB7uODaBYCQBbNTrDm1OeF/ZZWXewhtF21GJlb8GbD7xxwcBWwPrVYl6s6GgOnLsy3YWdFEvvq5xsp7Wjtie0D/4Q8uAt5gnbHBXqfYUbWzlgqNowIAwvnTW9AN+ia/k4KW1LrjfnRpRMfrVLEu3DDlyEiHDBk6xaEHamqIgjpO0Q== 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=nHNPcWftLWLkAPGzxEJd0Ra+N8iCWeIB6WzKxpGVt0E=; b=HDtr/cMl4fwvn5rJLFMLMpn7u3/uB3cRP66ibDKmUi8GE3afgv+nRMkHE3Gp/jf6iuPOXQ0Rqr0pXye7rwf5gpOsn2RzSvZvF3x0P5hTw5DJ85UKuxJlrWQqhDt3/8ABtuOCElFlqTYiUncu+fbN66+CKfhJr87ooetF+JCARn4= 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 DU0PR04MB9585.eurprd04.prod.outlook.com (2603:10a6:10:316::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.26; Sat, 23 Mar 2024 12:07:42 +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.017; Sat, 23 Mar 2024 12:07:42 +0000 From: "Peng Fan (OSS)" Date: Sat, 23 Mar 2024 20:15:17 +0800 Subject: [PATCH v6 4/4] pinctrl: Implementation of the generic scmi-pinctrl driver Message-Id: <20240323-pinctrl-scmi-v6-4-a895243257c0@nxp.com> References: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> In-Reply-To: <20240323-pinctrl-scmi-v6-0-a895243257c0@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Dan Carpenter 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=1711196144; l=18822; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=CC/Ed22/gPMkDQdaZQ+VKjMKDbtmNv4mvTyv3eV3s0k=; b=gInnj1qN5lHrtMY6nUSCvkbArwX9FYihGGSeC1LOyi/qOPkULWdmNyWxLeBsxIYIuO+wH/lKA 28fRJNb7Iy5BUFEcm4VFruwUycDMAPYUwqkOOco2CROj/jPb0EFY30U X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR06CA0016.apcprd06.prod.outlook.com (2603:1096:4:186::22) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|DU0PR04MB9585:EE_ X-MS-Office365-Filtering-Correlation-Id: aba87ca8-2571-43ff-3e90-08dc4b31d7b8 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: oVNBUvxCq+XlroWBY6CXF2C0Vf2t1XoqD24Gz9KToB/z06JOoksXrbp6XUax5U9KJBfY5fALYGl27G5DK+t8+5DeXkTBHEBWM5c5RncU2rXgLBhJPhspWj+NehczObsdBziExpAkaY2en+1osXEA/9CvlGJhjKbH336B2xEh4hkp8g3nn1Be0bm570X5PFN2VHqrH7vJvuqkzP1LKRiwoHLN5utalxo3fCBZazzWDW/6QGbb+9zf79ocOP/Pu3OiFuQLOxEFnQPEiN5x0iwIStNs4XuHBNkiLJMCymO0r5Gy/7dkrXhT3dayyqTB3TEQOVt6yn0EYrw7R2jr1PIt7SNeUsRf2/BX1vpScPEinNAMT1dsoX6nBynY27GNpreGLfFOFY4zcwHD5BE1wCI6nJiJtG0aGosOhS18slHI+G5BDU4sbJq+TjK2aHl1xyPH1aQ3RP6KspM9b7SE38QJwpb1rylVOVz4NuWV38kARvHkux7rXNGlcayOyGpjPJXi18Oh5ZY2ZdtywGw3FX4ixXOAC3YdWXIPcYJRuxnPRuhFoqcFpFUelm4l0gaf84qub3Fkffi9dYRccYQsaPMq3StbgmIe3wMFP3hUaXF4+Aw6eocmDt+dHI33Hn3DnxWqgKxgyIfWhAsubjG/sZX19evqSOLoZeI0TjhtC7pHOyO0wZ8I259q+qWhV8qO0OCz1WP5jrW8c7Tp5cPAaEw7gGzAJmeJTzB1qrxu/WdVcn0= 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)(366007)(52116005)(7416005)(1800799015)(376005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xFKVwLjve9MQ2ENiXHuwlE71pCh3?= =?utf-8?q?7nCLablnmj/1VBZLGZHn/DAWkjMJhL3DvSMMFgZX89DSOQjOaYj/v0CESCbqL1fle?= =?utf-8?q?KZudNC8EUQa1A0C/OL+ReU9OESSevfuP3d5QKjL/0D5Xgs0jf12bbAZVlEV62BhjK?= =?utf-8?q?NAo2RY+W2ngFOMzzO2Tv77prVnhEF+qsLmwWHubgVlGcYcjWWcyPzGY3Sh4sHGObh?= =?utf-8?q?7JgUosnfn+Y1QchM+upR9q80DDFENCDNxFvWrDGJDOGNbXxLAPYDM/AEpLCyA+sPJ?= =?utf-8?q?qORSfQOXnVSUH493zzYP3X8E2addD1KaPeGIOP5XCKt5i5ntqDrVLDvSkxGWRb+f5?= =?utf-8?q?5zAl++R4o8BwbuGL0KarC/+ItfmpI9/P/bflJLRyv9P4cnussc20OHxc7bOvpLZyq?= =?utf-8?q?Oj2DWUrA0ulRnxFQ5l66emjscxREkttS8iylYOK2fEwNAbk5ePaE6zcrL3g/DqaTY?= =?utf-8?q?83aVGi3BvRcEP0WS10JctrKUvG7ufuIjxa9LQbTPqU5vz49NcnyhHThH//5b+pHbN?= =?utf-8?q?67Ox+hygDcSEFR2PMU6DGNeSolqiQ/wGzCcwKvZ59w62dJf4m3Y5o72pMHHBkyBaC?= =?utf-8?q?LXduJ+qpjq5zzINv5wFvURHVTk3PXp73zoyB2ZErDMVFRK89IcPx9/anuNZckzZCd?= =?utf-8?q?P0f4MVQSNf6xD9I3zOB3XwT6yfU0AbbrO/JO86p/6gaZDg8+emDPnDFPtQaJB70Cs?= =?utf-8?q?zdRSyKfoyPJ9W4qAy1UwkrjgGE/0cujYgF+uCH/Gces0fUZKuBa/QGfpsMEUT5nd6?= =?utf-8?q?T9Nek6bJcvRpCXjDY0HevD/Zqs35xGA47D3MthMXxm34YHHHC7N/YQlWyb6C1NnOu?= =?utf-8?q?bzAotb+nIuZg7g6C1bF8tp5izCE8jEkDVm6t0yX85hcMERYrroIYyTbMc1eF3zOvp?= =?utf-8?q?+n03yutQc6bddv/4priuvb41MR1fdRnIJzmKr9Y8LaeJj1RdWAWiYmOO7StmEjEUI?= =?utf-8?q?ZzmlaeeAzFChbwezFRRkQovriD6WPMRVVJtwdaY+irPyODoAIkC/bxbiaPzQBqEp1?= =?utf-8?q?d351RPNfM9tLrQKEQfuv8KONmKgs9AAxUWZOs9fRHWGdeBexcM1Ltu5hbDihdGHbA?= =?utf-8?q?n0qoRRX+JKlu3GhhArxpiyutc9qeBx9FZjiehskjZqx97aLk2BgcyfGD4Vwl/QAvQ?= =?utf-8?q?Sc08j/4aNYjfQybwhMIHhkNKEu1Cnyg9unOaYcitMQsib3FI5/hU80z60MWMRQAVn?= =?utf-8?q?2N2+OUxYoZNq+5JOYARZFrAsfgm3RH+XFUNrq4Jpj6aTT3tBRjibH+se2oD83tso6?= =?utf-8?q?2vmB0Wcb7pBBED3P0J1L04w5Mz1ZKeVLNU8RHrc0gqGP3rOLkqA4sefLnolmmE4mr?= =?utf-8?q?ME7Celn5JkqxZCTcj5KISERJEjZCv+SuD1oboKngiehvIHM9wS66yKdFTnFHyYgft?= =?utf-8?q?OIbQTP4Uj6v3m/o/5Gnf1ck6hNUJKh4WWF1c7n4ZIhNrekJeATSWh4B+mO24/Haoq?= =?utf-8?q?fmGMaq5SBEGaruwWnNZ2LQaPKH2jFR2fNL1ntg04kDkxclz+OIhsBt3fABHIDFoze?= =?utf-8?q?tk6IX/cKkbfl?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aba87ca8-2571-43ff-3e90-08dc4b31d7b8 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2024 12:07:42.6198 (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: 6iAnwUM82qpPQcplqnNLKD7fP7q27LvhiuO/AnIjQZ5QNulyhhdD5jInPViMuiqIcHaTMe5HWyxYur30eYJUpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9585 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240323_050750_583450_1B5C7DDC X-CRM114-Status: GOOD ( 17.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/firmware/arm_scmi/pinctrl.c | 1 + drivers/pinctrl/Kconfig | 11 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-scmi.c | 564 ++++++++++++++++++++++++++++++++++++ 5 files changed, 578 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/firmware/arm_scmi/pinctrl.c b/drivers/firmware/arm_scmi/pinctrl.c index 87d9b89cab13..0ecefe855432 100644 --- a/drivers/firmware/arm_scmi/pinctrl.c +++ b/drivers/firmware/arm_scmi/pinctrl.c @@ -465,6 +465,7 @@ scmi_pinctrl_settings_conf(const struct scmi_protocol_handle *ph, tx = t->tx.buf; tx->identifier = cpu_to_le32(selector); + tx->function_id = cpu_to_le32(0xFFFFFFFF); attributes = FIELD_PREP(GENMASK(1, 0), type) | FIELD_PREP(GENMASK(9, 2), chunk); tx->attributes = cpu_to_le32(attributes); 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..b23533bff63a --- /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 "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_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; + 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 scmi_pinctrl_funcs *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->num_groups) + 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 = devm_kcalloc(pmx->dev, 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->num_groups = num_groups; + func->groups = groups; +done: + *p_groups = (const char * const *)func->groups; + *p_num_groups = func->num_groups; + + return 0; + +err_free: + devm_kfree(pmx->dev, 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(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(u32), GFP_KERNEL); + *p_config_type = kcalloc(num_configs, + sizeof(enum scmi_pinctrl_conf_type), + GFP_KERNEL); + + if (!*p_config_value || !*p_config_type) { + kfree(*p_config_value); + kfree(*p_config_type); + 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(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); + 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; + 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 %d", npins); + + 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); + 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 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");