Skip to contentSkip to conversation

ASoC: Add compatible for mt6359-sound device

RFC In review Shane Chien 3 participants 4 messages Dec 1, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 ASoC: Add compatible for mt6359-sound device

From: "Shane.Chien" <[email protected]>

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?

---
 sound/soc/codecs/mt6359.c |   58 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6359.h |    7 ++++++
 2 files changed, 65 insertions(+)
sound/soc/codecs/mt6359.c +58 -0
index 6de0d74..1fb47f4 100644
@@ -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,
 };
sound/soc/codecs/mt6359.h +7 -0
index 35f806b..52d2398 100644
@@ -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"
Signature · 5 lines
1.7.9.5
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#1 lore raw
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Shane,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on asoc/for-next]
[also build test WARNING on next-20201130]
[cannot apply to v5.10-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Shane-Chien/ASoC-Add-compatible-for-mt6359-sound-device/20201201-134616
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: nios2-allyesconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/5e3af2882978915507e75552c058e189b36ae0af
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shane-Chien/ASoC-Add-compatible-for-mt6359-sound-device/20201201-134616 git checkout 5e3af2882978915507e75552c058e189b36ae0af
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from include/linux/printk.h:7,

                    from include/linux/kernel.h:16,
                    from include/linux/delay.h:22,
                    from sound/soc/codecs/mt6359.c:8:
   sound/soc/codecs/mt6359.c: In function 'mt6359_get_audio_auxadc':
>> include/linux/kern_levels.h:5:18: warning: format '%s' expects a matching 'char *' argument [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:13:21: note: in expansion of macro 'KERN_SOH'
      13 | #define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
         |                     ^~~~~~~~
   include/linux/printk.h:363:9: note: in expansion of macro 'KERN_NOTICE'
     363 |  printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~
   sound/soc/codecs/mt6359.c:2760:3: note: in expansion of macro 'pr_notice'
    2760 |   pr_notice("%s() not support\n");
         |   ^~~~~~~~~
   sound/soc/codecs/mt6359.c:2760:15: note: format string is defined here
    2760 |   pr_notice("%s() not support\n");
         |              ~^
         |               |
         |               char *
   At top level:
   sound/soc/codecs/mt6359.c:2746:12: warning: 'mt6359_get_audio_auxadc' defined but not used [-Wunused-function]
    2746 | static int mt6359_get_audio_auxadc(struct mt6359_priv *priv, int auxadc_ch)
         |            ^~~~~~~~~~~~~~~~~~~~~~~

vim +5 include/linux/kern_levels.h

314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Shane Chien
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Shane,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on asoc/for-next]
[also build test ERROR on next-20201130]
[cannot apply to v5.10-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Shane-Chien/ASoC-Add-compatible-for-mt6359-sound-device/20201201-134616
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm64-randconfig-r035-20201201 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ac40a2d8f16b8a8c68fc811d67f647740e965cb8)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/5e3af2882978915507e75552c058e189b36ae0af
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Shane-Chien/ASoC-Add-compatible-for-mt6359-sound-device/20201201-134616 git checkout 5e3af2882978915507e75552c058e189b36ae0af
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

aarch64-linux-gnu-ld: warning: -z norelro ignored
aarch64-linux-gnu-ld: Unexpected GOT/PLT entries detected!
aarch64-linux-gnu-ld: Unexpected run-time procedure linkages detected!
aarch64-linux-gnu-ld: sound/soc/codecs/mt6359.o: in function `mt6359_platform_driver_probe':

>> mt6359.c:(.text+0x690): undefined reference to `devm_iio_channel_get'
>> aarch64-linux-gnu-ld: mt6359.c:(.text+0x6b8): undefined reference to `devm_iio_channel_get'
--
>> sound/soc/codecs/mt6359.c:2760:15: warning: more '%' conversions than data arguments [-Wformat-insufficient-args]
                   pr_notice("%s() not support\n");
                              ~^
   include/linux/printk.h:363:28: note: expanded from macro 'pr_notice'
           printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
                                     ^~~
   include/linux/printk.h:301:21: note: expanded from macro 'pr_fmt'
   #define pr_fmt(fmt) fmt
                       ^~~
   sound/soc/codecs/mt6359.c:2746:12: warning: unused function 'mt6359_get_audio_auxadc' [-Wunused-function]
   static int mt6359_get_audio_auxadc(struct mt6359_priv *priv, int auxadc_ch)
              ^

2 warnings generated.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#3 lore raw
In reply to Shane Chien
Quoted 8 lines · Shane Chien

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

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek