2 * Intel Baytrail SST RT5640 machine driver
3 * Copyright (c) 2014, Intel Corporation.
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.
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
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/dmi.h>
21 #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"
28 #include "../common/sst-dsp.h"
30 static 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
),
37 static const struct snd_soc_dapm_route byt_rt5640_audio_map
[] = {
38 {"Headset Mic", NULL
, "MICBIAS1"},
39 {"IN2P", NULL
, "Headset Mic"},
40 {"Headphone", NULL
, "HPOL"},
41 {"Headphone", NULL
, "HPOR"},
42 {"Speaker", NULL
, "SPOLP"},
43 {"Speaker", NULL
, "SPOLN"},
44 {"Speaker", NULL
, "SPORP"},
45 {"Speaker", NULL
, "SPORN"},
48 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map
[] = {
49 {"DMIC1", NULL
, "Internal Mic"},
52 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map
[] = {
53 {"DMIC2", NULL
, "Internal Mic"},
56 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map
[] = {
57 {"Internal Mic", NULL
, "MICBIAS1"},
58 {"IN1P", NULL
, "Internal Mic"},
67 #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
68 #define BYT_RT5640_DMIC_EN BIT(16)
70 static unsigned long byt_rt5640_quirk
= BYT_RT5640_DMIC1_MAP
|
73 static 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"),
80 static int byt_rt5640_hw_params(struct snd_pcm_substream
*substream
,
81 struct snd_pcm_hw_params
*params
)
83 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
84 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
87 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5640_SCLK_S_PLL1
,
88 params_rate(params
) * 256,
91 dev_err(codec_dai
->dev
, "can't set codec clock %d\n", ret
);
94 ret
= snd_soc_dai_set_pll(codec_dai
, 0, RT5640_PLL1_S_BCLK1
,
95 params_rate(params
) * 64,
96 params_rate(params
) * 256);
98 dev_err(codec_dai
->dev
, "can't set codec pll: %d\n", ret
);
104 static int byt_rt5640_quirk_cb(const struct dmi_system_id
*id
)
106 byt_rt5640_quirk
= (unsigned long)id
->driver_data
;
110 static const struct dmi_system_id byt_rt5640_quirk_table
[] = {
112 .callback
= byt_rt5640_quirk_cb
,
114 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK COMPUTER INC."),
115 DMI_MATCH(DMI_PRODUCT_NAME
, "T100TA"),
117 .driver_data
= (unsigned long *)BYT_RT5640_IN1_MAP
,
120 .callback
= byt_rt5640_quirk_cb
,
122 DMI_MATCH(DMI_SYS_VENDOR
, "DellInc."),
123 DMI_MATCH(DMI_PRODUCT_NAME
, "Venue 8 Pro 5830"),
125 .driver_data
= (unsigned long *)(BYT_RT5640_DMIC2_MAP
|
131 static int byt_rt5640_init(struct snd_soc_pcm_runtime
*runtime
)
134 struct snd_soc_codec
*codec
= runtime
->codec
;
135 struct snd_soc_card
*card
= runtime
->card
;
136 const struct snd_soc_dapm_route
*custom_map
;
139 card
->dapm
.idle_bias_off
= true;
141 ret
= snd_soc_add_card_controls(card
, byt_rt5640_controls
,
142 ARRAY_SIZE(byt_rt5640_controls
));
144 dev_err(card
->dev
, "unable to add card controls\n");
148 dmi_check_system(byt_rt5640_quirk_table
);
149 switch (BYT_RT5640_MAP(byt_rt5640_quirk
)) {
150 case BYT_RT5640_IN1_MAP
:
151 custom_map
= byt_rt5640_intmic_in1_map
;
152 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_in1_map
);
154 case BYT_RT5640_DMIC2_MAP
:
155 custom_map
= byt_rt5640_intmic_dmic2_map
;
156 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_dmic2_map
);
159 custom_map
= byt_rt5640_intmic_dmic1_map
;
160 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_dmic1_map
);
163 ret
= snd_soc_dapm_add_routes(&card
->dapm
, custom_map
, num_routes
);
167 if (byt_rt5640_quirk
& BYT_RT5640_DMIC_EN
) {
168 ret
= rt5640_dmic_enable(codec
, 0, 0);
173 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Headphone");
174 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Speaker");
179 static struct snd_soc_ops byt_rt5640_ops
= {
180 .hw_params
= byt_rt5640_hw_params
,
183 static struct snd_soc_dai_link byt_rt5640_dais
[] = {
185 .name
= "Baytrail Audio",
186 .stream_name
= "Audio",
187 .cpu_dai_name
= "baytrail-pcm-audio",
188 .codec_dai_name
= "rt5640-aif1",
189 .codec_name
= "i2c-10EC5640:00",
190 .platform_name
= "baytrail-pcm-audio",
191 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
192 SND_SOC_DAIFMT_CBS_CFS
,
193 .init
= byt_rt5640_init
,
194 .ops
= &byt_rt5640_ops
,
198 static struct snd_soc_card byt_rt5640_card
= {
199 .name
= "byt-rt5640",
200 .owner
= THIS_MODULE
,
201 .dai_link
= byt_rt5640_dais
,
202 .num_links
= ARRAY_SIZE(byt_rt5640_dais
),
203 .dapm_widgets
= byt_rt5640_widgets
,
204 .num_dapm_widgets
= ARRAY_SIZE(byt_rt5640_widgets
),
205 .dapm_routes
= byt_rt5640_audio_map
,
206 .num_dapm_routes
= ARRAY_SIZE(byt_rt5640_audio_map
),
207 .fully_routed
= true,
210 static int byt_rt5640_probe(struct platform_device
*pdev
)
212 struct snd_soc_card
*card
= &byt_rt5640_card
;
214 card
->dev
= &pdev
->dev
;
215 return devm_snd_soc_register_card(&pdev
->dev
, card
);
218 static struct platform_driver byt_rt5640_audio
= {
219 .probe
= byt_rt5640_probe
,
221 .name
= "byt-rt5640",
222 .pm
= &snd_soc_pm_ops
,
225 module_platform_driver(byt_rt5640_audio
)
227 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
228 MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
229 MODULE_LICENSE("GPL v2");
230 MODULE_ALIAS("platform:byt-rt5640");