From: "Shane.Chien" <shane.ch...@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.ch...@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

Reply via email to