blob: 8f92ffceb5cafb3b797678ea073a2fbc0a9c9647 [file] [log] [blame]
jassi brard0f5fa12009-09-19 09:46:06 +09001/*
Jassi Brard98ce6c2010-11-22 15:37:16 +09002 * smdk_wm8580.c
jassi brard0f5fa12009-09-19 09:46:06 +09003 *
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
jassi brard0f5fa12009-09-19 09:46:06 +090013#include <sound/soc.h>
Seungwhan Youn0378b6a2011-01-11 07:26:06 +090014#include <sound/pcm_params.h>
jassi brard0f5fa12009-09-19 09:46:06 +090015
Jassi Brarb0f39c22010-11-22 15:37:19 +090016#include <asm/mach-types.h>
17
jassi brard0f5fa12009-09-19 09:46:06 +090018#include "../codecs/wm8580.h"
Jassi Brar0fff21a2010-11-22 15:37:07 +090019#include "i2s.h"
jassi brard0f5fa12009-09-19 09:46:06 +090020
Mark Brown9d37e892010-08-06 17:57:45 +010021/*
22 * Default CFG switch settings to use this driver:
23 *
24 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
25 */
26
Jassi Brard98ce6c2010-11-22 15:37:16 +090027/* SMDK has a 12MHZ crystal attached to WM8580 */
28#define SMDK_WM8580_FREQ 12000000
jassi brard0f5fa12009-09-19 09:46:06 +090029
Jassi Brard98ce6c2010-11-22 15:37:16 +090030static int smdk_hw_params(struct snd_pcm_substream *substream,
jassi brard0f5fa12009-09-19 09:46:06 +090031 struct snd_pcm_hw_params *params)
32{
33 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000034 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
35 struct snd_soc_dai *codec_dai = rtd->codec_dai;
jassi brard0f5fa12009-09-19 09:46:06 +090036 unsigned int pll_out;
37 int bfs, rfs, ret;
38
39 switch (params_format(params)) {
40 case SNDRV_PCM_FORMAT_U8:
41 case SNDRV_PCM_FORMAT_S8:
42 bfs = 16;
43 break;
44 case SNDRV_PCM_FORMAT_U16_LE:
45 case SNDRV_PCM_FORMAT_S16_LE:
46 bfs = 32;
47 break;
48 default:
49 return -EINVAL;
50 }
51
52 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
53 * This criterion can't be met if we request PLL output
54 * as {8000x256, 64000x256, 11025x256}Hz.
55 * As a wayout, we rather change rfs to a minimum value that
56 * results in (params_rate(params) * rfs), and itself, acceptable
57 * to both - the CODEC and the CPU.
58 */
59 switch (params_rate(params)) {
60 case 16000:
61 case 22050:
62 case 32000:
63 case 44100:
64 case 48000:
65 case 88200:
66 case 96000:
67 rfs = 256;
68 break;
69 case 64000:
70 rfs = 384;
71 break;
72 case 8000:
73 case 11025:
74 rfs = 512;
75 break;
76 default:
77 return -EINVAL;
78 }
79 pll_out = params_rate(params) * rfs;
80
81 /* Set the Codec DAI configuration */
82 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
83 | SND_SOC_DAIFMT_NB_NF
84 | SND_SOC_DAIFMT_CBM_CFM);
85 if (ret < 0)
86 return ret;
87
88 /* Set the AP DAI configuration */
89 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
90 | SND_SOC_DAIFMT_NB_NF
91 | SND_SOC_DAIFMT_CBM_CFM);
92 if (ret < 0)
93 return ret;
94
Mark Brown26d95b62009-10-28 15:47:48 +000095 /* Set WM8580 to drive MCLK from its PLLA */
jassi brard0f5fa12009-09-19 09:46:06 +090096 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
97 WM8580_CLKSRC_PLLA);
98 if (ret < 0)
99 return ret;
100
Mark Brownc5607d82010-08-13 19:05:04 +0100101 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
Jassi Brard98ce6c2010-11-22 15:37:16 +0900102 SMDK_WM8580_FREQ, pll_out);
jassi brard0f5fa12009-09-19 09:46:06 +0900103 if (ret < 0)
104 return ret;
105
Mark Brownc5607d82010-08-13 19:05:04 +0100106 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
107 pll_out, SND_SOC_CLOCK_IN);
jassi brard0f5fa12009-09-19 09:46:06 +0900108 if (ret < 0)
109 return ret;
110
jassi brard0f5fa12009-09-19 09:46:06 +0900111 return 0;
112}
113
114/*
Jassi Brard98ce6c2010-11-22 15:37:16 +0900115 * SMDK WM8580 DAI operations.
jassi brard0f5fa12009-09-19 09:46:06 +0900116 */
Jassi Brard98ce6c2010-11-22 15:37:16 +0900117static struct snd_soc_ops smdk_ops = {
118 .hw_params = smdk_hw_params,
jassi brard0f5fa12009-09-19 09:46:06 +0900119};
120
Jassi Brard98ce6c2010-11-22 15:37:16 +0900121/* SMDK Playback widgets */
Mark Brownce363f62011-10-08 13:31:18 +0100122static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
Mark Brown698cb112010-08-06 17:23:02 +0100123 SND_SOC_DAPM_HP("Front", NULL),
124 SND_SOC_DAPM_HP("Center+Sub", NULL),
125 SND_SOC_DAPM_HP("Rear", NULL),
jassi brard0f5fa12009-09-19 09:46:06 +0900126
jassi brard0f5fa12009-09-19 09:46:06 +0900127 SND_SOC_DAPM_MIC("MicIn", NULL),
128 SND_SOC_DAPM_LINE("LineIn", NULL),
129};
130
131/* SMDK-PAIFTX connections */
Mark Brownce363f62011-10-08 13:31:18 +0100132static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
jassi brard0f5fa12009-09-19 09:46:06 +0900133 /* MicIn feeds AINL */
134 {"AINL", NULL, "MicIn"},
135
136 /* LineIn feeds AINL/R */
137 {"AINL", NULL, "LineIn"},
138 {"AINR", NULL, "LineIn"},
jassi brard0f5fa12009-09-19 09:46:06 +0900139
jassi brard0f5fa12009-09-19 09:46:06 +0900140 /* Front Left/Right are fed VOUT1L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100141 {"Front", NULL, "VOUT1L"},
142 {"Front", NULL, "VOUT1R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900143
144 /* Center/Sub are fed VOUT2L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100145 {"Center+Sub", NULL, "VOUT2L"},
146 {"Center+Sub", NULL, "VOUT2R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900147
148 /* Rear Left/Right are fed VOUT3L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100149 {"Rear", NULL, "VOUT3L"},
150 {"Rear", NULL, "VOUT3R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900151};
152
Jassi Brard98ce6c2010-11-22 15:37:16 +0900153static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
jassi brard0f5fa12009-09-19 09:46:06 +0900154{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000155 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200156 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000157
Mark Brown26d95b62009-10-28 15:47:48 +0000158 /* Enabling the microphone requires the fitting of a 0R
159 * resistor to connect the line from the microphone jack.
160 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200161 snd_soc_dapm_disable_pin(dapm, "MicIn");
jassi brard0f5fa12009-09-19 09:46:06 +0900162
jassi brard0f5fa12009-09-19 09:46:06 +0900163 return 0;
164}
165
Jassi Brarb0f39c22010-11-22 15:37:19 +0900166enum {
167 PRI_PLAYBACK = 0,
168 PRI_CAPTURE,
169 SEC_PLAYBACK,
170};
171
Jassi Brard98ce6c2010-11-22 15:37:16 +0900172static struct snd_soc_dai_link smdk_dai[] = {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900173 [PRI_PLAYBACK] = { /* Primary Playback i/f */
174 .name = "WM8580 PAIF RX",
175 .stream_name = "Playback",
Jassi Brar72685f22010-12-20 11:05:48 +0900176 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900177 .codec_dai_name = "wm8580-hifi-playback",
178 .platform_name = "samsung-audio",
Mark Brown5d5d09b2011-08-03 17:34:41 +0900179 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900180 .ops = &smdk_ops,
181 },
182 [PRI_CAPTURE] = { /* Primary Capture i/f */
183 .name = "WM8580 PAIF TX",
184 .stream_name = "Capture",
Jassi Brar72685f22010-12-20 11:05:48 +0900185 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900186 .codec_dai_name = "wm8580-hifi-capture",
187 .platform_name = "samsung-audio",
Mark Brown5d5d09b2011-08-03 17:34:41 +0900188 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900189 .init = smdk_wm8580_init_paiftx,
190 .ops = &smdk_ops,
191 },
192 [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
193 .name = "Sec_FIFO TX",
194 .stream_name = "Playback",
195 .cpu_dai_name = "samsung-i2s.x",
196 .codec_dai_name = "wm8580-hifi-playback",
197 .platform_name = "samsung-audio",
Mark Brown5d5d09b2011-08-03 17:34:41 +0900198 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900199 .ops = &smdk_ops,
200 },
jassi brard0f5fa12009-09-19 09:46:06 +0900201};
202
Jassi Brard98ce6c2010-11-22 15:37:16 +0900203static struct snd_soc_card smdk = {
204 .name = "SMDK-I2S",
205 .dai_link = smdk_dai,
Jassi Brarb0f39c22010-11-22 15:37:19 +0900206 .num_links = 2,
Mark Brownce363f62011-10-08 13:31:18 +0100207
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 brard0f5fa12009-09-19 09:46:06 +0900212};
213
Jassi Brard98ce6c2010-11-22 15:37:16 +0900214static struct platform_device *smdk_snd_device;
jassi brard0f5fa12009-09-19 09:46:06 +0900215
Jassi Brard98ce6c2010-11-22 15:37:16 +0900216static int __init smdk_audio_init(void)
jassi brard0f5fa12009-09-19 09:46:06 +0900217{
218 int ret;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900219 char *str;
220
Kukjin Kim4b421202011-05-11 16:28:45 +0900221 if (machine_is_smdkc100()
Jassi Brar40d24822010-12-20 11:05:55 +0900222 || machine_is_smdkv210() || machine_is_smdkc110()) {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900223 smdk.num_links = 3;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900224 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
225 str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
226 str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
Jassi Brar72685f22010-12-20 11:05:48 +0900227 } else if (machine_is_smdk6410()) {
228 str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
229 str[strlen(str) - 1] = '2';
230 str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
231 str[strlen(str) - 1] = '2';
Jassi Brarb0f39c22010-11-22 15:37:19 +0900232 }
jassi brard0f5fa12009-09-19 09:46:06 +0900233
Jassi Brard98ce6c2010-11-22 15:37:16 +0900234 smdk_snd_device = platform_device_alloc("soc-audio", -1);
235 if (!smdk_snd_device)
jassi brard0f5fa12009-09-19 09:46:06 +0900236 return -ENOMEM;
237
Jassi Brard98ce6c2010-11-22 15:37:16 +0900238 platform_set_drvdata(smdk_snd_device, &smdk);
239 ret = platform_device_add(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900240
241 if (ret)
Jassi Brard98ce6c2010-11-22 15:37:16 +0900242 platform_device_put(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900243
244 return ret;
245}
Jassi Brard98ce6c2010-11-22 15:37:16 +0900246module_init(smdk_audio_init);
jassi brard0f5fa12009-09-19 09:46:06 +0900247
Mark Brown38533692010-11-24 17:18:45 +0000248static void __exit smdk_audio_exit(void)
249{
250 platform_device_unregister(smdk_snd_device);
251}
252module_exit(smdk_audio_exit);
253
jassi brard0f5fa12009-09-19 09:46:06 +0900254MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
Jassi Brard98ce6c2010-11-22 15:37:16 +0900255MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
jassi brard0f5fa12009-09-19 09:46:06 +0900256MODULE_LICENSE("GPL");