Commit a065050a authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'asoc/topic/lm4857' into asoc-next

parents 54c1e27d 9b270968
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <sound/core.h> #include <sound/core.h>
...@@ -23,12 +24,15 @@ ...@@ -23,12 +24,15 @@
#include <sound/tlv.h> #include <sound/tlv.h>
struct lm4857 { struct lm4857 {
struct i2c_client *i2c; struct regmap *regmap;
uint8_t mode; uint8_t mode;
}; };
static const uint8_t lm4857_default_regs[] = { static const struct reg_default lm4857_default_regs[] = {
0x00, 0x00, 0x00, 0x00, { 0x0, 0x00 },
{ 0x1, 0x00 },
{ 0x2, 0x00 },
{ 0x3, 0x00 },
}; };
/* The register offsets in the cache array */ /* The register offsets in the cache array */
...@@ -42,39 +46,6 @@ static const uint8_t lm4857_default_regs[] = { ...@@ -42,39 +46,6 @@ static const uint8_t lm4857_default_regs[] = {
#define LM4857_WAKEUP 5 #define LM4857_WAKEUP 5
#define LM4857_EPGAIN 4 #define LM4857_EPGAIN 4
static int lm4857_write(struct snd_soc_codec *codec, unsigned int reg,
unsigned int value)
{
uint8_t data;
int ret;
ret = snd_soc_cache_write(codec, reg, value);
if (ret < 0)
return ret;
data = (reg << 6) | value;
ret = i2c_master_send(codec->control_data, &data, 1);
if (ret != 1) {
dev_err(codec->dev, "Failed to write register: %d\n", ret);
return ret;
}
return 0;
}
static unsigned int lm4857_read(struct snd_soc_codec *codec,
unsigned int reg)
{
unsigned int val;
int ret;
ret = snd_soc_cache_read(codec, reg, &val);
if (ret)
return -1;
return val;
}
static int lm4857_get_mode(struct snd_kcontrol *kcontrol, static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
...@@ -96,7 +67,7 @@ static int lm4857_set_mode(struct snd_kcontrol *kcontrol, ...@@ -96,7 +67,7 @@ static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
lm4857->mode = value; lm4857->mode = value;
if (codec->dapm.bias_level == SND_SOC_BIAS_ON) if (codec->dapm.bias_level == SND_SOC_BIAS_ON)
snd_soc_update_bits(codec, LM4857_CTRL, 0x0F, value + 6); regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F, value + 6);
return 1; return 1;
} }
...@@ -108,10 +79,11 @@ static int lm4857_set_bias_level(struct snd_soc_codec *codec, ...@@ -108,10 +79,11 @@ static int lm4857_set_bias_level(struct snd_soc_codec *codec,
switch (level) { switch (level) {
case SND_SOC_BIAS_ON: case SND_SOC_BIAS_ON:
snd_soc_update_bits(codec, LM4857_CTRL, 0x0F, lm4857->mode + 6); regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F,
lm4857->mode + 6);
break; break;
case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY:
snd_soc_update_bits(codec, LM4857_CTRL, 0x0F, 0); regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F, 0);
break; break;
default: default:
break; break;
...@@ -171,49 +143,32 @@ static const struct snd_soc_dapm_route lm4857_routes[] = { ...@@ -171,49 +143,32 @@ static const struct snd_soc_dapm_route lm4857_routes[] = {
{"EP", NULL, "IN"}, {"EP", NULL, "IN"},
}; };
static int lm4857_probe(struct snd_soc_codec *codec) static struct snd_soc_codec_driver soc_codec_dev_lm4857 = {
{ .set_bias_level = lm4857_set_bias_level,
struct lm4857 *lm4857 = snd_soc_codec_get_drvdata(codec);
struct snd_soc_dapm_context *dapm = &codec->dapm;
int ret;
codec->control_data = lm4857->i2c;
ret = snd_soc_add_codec_controls(codec, lm4857_controls,
ARRAY_SIZE(lm4857_controls));
if (ret)
return ret;
ret = snd_soc_dapm_new_controls(dapm, lm4857_dapm_widgets,
ARRAY_SIZE(lm4857_dapm_widgets));
if (ret)
return ret;
ret = snd_soc_dapm_add_routes(dapm, lm4857_routes, .controls = lm4857_controls,
ARRAY_SIZE(lm4857_routes)); .num_controls = ARRAY_SIZE(lm4857_controls),
if (ret) .dapm_widgets = lm4857_dapm_widgets,
return ret; .num_dapm_widgets = ARRAY_SIZE(lm4857_dapm_widgets),
.dapm_routes = lm4857_routes,
.num_dapm_routes = ARRAY_SIZE(lm4857_routes),
};
snd_soc_dapm_new_widgets(dapm); static const struct regmap_config lm4857_regmap_config = {
.val_bits = 6,
.reg_bits = 2,
return 0; .max_register = LM4857_CTRL,
}
static struct snd_soc_codec_driver soc_codec_dev_lm4857 = { .cache_type = REGCACHE_FLAT,
.write = lm4857_write, .reg_defaults = lm4857_default_regs,
.read = lm4857_read, .num_reg_defaults = ARRAY_SIZE(lm4857_default_regs),
.probe = lm4857_probe,
.reg_cache_size = ARRAY_SIZE(lm4857_default_regs),
.reg_word_size = sizeof(uint8_t),
.reg_cache_default = lm4857_default_regs,
.set_bias_level = lm4857_set_bias_level,
}; };
static int lm4857_i2c_probe(struct i2c_client *i2c, static int lm4857_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct lm4857 *lm4857; struct lm4857 *lm4857;
int ret;
lm4857 = devm_kzalloc(&i2c->dev, sizeof(*lm4857), GFP_KERNEL); lm4857 = devm_kzalloc(&i2c->dev, sizeof(*lm4857), GFP_KERNEL);
if (!lm4857) if (!lm4857)
...@@ -221,11 +176,11 @@ static int lm4857_i2c_probe(struct i2c_client *i2c, ...@@ -221,11 +176,11 @@ static int lm4857_i2c_probe(struct i2c_client *i2c,
i2c_set_clientdata(i2c, lm4857); i2c_set_clientdata(i2c, lm4857);
lm4857->i2c = i2c; lm4857->regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config);
if (IS_ERR(lm4857->regmap))
ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_lm4857, NULL, 0); return PTR_ERR(lm4857->regmap);
return ret; return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_lm4857, NULL, 0);
} }
static int lm4857_i2c_remove(struct i2c_client *i2c) static int lm4857_i2c_remove(struct i2c_client *i2c)
......
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