blob: 5001dbb9b257764d9b88427de5bc86bebfba5a7b [file] [log] [blame]
Qiao Zhoub883f362012-06-11 18:04:41 +08001/*
2 * linux/sound/soc/pxa/ttc_dkb.c
3 *
4 * Copyright (C) 2012 Marvell International Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/soc.h>
26#include <sound/jack.h>
27#include <asm/mach-types.h>
28#include <sound/pcm_params.h>
29#include "../codecs/88pm860x-codec.h"
30
31static struct snd_soc_jack hs_jack, mic_jack;
32
33static struct snd_soc_jack_pin hs_jack_pins[] = {
34 { .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE, },
35};
36
37static struct snd_soc_jack_pin mic_jack_pins[] = {
38 { .pin = "Headset Mic 2", .mask = SND_JACK_MICROPHONE, },
39};
40
41/* ttc machine dapm widgets */
42static const struct snd_soc_dapm_widget ttc_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
44 SND_SOC_DAPM_LINE("Lineout Out 1", NULL),
45 SND_SOC_DAPM_LINE("Lineout Out 2", NULL),
46 SND_SOC_DAPM_SPK("Ext Speaker", NULL),
47 SND_SOC_DAPM_MIC("Ext Mic 1", NULL),
48 SND_SOC_DAPM_MIC("Headset Mic 2", NULL),
49 SND_SOC_DAPM_MIC("Ext Mic 3", NULL),
50};
51
52/* ttc machine audio map */
53static const struct snd_soc_dapm_route ttc_audio_map[] = {
54 {"Headset Stereophone", NULL, "HS1"},
55 {"Headset Stereophone", NULL, "HS2"},
56
57 {"Ext Speaker", NULL, "LSP"},
58 {"Ext Speaker", NULL, "LSN"},
59
60 {"Lineout Out 1", NULL, "LINEOUT1"},
61 {"Lineout Out 2", NULL, "LINEOUT2"},
62
63 {"MIC1P", NULL, "Mic1 Bias"},
64 {"MIC1N", NULL, "Mic1 Bias"},
65 {"Mic1 Bias", NULL, "Ext Mic 1"},
66
67 {"MIC2P", NULL, "Mic1 Bias"},
68 {"MIC2N", NULL, "Mic1 Bias"},
69 {"Mic1 Bias", NULL, "Headset Mic 2"},
70
71 {"MIC3P", NULL, "Mic3 Bias"},
72 {"MIC3N", NULL, "Mic3 Bias"},
73 {"Mic3 Bias", NULL, "Ext Mic 3"},
74};
75
76static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd)
77{
78 struct snd_soc_codec *codec = rtd->codec;
Qiao Zhoub883f362012-06-11 18:04:41 +080079
80 /* Headset jack detection */
81 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
82 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2,
83 &hs_jack);
84 snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
85 hs_jack_pins);
86 snd_soc_jack_new(codec, "Microphone Jack", SND_JACK_MICROPHONE,
87 &mic_jack);
88 snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
89 mic_jack_pins);
90
91 /* headphone, microphone detection & headset short detection */
92 pm860x_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADPHONE,
93 SND_JACK_BTN_0, SND_JACK_BTN_1, SND_JACK_BTN_2);
94 pm860x_mic_jack_detect(codec, &hs_jack, SND_JACK_MICROPHONE);
95
96 return 0;
97}
98
99/* ttc/td-dkb digital audio interface glue - connects codec <--> CPU */
100static struct snd_soc_dai_link ttc_pm860x_hifi_dai[] = {
101{
102 .name = "88pm860x i2s",
103 .stream_name = "audio playback",
104 .codec_name = "88pm860x-codec",
105 .platform_name = "mmp-pcm-audio",
106 .cpu_dai_name = "pxa-ssp-dai.1",
107 .codec_dai_name = "88pm860x-i2s",
108 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
109 SND_SOC_DAIFMT_CBM_CFM,
110 .init = ttc_pm860x_init,
111},
112};
113
114/* ttc/td audio machine driver */
115static struct snd_soc_card ttc_dkb_card = {
116 .name = "ttc-dkb-hifi",
Wei Yongjun3986b982013-07-02 17:26:40 +0800117 .owner = THIS_MODULE,
Qiao Zhoub883f362012-06-11 18:04:41 +0800118 .dai_link = ttc_pm860x_hifi_dai,
119 .num_links = ARRAY_SIZE(ttc_pm860x_hifi_dai),
120
121 .dapm_widgets = ttc_dapm_widgets,
122 .num_dapm_widgets = ARRAY_SIZE(ttc_dapm_widgets),
123 .dapm_routes = ttc_audio_map,
124 .num_dapm_routes = ARRAY_SIZE(ttc_audio_map),
125};
126
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500127static int ttc_dkb_probe(struct platform_device *pdev)
Qiao Zhoub883f362012-06-11 18:04:41 +0800128{
129 struct snd_soc_card *card = &ttc_dkb_card;
130 int ret;
131
132 card->dev = &pdev->dev;
133
134 ret = snd_soc_register_card(card);
135 if (ret)
136 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
137 ret);
138
139 return ret;
140}
141
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500142static int ttc_dkb_remove(struct platform_device *pdev)
Qiao Zhoub883f362012-06-11 18:04:41 +0800143{
144 struct snd_soc_card *card = platform_get_drvdata(pdev);
145
146 snd_soc_unregister_card(card);
147
148 return 0;
149}
150
151static struct platform_driver ttc_dkb_driver = {
152 .driver = {
153 .name = "ttc-dkb-audio",
Dmitry Eremin-Solenikov7db16982013-10-17 14:01:37 +0400154 .pm = &snd_soc_pm_ops,
Qiao Zhoub883f362012-06-11 18:04:41 +0800155 },
156 .probe = ttc_dkb_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -0500157 .remove = ttc_dkb_remove,
Qiao Zhoub883f362012-06-11 18:04:41 +0800158};
159
160module_platform_driver(ttc_dkb_driver);
161
162/* Module information */
163MODULE_AUTHOR("Qiao Zhou, <zhouqiao@marvell.com>");
164MODULE_DESCRIPTION("ALSA SoC TTC DKB");
165MODULE_LICENSE("GPL");
166MODULE_ALIAS("platform:ttc-dkb-audio");