aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8804.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-29 14:58:06 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-01-20 08:58:23 -0500
commit891271c28f06881332c6131158ea13f328401aa7 (patch)
tree4c195d95725f77ad85a384c868eda7f1112d3d26 /sound/soc/codecs/wm8804.c
parentf649f1a8aadeb9ba146359daf51cc5ed137b394e (diff)
ASoC: Convert wm8804 to direct regmap API usage
The register map for this device is actually fairly sparse so the rbtree should be beneficial. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8804.c')
-rw-r--r--sound/soc/codecs/wm8804.c115
1 files changed, 62 insertions, 53 deletions
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index a9f1eb334f7..8abe3757a97 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -18,6 +18,7 @@
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/of_device.h> 19#include <linux/of_device.h>
20#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
21#include <linux/regmap.h>
21#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <sound/core.h> 24#include <sound/core.h>
@@ -35,45 +36,33 @@ static const char *wm8804_supply_names[WM8804_NUM_SUPPLIES] = {
35 "DVDD" 36 "DVDD"
36}; 37};
37 38
38static const u8 wm8804_reg_defs[] = { 39static const struct reg_default wm8804_reg_defaults[] = {
39 0x05, /* R0 - RST/DEVID1 */ 40 { 3, 0x21 }, /* R3 - PLL1 */
40 0x88, /* R1 - DEVID2 */ 41 { 4, 0xFD }, /* R4 - PLL2 */
41 0x04, /* R2 - DEVREV */ 42 { 5, 0x36 }, /* R5 - PLL3 */
42 0x21, /* R3 - PLL1 */ 43 { 6, 0x07 }, /* R6 - PLL4 */
43 0xFD, /* R4 - PLL2 */ 44 { 7, 0x16 }, /* R7 - PLL5 */
44 0x36, /* R5 - PLL3 */ 45 { 8, 0x18 }, /* R8 - PLL6 */
45 0x07, /* R6 - PLL4 */ 46 { 9, 0xFF }, /* R9 - SPDMODE */
46 0x16, /* R7 - PLL5 */ 47 { 10, 0x00 }, /* R10 - INTMASK */
47 0x18, /* R8 - PLL6 */ 48 { 18, 0x00 }, /* R18 - SPDTX1 */
48 0xFF, /* R9 - SPDMODE */ 49 { 19, 0x00 }, /* R19 - SPDTX2 */
49 0x00, /* R10 - INTMASK */ 50 { 20, 0x00 }, /* R20 - SPDTX3 */
50 0x00, /* R11 - INTSTAT */ 51 { 21, 0x71 }, /* R21 - SPDTX4 */
51 0x00, /* R12 - SPDSTAT */ 52 { 22, 0x0B }, /* R22 - SPDTX5 */
52 0x00, /* R13 - RXCHAN1 */ 53 { 23, 0x70 }, /* R23 - GPO0 */
53 0x00, /* R14 - RXCHAN2 */ 54 { 24, 0x57 }, /* R24 - GPO1 */
54 0x00, /* R15 - RXCHAN3 */ 55 { 26, 0x42 }, /* R26 - GPO2 */
55 0x00, /* R16 - RXCHAN4 */ 56 { 27, 0x06 }, /* R27 - AIFTX */
56 0x00, /* R17 - RXCHAN5 */ 57 { 28, 0x06 }, /* R28 - AIFRX */
57 0x00, /* R18 - SPDTX1 */ 58 { 29, 0x80 }, /* R29 - SPDRX1 */
58 0x00, /* R19 - SPDTX2 */ 59 { 30, 0x07 }, /* R30 - PWRDN */
59 0x00, /* R20 - SPDTX3 */
60 0x71, /* R21 - SPDTX4 */
61 0x0B, /* R22 - SPDTX5 */
62 0x70, /* R23 - GPO0 */
63 0x57, /* R24 - GPO1 */
64 0x00, /* R25 */
65 0x42, /* R26 - GPO2 */
66 0x06, /* R27 - AIFTX */
67 0x06, /* R28 - AIFRX */
68 0x80, /* R29 - SPDRX1 */
69 0x07, /* R30 - PWRDN */
70}; 60};
71 61
72struct wm8804_priv { 62struct wm8804_priv {
73 enum snd_soc_control_type control_type; 63 struct regmap *regmap;
74 struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES]; 64 struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
75 struct notifier_block disable_nb[WM8804_NUM_SUPPLIES]; 65 struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
76 struct snd_soc_codec *codec;
77}; 66};
78 67
79static int txsrc_get(struct snd_kcontrol *kcontrol, 68static int txsrc_get(struct snd_kcontrol *kcontrol,
@@ -94,7 +83,7 @@ static int wm8804_regulator_event_##n(struct notifier_block *nb, \
94 struct wm8804_priv *wm8804 = container_of(nb, struct wm8804_priv, \ 83 struct wm8804_priv *wm8804 = container_of(nb, struct wm8804_priv, \
95 disable_nb[n]); \ 84 disable_nb[n]); \
96 if (event & REGULATOR_EVENT_DISABLE) { \ 85 if (event & REGULATOR_EVENT_DISABLE) { \
97 wm8804->codec->cache_sync = 1; \ 86 regcache_mark_dirty(wm8804->regmap); \
98 } \ 87 } \
99 return 0; \ 88 return 0; \
100} 89}
@@ -176,7 +165,7 @@ static int txsrc_put(struct snd_kcontrol *kcontrol,
176 return 0; 165 return 0;
177} 166}
178 167
179static int wm8804_volatile(struct snd_soc_codec *codec, unsigned int reg) 168static bool wm8804_volatile(struct device *dev, unsigned int reg)
180{ 169{
181 switch (reg) { 170 switch (reg) {
182 case WM8804_RST_DEVID1: 171 case WM8804_RST_DEVID1:
@@ -189,12 +178,10 @@ static int wm8804_volatile(struct snd_soc_codec *codec, unsigned int reg)
189 case WM8804_RXCHAN3: 178 case WM8804_RXCHAN3:
190 case WM8804_RXCHAN4: 179 case WM8804_RXCHAN4:
191 case WM8804_RXCHAN5: 180 case WM8804_RXCHAN5:
192 return 1; 181 return true;
193 default: 182 default:
194 break; 183 return false;
195 } 184 }
196
197 return 0;
198} 185}
199 186
200static int wm8804_reset(struct snd_soc_codec *codec) 187static int wm8804_reset(struct snd_soc_codec *codec)
@@ -506,7 +493,7 @@ static int wm8804_set_bias_level(struct snd_soc_codec *codec,
506 ret); 493 ret);
507 return ret; 494 return ret;
508 } 495 }
509 snd_soc_cache_sync(codec); 496 regcache_sync(wm8804->regmap);
510 } 497 }
511 /* power down the OSC and the PLL */ 498 /* power down the OSC and the PLL */
512 snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9); 499 snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0x9);
@@ -561,11 +548,11 @@ static int wm8804_probe(struct snd_soc_codec *codec)
561 int i, id1, id2, ret; 548 int i, id1, id2, ret;
562 549
563 wm8804 = snd_soc_codec_get_drvdata(codec); 550 wm8804 = snd_soc_codec_get_drvdata(codec);
564 wm8804->codec = codec;
565 551
566 codec->dapm.idle_bias_off = 1; 552 codec->dapm.idle_bias_off = 1;
553 codec->control_data = wm8804->regmap;
567 554
568 ret = snd_soc_codec_set_cache_io(codec, 8, 8, wm8804->control_type); 555 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
569 if (ret < 0) { 556 if (ret < 0) {
570 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret); 557 dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret);
571 return ret; 558 return ret;
@@ -618,8 +605,7 @@ static int wm8804_probe(struct snd_soc_codec *codec)
618 605
619 id2 = (id2 << 8) | id1; 606 id2 = (id2 << 8) | id1;
620 607
621 if (id2 != ((wm8804_reg_defs[WM8804_DEVID2] << 8) 608 if (id2 != 0x8805) {
622 | wm8804_reg_defs[WM8804_RST_DEVID1])) {
623 dev_err(codec->dev, "Invalid device ID: %#x\n", id2); 609 dev_err(codec->dev, "Invalid device ID: %#x\n", id2);
624 ret = -EINVAL; 610 ret = -EINVAL;
625 goto err_reg_enable; 611 goto err_reg_enable;
@@ -692,10 +678,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8804 = {
692 .suspend = wm8804_suspend, 678 .suspend = wm8804_suspend,
693 .resume = wm8804_resume, 679 .resume = wm8804_resume,
694 .set_bias_level = wm8804_set_bias_level, 680 .set_bias_level = wm8804_set_bias_level,
695 .reg_cache_size = ARRAY_SIZE(wm8804_reg_defs),
696 .reg_word_size = sizeof(u8),
697 .reg_cache_default = wm8804_reg_defs,
698 .volatile_register = wm8804_volatile,
699 681
700 .controls = wm8804_snd_controls, 682 .controls = wm8804_snd_controls,
701 .num_controls = ARRAY_SIZE(wm8804_snd_controls), 683 .num_controls = ARRAY_SIZE(wm8804_snd_controls),
@@ -707,6 +689,18 @@ static const struct of_device_id wm8804_of_match[] = {
707}; 689};
708MODULE_DEVICE_TABLE(of, wm8804_of_match); 690MODULE_DEVICE_TABLE(of, wm8804_of_match);
709 691
692static struct regmap_config wm8804_regmap_config = {
693 .reg_bits = 8,
694 .val_bits = 8,
695
696 .max_register = WM8804_MAX_REGISTER,
697 .volatile_reg = wm8804_volatile,
698
699 .cache_type = REGCACHE_RBTREE,
700 .reg_defaults = wm8804_reg_defaults,
701 .num_reg_defaults = ARRAY_SIZE(wm8804_reg_defaults),
702};
703
710#if defined(CONFIG_SPI_MASTER) 704#if defined(CONFIG_SPI_MASTER)
711static int __devinit wm8804_spi_probe(struct spi_device *spi) 705static int __devinit wm8804_spi_probe(struct spi_device *spi)
712{ 706{
@@ -717,7 +711,12 @@ static int __devinit wm8804_spi_probe(struct spi_device *spi)
717 if (!wm8804) 711 if (!wm8804)
718 return -ENOMEM; 712 return -ENOMEM;
719 713
720 wm8804->control_type = SND_SOC_SPI; 714 wm8804->regmap = regmap_init_spi(spi, &wm8804_regmap_config);
715 if (IS_ERR(wm8804->regmap)) {
716 ret = PTR_ERR(wm8804->regmap);
717 return ret;
718 }
719
721 spi_set_drvdata(spi, wm8804); 720 spi_set_drvdata(spi, wm8804);
722 721
723 ret = snd_soc_register_codec(&spi->dev, 722 ret = snd_soc_register_codec(&spi->dev,
@@ -728,7 +727,9 @@ static int __devinit wm8804_spi_probe(struct spi_device *spi)
728 727
729static int __devexit wm8804_spi_remove(struct spi_device *spi) 728static int __devexit wm8804_spi_remove(struct spi_device *spi)
730{ 729{
730 struct wm8804_priv *wm8804 = spi_get_drvdata(spi);
731 snd_soc_unregister_codec(&spi->dev); 731 snd_soc_unregister_codec(&spi->dev);
732 regmap_exit(wm8804->regmap);
732 return 0; 733 return 0;
733} 734}
734 735
@@ -754,18 +755,26 @@ static __devinit int wm8804_i2c_probe(struct i2c_client *i2c,
754 if (!wm8804) 755 if (!wm8804)
755 return -ENOMEM; 756 return -ENOMEM;
756 757
757 wm8804->control_type = SND_SOC_I2C;
758 i2c_set_clientdata(i2c, wm8804); 758 i2c_set_clientdata(i2c, wm8804);
759 759
760 ret = snd_soc_register_codec(&i2c->dev, 760 ret = snd_soc_register_codec(&i2c->dev,
761 &soc_codec_dev_wm8804, &wm8804_dai, 1); 761 &soc_codec_dev_wm8804, &wm8804_dai, 1);
762 if (ret != 0)
763 goto err;
762 764
765 return 0;
766
767err:
768 regmap_exit(wm8804->regmap);
763 return ret; 769 return ret;
764} 770}
765 771
766static __devexit int wm8804_i2c_remove(struct i2c_client *client) 772static __devexit int wm8804_i2c_remove(struct i2c_client *i2c)
767{ 773{
768 snd_soc_unregister_codec(&client->dev); 774 struct wm8804_priv *wm8804 = i2c_get_clientdata(i2c);
775
776 snd_soc_unregister_codec(&i2c->dev);
777 regmap_exit(wm8804->regmap);
769 778
770 return 0; 779 return 0;
771} 780}