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/wm5100.h"
0014 #include "../codecs/wm9081.h"
0015
0016 #define MCLK1_RATE (44100 * 512)
0017 #define CLKOUT_RATE (44100 * 256)
0018
0019 static struct snd_soc_jack lowland_headset;
0020
0021
0022 static struct snd_soc_jack_pin lowland_headset_pins[] = {
0023 {
0024 .pin = "Headphone",
0025 .mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
0026 },
0027 {
0028 .pin = "Headset Mic",
0029 .mask = SND_JACK_MICROPHONE,
0030 },
0031 };
0032
0033 static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
0034 {
0035 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0036 int ret;
0037
0038 ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK,
0039 WM5100_CLKSRC_MCLK1, MCLK1_RATE,
0040 SND_SOC_CLOCK_IN);
0041 if (ret < 0) {
0042 pr_err("Failed to set SYSCLK clock source: %d\n", ret);
0043 return ret;
0044 }
0045
0046
0047 ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0,
0048 CLKOUT_RATE, 0);
0049 if (ret < 0) {
0050 pr_err("Failed to set OPCLK rate: %d\n", ret);
0051 return ret;
0052 }
0053
0054 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset",
0055 SND_JACK_LINEOUT | SND_JACK_HEADSET |
0056 SND_JACK_BTN_0,
0057 &lowland_headset, lowland_headset_pins,
0058 ARRAY_SIZE(lowland_headset_pins));
0059 if (ret)
0060 return ret;
0061
0062 wm5100_detect(component, &lowland_headset);
0063
0064 return 0;
0065 }
0066
0067 static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
0068 {
0069 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
0070
0071 snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
0072
0073
0074 return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
0075 CLKOUT_RATE, 0);
0076 }
0077
0078 static const struct snd_soc_pcm_stream sub_params = {
0079 .formats = SNDRV_PCM_FMTBIT_S32_LE,
0080 .rate_min = 44100,
0081 .rate_max = 44100,
0082 .channels_min = 2,
0083 .channels_max = 2,
0084 };
0085
0086 SND_SOC_DAILINK_DEFS(cpu,
0087 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
0088 DAILINK_COMP_ARRAY(COMP_CODEC("wm5100.1-001a", "wm5100-aif1")),
0089 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
0090
0091 SND_SOC_DAILINK_DEFS(baseband,
0092 DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif2")),
0093 DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
0094
0095 SND_SOC_DAILINK_DEFS(speaker,
0096 DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif3")),
0097 DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
0098
0099 static struct snd_soc_dai_link lowland_dai[] = {
0100 {
0101 .name = "CPU",
0102 .stream_name = "CPU",
0103 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0104 SND_SOC_DAIFMT_CBM_CFM,
0105 .init = lowland_wm5100_init,
0106 SND_SOC_DAILINK_REG(cpu),
0107 },
0108 {
0109 .name = "Baseband",
0110 .stream_name = "Baseband",
0111 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0112 SND_SOC_DAIFMT_CBM_CFM,
0113 .ignore_suspend = 1,
0114 SND_SOC_DAILINK_REG(baseband),
0115 },
0116 {
0117 .name = "Sub Speaker",
0118 .stream_name = "Sub Speaker",
0119 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
0120 SND_SOC_DAIFMT_CBM_CFM,
0121 .ignore_suspend = 1,
0122 .params = &sub_params,
0123 .init = lowland_wm9081_init,
0124 SND_SOC_DAILINK_REG(speaker),
0125 },
0126 };
0127
0128 static struct snd_soc_codec_conf lowland_codec_conf[] = {
0129 {
0130 .dlc = COMP_CODEC_CONF("wm9081.1-006c"),
0131 .name_prefix = "Sub",
0132 },
0133 };
0134
0135 static const struct snd_kcontrol_new controls[] = {
0136 SOC_DAPM_PIN_SWITCH("Main Speaker"),
0137 SOC_DAPM_PIN_SWITCH("Main DMIC"),
0138 SOC_DAPM_PIN_SWITCH("Main AMIC"),
0139 SOC_DAPM_PIN_SWITCH("WM1250 Input"),
0140 SOC_DAPM_PIN_SWITCH("WM1250 Output"),
0141 SOC_DAPM_PIN_SWITCH("Headphone"),
0142 };
0143
0144 static const struct snd_soc_dapm_widget widgets[] = {
0145 SND_SOC_DAPM_HP("Headphone", NULL),
0146 SND_SOC_DAPM_MIC("Headset Mic", NULL),
0147
0148 SND_SOC_DAPM_SPK("Main Speaker", NULL),
0149
0150 SND_SOC_DAPM_MIC("Main AMIC", NULL),
0151 SND_SOC_DAPM_MIC("Main DMIC", NULL),
0152 };
0153
0154 static const struct snd_soc_dapm_route audio_paths[] = {
0155 { "Sub IN1", NULL, "HPOUT2L" },
0156 { "Sub IN2", NULL, "HPOUT2R" },
0157
0158 { "Main Speaker", NULL, "Sub SPKN" },
0159 { "Main Speaker", NULL, "Sub SPKP" },
0160 { "Main Speaker", NULL, "SPKDAT1" },
0161 };
0162
0163 static struct snd_soc_card lowland = {
0164 .name = "Lowland",
0165 .owner = THIS_MODULE,
0166 .dai_link = lowland_dai,
0167 .num_links = ARRAY_SIZE(lowland_dai),
0168 .codec_conf = lowland_codec_conf,
0169 .num_configs = ARRAY_SIZE(lowland_codec_conf),
0170
0171 .controls = controls,
0172 .num_controls = ARRAY_SIZE(controls),
0173 .dapm_widgets = widgets,
0174 .num_dapm_widgets = ARRAY_SIZE(widgets),
0175 .dapm_routes = audio_paths,
0176 .num_dapm_routes = ARRAY_SIZE(audio_paths),
0177 };
0178
0179 static int lowland_probe(struct platform_device *pdev)
0180 {
0181 struct snd_soc_card *card = &lowland;
0182 int ret;
0183
0184 card->dev = &pdev->dev;
0185
0186 ret = devm_snd_soc_register_card(&pdev->dev, card);
0187 if (ret)
0188 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
0189
0190 return ret;
0191 }
0192
0193 static struct platform_driver lowland_driver = {
0194 .driver = {
0195 .name = "lowland",
0196 .pm = &snd_soc_pm_ops,
0197 },
0198 .probe = lowland_probe,
0199 };
0200
0201 module_platform_driver(lowland_driver);
0202
0203 MODULE_DESCRIPTION("Lowland audio support");
0204 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
0205 MODULE_LICENSE("GPL");
0206 MODULE_ALIAS("platform:lowland");