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