wm8731.c (19c22c34dcbecb50c24548aa2ff2b07039c26c14) | wm8731.c (05d448e2c9bc587216549d690332c72a74271abd) |
---|---|
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/slab.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/slab.h> |
22#include <linux/regmap.h> |
|
22#include <linux/regulator/consumer.h> 23#include <linux/spi/spi.h> 24#include <linux/of_device.h> 25#include <sound/core.h> 26#include <sound/pcm.h> 27#include <sound/pcm_params.h> 28#include <sound/soc.h> 29#include <sound/initval.h> --- 6 unchanged lines hidden (view full) --- 36 "AVDD", 37 "HPVDD", 38 "DCVDD", 39 "DBVDD", 40}; 41 42/* codec private data */ 43struct wm8731_priv { | 23#include <linux/regulator/consumer.h> 24#include <linux/spi/spi.h> 25#include <linux/of_device.h> 26#include <sound/core.h> 27#include <sound/pcm.h> 28#include <sound/pcm_params.h> 29#include <sound/soc.h> 30#include <sound/initval.h> --- 6 unchanged lines hidden (view full) --- 37 "AVDD", 38 "HPVDD", 39 "DCVDD", 40 "DBVDD", 41}; 42 43/* codec private data */ 44struct wm8731_priv { |
44 enum snd_soc_control_type control_type; | 45 struct regmap *regmap; |
45 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 46 unsigned int sysclk; 47 int sysclk_type; 48 int playback_fs; 49 bool deemph; 50}; 51 52 53/* 54 * wm8731 register cache | 46 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 47 unsigned int sysclk; 48 int sysclk_type; 49 int playback_fs; 50 bool deemph; 51}; 52 53 54/* 55 * wm8731 register cache |
55 * We can't read the WM8731 register space when we are 56 * using 2 wire for device control, so we cache them instead. 57 * There is no point in caching the reset register | |
58 */ | 56 */ |
59static const u16 wm8731_reg[WM8731_CACHEREGNUM] = { 60 0x0097, 0x0097, 0x0079, 0x0079, 61 0x000a, 0x0008, 0x009f, 0x000a, 62 0x0000, 0x0000 | 57static const struct reg_default wm8731_reg_defaults[] = { 58 { 0, 0x0097 }, 59 { 1, 0x0097 }, 60 { 2, 0x0079 }, 61 { 3, 0x0079 }, 62 { 4, 0x000a }, 63 { 5, 0x0008 }, 64 { 6, 0x009f }, 65 { 7, 0x000a }, 66 { 8, 0x0000 }, 67 { 9, 0x0000 }, |
63}; 64 | 68}; 69 |
70static bool wm8731_volatile(struct device *dev, unsigned int reg) 71{ 72 return reg == WM8731_RESET; 73} 74 75static bool wm8731_writeable(struct device *dev, unsigned int reg) 76{ 77 return reg <= WM8731_RESET; 78} 79 |
|
65#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) 66 67static const char *wm8731_input_select[] = {"Line In", "Mic"}; 68 69static const struct soc_enum wm8731_insel_enum = 70 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select); 71 72static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; --- 363 unchanged lines hidden (view full) --- 436 break; 437 case SND_SOC_BIAS_STANDBY: 438 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 439 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 440 wm8731->supplies); 441 if (ret != 0) 442 return ret; 443 | 80#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) 81 82static const char *wm8731_input_select[] = {"Line In", "Mic"}; 83 84static const struct soc_enum wm8731_insel_enum = 85 SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select); 86 87static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; --- 363 unchanged lines hidden (view full) --- 451 break; 452 case SND_SOC_BIAS_STANDBY: 453 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 454 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 455 wm8731->supplies); 456 if (ret != 0) 457 return ret; 458 |
444 snd_soc_cache_sync(codec); | 459 regcache_sync(wm8731->regmap); |
445 } 446 447 /* Clear PWROFF, gate CLKOUT, everything else as-is */ 448 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; 449 snd_soc_write(codec, WM8731_PWR, reg | 0x0040); 450 break; 451 case SND_SOC_BIAS_OFF: 452 snd_soc_write(codec, WM8731_PWR, 0xffff); 453 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 454 wm8731->supplies); | 460 } 461 462 /* Clear PWROFF, gate CLKOUT, everything else as-is */ 463 reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f; 464 snd_soc_write(codec, WM8731_PWR, reg | 0x0040); 465 break; 466 case SND_SOC_BIAS_OFF: 467 snd_soc_write(codec, WM8731_PWR, 0xffff); 468 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), 469 wm8731->supplies); |
455 codec->cache_sync = 1; | 470 regcache_mark_dirty(wm8731->regmap); |
456 break; 457 } 458 codec->dapm.bias_level = level; 459 return 0; 460} 461 462#define WM8731_RATES SNDRV_PCM_RATE_8000_96000 463 --- 44 unchanged lines hidden (view full) --- 508#define wm8731_resume NULL 509#endif 510 511static int wm8731_probe(struct snd_soc_codec *codec) 512{ 513 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 514 int ret = 0, i; 515 | 471 break; 472 } 473 codec->dapm.bias_level = level; 474 return 0; 475} 476 477#define WM8731_RATES SNDRV_PCM_RATE_8000_96000 478 --- 44 unchanged lines hidden (view full) --- 523#define wm8731_resume NULL 524#endif 525 526static int wm8731_probe(struct snd_soc_codec *codec) 527{ 528 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 529 int ret = 0, i; 530 |
516 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8731->control_type); | 531 codec->control_data = wm8731->regmap; 532 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); |
517 if (ret < 0) { 518 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 519 return ret; 520 } 521 522 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 523 wm8731->supplies[i].supply = wm8731_supply_names[i]; 524 --- 55 unchanged lines hidden (view full) --- 580} 581 582static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { 583 .probe = wm8731_probe, 584 .remove = wm8731_remove, 585 .suspend = wm8731_suspend, 586 .resume = wm8731_resume, 587 .set_bias_level = wm8731_set_bias_level, | 533 if (ret < 0) { 534 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 535 return ret; 536 } 537 538 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 539 wm8731->supplies[i].supply = wm8731_supply_names[i]; 540 --- 55 unchanged lines hidden (view full) --- 596} 597 598static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { 599 .probe = wm8731_probe, 600 .remove = wm8731_remove, 601 .suspend = wm8731_suspend, 602 .resume = wm8731_resume, 603 .set_bias_level = wm8731_set_bias_level, |
588 .reg_cache_size = ARRAY_SIZE(wm8731_reg), 589 .reg_word_size = sizeof(u16), 590 .reg_cache_default = wm8731_reg, | |
591 .dapm_widgets = wm8731_dapm_widgets, 592 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 593 .dapm_routes = wm8731_intercon, 594 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 595 .controls = wm8731_snd_controls, 596 .num_controls = ARRAY_SIZE(wm8731_snd_controls), 597}; 598 599static const struct of_device_id wm8731_of_match[] = { 600 { .compatible = "wlf,wm8731", }, 601 { } 602}; 603 604MODULE_DEVICE_TABLE(of, wm8731_of_match); 605 | 604 .dapm_widgets = wm8731_dapm_widgets, 605 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 606 .dapm_routes = wm8731_intercon, 607 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 608 .controls = wm8731_snd_controls, 609 .num_controls = ARRAY_SIZE(wm8731_snd_controls), 610}; 611 612static const struct of_device_id wm8731_of_match[] = { 613 { .compatible = "wlf,wm8731", }, 614 { } 615}; 616 617MODULE_DEVICE_TABLE(of, wm8731_of_match); 618 |
619static const struct regmap_config wm8731_regmap = { 620 .reg_bits = 7, 621 .val_bits = 9, 622 623 .max_register = WM8731_RESET, 624 .volatile_reg = wm8731_volatile, 625 .writeable_reg = wm8731_writeable, 626 627 .cache_type = REGCACHE_RBTREE, 628 .reg_defaults = wm8731_reg_defaults, 629 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults), 630}; 631 |
|
606#if defined(CONFIG_SPI_MASTER) 607static int __devinit wm8731_spi_probe(struct spi_device *spi) 608{ 609 struct wm8731_priv *wm8731; 610 int ret; 611 612 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 613 if (wm8731 == NULL) 614 return -ENOMEM; 615 | 632#if defined(CONFIG_SPI_MASTER) 633static int __devinit wm8731_spi_probe(struct spi_device *spi) 634{ 635 struct wm8731_priv *wm8731; 636 int ret; 637 638 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 639 if (wm8731 == NULL) 640 return -ENOMEM; 641 |
616 wm8731->control_type = SND_SOC_SPI; | 642 wm8731->regmap = regmap_init_spi(spi, &wm8731_regmap); 643 if (IS_ERR(wm8731->regmap)) { 644 ret = PTR_ERR(wm8731->regmap); 645 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 646 ret); 647 goto err; 648 } 649 |
617 spi_set_drvdata(spi, wm8731); 618 619 ret = snd_soc_register_codec(&spi->dev, 620 &soc_codec_dev_wm8731, &wm8731_dai, 1); | 650 spi_set_drvdata(spi, wm8731); 651 652 ret = snd_soc_register_codec(&spi->dev, 653 &soc_codec_dev_wm8731, &wm8731_dai, 1); |
621 if (ret < 0) 622 kfree(wm8731); | 654 if (ret != 0) { 655 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); 656 goto err_regmap; 657 } 658 659 return 0; 660 661err_regmap: 662 regmap_exit(wm8731->regmap); 663err: 664 kfree(wm8731); |
623 return ret; 624} 625 626static int __devexit wm8731_spi_remove(struct spi_device *spi) 627{ | 665 return ret; 666} 667 668static int __devexit wm8731_spi_remove(struct spi_device *spi) 669{ |
670 struct wm8731_priv *wm8731 = spi_get_drvdata(spi); 671 |
|
628 snd_soc_unregister_codec(&spi->dev); | 672 snd_soc_unregister_codec(&spi->dev); |
629 kfree(spi_get_drvdata(spi)); | 673 regmap_exit(wm8731->regmap); 674 kfree(wm8731); |
630 return 0; 631} 632 633static struct spi_driver wm8731_spi_driver = { 634 .driver = { 635 .name = "wm8731", 636 .owner = THIS_MODULE, 637 .of_match_table = wm8731_of_match, --- 9 unchanged lines hidden (view full) --- 647{ 648 struct wm8731_priv *wm8731; 649 int ret; 650 651 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 652 if (wm8731 == NULL) 653 return -ENOMEM; 654 | 675 return 0; 676} 677 678static struct spi_driver wm8731_spi_driver = { 679 .driver = { 680 .name = "wm8731", 681 .owner = THIS_MODULE, 682 .of_match_table = wm8731_of_match, --- 9 unchanged lines hidden (view full) --- 692{ 693 struct wm8731_priv *wm8731; 694 int ret; 695 696 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 697 if (wm8731 == NULL) 698 return -ENOMEM; 699 |
700 wm8731->regmap = regmap_init_i2c(i2c, &wm8731_regmap); 701 if (IS_ERR(wm8731->regmap)) { 702 ret = PTR_ERR(wm8731->regmap); 703 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 704 ret); 705 goto err; 706 } 707 |
|
655 i2c_set_clientdata(i2c, wm8731); | 708 i2c_set_clientdata(i2c, wm8731); |
656 wm8731->control_type = SND_SOC_I2C; | |
657 | 709 |
658 ret = snd_soc_register_codec(&i2c->dev, | 710 ret = snd_soc_register_codec(&i2c->dev, |
659 &soc_codec_dev_wm8731, &wm8731_dai, 1); | 711 &soc_codec_dev_wm8731, &wm8731_dai, 1); |
660 if (ret < 0) 661 kfree(wm8731); | 712 if (ret != 0) { 713 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); 714 goto err_regmap; 715 } 716 717 return 0; 718 719err_regmap: 720 regmap_exit(wm8731->regmap); 721err: 722 kfree(wm8731); |
662 return ret; 663} 664 665static __devexit int wm8731_i2c_remove(struct i2c_client *client) 666{ | 723 return ret; 724} 725 726static __devexit int wm8731_i2c_remove(struct i2c_client *client) 727{ |
728 struct wm8731_priv *wm8731 = i2c_get_clientdata(client); |
|
667 snd_soc_unregister_codec(&client->dev); | 729 snd_soc_unregister_codec(&client->dev); |
668 kfree(i2c_get_clientdata(client)); | 730 regmap_exit(wm8731->regmap); 731 kfree(wm8731); |
669 return 0; 670} 671 672static const struct i2c_device_id wm8731_i2c_id[] = { 673 { "wm8731", 0 }, 674 { } 675}; 676MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); --- 48 unchanged lines hidden --- | 732 return 0; 733} 734 735static const struct i2c_device_id wm8731_i2c_id[] = { 736 { "wm8731", 0 }, 737 { } 738}; 739MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); --- 48 unchanged lines hidden --- |