aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2014-02-11 14:24:31 -0500
committerMark Brown <broonie@linaro.org>2014-02-11 14:58:50 -0500
commitda071489762499a3635cb3563d32792cea20c087 (patch)
tree41e2ed15469e76b2e8738c9a8b8632f5c6b867dc
parent5be736442ed94217c6521ae0c948abab995f281f (diff)
ASoC: cs42l51: Convert to direct regmap API usage
As part of phasing out the ASoC level register I/O code (which is now just a thin wrapper around regmap anyway) convert the cs42l51 driver to use the regmap API directly. We now no longer initialise the cache from hardware at startup, the regmap caches are smart enough to understand which registers are actually cached and read on demand. This should have no visible effect on the system. Signed-off-by: Mark Brown <broonie@linaro.org> Acked-by: Brian Austin <brian.austin@cirrus.com>
-rw-r--r--sound/soc/codecs/cs42l51.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index b11079b38f15..e53c8714591f 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -30,6 +30,7 @@
30#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/regmap.h>
33 34
34#include "cs42l51.h" 35#include "cs42l51.h"
35 36
@@ -40,7 +41,6 @@ enum master_slave_mode {
40}; 41};
41 42
42struct cs42l51_private { 43struct cs42l51_private {
43 enum snd_soc_control_type control_type;
44 unsigned int mclk; 44 unsigned int mclk;
45 unsigned int audio_mode; /* The mode (I2S or left-justified) */ 45 unsigned int audio_mode; /* The mode (I2S or left-justified) */
46 enum master_slave_mode func; 46 enum master_slave_mode func;
@@ -52,24 +52,6 @@ struct cs42l51_private {
52 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \ 52 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
53 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) 53 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
54 54
55static int cs42l51_fill_cache(struct snd_soc_codec *codec)
56{
57 u8 *cache = codec->reg_cache + 1;
58 struct i2c_client *i2c_client = to_i2c_client(codec->dev);
59 s32 length;
60
61 length = i2c_smbus_read_i2c_block_data(i2c_client,
62 CS42L51_FIRSTREG | 0x80, CS42L51_NUMREGS, cache);
63 if (length != CS42L51_NUMREGS) {
64 dev_err(&i2c_client->dev,
65 "I2C read failure, addr=0x%x (ret=%d vs %d)\n",
66 i2c_client->addr, length, CS42L51_NUMREGS);
67 return -EIO;
68 }
69
70 return 0;
71}
72
73static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, 55static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
74 struct snd_ctl_elem_value *ucontrol) 56 struct snd_ctl_elem_value *ucontrol)
75{ 57{
@@ -508,13 +490,7 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
508 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec); 490 struct cs42l51_private *cs42l51 = snd_soc_codec_get_drvdata(codec);
509 int ret, reg; 491 int ret, reg;
510 492
511 ret = cs42l51_fill_cache(codec); 493 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
512 if (ret < 0) {
513 dev_err(codec->dev, "failed to fill register cache\n");
514 return ret;
515 }
516
517 ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs42l51->control_type);
518 if (ret < 0) { 494 if (ret < 0) {
519 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 495 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
520 return ret; 496 return ret;
@@ -538,8 +514,6 @@ static int cs42l51_probe(struct snd_soc_codec *codec)
538 514
539static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { 515static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
540 .probe = cs42l51_probe, 516 .probe = cs42l51_probe,
541 .reg_cache_size = CS42L51_NUMREGS + 1,
542 .reg_word_size = sizeof(u8),
543 517
544 .controls = cs42l51_snd_controls, 518 .controls = cs42l51_snd_controls,
545 .num_controls = ARRAY_SIZE(cs42l51_snd_controls), 519 .num_controls = ARRAY_SIZE(cs42l51_snd_controls),
@@ -549,28 +523,46 @@ static struct snd_soc_codec_driver soc_codec_device_cs42l51 = {
549 .num_dapm_routes = ARRAY_SIZE(cs42l51_routes), 523 .num_dapm_routes = ARRAY_SIZE(cs42l51_routes),
550}; 524};
551 525
526static const struct regmap_config cs42l51_regmap = {
527 .reg_bits = 8,
528 .val_bits = 8,
529
530 .max_register = CS42L51_CHARGE_FREQ,
531 .cache_type = REGCACHE_RBTREE,
532};
533
552static int cs42l51_i2c_probe(struct i2c_client *i2c_client, 534static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
553 const struct i2c_device_id *id) 535 const struct i2c_device_id *id)
554{ 536{
555 struct cs42l51_private *cs42l51; 537 struct cs42l51_private *cs42l51;
538 struct regmap *regmap;
539 unsigned int val;
556 int ret; 540 int ret;
557 541
542 regmap = devm_regmap_init_i2c(i2c_client, &cs42l51_regmap);
543 if (IS_ERR(regmap)) {
544 ret = PTR_ERR(regmap);
545 dev_err(&i2c_client->dev, "Failed to create regmap: %d\n",
546 ret);
547 return ret;
548 }
549
558 /* Verify that we have a CS42L51 */ 550 /* Verify that we have a CS42L51 */
559 ret = i2c_smbus_read_byte_data(i2c_client, CS42L51_CHIP_REV_ID); 551 ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val);
560 if (ret < 0) { 552 if (ret < 0) {
561 dev_err(&i2c_client->dev, "failed to read I2C\n"); 553 dev_err(&i2c_client->dev, "failed to read I2C\n");
562 goto error; 554 goto error;
563 } 555 }
564 556
565 if ((ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && 557 if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) &&
566 (ret != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { 558 (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) {
567 dev_err(&i2c_client->dev, "Invalid chip id\n"); 559 dev_err(&i2c_client->dev, "Invalid chip id: %x\n", val);
568 ret = -ENODEV; 560 ret = -ENODEV;
569 goto error; 561 goto error;
570 } 562 }
571 563
572 dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", 564 dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n",
573 ret & 7); 565 val & 7);
574 566
575 cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private), 567 cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private),
576 GFP_KERNEL); 568 GFP_KERNEL);
@@ -578,7 +570,6 @@ static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
578 return -ENOMEM; 570 return -ENOMEM;
579 571
580 i2c_set_clientdata(i2c_client, cs42l51); 572 i2c_set_clientdata(i2c_client, cs42l51);
581 cs42l51->control_type = SND_SOC_I2C;
582 573
583 ret = snd_soc_register_codec(&i2c_client->dev, 574 ret = snd_soc_register_codec(&i2c_client->dev,
584 &soc_codec_device_cs42l51, &cs42l51_dai, 1); 575 &soc_codec_device_cs42l51, &cs42l51_dai, 1);