Commit 03824376 authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: mediatek: mt8183-da7219: support machine driver for...

Merge series "ASoC: mediatek: mt8183-da7219: support machine driver for rt1015" from Tzung-Bi Shih <tzungbi@google.com>:

This series tries to reuse mt8183-da7219-max98357.c for supporting machine
driver with rt1015 speaker amplifier.

The first 3 patches refactor the code for easier to change for subsequent
patches.

The 4th patch adds document for the new proposed compatible string.

The 5th patch changes the machine driver to support either "MAX98357A" or
"RT1015" codecs.

Tzung-Bi Shih (5):
  ASoC: mediatek: mt8183-da7219: sort header inclusions in alphabetical
  ASoC: mediatek: mt8183-da7219: remove forward declaration of
    headset_init
  ASoC: mediatek: mt8183-da7219: extract codec and DAI names
  ASoC: mediatek: mt8183-da7219: add compatible string for using rt1015
  ASoC: mediatek: mt8183-da7219: support machine driver with rt1015

 .../bindings/sound/mt8183-da7219-max98357.txt |   5 +-
 sound/soc/mediatek/Kconfig                    |   5 +-
 .../mediatek/mt8183/mt8183-da7219-max98357.c  | 244 ++++++++++++++----
 3 files changed, 197 insertions(+), 57 deletions(-)

