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