summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2015-07-13 06:26:47 -0400
committerMark Brown <broonie@kernel.org>2015-07-13 06:51:35 -0400
commitf33c340a51e81a2e6af316b1b8b9b769d32ce8b7 (patch)
tree4bb1812909a9060c4652cac10a6cb1415563ac3f /sound
parent82c7b531f3328dbbb7a53d0f1dc53b92846c411c (diff)
ASoC: uda134x: Convert to regmap
Use regmap rather then the legacy ASoC IO for the uda134x driver. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/uda134x.c115
-rw-r--r--sound/soc/codecs/uda134x.h2
2 files changed, 62 insertions, 55 deletions
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index d47da0ec8f47..d25a9f3968d0 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -37,13 +37,27 @@ struct uda134x_priv {
37 37
38 struct snd_pcm_substream *master_substream; 38 struct snd_pcm_substream *master_substream;
39 struct snd_pcm_substream *slave_substream; 39 struct snd_pcm_substream *slave_substream;
40
41 struct regmap *regmap;
42 struct uda134x_platform_data *pd;
40}; 43};
41 44
42static const char uda134x_reg[UDA134X_REGS_NUM] = { 45static const struct reg_default uda134x_reg_defaults[] = {
43 /* Extended address registers */ 46 { UDA134X_EA000, 0x04 },
44 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 47 { UDA134X_EA001, 0x04 },
45 /* Status, data regs */ 48 { UDA134X_EA010, 0x04 },
46 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 49 { UDA134X_EA011, 0x00 },
50 { UDA134X_EA100, 0x00 },
51 { UDA134X_EA101, 0x00 },
52 { UDA134X_EA110, 0x00 },
53 { UDA134X_EA111, 0x00 },
54 { UDA134X_STATUS0, 0x00 },
55 { UDA134X_STATUS1, 0x03 },
56 { UDA134X_DATA000, 0x00 },
57 { UDA134X_DATA001, 0x00 },
58 { UDA134X_DATA010, 0x00 },
59 { UDA134X_DATA011, 0x00 },
60 { UDA134X_DATA1, 0x00 },
47}; 61};
48 62
49/* 63/*
@@ -52,47 +66,36 @@ static const char uda134x_reg[UDA134X_REGS_NUM] = {
52static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec, 66static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec,
53 unsigned int reg) 67 unsigned int reg)
54{ 68{
55 u8 *cache = codec->reg_cache; 69 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
70 unsigned int val;
71 int ret;
56 72
57 if (reg >= UDA134X_REGS_NUM) 73 ret = regmap_read(uda134x->regmap, reg, &val);
74 if (ret)
58 return -1; 75 return -1;
59 return cache[reg]; 76
77 return val;
60} 78}
61 79
62/* 80static void uda134x_write(struct snd_soc_codec *codec, unsigned int reg,
63 * Write the register cache 81 unsigned int val)
64 */
65static inline void uda134x_write_reg_cache(struct snd_soc_codec *codec,
66 u8 reg, unsigned int value)
67{ 82{
68 u8 *cache = codec->reg_cache; 83 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
69 84
70 if (reg >= UDA134X_REGS_NUM) 85 regmap_write(uda134x->regmap, reg, val);
71 return;
72 cache[reg] = value;
73} 86}
74 87
75/* 88/*
76 * Write to the uda134x registers 89 * Write to the uda134x registers
77 * 90 *
78 */ 91 */
79static int uda134x_write(struct snd_soc_codec *codec, unsigned int reg, 92static int uda134x_regmap_write(void *context, unsigned int reg,
80 unsigned int value) 93 unsigned int value)
81{ 94{
95 struct uda134x_platform_data *pd = context;
82 int ret; 96 int ret;
83 u8 addr; 97 u8 addr;
84 u8 data = value; 98 u8 data = value;
85 struct uda134x_platform_data *pd = codec->control_data;
86
87 pr_debug("%s reg: %02X, value:%02X\n", __func__, reg, value);
88
89 if (reg >= UDA134X_REGS_NUM) {
90 printk(KERN_ERR "%s unknown register: reg: %u",
91 __func__, reg);
92 return -EINVAL;
93 }
94
95 uda134x_write_reg_cache(codec, reg, value);
96 99
97 switch (reg) { 100 switch (reg) {
98 case UDA134X_STATUS0: 101 case UDA134X_STATUS0:
@@ -325,10 +328,8 @@ static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai,
325static int uda134x_set_bias_level(struct snd_soc_codec *codec, 328static int uda134x_set_bias_level(struct snd_soc_codec *codec,
326 enum snd_soc_bias_level level) 329 enum snd_soc_bias_level level)
327{ 330{
328 struct uda134x_platform_data *pd = codec->control_data; 331 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
329 int i; 332 struct uda134x_platform_data *pd = uda134x->pd;
330 u8 *cache = codec->reg_cache;
331
332 pr_debug("%s bias level %d\n", __func__, level); 333 pr_debug("%s bias level %d\n", __func__, level);
333 334
334 switch (level) { 335 switch (level) {
@@ -338,17 +339,17 @@ static int uda134x_set_bias_level(struct snd_soc_codec *codec,
338 /* power on */ 339 /* power on */
339 if (pd->power) { 340 if (pd->power) {
340 pd->power(1); 341 pd->power(1);
341 /* Sync reg_cache with the hardware */ 342 regcache_sync(uda134x->regmap);
342 for (i = 0; i < ARRAY_SIZE(uda134x_reg); i++)
343 codec->driver->write(codec, i, *cache++);
344 } 343 }
345 break; 344 break;
346 case SND_SOC_BIAS_STANDBY: 345 case SND_SOC_BIAS_STANDBY:
347 break; 346 break;
348 case SND_SOC_BIAS_OFF: 347 case SND_SOC_BIAS_OFF:
349 /* power off */ 348 /* power off */
350 if (pd->power) 349 if (pd->power) {
351 pd->power(0); 350 pd->power(0);
351 regcache_mark_dirty(uda134x->regmap);
352 }
352 break; 353 break;
353 } 354 }
354 return 0; 355 return 0;
@@ -479,21 +480,14 @@ static struct snd_soc_dai_driver uda134x_dai = {
479static int uda134x_soc_probe(struct snd_soc_codec *codec) 480static int uda134x_soc_probe(struct snd_soc_codec *codec)
480{ 481{
481 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); 482 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
482 struct uda134x_platform_data *pd = codec->component.card->dev->platform_data;
483 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec); 483 struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
484 struct uda134x_platform_data *pd = uda134x->pd;
484 const struct snd_soc_dapm_widget *widgets; 485 const struct snd_soc_dapm_widget *widgets;
485 unsigned num_widgets; 486 unsigned num_widgets;
486
487 int ret; 487 int ret;
488 488
489 printk(KERN_INFO "UDA134X SoC Audio Codec\n"); 489 printk(KERN_INFO "UDA134X SoC Audio Codec\n");
490 490
491 if (!pd) {
492 printk(KERN_ERR "UDA134X SoC codec: "
493 "missing L3 bitbang function\n");
494 return -ENODEV;
495 }
496
497 switch (pd->model) { 491 switch (pd->model) {
498 case UDA134X_UDA1340: 492 case UDA134X_UDA1340:
499 case UDA134X_UDA1341: 493 case UDA134X_UDA1341:
@@ -507,9 +501,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
507 return -EINVAL; 501 return -EINVAL;
508 } 502 }
509 503
510
511 codec->control_data = pd;
512
513 if (pd->power) 504 if (pd->power)
514 pd->power(1); 505 pd->power(1);
515 506
@@ -560,11 +551,6 @@ static int uda134x_soc_probe(struct snd_soc_codec *codec)
560 551
561static struct snd_soc_codec_driver soc_codec_dev_uda134x = { 552static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
562 .probe = uda134x_soc_probe, 553 .probe = uda134x_soc_probe,
563 .reg_cache_size = sizeof(uda134x_reg),
564 .reg_word_size = sizeof(u8),
565 .reg_cache_default = uda134x_reg,
566 .reg_cache_step = 1,
567 .read = uda134x_read_reg_cache,
568 .set_bias_level = uda134x_set_bias_level, 554 .set_bias_level = uda134x_set_bias_level,
569 .suspend_bias_off = true, 555 .suspend_bias_off = true,
570 556
@@ -574,16 +560,39 @@ static struct snd_soc_codec_driver soc_codec_dev_uda134x = {
574 .num_dapm_routes = ARRAY_SIZE(uda134x_dapm_routes), 560 .num_dapm_routes = ARRAY_SIZE(uda134x_dapm_routes),
575}; 561};
576 562
563static const struct regmap_config uda134x_regmap_config = {
564 .reg_bits = 8,
565 .val_bits = 8,
566 .max_register = UDA134X_DATA1,
567 .reg_defaults = uda134x_reg_defaults,
568 .num_reg_defaults = ARRAY_SIZE(uda134x_reg_defaults),
569 .cache_type = REGCACHE_RBTREE,
570
571 .reg_write = uda134x_regmap_write,
572};
573
577static int uda134x_codec_probe(struct platform_device *pdev) 574static int uda134x_codec_probe(struct platform_device *pdev)
578{ 575{
576 struct uda134x_platform_data *pd = pdev->dev.platform_data;
579 struct uda134x_priv *uda134x; 577 struct uda134x_priv *uda134x;
580 578
579 if (!pd) {
580 dev_err(&pdev->dev, "Missing L3 bitbang function\n");
581 return -ENODEV;
582 }
583
581 uda134x = devm_kzalloc(&pdev->dev, sizeof(*uda134x), GFP_KERNEL); 584 uda134x = devm_kzalloc(&pdev->dev, sizeof(*uda134x), GFP_KERNEL);
582 if (!uda134x) 585 if (!uda134x)
583 return -ENOMEM; 586 return -ENOMEM;
584 587
588 uda134x->pd = pd;
585 platform_set_drvdata(pdev, uda134x); 589 platform_set_drvdata(pdev, uda134x);
586 590
591 uda134x->regmap = devm_regmap_init(&pdev->dev, NULL, pd,
592 &uda134x_regmap_config);
593 if (IS_ERR(uda134x->regmap))
594 return PTR_ERR(uda134x->regmap);
595
587 return snd_soc_register_codec(&pdev->dev, 596 return snd_soc_register_codec(&pdev->dev,
588 &soc_codec_dev_uda134x, &uda134x_dai, 1); 597 &soc_codec_dev_uda134x, &uda134x_dai, 1);
589} 598}
diff --git a/sound/soc/codecs/uda134x.h b/sound/soc/codecs/uda134x.h
index 9faae06972b3..e41ab38c6f69 100644
--- a/sound/soc/codecs/uda134x.h
+++ b/sound/soc/codecs/uda134x.h
@@ -26,8 +26,6 @@
26#define UDA134X_DATA011 13 26#define UDA134X_DATA011 13
27#define UDA134X_DATA1 14 27#define UDA134X_DATA1 14
28 28
29#define UDA134X_REGS_NUM 15
30
31#define STATUS0_DAIFMT_MASK (~(7<<1)) 29#define STATUS0_DAIFMT_MASK (~(7<<1))
32#define STATUS0_SYSCLK_MASK (~(3<<4)) 30#define STATUS0_SYSCLK_MASK (~(3<<4))
33 31