Commit 8726ee61 authored by Tzung-Bi Shih's avatar Tzung-Bi Shih Committed by Mark Brown

ASoC: mediatek: mt8183-da7219: pull TDM GPIO pins down when probed

1. Switch TDM GPIO pins according to playback on or off.
2. Pull TDM GPIO pins down when probed to avoid current leakage.
Signed-off-by: default avatarTzung-Bi Shih <tzungbi@google.com>
Link: https://lore.kernel.org/r/20200213112003.2.I1d568b0c99742c6e755d051aadfd52e4be3cc0a5@changeidSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent ec7ba9e1
...@@ -18,6 +18,22 @@ ...@@ -18,6 +18,22 @@
static struct snd_soc_jack headset_jack; static struct snd_soc_jack headset_jack;
enum PINCTRL_PIN_STATE {
PIN_STATE_DEFAULT = 0,
PIN_TDM_OUT_ON,
PIN_TDM_OUT_OFF,
PIN_STATE_MAX
};
static const char * const mt8183_pin_str[PIN_STATE_MAX] = {
"default", "aud_tdm_out_on", "aud_tdm_out_off",
};
struct mt8183_da7219_max98357_priv {
struct pinctrl *pinctrl;
struct pinctrl_state *pin_states[PIN_STATE_MAX];
};
static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream, static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
...@@ -244,6 +260,47 @@ SND_SOC_DAILINK_DEFS(tdm, ...@@ -244,6 +260,47 @@ SND_SOC_DAILINK_DEFS(tdm,
DAILINK_COMP_ARRAY(COMP_DUMMY()), DAILINK_COMP_ARRAY(COMP_DUMMY()),
DAILINK_COMP_ARRAY(COMP_EMPTY())); DAILINK_COMP_ARRAY(COMP_EMPTY()));
static int mt8183_da7219_tdm_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct mt8183_da7219_max98357_priv *priv =
snd_soc_card_get_drvdata(rtd->card);
int ret;
if (IS_ERR(priv->pin_states[PIN_TDM_OUT_ON]))
return PTR_ERR(priv->pin_states[PIN_TDM_OUT_ON]);
ret = pinctrl_select_state(priv->pinctrl,
priv->pin_states[PIN_TDM_OUT_ON]);
if (ret)
dev_err(rtd->card->dev, "%s failed to select state %d\n",
__func__, ret);
return ret;
}
static void mt8183_da7219_tdm_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct mt8183_da7219_max98357_priv *priv =
snd_soc_card_get_drvdata(rtd->card);
int ret;
if (IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF]))
return;
ret = pinctrl_select_state(priv->pinctrl,
priv->pin_states[PIN_TDM_OUT_OFF]);
if (ret)
dev_err(rtd->card->dev, "%s failed to select state %d\n",
__func__, ret);
}
static struct snd_soc_ops mt8183_da7219_tdm_ops = {
.startup = mt8183_da7219_tdm_startup,
.shutdown = mt8183_da7219_tdm_shutdown,
};
static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = { static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = {
/* FE */ /* FE */
{ {
...@@ -395,6 +452,8 @@ static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = { ...@@ -395,6 +452,8 @@ static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = {
.no_pcm = 1, .no_pcm = 1,
.dpcm_playback = 1, .dpcm_playback = 1,
.ignore_suspend = 1, .ignore_suspend = 1,
.be_hw_params_fixup = mt8183_i2s_hw_params_fixup,
.ops = &mt8183_da7219_tdm_ops,
SND_SOC_DAILINK_REG(tdm), SND_SOC_DAILINK_REG(tdm),
}, },
}; };
...@@ -470,7 +529,7 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev) ...@@ -470,7 +529,7 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
struct snd_soc_card *card = &mt8183_da7219_max98357_card; struct snd_soc_card *card = &mt8183_da7219_max98357_card;
struct device_node *platform_node; struct device_node *platform_node;
struct snd_soc_dai_link *dai_link; struct snd_soc_dai_link *dai_link;
struct pinctrl *default_pins; struct mt8183_da7219_max98357_priv *priv;
int ret, i; int ret, i;
card->dev = &pdev->dev; card->dev = &pdev->dev;
...@@ -504,12 +563,45 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev) ...@@ -504,12 +563,45 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
return ret; return ret;
} }
default_pins = priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
devm_pinctrl_get_select(&pdev->dev, PINCTRL_STATE_DEFAULT); if (!priv)
if (IS_ERR(default_pins)) { return -ENOMEM;
dev_err(&pdev->dev, "%s set pins failed\n",
snd_soc_card_set_drvdata(card, priv);
priv->pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(priv->pinctrl)) {
dev_err(&pdev->dev, "%s devm_pinctrl_get failed\n",
__func__); __func__);
return PTR_ERR(default_pins); return PTR_ERR(priv->pinctrl);
}
for (i = 0; i < PIN_STATE_MAX; i++) {
priv->pin_states[i] = pinctrl_lookup_state(priv->pinctrl,
mt8183_pin_str[i]);
if (IS_ERR(priv->pin_states[i])) {
ret = PTR_ERR(priv->pin_states[i]);
dev_info(&pdev->dev, "%s Can't find pin state %s %d\n",
__func__, mt8183_pin_str[i], ret);
}
}
if (!IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) {
ret = pinctrl_select_state(priv->pinctrl,
priv->pin_states[PIN_TDM_OUT_OFF]);
if (ret)
dev_info(&pdev->dev,
"%s failed to select state %d\n",
__func__, ret);
}
if (!IS_ERR(priv->pin_states[PIN_STATE_DEFAULT])) {
ret = pinctrl_select_state(priv->pinctrl,
priv->pin_states[PIN_STATE_DEFAULT]);
if (ret)
dev_info(&pdev->dev,
"%s failed to select state %d\n",
__func__, ret);
} }
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment