diff options
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/ak4535.c | 100 |
1 files changed, 18 insertions, 82 deletions
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c index e1a214ee757f..68df32dd9f69 100644 --- a/sound/soc/codecs/ak4535.c +++ b/sound/soc/codecs/ak4535.c | |||
@@ -34,7 +34,6 @@ | |||
34 | struct ak4535_priv { | 34 | struct ak4535_priv { |
35 | unsigned int sysclk; | 35 | unsigned int sysclk; |
36 | enum snd_soc_control_type control_type; | 36 | enum snd_soc_control_type control_type; |
37 | void *control_data; | ||
38 | }; | 37 | }; |
39 | 38 | ||
40 | /* | 39 | /* |
@@ -47,63 +46,6 @@ static const u16 ak4535_reg[AK4535_CACHEREGNUM] = { | |||
47 | 0x0000, 0x0000, 0x0057, 0x0000, | 46 | 0x0000, 0x0000, 0x0057, 0x0000, |
48 | }; | 47 | }; |
49 | 48 | ||
50 | /* | ||
51 | * read ak4535 register cache | ||
52 | */ | ||
53 | static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec, | ||
54 | unsigned int reg) | ||
55 | { | ||
56 | u16 *cache = codec->reg_cache; | ||
57 | if (reg >= AK4535_CACHEREGNUM) | ||
58 | return -1; | ||
59 | return cache[reg]; | ||
60 | } | ||
61 | |||
62 | /* | ||
63 | * write ak4535 register cache | ||
64 | */ | ||
65 | static inline void ak4535_write_reg_cache(struct snd_soc_codec *codec, | ||
66 | u16 reg, unsigned int value) | ||
67 | { | ||
68 | u16 *cache = codec->reg_cache; | ||
69 | if (reg >= AK4535_CACHEREGNUM) | ||
70 | return; | ||
71 | cache[reg] = value; | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * write to the AK4535 register space | ||
76 | */ | ||
77 | static int ak4535_write(struct snd_soc_codec *codec, unsigned int reg, | ||
78 | unsigned int value) | ||
79 | { | ||
80 | u8 data[2]; | ||
81 | |||
82 | /* data is | ||
83 | * D15..D8 AK4535 register offset | ||
84 | * D7...D0 register data | ||
85 | */ | ||
86 | data[0] = reg & 0xff; | ||
87 | data[1] = value & 0xff; | ||
88 | |||
89 | ak4535_write_reg_cache(codec, reg, value); | ||
90 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
91 | return 0; | ||
92 | else | ||
93 | return -EIO; | ||
94 | } | ||
95 | |||
96 | static int ak4535_sync(struct snd_soc_codec *codec) | ||
97 | { | ||
98 | u16 *cache = codec->reg_cache; | ||
99 | int i, r = 0; | ||
100 | |||
101 | for (i = 0; i < AK4535_CACHEREGNUM; i++) | ||
102 | r |= ak4535_write(codec, i, cache[i]); | ||
103 | |||
104 | return r; | ||
105 | }; | ||
106 | |||
107 | static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"}; | 49 | static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"}; |
108 | static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"}; | 50 | static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"}; |
109 | static const char *ak4535_hp_out[] = {"Stereo", "Mono"}; | 51 | static const char *ak4535_hp_out[] = {"Stereo", "Mono"}; |
@@ -304,7 +246,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream, | |||
304 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 246 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
305 | struct snd_soc_codec *codec = rtd->codec; | 247 | struct snd_soc_codec *codec = rtd->codec; |
306 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); | 248 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
307 | u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5); | 249 | u8 mode2 = snd_soc_read(codec, AK4535_MODE2) & ~(0x3 << 5); |
308 | int rate = params_rate(params), fs = 256; | 250 | int rate = params_rate(params), fs = 256; |
309 | 251 | ||
310 | if (rate) | 252 | if (rate) |
@@ -323,7 +265,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream, | |||
323 | } | 265 | } |
324 | 266 | ||
325 | /* set rate */ | 267 | /* set rate */ |
326 | ak4535_write(codec, AK4535_MODE2, mode2); | 268 | snd_soc_write(codec, AK4535_MODE2, mode2); |
327 | return 0; | 269 | return 0; |
328 | } | 270 | } |
329 | 271 | ||
@@ -348,44 +290,37 @@ static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai, | |||
348 | /* use 32 fs for BCLK to save power */ | 290 | /* use 32 fs for BCLK to save power */ |
349 | mode1 |= 0x4; | 291 | mode1 |= 0x4; |
350 | 292 | ||
351 | ak4535_write(codec, AK4535_MODE1, mode1); | 293 | snd_soc_write(codec, AK4535_MODE1, mode1); |
352 | return 0; | 294 | return 0; |
353 | } | 295 | } |
354 | 296 | ||
355 | static int ak4535_mute(struct snd_soc_dai *dai, int mute) | 297 | static int ak4535_mute(struct snd_soc_dai *dai, int mute) |
356 | { | 298 | { |
357 | struct snd_soc_codec *codec = dai->codec; | 299 | struct snd_soc_codec *codec = dai->codec; |
358 | u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC); | 300 | u16 mute_reg = snd_soc_read(codec, AK4535_DAC); |
359 | if (!mute) | 301 | if (!mute) |
360 | ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20); | 302 | snd_soc_write(codec, AK4535_DAC, mute_reg & ~0x20); |
361 | else | 303 | else |
362 | ak4535_write(codec, AK4535_DAC, mute_reg | 0x20); | 304 | snd_soc_write(codec, AK4535_DAC, mute_reg | 0x20); |
363 | return 0; | 305 | return 0; |
364 | } | 306 | } |
365 | 307 | ||
366 | static int ak4535_set_bias_level(struct snd_soc_codec *codec, | 308 | static int ak4535_set_bias_level(struct snd_soc_codec *codec, |
367 | enum snd_soc_bias_level level) | 309 | enum snd_soc_bias_level level) |
368 | { | 310 | { |
369 | u16 i, mute_reg; | ||
370 | |||
371 | switch (level) { | 311 | switch (level) { |
372 | case SND_SOC_BIAS_ON: | 312 | case SND_SOC_BIAS_ON: |
373 | mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC); | 313 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0); |
374 | ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20); | ||
375 | break; | 314 | break; |
376 | case SND_SOC_BIAS_PREPARE: | 315 | case SND_SOC_BIAS_PREPARE: |
377 | mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC); | 316 | snd_soc_update_bits(codec, AK4535_DAC, 0x20, 0x20); |
378 | ak4535_write(codec, AK4535_DAC, mute_reg | 0x20); | ||
379 | break; | 317 | break; |
380 | case SND_SOC_BIAS_STANDBY: | 318 | case SND_SOC_BIAS_STANDBY: |
381 | i = ak4535_read_reg_cache(codec, AK4535_PM1); | 319 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0x80); |
382 | ak4535_write(codec, AK4535_PM1, i | 0x80); | 320 | snd_soc_update_bits(codec, AK4535_PM2, 0x80, 0); |
383 | i = ak4535_read_reg_cache(codec, AK4535_PM2); | ||
384 | ak4535_write(codec, AK4535_PM2, i & (~0x80)); | ||
385 | break; | 321 | break; |
386 | case SND_SOC_BIAS_OFF: | 322 | case SND_SOC_BIAS_OFF: |
387 | i = ak4535_read_reg_cache(codec, AK4535_PM1); | 323 | snd_soc_update_bits(codec, AK4535_PM1, 0x80, 0); |
388 | ak4535_write(codec, AK4535_PM1, i & (~0x80)); | ||
389 | break; | 324 | break; |
390 | } | 325 | } |
391 | codec->dapm.bias_level = level; | 326 | codec->dapm.bias_level = level; |
@@ -428,7 +363,7 @@ static int ak4535_suspend(struct snd_soc_codec *codec, pm_message_t state) | |||
428 | 363 | ||
429 | static int ak4535_resume(struct snd_soc_codec *codec) | 364 | static int ak4535_resume(struct snd_soc_codec *codec) |
430 | { | 365 | { |
431 | ak4535_sync(codec); | 366 | snd_soc_cache_sync(codec); |
432 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 367 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
433 | return 0; | 368 | return 0; |
434 | } | 369 | } |
@@ -436,11 +371,15 @@ static int ak4535_resume(struct snd_soc_codec *codec) | |||
436 | static int ak4535_probe(struct snd_soc_codec *codec) | 371 | static int ak4535_probe(struct snd_soc_codec *codec) |
437 | { | 372 | { |
438 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); | 373 | struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec); |
374 | int ret; | ||
439 | 375 | ||
440 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); | 376 | printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION); |
441 | 377 | ||
442 | codec->control_data = ak4535->control_data; | 378 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, ak4535->control_type); |
443 | 379 | if (ret < 0) { | |
380 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | ||
381 | return ret; | ||
382 | } | ||
444 | /* power on device */ | 383 | /* power on device */ |
445 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); | 384 | ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
446 | 385 | ||
@@ -461,8 +400,6 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4535 = { | |||
461 | .remove = ak4535_remove, | 400 | .remove = ak4535_remove, |
462 | .suspend = ak4535_suspend, | 401 | .suspend = ak4535_suspend, |
463 | .resume = ak4535_resume, | 402 | .resume = ak4535_resume, |
464 | .read = ak4535_read_reg_cache, | ||
465 | .write = ak4535_write, | ||
466 | .set_bias_level = ak4535_set_bias_level, | 403 | .set_bias_level = ak4535_set_bias_level, |
467 | .reg_cache_size = ARRAY_SIZE(ak4535_reg), | 404 | .reg_cache_size = ARRAY_SIZE(ak4535_reg), |
468 | .reg_word_size = sizeof(u8), | 405 | .reg_word_size = sizeof(u8), |
@@ -485,7 +422,6 @@ static __devinit int ak4535_i2c_probe(struct i2c_client *i2c, | |||
485 | return -ENOMEM; | 422 | return -ENOMEM; |
486 | 423 | ||
487 | i2c_set_clientdata(i2c, ak4535); | 424 | i2c_set_clientdata(i2c, ak4535); |
488 | ak4535->control_data = i2c; | ||
489 | ak4535->control_type = SND_SOC_I2C; | 425 | ak4535->control_type = SND_SOC_I2C; |
490 | 426 | ||
491 | ret = snd_soc_register_codec(&i2c->dev, | 427 | ret = snd_soc_register_codec(&i2c->dev, |