0001
0002
0003
0004
0005
0006
0007 #include <sound/soc.h>
0008 #include <sound/soc-dapm.h>
0009 #include <sound/jack.h>
0010 #include <linux/gpio.h>
0011 #include <linux/module.h>
0012
0013 #include "../codecs/wm5102.h"
0014 #include "../codecs/wm9081.h"
0015
0016
0017 #define BCLK2_RATE (64 * 8000)
0018
0019
0020
0021
0022
0023 #define MCLK_RATE 24576000
0024
0025 #define SYS_AUDIO_RATE 44100
0026 #define SYS_MCLK_RATE (SYS_AUDIO_RATE * 512)
0027
0028 #define DAI_AP_DSP 0
0029 #define DAI_DSP_CODEC 1
0030 #define DAI_CODEC_CP 2
0031 #define DAI_CODEC_SUB 3
0032
0033 struct bells_drvdata {
0034 int sysclk_rate;
0035 int asyncclk_rate;
0036 };
0037
0038 static struct bells_drvdata wm2200_drvdata = {
0039 .sysclk_rate = 22579200,
0040 };
0041
0042 static struct bells_drvdata wm5102_drvdata = {
0043 .sysclk_rate = 45158400,
0044 .asyncclk_rate = 49152000,
0045 };
0046
0047 static struct bells_drvdata wm5110_drvdata = {
0048 .sysclk_rate = 135475200,
0049 .asyncclk_rate = 147456000,
0050 };
0051
0052 static int bells_set_bias_level(struct snd_soc_card *card,
0053 struct snd_soc_dapm_context *dapm,
0054 enum snd_soc_bias_level level)
0055 {
0056 struct snd_soc_pcm_runtime *rtd;
0057 struct snd_soc_dai *codec_dai;
0058 struct snd_soc_component *component;
0059 struct bells_drvdata *bells = card->drvdata;
0060 int ret;
0061
0062 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_DSP_CODEC]);
0063 codec_dai = asoc_rtd_to_codec(rtd, 0);
0064 component = codec_dai->component;
0065
0066 if (dapm->dev != codec_dai->dev)
0067 return 0;
0068
0069 switch (level) {
0070 case SND_SOC_BIAS_PREPARE:
0071 if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
0072 break;
0073
0074 ret = snd_soc_component_set_pll(component, WM5102_FLL1,
0075 ARIZONA_FLL_SRC_MCLK1,
0076 MCLK_RATE,
0077 bells->sysclk_rate);
0078 if (ret < 0)
0079 pr_err("Failed to start FLL: %d\n", ret);
0080
0081 if (bells->asyncclk_rate) {
0082 ret = snd_soc_component_set_pll(component, WM5102_FLL2,
0083 ARIZONA_FLL_SRC_AIF2BCLK,
0084 BCLK2_RATE,
0085 bells->asyncclk_rate);
0086 if (ret < 0)
0087 pr_err("Failed to start FLL: %d\n", ret);
0088 }
0089 break;
0090
0091 default:
0092 break;
0093 }
0094
0095 return 0;
0096 }
0097
0098 static int bells_set_bias_level_post(struct snd_soc_card *card,
0099 struct snd_soc_dapm_context *dapm,
0100 enum snd_soc_bias_level level)
0101 {
0102 struct snd_soc_pcm_runtime *rtd;
0103 struct snd_soc_dai *codec_dai;
0104 struct snd_soc_component *component;
0105 struct bells_drvdata *bells = card->drvdata;
0106 int ret;
0107
0108 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_DSP_CODEC]);
0109 codec_dai = asoc_rtd_to_codec(rtd, 0);
0110 component = codec_dai->component;
0111
0112 if (dapm->dev != codec_dai->dev)
0113 return 0;
0114
0115 switch (level) {
0116 case SND_SOC_BIAS_STANDBY:
0117 ret = snd_soc_component_set_pll(component, WM5102_FLL1, 0, 0, 0);
0118 if (ret < 0) {
0119 pr_err("Failed to stop FLL: %d\n", ret);
0120 return ret;
0121 }
0122
0123 if (bells->asyncclk_rate) {
0124 ret = snd_soc_component_set_pll(component, WM5102_FLL2,
0125 0, 0, 0);
0126 if (ret < 0) {
0127 pr_err("Failed to stop FLL: %d\n", ret);
0128 return ret;
0129 }
0130 }
0131 break;
0132
0133 default:
0134 break;
0135 }
0136
0137 dapm->bias_level = level;
0138
0139 return 0;
0140 }
0141
0142 static int bells_late_probe(struct snd_soc_card *card)
0143 {
0144 struct bells_drvdata *bells = card->drvdata;
0145 struct snd_soc_pcm_runtime *rtd;
0146 struct snd_soc_component *wm0010;
0147 struct snd_soc_component *component;
0148 struct snd_soc_dai *aif1_dai;
0149 struct snd_soc_dai *aif2_dai;
0150 struct snd_soc_dai *aif3_dai;
0151 struct snd_soc_dai *wm9081_dai;
0152 int ret;
0153
0154 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_AP_DSP]);
0155 wm0010 = asoc_rtd_to_codec(rtd, 0)->component;
0156
0157 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_DSP_CODEC]);
0158 component = asoc_rtd_to_codec(rtd, 0)->component;
0159 aif1_dai = asoc_rtd_to_codec(rtd, 0);
0160
0161 ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_SYSCLK,
0162 ARIZONA_CLK_SRC_FLL1,
0163 bells->sysclk_rate,
0164 SND_SOC_CLOCK_IN);
0165 if (ret != 0) {
0166 dev_err(component->dev, "Failed to set SYSCLK: %d\n", ret);
0167 return ret;
0168 }
0169
0170 ret = snd_soc_component_set_sysclk(wm0010, 0, 0, SYS_MCLK_RATE, 0);
0171 if (ret != 0) {
0172 dev_err(wm0010->dev, "Failed to set WM0010 clock: %d\n", ret);
0173 return ret;
0174 }
0175
0176 ret = snd_soc_dai_set_sysclk(aif1_dai, ARIZONA_CLK_SYSCLK, 0, 0);
0177 if (ret != 0)
0178 dev_err(aif1_dai->dev, "Failed to set AIF1 clock: %d\n", ret);
0179
0180 ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_OPCLK, 0,
0181 SYS_MCLK_RATE, SND_SOC_CLOCK_OUT);
0182 if (ret != 0)
0183 dev_err(component->dev, "Failed to set OPCLK: %d\n", ret);
0184
0185 if (card->num_rtd == DAI_CODEC_CP)
0186 return 0;
0187
0188 ret = snd_soc_component_set_sysclk(component, ARIZONA_CLK_ASYNCCLK,
0189 ARIZONA_CLK_SRC_FLL2,
0190 bells->asyncclk_rate,
0191 SND_SOC_CLOCK_IN);
0192 if (ret != 0) {
0193 dev_err(component->dev, "Failed to set ASYNCCLK: %d\n", ret);
0194 return ret;
0195 }
0196
0197 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_CODEC_CP]);
0198 aif2_dai = asoc_rtd_to_cpu(rtd, 0);
0199
0200 ret = snd_soc_dai_set_sysclk(aif2_dai, ARIZONA_CLK_ASYNCCLK, 0, 0);
0201 if (ret != 0) {
0202 dev_err(aif2_dai->dev, "Failed to set AIF2 clock: %d\n", ret);
0203 return ret;
0204 }
0205
0206 if (card->num_rtd == DAI_CODEC_SUB)
0207 return 0;
0208
0209 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[DAI_CODEC_SUB]);
0210 aif3_dai = asoc_rtd_to_cpu(rtd, 0);
0211 wm9081_dai = asoc_rtd_to_codec(rtd, 0);
0212
0213 ret = snd_soc_dai_set_sysclk(aif3_dai, ARIZONA_CLK_SYSCLK, 0, 0);
0214 if (ret != 0) {
0215 dev_err(aif1_dai->dev, "Failed to set AIF1 clock: %d\n", ret);
0216 return ret;
0217 }
0218
0219 ret = snd_soc_component_set_sysclk(wm9081_dai->component, WM9081_SYSCLK_MCLK,
0220 0, SYS_MCLK_RATE, 0);
0221 if (ret != 0) {
0222 dev_err(wm9081_dai->dev, "Failed to set MCLK: %d\n", ret);
0223 return ret;
0224 }
0225
0226 return 0;
0227 }
0228
0229 static const struct snd_soc_pcm_stream baseband_params = {
0230 .formats = SNDRV_PCM_FMTBIT_S32_LE,
0231 .rate_min = 8000,
0232 .rate_max = 8000,
0233 .channels_min = 2,
0234 .channels_max = 2,
0235 };
0236
0237 static const struct snd_soc_pcm_stream sub_params = {
0238 .formats = SNDRV_PCM_FMTBIT_S32_LE,
0239 .rate_min = SYS_AUDIO_RATE,
0240 .rate_max = SYS_AUDIO_RATE,
0241 .channels_min = 2,
0242 .channels_max = 2,
0243 };
0244
0245 SND_SOC_DAILINK_DEFS(wm2200_cpu_dsp,
0246 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
0247 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
0248 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
0249
0250 SND_SOC_DAILINK_DEFS(wm2200_dsp_codec,
0251 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
0252 DAILINK_COMP_ARRAY(COMP_CODEC("wm2200.1-003a", "wm2200")));
0253
0254 static struct snd_soc_dai_link bells_dai_wm2200[] = {
0255 {
0256 .name = "CPU-DSP",
0257 .stream_name = "CPU-DSP",
0258 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0259 | SND_SOC_DAIFMT_CBM_CFM,
0260 SND_SOC_DAILINK_REG(wm2200_cpu_dsp),
0261 },
0262 {
0263 .name = "DSP-CODEC",
0264 .stream_name = "DSP-CODEC",
0265 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0266 | SND_SOC_DAIFMT_CBM_CFM,
0267 .params = &sub_params,
0268 .ignore_suspend = 1,
0269 SND_SOC_DAILINK_REG(wm2200_dsp_codec),
0270 },
0271 };
0272
0273 SND_SOC_DAILINK_DEFS(wm5102_cpu_dsp,
0274 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
0275 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
0276 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
0277
0278 SND_SOC_DAILINK_DEFS(wm5102_dsp_codec,
0279 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
0280 DAILINK_COMP_ARRAY(COMP_CODEC("wm5102-codec", "wm5102-aif1")));
0281
0282 SND_SOC_DAILINK_DEFS(wm5102_baseband,
0283 DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif2")),
0284 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
0285
0286 SND_SOC_DAILINK_DEFS(wm5102_sub,
0287 DAILINK_COMP_ARRAY(COMP_CPU("wm5102-aif3")),
0288 DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
0289
0290 static struct snd_soc_dai_link bells_dai_wm5102[] = {
0291 {
0292 .name = "CPU-DSP",
0293 .stream_name = "CPU-DSP",
0294 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0295 | SND_SOC_DAIFMT_CBM_CFM,
0296 SND_SOC_DAILINK_REG(wm5102_cpu_dsp),
0297 },
0298 {
0299 .name = "DSP-CODEC",
0300 .stream_name = "DSP-CODEC",
0301 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0302 | SND_SOC_DAIFMT_CBM_CFM,
0303 .params = &sub_params,
0304 .ignore_suspend = 1,
0305 SND_SOC_DAILINK_REG(wm5102_dsp_codec),
0306 },
0307 {
0308 .name = "Baseband",
0309 .stream_name = "Baseband",
0310 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0311 | SND_SOC_DAIFMT_CBM_CFM,
0312 .ignore_suspend = 1,
0313 .params = &baseband_params,
0314 SND_SOC_DAILINK_REG(wm5102_baseband),
0315 },
0316 {
0317 .name = "Sub",
0318 .stream_name = "Sub",
0319 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0320 | SND_SOC_DAIFMT_CBS_CFS,
0321 .ignore_suspend = 1,
0322 .params = &sub_params,
0323 SND_SOC_DAILINK_REG(wm5102_sub),
0324 },
0325 };
0326
0327 SND_SOC_DAILINK_DEFS(wm5110_cpu_dsp,
0328 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
0329 DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "wm0010-sdi1")),
0330 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
0331
0332 SND_SOC_DAILINK_DEFS(wm5110_dsp_codec,
0333 DAILINK_COMP_ARRAY(COMP_CPU("wm0010-sdi2")),
0334 DAILINK_COMP_ARRAY(COMP_CODEC("wm5110-codec", "wm5110-aif1")));
0335
0336 SND_SOC_DAILINK_DEFS(wm5110_baseband,
0337 DAILINK_COMP_ARRAY(COMP_CPU("wm5110-aif2")),
0338 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
0339
0340
0341 SND_SOC_DAILINK_DEFS(wm5110_sub,
0342 DAILINK_COMP_ARRAY(COMP_CPU("wm5110-aif3")),
0343 DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
0344
0345 static struct snd_soc_dai_link bells_dai_wm5110[] = {
0346 {
0347 .name = "CPU-DSP",
0348 .stream_name = "CPU-DSP",
0349 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0350 | SND_SOC_DAIFMT_CBM_CFM,
0351 SND_SOC_DAILINK_REG(wm5110_cpu_dsp),
0352 },
0353 {
0354 .name = "DSP-CODEC",
0355 .stream_name = "DSP-CODEC",
0356 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0357 | SND_SOC_DAIFMT_CBM_CFM,
0358 .params = &sub_params,
0359 .ignore_suspend = 1,
0360 SND_SOC_DAILINK_REG(wm5110_dsp_codec),
0361 },
0362 {
0363 .name = "Baseband",
0364 .stream_name = "Baseband",
0365 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0366 | SND_SOC_DAIFMT_CBM_CFM,
0367 .ignore_suspend = 1,
0368 .params = &baseband_params,
0369 SND_SOC_DAILINK_REG(wm5110_baseband),
0370 },
0371 {
0372 .name = "Sub",
0373 .stream_name = "Sub",
0374 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
0375 | SND_SOC_DAIFMT_CBS_CFS,
0376 .ignore_suspend = 1,
0377 .params = &sub_params,
0378 SND_SOC_DAILINK_REG(wm5110_sub),
0379 },
0380 };
0381
0382 static struct snd_soc_codec_conf bells_codec_conf[] = {
0383 {
0384 .dlc = COMP_CODEC_CONF("wm9081.1-006c"),
0385 .name_prefix = "Sub",
0386 },
0387 };
0388
0389 static const struct snd_soc_dapm_widget bells_widgets[] = {
0390 SND_SOC_DAPM_MIC("DMIC", NULL),
0391 };
0392
0393 static const struct snd_soc_dapm_route bells_routes[] = {
0394 { "Sub CLK_SYS", NULL, "OPCLK" },
0395 { "CLKIN", NULL, "OPCLK" },
0396
0397 { "DMIC", NULL, "MICBIAS2" },
0398 { "IN2L", NULL, "DMIC" },
0399 { "IN2R", NULL, "DMIC" },
0400 };
0401
0402 static struct snd_soc_card bells_cards[] = {
0403 {
0404 .name = "Bells WM2200",
0405 .owner = THIS_MODULE,
0406 .dai_link = bells_dai_wm2200,
0407 .num_links = ARRAY_SIZE(bells_dai_wm2200),
0408 .codec_conf = bells_codec_conf,
0409 .num_configs = ARRAY_SIZE(bells_codec_conf),
0410
0411 .late_probe = bells_late_probe,
0412
0413 .dapm_widgets = bells_widgets,
0414 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
0415 .dapm_routes = bells_routes,
0416 .num_dapm_routes = ARRAY_SIZE(bells_routes),
0417
0418 .set_bias_level = bells_set_bias_level,
0419 .set_bias_level_post = bells_set_bias_level_post,
0420
0421 .drvdata = &wm2200_drvdata,
0422 },
0423 {
0424 .name = "Bells WM5102",
0425 .owner = THIS_MODULE,
0426 .dai_link = bells_dai_wm5102,
0427 .num_links = ARRAY_SIZE(bells_dai_wm5102),
0428 .codec_conf = bells_codec_conf,
0429 .num_configs = ARRAY_SIZE(bells_codec_conf),
0430
0431 .late_probe = bells_late_probe,
0432
0433 .dapm_widgets = bells_widgets,
0434 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
0435 .dapm_routes = bells_routes,
0436 .num_dapm_routes = ARRAY_SIZE(bells_routes),
0437
0438 .set_bias_level = bells_set_bias_level,
0439 .set_bias_level_post = bells_set_bias_level_post,
0440
0441 .drvdata = &wm5102_drvdata,
0442 },
0443 {
0444 .name = "Bells WM5110",
0445 .owner = THIS_MODULE,
0446 .dai_link = bells_dai_wm5110,
0447 .num_links = ARRAY_SIZE(bells_dai_wm5110),
0448 .codec_conf = bells_codec_conf,
0449 .num_configs = ARRAY_SIZE(bells_codec_conf),
0450
0451 .late_probe = bells_late_probe,
0452
0453 .dapm_widgets = bells_widgets,
0454 .num_dapm_widgets = ARRAY_SIZE(bells_widgets),
0455 .dapm_routes = bells_routes,
0456 .num_dapm_routes = ARRAY_SIZE(bells_routes),
0457
0458 .set_bias_level = bells_set_bias_level,
0459 .set_bias_level_post = bells_set_bias_level_post,
0460
0461 .drvdata = &wm5110_drvdata,
0462 },
0463 };
0464
0465 static int bells_probe(struct platform_device *pdev)
0466 {
0467 int ret;
0468
0469 bells_cards[pdev->id].dev = &pdev->dev;
0470
0471 ret = devm_snd_soc_register_card(&pdev->dev, &bells_cards[pdev->id]);
0472 if (ret)
0473 dev_err(&pdev->dev,
0474 "snd_soc_register_card(%s) failed: %d\n",
0475 bells_cards[pdev->id].name, ret);
0476
0477 return ret;
0478 }
0479
0480 static struct platform_driver bells_driver = {
0481 .driver = {
0482 .name = "bells",
0483 .pm = &snd_soc_pm_ops,
0484 },
0485 .probe = bells_probe,
0486 };
0487
0488 module_platform_driver(bells_driver);
0489
0490 MODULE_DESCRIPTION("Bells audio support");
0491 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
0492 MODULE_LICENSE("GPL");
0493 MODULE_ALIAS("platform:bells");