aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-10 00:57:03 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-09-10 20:16:15 -0400
commit1ca6517566b52662f1dea65e3c3d02997282cb01 (patch)
tree40fe72d292512ee324f4395cd4aa98ca91c0f689
parentb61d6d40323997d9da3b95ecce2570f0b782a07f (diff)
ASoC: cs4270: Convert to direct regmap API usage
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Timur Tabi <timur@freescale.com>
-rw-r--r--sound/soc/codecs/cs4270.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index 64c29b8a379f..815b53bc2d27 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -112,14 +112,15 @@
112 * This array contains the power-on default values of the registers, with the 112 * This array contains the power-on default values of the registers, with the
113 * exception of the "CHIPID" register (01h). The lower four bits of that 113 * exception of the "CHIPID" register (01h). The lower four bits of that
114 * register contain the hardware revision, so it is treated as volatile. 114 * register contain the hardware revision, so it is treated as volatile.
115 *
116 * Also note that on the CS4270, the first readable register is 1, but ASoC
117 * assumes the first register is 0. Therfore, the array must have an entry for
118 * register 0, but we use cs4270_reg_is_readable() to tell ASoC that it can't
119 * be read.
120 */ 115 */
121static const u8 cs4270_default_reg_cache[CS4270_LASTREG + 1] = { 116static const struct reg_default cs4270_reg_defaults[] = {
122 0x00, 0x00, 0x00, 0x30, 0x00, 0x60, 0x20, 0x00, 0x00 117 { 2, 0x00 },
118 { 3, 0x30 },
119 { 4, 0x00 },
120 { 5, 0x60 },
121 { 6, 0x20 },
122 { 7, 0x00 },
123 { 8, 0x00 },
123}; 124};
124 125
125static const char *supply_names[] = { 126static const char *supply_names[] = {
@@ -128,7 +129,7 @@ static const char *supply_names[] = {
128 129
129/* Private data for the CS4270 */ 130/* Private data for the CS4270 */
130struct cs4270_private { 131struct cs4270_private {
131 enum snd_soc_control_type control_type; 132 struct regmap *regmap;
132 unsigned int mclk; /* Input frequency of the MCLK pin */ 133 unsigned int mclk; /* Input frequency of the MCLK pin */
133 unsigned int mode; /* The mode (I2S or left-justified) */ 134 unsigned int mode; /* The mode (I2S or left-justified) */
134 unsigned int slave_mode; 135 unsigned int slave_mode;
@@ -193,12 +194,12 @@ static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
193/* The number of MCLK/LRCK ratios supported by the CS4270 */ 194/* The number of MCLK/LRCK ratios supported by the CS4270 */
194#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) 195#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
195 196
196static int cs4270_reg_is_readable(struct snd_soc_codec *codec, unsigned int reg) 197static bool cs4270_reg_is_readable(struct device *dev, unsigned int reg)
197{ 198{
198 return (reg >= CS4270_FIRSTREG) && (reg <= CS4270_LASTREG); 199 return (reg >= CS4270_FIRSTREG) && (reg <= CS4270_LASTREG);
199} 200}
200 201
201static int cs4270_reg_is_volatile(struct snd_soc_codec *codec, unsigned int reg) 202static bool cs4270_reg_is_volatile(struct device *dev, unsigned int reg)
202{ 203{
203 /* Unreadable registers are considered volatile */ 204 /* Unreadable registers are considered volatile */
204 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG)) 205 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
@@ -492,7 +493,7 @@ static int cs4270_probe(struct snd_soc_codec *codec)
492 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will 493 /* Tell ASoC what kind of I/O to use to read the registers. ASoC will
493 * then do the I2C transactions itself. 494 * then do the I2C transactions itself.
494 */ 495 */
495 ret = snd_soc_codec_set_cache_io(codec, 8, 8, cs4270->control_type); 496 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
496 if (ret < 0) { 497 if (ret < 0) {
497 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret); 498 dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
498 return ret; 499 return ret;
@@ -587,7 +588,7 @@ static int cs4270_soc_resume(struct snd_soc_codec *codec)
587 ndelay(500); 588 ndelay(500);
588 589
589 /* first restore the entire register cache ... */ 590 /* first restore the entire register cache ... */
590 snd_soc_cache_sync(codec); 591 regcache_sync(cs4270->regmap);
591 592
592 /* ... then disable the power-down bits */ 593 /* ... then disable the power-down bits */
593 reg = snd_soc_read(codec, CS4270_PWRCTL); 594 reg = snd_soc_read(codec, CS4270_PWRCTL);
@@ -611,11 +612,6 @@ static const struct snd_soc_codec_driver soc_codec_device_cs4270 = {
611 612
612 .controls = cs4270_snd_controls, 613 .controls = cs4270_snd_controls,
613 .num_controls = ARRAY_SIZE(cs4270_snd_controls), 614 .num_controls = ARRAY_SIZE(cs4270_snd_controls),
614 .volatile_register = cs4270_reg_is_volatile,
615 .readable_register = cs4270_reg_is_readable,
616 .reg_cache_size = CS4270_LASTREG + 1,
617 .reg_word_size = sizeof(u8),
618 .reg_cache_default = cs4270_default_reg_cache,
619}; 615};
620 616
621/* 617/*
@@ -627,6 +623,18 @@ static const struct of_device_id cs4270_of_match[] = {
627}; 623};
628MODULE_DEVICE_TABLE(of, cs4270_of_match); 624MODULE_DEVICE_TABLE(of, cs4270_of_match);
629 625
626static const struct regmap_config cs4270_regmap = {
627 .reg_bits = 8,
628 .val_bits = 8,
629 .max_register = CS4270_LASTREG,
630 .reg_defaults = cs4270_reg_defaults,
631 .num_reg_defaults = ARRAY_SIZE(cs4270_reg_defaults),
632 .cache_type = REGCACHE_RBTREE,
633
634 .readable_reg = cs4270_reg_is_readable,
635 .volatile_reg = cs4270_reg_is_volatile,
636};
637
630/** 638/**
631 * cs4270_i2c_probe - initialize the I2C interface of the CS4270 639 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
632 * @i2c_client: the I2C client object 640 * @i2c_client: the I2C client object
@@ -640,6 +648,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
640{ 648{
641 struct device_node *np = i2c_client->dev.of_node; 649 struct device_node *np = i2c_client->dev.of_node;
642 struct cs4270_private *cs4270; 650 struct cs4270_private *cs4270;
651 unsigned int val;
643 int ret, i; 652 int ret, i;
644 653
645 cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private), 654 cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private),
@@ -674,16 +683,19 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
674 } 683 }
675 } 684 }
676 685
677 /* Verify that we have a CS4270 */ 686 cs4270->regmap = devm_regmap_init_i2c(i2c_client, &cs4270_regmap);
687 if (IS_ERR(cs4270->regmap))
688 return PTR_ERR(cs4270->regmap);
678 689
679 ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); 690 /* Verify that we have a CS4270 */
691 ret = regmap_read(cs4270->regmap, CS4270_CHIPID, &val);
680 if (ret < 0) { 692 if (ret < 0) {
681 dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n", 693 dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n",
682 i2c_client->addr); 694 i2c_client->addr);
683 return ret; 695 return ret;
684 } 696 }
685 /* The top four bits of the chip ID should be 1100. */ 697 /* The top four bits of the chip ID should be 1100. */
686 if ((ret & 0xF0) != 0xC0) { 698 if ((val & 0xF0) != 0xC0) {
687 dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n", 699 dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n",
688 i2c_client->addr); 700 i2c_client->addr);
689 return -ENODEV; 701 return -ENODEV;
@@ -691,10 +703,9 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
691 703
692 dev_info(&i2c_client->dev, "found device at i2c address %X\n", 704 dev_info(&i2c_client->dev, "found device at i2c address %X\n",
693 i2c_client->addr); 705 i2c_client->addr);
694 dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF); 706 dev_info(&i2c_client->dev, "hardware revision %X\n", val & 0xF);
695 707
696 i2c_set_clientdata(i2c_client, cs4270); 708 i2c_set_clientdata(i2c_client, cs4270);
697 cs4270->control_type = SND_SOC_I2C;
698 709
699 ret = snd_soc_register_codec(&i2c_client->dev, 710 ret = snd_soc_register_codec(&i2c_client->dev,
700 &soc_codec_device_cs4270, &cs4270_dai, 1); 711 &soc_codec_device_cs4270, &cs4270_dai, 1);