24 #include <linux/slab.h>
26 #include <linux/module.h>
38 #define AK4113_ADDR 0x00
41 static void ak4113_init_regs(
struct ak4113 *
chip);
48 if (reg <
sizeof(ak4113->
regmap))
52 static inline unsigned char reg_read(
struct ak4113 *ak4113,
unsigned char reg)
57 static void snd_ak4113_free(
struct ak4113 *
chip)
68 snd_ak4113_free(chip);
94 chip->
regmap[reg] = pgm[reg];
95 ak4113_init_regs(chip);
110 snd_ak4113_free(chip);
111 return err < 0 ? err : -
EIO;
116 unsigned char mask,
unsigned char val)
124 static void ak4113_init_regs(
struct ak4113 *
chip)
145 ak4113_init_regs(chip);
153 static unsigned int external_rate(
unsigned char rcs1)
187 static int snd_ak4113_in_error_info(
struct snd_kcontrol *kcontrol,
197 static int snd_ak4113_in_error_get(
struct snd_kcontrol *kcontrol,
203 spin_lock_irq(&chip->
lock);
205 ucontrol->
value.integer.value[0] = *
ptr;
207 spin_unlock_irq(&chip->
lock);
211 #define snd_ak4113_in_bit_info snd_ctl_boolean_mono_info
213 static int snd_ak4113_in_bit_get(
struct snd_kcontrol *kcontrol,
221 ucontrol->
value.integer.value[0] =
222 ((
reg_read(chip, reg) & (1 <<
bit)) ? 1 : 0) ^ inv;
226 static int snd_ak4113_rx_info(
struct snd_kcontrol *kcontrol,
236 static int snd_ak4113_rx_get(
struct snd_kcontrol *kcontrol,
241 ucontrol->
value.integer.value[0] =
246 static int snd_ak4113_rx_put(
struct snd_kcontrol *kcontrol,
253 spin_lock_irq(&chip->
lock);
260 spin_unlock_irq(&chip->
lock);
264 static int snd_ak4113_rate_info(
struct snd_kcontrol *kcontrol,
274 static int snd_ak4113_rate_get(
struct snd_kcontrol *kcontrol,
279 ucontrol->
value.integer.value[0] = external_rate(
reg_read(chip,
284 static int snd_ak4113_spdif_info(
struct snd_kcontrol *kcontrol,
292 static int snd_ak4113_spdif_get(
struct snd_kcontrol *kcontrol,
304 static int snd_ak4113_spdif_mask_info(
struct snd_kcontrol *kcontrol,
312 static int snd_ak4113_spdif_mask_get(
struct snd_kcontrol *kcontrol,
315 memset(ucontrol->
value.iec958.status, 0xff, AK4113_REG_RXCSB_SIZE);
319 static int snd_ak4113_spdif_pinfo(
struct snd_kcontrol *kcontrol,
329 static int snd_ak4113_spdif_pget(
struct snd_kcontrol *kcontrol,
335 ucontrol->
value.integer.value[0] = 0xf8f2;
336 ucontrol->
value.integer.value[1] = 0x4e1f;
339 ucontrol->
value.integer.value[2] =
tmp;
342 ucontrol->
value.integer.value[3] =
tmp;
346 static int snd_ak4113_spdif_qinfo(
struct snd_kcontrol *kcontrol,
354 static int snd_ak4113_spdif_qget(
struct snd_kcontrol *kcontrol,
370 .name =
"IEC958 Parity Errors",
373 .info = snd_ak4113_in_error_info,
374 .get = snd_ak4113_in_error_get,
375 .private_value =
offsetof(
struct ak4113, parity_errors),
379 .name =
"IEC958 V-Bit Errors",
382 .info = snd_ak4113_in_error_info,
383 .get = snd_ak4113_in_error_get,
384 .private_value =
offsetof(
struct ak4113, v_bit_errors),
388 .name =
"IEC958 C-CRC Errors",
391 .info = snd_ak4113_in_error_info,
392 .get = snd_ak4113_in_error_get,
393 .private_value =
offsetof(
struct ak4113, ccrc_errors),
397 .name =
"IEC958 Q-CRC Errors",
400 .info = snd_ak4113_in_error_info,
401 .get = snd_ak4113_in_error_get,
402 .private_value =
offsetof(
struct ak4113, qcrc_errors),
406 .name =
"IEC958 External Rate",
409 .info = snd_ak4113_rate_info,
410 .get = snd_ak4113_rate_get,
416 .info = snd_ak4113_spdif_mask_info,
417 .get = snd_ak4113_spdif_mask_get,
424 .info = snd_ak4113_spdif_info,
425 .get = snd_ak4113_spdif_get,
429 .name =
"IEC958 Preamble Capture Default",
432 .info = snd_ak4113_spdif_pinfo,
433 .get = snd_ak4113_spdif_pget,
437 .name =
"IEC958 Q-subcode Capture Default",
440 .info = snd_ak4113_spdif_qinfo,
441 .get = snd_ak4113_spdif_qget,
445 .name =
"IEC958 Audio",
449 .get = snd_ak4113_in_bit_get,
454 .name =
"IEC958 Non-PCM Bitstream",
458 .get = snd_ak4113_in_bit_get,
463 .name =
"IEC958 DTS Bitstream",
467 .get = snd_ak4113_in_bit_get,
472 .name =
"AK4113 Input Select",
475 .info = snd_ak4113_rx_info,
476 .get = snd_ak4113_rx_get,
477 .put = snd_ak4113_rx_put,
487 for (reg = 0; reg < 0x1d; reg++) {
489 snd_iprintf(buffer,
"0x%02x = 0x%02x\n", reg, val);
493 static void snd_ak4113_proc_init(
struct ak4113 *ak4113)
496 if (!snd_card_proc_new(ak4113->
card,
"ak4113", &entry))
497 snd_info_set_text_ops(entry, ak4113, snd_ak4113_proc_regs_read);
511 kctl =
snd_ctl_new1(&snd_ak4113_iec958_controls[idx], ak4113);
514 kctl->
id.device = cap_substream->
pcm->device;
515 kctl->
id.subdevice = cap_substream->
number;
521 snd_ak4113_proc_init(ak4113);
533 return external_rate(rcs1);
541 unsigned long _flags;
543 unsigned char rcs0, rcs1, rcs2;
544 unsigned char c0, c1;
571 spin_unlock_irqrestore(&ak4113->
lock, _flags);
573 if (rcs0 & AK4113_PAR)
575 &ak4113->
kctls[0]->id);
578 &ak4113->
kctls[1]->id);
579 if (rcs2 & AK4113_CCRC)
581 &ak4113->
kctls[2]->id);
582 if (rcs2 & AK4113_QCRC)
584 &ak4113->
kctls[3]->id);
589 &ak4113->
kctls[4]->id);
593 &ak4113->
kctls[6]->id);
596 &ak4113->
kctls[8]->id);
600 &ak4113->
kctls[9]->id);
603 &ak4113->
kctls[10]->id);
606 &ak4113->
kctls[11]->id);
613 res = external_rate(rcs1);
615 (runtime->
rate != res)) {
617 if (snd_pcm_running(ak4113->
substream)) {
633 struct ak4113 *chip =
container_of(work,
struct ak4113, work.work);