Loading sound/soc/codecs/max9850.c +29 −10 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <linux/module.h> #include <linux/module.h> #include <linux/init.h> #include <linux/init.h> #include <linux/i2c.h> #include <linux/i2c.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/slab.h> #include <sound/pcm.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/pcm_params.h> Loading @@ -27,18 +28,26 @@ #include "max9850.h" #include "max9850.h" struct max9850_priv { struct max9850_priv { struct regmap *regmap; unsigned int sysclk; unsigned int sysclk; }; }; /* max9850 register cache */ /* max9850 register cache */ static const u8 max9850_reg[MAX9850_CACHEREGNUM] = { static const struct reg_default max9850_reg[] = { 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 { 2, 0x0c }, { 3, 0x00 }, { 4, 0x00 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 }, { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, }; }; /* these registers are not used at the moment but provided for the sake of /* these registers are not used at the moment but provided for the sake of * completeness */ * completeness */ static int max9850_volatile_register(struct snd_soc_codec *codec, static bool max9850_volatile_register(struct device *dev, unsigned int reg) unsigned int reg) { { switch (reg) { switch (reg) { case MAX9850_STATUSA: case MAX9850_STATUSA: Loading @@ -49,6 +58,15 @@ static int max9850_volatile_register(struct snd_soc_codec *codec, } } } } static const struct regmap_config max9850_regmap = { .reg_bits = 8, .val_bits = 8, .max_register = MAX9850_DIGITAL_AUDIO, .volatile_reg = max9850_volatile_register, .cache_type = REGCACHE_RBTREE, }; static const unsigned int max9850_tlv[] = { static const unsigned int max9850_tlv[] = { TLV_DB_RANGE_HEAD(4), TLV_DB_RANGE_HEAD(4), 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), Loading Loading @@ -225,6 +243,7 @@ static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) static int max9850_set_bias_level(struct snd_soc_codec *codec, static int max9850_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) enum snd_soc_bias_level level) { { struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); int ret; int ret; switch (level) { switch (level) { Loading @@ -234,7 +253,7 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec, break; break; case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY: if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { ret = snd_soc_cache_sync(codec); ret = regcache_sync(max9850->regmap); if (ret) { if (ret) { dev_err(codec->dev, dev_err(codec->dev, "Failed to sync cache: %d\n", ret); "Failed to sync cache: %d\n", ret); Loading Loading @@ -295,7 +314,7 @@ static int max9850_probe(struct snd_soc_codec *codec) { { int ret; int ret; ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); ret = snd_soc_codec_set_cache_io(codec, 8, 8, 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; Loading @@ -316,10 +335,6 @@ static struct snd_soc_codec_driver soc_codec_dev_max9850 = { .suspend = max9850_suspend, .suspend = max9850_suspend, .resume = max9850_resume, .resume = max9850_resume, .set_bias_level = max9850_set_bias_level, .set_bias_level = max9850_set_bias_level, .reg_cache_size = ARRAY_SIZE(max9850_reg), .reg_word_size = sizeof(u8), .reg_cache_default = max9850_reg, .volatile_register = max9850_volatile_register, .controls = max9850_controls, .controls = max9850_controls, .num_controls = ARRAY_SIZE(max9850_controls), .num_controls = ARRAY_SIZE(max9850_controls), Loading @@ -340,6 +355,10 @@ static int max9850_i2c_probe(struct i2c_client *i2c, if (max9850 == NULL) if (max9850 == NULL) return -ENOMEM; return -ENOMEM; max9850->regmap = devm_regmap_init_i2c(i2c, &max9850_regmap); if (IS_ERR(max9850->regmap)) return PTR_ERR(max9850->regmap); i2c_set_clientdata(i2c, max9850); i2c_set_clientdata(i2c, max9850); ret = snd_soc_register_codec(&i2c->dev, ret = snd_soc_register_codec(&i2c->dev, Loading Loading
sound/soc/codecs/max9850.c +29 −10 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <linux/module.h> #include <linux/module.h> #include <linux/init.h> #include <linux/init.h> #include <linux/i2c.h> #include <linux/i2c.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/slab.h> #include <sound/pcm.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/pcm_params.h> Loading @@ -27,18 +28,26 @@ #include "max9850.h" #include "max9850.h" struct max9850_priv { struct max9850_priv { struct regmap *regmap; unsigned int sysclk; unsigned int sysclk; }; }; /* max9850 register cache */ /* max9850 register cache */ static const u8 max9850_reg[MAX9850_CACHEREGNUM] = { static const struct reg_default max9850_reg[] = { 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 { 2, 0x0c }, { 3, 0x00 }, { 4, 0x00 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 }, { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, }; }; /* these registers are not used at the moment but provided for the sake of /* these registers are not used at the moment but provided for the sake of * completeness */ * completeness */ static int max9850_volatile_register(struct snd_soc_codec *codec, static bool max9850_volatile_register(struct device *dev, unsigned int reg) unsigned int reg) { { switch (reg) { switch (reg) { case MAX9850_STATUSA: case MAX9850_STATUSA: Loading @@ -49,6 +58,15 @@ static int max9850_volatile_register(struct snd_soc_codec *codec, } } } } static const struct regmap_config max9850_regmap = { .reg_bits = 8, .val_bits = 8, .max_register = MAX9850_DIGITAL_AUDIO, .volatile_reg = max9850_volatile_register, .cache_type = REGCACHE_RBTREE, }; static const unsigned int max9850_tlv[] = { static const unsigned int max9850_tlv[] = { TLV_DB_RANGE_HEAD(4), TLV_DB_RANGE_HEAD(4), 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), Loading Loading @@ -225,6 +243,7 @@ static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) static int max9850_set_bias_level(struct snd_soc_codec *codec, static int max9850_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) enum snd_soc_bias_level level) { { struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); int ret; int ret; switch (level) { switch (level) { Loading @@ -234,7 +253,7 @@ static int max9850_set_bias_level(struct snd_soc_codec *codec, break; break; case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY: if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { ret = snd_soc_cache_sync(codec); ret = regcache_sync(max9850->regmap); if (ret) { if (ret) { dev_err(codec->dev, dev_err(codec->dev, "Failed to sync cache: %d\n", ret); "Failed to sync cache: %d\n", ret); Loading Loading @@ -295,7 +314,7 @@ static int max9850_probe(struct snd_soc_codec *codec) { { int ret; int ret; ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C); ret = snd_soc_codec_set_cache_io(codec, 8, 8, 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; Loading @@ -316,10 +335,6 @@ static struct snd_soc_codec_driver soc_codec_dev_max9850 = { .suspend = max9850_suspend, .suspend = max9850_suspend, .resume = max9850_resume, .resume = max9850_resume, .set_bias_level = max9850_set_bias_level, .set_bias_level = max9850_set_bias_level, .reg_cache_size = ARRAY_SIZE(max9850_reg), .reg_word_size = sizeof(u8), .reg_cache_default = max9850_reg, .volatile_register = max9850_volatile_register, .controls = max9850_controls, .controls = max9850_controls, .num_controls = ARRAY_SIZE(max9850_controls), .num_controls = ARRAY_SIZE(max9850_controls), Loading @@ -340,6 +355,10 @@ static int max9850_i2c_probe(struct i2c_client *i2c, if (max9850 == NULL) if (max9850 == NULL) return -ENOMEM; return -ENOMEM; max9850->regmap = devm_regmap_init_i2c(i2c, &max9850_regmap); if (IS_ERR(max9850->regmap)) return PTR_ERR(max9850->regmap); i2c_set_clientdata(i2c, max9850); i2c_set_clientdata(i2c, max9850); ret = snd_soc_register_codec(&i2c->dev, ret = snd_soc_register_codec(&i2c->dev, Loading