--
2.27.0.383.g050319c2ae-goog
parents 1c6579b5 9e30251f
MT8183 with MT6358, DA7219 and MAX98357 CODECS
MT8183 with MT6358, DA7219, MAX98357, and RT1015 CODECS
Required properties:
- compatible : "mediatek,mt8183_da7219_max98357"
- compatible : "mediatek,mt8183_da7219_max98357" for MAX98357A codec
"mediatek,mt8183_da7219_rt1015" for RT1015 codec
- mediatek,headset-codec: the phandles of da7219 codecs
- mediatek,platform: the phandle of MT8183 ASoC platform
......
......@@ -134,15 +134,16 @@ config SND_SOC_MT8183_MT6358_TS3A227E_MAX98357A
If unsure select "N".
config SND_SOC_MT8183_DA7219_MAX98357A
tristate "ASoC Audio driver for MT8183 with DA7219 MAX98357A codec"
tristate "ASoC Audio driver for MT8183 with DA7219 MAX98357A RT1015 codec"
depends on SND_SOC_MT8183 && I2C
select SND_SOC_MT6358
select SND_SOC_MAX98357A
select SND_SOC_RT1015
select SND_SOC_DA7219
select SND_SOC_BT_SCO
help
This adds ASoC driver for Mediatek MT8183 boards
with the DA7219 MAX98357A audio codec.
with the DA7219 MAX98357A RT1015 audio codec.
Select Y if you have such device.
If unsure select "N".
......
......@@ -8,14 +8,22 @@
#include <linux/input.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/pinctrl/consumer.h>
#include <sound/jack.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include "mt8183-afe-common.h"
#include "../../codecs/da7219-aad.h"
#include "../../codecs/da7219.h"
#include "../../codecs/rt1015.h"
#include "mt8183-afe-common.h"
#define DA7219_CODEC_DAI "da7219-hifi"
#define DA7219_DEV_NAME "da7219.5-001a"
#define RT1015_CODEC_DAI "rt1015-aif"
#define RT1015_DEV0_NAME "rt1015.6-0028"
#define RT1015_DEV1_NAME "rt1015.6-0029"
struct mt8183_da7219_max98357_priv {
struct snd_soc_jack headset_jack;
......@@ -54,8 +62,7 @@ static int mt8183_da7219_i2s_hw_params(struct snd_pcm_substream *substream,
dev_err(rtd->dev, "failed to set cpu dai sysclk\n");
for_each_rtd_codec_dais(rtd, j, codec_dai) {
if (!strcmp(codec_dai->component->name, "da7219.5-001a")) {
if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) {
ret = snd_soc_dai_set_sysclk(codec_dai,
DA7219_CLKSRC_MCLK,
mclk_fs,
......@@ -87,8 +94,7 @@ static int mt8183_da7219_hw_free(struct snd_pcm_substream *substream)
int ret = 0, j;
for_each_rtd_codec_dais(rtd, j, codec_dai) {
if (!strcmp(codec_dai->component->name, "da7219.5-001a")) {
if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) {
ret = snd_soc_dai_set_pll(codec_dai,
0, DA7219_SYSCLK_MCLK, 0, 0);
if (ret < 0) {
......@@ -107,6 +113,51 @@ static const struct snd_soc_ops mt8183_da7219_i2s_ops = {
.hw_free = mt8183_da7219_hw_free,
};
static int
mt8183_da7219_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
unsigned int rate = params_rate(params);
struct snd_soc_dai *codec_dai;
int ret = 0, i;
for_each_rtd_codec_dais(rtd, i, codec_dai) {
if (!strcmp(codec_dai->component->name, RT1015_DEV0_NAME) ||
!strcmp(codec_dai->component->name, RT1015_DEV1_NAME)) {
ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64);
if (ret) {
dev_err(rtd->dev, "failed to set bclk ratio\n");
return ret;
}
ret = snd_soc_dai_set_pll(codec_dai, 0,
RT1015_PLL_S_BCLK,
rate * 64, rate * 256);
if (ret) {
dev_err(rtd->dev, "failed to set pll\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai,
RT1015_SCLK_S_PLL,
rate * 256,
SND_SOC_CLOCK_IN);
if (ret) {
dev_err(rtd->dev, "failed to set sysclk\n");
return ret;
}
}
}
return mt8183_da7219_i2s_hw_params(substream, params);
}
static const struct snd_soc_ops mt8183_da7219_rt1015_i2s_ops = {
.hw_params = mt8183_da7219_rt1015_i2s_hw_params,
.hw_free = mt8183_da7219_hw_free,
};
static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
......@@ -119,6 +170,18 @@ static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
return 0;
}
static int mt8183_rt1015_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
struct snd_pcm_hw_params *params)
{
/* fix BE i2s format to 32bit, clean param mask first */
snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
0, SNDRV_PCM_FORMAT_LAST);
params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
return 0;
}
static int
mt8183_da7219_max98357_startup(
struct snd_pcm_substream *substream)
......@@ -268,13 +331,20 @@ SND_SOC_DAILINK_DEFS(i2s1,
SND_SOC_DAILINK_DEFS(i2s2,
DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
DAILINK_COMP_ARRAY(COMP_CODEC("da7219.5-001a", "da7219-hifi")),
DAILINK_COMP_ARRAY(COMP_CODEC(DA7219_DEV_NAME, DA7219_CODEC_DAI)),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
SND_SOC_DAILINK_DEFS(i2s3,
SND_SOC_DAILINK_DEFS(i2s3_max98357a,
DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
DAILINK_COMP_ARRAY(COMP_CODEC("max98357a", "HiFi"),
COMP_CODEC("da7219.5-001a", "da7219-hifi")),
COMP_CODEC(DA7219_DEV_NAME, DA7219_CODEC_DAI)),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
SND_SOC_DAILINK_DEFS(i2s3_rt1015,
DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
DAILINK_COMP_ARRAY(COMP_CODEC(RT1015_DEV0_NAME, RT1015_CODEC_DAI),
COMP_CODEC(RT1015_DEV1_NAME, RT1015_CODEC_DAI),
COMP_CODEC(DA7219_DEV_NAME, DA7219_CODEC_DAI)),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
SND_SOC_DAILINK_DEFS(i2s5,
......@@ -287,7 +357,7 @@ SND_SOC_DAILINK_DEFS(tdm,
DAILINK_COMP_ARRAY(COMP_DUMMY()),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = {
static struct snd_soc_dai_link mt8183_da7219_dai_links[] = {
/* FE */
{
.name = "Playback_1",
......@@ -422,9 +492,6 @@ static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = {
.no_pcm = 1,
.dpcm_playback = 1,
.ignore_suspend = 1,
.be_hw_params_fixup = mt8183_i2s_hw_params_fixup,
.ops = &mt8183_da7219_i2s_ops,
SND_SOC_DAILINK_REG(i2s3),
},
{
.name = "I2S5",
......@@ -449,7 +516,36 @@ static struct snd_soc_dai_link mt8183_da7219_max98357_dai_links[] = {
};
static int
mt8183_da7219_max98357_headset_init(struct snd_soc_component *component);
mt8183_da7219_max98357_headset_init(struct snd_soc_component *component)
{
int ret;
struct mt8183_da7219_max98357_priv *priv =
snd_soc_card_get_drvdata(component->card);
/* Enable Headset and 4 Buttons Jack detection */
ret = snd_soc_card_jack_new(component->card,
"Headset Jack",
SND_JACK_HEADSET |
SND_JACK_BTN_0 | SND_JACK_BTN_1 |
SND_JACK_BTN_2 | SND_JACK_BTN_3,
&priv->headset_jack,
NULL, 0);
if (ret)
return ret;
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
da7219_aad_jack_det(component, &priv->headset_jack);
return 0;
}
static struct snd_soc_aux_dev mt8183_da7219_max98357_headset_dev = {
.dlc = COMP_EMPTY(),
......@@ -488,57 +584,56 @@ static struct snd_soc_card mt8183_da7219_max98357_card = {
.num_dapm_widgets = ARRAY_SIZE(mt8183_da7219_max98357_dapm_widgets),
.dapm_routes = mt8183_da7219_max98357_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(mt8183_da7219_max98357_dapm_routes),
.dai_link = mt8183_da7219_max98357_dai_links,
.num_links = ARRAY_SIZE(mt8183_da7219_max98357_dai_links),
.dai_link = mt8183_da7219_dai_links,
.num_links = ARRAY_SIZE(mt8183_da7219_dai_links),
.aux_dev = &mt8183_da7219_max98357_headset_dev,
.num_aux_devs = 1,
.codec_conf = mt6358_codec_conf,
.num_configs = ARRAY_SIZE(mt6358_codec_conf),
};
static int
mt8183_da7219_max98357_headset_init(struct snd_soc_component *component)
{
int ret;
struct mt8183_da7219_max98357_priv *priv =
snd_soc_card_get_drvdata(component->card);
/* Enable Headset and 4 Buttons Jack detection */
ret = snd_soc_card_jack_new(&mt8183_da7219_max98357_card,
"Headset Jack",
SND_JACK_HEADSET |
SND_JACK_BTN_0 | SND_JACK_BTN_1 |
SND_JACK_BTN_2 | SND_JACK_BTN_3,
&priv->headset_jack,
NULL, 0);
if (ret)
return ret;
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
snd_jack_set_key(
priv->headset_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
da7219_aad_jack_det(component, &priv->headset_jack);
static struct snd_soc_codec_conf mt8183_da7219_rt1015_codec_conf[] = {
{
.dlc = COMP_CODEC_CONF("mt6358-sound"),
.name_prefix = "Mt6358",
},
{
.dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
.name_prefix = "Left",
},
{
.dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
.name_prefix = "Right",
},
};
return 0;
}
static struct snd_soc_card mt8183_da7219_rt1015_card = {
.name = "mt8183_da7219_rt1015",
.owner = THIS_MODULE,
.controls = mt8183_da7219_max98357_snd_controls,
.num_controls = ARRAY_SIZE(mt8183_da7219_max98357_snd_controls),
.dapm_widgets = mt8183_da7219_max98357_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(mt8183_da7219_max98357_dapm_widgets),
.dapm_routes = mt8183_da7219_max98357_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(mt8183_da7219_max98357_dapm_routes),
.dai_link = mt8183_da7219_dai_links,
.num_links = ARRAY_SIZE(mt8183_da7219_dai_links),
.aux_dev = &mt8183_da7219_max98357_headset_dev,
.num_aux_devs = 1,
.codec_conf = mt8183_da7219_rt1015_codec_conf,
.num_configs = ARRAY_SIZE(mt8183_da7219_rt1015_codec_conf),
};
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;
struct device_node *platform_node;
struct snd_soc_dai_link *dai_link;
struct mt8183_da7219_max98357_priv *priv;
struct pinctrl *pinctrl;
const struct of_device_id *match;
int ret, i;
card->dev = &pdev->dev;
platform_node = of_parse_phandle(pdev->dev.of_node,
"mediatek,platform", 0);
if (!platform_node) {
......@@ -546,10 +641,46 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
return -EINVAL;
}
match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
if (!match || !match->data)
return -EINVAL;
card = (struct snd_soc_card *)match->data;
card->dev = &pdev->dev;
for_each_card_prelinks(card, i, dai_link) {
if (dai_link->platforms->name)
continue;
dai_link->platforms->of_node = platform_node;
if (strcmp(dai_link->name, "I2S3") == 0) {
if (card == &mt8183_da7219_max98357_card) {
dai_link->be_hw_params_fixup =
mt8183_i2s_hw_params_fixup;
dai_link->ops = &mt8183_mt6358_i2s_ops;
dai_link->cpus = i2s3_max98357a_cpus;
dai_link->num_cpus =
ARRAY_SIZE(i2s3_max98357a_cpus);
dai_link->codecs = i2s3_max98357a_codecs;
dai_link->num_codecs =
ARRAY_SIZE(i2s3_max98357a_codecs);
dai_link->platforms = i2s3_max98357a_platforms;
dai_link->num_platforms =
ARRAY_SIZE(i2s3_max98357a_platforms);
} else if (card == &mt8183_da7219_rt1015_card) {
dai_link->be_hw_params_fixup =
mt8183_rt1015_i2s_hw_params_fixup;
dai_link->ops = &mt8183_da7219_rt1015_i2s_ops;
dai_link->cpus = i2s3_rt1015_cpus;
dai_link->num_cpus =
ARRAY_SIZE(i2s3_rt1015_cpus);
dai_link->codecs = i2s3_rt1015_codecs;
dai_link->num_codecs =
ARRAY_SIZE(i2s3_rt1015_codecs);
dai_link->platforms = i2s3_rt1015_platforms;
dai_link->num_platforms =
ARRAY_SIZE(i2s3_rt1015_platforms);
}
}
if (!dai_link->platforms->name)
dai_link->platforms->of_node = platform_node;
}
mt8183_da7219_max98357_headset_dev.dlc.of_node =
......@@ -580,14 +711,21 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
#ifdef CONFIG_OF
static const struct of_device_id mt8183_da7219_max98357_dt_match[] = {
{.compatible = "mediatek,mt8183_da7219_max98357",},
{
.compatible = "mediatek,mt8183_da7219_max98357",
.data = &mt8183_da7219_max98357_card,
},
{
.compatible = "mediatek,mt8183_da7219_rt1015",
.data = &mt8183_da7219_rt1015_card,
},
{}
};
#endif
static struct platform_driver mt8183_da7219_max98357_driver = {
.driver = {
.name = "mt8183_da7219_max98357",
.name = "mt8183_da7219",
#ifdef CONFIG_OF
.of_match_table = mt8183_da7219_max98357_dt_match,
#endif
......
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