diff options
Diffstat (limited to 'sound/soc/codecs/wm8731.c')
| -rw-r--r-- | sound/soc/codecs/wm8731.c | 218 |
1 files changed, 97 insertions, 121 deletions
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c index 7a205876ef4f..d3fd4f28d96e 100644 --- a/sound/soc/codecs/wm8731.c +++ b/sound/soc/codecs/wm8731.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <sound/soc.h> | 26 | #include <sound/soc.h> |
| 27 | #include <sound/soc-dapm.h> | 27 | #include <sound/soc-dapm.h> |
| 28 | #include <sound/initval.h> | 28 | #include <sound/initval.h> |
| 29 | #include <sound/tlv.h> | ||
| 29 | 30 | ||
| 30 | #include "wm8731.h" | 31 | #include "wm8731.h" |
| 31 | 32 | ||
| @@ -39,9 +40,6 @@ struct wm8731_priv { | |||
| 39 | unsigned int sysclk; | 40 | unsigned int sysclk; |
| 40 | }; | 41 | }; |
| 41 | 42 | ||
| 42 | #ifdef CONFIG_SPI_MASTER | ||
| 43 | static int wm8731_spi_write(struct spi_device *spi, const char *data, int len); | ||
| 44 | #endif | ||
| 45 | 43 | ||
| 46 | /* | 44 | /* |
| 47 | * wm8731 register cache | 45 | * wm8731 register cache |
| @@ -50,60 +48,12 @@ static int wm8731_spi_write(struct spi_device *spi, const char *data, int len); | |||
| 50 | * There is no point in caching the reset register | 48 | * There is no point in caching the reset register |
| 51 | */ | 49 | */ |
| 52 | static const u16 wm8731_reg[WM8731_CACHEREGNUM] = { | 50 | static const u16 wm8731_reg[WM8731_CACHEREGNUM] = { |
| 53 | 0x0097, 0x0097, 0x0079, 0x0079, | 51 | 0x0097, 0x0097, 0x0079, 0x0079, |
| 54 | 0x000a, 0x0008, 0x009f, 0x000a, | 52 | 0x000a, 0x0008, 0x009f, 0x000a, |
| 55 | 0x0000, 0x0000 | 53 | 0x0000, 0x0000 |
| 56 | }; | 54 | }; |
| 57 | 55 | ||
| 58 | /* | 56 | #define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) |
| 59 | * read wm8731 register cache | ||
| 60 | */ | ||
| 61 | static inline unsigned int wm8731_read_reg_cache(struct snd_soc_codec *codec, | ||
| 62 | unsigned int reg) | ||
| 63 | { | ||
| 64 | u16 *cache = codec->reg_cache; | ||
| 65 | if (reg == WM8731_RESET) | ||
| 66 | return 0; | ||
| 67 | if (reg >= WM8731_CACHEREGNUM) | ||
| 68 | return -1; | ||
| 69 | return cache[reg]; | ||
| 70 | } | ||
| 71 | |||
| 72 | /* | ||
| 73 | * write wm8731 register cache | ||
| 74 | */ | ||
| 75 | static inline void wm8731_write_reg_cache(struct snd_soc_codec *codec, | ||
| 76 | u16 reg, unsigned int value) | ||
| 77 | { | ||
| 78 | u16 *cache = codec->reg_cache; | ||
| 79 | if (reg >= WM8731_CACHEREGNUM) | ||
| 80 | return; | ||
| 81 | cache[reg] = value; | ||
| 82 | } | ||
| 83 | |||
| 84 | /* | ||
| 85 | * write to the WM8731 register space | ||
| 86 | */ | ||
| 87 | static int wm8731_write(struct snd_soc_codec *codec, unsigned int reg, | ||
| 88 | unsigned int value) | ||
| 89 | { | ||
| 90 | u8 data[2]; | ||
| 91 | |||
| 92 | /* data is | ||
| 93 | * D15..D9 WM8731 register offset | ||
| 94 | * D8...D0 register data | ||
| 95 | */ | ||
| 96 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | ||
| 97 | data[1] = value & 0x00ff; | ||
| 98 | |||
| 99 | wm8731_write_reg_cache(codec, reg, value); | ||
| 100 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
| 101 | return 0; | ||
| 102 | else | ||
| 103 | return -EIO; | ||
| 104 | } | ||
| 105 | |||
| 106 | #define wm8731_reset(c) wm8731_write(c, WM8731_RESET, 0) | ||
| 107 | 57 | ||
| 108 | static const char *wm8731_input_select[] = {"Line In", "Mic"}; | 58 | static const char *wm8731_input_select[] = {"Line In", "Mic"}; |
| 109 | static const char *wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; | 59 | static const char *wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"}; |
| @@ -113,20 +63,26 @@ static const struct soc_enum wm8731_enum[] = { | |||
| 113 | SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph), | 63 | SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph), |
| 114 | }; | 64 | }; |
| 115 | 65 | ||
| 66 | static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0); | ||
| 67 | static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0); | ||
| 68 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); | ||
| 69 | |||
| 116 | static const struct snd_kcontrol_new wm8731_snd_controls[] = { | 70 | static const struct snd_kcontrol_new wm8731_snd_controls[] = { |
| 117 | 71 | ||
| 118 | SOC_DOUBLE_R("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V, | 72 | SOC_DOUBLE_R_TLV("Master Playback Volume", WM8731_LOUT1V, WM8731_ROUT1V, |
| 119 | 0, 127, 0), | 73 | 0, 127, 0, out_tlv), |
| 120 | SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V, | 74 | SOC_DOUBLE_R("Master Playback ZC Switch", WM8731_LOUT1V, WM8731_ROUT1V, |
| 121 | 7, 1, 0), | 75 | 7, 1, 0), |
| 122 | 76 | ||
| 123 | SOC_DOUBLE_R("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0), | 77 | SOC_DOUBLE_R_TLV("Capture Volume", WM8731_LINVOL, WM8731_RINVOL, 0, 31, 0, |
| 78 | in_tlv), | ||
| 124 | SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1), | 79 | SOC_DOUBLE_R("Line Capture Switch", WM8731_LINVOL, WM8731_RINVOL, 7, 1, 1), |
| 125 | 80 | ||
| 126 | SOC_SINGLE("Mic Boost (+20dB)", WM8731_APANA, 0, 1, 0), | 81 | SOC_SINGLE("Mic Boost (+20dB)", WM8731_APANA, 0, 1, 0), |
| 127 | SOC_SINGLE("Capture Mic Switch", WM8731_APANA, 1, 1, 1), | 82 | SOC_SINGLE("Mic Capture Switch", WM8731_APANA, 1, 1, 1), |
| 128 | 83 | ||
| 129 | SOC_SINGLE("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1), | 84 | SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1, |
| 85 | sidetone_tlv), | ||
| 130 | 86 | ||
| 131 | SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1), | 87 | SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1), |
| 132 | SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), | 88 | SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0), |
| @@ -260,12 +216,12 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, | |||
| 260 | struct snd_soc_device *socdev = rtd->socdev; | 216 | struct snd_soc_device *socdev = rtd->socdev; |
| 261 | struct snd_soc_codec *codec = socdev->card->codec; | 217 | struct snd_soc_codec *codec = socdev->card->codec; |
| 262 | struct wm8731_priv *wm8731 = codec->private_data; | 218 | struct wm8731_priv *wm8731 = codec->private_data; |
| 263 | u16 iface = wm8731_read_reg_cache(codec, WM8731_IFACE) & 0xfff3; | 219 | u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3; |
| 264 | int i = get_coeff(wm8731->sysclk, params_rate(params)); | 220 | int i = get_coeff(wm8731->sysclk, params_rate(params)); |
| 265 | u16 srate = (coeff_div[i].sr << 2) | | 221 | u16 srate = (coeff_div[i].sr << 2) | |
| 266 | (coeff_div[i].bosr << 1) | coeff_div[i].usb; | 222 | (coeff_div[i].bosr << 1) | coeff_div[i].usb; |
| 267 | 223 | ||
| 268 | wm8731_write(codec, WM8731_SRATE, srate); | 224 | snd_soc_write(codec, WM8731_SRATE, srate); |
| 269 | 225 | ||
| 270 | /* bit size */ | 226 | /* bit size */ |
| 271 | switch (params_format(params)) { | 227 | switch (params_format(params)) { |
| @@ -279,7 +235,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream, | |||
| 279 | break; | 235 | break; |
| 280 | } | 236 | } |
| 281 | 237 | ||
| 282 | wm8731_write(codec, WM8731_IFACE, iface); | 238 | snd_soc_write(codec, WM8731_IFACE, iface); |
| 283 | return 0; | 239 | return 0; |
| 284 | } | 240 | } |
| 285 | 241 | ||
| @@ -291,7 +247,7 @@ static int wm8731_pcm_prepare(struct snd_pcm_substream *substream, | |||
| 291 | struct snd_soc_codec *codec = socdev->card->codec; | 247 | struct snd_soc_codec *codec = socdev->card->codec; |
| 292 | 248 | ||
| 293 | /* set active */ | 249 | /* set active */ |
| 294 | wm8731_write(codec, WM8731_ACTIVE, 0x0001); | 250 | snd_soc_write(codec, WM8731_ACTIVE, 0x0001); |
| 295 | 251 | ||
| 296 | return 0; | 252 | return 0; |
| 297 | } | 253 | } |
| @@ -306,19 +262,19 @@ static void wm8731_shutdown(struct snd_pcm_substream *substream, | |||
| 306 | /* deactivate */ | 262 | /* deactivate */ |
| 307 | if (!codec->active) { | 263 | if (!codec->active) { |
| 308 | udelay(50); | 264 | udelay(50); |
| 309 | wm8731_write(codec, WM8731_ACTIVE, 0x0); | 265 | snd_soc_write(codec, WM8731_ACTIVE, 0x0); |
| 310 | } | 266 | } |
| 311 | } | 267 | } |
| 312 | 268 | ||
| 313 | static int wm8731_mute(struct snd_soc_dai *dai, int mute) | 269 | static int wm8731_mute(struct snd_soc_dai *dai, int mute) |
| 314 | { | 270 | { |
| 315 | struct snd_soc_codec *codec = dai->codec; | 271 | struct snd_soc_codec *codec = dai->codec; |
| 316 | u16 mute_reg = wm8731_read_reg_cache(codec, WM8731_APDIGI) & 0xfff7; | 272 | u16 mute_reg = snd_soc_read(codec, WM8731_APDIGI) & 0xfff7; |
| 317 | 273 | ||
| 318 | if (mute) | 274 | if (mute) |
| 319 | wm8731_write(codec, WM8731_APDIGI, mute_reg | 0x8); | 275 | snd_soc_write(codec, WM8731_APDIGI, mute_reg | 0x8); |
| 320 | else | 276 | else |
| 321 | wm8731_write(codec, WM8731_APDIGI, mute_reg); | 277 | snd_soc_write(codec, WM8731_APDIGI, mute_reg); |
| 322 | return 0; | 278 | return 0; |
| 323 | } | 279 | } |
| 324 | 280 | ||
| @@ -396,7 +352,7 @@ static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
| 396 | } | 352 | } |
| 397 | 353 | ||
| 398 | /* set iface */ | 354 | /* set iface */ |
| 399 | wm8731_write(codec, WM8731_IFACE, iface); | 355 | snd_soc_write(codec, WM8731_IFACE, iface); |
| 400 | return 0; | 356 | return 0; |
| 401 | } | 357 | } |
| 402 | 358 | ||
| @@ -412,12 +368,12 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec, | |||
| 412 | break; | 368 | break; |
| 413 | case SND_SOC_BIAS_STANDBY: | 369 | case SND_SOC_BIAS_STANDBY: |
| 414 | /* Clear PWROFF, gate CLKOUT, everything else as-is */ | 370 | /* Clear PWROFF, gate CLKOUT, everything else as-is */ |
| 415 | reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f; | 371 | reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; |
| 416 | wm8731_write(codec, WM8731_PWR, reg | 0x0040); | 372 | snd_soc_write(codec, WM8731_PWR, reg | 0x0040); |
| 417 | break; | 373 | break; |
| 418 | case SND_SOC_BIAS_OFF: | 374 | case SND_SOC_BIAS_OFF: |
| 419 | wm8731_write(codec, WM8731_ACTIVE, 0x0); | 375 | snd_soc_write(codec, WM8731_ACTIVE, 0x0); |
| 420 | wm8731_write(codec, WM8731_PWR, 0xffff); | 376 | snd_soc_write(codec, WM8731_PWR, 0xffff); |
| 421 | break; | 377 | break; |
| 422 | } | 378 | } |
| 423 | codec->bias_level = level; | 379 | codec->bias_level = level; |
| @@ -457,15 +413,17 @@ struct snd_soc_dai wm8731_dai = { | |||
| 457 | .rates = WM8731_RATES, | 413 | .rates = WM8731_RATES, |
| 458 | .formats = WM8731_FORMATS,}, | 414 | .formats = WM8731_FORMATS,}, |
| 459 | .ops = &wm8731_dai_ops, | 415 | .ops = &wm8731_dai_ops, |
| 416 | .symmetric_rates = 1, | ||
| 460 | }; | 417 | }; |
| 461 | EXPORT_SYMBOL_GPL(wm8731_dai); | 418 | EXPORT_SYMBOL_GPL(wm8731_dai); |
| 462 | 419 | ||
| 420 | #ifdef CONFIG_PM | ||
| 463 | static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) | 421 | static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) |
| 464 | { | 422 | { |
| 465 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 423 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 466 | struct snd_soc_codec *codec = socdev->card->codec; | 424 | struct snd_soc_codec *codec = socdev->card->codec; |
| 467 | 425 | ||
| 468 | wm8731_write(codec, WM8731_ACTIVE, 0x0); | 426 | snd_soc_write(codec, WM8731_ACTIVE, 0x0); |
| 469 | wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); | 427 | wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 470 | return 0; | 428 | return 0; |
| 471 | } | 429 | } |
| @@ -488,6 +446,10 @@ static int wm8731_resume(struct platform_device *pdev) | |||
| 488 | wm8731_set_bias_level(codec, codec->suspend_bias_level); | 446 | wm8731_set_bias_level(codec, codec->suspend_bias_level); |
| 489 | return 0; | 447 | return 0; |
| 490 | } | 448 | } |
| 449 | #else | ||
| 450 | #define wm8731_suspend NULL | ||
| 451 | #define wm8731_resume NULL | ||
| 452 | #endif | ||
| 491 | 453 | ||
| 492 | static int wm8731_probe(struct platform_device *pdev) | 454 | static int wm8731_probe(struct platform_device *pdev) |
| 493 | { | 455 | { |
| @@ -547,15 +509,16 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = { | |||
| 547 | }; | 509 | }; |
| 548 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); | 510 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); |
| 549 | 511 | ||
| 550 | static int wm8731_register(struct wm8731_priv *wm8731) | 512 | static int wm8731_register(struct wm8731_priv *wm8731, |
| 513 | enum snd_soc_control_type control) | ||
| 551 | { | 514 | { |
| 552 | int ret; | 515 | int ret; |
| 553 | struct snd_soc_codec *codec = &wm8731->codec; | 516 | struct snd_soc_codec *codec = &wm8731->codec; |
| 554 | u16 reg; | ||
| 555 | 517 | ||
| 556 | if (wm8731_codec) { | 518 | if (wm8731_codec) { |
| 557 | dev_err(codec->dev, "Another WM8731 is registered\n"); | 519 | dev_err(codec->dev, "Another WM8731 is registered\n"); |
| 558 | return -EINVAL; | 520 | ret = -EINVAL; |
| 521 | goto err; | ||
| 559 | } | 522 | } |
| 560 | 523 | ||
| 561 | mutex_init(&codec->mutex); | 524 | mutex_init(&codec->mutex); |
| @@ -565,8 +528,6 @@ static int wm8731_register(struct wm8731_priv *wm8731) | |||
| 565 | codec->private_data = wm8731; | 528 | codec->private_data = wm8731; |
| 566 | codec->name = "WM8731"; | 529 | codec->name = "WM8731"; |
| 567 | codec->owner = THIS_MODULE; | 530 | codec->owner = THIS_MODULE; |
| 568 | codec->read = wm8731_read_reg_cache; | ||
| 569 | codec->write = wm8731_write; | ||
| 570 | codec->bias_level = SND_SOC_BIAS_OFF; | 531 | codec->bias_level = SND_SOC_BIAS_OFF; |
| 571 | codec->set_bias_level = wm8731_set_bias_level; | 532 | codec->set_bias_level = wm8731_set_bias_level; |
| 572 | codec->dai = &wm8731_dai; | 533 | codec->dai = &wm8731_dai; |
| @@ -576,10 +537,16 @@ static int wm8731_register(struct wm8731_priv *wm8731) | |||
| 576 | 537 | ||
| 577 | memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); | 538 | memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); |
| 578 | 539 | ||
| 540 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); | ||
| 541 | if (ret < 0) { | ||
| 542 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
| 543 | goto err; | ||
| 544 | } | ||
| 545 | |||
| 579 | ret = wm8731_reset(codec); | 546 | ret = wm8731_reset(codec); |
| 580 | if (ret < 0) { | 547 | if (ret < 0) { |
| 581 | dev_err(codec->dev, "Failed to issue reset\n"); | 548 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
| 582 | return ret; | 549 | goto err; |
| 583 | } | 550 | } |
| 584 | 551 | ||
| 585 | wm8731_dai.dev = codec->dev; | 552 | wm8731_dai.dev = codec->dev; |
| @@ -587,35 +554,36 @@ static int wm8731_register(struct wm8731_priv *wm8731) | |||
| 587 | wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 554 | wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 588 | 555 | ||
| 589 | /* Latch the update bits */ | 556 | /* Latch the update bits */ |
| 590 | reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V); | 557 | snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); |
| 591 | wm8731_write(codec, WM8731_LOUT1V, reg & ~0x0100); | 558 | snd_soc_update_bits(codec, WM8731_ROUT1V, 0x100, 0); |
| 592 | reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V); | 559 | snd_soc_update_bits(codec, WM8731_LINVOL, 0x100, 0); |
| 593 | wm8731_write(codec, WM8731_ROUT1V, reg & ~0x0100); | 560 | snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0); |
| 594 | reg = wm8731_read_reg_cache(codec, WM8731_LINVOL); | ||
| 595 | wm8731_write(codec, WM8731_LINVOL, reg & ~0x0100); | ||
| 596 | reg = wm8731_read_reg_cache(codec, WM8731_RINVOL); | ||
| 597 | wm8731_write(codec, WM8731_RINVOL, reg & ~0x0100); | ||
| 598 | 561 | ||
| 599 | /* Disable bypass path by default */ | 562 | /* Disable bypass path by default */ |
| 600 | reg = wm8731_read_reg_cache(codec, WM8731_APANA); | 563 | snd_soc_update_bits(codec, WM8731_APANA, 0x4, 0); |
| 601 | wm8731_write(codec, WM8731_APANA, reg & ~0x4); | ||
| 602 | 564 | ||
| 603 | wm8731_codec = codec; | 565 | wm8731_codec = codec; |
| 604 | 566 | ||
| 605 | ret = snd_soc_register_codec(codec); | 567 | ret = snd_soc_register_codec(codec); |
| 606 | if (ret != 0) { | 568 | if (ret != 0) { |
| 607 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); | 569 | dev_err(codec->dev, "Failed to register codec: %d\n", ret); |
| 608 | return ret; | 570 | goto err; |
| 609 | } | 571 | } |
| 610 | 572 | ||
| 611 | ret = snd_soc_register_dai(&wm8731_dai); | 573 | ret = snd_soc_register_dai(&wm8731_dai); |
| 612 | if (ret != 0) { | 574 | if (ret != 0) { |
| 613 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); | 575 | dev_err(codec->dev, "Failed to register DAI: %d\n", ret); |
| 614 | snd_soc_unregister_codec(codec); | 576 | snd_soc_unregister_codec(codec); |
| 615 | return ret; | 577 | goto err_codec; |
| 616 | } | 578 | } |
| 617 | 579 | ||
| 618 | return 0; | 580 | return 0; |
| 581 | |||
| 582 | err_codec: | ||
| 583 | snd_soc_unregister_codec(codec); | ||
| 584 | err: | ||
| 585 | kfree(wm8731); | ||
| 586 | return ret; | ||
| 619 | } | 587 | } |
| 620 | 588 | ||
| 621 | static void wm8731_unregister(struct wm8731_priv *wm8731) | 589 | static void wm8731_unregister(struct wm8731_priv *wm8731) |
| @@ -628,30 +596,6 @@ static void wm8731_unregister(struct wm8731_priv *wm8731) | |||
| 628 | } | 596 | } |
| 629 | 597 | ||
| 630 | #if defined(CONFIG_SPI_MASTER) | 598 | #if defined(CONFIG_SPI_MASTER) |
| 631 | static int wm8731_spi_write(struct spi_device *spi, const char *data, int len) | ||
| 632 | { | ||
| 633 | struct spi_transfer t; | ||
| 634 | struct spi_message m; | ||
| 635 | u8 msg[2]; | ||
| 636 | |||
| 637 | if (len <= 0) | ||
| 638 | return 0; | ||
| 639 | |||
| 640 | msg[0] = data[0]; | ||
| 641 | msg[1] = data[1]; | ||
| 642 | |||
| 643 | spi_message_init(&m); | ||
| 644 | memset(&t, 0, (sizeof t)); | ||
| 645 | |||
| 646 | t.tx_buf = &msg[0]; | ||
| 647 | t.len = len; | ||
| 648 | |||
| 649 | spi_message_add_tail(&t, &m); | ||
| 650 | spi_sync(spi, &m); | ||
| 651 | |||
| 652 | return len; | ||
| 653 | } | ||
| 654 | |||
| 655 | static int __devinit wm8731_spi_probe(struct spi_device *spi) | 599 | static int __devinit wm8731_spi_probe(struct spi_device *spi) |
| 656 | { | 600 | { |
| 657 | struct snd_soc_codec *codec; | 601 | struct snd_soc_codec *codec; |
| @@ -663,12 +607,11 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi) | |||
| 663 | 607 | ||
| 664 | codec = &wm8731->codec; | 608 | codec = &wm8731->codec; |
| 665 | codec->control_data = spi; | 609 | codec->control_data = spi; |
| 666 | codec->hw_write = (hw_write_t)wm8731_spi_write; | ||
| 667 | codec->dev = &spi->dev; | 610 | codec->dev = &spi->dev; |
| 668 | 611 | ||
| 669 | dev_set_drvdata(&spi->dev, wm8731); | 612 | dev_set_drvdata(&spi->dev, wm8731); |
| 670 | 613 | ||
| 671 | return wm8731_register(wm8731); | 614 | return wm8731_register(wm8731, SND_SOC_SPI); |
| 672 | } | 615 | } |
| 673 | 616 | ||
| 674 | static int __devexit wm8731_spi_remove(struct spi_device *spi) | 617 | static int __devexit wm8731_spi_remove(struct spi_device *spi) |
| @@ -680,6 +623,21 @@ static int __devexit wm8731_spi_remove(struct spi_device *spi) | |||
| 680 | return 0; | 623 | return 0; |
| 681 | } | 624 | } |
| 682 | 625 | ||
| 626 | #ifdef CONFIG_PM | ||
| 627 | static int wm8731_spi_suspend(struct spi_device *spi, pm_message_t msg) | ||
| 628 | { | ||
| 629 | return snd_soc_suspend_device(&spi->dev); | ||
| 630 | } | ||
| 631 | |||
| 632 | static int wm8731_spi_resume(struct spi_device *spi) | ||
| 633 | { | ||
| 634 | return snd_soc_resume_device(&spi->dev); | ||
| 635 | } | ||
| 636 | #else | ||
| 637 | #define wm8731_spi_suspend NULL | ||
| 638 | #define wm8731_spi_resume NULL | ||
| 639 | #endif | ||
| 640 | |||
| 683 | static struct spi_driver wm8731_spi_driver = { | 641 | static struct spi_driver wm8731_spi_driver = { |
| 684 | .driver = { | 642 | .driver = { |
| 685 | .name = "wm8731", | 643 | .name = "wm8731", |
| @@ -687,6 +645,8 @@ static struct spi_driver wm8731_spi_driver = { | |||
| 687 | .owner = THIS_MODULE, | 645 | .owner = THIS_MODULE, |
| 688 | }, | 646 | }, |
| 689 | .probe = wm8731_spi_probe, | 647 | .probe = wm8731_spi_probe, |
| 648 | .suspend = wm8731_spi_suspend, | ||
| 649 | .resume = wm8731_spi_resume, | ||
| 690 | .remove = __devexit_p(wm8731_spi_remove), | 650 | .remove = __devexit_p(wm8731_spi_remove), |
| 691 | }; | 651 | }; |
| 692 | #endif /* CONFIG_SPI_MASTER */ | 652 | #endif /* CONFIG_SPI_MASTER */ |
| @@ -703,14 +663,13 @@ static __devinit int wm8731_i2c_probe(struct i2c_client *i2c, | |||
| 703 | return -ENOMEM; | 663 | return -ENOMEM; |
| 704 | 664 | ||
| 705 | codec = &wm8731->codec; | 665 | codec = &wm8731->codec; |
| 706 | codec->hw_write = (hw_write_t)i2c_master_send; | ||
| 707 | 666 | ||
| 708 | i2c_set_clientdata(i2c, wm8731); | 667 | i2c_set_clientdata(i2c, wm8731); |
| 709 | codec->control_data = i2c; | 668 | codec->control_data = i2c; |
| 710 | 669 | ||
| 711 | codec->dev = &i2c->dev; | 670 | codec->dev = &i2c->dev; |
| 712 | 671 | ||
| 713 | return wm8731_register(wm8731); | 672 | return wm8731_register(wm8731, SND_SOC_I2C); |
| 714 | } | 673 | } |
| 715 | 674 | ||
| 716 | static __devexit int wm8731_i2c_remove(struct i2c_client *client) | 675 | static __devexit int wm8731_i2c_remove(struct i2c_client *client) |
| @@ -720,6 +679,21 @@ static __devexit int wm8731_i2c_remove(struct i2c_client *client) | |||
| 720 | return 0; | 679 | return 0; |
| 721 | } | 680 | } |
| 722 | 681 | ||
| 682 | #ifdef CONFIG_PM | ||
| 683 | static int wm8731_i2c_suspend(struct i2c_client *i2c, pm_message_t msg) | ||
| 684 | { | ||
| 685 | return snd_soc_suspend_device(&i2c->dev); | ||
| 686 | } | ||
| 687 | |||
| 688 | static int wm8731_i2c_resume(struct i2c_client *i2c) | ||
| 689 | { | ||
| 690 | return snd_soc_resume_device(&i2c->dev); | ||
| 691 | } | ||
| 692 | #else | ||
| 693 | #define wm8731_i2c_suspend NULL | ||
| 694 | #define wm8731_i2c_resume NULL | ||
| 695 | #endif | ||
| 696 | |||
| 723 | static const struct i2c_device_id wm8731_i2c_id[] = { | 697 | static const struct i2c_device_id wm8731_i2c_id[] = { |
| 724 | { "wm8731", 0 }, | 698 | { "wm8731", 0 }, |
| 725 | { } | 699 | { } |
| @@ -733,6 +707,8 @@ static struct i2c_driver wm8731_i2c_driver = { | |||
| 733 | }, | 707 | }, |
| 734 | .probe = wm8731_i2c_probe, | 708 | .probe = wm8731_i2c_probe, |
| 735 | .remove = __devexit_p(wm8731_i2c_remove), | 709 | .remove = __devexit_p(wm8731_i2c_remove), |
| 710 | .suspend = wm8731_i2c_suspend, | ||
| 711 | .resume = wm8731_i2c_resume, | ||
| 736 | .id_table = wm8731_i2c_id, | 712 | .id_table = wm8731_i2c_id, |
| 737 | }; | 713 | }; |
| 738 | #endif | 714 | #endif |
