linux-sound.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Alexey Klimov" <alexey.klimov@linaro.org>
To: "Christophe JAILLET" <christophe.jaillet@wanadoo.fr>
Cc: "Srinivas Kandagatla" <srini@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Stephen Boyd" <sboyd@kernel.org>, "Lee Jones" <lee@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>, <linux-arm-msm@vger.kernel.org>,
	<linux-sound@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>,
	"Srinivas Kandagatla" <srinivas.kandagatla@oss.qualcomm.com>
Subject: Re: [PATCH v2 2/3] ASoC: codecs: add new pm4125 audio codec driver
Date: Thu, 14 Aug 2025 00:04:13 +0100	[thread overview]
Message-ID: <DC1OBXZ7UUTZ.2V473MOKABPKJ@linaro.org> (raw)
In-Reply-To: <0acde3b4-a437-4fa1-b5bd-fe1810309bb8@wanadoo.fr>

On Fri Jul 11, 2025 at 4:15 PM BST, Christophe JAILLET wrote:
> Hi,

Hi Christophe,

>> +static int pm4125_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
>> +{
>> +	struct device *dev = &pdev->dev;
>> +	struct pm4125_sdw_priv *priv;
>> +	u8 master_ch_mask[PM4125_MAX_SWR_CH_IDS];
>> +	int master_ch_mask_size = 0;
>> +	int ret, i;
>> +
>> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return -ENOMEM;
>> +
>> +	/* Port map index starts at 0, however the data port for this codec starts at index 1 */
>> +	if (of_property_present(dev->of_node, "qcom,tx-port-mapping")) {
>> +		priv->is_tx = true;
>> +		ret = of_property_read_u32_array(dev->of_node, "qcom,tx-port-mapping",
>> +						 &pdev->m_port_map[1], PM4125_MAX_TX_SWR_PORTS);
>> +	} else
>> +		ret = of_property_read_u32_array(dev->of_node, "qcom,rx-port-mapping",
>> +						 &pdev->m_port_map[1], PM4125_MAX_SWR_PORTS);
>
> Nitpick: If a branch of an if needs { }, I think that both should have.

Yes. Thanks.

>> +
>> +	if (ret < 0)
>> +		dev_info(dev, "Error getting static port mapping for %s (%d)\n",
>> +			 priv->is_tx ? "TX" : "RX", ret);
>> +
>> +	priv->sdev = pdev;
>> +	dev_set_drvdata(dev, priv);
>
> ...
>
>> +static const struct sdw_device_id pm4125_slave_id[] = {
>> +	SDW_SLAVE_ENTRY(0x0217, 0x10c, 0), /* Soundwire pm4125 RX/TX Device ID */
>> +	{ },
>
> No need for a trailing comma after a terminator

Ok.


>> +};
>> +MODULE_DEVICE_TABLE(sdw, pm4125_slave_id);
>
> ...
>
>> +#include <linux/component.h>
>> +#include <linux/delay.h>
>> +#include <linux/device.h>
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pm_runtime.h>
>> +#include <linux/regmap.h>
>> +#include <linux/regulator/consumer.h>
>> +#include <linux/slab.h>
>> +#include <sound/jack.h>
>
> Maybe, keep alphabetical order?

It looks like the headers were sorted in pm4125-sdw.c.
However, in pm4125.c I changed the order a bit for the next submission.

>> +#include <sound/pcm_params.h>
>> +#include <sound/pcm.h>
>> +#include <sound/soc-dapm.h>
>> +#include <sound/soc.h>
>> +#include <sound/tlv.h>
>
> ...
>
>> +static int pm4125_bind(struct device *dev)
>
> If an error occures at some point, should things be undone before returning?

Thanks! This probably inherited from other codecs.
I reimplemented this for the next version.

>> +{
>> +	struct pm4125_priv *pm4125 = dev_get_drvdata(dev);
>> +	int ret;
>> +
>> +	/* Give the soundwire subdevices some more time to settle */
>> +	usleep_range(15000, 15010);
>> +
>> +	ret = component_bind_all(dev, pm4125);
>> +	if (ret) {
>> +		dev_err(dev, "Slave bind failed, ret = %d\n", ret);
>> +		return ret;
>> +	}
>> +
>> +	pm4125->rxdev = pm4125_sdw_device_get(pm4125->rxnode);
>> +	if (!pm4125->rxdev) {
>> +		dev_err(dev, "could not find rxslave with matching of node\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	pm4125->sdw_priv[AIF1_PB] = dev_get_drvdata(pm4125->rxdev);
>> +	pm4125->sdw_priv[AIF1_PB]->pm4125 = pm4125;
>> +
>> +	pm4125->txdev = pm4125_sdw_device_get(pm4125->txnode);
>> +	if (!pm4125->txdev) {
>> +		dev_err(dev, "could not find txslave with matching of node\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	pm4125->sdw_priv[AIF1_CAP] = dev_get_drvdata(pm4125->txdev);
>> +	pm4125->sdw_priv[AIF1_CAP]->pm4125 = pm4125;
>> +
>> +	pm4125->tx_sdw_dev = dev_to_sdw_dev(pm4125->txdev);
>> +	if (!pm4125->tx_sdw_dev) {
>> +		dev_err(dev, "could not get txslave with matching of dev\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	/*
>> +	 * As TX is the main CSR reg interface, which should not be suspended first.
>> +	 * expicilty add the dependency link
>> +	 */
>> +	if (!device_link_add(pm4125->rxdev, pm4125->txdev,
>> +			     DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) {
>> +		dev_err(dev, "Could not devlink TX and RX\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (!device_link_add(dev, pm4125->txdev,
>> +			     DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) {
>> +		dev_err(dev, "Could not devlink PM4125 and TX\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (!device_link_add(dev, pm4125->rxdev,
>> +			     DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) {
>> +		dev_err(dev, "Could not devlink PM4125 and RX\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	pm4125->regmap = dev_get_regmap(&pm4125->tx_sdw_dev->dev, NULL);
>> +	if (!pm4125->regmap) {
>> +		dev_err(dev, "could not get TX device regmap\n");
>> +		return -EINVAL;
>> +	}
>> +
>> +	ret = pm4125_irq_init(pm4125, dev);
>> +	if (ret) {
>> +		dev_err(dev, "IRQ init failed: %d\n", ret);
>> +		return ret;
>> +	}
>> +
>> +	pm4125->sdw_priv[AIF1_PB]->slave_irq = pm4125->virq;
>> +	pm4125->sdw_priv[AIF1_CAP]->slave_irq = pm4125->virq;
>> +
>> +	ret = pm4125_set_micbias_data(pm4125);
>> +	if (ret < 0) {
>> +		dev_err(dev, "Bad micbias pdata\n");
>> +		return ret;
>> +	}
>> +
>> +	ret = snd_soc_register_component(dev, &soc_codec_dev_pm4125,
>> +					 pm4125_dais, ARRAY_SIZE(pm4125_dais));
>> +	if (ret)
>> +		dev_err(dev, "Codec registration failed\n");
>> +
>> +	return ret;
>> +}

[..]

>> +static int pm4125_probe(struct platform_device *pdev)
>> +{
>> +	struct component_match *match = NULL;
>> +	struct device *dev = &pdev->dev;
>> +	struct pm4125_priv *pm4125;
>> +	struct wcd_mbhc_config *cfg;
>> +	int ret;
>> +
>> +	pm4125 = devm_kzalloc(dev, sizeof(*pm4125), GFP_KERNEL);
>> +	if (!pm4125)
>> +		return -ENOMEM;
>> +
>> +	dev_set_drvdata(dev, pm4125);
>> +
>> +	pm4125->supplies[0].supply = "vdd-io";
>> +	pm4125->supplies[1].supply = "vdd-cp";
>> +	pm4125->supplies[2].supply = "vdd-mic-bias";
>> +	pm4125->supplies[3].supply = "vdd-pa-vpos";
>> +
>> +	ret = devm_regulator_bulk_get(dev, PM4125_MAX_BULK_SUPPLY, pm4125->supplies);
>
> devm_regulator_bulk_get_enable() could certainly be used to save a few 
> lines of code after fix the missing regulator_bulk_disable() in the 
> error handling of the probe.

Thanks! I'll reimplement this.
For me it looks like after staring at devm_regulator_bulk_get_enable()
that regulator_bulk_disable() is not needed.

[..]

>> +static void pm4125_remove(struct platform_device *pdev)
>> +{
>> +	struct device *dev = &pdev->dev;
>> +	struct pm4125_priv *pm4125 = dev_get_drvdata(dev);
>> +
>> +	component_master_del(&pdev->dev, &pm4125_comp_ops);
>> +
>> +	pm_runtime_disable(dev);
>> +	pm_runtime_set_suspended(dev);
>> +	pm_runtime_dont_use_autosuspend(dev);
>> +
>> +	regulator_bulk_disable(PM4125_MAX_BULK_SUPPLY, pm4125->supplies);
>> +	regulator_bulk_free(PM4125_MAX_BULK_SUPPLY, pm4125->supplies);
>
> Is it correct? (it looks related to devm_regulator_bulk_get())

I'll take a look at that.

Thank you,
Alexey

  reply	other threads:[~2025-08-13 23:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11  3:00 [PATCH v2 0/3] Add PM4125 audio codec driver Alexey Klimov
2025-07-11  3:00 ` [PATCH v2 1/3] dt-bindings: sound: add bindings for pm4125 audio codec Alexey Klimov
2025-07-11  8:27   ` Krzysztof Kozlowski
2025-07-18 13:43   ` Lee Jones
2025-07-24 15:17     ` Alexey Klimov
2025-07-24 15:48       ` Krzysztof Kozlowski
2025-08-13 22:28         ` Alexey Klimov
2025-07-11  3:00 ` [PATCH v2 2/3] ASoC: codecs: add new pm4125 audio codec driver Alexey Klimov
2025-07-11  8:29   ` Krzysztof Kozlowski
2025-07-24 15:41     ` Alexey Klimov
2025-08-13 23:08     ` Alexey Klimov
2025-07-11 13:32   ` Srinivas Kandagatla
2025-08-13 23:07     ` Alexey Klimov
2025-07-11 15:15   ` Christophe JAILLET
2025-08-13 23:04     ` Alexey Klimov [this message]
2025-07-11  3:00 ` [PATCH v2 3/3] MAINTAINERS: add Qualcomm PM4125 audio codec to drivers list Alexey Klimov

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=DC1OBXZ7UUTZ.2V473MOKABPKJ@linaro.org \
    --to=alexey.klimov@linaro.org \
    --cc=broonie@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=srini@kernel.org \
    --cc=srinivas.kandagatla@oss.qualcomm.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).