diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-10-10 07:22:42 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-10-14 22:49:40 -0400 |
commit | dc43b0467115976ad90169ada94f6d8462469d6c (patch) | |
tree | 044b18a7d5a42fdb2bb213a2cd1ac7a952f91e07 /sound/soc/codecs/wm8770.c | |
parent | ddffeb8c4d0331609ef2581d84de4d763607bd37 (diff) |
ASoC: wm8770: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8770.c')
-rw-r--r-- | sound/soc/codecs/wm8770.c | 100 |
1 files changed, 65 insertions, 35 deletions
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c index c7c0034d3966..21ec563ad12b 100644 --- a/sound/soc/codecs/wm8770.c +++ b/sound/soc/codecs/wm8770.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/of_device.h> | 17 | #include <linux/of_device.h> |
18 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
19 | #include <linux/spi/spi.h> | 19 | #include <linux/spi/spi.h> |
20 | #include <linux/regmap.h> | ||
20 | #include <linux/regulator/consumer.h> | 21 | #include <linux/regulator/consumer.h> |
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
22 | #include <sound/core.h> | 23 | #include <sound/core.h> |
@@ -35,19 +36,52 @@ static const char *wm8770_supply_names[WM8770_NUM_SUPPLIES] = { | |||
35 | "DVDD" | 36 | "DVDD" |
36 | }; | 37 | }; |
37 | 38 | ||
38 | static const u16 wm8770_reg_defs[WM8770_CACHEREGNUM] = { | 39 | static const struct reg_default wm8770_reg_defaults[] = { |
39 | 0x7f, 0x7f, 0x7f, 0x7f, | 40 | { 0, 0x7f }, |
40 | 0x7f, 0x7f, 0x7f, 0x7f, | 41 | { 1, 0x7f }, |
41 | 0x7f, 0xff, 0xff, 0xff, | 42 | { 2, 0x7f }, |
42 | 0xff, 0xff, 0xff, 0xff, | 43 | { 3, 0x7f }, |
43 | 0xff, 0xff, 0, 0x90, 0, | 44 | { 4, 0x7f }, |
44 | 0, 0x22, 0x22, 0x3e, | 45 | { 5, 0x7f }, |
45 | 0xc, 0xc, 0x100, 0x189, | 46 | { 6, 0x7f }, |
46 | 0x189, 0x8770 | 47 | { 7, 0x7f }, |
48 | { 8, 0x7f }, | ||
49 | { 9, 0xff }, | ||
50 | { 10, 0xff }, | ||
51 | { 11, 0xff }, | ||
52 | { 12, 0xff }, | ||
53 | { 13, 0xff }, | ||
54 | { 14, 0xff }, | ||
55 | { 15, 0xff }, | ||
56 | { 16, 0xff }, | ||
57 | { 17, 0xff }, | ||
58 | { 18, 0 }, | ||
59 | { 19, 0x90 }, | ||
60 | { 20, 0 }, | ||
61 | { 21, 0 }, | ||
62 | { 22, 0x22 }, | ||
63 | { 23, 0x22 }, | ||
64 | { 24, 0x3e }, | ||
65 | { 25, 0xc }, | ||
66 | { 26, 0xc }, | ||
67 | { 27, 0x100 }, | ||
68 | { 28, 0x189 }, | ||
69 | { 29, 0x189 }, | ||
70 | { 30, 0x8770 }, | ||
47 | }; | 71 | }; |
48 | 72 | ||
73 | static bool wm8770_volatile_reg(struct device *dev, unsigned int reg) | ||
74 | { | ||
75 | switch (reg) { | ||
76 | case WM8770_RESET: | ||
77 | return true; | ||
78 | default: | ||
79 | return false; | ||
80 | } | ||
81 | } | ||
82 | |||
49 | struct wm8770_priv { | 83 | struct wm8770_priv { |
50 | enum snd_soc_control_type control_type; | 84 | struct regmap *regmap; |
51 | struct regulator_bulk_data supplies[WM8770_NUM_SUPPLIES]; | 85 | struct regulator_bulk_data supplies[WM8770_NUM_SUPPLIES]; |
52 | struct notifier_block disable_nb[WM8770_NUM_SUPPLIES]; | 86 | struct notifier_block disable_nb[WM8770_NUM_SUPPLIES]; |
53 | struct snd_soc_codec *codec; | 87 | struct snd_soc_codec *codec; |
@@ -71,7 +105,7 @@ static int wm8770_regulator_event_##n(struct notifier_block *nb, \ | |||
71 | struct wm8770_priv *wm8770 = container_of(nb, struct wm8770_priv, \ | 105 | struct wm8770_priv *wm8770 = container_of(nb, struct wm8770_priv, \ |
72 | disable_nb[n]); \ | 106 | disable_nb[n]); \ |
73 | if (event & REGULATOR_EVENT_DISABLE) { \ | 107 | if (event & REGULATOR_EVENT_DISABLE) { \ |
74 | wm8770->codec->cache_sync = 1; \ | 108 | regcache_mark_dirty(wm8770->regmap); \ |
75 | } \ | 109 | } \ |
76 | return 0; \ | 110 | return 0; \ |
77 | } | 111 | } |
@@ -466,24 +500,6 @@ static int wm8770_set_sysclk(struct snd_soc_dai *dai, | |||
466 | return 0; | 500 | return 0; |
467 | } | 501 | } |
468 | 502 | ||
469 | static void wm8770_sync_cache(struct snd_soc_codec *codec) | ||
470 | { | ||
471 | int i; | ||
472 | u16 *cache; | ||
473 | |||
474 | if (!codec->cache_sync) | ||
475 | return; | ||
476 | |||
477 | codec->cache_only = 0; | ||
478 | cache = codec->reg_cache; | ||
479 | for (i = 0; i < codec->driver->reg_cache_size; i++) { | ||
480 | if (i == WM8770_RESET || cache[i] == wm8770_reg_defs[i]) | ||
481 | continue; | ||
482 | snd_soc_write(codec, i, cache[i]); | ||
483 | } | ||
484 | codec->cache_sync = 0; | ||
485 | } | ||
486 | |||
487 | static int wm8770_set_bias_level(struct snd_soc_codec *codec, | 503 | static int wm8770_set_bias_level(struct snd_soc_codec *codec, |
488 | enum snd_soc_bias_level level) | 504 | enum snd_soc_bias_level level) |
489 | { | 505 | { |
@@ -507,7 +523,9 @@ static int wm8770_set_bias_level(struct snd_soc_codec *codec, | |||
507 | ret); | 523 | ret); |
508 | return ret; | 524 | return ret; |
509 | } | 525 | } |
510 | wm8770_sync_cache(codec); | 526 | |
527 | regcache_sync(wm8770->regmap); | ||
528 | |||
511 | /* global powerup */ | 529 | /* global powerup */ |
512 | snd_soc_write(codec, WM8770_PWDNCTRL, 0); | 530 | snd_soc_write(codec, WM8770_PWDNCTRL, 0); |
513 | } | 531 | } |
@@ -580,7 +598,7 @@ static int wm8770_probe(struct snd_soc_codec *codec) | |||
580 | wm8770 = snd_soc_codec_get_drvdata(codec); | 598 | wm8770 = snd_soc_codec_get_drvdata(codec); |
581 | wm8770->codec = codec; | 599 | wm8770->codec = codec; |
582 | 600 | ||
583 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8770->control_type); | 601 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); |
584 | if (ret < 0) { | 602 | if (ret < 0) { |
585 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 603 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
586 | return ret; | 604 | return ret; |
@@ -678,9 +696,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8770 = { | |||
678 | .resume = wm8770_resume, | 696 | .resume = wm8770_resume, |
679 | .set_bias_level = wm8770_set_bias_level, | 697 | .set_bias_level = wm8770_set_bias_level, |
680 | .idle_bias_off = true, | 698 | .idle_bias_off = true, |
681 | .reg_cache_size = ARRAY_SIZE(wm8770_reg_defs), | ||
682 | .reg_word_size = sizeof (u16), | ||
683 | .reg_cache_default = wm8770_reg_defs | ||
684 | }; | 699 | }; |
685 | 700 | ||
686 | static const struct of_device_id wm8770_of_match[] = { | 701 | static const struct of_device_id wm8770_of_match[] = { |
@@ -689,6 +704,18 @@ static const struct of_device_id wm8770_of_match[] = { | |||
689 | }; | 704 | }; |
690 | MODULE_DEVICE_TABLE(of, wm8770_of_match); | 705 | MODULE_DEVICE_TABLE(of, wm8770_of_match); |
691 | 706 | ||
707 | static const struct regmap_config wm8770_regmap = { | ||
708 | .reg_bits = 7, | ||
709 | .val_bits = 9, | ||
710 | .max_register = WM8770_RESET, | ||
711 | |||
712 | .reg_defaults = wm8770_reg_defaults, | ||
713 | .num_reg_defaults = ARRAY_SIZE(wm8770_reg_defaults), | ||
714 | .cache_type = REGCACHE_RBTREE, | ||
715 | |||
716 | .volatile_reg = wm8770_volatile_reg, | ||
717 | }; | ||
718 | |||
692 | static int __devinit wm8770_spi_probe(struct spi_device *spi) | 719 | static int __devinit wm8770_spi_probe(struct spi_device *spi) |
693 | { | 720 | { |
694 | struct wm8770_priv *wm8770; | 721 | struct wm8770_priv *wm8770; |
@@ -699,7 +726,10 @@ static int __devinit wm8770_spi_probe(struct spi_device *spi) | |||
699 | if (!wm8770) | 726 | if (!wm8770) |
700 | return -ENOMEM; | 727 | return -ENOMEM; |
701 | 728 | ||
702 | wm8770->control_type = SND_SOC_SPI; | 729 | wm8770->regmap = devm_regmap_init_spi(spi, &wm8770_regmap); |
730 | if (IS_ERR(wm8770->regmap)) | ||
731 | return PTR_ERR(wm8770->regmap); | ||
732 | |||
703 | spi_set_drvdata(spi, wm8770); | 733 | spi_set_drvdata(spi, wm8770); |
704 | 734 | ||
705 | ret = snd_soc_register_codec(&spi->dev, | 735 | ret = snd_soc_register_codec(&spi->dev, |