Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp325631iog; Thu, 30 Jun 2022 01:18:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v6Gmy6gP6S///AHKrPtWc7VBzJG+ORQUc4FMNTQxt6S70ERH1+hcemVneh7WirOUTlpOVL X-Received: by 2002:a17:906:9751:b0:722:e52b:aef7 with SMTP id o17-20020a170906975100b00722e52baef7mr7362072ejy.537.1656577122411; Thu, 30 Jun 2022 01:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656577122; cv=none; d=google.com; s=arc-20160816; b=isaiju2g3cjmywllKW5gTWMzOEPYfgEYyNpR3wZzWTu7PxzyAXLT1QGH9lFMZuyScJ HrR/Pjy/vqmAdMoJ9DUyvMFaicK2qSpQueJCLC7nye2ya3KbXT5Z+Knv5zUlIf6Ur/YN xxqKzC4JacLzxOyODhZjT0QNMyeXE5SPt47qF0O+Y/f6D9CGhFq83VK8tEDl+qxZxeMN 5yhj1m+AM7QICAT9gaXuFVVhRGmUCSWX/fpzeNaZrtQwCkK0sUtD/b+5pVFwvjzCCdmy Keld3yI38UuurMZhcXpKHrE74BhMJbtv67Fnlhhyk1+pNC6KtSBEhsteuU4ySjZMm/3f TDww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CCykJYUXKv51rZ8nTMW18vjqVnPZBcTRE0urrPA7hH4=; b=0ZFju002ivPrtqw/b5HKvWRPToLH3e6ecYmXifit+hGZhA9igBvFOdPinhDNSlwUn/ vRnnNLLxSw1Dpdf6YzD5LeXgEXqzMxlh7kWXCc/flXYSdo2Rp3Z17789DUOki8G6A5Zh Wd80ovwTuQNTZU2SPIxB1zfp4DxSgZqH0QbXKaJZNOj/yUPhIHUuB3DhrieD5i7h2L/s 4ljrXwBluCKFUGTRQ27w1oxQM1MXjWsha+k+XZf3k+4PDf8vwsqMIWMNO0Nx3hmyNdPK DbS8wLgXpAm47IZp2/zZj3Ykv6WzeErxcFGl07E8s0S3GpVdp3IGX0CgCmH2wWt8KTc/ tGAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z3YQlrsY; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd7-20020a170907968700b0070bf25f1732si6585206ejc.155.2022.06.30.01.18.14; Thu, 30 Jun 2022 01:18:42 -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=@linaro.org header.s=google header.b=Z3YQlrsY; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbiF3Hyv (ORCPT + 99 others); Thu, 30 Jun 2022 03:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232787AbiF3Hyr (ORCPT ); Thu, 30 Jun 2022 03:54:47 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B753ED3C for ; Thu, 30 Jun 2022 00:54:46 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id k129so9386440wme.0 for ; Thu, 30 Jun 2022 00:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=CCykJYUXKv51rZ8nTMW18vjqVnPZBcTRE0urrPA7hH4=; b=Z3YQlrsYDNeBCjZRgzx9MKmS0d+MIjGEWt+UBH1uzDnDvllumP4ONc+5d2XS9hu4a8 1g1WWWcMRnXTjpSnpEU1dhS2gvsOkfAdcz1G2mkSUzUY3fTbAswgt83sm3cwfEMiZ57t vvcWk2wc6G0iaW1tjYMUtuc3EZHs7WPXa6u6tm6VJYOvqEQNCmXggkcUwSM1Btwmda2o cEX4TkVzHSkGtmy/4k9x6PjofkRoSeD/rUbY9J6WrAT7y66c+5GvbIzUmj9TRbyXaB1/ 43H07TvNeTX2IUgvbjxa9Rysv4aDDL60oNgfpjHap+0g2DNozvyq748EZRLwPx4HaUyX gahg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=CCykJYUXKv51rZ8nTMW18vjqVnPZBcTRE0urrPA7hH4=; b=mHZb9qigpae4j1+VzAIxtjUpEhhciLfYcde2Uu7Ltm+cCH4hYWuitaYMKEyKXUt1k5 Se7VZt5pNXgqlZwwSEsKTYWMPz04Wh6lz+CBXS/9dm/nsngIfmY2AJIE0SjpCaq8lHQU HF7A2n/V+jGMBLYCUGXp+IGg2LHGSJ74vF6H4Pd2nVpaQlgDD41vziFCmbAWrTJ+YHqn LsDTIegJGnlxmvHBY7PRePpTrLkBgLJPhijC7u9wdn9HBj+692KYMa9+m6wTuDev1idH rK6wlmvqZ3+18cpEpXwZdqR8QG3+ZWfRY/ud6Ar+JS03nvvBSG7rO4kXQjjfb9udkUWW zIQg== X-Gm-Message-State: AJIora+oihkDSHr9MX4bP+kNuDB3v8sKuYV7THR6TAuUEXSQ6Ge+fQyZ okvkwHYWyhvlwJBtfSEtrDi+OQ== X-Received: by 2002:a7b:cd85:0:b0:3a0:4c45:16c1 with SMTP id y5-20020a7bcd85000000b003a04c4516c1mr10046046wmj.125.1656575684605; Thu, 30 Jun 2022 00:54:44 -0700 (PDT) Received: from google.com (cpc155339-bagu17-2-0-cust87.1-3.cable.virginm.net. [86.27.177.88]) by smtp.gmail.com with ESMTPSA id h19-20020a05600c351300b0039c54bb28f2sm6092291wmq.36.2022.06.30.00.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 00:54:44 -0700 (PDT) Date: Thu, 30 Jun 2022 08:54:41 +0100 From: Lee Jones To: Colin Foster Cc: Vladimir Oltean , Andy Shevchenko , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-gpio@vger.kernel.org" , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lars Povlsen , Steen Hegelund , "UNGLinuxDriver@microchip.com" , Linus Walleij , Wolfram Sang , Terry Bowman , Alexandre Belloni , Arnd Bergmann Subject: Re: [PATCH v11 net-next 1/9] mfd: ocelot: add helper to get regmap from a resource Message-ID: References: <20220628160809.marto7t6k24lneau@skbuf> <20220628172518.GA855398@euler> <20220628184659.sel4kfvrm2z6rwx6@skbuf> <20220628185638.dpm2w2rfc3xls7xd@skbuf> <20220628195654.GE855398@euler> <20220629175305.4pugpbmf5ezeemx3@skbuf> <20220629203905.GA932353@euler> <20220629230805.klgcklovkkunn5cm@skbuf> <20220629235435.GA992734@euler> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220629235435.GA992734@euler> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, 29 Jun 2022, Colin Foster wrote: > On Wed, Jun 29, 2022 at 11:08:05PM +0000, Vladimir Oltean wrote: > > On Wed, Jun 29, 2022 at 01:39:05PM -0700, Colin Foster wrote: > > > I liked the idea of the MFD being "code complete" so if future regmaps > > > were needed for the felix dsa driver came about, it wouldn't require > > > changes to the "parent." But I think that was a bad goal - especially > > > since MFD requires all the resources anyway. > > > > > > Also at the time, I was trying a hybrid "create it if it doesn't exist, > > > return it if was already created" approach. I backed that out after an > > > RFC. > > > > > > Focusing only on the non-felix drivers: it seems trivial for the parent > > > to create _all_ the possible child regmaps, register them to the parent > > > via by way of regmap_attach_dev(). > > > > > > At that point, changing things like drivers/pinctrl/pinctrl-ocelot.c to > > > initalize like (untested, and apologies for indentation): > > > > > > regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > > > if (IS_ERR(regs)) { > > > map = dev_get_regmap(dev->parent, name); > > > } else { > > > map = devm_regmap_init_mmio(dev, regs, config); > > > } > > > > Again, those dev_err(dev, "invalid resource\n"); prints you were > > complaining about earlier are self-inflicted IMO, and caused exactly by > > this pattern. I get why you prefer to call larger building blocks if > > possible, but in this case, devm_platform_get_and_ioremap_resource() > > calls exactly 2 sub-functions: platform_get_resource() and > > devm_ioremap_resource(). The IS_ERR() that you check for is caused by > > devm_ioremap_resource() being passed a NULL pointer, and same goes for > > the print. Just call them individually, and put your dev_get_regmap() > > hook in case platform_get_resource() returns NULL, rather than passing > > NULL to devm_ioremap_resource() and waiting for that to fail. > > I see that now. Hoping this next version removes a lot of this > unnecessary complexity. > > > > > > In that case, "name" would either be hard-coded to match what is in > > > drivers/mfd/ocelot-core.c. The other option is to fall back to > > > platform_get_resource(pdev, IORESOURCE_REG, 0), and pass in > > > resource->name. I'll be able to deal with that when I try it. (hopefully > > > this evening) > > > > I'm not exactly clear on what you'd do with the REG resource once you > > get it. Assuming you'd get access to the "reg = <0x71070034 0x6c>;" > > from the device tree, what next, who's going to set up the SPI regmap > > for you? > > The REG resource would only get the resource name, while the MFD core > driver would set up the regmaps. > > e.g. drivers/mfd/ocelot-core.c has (annotated): > static const struct resource vsc7512_sgpio_resources[] = { > DEFINE_RES_REG_NAMED(start, size, "gcb_gpio") }; > > Now, the drivers/pinctrl/pinctrl-ocelot.c expects resource 0 to be the > gpio resource, and gets the resource by index. > > So for this there seem to be two options: > Option 1: > drivers/pinctrl/pinctrl-ocelot.c: > res = platform_get_resource(pdev, IORESOURCE_REG, 0); > map = dev_get_regmap(dev->parent, res->name); > > > OR Option 2: > include/linux/mfd/ocelot.h has something like: > #define GCB_GPIO_REGMAP_NAME "gcb_gpio" > > and drivers/pinctrl/pinctrl-ocelot.c skips get_resource and jumps to: > map = dev_get_regmap(dev->parent, GCB_GPIO_REGMAP_NAME); > > (With error checking, macro reuse, etc.) > > > I like option 1, since it then makes ocelot-pinctrl.c have no reliance > on include/linux/mfd/ocelot.h. But in both cases, all the regmaps are > set up in advance during the start of ocelot_core_init, just before > devm_mfd_add_devices is called. > > > I should be able to test this all tonight. Thank you Vladimir for stepping in to clarify previous points. Well done both of you for this collaborative effort. Great to see! -- Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog