Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp178373imn; Tue, 2 Aug 2022 22:50:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBmaz+opMkkYXydagJVm0w+D36D0yB4tlCpg6LSMAPxq9/KbpLZMcxbdGce2PhPx+mRiNe X-Received: by 2002:aa7:dc12:0:b0:43b:5d77:f0b with SMTP id b18-20020aa7dc12000000b0043b5d770f0bmr24325962edu.37.1659505813734; Tue, 02 Aug 2022 22:50:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659505813; cv=pass; d=google.com; s=arc-20160816; b=kOw0rmTvA3H0ai0sSmT2sJbbaBYcCVi+ooaeuDwhQQXBN6d/nTf4GyHuMpLqqvHH97 pfhwwBjV5M2u9NElRl/naAZh0iAN5qySP0JUM59/z9+XN1u+tIrxB+uzUhvf4koEsVTT 4FuA5Kw/2+t9lW2Q9gEZDAxhiU1HW7avRPKMJ+0E2xVG80e2QM3tRQlHGjTcDTvWdDN/ DejFln07kfKSNL9HRpMglFk7H6LlbpbInA8TTXW6TUCVIYgqBM1tZk0vA4sO6hicXsKU mGf0+hQB1tFXJnncN95V77k9KbPtvg67Wr9TnXRhR1oyGRpms1FFjK92R4SmA5EnIn4N vT6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5/XcCw7ZF/2dEB8dgem0EIgpd5fGnQGzsj6FzPHDvzU=; b=PNNrBs65RnI4fXPio4qRhSVRZvhe5W0fxN8e+1WVmS9QrSk5pi19WZM5vM5QnS4Fm6 wZa8zU/PmU90AWbyMQo6jhQyjrLxoWd4yi/bt5Oj1TmHw26YpnqsQe4AVBR0e0o4kP03 k00qLv+8b94i8j3HuswyCyDIeYDmsf74aFcHDSl1yymaM1tZEi9/904Fn9r7Vx9iLuGY d0ro++ooEyE2y500IGc6DcEBhxqvx873HVqCUUVIDx2509w3xkJGLt59EpuQcO+eACVv ELafZWskbPzGzXfRA0ueLDnA07WiEvQQVCc7h21hq6R/bNBuGhmoNhewHJOEUuX3KmEd S7Xg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@inadvantage.onmicrosoft.com header.s=selector2-inadvantage-onmicrosoft-com header.b=Kltx0wvM; arc=pass (i=1 spf=pass spfdomain=in-advantage.com dkim=pass dkdomain=in-advantage.com dmarc=pass fromdomain=in-advantage.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=in-advantage.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb38-20020a1709071ca600b007306854acc4si2320920ejc.206.2022.08.02.22.49.48; Tue, 02 Aug 2022 22:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@inadvantage.onmicrosoft.com header.s=selector2-inadvantage-onmicrosoft-com header.b=Kltx0wvM; arc=pass (i=1 spf=pass spfdomain=in-advantage.com dkim=pass dkdomain=in-advantage.com dmarc=pass fromdomain=in-advantage.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=in-advantage.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235876AbiHCFru (ORCPT + 99 others); Wed, 3 Aug 2022 01:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233757AbiHCFrs (ORCPT ); Wed, 3 Aug 2022 01:47:48 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2121.outbound.protection.outlook.com [40.107.244.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC24F275F3; Tue, 2 Aug 2022 22:47:46 -0700 (PDT) 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> Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: =?us-ascii?Q?uxlS4Zcy0ZFe48H4Bv/c13Pa55HTP7CQtXhM1FMOuikz2mx4eFEnhJU3OF2N?= =?us-ascii?Q?Q6wmQfWo0JQx8UXZ+SnOgeGtHetkD3gsnhyhfvXn3Wf0r75nVuFqpT8+mDVr?= =?us-ascii?Q?H9OWv4NemVuh6eZwrqDDCks3w+9VR0Eme5IF8Z7upQp13p0wFFAS2f65GLdU?= =?us-ascii?Q?UmqzAJcABwR2a7DZ+WcAfnqvxNINc1KQtwPSDD6zE5mtmbRxZ6H3s+Kqcivf?= =?us-ascii?Q?vBWS4rKXJcFxBrbhsxmte48uJQ6FtfovJjkZukW/zygt6qu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qv96OoZ9VLOUTOYmFFRs8R7ls/wuwxJmU6VdW+bZDG0?= =?us-ascii?Q?P5szlDi7BJ3DF1Xcvx8uaei3YzTI+uEM4ceb0j1e5IZmII+tsnPynAdi4u89?= =?us-ascii?Q?OikFKFsXhkVJtWQKiY+Bx2Kn12OfcDEa8L4uWof8EiHARWsFhQAJaOJocWQP?= =?us-ascii?Q?Hl3PvhhQ+UcJPZzSYeOtvZd6YP5CJ6AGjH/gbiPLabnvqNnCbBiIqDuYI6Tz?= =?us-ascii?Q?xj/+Vgj0FgPcDVFzbFGqNTxphZ62JLfk6q5BMYsRMEBwfrMsEJUFUZmnWfvd?= =?us-ascii?Q?MVuIxvu6nqrSJg2eZBqtfGCCzX7wx/29h0gHfiWXdg3GzLXjP3cqOnl824jr?= =?us-ascii?Q?AEQ63k4M1s05cqK5RPYfMQLSgg42Mi2GsyxuaHpXidPDWVqBszHt4BW0L/q1?= =?us-ascii?Q?vxrajkQOItfTXHL5m9iIjLbwCXadb871Hx1lBnrrq8VoG9gU3cXwaPLhDvrv?= =?us-ascii?Q?nA=3D=3D?= 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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 -- 2.25.1