From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0BB6CCA47E for ; Thu, 30 Jun 2022 07:54:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231920AbiF3Hys (ORCPT ); Thu, 30 Jun 2022 03:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232342AbiF3Hyr (ORCPT ); Thu, 30 Jun 2022 03:54:47 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 156DA3ED35 for ; Thu, 30 Jun 2022 00:54:46 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m6-20020a05600c3b0600b003a0489f412cso1764464wms.1 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=DZpdVuv8Xn/Pzs5Sc1YcaaHuxM73jQiCBE4Fpy1gpDAbpJcRap9XKNWXYXR3KiL6gH O4AFDBUqZaJzZ7/ukSYC2u6ZBDDMC70L4g1hr48v71m85Hp/tRsIHCXxnVx6OK/uaDvO Nys8ET8b+n5L4ihBRvhfBivcG0WqkGqDqmdRURNCnVXrReqMgDIwNTia63vo7ehYsBvM Qq4ridWuAXH5SrDrvV0KPh5DRiOPmOaGLYTxH+a6AmbPCjatvU0d3cp4PNmG4T8wbKBa nZCVIM1oaouRrrEJ0MBE/w5ANwb1O/5s7eCR7DBgHW2vxzK34MwO5A37f0Ie45opZi3o 264Q== X-Gm-Message-State: AJIora9Ry2U0juDVWR9xEIYG4d0Fsh6wSrPR4MrSSmgq5Ct7Isq0qd7I ZcBwOJtrtLdT8Z2nUOg+f6vhBb3ah1fmgg== X-Google-Smtp-Source: AGRyM1tBnnpxwzXTNYYIrONKbhI1E0t5nzd18tCkH1azo2MF2q31f4j7BJc+CfboYCD9eU+M66/zYQ== 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> Precedence: bulk List-ID: X-Mailing-List: devicetree@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