aboutsummaryrefslogtreecommitdiffstats
path: root/sound/i2c/other/ak4114.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/i2c/other/ak4114.c')
-rw-r--r--sound/i2c/other/ak4114.c114
1 files changed, 77 insertions, 37 deletions
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index adbfd5884d0..1efb973137a 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -36,6 +36,7 @@ MODULE_LICENSE("GPL");
36#define AK4114_ADDR 0x00 /* fixed address */ 36#define AK4114_ADDR 0x00 /* fixed address */
37 37
38static void ak4114_stats(struct work_struct *work); 38static void ak4114_stats(struct work_struct *work);
39static void ak4114_init_regs(struct ak4114 *chip);
39 40
40static void reg_write(struct ak4114 *ak4114, unsigned char reg, unsigned char val) 41static void reg_write(struct ak4114 *ak4114, unsigned char reg, unsigned char val)
41{ 42{
@@ -105,7 +106,7 @@ int snd_ak4114_create(struct snd_card *card,
105 for (reg = 0; reg < 5; reg++) 106 for (reg = 0; reg < 5; reg++)
106 chip->txcsb[reg] = txcsb[reg]; 107 chip->txcsb[reg] = txcsb[reg];
107 108
108 snd_ak4114_reinit(chip); 109 ak4114_init_regs(chip);
109 110
110 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); 111 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT);
111 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); 112 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1);
@@ -131,13 +132,10 @@ void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned char
131 (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val); 132 (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val);
132} 133}
133 134
134void snd_ak4114_reinit(struct ak4114 *chip) 135static void ak4114_init_regs(struct ak4114 *chip)
135{ 136{
136 unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; 137 unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg;
137 138
138 chip->init = 1;
139 mb();
140 flush_scheduled_work();
141 /* bring the chip to reset state and powerdown state */ 139 /* bring the chip to reset state and powerdown state */
142 reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); 140 reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN));
143 udelay(200); 141 udelay(200);
@@ -150,9 +148,18 @@ void snd_ak4114_reinit(struct ak4114 *chip)
150 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); 148 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]);
151 /* release powerdown, everything is initialized now */ 149 /* release powerdown, everything is initialized now */
152 reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); 150 reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN);
151}
152
153void snd_ak4114_reinit(struct ak4114 *chip)
154{
155 chip->init = 1;
156 mb();
157 flush_scheduled_work();
158 ak4114_init_regs(chip);
153 /* bring up statistics / event queing */ 159 /* bring up statistics / event queing */
154 chip->init = 0; 160 chip->init = 0;
155 schedule_delayed_work(&chip->work, HZ / 10); 161 if (chip->kctls[0])
162 schedule_delayed_work(&chip->work, HZ / 10);
156} 163}
157 164
158static unsigned int external_rate(unsigned char rcs1) 165static unsigned int external_rate(unsigned char rcs1)
@@ -428,7 +435,7 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = {
428 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 435 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
429 .info = snd_ak4114_in_bit_info, 436 .info = snd_ak4114_in_bit_info,
430 .get = snd_ak4114_in_bit_get, 437 .get = snd_ak4114_in_bit_get,
431 .private_value = (6<<8) | AK4114_REG_RCS1, 438 .private_value = (6<<8) | AK4114_REG_RCS0,
432}, 439},
433{ 440{
434 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 441 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
@@ -436,7 +443,15 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = {
436 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 443 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
437 .info = snd_ak4114_in_bit_info, 444 .info = snd_ak4114_in_bit_info,
438 .get = snd_ak4114_in_bit_get, 445 .get = snd_ak4114_in_bit_get,
439 .private_value = (3<<8) | AK4114_REG_RCS1, 446 .private_value = (3<<8) | AK4114_REG_RCS0,
447},
448{
449 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
450 .name = "IEC958 PPL Lock Status",
451 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
452 .info = snd_ak4114_in_bit_info,
453 .get = snd_ak4114_in_bit_get,
454 .private_value = (1<<31) | (4<<8) | AK4114_REG_RCS0,
440} 455}
441}; 456};
442 457
@@ -455,7 +470,7 @@ int snd_ak4114_build(struct ak4114 *ak4114,
455 kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114); 470 kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114);
456 if (kctl == NULL) 471 if (kctl == NULL)
457 return -ENOMEM; 472 return -ENOMEM;
458 if (!strstr(kctl->id.name, "Playback")) { 473 if (strstr(kctl->id.name, "Playback")) {
459 if (ply_substream == NULL) { 474 if (ply_substream == NULL) {
460 snd_ctl_free_one(kctl); 475 snd_ctl_free_one(kctl);
461 ak4114->kctls[idx] = NULL; 476 ak4114->kctls[idx] = NULL;
@@ -472,9 +487,58 @@ int snd_ak4114_build(struct ak4114 *ak4114,
472 return err; 487 return err;
473 ak4114->kctls[idx] = kctl; 488 ak4114->kctls[idx] = kctl;
474 } 489 }
490 /* trigger workq */
491 schedule_delayed_work(&ak4114->work, HZ / 10);
475 return 0; 492 return 0;
476} 493}
477 494
495/* notify kcontrols if any parameters are changed */
496static void ak4114_notify(struct ak4114 *ak4114,
497 unsigned char rcs0, unsigned char rcs1,
498 unsigned char c0, unsigned char c1)
499{
500 if (!ak4114->kctls[0])
501 return;
502
503 if (rcs0 & AK4114_PAR)
504 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
505 &ak4114->kctls[0]->id);
506 if (rcs0 & AK4114_V)
507 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
508 &ak4114->kctls[1]->id);
509 if (rcs1 & AK4114_CCRC)
510 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
511 &ak4114->kctls[2]->id);
512 if (rcs1 & AK4114_QCRC)
513 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
514 &ak4114->kctls[3]->id);
515
516 /* rate change */
517 if (c1 & 0xf0)
518 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
519 &ak4114->kctls[4]->id);
520
521 if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT))
522 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
523 &ak4114->kctls[9]->id);
524 if (c0 & AK4114_QINT)
525 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
526 &ak4114->kctls[10]->id);
527
528 if (c0 & AK4114_AUDION)
529 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
530 &ak4114->kctls[11]->id);
531 if (c0 & AK4114_AUTO)
532 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
533 &ak4114->kctls[12]->id);
534 if (c0 & AK4114_DTSCD)
535 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
536 &ak4114->kctls[13]->id);
537 if (c0 & AK4114_UNLCK)
538 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE,
539 &ak4114->kctls[14]->id);
540}
541
478int snd_ak4114_external_rate(struct ak4114 *ak4114) 542int snd_ak4114_external_rate(struct ak4114 *ak4114)
479{ 543{
480 unsigned char rcs1; 544 unsigned char rcs1;
@@ -511,31 +575,7 @@ int snd_ak4114_check_rate_and_errors(struct ak4114 *ak4114, unsigned int flags)
511 ak4114->rcs1 = rcs1; 575 ak4114->rcs1 = rcs1;
512 spin_unlock_irqrestore(&ak4114->lock, _flags); 576 spin_unlock_irqrestore(&ak4114->lock, _flags);
513 577
514 if (rcs0 & AK4114_PAR) 578 ak4114_notify(ak4114, rcs0, rcs1, c0, c1);
515 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[0]->id);
516 if (rcs0 & AK4114_V)
517 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[1]->id);
518 if (rcs1 & AK4114_CCRC)
519 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[2]->id);
520 if (rcs1 & AK4114_QCRC)
521 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[3]->id);
522
523 /* rate change */
524 if (c1 & 0xf0)
525 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[4]->id);
526
527 if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT))
528 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[9]->id);
529 if (c0 & AK4114_QINT)
530 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[10]->id);
531
532 if (c0 & AK4114_AUDION)
533 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[11]->id);
534 if (c0 & AK4114_AUTO)
535 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[12]->id);
536 if (c0 & AK4114_DTSCD)
537 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[13]->id);
538
539 if (ak4114->change_callback && (c0 | c1) != 0) 579 if (ak4114->change_callback && (c0 | c1) != 0)
540 ak4114->change_callback(ak4114, c0, c1); 580 ak4114->change_callback(ak4114, c0, c1);
541 581
@@ -558,9 +598,9 @@ static void ak4114_stats(struct work_struct *work)
558{ 598{
559 struct ak4114 *chip = container_of(work, struct ak4114, work.work); 599 struct ak4114 *chip = container_of(work, struct ak4114, work.work);
560 600
561 if (chip->init) 601 if (!chip->init)
562 return; 602 snd_ak4114_check_rate_and_errors(chip, 0);
563 snd_ak4114_check_rate_and_errors(chip, 0); 603
564 schedule_delayed_work(&chip->work, HZ / 10); 604 schedule_delayed_work(&chip->work, HZ / 10);
565} 605}
566 606