Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: ad1836: Convert to direct regmap usage.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Lars-Peter Clausen and committed by
Mark Brown
7f22fd9c 040242cc

+53 -23
+53 -23
sound/soc/codecs/ad1836.c
··· 19 19 #include <sound/soc.h> 20 20 #include <sound/tlv.h> 21 21 #include <linux/spi/spi.h> 22 + #include <linux/regmap.h> 23 + 22 24 #include "ad1836.h" 23 25 24 26 enum ad1836_type { ··· 32 30 /* codec private data */ 33 31 struct ad1836_priv { 34 32 enum ad1836_type type; 33 + struct regmap *regmap; 35 34 }; 36 35 37 36 /* ··· 164 161 struct snd_pcm_hw_params *params, 165 162 struct snd_soc_dai *dai) 166 163 { 164 + struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(dai->codec); 167 165 int word_len = 0; 168 - struct snd_soc_codec *codec = dai->codec; 169 166 170 167 /* bit size */ 171 168 switch (params_format(params)) { ··· 181 178 break; 182 179 } 183 180 184 - snd_soc_update_bits(codec, AD1836_DAC_CTRL1, AD1836_DAC_WORD_LEN_MASK, 181 + regmap_update_bits(ad1836->regmap, AD1836_DAC_CTRL1, 182 + AD1836_DAC_WORD_LEN_MASK, 185 183 word_len << AD1836_DAC_WORD_LEN_OFFSET); 186 184 187 - snd_soc_update_bits(codec, AD1836_ADC_CTRL2, AD1836_ADC_WORD_LEN_MASK, 185 + regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, 186 + AD1836_ADC_WORD_LEN_MASK, 188 187 word_len << AD1836_ADC_WORD_OFFSET); 189 188 190 189 return 0; ··· 228 223 #ifdef CONFIG_PM 229 224 static int ad1836_suspend(struct snd_soc_codec *codec) 230 225 { 226 + struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); 231 227 /* reset clock control mode */ 232 - return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, 228 + return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, 233 229 AD1836_ADC_SERFMT_MASK, 0); 234 230 } 235 231 236 232 static int ad1836_resume(struct snd_soc_codec *codec) 237 233 { 234 + struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); 238 235 /* restore clock control mode */ 239 - return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, 236 + return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, 240 237 AD1836_ADC_SERFMT_MASK, AD1836_ADC_AUX); 241 238 } 242 239 #else ··· 257 250 num_dacs = ad183x_dais[ad1836->type].playback.channels_max / 2; 258 251 num_adcs = ad183x_dais[ad1836->type].capture.channels_max / 2; 259 252 260 - ret = snd_soc_codec_set_cache_io(codec, 4, 12, SND_SOC_SPI); 261 - if (ret < 0) { 262 - dev_err(codec->dev, "failed to set cache I/O: %d\n", 263 - ret); 264 - return ret; 265 - } 266 - 267 253 /* default setting for ad1836 */ 268 254 /* de-emphasis: 48kHz, power-on dac */ 269 - snd_soc_write(codec, AD1836_DAC_CTRL1, 0x300); 255 + regmap_write(ad1836->regmap, AD1836_DAC_CTRL1, 0x300); 270 256 /* unmute dac channels */ 271 - snd_soc_write(codec, AD1836_DAC_CTRL2, 0x0); 257 + regmap_write(ad1836->regmap, AD1836_DAC_CTRL2, 0x0); 272 258 /* high-pass filter enable, power-on adc */ 273 - snd_soc_write(codec, AD1836_ADC_CTRL1, 0x100); 259 + regmap_write(ad1836->regmap, AD1836_ADC_CTRL1, 0x100); 274 260 /* unmute adc channles, adc aux mode */ 275 - snd_soc_write(codec, AD1836_ADC_CTRL2, 0x180); 261 + regmap_write(ad1836->regmap, AD1836_ADC_CTRL2, 0x180); 276 262 /* volume */ 277 263 for (i = 1; i <= num_dacs; ++i) { 278 - snd_soc_write(codec, AD1836_DAC_L_VOL(i), 0x3FF); 279 - snd_soc_write(codec, AD1836_DAC_R_VOL(i), 0x3FF); 264 + regmap_write(ad1836->regmap, AD1836_DAC_L_VOL(i), 0x3FF); 265 + regmap_write(ad1836->regmap, AD1836_DAC_R_VOL(i), 0x3FF); 280 266 } 281 267 282 268 if (ad1836->type == AD1836) { 283 269 /* left/right diff:PGA/MUX */ 284 - snd_soc_write(codec, AD1836_ADC_CTRL3, 0x3A); 270 + regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x3A); 285 271 ret = snd_soc_add_codec_controls(codec, ad1836_controls, 286 272 ARRAY_SIZE(ad1836_controls)); 287 273 if (ret) 288 274 return ret; 289 275 } else { 290 - snd_soc_write(codec, AD1836_ADC_CTRL3, 0x00); 276 + regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x00); 291 277 } 292 278 293 279 ret = snd_soc_add_codec_controls(codec, ad183x_dac_controls, num_dacs * 2); ··· 313 313 /* power down chip */ 314 314 static int ad1836_remove(struct snd_soc_codec *codec) 315 315 { 316 + struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec); 316 317 /* reset clock control mode */ 317 - return snd_soc_update_bits(codec, AD1836_ADC_CTRL2, 318 + return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2, 318 319 AD1836_ADC_SERFMT_MASK, 0); 319 320 } 320 321 ··· 324 323 .remove = ad1836_remove, 325 324 .suspend = ad1836_suspend, 326 325 .resume = ad1836_resume, 327 - .reg_cache_size = AD1836_NUM_REGS, 328 - .reg_word_size = sizeof(u16), 329 326 330 327 .controls = ad183x_controls, 331 328 .num_controls = ARRAY_SIZE(ad183x_controls), ··· 331 332 .num_dapm_widgets = ARRAY_SIZE(ad183x_dapm_widgets), 332 333 .dapm_routes = ad183x_dapm_routes, 333 334 .num_dapm_routes = ARRAY_SIZE(ad183x_dapm_routes), 335 + }; 336 + 337 + static const struct reg_default ad1836_reg_defaults[] = { 338 + { AD1836_DAC_CTRL1, 0x0000 }, 339 + { AD1836_DAC_CTRL2, 0x0000 }, 340 + { AD1836_DAC_L_VOL(0), 0x0000 }, 341 + { AD1836_DAC_R_VOL(0), 0x0000 }, 342 + { AD1836_DAC_L_VOL(1), 0x0000 }, 343 + { AD1836_DAC_R_VOL(1), 0x0000 }, 344 + { AD1836_DAC_L_VOL(2), 0x0000 }, 345 + { AD1836_DAC_R_VOL(2), 0x0000 }, 346 + { AD1836_DAC_L_VOL(3), 0x0000 }, 347 + { AD1836_DAC_R_VOL(3), 0x0000 }, 348 + { AD1836_ADC_CTRL1, 0x0000 }, 349 + { AD1836_ADC_CTRL2, 0x0000 }, 350 + { AD1836_ADC_CTRL3, 0x0000 }, 351 + }; 352 + 353 + static const struct regmap_config ad1836_regmap_config = { 354 + .val_bits = 12, 355 + .reg_bits = 4, 356 + .read_flag_mask = 0x08, 357 + 358 + .max_register = AD1836_ADC_CTRL3, 359 + .reg_defaults = ad1836_reg_defaults, 360 + .num_reg_defaults = ARRAY_SIZE(ad1836_reg_defaults), 361 + .cache_type = REGCACHE_RBTREE, 334 362 }; 335 363 336 364 static int __devinit ad1836_spi_probe(struct spi_device *spi) ··· 369 343 GFP_KERNEL); 370 344 if (ad1836 == NULL) 371 345 return -ENOMEM; 346 + 347 + ad1836->regmap = devm_regmap_init_spi(spi, &ad1836_regmap_config); 348 + if (IS_ERR(ad1836->regmap)) 349 + return PTR_ERR(ad1836->regmap); 372 350 373 351 ad1836->type = spi_get_device_id(spi)->driver_data; 374 352