1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Baytrail SST MAX98090 machine driver
4 * Copyright (c) 2014, Intel Corporation.
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>
12 #include <linux/gpio.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/slab.h>
15 #include <sound/pcm.h>
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
18 #include <sound/jack.h>
19 #include "../../codecs/max98090.h"
21 struct byt_max98090_private
{
22 struct snd_soc_jack jack
;
25 static const struct snd_soc_dapm_widget byt_max98090_widgets
[] = {
26 SND_SOC_DAPM_HP("Headphone", NULL
),
27 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
28 SND_SOC_DAPM_MIC("Int Mic", NULL
),
29 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
32 static const struct snd_soc_dapm_route byt_max98090_audio_map
[] = {
33 {"IN34", NULL
, "Headset Mic"},
34 {"Headset Mic", NULL
, "MICBIAS"},
35 {"DMICL", NULL
, "Int Mic"},
36 {"Headphone", NULL
, "HPL"},
37 {"Headphone", NULL
, "HPR"},
38 {"Ext Spk", NULL
, "SPKL"},
39 {"Ext Spk", NULL
, "SPKR"},
42 static const struct snd_kcontrol_new byt_max98090_controls
[] = {
43 SOC_DAPM_PIN_SWITCH("Headphone"),
44 SOC_DAPM_PIN_SWITCH("Headset Mic"),
45 SOC_DAPM_PIN_SWITCH("Int Mic"),
46 SOC_DAPM_PIN_SWITCH("Ext Spk"),
49 static struct snd_soc_jack_pin hs_jack_pins
[] = {
52 .mask
= SND_JACK_HEADPHONE
,
56 .mask
= SND_JACK_MICROPHONE
,
60 static struct snd_soc_jack_gpio hs_jack_gpios
[] = {
63 .report
= SND_JACK_HEADPHONE
| SND_JACK_LINEOUT
,
69 .report
= SND_JACK_MICROPHONE
,
74 static const struct acpi_gpio_params hp_gpios
= { 0, 0, false };
75 static const struct acpi_gpio_params mic_gpios
= { 1, 0, false };
77 static const struct acpi_gpio_mapping acpi_byt_max98090_gpios
[] = {
78 { "hp-gpios", &hp_gpios
, 1 },
79 { "mic-gpios", &mic_gpios
, 1 },
83 static int byt_max98090_init(struct snd_soc_pcm_runtime
*runtime
)
86 struct snd_soc_card
*card
= runtime
->card
;
87 struct byt_max98090_private
*drv
= snd_soc_card_get_drvdata(card
);
88 struct snd_soc_jack
*jack
= &drv
->jack
;
90 card
->dapm
.idle_bias_off
= true;
92 ret
= snd_soc_dai_set_sysclk(runtime
->codec_dai
,
93 M98090_REG_SYSTEM_CLOCK
,
94 25000000, SND_SOC_CLOCK_IN
);
96 dev_err(card
->dev
, "Can't set codec clock %d\n", ret
);
100 /* Enable jack detection */
101 ret
= snd_soc_card_jack_new(runtime
->card
, "Headset",
102 SND_JACK_LINEOUT
| SND_JACK_HEADSET
, jack
,
103 hs_jack_pins
, ARRAY_SIZE(hs_jack_pins
));
107 return snd_soc_jack_add_gpiods(card
->dev
->parent
, jack
,
108 ARRAY_SIZE(hs_jack_gpios
),
112 SND_SOC_DAILINK_DEFS(baytrail
,
113 DAILINK_COMP_ARRAY(COMP_CPU("baytrail-pcm-audio")),
114 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-193C9890:00", "HiFi")),
115 DAILINK_COMP_ARRAY(COMP_PLATFORM("baytrail-pcm-audio")));
117 static struct snd_soc_dai_link byt_max98090_dais
[] = {
119 .name
= "Baytrail Audio",
120 .stream_name
= "Audio",
121 .init
= byt_max98090_init
,
122 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
123 SND_SOC_DAIFMT_CBS_CFS
,
124 SND_SOC_DAILINK_REG(baytrail
),
128 static struct snd_soc_card byt_max98090_card
= {
129 .name
= "byt-max98090",
130 .owner
= THIS_MODULE
,
131 .dai_link
= byt_max98090_dais
,
132 .num_links
= ARRAY_SIZE(byt_max98090_dais
),
133 .dapm_widgets
= byt_max98090_widgets
,
134 .num_dapm_widgets
= ARRAY_SIZE(byt_max98090_widgets
),
135 .dapm_routes
= byt_max98090_audio_map
,
136 .num_dapm_routes
= ARRAY_SIZE(byt_max98090_audio_map
),
137 .controls
= byt_max98090_controls
,
138 .num_controls
= ARRAY_SIZE(byt_max98090_controls
),
139 .fully_routed
= true,
142 static int byt_max98090_probe(struct platform_device
*pdev
)
144 struct device
*dev
= &pdev
->dev
;
145 struct byt_max98090_private
*priv
;
148 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
150 dev_err(&pdev
->dev
, "allocation failed\n");
154 ret_val
= devm_acpi_dev_add_driver_gpios(dev
->parent
, acpi_byt_max98090_gpios
);
156 dev_dbg(dev
, "Unable to add GPIO mapping table\n");
158 byt_max98090_card
.dev
= &pdev
->dev
;
159 snd_soc_card_set_drvdata(&byt_max98090_card
, priv
);
160 ret_val
= devm_snd_soc_register_card(&pdev
->dev
, &byt_max98090_card
);
163 "snd_soc_register_card failed %d\n", ret_val
);
170 static struct platform_driver byt_max98090_driver
= {
171 .probe
= byt_max98090_probe
,
173 .name
= "byt-max98090",
174 .pm
= &snd_soc_pm_ops
,
177 module_platform_driver(byt_max98090_driver
)
179 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver");
180 MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula");
181 MODULE_LICENSE("GPL v2");
182 MODULE_ALIAS("platform:byt-max98090");