wm8737.c (4f69bb31b8840713f82c6c476bae3f2356819ce2) | wm8737.c (3ef8ac0d7bd0532fbfb319f3fbf615538394119f) |
---|---|
1/* 2 * wm8737.c -- WM8737 ALSA SoC Audio driver 3 * 4 * Copyright 2010 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> | 1/* 2 * wm8737.c -- WM8737 ALSA SoC Audio driver 3 * 4 * Copyright 2010 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/regmap.h> |
|
19#include <linux/regulator/consumer.h> 20#include <linux/spi/spi.h> 21#include <linux/slab.h> 22#include <linux/of_device.h> 23#include <sound/core.h> 24#include <sound/pcm.h> 25#include <sound/pcm_params.h> 26#include <sound/soc.h> --- 8 unchanged lines hidden (view full) --- 35 "DCVDD", 36 "DBVDD", 37 "AVDD", 38 "MVDD", 39}; 40 41/* codec private data */ 42struct wm8737_priv { | 20#include <linux/regulator/consumer.h> 21#include <linux/spi/spi.h> 22#include <linux/slab.h> 23#include <linux/of_device.h> 24#include <sound/core.h> 25#include <sound/pcm.h> 26#include <sound/pcm_params.h> 27#include <sound/soc.h> --- 8 unchanged lines hidden (view full) --- 36 "DCVDD", 37 "DBVDD", 38 "AVDD", 39 "MVDD", 40}; 41 42/* codec private data */ 43struct wm8737_priv { |
43 enum snd_soc_control_type control_type; | 44 struct regmap *regmap; |
44 struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; 45 unsigned int mclk; 46}; 47 | 45 struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; 46 unsigned int mclk; 47}; 48 |
48static const u16 wm8737_reg[WM8737_REGISTER_COUNT] = { 49 0x00C3, /* R0 - Left PGA volume */ 50 0x00C3, /* R1 - Right PGA volume */ 51 0x0007, /* R2 - AUDIO path L */ 52 0x0007, /* R3 - AUDIO path R */ 53 0x0000, /* R4 - 3D Enhance */ 54 0x0000, /* R5 - ADC Control */ 55 0x0000, /* R6 - Power Management */ 56 0x000A, /* R7 - Audio Format */ 57 0x0000, /* R8 - Clocking */ 58 0x000F, /* R9 - MIC Preamp Control */ 59 0x0003, /* R10 - Misc Bias Control */ 60 0x0000, /* R11 - Noise Gate */ 61 0x007C, /* R12 - ALC1 */ 62 0x0000, /* R13 - ALC2 */ 63 0x0032, /* R14 - ALC3 */ | 49static const struct reg_default wm8737_reg_defaults[] = { 50 { 0, 0x00C3 }, /* R0 - Left PGA volume */ 51 { 1, 0x00C3 }, /* R1 - Right PGA volume */ 52 { 2, 0x0007 }, /* R2 - AUDIO path L */ 53 { 3, 0x0007 }, /* R3 - AUDIO path R */ 54 { 4, 0x0000 }, /* R4 - 3D Enhance */ 55 { 5, 0x0000 }, /* R5 - ADC Control */ 56 { 6, 0x0000 }, /* R6 - Power Management */ 57 { 7, 0x000A }, /* R7 - Audio Format */ 58 { 8, 0x0000 }, /* R8 - Clocking */ 59 { 9, 0x000F }, /* R9 - MIC Preamp Control */ 60 { 10, 0x0003 }, /* R10 - Misc Bias Control */ 61 { 11, 0x0000 }, /* R11 - Noise Gate */ 62 { 12, 0x007C }, /* R12 - ALC1 */ 63 { 13, 0x0000 }, /* R13 - ALC2 */ 64 { 14, 0x0032 }, /* R14 - ALC3 */ |
64}; 65 | 65}; 66 |
67static bool wm8737_volatile(struct device *dev, unsigned int reg) 68{ 69 switch (reg) { 70 case WM8737_RESET: 71 return true; 72 default: 73 return false; 74 } 75} 76 |
|
66static int wm8737_reset(struct snd_soc_codec *codec) 67{ 68 return snd_soc_write(codec, WM8737_RESET, 0); 69} 70 71static const unsigned int micboost_tlv[] = { 72 TLV_DB_RANGE_HEAD(4), 73 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0), --- 400 unchanged lines hidden (view full) --- 474 wm8737->supplies); 475 if (ret != 0) { 476 dev_err(codec->dev, 477 "Failed to enable supplies: %d\n", 478 ret); 479 return ret; 480 } 481 | 77static int wm8737_reset(struct snd_soc_codec *codec) 78{ 79 return snd_soc_write(codec, WM8737_RESET, 0); 80} 81 82static const unsigned int micboost_tlv[] = { 83 TLV_DB_RANGE_HEAD(4), 84 0, 0, TLV_DB_SCALE_ITEM(1300, 0, 0), --- 400 unchanged lines hidden (view full) --- 485 wm8737->supplies); 486 if (ret != 0) { 487 dev_err(codec->dev, 488 "Failed to enable supplies: %d\n", 489 ret); 490 return ret; 491 } 492 |
482 snd_soc_cache_sync(codec); | 493 regcache_sync(wm8737->regmap); |
483 484 /* Fast VMID ramp at 2*2.5k */ 485 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 486 WM8737_VMIDSEL_MASK, 0x4); 487 488 /* Bring VMID up */ 489 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 490 WM8737_VMID_MASK | --- 63 unchanged lines hidden (view full) --- 554#define wm8737_resume NULL 555#endif 556 557static int wm8737_probe(struct snd_soc_codec *codec) 558{ 559 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 560 int ret; 561 | 494 495 /* Fast VMID ramp at 2*2.5k */ 496 snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, 497 WM8737_VMIDSEL_MASK, 0x4); 498 499 /* Bring VMID up */ 500 snd_soc_update_bits(codec, WM8737_POWER_MANAGEMENT, 501 WM8737_VMID_MASK | --- 63 unchanged lines hidden (view full) --- 565#define wm8737_resume NULL 566#endif 567 568static int wm8737_probe(struct snd_soc_codec *codec) 569{ 570 struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); 571 int ret; 572 |
562 ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8737->control_type); | 573 ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); |
563 if (ret != 0) { 564 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 565 return ret; 566 } 567 568 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 569 wm8737->supplies); 570 if (ret != 0) { --- 36 unchanged lines hidden (view full) --- 607} 608 609static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { 610 .probe = wm8737_probe, 611 .remove = wm8737_remove, 612 .suspend = wm8737_suspend, 613 .resume = wm8737_resume, 614 .set_bias_level = wm8737_set_bias_level, | 574 if (ret != 0) { 575 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 576 return ret; 577 } 578 579 ret = regulator_bulk_enable(ARRAY_SIZE(wm8737->supplies), 580 wm8737->supplies); 581 if (ret != 0) { --- 36 unchanged lines hidden (view full) --- 618} 619 620static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { 621 .probe = wm8737_probe, 622 .remove = wm8737_remove, 623 .suspend = wm8737_suspend, 624 .resume = wm8737_resume, 625 .set_bias_level = wm8737_set_bias_level, |
615 616 .reg_cache_size = WM8737_REGISTER_COUNT - 1, /* Skip reset */ 617 .reg_word_size = sizeof(u16), 618 .reg_cache_default = wm8737_reg, | |
619}; 620 621static const struct of_device_id wm8737_of_match[] = { 622 { .compatible = "wlf,wm8737", }, 623 { } 624}; 625 626MODULE_DEVICE_TABLE(of, wm8737_of_match); 627 | 626}; 627 628static const struct of_device_id wm8737_of_match[] = { 629 { .compatible = "wlf,wm8737", }, 630 { } 631}; 632 633MODULE_DEVICE_TABLE(of, wm8737_of_match); 634 |
635static const struct regmap_config wm8737_regmap = { 636 .reg_bits = 7, 637 .val_bits = 9, 638 .max_register = WM8737_MAX_REGISTER, 639 640 .reg_defaults = wm8737_reg_defaults, 641 .num_reg_defaults = ARRAY_SIZE(wm8737_reg_defaults), 642 .cache_type = REGCACHE_RBTREE, 643 644 .volatile_reg = wm8737_volatile, 645}; 646 |
|
628#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 629static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, 630 const struct i2c_device_id *id) 631{ 632 struct wm8737_priv *wm8737; 633 int ret, i; 634 635 wm8737 = devm_kzalloc(&i2c->dev, sizeof(struct wm8737_priv), --- 6 unchanged lines hidden (view full) --- 642 643 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8737->supplies), 644 wm8737->supplies); 645 if (ret != 0) { 646 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); 647 return ret; 648 } 649 | 647#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 648static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, 649 const struct i2c_device_id *id) 650{ 651 struct wm8737_priv *wm8737; 652 int ret, i; 653 654 wm8737 = devm_kzalloc(&i2c->dev, sizeof(struct wm8737_priv), --- 6 unchanged lines hidden (view full) --- 661 662 ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8737->supplies), 663 wm8737->supplies); 664 if (ret != 0) { 665 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); 666 return ret; 667 } 668 |
669 wm8737->regmap = devm_regmap_init_i2c(i2c, &wm8737_regmap); 670 if (IS_ERR(wm8737->regmap)) 671 return PTR_ERR(wm8737->regmap); 672 |
|
650 i2c_set_clientdata(i2c, wm8737); | 673 i2c_set_clientdata(i2c, wm8737); |
651 wm8737->control_type = SND_SOC_I2C; | |
652 653 ret = snd_soc_register_codec(&i2c->dev, 654 &soc_codec_dev_wm8737, &wm8737_dai, 1); 655 656 return ret; 657 658} 659 --- 38 unchanged lines hidden (view full) --- 698 699 ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8737->supplies), 700 wm8737->supplies); 701 if (ret != 0) { 702 dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); 703 return ret; 704 } 705 | 674 675 ret = snd_soc_register_codec(&i2c->dev, 676 &soc_codec_dev_wm8737, &wm8737_dai, 1); 677 678 return ret; 679 680} 681 --- 38 unchanged lines hidden (view full) --- 720 721 ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8737->supplies), 722 wm8737->supplies); 723 if (ret != 0) { 724 dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); 725 return ret; 726 } 727 |
706 wm8737->control_type = SND_SOC_SPI; | 728 wm8737->regmap = devm_regmap_init_spi(spi, &wm8737_regmap); 729 if (IS_ERR(wm8737->regmap)) 730 return PTR_ERR(wm8737->regmap); 731 |
707 spi_set_drvdata(spi, wm8737); 708 709 ret = snd_soc_register_codec(&spi->dev, 710 &soc_codec_dev_wm8737, &wm8737_dai, 1); 711 712 return ret; 713} 714 --- 53 unchanged lines hidden --- | 732 spi_set_drvdata(spi, wm8737); 733 734 ret = snd_soc_register_codec(&spi->dev, 735 &soc_codec_dev_wm8737, &wm8737_dai, 1); 736 737 return ret; 738} 739 --- 53 unchanged lines hidden --- |