]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - sound/soc/samsung/smdk_wm8580.c
Merge remote-tracking branches 'asoc/topic/rt5665', 'asoc/topic/rt5677', 'asoc/topic...
[mirror_ubuntu-artful-kernel.git] / sound / soc / samsung / smdk_wm8580.c
CommitLineData
d0f5fa17 1/*
d98ce6cf 2 * smdk_wm8580.c
d0f5fa17 3 *
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
df8ad335 5 * Author: Jaswinder Singh <jassisinghbrar@gmail.com>
d0f5fa17 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
da155d5b 13#include <linux/module.h>
d0f5fa17 14#include <sound/soc.h>
0378b6ac 15#include <sound/pcm_params.h>
d0f5fa17 16
17#include "../codecs/wm8580.h"
0fff21a8 18#include "i2s.h"
d0f5fa17 19
9d37e894
MB
20/*
21 * Default CFG switch settings to use this driver:
22 *
23 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
24 */
25
d98ce6cf
JB
26/* SMDK has a 12MHZ crystal attached to WM8580 */
27#define SMDK_WM8580_FREQ 12000000
d0f5fa17 28
d98ce6cf 29static int smdk_hw_params(struct snd_pcm_substream *substream,
d0f5fa17 30 struct snd_pcm_hw_params *params)
31{
32 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad 33 struct snd_soc_dai *codec_dai = rtd->codec_dai;
d0f5fa17 34 unsigned int pll_out;
e85a7099 35 int rfs, ret;
d0f5fa17 36
88ce1465
TB
37 switch (params_width(params)) {
38 case 8:
88ce1465 39 case 16:
d0f5fa17 40 break;
41 default:
42 return -EINVAL;
43 }
44
45 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
46 * This criterion can't be met if we request PLL output
47 * as {8000x256, 64000x256, 11025x256}Hz.
48 * As a wayout, we rather change rfs to a minimum value that
49 * results in (params_rate(params) * rfs), and itself, acceptable
50 * to both - the CODEC and the CPU.
51 */
52 switch (params_rate(params)) {
53 case 16000:
54 case 22050:
55 case 32000:
56 case 44100:
57 case 48000:
58 case 88200:
59 case 96000:
60 rfs = 256;
61 break;
62 case 64000:
63 rfs = 384;
64 break;
65 case 8000:
66 case 11025:
67 rfs = 512;
68 break;
69 default:
70 return -EINVAL;
71 }
72 pll_out = params_rate(params) * rfs;
73
26d95b6e 74 /* Set WM8580 to drive MCLK from its PLLA */
d0f5fa17 75 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
76 WM8580_CLKSRC_PLLA);
77 if (ret < 0)
78 return ret;
79
c5607d8e 80 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
d98ce6cf 81 SMDK_WM8580_FREQ, pll_out);
d0f5fa17 82 if (ret < 0)
83 return ret;
84
c5607d8e
MB
85 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
86 pll_out, SND_SOC_CLOCK_IN);
d0f5fa17 87 if (ret < 0)
88 return ret;
89
d0f5fa17 90 return 0;
91}
92
93/*
d98ce6cf 94 * SMDK WM8580 DAI operations.
d0f5fa17 95 */
d98ce6cf
JB
96static struct snd_soc_ops smdk_ops = {
97 .hw_params = smdk_hw_params,
d0f5fa17 98};
99
d98ce6cf 100/* SMDK Playback widgets */
ce363f6d 101static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
698cb111
MB
102 SND_SOC_DAPM_HP("Front", NULL),
103 SND_SOC_DAPM_HP("Center+Sub", NULL),
104 SND_SOC_DAPM_HP("Rear", NULL),
d0f5fa17 105
d0f5fa17 106 SND_SOC_DAPM_MIC("MicIn", NULL),
107 SND_SOC_DAPM_LINE("LineIn", NULL),
108};
109
110/* SMDK-PAIFTX connections */
ce363f6d 111static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
d0f5fa17 112 /* MicIn feeds AINL */
113 {"AINL", NULL, "MicIn"},
114
115 /* LineIn feeds AINL/R */
116 {"AINL", NULL, "LineIn"},
117 {"AINR", NULL, "LineIn"},
d0f5fa17 118
d0f5fa17 119 /* Front Left/Right are fed VOUT1L/R */
698cb111
MB
120 {"Front", NULL, "VOUT1L"},
121 {"Front", NULL, "VOUT1R"},
d0f5fa17 122
123 /* Center/Sub are fed VOUT2L/R */
698cb111
MB
124 {"Center+Sub", NULL, "VOUT2L"},
125 {"Center+Sub", NULL, "VOUT2R"},
d0f5fa17 126
127 /* Rear Left/Right are fed VOUT3L/R */
698cb111
MB
128 {"Rear", NULL, "VOUT3L"},
129 {"Rear", NULL, "VOUT3R"},
d0f5fa17 130};
131
d98ce6cf 132static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
d0f5fa17 133{
26d95b6e
MB
134 /* Enabling the microphone requires the fitting of a 0R
135 * resistor to connect the line from the microphone jack.
136 */
e236d4d7 137 snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
d0f5fa17 138
d0f5fa17 139 return 0;
140}
141
b0f39c25
JB
142enum {
143 PRI_PLAYBACK = 0,
144 PRI_CAPTURE,
b0f39c25
JB
145};
146
7a57ca23
LPC
147#define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
148 SND_SOC_DAIFMT_CBM_CFM)
149
d98ce6cf 150static struct snd_soc_dai_link smdk_dai[] = {
b0f39c25
JB
151 [PRI_PLAYBACK] = { /* Primary Playback i/f */
152 .name = "WM8580 PAIF RX",
153 .stream_name = "Playback",
cd9e2b62 154 .cpu_dai_name = "samsung-i2s.2",
b0f39c25 155 .codec_dai_name = "wm8580-hifi-playback",
a08485d8 156 .platform_name = "samsung-i2s.0",
5d5d09b2 157 .codec_name = "wm8580.0-001b",
7a57ca23 158 .dai_fmt = SMDK_DAI_FMT,
b0f39c25
JB
159 .ops = &smdk_ops,
160 },
161 [PRI_CAPTURE] = { /* Primary Capture i/f */
162 .name = "WM8580 PAIF TX",
163 .stream_name = "Capture",
cd9e2b62 164 .cpu_dai_name = "samsung-i2s.2",
b0f39c25 165 .codec_dai_name = "wm8580-hifi-capture",
a08485d8 166 .platform_name = "samsung-i2s.0",
5d5d09b2 167 .codec_name = "wm8580.0-001b",
7a57ca23 168 .dai_fmt = SMDK_DAI_FMT,
b0f39c25
JB
169 .init = smdk_wm8580_init_paiftx,
170 .ops = &smdk_ops,
171 },
d0f5fa17 172};
173
d98ce6cf
JB
174static struct snd_soc_card smdk = {
175 .name = "SMDK-I2S",
095d79dc 176 .owner = THIS_MODULE,
d98ce6cf 177 .dai_link = smdk_dai,
cd9e2b62 178 .num_links = ARRAY_SIZE(smdk_dai),
ce363f6d
MB
179
180 .dapm_widgets = smdk_wm8580_dapm_widgets,
181 .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
182 .dapm_routes = smdk_wm8580_audio_map,
183 .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
d0f5fa17 184};
185
d98ce6cf 186static struct platform_device *smdk_snd_device;
d0f5fa17 187
d98ce6cf 188static int __init smdk_audio_init(void)
d0f5fa17 189{
190 int ret;
191
d98ce6cf
JB
192 smdk_snd_device = platform_device_alloc("soc-audio", -1);
193 if (!smdk_snd_device)
d0f5fa17 194 return -ENOMEM;
195
d98ce6cf
JB
196 platform_set_drvdata(smdk_snd_device, &smdk);
197 ret = platform_device_add(smdk_snd_device);
d0f5fa17 198
199 if (ret)
d98ce6cf 200 platform_device_put(smdk_snd_device);
d0f5fa17 201
202 return ret;
203}
d98ce6cf 204module_init(smdk_audio_init);
d0f5fa17 205
38533698
MB
206static void __exit smdk_audio_exit(void)
207{
208 platform_device_unregister(smdk_snd_device);
209}
210module_exit(smdk_audio_exit);
211
df8ad335 212MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
d98ce6cf 213MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
d0f5fa17 214MODULE_LICENSE("GPL");