aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2011-10-11 19:16:25 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-10-12 06:25:59 -0400
commit40a49710107c237a2f4362c8b8bf07df3bac53dd (patch)
treed93d97390fadf5e2672da09dcf54d993d59d31f3
parent48df93d4c73b95c3936beab4c69d4c522a29dca3 (diff)
ASoC: da7210: convert to soc-cache
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--sound/soc/codecs/da7210.c123
1 files changed, 45 insertions, 78 deletions
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index 92fd9d7a9221..a9d9d39cfea9 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -161,7 +161,6 @@ static const struct snd_kcontrol_new da7210_snd_controls[] = {
161/* Codec private data */ 161/* Codec private data */
162struct da7210_priv { 162struct da7210_priv {
163 enum snd_soc_control_type control_type; 163 enum snd_soc_control_type control_type;
164 void *control_data;
165}; 164};
166 165
167/* 166/*
@@ -188,50 +187,16 @@ static const u8 da7210_reg[] = {
188 0x00, /* R88 */ 187 0x00, /* R88 */
189}; 188};
190 189
191/* 190static int da7210_volatile_register(struct snd_soc_codec *codec,
192 * Read da7210 register cache 191 unsigned int reg)
193 */
194static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
195{
196 u8 *cache = codec->reg_cache;
197 BUG_ON(reg >= ARRAY_SIZE(da7210_reg));
198 return cache[reg];
199}
200
201/*
202 * Write to the da7210 register space
203 */
204static int da7210_write(struct snd_soc_codec *codec, u32 reg, u32 value)
205{
206 u8 *cache = codec->reg_cache;
207 u8 data[2];
208
209 BUG_ON(codec->driver->volatile_register);
210
211 data[0] = reg & 0xff;
212 data[1] = value & 0xff;
213
214 if (reg >= codec->driver->reg_cache_size)
215 return -EIO;
216
217 if (2 != codec->hw_write(codec->control_data, data, 2))
218 return -EIO;
219
220 cache[reg] = value;
221 return 0;
222}
223
224/*
225 * Read from the da7210 register space.
226 */
227static inline u32 da7210_read(struct snd_soc_codec *codec, u32 reg)
228{ 192{
229 if (DA7210_STATUS == reg) 193 switch (reg) {
230 return i2c_smbus_read_byte_data(codec->control_data, reg); 194 case DA7210_STATUS:
231 195 return 1;
232 return da7210_read_reg_cache(codec, reg); 196 default:
197 return 0;
198 }
233} 199}
234
235static int da7210_startup(struct snd_pcm_substream *substream, 200static int da7210_startup(struct snd_pcm_substream *substream,
236 struct snd_soc_dai *dai) 201 struct snd_soc_dai *dai)
237{ 202{
@@ -270,13 +235,13 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
270 u32 fs, bypass; 235 u32 fs, bypass;
271 236
272 /* set DAI source to Left and Right ADC */ 237 /* set DAI source to Left and Right ADC */
273 da7210_write(codec, DA7210_DAI_SRC_SEL, 238 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
274 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); 239 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
275 240
276 /* Enable DAI */ 241 /* Enable DAI */
277 da7210_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); 242 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
278 243
279 dai_cfg1 = 0xFC & da7210_read(codec, DA7210_DAI_CFG1); 244 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
280 245
281 switch (params_format(params)) { 246 switch (params_format(params)) {
282 case SNDRV_PCM_FORMAT_S16_LE: 247 case SNDRV_PCM_FORMAT_S16_LE:
@@ -289,7 +254,7 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
289 return -EINVAL; 254 return -EINVAL;
290 } 255 }
291 256
292 da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1); 257 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
293 258
294 hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ? 259 hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
295 DA7210_DAC_HPF : DA7210_ADC_HPF; 260 DA7210_DAC_HPF : DA7210_ADC_HPF;
@@ -382,8 +347,8 @@ static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
382 u32 dai_cfg1; 347 u32 dai_cfg1;
383 u32 dai_cfg3; 348 u32 dai_cfg3;
384 349
385 dai_cfg1 = 0x7f & da7210_read(codec, DA7210_DAI_CFG1); 350 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
386 dai_cfg3 = 0xfc & da7210_read(codec, DA7210_DAI_CFG3); 351 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
387 352
388 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 353 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
389 case SND_SOC_DAIFMT_CBM_CFM: 354 case SND_SOC_DAIFMT_CBM_CFM:
@@ -411,8 +376,8 @@ static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
411 */ 376 */
412 dai_cfg1 |= DA7210_DAI_FLEN_64BIT; 377 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
413 378
414 da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1); 379 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
415 da7210_write(codec, DA7210_DAI_CFG3, dai_cfg3); 380 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
416 381
417 return 0; 382 return 0;
418} 383}
@@ -451,11 +416,15 @@ static struct snd_soc_dai_driver da7210_dai = {
451static int da7210_probe(struct snd_soc_codec *codec) 416static int da7210_probe(struct snd_soc_codec *codec)
452{ 417{
453 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); 418 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
419 int ret;
454 420
455 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); 421 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
456 422
457 codec->control_data = da7210->control_data; 423 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
458 codec->hw_write = (hw_write_t)i2c_master_send; 424 if (ret < 0) {
425 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
426 return ret;
427 }
459 428
460 /* FIXME 429 /* FIXME
461 * 430 *
@@ -472,8 +441,8 @@ static int da7210_probe(struct snd_soc_codec *codec)
472 /* 441 /*
473 * make sure that DA7210 use bypass mode before start up 442 * make sure that DA7210 use bypass mode before start up
474 */ 443 */
475 da7210_write(codec, DA7210_STARTUP1, 0); 444 snd_soc_write(codec, DA7210_STARTUP1, 0);
476 da7210_write(codec, DA7210_PLL_DIV3, 445 snd_soc_write(codec, DA7210_PLL_DIV3,
477 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); 446 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
478 447
479 /* 448 /*
@@ -481,36 +450,36 @@ static int da7210_probe(struct snd_soc_codec *codec)
481 */ 450 */
482 451
483 /* Enable Left & Right MIC PGA and Mic Bias */ 452 /* Enable Left & Right MIC PGA and Mic Bias */
484 da7210_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); 453 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
485 da7210_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); 454 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
486 455
487 /* Enable Left and Right input PGA */ 456 /* Enable Left and Right input PGA */
488 da7210_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); 457 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
489 da7210_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); 458 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
490 459
491 /* Enable Left and Right ADC */ 460 /* Enable Left and Right ADC */
492 da7210_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); 461 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
493 462
494 /* 463 /*
495 * DAC settings 464 * DAC settings
496 */ 465 */
497 466
498 /* Enable Left and Right DAC */ 467 /* Enable Left and Right DAC */
499 da7210_write(codec, DA7210_DAC_SEL, 468 snd_soc_write(codec, DA7210_DAC_SEL,
500 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | 469 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
501 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); 470 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
502 471
503 /* Enable Left and Right out PGA */ 472 /* Enable Left and Right out PGA */
504 da7210_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); 473 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
505 da7210_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); 474 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
506 475
507 /* Enable Left and Right HeadPhone PGA */ 476 /* Enable Left and Right HeadPhone PGA */
508 da7210_write(codec, DA7210_HP_CFG, 477 snd_soc_write(codec, DA7210_HP_CFG,
509 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | 478 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
510 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); 479 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
511 480
512 /* Diable PLL and bypass it */ 481 /* Diable PLL and bypass it */
513 da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); 482 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
514 483
515 /* 484 /*
516 * If 48kHz sound came, it use bypass mode, 485 * If 48kHz sound came, it use bypass mode,
@@ -521,22 +490,22 @@ static int da7210_probe(struct snd_soc_codec *codec)
521 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. 490 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
522 * see da7210_hw_params 491 * see da7210_hw_params
523 */ 492 */
524 da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ 493 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
525 da7210_write(codec, DA7210_PLL_DIV2, 0x99); 494 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
526 da7210_write(codec, DA7210_PLL_DIV3, 0x0A | 495 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
527 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); 496 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
528 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); 497 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
529 498
530 /* As suggested by Dialog */ 499 /* As suggested by Dialog */
531 da7210_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */ 500 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
532 da7210_write(codec, DA7210_A_TEST_UNLOCK, 0xB4); 501 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
533 da7210_write(codec, DA7210_A_PLL1, 0x01); 502 snd_soc_write(codec, DA7210_A_PLL1, 0x01);
534 da7210_write(codec, DA7210_A_CP_MODE, 0x7C); 503 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
535 da7210_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */ 504 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
536 da7210_write(codec, DA7210_A_TEST_UNLOCK, 0x00); 505 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
537 506
538 /* Activate all enabled subsystem */ 507 /* Activate all enabled subsystem */
539 da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); 508 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
540 509
541 snd_soc_add_controls(codec, da7210_snd_controls, 510 snd_soc_add_controls(codec, da7210_snd_controls,
542 ARRAY_SIZE(da7210_snd_controls)); 511 ARRAY_SIZE(da7210_snd_controls));
@@ -548,11 +517,10 @@ static int da7210_probe(struct snd_soc_codec *codec)
548 517
549static struct snd_soc_codec_driver soc_codec_dev_da7210 = { 518static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
550 .probe = da7210_probe, 519 .probe = da7210_probe,
551 .read = da7210_read,
552 .write = da7210_write,
553 .reg_cache_size = ARRAY_SIZE(da7210_reg), 520 .reg_cache_size = ARRAY_SIZE(da7210_reg),
554 .reg_word_size = sizeof(u8), 521 .reg_word_size = sizeof(u8),
555 .reg_cache_default = da7210_reg, 522 .reg_cache_default = da7210_reg,
523 .volatile_register = da7210_volatile_register,
556}; 524};
557 525
558#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 526#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
@@ -567,7 +535,6 @@ static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
567 return -ENOMEM; 535 return -ENOMEM;
568 536
569 i2c_set_clientdata(i2c, da7210); 537 i2c_set_clientdata(i2c, da7210);
570 da7210->control_data = i2c;
571 da7210->control_type = SND_SOC_I2C; 538 da7210->control_type = SND_SOC_I2C;
572 539
573 ret = snd_soc_register_codec(&i2c->dev, 540 ret = snd_soc_register_codec(&i2c->dev,