aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8776.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2009-08-08 05:37:33 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-08-08 05:37:33 -0400
commit35b1207b34975d7ff2ea014171229c02bdb066f1 (patch)
tree1d4cb045f24268929481c296e5e9adc69841df03 /sound/soc/codecs/wm8776.c
parent7ae5945f0cacdfa30ed3257892dbea75bc959a28 (diff)
ASoC: Convert WM8776 to use factored out register cache code
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8776.c')
-rw-r--r--sound/soc/codecs/wm8776.c59
1 files changed, 11 insertions, 48 deletions
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index ee12bf824a40..a9829aa26e53 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -52,51 +52,9 @@ static const u16 wm8776_reg[WM8776_CACHEREGNUM] = {
52 0xa6, 0x01, 0x01 52 0xa6, 0x01, 0x01
53}; 53};
54 54
55/*
56 * read wm8776 register cache
57 */
58static inline unsigned int wm8776_read_reg_cache(struct snd_soc_codec *codec,
59 unsigned int reg)
60{
61 u16 *cache = codec->reg_cache;
62 if (reg >= WM8776_CACHEREGNUM)
63 return -1;
64 return cache[reg];
65}
66
67/*
68 * write wm8776 register cache
69 */
70static inline void wm8776_write_reg_cache(struct snd_soc_codec *codec,
71 u16 reg, unsigned int value)
72{
73 u16 *cache = codec->reg_cache;
74 if (reg >= WM8776_CACHEREGNUM)
75 return;
76 cache[reg] = value;
77}
78
79/*
80 * write to the WM8776 register space
81 */
82static int wm8776_write(struct snd_soc_codec *codec, unsigned int reg,
83 unsigned int value)
84{
85 u8 data[2];
86
87 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
88 data[1] = value & 0x00ff;
89
90 wm8776_write_reg_cache(codec, reg, value);
91 if (codec->hw_write(codec->control_data, data, 2) == 2)
92 return 0;
93 else
94 return -EIO;
95}
96
97static int wm8776_reset(struct snd_soc_codec *codec) 55static int wm8776_reset(struct snd_soc_codec *codec)
98{ 56{
99 return wm8776_write(codec, WM8776_RESET, 0); 57 return snd_soc_write(codec, WM8776_RESET, 0);
100} 58}
101 59
102static const DECLARE_TLV_DB_SCALE(hp_tlv, -12100, 100, 1); 60static const DECLARE_TLV_DB_SCALE(hp_tlv, -12100, 100, 1);
@@ -523,7 +481,8 @@ struct snd_soc_codec_device soc_codec_dev_wm8776 = {
523}; 481};
524EXPORT_SYMBOL_GPL(soc_codec_dev_wm8776); 482EXPORT_SYMBOL_GPL(soc_codec_dev_wm8776);
525 483
526static int wm8776_register(struct wm8776_priv *wm8776) 484static int wm8776_register(struct wm8776_priv *wm8776,
485 enum snd_soc_control_type control)
527{ 486{
528 int ret, i; 487 int ret, i;
529 struct snd_soc_codec *codec = &wm8776->codec; 488 struct snd_soc_codec *codec = &wm8776->codec;
@@ -541,8 +500,6 @@ static int wm8776_register(struct wm8776_priv *wm8776)
541 codec->private_data = wm8776; 500 codec->private_data = wm8776;
542 codec->name = "WM8776"; 501 codec->name = "WM8776";
543 codec->owner = THIS_MODULE; 502 codec->owner = THIS_MODULE;
544 codec->read = wm8776_read_reg_cache;
545 codec->write = wm8776_write;
546 codec->bias_level = SND_SOC_BIAS_OFF; 503 codec->bias_level = SND_SOC_BIAS_OFF;
547 codec->set_bias_level = wm8776_set_bias_level; 504 codec->set_bias_level = wm8776_set_bias_level;
548 codec->dai = wm8776_dai; 505 codec->dai = wm8776_dai;
@@ -552,6 +509,12 @@ static int wm8776_register(struct wm8776_priv *wm8776)
552 509
553 memcpy(codec->reg_cache, wm8776_reg, sizeof(wm8776_reg)); 510 memcpy(codec->reg_cache, wm8776_reg, sizeof(wm8776_reg));
554 511
512 ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
513 if (ret < 0) {
514 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
515 goto err;
516 }
517
555 for (i = 0; i < ARRAY_SIZE(wm8776_dai); i++) 518 for (i = 0; i < ARRAY_SIZE(wm8776_dai); i++)
556 wm8776_dai[i].dev = codec->dev; 519 wm8776_dai[i].dev = codec->dev;
557 520
@@ -641,7 +604,7 @@ static int __devinit wm8776_spi_probe(struct spi_device *spi)
641 604
642 dev_set_drvdata(&spi->dev, wm8776); 605 dev_set_drvdata(&spi->dev, wm8776);
643 606
644 return wm8776_register(wm8776); 607 return wm8776_register(wm8776, SND_SOC_SPI);
645} 608}
646 609
647static int __devexit wm8776_spi_remove(struct spi_device *spi) 610static int __devexit wm8776_spi_remove(struct spi_device *spi)
@@ -700,7 +663,7 @@ static __devinit int wm8776_i2c_probe(struct i2c_client *i2c,
700 663
701 codec->dev = &i2c->dev; 664 codec->dev = &i2c->dev;
702 665
703 return wm8776_register(wm8776); 666 return wm8776_register(wm8776, SND_SOC_I2C);
704} 667}
705 668
706static __devexit int wm8776_i2c_remove(struct i2c_client *client) 669static __devexit int wm8776_i2c_remove(struct i2c_client *client)