From: Shane Chien <shane.chien@mediatek.com>
To: Matthias Brugger <matthias.bgg@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>,
<devicetree@vger.kernel.org>, <wsd_upstream@mediatek.com>,
<alsa-devel@alsa-project.org>, <jiaxin.yu@mediatek.com>,
<chipeng.chang@mediatek.com>, <jeter.chen@mediatek.com>,
<tzungbi@google.com>, <fan.chen@mediatek.com>,
<Hsin-Hsiung.Wang@mediatek.com>, <shane.chien@mediatek.com>
Subject: [RFC] ASoC: Add compatible for mt6359-sound device
Date: Tue, 1 Dec 2020 13:41:33 +0800 [thread overview]
Message-ID: <1606801293-19472-1-git-send-email-shane.chien@mediatek.com> (raw)
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
next reply other threads:[~2020-12-01 5:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 5:41 Shane Chien [this message]
2020-12-01 15:16 ` Mark Brown
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=1606801293-19472-1-git-send-email-shane.chien@mediatek.com \
--to=shane.chien@mediatek.com \
--cc=Hsin-Hsiung.Wang@mediatek.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=chipeng.chang@mediatek.com \
--cc=devicetree@vger.kernel.org \
--cc=fan.chen@mediatek.com \
--cc=jeter.chen@mediatek.com \
--cc=jiaxin.yu@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=tzungbi@google.com \
--cc=wsd_upstream@mediatek.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
all inboxes | Powered by JetHome®