blob: 18cbe0e7c2235862e3ae139fcc92c1d34e4c9e04 [file] [log] [blame]
Haojian Zhuangb0547a72010-08-19 00:36:00 +08001/*
2 * tavorevb3.c -- SoC audio for Tavor EVB3
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>
21#include <sound/soc-dapm.h>
22#include <sound/jack.h>
23
24#include <asm/mach-types.h>
25
26#include "../codecs/88pm860x-codec.h"
27#include "pxa-ssp.h"
28
29static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd);
30
31static struct platform_device *evb3_snd_device;
32
33static struct snd_soc_jack hs_jack, mic_jack;
34
35static struct snd_soc_jack_pin hs_jack_pins[] = {
36 { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
37};
38
39static struct snd_soc_jack_pin mic_jack_pins[] = {
40 { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
41};
42
43/* tavorevb3 machine dapm widgets */
44static const struct snd_soc_dapm_widget evb3_dapm_widgets[] = {
45 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
46 SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
47 SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
48 SND_SOC_DAPM_SPK("Ext Speaker", NULL),
49 SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
50 SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
51 SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
52};
53
54/* tavorevb3 machine audio map */
55static const struct snd_soc_dapm_route audio_map[] = {
56 {"Headset Stereophone", NULL, "HS1"},
57 {"Headset Stereophone", NULL, "HS2"},
58
59 {"Ext Speaker", NULL, "LSP"},
60 {"Ext Speaker", NULL, "LSN"},
61
62 {"Lineout Out 1", NULL, "LINEOUT1"},
63 {"Lineout Out 2", NULL, "LINEOUT2"},
64
65 {"MIC1P", NULL, "Mic1 Bias"},
66 {"MIC1N", NULL, "Mic1 Bias"},
67 {"Mic1 Bias", NULL, "Ext Mic 1"},
68
69 {"MIC2P", NULL, "Mic1 Bias"},
70 {"MIC2N", NULL, "Mic1 Bias"},
71 {"Mic1 Bias", NULL, "Headset Mic 2"},
72
73 {"MIC3P", NULL, "Mic3 Bias"},
74 {"MIC3N", NULL, "Mic3 Bias"},
75 {"Mic3 Bias", NULL, "Ext Mic 3"},
76};
77
78static int evb3_i2s_hw_params(struct snd_pcm_substream *substream,
79 struct snd_pcm_hw_params *params)
80{
81 struct snd_soc_pcm_runtime *rtd = substream->private_data;
82 struct snd_soc_dai *codec_dai = rtd->codec_dai;
83 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
84 int width = snd_pcm_format_physical_width(params_format(params));
85 int ret;
86
87 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_NET_PLL, 0,
88 PM860X_CLK_DIR_OUT);
89 if (ret < 0)
90 return ret;
91
92 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 0, PM860X_CLK_DIR_OUT);
93 if (ret < 0)
94 return ret;
95
96 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
97 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
98 if (ret < 0)
99 return ret;
100
101 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
102 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
103 if (ret < 0)
104 return ret;
105
106 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 3, 3, 2, width);
107 return ret;
108}
109
110static struct snd_soc_ops evb3_i2s_ops = {
111 .hw_params = evb3_i2s_hw_params,
112};
113
114static struct snd_soc_dai_link evb3_dai[] = {
115 {
116 .name = "88PM860x I2S",
117 .stream_name = "I2S Audio",
118 .cpu_dai_name = "pxa-ssp-dai.1",
119 .codec_dai_name = "88pm860x-i2s",
120 .platform_name = "pxa-pcm-audio",
121 .codec_name = "88pm860x-codec",
122 .init = evb3_pm860x_init,
123 .ops = &evb3_i2s_ops,
124 },
125};
126
127static struct snd_soc_card snd_soc_card_evb3 = {
128 .name = "Tavor EVB3",
129 .dai_link = evb3_dai,
130 .num_links = ARRAY_SIZE(evb3_dai),
131};
132
133static int evb3_pm860x_init(struct snd_soc_pcm_runtime *rtd)
134{
135 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200136 struct snd_soc_dapm_context *dapm = &codec->dapm;
Haojian Zhuangb0547a72010-08-19 00:36:00 +0800137 int ret;
138
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200139 snd_soc_dapm_new_controls(dapm, evb3_dapm_widgets,
Haojian Zhuangb0547a72010-08-19 00:36:00 +0800140 ARRAY_SIZE(evb3_dapm_widgets));
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200141 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Haojian Zhuangb0547a72010-08-19 00:36:00 +0800142
143 /* connected pins */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200144 snd_soc_dapm_enable_pin(dapm, "Ext Speaker");
145 snd_soc_dapm_enable_pin(dapm, "Ext Mic 1");
146 snd_soc_dapm_enable_pin(dapm, "Ext Mic 3");
147 snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
148 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
Haojian Zhuangb0547a72010-08-19 00:36:00 +0800149
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200150 ret = snd_soc_dapm_sync(dapm);
Haojian Zhuangb0547a72010-08-19 00:36:00 +0800151 if (ret)
152 return ret;
153
154 /* Headset jack detection */
155 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
156 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
157 &hs_jack);
158 snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
159 hs_jack_pins);
160 snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE,
161 &mic_jack);
162 snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
163 mic_jack_pins);
164
165 /* headphone, microphone detection & headset short detection */
166 pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
167 SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
168 pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
169 return 0;
170}
171
172static int __init tavorevb3_init(void)
173{
174 int ret;
175
176 if (!machine_is_tavorevb3())
177 return -ENODEV;
178 evb3_snd_device = platform_device_alloc("soc-audio", -1);
179 if (!evb3_snd_device)
180 return -ENOMEM;
181
182 platform_set_drvdata(evb3_snd_device, &snd_soc_card_evb3);
183
184 ret = platform_device_add(evb3_snd_device);
185 if (ret)
186 platform_device_put(evb3_snd_device);
187
188 return ret;
189}
190
191static void __exit tavorevb3_exit(void)
192{
193 platform_device_unregister(evb3_snd_device);
194}
195
196module_init(tavorevb3_init);
197module_exit(tavorevb3_exit);
198
199MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
200MODULE_DESCRIPTION("ALSA SoC 88PM860x Tavor EVB3");
201MODULE_LICENSE("GPL");