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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61D50C433EF for ; Fri, 1 Jul 2022 17:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=52F7SliicjTCmd6rZS4RZvN47fglGeS43eovUkbnyX4=; b=r4b0CIKpMAI+nQ 50slBPOPVY97IYz7YIBpkxoJ1DOEc1iBlS4qdjD9SP6lhpJHra03LYRFhIIK7MGxcB3QdOnEaF52z JV0yZ/w18WsftJRenUct71I3IWf5aMvjvAY5bfEVKpsDYVJhjfGKI/ByNq6bXVaWK6d2zF91wOSHN vIIxKTdaybN7DDgb4oLuiMTFve7JmH4CwEA8taM1gVzX6RpHdTlvY5ZC94XGidh5UmyP2qHNTvmcR Ndt/2v8GpDZU/LXKn6BBkFx562w5b/kd4UIBK5484MJMkemPos4ADdPFnjuOxT4hAKNG747wxHQII 7vKvEYbcs+BJWBSlfivg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7KIE-006Bub-J2; Fri, 01 Jul 2022 17:18:58 +0000 Received: from mail-dm6nam04on2135.outbound.protection.outlook.com ([40.107.102.135] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7KI8-006Bs1-US for linux-arm-kernel@lists.infradead.org; Fri, 01 Jul 2022 17:18:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BgE4BVQonD7ArYbQUZoCs2+vP7YBOAS9r5oitI+vmfQXFM0X52+cVy5OvYBjn+RP4LIhMvALD/zgvqMu/nvNWXBzNj/cgBkg49SqkbewOjINgeM1DfsGHYqJXbTeAXlwB2vjnnWxE2TgUzrst4fv62i/S55pK49Yygwngb2VNdjw1XmpSXKhQQrgSSa136CAlYrqI6CgRCaDZPCAYJBcPvKj5o+zwxIt47w8PF8xcZw8+heM3mzaviJIar2qV8ve1rVUdZIHd7q8xHB+SiqHdM76j3zOeXC4u+I1bzKQFlO00JP+IEvShhtOpWp3B/eJRugrwkLXiqEa6jhyulp6qQ== 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=rnam+bJ5hwRdkQVl69VO12O54KR7qTWObxXRcrGzoZo=; b=Hv1FOhOl8j2H5Nznf/kbihq2PS5mArb5lbPI0iIb6B4pd5XbTSDfIIkrdDjUzQLhg5zaLOXJSir9MUSQzVhClezD/rp+jLQTrkE8RM9BZEI1kz7l5Qlk4FBD7/uEfVfscRKmK705XGJqZsHh1QhtgIca1bA8eoHKB+ve2fw+NLbKErHu2PxrWYFOtIcoEnGW+yYWhnhNp1BiHpijAT1+hHKXzpjxjFTXAQKRPHuP7/CBKTH2SuL56OoSfZ1r2J+hmHYy+r3oq5HBeLZzQYYX+WQ5IRdmD//CeLqo20WxKAqsvkp5hERoMIwgCiELc8HTeCM1YLQas+ki9JreuQKRxw== 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=rnam+bJ5hwRdkQVl69VO12O54KR7qTWObxXRcrGzoZo=; b=alThQoD5xo4drwR4tSSjrmg723ZQeUw8XsUrnZ8EzZA9vM+D+4fCp+63lZDerHRXXwDe7MIlgQgGlcTd2LUX8F3vUB2GhfL+nS+HsqWZEYD5u0IVkt2i0iNBESf6N1ClZ0jV6fECsgm9zrew8c2uRd+Ia/NqE323gCN5uVein6k= 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 CY4PR10MB1671.namprd10.prod.outlook.com (2603:10b6:910:8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15; Fri, 1 Jul 2022 17:18:38 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::712f:6916:3431:e74e]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::712f:6916:3431:e74e%6]) with mapi id 15.20.5373.018; Fri, 1 Jul 2022 17:18:38 +0000 Date: Fri, 1 Jul 2022 10:18:31 -0700 From: Colin Foster To: Vladimir Oltean Cc: 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" , Lee Jones , 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: <20220701171831.GA3327062@euler> References: <20220628185638.dpm2w2rfc3xls7xd@skbuf> <20220628195654.GE855398@euler> <20220629175305.4pugpbmf5ezeemx3@skbuf> <20220629203905.GA932353@euler> <20220629230805.klgcklovkkunn5cm@skbuf> <20220629235435.GA992734@euler> <20220630131155.hs7jzehiyw7tpf5f@skbuf> <20220630200951.GB2152027@euler> <20220701162126.wbembm47snbggxwv@skbuf> Content-Disposition: inline In-Reply-To: <20220701162126.wbembm47snbggxwv@skbuf> X-ClientProxiedBy: CO2PR04CA0096.namprd04.prod.outlook.com (2603:10b6:104:6::22) 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: 0950b93f-58c2-4e8f-bd8a-08da5b85bc6b X-MS-TrafficTypeDiagnostic: CY4PR10MB1671:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y+S8N/7eY9BcRqYgkWeMitsVuFVfRugUlM/BL1ICy0GjQJMxcJnOHKoy8p1LXULkBs7c6pDvHuv/A3jUXvEo98XITZpcSO2d3Lc+eKfNXRQxLpK+PuCgkxQrbKdQcgaOK4k70bxJeeB01MoCzuxBa4j08Q9lvvciEnM0VE6eh9nx/rxgNpaJjn3DctGfs+0k8T0S8Xuy2Ft/3qmH7r/+UAaF/p2SlZJqS8DTJH4bVegktexFoHL0R6h0T8bFpQxiQ7rDo6R/CtEiSi11BH4bcNqMcTGh7b3s48X0PejENKtCLQIeZDtw1QUHqEt35uhpV6vjGi0NTvwCt8U9K5GsGGfVcWYrNqgyb9KnON1JOX9jDmj7fEHd6K+WCWlZNVd5jL26k0iGpFPoQhC9ujy0Lieq/kUoC5+A6hlZm9Cuh7hjPiM2JfckXLi6dK/NCSJOcoQxvBEzNaariRoWu8EaAwCjqGoNHtZwv+0hoZ627qGhA9fYeuvOO+ZFm4yGC4kFntQdnBe9dJsXbe4Lf6CdidFfPMJKQYz3QZWz5+ePIsTKkSgZ/NPgDyVkr17BM1rnjdSYXmCjFAJYecp+GL3mynPRx8sQ2qrAyIWpkGsQeCeY82ysSXqw1/kJqThotEN7yuu0ejreT6yVG3CSu9IeewnlUrTM3mxiK1TFhHWjmdwtlpcGn3Gv6eTfbjFuYMLZ73cM+AYQ7cbFWNY+nS+Z926d9nzzdsi44HJMb7U6DES9sb+ockPFCYH8iO73VUrKkdBlD0vYxTFyLErWVTabSxi+pCNcRkQS4gco206HXJY0EFhP6bzUVI2sbpCqw7fR 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)(7916004)(376002)(346002)(396003)(366004)(136003)(39830400003)(5660300002)(8936002)(6512007)(7416002)(54906003)(6506007)(33656002)(52116002)(33716001)(6486002)(9686003)(44832011)(1076003)(38100700002)(66946007)(8676002)(41300700001)(6666004)(4326008)(186003)(26005)(66476007)(66556008)(38350700002)(2906002)(6916009)(86362001)(316002)(478600001)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?GnNVBvoX98zl9LnfK11GdSb0aFvyAZihog8WKYV39l5a2PzwXgd2PR7qG11W?= =?us-ascii?Q?GFFlyA8kewiHqe5+MQUlChUqVxB2keV/9tzvLdnBmsvU6QXgivyLaFJvPzQT?= =?us-ascii?Q?gmnB6y0lDFrWsonuuTiuYt8u4+bZMXnjuIg7+ahrfZWRWWH0Jo9Du5kk6k1i?= =?us-ascii?Q?yI1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pl157pMZce5aMD/o3yp72GZxyir++v?= =?us-ascii?Q?xEkKsc+hnIAC3oYRkOvSs8gFHWDApJA48XElr4JpWn8byrfZLq5SSoiHQwlq?= =?us-ascii?Q?mP8kUJXoRvHzqiIuEtQ+Bv/r2r6yhSXNgfcbD13/8ghNfpg4qsKLF6wJtIav?= =?us-ascii?Q?U19YyhMd7lgNZAw8o/eAnW748XRPLBkQ97QtvdMOpok+dnoOmVdQqC4ndNwt?= =?us-ascii?Q?InqvvaVtiQgY1AEajixwN/Psm+gWfDXzPoBRhNU/KUnsvpzaEMs4Z7UqsmYl?= =?us-ascii?Q?Bu7B89eY3WyXGVn74ABo/kOhG4a1rNblD8t4ijapraQ+ZifqUuMauTLL3HaE?= =?us-ascii?Q?x0PKJgkcG5cDBE6XbAYmO/qpJFKXzseBVVKvfftCbFylTcZh+COJ+2I5Q0p9?= =?us-ascii?Q?qlFjp+LQjg9MAk+2S1T2lDqdUMzb3Ubq0R23PBZRxcjHbDxVOETT8gpDKN8M?= =?us-ascii?Q?6YyF4hJetU+5Cajg2KlXrMpBVwPIwOk2RUyLO028pPAZvRDvL3HweZT8vwIA?= =?us-ascii?Q?AGjV2Plt8yLgJ+HSVaVsT3hO4YQ5UJRwsBw2m4xqRnN72Dt94mPDAIFQTbmG?= =?us-ascii?Q?0A=3D=3D?= X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0950b93f-58c2-4e8f-bd8a-08da5b85bc6b X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2022 17:18:37.8645 (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: SOhj5AOIO3juyJsPL08mk/f5rhCpUh1FJendiv3cEeeGqct26lINv1OPweIs/9Ydm0IWo1IWc8sjIB1f8ZG9G2WvVFoyyQyJkqR0eY5Doak= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR10MB1671 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220701_101853_034292_8022DE94 X-CRM114-Status: GOOD ( 41.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jul 01, 2022 at 04:21:28PM +0000, Vladimir Oltean wrote: > On Thu, Jun 30, 2022 at 01:09:51PM -0700, Colin Foster wrote: > > Ok... so I haven't yet changed any of the pinctrl / mdio drivers yet, > > but I'm liking this: > > > > static inline struct regmap * > > ocelot_regmap_from_resource(struct platform_device *pdev, unsigned int index, > > const struct regmap_config *config) > > { > > struct device *dev = &pdev->dev; > > struct resource *res; > > u32 __iomem *regs; > > > > 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 > > */ > > res = platform_get_resource(pdev, IORESOURCE_REG, index); > > if (!res) > > return ERR_PTR(-ENOENT); > > > > return (dev_get_regmap(dev->parent, res->name)); > > parentheses not needed around dev_get_regmap. Oops. While I have your ear: do I need to check for dev->parent == NULL before calling dev_get_regmap? I see find_dr will call (dev->parent)->devres_head... but specifically "does every device have a valid parent?" > > > } > > > > So now there's no need for #if (CONFIG_MFD_OCELOT) - it can just remain > > an inline helper function. And so long as ocelot_core_init does this: > > > > static void ocelot_core_try_add_regmap(struct device *dev, > > const struct resource *res) > > { > > if (!dev_get_regmap(dev, res->name)) { > > ocelot_spi_init_regmap(dev, res); > > } > > } > > > > static void ocelot_core_try_add_regmaps(struct device *dev, > > const struct mfd_cell *cell) > > { > > int i; > > > > for (i = 0; i < cell->num_resources; i++) { > > ocelot_core_try_add_regmap(dev, &cell->resources[i]); > > } > > } > > > > int ocelot_core_init(struct device *dev) > > { > > int i, ndevs; > > > > ndevs = ARRAY_SIZE(vsc7512_devs); > > > > for (i = 0; i < ndevs; i++) > > ocelot_core_try_add_regmaps(dev, &vsc7512_devs[i]); > > Dumb question, why just "try"? Because of this conditional: > > if (!dev_get_regmap(dev, res->name)) { Don't add it if it is already there. This might get interesting... The soc uses the HSIO regmap by way of syscon. Among other things, drivers/phy/mscc/phy-ocelot-serdes.c. If dev->parent has all the regmaps, what role does syscon play? But that's a problem for another day... > > > > > return devm_mfd_add_devices(dev, PLATFORM_DEVID_AUTO, vsc7512_devs, > > ndevs, NULL, 0, NULL); > > } > > EXPORT_SYMBOL_NS(ocelot_core_init, MFD_OCELOT); > > > > we're good! (sorry about spaces / tabs... I have to up my mutt/vim/tmux > > game still) > > > > > > I like the enum / macro idea for cleanup, but I think that's a different > > problem I can address. The main question I have now is this: > > > > The ocelot_regmap_from_resource now has nothing to do with the ocelot > > MFD system. It is generic. (If you listen carefully, you might hear me > > cheering) > > > > I can keep this in linux/mfd/ocelot.h, but is this actually something > > that belongs elsewhere? platform? device? mfd-core? > > Sounds like something which could be named devm_platform_get_regmap_from_resource_or_parent(), > but I'm not 100% clear where it should sit. Platform devices are independent > of regmap, regmap is independent of platform devices, device core of both. > > FWIW platform devices are always built-in and have no config option; > regmap is bool and is selected by others. > > Logically, the melting pot of regmaps and platform devices is mfd. > However, it seems that include/linux/mfd/core.h only provides API for > mfd parent drivers, not children. So a new header would be needed? > > Alternatively, you could just duplicate this logic in the drivers > (by the way, only spelling out the function name takes up half of the > implementation). How many times would it be needed? Felix DSA would roll > its own thing, as mentioned. I'm thinking, let it be open coded for now, > let's agree on the entire solution in terms of operations that are > actually being done, and we can revisit proper placement for this later. I came to the same conclusion. Hopefully I'll button up v12 today. > > > And yes, I like the idea of changing the driver to > > "ocelot_regmap_from_resource(pdev, GPIO, config);" from > > "ocelot_regmap_from_resource(pdev, 0, config);" > > Sorry, I just realized we need to junk this idea with GPIO instead of 0. > Presenting the entire resource table to all peripherals implies that > there is no more than one single peripheral of each kind. This is not > true for the MDIO controllers, where the driver would need to know it > has to request the region corresponding to MIIM1 or MIIM2 according to > some crystal ball. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel