diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 06:00:21 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-10 06:04:42 -0400 |
commit | fe98c0cf40883e7d12456e0abc269e4fa31bed69 (patch) | |
tree | 031fe5858f8a5e9ea576788b0a05ed7da08ad063 | |
parent | d9780550a354058bc47db6ac48d3b77f186882c6 (diff) |
ASoC: wm8741: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | sound/soc/codecs/wm8741.c | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index 742744b4bba7..4281a0802138 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/pm.h> | 18 | #include <linux/pm.h> |
19 | #include <linux/i2c.h> | 19 | #include <linux/i2c.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 <linux/of_device.h> | 24 | #include <linux/of_device.h> |
@@ -40,26 +41,43 @@ static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = { | |||
40 | 41 | ||
41 | /* codec private data */ | 42 | /* codec private data */ |
42 | struct wm8741_priv { | 43 | struct wm8741_priv { |
43 | enum snd_soc_control_type control_type; | 44 | struct regmap *regmap; |
44 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; | 45 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; |
45 | unsigned int sysclk; | 46 | unsigned int sysclk; |
46 | struct snd_pcm_hw_constraint_list *sysclk_constraints; | 47 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
47 | }; | 48 | }; |
48 | 49 | ||
49 | static const u16 wm8741_reg_defaults[WM8741_REGISTER_COUNT] = { | 50 | static const struct reg_default wm8741_reg_defaults[] = { |
50 | 0x0000, /* R0 - DACLLSB Attenuation */ | 51 | { 0, 0x0000 }, /* R0 - DACLLSB Attenuation */ |
51 | 0x0000, /* R1 - DACLMSB Attenuation */ | 52 | { 1, 0x0000 }, /* R1 - DACLMSB Attenuation */ |
52 | 0x0000, /* R2 - DACRLSB Attenuation */ | 53 | { 2, 0x0000 }, /* R2 - DACRLSB Attenuation */ |
53 | 0x0000, /* R3 - DACRMSB Attenuation */ | 54 | { 3, 0x0000 }, /* R3 - DACRMSB Attenuation */ |
54 | 0x0000, /* R4 - Volume Control */ | 55 | { 4, 0x0000 }, /* R4 - Volume Control */ |
55 | 0x000A, /* R5 - Format Control */ | 56 | { 5, 0x000A }, /* R5 - Format Control */ |
56 | 0x0000, /* R6 - Filter Control */ | 57 | { 6, 0x0000 }, /* R6 - Filter Control */ |
57 | 0x0000, /* R7 - Mode Control 1 */ | 58 | { 7, 0x0000 }, /* R7 - Mode Control 1 */ |
58 | 0x0002, /* R8 - Mode Control 2 */ | 59 | { 8, 0x0002 }, /* R8 - Mode Control 2 */ |
59 | 0x0000, /* R9 - Reset */ | 60 | { 32, 0x0002 }, /* R32 - ADDITONAL_CONTROL_1 */ |
60 | 0x0002, /* R32 - ADDITONAL_CONTROL_1 */ | ||
61 | }; | 61 | }; |
62 | 62 | ||
63 | static bool wm8741_readable(struct device *dev, unsigned int reg) | ||
64 | { | ||
65 | switch (reg) { | ||
66 | case WM8741_DACLLSB_ATTENUATION: | ||
67 | case WM8741_DACLMSB_ATTENUATION: | ||
68 | case WM8741_DACRLSB_ATTENUATION: | ||
69 | case WM8741_DACRMSB_ATTENUATION: | ||
70 | case WM8741_VOLUME_CONTROL: | ||
71 | case WM8741_FORMAT_CONTROL: | ||
72 | case WM8741_FILTER_CONTROL: | ||
73 | case WM8741_MODE_CONTROL_1: | ||
74 | case WM8741_MODE_CONTROL_2: | ||
75 | case WM8741_ADDITIONAL_CONTROL_1: | ||
76 | return true; | ||
77 | default: | ||
78 | return false; | ||
79 | } | ||
80 | } | ||
63 | 81 | ||
64 | static int wm8741_reset(struct snd_soc_codec *codec) | 82 | static int wm8741_reset(struct snd_soc_codec *codec) |
65 | { | 83 | { |
@@ -411,7 +429,7 @@ static int wm8741_probe(struct snd_soc_codec *codec) | |||
411 | goto err_get; | 429 | goto err_get; |
412 | } | 430 | } |
413 | 431 | ||
414 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8741->control_type); | 432 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); |
415 | if (ret != 0) { | 433 | if (ret != 0) { |
416 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 434 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
417 | goto err_enable; | 435 | goto err_enable; |
@@ -439,7 +457,6 @@ static int wm8741_probe(struct snd_soc_codec *codec) | |||
439 | err_enable: | 457 | err_enable: |
440 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); | 458 | regulator_bulk_disable(ARRAY_SIZE(wm8741->supplies), wm8741->supplies); |
441 | err_get: | 459 | err_get: |
442 | err: | ||
443 | return ret; | 460 | return ret; |
444 | } | 461 | } |
445 | 462 | ||
@@ -456,9 +473,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8741 = { | |||
456 | .probe = wm8741_probe, | 473 | .probe = wm8741_probe, |
457 | .remove = wm8741_remove, | 474 | .remove = wm8741_remove, |
458 | .resume = wm8741_resume, | 475 | .resume = wm8741_resume, |
459 | .reg_cache_size = ARRAY_SIZE(wm8741_reg_defaults), | ||
460 | .reg_word_size = sizeof(u16), | ||
461 | .reg_cache_default = wm8741_reg_defaults, | ||
462 | 476 | ||
463 | .controls = wm8741_snd_controls, | 477 | .controls = wm8741_snd_controls, |
464 | .num_controls = ARRAY_SIZE(wm8741_snd_controls), | 478 | .num_controls = ARRAY_SIZE(wm8741_snd_controls), |
@@ -474,6 +488,18 @@ static const struct of_device_id wm8741_of_match[] = { | |||
474 | }; | 488 | }; |
475 | MODULE_DEVICE_TABLE(of, wm8741_of_match); | 489 | MODULE_DEVICE_TABLE(of, wm8741_of_match); |
476 | 490 | ||
491 | static const struct regmap_config wm8741_regmap = { | ||
492 | .reg_bits = 7, | ||
493 | .val_bits = 9, | ||
494 | .max_register = WM8741_MAX_REGISTER, | ||
495 | |||
496 | .reg_defaults = wm8741_reg_defaults, | ||
497 | .num_reg_defaults = ARRAY_SIZE(wm8741_reg_defaults), | ||
498 | .cache_type = REGCACHE_RBTREE, | ||
499 | |||
500 | .readable_reg = wm8741_readable, | ||
501 | }; | ||
502 | |||
477 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | 503 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
478 | static int wm8741_i2c_probe(struct i2c_client *i2c, | 504 | static int wm8741_i2c_probe(struct i2c_client *i2c, |
479 | const struct i2c_device_id *id) | 505 | const struct i2c_device_id *id) |
@@ -492,12 +518,18 @@ static int wm8741_i2c_probe(struct i2c_client *i2c, | |||
492 | ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies), | 518 | ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies), |
493 | wm8741->supplies); | 519 | wm8741->supplies); |
494 | if (ret != 0) { | 520 | if (ret != 0) { |
495 | dev_err(codec->dev, "Failed to request supplies: %d\n", ret); | 521 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
496 | goto err; | 522 | return ret; |
523 | } | ||
524 | |||
525 | wm8741->regmap = regmap_init_i2c(i2c, &wm8741_regmap); | ||
526 | if (IS_ERR(wm8741->regmap)) { | ||
527 | ret = PTR_ERR(wm8741->regmap); | ||
528 | dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); | ||
529 | return ret; | ||
497 | } | 530 | } |
498 | 531 | ||
499 | i2c_set_clientdata(i2c, wm8741); | 532 | i2c_set_clientdata(i2c, wm8741); |
500 | wm8741->control_type = SND_SOC_I2C; | ||
501 | 533 | ||
502 | ret = snd_soc_register_codec(&i2c->dev, | 534 | ret = snd_soc_register_codec(&i2c->dev, |
503 | &soc_codec_dev_wm8741, &wm8741_dai, 1); | 535 | &soc_codec_dev_wm8741, &wm8741_dai, 1); |
@@ -543,14 +575,20 @@ static int __devinit wm8741_spi_probe(struct spi_device *spi) | |||
543 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) | 575 | for (i = 0; i < ARRAY_SIZE(wm8741->supplies); i++) |
544 | wm8741->supplies[i].supply = wm8741_supply_names[i]; | 576 | wm8741->supplies[i].supply = wm8741_supply_names[i]; |
545 | 577 | ||
546 | ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8741->supplies), | 578 | ret = devm_regulator_bulk_get(&spi->dev, ARRAY_SIZE(wm8741->supplies), |
547 | wm8741->supplies); | 579 | wm8741->supplies); |
548 | if (ret != 0) { | 580 | if (ret != 0) { |
549 | dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); | 581 | dev_err(&spi->dev, "Failed to request supplies: %d\n", ret); |
550 | goto err; | 582 | return ret; |
583 | } | ||
584 | |||
585 | wm8741->regmap = regmap_init_spi(spi, &wm8741_regmap); | ||
586 | if (IS_ERR(wm8741->regmap)) { | ||
587 | ret = PTR_ERR(wm8741->regmap); | ||
588 | dev_err(&spi->dev, "Failed to init regmap: %d\n", ret); | ||
589 | return ret; | ||
551 | } | 590 | } |
552 | 591 | ||
553 | wm8741->control_type = SND_SOC_SPI; | ||
554 | spi_set_drvdata(spi, wm8741); | 592 | spi_set_drvdata(spi, wm8741); |
555 | 593 | ||
556 | ret = snd_soc_register_codec(&spi->dev, | 594 | ret = snd_soc_register_codec(&spi->dev, |