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> 21459dc352SJanusz Krzysztofik #include <sound/soc-dapm.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 { 92459dc352SJanusz Krzysztofik snd_soc_dapm_new_controls(codec, cx20442_dapm_widgets, 93459dc352SJanusz Krzysztofik ARRAY_SIZE(cx20442_dapm_widgets)); 94459dc352SJanusz Krzysztofik 95459dc352SJanusz Krzysztofik snd_soc_dapm_add_routes(codec, cx20442_audio_map, 96459dc352SJanusz Krzysztofik ARRAY_SIZE(cx20442_audio_map)); 97459dc352SJanusz Krzysztofik 98459dc352SJanusz Krzysztofik return 0; 99459dc352SJanusz Krzysztofik } 100459dc352SJanusz Krzysztofik 101459dc352SJanusz Krzysztofik static unsigned int cx20442_read_reg_cache(struct snd_soc_codec *codec, 102459dc352SJanusz Krzysztofik unsigned int reg) 103459dc352SJanusz Krzysztofik { 104459dc352SJanusz Krzysztofik u8 *reg_cache = codec->reg_cache; 105459dc352SJanusz Krzysztofik 106f0fba2adSLiam Girdwood if (reg >= codec->driver->reg_cache_size) 107459dc352SJanusz Krzysztofik return -EINVAL; 108459dc352SJanusz Krzysztofik 109459dc352SJanusz Krzysztofik return reg_cache[reg]; 110459dc352SJanusz Krzysztofik } 111459dc352SJanusz Krzysztofik 112459dc352SJanusz Krzysztofik enum v253_vls { 113459dc352SJanusz Krzysztofik V253_VLS_NONE = 0, 114459dc352SJanusz Krzysztofik V253_VLS_T, 115459dc352SJanusz Krzysztofik V253_VLS_L, 116459dc352SJanusz Krzysztofik V253_VLS_LT, 117459dc352SJanusz Krzysztofik V253_VLS_S, 118459dc352SJanusz Krzysztofik V253_VLS_ST, 119459dc352SJanusz Krzysztofik V253_VLS_M, 120459dc352SJanusz Krzysztofik V253_VLS_MST, 121459dc352SJanusz Krzysztofik V253_VLS_S1, 122459dc352SJanusz Krzysztofik V253_VLS_S1T, 123459dc352SJanusz Krzysztofik V253_VLS_MS1T, 124459dc352SJanusz Krzysztofik V253_VLS_M1, 125459dc352SJanusz Krzysztofik V253_VLS_M1ST, 126459dc352SJanusz Krzysztofik V253_VLS_M1S1T, 127459dc352SJanusz Krzysztofik V253_VLS_H, 128459dc352SJanusz Krzysztofik V253_VLS_HT, 129459dc352SJanusz Krzysztofik V253_VLS_MS, 130459dc352SJanusz Krzysztofik V253_VLS_MS1, 131459dc352SJanusz Krzysztofik V253_VLS_M1S, 132459dc352SJanusz Krzysztofik V253_VLS_M1S1, 133459dc352SJanusz Krzysztofik V253_VLS_TEST, 134459dc352SJanusz Krzysztofik }; 135459dc352SJanusz Krzysztofik 136459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vls(u8 value) 137459dc352SJanusz Krzysztofik { 138459dc352SJanusz Krzysztofik switch (value & ~(1 << CX20442_AGC)) { 139459dc352SJanusz Krzysztofik case 0: 140459dc352SJanusz Krzysztofik return V253_VLS_T; 141459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT): 142459dc352SJanusz Krzysztofik case (1 << CX20442_MIC): 143459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC): 144459dc352SJanusz Krzysztofik return V253_VLS_M1S1; 145459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT): 146459dc352SJanusz Krzysztofik case (1 << CX20442_TELIN): 147459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT) | (1 << CX20442_TELIN): 148459dc352SJanusz Krzysztofik return V253_VLS_L; 149459dc352SJanusz Krzysztofik case (1 << CX20442_TELOUT) | (1 << CX20442_MIC): 150459dc352SJanusz Krzysztofik return V253_VLS_NONE; 151459dc352SJanusz Krzysztofik } 152459dc352SJanusz Krzysztofik return -EINVAL; 153459dc352SJanusz Krzysztofik } 154459dc352SJanusz Krzysztofik static int cx20442_pm_to_v253_vsp(u8 value) 155459dc352SJanusz Krzysztofik { 156459dc352SJanusz Krzysztofik switch (value & ~(1 << CX20442_AGC)) { 157459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT): 158459dc352SJanusz Krzysztofik case (1 << CX20442_MIC): 159459dc352SJanusz Krzysztofik case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC): 160459dc352SJanusz Krzysztofik return (bool)(value & (1 << CX20442_AGC)); 161459dc352SJanusz Krzysztofik } 162459dc352SJanusz Krzysztofik return (value & (1 << CX20442_AGC)) ? -EINVAL : 0; 163459dc352SJanusz Krzysztofik } 164459dc352SJanusz Krzysztofik 165459dc352SJanusz Krzysztofik static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg, 166459dc352SJanusz Krzysztofik unsigned int value) 167459dc352SJanusz Krzysztofik { 168f0fba2adSLiam Girdwood struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); 169459dc352SJanusz Krzysztofik u8 *reg_cache = codec->reg_cache; 170459dc352SJanusz Krzysztofik int vls, vsp, old, len; 171459dc352SJanusz Krzysztofik char buf[18]; 172459dc352SJanusz Krzysztofik 173f0fba2adSLiam Girdwood if (reg >= codec->driver->reg_cache_size) 174459dc352SJanusz Krzysztofik return -EINVAL; 175459dc352SJanusz Krzysztofik 176b84eab08SJanusz Krzysztofik /* hw_write and control_data pointers required for talking to the modem 177ad120daeSJanusz Krzysztofik * are expected to be set by the line discipline initialization code */ 178f0fba2adSLiam Girdwood if (!codec->hw_write || !cx20442->control_data) 179459dc352SJanusz Krzysztofik return -EIO; 180459dc352SJanusz Krzysztofik 181459dc352SJanusz Krzysztofik old = reg_cache[reg]; 182459dc352SJanusz Krzysztofik reg_cache[reg] = value; 183459dc352SJanusz Krzysztofik 184459dc352SJanusz Krzysztofik vls = cx20442_pm_to_v253_vls(value); 185459dc352SJanusz Krzysztofik if (vls < 0) 186459dc352SJanusz Krzysztofik return vls; 187459dc352SJanusz Krzysztofik 188459dc352SJanusz Krzysztofik vsp = cx20442_pm_to_v253_vsp(value); 189459dc352SJanusz Krzysztofik if (vsp < 0) 190459dc352SJanusz Krzysztofik return vsp; 191459dc352SJanusz Krzysztofik 192459dc352SJanusz Krzysztofik if ((vls == V253_VLS_T) || 193459dc352SJanusz Krzysztofik (vls == cx20442_pm_to_v253_vls(old))) { 194459dc352SJanusz Krzysztofik if (vsp == cx20442_pm_to_v253_vsp(old)) 195459dc352SJanusz Krzysztofik return 0; 196459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp); 197459dc352SJanusz Krzysztofik } else if (vsp == cx20442_pm_to_v253_vsp(old)) 198459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls); 199459dc352SJanusz Krzysztofik else 200459dc352SJanusz Krzysztofik len = snprintf(buf, ARRAY_SIZE(buf), 201459dc352SJanusz Krzysztofik "at+vls=%d;+vsp=%d\r", vls, vsp); 202459dc352SJanusz Krzysztofik 203459dc352SJanusz Krzysztofik if (unlikely(len > (ARRAY_SIZE(buf) - 1))) 204459dc352SJanusz Krzysztofik return -ENOMEM; 205459dc352SJanusz Krzysztofik 2064977b03eSJanusz Krzysztofik dev_dbg(codec->dev, "%s: %s\n", __func__, buf); 207f0fba2adSLiam Girdwood if (codec->hw_write(cx20442->control_data, buf, len) != len) 208459dc352SJanusz Krzysztofik return -EIO; 209459dc352SJanusz Krzysztofik 210459dc352SJanusz Krzysztofik return 0; 211459dc352SJanusz Krzysztofik } 212459dc352SJanusz Krzysztofik 213ad120daeSJanusz Krzysztofik 214ad120daeSJanusz Krzysztofik /* 215ad120daeSJanusz Krzysztofik * Line discpline related code 216ad120daeSJanusz Krzysztofik * 217ad120daeSJanusz Krzysztofik * Any of the callback functions below can be used in two ways: 218ad120daeSJanusz Krzysztofik * 1) registerd by a machine driver as one of line discipline operations, 219ad120daeSJanusz Krzysztofik * 2) called from a machine's provided line discipline callback function 220ad120daeSJanusz Krzysztofik * in case when extra machine specific code must be run as well. 221ad120daeSJanusz Krzysztofik */ 222ad120daeSJanusz Krzysztofik 223ad120daeSJanusz Krzysztofik /* Modem init: echo off, digital speaker off, quiet off, voice mode */ 224ad120daeSJanusz Krzysztofik static const char *v253_init = "ate0m0q0+fclass=8\r"; 225ad120daeSJanusz Krzysztofik 226ad120daeSJanusz Krzysztofik /* Line discipline .open() */ 227ad120daeSJanusz Krzysztofik static int v253_open(struct tty_struct *tty) 228ad120daeSJanusz Krzysztofik { 229ad120daeSJanusz Krzysztofik int ret, len = strlen(v253_init); 230ad120daeSJanusz Krzysztofik 231ad120daeSJanusz Krzysztofik /* Doesn't make sense without write callback */ 232ad120daeSJanusz Krzysztofik if (!tty->ops->write) 233ad120daeSJanusz Krzysztofik return -EINVAL; 234ad120daeSJanusz Krzysztofik 235f0fba2adSLiam Girdwood /* Won't work if no codec pointer has been passed by a card driver */ 236f0fba2adSLiam Girdwood if (!tty->disc_data) 237f0fba2adSLiam Girdwood return -ENODEV; 238ad120daeSJanusz Krzysztofik 239ad120daeSJanusz Krzysztofik if (tty->ops->write(tty, v253_init, len) != len) { 240ad120daeSJanusz Krzysztofik ret = -EIO; 241ad120daeSJanusz Krzysztofik goto err; 242ad120daeSJanusz Krzysztofik } 243ad120daeSJanusz Krzysztofik /* Actual setup will be performed after the modem responds. */ 244ad120daeSJanusz Krzysztofik return 0; 245ad120daeSJanusz Krzysztofik err: 246ad120daeSJanusz Krzysztofik tty->disc_data = NULL; 247ad120daeSJanusz Krzysztofik return ret; 248ad120daeSJanusz Krzysztofik } 249ad120daeSJanusz Krzysztofik 250ad120daeSJanusz Krzysztofik /* Line discipline .close() */ 251ad120daeSJanusz Krzysztofik static void v253_close(struct tty_struct *tty) 252ad120daeSJanusz Krzysztofik { 253ad120daeSJanusz Krzysztofik struct snd_soc_codec *codec = tty->disc_data; 254f0fba2adSLiam Girdwood struct cx20442_priv *cx20442; 255ad120daeSJanusz Krzysztofik 256ad120daeSJanusz Krzysztofik tty->disc_data = NULL; 257ad120daeSJanusz Krzysztofik 258ad120daeSJanusz Krzysztofik if (!codec) 259ad120daeSJanusz Krzysztofik return; 260ad120daeSJanusz Krzysztofik 261f0fba2adSLiam Girdwood cx20442 = snd_soc_codec_get_drvdata(codec); 262f0fba2adSLiam Girdwood 263ad120daeSJanusz Krzysztofik /* Prevent the codec driver from further accessing the modem */ 264ad120daeSJanusz Krzysztofik codec->hw_write = NULL; 265f0fba2adSLiam Girdwood cx20442->control_data = NULL; 266ad120daeSJanusz Krzysztofik codec->pop_time = 0; 267ad120daeSJanusz Krzysztofik } 268ad120daeSJanusz Krzysztofik 269ad120daeSJanusz Krzysztofik /* Line discipline .hangup() */ 270ad120daeSJanusz Krzysztofik static int v253_hangup(struct tty_struct *tty) 271ad120daeSJanusz Krzysztofik { 272ad120daeSJanusz Krzysztofik v253_close(tty); 273ad120daeSJanusz Krzysztofik return 0; 274ad120daeSJanusz Krzysztofik } 275ad120daeSJanusz Krzysztofik 276ad120daeSJanusz Krzysztofik /* Line discipline .receive_buf() */ 277ad120daeSJanusz Krzysztofik static void v253_receive(struct tty_struct *tty, 278ad120daeSJanusz Krzysztofik const unsigned char *cp, char *fp, int count) 279ad120daeSJanusz Krzysztofik { 280ad120daeSJanusz Krzysztofik struct snd_soc_codec *codec = tty->disc_data; 281f0fba2adSLiam Girdwood struct cx20442_priv *cx20442; 282ad120daeSJanusz Krzysztofik 283ad120daeSJanusz Krzysztofik if (!codec) 284ad120daeSJanusz Krzysztofik return; 285ad120daeSJanusz Krzysztofik 286f0fba2adSLiam Girdwood cx20442 = snd_soc_codec_get_drvdata(codec); 287f0fba2adSLiam Girdwood 288f0fba2adSLiam Girdwood if (!cx20442->control_data) { 289ad120daeSJanusz Krzysztofik /* First modem response, complete setup procedure */ 290ad120daeSJanusz Krzysztofik 291ad120daeSJanusz Krzysztofik /* Set up codec driver access to modem controls */ 292f0fba2adSLiam Girdwood cx20442->control_data = tty; 293ad120daeSJanusz Krzysztofik codec->hw_write = (hw_write_t)tty->ops->write; 294ad120daeSJanusz Krzysztofik codec->pop_time = 1; 295ad120daeSJanusz Krzysztofik } 296ad120daeSJanusz Krzysztofik } 297ad120daeSJanusz Krzysztofik 298ad120daeSJanusz Krzysztofik /* Line discipline .write_wakeup() */ 299ad120daeSJanusz Krzysztofik static void v253_wakeup(struct tty_struct *tty) 300ad120daeSJanusz Krzysztofik { 301ad120daeSJanusz Krzysztofik } 302ad120daeSJanusz Krzysztofik 303ad120daeSJanusz Krzysztofik struct tty_ldisc_ops v253_ops = { 304ad120daeSJanusz Krzysztofik .magic = TTY_LDISC_MAGIC, 305ad120daeSJanusz Krzysztofik .name = "cx20442", 306ad120daeSJanusz Krzysztofik .owner = THIS_MODULE, 307ad120daeSJanusz Krzysztofik .open = v253_open, 308ad120daeSJanusz Krzysztofik .close = v253_close, 309ad120daeSJanusz Krzysztofik .hangup = v253_hangup, 310ad120daeSJanusz Krzysztofik .receive_buf = v253_receive, 311ad120daeSJanusz Krzysztofik .write_wakeup = v253_wakeup, 312ad120daeSJanusz Krzysztofik }; 313ad120daeSJanusz Krzysztofik EXPORT_SYMBOL_GPL(v253_ops); 314ad120daeSJanusz Krzysztofik 315ad120daeSJanusz Krzysztofik 316ad120daeSJanusz Krzysztofik /* 317ad120daeSJanusz Krzysztofik * Codec DAI 318ad120daeSJanusz Krzysztofik */ 319ad120daeSJanusz Krzysztofik 320f0fba2adSLiam Girdwood static struct snd_soc_dai_driver cx20442_dai = { 321*5394637aSJanusz Krzysztofik .name = "cx20442-voice", 322459dc352SJanusz Krzysztofik .playback = { 323459dc352SJanusz Krzysztofik .stream_name = "Playback", 324459dc352SJanusz Krzysztofik .channels_min = 1, 325459dc352SJanusz Krzysztofik .channels_max = 1, 326459dc352SJanusz Krzysztofik .rates = SNDRV_PCM_RATE_8000, 327459dc352SJanusz Krzysztofik .formats = SNDRV_PCM_FMTBIT_S16_LE, 328459dc352SJanusz Krzysztofik }, 329459dc352SJanusz Krzysztofik .capture = { 330459dc352SJanusz Krzysztofik .stream_name = "Capture", 331459dc352SJanusz Krzysztofik .channels_min = 1, 332459dc352SJanusz Krzysztofik .channels_max = 1, 333459dc352SJanusz Krzysztofik .rates = SNDRV_PCM_RATE_8000, 334459dc352SJanusz Krzysztofik .formats = SNDRV_PCM_FMTBIT_S16_LE, 335459dc352SJanusz Krzysztofik }, 336459dc352SJanusz Krzysztofik }; 337459dc352SJanusz Krzysztofik 338f0fba2adSLiam Girdwood static int cx20442_codec_probe(struct snd_soc_codec *codec) 339459dc352SJanusz Krzysztofik { 340459dc352SJanusz Krzysztofik struct cx20442_priv *cx20442; 341459dc352SJanusz Krzysztofik 342459dc352SJanusz Krzysztofik cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL); 343459dc352SJanusz Krzysztofik if (cx20442 == NULL) 344459dc352SJanusz Krzysztofik return -ENOMEM; 345f0fba2adSLiam Girdwood snd_soc_codec_set_drvdata(codec, cx20442); 346459dc352SJanusz Krzysztofik 347f0fba2adSLiam Girdwood cx20442_add_widgets(codec); 348459dc352SJanusz Krzysztofik 349f0fba2adSLiam Girdwood cx20442->control_data = NULL; 350459dc352SJanusz Krzysztofik codec->hw_write = NULL; 351459dc352SJanusz Krzysztofik codec->pop_time = 0; 352459dc352SJanusz Krzysztofik 353f0fba2adSLiam Girdwood return 0; 354f0fba2adSLiam Girdwood } 355459dc352SJanusz Krzysztofik 356f0fba2adSLiam Girdwood /* power down chip */ 357f0fba2adSLiam Girdwood static int cx20442_codec_remove(struct snd_soc_codec *codec) 358f0fba2adSLiam Girdwood { 359f0fba2adSLiam Girdwood struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); 360f0fba2adSLiam Girdwood 361f0fba2adSLiam Girdwood if (cx20442->control_data) { 362f0fba2adSLiam Girdwood struct tty_struct *tty = cx20442->control_data; 363f0fba2adSLiam Girdwood tty_hangup(tty); 364f0fba2adSLiam Girdwood } 365f0fba2adSLiam Girdwood 366f0fba2adSLiam Girdwood kfree(cx20442); 367f0fba2adSLiam Girdwood return 0; 368f0fba2adSLiam Girdwood } 369f0fba2adSLiam Girdwood 370f0fba2adSLiam Girdwood static struct snd_soc_codec_driver cx20442_codec_dev = { 371f0fba2adSLiam Girdwood .probe = cx20442_codec_probe, 372f0fba2adSLiam Girdwood .remove = cx20442_codec_remove, 373f0fba2adSLiam Girdwood .reg_cache_size = 1, 374f0fba2adSLiam Girdwood .reg_word_size = sizeof(u8), 375f0fba2adSLiam Girdwood .read = cx20442_read_reg_cache, 376f0fba2adSLiam Girdwood .write = cx20442_write, 377f0fba2adSLiam Girdwood }; 378f0fba2adSLiam Girdwood 379f0fba2adSLiam Girdwood static int cx20442_platform_probe(struct platform_device *pdev) 380f0fba2adSLiam Girdwood { 381f0fba2adSLiam Girdwood return snd_soc_register_codec(&pdev->dev, 382f0fba2adSLiam Girdwood &cx20442_codec_dev, &cx20442_dai, 1); 383459dc352SJanusz Krzysztofik } 384459dc352SJanusz Krzysztofik 385459dc352SJanusz Krzysztofik static int __exit cx20442_platform_remove(struct platform_device *pdev) 386459dc352SJanusz Krzysztofik { 387f0fba2adSLiam Girdwood snd_soc_unregister_codec(&pdev->dev); 388459dc352SJanusz Krzysztofik return 0; 389459dc352SJanusz Krzysztofik } 390459dc352SJanusz Krzysztofik 391459dc352SJanusz Krzysztofik static struct platform_driver cx20442_platform_driver = { 392459dc352SJanusz Krzysztofik .driver = { 393f0fba2adSLiam Girdwood .name = "cx20442-codec", 394459dc352SJanusz Krzysztofik .owner = THIS_MODULE, 395459dc352SJanusz Krzysztofik }, 396459dc352SJanusz Krzysztofik .probe = cx20442_platform_probe, 397459dc352SJanusz Krzysztofik .remove = __exit_p(cx20442_platform_remove), 398459dc352SJanusz Krzysztofik }; 399459dc352SJanusz Krzysztofik 400459dc352SJanusz Krzysztofik static int __init cx20442_init(void) 401459dc352SJanusz Krzysztofik { 402459dc352SJanusz Krzysztofik return platform_driver_register(&cx20442_platform_driver); 403459dc352SJanusz Krzysztofik } 404459dc352SJanusz Krzysztofik module_init(cx20442_init); 405459dc352SJanusz Krzysztofik 406459dc352SJanusz Krzysztofik static void __exit cx20442_exit(void) 407459dc352SJanusz Krzysztofik { 408459dc352SJanusz Krzysztofik platform_driver_unregister(&cx20442_platform_driver); 409459dc352SJanusz Krzysztofik } 410459dc352SJanusz Krzysztofik module_exit(cx20442_exit); 411459dc352SJanusz Krzysztofik 412459dc352SJanusz Krzysztofik MODULE_DESCRIPTION("ASoC CX20442-11 voice modem codec driver"); 413459dc352SJanusz Krzysztofik MODULE_AUTHOR("Janusz Krzysztofik"); 414459dc352SJanusz Krzysztofik MODULE_LICENSE("GPL"); 415f0fba2adSLiam Girdwood MODULE_ALIAS("platform:cx20442-codec"); 416