diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-12 00:48:48 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-12 02:09:38 -0400 |
commit | 3ef8ac0d7bd0532fbfb319f3fbf615538394119f (patch) | |
tree | 9a67471cc09a03c8d130aef75a02eb7cd6923e20 /sound | |
parent | 4f69bb31b8840713f82c6c476bae3f2356819ce2 (diff) |
ASoC: wm8737: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/wm8737.c | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c index 3bf5bc73e2de..5c9634f4c1f0 100644 --- a/sound/soc/codecs/wm8737.c +++ b/sound/soc/codecs/wm8737.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/pm.h> | 17 | #include <linux/pm.h> |
18 | #include <linux/i2c.h> | 18 | #include <linux/i2c.h> |
19 | #include <linux/regmap.h> | ||
19 | #include <linux/regulator/consumer.h> | 20 | #include <linux/regulator/consumer.h> |
20 | #include <linux/spi/spi.h> | 21 | #include <linux/spi/spi.h> |
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
@@ -40,29 +41,39 @@ static const char *wm8737_supply_names[WM8737_NUM_SUPPLIES] = { | |||
40 | 41 | ||
41 | /* codec private data */ | 42 | /* codec private data */ |
42 | struct wm8737_priv { | 43 | struct wm8737_priv { |
43 | enum snd_soc_control_type control_type; | 44 | struct regmap *regmap; |
44 | struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; | 45 | struct regulator_bulk_data supplies[WM8737_NUM_SUPPLIES]; |
45 | unsigned int mclk; | 46 | unsigned int mclk; |
46 | }; | 47 | }; |
47 | 48 | ||
48 | static const u16 wm8737_reg[WM8737_REGISTER_COUNT] = { | 49 | static const struct reg_default wm8737_reg_defaults[] = { |
49 | 0x00C3, /* R0 - Left PGA volume */ | 50 | { 0, 0x00C3 }, /* R0 - Left PGA volume */ |
50 | 0x00C3, /* R1 - Right PGA volume */ | 51 | { 1, 0x00C3 }, /* R1 - Right PGA volume */ |
51 | 0x0007, /* R2 - AUDIO path L */ | 52 | { 2, 0x0007 }, /* R2 - AUDIO path L */ |
52 | 0x0007, /* R3 - AUDIO path R */ | 53 | { 3, 0x0007 }, /* R3 - AUDIO path R */ |
53 | 0x0000, /* R4 - 3D Enhance */ | 54 | { 4, 0x0000 }, /* R4 - 3D Enhance */ |
54 | 0x0000, /* R5 - ADC Control */ | 55 | { 5, 0x0000 }, /* R5 - ADC Control */ |
55 | 0x0000, /* R6 - Power Management */ | 56 | { 6, 0x0000 }, /* R6 - Power Management */ |
56 | 0x000A, /* R7 - Audio Format */ | 57 | { 7, 0x000A }, /* R7 - Audio Format */ |
57 | 0x0000, /* R8 - Clocking */ | 58 | { 8, 0x0000 }, /* R8 - Clocking */ |
58 | 0x000F, /* R9 - MIC Preamp Control */ | 59 | { 9, 0x000F }, /* R9 - MIC Preamp Control */ |
59 | 0x0003, /* R10 - Misc Bias Control */ | 60 | { 10, 0x0003 }, /* R10 - Misc Bias Control */ |
60 | 0x0000, /* R11 - Noise Gate */ | 61 | { 11, 0x0000 }, /* R11 - Noise Gate */ |
61 | 0x007C, /* R12 - ALC1 */ | 62 | { 12, 0x007C }, /* R12 - ALC1 */ |
62 | 0x0000, /* R13 - ALC2 */ | 63 | { 13, 0x0000 }, /* R13 - ALC2 */ |
63 | 0x0032, /* R14 - ALC3 */ | 64 | { 14, 0x0032 }, /* R14 - ALC3 */ |
64 | }; | 65 | }; |
65 | 66 | ||
67 | static 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 | |||
66 | static int wm8737_reset(struct snd_soc_codec *codec) | 77 | static int wm8737_reset(struct snd_soc_codec *codec) |
67 | { | 78 | { |
68 | return snd_soc_write(codec, WM8737_RESET, 0); | 79 | return snd_soc_write(codec, WM8737_RESET, 0); |
@@ -479,7 +490,7 @@ static int wm8737_set_bias_level(struct snd_soc_codec *codec, | |||
479 | return ret; | 490 | return ret; |
480 | } | 491 | } |
481 | 492 | ||
482 | snd_soc_cache_sync(codec); | 493 | regcache_sync(wm8737->regmap); |
483 | 494 | ||
484 | /* Fast VMID ramp at 2*2.5k */ | 495 | /* Fast VMID ramp at 2*2.5k */ |
485 | snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, | 496 | snd_soc_update_bits(codec, WM8737_MISC_BIAS_CONTROL, |
@@ -559,7 +570,7 @@ static int wm8737_probe(struct snd_soc_codec *codec) | |||
559 | struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); | 570 | struct wm8737_priv *wm8737 = snd_soc_codec_get_drvdata(codec); |
560 | int ret; | 571 | int ret; |
561 | 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) { | 574 | if (ret != 0) { |
564 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 575 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
565 | return ret; | 576 | return ret; |
@@ -612,10 +623,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8737 = { | |||
612 | .suspend = wm8737_suspend, | 623 | .suspend = wm8737_suspend, |
613 | .resume = wm8737_resume, | 624 | .resume = wm8737_resume, |
614 | .set_bias_level = wm8737_set_bias_level, | 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 | }; | 626 | }; |
620 | 627 | ||
621 | static const struct of_device_id wm8737_of_match[] = { | 628 | static const struct of_device_id wm8737_of_match[] = { |
@@ -625,6 +632,18 @@ static const struct of_device_id wm8737_of_match[] = { | |||
625 | 632 | ||
626 | MODULE_DEVICE_TABLE(of, wm8737_of_match); | 633 | MODULE_DEVICE_TABLE(of, wm8737_of_match); |
627 | 634 | ||
635 | static 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) | 647 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
629 | static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, | 648 | static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, |
630 | const struct i2c_device_id *id) | 649 | const struct i2c_device_id *id) |
@@ -647,8 +666,11 @@ static __devinit int wm8737_i2c_probe(struct i2c_client *i2c, | |||
647 | return ret; | 666 | return ret; |
648 | } | 667 | } |
649 | 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 | 674 | ||
653 | ret = snd_soc_register_codec(&i2c->dev, | 675 | ret = snd_soc_register_codec(&i2c->dev, |
654 | &soc_codec_dev_wm8737, &wm8737_dai, 1); | 676 | &soc_codec_dev_wm8737, &wm8737_dai, 1); |
@@ -703,7 +725,10 @@ static int __devinit wm8737_spi_probe(struct spi_device *spi) | |||
703 | return ret; | 725 | return ret; |
704 | } | 726 | } |
705 | 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); | 732 | spi_set_drvdata(spi, wm8737); |
708 | 733 | ||
709 | ret = snd_soc_register_codec(&spi->dev, | 734 | ret = snd_soc_register_codec(&spi->dev, |