21 #include <linux/kernel.h>
23 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
74 #ifdef CONFIG_SND_DEBUG_VERBOSE
77 #define verbose_debug(fmt, args...) \
78 do { if (debug > 1) printk(KERN_DEBUG SFX fmt, ##args); } while (0)
80 #define verbose_debug(fmt, args...)
87 static int corb_send_verb(
struct lola *
chip,
unsigned int nid,
88 unsigned int verb,
unsigned int data,
98 data |= (nid << 20) | (verb << 8);
102 unsigned int wp = chip->
corb.wp + 1;
112 spin_unlock_irqrestore(&chip->
reg_lock, flags);
116 static void lola_queue_unsol_event(
struct lola *
chip,
unsigned int res,
123 static void lola_update_rirb(
struct lola *
chip)
129 if (wp == chip->
rirb.wp)
133 while (chip->
rirb.rp != wp) {
137 rp = chip->
rirb.rp << 1;
141 lola_queue_unsol_event(chip, res, res_ex);
142 else if (chip->
rirb.cmds) {
151 static int rirb_get_response(
struct lola *chip,
unsigned int *
val,
152 unsigned int *extval)
161 lola_update_rirb(chip);
164 if (!chip->
rirb.cmds) {
172 "NID=%x, verb=%x, data=%x, ext=%x\n",
196 unsigned int data,
unsigned int extdata)
198 verbose_debug(
"codec_write NID=%x, verb=%x, data=%x, ext=%x\n",
199 nid, verb, data, extdata);
200 return corb_send_verb(chip, nid, verb, data, extdata);
205 unsigned int data,
unsigned int extdata,
206 unsigned int *val,
unsigned int *extval)
210 verbose_debug(
"codec_read NID=%x, verb=%x, data=%x, ext=%x\n",
211 nid, verb, data, extdata);
212 err = corb_send_verb(chip, nid, verb, data, extdata);
215 err = rirb_get_response(chip, val, extval);
223 return rirb_get_response(chip, &tmp,
NULL);
232 unsigned int notify_ins, notify_outs, error_ins, error_outs;
236 notify_ins = notify_outs = error_ins = error_outs = 0;
239 unsigned int status, in_sts, out_sts;
243 if (!status || status == -1)
250 for (i = 0; in_sts && i < chip->
pcm[
CAPT].num_streams; i++) {
251 if (!(in_sts & (1 << i)))
256 error_ins |= (1 <<
i);
258 notify_ins |= (1 <<
i);
264 for (i = 0; out_sts && i < chip->
pcm[
PLAY].num_streams; i++) {
265 if (!(out_sts & (1 << i)))
267 out_sts &= ~(1 <<
i);
269 if (reg & LOLA_DSD_STS_DESE)
270 error_outs |= (1 <<
i);
272 notify_outs |= (1 <<
i);
287 lola_update_rirb(chip);
309 static int reset_controller(
struct lola *chip)
312 unsigned long end_time;
336 static void lola_irq_enable(
struct lola *chip)
341 val = (1 << chip->
pcm[
PLAY].num_streams) - 1;
343 val = (1 << chip->
pcm[
CAPT].num_streams) - 1;
352 static void lola_irq_disable(
struct lola *chip)
359 static int setup_corb_rirb(
struct lola *chip)
363 unsigned long end_time;
371 chip->
corb.addr = chip->
rb.addr;
373 chip->
rirb.addr = chip->
rb.addr + 2048;
374 chip->
rirb.buf = (
u32 *)(chip->
rb.area + 2048);
420 chip->
rirb.rp = chip->
rirb.cmds = 0;
425 static void stop_corb_rirb(
struct lola *chip)
432 static void lola_reset_setups(
struct lola *chip)
529 lola_reset_setups(chip);
540 static void lola_stop_hw(
struct lola *chip)
542 stop_corb_rirb(chip);
543 lola_irq_disable(chip);
546 static void lola_free(
struct lola *chip)
554 if (chip->
bar[0].remap_addr)
556 if (chip->
bar[1].remap_addr)
578 .dev_free = lola_dev_free,
613 "Invalid granularity %d, reset to %d\n",
622 "Invalid sample_rate_min %d, reset to 16000\n",
638 if (!chip->
bar[0].remap_addr || !chip->
bar[1].remap_addr) {
646 err = reset_controller(chip);
651 KBUILD_MODNAME, chip)) {
660 chip->
pcm[
CAPT].num_streams = (dever >> 0) & 0x3ff;
661 chip->
pcm[
PLAY].num_streams = (dever >> 10) & 0x3ff;
662 chip->
version = (dever >> 24) & 0xff;
670 (!chip->
pcm[
CAPT].num_streams &&
671 !chip->
pcm[
PLAY].num_streams)) {
677 err = setup_corb_rirb(chip);
690 "%s at 0x%lx irq %i",
694 lola_irq_enable(chip);
728 err = lola_create(card, pci, dev, &chip);
733 err = lola_parse_tree(chip);
751 pci_set_drvdata(pci, card);
762 pci_set_drvdata(pci,
NULL);
774 .name = KBUILD_MODNAME,
775 .id_table = lola_ids,