linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC] ASoC: Add compatible for mt6359-sound device
@ 2020-12-01  5:41 Shane Chien
  2020-12-01 15:16 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Shane Chien @ 2020-12-01  5:41 UTC (permalink / raw)
  To: Matthias Brugger, Mark Brown
  Cc: devicetree, alsa-devel, chipeng.chang, wsd_upstream, fan.chen,
	linux-kernel, jiaxin.yu, jeter.chen, tzungbi, linux-mediatek,
	shane.chien, Hsin-Hsiung.Wang

From: "Shane.Chien" <shane.chien@mediatek.com>

In the change "[v2,1/2] Add mediatek codec mt6359 driver",
The compatible of mt6359-sound device is removed
due to it is regarded as a part of parent device,
which is only reflecting Linux model instead of hardware.
However, if the device is not given a comaptible,
of_node of struct device is null. I cannot use
devm_iio_channel_get such iio interface to get
auxadc value from iio channel. Because during
using devm_iio_channel_get, of_node of mt6359-sound is a
input parameter of of_iio_channel_get_by_name.
If the of_node is null, devm_iio_channel_get will
eventually return ENODEV error.
static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
						      const char *name)
{
	struct iio_channel *chan = NULL;

	/* Walk up the tree of devices looking for a matching iio channel */
	while (np) {  // np is null and will not enter the while loop
	....
	}
	return chan; // directly return null
}
I add the compatible back to mt6359.c and it
can successfully use devm_iio_channel_get without error.
Is there any suggestions if I need to use this kind of
native interface or can I add the compatible directly?
And I wonder what kind of device can add compatible
under mfd device?

Signed-off-by: Shane.Chien <shane.chien@mediatek.com>
---
 sound/soc/codecs/mt6359.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6359.h |    7 ++++++
 2 files changed, 65 insertions(+)

diff --git a/sound/soc/codecs/mt6359.c b/sound/soc/codecs/mt6359.c
index 6de0d74..1fb47f4 100644
--- a/sound/soc/codecs/mt6359.c
+++ b/sound/soc/codecs/mt6359.c
@@ -12,6 +12,7 @@
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
+#include <linux/iio/consumer.h>
 #include <linux/sched.h>
 #include <sound/soc.h>
 #include <sound/tlv.h>
@@ -2741,6 +2742,37 @@ static void mt6359_codec_remove(struct snd_soc_component *cmpnt)
 	.num_dapm_routes = ARRAY_SIZE(mt6359_dapm_routes),
 };
 
+/* dc trim */
+static int mt6359_get_audio_auxadc(struct mt6359_priv *priv, int auxadc_ch)
+{
+	int value = 0;
+	int ret;
+	struct iio_channel *auxadc;
+
+	switch (auxadc_ch) {
+	case AUXADC_HP_OFFSET_CAL:
+		auxadc = priv->hpofs_cal_auxadc;
+		break;
+	case AUXADC_ACCDET:
+		auxadc = priv->accdet_auxadc;
+		break;
+	default:
+		pr_notice("%s() not support\n");
+		break;
+	}
+
+	if (!IS_ERR(auxadc)) {
+		ret = iio_read_channel_processed(auxadc, &value);
+		if (ret < 0) {
+			pr_err("Error: %s read fail (%d)\n", __func__, ret);
+			return ret;
+		}
+	}
+	pr_info("%s() value %d\n", __func__, value);
+
+	return value;
+}
+
 static int mt6359_parse_dt(struct mt6359_priv *priv)
 {
 	int ret;
@@ -2783,6 +2815,25 @@ static int mt6359_parse_dt(struct mt6359_priv *priv)
 		priv->mux_select[MUX_MIC_TYPE_2] = MIC_TYPE_MUX_IDLE;
 	}
 
+	/* get auxadc channel */
+	priv->hpofs_cal_auxadc = devm_iio_channel_get(dev,
+						      "pmic_hpofs_cal");
+	ret = PTR_ERR_OR_ZERO(priv->hpofs_cal_auxadc);
+	if (ret) {
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev,
+				"%s() Get pmic_hpofs_cal iio ch failed (%d)\n",
+				__func__, ret);
+	}
+	priv->accdet_auxadc = devm_iio_channel_get(dev, "pmic_accdet");
+	ret = PTR_ERR_OR_ZERO(priv->accdet_auxadc);
+	if (ret) {
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev,
+				"%s() Get pmic_accdet iio ch failed (%d)\n",
+				__func__, ret);
+	}
+
 	return 0;
 }
 
@@ -2818,9 +2869,16 @@ static int mt6359_platform_driver_probe(struct platform_device *pdev)
 					       ARRAY_SIZE(mt6359_dai_driver));
 }
 
+static const struct of_device_id mt6359_of_match[] = {
+	{.compatible = "mediatek,mt6359-sound",},
+	{}
+};
+MODULE_DEVICE_TABLE(of, mt6359_of_match);
+
 static struct platform_driver mt6359_platform_driver = {
 	.driver = {
 		.name = "mt6359-sound",
+		.of_match_table = mt6359_of_match,
 	},
 	.probe = mt6359_platform_driver_probe,
 };
diff --git a/sound/soc/codecs/mt6359.h b/sound/soc/codecs/mt6359.h
index 35f806b..52d2398 100644
--- a/sound/soc/codecs/mt6359.h
+++ b/sound/soc/codecs/mt6359.h
@@ -2610,6 +2610,11 @@ enum {
 	PGA_3_MUX_AIN2,
 };
 
+enum {
+	AUXADC_HP_OFFSET_CAL = 0,
+	AUXADC_ACCDET,
+};
+
 struct mt6359_priv {
 	struct device *dev;
 	struct regmap *regmap;
@@ -2622,6 +2627,8 @@ struct mt6359_priv {
 	int hp_gain_ctl;
 	int hp_hifi_mode;
 	int mtkaif_protocol;
+	struct iio_channel *hpofs_cal_auxadc;
+	struct iio_channel *accdet_auxadc;
 };
 
 #define CODEC_MT6359_NAME "mtk-codec-mt6359"
-- 
1.7.9.5
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC] ASoC: Add compatible for mt6359-sound device
  2020-12-01  5:41 [RFC] ASoC: Add compatible for mt6359-sound device Shane Chien
@ 2020-12-01 15:16 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2020-12-01 15:16 UTC (permalink / raw)
  To: Shane Chien
  Cc: devicetree, alsa-devel, chipeng.chang, wsd_upstream, fan.chen,
	linux-kernel, jiaxin.yu, jeter.chen, tzungbi, linux-mediatek,
	Matthias Brugger, Hsin-Hsiung.Wang


[-- Attachment #1.1: Type: text/plain, Size: 737 bytes --]

On Tue, Dec 01, 2020 at 01:41:33PM +0800, Shane Chien wrote:

> However, if the device is not given a comaptible,
> of_node of struct device is null. I cannot use
> devm_iio_channel_get such iio interface to get
> auxadc value from iio channel. Because during
> using devm_iio_channel_get, of_node of mt6359-sound is a
> input parameter of of_iio_channel_get_by_name.
> If the of_node is null, devm_iio_channel_get will
> eventually return ENODEV error.

I would expect the IIO channel to be requestable using the top level
device for the MFD - part of the deal here is that the function drivers
for the MFD know they're part of the MFD so can look at their parent
device for some things (eg, this is how regmaps are normally obtained).

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-01 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-01  5:41 [RFC] ASoC: Add compatible for mt6359-sound device Shane Chien
2020-12-01 15:16 ` Mark Brown

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).