2 * Routines for control of the AK4114 via I2C and 4-wire serial interface
3 * IEC958 (S/PDIF) receiver by Asahi Kasei
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/slab.h>
24 #include <linux/delay.h>
25 #include <linux/module.h>
26 #include <sound/core.h>
27 #include <sound/control.h>
28 #include <sound/pcm.h>
29 #include <sound/ak4114.h>
30 #include <sound/asoundef.h>
31 #include <sound/info.h>
33 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
34 MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
35 MODULE_LICENSE("GPL");
37 #define AK4114_ADDR 0x00 /* fixed address */
39 static void ak4114_stats(struct work_struct
*work
);
40 static void ak4114_init_regs(struct ak4114
*chip
);
42 static void reg_write(struct ak4114
*ak4114
, unsigned char reg
, unsigned char val
)
44 ak4114
->write(ak4114
->private_data
, reg
, val
);
45 if (reg
<= AK4114_REG_INT1_MASK
)
46 ak4114
->regmap
[reg
] = val
;
47 else if (reg
>= AK4114_REG_TXCSB0
&& reg
<= AK4114_REG_TXCSB4
)
48 ak4114
->txcsb
[reg
-AK4114_REG_TXCSB0
] = val
;
51 static inline unsigned char reg_read(struct ak4114
*ak4114
, unsigned char reg
)
53 return ak4114
->read(ak4114
->private_data
, reg
);
57 static void reg_dump(struct ak4114
*ak4114
)
61 printk(KERN_DEBUG
"AK4114 REG DUMP:\n");
62 for (i
= 0; i
< 0x20; i
++)
63 printk(KERN_DEBUG
"reg[%02x] = %02x (%02x)\n", i
, reg_read(ak4114
, i
), i
< ARRAY_SIZE(ak4114
->regmap
) ? ak4114
->regmap
[i
] : 0);
67 static void snd_ak4114_free(struct ak4114
*chip
)
69 atomic_inc(&chip
->wq_processing
); /* don't schedule new work */
70 cancel_delayed_work_sync(&chip
->work
);
74 static int snd_ak4114_dev_free(struct snd_device
*device
)
76 struct ak4114
*chip
= device
->device_data
;
77 snd_ak4114_free(chip
);
81 int snd_ak4114_create(struct snd_card
*card
,
82 ak4114_read_t
*read
, ak4114_write_t
*write
,
83 const unsigned char pgm
[6], const unsigned char txcsb
[5],
84 void *private_data
, struct ak4114
**r_ak4114
)
89 static struct snd_device_ops ops
= {
90 .dev_free
= snd_ak4114_dev_free
,
93 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
96 spin_lock_init(&chip
->lock
);
100 chip
->private_data
= private_data
;
101 INIT_DELAYED_WORK(&chip
->work
, ak4114_stats
);
102 atomic_set(&chip
->wq_processing
, 0);
104 for (reg
= 0; reg
< 6; 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
);
111 chip
->rcs0
= reg_read(chip
, AK4114_REG_RCS0
) & ~(AK4114_QINT
| AK4114_CINT
);
112 chip
->rcs1
= reg_read(chip
, AK4114_REG_RCS1
);
114 if ((err
= snd_device_new(card
, SNDRV_DEV_CODEC
, chip
, &ops
)) < 0)
122 snd_ak4114_free(chip
);
123 return err
< 0 ? err
: -EIO
;
125 EXPORT_SYMBOL(snd_ak4114_create
);
127 void snd_ak4114_reg_write(struct ak4114
*chip
, unsigned char reg
, unsigned char mask
, unsigned char val
)
129 if (reg
<= AK4114_REG_INT1_MASK
)
130 reg_write(chip
, reg
, (chip
->regmap
[reg
] & ~mask
) | val
);
131 else if (reg
>= AK4114_REG_TXCSB0
&& reg
<= AK4114_REG_TXCSB4
)
133 (chip
->txcsb
[reg
-AK4114_REG_TXCSB0
] & ~mask
) | val
);
135 EXPORT_SYMBOL(snd_ak4114_reg_write
);
137 static void ak4114_init_regs(struct ak4114
*chip
)
139 unsigned char old
= chip
->regmap
[AK4114_REG_PWRDN
], reg
;
141 /* bring the chip to reset state and powerdown state */
142 reg_write(chip
, AK4114_REG_PWRDN
, old
& ~(AK4114_RST
|AK4114_PWN
));
144 /* release reset, but leave powerdown */
145 reg_write(chip
, AK4114_REG_PWRDN
, (old
| AK4114_RST
) & ~AK4114_PWN
);
147 for (reg
= 1; reg
< 6; reg
++)
148 reg_write(chip
, reg
, chip
->regmap
[reg
]);
149 for (reg
= 0; reg
< 5; reg
++)
150 reg_write(chip
, reg
+ AK4114_REG_TXCSB0
, chip
->txcsb
[reg
]);
151 /* release powerdown, everything is initialized now */
152 reg_write(chip
, AK4114_REG_PWRDN
, old
| AK4114_RST
| AK4114_PWN
);
155 void snd_ak4114_reinit(struct ak4114
*chip
)
157 if (atomic_inc_return(&chip
->wq_processing
) == 1)
158 cancel_delayed_work_sync(&chip
->work
);
159 ak4114_init_regs(chip
);
160 /* bring up statistics / event queing */
161 if (atomic_dec_and_test(&chip
->wq_processing
))
162 schedule_delayed_work(&chip
->work
, HZ
/ 10);
164 EXPORT_SYMBOL(snd_ak4114_reinit
);
166 static unsigned int external_rate(unsigned char rcs1
)
168 switch (rcs1
& (AK4114_FS0
|AK4114_FS1
|AK4114_FS2
|AK4114_FS3
)) {
169 case AK4114_FS_32000HZ
: return 32000;
170 case AK4114_FS_44100HZ
: return 44100;
171 case AK4114_FS_48000HZ
: return 48000;
172 case AK4114_FS_88200HZ
: return 88200;
173 case AK4114_FS_96000HZ
: return 96000;
174 case AK4114_FS_176400HZ
: return 176400;
175 case AK4114_FS_192000HZ
: return 192000;
180 static int snd_ak4114_in_error_info(struct snd_kcontrol
*kcontrol
,
181 struct snd_ctl_elem_info
*uinfo
)
183 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
185 uinfo
->value
.integer
.min
= 0;
186 uinfo
->value
.integer
.max
= LONG_MAX
;
190 static int snd_ak4114_in_error_get(struct snd_kcontrol
*kcontrol
,
191 struct snd_ctl_elem_value
*ucontrol
)
193 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
196 spin_lock_irq(&chip
->lock
);
197 ptr
= (long *)(((char *)chip
) + kcontrol
->private_value
);
198 ucontrol
->value
.integer
.value
[0] = *ptr
;
200 spin_unlock_irq(&chip
->lock
);
204 #define snd_ak4114_in_bit_info snd_ctl_boolean_mono_info
206 static int snd_ak4114_in_bit_get(struct snd_kcontrol
*kcontrol
,
207 struct snd_ctl_elem_value
*ucontrol
)
209 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
210 unsigned char reg
= kcontrol
->private_value
& 0xff;
211 unsigned char bit
= (kcontrol
->private_value
>> 8) & 0xff;
212 unsigned char inv
= (kcontrol
->private_value
>> 31) & 1;
214 ucontrol
->value
.integer
.value
[0] = ((reg_read(chip
, reg
) & (1 << bit
)) ? 1 : 0) ^ inv
;
218 static int snd_ak4114_rate_info(struct snd_kcontrol
*kcontrol
,
219 struct snd_ctl_elem_info
*uinfo
)
221 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
223 uinfo
->value
.integer
.min
= 0;
224 uinfo
->value
.integer
.max
= 192000;
228 static int snd_ak4114_rate_get(struct snd_kcontrol
*kcontrol
,
229 struct snd_ctl_elem_value
*ucontrol
)
231 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
233 ucontrol
->value
.integer
.value
[0] = external_rate(reg_read(chip
, AK4114_REG_RCS1
));
237 static int snd_ak4114_spdif_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
239 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
244 static int snd_ak4114_spdif_get(struct snd_kcontrol
*kcontrol
,
245 struct snd_ctl_elem_value
*ucontrol
)
247 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
250 for (i
= 0; i
< AK4114_REG_RXCSB_SIZE
; i
++)
251 ucontrol
->value
.iec958
.status
[i
] = reg_read(chip
, AK4114_REG_RXCSB0
+ i
);
255 static int snd_ak4114_spdif_playback_get(struct snd_kcontrol
*kcontrol
,
256 struct snd_ctl_elem_value
*ucontrol
)
258 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
261 for (i
= 0; i
< AK4114_REG_TXCSB_SIZE
; i
++)
262 ucontrol
->value
.iec958
.status
[i
] = chip
->txcsb
[i
];
266 static int snd_ak4114_spdif_playback_put(struct snd_kcontrol
*kcontrol
,
267 struct snd_ctl_elem_value
*ucontrol
)
269 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
272 for (i
= 0; i
< AK4114_REG_TXCSB_SIZE
; i
++)
273 reg_write(chip
, AK4114_REG_TXCSB0
+ i
, ucontrol
->value
.iec958
.status
[i
]);
277 static int snd_ak4114_spdif_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
279 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
284 static int snd_ak4114_spdif_mask_get(struct snd_kcontrol
*kcontrol
,
285 struct snd_ctl_elem_value
*ucontrol
)
287 memset(ucontrol
->value
.iec958
.status
, 0xff, AK4114_REG_RXCSB_SIZE
);
291 static int snd_ak4114_spdif_pinfo(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
293 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
294 uinfo
->value
.integer
.min
= 0;
295 uinfo
->value
.integer
.max
= 0xffff;
300 static int snd_ak4114_spdif_pget(struct snd_kcontrol
*kcontrol
,
301 struct snd_ctl_elem_value
*ucontrol
)
303 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
306 ucontrol
->value
.integer
.value
[0] = 0xf8f2;
307 ucontrol
->value
.integer
.value
[1] = 0x4e1f;
308 tmp
= reg_read(chip
, AK4114_REG_Pc0
) | (reg_read(chip
, AK4114_REG_Pc1
) << 8);
309 ucontrol
->value
.integer
.value
[2] = tmp
;
310 tmp
= reg_read(chip
, AK4114_REG_Pd0
) | (reg_read(chip
, AK4114_REG_Pd1
) << 8);
311 ucontrol
->value
.integer
.value
[3] = tmp
;
315 static int snd_ak4114_spdif_qinfo(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
317 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BYTES
;
318 uinfo
->count
= AK4114_REG_QSUB_SIZE
;
322 static int snd_ak4114_spdif_qget(struct snd_kcontrol
*kcontrol
,
323 struct snd_ctl_elem_value
*ucontrol
)
325 struct ak4114
*chip
= snd_kcontrol_chip(kcontrol
);
328 for (i
= 0; i
< AK4114_REG_QSUB_SIZE
; i
++)
329 ucontrol
->value
.bytes
.data
[i
] = reg_read(chip
, AK4114_REG_QSUB_ADDR
+ i
);
333 /* Don't forget to change AK4114_CONTROLS define!!! */
334 static struct snd_kcontrol_new snd_ak4114_iec958_controls
[] = {
336 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
337 .name
= "IEC958 Parity Errors",
338 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
339 .info
= snd_ak4114_in_error_info
,
340 .get
= snd_ak4114_in_error_get
,
341 .private_value
= offsetof(struct ak4114
, parity_errors
),
344 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
345 .name
= "IEC958 V-Bit Errors",
346 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
347 .info
= snd_ak4114_in_error_info
,
348 .get
= snd_ak4114_in_error_get
,
349 .private_value
= offsetof(struct ak4114
, v_bit_errors
),
352 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
353 .name
= "IEC958 C-CRC Errors",
354 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
355 .info
= snd_ak4114_in_error_info
,
356 .get
= snd_ak4114_in_error_get
,
357 .private_value
= offsetof(struct ak4114
, ccrc_errors
),
360 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
361 .name
= "IEC958 Q-CRC Errors",
362 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
363 .info
= snd_ak4114_in_error_info
,
364 .get
= snd_ak4114_in_error_get
,
365 .private_value
= offsetof(struct ak4114
, qcrc_errors
),
368 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
369 .name
= "IEC958 External Rate",
370 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
371 .info
= snd_ak4114_rate_info
,
372 .get
= snd_ak4114_rate_get
,
375 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
376 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,MASK
),
377 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
378 .info
= snd_ak4114_spdif_mask_info
,
379 .get
= snd_ak4114_spdif_mask_get
,
382 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
383 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
384 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
385 .info
= snd_ak4114_spdif_info
,
386 .get
= snd_ak4114_spdif_playback_get
,
387 .put
= snd_ak4114_spdif_playback_put
,
390 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
391 .name
= SNDRV_CTL_NAME_IEC958("",CAPTURE
,MASK
),
392 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
393 .info
= snd_ak4114_spdif_mask_info
,
394 .get
= snd_ak4114_spdif_mask_get
,
397 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
398 .name
= SNDRV_CTL_NAME_IEC958("",CAPTURE
,DEFAULT
),
399 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
400 .info
= snd_ak4114_spdif_info
,
401 .get
= snd_ak4114_spdif_get
,
404 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
405 .name
= "IEC958 Preamble Capture Default",
406 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
407 .info
= snd_ak4114_spdif_pinfo
,
408 .get
= snd_ak4114_spdif_pget
,
411 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
412 .name
= "IEC958 Q-subcode Capture Default",
413 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
414 .info
= snd_ak4114_spdif_qinfo
,
415 .get
= snd_ak4114_spdif_qget
,
418 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
419 .name
= "IEC958 Audio",
420 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
421 .info
= snd_ak4114_in_bit_info
,
422 .get
= snd_ak4114_in_bit_get
,
423 .private_value
= (1<<31) | (1<<8) | AK4114_REG_RCS0
,
426 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
427 .name
= "IEC958 Non-PCM Bitstream",
428 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
429 .info
= snd_ak4114_in_bit_info
,
430 .get
= snd_ak4114_in_bit_get
,
431 .private_value
= (6<<8) | AK4114_REG_RCS0
,
434 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
435 .name
= "IEC958 DTS Bitstream",
436 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
437 .info
= snd_ak4114_in_bit_info
,
438 .get
= snd_ak4114_in_bit_get
,
439 .private_value
= (3<<8) | AK4114_REG_RCS0
,
442 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
443 .name
= "IEC958 PPL Lock Status",
444 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
445 .info
= snd_ak4114_in_bit_info
,
446 .get
= snd_ak4114_in_bit_get
,
447 .private_value
= (1<<31) | (4<<8) | AK4114_REG_RCS0
,
452 static void snd_ak4114_proc_regs_read(struct snd_info_entry
*entry
,
453 struct snd_info_buffer
*buffer
)
455 struct ak4114
*ak4114
= entry
->private_data
;
457 /* all ak4114 registers 0x00 - 0x1f */
458 for (reg
= 0; reg
< 0x20; reg
++) {
459 val
= reg_read(ak4114
, reg
);
460 snd_iprintf(buffer
, "0x%02x = 0x%02x\n", reg
, val
);
464 static void snd_ak4114_proc_init(struct ak4114
*ak4114
)
466 struct snd_info_entry
*entry
;
467 if (!snd_card_proc_new(ak4114
->card
, "ak4114", &entry
))
468 snd_info_set_text_ops(entry
, ak4114
, snd_ak4114_proc_regs_read
);
471 int snd_ak4114_build(struct ak4114
*ak4114
,
472 struct snd_pcm_substream
*ply_substream
,
473 struct snd_pcm_substream
*cap_substream
)
475 struct snd_kcontrol
*kctl
;
479 if (snd_BUG_ON(!cap_substream
))
481 ak4114
->playback_substream
= ply_substream
;
482 ak4114
->capture_substream
= cap_substream
;
483 for (idx
= 0; idx
< AK4114_CONTROLS
; idx
++) {
484 kctl
= snd_ctl_new1(&snd_ak4114_iec958_controls
[idx
], ak4114
);
487 if (strstr(kctl
->id
.name
, "Playback")) {
488 if (ply_substream
== NULL
) {
489 snd_ctl_free_one(kctl
);
490 ak4114
->kctls
[idx
] = NULL
;
493 kctl
->id
.device
= ply_substream
->pcm
->device
;
494 kctl
->id
.subdevice
= ply_substream
->number
;
496 kctl
->id
.device
= cap_substream
->pcm
->device
;
497 kctl
->id
.subdevice
= cap_substream
->number
;
499 err
= snd_ctl_add(ak4114
->card
, kctl
);
502 ak4114
->kctls
[idx
] = kctl
;
504 snd_ak4114_proc_init(ak4114
);
506 schedule_delayed_work(&ak4114
->work
, HZ
/ 10);
509 EXPORT_SYMBOL(snd_ak4114_build
);
511 /* notify kcontrols if any parameters are changed */
512 static void ak4114_notify(struct ak4114
*ak4114
,
513 unsigned char rcs0
, unsigned char rcs1
,
514 unsigned char c0
, unsigned char c1
)
516 if (!ak4114
->kctls
[0])
519 if (rcs0
& AK4114_PAR
)
520 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
521 &ak4114
->kctls
[0]->id
);
523 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
524 &ak4114
->kctls
[1]->id
);
525 if (rcs1
& AK4114_CCRC
)
526 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
527 &ak4114
->kctls
[2]->id
);
528 if (rcs1
& AK4114_QCRC
)
529 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
530 &ak4114
->kctls
[3]->id
);
534 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
535 &ak4114
->kctls
[4]->id
);
537 if ((c0
& AK4114_PEM
) | (c0
& AK4114_CINT
))
538 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
539 &ak4114
->kctls
[9]->id
);
540 if (c0
& AK4114_QINT
)
541 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
542 &ak4114
->kctls
[10]->id
);
544 if (c0
& AK4114_AUDION
)
545 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
546 &ak4114
->kctls
[11]->id
);
547 if (c0
& AK4114_AUTO
)
548 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
549 &ak4114
->kctls
[12]->id
);
550 if (c0
& AK4114_DTSCD
)
551 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
552 &ak4114
->kctls
[13]->id
);
553 if (c0
& AK4114_UNLCK
)
554 snd_ctl_notify(ak4114
->card
, SNDRV_CTL_EVENT_MASK_VALUE
,
555 &ak4114
->kctls
[14]->id
);
558 int snd_ak4114_external_rate(struct ak4114
*ak4114
)
562 rcs1
= reg_read(ak4114
, AK4114_REG_RCS1
);
563 return external_rate(rcs1
);
565 EXPORT_SYMBOL(snd_ak4114_external_rate
);
567 int snd_ak4114_check_rate_and_errors(struct ak4114
*ak4114
, unsigned int flags
)
569 struct snd_pcm_runtime
*runtime
= ak4114
->capture_substream
? ak4114
->capture_substream
->runtime
: NULL
;
570 unsigned long _flags
;
572 unsigned char rcs0
, rcs1
;
573 unsigned char c0
, c1
;
575 rcs1
= reg_read(ak4114
, AK4114_REG_RCS1
);
576 if (flags
& AK4114_CHECK_NO_STAT
)
578 rcs0
= reg_read(ak4114
, AK4114_REG_RCS0
);
579 spin_lock_irqsave(&ak4114
->lock
, _flags
);
580 if (rcs0
& AK4114_PAR
)
581 ak4114
->parity_errors
++;
583 ak4114
->v_bit_errors
++;
584 if (rcs1
& AK4114_CCRC
)
585 ak4114
->ccrc_errors
++;
586 if (rcs1
& AK4114_QCRC
)
587 ak4114
->qcrc_errors
++;
588 c0
= (ak4114
->rcs0
& (AK4114_QINT
| AK4114_CINT
| AK4114_PEM
| AK4114_AUDION
| AK4114_AUTO
| AK4114_UNLCK
)) ^
589 (rcs0
& (AK4114_QINT
| AK4114_CINT
| AK4114_PEM
| AK4114_AUDION
| AK4114_AUTO
| AK4114_UNLCK
));
590 c1
= (ak4114
->rcs1
& 0xf0) ^ (rcs1
& 0xf0);
591 ak4114
->rcs0
= rcs0
& ~(AK4114_QINT
| AK4114_CINT
);
593 spin_unlock_irqrestore(&ak4114
->lock
, _flags
);
595 ak4114_notify(ak4114
, rcs0
, rcs1
, c0
, c1
);
596 if (ak4114
->change_callback
&& (c0
| c1
) != 0)
597 ak4114
->change_callback(ak4114
, c0
, c1
);
601 res
= external_rate(rcs1
);
602 if (!(flags
& AK4114_CHECK_NO_RATE
) && runtime
&& runtime
->rate
!= res
) {
603 snd_pcm_stream_lock_irqsave(ak4114
->capture_substream
, _flags
);
604 if (snd_pcm_running(ak4114
->capture_substream
)) {
605 // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res);
606 snd_pcm_stop(ak4114
->capture_substream
, SNDRV_PCM_STATE_DRAINING
);
609 snd_pcm_stream_unlock_irqrestore(ak4114
->capture_substream
, _flags
);
613 EXPORT_SYMBOL(snd_ak4114_check_rate_and_errors
);
615 static void ak4114_stats(struct work_struct
*work
)
617 struct ak4114
*chip
= container_of(work
, struct ak4114
, work
.work
);
619 if (atomic_inc_return(&chip
->wq_processing
) == 1)
620 snd_ak4114_check_rate_and_errors(chip
, chip
->check_flags
);
621 if (atomic_dec_and_test(&chip
->wq_processing
))
622 schedule_delayed_work(&chip
->work
, HZ
/ 10);
626 void snd_ak4114_suspend(struct ak4114
*chip
)
628 atomic_inc(&chip
->wq_processing
); /* don't schedule new work */
629 cancel_delayed_work_sync(&chip
->work
);
631 EXPORT_SYMBOL(snd_ak4114_suspend
);
633 void snd_ak4114_resume(struct ak4114
*chip
)
635 atomic_dec(&chip
->wq_processing
);
636 snd_ak4114_reinit(chip
);
638 EXPORT_SYMBOL(snd_ak4114_resume
);