blob: ade2809cf393eebc97d74952b44c65aaa35835ac [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
Jaswinder Singhdf8ad332012-02-25 16:24:36 +05305 * Author: Jaswinder Singh <jassisinghbrar@gmail.com>
jassi brard0f5fa12009-09-19 09:46:06 +09006 *
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 Gortmakerda155d52011-07-15 12:38:28 -040013#include <linux/module.h>
jassi brard0f5fa12009-09-19 09:46:06 +090014#include <sound/soc.h>
Seungwhan Youn0378b6a2011-01-11 07:26:06 +090015#include <sound/pcm_params.h>
jassi brard0f5fa12009-09-19 09:46:06 +090016
Jassi Brarb0f39c22010-11-22 15:37:19 +090017#include <asm/mach-types.h>
18
jassi brard0f5fa12009-09-19 09:46:06 +090019#include "../codecs/wm8580.h"
Jassi Brar0fff21a2010-11-22 15:37:07 +090020#include "i2s.h"
jassi brard0f5fa12009-09-19 09:46:06 +090021
Mark Brown9d37e892010-08-06 17:57:45 +010022/*
23 * Default CFG switch settings to use this driver:
24 *
25 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
26 */
27
Jassi Brard98ce6c2010-11-22 15:37:16 +090028/* SMDK has a 12MHZ crystal attached to WM8580 */
29#define SMDK_WM8580_FREQ 12000000
jassi brard0f5fa12009-09-19 09:46:06 +090030
Jassi Brard98ce6c2010-11-22 15:37:16 +090031static int smdk_hw_params(struct snd_pcm_substream *substream,
jassi brard0f5fa12009-09-19 09:46:06 +090032 struct snd_pcm_hw_params *params)
33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000035 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
36 struct snd_soc_dai *codec_dai = rtd->codec_dai;
jassi brard0f5fa12009-09-19 09:46:06 +090037 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 Brown26d95b62009-10-28 15:47:48 +000096 /* Set WM8580 to drive MCLK from its PLLA */
jassi brard0f5fa12009-09-19 09:46:06 +090097 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
98 WM8580_CLKSRC_PLLA);
99 if (ret < 0)
100 return ret;
101
Mark Brownc5607d82010-08-13 19:05:04 +0100102 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
Jassi Brard98ce6c2010-11-22 15:37:16 +0900103 SMDK_WM8580_FREQ, pll_out);
jassi brard0f5fa12009-09-19 09:46:06 +0900104 if (ret < 0)
105 return ret;
106
Mark Brownc5607d82010-08-13 19:05:04 +0100107 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
108 pll_out, SND_SOC_CLOCK_IN);
jassi brard0f5fa12009-09-19 09:46:06 +0900109 if (ret < 0)
110 return ret;
111
jassi brard0f5fa12009-09-19 09:46:06 +0900112 return 0;
113}
114
115/*
Jassi Brard98ce6c2010-11-22 15:37:16 +0900116 * SMDK WM8580 DAI operations.
jassi brard0f5fa12009-09-19 09:46:06 +0900117 */
Jassi Brard98ce6c2010-11-22 15:37:16 +0900118static struct snd_soc_ops smdk_ops = {
119 .hw_params = smdk_hw_params,
jassi brard0f5fa12009-09-19 09:46:06 +0900120};
121
Jassi Brard98ce6c2010-11-22 15:37:16 +0900122/* SMDK Playback widgets */
Mark Brownce363f62011-10-08 13:31:18 +0100123static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
Mark Brown698cb112010-08-06 17:23:02 +0100124 SND_SOC_DAPM_HP("Front", NULL),
125 SND_SOC_DAPM_HP("Center+Sub", NULL),
126 SND_SOC_DAPM_HP("Rear", NULL),
jassi brard0f5fa12009-09-19 09:46:06 +0900127
jassi brard0f5fa12009-09-19 09:46:06 +0900128 SND_SOC_DAPM_MIC("MicIn", NULL),
129 SND_SOC_DAPM_LINE("LineIn", NULL),
130};
131
132/* SMDK-PAIFTX connections */
Mark Brownce363f62011-10-08 13:31:18 +0100133static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
jassi brard0f5fa12009-09-19 09:46:06 +0900134 /* MicIn feeds AINL */
135 {"AINL", NULL, "MicIn"},
136
137 /* LineIn feeds AINL/R */
138 {"AINL", NULL, "LineIn"},
139 {"AINR", NULL, "LineIn"},
jassi brard0f5fa12009-09-19 09:46:06 +0900140
jassi brard0f5fa12009-09-19 09:46:06 +0900141 /* Front Left/Right are fed VOUT1L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100142 {"Front", NULL, "VOUT1L"},
143 {"Front", NULL, "VOUT1R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900144
145 /* Center/Sub are fed VOUT2L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100146 {"Center+Sub", NULL, "VOUT2L"},
147 {"Center+Sub", NULL, "VOUT2R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900148
149 /* Rear Left/Right are fed VOUT3L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100150 {"Rear", NULL, "VOUT3L"},
151 {"Rear", NULL, "VOUT3R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900152};
153
Jassi Brard98ce6c2010-11-22 15:37:16 +0900154static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
jassi brard0f5fa12009-09-19 09:46:06 +0900155{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000156 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200157 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000158
Mark Brown26d95b62009-10-28 15:47:48 +0000159 /* Enabling the microphone requires the fitting of a 0R
160 * resistor to connect the line from the microphone jack.
161 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200162 snd_soc_dapm_disable_pin(dapm, "MicIn");
jassi brard0f5fa12009-09-19 09:46:06 +0900163
jassi brard0f5fa12009-09-19 09:46:06 +0900164 return 0;
165}
166
Jassi Brarb0f39c22010-11-22 15:37:19 +0900167enum {
168 PRI_PLAYBACK = 0,
169 PRI_CAPTURE,
170 SEC_PLAYBACK,
171};
172
Jassi Brard98ce6c2010-11-22 15:37:16 +0900173static struct snd_soc_dai_link smdk_dai[] = {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900174 [PRI_PLAYBACK] = { /* Primary Playback i/f */
175 .name = "WM8580 PAIF RX",
176 .stream_name = "Playback",
Jassi Brar72685f22010-12-20 11:05:48 +0900177 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900178 .codec_dai_name = "wm8580-hifi-playback",
179 .platform_name = "samsung-audio",
Mark Brown5d5d09b2011-08-03 17:34:41 +0900180 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900181 .ops = &smdk_ops,
182 },
183 [PRI_CAPTURE] = { /* Primary Capture i/f */
184 .name = "WM8580 PAIF TX",
185 .stream_name = "Capture",
Jassi Brar72685f22010-12-20 11:05:48 +0900186 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900187 .codec_dai_name = "wm8580-hifi-capture",
188 .platform_name = "samsung-audio",
Mark Brown5d5d09b2011-08-03 17:34:41 +0900189 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900190 .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 Brown5d5d09b2011-08-03 17:34:41 +0900199 .codec_name = "wm8580.0-001b",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900200 .ops = &smdk_ops,
201 },
jassi brard0f5fa12009-09-19 09:46:06 +0900202};
203
Jassi Brard98ce6c2010-11-22 15:37:16 +0900204static struct snd_soc_card smdk = {
205 .name = "SMDK-I2S",
Axel Lin095d79d2011-12-22 10:53:15 +0800206 .owner = THIS_MODULE,
Jassi Brard98ce6c2010-11-22 15:37:16 +0900207 .dai_link = smdk_dai,
Jassi Brarb0f39c22010-11-22 15:37:19 +0900208 .num_links = 2,
Mark Brownce363f62011-10-08 13:31:18 +0100209
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 brard0f5fa12009-09-19 09:46:06 +0900214};
215
Jassi Brard98ce6c2010-11-22 15:37:16 +0900216static struct platform_device *smdk_snd_device;
jassi brard0f5fa12009-09-19 09:46:06 +0900217
Jassi Brard98ce6c2010-11-22 15:37:16 +0900218static int __init smdk_audio_init(void)
jassi brard0f5fa12009-09-19 09:46:06 +0900219{
220 int ret;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900221 char *str;
222
Kukjin Kim4b421202011-05-11 16:28:45 +0900223 if (machine_is_smdkc100()
Jassi Brar40d24822010-12-20 11:05:55 +0900224 || machine_is_smdkv210() || machine_is_smdkc110()) {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900225 smdk.num_links = 3;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900226 /* 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 Brar72685f22010-12-20 11:05:48 +0900229 } 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 Brarb0f39c22010-11-22 15:37:19 +0900234 }
jassi brard0f5fa12009-09-19 09:46:06 +0900235
Jassi Brard98ce6c2010-11-22 15:37:16 +0900236 smdk_snd_device = platform_device_alloc("soc-audio", -1);
237 if (!smdk_snd_device)
jassi brard0f5fa12009-09-19 09:46:06 +0900238 return -ENOMEM;
239
Jassi Brard98ce6c2010-11-22 15:37:16 +0900240 platform_set_drvdata(smdk_snd_device, &smdk);
241 ret = platform_device_add(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900242
243 if (ret)
Jassi Brard98ce6c2010-11-22 15:37:16 +0900244 platform_device_put(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900245
246 return ret;
247}
Jassi Brard98ce6c2010-11-22 15:37:16 +0900248module_init(smdk_audio_init);
jassi brard0f5fa12009-09-19 09:46:06 +0900249
Mark Brown38533692010-11-24 17:18:45 +0000250static void __exit smdk_audio_exit(void)
251{
252 platform_device_unregister(smdk_snd_device);
253}
254module_exit(smdk_audio_exit);
255
Jaswinder Singhdf8ad332012-02-25 16:24:36 +0530256MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
Jassi Brard98ce6c2010-11-22 15:37:16 +0900257MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
jassi brard0f5fa12009-09-19 09:46:06 +0900258MODULE_LICENSE("GPL");