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