diff options
| -rw-r--r-- | sound/soc/codecs/tlv320aic32x4.c | 89 |
1 files changed, 23 insertions, 66 deletions
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c index cf70bf86c344..18cdcca9014c 100644 --- a/sound/soc/codecs/tlv320aic32x4.c +++ b/sound/soc/codecs/tlv320aic32x4.c | |||
| @@ -60,9 +60,8 @@ struct aic32x4_rate_divs { | |||
| 60 | }; | 60 | }; |
| 61 | 61 | ||
| 62 | struct aic32x4_priv { | 62 | struct aic32x4_priv { |
| 63 | struct regmap *regmap; | ||
| 63 | u32 sysclk; | 64 | u32 sysclk; |
| 64 | u8 page_no; | ||
| 65 | void *control_data; | ||
| 66 | u32 power_cfg; | 65 | u32 power_cfg; |
| 67 | u32 micpga_routing; | 66 | u32 micpga_routing; |
| 68 | bool swapdacs; | 67 | bool swapdacs; |
| @@ -262,67 +261,25 @@ static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = { | |||
| 262 | {"Right ADC", NULL, "Right Input Mixer"}, | 261 | {"Right ADC", NULL, "Right Input Mixer"}, |
| 263 | }; | 262 | }; |
| 264 | 263 | ||
| 265 | static inline int aic32x4_change_page(struct snd_soc_codec *codec, | 264 | static const struct regmap_range_cfg aic32x4_regmap_pages[] = { |
| 266 | unsigned int new_page) | 265 | { |
| 267 | { | 266 | .selector_reg = 0, |
| 268 | struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); | 267 | .selector_mask = 0xff, |
| 269 | u8 data[2]; | 268 | .window_start = 0, |
| 270 | int ret; | 269 | .window_len = 128, |
| 271 | 270 | .range_min = AIC32X4_PAGE1, | |
| 272 | data[0] = 0x00; | 271 | .range_max = AIC32X4_PAGE1 + 127, |
| 273 | data[1] = new_page & 0xff; | 272 | }, |
| 274 | 273 | }; | |
| 275 | ret = codec->hw_write(codec->control_data, data, 2); | ||
| 276 | if (ret == 2) { | ||
| 277 | aic32x4->page_no = new_page; | ||
| 278 | return 0; | ||
| 279 | } else { | ||
| 280 | return ret; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | static int aic32x4_write(struct snd_soc_codec *codec, unsigned int reg, | ||
| 285 | unsigned int val) | ||
| 286 | { | ||
| 287 | struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); | ||
| 288 | unsigned int page = reg / 128; | ||
| 289 | unsigned int fixed_reg = reg % 128; | ||
| 290 | u8 data[2]; | ||
| 291 | int ret; | ||
| 292 | |||
| 293 | /* A write to AIC32X4_PSEL is really a non-explicit page change */ | ||
| 294 | if (reg == AIC32X4_PSEL) | ||
| 295 | return aic32x4_change_page(codec, val); | ||
| 296 | |||
| 297 | if (aic32x4->page_no != page) { | ||
| 298 | ret = aic32x4_change_page(codec, page); | ||
| 299 | if (ret != 0) | ||
| 300 | return ret; | ||
| 301 | } | ||
| 302 | 274 | ||
| 303 | data[0] = fixed_reg & 0xff; | 275 | static const struct regmap_config aic32x4_regmap = { |
| 304 | data[1] = val & 0xff; | 276 | .reg_bits = 8, |
| 277 | .val_bits = 8, | ||
| 305 | 278 | ||
| 306 | if (codec->hw_write(codec->control_data, data, 2) == 2) | 279 | .max_register = AIC32X4_RMICPGAVOL, |
| 307 | return 0; | 280 | .ranges = aic32x4_regmap_pages, |
| 308 | else | 281 | .num_ranges = ARRAY_SIZE(aic32x4_regmap_pages), |
| 309 | return -EIO; | 282 | }; |
| 310 | } | ||
| 311 | |||
| 312 | static unsigned int aic32x4_read(struct snd_soc_codec *codec, unsigned int reg) | ||
| 313 | { | ||
| 314 | struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); | ||
| 315 | unsigned int page = reg / 128; | ||
| 316 | unsigned int fixed_reg = reg % 128; | ||
| 317 | int ret; | ||
| 318 | |||
| 319 | if (aic32x4->page_no != page) { | ||
| 320 | ret = aic32x4_change_page(codec, page); | ||
| 321 | if (ret != 0) | ||
| 322 | return ret; | ||
| 323 | } | ||
| 324 | return i2c_smbus_read_byte_data(codec->control_data, fixed_reg & 0xff); | ||
| 325 | } | ||
| 326 | 283 | ||
| 327 | static inline int aic32x4_get_divs(int mclk, int rate) | 284 | static inline int aic32x4_get_divs(int mclk, int rate) |
| 328 | { | 285 | { |
| @@ -618,8 +575,7 @@ static int aic32x4_probe(struct snd_soc_codec *codec) | |||
| 618 | struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); | 575 | struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec); |
| 619 | u32 tmp_reg; | 576 | u32 tmp_reg; |
| 620 | 577 | ||
| 621 | codec->hw_write = (hw_write_t) i2c_master_send; | 578 | snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); |
| 622 | codec->control_data = aic32x4->control_data; | ||
| 623 | 579 | ||
| 624 | if (aic32x4->rstn_gpio >= 0) { | 580 | if (aic32x4->rstn_gpio >= 0) { |
| 625 | ndelay(10); | 581 | ndelay(10); |
| @@ -687,8 +643,6 @@ static int aic32x4_remove(struct snd_soc_codec *codec) | |||
| 687 | } | 643 | } |
| 688 | 644 | ||
| 689 | static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = { | 645 | static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = { |
| 690 | .read = aic32x4_read, | ||
| 691 | .write = aic32x4_write, | ||
| 692 | .probe = aic32x4_probe, | 646 | .probe = aic32x4_probe, |
| 693 | .remove = aic32x4_remove, | 647 | .remove = aic32x4_remove, |
| 694 | .suspend = aic32x4_suspend, | 648 | .suspend = aic32x4_suspend, |
| @@ -715,7 +669,10 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c, | |||
| 715 | if (aic32x4 == NULL) | 669 | if (aic32x4 == NULL) |
| 716 | return -ENOMEM; | 670 | return -ENOMEM; |
| 717 | 671 | ||
| 718 | aic32x4->control_data = i2c; | 672 | aic32x4->regmap = devm_regmap_init_i2c(i2c, &aic32x4_regmap); |
| 673 | if (IS_ERR(aic32x4->regmap)) | ||
| 674 | return PTR_ERR(aic32x4->regmap); | ||
| 675 | |||
| 719 | i2c_set_clientdata(i2c, aic32x4); | 676 | i2c_set_clientdata(i2c, aic32x4); |
| 720 | 677 | ||
| 721 | if (pdata) { | 678 | if (pdata) { |
