Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp321257imn; Wed, 3 Aug 2022 05:22:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u+T/kpkPkaRHtQtP6YMbJB1b+jy43WEo8URy3PCl7SO0tcfT7IZgdaOQn+5qCtX3KCFKO9 X-Received: by 2002:a63:6a89:0:b0:419:d863:321a with SMTP id f131-20020a636a89000000b00419d863321amr20917541pgc.9.1659529360234; Wed, 03 Aug 2022 05:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659529360; cv=none; d=google.com; s=arc-20160816; b=Exf+t5xlgecWdeR8RueLInnw5Hc7N8vgwXKrpMxgX424kMA+bYeWQjOP6wMEfGCtLa WugqLbYWwnB6Ym294XJgcbouVA3iZgV0ph1O2xVcd1yeMpOjtSzX7cHi0Q/pLz8dlEXl QiFtT7w78L85RLxtBSSQPudzLuYFKQPsk5g6kswRj1D8Rts3VbG8tPTfCe60mKVG25x5 FbgyCxvXMHRVAktlhnZfLBMH79vNKEAm047dx2DhVJUT0UE3hJaGhz7DeKLferYjvJ92 aMKmAWQ50UZ5W20lPp0wb29P69FuE2bXI5xN0smEkN2csCKmIJilUMGdlWIdp+gHRFQr Hxaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3wQQVAw0AEj2rKso/cKnl1tlt539pW1XXl86QQyFILQ=; b=ofWwkdcGlLZ8jWY1zHbDyqzN46+zgUdLDDCgxoulxW9GD0iLHWuABoGRsKNARd7BPE mPR7R/7C8peTfCrTV4+NlwI9qa6h22xwMorntItS4/qb3KOunQJ14mQXt6IF583a/sSB fZ501YQRJMCjVVZN3tVFyGO1w9ur5ps30RvUxU9ZqhgXCUiIawBVIswTIOu/zhrGuXwP u6yWJXrntiWf/iMAzdw+fhIHKAYkzRkSg1YdxwBovgLxlrexeG02S6OXy/cKP9TwyaP4 n/r/4bs4POk+F64Dq+Suy7DyVim/tHQgaCBWV7hoMN//7lmFiuClFmAtPK4Wy/QyxF2L nJVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YLfbOS2e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a170902dacc00b0016c323e8151si2475381plx.214.2022.08.03.05.22.25; Wed, 03 Aug 2022 05:22:40 -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=@gmail.com header.s=20210112 header.b=YLfbOS2e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236255AbiHCLcA (ORCPT + 99 others); Wed, 3 Aug 2022 07:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234639AbiHCLb5 (ORCPT ); Wed, 3 Aug 2022 07:31:57 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD092C673; Wed, 3 Aug 2022 04:31:55 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id uj29so17776169ejc.0; Wed, 03 Aug 2022 04:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=3wQQVAw0AEj2rKso/cKnl1tlt539pW1XXl86QQyFILQ=; b=YLfbOS2enJ+s26RtfesBJ8zGnIqOz8N1zVQYbOjbnUMzFumntwAsg2wEbx4BZDcy8K DjhgEL4q7F389yVMDemajrC+7YZy05+V2vUwkeiTyrnkiZdOqeDtl2Jp3uxYzxtf2EzZ cbfZwx6yWgzRf9i2YER4UAIisghjpJ48M7A7JLUi5ILL35agh9k0wP2wyoMevrC0WaQX uYdvczGJBIeGDOBCyn5x+kjPEa2y9OG1E6AJ+PC4VANYvn3cKZS3aTw0ESO5Z6qyewfH mPMzpXxxw7hVyEX5t4ZkLv12mRPc8ANE3dnFmm57K24jzCcHjdur0NH5WjwLfihg5fnQ 0hqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=3wQQVAw0AEj2rKso/cKnl1tlt539pW1XXl86QQyFILQ=; b=7SRusJ7KLVEHCGekWUmnwNeqHlRyS9RlP1+ZYAjpJVCDqBqylu2qztymdqMIklK38E hr3rWyhOmsUOrn1gBBr0CGcyiCr95vbQF2eZu4zuz2p0yxDUkNodSYS/2JFuLkm2LIEy oeSqIi6HYg+ZFPnTjmyMNGEh+aMDKXg9gwn4FgEhok0r89vZPXvUxSPReHGETFk+TJrA Dz0TbmUWdBDM/rtQJkE6cYS8te8Vm557WIfjnSQnFywUjAEP+j8kWyefYftvTrLaFhpH WGeWAF11wDI6sRU7C5/2MeCSYru5RuNqJH80nQSmffQr4ODHxIlkf9e4YKhBg66MuIL8 oubg== X-Gm-Message-State: AJIora8zII7VSyGsGNey8qrj5VUV/pIT2vDLQC9d/0usM9yOc/7yVdZE Hc/t5jTWniTRkgjZUP5IcnhwndWGgdO3GygLvjw= X-Received: by 2002:a17:907:c06:b0:701:eb60:ded with SMTP id ga6-20020a1709070c0600b00701eb600dedmr20395317ejc.178.1659526313516; Wed, 03 Aug 2022 04:31:53 -0700 (PDT) MIME-Version: 1.0 References: <20220803054728.1541104-1-colin.foster@in-advantage.com> <20220803054728.1541104-2-colin.foster@in-advantage.com> In-Reply-To: <20220803054728.1541104-2-colin.foster@in-advantage.com> From: Andy Shevchenko Date: Wed, 3 Aug 2022 13:31:16 +0200 Message-ID: Subject: Re: [PATCH v15 mfd 1/9] mfd: ocelot: add helper to get regmap from a resource To: Colin Foster Cc: linux-arm Mailing List , "open list:GPIO SUBSYSTEM" , netdev , Linux Kernel Mailing List , devicetree , Terry Bowman , Vladimir Oltean , Wolfram Sang , Microchip Linux Driver Support , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 On Wed, Aug 3, 2022 at 7:47 AM Colin Foster wrote: > > 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. FWIW, Reviewed-by: Andy Shevchenko > 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 > -- With Best Regards, Andy Shevchenko