diff options
| author | Koro Chen <koro.chen@mediatek.com> | 2015-06-15 10:38:04 -0400 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2015-06-16 07:52:36 -0400 |
| commit | 662e8d917f685011a24492c106737ea5fdff8136 (patch) | |
| tree | a47336fd836967a809393bb0892887ccbdcc62be | |
| parent | a54f6f0c5b7fb4048ea3de9751720090ac92a570 (diff) | |
ASoC: mediatek: Add machine driver for rt5650 rt5676 codec
This is the DPCM based machine driver with rt5650 and rt5676
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Koro Chen <koro.chen@mediatek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
| -rw-r--r-- | Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt | 13 | ||||
| -rw-r--r-- | sound/soc/mediatek/Kconfig | 11 | ||||
| -rw-r--r-- | sound/soc/mediatek/Makefile | 1 | ||||
| -rw-r--r-- | sound/soc/mediatek/mt8173-rt5650-rt5676.c | 278 |
4 files changed, 303 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt b/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt new file mode 100644 index 000000000000..61e98c976bd4 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/mt8173-rt5650-rt5676.txt | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | MT8173 with RT5650 RT5676 CODECS | ||
| 2 | |||
| 3 | Required properties: | ||
| 4 | - compatible : "mediatek,mt8173-rt5650-rt5676" | ||
| 5 | - mediatek,audio-codec: the phandles of rt5650 and rt5676 codecs | ||
| 6 | |||
| 7 | Example: | ||
| 8 | |||
| 9 | sound { | ||
| 10 | compatible = "mediatek,mt8173-rt5650-rt5676"; | ||
| 11 | mediatek,audio-codec = <&rt5650 &rt5676>; | ||
| 12 | }; | ||
| 13 | |||
diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig index 0bfd2a02a408..15c04e2eae34 100644 --- a/sound/soc/mediatek/Kconfig +++ b/sound/soc/mediatek/Kconfig | |||
| @@ -17,3 +17,14 @@ config SND_SOC_MT8173_MAX98090 | |||
| 17 | Select Y if you have such device. | 17 | Select Y if you have such device. |
| 18 | If unsure select "N". | 18 | If unsure select "N". |
| 19 | 19 | ||
| 20 | config SND_SOC_MT8173_RT5650_RT5676 | ||
| 21 | tristate "ASoC Audio driver for MT8173 with RT5650 RT5676 codecs" | ||
| 22 | depends on SND_SOC_MEDIATEK | ||
| 23 | select SND_SOC_RT5645 | ||
| 24 | select SND_SOC_RT5677 | ||
| 25 | help | ||
| 26 | This adds ASoC driver for Mediatek MT8173 boards | ||
| 27 | with the RT5650 and RT5676 codecs. | ||
| 28 | Select Y if you have such device. | ||
| 29 | If unsure select "N". | ||
| 30 | |||
diff --git a/sound/soc/mediatek/Makefile b/sound/soc/mediatek/Makefile index 08fa765b1f0b..75effbec438d 100644 --- a/sound/soc/mediatek/Makefile +++ b/sound/soc/mediatek/Makefile | |||
| @@ -2,3 +2,4 @@ | |||
| 2 | obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o | 2 | obj-$(CONFIG_SND_SOC_MEDIATEK) += mtk-afe-pcm.o |
| 3 | # Machine support | 3 | # Machine support |
| 4 | obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o | 4 | obj-$(CONFIG_SND_SOC_MT8173_MAX98090) += mt8173-max98090.o |
| 5 | obj-$(CONFIG_SND_SOC_MT8173_RT5650_RT5676) += mt8173-rt5650-rt5676.o | ||
diff --git a/sound/soc/mediatek/mt8173-rt5650-rt5676.c b/sound/soc/mediatek/mt8173-rt5650-rt5676.c new file mode 100644 index 000000000000..094055323059 --- /dev/null +++ b/sound/soc/mediatek/mt8173-rt5650-rt5676.c | |||
| @@ -0,0 +1,278 @@ | |||
| 1 | /* | ||
| 2 | * mt8173-rt5650-rt5676.c -- MT8173 machine driver with RT5650/5676 codecs | ||
| 3 | * | ||
| 4 | * Copyright (c) 2015 MediaTek Inc. | ||
| 5 | * Author: Koro Chen <koro.chen@mediatek.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 and | ||
| 9 | * only version 2 as published by the Free Software Foundation. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/gpio.h> | ||
| 19 | #include <linux/of_gpio.h> | ||
| 20 | #include <sound/soc.h> | ||
| 21 | #include <sound/jack.h> | ||
| 22 | #include "../codecs/rt5645.h" | ||
| 23 | #include "../codecs/rt5677.h" | ||
| 24 | |||
| 25 | #define MCLK_FOR_CODECS 12288000 | ||
| 26 | |||
| 27 | static const struct snd_soc_dapm_widget mt8173_rt5650_rt5676_widgets[] = { | ||
| 28 | SND_SOC_DAPM_SPK("Speaker", NULL), | ||
| 29 | SND_SOC_DAPM_MIC("Int Mic", NULL), | ||
| 30 | SND_SOC_DAPM_HP("Headphone", NULL), | ||
| 31 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | ||
| 32 | }; | ||
| 33 | |||
| 34 | static const struct snd_soc_dapm_route mt8173_rt5650_rt5676_routes[] = { | ||
| 35 | {"Speaker", NULL, "SPOL"}, | ||
| 36 | {"Speaker", NULL, "SPOR"}, | ||
| 37 | {"Speaker", NULL, "Sub AIF2TX"}, /* IF2 ADC to 5650 */ | ||
| 38 | {"Sub DMIC L1", NULL, "Int Mic"}, /* DMIC from 5676 */ | ||
| 39 | {"Sub DMIC R1", NULL, "Int Mic"}, | ||
| 40 | {"Headphone", NULL, "HPOL"}, | ||
| 41 | {"Headphone", NULL, "HPOR"}, | ||
| 42 | {"Headphone", NULL, "Sub AIF2TX"}, /* IF2 ADC to 5650 */ | ||
| 43 | {"Headset Mic", NULL, "micbias1"}, | ||
| 44 | {"Headset Mic", NULL, "micbias2"}, | ||
| 45 | {"IN1P", NULL, "Headset Mic"}, | ||
| 46 | {"IN1N", NULL, "Headset Mic"}, | ||
| 47 | {"Sub AIF2RX", NULL, "Headset Mic"}, /* IF2 DAC from 5650 */ | ||
| 48 | }; | ||
| 49 | |||
| 50 | static const struct snd_kcontrol_new mt8173_rt5650_rt5676_controls[] = { | ||
| 51 | SOC_DAPM_PIN_SWITCH("Speaker"), | ||
| 52 | SOC_DAPM_PIN_SWITCH("Int Mic"), | ||
| 53 | SOC_DAPM_PIN_SWITCH("Headphone"), | ||
| 54 | SOC_DAPM_PIN_SWITCH("Headset Mic"), | ||
| 55 | }; | ||
| 56 | |||
| 57 | static int mt8173_rt5650_rt5676_hw_params(struct snd_pcm_substream *substream, | ||
| 58 | struct snd_pcm_hw_params *params) | ||
| 59 | { | ||
| 60 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
| 61 | int i, ret; | ||
| 62 | |||
| 63 | for (i = 0; i < rtd->num_codecs; i++) { | ||
| 64 | struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; | ||
| 65 | |||
| 66 | /* pll from mclk 12.288M */ | ||
| 67 | ret = snd_soc_dai_set_pll(codec_dai, 0, 0, MCLK_FOR_CODECS, | ||
| 68 | params_rate(params) * 512); | ||
| 69 | if (ret) | ||
| 70 | return ret; | ||
| 71 | |||
| 72 | /* sysclk from pll */ | ||
| 73 | ret = snd_soc_dai_set_sysclk(codec_dai, 1, | ||
| 74 | params_rate(params) * 512, | ||
| 75 | SND_SOC_CLOCK_IN); | ||
| 76 | if (ret) | ||
| 77 | return ret; | ||
| 78 | } | ||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | static struct snd_soc_ops mt8173_rt5650_rt5676_ops = { | ||
| 83 | .hw_params = mt8173_rt5650_rt5676_hw_params, | ||
| 84 | }; | ||
| 85 | |||
| 86 | static struct snd_soc_jack mt8173_rt5650_rt5676_jack; | ||
| 87 | |||
| 88 | static int mt8173_rt5650_rt5676_init(struct snd_soc_pcm_runtime *runtime) | ||
| 89 | { | ||
| 90 | struct snd_soc_card *card = runtime->card; | ||
| 91 | struct snd_soc_codec *codec = runtime->codec_dais[0]->codec; | ||
| 92 | struct snd_soc_codec *codec_sub = runtime->codec_dais[1]->codec; | ||
| 93 | int ret; | ||
| 94 | |||
| 95 | rt5645_sel_asrc_clk_src(codec, | ||
| 96 | RT5645_DA_STEREO_FILTER | | ||
| 97 | RT5645_AD_STEREO_FILTER, | ||
| 98 | RT5645_CLK_SEL_I2S1_ASRC); | ||
| 99 | rt5677_sel_asrc_clk_src(codec_sub, | ||
| 100 | RT5677_DA_STEREO_FILTER | | ||
| 101 | RT5677_AD_STEREO1_FILTER, | ||
| 102 | RT5677_CLK_SEL_I2S1_ASRC); | ||
| 103 | rt5677_sel_asrc_clk_src(codec_sub, | ||
| 104 | RT5677_AD_STEREO2_FILTER | | ||
| 105 | RT5677_I2S2_SOURCE, | ||
| 106 | RT5677_CLK_SEL_I2S2_ASRC); | ||
| 107 | |||
| 108 | /* enable jack detection */ | ||
| 109 | ret = snd_soc_card_jack_new(card, "Headset Jack", | ||
| 110 | SND_JACK_HEADPHONE | SND_JACK_MICROPHONE | | ||
| 111 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | | ||
| 112 | SND_JACK_BTN_2 | SND_JACK_BTN_3, | ||
| 113 | &mt8173_rt5650_rt5676_jack, NULL, 0); | ||
| 114 | if (ret) { | ||
| 115 | dev_err(card->dev, "Can't new Headset Jack %d\n", ret); | ||
| 116 | return ret; | ||
| 117 | } | ||
| 118 | |||
| 119 | return rt5645_set_jack_detect(codec, | ||
| 120 | &mt8173_rt5650_rt5676_jack, | ||
| 121 | &mt8173_rt5650_rt5676_jack, | ||
| 122 | &mt8173_rt5650_rt5676_jack); | ||
| 123 | } | ||
| 124 | |||
| 125 | static struct snd_soc_dai_link_component mt8173_rt5650_rt5676_codecs[] = { | ||
| 126 | { | ||
| 127 | .dai_name = "rt5645-aif1", | ||
| 128 | }, | ||
| 129 | { | ||
| 130 | .dai_name = "rt5677-aif1", | ||
| 131 | }, | ||
| 132 | }; | ||
| 133 | |||
| 134 | /* Digital audio interface glue - connects codec <---> CPU */ | ||
| 135 | static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = { | ||
| 136 | /* Front End DAI links */ | ||
| 137 | { | ||
| 138 | .name = "rt5650_rt5676 Playback", | ||
| 139 | .stream_name = "rt5650_rt5676 Playback", | ||
| 140 | .cpu_dai_name = "DL1", | ||
| 141 | .platform_name = "11220000.mt8173-afe-pcm", | ||
| 142 | .codec_name = "snd-soc-dummy", | ||
| 143 | .codec_dai_name = "snd-soc-dummy-dai", | ||
| 144 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, | ||
| 145 | .dynamic = 1, | ||
| 146 | .dpcm_playback = 1, | ||
| 147 | }, | ||
| 148 | { | ||
| 149 | .name = "rt5650_rt5676 Capture", | ||
| 150 | .stream_name = "rt5650_rt5676 Capture", | ||
| 151 | .cpu_dai_name = "VUL", | ||
| 152 | .platform_name = "11220000.mt8173-afe-pcm", | ||
| 153 | .codec_name = "snd-soc-dummy", | ||
| 154 | .codec_dai_name = "snd-soc-dummy-dai", | ||
| 155 | .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, | ||
| 156 | .dynamic = 1, | ||
| 157 | .dpcm_capture = 1, | ||
| 158 | }, | ||
| 159 | |||
| 160 | /* Back End DAI links */ | ||
| 161 | { | ||
| 162 | .name = "Codec", | ||
| 163 | .cpu_dai_name = "I2S", | ||
| 164 | .platform_name = "11220000.mt8173-afe-pcm", | ||
| 165 | .no_pcm = 1, | ||
| 166 | .codecs = mt8173_rt5650_rt5676_codecs, | ||
| 167 | .num_codecs = 2, | ||
| 168 | .init = mt8173_rt5650_rt5676_init, | ||
| 169 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
| 170 | SND_SOC_DAIFMT_CBS_CFS, | ||
| 171 | .ops = &mt8173_rt5650_rt5676_ops, | ||
| 172 | .ignore_pmdown_time = 1, | ||
| 173 | .dpcm_playback = 1, | ||
| 174 | .dpcm_capture = 1, | ||
| 175 | }, | ||
| 176 | { /* rt5676 <-> rt5650 intercodec link: Sets rt5676 I2S2 as master */ | ||
| 177 | .name = "rt5650_rt5676 intercodec", | ||
| 178 | .stream_name = "rt5650_rt5676 intercodec", | ||
| 179 | .cpu_dai_name = "snd-soc-dummy-dai", | ||
| 180 | .platform_name = "snd-soc-dummy", | ||
| 181 | .no_pcm = 1, | ||
| 182 | .codec_dai_name = "rt5677-aif2", | ||
| 183 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
| 184 | SND_SOC_DAIFMT_CBM_CFM, | ||
| 185 | }, | ||
| 186 | |||
| 187 | }; | ||
| 188 | |||
| 189 | static struct snd_soc_codec_conf mt8173_rt5650_rt5676_codec_conf[] = { | ||
| 190 | { | ||
| 191 | .name_prefix = "Sub", | ||
| 192 | }, | ||
| 193 | }; | ||
| 194 | |||
| 195 | static struct snd_soc_card mt8173_rt5650_rt5676_card = { | ||
| 196 | .name = "mtk-rt5650-rt5676", | ||
| 197 | .dai_link = mt8173_rt5650_rt5676_dais, | ||
| 198 | .num_links = ARRAY_SIZE(mt8173_rt5650_rt5676_dais), | ||
| 199 | .codec_conf = mt8173_rt5650_rt5676_codec_conf, | ||
| 200 | .num_configs = ARRAY_SIZE(mt8173_rt5650_rt5676_codec_conf), | ||
| 201 | .controls = mt8173_rt5650_rt5676_controls, | ||
| 202 | .num_controls = ARRAY_SIZE(mt8173_rt5650_rt5676_controls), | ||
| 203 | .dapm_widgets = mt8173_rt5650_rt5676_widgets, | ||
| 204 | .num_dapm_widgets = ARRAY_SIZE(mt8173_rt5650_rt5676_widgets), | ||
| 205 | .dapm_routes = mt8173_rt5650_rt5676_routes, | ||
| 206 | .num_dapm_routes = ARRAY_SIZE(mt8173_rt5650_rt5676_routes), | ||
| 207 | }; | ||
| 208 | |||
| 209 | static int mt8173_rt5650_rt5676_dev_probe(struct platform_device *pdev) | ||
| 210 | { | ||
| 211 | struct snd_soc_card *card = &mt8173_rt5650_rt5676_card; | ||
| 212 | int ret; | ||
| 213 | |||
| 214 | mt8173_rt5650_rt5676_codecs[0].of_node = | ||
| 215 | of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 0); | ||
| 216 | if (!mt8173_rt5650_rt5676_codecs[0].of_node) { | ||
| 217 | dev_err(&pdev->dev, | ||
| 218 | "Property 'audio-codec' missing or invalid\n"); | ||
| 219 | return -EINVAL; | ||
| 220 | } | ||
| 221 | mt8173_rt5650_rt5676_codecs[1].of_node = | ||
| 222 | of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 1); | ||
| 223 | if (!mt8173_rt5650_rt5676_codecs[1].of_node) { | ||
| 224 | dev_err(&pdev->dev, | ||
| 225 | "Property 'audio-codec' missing or invalid\n"); | ||
| 226 | return -EINVAL; | ||
| 227 | } | ||
| 228 | mt8173_rt5650_rt5676_codec_conf[0].of_node = | ||
| 229 | mt8173_rt5650_rt5676_codecs[1].of_node; | ||
| 230 | |||
| 231 | mt8173_rt5650_rt5676_dais[3].codec_of_node = | ||
| 232 | mt8173_rt5650_rt5676_codecs[1].of_node; | ||
| 233 | |||
| 234 | card->dev = &pdev->dev; | ||
| 235 | platform_set_drvdata(pdev, card); | ||
| 236 | |||
| 237 | ret = snd_soc_register_card(card); | ||
| 238 | if (ret) | ||
| 239 | dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", | ||
| 240 | __func__, ret); | ||
| 241 | return ret; | ||
| 242 | } | ||
| 243 | |||
| 244 | static int mt8173_rt5650_rt5676_dev_remove(struct platform_device *pdev) | ||
| 245 | { | ||
| 246 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
| 247 | |||
| 248 | snd_soc_unregister_card(card); | ||
| 249 | return 0; | ||
| 250 | } | ||
| 251 | |||
| 252 | static const struct of_device_id mt8173_rt5650_rt5676_dt_match[] = { | ||
| 253 | { .compatible = "mediatek,mt8173-rt5650-rt5676", }, | ||
| 254 | { } | ||
| 255 | }; | ||
| 256 | MODULE_DEVICE_TABLE(of, mt8173_rt5650_rt5676_dt_match); | ||
| 257 | |||
| 258 | static struct platform_driver mt8173_rt5650_rt5676_driver = { | ||
| 259 | .driver = { | ||
| 260 | .name = "mtk-rt5650-rt5676", | ||
| 261 | .owner = THIS_MODULE, | ||
| 262 | .of_match_table = mt8173_rt5650_rt5676_dt_match, | ||
| 263 | #ifdef CONFIG_PM | ||
| 264 | .pm = &snd_soc_pm_ops, | ||
| 265 | #endif | ||
| 266 | }, | ||
| 267 | .probe = mt8173_rt5650_rt5676_dev_probe, | ||
| 268 | .remove = mt8173_rt5650_rt5676_dev_remove, | ||
| 269 | }; | ||
| 270 | |||
| 271 | module_platform_driver(mt8173_rt5650_rt5676_driver); | ||
| 272 | |||
| 273 | /* Module information */ | ||
| 274 | MODULE_DESCRIPTION("MT8173 RT5650 and RT5676 SoC machine driver"); | ||
| 275 | MODULE_AUTHOR("Koro Chen <koro.chen@mediatek.com>"); | ||
| 276 | MODULE_LICENSE("GPL v2"); | ||
| 277 | MODULE_ALIAS("platform:mtk-rt5650-rt5676"); | ||
| 278 | |||
