Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp256088imi; Thu, 21 Jul 2022 21:08:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBvqPiQ5ql5hmue/KNyFZWMnTawavNVxQ18wg64ewP+0g0Gc67a95AL3HynGsarHorDEWe X-Received: by 2002:a05:6402:1766:b0:43b:cb78:5c4d with SMTP id da6-20020a056402176600b0043bcb785c4dmr1514915edb.354.1658462913867; Thu, 21 Jul 2022 21:08:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658462913; cv=pass; d=google.com; s=arc-20160816; b=fSPPcnHn1Qr+rIf/3R9cH3jVSOp7IevS7Q7zAo2yK4ndNJCybE6h429A9+KYn88P9n oFcGu2NmRGKOaa8TGxS7EhhWgfJKQxmo/mlSBDhvPqMWlanxV1QPCqLE/P7Ykk8rkvG7 EXhgWUXkF7qM7PDfPtNC76sH1YLOuwTzBv51NbJtWAHH67GyJy2O2Rn5zQtegLDG32y2 bCXOFfGozrL32bPZ/opNpoJ2xQfL8pNSJgbRzrOsgZetDg2+hQHEMmoTrrS9F9CdAKbr ur5qF1lHAIFSU0KRzCWLpehHFNte7Hq24oD1D7EOneUQa936E97ISPjxapj+NE9AOlx5 Z/Kw== 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=PAchGmMFX/04T3UU1T0/gNCIsHcZw3dbC8/DL+At50U=; b=BYUpLXbOByQHfOhMlN6OXrSJQ/814ogL7yWKZDcisZR9oFlT7oMsmHXefnYbIbOB+c wBvJbeA2YEWzPfUn1gKGvEOGZZHLzSmCl93uvnhSX+93zrplv70Vy8E/HgslW/anemAW xTRGqXdT5WweiR9tTDoowYzvKSyF7C+TfGljzJRf7qQkYmrxthwUe23MsBk208ngl3lM Q1+bN4Vp4jwF6T8eYusfEeh9N64ELaT9xC9HeXsy1b+OYwDtM6LXm4s0t9ngpir8+7xU MyZ6ErU9qs4KnzdBsTzxzRr9Vl4pRPdYMaVL+hmK+ZGljjvYqNObC7atoxI5XlPwvNPf GiNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@inadvantage.onmicrosoft.com header.s=selector2-inadvantage-onmicrosoft-com header.b=LsyHSQPU; 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 z14-20020a1709063a0e00b0072b4a71ec5fsi3842644eje.882.2022.07.21.21.08.08; Thu, 21 Jul 2022 21:08:33 -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=LsyHSQPU; 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 S233823AbiGVEGh (ORCPT + 99 others); Fri, 22 Jul 2022 00:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233663AbiGVEGa (ORCPT ); Fri, 22 Jul 2022 00:06:30 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2097.outbound.protection.outlook.com [40.107.220.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3761D89A68; Thu, 21 Jul 2022 21:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cf9t2ELfDgLK4kPJbtynYOjsoKOt9+YV/R8QXg6WT/dUM02Q/TxcHRzUrB0vX0H078pJP0Ft4lDaQ5xgFVkN6R/xE7zdxOMhvA2MWzOchORxq2PTzuhCAqABK30Ro3ToAmsKLdZXa/gJ2gc2VtG/PitsBAoQVntZ9c/nF6sOjHI1nTQWxLmCz/9N6Sgb/IOjO9YexVeGK4YeYVv6T6zKjESMrpCCKqI5Wa7I7ZCuurAro9LFLFkRRLjdH7UBC8jHNBcJC1QvfX8zPekgme7uu8CcmCC4i6kgrbu4sGWeMxrk6CWGwECTRSjoWmwKWLRVvaDPG8BFlyo7u/7tYUUZ/Q== 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=PAchGmMFX/04T3UU1T0/gNCIsHcZw3dbC8/DL+At50U=; b=XOdx1sXPC0Orei/tIHVMH9yaHKpkcr9SHuv6lC2I/WMXt2NgwNmuI1b1B2/palqU2E5eFKYM7AiQldq0/aPhwvB0DJ8JVG5+CwA0ne8s6aTUCYUEULAs1s6C2q1jisO1oNMZD+IWKFTUcvWJkjupWLkoTxNyF8hE2ceg4te1CMwu6P9wHsdbLj2v4ZatBQApJoa8o8d5LOqk0YBY0uvtHOtbsYdtLlmVkjdohV3bWtZRpKHQThoQVn2S2MY7vTmaBSEpZY/BNZZp2HGLn4mRcIL3V58haaLzUyZdPvuWl/oKetJVBkJbroeamI4kI6tB+/ry++yrweL3UGVgfjtL5A== 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=PAchGmMFX/04T3UU1T0/gNCIsHcZw3dbC8/DL+At50U=; b=LsyHSQPUaw/kIXkjPBsmYbJItFUJtmFa4ZOLzn10w73Z+VO+Z2+I2XeSiVlk3oHTyunaOyBEd2P9FTb2Vyv/Uqwp8VTE4OPLGUJk8vK20fkD22VdMxR2H3xEycr1b/RooEqMDTivnWI8IfrBGxa5Nwv+QNhBpIgzrP2vsf7bS/k= 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 MN2PR10MB3919.namprd10.prod.outlook.com (2603:10b6:208:1be::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.20; Fri, 22 Jul 2022 04:06:27 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::7451:2903:45de:3912]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::7451:2903:45de:3912%7]) with mapi id 15.20.5438.023; Fri, 22 Jul 2022 04:06:27 +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 v14 mfd 1/9] mfd: ocelot: add helper to get regmap from a resource Date: Thu, 21 Jul 2022 21:06:01 -0700 Message-Id: <20220722040609.91703-2-colin.foster@in-advantage.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220722040609.91703-1-colin.foster@in-advantage.com> References: <20220722040609.91703-1-colin.foster@in-advantage.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0044.namprd03.prod.outlook.com (2603:10b6:303:8e::19) 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: ad0ad3a1-d9fd-4afc-e634-08da6b978bc6 X-MS-TrafficTypeDiagnostic: MN2PR10MB3919:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QlFVrgh4YyKTScuubrFoMllhDBmxaz+R1BENR/tJ1WVk8pHD8a75gYIiMZ6HLR0wTfZIe37/2U/o8MKNh74nGOo9EC58ymGGiwSzYF/giCmBVYpIa4NA2vhS6BemYXvs6DrRwc76rZLkmNG9vKy7+cbuoMe/nJh/vMqFpBl/1G39Wh3PEsa16SvAu/hnROE1g6R0nFGFB9ghddPn+bfY2LNBuQ60N1qVgVi3dMpt8wDjBoZCJ0rAzFfv4a4z8EwXn9v4zpghMWj89uXuZ5lHRK5yfOell0E/g8hEZc0Bv8i0vqf7XBXroPTWOmkQ44Mb2PIZiDP4113NRaqD/v39kpL3ENs56H5n6PDXBRVijIeTE2Qp2XtemzGXmXlD/Q7xFePbFwapJbYXYSqtqYHiVU/RxP0HXXAPu1gFFEIrrrm9TBjxi7nhNaf/XQXeC0Y8WVFXQ8ErHHJvmsTqfhsmC2g32ANRyltLk3C/V62pVbjjlecoU4WtU6pDNDFmJR4FcNKmLLvBxa/YiUTVlf7tCPt2byvkmIyplUjXMmPR9p5EEXA9tNTGNU2s15aiMOApt5g9jA3CdJX41sIT70tmxlGyM8OfAdRuwN+lc4I/6qHFxKZsUI7U+i2h+c5fcdt4bIyACnEO0CLDBeOxeN0YnEctIPKwEo8Zx5uExQJSTvGarRqgH/lPseY8/MNxYjUAW0QdzIZ4dM7+bGwzBj56vf9A+RsESiKefn3cbwKoh1S54n0RfaHn9qd8hIQvcWEdPxbS04sykfQFnw4jpIYE2VRbgUtf8BL99xl6PK53uOkty0dpWNsPOFudJ0kTaPni 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)(366004)(346002)(376002)(136003)(396003)(39840400004)(36756003)(6506007)(2906002)(44832011)(41300700001)(52116002)(5660300002)(1076003)(66556008)(8676002)(8936002)(4326008)(66476007)(186003)(6486002)(478600001)(6666004)(6512007)(7416002)(83380400001)(26005)(316002)(86362001)(38100700002)(107886003)(2616005)(38350700002)(54906003)(66946007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?r1RGFXmnVXjF4r8rekSI5i/aH3cF3JV+Hi3Is+WQDhZJbQ4HReWk/un+KkqW?= =?us-ascii?Q?dz7emaIb+AD8E2KM8YiKLxm84hJN3aneBej+8HE9icM2F6W645Lq5QspRHC4?= =?us-ascii?Q?tIqoxLHHwN2a32NwkGFmwvU/CYWYkK1oGRo3dBGX46AkNgcgUNG7zBXOwlAh?= =?us-ascii?Q?3Op/eeSf6W0n+0D2KdDTkGX+UxlWYo1cMCP3U2jcpf1R0y1uxX1m9VlpjROG?= =?us-ascii?Q?OiorpYzWhzxIfBMkh2hTzmpcsV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ascii?Q?BIZ/isOKoX1brYmcTsrlzek+FnR4lBPtT1Z7M2zm0adQigWH6tzO5LvDwure?= =?us-ascii?Q?INaZCjDuWXYUx8ndzA6EFXnCV4kBka0jtZdEA4VqQJHkv6oqbJH/hJ1oyA5U?= =?us-ascii?Q?ykhiw1GD43MaP5vDeM5ThDYppDwk54ersUD9MARkHbW+kOC6TNtCClgYovcO?= =?us-ascii?Q?QQKWU7nm6L30pOxv3r4xxy18aAZYIarhHhJeEG5+MSMzagscYJvmY0dIgKVI?= =?us-ascii?Q?ZoNCG6iJHUl1uJKwT7F8NB24Ct7fOV411sGGSkoBhAsSfBg7gYBR1eBVgsqI?= =?us-ascii?Q?E4BROrDqrQb8vR62aRRGKHvSQwkWmzN5nYsyrvMiNkEamWrexxjAZh0yvfNi?= =?us-ascii?Q?/MNQAXmWuICPzdggMgZy3yfKyZfDEi1qdrf50m047+olCtx3nHvJxSqR4cVF?= =?us-ascii?Q?ZrDZCFxlgDwYxaiJtT+dfzD3HzJ5t8sWxM7BK2PZtaUzKSqgZEPnAxd+xZwn?= =?us-ascii?Q?vikojdu/677UNr2+2GUfMDs=3D?= X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad0ad3a1-d9fd-4afc-e634-08da6b978bc6 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2022 04:06:25.7679 (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: UymYj496281dIDUKMUCB3vz5pSb6OEDx95jSFKUKy7H9MWI4BQCgxwa5UikfypAXVV3mCrEEAcovQz2eDpBy451u0l9HuwYvCo12AGhhy3Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3919 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 --- v14 * Add header guard * Change regs type from u32* to void* * Add Reviewed-by tag --- MAINTAINERS | 5 ++++ include/linux/mfd/ocelot.h | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 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..7abca80ba7dc --- /dev/null +++ b/include/linux/mfd/ocelot.h @@ -0,0 +1,60 @@ +/* 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 + +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 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