10a590b1dSMark Brown /* 20a590b1dSMark Brown * Littlemill audio support 30a590b1dSMark Brown * 40a590b1dSMark Brown * Copyright 2011 Wolfson Microelectronics 50a590b1dSMark Brown * 60a590b1dSMark Brown * This program is free software; you can redistribute it and/or modify it 70a590b1dSMark Brown * under the terms of the GNU General Public License as published by the 80a590b1dSMark Brown * Free Software Foundation; either version 2 of the License, or (at your 90a590b1dSMark Brown * option) any later version. 100a590b1dSMark Brown */ 110a590b1dSMark Brown 120a590b1dSMark Brown #include <sound/soc.h> 130a590b1dSMark Brown #include <sound/soc-dapm.h> 140a590b1dSMark Brown #include <sound/jack.h> 150a590b1dSMark Brown #include <linux/gpio.h> 160a590b1dSMark Brown #include <linux/module.h> 170a590b1dSMark Brown 180a590b1dSMark Brown #include "../codecs/wm8994.h" 190a590b1dSMark Brown 200a590b1dSMark Brown static int sample_rate = 44100; 210a590b1dSMark Brown 220a590b1dSMark Brown static int littlemill_set_bias_level(struct snd_soc_card *card, 230a590b1dSMark Brown struct snd_soc_dapm_context *dapm, 240a590b1dSMark Brown enum snd_soc_bias_level level) 250a590b1dSMark Brown { 26*0cbe4b36SMark Brown struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; 270a590b1dSMark Brown int ret; 280a590b1dSMark Brown 29*0cbe4b36SMark Brown if (dapm->dev != aif1_dai->dev) 300a590b1dSMark Brown return 0; 310a590b1dSMark Brown 320a590b1dSMark Brown switch (level) { 330a590b1dSMark Brown case SND_SOC_BIAS_PREPARE: 340a590b1dSMark Brown /* 350a590b1dSMark Brown * If we've not already clocked things via hw_params() 360a590b1dSMark Brown * then do so now, otherwise these are noops. 370a590b1dSMark Brown */ 380a590b1dSMark Brown if (dapm->bias_level == SND_SOC_BIAS_STANDBY) { 39*0cbe4b36SMark Brown ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 400a590b1dSMark Brown WM8994_FLL_SRC_MCLK2, 32768, 410a590b1dSMark Brown sample_rate * 512); 420a590b1dSMark Brown if (ret < 0) { 430a590b1dSMark Brown pr_err("Failed to start FLL: %d\n", ret); 440a590b1dSMark Brown return ret; 450a590b1dSMark Brown } 460a590b1dSMark Brown 47*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif1_dai, 480a590b1dSMark Brown WM8994_SYSCLK_FLL1, 490a590b1dSMark Brown sample_rate * 512, 500a590b1dSMark Brown SND_SOC_CLOCK_IN); 510a590b1dSMark Brown if (ret < 0) { 520a590b1dSMark Brown pr_err("Failed to set SYSCLK: %d\n", ret); 530a590b1dSMark Brown return ret; 540a590b1dSMark Brown } 550a590b1dSMark Brown } 560a590b1dSMark Brown break; 570a590b1dSMark Brown 580a590b1dSMark Brown default: 590a590b1dSMark Brown break; 600a590b1dSMark Brown } 610a590b1dSMark Brown 620a590b1dSMark Brown return 0; 630a590b1dSMark Brown } 640a590b1dSMark Brown 650a590b1dSMark Brown static int littlemill_set_bias_level_post(struct snd_soc_card *card, 660a590b1dSMark Brown struct snd_soc_dapm_context *dapm, 670a590b1dSMark Brown enum snd_soc_bias_level level) 680a590b1dSMark Brown { 69*0cbe4b36SMark Brown struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; 70*0cbe4b36SMark Brown struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; 710a590b1dSMark Brown int ret; 720a590b1dSMark Brown 73*0cbe4b36SMark Brown if (dapm->dev != aif1_dai->dev) 740a590b1dSMark Brown return 0; 750a590b1dSMark Brown 760a590b1dSMark Brown switch (level) { 770a590b1dSMark Brown case SND_SOC_BIAS_STANDBY: 78*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, 790a590b1dSMark Brown 32768, SND_SOC_CLOCK_IN); 800a590b1dSMark Brown if (ret < 0) { 81*0cbe4b36SMark Brown pr_err("Failed to switch away from FLL2: %d\n", ret); 820a590b1dSMark Brown return ret; 830a590b1dSMark Brown } 840a590b1dSMark Brown 85*0cbe4b36SMark Brown ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 860a590b1dSMark Brown 0, 0, 0); 870a590b1dSMark Brown if (ret < 0) { 88*0cbe4b36SMark Brown pr_err("Failed to stop FLL2: %d\n", ret); 89*0cbe4b36SMark Brown return ret; 90*0cbe4b36SMark Brown } 91*0cbe4b36SMark Brown 92*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, 93*0cbe4b36SMark Brown 32768, SND_SOC_CLOCK_IN); 94*0cbe4b36SMark Brown if (ret < 0) { 95*0cbe4b36SMark Brown pr_err("Failed to switch away from FLL1: %d\n", ret); 96*0cbe4b36SMark Brown return ret; 97*0cbe4b36SMark Brown } 98*0cbe4b36SMark Brown 99*0cbe4b36SMark Brown ret = snd_soc_dai_set_pll(aif1_dai, WM8994_FLL1, 100*0cbe4b36SMark Brown 0, 0, 0); 101*0cbe4b36SMark Brown if (ret < 0) { 102*0cbe4b36SMark Brown pr_err("Failed to stop FLL1: %d\n", ret); 103*0cbe4b36SMark Brown return ret; 104*0cbe4b36SMark Brown } 105*0cbe4b36SMark Brown break; 106*0cbe4b36SMark Brown 107*0cbe4b36SMark Brown case SND_SOC_BIAS_PREPARE: 108*0cbe4b36SMark Brown ret = snd_soc_dai_set_pll(aif2_dai, WM8994_FLL2, 109*0cbe4b36SMark Brown WM8994_FLL_SRC_BCLK, 64 * 8000, 110*0cbe4b36SMark Brown 8000 * 256); 111*0cbe4b36SMark Brown if (ret < 0) { 112*0cbe4b36SMark Brown pr_err("Failed to start FLL: %d\n", ret); 113*0cbe4b36SMark Brown return ret; 114*0cbe4b36SMark Brown } 115*0cbe4b36SMark Brown 116*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_FLL2, 117*0cbe4b36SMark Brown 8000 * 256, 118*0cbe4b36SMark Brown SND_SOC_CLOCK_IN); 119*0cbe4b36SMark Brown if (ret < 0) { 120*0cbe4b36SMark Brown pr_err("Failed to set SYSCLK: %d\n", ret); 1210a590b1dSMark Brown return ret; 1220a590b1dSMark Brown } 1230a590b1dSMark Brown break; 1240a590b1dSMark Brown 1250a590b1dSMark Brown default: 1260a590b1dSMark Brown break; 1270a590b1dSMark Brown } 1280a590b1dSMark Brown 1290a590b1dSMark Brown dapm->bias_level = level; 1300a590b1dSMark Brown 1310a590b1dSMark Brown return 0; 1320a590b1dSMark Brown } 1330a590b1dSMark Brown 1340a590b1dSMark Brown static int littlemill_hw_params(struct snd_pcm_substream *substream, 1350a590b1dSMark Brown struct snd_pcm_hw_params *params) 1360a590b1dSMark Brown { 1370a590b1dSMark Brown struct snd_soc_pcm_runtime *rtd = substream->private_data; 1380a590b1dSMark Brown struct snd_soc_dai *codec_dai = rtd->codec_dai; 1390a590b1dSMark Brown int ret; 1400a590b1dSMark Brown 1410a590b1dSMark Brown sample_rate = params_rate(params); 1420a590b1dSMark Brown 1430a590b1dSMark Brown ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 1440a590b1dSMark Brown WM8994_FLL_SRC_MCLK2, 32768, 1450a590b1dSMark Brown sample_rate * 512); 1460a590b1dSMark Brown if (ret < 0) { 1470a590b1dSMark Brown pr_err("Failed to start FLL: %d\n", ret); 1480a590b1dSMark Brown return ret; 1490a590b1dSMark Brown } 1500a590b1dSMark Brown 1510a590b1dSMark Brown ret = snd_soc_dai_set_sysclk(codec_dai, 1520a590b1dSMark Brown WM8994_SYSCLK_FLL1, 1530a590b1dSMark Brown sample_rate * 512, 1540a590b1dSMark Brown SND_SOC_CLOCK_IN); 1550a590b1dSMark Brown if (ret < 0) { 1560a590b1dSMark Brown pr_err("Failed to set SYSCLK: %d\n", ret); 1570a590b1dSMark Brown return ret; 1580a590b1dSMark Brown } 1590a590b1dSMark Brown 1600a590b1dSMark Brown return 0; 1610a590b1dSMark Brown } 1620a590b1dSMark Brown 1630a590b1dSMark Brown static struct snd_soc_ops littlemill_ops = { 1640a590b1dSMark Brown .hw_params = littlemill_hw_params, 1650a590b1dSMark Brown }; 1660a590b1dSMark Brown 167*0cbe4b36SMark Brown static const struct snd_soc_pcm_stream baseband_params = { 168*0cbe4b36SMark Brown .formats = SNDRV_PCM_FMTBIT_S32_LE, 169*0cbe4b36SMark Brown .rate_min = 8000, 170*0cbe4b36SMark Brown .rate_max = 8000, 171*0cbe4b36SMark Brown .channels_min = 2, 172*0cbe4b36SMark Brown .channels_max = 2, 173*0cbe4b36SMark Brown }; 174*0cbe4b36SMark Brown 1750a590b1dSMark Brown static struct snd_soc_dai_link littlemill_dai[] = { 1760a590b1dSMark Brown { 1770a590b1dSMark Brown .name = "CPU", 1780a590b1dSMark Brown .stream_name = "CPU", 1790a590b1dSMark Brown .cpu_dai_name = "samsung-i2s.0", 1800a590b1dSMark Brown .codec_dai_name = "wm8994-aif1", 1810a590b1dSMark Brown .platform_name = "samsung-audio", 1820a590b1dSMark Brown .codec_name = "wm8994-codec", 1830a590b1dSMark Brown .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 1840a590b1dSMark Brown | SND_SOC_DAIFMT_CBM_CFM, 1850a590b1dSMark Brown .ops = &littlemill_ops, 1860a590b1dSMark Brown }, 187*0cbe4b36SMark Brown { 188*0cbe4b36SMark Brown .name = "Baseband", 189*0cbe4b36SMark Brown .stream_name = "Baseband", 190*0cbe4b36SMark Brown .cpu_dai_name = "wm8994-aif2", 191*0cbe4b36SMark Brown .codec_dai_name = "wm1250-ev1", 192*0cbe4b36SMark Brown .codec_name = "wm1250-ev1.1-0027", 193*0cbe4b36SMark Brown .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 194*0cbe4b36SMark Brown | SND_SOC_DAIFMT_CBM_CFM, 195*0cbe4b36SMark Brown .ignore_suspend = 1, 196*0cbe4b36SMark Brown .params = &baseband_params, 197*0cbe4b36SMark Brown }, 1980a590b1dSMark Brown }; 1990a590b1dSMark Brown 2000a590b1dSMark Brown static struct snd_soc_dapm_widget widgets[] = { 2010a590b1dSMark Brown SND_SOC_DAPM_HP("Headphone", NULL), 2028f103167SMark Brown 2038f103167SMark Brown SND_SOC_DAPM_MIC("AMIC", NULL), 2048f103167SMark Brown SND_SOC_DAPM_MIC("DMIC", NULL), 2050a590b1dSMark Brown }; 2060a590b1dSMark Brown 2070a590b1dSMark Brown static struct snd_soc_dapm_route audio_paths[] = { 2080a590b1dSMark Brown { "Headphone", NULL, "HPOUT1L" }, 2090a590b1dSMark Brown { "Headphone", NULL, "HPOUT1R" }, 2108f103167SMark Brown 2118f103167SMark Brown { "AMIC", NULL, "MICBIAS1" }, /* Default for AMICBIAS jumper */ 2128f103167SMark Brown { "IN1LN", NULL, "AMIC" }, 2138f103167SMark Brown 2148f103167SMark Brown { "DMIC", NULL, "MICBIAS2" }, /* Default for DMICBIAS jumper */ 2158f103167SMark Brown { "DMIC1DAT", NULL, "DMIC" }, 2168f103167SMark Brown { "DMIC2DAT", NULL, "DMIC" }, 2170a590b1dSMark Brown }; 2180a590b1dSMark Brown 219f2e2026cSMark Brown static struct snd_soc_jack littlemill_headset; 220f2e2026cSMark Brown 2210a590b1dSMark Brown static int littlemill_late_probe(struct snd_soc_card *card) 2220a590b1dSMark Brown { 223f2e2026cSMark Brown struct snd_soc_codec *codec = card->rtd[0].codec; 224*0cbe4b36SMark Brown struct snd_soc_dai *aif1_dai = card->rtd[0].codec_dai; 225*0cbe4b36SMark Brown struct snd_soc_dai *aif2_dai = card->rtd[1].cpu_dai; 2260a590b1dSMark Brown int ret; 2270a590b1dSMark Brown 228*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif1_dai, WM8994_SYSCLK_MCLK2, 229*0cbe4b36SMark Brown 32768, SND_SOC_CLOCK_IN); 230*0cbe4b36SMark Brown if (ret < 0) 231*0cbe4b36SMark Brown return ret; 232*0cbe4b36SMark Brown 233*0cbe4b36SMark Brown ret = snd_soc_dai_set_sysclk(aif2_dai, WM8994_SYSCLK_MCLK2, 2340a590b1dSMark Brown 32768, SND_SOC_CLOCK_IN); 2350a590b1dSMark Brown if (ret < 0) 2360a590b1dSMark Brown return ret; 2370a590b1dSMark Brown 238f2e2026cSMark Brown ret = snd_soc_jack_new(codec, "Headset", 239f2e2026cSMark Brown SND_JACK_HEADSET | SND_JACK_MECHANICAL | 240f2e2026cSMark Brown SND_JACK_BTN_0 | SND_JACK_BTN_1 | 241f2e2026cSMark Brown SND_JACK_BTN_2 | SND_JACK_BTN_3 | 242f2e2026cSMark Brown SND_JACK_BTN_4 | SND_JACK_BTN_5, 243f2e2026cSMark Brown &littlemill_headset); 244f2e2026cSMark Brown if (ret) 245f2e2026cSMark Brown return ret; 246f2e2026cSMark Brown 247f2e2026cSMark Brown /* This will check device compatibility itself */ 248f2e2026cSMark Brown wm8958_mic_detect(codec, &littlemill_headset, NULL, NULL); 249f2e2026cSMark Brown 250654a28c9SMark Brown /* As will this */ 251654a28c9SMark Brown wm8994_mic_detect(codec, &littlemill_headset, 1); 252654a28c9SMark Brown 2530a590b1dSMark Brown return 0; 2540a590b1dSMark Brown } 2550a590b1dSMark Brown 2560a590b1dSMark Brown static struct snd_soc_card littlemill = { 2570a590b1dSMark Brown .name = "Littlemill", 258095d79dcSAxel Lin .owner = THIS_MODULE, 2590a590b1dSMark Brown .dai_link = littlemill_dai, 2600a590b1dSMark Brown .num_links = ARRAY_SIZE(littlemill_dai), 2610a590b1dSMark Brown 2620a590b1dSMark Brown .set_bias_level = littlemill_set_bias_level, 2630a590b1dSMark Brown .set_bias_level_post = littlemill_set_bias_level_post, 2640a590b1dSMark Brown 2650a590b1dSMark Brown .dapm_widgets = widgets, 2660a590b1dSMark Brown .num_dapm_widgets = ARRAY_SIZE(widgets), 2670a590b1dSMark Brown .dapm_routes = audio_paths, 2680a590b1dSMark Brown .num_dapm_routes = ARRAY_SIZE(audio_paths), 2690a590b1dSMark Brown 2700a590b1dSMark Brown .late_probe = littlemill_late_probe, 2710a590b1dSMark Brown }; 2720a590b1dSMark Brown 2730a590b1dSMark Brown static __devinit int littlemill_probe(struct platform_device *pdev) 2740a590b1dSMark Brown { 2750a590b1dSMark Brown struct snd_soc_card *card = &littlemill; 2760a590b1dSMark Brown int ret; 2770a590b1dSMark Brown 2780a590b1dSMark Brown card->dev = &pdev->dev; 2790a590b1dSMark Brown 2800a590b1dSMark Brown ret = snd_soc_register_card(card); 2810a590b1dSMark Brown if (ret) { 2820a590b1dSMark Brown dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", 2830a590b1dSMark Brown ret); 2840a590b1dSMark Brown return ret; 2850a590b1dSMark Brown } 2860a590b1dSMark Brown 2870a590b1dSMark Brown return 0; 2880a590b1dSMark Brown } 2890a590b1dSMark Brown 2900a590b1dSMark Brown static int __devexit littlemill_remove(struct platform_device *pdev) 2910a590b1dSMark Brown { 2920a590b1dSMark Brown struct snd_soc_card *card = platform_get_drvdata(pdev); 2930a590b1dSMark Brown 2940a590b1dSMark Brown snd_soc_unregister_card(card); 2950a590b1dSMark Brown 2960a590b1dSMark Brown return 0; 2970a590b1dSMark Brown } 2980a590b1dSMark Brown 2990a590b1dSMark Brown static struct platform_driver littlemill_driver = { 3000a590b1dSMark Brown .driver = { 3010a590b1dSMark Brown .name = "littlemill", 3020a590b1dSMark Brown .owner = THIS_MODULE, 3030a590b1dSMark Brown .pm = &snd_soc_pm_ops, 3040a590b1dSMark Brown }, 3050a590b1dSMark Brown .probe = littlemill_probe, 3060a590b1dSMark Brown .remove = __devexit_p(littlemill_remove), 3070a590b1dSMark Brown }; 3080a590b1dSMark Brown 3090a590b1dSMark Brown module_platform_driver(littlemill_driver); 3100a590b1dSMark Brown 3110a590b1dSMark Brown MODULE_DESCRIPTION("Littlemill audio support"); 3120a590b1dSMark Brown MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 3130a590b1dSMark Brown MODULE_LICENSE("GPL"); 3140a590b1dSMark Brown MODULE_ALIAS("platform:littlemill"); 315