23 #include <linux/slab.h>
25 #include <linux/module.h>
37 #define AK4114_ADDR 0x00
40 static void ak4114_init_regs(
struct ak4114 *
chip);
51 static inline unsigned char reg_read(
struct ak4114 *ak4114,
unsigned char reg)
57 static void reg_dump(
struct ak4114 *ak4114)
62 for (i = 0; i < 0x20; i++)
67 static void snd_ak4114_free(
struct ak4114 *
chip)
78 snd_ak4114_free(chip);
84 const unsigned char pgm[7],
const unsigned char txcsb[5],
104 for (reg = 0; reg < 7; reg++)
105 chip->
regmap[reg] = pgm[reg];
106 for (reg = 0; reg < 5; reg++)
107 chip->
txcsb[reg] = txcsb[reg];
109 ak4114_init_regs(chip);
122 snd_ak4114_free(chip);
123 return err < 0 ? err : -
EIO;
135 static void ak4114_init_regs(
struct ak4114 *
chip)
145 for (reg = 1; reg < 7; reg++)
147 for (reg = 0; reg < 5; reg++)
158 ak4114_init_regs(chip);
165 static unsigned int external_rate(
unsigned char rcs1)
179 static int snd_ak4114_in_error_info(
struct snd_kcontrol *kcontrol,
189 static int snd_ak4114_in_error_get(
struct snd_kcontrol *kcontrol,
195 spin_lock_irq(&chip->
lock);
197 ucontrol->
value.integer.value[0] = *
ptr;
199 spin_unlock_irq(&chip->
lock);
203 #define snd_ak4114_in_bit_info snd_ctl_boolean_mono_info
205 static int snd_ak4114_in_bit_get(
struct snd_kcontrol *kcontrol,
213 ucontrol->
value.integer.value[0] = ((
reg_read(chip, reg) & (1 <<
bit)) ? 1 : 0) ^ inv;
217 static int snd_ak4114_rate_info(
struct snd_kcontrol *kcontrol,
227 static int snd_ak4114_rate_get(
struct snd_kcontrol *kcontrol,
243 static int snd_ak4114_spdif_get(
struct snd_kcontrol *kcontrol,
254 static int snd_ak4114_spdif_playback_get(
struct snd_kcontrol *kcontrol,
261 ucontrol->
value.iec958.status[i] = chip->
txcsb[i];
265 static int snd_ak4114_spdif_playback_put(
struct snd_kcontrol *kcontrol,
283 static int snd_ak4114_spdif_mask_get(
struct snd_kcontrol *kcontrol,
286 memset(ucontrol->
value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE);
299 static int snd_ak4114_spdif_pget(
struct snd_kcontrol *kcontrol,
305 ucontrol->
value.integer.value[0] = 0xf8f2;
306 ucontrol->
value.integer.value[1] = 0x4e1f;
308 ucontrol->
value.integer.value[2] =
tmp;
310 ucontrol->
value.integer.value[3] =
tmp;
321 static int snd_ak4114_spdif_qget(
struct snd_kcontrol *kcontrol,
336 .name =
"IEC958 Parity Errors",
338 .info = snd_ak4114_in_error_info,
339 .get = snd_ak4114_in_error_get,
340 .private_value =
offsetof(
struct ak4114, parity_errors),
344 .name =
"IEC958 V-Bit Errors",
346 .info = snd_ak4114_in_error_info,
347 .get = snd_ak4114_in_error_get,
348 .private_value =
offsetof(
struct ak4114, v_bit_errors),
352 .name =
"IEC958 C-CRC Errors",
354 .info = snd_ak4114_in_error_info,
355 .get = snd_ak4114_in_error_get,
356 .private_value =
offsetof(
struct ak4114, ccrc_errors),
360 .name =
"IEC958 Q-CRC Errors",
362 .info = snd_ak4114_in_error_info,
363 .get = snd_ak4114_in_error_get,
364 .private_value =
offsetof(
struct ak4114, qcrc_errors),
368 .name =
"IEC958 External Rate",
370 .info = snd_ak4114_rate_info,
371 .get = snd_ak4114_rate_get,
377 .info = snd_ak4114_spdif_mask_info,
378 .get = snd_ak4114_spdif_mask_get,
384 .info = snd_ak4114_spdif_info,
385 .get = snd_ak4114_spdif_playback_get,
386 .put = snd_ak4114_spdif_playback_put,
392 .info = snd_ak4114_spdif_mask_info,
393 .get = snd_ak4114_spdif_mask_get,
399 .info = snd_ak4114_spdif_info,
400 .get = snd_ak4114_spdif_get,
404 .name =
"IEC958 Preamble Capture Default",
406 .info = snd_ak4114_spdif_pinfo,
407 .get = snd_ak4114_spdif_pget,
411 .name =
"IEC958 Q-subcode Capture Default",
413 .info = snd_ak4114_spdif_qinfo,
414 .get = snd_ak4114_spdif_qget,
418 .name =
"IEC958 Audio",
421 .get = snd_ak4114_in_bit_get,
426 .name =
"IEC958 Non-PCM Bitstream",
429 .get = snd_ak4114_in_bit_get,
434 .name =
"IEC958 DTS Bitstream",
437 .get = snd_ak4114_in_bit_get,
442 .name =
"IEC958 PPL Lock Status",
445 .get = snd_ak4114_in_bit_get,
457 for (reg = 0; reg < 0x20; reg++) {
459 snd_iprintf(buffer,
"0x%02x = 0x%02x\n", reg, val);
463 static void snd_ak4114_proc_init(
struct ak4114 *ak4114)
466 if (!snd_card_proc_new(ak4114->
card,
"ak4114", &entry))
467 snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read);
483 kctl =
snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114);
486 if (
strstr(kctl->
id.name,
"Playback")) {
487 if (ply_substream ==
NULL) {
492 kctl->
id.device = ply_substream->
pcm->device;
493 kctl->
id.subdevice = ply_substream->
number;
495 kctl->
id.device = cap_substream->
pcm->device;
496 kctl->
id.subdevice = cap_substream->
number;
503 snd_ak4114_proc_init(ak4114);
510 static void ak4114_notify(
struct ak4114 *ak4114,
511 unsigned char rcs0,
unsigned char rcs1,
512 unsigned char c0,
unsigned char c1)
514 if (!ak4114->
kctls[0])
519 &ak4114->
kctls[0]->id);
522 &ak4114->
kctls[1]->id);
525 &ak4114->
kctls[2]->id);
528 &ak4114->
kctls[3]->id);
533 &ak4114->
kctls[4]->id);
537 &ak4114->
kctls[9]->id);
540 &ak4114->
kctls[10]->id);
544 &ak4114->
kctls[11]->id);
547 &ak4114->
kctls[12]->id);
550 &ak4114->
kctls[13]->id);
553 &ak4114->
kctls[14]->id);
561 return external_rate(rcs1);
567 unsigned long _flags;
569 unsigned char rcs0, rcs1;
570 unsigned char c0, c1;
577 if (rcs0 & AK4114_PAR)
581 if (rcs1 & AK4114_CCRC)
583 if (rcs1 & AK4114_QCRC)
585 c0 = (ak4114->
rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO |
AK4114_UNLCK)) ^
586 (rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO |
AK4114_UNLCK));
587 c1 = (ak4114->
rcs1 & 0xf0) ^ (rcs1 & 0xf0);
590 spin_unlock_irqrestore(&ak4114->
lock, _flags);
592 ak4114_notify(ak4114, rcs0, rcs1, c0, c1);
598 res = external_rate(rcs1);
613 struct ak4114 *chip =
container_of(work,
struct ak4114, work.work);