blob: a3c5f02a60fc57f05a4ef842881213a76349a744 [file] [log] [blame]
Jarkko Nikula9b351d42014-05-30 15:16:43 +03001/*
2 * Intel Baytrail SST MAX98090 machine driver
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/acpi.h>
19#include <linux/device.h>
20#include <linux/gpio.h>
21#include <linux/gpio/consumer.h>
22#include <linux/slab.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26#include <sound/jack.h>
27#include "../codecs/max98090.h"
28
29struct byt_max98090_private {
30 struct snd_soc_jack jack;
31};
32
33static const struct snd_soc_dapm_widget byt_max98090_widgets[] = {
34 SND_SOC_DAPM_HP("Headphone", NULL),
35 SND_SOC_DAPM_MIC("Headset Mic", NULL),
36 SND_SOC_DAPM_MIC("Int Mic", NULL),
37 SND_SOC_DAPM_SPK("Ext Spk", NULL),
38};
39
40static const struct snd_soc_dapm_route byt_max98090_audio_map[] = {
41 {"IN34", NULL, "Headset Mic"},
Jarkko Nikulaa5b37bf2014-06-23 16:29:37 +030042 {"Headset Mic", NULL, "MICBIAS"},
Jarkko Nikula9b351d42014-05-30 15:16:43 +030043 {"DMICL", NULL, "Int Mic"},
44 {"Headphone", NULL, "HPL"},
45 {"Headphone", NULL, "HPR"},
46 {"Ext Spk", NULL, "SPKL"},
47 {"Ext Spk", NULL, "SPKR"},
48};
49
50static const struct snd_kcontrol_new byt_max98090_controls[] = {
51 SOC_DAPM_PIN_SWITCH("Headphone"),
52 SOC_DAPM_PIN_SWITCH("Headset Mic"),
53 SOC_DAPM_PIN_SWITCH("Int Mic"),
54 SOC_DAPM_PIN_SWITCH("Ext Spk"),
55};
56
57static struct snd_soc_jack_pin hs_jack_pins[] = {
58 {
59 .pin = "Headphone",
60 .mask = SND_JACK_HEADPHONE,
61 },
62 {
63 .pin = "Headset Mic",
64 .mask = SND_JACK_MICROPHONE,
65 },
66 {
67 .pin = "Ext Spk",
68 .mask = SND_JACK_LINEOUT,
69 },
70 {
71 .pin = "Int Mic",
72 .mask = SND_JACK_LINEIN,
73 },
74};
75
76static struct snd_soc_jack_gpio hs_jack_gpios[] = {
77 {
78 .name = "hp-gpio",
79 .idx = 0,
80 .report = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
81 .debounce_time = 200,
82 },
83 {
84 .name = "mic-gpio",
85 .idx = 1,
86 .report = SND_JACK_MICROPHONE | SND_JACK_LINEIN,
87 .debounce_time = 200,
88 },
89};
90
91static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime)
92{
93 int ret;
94 struct snd_soc_codec *codec = runtime->codec;
95 struct snd_soc_card *card = runtime->card;
96 struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card);
97 struct snd_soc_jack *jack = &drv->jack;
98
99 card->dapm.idle_bias_off = true;
100
101 ret = snd_soc_dai_set_sysclk(runtime->codec_dai,
102 M98090_REG_SYSTEM_CLOCK,
103 25000000, SND_SOC_CLOCK_IN);
104 if (ret < 0) {
105 dev_err(card->dev, "Can't set codec clock %d\n", ret);
106 return ret;
107 }
108
109 /* Enable jack detection */
110 ret = snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, jack);
111 if (ret)
112 return ret;
113
114 ret = snd_soc_jack_add_pins(jack, ARRAY_SIZE(hs_jack_pins),
115 hs_jack_pins);
116 if (ret)
117 return ret;
118
119 ret = snd_soc_jack_add_gpiods(card->dev->parent, jack,
120 ARRAY_SIZE(hs_jack_gpios),
121 hs_jack_gpios);
122 if (ret)
123 return ret;
124
125 return max98090_mic_detect(codec, jack);
126}
127
128static struct snd_soc_dai_link byt_max98090_dais[] = {
129 {
130 .name = "Baytrail Audio",
131 .stream_name = "Audio",
132 .cpu_dai_name = "baytrail-pcm-audio",
133 .codec_dai_name = "HiFi",
134 .codec_name = "i2c-193C9890:00",
135 .platform_name = "baytrail-pcm-audio",
136 .init = byt_max98090_init,
137 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
138 SND_SOC_DAIFMT_CBS_CFS,
139 },
140};
141
142static struct snd_soc_card byt_max98090_card = {
143 .name = "byt-max98090",
144 .dai_link = byt_max98090_dais,
145 .num_links = ARRAY_SIZE(byt_max98090_dais),
146 .dapm_widgets = byt_max98090_widgets,
147 .num_dapm_widgets = ARRAY_SIZE(byt_max98090_widgets),
148 .dapm_routes = byt_max98090_audio_map,
149 .num_dapm_routes = ARRAY_SIZE(byt_max98090_audio_map),
150 .controls = byt_max98090_controls,
151 .num_controls = ARRAY_SIZE(byt_max98090_controls),
152};
153
154static int byt_max98090_probe(struct platform_device *pdev)
155{
156 int ret_val = 0;
157 struct byt_max98090_private *priv;
158
159 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
160 if (!priv) {
161 dev_err(&pdev->dev, "allocation failed\n");
162 return -ENOMEM;
163 }
164
165 byt_max98090_card.dev = &pdev->dev;
166 snd_soc_card_set_drvdata(&byt_max98090_card, priv);
167 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_max98090_card);
168 if (ret_val) {
169 dev_err(&pdev->dev,
170 "snd_soc_register_card failed %d\n", ret_val);
171 return ret_val;
172 }
173
174 return ret_val;
175}
176
177static int byt_max98090_remove(struct platform_device *pdev)
178{
179 struct snd_soc_card *card = platform_get_drvdata(pdev);
180 struct byt_max98090_private *priv = snd_soc_card_get_drvdata(card);
181
182 snd_soc_jack_free_gpios(&priv->jack, ARRAY_SIZE(hs_jack_gpios),
183 hs_jack_gpios);
184
185 return 0;
186}
187
188static struct platform_driver byt_max98090_driver = {
189 .probe = byt_max98090_probe,
190 .remove = byt_max98090_remove,
191 .driver = {
192 .name = "byt-max98090",
193 .owner = THIS_MODULE,
194 .pm = &snd_soc_pm_ops,
195 },
196};
197module_platform_driver(byt_max98090_driver)
198
199MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
200MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
201MODULE_LICENSE("GPL v2");
202MODULE_ALIAS("platform:byt-max98090");