wm8731.c (d2058b0cd039aad89b111d83b9c347e9d8f57a84) | wm8731.c (7dea7c01dac9b74faa9afa93fc9bb5f2d37521dc) |
---|---|
1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * 6 * Author: Richard Purdie <richard@openedhand.com> 7 * 8 * Based on wm8753.c by Liam Girdwood --- 5 unchanged lines hidden (view full) --- 14 15#include <linux/module.h> 16#include <linux/moduleparam.h> 17#include <linux/init.h> 18#include <linux/delay.h> 19#include <linux/pm.h> 20#include <linux/i2c.h> 21#include <linux/platform_device.h> | 1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * 6 * Author: Richard Purdie <richard@openedhand.com> 7 * 8 * Based on wm8753.c by Liam Girdwood --- 5 unchanged lines hidden (view full) --- 14 15#include <linux/module.h> 16#include <linux/moduleparam.h> 17#include <linux/init.h> 18#include <linux/delay.h> 19#include <linux/pm.h> 20#include <linux/i2c.h> 21#include <linux/platform_device.h> |
22#include <linux/regulator/consumer.h> |
|
22#include <linux/spi/spi.h> 23#include <sound/core.h> 24#include <sound/pcm.h> 25#include <sound/pcm_params.h> 26#include <sound/soc.h> 27#include <sound/soc-dapm.h> 28#include <sound/initval.h> 29#include <sound/tlv.h> 30 31#include "wm8731.h" 32 33static struct snd_soc_codec *wm8731_codec; 34struct snd_soc_codec_device soc_codec_dev_wm8731; 35 | 23#include <linux/spi/spi.h> 24#include <sound/core.h> 25#include <sound/pcm.h> 26#include <sound/pcm_params.h> 27#include <sound/soc.h> 28#include <sound/soc-dapm.h> 29#include <sound/initval.h> 30#include <sound/tlv.h> 31 32#include "wm8731.h" 33 34static struct snd_soc_codec *wm8731_codec; 35struct snd_soc_codec_device soc_codec_dev_wm8731; 36 |
37#define WM8731_NUM_SUPPLIES 4 38static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 39 "AVDD", 40 "HPVDD", 41 "DCVDD", 42 "DBVDD", 43}; 44 |
|
36/* codec private data */ 37struct wm8731_priv { 38 struct snd_soc_codec codec; | 45/* codec private data */ 46struct wm8731_priv { 47 struct snd_soc_codec codec; |
48 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; |
|
39 u16 reg_cache[WM8731_CACHEREGNUM]; 40 unsigned int sysclk; 41}; 42 43 44/* 45 * wm8731 register cache 46 * We can't read the WM8731 register space when we are --- 370 unchanged lines hidden (view full) --- 417}; 418EXPORT_SYMBOL_GPL(wm8731_dai); 419 420#ifdef CONFIG_PM 421static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) 422{ 423 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 424 struct snd_soc_codec *codec = socdev->card->codec; | 49 u16 reg_cache[WM8731_CACHEREGNUM]; 50 unsigned int sysclk; 51}; 52 53 54/* 55 * wm8731 register cache 56 * We can't read the WM8731 register space when we are --- 370 unchanged lines hidden (view full) --- 427}; 428EXPORT_SYMBOL_GPL(wm8731_dai); 429 430#ifdef CONFIG_PM 431static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) 432{ 433 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 434 struct snd_soc_codec *codec = socdev->card->codec; |
435 struct wm8731_priv *wm8731 = codec->private_data; |
|
425 426 snd_soc_write(codec, WM8731_ACTIVE, 0x0); 427 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); | 436 437 snd_soc_write(codec, WM8731_ACTIVE, 0x0); 438 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); |
439 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 440 wm8731->supplies); |
|
428 return 0; 429} 430 431static int wm8731_resume(struct platform_device *pdev) 432{ 433 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 434 struct snd_soc_codec *codec = socdev->card->codec; | 441 return 0; 442} 443 444static int wm8731_resume(struct platform_device *pdev) 445{ 446 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 447 struct snd_soc_codec *codec = socdev->card->codec; |
435 int i; | 448 struct wm8731_priv *wm8731 = codec->private_data; 449 int i, ret; |
436 u8 data[2]; 437 u16 *cache = codec->reg_cache; 438 | 450 u8 data[2]; 451 u16 *cache = codec->reg_cache; 452 |
453 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 454 wm8731->supplies); 455 if (ret != 0) 456 return ret; 457 |
|
439 /* Sync reg_cache with the hardware */ 440 for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) { 441 data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001); 442 data[1] = cache[i] & 0x00ff; 443 codec->hw_write(codec->control_data, data, 2); 444 } 445 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 446 wm8731_set_bias_level(codec, codec->suspend_bias_level); | 458 /* Sync reg_cache with the hardware */ 459 for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) { 460 data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001); 461 data[1] = cache[i] & 0x00ff; 462 codec->hw_write(codec->control_data, data, 2); 463 } 464 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 465 wm8731_set_bias_level(codec, codec->suspend_bias_level); |
466 |
|
447 return 0; 448} 449#else 450#define wm8731_suspend NULL 451#define wm8731_resume NULL 452#endif 453 454static int wm8731_probe(struct platform_device *pdev) --- 52 unchanged lines hidden (view full) --- 507 .suspend = wm8731_suspend, 508 .resume = wm8731_resume, 509}; 510EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 511 512static int wm8731_register(struct wm8731_priv *wm8731, 513 enum snd_soc_control_type control) 514{ | 467 return 0; 468} 469#else 470#define wm8731_suspend NULL 471#define wm8731_resume NULL 472#endif 473 474static int wm8731_probe(struct platform_device *pdev) --- 52 unchanged lines hidden (view full) --- 527 .suspend = wm8731_suspend, 528 .resume = wm8731_resume, 529}; 530EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 531 532static int wm8731_register(struct wm8731_priv *wm8731, 533 enum snd_soc_control_type control) 534{ |
515 int ret; | 535 int ret, i; |
516 struct snd_soc_codec *codec = &wm8731->codec; 517 518 if (wm8731_codec) { 519 dev_err(codec->dev, "Another WM8731 is registered\n"); 520 ret = -EINVAL; 521 goto err; 522 } 523 --- 14 unchanged lines hidden (view full) --- 538 memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); 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 | 536 struct snd_soc_codec *codec = &wm8731->codec; 537 538 if (wm8731_codec) { 539 dev_err(codec->dev, "Another WM8731 is registered\n"); 540 ret = -EINVAL; 541 goto err; 542 } 543 --- 14 unchanged lines hidden (view full) --- 558 memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg)); 559 560 ret = snd_soc_codec_set_cache_io(codec, 7, 9, control); 561 if (ret < 0) { 562 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 563 goto err; 564 } 565 |
566 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 567 wm8731->supplies[i].supply = wm8731_supply_names[i]; 568 569 ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies), 570 wm8731->supplies); 571 if (ret != 0) { 572 dev_err(codec->dev, "Failed to request supplies: %d\n", ret); 573 goto err; 574 } 575 576 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 577 wm8731->supplies); 578 if (ret != 0) { 579 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); 580 goto err_regulator_get; 581 } 582 |
|
546 ret = wm8731_reset(codec); 547 if (ret < 0) { 548 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); | 583 ret = wm8731_reset(codec); 584 if (ret < 0) { 585 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
549 goto err; | 586 goto err_regulator_enable; |
550 } 551 552 wm8731_dai.dev = codec->dev; 553 554 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 555 556 /* Latch the update bits */ 557 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); --- 4 unchanged lines hidden (view full) --- 562 /* Disable bypass path by default */ 563 snd_soc_update_bits(codec, WM8731_APANA, 0x4, 0); 564 565 wm8731_codec = codec; 566 567 ret = snd_soc_register_codec(codec); 568 if (ret != 0) { 569 dev_err(codec->dev, "Failed to register codec: %d\n", ret); | 587 } 588 589 wm8731_dai.dev = codec->dev; 590 591 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 592 593 /* Latch the update bits */ 594 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); --- 4 unchanged lines hidden (view full) --- 599 /* Disable bypass path by default */ 600 snd_soc_update_bits(codec, WM8731_APANA, 0x4, 0); 601 602 wm8731_codec = codec; 603 604 ret = snd_soc_register_codec(codec); 605 if (ret != 0) { 606 dev_err(codec->dev, "Failed to register codec: %d\n", ret); |
570 goto err; | 607 goto err_regulator_enable; |
571 } 572 573 ret = snd_soc_register_dai(&wm8731_dai); 574 if (ret != 0) { 575 dev_err(codec->dev, "Failed to register DAI: %d\n", ret); 576 snd_soc_unregister_codec(codec); 577 goto err_codec; 578 } 579 580 return 0; 581 582err_codec: 583 snd_soc_unregister_codec(codec); | 608 } 609 610 ret = snd_soc_register_dai(&wm8731_dai); 611 if (ret != 0) { 612 dev_err(codec->dev, "Failed to register DAI: %d\n", ret); 613 snd_soc_unregister_codec(codec); 614 goto err_codec; 615 } 616 617 return 0; 618 619err_codec: 620 snd_soc_unregister_codec(codec); |
621err_regulator_enable: 622 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 623err_regulator_get: 624 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); |
|
584err: 585 kfree(wm8731); 586 return ret; 587} 588 589static void wm8731_unregister(struct wm8731_priv *wm8731) 590{ 591 wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF); 592 snd_soc_unregister_dai(&wm8731_dai); 593 snd_soc_unregister_codec(&wm8731->codec); | 625err: 626 kfree(wm8731); 627 return ret; 628} 629 630static void wm8731_unregister(struct wm8731_priv *wm8731) 631{ 632 wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF); 633 snd_soc_unregister_dai(&wm8731_dai); 634 snd_soc_unregister_codec(&wm8731->codec); |
635 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 636 regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); |
|
594 kfree(wm8731); 595 wm8731_codec = NULL; 596} 597 598#if defined(CONFIG_SPI_MASTER) 599static int __devinit wm8731_spi_probe(struct spi_device *spi) 600{ 601 struct snd_soc_codec *codec; --- 115 unchanged lines hidden --- | 637 kfree(wm8731); 638 wm8731_codec = NULL; 639} 640 641#if defined(CONFIG_SPI_MASTER) 642static int __devinit wm8731_spi_probe(struct spi_device *spi) 643{ 644 struct snd_soc_codec *codec; --- 115 unchanged lines hidden --- |