From patchwork Thu Aug 4 18:49:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 12936613 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 CEB1CC19F2A for ; Thu, 4 Aug 2022 18:52:12 +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:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eF+DtUYaNUqiNTvT0+IrpZEp3dHRCTnvNwTykm5lYH8=; b=wjqE9rutpY9rug YR+XaVbLN3IFOxmck8KjUFwcovinV7reu2JYohsBQLxBzc0MtoId5Xb8k/gbJ5I5a5+egekOAigeH 9yIs5e4JcmPYO+G5pZGZTB50UgyE1v0WGyrSq0OaCbBvQzaeCXyFrHcDpwivd1VhOB5p2+16gU2Jh HXiVhOmntExI/u0pNEhPRgBhwJo5AInfa5c8CPmb6Q07weLHN74cnC4uGf8Qzsie9ovLqka3xJSKn jIDIuSf9L2mk9Hc7Em5YzhBkIvkv2/eyL5DruHw2LEzlI/JtLs5yyjrgDrZDPHUKaCzOb1G0ZARXT JlXHobiaGz2DMuOyYJUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJfvw-008LUw-8p; Thu, 04 Aug 2022 18:51:00 +0000 Received: from mail-eopbgr60040.outbound.protection.outlook.com ([40.107.6.40] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJfvS-008LFD-7O for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2022 18:50:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J8tkRYBzsqJK8h/O+5ImqkCmZNoZV4g9qdhvTmscAygcLQY+xQKfO5QSc4vElNGl7tiWxKvSYy+6mP8G9quIk9/S9tuIuYX9/Yyfr7gkH5/kbWq28NGra1owhTWgbIonue4sgZJ7klUURWSNPwRIlo6XMy744apE+q7R1ZNYi7gLTRzQUBpcWUTPbcoU48NxBDgnd/wy1GqidI5cFshECGbymXXDMlGl3o11domAzP+jH7zqTPFgqMC4U10iFSUBlHha9dxmtDf54qsiwH85O/DZu9vvocKtnFMtAhN7TEnP5Exht+uyeR/e6oz06rVmWv8BW0HSXb0oTJl1Fms4ag== 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=mSYlgki2uUy08cGzelO1onOjK1dHM751zgleNz3R62E=; b=VURCenFCpHbxgdRqXV2O/2Lee0G2+TTORey0arnsZTRcVaaGYNXsOoWAtYPFCdG93PXmjLr5wWMJ8Nj77ArKPlILD8FfzuV8IY6ESCcMSRLr/GcBgCq3d5zv+la9tM8twa/FQt7aKi+5HpqLpbrL1NuikCgq907avXJMewU1stz10ir0gfxZXYAw2UbofYLU/ueI4RDYCfRRP29iChmwy3puYh15w5dzKxjf4ji40f8H4plaqGd6xUPKjZb6qGdw3UdxJx6mpC2RlMIJm/ghCrjmaQuHC0Z/uyEhTxnR+72QJ6tbTiZz+6n2DNM/jY6gE5NBvstK/+eZ2FCeViry7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mSYlgki2uUy08cGzelO1onOjK1dHM751zgleNz3R62E=; b=BsfRMfW+9MENVWHogO/Vaggdz8AkFIK+tpUDtGA2KU1DTbPh1F0RE0rVSg11AAy+4YTFnyTJdZmgL82zF3UTs0ErcK9nypQN1TWGmKnmGy11QH7PGnN5Tetimn9+XL4xtCTiDfH6PUXwCuwVNnWIkNDTEH4VQLXwDdiqJ3HErDs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8274.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::23) by AM6PR04MB3992.eurprd04.prod.outlook.com (2603:10a6:209:50::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Thu, 4 Aug 2022 18:50:21 +0000 Received: from AM9PR04MB8274.eurprd04.prod.outlook.com ([fe80::747c:397f:a003:dbca]) by AM9PR04MB8274.eurprd04.prod.outlook.com ([fe80::747c:397f:a003:dbca%5]) with mapi id 15.20.5504.015; Thu, 4 Aug 2022 18:50:21 +0000 From: Shenwei Wang To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, linus.walleij@linaro.org, brgl@bgdev.pl, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Shenwei Wang Subject: [PATCH v1 3/3] firmware: imx: add imx-scu GPIO driver Date: Thu, 4 Aug 2022 13:49:08 -0500 Message-Id: <20220804184908.470216-4-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220804184908.470216-1-shenwei.wang@nxp.com> References: <20220804184908.470216-1-shenwei.wang@nxp.com> X-ClientProxiedBy: MN2PR03CA0029.namprd03.prod.outlook.com (2603:10b6:208:23a::34) To AM9PR04MB8274.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebc9bde4-dd0f-479a-a5a4-08da764a2eb3 X-MS-TrafficTypeDiagnostic: AM6PR04MB3992:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BLDdbOk+j/QfBGPTWHWi/mSohWRlO9E6vVdav2bwue5WMr3qXuY6re/yUREbveXG/xSrM4WznDFCkqEHn4HCYKKCPhTBvm30uPNjB3Vj0P0RfphJ4KvIM6u+jVILERZZ+uOmK+Ve2sdSaAfw9jALAYw63TVtRPGFcQ8+R0Ujfxr4ViYGprJhw/cXZeSsdGcVqS5IVwjCBkTAxcm4ykMhW/VydHE6mvrTylzzRlYcRevq/b9qcEVtWqXbBDuxqjA32Cws1vUXaesomXaGwPf10iYzmyBLbqCkJt45I74zbf7aDQoRI7wcX41ybWHYrXGO+9SWrzT0m7u6O54B0RJFVYN5W8vBmpfCa5pV/8DpYqTXcUljjDKBFacr6NwWGBB2sDtFTo214IdGZw2wt8KLIFOGFiz6eWsRF7oMRLc0ktOHZuTshdx6Vjtps/aVu6qcx+l4U4HVR10qN+5e2pVKJzcOxVFyhKoXp5/zdVuL5Blk7AeD0y/m/kiQ1+cYHZzkrvEFGFYznKOUwwJl+8O7Jftricu/ANnu1sRtcjIqD2vtjcqV8dsJyaEz7GDzXQwWnaevPM5ZYoGyBv+LVQw7JN80e643sA4FHOTNB+ufbTtvVubksNjtqSMB/dTEJQs/t8tJf/m36l4mzbrutCvqeU00vunxRKDJp7E2RGqRjenZRJ4eN7TRTXgneahocGR/8K6/W003BiOafLkXLlkc0mDeZB6cXOnfDpjs2c2WbEHRqvN8F0QHqVXw8u8mJggIwcK3MRiXNBLNwWlINdad6ARNEwbE8RlvWv2+aic8PSQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8274.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(136003)(346002)(366004)(396003)(376002)(2906002)(6636002)(36756003)(4326008)(8676002)(66946007)(38100700002)(66556008)(8936002)(316002)(66476007)(6486002)(38350700002)(6666004)(86362001)(52116002)(478600001)(6506007)(55236004)(26005)(6512007)(41300700001)(7416002)(5660300002)(44832011)(2616005)(186003)(1076003)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eE7qzfHdH7pnlMx1eSJb06ebrXQyJENCE+fj82Q+tnWWkRWoYTk4OrBxZMyik2rIZoteQ84DcRscQ6ktPLEl9yYmN80Qbb7+jizTkkltCh5YXIMOsmoZZQeWkhucBU7GffBA++Nw3GWc0iEUkKe/xh1DTbnszg9rk6SYXyyOYDIJRpQcuAzZndQu+AAK1Z30pYtnRQPhKyz+83FzJI9rmf352OCJGyYe7xkuAPmcnJ9MRJrlczHTOIb4CggFv8mPg+EiaKegVN2kpOUStvw0JwAjLYDvBxSnNO8yNcW865TYBwUIbecmHr27HSyywii4BpKYsOWTAM3L48eAEvcLm6X6xvu3I4UNHDCeMNQpYiO9w5gdZbtbXpKuRbk8LdcFsOyblrtSgxgbsZRzANw37bElp4emm+/hGzWrfdzKwGNI6RV1f0tkcgi9/+qwBO74BJvqapju/jJOIJXs2xol9yrDR7CIOxYmvbRT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gmzqFfBnws+R/SPaLHVAFCEcpXnu1mH X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebc9bde4-dd0f-479a-a5a4-08da764a2eb3 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8274.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2022 18:50:21.0466 (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: fBhUKRSmrjH432Z5msc4yxRMEml1aM1G/BwgztSilYmPAm3rW6DdHh2w8x/yA8SY8fW0ZxUroC96y6xGEExCzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB3992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_115030_308154_4D122FEA X-CRM114-Status: GOOD ( 23.43 ) 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 The SCU firmware on i.MX8 platforms provides a set of APIs to control the GPIO PINs on the SCU domain. This patch implements the standard GPIO driver interface to access those PINs on the SCU domain over the SCU APIs. Signed-off-by: Shenwei Wang --- drivers/firmware/imx/Kconfig | 6 ++ drivers/firmware/imx/Makefile | 1 + drivers/firmware/imx/imx-scu-gpio.c | 139 ++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 drivers/firmware/imx/imx-scu-gpio.c diff --git a/drivers/firmware/imx/Kconfig b/drivers/firmware/imx/Kconfig index c027d99f2a59..484c13f3149a 100644 --- a/drivers/firmware/imx/Kconfig +++ b/drivers/firmware/imx/Kconfig @@ -28,3 +28,9 @@ config IMX_SCU_PD depends on IMX_SCU help The System Controller Firmware (SCFW) based power domain driver. + +config IMX_SCU_GPIO + def_bool y + depends on IMX_SCU + help + Say Y here to enable the imx8 gpio over SCFW MISC API diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile index b76acbade2a0..436476502bd8 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o +obj-$(CONFIG_IMX_SCU_GPIO) += imx-scu-gpio.o obj-$(CONFIG_IMX_SCU_PD) += scu-pd.o diff --git a/drivers/firmware/imx/imx-scu-gpio.c b/drivers/firmware/imx/imx-scu-gpio.c new file mode 100644 index 000000000000..2f4a991a9ad6 --- /dev/null +++ b/drivers/firmware/imx/imx-scu-gpio.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021~2022 NXP + * + * The driver exports a standard gpiochip interface + * to control the PIN resources on SCU domain. + */ + +#include +#include +#include +#include +#include + +struct scu_gpio_priv { + struct gpio_chip chip; + struct mutex lock; + struct device *dev; + struct imx_sc_ipc *handle; +}; + +static unsigned int scu_rsrc_arr[] = { + IMX_SC_R_BOARD_R0, + IMX_SC_R_BOARD_R1, + IMX_SC_R_BOARD_R2, + IMX_SC_R_BOARD_R3, + IMX_SC_R_BOARD_R4, + IMX_SC_R_BOARD_R5, + IMX_SC_R_BOARD_R6, + IMX_SC_R_BOARD_R7, +}; + +static int imx_scu_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct scu_gpio_priv *priv = gpiochip_get_data(chip); + int level; + int err; + + if (offset >= chip->ngpio) + return -EINVAL; + + mutex_lock(&priv->lock); + + /* to read PIN state via scu api */ + err = imx_sc_misc_get_control(priv->handle, + scu_rsrc_arr[offset], 0, &level); + mutex_unlock(&priv->lock); + + if (err) { + dev_err(priv->dev, "SCU get failed: %d\n", err); + return err; + } + + return level; +} + +static void imx_scu_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) +{ + struct scu_gpio_priv *priv = gpiochip_get_data(chip); + int err; + + if (offset >= chip->ngpio) + return; + + mutex_lock(&priv->lock); + + /* to set PIN output level via scu api */ + err = imx_sc_misc_set_control(priv->handle, + scu_rsrc_arr[offset], 0, value); + mutex_unlock(&priv->lock); + + if (err) + dev_err(priv->dev, "SCU set (%d) failed: %d\n", + scu_rsrc_arr[offset], err); +} + +static int imx_scu_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) +{ + if (offset >= chip->ngpio) + return -EINVAL; + + return GPIO_LINE_DIRECTION_OUT; +} + +static int imx_scu_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct scu_gpio_priv *priv; + struct gpio_chip *gc; + int ret; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + ret = imx_scu_get_handle(&priv->handle); + if (ret) + return ret; + + priv->dev = dev; + mutex_init(&priv->lock); + + gc = &priv->chip; + gc->base = -1; + gc->parent = dev; + gc->ngpio = sizeof(scu_rsrc_arr)/sizeof(unsigned int); + gc->label = dev_name(dev); + gc->get = imx_scu_gpio_get; + gc->set = imx_scu_gpio_set; + gc->get_direction = imx_scu_gpio_get_direction; + + platform_set_drvdata(pdev, priv); + + return devm_gpiochip_add_data(dev, gc, priv); +} + +static const struct of_device_id imx_scu_gpio_dt_ids[] = { + { .compatible = "fsl,imx8-scu-gpio" }, + { /* sentinel */ } +}; + +static struct platform_driver imx_scu_gpio_driver = { + .driver = { + .name = "gpio-imx-scu", + .of_match_table = imx_scu_gpio_dt_ids, + }, + .probe = imx_scu_gpio_probe, +}; + +static int __init _imx_scu_gpio_init(void) +{ + return platform_driver_register(&imx_scu_gpio_driver); +} + +subsys_initcall_sync(_imx_scu_gpio_init); + +MODULE_AUTHOR("Shenwei Wang "); +MODULE_DESCRIPTION("NXP GPIO over IMX SCU API"); +MODULE_LICENSE("GPL");