xref: /openbmc/linux/sound/soc/codecs/cx20442.c (revision ce6120cca2589ede530200c7cfe11ac9f144333c)
1459dc352SJanusz Krzysztofik /*
2459dc352SJanusz Krzysztofik  * cx20442.c  --  CX20442 ALSA Soc Audio driver
3459dc352SJanusz Krzysztofik  *
4459dc352SJanusz Krzysztofik  * Copyright 2009 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>
5459dc352SJanusz Krzysztofik  *
6459dc352SJanusz Krzysztofik  * Initially based on sound/soc/codecs/wm8400.c
7459dc352SJanusz Krzysztofik  * Copyright 2008, 2009 Wolfson Microelectronics PLC.
8459dc352SJanusz Krzysztofik  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9459dc352SJanusz Krzysztofik  *
10459dc352SJanusz Krzysztofik  *  This program is free software; you can redistribute  it and/or modify it
11459dc352SJanusz Krzysztofik  *  under  the terms of  the GNU General  Public License as published by the
12459dc352SJanusz Krzysztofik  *  Free Software Foundation;  either version 2 of the  License, or (at your
13459dc352SJanusz Krzysztofik  *  option) any later version.
14459dc352SJanusz Krzysztofik  */
15459dc352SJanusz Krzysztofik 
16ad120daeSJanusz Krzysztofik #include <linux/tty.h>
175a0e3ad6STejun Heo #include <linux/slab.h>
18ad120daeSJanusz Krzysztofik 
19459dc352SJanusz Krzysztofik #include <sound/core.h>
20459dc352SJanusz Krzysztofik #include <sound/initval.h>
21*ce6120ccSLiam Girdwood #include <sound/soc.h>
22459dc352SJanusz Krzysztofik 
23459dc352SJanusz Krzysztofik #include "cx20442.h"
24459dc352SJanusz Krzysztofik 
25459dc352SJanusz Krzysztofik 
26459dc352SJanusz Krzysztofik struct cx20442_priv {
27f0fba2adSLiam Girdwood 	enum snd_soc_control_type control_type;
28f0fba2adSLiam Girdwood 	void *control_data;
29459dc352SJanusz Krzysztofik 	u8 reg_cache[1];
30459dc352SJanusz Krzysztofik };
31459dc352SJanusz Krzysztofik 
32459dc352SJanusz Krzysztofik #define CX20442_PM		0x0
33459dc352SJanusz Krzysztofik 
34459dc352SJanusz Krzysztofik #define CX20442_TELIN		0
35459dc352SJanusz Krzysztofik #define CX20442_TELOUT		1
36459dc352SJanusz Krzysztofik #define CX20442_MIC		2
37459dc352SJanusz Krzysztofik #define CX20442_SPKOUT		3
38459dc352SJanusz Krzysztofik #define CX20442_AGC		4
39459dc352SJanusz Krzysztofik 
40459dc352SJanusz Krzysztofik static const struct snd_soc_dapm_widget cx20442_dapm_widgets[] = {
41459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_OUTPUT("TELOUT"),
42459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_OUTPUT("SPKOUT"),
43459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_OUTPUT("AGCOUT"),
44459dc352SJanusz Krzysztofik 
45459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_MIXER("SPKOUT Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
46459dc352SJanusz Krzysztofik 
47459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_PGA("TELOUT Amp", CX20442_PM, CX20442_TELOUT, 0, NULL, 0),
48459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_PGA("SPKOUT Amp", CX20442_PM, CX20442_SPKOUT, 0, NULL, 0),
49459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_PGA("SPKOUT AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0),
50459dc352SJanusz Krzysztofik 
51459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0),
52459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
53459dc352SJanusz Krzysztofik 
54459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
55459dc352SJanusz Krzysztofik 
56459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_MICBIAS("TELIN Bias", CX20442_PM, CX20442_TELIN, 0),
57459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_MICBIAS("MIC Bias", CX20442_PM, CX20442_MIC, 0),
58459dc352SJanusz Krzysztofik 
59459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_PGA("MIC AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0),
60459dc352SJanusz Krzysztofik 
61459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_INPUT("TELIN"),
62459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_INPUT("MIC"),
63459dc352SJanusz Krzysztofik 	SND_SOC_DAPM_INPUT("AGCIN"),
64459dc352SJanusz Krzysztofik };
65459dc352SJanusz Krzysztofik 
66459dc352SJanusz Krzysztofik static const struct snd_soc_dapm_route cx20442_audio_map[] = {
67459dc352SJanusz Krzysztofik 	{"TELOUT", NULL, "TELOUT Amp"},
68459dc352SJanusz Krzysztofik 
69459dc352SJanusz Krzysztofik 	{"SPKOUT", NULL, "SPKOUT Mixer"},
70459dc352SJanusz Krzysztofik 	{"SPKOUT Mixer", NULL, "SPKOUT Amp"},
71459dc352SJanusz Krzysztofik 
72459dc352SJanusz Krzysztofik 	{"TELOUT Amp", NULL, "DAC"},
73459dc352SJanusz Krzysztofik 	{"SPKOUT Amp", NULL, "DAC"},
74459dc352SJanusz Krzysztofik 
75459dc352SJanusz Krzysztofik 	{"SPKOUT Mixer", NULL, "SPKOUT AGC"},
76459dc352SJanusz Krzysztofik 	{"SPKOUT AGC", NULL, "AGCIN"},
77459dc352SJanusz Krzysztofik 
78459dc352SJanusz Krzysztofik 	{"AGCOUT", NULL, "MIC AGC"},
79459dc352SJanusz Krzysztofik 	{"MIC AGC", NULL, "MIC"},
80459dc352SJanusz Krzysztofik 
81459dc352SJanusz Krzysztofik 	{"MIC Bias", NULL, "MIC"},
82459dc352SJanusz Krzysztofik 	{"Input Mixer", NULL, "MIC Bias"},
83459dc352SJanusz Krzysztofik 
84459dc352SJanusz Krzysztofik 	{"TELIN Bias", NULL, "TELIN"},
85459dc352SJanusz Krzysztofik 	{"Input Mixer", NULL, "TELIN Bias"},
86459dc352SJanusz Krzysztofik 
87459dc352SJanusz Krzysztofik 	{"ADC", NULL, "Input Mixer"},
88459dc352SJanusz Krzysztofik };
89459dc352SJanusz Krzysztofik 
90459dc352SJanusz Krzysztofik static int cx20442_add_widgets(struct snd_soc_codec *codec)
91459dc352SJanusz Krzysztofik {
92*ce6120ccSLiam Girdwood 	struct snd_soc_dapm_context *dapm = &codec->dapm;
93459dc352SJanusz Krzysztofik 
94*ce6120ccSLiam Girdwood 	snd_soc_dapm_new_controls(dapm, cx20442_dapm_widgets,
95*ce6120ccSLiam Girdwood 				  ARRAY_SIZE(cx20442_dapm_widgets));
96*ce6120ccSLiam Girdwood 	snd_soc_dapm_add_routes(dapm, cx20442_audio_map,
97459dc352SJanusz Krzysztofik 				ARRAY_SIZE(cx20442_audio_map));
98459dc352SJanusz Krzysztofik 
99459dc352SJanusz Krzysztofik 	return 0;
100459dc352SJanusz Krzysztofik }
101459dc352SJanusz Krzysztofik 
102459dc352SJanusz Krzysztofik static unsigned int cx20442_read_reg_cache(struct snd_soc_codec *codec,
103459dc352SJanusz Krzysztofik 							unsigned int reg)
104459dc352SJanusz Krzysztofik {
105459dc352SJanusz Krzysztofik 	u8 *reg_cache = codec->reg_cache;
106459dc352SJanusz Krzysztofik 
107f0fba2adSLiam Girdwood 	if (reg >= codec->driver->reg_cache_size)
108459dc352SJanusz Krzysztofik 		return -EINVAL;
109459dc352SJanusz Krzysztofik 
110459dc352SJanusz Krzysztofik 	return reg_cache[reg];
111459dc352SJanusz Krzysztofik }
112459dc352SJanusz Krzysztofik 
113459dc352SJanusz Krzysztofik enum v253_vls {
114459dc352SJanusz Krzysztofik 	V253_VLS_NONE = 0,
115459dc352SJanusz Krzysztofik 	V253_VLS_T,
116459dc352SJanusz Krzysztofik 	V253_VLS_L,
117459dc352SJanusz Krzysztofik 	V253_VLS_LT,
118459dc352SJanusz Krzysztofik 	V253_VLS_S,
119459dc352SJanusz Krzysztofik 	V253_VLS_ST,
120459dc352SJanusz Krzysztofik 	V253_VLS_M,
121459dc352SJanusz Krzysztofik 	V253_VLS_MST,
122459dc352SJanusz Krzysztofik 	V253_VLS_S1,
123459dc352SJanusz Krzysztofik 	V253_VLS_S1T,
124459dc352SJanusz Krzysztofik 	V253_VLS_MS1T,
125459dc352SJanusz Krzysztofik 	V253_VLS_M1,
126459dc352SJanusz Krzysztofik 	V253_VLS_M1ST,
127459dc352SJanusz Krzysztofik 	V253_VLS_M1S1T,
128459dc352SJanusz Krzysztofik 	V253_VLS_H,
129459dc352SJanusz Krzysztofik 	V253_VLS_HT,
130459dc352SJanusz Krzysztofik 	V253_VLS_MS,
131459dc352SJanusz Krzysztofik 	V253_VLS_MS1,
132459dc352SJanusz Krzysztofik 	V253_VLS_M1S,
133459dc352SJanusz Krzysztofik 	V253_VLS_M1S1,
134459dc352SJanusz Krzysztofik 	V253_VLS_TEST,
135459dc352SJanusz Krzysztofik };
136459dc352SJanusz Krzysztofik 
137459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vls(u8 value)
138459dc352SJanusz Krzysztofik {
139459dc352SJanusz Krzysztofik 	switch (value & ~(1 << CX20442_AGC)) {
140459dc352SJanusz Krzysztofik 	case 0:
141459dc352SJanusz Krzysztofik 		return V253_VLS_T;
142459dc352SJanusz Krzysztofik 	case (1 << CX20442_SPKOUT):
143459dc352SJanusz Krzysztofik 	case (1 << CX20442_MIC):
144459dc352SJanusz Krzysztofik 	case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC):
145459dc352SJanusz Krzysztofik 		return V253_VLS_M1S1;
146459dc352SJanusz Krzysztofik 	case (1 << CX20442_TELOUT):
147459dc352SJanusz Krzysztofik 	case (1 << CX20442_TELIN):
148459dc352SJanusz Krzysztofik 	case (1 << CX20442_TELOUT) | (1 << CX20442_TELIN):
149459dc352SJanusz Krzysztofik 		return V253_VLS_L;
150459dc352SJanusz Krzysztofik 	case (1 << CX20442_TELOUT) | (1 << CX20442_MIC):
151459dc352SJanusz Krzysztofik 		return V253_VLS_NONE;
152459dc352SJanusz Krzysztofik 	}
153459dc352SJanusz Krzysztofik 	return -EINVAL;
154459dc352SJanusz Krzysztofik }
155459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vsp(u8 value)
156459dc352SJanusz Krzysztofik {
157459dc352SJanusz Krzysztofik 	switch (value & ~(1 << CX20442_AGC)) {
158459dc352SJanusz Krzysztofik 	case (1 << CX20442_SPKOUT):
159459dc352SJanusz Krzysztofik 	case (1 << CX20442_MIC):
160459dc352SJanusz Krzysztofik 	case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC):
161459dc352SJanusz Krzysztofik 		return (bool)(value & (1 << CX20442_AGC));
162459dc352SJanusz Krzysztofik 	}
163459dc352SJanusz Krzysztofik 	return (value & (1 << CX20442_AGC)) ? -EINVAL : 0;
164459dc352SJanusz Krzysztofik }
165459dc352SJanusz Krzysztofik 
166459dc352SJanusz Krzysztofik static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg,
167459dc352SJanusz Krzysztofik 							unsigned int value)
168459dc352SJanusz Krzysztofik {
169f0fba2adSLiam Girdwood 	struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec);
170459dc352SJanusz Krzysztofik 	u8 *reg_cache = codec->reg_cache;
171459dc352SJanusz Krzysztofik 	int vls, vsp, old, len;
172459dc352SJanusz Krzysztofik 	char buf[18];
173459dc352SJanusz Krzysztofik 
174f0fba2adSLiam Girdwood 	if (reg >= codec->driver->reg_cache_size)
175459dc352SJanusz Krzysztofik 		return -EINVAL;
176459dc352SJanusz Krzysztofik 
177b84eab08SJanusz Krzysztofik 	/* hw_write and control_data pointers required for talking to the modem
178ad120daeSJanusz Krzysztofik 	 * are expected to be set by the line discipline initialization code */
179f0fba2adSLiam Girdwood 	if (!codec->hw_write || !cx20442->control_data)
180459dc352SJanusz Krzysztofik 		return -EIO;
181459dc352SJanusz Krzysztofik 
182459dc352SJanusz Krzysztofik 	old = reg_cache[reg];
183459dc352SJanusz Krzysztofik 	reg_cache[reg] = value;
184459dc352SJanusz Krzysztofik 
185459dc352SJanusz Krzysztofik 	vls = cx20442_pm_to_v253_vls(value);
186459dc352SJanusz Krzysztofik 	if (vls < 0)
187459dc352SJanusz Krzysztofik 		return vls;
188459dc352SJanusz Krzysztofik 
189459dc352SJanusz Krzysztofik 	vsp = cx20442_pm_to_v253_vsp(value);
190459dc352SJanusz Krzysztofik 	if (vsp < 0)
191459dc352SJanusz Krzysztofik 		return vsp;
192459dc352SJanusz Krzysztofik 
193459dc352SJanusz Krzysztofik 	if ((vls == V253_VLS_T) ||
194459dc352SJanusz Krzysztofik 			(vls == cx20442_pm_to_v253_vls(old))) {
195459dc352SJanusz Krzysztofik 		if (vsp == cx20442_pm_to_v253_vsp(old))
196459dc352SJanusz Krzysztofik 			return 0;
197459dc352SJanusz Krzysztofik 		len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp);
198459dc352SJanusz Krzysztofik 	} else if (vsp == cx20442_pm_to_v253_vsp(old))
199459dc352SJanusz Krzysztofik 		len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls);
200459dc352SJanusz Krzysztofik 	else
201459dc352SJanusz Krzysztofik 		len = snprintf(buf, ARRAY_SIZE(buf),
202459dc352SJanusz Krzysztofik 					"at+vls=%d;+vsp=%d\r", vls, vsp);
203459dc352SJanusz Krzysztofik 
204459dc352SJanusz Krzysztofik 	if (unlikely(len > (ARRAY_SIZE(buf) - 1)))
205459dc352SJanusz Krzysztofik 		return -ENOMEM;
206459dc352SJanusz Krzysztofik 
2074977b03eSJanusz Krzysztofik 	dev_dbg(codec->dev, "%s: %s\n", __func__, buf);
208f0fba2adSLiam Girdwood 	if (codec->hw_write(cx20442->control_data, buf, len) != len)
209459dc352SJanusz Krzysztofik 		return -EIO;
210459dc352SJanusz Krzysztofik 
211459dc352SJanusz Krzysztofik 	return 0;
212459dc352SJanusz Krzysztofik }
213459dc352SJanusz Krzysztofik 
214ad120daeSJanusz Krzysztofik 
215ad120daeSJanusz Krzysztofik /*
216ad120daeSJanusz Krzysztofik  * Line discpline related code
217ad120daeSJanusz Krzysztofik  *
218ad120daeSJanusz Krzysztofik  * Any of the callback functions below can be used in two ways:
219ad120daeSJanusz Krzysztofik  * 1) registerd by a machine driver as one of line discipline operations,
220ad120daeSJanusz Krzysztofik  * 2) called from a machine's provided line discipline callback function
221ad120daeSJanusz Krzysztofik  *    in case when extra machine specific code must be run as well.
222ad120daeSJanusz Krzysztofik  */
223ad120daeSJanusz Krzysztofik 
224ad120daeSJanusz Krzysztofik /* Modem init: echo off, digital speaker off, quiet off, voice mode */
225ad120daeSJanusz Krzysztofik static const char *v253_init = "ate0m0q0+fclass=8\r";
226ad120daeSJanusz Krzysztofik 
227ad120daeSJanusz Krzysztofik /* Line discipline .open() */
228ad120daeSJanusz Krzysztofik static int v253_open(struct tty_struct *tty)
229ad120daeSJanusz Krzysztofik {
230ad120daeSJanusz Krzysztofik 	int ret, len = strlen(v253_init);
231ad120daeSJanusz Krzysztofik 
232ad120daeSJanusz Krzysztofik 	/* Doesn't make sense without write callback */
233ad120daeSJanusz Krzysztofik 	if (!tty->ops->write)
234ad120daeSJanusz Krzysztofik 		return -EINVAL;
235ad120daeSJanusz Krzysztofik 
236f0fba2adSLiam Girdwood 	/* Won't work if no codec pointer has been passed by a card driver */
237f0fba2adSLiam Girdwood 	if (!tty->disc_data)
238f0fba2adSLiam Girdwood 		return -ENODEV;
239ad120daeSJanusz Krzysztofik 
240ad120daeSJanusz Krzysztofik 	if (tty->ops->write(tty, v253_init, len) != len) {
241ad120daeSJanusz Krzysztofik 		ret = -EIO;
242ad120daeSJanusz Krzysztofik 		goto err;
243ad120daeSJanusz Krzysztofik 	}
244ad120daeSJanusz Krzysztofik 	/* Actual setup will be performed after the modem responds. */
245ad120daeSJanusz Krzysztofik 	return 0;
246ad120daeSJanusz Krzysztofik err:
247ad120daeSJanusz Krzysztofik 	tty->disc_data = NULL;
248ad120daeSJanusz Krzysztofik 	return ret;
249ad120daeSJanusz Krzysztofik }
250ad120daeSJanusz Krzysztofik 
251ad120daeSJanusz Krzysztofik /* Line discipline .close() */
252ad120daeSJanusz Krzysztofik static void v253_close(struct tty_struct *tty)
253ad120daeSJanusz Krzysztofik {
254ad120daeSJanusz Krzysztofik 	struct snd_soc_codec *codec = tty->disc_data;
255f0fba2adSLiam Girdwood 	struct cx20442_priv *cx20442;
256ad120daeSJanusz Krzysztofik 
257ad120daeSJanusz Krzysztofik 	tty->disc_data = NULL;
258ad120daeSJanusz Krzysztofik 
259ad120daeSJanusz Krzysztofik 	if (!codec)
260ad120daeSJanusz Krzysztofik 		return;
261ad120daeSJanusz Krzysztofik 
262f0fba2adSLiam Girdwood 	cx20442 = snd_soc_codec_get_drvdata(codec);
263f0fba2adSLiam Girdwood 
264ad120daeSJanusz Krzysztofik 	/* Prevent the codec driver from further accessing the modem */
265ad120daeSJanusz Krzysztofik 	codec->hw_write = NULL;
266f0fba2adSLiam Girdwood 	cx20442->control_data = NULL;
267*ce6120ccSLiam Girdwood 	codec->dapm.pop_time = 0;
268ad120daeSJanusz Krzysztofik }
269ad120daeSJanusz Krzysztofik 
270ad120daeSJanusz Krzysztofik /* Line discipline .hangup() */
271ad120daeSJanusz Krzysztofik static int v253_hangup(struct tty_struct *tty)
272ad120daeSJanusz Krzysztofik {
273ad120daeSJanusz Krzysztofik 	v253_close(tty);
274ad120daeSJanusz Krzysztofik 	return 0;
275ad120daeSJanusz Krzysztofik }
276ad120daeSJanusz Krzysztofik 
277ad120daeSJanusz Krzysztofik /* Line discipline .receive_buf() */
278ad120daeSJanusz Krzysztofik static void v253_receive(struct tty_struct *tty,
279ad120daeSJanusz Krzysztofik 				const unsigned char *cp, char *fp, int count)
280ad120daeSJanusz Krzysztofik {
281ad120daeSJanusz Krzysztofik 	struct snd_soc_codec *codec = tty->disc_data;
282f0fba2adSLiam Girdwood 	struct cx20442_priv *cx20442;
283ad120daeSJanusz Krzysztofik 
284ad120daeSJanusz Krzysztofik 	if (!codec)
285ad120daeSJanusz Krzysztofik 		return;
286ad120daeSJanusz Krzysztofik 
287f0fba2adSLiam Girdwood 	cx20442 = snd_soc_codec_get_drvdata(codec);
288f0fba2adSLiam Girdwood 
289f0fba2adSLiam Girdwood 	if (!cx20442->control_data) {
290ad120daeSJanusz Krzysztofik 		/* First modem response, complete setup procedure */
291ad120daeSJanusz Krzysztofik 
292ad120daeSJanusz Krzysztofik 		/* Set up codec driver access to modem controls */
293f0fba2adSLiam Girdwood 		cx20442->control_data = tty;
294ad120daeSJanusz Krzysztofik 		codec->hw_write = (hw_write_t)tty->ops->write;
295*ce6120ccSLiam Girdwood 		codec->dapm.pop_time = 1;
296ad120daeSJanusz Krzysztofik 	}
297ad120daeSJanusz Krzysztofik }
298ad120daeSJanusz Krzysztofik 
299ad120daeSJanusz Krzysztofik /* Line discipline .write_wakeup() */
300ad120daeSJanusz Krzysztofik static void v253_wakeup(struct tty_struct *tty)
301ad120daeSJanusz Krzysztofik {
302ad120daeSJanusz Krzysztofik }
303ad120daeSJanusz Krzysztofik 
304ad120daeSJanusz Krzysztofik struct tty_ldisc_ops v253_ops = {
305ad120daeSJanusz Krzysztofik 	.magic = TTY_LDISC_MAGIC,
306ad120daeSJanusz Krzysztofik 	.name = "cx20442",
307ad120daeSJanusz Krzysztofik 	.owner = THIS_MODULE,
308ad120daeSJanusz Krzysztofik 	.open = v253_open,
309ad120daeSJanusz Krzysztofik 	.close = v253_close,
310ad120daeSJanusz Krzysztofik 	.hangup = v253_hangup,
311ad120daeSJanusz Krzysztofik 	.receive_buf = v253_receive,
312ad120daeSJanusz Krzysztofik 	.write_wakeup = v253_wakeup,
313ad120daeSJanusz Krzysztofik };
314ad120daeSJanusz Krzysztofik EXPORT_SYMBOL_GPL(v253_ops);
315ad120daeSJanusz Krzysztofik 
316ad120daeSJanusz Krzysztofik 
317ad120daeSJanusz Krzysztofik /*
318ad120daeSJanusz Krzysztofik  * Codec DAI
319ad120daeSJanusz Krzysztofik  */
320ad120daeSJanusz Krzysztofik 
321f0fba2adSLiam Girdwood static struct snd_soc_dai_driver cx20442_dai = {
3225394637aSJanusz Krzysztofik 	.name = "cx20442-voice",
323459dc352SJanusz Krzysztofik 	.playback = {
324459dc352SJanusz Krzysztofik 		.stream_name = "Playback",
325459dc352SJanusz Krzysztofik 		.channels_min = 1,
326459dc352SJanusz Krzysztofik 		.channels_max = 1,
327459dc352SJanusz Krzysztofik 		.rates = SNDRV_PCM_RATE_8000,
328459dc352SJanusz Krzysztofik 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
329459dc352SJanusz Krzysztofik 	},
330459dc352SJanusz Krzysztofik 	.capture = {
331459dc352SJanusz Krzysztofik 		.stream_name = "Capture",
332459dc352SJanusz Krzysztofik 		.channels_min = 1,
333459dc352SJanusz Krzysztofik 		.channels_max = 1,
334459dc352SJanusz Krzysztofik 		.rates = SNDRV_PCM_RATE_8000,
335459dc352SJanusz Krzysztofik 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
336459dc352SJanusz Krzysztofik 	},
337459dc352SJanusz Krzysztofik };
338459dc352SJanusz Krzysztofik 
339f0fba2adSLiam Girdwood static int cx20442_codec_probe(struct snd_soc_codec *codec)
340459dc352SJanusz Krzysztofik {
341459dc352SJanusz Krzysztofik 	struct cx20442_priv *cx20442;
342459dc352SJanusz Krzysztofik 
343459dc352SJanusz Krzysztofik 	cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL);
344459dc352SJanusz Krzysztofik 	if (cx20442 == NULL)
345459dc352SJanusz Krzysztofik 		return -ENOMEM;
346f0fba2adSLiam Girdwood 	snd_soc_codec_set_drvdata(codec, cx20442);
347459dc352SJanusz Krzysztofik 
348f0fba2adSLiam Girdwood 	cx20442_add_widgets(codec);
349459dc352SJanusz Krzysztofik 
350f0fba2adSLiam Girdwood 	cx20442->control_data = NULL;
351459dc352SJanusz Krzysztofik 	codec->hw_write = NULL;
352*ce6120ccSLiam Girdwood 	codec->dapm.pop_time = 0;
353459dc352SJanusz Krzysztofik 
354f0fba2adSLiam Girdwood 	return 0;
355f0fba2adSLiam Girdwood }
356459dc352SJanusz Krzysztofik 
357f0fba2adSLiam Girdwood /* power down chip */
358f0fba2adSLiam Girdwood static int cx20442_codec_remove(struct snd_soc_codec *codec)
359f0fba2adSLiam Girdwood {
360f0fba2adSLiam Girdwood 	struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec);
361f0fba2adSLiam Girdwood 
362f0fba2adSLiam Girdwood 	if (cx20442->control_data) {
363f0fba2adSLiam Girdwood 			struct tty_struct *tty = cx20442->control_data;
364f0fba2adSLiam Girdwood 			tty_hangup(tty);
365f0fba2adSLiam Girdwood 	}
366f0fba2adSLiam Girdwood 
367f0fba2adSLiam Girdwood 	kfree(cx20442);
368f0fba2adSLiam Girdwood 	return 0;
369f0fba2adSLiam Girdwood }
370f0fba2adSLiam Girdwood 
371f0fba2adSLiam Girdwood static struct snd_soc_codec_driver cx20442_codec_dev = {
372f0fba2adSLiam Girdwood 	.probe = 	cx20442_codec_probe,
373f0fba2adSLiam Girdwood 	.remove = 	cx20442_codec_remove,
374f0fba2adSLiam Girdwood 	.reg_cache_size = 1,
375f0fba2adSLiam Girdwood 	.reg_word_size = sizeof(u8),
376f0fba2adSLiam Girdwood 	.read = cx20442_read_reg_cache,
377f0fba2adSLiam Girdwood 	.write = cx20442_write,
378f0fba2adSLiam Girdwood };
379f0fba2adSLiam Girdwood 
380f0fba2adSLiam Girdwood static int cx20442_platform_probe(struct platform_device *pdev)
381f0fba2adSLiam Girdwood {
382f0fba2adSLiam Girdwood 	return snd_soc_register_codec(&pdev->dev,
383f0fba2adSLiam Girdwood 			&cx20442_codec_dev, &cx20442_dai, 1);
384459dc352SJanusz Krzysztofik }
385459dc352SJanusz Krzysztofik 
386459dc352SJanusz Krzysztofik static int __exit cx20442_platform_remove(struct platform_device *pdev)
387459dc352SJanusz Krzysztofik {
388f0fba2adSLiam Girdwood 	snd_soc_unregister_codec(&pdev->dev);
389459dc352SJanusz Krzysztofik 	return 0;
390459dc352SJanusz Krzysztofik }
391459dc352SJanusz Krzysztofik 
392459dc352SJanusz Krzysztofik static struct platform_driver cx20442_platform_driver = {
393459dc352SJanusz Krzysztofik 	.driver = {
394f0fba2adSLiam Girdwood 		.name = "cx20442-codec",
395459dc352SJanusz Krzysztofik 		.owner = THIS_MODULE,
396459dc352SJanusz Krzysztofik 		},
397459dc352SJanusz Krzysztofik 	.probe = cx20442_platform_probe,
398459dc352SJanusz Krzysztofik 	.remove = __exit_p(cx20442_platform_remove),
399459dc352SJanusz Krzysztofik };
400459dc352SJanusz Krzysztofik 
401459dc352SJanusz Krzysztofik static int __init cx20442_init(void)
402459dc352SJanusz Krzysztofik {
403459dc352SJanusz Krzysztofik 	return platform_driver_register(&cx20442_platform_driver);
404459dc352SJanusz Krzysztofik }
405459dc352SJanusz Krzysztofik module_init(cx20442_init);
406459dc352SJanusz Krzysztofik 
407459dc352SJanusz Krzysztofik static void __exit cx20442_exit(void)
408459dc352SJanusz Krzysztofik {
409459dc352SJanusz Krzysztofik 	platform_driver_unregister(&cx20442_platform_driver);
410459dc352SJanusz Krzysztofik }
411459dc352SJanusz Krzysztofik module_exit(cx20442_exit);
412459dc352SJanusz Krzysztofik 
413459dc352SJanusz Krzysztofik MODULE_DESCRIPTION("ASoC CX20442-11 voice modem codec driver");
414459dc352SJanusz Krzysztofik MODULE_AUTHOR("Janusz Krzysztofik");
415459dc352SJanusz Krzysztofik MODULE_LICENSE("GPL");
416f0fba2adSLiam Girdwood MODULE_ALIAS("platform:cx20442-codec");
417