Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5749547rwl; Tue, 11 Apr 2023 09:26:15 -0700 (PDT) X-Google-Smtp-Source: AKy350bpj93uEBxoMlAnwEUV/GO9MDehumbMgs0EilIWDk4dQoUbcLzB828BIzl66sGCDkFhmrK8 X-Received: by 2002:a17:906:dac7:b0:94a:5c6c:e19a with SMTP id xi7-20020a170906dac700b0094a5c6ce19amr9334141ejb.19.1681230374867; Tue, 11 Apr 2023 09:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681230374; cv=none; d=google.com; s=arc-20160816; b=Dy1sTH0YJfeSHQEXoCTHVcjn7d5hdecPQHrNNoEZ27sROX7I7RGxgyfME8Sezy6hTc xeKM76y7BCfx5VqgJrXxIUhhKNeIGire5TkYX9OY2Mgb3Yy0xqOzTXAGpbMnaRXJtp3u Y3vSscbzokHw22SjK/0oFuOwKiJPSj9tqFxwEX/QPvR1vclQmN+uOMIxDfy7JiQh+TQp meGonZ5/y1O7fK8yuf1X3Jqj31qI7RFSE4A6/El5oeJlFVoN7WuqYRFXeSXqb+CDsqRq m0Op0X6OB/y9dzdfxSz86sVKfuTdmtjBXJz7u0MhGYGJhh6+p+8EUtj5ej4v2IVLsdbv rgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=YN1HFAut0wlkhACR1rC7RVWyzDX8GM5pnpZhh86udRk=; b=utoxOF0KaQqaGj0WJn+IzX3+QNqScaP9t4/BfPDGPnRqv/Jse2RKV6uk3F23vjz1GD 37rRe0u/UDrSh5zc1PnxLZWkQjzVIXgYUfKYMNzBJdnl9D6MNYWIdpZdTFrce89IFSPs DHrSjY1oP/rAwjRfywrQp08Fw6alyal+rMCNyPFBuFmwcMwDiNs4BJ3yYazC0oYlAk2+ JQGJ5SXB/cD+9WcZkOjFOUY0qC3lEhO/jDh+60Ad+w7VY0i2kAISMK2TCyJvcBbI1uK4 cKh3T+ZBBw+MdGs+RDy4QYX3AtbZVIoDUP9TesxQhZNZuWFZymvQOcmJ097dg7Sx3Sgu Fwdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=EKMDssOG; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a1709067f9200b0094a9d9bdd90si1603857ejr.749.2023.04.11.09.25.48; Tue, 11 Apr 2023 09:26:14 -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=@bootlin.com header.s=gm1 header.b=EKMDssOG; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbjDKQSG (ORCPT + 99 others); Tue, 11 Apr 2023 12:18:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjDKQRv (ORCPT ); Tue, 11 Apr 2023 12:17:51 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE0492D53; Tue, 11 Apr 2023 09:16:44 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id EF10F1BF203; Tue, 11 Apr 2023 16:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1681229803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YN1HFAut0wlkhACR1rC7RVWyzDX8GM5pnpZhh86udRk=; b=EKMDssOG843Uardxa6RwBGRbMOzfLVszXIbDuTnWbFZ1B3lncrlUZE++iYyTOzyeat48k7 c4g0LlKJTXV/PvvYYgj+aPv3Dw/18k+BqyvXe00AhM2XJV+U5SpZp4EkWwodhOpAISw3y2 L5BKZTltFS0CREQXmMmorn5Ya56DHqZJuzUK1SI5i6oezMRh5WOsaOBuuCeUVzoZ6RLJ5V 05WE03kqdDkEv0aL/PaqbQfJKN4fDObGcDiEKaMLd4r9anaug2ArnmRnZF/kWNdeGak3pn OcaJh4DOFkxBCDztunLHiPOHVG5Au+YsFQ4ttteU5CeI3yDs0HVDpwwm8YAvTA== Date: Tue, 11 Apr 2023 18:16:40 +0200 From: Herve Codina To: Lee Jones Cc: Krzysztof Kozlowski , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: Re: [PATCH v5 2/5] mfd: Add support for the Lantiq PEF2256 framer Message-ID: <20230411181640.50c19d4e@bootlin.com> In-Reply-To: <20230405180023.4aebaa08@bootlin.com> References: <20230331094208.41ab4420@bootlin.com> <6d39e9c3-fb6a-4b2a-9889-8fe8d86716d5@linaro.org> <20230331141104.42445da9@bootlin.com> <20230331165904.4e7f46a1@bootlin.com> <20230403142822.GA8371@google.com> <20230404092036.2d1cd5d9@bootlin.com> <20230404100759.5bc9cd20@bootlin.com> <143754c2-9e37-4386-af92-174c0df2eb0a@linaro.org> <20230405135450.GF8371@google.com> <20230405180023.4aebaa08@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS 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 Hi Lee, On Wed, 5 Apr 2023 18:00:23 +0200 Herve Codina wrote: > Hi Lee, > On Wed, 5 Apr 2023 14:54:50 +0100 > Lee Jones wrote: > > > On Tue, 04 Apr 2023, Krzysztof Kozlowski wrote: > > > > > On 04/04/2023 10:07, Herve Codina wrote: > > > > > > >>> So, the structure I have in mind: > > > >>> - pef2256.c (MFD) > > > >>> implement and do the setup at probe() > > > >>> Add the children at probe(): > > > >>> - pef2256-pinctrl (pinctrl) added using mfd_add_devices() > > > >>> - pef2256-codec (ASoC codec) added using devm_of_platform_populate() > > > >>> > > > >>> Lee, with this in mind, can the core pef2256.c be a MFD driver ? > > > >> > > > >> You do not use MFD here, so why do you want to keep it in MFD? If you > > > >> disagree, please tell me where is the MFD code in your patch? > > > > > > > > I don't want to absolutely use MFD. > > > > I just want to put my driver somewhere and I don't know the right location > > > > between MFD and Misc. > > > > > > > > Basically, the driver needs to do (little simplified and error path removed): > > > > > > > > static const struct mfd_cell pef2256_devs[] = { > > > > { .name = "lantiq-pef2256-pinctrl", }, > > > > }; > > > > > > > > static int pef2256_probe(struct platform_device *pdev) > > > > { > > > > struct pef2256 *pef2256; > > > > void __iomem *iomem; > > > > int ret; > > > > int irq; > > > > > > > > pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); > > > > if (!pef2256) > > > > return -ENOMEM; > > > > > > > > pef2256->dev = &pdev->dev; > > > > > > > > iomem = devm_platform_ioremap_resource(pdev, 0); > > > > > > > > pef2256->regmap = devm_regmap_init_mmio(&pdev->dev, iomem, > > > > &pef2256_regmap_config); > > > > > > > > pef2256->mclk = devm_clk_get_enabled(&pdev->dev, "mclk"); > > > > pef2256->sclkr = devm_clk_get_enabled(&pdev->dev, "sclkr"); > > > > pef2256->sclkx = devm_clk_get_enabled(&pdev->dev, "sclkx"); > > > > > > > > pef2256->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); > > > > if (pef2256->reset_gpio) { > > > > gpiod_set_value_cansleep(pef2256->reset_gpio, 1); > > > > udelay(10); > > > > gpiod_set_value_cansleep(pef2256->reset_gpio, 0); > > > > udelay(10); > > > > } > > > > > > > > pef2556_of_parse(pef2256, np); > > > > > > > > irq = platform_get_irq(pdev, 0); > > > > ret = devm_request_irq(pef2256->dev, irq, pef2256_irq_handler, 0, "pef2256", pef2256); > > > > > > > > platform_set_drvdata(pdev, pef2256); > > > > > > > > mfd_add_devices(pef2256->dev, PLATFORM_DEVID_NONE, pef2256_devs, > > > > ARRAY_SIZE(pef2256_devs), NULL, 0, NULL); > > > > > > Wait, now you use MFD framework, so the driver is suitable for MFD. > > > Before there was nothing like that in your code. > > > > Agree, the above is suitable for MFD, since it does all the things I > > said your last one did not. You *can* also use of_platform_populate() > > here, since you are *also* requesting and initialising shared resources. > > You cannot do *both* however. > > > > Thanks for having confirmed that this driver can be a MFD driver. > > Related to of_platform_populate() / mfd_add_devices(), I wanted to use both > because: > - the pinctrl part does not have (and does not need to have) a specific node > with a specific compatible property. In order to instantiate the related > driver mfd_add_devices() is the only way I know. > - the audio component nodes have a compatible string and several components > (ie several nodes) can be present. of_platform_populate() call seems the > simple way to instantiate them. > > Is there a way to use mfd_add_devices() in this case without the need to > count the audio component nodes in order to allocate as much mfd_cell as > nodes having a matching compatible property ? Is there an other API to do > it ? > I looked deeper for using mfd_add_devices() only and found an issue (related to my use-case). mfd_add_devices() calls mfd_add_device() and in this function we have: ---- 8< ---- if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) { for_each_child_of_node(parent->of_node, np) { if (of_device_is_compatible(np, cell->of_compatible)) { /* Ignore 'disabled' devices error free */ if (!of_device_is_available(np)) { of_node_put(np); ret = 0; goto fail_alias; } ret = mfd_match_of_node_to_dev(pdev, np, cell); if (ret == -EAGAIN) continue; of_node_put(np); if (ret) goto fail_alias; break; } } if (!pdev->dev.of_node) pr_warn("%s: Failed to locate of_node [id: %d]\n", cell->name, platform_id); } ---- 8< ---- My issue is related to the loop. The loop is aborted if the device is not available (typically 'Disabled' in the DT node). My full pef2256 node can have several pef2256 audio subnodes with compatible set to "lantiq,pef2256-codec" and some of them can have 'status = "Disabled";' As soon as one device (with my expected compatible) is found 'Disabled', there is no way to look at other children. Having 'continue' in case of device not available in the loop to look at the next child will change the behavior of mfd_add_device(). Do you think that looking at next child if we find a 'not available' child can be correct for mfd_add_device() ? This probably will have impacts on other MFD drivers. Best regards, Hervé