Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * wm8728.c -- WM8728 ALSA SoC Audio driver |
| 3 | * |
| 4 | * Copyright 2008 Wolfson Microelectronics plc |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/pm.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/spi/spi.h> |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
| 24 | #include <sound/soc.h> |
| 25 | #include <sound/soc-dapm.h> |
| 26 | #include <sound/initval.h> |
| 27 | #include <sound/tlv.h> |
| 28 | |
| 29 | #include "wm8728.h" |
| 30 | |
| 31 | struct snd_soc_codec_device soc_codec_dev_wm8728; |
| 32 | |
| 33 | /* |
| 34 | * We can't read the WM8728 register space so we cache them instead. |
| 35 | * Note that the defaults here aren't the physical defaults, we latch |
| 36 | * the volume update bits, mute the output and enable infinite zero |
| 37 | * detect. |
| 38 | */ |
| 39 | static const u16 wm8728_reg_defaults[] = { |
| 40 | 0x1ff, |
| 41 | 0x1ff, |
| 42 | 0x001, |
| 43 | 0x100, |
| 44 | }; |
| 45 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 46 | static const DECLARE_TLV_DB_SCALE(wm8728_tlv, -12750, 50, 1); |
| 47 | |
| 48 | static const struct snd_kcontrol_new wm8728_snd_controls[] = { |
| 49 | |
| 50 | SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8728_DACLVOL, WM8728_DACRVOL, |
| 51 | 0, 255, 0, wm8728_tlv), |
| 52 | |
| 53 | SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), |
| 54 | }; |
| 55 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 56 | /* |
| 57 | * DAPM controls. |
| 58 | */ |
| 59 | static const struct snd_soc_dapm_widget wm8728_dapm_widgets[] = { |
| 60 | SND_SOC_DAPM_DAC("DAC", "HiFi Playback", SND_SOC_NOPM, 0, 0), |
| 61 | SND_SOC_DAPM_OUTPUT("VOUTL"), |
| 62 | SND_SOC_DAPM_OUTPUT("VOUTR"), |
| 63 | }; |
| 64 | |
| 65 | static const struct snd_soc_dapm_route intercon[] = { |
| 66 | {"VOUTL", NULL, "DAC"}, |
| 67 | {"VOUTR", NULL, "DAC"}, |
| 68 | }; |
| 69 | |
| 70 | static int wm8728_add_widgets(struct snd_soc_codec *codec) |
| 71 | { |
| 72 | snd_soc_dapm_new_controls(codec, wm8728_dapm_widgets, |
| 73 | ARRAY_SIZE(wm8728_dapm_widgets)); |
| 74 | |
| 75 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); |
| 76 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static int wm8728_mute(struct snd_soc_dai *dai, int mute) |
| 81 | { |
| 82 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 83 | u16 mute_reg = snd_soc_read(codec, WM8728_DACCTL); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 84 | |
| 85 | if (mute) |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 86 | snd_soc_write(codec, WM8728_DACCTL, mute_reg | 1); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 87 | else |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 88 | snd_soc_write(codec, WM8728_DACCTL, mute_reg & ~1); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static int wm8728_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 94 | struct snd_pcm_hw_params *params, |
| 95 | struct snd_soc_dai *dai) |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 96 | { |
| 97 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 98 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 99 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 100 | u16 dac = snd_soc_read(codec, WM8728_DACCTL); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 101 | |
| 102 | dac &= ~0x18; |
| 103 | |
| 104 | switch (params_format(params)) { |
| 105 | case SNDRV_PCM_FORMAT_S16_LE: |
| 106 | break; |
| 107 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 108 | dac |= 0x10; |
| 109 | break; |
| 110 | case SNDRV_PCM_FORMAT_S24_LE: |
| 111 | dac |= 0x08; |
| 112 | break; |
| 113 | default: |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 117 | snd_soc_write(codec, WM8728_DACCTL, dac); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static int wm8728_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 123 | unsigned int fmt) |
| 124 | { |
| 125 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 126 | u16 iface = snd_soc_read(codec, WM8728_IFCTL); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 127 | |
| 128 | /* Currently only I2S is supported by the driver, though the |
| 129 | * hardware is more flexible. |
| 130 | */ |
| 131 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 132 | case SND_SOC_DAIFMT_I2S: |
| 133 | iface |= 1; |
| 134 | break; |
| 135 | default: |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | /* The hardware only support full slave mode */ |
| 140 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 141 | case SND_SOC_DAIFMT_CBS_CFS: |
| 142 | break; |
| 143 | default: |
| 144 | return -EINVAL; |
| 145 | } |
| 146 | |
| 147 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 148 | case SND_SOC_DAIFMT_NB_NF: |
| 149 | iface &= ~0x22; |
| 150 | break; |
| 151 | case SND_SOC_DAIFMT_IB_NF: |
| 152 | iface |= 0x20; |
| 153 | iface &= ~0x02; |
| 154 | break; |
| 155 | case SND_SOC_DAIFMT_NB_IF: |
| 156 | iface |= 0x02; |
| 157 | iface &= ~0x20; |
| 158 | break; |
| 159 | case SND_SOC_DAIFMT_IB_IF: |
| 160 | iface |= 0x22; |
| 161 | break; |
| 162 | default: |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 166 | snd_soc_write(codec, WM8728_IFCTL, iface); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static int wm8728_set_bias_level(struct snd_soc_codec *codec, |
| 171 | enum snd_soc_bias_level level) |
| 172 | { |
| 173 | u16 reg; |
| 174 | int i; |
| 175 | |
| 176 | switch (level) { |
| 177 | case SND_SOC_BIAS_ON: |
| 178 | case SND_SOC_BIAS_PREPARE: |
| 179 | case SND_SOC_BIAS_STANDBY: |
| 180 | if (codec->bias_level == SND_SOC_BIAS_OFF) { |
| 181 | /* Power everything up... */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 182 | reg = snd_soc_read(codec, WM8728_DACCTL); |
| 183 | snd_soc_write(codec, WM8728_DACCTL, reg & ~0x4); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 184 | |
| 185 | /* ..then sync in the register cache. */ |
| 186 | for (i = 0; i < ARRAY_SIZE(wm8728_reg_defaults); i++) |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 187 | snd_soc_write(codec, i, |
| 188 | snd_soc_read(codec, i)); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 189 | } |
| 190 | break; |
| 191 | |
| 192 | case SND_SOC_BIAS_OFF: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 193 | reg = snd_soc_read(codec, WM8728_DACCTL); |
| 194 | snd_soc_write(codec, WM8728_DACCTL, reg | 0x4); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 195 | break; |
| 196 | } |
| 197 | codec->bias_level = level; |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | #define WM8728_RATES (SNDRV_PCM_RATE_8000_192000) |
| 202 | |
| 203 | #define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 204 | SNDRV_PCM_FMTBIT_S24_LE) |
| 205 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 206 | static struct snd_soc_dai_ops wm8728_dai_ops = { |
| 207 | .hw_params = wm8728_hw_params, |
| 208 | .digital_mute = wm8728_mute, |
| 209 | .set_fmt = wm8728_set_dai_fmt, |
| 210 | }; |
| 211 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 212 | struct snd_soc_dai wm8728_dai = { |
| 213 | .name = "WM8728", |
| 214 | .playback = { |
| 215 | .stream_name = "Playback", |
| 216 | .channels_min = 2, |
| 217 | .channels_max = 2, |
| 218 | .rates = WM8728_RATES, |
| 219 | .formats = WM8728_FORMATS, |
| 220 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 221 | .ops = &wm8728_dai_ops, |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 222 | }; |
| 223 | EXPORT_SYMBOL_GPL(wm8728_dai); |
| 224 | |
| 225 | static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) |
| 226 | { |
| 227 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 228 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 229 | |
| 230 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int wm8728_resume(struct platform_device *pdev) |
| 236 | { |
| 237 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 238 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 239 | |
| 240 | wm8728_set_bias_level(codec, codec->suspend_bias_level); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * initialise the WM8728 driver |
| 247 | * register the mixer and dsp interfaces with the kernel |
| 248 | */ |
Mark Brown | 7084a42 | 2009-07-10 22:24:27 +0100 | [diff] [blame] | 249 | static int wm8728_init(struct snd_soc_device *socdev, |
| 250 | enum snd_soc_control_type control) |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 251 | { |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 252 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 253 | int ret = 0; |
| 254 | |
| 255 | codec->name = "WM8728"; |
| 256 | codec->owner = THIS_MODULE; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 257 | codec->set_bias_level = wm8728_set_bias_level; |
| 258 | codec->dai = &wm8728_dai; |
| 259 | codec->num_dai = 1; |
| 260 | codec->bias_level = SND_SOC_BIAS_OFF; |
| 261 | codec->reg_cache_size = ARRAY_SIZE(wm8728_reg_defaults); |
| 262 | codec->reg_cache = kmemdup(wm8728_reg_defaults, |
| 263 | sizeof(wm8728_reg_defaults), |
| 264 | GFP_KERNEL); |
| 265 | if (codec->reg_cache == NULL) |
| 266 | return -ENOMEM; |
| 267 | |
Mark Brown | 7084a42 | 2009-07-10 22:24:27 +0100 | [diff] [blame] | 268 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 269 | if (ret < 0) { |
| 270 | printk(KERN_ERR "wm8728: failed to configure cache I/O: %d\n", |
| 271 | ret); |
| 272 | goto err; |
| 273 | } |
| 274 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 275 | /* register pcms */ |
| 276 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 277 | if (ret < 0) { |
| 278 | printk(KERN_ERR "wm8728: failed to create pcms\n"); |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 279 | goto err; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /* power on device */ |
| 283 | wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 284 | |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 285 | snd_soc_add_controls(codec, wm8728_snd_controls, |
| 286 | ARRAY_SIZE(wm8728_snd_controls)); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 287 | wm8728_add_widgets(codec); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 288 | |
| 289 | return ret; |
| 290 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 291 | err: |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 292 | kfree(codec->reg_cache); |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | static struct snd_soc_device *wm8728_socdev; |
| 297 | |
| 298 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 299 | |
| 300 | /* |
| 301 | * WM8728 2 wire address is determined by GPIO5 |
| 302 | * state during powerup. |
| 303 | * low = 0x1a |
| 304 | * high = 0x1b |
| 305 | */ |
| 306 | |
| 307 | static int wm8728_i2c_probe(struct i2c_client *i2c, |
| 308 | const struct i2c_device_id *id) |
| 309 | { |
| 310 | struct snd_soc_device *socdev = wm8728_socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 311 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 312 | int ret; |
| 313 | |
| 314 | i2c_set_clientdata(i2c, codec); |
| 315 | codec->control_data = i2c; |
| 316 | |
Mark Brown | 7084a42 | 2009-07-10 22:24:27 +0100 | [diff] [blame] | 317 | ret = wm8728_init(socdev, SND_SOC_I2C); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 318 | if (ret < 0) |
| 319 | pr_err("failed to initialise WM8728\n"); |
| 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | static int wm8728_i2c_remove(struct i2c_client *client) |
| 325 | { |
| 326 | struct snd_soc_codec *codec = i2c_get_clientdata(client); |
| 327 | kfree(codec->reg_cache); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static const struct i2c_device_id wm8728_i2c_id[] = { |
| 332 | { "wm8728", 0 }, |
| 333 | { } |
| 334 | }; |
| 335 | MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id); |
| 336 | |
| 337 | static struct i2c_driver wm8728_i2c_driver = { |
| 338 | .driver = { |
| 339 | .name = "WM8728 I2C Codec", |
| 340 | .owner = THIS_MODULE, |
| 341 | }, |
| 342 | .probe = wm8728_i2c_probe, |
| 343 | .remove = wm8728_i2c_remove, |
| 344 | .id_table = wm8728_i2c_id, |
| 345 | }; |
| 346 | |
| 347 | static int wm8728_add_i2c_device(struct platform_device *pdev, |
| 348 | const struct wm8728_setup_data *setup) |
| 349 | { |
| 350 | struct i2c_board_info info; |
| 351 | struct i2c_adapter *adapter; |
| 352 | struct i2c_client *client; |
| 353 | int ret; |
| 354 | |
| 355 | ret = i2c_add_driver(&wm8728_i2c_driver); |
| 356 | if (ret != 0) { |
| 357 | dev_err(&pdev->dev, "can't add i2c driver\n"); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 362 | info.addr = setup->i2c_address; |
| 363 | strlcpy(info.type, "wm8728", I2C_NAME_SIZE); |
| 364 | |
| 365 | adapter = i2c_get_adapter(setup->i2c_bus); |
| 366 | if (!adapter) { |
| 367 | dev_err(&pdev->dev, "can't get i2c adapter %d\n", |
| 368 | setup->i2c_bus); |
| 369 | goto err_driver; |
| 370 | } |
| 371 | |
| 372 | client = i2c_new_device(adapter, &info); |
| 373 | i2c_put_adapter(adapter); |
| 374 | if (!client) { |
| 375 | dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", |
| 376 | (unsigned int)info.addr); |
| 377 | goto err_driver; |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | |
| 382 | err_driver: |
| 383 | i2c_del_driver(&wm8728_i2c_driver); |
| 384 | return -ENODEV; |
| 385 | } |
| 386 | #endif |
| 387 | |
| 388 | #if defined(CONFIG_SPI_MASTER) |
| 389 | static int __devinit wm8728_spi_probe(struct spi_device *spi) |
| 390 | { |
| 391 | struct snd_soc_device *socdev = wm8728_socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 392 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 393 | int ret; |
| 394 | |
| 395 | codec->control_data = spi; |
| 396 | |
Mark Brown | 7084a42 | 2009-07-10 22:24:27 +0100 | [diff] [blame] | 397 | ret = wm8728_init(socdev, SND_SOC_SPI); |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 398 | if (ret < 0) |
| 399 | dev_err(&spi->dev, "failed to initialise WM8728\n"); |
| 400 | |
| 401 | return ret; |
| 402 | } |
| 403 | |
| 404 | static int __devexit wm8728_spi_remove(struct spi_device *spi) |
| 405 | { |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static struct spi_driver wm8728_spi_driver = { |
| 410 | .driver = { |
| 411 | .name = "wm8728", |
| 412 | .bus = &spi_bus_type, |
| 413 | .owner = THIS_MODULE, |
| 414 | }, |
| 415 | .probe = wm8728_spi_probe, |
| 416 | .remove = __devexit_p(wm8728_spi_remove), |
| 417 | }; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 418 | #endif /* CONFIG_SPI_MASTER */ |
| 419 | |
| 420 | static int wm8728_probe(struct platform_device *pdev) |
| 421 | { |
| 422 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 423 | struct wm8728_setup_data *setup; |
| 424 | struct snd_soc_codec *codec; |
| 425 | int ret = 0; |
| 426 | |
| 427 | setup = socdev->codec_data; |
| 428 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 429 | if (codec == NULL) |
| 430 | return -ENOMEM; |
| 431 | |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 432 | socdev->card->codec = codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 433 | mutex_init(&codec->mutex); |
| 434 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 435 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 436 | |
| 437 | wm8728_socdev = socdev; |
| 438 | ret = -ENODEV; |
| 439 | |
| 440 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 441 | if (setup->i2c_address) { |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 442 | ret = wm8728_add_i2c_device(pdev, setup); |
| 443 | } |
| 444 | #endif |
| 445 | #if defined(CONFIG_SPI_MASTER) |
| 446 | if (setup->spi) { |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 447 | ret = spi_register_driver(&wm8728_spi_driver); |
| 448 | if (ret != 0) |
| 449 | printk(KERN_ERR "can't add spi driver"); |
| 450 | } |
| 451 | #endif |
| 452 | |
| 453 | if (ret != 0) |
| 454 | kfree(codec); |
| 455 | |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | /* power down chip */ |
| 460 | static int wm8728_remove(struct platform_device *pdev) |
| 461 | { |
| 462 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 463 | struct snd_soc_codec *codec = socdev->card->codec; |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 464 | |
| 465 | if (codec->control_data) |
| 466 | wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 467 | |
| 468 | snd_soc_free_pcms(socdev); |
| 469 | snd_soc_dapm_free(socdev); |
| 470 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 471 | i2c_unregister_device(codec->control_data); |
| 472 | i2c_del_driver(&wm8728_i2c_driver); |
| 473 | #endif |
| 474 | #if defined(CONFIG_SPI_MASTER) |
| 475 | spi_unregister_driver(&wm8728_spi_driver); |
| 476 | #endif |
| 477 | kfree(codec); |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | struct snd_soc_codec_device soc_codec_dev_wm8728 = { |
| 483 | .probe = wm8728_probe, |
| 484 | .remove = wm8728_remove, |
| 485 | .suspend = wm8728_suspend, |
| 486 | .resume = wm8728_resume, |
| 487 | }; |
| 488 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8728); |
| 489 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 490 | static int __init wm8728_modinit(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 491 | { |
| 492 | return snd_soc_register_dai(&wm8728_dai); |
| 493 | } |
| 494 | module_init(wm8728_modinit); |
| 495 | |
| 496 | static void __exit wm8728_exit(void) |
| 497 | { |
| 498 | snd_soc_unregister_dai(&wm8728_dai); |
| 499 | } |
| 500 | module_exit(wm8728_exit); |
| 501 | |
Mark Brown | 71cfc90 | 2008-11-13 14:33:14 +0000 | [diff] [blame] | 502 | MODULE_DESCRIPTION("ASoC WM8728 driver"); |
| 503 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 504 | MODULE_LICENSE("GPL"); |