jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 1 | /* |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 2 | * smdk_wm8580.c |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2009 Samsung Electronics Co. Ltd |
| 5 | * Author: Jaswinder Singh <jassi.brar@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/clk.h> |
| 15 | #include <sound/core.h> |
| 16 | #include <sound/pcm.h> |
| 17 | #include <sound/pcm_params.h> |
| 18 | #include <sound/soc.h> |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 19 | |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
| 21 | |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 22 | #include "../codecs/wm8580.h" |
Jassi Brar | 4b640cf | 2010-11-22 15:35:57 +0900 | [diff] [blame] | 23 | #include "dma.h" |
Jassi Brar | 0fff21a | 2010-11-22 15:37:07 +0900 | [diff] [blame] | 24 | #include "i2s.h" |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 25 | |
Mark Brown | 9d37e89 | 2010-08-06 17:57:45 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Default CFG switch settings to use this driver: |
| 28 | * |
| 29 | * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On |
| 30 | */ |
| 31 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 32 | /* SMDK has a 12MHZ crystal attached to WM8580 */ |
| 33 | #define SMDK_WM8580_FREQ 12000000 |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 34 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 35 | static int smdk_hw_params(struct snd_pcm_substream *substream, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 36 | struct snd_pcm_hw_params *params) |
| 37 | { |
| 38 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 39 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 40 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 41 | unsigned int pll_out; |
| 42 | int bfs, rfs, ret; |
| 43 | |
| 44 | switch (params_format(params)) { |
| 45 | case SNDRV_PCM_FORMAT_U8: |
| 46 | case SNDRV_PCM_FORMAT_S8: |
| 47 | bfs = 16; |
| 48 | break; |
| 49 | case SNDRV_PCM_FORMAT_U16_LE: |
| 50 | case SNDRV_PCM_FORMAT_S16_LE: |
| 51 | bfs = 32; |
| 52 | break; |
| 53 | default: |
| 54 | return -EINVAL; |
| 55 | } |
| 56 | |
| 57 | /* The Fvco for WM8580 PLLs must fall within [90,100]MHz. |
| 58 | * This criterion can't be met if we request PLL output |
| 59 | * as {8000x256, 64000x256, 11025x256}Hz. |
| 60 | * As a wayout, we rather change rfs to a minimum value that |
| 61 | * results in (params_rate(params) * rfs), and itself, acceptable |
| 62 | * to both - the CODEC and the CPU. |
| 63 | */ |
| 64 | switch (params_rate(params)) { |
| 65 | case 16000: |
| 66 | case 22050: |
| 67 | case 32000: |
| 68 | case 44100: |
| 69 | case 48000: |
| 70 | case 88200: |
| 71 | case 96000: |
| 72 | rfs = 256; |
| 73 | break; |
| 74 | case 64000: |
| 75 | rfs = 384; |
| 76 | break; |
| 77 | case 8000: |
| 78 | case 11025: |
| 79 | rfs = 512; |
| 80 | break; |
| 81 | default: |
| 82 | return -EINVAL; |
| 83 | } |
| 84 | pll_out = params_rate(params) * rfs; |
| 85 | |
| 86 | /* Set the Codec DAI configuration */ |
| 87 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
| 88 | | SND_SOC_DAIFMT_NB_NF |
| 89 | | SND_SOC_DAIFMT_CBM_CFM); |
| 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
| 93 | /* Set the AP DAI configuration */ |
| 94 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
| 95 | | SND_SOC_DAIFMT_NB_NF |
| 96 | | SND_SOC_DAIFMT_CBM_CFM); |
| 97 | if (ret < 0) |
| 98 | return ret; |
| 99 | |
Mark Brown | 26d95b6 | 2009-10-28 15:47:48 +0000 | [diff] [blame] | 100 | /* Set WM8580 to drive MCLK from its PLLA */ |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 101 | ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, |
| 102 | WM8580_CLKSRC_PLLA); |
| 103 | if (ret < 0) |
| 104 | return ret; |
| 105 | |
Mark Brown | c5607d8 | 2010-08-13 19:05:04 +0100 | [diff] [blame] | 106 | ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0, |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 107 | SMDK_WM8580_FREQ, pll_out); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 108 | if (ret < 0) |
| 109 | return ret; |
| 110 | |
Mark Brown | c5607d8 | 2010-08-13 19:05:04 +0100 | [diff] [blame] | 111 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA, |
| 112 | pll_out, SND_SOC_CLOCK_IN); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 113 | if (ret < 0) |
| 114 | return ret; |
| 115 | |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | /* |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 120 | * SMDK WM8580 DAI operations. |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 121 | */ |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 122 | static struct snd_soc_ops smdk_ops = { |
| 123 | .hw_params = smdk_hw_params, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 124 | }; |
| 125 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 126 | /* SMDK Playback widgets */ |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 127 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = { |
Mark Brown | 698cb11 | 2010-08-06 17:23:02 +0100 | [diff] [blame] | 128 | SND_SOC_DAPM_HP("Front", NULL), |
| 129 | SND_SOC_DAPM_HP("Center+Sub", NULL), |
| 130 | SND_SOC_DAPM_HP("Rear", NULL), |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 131 | }; |
| 132 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 133 | /* SMDK Capture widgets */ |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 134 | static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = { |
| 135 | SND_SOC_DAPM_MIC("MicIn", NULL), |
| 136 | SND_SOC_DAPM_LINE("LineIn", NULL), |
| 137 | }; |
| 138 | |
| 139 | /* SMDK-PAIFTX connections */ |
| 140 | static const struct snd_soc_dapm_route audio_map_tx[] = { |
| 141 | /* MicIn feeds AINL */ |
| 142 | {"AINL", NULL, "MicIn"}, |
| 143 | |
| 144 | /* LineIn feeds AINL/R */ |
| 145 | {"AINL", NULL, "LineIn"}, |
| 146 | {"AINR", NULL, "LineIn"}, |
| 147 | }; |
| 148 | |
| 149 | /* SMDK-PAIFRX connections */ |
| 150 | static const struct snd_soc_dapm_route audio_map_rx[] = { |
| 151 | /* Front Left/Right are fed VOUT1L/R */ |
Mark Brown | 698cb11 | 2010-08-06 17:23:02 +0100 | [diff] [blame] | 152 | {"Front", NULL, "VOUT1L"}, |
| 153 | {"Front", NULL, "VOUT1R"}, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 154 | |
| 155 | /* Center/Sub are fed VOUT2L/R */ |
Mark Brown | 698cb11 | 2010-08-06 17:23:02 +0100 | [diff] [blame] | 156 | {"Center+Sub", NULL, "VOUT2L"}, |
| 157 | {"Center+Sub", NULL, "VOUT2R"}, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 158 | |
| 159 | /* Rear Left/Right are fed VOUT3L/R */ |
Mark Brown | 698cb11 | 2010-08-06 17:23:02 +0100 | [diff] [blame] | 160 | {"Rear", NULL, "VOUT3L"}, |
| 161 | {"Rear", NULL, "VOUT3R"}, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 162 | }; |
| 163 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 164 | static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 165 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 166 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 167 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 168 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 169 | /* Add smdk specific Capture widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 170 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 171 | ARRAY_SIZE(wm8580_dapm_widgets_cpt)); |
| 172 | |
| 173 | /* Set up PAIFTX audio path */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 174 | snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx)); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 175 | |
Mark Brown | 26d95b6 | 2009-10-28 15:47:48 +0000 | [diff] [blame] | 176 | /* Enabling the microphone requires the fitting of a 0R |
| 177 | * resistor to connect the line from the microphone jack. |
| 178 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 179 | snd_soc_dapm_disable_pin(dapm, "MicIn"); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 180 | |
| 181 | /* signal a DAPM event */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 182 | snd_soc_dapm_sync(dapm); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 187 | static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd) |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 188 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 189 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 190 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 191 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 192 | /* Add smdk specific Playback widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 193 | snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 194 | ARRAY_SIZE(wm8580_dapm_widgets_pbk)); |
| 195 | |
| 196 | /* Set up PAIFRX audio path */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 197 | snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx)); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 198 | |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 199 | /* signal a DAPM event */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 200 | snd_soc_dapm_sync(dapm); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 205 | enum { |
| 206 | PRI_PLAYBACK = 0, |
| 207 | PRI_CAPTURE, |
| 208 | SEC_PLAYBACK, |
| 209 | }; |
| 210 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 211 | static struct snd_soc_dai_link smdk_dai[] = { |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 212 | [PRI_PLAYBACK] = { /* Primary Playback i/f */ |
| 213 | .name = "WM8580 PAIF RX", |
| 214 | .stream_name = "Playback", |
Jassi Brar | 72685f2 | 2010-12-20 11:05:48 +0900 | [diff] [blame] | 215 | .cpu_dai_name = "samsung-i2s.0", |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 216 | .codec_dai_name = "wm8580-hifi-playback", |
| 217 | .platform_name = "samsung-audio", |
| 218 | .codec_name = "wm8580-codec.0-001b", |
| 219 | .init = smdk_wm8580_init_paifrx, |
| 220 | .ops = &smdk_ops, |
| 221 | }, |
| 222 | [PRI_CAPTURE] = { /* Primary Capture i/f */ |
| 223 | .name = "WM8580 PAIF TX", |
| 224 | .stream_name = "Capture", |
Jassi Brar | 72685f2 | 2010-12-20 11:05:48 +0900 | [diff] [blame] | 225 | .cpu_dai_name = "samsung-i2s.0", |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 226 | .codec_dai_name = "wm8580-hifi-capture", |
| 227 | .platform_name = "samsung-audio", |
| 228 | .codec_name = "wm8580-codec.0-001b", |
| 229 | .init = smdk_wm8580_init_paiftx, |
| 230 | .ops = &smdk_ops, |
| 231 | }, |
| 232 | [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */ |
| 233 | .name = "Sec_FIFO TX", |
| 234 | .stream_name = "Playback", |
| 235 | .cpu_dai_name = "samsung-i2s.x", |
| 236 | .codec_dai_name = "wm8580-hifi-playback", |
| 237 | .platform_name = "samsung-audio", |
| 238 | .codec_name = "wm8580-codec.0-001b", |
| 239 | .init = smdk_wm8580_init_paifrx, |
| 240 | .ops = &smdk_ops, |
| 241 | }, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 242 | }; |
| 243 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 244 | static struct snd_soc_card smdk = { |
| 245 | .name = "SMDK-I2S", |
| 246 | .dai_link = smdk_dai, |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 247 | .num_links = 2, |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 248 | }; |
| 249 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 250 | static struct platform_device *smdk_snd_device; |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 251 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 252 | static int __init smdk_audio_init(void) |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 253 | { |
| 254 | int ret; |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 255 | char *str; |
| 256 | |
Jassi Brar | e3bd3e1 | 2010-12-20 11:05:53 +0900 | [diff] [blame] | 257 | if (machine_is_smdkc100() || machine_is_smdk6442() |
Jassi Brar | 40d2482 | 2010-12-20 11:05:55 +0900 | [diff] [blame] | 258 | || machine_is_smdkv210() || machine_is_smdkc110()) { |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 259 | smdk.num_links = 3; |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 260 | /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */ |
| 261 | str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name; |
| 262 | str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF; |
Jassi Brar | 72685f2 | 2010-12-20 11:05:48 +0900 | [diff] [blame] | 263 | } else if (machine_is_smdk6410()) { |
| 264 | str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name; |
| 265 | str[strlen(str) - 1] = '2'; |
| 266 | str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name; |
| 267 | str[strlen(str) - 1] = '2'; |
Jassi Brar | b0f39c2 | 2010-11-22 15:37:19 +0900 | [diff] [blame] | 268 | } |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 269 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 270 | smdk_snd_device = platform_device_alloc("soc-audio", -1); |
| 271 | if (!smdk_snd_device) |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 272 | return -ENOMEM; |
| 273 | |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 274 | platform_set_drvdata(smdk_snd_device, &smdk); |
| 275 | ret = platform_device_add(smdk_snd_device); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 276 | |
| 277 | if (ret) |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 278 | platform_device_put(smdk_snd_device); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 279 | |
| 280 | return ret; |
| 281 | } |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 282 | module_init(smdk_audio_init); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 283 | |
Mark Brown | 3853369 | 2010-11-24 17:18:45 +0000 | [diff] [blame] | 284 | static void __exit smdk_audio_exit(void) |
| 285 | { |
| 286 | platform_device_unregister(smdk_snd_device); |
| 287 | } |
| 288 | module_exit(smdk_audio_exit); |
| 289 | |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 290 | MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com"); |
Jassi Brar | d98ce6c | 2010-11-22 15:37:16 +0900 | [diff] [blame] | 291 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8580"); |
jassi brar | d0f5fa1 | 2009-09-19 09:46:06 +0900 | [diff] [blame] | 292 | MODULE_LICENSE("GPL"); |