23 #include <linux/slab.h>
27 #include <linux/module.h>
28 #include <asm/unaligned.h>
41 #define CS8427_ADDR (0x20>>1)
70 "to CS8427 (%i)\n", buf[0], buf[1], err);
71 return err < 0 ? err : -
EIO;
86 return err < 0 ? err : -
EIO;
90 "from CS8427\n", reg);
91 return err < 0 ? err : -
EIO;
96 static int snd_cs8427_select_corudata(
struct snd_i2c_device *device,
int udata)
113 static int snd_cs8427_send_corudata(
struct snd_i2c_device *device,
115 unsigned char *ndata,
124 if (!
memcmp(hw_data, ndata, count))
126 if ((err = snd_cs8427_select_corudata(device, udata)) < 0)
128 memcpy(hw_data, ndata, count);
130 memset(data, 0,
sizeof(data));
131 if (
memcmp(hw_data, data, count) == 0) {
137 return err < 0 ? err : 0;
141 for (idx = 0; idx <
count; idx++)
142 data[idx + 1] = bitrev8(ndata[idx]);
158 static unsigned char initvals1[] = {
181 static unsigned char initvals2[] = {
206 unsigned char buf[24];
224 "let me try again...\n", err);
230 "(expected 0x%x, read 0x%x),\n",
240 memcpy(chip->
regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6);
242 err = err < 0 ? err : -
EIO;
252 memcpy(chip->
regmap + (initvals2[0] & 0x7f), initvals2 + 1, 3);
254 err = err < 0 ? err : -
EIO;
259 memset(buf + 4, 0, 24 - 4);
260 if (snd_cs8427_send_corudata(device, 0, buf, 24) < 0)
267 if (reset_timeout < 1)
270 snd_cs8427_reset(device);
272 #if 0 // it's nice for read tests
279 for (xx = 0; xx < 127; xx++)
291 return err < 0 ? err : -
EIO;
304 unsigned long end_time;
305 int data, aes3input = 0;
310 snd_i2c_lock(cs8427->
bus);
322 snd_i2c_unlock(cs8427->
bus);
325 snd_i2c_lock(cs8427->
bus);
327 snd_i2c_unlock(cs8427->
bus);
332 snd_i2c_lock(cs8427->
bus);
338 snd_i2c_unlock(cs8427->
bus);
341 static int snd_cs8427_in_status_info(
struct snd_kcontrol *kcontrol,
351 static int snd_cs8427_in_status_get(
struct snd_kcontrol *kcontrol,
357 snd_i2c_lock(device->
bus);
359 snd_i2c_unlock(device->
bus);
366 static int snd_cs8427_qsubcode_info(
struct snd_kcontrol *kcontrol,
374 static int snd_cs8427_qsubcode_get(
struct snd_kcontrol *kcontrol,
381 snd_i2c_lock(device->
bus);
385 snd_i2c_unlock(device->
bus);
386 return err < 0 ? err : -
EIO;
392 snd_i2c_unlock(device->
bus);
393 return err < 0 ? err : -
EIO;
395 snd_i2c_unlock(device->
bus);
399 static int snd_cs8427_spdif_info(
struct snd_kcontrol *kcontrol,
407 static int snd_cs8427_spdif_get(
struct snd_kcontrol *kcontrol,
413 snd_i2c_lock(device->
bus);
415 snd_i2c_unlock(device->
bus);
419 static int snd_cs8427_spdif_put(
struct snd_kcontrol *kcontrol,
430 snd_i2c_lock(device->
bus);
431 change =
memcmp(ucontrol->
value.iec958.status, status, 24) != 0;
434 runtime !=
NULL : runtime ==
NULL)) {
435 err = snd_cs8427_send_corudata(device, 0, status, 24);
439 snd_i2c_unlock(device->
bus);
443 static int snd_cs8427_spdif_mask_info(
struct snd_kcontrol *kcontrol,
451 static int snd_cs8427_spdif_mask_get(
struct snd_kcontrol *kcontrol,
461 .info = snd_cs8427_in_status_info,
462 .name =
"IEC958 CS8427 Input Status",
465 .
get = snd_cs8427_in_status_get,
470 .info = snd_cs8427_in_status_info,
471 .name =
"IEC958 CS8427 Error Status",
474 .
get = snd_cs8427_in_status_get,
481 .info = snd_cs8427_spdif_mask_info,
482 .get = snd_cs8427_spdif_mask_get,
487 .info = snd_cs8427_spdif_info,
488 .get = snd_cs8427_spdif_get,
489 .put = snd_cs8427_spdif_put,
497 .info = snd_cs8427_spdif_info,
498 .get = snd_cs8427_spdif_get,
499 .put = snd_cs8427_spdif_put,
504 .info = snd_cs8427_qsubcode_info,
505 .name =
"IEC958 Q-subcode Capture Default",
508 .
get = snd_cs8427_qsubcode_get
520 if (
snd_BUG_ON(!play_substream || !cap_substream))
522 for (idx = 0; idx <
ARRAY_SIZE(snd_cs8427_iec958_controls); idx++) {
523 kctl =
snd_ctl_new1(&snd_cs8427_iec958_controls[idx], cs8427);
526 kctl->
id.device = play_substream->
pcm->device;
527 kctl->
id.subdevice = play_substream->
number;
536 chip->
playback.substream = play_substream;
537 chip->
capture.substream = cap_substream;
574 snd_i2c_lock(cs8427->
bus);
591 err = snd_cs8427_send_corudata(cs8427, 0, status, 24);
598 snd_i2c_unlock(cs8427->
bus);
600 snd_cs8427_reset(cs8427);
601 return err < 0 ? err : 0;
606 static int __init alsa_cs8427_module_init(
void)
611 static void __exit alsa_cs8427_module_exit(
void)