blob: d9467a2c6de0ec635d0c4d9a0cc8f838b24f8f64 [file] [log] [blame]
Haojian Zhuangb6905d02010-08-19 00:36:30 +08001/*
2 * saarb.c -- SoC audio for saarb
3 *
4 * Copyright (C) 2010 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/device.h>
15#include <linux/clk.h>
16#include <linux/i2c.h>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/pcm_params.h>
20#include <sound/soc.h>
Haojian Zhuangb6905d02010-08-19 00:36:30 +080021#include <sound/jack.h>
22
23#include <asm/mach-types.h>
24
25#include "../codecs/88pm860x-codec.h"
26#include "pxa-ssp.h"
27
28static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd);
29
30static struct platform_device *saarb_snd_device;
31
32static struct snd_soc_jack hs_jack, mic_jack;
33
34static struct snd_soc_jack_pin hs_jack_pins[] = {
35 { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
36};
37
38static struct snd_soc_jack_pin mic_jack_pins[] = {
39 { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
40};
41
42/* saarb machine dapm widgets */
43static const struct snd_soc_dapm_widget saarb_dapm_widgets[] = {
44 SND_SOC_DAPM_HP("Headphone Stereophone", NULL),
45 SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
46 SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
47 SND_SOC_DAPM_SPK("Ext Speaker", NULL),
48 SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
49 SND_SOC_DAPM_MIC("Headset Mic", NULL),
50 SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
51};
52
53/* saarb machine audio map */
54static const struct snd_soc_dapm_route audio_map[] = {
55 {"Headset Stereophone", NULL, "HS1"},
56 {"Headset Stereophone", NULL, "HS2"},
57
58 {"Ext Speaker", NULL, "LSP"},
59 {"Ext Speaker", NULL, "LSN"},
60
61 {"Lineout Out 1", NULL, "LINEOUT1"},
62 {"Lineout Out 2", NULL, "LINEOUT2"},
63
64 {"MIC1P", NULL, "Mic1 Bias"},
65 {"MIC1N", NULL, "Mic1 Bias"},
66 {"Mic1 Bias", NULL, "Ext Mic 1"},
67
68 {"MIC2P", NULL, "Mic1 Bias"},
69 {"MIC2N", NULL, "Mic1 Bias"},
70 {"Mic1 Bias", NULL, "Headset Mic 2"},
71
72 {"MIC3P", NULL, "Mic3 Bias"},
73 {"MIC3N", NULL, "Mic3 Bias"},
74 {"Mic3 Bias", NULL, "Ext Mic 3"},
75};
76
77static int saarb_i2s_hw_params(struct snd_pcm_substream *substream,
78 struct snd_pcm_hw_params *params)
79{
80 struct snd_soc_pcm_runtime *rtd = substream->private_data;
81 struct snd_soc_dai *codec_dai = rtd->codec_dai;
82 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
83 int width = snd_pcm_format_physical_width(params_format(params));
84 int ret;
85
86 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_NET_PLL, 0,
87 PM860X_CLK_DIR_OUT);
88 if (ret < 0)
89 return ret;
90
91 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 0, PM860X_CLK_DIR_OUT);
92 if (ret < 0)
93 return ret;
94
95 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
96 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
97 if (ret < 0)
98 return ret;
99 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
100 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
101 if (ret < 0)
102 return ret;
103
104 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 3, 3, 2, width);
105
106 return ret;
107}
108
109static struct snd_soc_ops saarb_i2s_ops = {
110 .hw_params = saarb_i2s_hw_params,
111};
112
113static struct snd_soc_dai_link saarb_dai[] = {
114 {
115 .name = "88PM860x I2S",
116 .stream_name = "I2S Audio",
117 .cpu_dai_name = "pxa-ssp-dai.1",
118 .codec_dai_name = "88pm860x-i2s",
119 .platform_name = "pxa-pcm-audio",
120 .codec_name = "88pm860x-codec",
121 .init = saarb_pm860x_init,
122 .ops = &saarb_i2s_ops,
123 },
124};
125
126static struct snd_soc_card snd_soc_card_saarb = {
127 .name = "Saarb",
128 .dai_link = saarb_dai,
129 .num_links = ARRAY_SIZE(saarb_dai),
130};
131
132static int saarb_pm860x_init(struct snd_soc_pcm_runtime *rtd)
133{
134 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200135 struct snd_soc_dapm_context *dapm = &codec->dapm;
Haojian Zhuangb6905d02010-08-19 00:36:30 +0800136 int ret;
137
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200138 snd_soc_dapm_new_controls(dapm, saarb_dapm_widgets,
Haojian Zhuangb6905d02010-08-19 00:36:30 +0800139 ARRAY_SIZE(saarb_dapm_widgets));
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200140 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Haojian Zhuangb6905d02010-08-19 00:36:30 +0800141
142 /* connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200143 snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
144 snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
145 snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
146 snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
147 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
Haojian Zhuangb6905d02010-08-19 00:36:30 +0800148
Haojian Zhuangb6905d02010-08-19 00:36:30 +0800149 /* Headset jack detection */
150 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
151 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
152 &hs_jack);
153 snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
154 hs_jack_pins);
155 snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE,
156 &mic_jack);
157 snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
158 mic_jack_pins);
159
160 /* headphone, microphone detection & headset short detection */
161 pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
162 SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
163 pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
164 return 0;
165}
166
167static int __init saarb_init(void)
168{
169 int ret;
170
171 if (!machine_is_saarb())
172 return -ENODEV;
173 saarb_snd_device = platform_device_alloc("soc-audio", -1);
174 if (!saarb_snd_device)
175 return -ENOMEM;
176
177 platform_set_drvdata(saarb_snd_device, &snd_soc_card_saarb);
178
179 ret = platform_device_add(saarb_snd_device);
180 if (ret)
181 platform_device_put(saarb_snd_device);
182
183 return ret;
184}
185
186static void __exit saarb_exit(void)
187{
188 platform_device_unregister(saarb_snd_device);
189}
190
191module_init(saarb_init);
192module_exit(saarb_exit);
193
194MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
195MODULE_DESCRIPTION("ALSA SoC 88PM860x Saarb");
196MODULE_LICENSE("GPL");