]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - sound/soc/intel/boards/byt-rt5640.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288
[mirror_ubuntu-focal-kernel.git] / sound / soc / intel / boards / byt-rt5640.c
CommitLineData
2025cf9e 1// SPDX-License-Identifier: GPL-2.0-only
a4b12990
MB
2/*
3 * Intel Baytrail SST RT5640 machine driver
4 * Copyright (c) 2014, Intel Corporation.
a4b12990
MB
5 */
6
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/platform_device.h>
10#include <linux/acpi.h>
11#include <linux/device.h>
f8a770c2 12#include <linux/dmi.h>
a4b12990
MB
13#include <linux/slab.h>
14#include <sound/pcm.h>
15#include <sound/pcm_params.h>
16#include <sound/soc.h>
17#include <sound/jack.h>
e56c72d5 18#include "../../codecs/rt5640.h"
a4b12990 19
e56c72d5 20#include "../common/sst-dsp.h"
a4b12990
MB
21
22static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
23 SND_SOC_DAPM_HP("Headphone", NULL),
24 SND_SOC_DAPM_MIC("Headset Mic", NULL),
25 SND_SOC_DAPM_MIC("Internal Mic", NULL),
26 SND_SOC_DAPM_SPK("Speaker", NULL),
27};
28
29static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
c9a8e3bd 30 {"Headset Mic", NULL, "MICBIAS1"},
a4b12990 31 {"IN2P", NULL, "Headset Mic"},
a4b12990
MB
32 {"Headphone", NULL, "HPOL"},
33 {"Headphone", NULL, "HPOR"},
34 {"Speaker", NULL, "SPOLP"},
35 {"Speaker", NULL, "SPOLN"},
36 {"Speaker", NULL, "SPORP"},
37 {"Speaker", NULL, "SPORN"},
38};
39
f8a770c2
JN
40static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
41 {"DMIC1", NULL, "Internal Mic"},
42};
43
24221dcc
JN
44static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
45 {"DMIC2", NULL, "Internal Mic"},
46};
47
f8a770c2
JN
48static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
49 {"Internal Mic", NULL, "MICBIAS1"},
50 {"IN1P", NULL, "Internal Mic"},
51};
52
53enum {
54 BYT_RT5640_DMIC1_MAP,
24221dcc 55 BYT_RT5640_DMIC2_MAP,
f8a770c2
JN
56 BYT_RT5640_IN1_MAP,
57};
58
a5f0ab05
JN
59#define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
60#define BYT_RT5640_DMIC_EN BIT(16)
61
62static unsigned long byt_rt5640_quirk = BYT_RT5640_DMIC1_MAP |
63 BYT_RT5640_DMIC_EN;
f8a770c2 64
a4b12990
MB
65static const struct snd_kcontrol_new byt_rt5640_controls[] = {
66 SOC_DAPM_PIN_SWITCH("Headphone"),
67 SOC_DAPM_PIN_SWITCH("Headset Mic"),
68 SOC_DAPM_PIN_SWITCH("Internal Mic"),
69 SOC_DAPM_PIN_SWITCH("Speaker"),
70};
71
72static int byt_rt5640_hw_params(struct snd_pcm_substream *substream,
73 struct snd_pcm_hw_params *params)
74{
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct snd_soc_dai *codec_dai = rtd->codec_dai;
77 int ret;
78
79 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
80 params_rate(params) * 256,
81 SND_SOC_CLOCK_IN);
82 if (ret < 0) {
83 dev_err(codec_dai->dev, "can't set codec clock %d\n", ret);
84 return ret;
85 }
86 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
87 params_rate(params) * 64,
88 params_rate(params) * 256);
89 if (ret < 0) {
90 dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
91 return ret;
92 }
93 return 0;
94}
95
f8a770c2
JN
96static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
97{
a5f0ab05 98 byt_rt5640_quirk = (unsigned long)id->driver_data;
f8a770c2
JN
99 return 1;
100}
101
102static const struct dmi_system_id byt_rt5640_quirk_table[] = {
103 {
104 .callback = byt_rt5640_quirk_cb,
105 .matches = {
106 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
107 DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"),
108 },
109 .driver_data = (unsigned long *)BYT_RT5640_IN1_MAP,
110 },
24221dcc
JN
111 {
112 .callback = byt_rt5640_quirk_cb,
113 .matches = {
114 DMI_MATCH(DMI_SYS_VENDOR, "DellInc."),
115 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
116 },
117 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
118 BYT_RT5640_DMIC_EN),
119 },
f8a770c2
JN
120 {}
121};
122
a4b12990
MB
123static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
124{
125 int ret;
d5a41b5d 126 struct snd_soc_component *component = runtime->codec_dai->component;
a4b12990 127 struct snd_soc_card *card = runtime->card;
f8a770c2
JN
128 const struct snd_soc_dapm_route *custom_map;
129 int num_routes;
a4b12990
MB
130
131 card->dapm.idle_bias_off = true;
132
133 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
134 ARRAY_SIZE(byt_rt5640_controls));
135 if (ret) {
136 dev_err(card->dev, "unable to add card controls\n");
137 return ret;
138 }
139
f8a770c2 140 dmi_check_system(byt_rt5640_quirk_table);
a5f0ab05 141 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
f8a770c2
JN
142 case BYT_RT5640_IN1_MAP:
143 custom_map = byt_rt5640_intmic_in1_map;
144 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
145 break;
24221dcc
JN
146 case BYT_RT5640_DMIC2_MAP:
147 custom_map = byt_rt5640_intmic_dmic2_map;
148 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
149 break;
f8a770c2
JN
150 default:
151 custom_map = byt_rt5640_intmic_dmic1_map;
152 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
bb78cdd4 153 }
f8a770c2 154
b93673be 155 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
f8a770c2
JN
156 if (ret)
157 return ret;
158
a5f0ab05 159 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
d5a41b5d 160 ret = rt5640_dmic_enable(component, 0, 0);
a5f0ab05
JN
161 if (ret)
162 return ret;
163 }
164
7a81140b
LPC
165 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
166 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
a4b12990 167
a4b12990
MB
168 return ret;
169}
170
171static struct snd_soc_ops byt_rt5640_ops = {
172 .hw_params = byt_rt5640_hw_params,
173};
174
175static struct snd_soc_dai_link byt_rt5640_dais[] = {
176 {
177 .name = "Baytrail Audio",
178 .stream_name = "Audio",
49fee178 179 .cpu_dai_name = "baytrail-pcm-audio",
a4b12990
MB
180 .codec_dai_name = "rt5640-aif1",
181 .codec_name = "i2c-10EC5640:00",
182 .platform_name = "baytrail-pcm-audio",
183 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
184 SND_SOC_DAIFMT_CBS_CFS,
185 .init = byt_rt5640_init,
a4b12990
MB
186 .ops = &byt_rt5640_ops,
187 },
188};
189
190static struct snd_soc_card byt_rt5640_card = {
191 .name = "byt-rt5640",
54d8697f 192 .owner = THIS_MODULE,
a4b12990
MB
193 .dai_link = byt_rt5640_dais,
194 .num_links = ARRAY_SIZE(byt_rt5640_dais),
195 .dapm_widgets = byt_rt5640_widgets,
196 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
197 .dapm_routes = byt_rt5640_audio_map,
198 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
c47a39a6 199 .fully_routed = true,
a4b12990
MB
200};
201
202static int byt_rt5640_probe(struct platform_device *pdev)
203{
204 struct snd_soc_card *card = &byt_rt5640_card;
a4b12990
MB
205
206 card->dev = &pdev->dev;
8eb776ab 207 return devm_snd_soc_register_card(&pdev->dev, card);
a4b12990
MB
208}
209
210static struct platform_driver byt_rt5640_audio = {
211 .probe = byt_rt5640_probe,
a4b12990
MB
212 .driver = {
213 .name = "byt-rt5640",
4af72f4e 214 .pm = &snd_soc_pm_ops,
a4b12990
MB
215 },
216};
217module_platform_driver(byt_rt5640_audio)
218
219MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
220MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
221MODULE_LICENSE("GPL v2");
222MODULE_ALIAS("platform:byt-rt5640");