treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / sound / soc / samsung / smartq_wm8987.c
blobfab3db9fdb98f28df797090a618cbc55bd82dd6d
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Copyright 2010 Maurus Cuelenaere <mcuelenaere@gmail.com>
4 //
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>
15 #include "i2s.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;
30 unsigned int clk = 0;
31 int ret;
33 switch (params_rate(params)) {
34 case 8000:
35 case 16000:
36 case 32000:
37 case 48000:
38 case 96000:
39 clk = 12288000;
40 break;
41 case 11025:
42 case 22050:
43 case 44100:
44 case 88200:
45 clk = 11289600;
46 break;
49 /* Use PCLK for I2S signal generation */
50 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
51 0, SND_SOC_CLOCK_IN);
52 if (ret < 0)
53 return ret;
55 /* Gate the RCLK output on PAD */
56 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
57 0, SND_SOC_CLOCK_IN);
58 if (ret < 0)
59 return ret;
61 /* set the codec system clock for DAC and ADC */
62 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
63 SND_SOC_CLOCK_IN);
64 if (ret < 0)
65 return ret;
67 return 0;
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[] = {
89 .gpio = -1,
90 .name = "headphone detect",
91 .report = SND_JACK_HEADPHONE,
92 .debounce_time = 200,
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,
104 int event)
106 struct gpio_desc *gpio = snd_soc_card_get_drvdata(&snd_soc_smartq);
108 gpiod_set_value(gpio, SND_SOC_DAPM_EVENT_OFF(event));
110 return 0;
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;
133 int err = 0;
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,
144 smartq_jack_pins,
145 ARRAY_SIZE(smartq_jack_pins));
146 if (err)
147 return err;
149 err = snd_soc_jack_add_gpios(&smartq_jack,
150 ARRAY_SIZE(smartq_jack_gpios),
151 smartq_jack_gpios);
153 return err;
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[] = {
163 .name = "wm8987",
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 = {
174 .name = "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;
190 int ret;
192 platform_set_drvdata(pdev, &snd_soc_smartq);
194 /* Initialise GPIOs used by amplifiers */
195 gpio = devm_gpiod_get(&pdev->dev, "amplifiers shutdown",
196 GPIOD_OUT_HIGH);
197 if (IS_ERR(gpio)) {
198 dev_err(&pdev->dev, "Failed to register GPK12\n");
199 ret = PTR_ERR(gpio);
200 goto out;
202 snd_soc_card_set_drvdata(&snd_soc_smartq, gpio);
204 ret = devm_snd_soc_register_card(&pdev->dev, &snd_soc_smartq);
205 if (ret)
206 dev_err(&pdev->dev, "Failed to register card\n");
208 out:
209 return ret;
212 static struct platform_driver smartq_driver = {
213 .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");