From patchwork Wed Aug 3 05:47:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Foster X-Patchwork-Id: 12935207 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 AECF6C19F2D for ; Wed, 3 Aug 2022 05:49:04 +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=nwfuxZqsNa/Rltf1x/xC1sPcpnGsWKEnFNAG9ZKA2qU=; b=3aMO+U91GTTZVY ppAffsIbaKiQpkNG4eH0TY9+hB5LaiQus9otqGh7i7w40xI2duXmHjSZxZ4U9H5J8BlFYwwZaZR3x z83uhxe9dlQt1sXP9PH/OVprMB+PCRxfb8tcOj8Q3O5O+vNK2gii79kYkvYe3tWliS2D97N7yTawR qTt/QZmylLZ5Wifi+E+/49A9+JSvOCEZ1G5LJ1ihDs8K7o+oiJbhiskKLO0QZOQRTCnA4jmPn2kdz wBCrPw0AhjcLkNWbLuWt4ocafisRZ4/DfS+D3+q6+0J7Y5w4y2wpvlqlZa5HBJzNPKINZf73GLsxN EGDb+KTLPlQ7y5zz5nkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJ7Ea-002omu-Jb; Wed, 03 Aug 2022 05:47:56 +0000 Received: from mail-dm6nam11on2121.outbound.protection.outlook.com ([40.107.223.121] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJ7EV-002ohk-S5 for linux-arm-kernel@lists.infradead.org; Wed, 03 Aug 2022 05:47:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MopFt6CFo/1jwPN8RJYbSIC7ZbMyM+HBJ3Sqx8ro/Fto+mgyUKmTaCxIiNyHfjLoNEcWZYbhfK8qlXFL1B8hUKBnnW5IuJLi5LhKEVxzRXQTtobIeHNNTdu6BDCZQ2FY0GiWPEt3art/QC1IEJzAgNmkXH1diq7RfZwWzIclbWr4V1yIGoJVGty80NzWqkqed7cNbIpWCJjj6wCtiENzhtbxk2u48tPIlywWiNK+GUy7rzpUvCelw1KvB4vJP7TyuRMUijl/qBdEc8WW6LW39OBj0BHP2tPwB0P76HcNZt6XE0y8wZttRkiOlXA4/y6xYIXjpaA9FZhwFwmEIGw+SA== 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=5/XcCw7ZF/2dEB8dgem0EIgpd5fGnQGzsj6FzPHDvzU=; b=P1xjTSwkzakoLZYUv5TKE+NjrTUk0rgj3l+ttyoizUlTYhianNXZcQ3uYpKRZbRsrIynGy4RtXVT6DYkI5hPM9qlz/G43pKNhjl9J0Ri9udwxDYN46aYSOdM+JPhDh1zviRswtyYW2r42G0rKvticccclJ7krJPOowBWiVg2FKEm7hFdGU0BELqQSUb95qquFM/weCbWW2BcaHGFU/etiE3Kzg8FxwjcBl91yqTeP8m0juhe/jpBMNWioEUnMUGval+ljBlVQdXZuvZNC/4QV7f3K2+eUYCR0bXLG9CqVueeJPQ0wDPpqEIBq5E5D9G86BqTBkPwS3T0AQPd6Zo97A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=in-advantage.com; dmarc=pass action=none header.from=in-advantage.com; dkim=pass header.d=in-advantage.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inadvantage.onmicrosoft.com; s=selector2-inadvantage-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5/XcCw7ZF/2dEB8dgem0EIgpd5fGnQGzsj6FzPHDvzU=; b=Kltx0wvMQAO8mO0KGoFXzEK61vXVsRolEUYOhjD99S2BvOe42ZGDUnV8uRpQAG+Gg/JDaIRV8wu4h3MQRN92MGhaqCjdUMf6dd6YXx+K/W/6GAfBXnsWLIheeGXHl+6SbAMs5ArmUEZhRQjM7+p3+UPikYvLq5u3rxaRH8TShuM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=in-advantage.com; Received: from MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) by MW4PR10MB6438.namprd10.prod.outlook.com (2603:10b6:303:218::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Wed, 3 Aug 2022 05:47:44 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::b869:6c52:7a8d:ddee]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::b869:6c52:7a8d:ddee%4]) with mapi id 15.20.5482.014; Wed, 3 Aug 2022 05:47:44 +0000 From: Colin Foster To: linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Cc: Terry Bowman , Vladimir Oltean , Wolfram Sang , Andy Shevchenko , UNGLinuxDriver@microchip.com, Steen Hegelund , Lars Povlsen , Linus Walleij , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Russell King , Heiner Kallweit , Andrew Lunn , Krzysztof Kozlowski , Rob Herring , Lee Jones , katie.morris@in-advantage.com Subject: [PATCH v15 mfd 1/9] mfd: ocelot: add helper to get regmap from a resource Date: Tue, 2 Aug 2022 22:47:20 -0700 Message-Id: <20220803054728.1541104-2-colin.foster@in-advantage.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803054728.1541104-1-colin.foster@in-advantage.com> References: <20220803054728.1541104-1-colin.foster@in-advantage.com> X-ClientProxiedBy: BYAPR01CA0026.prod.exchangelabs.com (2603:10b6:a02:80::39) To MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00ab748f-59bc-49bc-633b-08da7513b00a X-MS-TrafficTypeDiagnostic: MW4PR10MB6438:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5dz8K3z0wr5aGwlQ8MN47Zf53V6b/phzNGtVMAWWm+xrT/uAXsDYSkT6g+19eRcFCwUsIidHfTBhkzCBTovo6S1vz9aw4Ia/LOs5AYqkwv9IZcwZzPGZxqyzEhkNkl8wrUnojMuTnXvsYXHW9brd2T8YNxlg7TQTHGlAwGdIbRGvEavqps1AcBFFuziou9S1RAlLAm+96Vov+ugF425UWOdZC3JvpqlgzRbTyxxcN2EcO+dn9dVbgH8rUc9IPrEyo4O1+GKxrCpim+6LIPZ6WEiWfDlPJjr0OD4gFv6w80rHUtHPL06TLYxMLz34JdtBBfjJ2rGeWNfMDG5fJm3dS/2CWqYNHWxl2zRS4LkH4cDfnq1STpouWbsqLNjSF2PuOgVN553+nu9x3+5AP/S/1AMJSYarU8+TzAamI40o8PyHrZL8cbFXvOarvyhfUL3ocLDehI4pK2M/E0WTMFm3jBAjrj6Egk1zMqGpHZE1pvqeu90QUNvqXWvyjqpVezYRS8XakJG7OMcDZ3ugByhfWEC+cKT+Ajt6OVt8/7KU8uMce+f+Murs2P/UAzKap2AquxwoEeInj/gqBw7uFX8z34N/Q8MfI3c65YQSnUTGtsf7YDSKOGTA8qW+YSs0T8XBVhXU977TJ9Ekt/MlIkrbUgY1UvGzW0uprj9DozsfRHIhLn+T/5qLoxC8Jn9mqOUdJck0ttm1H+ZepZyUgSZw4GsxLmc1mepM8oaeQhoXmj8WGU53NtZSudX6ZrQ42VlFDgxxexS2k01/FK4jK712SWF7eUnjJI3TMXV7//HABpc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2351.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(376002)(366004)(346002)(136003)(39830400003)(396003)(186003)(41300700001)(6666004)(2906002)(6512007)(26005)(52116002)(1076003)(6506007)(107886003)(2616005)(38350700002)(38100700002)(86362001)(83380400001)(5660300002)(36756003)(7416002)(6486002)(478600001)(8676002)(4326008)(66476007)(66556008)(66946007)(8936002)(44832011)(316002)(54906003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uxlS4Zcy0ZFe48H4Bv/c13Pa55HTP7CQtXhM1FMOuikz2mx4eFEnhJU3OF2NQ6wmQfWo0JQx8UXZ+SnOgeGtHetkD3gsnhyhfvXn3Wf0r75nVuFqpT8+mDVrH9OWv4NemVuh6eZwrqDDCks3w+9VR0Eme5IF8Z7upQp13p0wFFAS2f65GLdUUmqzAJcABwR2a7DZ+WcAfnqvxNINc1KQtwPSDD6zE5mtmbRxZ6H3s+KqcivfvBWS4rKXJcFxBrbhsxmte48uJQ6FtfovJjkZukW/zygt6quWnW+MYzkOG7Yl+4UMNsBRmCCaRoUTiXOo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VFzbFGqNTxphZ62JLfk6q5BMYsRMEBwfrMsEJUFUZmnWfvdMVuIxvu6nqrSJg2eZBqtfGCCzX7wx/29h0gHfiWXdg3GzLXjP3cqOnl824jrAEQ63k4M1s05cqK5RPYfMQLSgg42Mi2GsyxuaHpXidPDWVqBszHt4BW0L/q1vxrajkQOItfTXHL5m9iIjLbwCXadb871Hx1lBnrrq8VoG9gU3cXwaPLhDvrvnA== X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00ab748f-59bc-49bc-633b-08da7513b00a X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2022 05:47:44.6989 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 48e842ca-fbd8-4633-a79d-0c955a7d3aae X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bm/ti1ZaFhphUdZBQ30Cdh+xL2Trp9NtLxgFRNcT6bE8nC9AHYuZXC0cYvyUlwB86YI2FByGhpW+s+MrLUOkyIiCLlLpCTgj7scbPZ0eFPA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6438 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220802_224753_307506_16CFE4F9 X-CRM114-Status: GOOD ( 21.99 ) 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 Several ocelot-related modules are designed for MMIO / regmaps. As such, they often use a combination of devm_platform_get_and_ioremap_resource() and devm_regmap_init_mmio(). Operating in an MFD might be different, in that it could be memory mapped, or it could be SPI, I2C... In these cases a fallback to use IORESOURCE_REG instead of IORESOURCE_MEM becomes necessary. When this happens, there's redundant logic that needs to be implemented in every driver. In order to avoid this redundancy, utilize a single function that, if the MFD scenario is enabled, will perform this fallback logic. Signed-off-by: Colin Foster Reviewed-by: Vladimir Oltean Reviewed-by: Andy Shevchenko --- v15 * Add missed errno.h and ioport.h includes * Add () to function references in both the commit log and comments v14 * Add header guard * Change regs type from u32* to void* * Add Reviewed-by tag --- MAINTAINERS | 5 +++ include/linux/mfd/ocelot.h | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 include/linux/mfd/ocelot.h diff --git a/MAINTAINERS b/MAINTAINERS index 28108e4fdb8f..f781caceeb38 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14467,6 +14467,11 @@ F: net/dsa/tag_ocelot.c F: net/dsa/tag_ocelot_8021q.c F: tools/testing/selftests/drivers/net/ocelot/* +OCELOT EXTERNAL SWITCH CONTROL +M: Colin Foster +S: Supported +F: include/linux/mfd/ocelot.h + OCXL (Open Coherent Accelerator Processor Interface OpenCAPI) DRIVER M: Frederic Barrat M: Andrew Donnellan diff --git a/include/linux/mfd/ocelot.h b/include/linux/mfd/ocelot.h new file mode 100644 index 000000000000..dd72073d2d4f --- /dev/null +++ b/include/linux/mfd/ocelot.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2022 Innovative Advantage Inc. */ + +#ifndef _LINUX_MFD_OCELOT_H +#define _LINUX_MFD_OCELOT_H + +#include +#include +#include +#include +#include +#include + +struct resource; + +static inline struct regmap * +ocelot_regmap_from_resource_optional(struct platform_device *pdev, + unsigned int index, + const struct regmap_config *config) +{ + struct device *dev = &pdev->dev; + struct resource *res; + void __iomem *regs; + + /* + * Don't use _get_and_ioremap_resource() here, since that will invoke + * prints of "invalid resource" which will simply add confusion. + */ + res = platform_get_resource(pdev, IORESOURCE_MEM, index); + if (res) { + regs = devm_ioremap_resource(dev, res); + if (IS_ERR(regs)) + return ERR_CAST(regs); + return devm_regmap_init_mmio(dev, regs, config); + } + + /* + * Fall back to using REG and getting the resource from the parent + * device, which is possible in an MFD configuration + */ + if (dev->parent) { + res = platform_get_resource(pdev, IORESOURCE_REG, index); + if (!res) + return NULL; + + return dev_get_regmap(dev->parent, res->name); + } + + return NULL; +} + +static inline struct regmap * +ocelot_regmap_from_resource(struct platform_device *pdev, unsigned int index, + const struct regmap_config *config) +{ + struct regmap *map; + + map = ocelot_regmap_from_resource_optional(pdev, index, config); + return map ?: ERR_PTR(-ENOENT); +} + +#endif