diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-04-25 05:42:48 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-04-25 06:28:10 -0400 |
commit | bec3d9a97324a9ef84cc1dfcb918432a86c58894 (patch) | |
tree | 557832fd6694896f77fc4ab8baa12fa5348a5723 /sound/soc | |
parent | d86a11d68c309a7eaf0a5aa8b5e143eea16dc09d (diff) |
ASoC: SSM2602: Convert to direct regmap API usage
Mostly a one to one converion. On one occasion the patch replaces a
snd_soc_read-snd_soc_write sequence with regmap_update_bits though as it helps
to keep the conversion simple.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc')
-rw-r--r-- | sound/soc/codecs/ssm2602.c | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c index aef8a496e2d9..079066fef425 100644 --- a/sound/soc/codecs/ssm2602.c +++ b/sound/soc/codecs/ssm2602.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/pm.h> | 33 | #include <linux/pm.h> |
34 | #include <linux/i2c.h> | 34 | #include <linux/i2c.h> |
35 | #include <linux/spi/spi.h> | 35 | #include <linux/spi/spi.h> |
36 | #include <linux/regmap.h> | ||
36 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
37 | #include <sound/core.h> | 38 | #include <sound/core.h> |
38 | #include <sound/pcm.h> | 39 | #include <sound/pcm.h> |
@@ -52,10 +53,11 @@ enum ssm2602_type { | |||
52 | struct ssm2602_priv { | 53 | struct ssm2602_priv { |
53 | unsigned int sysclk; | 54 | unsigned int sysclk; |
54 | struct snd_pcm_hw_constraint_list *sysclk_constraints; | 55 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
55 | enum snd_soc_control_type control_type; | ||
56 | struct snd_pcm_substream *master_substream; | 56 | struct snd_pcm_substream *master_substream; |
57 | struct snd_pcm_substream *slave_substream; | 57 | struct snd_pcm_substream *slave_substream; |
58 | 58 | ||
59 | struct regmap *regmap; | ||
60 | |||
59 | enum ssm2602_type type; | 61 | enum ssm2602_type type; |
60 | unsigned int clk_out_pwr; | 62 | unsigned int clk_out_pwr; |
61 | }; | 63 | }; |
@@ -72,7 +74,6 @@ static const u16 ssm2602_reg[SSM2602_CACHEREGNUM] = { | |||
72 | 0x0000, 0x0000 | 74 | 0x0000, 0x0000 |
73 | }; | 75 | }; |
74 | 76 | ||
75 | #define ssm2602_reset(c) snd_soc_write(c, SSM2602_RESET, 0) | ||
76 | 77 | ||
77 | /*Appending several "None"s just for OSS mixer use*/ | 78 | /*Appending several "None"s just for OSS mixer use*/ |
78 | static const char *ssm2602_input_select[] = { | 79 | static const char *ssm2602_input_select[] = { |
@@ -273,8 +274,8 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
273 | { | 274 | { |
274 | struct snd_soc_codec *codec = dai->codec; | 275 | struct snd_soc_codec *codec = dai->codec; |
275 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 276 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
276 | u16 iface = snd_soc_read(codec, SSM2602_IFACE) & 0xfff3; | ||
277 | int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); | 277 | int srate = ssm2602_get_coeff(ssm2602->sysclk, params_rate(params)); |
278 | unsigned int iface; | ||
278 | 279 | ||
279 | if (substream == ssm2602->slave_substream) { | 280 | if (substream == ssm2602->slave_substream) { |
280 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); | 281 | dev_dbg(codec->dev, "Ignoring hw_params for slave substream\n"); |
@@ -284,23 +285,27 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream, | |||
284 | if (srate < 0) | 285 | if (srate < 0) |
285 | return srate; | 286 | return srate; |
286 | 287 | ||
287 | snd_soc_write(codec, SSM2602_SRATE, srate); | 288 | regmap_write(ssm2602->regmap, SSM2602_SRATE, srate); |
288 | 289 | ||
289 | /* bit size */ | 290 | /* bit size */ |
290 | switch (params_format(params)) { | 291 | switch (params_format(params)) { |
291 | case SNDRV_PCM_FORMAT_S16_LE: | 292 | case SNDRV_PCM_FORMAT_S16_LE: |
293 | iface = 0x0; | ||
292 | break; | 294 | break; |
293 | case SNDRV_PCM_FORMAT_S20_3LE: | 295 | case SNDRV_PCM_FORMAT_S20_3LE: |
294 | iface |= 0x0004; | 296 | iface = 0x4; |
295 | break; | 297 | break; |
296 | case SNDRV_PCM_FORMAT_S24_LE: | 298 | case SNDRV_PCM_FORMAT_S24_LE: |
297 | iface |= 0x0008; | 299 | iface = 0x8; |
298 | break; | 300 | break; |
299 | case SNDRV_PCM_FORMAT_S32_LE: | 301 | case SNDRV_PCM_FORMAT_S32_LE: |
300 | iface |= 0x000c; | 302 | iface = 0xc; |
301 | break; | 303 | break; |
304 | default: | ||
305 | return -EINVAL; | ||
302 | } | 306 | } |
303 | snd_soc_write(codec, SSM2602_IFACE, iface); | 307 | regmap_update_bits(ssm2602->regmap, SSM2602_IFACE, |
308 | IFACE_AUDIO_DATA_LEN, iface); | ||
304 | return 0; | 309 | return 0; |
305 | } | 310 | } |
306 | 311 | ||
@@ -361,14 +366,14 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream, | |||
361 | 366 | ||
362 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) | 367 | static int ssm2602_mute(struct snd_soc_dai *dai, int mute) |
363 | { | 368 | { |
364 | struct snd_soc_codec *codec = dai->codec; | 369 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(dai->codec); |
365 | 370 | ||
366 | if (mute) | 371 | if (mute) |
367 | snd_soc_update_bits(codec, SSM2602_APDIGI, | 372 | regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, |
368 | APDIGI_ENABLE_DAC_MUTE, | 373 | APDIGI_ENABLE_DAC_MUTE, |
369 | APDIGI_ENABLE_DAC_MUTE); | 374 | APDIGI_ENABLE_DAC_MUTE); |
370 | else | 375 | else |
371 | snd_soc_update_bits(codec, SSM2602_APDIGI, | 376 | regmap_update_bits(ssm2602->regmap, SSM2602_APDIGI, |
372 | APDIGI_ENABLE_DAC_MUTE, 0); | 377 | APDIGI_ENABLE_DAC_MUTE, 0); |
373 | return 0; | 378 | return 0; |
374 | } | 379 | } |
@@ -418,7 +423,7 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
418 | else | 423 | else |
419 | ssm2602->clk_out_pwr &= ~mask; | 424 | ssm2602->clk_out_pwr &= ~mask; |
420 | 425 | ||
421 | snd_soc_update_bits(codec, SSM2602_PWR, | 426 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
422 | PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); | 427 | PWR_CLK_OUT_PDN | PWR_OSC_PDN, ssm2602->clk_out_pwr); |
423 | } | 428 | } |
424 | 429 | ||
@@ -428,8 +433,8 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
428 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | 433 | static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, |
429 | unsigned int fmt) | 434 | unsigned int fmt) |
430 | { | 435 | { |
431 | struct snd_soc_codec *codec = codec_dai->codec; | 436 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec_dai->codec); |
432 | u16 iface = 0; | 437 | unsigned int iface = 0; |
433 | 438 | ||
434 | /* set master/slave audio interface */ | 439 | /* set master/slave audio interface */ |
435 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 440 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
@@ -480,7 +485,7 @@ static int ssm2602_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
480 | } | 485 | } |
481 | 486 | ||
482 | /* set iface */ | 487 | /* set iface */ |
483 | snd_soc_write(codec, SSM2602_IFACE, iface); | 488 | regmap_write(ssm2602->regmap, SSM2602_IFACE, iface); |
484 | return 0; | 489 | return 0; |
485 | } | 490 | } |
486 | 491 | ||
@@ -492,7 +497,7 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
492 | switch (level) { | 497 | switch (level) { |
493 | case SND_SOC_BIAS_ON: | 498 | case SND_SOC_BIAS_ON: |
494 | /* vref/mid on, osc and clkout on if enabled */ | 499 | /* vref/mid on, osc and clkout on if enabled */ |
495 | snd_soc_update_bits(codec, SSM2602_PWR, | 500 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
496 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, | 501 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, |
497 | ssm2602->clk_out_pwr); | 502 | ssm2602->clk_out_pwr); |
498 | break; | 503 | break; |
@@ -500,13 +505,13 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec, | |||
500 | break; | 505 | break; |
501 | case SND_SOC_BIAS_STANDBY: | 506 | case SND_SOC_BIAS_STANDBY: |
502 | /* everything off except vref/vmid, */ | 507 | /* everything off except vref/vmid, */ |
503 | snd_soc_update_bits(codec, SSM2602_PWR, | 508 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
504 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, | 509 | PWR_POWER_OFF | PWR_CLK_OUT_PDN | PWR_OSC_PDN, |
505 | PWR_CLK_OUT_PDN | PWR_OSC_PDN); | 510 | PWR_CLK_OUT_PDN | PWR_OSC_PDN); |
506 | break; | 511 | break; |
507 | case SND_SOC_BIAS_OFF: | 512 | case SND_SOC_BIAS_OFF: |
508 | /* everything off */ | 513 | /* everything off */ |
509 | snd_soc_update_bits(codec, SSM2602_PWR, | 514 | regmap_update_bits(ssm2602->regmap, SSM2602_PWR, |
510 | PWR_POWER_OFF, PWR_POWER_OFF); | 515 | PWR_POWER_OFF, PWR_POWER_OFF); |
511 | break; | 516 | break; |
512 | 517 | ||
@@ -565,12 +570,13 @@ static int ssm2602_resume(struct snd_soc_codec *codec) | |||
565 | 570 | ||
566 | static int ssm2602_probe(struct snd_soc_codec *codec) | 571 | static int ssm2602_probe(struct snd_soc_codec *codec) |
567 | { | 572 | { |
573 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | ||
568 | struct snd_soc_dapm_context *dapm = &codec->dapm; | 574 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
569 | int ret; | 575 | int ret; |
570 | 576 | ||
571 | snd_soc_update_bits(codec, SSM2602_LOUT1V, | 577 | regmap_update_bits(ssm2602->regmap, SSM2602_LOUT1V, |
572 | LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); | 578 | LOUT1V_LRHP_BOTH, LOUT1V_LRHP_BOTH); |
573 | snd_soc_update_bits(codec, SSM2602_ROUT1V, | 579 | regmap_update_bits(ssm2602->regmap, SSM2602_ROUT1V, |
574 | ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); | 580 | ROUT1V_RLHP_BOTH, ROUT1V_RLHP_BOTH); |
575 | 581 | ||
576 | ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls, | 582 | ret = snd_soc_add_codec_controls(codec, ssm2602_snd_controls, |
@@ -606,25 +612,26 @@ static int ssm260x_probe(struct snd_soc_codec *codec) | |||
606 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); | 612 | struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec); |
607 | int ret; | 613 | int ret; |
608 | 614 | ||
609 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, ssm2602->control_type); | 615 | codec->control_data = ssm2602->regmap; |
616 | ret = snd_soc_codec_set_cache_io(codec, 0, 0, SND_SOC_REGMAP); | ||
610 | if (ret < 0) { | 617 | if (ret < 0) { |
611 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | 618 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
612 | return ret; | 619 | return ret; |
613 | } | 620 | } |
614 | 621 | ||
615 | ret = ssm2602_reset(codec); | 622 | ret = regmap_write(ssm2602->regmap, SSM2602_RESET, 0); |
616 | if (ret < 0) { | 623 | if (ret < 0) { |
617 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); | 624 | dev_err(codec->dev, "Failed to issue reset: %d\n", ret); |
618 | return ret; | 625 | return ret; |
619 | } | 626 | } |
620 | 627 | ||
621 | /* set the update bits */ | 628 | /* set the update bits */ |
622 | snd_soc_update_bits(codec, SSM2602_LINVOL, | 629 | regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL, |
623 | LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); | 630 | LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH); |
624 | snd_soc_update_bits(codec, SSM2602_RINVOL, | 631 | regmap_update_bits(ssm2602->regmap, SSM2602_RINVOL, |
625 | RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); | 632 | RINVOL_RLIN_BOTH, RINVOL_RLIN_BOTH); |
626 | /*select Line in as default input*/ | 633 | /*select Line in as default input*/ |
627 | snd_soc_write(codec, SSM2602_APANA, APANA_SELECT_DAC | | 634 | regmap_write(ssm2602->regmap, SSM2602_APANA, APANA_SELECT_DAC | |
628 | APANA_ENABLE_MIC_BOOST); | 635 | APANA_ENABLE_MIC_BOOST); |
629 | 636 | ||
630 | switch (ssm2602->type) { | 637 | switch (ssm2602->type) { |
@@ -657,9 +664,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { | |||
657 | .suspend = ssm2602_suspend, | 664 | .suspend = ssm2602_suspend, |
658 | .resume = ssm2602_resume, | 665 | .resume = ssm2602_resume, |
659 | .set_bias_level = ssm2602_set_bias_level, | 666 | .set_bias_level = ssm2602_set_bias_level, |
660 | .reg_cache_size = ARRAY_SIZE(ssm2602_reg), | ||
661 | .reg_word_size = sizeof(u16), | ||
662 | .reg_cache_default = ssm2602_reg, | ||
663 | 667 | ||
664 | .controls = ssm260x_snd_controls, | 668 | .controls = ssm260x_snd_controls, |
665 | .num_controls = ARRAY_SIZE(ssm260x_snd_controls), | 669 | .num_controls = ARRAY_SIZE(ssm260x_snd_controls), |
@@ -669,6 +673,23 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = { | |||
669 | .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), | 673 | .num_dapm_routes = ARRAY_SIZE(ssm260x_routes), |
670 | }; | 674 | }; |
671 | 675 | ||
676 | static bool ssm2602_register_volatile(struct device *dev, unsigned int reg) | ||
677 | { | ||
678 | return reg == SSM2602_RESET; | ||
679 | } | ||
680 | |||
681 | static const struct regmap_config ssm2602_regmap_config = { | ||
682 | .val_bits = 9, | ||
683 | .reg_bits = 7, | ||
684 | |||
685 | .max_register = SSM2602_RESET, | ||
686 | .volatile_reg = ssm2602_register_volatile, | ||
687 | |||
688 | .cache_type = REGCACHE_RBTREE, | ||
689 | .reg_defaults_raw = ssm2602_reg, | ||
690 | .num_reg_defaults_raw = ARRAY_SIZE(ssm2602_reg), | ||
691 | }; | ||
692 | |||
672 | #if defined(CONFIG_SPI_MASTER) | 693 | #if defined(CONFIG_SPI_MASTER) |
673 | static int __devinit ssm2602_spi_probe(struct spi_device *spi) | 694 | static int __devinit ssm2602_spi_probe(struct spi_device *spi) |
674 | { | 695 | { |
@@ -681,9 +702,12 @@ static int __devinit ssm2602_spi_probe(struct spi_device *spi) | |||
681 | return -ENOMEM; | 702 | return -ENOMEM; |
682 | 703 | ||
683 | spi_set_drvdata(spi, ssm2602); | 704 | spi_set_drvdata(spi, ssm2602); |
684 | ssm2602->control_type = SND_SOC_SPI; | ||
685 | ssm2602->type = SSM2602; | 705 | ssm2602->type = SSM2602; |
686 | 706 | ||
707 | ssm2602->regmap = devm_regmap_init_spi(spi, &ssm2602_regmap_config); | ||
708 | if (IS_ERR(ssm2602->regmap)) | ||
709 | return PTR_ERR(ssm2602->regmap); | ||
710 | |||
687 | ret = snd_soc_register_codec(&spi->dev, | 711 | ret = snd_soc_register_codec(&spi->dev, |
688 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); | 712 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
689 | return ret; | 713 | return ret; |
@@ -724,9 +748,12 @@ static int __devinit ssm2602_i2c_probe(struct i2c_client *i2c, | |||
724 | return -ENOMEM; | 748 | return -ENOMEM; |
725 | 749 | ||
726 | i2c_set_clientdata(i2c, ssm2602); | 750 | i2c_set_clientdata(i2c, ssm2602); |
727 | ssm2602->control_type = SND_SOC_I2C; | ||
728 | ssm2602->type = id->driver_data; | 751 | ssm2602->type = id->driver_data; |
729 | 752 | ||
753 | ssm2602->regmap = devm_regmap_init_i2c(i2c, &ssm2602_regmap_config); | ||
754 | if (IS_ERR(ssm2602->regmap)) | ||
755 | return PTR_ERR(ssm2602->regmap); | ||
756 | |||
730 | ret = snd_soc_register_codec(&i2c->dev, | 757 | ret = snd_soc_register_codec(&i2c->dev, |
731 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); | 758 | &soc_codec_dev_ssm2602, &ssm2602_dai, 1); |
732 | return ret; | 759 | return ret; |