Commit b689d9f9 authored by Mark Brown's avatar Mark Brown

ASoC: wm8580: Convert to direct regmap API usage

Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent e643049d
/* /*
* wm8580.c -- WM8580 ALSA Soc Audio driver * wm8580.c -- WM8580 ALSA Soc Audio driver
* *
* Copyright 2008-11 Wolfson Microelectronics PLC. * Copyright 2008-12 Wolfson Microelectronics PLC.
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -157,23 +158,72 @@ ...@@ -157,23 +158,72 @@
* We can't read the WM8580 register space when we * We can't read the WM8580 register space when we
* are using 2 wire for device control, so we cache them instead. * are using 2 wire for device control, so we cache them instead.
*/ */
static const u16 wm8580_reg[] = { static const struct reg_default wm8580_reg_defaults[] = {
0x0121, 0x017e, 0x007d, 0x0014, /*R3*/ { 0, 0x0121 },
0x0121, 0x017e, 0x007d, 0x0194, /*R7*/ { 1, 0x017e },
0x0010, 0x0002, 0x0002, 0x00c2, /*R11*/ { 2, 0x007d },
0x0182, 0x0082, 0x000a, 0x0024, /*R15*/ { 3, 0x0014 },
0x0009, 0x0000, 0x00ff, 0x0000, /*R19*/ { 4, 0x0121 },
0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R23*/ { 5, 0x017e },
0x00ff, 0x00ff, 0x00ff, 0x00ff, /*R27*/ { 6, 0x007d },
0x01f0, 0x0040, 0x0000, 0x0000, /*R31(0x1F)*/ { 7, 0x0194 },
0x0000, 0x0000, 0x0031, 0x000b, /*R35*/ { 8, 0x0010 },
0x0039, 0x0000, 0x0010, 0x0032, /*R39*/ { 9, 0x0002 },
0x0054, 0x0076, 0x0098, 0x0000, /*R43(0x2B)*/ { 10, 0x0002 },
0x0000, 0x0000, 0x0000, 0x0000, /*R47*/ { 11, 0x00c2 },
0x0000, 0x0000, 0x005e, 0x003e, /*R51(0x33)*/ { 12, 0x0182 },
0x0000, 0x0000 /*R53*/ { 13, 0x0082 },
{ 14, 0x000a },
{ 15, 0x0024 },
{ 16, 0x0009 },
{ 17, 0x0000 },
{ 18, 0x00ff },
{ 19, 0x0000 },
{ 20, 0x00ff },
{ 21, 0x00ff },
{ 22, 0x00ff },
{ 23, 0x00ff },
{ 24, 0x00ff },
{ 25, 0x00ff },
{ 26, 0x00ff },
{ 27, 0x00ff },
{ 28, 0x01f0 },
{ 29, 0x0040 },
{ 30, 0x0000 },
{ 31, 0x0000 },
{ 32, 0x0000 },
{ 33, 0x0000 },
{ 34, 0x0031 },
{ 35, 0x000b },
{ 36, 0x0039 },
{ 37, 0x0000 },
{ 38, 0x0010 },
{ 39, 0x0032 },
{ 40, 0x0054 },
{ 41, 0x0076 },
{ 42, 0x0098 },
{ 43, 0x0000 },
{ 44, 0x0000 },
{ 45, 0x0000 },
{ 46, 0x0000 },
{ 47, 0x0000 },
{ 48, 0x0000 },
{ 49, 0x0000 },
{ 50, 0x005e },
{ 51, 0x003e },
{ 52, 0x0000 },
}; };
static bool wm8580_volatile(struct device *dev, unsigned int reg)
{
switch (reg) {
case WM8580_RESET:
return true;
default:
return false;
}
}
struct pll_state { struct pll_state {
unsigned int in; unsigned int in;
unsigned int out; unsigned int out;
...@@ -188,7 +238,7 @@ static const char *wm8580_supply_names[WM8580_NUM_SUPPLIES] = { ...@@ -188,7 +238,7 @@ static const char *wm8580_supply_names[WM8580_NUM_SUPPLIES] = {
/* codec private data */ /* codec private data */
struct wm8580_priv { struct wm8580_priv {
enum snd_soc_control_type control_type; struct regmap *regmap;
struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES]; struct regulator_bulk_data supplies[WM8580_NUM_SUPPLIES];
struct pll_state a; struct pll_state a;
struct pll_state b; struct pll_state b;
...@@ -203,14 +253,16 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol, ...@@ -203,14 +253,16 @@ static int wm8580_out_vu(struct snd_kcontrol *kcontrol,
struct soc_mixer_control *mc = struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value; (struct soc_mixer_control *)kcontrol->private_value;
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
u16 *reg_cache = codec->reg_cache; struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
unsigned int reg = mc->reg; unsigned int reg = mc->reg;
unsigned int reg2 = mc->rreg; unsigned int reg2 = mc->rreg;
int ret; int ret;
/* Clear the register cache so we write without VU set */ /* Clear the register cache VU so we write without VU set */
reg_cache[reg] = 0; regcache_cache_only(wm8580->regmap, true);
reg_cache[reg2] = 0; regmap_update_bits(wm8580->regmap, reg, 0x100, 0x000);
regmap_update_bits(wm8580->regmap, reg2, 0x100, 0x000);
regcache_cache_only(wm8580->regmap, false);
ret = snd_soc_put_volsw(kcontrol, ucontrol); ret = snd_soc_put_volsw(kcontrol, ucontrol);
if (ret < 0) if (ret < 0)
...@@ -817,7 +869,7 @@ static int wm8580_probe(struct snd_soc_codec *codec) ...@@ -817,7 +869,7 @@ static int wm8580_probe(struct snd_soc_codec *codec)
struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec); struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
int ret = 0,i; int ret = 0,i;
ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8580->control_type); ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
if (ret < 0) { if (ret < 0) {
dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
return ret; return ret;
...@@ -875,9 +927,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8580 = { ...@@ -875,9 +927,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8580 = {
.probe = wm8580_probe, .probe = wm8580_probe,
.remove = wm8580_remove, .remove = wm8580_remove,
.set_bias_level = wm8580_set_bias_level, .set_bias_level = wm8580_set_bias_level,
.reg_cache_size = ARRAY_SIZE(wm8580_reg),
.reg_word_size = sizeof(u16),
.reg_cache_default = wm8580_reg,
.controls = wm8580_snd_controls, .controls = wm8580_snd_controls,
.num_controls = ARRAY_SIZE(wm8580_snd_controls), .num_controls = ARRAY_SIZE(wm8580_snd_controls),
...@@ -892,6 +941,18 @@ static const struct of_device_id wm8580_of_match[] = { ...@@ -892,6 +941,18 @@ static const struct of_device_id wm8580_of_match[] = {
{ }, { },
}; };
static const struct regmap_config wm8580_regmap = {
.reg_bits = 7,
.val_bits = 9,
.max_register = WM8580_MAX_REGISTER,
.reg_defaults = wm8580_reg_defaults,
.num_reg_defaults = ARRAY_SIZE(wm8580_reg_defaults),
.cache_type = REGCACHE_RBTREE,
.volatile_reg = wm8580_volatile,
};
#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
static int wm8580_i2c_probe(struct i2c_client *i2c, static int wm8580_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
...@@ -904,8 +965,11 @@ static int wm8580_i2c_probe(struct i2c_client *i2c, ...@@ -904,8 +965,11 @@ static int wm8580_i2c_probe(struct i2c_client *i2c,
if (wm8580 == NULL) if (wm8580 == NULL)
return -ENOMEM; return -ENOMEM;
wm8580->regmap = devm_regmap_init_i2c(i2c, &wm8580_regmap);
if (IS_ERR(wm8580->regmap))
return PTR_ERR(wm8580->regmap);
i2c_set_clientdata(i2c, wm8580); i2c_set_clientdata(i2c, wm8580);
wm8580->control_type = SND_SOC_I2C;
ret = snd_soc_register_codec(&i2c->dev, ret = snd_soc_register_codec(&i2c->dev,
&soc_codec_dev_wm8580, wm8580_dai, ARRAY_SIZE(wm8580_dai)); &soc_codec_dev_wm8580, wm8580_dai, ARRAY_SIZE(wm8580_dai));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment