12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2459dc352SJanusz Krzysztofik /*
3459dc352SJanusz Krzysztofik * cx20442.c -- CX20442 ALSA Soc Audio driver
4459dc352SJanusz Krzysztofik *
5459dc352SJanusz Krzysztofik * Copyright 2009 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
6459dc352SJanusz Krzysztofik *
7459dc352SJanusz Krzysztofik * Initially based on sound/soc/codecs/wm8400.c
8459dc352SJanusz Krzysztofik * Copyright 2008, 2009 Wolfson Microelectronics PLC.
9459dc352SJanusz Krzysztofik * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10459dc352SJanusz Krzysztofik */
11459dc352SJanusz Krzysztofik
12ad120daeSJanusz Krzysztofik #include <linux/tty.h>
135a0e3ad6STejun Heo #include <linux/slab.h>
14da155d5bSPaul Gortmaker #include <linux/module.h>
15f75a8ff6SJanusz Krzysztofik #include <linux/regulator/consumer.h>
16ad120daeSJanusz Krzysztofik
17459dc352SJanusz Krzysztofik #include <sound/core.h>
18459dc352SJanusz Krzysztofik #include <sound/initval.h>
19ce6120ccSLiam Girdwood #include <sound/soc.h>
20459dc352SJanusz Krzysztofik
21459dc352SJanusz Krzysztofik #include "cx20442.h"
22459dc352SJanusz Krzysztofik
23459dc352SJanusz Krzysztofik
24459dc352SJanusz Krzysztofik struct cx20442_priv {
25fac3f5e2SKuninori Morimoto struct tty_struct *tty;
26f75a8ff6SJanusz Krzysztofik struct regulator *por;
273c89724eSKuninori Morimoto u8 reg_cache;
28459dc352SJanusz Krzysztofik };
29459dc352SJanusz Krzysztofik
30459dc352SJanusz Krzysztofik #define CX20442_PM 0x0
31459dc352SJanusz Krzysztofik
32459dc352SJanusz Krzysztofik #define CX20442_TELIN 0
33459dc352SJanusz Krzysztofik #define CX20442_TELOUT 1
34459dc352SJanusz Krzysztofik #define CX20442_MIC 2
35459dc352SJanusz Krzysztofik #define CX20442_SPKOUT 3
36459dc352SJanusz Krzysztofik #define CX20442_AGC 4
37459dc352SJanusz Krzysztofik
38459dc352SJanusz Krzysztofik static const struct snd_soc_dapm_widget cx20442_dapm_widgets[] = {
39459dc352SJanusz Krzysztofik SND_SOC_DAPM_OUTPUT("TELOUT"),
40459dc352SJanusz Krzysztofik SND_SOC_DAPM_OUTPUT("SPKOUT"),
41459dc352SJanusz Krzysztofik SND_SOC_DAPM_OUTPUT("AGCOUT"),
42459dc352SJanusz Krzysztofik
43459dc352SJanusz Krzysztofik SND_SOC_DAPM_MIXER("SPKOUT Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
44459dc352SJanusz Krzysztofik
45459dc352SJanusz Krzysztofik SND_SOC_DAPM_PGA("TELOUT Amp", CX20442_PM, CX20442_TELOUT, 0, NULL, 0),
46459dc352SJanusz Krzysztofik SND_SOC_DAPM_PGA("SPKOUT Amp", CX20442_PM, CX20442_SPKOUT, 0, NULL, 0),
47459dc352SJanusz Krzysztofik SND_SOC_DAPM_PGA("SPKOUT AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0),
48459dc352SJanusz Krzysztofik
49459dc352SJanusz Krzysztofik SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
50459dc352SJanusz Krzysztofik SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
51459dc352SJanusz Krzysztofik
52459dc352SJanusz Krzysztofik SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
53459dc352SJanusz Krzysztofik
54459dc352SJanusz Krzysztofik SND_SOC_DAPM_MICBIAS("TELIN Bias", CX20442_PM, CX20442_TELIN, 0),
55459dc352SJanusz Krzysztofik SND_SOC_DAPM_MICBIAS("MIC Bias", CX20442_PM, CX20442_MIC, 0),
56459dc352SJanusz Krzysztofik
57459dc352SJanusz Krzysztofik SND_SOC_DAPM_PGA("MIC AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0),
58459dc352SJanusz Krzysztofik
59459dc352SJanusz Krzysztofik SND_SOC_DAPM_INPUT("TELIN"),
60459dc352SJanusz Krzysztofik SND_SOC_DAPM_INPUT("MIC"),
61459dc352SJanusz Krzysztofik SND_SOC_DAPM_INPUT("AGCIN"),
62459dc352SJanusz Krzysztofik };
63459dc352SJanusz Krzysztofik
64459dc352SJanusz Krzysztofik static const struct snd_soc_dapm_route cx20442_audio_map[] = {
65459dc352SJanusz Krzysztofik {"TELOUT", NULL, "TELOUT Amp"},
66459dc352SJanusz Krzysztofik
67459dc352SJanusz Krzysztofik {"SPKOUT", NULL, "SPKOUT Mixer"},
68459dc352SJanusz Krzysztofik {"SPKOUT Mixer", NULL, "SPKOUT Amp"},
69459dc352SJanusz Krzysztofik
70459dc352SJanusz Krzysztofik {"TELOUT Amp", NULL, "DAC"},
71459dc352SJanusz Krzysztofik {"SPKOUT Amp", NULL, "DAC"},
72459dc352SJanusz Krzysztofik
73459dc352SJanusz Krzysztofik {"SPKOUT Mixer", NULL, "SPKOUT AGC"},
74459dc352SJanusz Krzysztofik {"SPKOUT AGC", NULL, "AGCIN"},
75459dc352SJanusz Krzysztofik
76459dc352SJanusz Krzysztofik {"AGCOUT", NULL, "MIC AGC"},
77459dc352SJanusz Krzysztofik {"MIC AGC", NULL, "MIC"},
78459dc352SJanusz Krzysztofik
79459dc352SJanusz Krzysztofik {"MIC Bias", NULL, "MIC"},
80459dc352SJanusz Krzysztofik {"Input Mixer", NULL, "MIC Bias"},
81459dc352SJanusz Krzysztofik
82459dc352SJanusz Krzysztofik {"TELIN Bias", NULL, "TELIN"},
83459dc352SJanusz Krzysztofik {"Input Mixer", NULL, "TELIN Bias"},
84459dc352SJanusz Krzysztofik
85459dc352SJanusz Krzysztofik {"ADC", NULL, "Input Mixer"},
86459dc352SJanusz Krzysztofik };
87459dc352SJanusz Krzysztofik
cx20442_read_reg_cache(struct snd_soc_component * component,unsigned int reg)88d0fdfe34SKuninori Morimoto static unsigned int cx20442_read_reg_cache(struct snd_soc_component *component,
893c89724eSKuninori Morimoto unsigned int reg)
903c89724eSKuninori Morimoto {
91d0fdfe34SKuninori Morimoto struct cx20442_priv *cx20442 = snd_soc_component_get_drvdata(component);
923c89724eSKuninori Morimoto
933c89724eSKuninori Morimoto if (reg >= 1)
943c89724eSKuninori Morimoto return -EINVAL;
953c89724eSKuninori Morimoto
963c89724eSKuninori Morimoto return cx20442->reg_cache;
973c89724eSKuninori Morimoto }
983c89724eSKuninori Morimoto
99459dc352SJanusz Krzysztofik enum v253_vls {
100459dc352SJanusz Krzysztofik V253_VLS_NONE = 0,
101459dc352SJanusz Krzysztofik V253_VLS_T,
102459dc352SJanusz Krzysztofik V253_VLS_L,
103459dc352SJanusz Krzysztofik V253_VLS_LT,
104459dc352SJanusz Krzysztofik V253_VLS_S,
105459dc352SJanusz Krzysztofik V253_VLS_ST,
106459dc352SJanusz Krzysztofik V253_VLS_M,
107459dc352SJanusz Krzysztofik V253_VLS_MST,
108459dc352SJanusz Krzysztofik V253_VLS_S1,
109459dc352SJanusz Krzysztofik V253_VLS_S1T,
110459dc352SJanusz Krzysztofik V253_VLS_MS1T,
111459dc352SJanusz Krzysztofik V253_VLS_M1,
112459dc352SJanusz Krzysztofik V253_VLS_M1ST,
113459dc352SJanusz Krzysztofik V253_VLS_M1S1T,
114459dc352SJanusz Krzysztofik V253_VLS_H,
115459dc352SJanusz Krzysztofik V253_VLS_HT,
116459dc352SJanusz Krzysztofik V253_VLS_MS,
117459dc352SJanusz Krzysztofik V253_VLS_MS1,
118459dc352SJanusz Krzysztofik V253_VLS_M1S,
119459dc352SJanusz Krzysztofik V253_VLS_M1S1,
120459dc352SJanusz Krzysztofik V253_VLS_TEST,
121459dc352SJanusz Krzysztofik };
122459dc352SJanusz Krzysztofik
cx20442_pm_to_v253_vls(u8 value)123459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vls(u8 value)
124459dc352SJanusz Krzysztofik {
125459dc352SJanusz Krzysztofik switch (value & ~(1 << CX20442_AGC)) {
126459dc352SJanusz Krzysztofik case 0:
127459dc352SJanusz Krzysztofik return V253_VLS_T;
128459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT):
129459dc352SJanusz Krzysztofik case (1 << CX20442_MIC):
130459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC):
131459dc352SJanusz Krzysztofik return V253_VLS_M1S1;
132459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT):
133459dc352SJanusz Krzysztofik case (1 << CX20442_TELIN):
134459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT) | (1 << CX20442_TELIN):
135459dc352SJanusz Krzysztofik return V253_VLS_L;
136459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT) | (1 << CX20442_MIC):
137459dc352SJanusz Krzysztofik return V253_VLS_NONE;
138459dc352SJanusz Krzysztofik }
139459dc352SJanusz Krzysztofik return -EINVAL;
140459dc352SJanusz Krzysztofik }
cx20442_pm_to_v253_vsp(u8 value)141459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vsp(u8 value)
142459dc352SJanusz Krzysztofik {
143459dc352SJanusz Krzysztofik switch (value & ~(1 << CX20442_AGC)) {
144459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT):
145459dc352SJanusz Krzysztofik case (1 << CX20442_MIC):
146459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC):
147459dc352SJanusz Krzysztofik return (bool)(value & (1 << CX20442_AGC));
148459dc352SJanusz Krzysztofik }
149459dc352SJanusz Krzysztofik return (value & (1 << CX20442_AGC)) ? -EINVAL : 0;
150459dc352SJanusz Krzysztofik }
151459dc352SJanusz Krzysztofik
cx20442_write(struct snd_soc_component * component,unsigned int reg,unsigned int value)152d0fdfe34SKuninori Morimoto static int cx20442_write(struct snd_soc_component *component, unsigned int reg,
153459dc352SJanusz Krzysztofik unsigned int value)
154459dc352SJanusz Krzysztofik {
155d0fdfe34SKuninori Morimoto struct cx20442_priv *cx20442 = snd_soc_component_get_drvdata(component);
156459dc352SJanusz Krzysztofik int vls, vsp, old, len;
157459dc352SJanusz Krzysztofik char buf[18];
158459dc352SJanusz Krzysztofik
1593c89724eSKuninori Morimoto if (reg >= 1)
160459dc352SJanusz Krzysztofik return -EINVAL;
161459dc352SJanusz Krzysztofik
162fac3f5e2SKuninori Morimoto /* tty and write pointers required for talking to the modem
163ad120daeSJanusz Krzysztofik * are expected to be set by the line discipline initialization code */
164fac3f5e2SKuninori Morimoto if (!cx20442->tty || !cx20442->tty->ops->write)
165459dc352SJanusz Krzysztofik return -EIO;
166459dc352SJanusz Krzysztofik
1673c89724eSKuninori Morimoto old = cx20442->reg_cache;
1683c89724eSKuninori Morimoto cx20442->reg_cache = value;
169459dc352SJanusz Krzysztofik
170459dc352SJanusz Krzysztofik vls = cx20442_pm_to_v253_vls(value);
171459dc352SJanusz Krzysztofik if (vls < 0)
172459dc352SJanusz Krzysztofik return vls;
173459dc352SJanusz Krzysztofik
174459dc352SJanusz Krzysztofik vsp = cx20442_pm_to_v253_vsp(value);
175459dc352SJanusz Krzysztofik if (vsp < 0)
176459dc352SJanusz Krzysztofik return vsp;
177459dc352SJanusz Krzysztofik
178459dc352SJanusz Krzysztofik if ((vls == V253_VLS_T) ||
179459dc352SJanusz Krzysztofik (vls == cx20442_pm_to_v253_vls(old))) {
180459dc352SJanusz Krzysztofik if (vsp == cx20442_pm_to_v253_vsp(old))
181459dc352SJanusz Krzysztofik return 0;
182459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp);
183459dc352SJanusz Krzysztofik } else if (vsp == cx20442_pm_to_v253_vsp(old))
184459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls);
185459dc352SJanusz Krzysztofik else
186459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf),
187459dc352SJanusz Krzysztofik "at+vls=%d;+vsp=%d\r", vls, vsp);
188459dc352SJanusz Krzysztofik
189459dc352SJanusz Krzysztofik if (unlikely(len > (ARRAY_SIZE(buf) - 1)))
190459dc352SJanusz Krzysztofik return -ENOMEM;
191459dc352SJanusz Krzysztofik
192d0fdfe34SKuninori Morimoto dev_dbg(component->dev, "%s: %s\n", __func__, buf);
193fac3f5e2SKuninori Morimoto if (cx20442->tty->ops->write(cx20442->tty, buf, len) != len)
194459dc352SJanusz Krzysztofik return -EIO;
195459dc352SJanusz Krzysztofik
196459dc352SJanusz Krzysztofik return 0;
197459dc352SJanusz Krzysztofik }
198ad120daeSJanusz Krzysztofik
199ad120daeSJanusz Krzysztofik /*
200ad120daeSJanusz Krzysztofik * Line discpline related code
201ad120daeSJanusz Krzysztofik *
202ad120daeSJanusz Krzysztofik * Any of the callback functions below can be used in two ways:
203ad120daeSJanusz Krzysztofik * 1) registerd by a machine driver as one of line discipline operations,
204ad120daeSJanusz Krzysztofik * 2) called from a machine's provided line discipline callback function
205ad120daeSJanusz Krzysztofik * in case when extra machine specific code must be run as well.
206ad120daeSJanusz Krzysztofik */
207ad120daeSJanusz Krzysztofik
208ad120daeSJanusz Krzysztofik /* Modem init: echo off, digital speaker off, quiet off, voice mode */
209dfe11146SJiri Slaby static const char v253_init[] = "ate0m0q0+fclass=8\r";
210ad120daeSJanusz Krzysztofik
211ad120daeSJanusz Krzysztofik /* Line discipline .open() */
v253_open(struct tty_struct * tty)212ad120daeSJanusz Krzysztofik static int v253_open(struct tty_struct *tty)
213ad120daeSJanusz Krzysztofik {
214ad120daeSJanusz Krzysztofik int ret, len = strlen(v253_init);
215ad120daeSJanusz Krzysztofik
216ad120daeSJanusz Krzysztofik /* Doesn't make sense without write callback */
217ad120daeSJanusz Krzysztofik if (!tty->ops->write)
218ad120daeSJanusz Krzysztofik return -EINVAL;
219ad120daeSJanusz Krzysztofik
220f0fba2adSLiam Girdwood /* Won't work if no codec pointer has been passed by a card driver */
221f0fba2adSLiam Girdwood if (!tty->disc_data)
222f0fba2adSLiam Girdwood return -ENODEV;
223ad120daeSJanusz Krzysztofik
22486c0ae7cSJanusz Krzysztofik tty->receive_room = 16;
225ad120daeSJanusz Krzysztofik if (tty->ops->write(tty, v253_init, len) != len) {
226ad120daeSJanusz Krzysztofik ret = -EIO;
227ad120daeSJanusz Krzysztofik goto err;
228ad120daeSJanusz Krzysztofik }
229ad120daeSJanusz Krzysztofik /* Actual setup will be performed after the modem responds. */
230ad120daeSJanusz Krzysztofik return 0;
231ad120daeSJanusz Krzysztofik err:
232ad120daeSJanusz Krzysztofik tty->disc_data = NULL;
233ad120daeSJanusz Krzysztofik return ret;
234ad120daeSJanusz Krzysztofik }
235ad120daeSJanusz Krzysztofik
236ad120daeSJanusz Krzysztofik /* Line discipline .close() */
v253_close(struct tty_struct * tty)237ad120daeSJanusz Krzysztofik static void v253_close(struct tty_struct *tty)
238ad120daeSJanusz Krzysztofik {
239d0fdfe34SKuninori Morimoto struct snd_soc_component *component = tty->disc_data;
240f0fba2adSLiam Girdwood struct cx20442_priv *cx20442;
241ad120daeSJanusz Krzysztofik
242ad120daeSJanusz Krzysztofik tty->disc_data = NULL;
243ad120daeSJanusz Krzysztofik
244d0fdfe34SKuninori Morimoto if (!component)
245ad120daeSJanusz Krzysztofik return;
246ad120daeSJanusz Krzysztofik
247d0fdfe34SKuninori Morimoto cx20442 = snd_soc_component_get_drvdata(component);
248f0fba2adSLiam Girdwood
249ad120daeSJanusz Krzysztofik /* Prevent the codec driver from further accessing the modem */
250fac3f5e2SKuninori Morimoto cx20442->tty = NULL;
251d0fdfe34SKuninori Morimoto component->card->pop_time = 0;
252ad120daeSJanusz Krzysztofik }
253ad120daeSJanusz Krzysztofik
254ad120daeSJanusz Krzysztofik /* Line discipline .hangup() */
v253_hangup(struct tty_struct * tty)25528f194daSJiri Slaby static void v253_hangup(struct tty_struct *tty)
256ad120daeSJanusz Krzysztofik {
257ad120daeSJanusz Krzysztofik v253_close(tty);
258ad120daeSJanusz Krzysztofik }
259ad120daeSJanusz Krzysztofik
260ad120daeSJanusz Krzysztofik /* Line discipline .receive_buf() */
v253_receive(struct tty_struct * tty,const u8 * cp,const u8 * fp,size_t count)261*892bc209SJiri Slaby (SUSE) static void v253_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp,
262a8d9cd23SJiri Slaby (SUSE) size_t count)
263ad120daeSJanusz Krzysztofik {
264d0fdfe34SKuninori Morimoto struct snd_soc_component *component = tty->disc_data;
265f0fba2adSLiam Girdwood struct cx20442_priv *cx20442;
266ad120daeSJanusz Krzysztofik
267d0fdfe34SKuninori Morimoto if (!component)
268bb3d6bf1SLinus Torvalds return;
269ad120daeSJanusz Krzysztofik
270d0fdfe34SKuninori Morimoto cx20442 = snd_soc_component_get_drvdata(component);
271f0fba2adSLiam Girdwood
272fac3f5e2SKuninori Morimoto if (!cx20442->tty) {
273ad120daeSJanusz Krzysztofik /* First modem response, complete setup procedure */
274ad120daeSJanusz Krzysztofik
275ad120daeSJanusz Krzysztofik /* Set up codec driver access to modem controls */
276fac3f5e2SKuninori Morimoto cx20442->tty = tty;
277d0fdfe34SKuninori Morimoto component->card->pop_time = 1;
278ad120daeSJanusz Krzysztofik }
279ad120daeSJanusz Krzysztofik }
280ad120daeSJanusz Krzysztofik
281ad120daeSJanusz Krzysztofik struct tty_ldisc_ops v253_ops = {
282ad120daeSJanusz Krzysztofik .name = "cx20442",
283ad120daeSJanusz Krzysztofik .owner = THIS_MODULE,
284ad120daeSJanusz Krzysztofik .open = v253_open,
285ad120daeSJanusz Krzysztofik .close = v253_close,
286ad120daeSJanusz Krzysztofik .hangup = v253_hangup,
287ad120daeSJanusz Krzysztofik .receive_buf = v253_receive,
288ad120daeSJanusz Krzysztofik };
289ad120daeSJanusz Krzysztofik EXPORT_SYMBOL_GPL(v253_ops);
290ad120daeSJanusz Krzysztofik
291ad120daeSJanusz Krzysztofik
292ad120daeSJanusz Krzysztofik /*
293ad120daeSJanusz Krzysztofik * Codec DAI
294ad120daeSJanusz Krzysztofik */
295ad120daeSJanusz Krzysztofik
296f0fba2adSLiam Girdwood static struct snd_soc_dai_driver cx20442_dai = {
2975394637aSJanusz Krzysztofik .name = "cx20442-voice",
298459dc352SJanusz Krzysztofik .playback = {
299459dc352SJanusz Krzysztofik .stream_name = "Playback",
300459dc352SJanusz Krzysztofik .channels_min = 1,
301459dc352SJanusz Krzysztofik .channels_max = 1,
302459dc352SJanusz Krzysztofik .rates = SNDRV_PCM_RATE_8000,
303459dc352SJanusz Krzysztofik .formats = SNDRV_PCM_FMTBIT_S16_LE,
304459dc352SJanusz Krzysztofik },
305459dc352SJanusz Krzysztofik .capture = {
306459dc352SJanusz Krzysztofik .stream_name = "Capture",
307459dc352SJanusz Krzysztofik .channels_min = 1,
308459dc352SJanusz Krzysztofik .channels_max = 1,
309459dc352SJanusz Krzysztofik .rates = SNDRV_PCM_RATE_8000,
310459dc352SJanusz Krzysztofik .formats = SNDRV_PCM_FMTBIT_S16_LE,
311459dc352SJanusz Krzysztofik },
312459dc352SJanusz Krzysztofik };
313459dc352SJanusz Krzysztofik
cx20442_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)314d0fdfe34SKuninori Morimoto static int cx20442_set_bias_level(struct snd_soc_component *component,
315f75a8ff6SJanusz Krzysztofik enum snd_soc_bias_level level)
316f75a8ff6SJanusz Krzysztofik {
317d0fdfe34SKuninori Morimoto struct cx20442_priv *cx20442 = snd_soc_component_get_drvdata(component);
318f75a8ff6SJanusz Krzysztofik int err = 0;
319f75a8ff6SJanusz Krzysztofik
320f75a8ff6SJanusz Krzysztofik switch (level) {
321f75a8ff6SJanusz Krzysztofik case SND_SOC_BIAS_PREPARE:
322d0fdfe34SKuninori Morimoto if (snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_STANDBY)
323f75a8ff6SJanusz Krzysztofik break;
324f75a8ff6SJanusz Krzysztofik if (IS_ERR(cx20442->por))
325f75a8ff6SJanusz Krzysztofik err = PTR_ERR(cx20442->por);
326f75a8ff6SJanusz Krzysztofik else
327f75a8ff6SJanusz Krzysztofik err = regulator_enable(cx20442->por);
328f75a8ff6SJanusz Krzysztofik break;
329f75a8ff6SJanusz Krzysztofik case SND_SOC_BIAS_STANDBY:
330d0fdfe34SKuninori Morimoto if (snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_PREPARE)
331f75a8ff6SJanusz Krzysztofik break;
332f75a8ff6SJanusz Krzysztofik if (IS_ERR(cx20442->por))
333f75a8ff6SJanusz Krzysztofik err = PTR_ERR(cx20442->por);
334f75a8ff6SJanusz Krzysztofik else
335f75a8ff6SJanusz Krzysztofik err = regulator_disable(cx20442->por);
336f75a8ff6SJanusz Krzysztofik break;
337f75a8ff6SJanusz Krzysztofik default:
338f75a8ff6SJanusz Krzysztofik break;
339f75a8ff6SJanusz Krzysztofik }
340f75a8ff6SJanusz Krzysztofik
341f75a8ff6SJanusz Krzysztofik return err;
342f75a8ff6SJanusz Krzysztofik }
343f75a8ff6SJanusz Krzysztofik
cx20442_component_probe(struct snd_soc_component * component)344d0fdfe34SKuninori Morimoto static int cx20442_component_probe(struct snd_soc_component *component)
345459dc352SJanusz Krzysztofik {
346459dc352SJanusz Krzysztofik struct cx20442_priv *cx20442;
347459dc352SJanusz Krzysztofik
348459dc352SJanusz Krzysztofik cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL);
349459dc352SJanusz Krzysztofik if (cx20442 == NULL)
350459dc352SJanusz Krzysztofik return -ENOMEM;
351459dc352SJanusz Krzysztofik
352d0fdfe34SKuninori Morimoto cx20442->por = regulator_get(component->dev, "POR");
35350c67877SJanusz Krzysztofik if (IS_ERR(cx20442->por)) {
35450c67877SJanusz Krzysztofik int err = PTR_ERR(cx20442->por);
35550c67877SJanusz Krzysztofik
35650c67877SJanusz Krzysztofik dev_warn(component->dev, "failed to get POR supply (%d)", err);
35750c67877SJanusz Krzysztofik /*
35850c67877SJanusz Krzysztofik * When running on a non-dt platform and requested regulator
35950c67877SJanusz Krzysztofik * is not available, regulator_get() never returns
36050c67877SJanusz Krzysztofik * -EPROBE_DEFER as it is not able to justify if the regulator
36150c67877SJanusz Krzysztofik * may still appear later. On the other hand, the board can
36250c67877SJanusz Krzysztofik * still set full constraints flag at late_initcall in order
36350c67877SJanusz Krzysztofik * to instruct regulator_get() to return a dummy one if
36450c67877SJanusz Krzysztofik * sufficient. Hence, if we get -ENODEV here, let's convert
36550c67877SJanusz Krzysztofik * it to -EPROBE_DEFER and wait for the board to decide or
36650c67877SJanusz Krzysztofik * let Deferred Probe infrastructure handle this error.
36750c67877SJanusz Krzysztofik */
36850c67877SJanusz Krzysztofik if (err == -ENODEV)
36950c67877SJanusz Krzysztofik err = -EPROBE_DEFER;
37050c67877SJanusz Krzysztofik kfree(cx20442);
37150c67877SJanusz Krzysztofik return err;
37250c67877SJanusz Krzysztofik }
37350c67877SJanusz Krzysztofik
374fac3f5e2SKuninori Morimoto cx20442->tty = NULL;
375f75a8ff6SJanusz Krzysztofik
376d0fdfe34SKuninori Morimoto snd_soc_component_set_drvdata(component, cx20442);
377d0fdfe34SKuninori Morimoto component->card->pop_time = 0;
378459dc352SJanusz Krzysztofik
379f0fba2adSLiam Girdwood return 0;
380f0fba2adSLiam Girdwood }
381459dc352SJanusz Krzysztofik
382f0fba2adSLiam Girdwood /* power down chip */
cx20442_component_remove(struct snd_soc_component * component)383d0fdfe34SKuninori Morimoto static void cx20442_component_remove(struct snd_soc_component *component)
384f0fba2adSLiam Girdwood {
385d0fdfe34SKuninori Morimoto struct cx20442_priv *cx20442 = snd_soc_component_get_drvdata(component);
386f0fba2adSLiam Girdwood
387fac3f5e2SKuninori Morimoto if (cx20442->tty) {
388fac3f5e2SKuninori Morimoto struct tty_struct *tty = cx20442->tty;
389f0fba2adSLiam Girdwood tty_hangup(tty);
390f0fba2adSLiam Girdwood }
391f0fba2adSLiam Girdwood
392f75a8ff6SJanusz Krzysztofik if (!IS_ERR(cx20442->por)) {
393f75a8ff6SJanusz Krzysztofik /* should be already in STANDBY, hence disabled */
394f75a8ff6SJanusz Krzysztofik regulator_put(cx20442->por);
395f75a8ff6SJanusz Krzysztofik }
396f75a8ff6SJanusz Krzysztofik
397d0fdfe34SKuninori Morimoto snd_soc_component_set_drvdata(component, NULL);
398f0fba2adSLiam Girdwood kfree(cx20442);
399f0fba2adSLiam Girdwood }
400f0fba2adSLiam Girdwood
401d0fdfe34SKuninori Morimoto static const struct snd_soc_component_driver cx20442_component_dev = {
402d0fdfe34SKuninori Morimoto .probe = cx20442_component_probe,
403d0fdfe34SKuninori Morimoto .remove = cx20442_component_remove,
404f75a8ff6SJanusz Krzysztofik .set_bias_level = cx20442_set_bias_level,
4053c89724eSKuninori Morimoto .read = cx20442_read_reg_cache,
4063c89724eSKuninori Morimoto .write = cx20442_write,
40751fb1a87SLu Guanqun .dapm_widgets = cx20442_dapm_widgets,
40851fb1a87SLu Guanqun .num_dapm_widgets = ARRAY_SIZE(cx20442_dapm_widgets),
40951fb1a87SLu Guanqun .dapm_routes = cx20442_audio_map,
41051fb1a87SLu Guanqun .num_dapm_routes = ARRAY_SIZE(cx20442_audio_map),
411d0fdfe34SKuninori Morimoto .idle_bias_on = 1,
412d0fdfe34SKuninori Morimoto .use_pmdown_time = 1,
413d0fdfe34SKuninori Morimoto .endianness = 1,
414f0fba2adSLiam Girdwood };
415f0fba2adSLiam Girdwood
cx20442_platform_probe(struct platform_device * pdev)416f0fba2adSLiam Girdwood static int cx20442_platform_probe(struct platform_device *pdev)
417f0fba2adSLiam Girdwood {
418d0fdfe34SKuninori Morimoto return devm_snd_soc_register_component(&pdev->dev,
419d0fdfe34SKuninori Morimoto &cx20442_component_dev, &cx20442_dai, 1);
420459dc352SJanusz Krzysztofik }
421459dc352SJanusz Krzysztofik
422459dc352SJanusz Krzysztofik static struct platform_driver cx20442_platform_driver = {
423459dc352SJanusz Krzysztofik .driver = {
424f0fba2adSLiam Girdwood .name = "cx20442-codec",
425459dc352SJanusz Krzysztofik },
426459dc352SJanusz Krzysztofik .probe = cx20442_platform_probe,
427459dc352SJanusz Krzysztofik };
428459dc352SJanusz Krzysztofik
4295bbcc3c0SMark Brown module_platform_driver(cx20442_platform_driver);
430459dc352SJanusz Krzysztofik
431459dc352SJanusz Krzysztofik MODULE_DESCRIPTION("ASoC CX20442-11 voice modem codec driver");
432459dc352SJanusz Krzysztofik MODULE_AUTHOR("Janusz Krzysztofik");
433459dc352SJanusz Krzysztofik MODULE_LICENSE("GPL");
434f0fba2adSLiam Girdwood MODULE_ALIAS("platform:cx20442-codec");
435