aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-11-28 13:03:49 -0500
committerMark Brown <broonie@linaro.org>2013-12-02 06:53:30 -0500
commit4574cd94a717eff3021a3e187dd48846adbd21ea (patch)
tree81c34522e404800d832cfd1f7daaf45d26c254d4
parenta8ca52b7911378864e6defb42be9166c248a3749 (diff)
ASoC: ak4642: Convert to direct regmap API usage
This moves us towards being able to remove the ASoC level I/O code which duplicates regmap functionality. Currently the only difference between the supported devices in the driver is the regmap so we can replace the CODEC driver selections with regmap selection instead. Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--sound/soc/codecs/ak4642.c113
1 files changed, 59 insertions, 54 deletions
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 7fe1e9030c4f..5af237468618 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/of_device.h> 29#include <linux/of_device.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/regmap.h>
31#include <sound/soc.h> 32#include <sound/soc.h>
32#include <sound/initval.h> 33#include <sound/initval.h>
33#include <sound/tlv.h> 34#include <sound/tlv.h>
@@ -198,30 +199,30 @@ static const struct snd_soc_dapm_route ak4642_intercon[] = {
198/* 199/*
199 * ak4642 register cache 200 * ak4642 register cache
200 */ 201 */
201static const u8 ak4642_reg[] = { 202static const struct reg_default ak4642_reg[] = {
202 0x00, 0x00, 0x01, 0x00, 203 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
203 0x02, 0x00, 0x00, 0x00, 204 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
204 0xe1, 0xe1, 0x18, 0x00, 205 { 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 },
205 0xe1, 0x18, 0x11, 0x08, 206 { 12, 0xe1 }, { 13, 0x18 }, { 14, 0x11 }, { 15, 0x08 },
206 0x00, 0x00, 0x00, 0x00, 207 { 16, 0x00 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x00 },
207 0x00, 0x00, 0x00, 0x00, 208 { 20, 0x00 }, { 21, 0x00 }, { 22, 0x00 }, { 23, 0x00 },
208 0x00, 0x00, 0x00, 0x00, 209 { 24, 0x00 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0x00 },
209 0x00, 0x00, 0x00, 0x00, 210 { 28, 0x00 }, { 29, 0x00 }, { 30, 0x00 }, { 31, 0x00 },
210 0x00, 0x00, 0x00, 0x00, 211 { 32, 0x00 }, { 33, 0x00 }, { 34, 0x00 }, { 35, 0x00 },
211 0x00, 212 { 36, 0x00 },
212}; 213};
213 214
214static const u8 ak4648_reg[] = { 215static const struct reg_default ak4648_reg[] = {
215 0x00, 0x00, 0x01, 0x00, 216 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
216 0x02, 0x00, 0x00, 0x00, 217 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
217 0xe1, 0xe1, 0x18, 0x00, 218 { 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 },
218 0xe1, 0x18, 0x11, 0xb8, 219 { 12, 0xe1 }, { 13, 0x18 }, { 14, 0x11 }, { 15, 0xb8 },
219 0x00, 0x00, 0x00, 0x00, 220 { 16, 0x00 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x00 },
220 0x00, 0x00, 0x00, 0x00, 221 { 20, 0x00 }, { 21, 0x00 }, { 22, 0x00 }, { 23, 0x00 },
221 0x00, 0x00, 0x00, 0x00, 222 { 24, 0x00 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0x00 },
222 0x00, 0x00, 0x00, 0x00, 223 { 28, 0x00 }, { 29, 0x00 }, { 30, 0x00 }, { 31, 0x00 },
223 0x00, 0x00, 0x00, 0x00, 224 { 32, 0x00 }, { 33, 0x00 }, { 34, 0x00 }, { 35, 0x00 },
224 0x00, 0x88, 0x88, 0x08, 225 { 36, 0x00 }, { 37, 0x88 }, { 38, 0x88 }, { 39, 0x08 },
225}; 226};
226 227
227static int ak4642_dai_startup(struct snd_pcm_substream *substream, 228static int ak4642_dai_startup(struct snd_pcm_substream *substream,
@@ -454,7 +455,10 @@ static struct snd_soc_dai_driver ak4642_dai = {
454 455
455static int ak4642_resume(struct snd_soc_codec *codec) 456static int ak4642_resume(struct snd_soc_codec *codec)
456{ 457{
457 snd_soc_cache_sync(codec); 458 struct regmap *regmap = dev_get_regmap(codec->dev, NULL);
459
460 regcache_mark_dirty(regmap);
461 regcache_sync(regmap);
458 return 0; 462 return 0;
459} 463}
460 464
@@ -463,7 +467,7 @@ static int ak4642_probe(struct snd_soc_codec *codec)
463{ 467{
464 int ret; 468 int ret;
465 469
466 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 470 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
467 if (ret < 0) { 471 if (ret < 0) {
468 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 472 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
469 return ret; 473 return ret;
@@ -485,9 +489,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
485 .remove = ak4642_remove, 489 .remove = ak4642_remove,
486 .resume = ak4642_resume, 490 .resume = ak4642_resume,
487 .set_bias_level = ak4642_set_bias_level, 491 .set_bias_level = ak4642_set_bias_level,
488 .reg_cache_default = ak4642_reg, /* ak4642 reg */
489 .reg_cache_size = ARRAY_SIZE(ak4642_reg), /* ak4642 reg */
490 .reg_word_size = sizeof(u8),
491 .controls = ak4642_snd_controls, 492 .controls = ak4642_snd_controls,
492 .num_controls = ARRAY_SIZE(ak4642_snd_controls), 493 .num_controls = ARRAY_SIZE(ak4642_snd_controls),
493 .dapm_widgets = ak4642_dapm_widgets, 494 .dapm_widgets = ak4642_dapm_widgets,
@@ -496,20 +497,20 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
496 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon), 497 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon),
497}; 498};
498 499
499static struct snd_soc_codec_driver soc_codec_dev_ak4648 = { 500static const struct regmap_config ak4642_regmap = {
500 .probe = ak4642_probe, 501 .reg_bits = 8,
501 .remove = ak4642_remove, 502 .val_bits = 8,
502 .resume = ak4642_resume, 503 .max_register = ARRAY_SIZE(ak4642_reg) + 1,
503 .set_bias_level = ak4642_set_bias_level, 504 .reg_defaults = ak4642_reg,
504 .reg_cache_default = ak4648_reg, /* ak4648 reg */ 505 .num_reg_defaults = ARRAY_SIZE(ak4642_reg),
505 .reg_cache_size = ARRAY_SIZE(ak4648_reg), /* ak4648 reg */ 506};
506 .reg_word_size = sizeof(u8), 507
507 .controls = ak4642_snd_controls, 508static const struct regmap_config ak4648_regmap = {
508 .num_controls = ARRAY_SIZE(ak4642_snd_controls), 509 .reg_bits = 8,
509 .dapm_widgets = ak4642_dapm_widgets, 510 .val_bits = 8,
510 .num_dapm_widgets = ARRAY_SIZE(ak4642_dapm_widgets), 511 .max_register = ARRAY_SIZE(ak4648_reg) + 1,
511 .dapm_routes = ak4642_intercon, 512 .reg_defaults = ak4648_reg,
512 .num_dapm_routes = ARRAY_SIZE(ak4642_intercon), 513 .num_reg_defaults = ARRAY_SIZE(ak4648_reg),
513}; 514};
514 515
515#if IS_ENABLED(CONFIG_I2C) 516#if IS_ENABLED(CONFIG_I2C)
@@ -518,26 +519,30 @@ static int ak4642_i2c_probe(struct i2c_client *i2c,
518 const struct i2c_device_id *id) 519 const struct i2c_device_id *id)
519{ 520{
520 struct device_node *np = i2c->dev.of_node; 521 struct device_node *np = i2c->dev.of_node;
521 const struct snd_soc_codec_driver *driver; 522 const struct regmap_config *regmap_config = NULL;
523 struct regmap *regmap;
522 524
523 driver = NULL;
524 if (np) { 525 if (np) {
525 const struct of_device_id *of_id; 526 const struct of_device_id *of_id;
526 527
527 of_id = of_match_device(ak4642_of_match, &i2c->dev); 528 of_id = of_match_device(ak4642_of_match, &i2c->dev);
528 if (of_id) 529 if (of_id)
529 driver = of_id->data; 530 regmap_config = of_id->data;
530 } else { 531 } else {
531 driver = (struct snd_soc_codec_driver *)id->driver_data; 532 regmap_config = (const struct regmap_config *)id->driver_data;
532 } 533 }
533 534
534 if (!driver) { 535 if (!regmap_config) {
535 dev_err(&i2c->dev, "no driver\n"); 536 dev_err(&i2c->dev, "Unknown device type\n");
536 return -EINVAL; 537 return -EINVAL;
537 } 538 }
538 539
540 regmap = devm_regmap_init_i2c(i2c, regmap_config);
541 if (IS_ERR(regmap))
542 return PTR_ERR(regmap);
543
539 return snd_soc_register_codec(&i2c->dev, 544 return snd_soc_register_codec(&i2c->dev,
540 driver, &ak4642_dai, 1); 545 &soc_codec_dev_ak4642, &ak4642_dai, 1);
541} 546}
542 547
543static int ak4642_i2c_remove(struct i2c_client *client) 548static int ak4642_i2c_remove(struct i2c_client *client)
@@ -547,17 +552,17 @@ static int ak4642_i2c_remove(struct i2c_client *client)
547} 552}
548 553
549static struct of_device_id ak4642_of_match[] = { 554static struct of_device_id ak4642_of_match[] = {
550 { .compatible = "asahi-kasei,ak4642", .data = &soc_codec_dev_ak4642}, 555 { .compatible = "asahi-kasei,ak4642", .data = &ak4642_regmap},
551 { .compatible = "asahi-kasei,ak4643", .data = &soc_codec_dev_ak4642}, 556 { .compatible = "asahi-kasei,ak4643", .data = &ak4642_regmap},
552 { .compatible = "asahi-kasei,ak4648", .data = &soc_codec_dev_ak4648}, 557 { .compatible = "asahi-kasei,ak4648", .data = &ak4648_regmap},
553 {}, 558 {},
554}; 559};
555MODULE_DEVICE_TABLE(of, ak4642_of_match); 560MODULE_DEVICE_TABLE(of, ak4642_of_match);
556 561
557static const struct i2c_device_id ak4642_i2c_id[] = { 562static const struct i2c_device_id ak4642_i2c_id[] = {
558 { "ak4642", (kernel_ulong_t)&soc_codec_dev_ak4642 }, 563 { "ak4642", (kernel_ulong_t)&ak4642_regmap },
559 { "ak4643", (kernel_ulong_t)&soc_codec_dev_ak4642 }, 564 { "ak4643", (kernel_ulong_t)&ak4642_regmap },
560 { "ak4648", (kernel_ulong_t)&soc_codec_dev_ak4648 }, 565 { "ak4648", (kernel_ulong_t)&ak4648_regmap },
561 { } 566 { }
562}; 567};
563MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id); 568MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);