23 #include <linux/slab.h>
25 #include <linux/module.h>
36 #define AK4117_ADDR 0x00
38 static void snd_ak4117_timer(
unsigned long data);
43 if (reg <
sizeof(ak4117->
regmap))
47 static inline unsigned char reg_read(
struct ak4117 *ak4117,
unsigned char reg)
53 static void reg_dump(
struct ak4117 *ak4117)
58 for (i = 0; i < 0x1b; i++)
63 static void snd_ak4117_free(
struct ak4117 *
chip)
72 snd_ak4117_free(chip);
77 const unsigned char pgm[5],
void *
private_data,
struct ak4117 **r_ak4117)
96 chip->
timer.function = snd_ak4117_timer;
98 for (reg = 0; reg < 5; reg++)
99 chip->
regmap[reg] = pgm[reg];
114 snd_ak4117_free(chip);
115 return err < 0 ? err : -
EIO;
137 for (reg = 1; reg < 5; reg++)
146 static unsigned int external_rate(
unsigned char rcs1)
160 static int snd_ak4117_in_error_info(
struct snd_kcontrol *kcontrol,
170 static int snd_ak4117_in_error_get(
struct snd_kcontrol *kcontrol,
176 spin_lock_irq(&chip->
lock);
178 ucontrol->
value.integer.value[0] = *
ptr;
180 spin_unlock_irq(&chip->
lock);
184 #define snd_ak4117_in_bit_info snd_ctl_boolean_mono_info
186 static int snd_ak4117_in_bit_get(
struct snd_kcontrol *kcontrol,
194 ucontrol->
value.integer.value[0] = ((
reg_read(chip, reg) & (1 <<
bit)) ? 1 : 0) ^ inv;
198 static int snd_ak4117_rx_info(
struct snd_kcontrol *kcontrol,
208 static int snd_ak4117_rx_get(
struct snd_kcontrol *kcontrol,
217 static int snd_ak4117_rx_put(
struct snd_kcontrol *kcontrol,
224 spin_lock_irq(&chip->
lock);
226 change = !!ucontrol->
value.integer.value[0] != ((old_val &
AK4117_IPS) ? 1 : 0);
229 spin_unlock_irq(&chip->
lock);
233 static int snd_ak4117_rate_info(
struct snd_kcontrol *kcontrol,
243 static int snd_ak4117_rate_get(
struct snd_kcontrol *kcontrol,
259 static int snd_ak4117_spdif_get(
struct snd_kcontrol *kcontrol,
277 static int snd_ak4117_spdif_mask_get(
struct snd_kcontrol *kcontrol,
280 memset(ucontrol->
value.iec958.status, 0xff, AK4117_REG_RXCSB_SIZE);
293 static int snd_ak4117_spdif_pget(
struct snd_kcontrol *kcontrol,
299 ucontrol->
value.integer.value[0] = 0xf8f2;
300 ucontrol->
value.integer.value[1] = 0x4e1f;
302 ucontrol->
value.integer.value[2] =
tmp;
304 ucontrol->
value.integer.value[3] =
tmp;
315 static int snd_ak4117_spdif_qget(
struct snd_kcontrol *kcontrol,
330 .name =
"IEC958 Parity Errors",
332 .info = snd_ak4117_in_error_info,
333 .get = snd_ak4117_in_error_get,
334 .private_value =
offsetof(
struct ak4117, parity_errors),
338 .name =
"IEC958 V-Bit Errors",
340 .info = snd_ak4117_in_error_info,
341 .get = snd_ak4117_in_error_get,
342 .private_value =
offsetof(
struct ak4117, v_bit_errors),
346 .name =
"IEC958 C-CRC Errors",
348 .info = snd_ak4117_in_error_info,
349 .get = snd_ak4117_in_error_get,
350 .private_value =
offsetof(
struct ak4117, ccrc_errors),
354 .name =
"IEC958 Q-CRC Errors",
356 .info = snd_ak4117_in_error_info,
357 .get = snd_ak4117_in_error_get,
358 .private_value =
offsetof(
struct ak4117, qcrc_errors),
362 .name =
"IEC958 External Rate",
364 .info = snd_ak4117_rate_info,
365 .get = snd_ak4117_rate_get,
371 .info = snd_ak4117_spdif_mask_info,
372 .get = snd_ak4117_spdif_mask_get,
378 .info = snd_ak4117_spdif_info,
379 .get = snd_ak4117_spdif_get,
383 .name =
"IEC958 Preamble Capture Default",
385 .info = snd_ak4117_spdif_pinfo,
386 .get = snd_ak4117_spdif_pget,
390 .name =
"IEC958 Q-subcode Capture Default",
392 .info = snd_ak4117_spdif_qinfo,
393 .get = snd_ak4117_spdif_qget,
397 .name =
"IEC958 Audio",
400 .get = snd_ak4117_in_bit_get,
405 .name =
"IEC958 Non-PCM Bitstream",
408 .get = snd_ak4117_in_bit_get,
413 .name =
"IEC958 DTS Bitstream",
416 .get = snd_ak4117_in_bit_get,
421 .name =
"AK4117 Input Select",
423 .info = snd_ak4117_rx_info,
424 .get = snd_ak4117_rx_get,
425 .put = snd_ak4117_rx_put,
439 kctl =
snd_ctl_new1(&snd_ak4117_iec958_controls[idx], ak4117);
442 kctl->
id.device = cap_substream->
pcm->device;
443 kctl->
id.subdevice = cap_substream->
number;
457 return external_rate(rcs1);
463 unsigned long _flags;
465 unsigned char rcs0, rcs1, rcs2;
466 unsigned char c0, c1;
490 spin_unlock_irqrestore(&ak4117->
lock, _flags);
492 if (rcs0 & AK4117_PAR)
496 if (rcs2 & AK4117_CCRC)
498 if (rcs2 & AK4117_QCRC)
522 res = external_rate(rcs1);
525 if (snd_pcm_running(ak4117->
substream)) {
536 static void snd_ak4117_timer(
unsigned long data)
538 struct ak4117 *chip = (
struct ak4117 *)data;