Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cx20442.c -- CX20442 ALSA Soc Audio driver |
| 3 | * |
| 4 | * Copyright 2009 Janusz Krzysztofik <jkrzyszt@tis.icnet.pl> |
| 5 | * |
| 6 | * Initially based on sound/soc/codecs/wm8400.c |
| 7 | * Copyright 2008, 2009 Wolfson Microelectronics PLC. |
| 8 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | */ |
| 15 | |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 16 | #include <linux/tty.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 18 | #include <linux/module.h> |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 19 | #include <linux/regulator/consumer.h> |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 20 | |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 21 | #include <sound/core.h> |
| 22 | #include <sound/initval.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 23 | #include <sound/soc.h> |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 24 | |
| 25 | #include "cx20442.h" |
| 26 | |
| 27 | |
| 28 | struct cx20442_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 29 | void *control_data; |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 30 | struct regulator *por; |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | #define CX20442_PM 0x0 |
| 34 | |
| 35 | #define CX20442_TELIN 0 |
| 36 | #define CX20442_TELOUT 1 |
| 37 | #define CX20442_MIC 2 |
| 38 | #define CX20442_SPKOUT 3 |
| 39 | #define CX20442_AGC 4 |
| 40 | |
| 41 | static const struct snd_soc_dapm_widget cx20442_dapm_widgets[] = { |
| 42 | SND_SOC_DAPM_OUTPUT("TELOUT"), |
| 43 | SND_SOC_DAPM_OUTPUT("SPKOUT"), |
| 44 | SND_SOC_DAPM_OUTPUT("AGCOUT"), |
| 45 | |
| 46 | SND_SOC_DAPM_MIXER("SPKOUT Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 47 | |
| 48 | SND_SOC_DAPM_PGA("TELOUT Amp", CX20442_PM, CX20442_TELOUT, 0, NULL, 0), |
| 49 | SND_SOC_DAPM_PGA("SPKOUT Amp", CX20442_PM, CX20442_SPKOUT, 0, NULL, 0), |
| 50 | SND_SOC_DAPM_PGA("SPKOUT AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0), |
| 51 | |
| 52 | SND_SOC_DAPM_DAC("DAC", "Playback", SND_SOC_NOPM, 0, 0), |
| 53 | SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0), |
| 54 | |
| 55 | SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 56 | |
| 57 | SND_SOC_DAPM_MICBIAS("TELIN Bias", CX20442_PM, CX20442_TELIN, 0), |
| 58 | SND_SOC_DAPM_MICBIAS("MIC Bias", CX20442_PM, CX20442_MIC, 0), |
| 59 | |
| 60 | SND_SOC_DAPM_PGA("MIC AGC", CX20442_PM, CX20442_AGC, 0, NULL, 0), |
| 61 | |
| 62 | SND_SOC_DAPM_INPUT("TELIN"), |
| 63 | SND_SOC_DAPM_INPUT("MIC"), |
| 64 | SND_SOC_DAPM_INPUT("AGCIN"), |
| 65 | }; |
| 66 | |
| 67 | static const struct snd_soc_dapm_route cx20442_audio_map[] = { |
| 68 | {"TELOUT", NULL, "TELOUT Amp"}, |
| 69 | |
| 70 | {"SPKOUT", NULL, "SPKOUT Mixer"}, |
| 71 | {"SPKOUT Mixer", NULL, "SPKOUT Amp"}, |
| 72 | |
| 73 | {"TELOUT Amp", NULL, "DAC"}, |
| 74 | {"SPKOUT Amp", NULL, "DAC"}, |
| 75 | |
| 76 | {"SPKOUT Mixer", NULL, "SPKOUT AGC"}, |
| 77 | {"SPKOUT AGC", NULL, "AGCIN"}, |
| 78 | |
| 79 | {"AGCOUT", NULL, "MIC AGC"}, |
| 80 | {"MIC AGC", NULL, "MIC"}, |
| 81 | |
| 82 | {"MIC Bias", NULL, "MIC"}, |
| 83 | {"Input Mixer", NULL, "MIC Bias"}, |
| 84 | |
| 85 | {"TELIN Bias", NULL, "TELIN"}, |
| 86 | {"Input Mixer", NULL, "TELIN Bias"}, |
| 87 | |
| 88 | {"ADC", NULL, "Input Mixer"}, |
| 89 | }; |
| 90 | |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 91 | static unsigned int cx20442_read_reg_cache(struct snd_soc_codec *codec, |
| 92 | unsigned int reg) |
| 93 | { |
| 94 | u8 *reg_cache = codec->reg_cache; |
| 95 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 96 | if (reg >= codec->driver->reg_cache_size) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 97 | return -EINVAL; |
| 98 | |
| 99 | return reg_cache[reg]; |
| 100 | } |
| 101 | |
| 102 | enum v253_vls { |
| 103 | V253_VLS_NONE = 0, |
| 104 | V253_VLS_T, |
| 105 | V253_VLS_L, |
| 106 | V253_VLS_LT, |
| 107 | V253_VLS_S, |
| 108 | V253_VLS_ST, |
| 109 | V253_VLS_M, |
| 110 | V253_VLS_MST, |
| 111 | V253_VLS_S1, |
| 112 | V253_VLS_S1T, |
| 113 | V253_VLS_MS1T, |
| 114 | V253_VLS_M1, |
| 115 | V253_VLS_M1ST, |
| 116 | V253_VLS_M1S1T, |
| 117 | V253_VLS_H, |
| 118 | V253_VLS_HT, |
| 119 | V253_VLS_MS, |
| 120 | V253_VLS_MS1, |
| 121 | V253_VLS_M1S, |
| 122 | V253_VLS_M1S1, |
| 123 | V253_VLS_TEST, |
| 124 | }; |
| 125 | |
| 126 | static int cx20442_pm_to_v253_vls(u8 value) |
| 127 | { |
Janusz Krzysztofik | b84eab0 | 2009-07-28 20:24:12 +0200 | [diff] [blame] | 128 | switch (value & ~(1 << CX20442_AGC)) { |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 129 | case 0: |
| 130 | return V253_VLS_T; |
| 131 | case (1 << CX20442_SPKOUT): |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 132 | case (1 << CX20442_MIC): |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 133 | case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC): |
| 134 | return V253_VLS_M1S1; |
| 135 | case (1 << CX20442_TELOUT): |
| 136 | case (1 << CX20442_TELIN): |
| 137 | case (1 << CX20442_TELOUT) | (1 << CX20442_TELIN): |
| 138 | return V253_VLS_L; |
| 139 | case (1 << CX20442_TELOUT) | (1 << CX20442_MIC): |
| 140 | return V253_VLS_NONE; |
| 141 | } |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | static int cx20442_pm_to_v253_vsp(u8 value) |
| 145 | { |
Janusz Krzysztofik | b84eab0 | 2009-07-28 20:24:12 +0200 | [diff] [blame] | 146 | switch (value & ~(1 << CX20442_AGC)) { |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 147 | case (1 << CX20442_SPKOUT): |
| 148 | case (1 << CX20442_MIC): |
| 149 | case (1 << CX20442_SPKOUT) | (1 << CX20442_MIC): |
| 150 | return (bool)(value & (1 << CX20442_AGC)); |
| 151 | } |
| 152 | return (value & (1 << CX20442_AGC)) ? -EINVAL : 0; |
| 153 | } |
| 154 | |
| 155 | static int cx20442_write(struct snd_soc_codec *codec, unsigned int reg, |
| 156 | unsigned int value) |
| 157 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 158 | struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 159 | u8 *reg_cache = codec->reg_cache; |
| 160 | int vls, vsp, old, len; |
| 161 | char buf[18]; |
| 162 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 163 | if (reg >= codec->driver->reg_cache_size) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 164 | return -EINVAL; |
| 165 | |
Janusz Krzysztofik | b84eab0 | 2009-07-28 20:24:12 +0200 | [diff] [blame] | 166 | /* hw_write and control_data pointers required for talking to the modem |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 167 | * are expected to be set by the line discipline initialization code */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 168 | if (!codec->hw_write || !cx20442->control_data) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 169 | return -EIO; |
| 170 | |
| 171 | old = reg_cache[reg]; |
| 172 | reg_cache[reg] = value; |
| 173 | |
| 174 | vls = cx20442_pm_to_v253_vls(value); |
| 175 | if (vls < 0) |
| 176 | return vls; |
| 177 | |
| 178 | vsp = cx20442_pm_to_v253_vsp(value); |
Janusz Krzysztofik | b84eab0 | 2009-07-28 20:24:12 +0200 | [diff] [blame] | 179 | if (vsp < 0) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 180 | return vsp; |
| 181 | |
| 182 | if ((vls == V253_VLS_T) || |
| 183 | (vls == cx20442_pm_to_v253_vls(old))) { |
| 184 | if (vsp == cx20442_pm_to_v253_vsp(old)) |
| 185 | return 0; |
| 186 | len = snprintf(buf, ARRAY_SIZE(buf), "at+vsp=%d\r", vsp); |
| 187 | } else if (vsp == cx20442_pm_to_v253_vsp(old)) |
| 188 | len = snprintf(buf, ARRAY_SIZE(buf), "at+vls=%d\r", vls); |
| 189 | else |
| 190 | len = snprintf(buf, ARRAY_SIZE(buf), |
| 191 | "at+vls=%d;+vsp=%d\r", vls, vsp); |
| 192 | |
| 193 | if (unlikely(len > (ARRAY_SIZE(buf) - 1))) |
| 194 | return -ENOMEM; |
| 195 | |
Janusz Krzysztofik | 4977b03 | 2009-08-06 12:24:54 +0200 | [diff] [blame] | 196 | dev_dbg(codec->dev, "%s: %s\n", __func__, buf); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 197 | if (codec->hw_write(cx20442->control_data, buf, len) != len) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 198 | return -EIO; |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 203 | |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 204 | /* |
| 205 | * Line discpline related code |
| 206 | * |
| 207 | * Any of the callback functions below can be used in two ways: |
| 208 | * 1) registerd by a machine driver as one of line discipline operations, |
| 209 | * 2) called from a machine's provided line discipline callback function |
| 210 | * in case when extra machine specific code must be run as well. |
| 211 | */ |
| 212 | |
| 213 | /* Modem init: echo off, digital speaker off, quiet off, voice mode */ |
| 214 | static const char *v253_init = "ate0m0q0+fclass=8\r"; |
| 215 | |
| 216 | /* Line discipline .open() */ |
| 217 | static int v253_open(struct tty_struct *tty) |
| 218 | { |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 219 | int ret, len = strlen(v253_init); |
| 220 | |
| 221 | /* Doesn't make sense without write callback */ |
| 222 | if (!tty->ops->write) |
| 223 | return -EINVAL; |
| 224 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 225 | /* Won't work if no codec pointer has been passed by a card driver */ |
| 226 | if (!tty->disc_data) |
| 227 | return -ENODEV; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 228 | |
Janusz Krzysztofik | 86c0ae7 | 2016-06-16 22:04:35 +0200 | [diff] [blame] | 229 | tty->receive_room = 16; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 230 | if (tty->ops->write(tty, v253_init, len) != len) { |
| 231 | ret = -EIO; |
| 232 | goto err; |
| 233 | } |
| 234 | /* Actual setup will be performed after the modem responds. */ |
| 235 | return 0; |
| 236 | err: |
| 237 | tty->disc_data = NULL; |
| 238 | return ret; |
| 239 | } |
| 240 | |
| 241 | /* Line discipline .close() */ |
| 242 | static void v253_close(struct tty_struct *tty) |
| 243 | { |
| 244 | struct snd_soc_codec *codec = tty->disc_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 245 | struct cx20442_priv *cx20442; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 246 | |
| 247 | tty->disc_data = NULL; |
| 248 | |
| 249 | if (!codec) |
| 250 | return; |
| 251 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 252 | cx20442 = snd_soc_codec_get_drvdata(codec); |
| 253 | |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 254 | /* Prevent the codec driver from further accessing the modem */ |
| 255 | codec->hw_write = NULL; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 256 | cx20442->control_data = NULL; |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 257 | codec->component.card->pop_time = 0; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* Line discipline .hangup() */ |
| 261 | static int v253_hangup(struct tty_struct *tty) |
| 262 | { |
| 263 | v253_close(tty); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | /* Line discipline .receive_buf() */ |
Linus Torvalds | bb3d6bf | 2011-06-04 07:00:50 +0900 | [diff] [blame] | 268 | static void v253_receive(struct tty_struct *tty, |
| 269 | const unsigned char *cp, char *fp, int count) |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 270 | { |
| 271 | struct snd_soc_codec *codec = tty->disc_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 272 | struct cx20442_priv *cx20442; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 273 | |
| 274 | if (!codec) |
Linus Torvalds | bb3d6bf | 2011-06-04 07:00:50 +0900 | [diff] [blame] | 275 | return; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 276 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 277 | cx20442 = snd_soc_codec_get_drvdata(codec); |
| 278 | |
| 279 | if (!cx20442->control_data) { |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 280 | /* First modem response, complete setup procedure */ |
| 281 | |
| 282 | /* Set up codec driver access to modem controls */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 283 | cx20442->control_data = tty; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 284 | codec->hw_write = (hw_write_t)tty->ops->write; |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 285 | codec->component.card->pop_time = 1; |
Janusz Krzysztofik | ad120da | 2009-07-29 12:24:46 +0200 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
| 289 | /* Line discipline .write_wakeup() */ |
| 290 | static void v253_wakeup(struct tty_struct *tty) |
| 291 | { |
| 292 | } |
| 293 | |
| 294 | struct tty_ldisc_ops v253_ops = { |
| 295 | .magic = TTY_LDISC_MAGIC, |
| 296 | .name = "cx20442", |
| 297 | .owner = THIS_MODULE, |
| 298 | .open = v253_open, |
| 299 | .close = v253_close, |
| 300 | .hangup = v253_hangup, |
| 301 | .receive_buf = v253_receive, |
| 302 | .write_wakeup = v253_wakeup, |
| 303 | }; |
| 304 | EXPORT_SYMBOL_GPL(v253_ops); |
| 305 | |
| 306 | |
| 307 | /* |
| 308 | * Codec DAI |
| 309 | */ |
| 310 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 311 | static struct snd_soc_dai_driver cx20442_dai = { |
Janusz Krzysztofik | 5394637 | 2010-08-19 15:15:50 +0200 | [diff] [blame] | 312 | .name = "cx20442-voice", |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 313 | .playback = { |
| 314 | .stream_name = "Playback", |
| 315 | .channels_min = 1, |
| 316 | .channels_max = 1, |
| 317 | .rates = SNDRV_PCM_RATE_8000, |
| 318 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 319 | }, |
| 320 | .capture = { |
| 321 | .stream_name = "Capture", |
| 322 | .channels_min = 1, |
| 323 | .channels_max = 1, |
| 324 | .rates = SNDRV_PCM_RATE_8000, |
| 325 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 326 | }, |
| 327 | }; |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 328 | |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 329 | static int cx20442_set_bias_level(struct snd_soc_codec *codec, |
| 330 | enum snd_soc_bias_level level) |
| 331 | { |
| 332 | struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); |
| 333 | int err = 0; |
| 334 | |
| 335 | switch (level) { |
| 336 | case SND_SOC_BIAS_PREPARE: |
Lars-Peter Clausen | 3f36f3c | 2015-05-11 09:42:29 +0200 | [diff] [blame] | 337 | if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_STANDBY) |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 338 | break; |
| 339 | if (IS_ERR(cx20442->por)) |
| 340 | err = PTR_ERR(cx20442->por); |
| 341 | else |
| 342 | err = regulator_enable(cx20442->por); |
| 343 | break; |
| 344 | case SND_SOC_BIAS_STANDBY: |
Lars-Peter Clausen | 3f36f3c | 2015-05-11 09:42:29 +0200 | [diff] [blame] | 345 | if (snd_soc_codec_get_bias_level(codec) != SND_SOC_BIAS_PREPARE) |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 346 | break; |
| 347 | if (IS_ERR(cx20442->por)) |
| 348 | err = PTR_ERR(cx20442->por); |
| 349 | else |
| 350 | err = regulator_disable(cx20442->por); |
| 351 | break; |
| 352 | default: |
| 353 | break; |
| 354 | } |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 355 | |
| 356 | return err; |
| 357 | } |
| 358 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 359 | static int cx20442_codec_probe(struct snd_soc_codec *codec) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 360 | { |
| 361 | struct cx20442_priv *cx20442; |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 362 | |
| 363 | cx20442 = kzalloc(sizeof(struct cx20442_priv), GFP_KERNEL); |
| 364 | if (cx20442 == NULL) |
| 365 | return -ENOMEM; |
| 366 | |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 367 | cx20442->por = regulator_get(codec->dev, "POR"); |
| 368 | if (IS_ERR(cx20442->por)) |
| 369 | dev_warn(codec->dev, "failed to get the regulator"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 370 | cx20442->control_data = NULL; |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 371 | |
| 372 | snd_soc_codec_set_drvdata(codec, cx20442); |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 373 | codec->hw_write = NULL; |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 374 | codec->component.card->pop_time = 0; |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 375 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 376 | return 0; |
| 377 | } |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 378 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 379 | /* power down chip */ |
| 380 | static int cx20442_codec_remove(struct snd_soc_codec *codec) |
| 381 | { |
| 382 | struct cx20442_priv *cx20442 = snd_soc_codec_get_drvdata(codec); |
| 383 | |
| 384 | if (cx20442->control_data) { |
Mark Brown | aaed2a6 | 2014-03-04 17:20:56 +0800 | [diff] [blame] | 385 | struct tty_struct *tty = cx20442->control_data; |
| 386 | tty_hangup(tty); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 389 | if (!IS_ERR(cx20442->por)) { |
| 390 | /* should be already in STANDBY, hence disabled */ |
| 391 | regulator_put(cx20442->por); |
| 392 | } |
| 393 | |
| 394 | snd_soc_codec_set_drvdata(codec, NULL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 395 | kfree(cx20442); |
| 396 | return 0; |
| 397 | } |
| 398 | |
Janusz Krzysztofik | 8e6bfb9 | 2011-02-10 13:24:32 +0100 | [diff] [blame] | 399 | static const u8 cx20442_reg; |
Janusz Krzysztofik | f019ee5 | 2011-02-01 13:01:17 +0100 | [diff] [blame] | 400 | |
Bhumika Goyal | a180ba4 | 2017-08-03 21:30:19 +0530 | [diff] [blame^] | 401 | static const struct snd_soc_codec_driver cx20442_codec_dev = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 402 | .probe = cx20442_codec_probe, |
| 403 | .remove = cx20442_codec_remove, |
Janusz Krzysztofik | f75a8ff | 2011-12-30 04:04:54 +0100 | [diff] [blame] | 404 | .set_bias_level = cx20442_set_bias_level, |
Janusz Krzysztofik | f019ee5 | 2011-02-01 13:01:17 +0100 | [diff] [blame] | 405 | .reg_cache_default = &cx20442_reg, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 406 | .reg_cache_size = 1, |
| 407 | .reg_word_size = sizeof(u8), |
| 408 | .read = cx20442_read_reg_cache, |
| 409 | .write = cx20442_write, |
Kuninori Morimoto | a2c9c0f | 2016-08-08 09:14:19 +0000 | [diff] [blame] | 410 | .component_driver = { |
| 411 | .dapm_widgets = cx20442_dapm_widgets, |
| 412 | .num_dapm_widgets = ARRAY_SIZE(cx20442_dapm_widgets), |
| 413 | .dapm_routes = cx20442_audio_map, |
| 414 | .num_dapm_routes = ARRAY_SIZE(cx20442_audio_map), |
| 415 | }, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | static int cx20442_platform_probe(struct platform_device *pdev) |
| 419 | { |
| 420 | return snd_soc_register_codec(&pdev->dev, |
| 421 | &cx20442_codec_dev, &cx20442_dai, 1); |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Dmitry Torokhov | 3255639 | 2015-03-09 11:15:28 -0700 | [diff] [blame] | 424 | static int cx20442_platform_remove(struct platform_device *pdev) |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 425 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 426 | snd_soc_unregister_codec(&pdev->dev); |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static struct platform_driver cx20442_platform_driver = { |
| 431 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 432 | .name = "cx20442-codec", |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 433 | }, |
| 434 | .probe = cx20442_platform_probe, |
Dmitry Torokhov | 3255639 | 2015-03-09 11:15:28 -0700 | [diff] [blame] | 435 | .remove = cx20442_platform_remove, |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 436 | }; |
| 437 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 438 | module_platform_driver(cx20442_platform_driver); |
Janusz Krzysztofik | 459dc35 | 2009-07-22 05:22:28 +0200 | [diff] [blame] | 439 | |
| 440 | MODULE_DESCRIPTION("ASoC CX20442-11 voice modem codec driver"); |
| 441 | MODULE_AUTHOR("Janusz Krzysztofik"); |
| 442 | MODULE_LICENSE("GPL"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 443 | MODULE_ALIAS("platform:cx20442-codec"); |