1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com>
5 // Based on smdk6410_wm8987.c
6 // Copyright 2007 Wolfson Microelectronics PLC. - linux@wolfsonmicro.com
7 // Graeme Gregory - graeme.gregory@wolfsonmicro.com
9 #include <linux/gpio/consumer.h>
10 #include <linux/module.h>
12 #include <sound/soc.h>
13 #include <sound/jack.h>
16 #include "../codecs/wm8750.h"
19 * WM8987 is register compatible with WM8750, so using that as base driver.
22 static struct snd_soc_card snd_soc_smartq
;
24 static int smartq_hifi_hw_params(struct snd_pcm_substream
*substream
,
25 struct snd_pcm_hw_params
*params
)
27 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
28 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
29 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
33 switch (params_rate(params
)) {
49 /* Use PCLK for I2S signal generation */
50 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SAMSUNG_I2S_RCLKSRC_0
,
55 /* Gate the RCLK output on PAD */
56 ret
= snd_soc_dai_set_sysclk(cpu_dai
, SAMSUNG_I2S_CDCLK
,
61 /* set the codec system clock for DAC and ADC */
62 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
71 * SmartQ WM8987 HiFi DAI operations.
73 static struct snd_soc_ops smartq_hifi_ops
= {
74 .hw_params
= smartq_hifi_hw_params
,
77 static struct snd_soc_jack smartq_jack
;
79 static struct snd_soc_jack_pin smartq_jack_pins
[] = {
80 /* Disable speaker when headphone is plugged in */
82 .pin
= "Internal Speaker",
83 .mask
= SND_JACK_HEADPHONE
,
87 static struct snd_soc_jack_gpio smartq_jack_gpios
[] = {
90 .name
= "headphone detect",
91 .report
= SND_JACK_HEADPHONE
,
96 static const struct snd_kcontrol_new wm8987_smartq_controls
[] = {
97 SOC_DAPM_PIN_SWITCH("Internal Speaker"),
98 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
99 SOC_DAPM_PIN_SWITCH("Internal Mic"),
102 static int smartq_speaker_event(struct snd_soc_dapm_widget
*w
,
103 struct snd_kcontrol
*k
,
106 struct gpio_desc
*gpio
= snd_soc_card_get_drvdata(&snd_soc_smartq
);
108 gpiod_set_value(gpio
, SND_SOC_DAPM_EVENT_OFF(event
));
113 static const struct snd_soc_dapm_widget wm8987_dapm_widgets
[] = {
114 SND_SOC_DAPM_SPK("Internal Speaker", smartq_speaker_event
),
115 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
116 SND_SOC_DAPM_MIC("Internal Mic", NULL
),
119 static const struct snd_soc_dapm_route audio_map
[] = {
120 {"Headphone Jack", NULL
, "LOUT2"},
121 {"Headphone Jack", NULL
, "ROUT2"},
123 {"Internal Speaker", NULL
, "LOUT2"},
124 {"Internal Speaker", NULL
, "ROUT2"},
126 {"Mic Bias", NULL
, "Internal Mic"},
127 {"LINPUT2", NULL
, "Mic Bias"},
130 static int smartq_wm8987_init(struct snd_soc_pcm_runtime
*rtd
)
132 struct snd_soc_dapm_context
*dapm
= &rtd
->card
->dapm
;
135 /* set endpoints to not connected */
136 snd_soc_dapm_nc_pin(dapm
, "LINPUT1");
137 snd_soc_dapm_nc_pin(dapm
, "RINPUT1");
138 snd_soc_dapm_nc_pin(dapm
, "OUT3");
139 snd_soc_dapm_nc_pin(dapm
, "ROUT1");
141 /* Headphone jack detection */
142 err
= snd_soc_card_jack_new(rtd
->card
, "Headphone Jack",
143 SND_JACK_HEADPHONE
, &smartq_jack
,
145 ARRAY_SIZE(smartq_jack_pins
));
149 err
= snd_soc_jack_add_gpios(&smartq_jack
,
150 ARRAY_SIZE(smartq_jack_gpios
),
156 SND_SOC_DAILINK_DEFS(wm8987
,
157 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
158 DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-0x1a", "wm8750-hifi")),
159 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
161 static struct snd_soc_dai_link smartq_dai
[] = {
164 .stream_name
= "SmartQ Hi-Fi",
165 .init
= smartq_wm8987_init
,
166 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
167 SND_SOC_DAIFMT_CBS_CFS
,
168 .ops
= &smartq_hifi_ops
,
169 SND_SOC_DAILINK_REG(wm8987
),
173 static struct snd_soc_card snd_soc_smartq
= {
175 .owner
= THIS_MODULE
,
176 .dai_link
= smartq_dai
,
177 .num_links
= ARRAY_SIZE(smartq_dai
),
179 .dapm_widgets
= wm8987_dapm_widgets
,
180 .num_dapm_widgets
= ARRAY_SIZE(wm8987_dapm_widgets
),
181 .dapm_routes
= audio_map
,
182 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
183 .controls
= wm8987_smartq_controls
,
184 .num_controls
= ARRAY_SIZE(wm8987_smartq_controls
),
187 static int smartq_probe(struct platform_device
*pdev
)
189 struct gpio_desc
*gpio
;
192 platform_set_drvdata(pdev
, &snd_soc_smartq
);
194 /* Initialise GPIOs used by amplifiers */
195 gpio
= devm_gpiod_get(&pdev
->dev
, "amplifiers shutdown",
198 dev_err(&pdev
->dev
, "Failed to register GPK12\n");
202 snd_soc_card_set_drvdata(&snd_soc_smartq
, gpio
);
204 ret
= devm_snd_soc_register_card(&pdev
->dev
, &snd_soc_smartq
);
206 dev_err(&pdev
->dev
, "Failed to register card\n");
212 static struct platform_driver smartq_driver
= {
214 .name
= "smartq-audio",
216 .probe
= smartq_probe
,
219 module_platform_driver(smartq_driver
);
221 /* Module information */
222 MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");
223 MODULE_DESCRIPTION("ALSA SoC SmartQ WM8987");
224 MODULE_LICENSE("GPL");