aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/ak4641.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/ak4641.c')
-rw-r--r--sound/soc/codecs/ak4641.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 49cc5f6d6dba..94cbe508dd37 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -17,6 +17,7 @@
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/pm.h> 18#include <linux/pm.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/regmap.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
@@ -30,6 +31,7 @@
30 31
31/* codec private data */ 32/* codec private data */
32struct ak4641_priv { 33struct ak4641_priv {
34 struct regmap *regmap;
33 unsigned int sysclk; 35 unsigned int sysclk;
34 int deemph; 36 int deemph;
35 int playback_fs; 37 int playback_fs;
@@ -38,12 +40,12 @@ struct ak4641_priv {
38/* 40/*
39 * ak4641 register cache 41 * ak4641 register cache
40 */ 42 */
41static const u8 ak4641_reg[AK4641_CACHEREGNUM] = { 43static const struct reg_default ak4641_reg_defaults[] = {
42 0x00, 0x80, 0x00, 0x80, 44 { 0, 0x00 }, { 1, 0x80 }, { 2, 0x00 }, { 3, 0x80 },
43 0x02, 0x00, 0x11, 0x05, 45 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x11 }, { 7, 0x05 },
44 0x00, 0x00, 0x36, 0x10, 46 { 8, 0x00 }, { 9, 0x00 }, { 10, 0x36 }, { 11, 0x10 },
45 0x00, 0x00, 0x57, 0x00, 47 { 12, 0x00 }, { 13, 0x00 }, { 14, 0x57 }, { 15, 0x00 },
46 0x88, 0x88, 0x08, 0x08 48 { 16, 0x88 }, { 17, 0x88 }, { 18, 0x08 }, { 19, 0x08 }
47}; 49};
48 50
49static const int deemph_settings[] = {44100, 0, 48000, 32000}; 51static const int deemph_settings[] = {44100, 0, 48000, 32000};
@@ -396,6 +398,7 @@ static int ak4641_mute(struct snd_soc_dai *dai, int mute)
396static int ak4641_set_bias_level(struct snd_soc_codec *codec, 398static int ak4641_set_bias_level(struct snd_soc_codec *codec,
397 enum snd_soc_bias_level level) 399 enum snd_soc_bias_level level)
398{ 400{
401 struct ak4641_priv *ak4641 = snd_soc_codec_get_drvdata(codec);
399 struct ak4641_platform_data *pdata = codec->dev->platform_data; 402 struct ak4641_platform_data *pdata = codec->dev->platform_data;
400 int ret; 403 int ret;
401 404
@@ -417,7 +420,7 @@ static int ak4641_set_bias_level(struct snd_soc_codec *codec,
417 gpio_set_value(pdata->gpio_npdn, 1); 420 gpio_set_value(pdata->gpio_npdn, 1);
418 mdelay(1); 421 mdelay(1);
419 422
420 ret = snd_soc_cache_sync(codec); 423 ret = regcache_sync(ak4641->regmap);
421 if (ret) { 424 if (ret) {
422 dev_err(codec->dev, 425 dev_err(codec->dev,
423 "Failed to sync cache: %d\n", ret); 426 "Failed to sync cache: %d\n", ret);
@@ -433,7 +436,7 @@ static int ak4641_set_bias_level(struct snd_soc_codec *codec,
433 gpio_set_value(pdata->gpio_npdn, 0); 436 gpio_set_value(pdata->gpio_npdn, 0);
434 if (pdata && gpio_is_valid(pdata->gpio_power)) 437 if (pdata && gpio_is_valid(pdata->gpio_power))
435 gpio_set_value(pdata->gpio_power, 0); 438 gpio_set_value(pdata->gpio_power, 0);
436 codec->cache_sync = 1; 439 regcache_mark_dirty(ak4641->regmap);
437 break; 440 break;
438 } 441 }
439 codec->dapm.bias_level = level; 442 codec->dapm.bias_level = level;
@@ -518,7 +521,7 @@ static int ak4641_probe(struct snd_soc_codec *codec)
518{ 521{
519 int ret; 522 int ret;
520 523
521 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); 524 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
522 if (ret != 0) { 525 if (ret != 0) {
523 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 526 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
524 return ret; 527 return ret;
@@ -550,12 +553,17 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4641 = {
550 .dapm_routes = ak4641_audio_map, 553 .dapm_routes = ak4641_audio_map,
551 .num_dapm_routes = ARRAY_SIZE(ak4641_audio_map), 554 .num_dapm_routes = ARRAY_SIZE(ak4641_audio_map),
552 .set_bias_level = ak4641_set_bias_level, 555 .set_bias_level = ak4641_set_bias_level,
553 .reg_cache_size = ARRAY_SIZE(ak4641_reg),
554 .reg_word_size = sizeof(u8),
555 .reg_cache_default = ak4641_reg,
556 .reg_cache_step = 1,
557}; 556};
558 557
558static const struct regmap_config ak4641_regmap = {
559 .reg_bits = 8,
560 .val_bits = 8,
561
562 .max_register = AK4641_BTIF,
563 .reg_defaults = ak4641_reg_defaults,
564 .num_reg_defaults = ARRAY_SIZE(ak4641_reg_defaults),
565 .cache_type = REGCACHE_RBTREE,
566};
559 567
560static int ak4641_i2c_probe(struct i2c_client *i2c, 568static int ak4641_i2c_probe(struct i2c_client *i2c,
561 const struct i2c_device_id *id) 569 const struct i2c_device_id *id)
@@ -569,6 +577,10 @@ static int ak4641_i2c_probe(struct i2c_client *i2c,
569 if (!ak4641) 577 if (!ak4641)
570 return -ENOMEM; 578 return -ENOMEM;
571 579
580 ak4641->regmap = devm_regmap_init_i2c(i2c, &ak4641_regmap);
581 if (IS_ERR(ak4641->regmap))
582 return PTR_ERR(ak4641->regmap);
583
572 if (pdata) { 584 if (pdata) {
573 if (gpio_is_valid(pdata->gpio_power)) { 585 if (gpio_is_valid(pdata->gpio_power)) {
574 ret = gpio_request_one(pdata->gpio_power, 586 ret = gpio_request_one(pdata->gpio_power,