blob: e03abdf21c1bc3f4dbff62f4cd46d80327dbadd1 [file] [log] [blame]
Mark Browna4b12992014-03-12 23:04:35 +00001/*
2 * Intel Baytrail SST RT5640 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>
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +030020#include <linux/dmi.h>
Mark Browna4b12992014-03-12 23:04:35 +000021#include <linux/slab.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
25#include <sound/jack.h>
26#include "../codecs/rt5640.h"
27
28#include "sst-dsp.h"
29
30static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
31 SND_SOC_DAPM_HP("Headphone", NULL),
32 SND_SOC_DAPM_MIC("Headset Mic", NULL),
33 SND_SOC_DAPM_MIC("Internal Mic", NULL),
34 SND_SOC_DAPM_SPK("Speaker", NULL),
35};
36
37static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Jarkko Nikulac9a8e3b2014-06-09 14:39:06 +030038 {"Headset Mic", NULL, "MICBIAS1"},
Mark Browna4b12992014-03-12 23:04:35 +000039 {"IN2P", NULL, "Headset Mic"},
Mark Browna4b12992014-03-12 23:04:35 +000040 {"Headphone", NULL, "HPOL"},
41 {"Headphone", NULL, "HPOR"},
42 {"Speaker", NULL, "SPOLP"},
43 {"Speaker", NULL, "SPOLN"},
44 {"Speaker", NULL, "SPORP"},
45 {"Speaker", NULL, "SPORN"},
46};
47
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +030048static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
49 {"DMIC1", NULL, "Internal Mic"},
50};
51
Jarkko Nikula24221dc2014-10-02 13:29:08 +030052static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
53 {"DMIC2", NULL, "Internal Mic"},
54};
55
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +030056static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
57 {"Internal Mic", NULL, "MICBIAS1"},
58 {"IN1P", NULL, "Internal Mic"},
59};
60
61enum {
62 BYT_RT5640_DMIC1_MAP,
Jarkko Nikula24221dc2014-10-02 13:29:08 +030063 BYT_RT5640_DMIC2_MAP,
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +030064 BYT_RT5640_IN1_MAP,
65};
66
Jarkko Nikulaa5f0ab02014-10-01 15:08:15 +030067#define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
68#define BYT_RT5640_DMIC_EN BIT(16)
69
70static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP |
71 BYT_RT5640_DMIC_EN;
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +030072
Mark Browna4b12992014-03-12 23:04:35 +000073static const struct snd_kcontrol_new byt_rt5640_controls[] = {
74 SOC_DAPM_PIN_SWITCH("Headphone"),
75 SOC_DAPM_PIN_SWITCH("Headset Mic"),
76 SOC_DAPM_PIN_SWITCH("Internal Mic"),
77 SOC_DAPM_PIN_SWITCH("Speaker"),
78};
79
80static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
81 struct snd_pcm_hw_params *params)
82{
83 struct snd_soc_pcm_runtime *rtd = substream->private_data;
84 struct snd_soc_dai *codec_dai = rtd->codec_dai;
85 int ret;
86
87 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
88 params_rate(params) * 256,
89 SND_SOC_CLOCK_IN);
90 if (ret < 0) {
91 dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
92 return ret;
93 }
94 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
95 params_rate(params) * 64,
96 params_rate(params) * 256);
97 if (ret < 0) {
98 dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
99 return ret;
100 }
101 return 0;
102}
103
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300104static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
105{
Jarkko Nikulaa5f0ab02014-10-01 15:08:15 +0300106 byt_rt5640_quirk = (unsigned long)id->driver_data;
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300107 return 1;
108}
109
110static const struct dmi_system_id byt_rt5640_quirk_table[] = {
111 {
112 .callback = byt_rt5640_quirk_cb,
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
115 DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"),
116 },
117 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
118 },
Jarkko Nikula24221dc2014-10-02 13:29:08 +0300119 {
120 .callback = byt_rt5640_quirk_cb,
121 .matches = {
122 DMI_MATCH(DMI_SYS_VENDOR, "DellInc."),
123 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
124 },
125 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
126 BYT_RT5640_DMIC_EN),
127 },
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300128 {}
129};
130
Mark Browna4b12992014-03-12 23:04:35 +0000131static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
132{
133 int ret;
134 struct snd_soc_codec *codec = runtime->codec;
135 struct snd_soc_dapm_context *dapm = &codec->dapm;
136 struct snd_soc_card *card = runtime->card;
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300137 const struct snd_soc_dapm_route *custom_map;
138 int num_routes;
Mark Browna4b12992014-03-12 23:04:35 +0000139
140 card->dapm.idle_bias_off = true;
141
142 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
143 ARRAY_SIZE(byt_rt5640_controls));
144 if (ret) {
145 dev_err(card->dev, "unable to add card controls\n");
146 return ret;
147 }
148
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300149 dmi_check_system(byt_rt5640_quirk_table);
Jarkko Nikulaa5f0ab02014-10-01 15:08:15 +0300150 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300151 case BYT_RT5640_IN1_MAP:
152 custom_map = byt_rt5640_intmic_in1_map;
153 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
154 break;
Jarkko Nikula24221dc2014-10-02 13:29:08 +0300155 case BYT_RT5640_DMIC2_MAP:
156 custom_map = byt_rt5640_intmic_dmic2_map;
157 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
158 break;
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300159 default:
160 custom_map = byt_rt5640_intmic_dmic1_map;
161 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
Fengguang Wubb78cdd2014-10-04 19:09:33 +0100162 }
Jarkko Nikulaf8a770c2014-09-29 16:58:16 +0300163
164 ret = snd_soc_dapm_add_routes(dapm, custom_map, num_routes);
165 if (ret)
166 return ret;
167
Jarkko Nikulaa5f0ab02014-10-01 15:08:15 +0300168 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
169 ret = rt5640_dmic_enable(codec, 0, 0);
170 if (ret)
171 return ret;
172 }
173
Mark Browna4b12992014-03-12 23:04:35 +0000174 snd_soc_dapm_ignore_suspend(dapm, "HPOL");
175 snd_soc_dapm_ignore_suspend(dapm, "HPOR");
176
177 snd_soc_dapm_ignore_suspend(dapm, "SPOLP");
178 snd_soc_dapm_ignore_suspend(dapm, "SPOLN");
179 snd_soc_dapm_ignore_suspend(dapm, "SPORP");
180 snd_soc_dapm_ignore_suspend(dapm, "SPORN");
181
Mark Browna4b12992014-03-12 23:04:35 +0000182 return ret;
183}
184
185static struct snd_soc_ops byt_rt5640_ops = {
186 .hw_params = byt_rt5640_hw_params,
187};
188
189static struct snd_soc_dai_link byt_rt5640_dais[] = {
190 {
191 .name = "Baytrail Audio",
192 .stream_name = "Audio",
Liam Girdwood49fee172014-05-14 17:20:54 +0300193 .cpu_dai_name = "baytrail-pcm-audio",
Mark Browna4b12992014-03-12 23:04:35 +0000194 .codec_dai_name = "rt5640-aif1",
195 .codec_name = "i2c-10EC5640:00",
196 .platform_name = "baytrail-pcm-audio",
197 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
198 SND_SOC_DAIFMT_CBS_CFS,
199 .init = byt_rt5640_init,
Mark Browna4b12992014-03-12 23:04:35 +0000200 .ops = &byt_rt5640_ops,
201 },
202};
203
204static struct snd_soc_card byt_rt5640_card = {
205 .name = "byt-rt5640",
206 .dai_link = byt_rt5640_dais,
207 .num_links = ARRAY_SIZE(byt_rt5640_dais),
208 .dapm_widgets = byt_rt5640_widgets,
209 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
210 .dapm_routes = byt_rt5640_audio_map,
211 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Jarkko Nikulac47a39a2014-10-02 13:29:09 +0300212 .fully_routed = true,
Mark Browna4b12992014-03-12 23:04:35 +0000213};
214
215static int byt_rt5640_probe(struct platform_device *pdev)
216{
217 struct snd_soc_card *card = &byt_rt5640_card;
Mark Browna4b12992014-03-12 23:04:35 +0000218
219 card->dev = &pdev->dev;
Jarkko Nikula8eb776a2014-05-28 12:35:39 +0300220 return devm_snd_soc_register_card(&pdev->dev, card);
Mark Browna4b12992014-03-12 23:04:35 +0000221}
222
223static struct platform_driver byt_rt5640_audio = {
224 .probe = byt_rt5640_probe,
Mark Browna4b12992014-03-12 23:04:35 +0000225 .driver = {
226 .name = "byt-rt5640",
227 .owner = THIS_MODULE,
Jarkko Nikula4af72f42014-05-26 16:56:33 +0300228 .pm = &snd_soc_pm_ops,
Mark Browna4b12992014-03-12 23:04:35 +0000229 },
230};
231module_platform_driver(byt_rt5640_audio)
232
233MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
234MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
235MODULE_LICENSE("GPL v2");
236MODULE_ALIAS("platform:byt-rt5640");