diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-12 00:15:20 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-09-12 02:09:19 -0400 |
commit | 5aa5fa9fdbda20eee3351dd2492cd5c0d6fa7d1d (patch) | |
tree | 6a55c671a121f1121d920310554ef82af52f2717 /sound/soc/codecs/wm8711.c | |
parent | 18273b05def692d1883745d22e72fa275bc92c17 (diff) |
ASoC: wm8711: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8711.c')
-rw-r--r-- | sound/soc/codecs/wm8711.c | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c index 1b1209a4c791..8b8bb70f1eb9 100644 --- a/sound/soc/codecs/wm8711.c +++ b/sound/soc/codecs/wm8711.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/pm.h> | 19 | #include <linux/pm.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/regmap.h> | ||
21 | #include <linux/spi/spi.h> | 22 | #include <linux/spi/spi.h> |
22 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
23 | #include <linux/of_device.h> | 24 | #include <linux/of_device.h> |
@@ -32,7 +33,7 @@ | |||
32 | 33 | ||
33 | /* codec private data */ | 34 | /* codec private data */ |
34 | struct wm8711_priv { | 35 | struct wm8711_priv { |
35 | enum snd_soc_control_type bus_type; | 36 | struct regmap *regmap; |
36 | unsigned int sysclk; | 37 | unsigned int sysclk; |
37 | }; | 38 | }; |
38 | 39 | ||
@@ -42,11 +43,21 @@ struct wm8711_priv { | |||
42 | * using 2 wire for device control, so we cache them instead. | 43 | * using 2 wire for device control, so we cache them instead. |
43 | * There is no point in caching the reset register | 44 | * There is no point in caching the reset register |
44 | */ | 45 | */ |
45 | static const u16 wm8711_reg[WM8711_CACHEREGNUM] = { | 46 | static const struct reg_default wm8711_reg_defaults[] = { |
46 | 0x0079, 0x0079, 0x000a, 0x0008, | 47 | { 0, 0x0079 }, { 1, 0x0079 }, { 2, 0x000a }, { 3, 0x0008 }, |
47 | 0x009f, 0x000a, 0x0000, 0x0000 | 48 | { 4, 0x009f }, { 5, 0x000a }, { 6, 0x0000 }, { 7, 0x0000 }, |
48 | }; | 49 | }; |
49 | 50 | ||
51 | static bool wm8711_volatile(struct device *dev, unsigned int reg) | ||
52 | { | ||
53 | switch (reg) { | ||
54 | case WM8711_RESET: | ||
55 | return true; | ||
56 | default: | ||
57 | return false; | ||
58 | } | ||
59 | } | ||
60 | |||
50 | #define wm8711_reset(c) snd_soc_write(c, WM8711_RESET, 0) | 61 | #define wm8711_reset(c) snd_soc_write(c, WM8711_RESET, 0) |
51 | 62 | ||
52 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); | 63 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); |
@@ -289,6 +300,7 @@ static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
289 | static int wm8711_set_bias_level(struct snd_soc_codec *codec, | 300 | static int wm8711_set_bias_level(struct snd_soc_codec *codec, |
290 | enum snd_soc_bias_level level) | 301 | enum snd_soc_bias_level level) |
291 | { | 302 | { |
303 | struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); | ||
292 | u16 reg = snd_soc_read(codec, WM8711_PWR) & 0xff7f; | 304 | u16 reg = snd_soc_read(codec, WM8711_PWR) & 0xff7f; |
293 | 305 | ||
294 | switch (level) { | 306 | switch (level) { |
@@ -299,7 +311,7 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec, | |||
299 | break; | 311 | break; |
300 | case SND_SOC_BIAS_STANDBY: | 312 | case SND_SOC_BIAS_STANDBY: |
301 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) | 313 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) |
302 | snd_soc_cache_sync(codec); | 314 | regcache_sync(wm8711->regmap); |
303 | 315 | ||
304 | snd_soc_write(codec, WM8711_PWR, reg | 0x0040); | 316 | snd_soc_write(codec, WM8711_PWR, reg | 0x0040); |
305 | break; | 317 | break; |
@@ -353,10 +365,9 @@ static int wm8711_resume(struct snd_soc_codec *codec) | |||
353 | 365 | ||
354 | static int wm8711_probe(struct snd_soc_codec *codec) | 366 | static int wm8711_probe(struct snd_soc_codec *codec) |
355 | { | 367 | { |
356 | struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec); | ||
357 | int ret; | 368 | int ret; |
358 | 369 | ||
359 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8711->bus_type); | 370 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP); |
360 | if (ret < 0) { | 371 | if (ret < 0) { |
361 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 372 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
362 | return ret; | 373 | return ret; |
@@ -391,9 +402,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8711 = { | |||
391 | .suspend = wm8711_suspend, | 402 | .suspend = wm8711_suspend, |
392 | .resume = wm8711_resume, | 403 | .resume = wm8711_resume, |
393 | .set_bias_level = wm8711_set_bias_level, | 404 | .set_bias_level = wm8711_set_bias_level, |
394 | .reg_cache_size = ARRAY_SIZE(wm8711_reg), | ||
395 | .reg_word_size = sizeof(u16), | ||
396 | .reg_cache_default = wm8711_reg, | ||
397 | .controls = wm8711_snd_controls, | 405 | .controls = wm8711_snd_controls, |
398 | .num_controls = ARRAY_SIZE(wm8711_snd_controls), | 406 | .num_controls = ARRAY_SIZE(wm8711_snd_controls), |
399 | .dapm_widgets = wm8711_dapm_widgets, | 407 | .dapm_widgets = wm8711_dapm_widgets, |
@@ -408,6 +416,18 @@ static const struct of_device_id wm8711_of_match[] = { | |||
408 | }; | 416 | }; |
409 | MODULE_DEVICE_TABLE(of, wm8711_of_match); | 417 | MODULE_DEVICE_TABLE(of, wm8711_of_match); |
410 | 418 | ||
419 | static const struct regmap_config wm8711_regmap = { | ||
420 | .reg_bits = 7, | ||
421 | .val_bits = 9, | ||
422 | .max_register = WM8711_RESET, | ||
423 | |||
424 | .reg_defaults = wm8711_reg_defaults, | ||
425 | .num_reg_defaults = ARRAY_SIZE(wm8711_reg_defaults), | ||
426 | .cache_type = REGCACHE_RBTREE, | ||
427 | |||
428 | .volatile_reg = wm8711_volatile, | ||
429 | }; | ||
430 | |||
411 | #if defined(CONFIG_SPI_MASTER) | 431 | #if defined(CONFIG_SPI_MASTER) |
412 | static int __devinit wm8711_spi_probe(struct spi_device *spi) | 432 | static int __devinit wm8711_spi_probe(struct spi_device *spi) |
413 | { | 433 | { |
@@ -419,8 +439,11 @@ static int __devinit wm8711_spi_probe(struct spi_device *spi) | |||
419 | if (wm8711 == NULL) | 439 | if (wm8711 == NULL) |
420 | return -ENOMEM; | 440 | return -ENOMEM; |
421 | 441 | ||
442 | wm8711->regmap = devm_regmap_init_spi(spi, &wm8711_regmap); | ||
443 | if (IS_ERR(wm8711->regmap)) | ||
444 | return PTR_ERR(wm8711->regmap); | ||
445 | |||
422 | spi_set_drvdata(spi, wm8711); | 446 | spi_set_drvdata(spi, wm8711); |
423 | wm8711->bus_type = SND_SOC_SPI; | ||
424 | 447 | ||
425 | ret = snd_soc_register_codec(&spi->dev, | 448 | ret = snd_soc_register_codec(&spi->dev, |
426 | &soc_codec_dev_wm8711, &wm8711_dai, 1); | 449 | &soc_codec_dev_wm8711, &wm8711_dai, 1); |
@@ -458,8 +481,11 @@ static __devinit int wm8711_i2c_probe(struct i2c_client *client, | |||
458 | if (wm8711 == NULL) | 481 | if (wm8711 == NULL) |
459 | return -ENOMEM; | 482 | return -ENOMEM; |
460 | 483 | ||
484 | wm8711->regmap = devm_regmap_init_i2c(client, &wm8711_regmap); | ||
485 | if (IS_ERR(wm8711->regmap)) | ||
486 | return PTR_ERR(wm8711->regmap); | ||
487 | |||
461 | i2c_set_clientdata(client, wm8711); | 488 | i2c_set_clientdata(client, wm8711); |
462 | wm8711->bus_type = SND_SOC_I2C; | ||
463 | 489 | ||
464 | ret = snd_soc_register_codec(&client->dev, | 490 | ret = snd_soc_register_codec(&client->dev, |
465 | &soc_codec_dev_wm8711, &wm8711_dai, 1); | 491 | &soc_codec_dev_wm8711, &wm8711_dai, 1); |