devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: Lee Jones <lee@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	alsa-devel@alsa-project.org,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v5 2/5] mfd: Add support for the Lantiq PEF2256 framer
Date: Thu, 13 Apr 2023 08:31:09 +0200	[thread overview]
Message-ID: <20230413083109.5ad09d2a@bootlin.com> (raw)
In-Reply-To: <20230412095918.GZ8371@google.com>

On Wed, 12 Apr 2023 10:59:18 +0100
Lee Jones <lee@kernel.org> wrote:

> On Tue, 11 Apr 2023, Herve Codina wrote:
> 
> > Hi Lee,
> >
> > On Wed, 5 Apr 2023 18:00:23 +0200
> > Herve Codina <herve.codina@bootlin.com> wrote:
> >  
> > > Hi Lee,
> > > On Wed, 5 Apr 2023 14:54:50 +0100
> > > Lee Jones <lee@kernel.org> 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.  
> 
> Looks like a bug.  Encountering one disabled cell should not prevent the
> others from registering IMHO.
> 

Thanks for your confirmation.
I will propose a fix in the next iteration of this series.

Regards,
Hervé

  reply	other threads:[~2023-04-13  6:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28  9:26 [PATCH v5 0/5] Add the Lantiq PEF2256 audio support Herve Codina
2023-03-28  9:26 ` [PATCH v5 1/5] dt-bindings: mfd: Add the Lantiq PEF2256 E1/T1/J1 framer Herve Codina
2023-03-28 10:39   ` Krzysztof Kozlowski
2023-03-28  9:26 ` [PATCH v5 2/5] mfd: Add support for the Lantiq PEF2256 framer Herve Codina
2023-03-30 16:05   ` Lee Jones
2023-03-31  7:42     ` Herve Codina
2023-03-31  9:13       ` Krzysztof Kozlowski
2023-03-31 12:11         ` Herve Codina
2023-03-31 13:44           ` Krzysztof Kozlowski
2023-03-31 14:59             ` Herve Codina
2023-04-03 14:28               ` Lee Jones
2023-04-04  7:20                 ` Herve Codina
2023-04-04  7:23                   ` Krzysztof Kozlowski
2023-04-04  8:07                     ` Herve Codina
2023-04-04  8:15                       ` Krzysztof Kozlowski
2023-04-05 13:54                         ` Lee Jones
2023-04-05 16:00                           ` Herve Codina
2023-04-11 16:16                             ` Herve Codina
2023-04-12  9:59                               ` Lee Jones
2023-04-13  6:31                                 ` Herve Codina [this message]
2023-03-28  9:26 ` [PATCH v5 3/5] Documentation: sysfs: Document the Lantiq PEF2256 sysfs entry Herve Codina
2023-03-28  9:26 ` [PATCH v5 4/5] ASoC: codecs: Add support for the Lantiq PEF2256 codec Herve Codina
2023-03-28  9:26 ` [PATCH v5 5/5] MAINTAINERS: Add the Lantiq PEF2256 driver entry Herve Codina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413083109.5ad09d2a@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).