Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 1 | /* |
| 2 | * smdk_wm8994.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | */ |
| 9 | |
| 10 | #include "../codecs/wm8994.h" |
Giridhar Maruthy | b3d7615 | 2011-07-13 16:52:06 +0530 | [diff] [blame] | 11 | #include <sound/pcm_params.h> |
Boojin Kim | 3d94a2a | 2011-11-22 11:03:22 +0900 | [diff] [blame] | 12 | #include <linux/module.h> |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 13 | #include <linux/of.h> |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 14 | #include <linux/of_device.h> |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * Default CFG switch settings to use this driver: |
| 18 | * SMDKV310: CFG5-1000, CFG7-111111 |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Configure audio route as :- |
| 23 | * $ amixer sset 'DAC1' on,on |
| 24 | * $ amixer sset 'Right Headphone Mux' 'DAC' |
| 25 | * $ amixer sset 'Left Headphone Mux' 'DAC' |
| 26 | * $ amixer sset 'DAC1R Mixer AIF1.1' on |
| 27 | * $ amixer sset 'DAC1L Mixer AIF1.1' on |
| 28 | * $ amixer sset 'IN2L' on |
| 29 | * $ amixer sset 'IN2L PGA IN2LN' on |
| 30 | * $ amixer sset 'MIXINL IN2L' on |
| 31 | * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on |
| 32 | * $ amixer sset 'IN2R' on |
| 33 | * $ amixer sset 'IN2R PGA IN2RN' on |
| 34 | * $ amixer sset 'MIXINR IN2R' on |
| 35 | * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on |
| 36 | */ |
| 37 | |
| 38 | /* SMDK has a 16.934MHZ crystal attached to WM8994 */ |
| 39 | #define SMDK_WM8994_FREQ 16934000 |
| 40 | |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 41 | struct smdk_wm8994_data { |
| 42 | int mclk1_rate; |
| 43 | }; |
| 44 | |
| 45 | /* Default SMDKs */ |
| 46 | static struct smdk_wm8994_data smdk_board_data = { |
| 47 | .mclk1_rate = SMDK_WM8994_FREQ, |
| 48 | }; |
| 49 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 50 | static int smdk_hw_params(struct snd_pcm_substream *substream, |
| 51 | struct snd_pcm_hw_params *params) |
| 52 | { |
| 53 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 54 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 55 | unsigned int pll_out; |
| 56 | int ret; |
| 57 | |
| 58 | /* AIF1CLK should be >=3MHz for optimal performance */ |
Giridhar Maruthy | b3d7615 | 2011-07-13 16:52:06 +0530 | [diff] [blame] | 59 | if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE) |
| 60 | pll_out = params_rate(params) * 384; |
| 61 | else if (params_rate(params) == 8000 || params_rate(params) == 11025) |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 62 | pll_out = params_rate(params) * 512; |
| 63 | else |
| 64 | pll_out = params_rate(params) * 256; |
| 65 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 66 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1, |
| 67 | SMDK_WM8994_FREQ, pll_out); |
| 68 | if (ret < 0) |
| 69 | return ret; |
| 70 | |
| 71 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, |
| 72 | pll_out, SND_SOC_CLOCK_IN); |
| 73 | if (ret < 0) |
| 74 | return ret; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * SMDK WM8994 DAI operations. |
| 81 | */ |
| 82 | static struct snd_soc_ops smdk_ops = { |
| 83 | .hw_params = smdk_hw_params, |
| 84 | }; |
| 85 | |
| 86 | static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
| 87 | { |
| 88 | struct snd_soc_codec *codec = rtd->codec; |
| 89 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 90 | |
| 91 | /* HeadPhone */ |
| 92 | snd_soc_dapm_enable_pin(dapm, "HPOUT1R"); |
| 93 | snd_soc_dapm_enable_pin(dapm, "HPOUT1L"); |
| 94 | |
| 95 | /* MicIn */ |
| 96 | snd_soc_dapm_enable_pin(dapm, "IN1LN"); |
| 97 | snd_soc_dapm_enable_pin(dapm, "IN1RN"); |
| 98 | |
| 99 | /* LineIn */ |
| 100 | snd_soc_dapm_enable_pin(dapm, "IN2LN"); |
| 101 | snd_soc_dapm_enable_pin(dapm, "IN2RN"); |
| 102 | |
| 103 | /* Other pins NC */ |
| 104 | snd_soc_dapm_nc_pin(dapm, "HPOUT2P"); |
| 105 | snd_soc_dapm_nc_pin(dapm, "HPOUT2N"); |
| 106 | snd_soc_dapm_nc_pin(dapm, "SPKOUTLN"); |
| 107 | snd_soc_dapm_nc_pin(dapm, "SPKOUTLP"); |
| 108 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRP"); |
| 109 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRN"); |
| 110 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1N"); |
| 111 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1P"); |
| 112 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2N"); |
| 113 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2P"); |
| 114 | snd_soc_dapm_nc_pin(dapm, "IN1LP"); |
| 115 | snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN"); |
| 116 | snd_soc_dapm_nc_pin(dapm, "IN1RP"); |
| 117 | snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP"); |
| 118 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static struct snd_soc_dai_link smdk_dai[] = { |
| 123 | { /* Primary DAI i/f */ |
| 124 | .name = "WM8994 AIF1", |
| 125 | .stream_name = "Pri_Dai", |
| 126 | .cpu_dai_name = "samsung-i2s.0", |
| 127 | .codec_dai_name = "wm8994-aif1", |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 128 | .platform_name = "samsung-i2s.0", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 129 | .codec_name = "wm8994-codec", |
| 130 | .init = smdk_wm8994_init_paiftx, |
Mark Brown | f6ecf50 | 2013-07-26 12:01:53 +0100 | [diff] [blame] | 131 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 132 | SND_SOC_DAIFMT_CBM_CFM, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 133 | .ops = &smdk_ops, |
| 134 | }, { /* Sec_Fifo Playback i/f */ |
| 135 | .name = "Sec_FIFO TX", |
| 136 | .stream_name = "Sec_Dai", |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 137 | .cpu_dai_name = "samsung-i2s-sec", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 138 | .codec_dai_name = "wm8994-aif1", |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 139 | .platform_name = "samsung-i2s-sec", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 140 | .codec_name = "wm8994-codec", |
Mark Brown | f6ecf50 | 2013-07-26 12:01:53 +0100 | [diff] [blame] | 141 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 142 | SND_SOC_DAIFMT_CBM_CFM, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 143 | .ops = &smdk_ops, |
| 144 | }, |
| 145 | }; |
| 146 | |
| 147 | static struct snd_soc_card smdk = { |
| 148 | .name = "SMDK-I2S", |
Axel Lin | 095d79d | 2011-12-22 10:53:15 +0800 | [diff] [blame] | 149 | .owner = THIS_MODULE, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 150 | .dai_link = smdk_dai, |
| 151 | .num_links = ARRAY_SIZE(smdk_dai), |
| 152 | }; |
| 153 | |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 154 | #ifdef CONFIG_OF |
| 155 | static const struct of_device_id samsung_wm8994_of_match[] = { |
| 156 | { .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data }, |
| 157 | {}, |
| 158 | }; |
| 159 | MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match); |
| 160 | #endif /* CONFIG_OF */ |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 161 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 162 | static int smdk_audio_probe(struct platform_device *pdev) |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 163 | { |
| 164 | int ret; |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 165 | struct device_node *np = pdev->dev.of_node; |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 166 | struct snd_soc_card *card = &smdk; |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 167 | struct smdk_wm8994_data *board; |
| 168 | const struct of_device_id *id; |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 169 | |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 170 | card->dev = &pdev->dev; |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 171 | |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 172 | board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL); |
| 173 | if (!board) |
| 174 | return -ENOMEM; |
| 175 | |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 176 | if (np) { |
| 177 | smdk_dai[0].cpu_dai_name = NULL; |
| 178 | smdk_dai[0].cpu_of_node = of_parse_phandle(np, |
| 179 | "samsung,i2s-controller", 0); |
| 180 | if (!smdk_dai[0].cpu_of_node) { |
| 181 | dev_err(&pdev->dev, |
| 182 | "Property 'samsung,i2s-controller' missing or invalid\n"); |
| 183 | ret = -EINVAL; |
| 184 | } |
| 185 | |
| 186 | smdk_dai[0].platform_name = NULL; |
| 187 | smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node; |
| 188 | } |
| 189 | |
Mark Brown | d30c148 | 2013-07-26 12:42:19 +0100 | [diff] [blame] | 190 | id = of_match_device(samsung_wm8994_of_match, &pdev->dev); |
| 191 | if (id) |
| 192 | *board = *((struct smdk_wm8994_data *)id->data); |
| 193 | |
| 194 | platform_set_drvdata(pdev, board); |
| 195 | |
Mark Brown | 9a8e032 | 2013-09-16 18:02:28 +0100 | [diff] [blame] | 196 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 197 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 198 | if (ret) |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 199 | dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 200 | |
| 201 | return ret; |
| 202 | } |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 203 | |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 204 | static struct platform_driver smdk_audio_driver = { |
| 205 | .driver = { |
Mark Brown | 0d47acc | 2013-07-17 17:20:19 +0100 | [diff] [blame] | 206 | .name = "smdk-audio-wm8894", |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 207 | .owner = THIS_MODULE, |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 208 | .of_match_table = of_match_ptr(samsung_wm8994_of_match), |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 209 | }, |
| 210 | .probe = smdk_audio_probe, |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | module_platform_driver(smdk_audio_driver); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 214 | |
| 215 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8994"); |
| 216 | MODULE_LICENSE("GPL"); |
Mark Brown | 0d47acc | 2013-07-17 17:20:19 +0100 | [diff] [blame] | 217 | MODULE_ALIAS("platform:smdk-audio-wm8994"); |