Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2601625imi; Mon, 25 Jul 2022 03:11:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAp685pshG71jF0pbN2d/Kh0CpjYUChrSretRoqSS9lbNfFBwBhb+rykyUcKjTl2222Yle X-Received: by 2002:a17:90b:4a92:b0:1f2:a67b:296d with SMTP id lp18-20020a17090b4a9200b001f2a67b296dmr6114383pjb.149.1658743915746; Mon, 25 Jul 2022 03:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658743915; cv=none; d=google.com; s=arc-20160816; b=h4+1F1OtNfpic7hAERw/7y7NUfS/jrKDhsuTViTXUlRd5rwClmh7lGW9+NNmfRxkVd SkQ+nMq69/x5g+admGplkY2PN5OK9DCMypYSnns992x5mgxX2Dni82Ge2aQgyOOf87ig 5DcZEQaRuvdprSzzq9/e7aE0uiMqjAOhHul65nWvPANdHHHJYNia80p1CEfTVhdDtAaI 5Uwv3n0xlVIF3IftQIrDb9DsbWf0LkN2Zj/vcMi2+EJUvCKExSE7CaimFNlMQ2f5BfrS rQ4JuEU1jQfjxAPxmw6gpkLE/2CLhwrnXv4hueGlgXABCf58Q5d1ZEbTCY2xIKvFG123 euBg== 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=Wk5AdTHZkK3y/y86s2c6z+V6gZGrMEpCv6krR/2aEhw=; b=o122PTW1ELwuyPOsgPb607o1CAfOTtLo9XhfLbhKlAZAydhn+eVDRkGH8vYj3GCuMW llwsBkcPmgn0UvgmCyXOvQ/gqGfbG3xAPIY7JJ4ZIPF8CRNfhx2sjs9R/gveU5DWubR7 iHnyZVIzuOa2zQGEAbwQZ9sod3kXbO6RknsgRoPLxWl/zzprtQa+Pv+Oi7afmuFMDIDX 5i/yMU3ijcF7urz9D2l+LCbXblm48fwWUzINujS/fO7DAILIxHwwf94D+AgwTbNCRRyN BiuEAUTmCl7anndzz8NmT4B2h51z7vqXzUOnc4Fqnm+YHnLdcfUHeKPW2weNskKvO4t7 C+EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WyCpx2vu; 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 m12-20020a17090ab78c00b001f05643fa88si15387537pjr.127.2022.07.25.03.11.40; Mon, 25 Jul 2022 03:11:55 -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=WyCpx2vu; 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 S234334AbiGYJkb (ORCPT + 99 others); Mon, 25 Jul 2022 05:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233967AbiGYJk2 (ORCPT ); Mon, 25 Jul 2022 05:40:28 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD414E7B; Mon, 25 Jul 2022 02:40:27 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id c12so5762459ede.3; Mon, 25 Jul 2022 02:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Wk5AdTHZkK3y/y86s2c6z+V6gZGrMEpCv6krR/2aEhw=; b=WyCpx2vunPvzLmeyFWBQxitXLhUa99to7s/rJpVE8ru7UYq8XMRsSPtcU6LC//Uiup Uj5cM7BdEu6VHp1DfMXcnKz8XFRoKnnxjvsHrVS9ov8b6Cowtcp7DBteWxnug3FPyrwd t++iCranU4Pg1it/saglRtJjPEZumxxD4QqC8TsJvV8GWfrcbDkEN9C6mZUlc3Q3eDPX kJIamuZUKv93P9h8gOGuTp1WNFPjdcs5Mg+qGXKE/eoC5eBHzWqYelnOYvl1vB3fV0tS /PQlJlmAHtG+BA1QxFkTTJdMiwum3FnlTGoufX2F+DXLGauusXHKLcATIU0f6cyujV6u Aqrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Wk5AdTHZkK3y/y86s2c6z+V6gZGrMEpCv6krR/2aEhw=; b=7qKl05PIW2U0Nm0A4pHlXynwCJ/4SvIVuaSxuFkewMuNeUCE9FY8xY5o9FPK/4B08C FeyVy96V15fl6MuY8F0ePDKzvFXee1htt0OqFqpa5IzaeR3V7CyX4E5CTGs9z3lYmCQ+ ZDT4cSwU0QpERFH+HBkVsK5lpUY9JxNKRU7nvE4rvJxzOroP57Jx62dxFUDFjx58Xcb0 yeJSDDCFzHhhwi89bgM5lnfccZ2o9fhP3sTWb7d6aqKE0GOwzgxf2tUBm+b+XG0/23aq tT5ZbxXky9CI/i4FzAfjPb/XkfNNjDJsELeSQD+SGgcdKuQamegbVHTgCGzWd1WNz6fr lZ1A== X-Gm-Message-State: AJIora/p0FPbRdAvua781MzC0dBE666pwvm/sRZJpuw4ZuTP6siUQtbM b7bkzWJrYgBkY5DeF26lKcTz+YIe4ebTzkcdALo= X-Received: by 2002:a05:6402:d53:b0:43b:a0cf:d970 with SMTP id ec19-20020a0564020d5300b0043ba0cfd970mr11829902edb.277.1658742026168; Mon, 25 Jul 2022 02:40:26 -0700 (PDT) MIME-Version: 1.0 References: <20220722040609.91703-1-colin.foster@in-advantage.com> <20220722040609.91703-2-colin.foster@in-advantage.com> In-Reply-To: <20220722040609.91703-2-colin.foster@in-advantage.com> From: Andy Shevchenko Date: Mon, 25 Jul 2022 11:39:48 +0200 Message-ID: Subject: Re: [PATCH v14 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 Fri, Jul 22, 2022 at 6:06 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. When we refer to functions we put it like func(). > 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. ... > +#include You also missed errno.h > +#include > +#include > +#include ... > +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 _get_and_ioremap_resource() > + * prints of "invalid resource" which simply add confusion > + */ will simply add Missed period. > + res = platform_get_resource(pdev, IORESOURCE_MEM, index); Where are the IORESOURCE_* defined? Haven't you missed a header? > + 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; > +} -- With Best Regards, Andy Shevchenko