static int __init maui_init(int irq) { unsigned char bits; switch (irq) { case 9: bits = 0x00; break; case 5: bits = 0x08; break; case 12: bits = 0x10; break; case 15: bits = 0x18; break; default: printk(KERN_ERR "Maui: Invalid IRQ %d\n", irq); return 0; } outb((0x00), HOST_CTRL_PORT); /* Reset */ outb((bits), HOST_DATA_PORT); /* Set the IRQ bits */ outb((bits | 0x80), HOST_DATA_PORT); /* Set the IRQ bits again? */ outb((0x80), HOST_CTRL_PORT); /* Leave reset */ outb((0x80), HOST_CTRL_PORT); /* Leave reset */ outb((0xD0), HOST_CTRL_PORT); /* Cause interrupt */ #ifdef CONFIG_SMP { int i; for (i = 0; i < 1000000 && !irq_ok; i++) ; if (!irq_ok) return 0; } #endif outb((0x80), HOST_CTRL_PORT); /* Leave reset */ printk(KERN_INFO "Turtle Beach Maui initialization\n"); if (!download_code()) return 0; outb((0xE0), HOST_CTRL_PORT); /* Normal operation */ /* Select mpu401 mode */ maui_write(0xf0); maui_write(1); if (maui_read() != 0x80) { maui_write(0xf0); maui_write(1); if (maui_read() != 0x80) printk(KERN_ERR "Maui didn't acknowledge set HW mode command\n"); } printk(KERN_INFO "Maui initialized OK\n"); return 1; }
static int maui_load_patch(int dev, int format, const char __user *addr, int offs, int count, int pmgr_flag) { struct sysex_info header; unsigned long left, src_offs; int hdr_size = (unsigned long) &header.data[0] - (unsigned long) &header; int i; if (format == SYSEX_PATCH) /* Handled by midi_synth.c */ return orig_load_patch(dev, format, addr, offs, count, pmgr_flag); if (format != MAUI_PATCH) { printk(KERN_WARNING "Maui: Unknown patch format\n"); } if (count < hdr_size) { /* printk("Maui error: Patch header too short\n");*/ return -EINVAL; } count -= hdr_size; /* * Copy the header from user space but ignore the first bytes which have * been transferred already. */ if(copy_from_user(&((char *) &header)[offs], &(addr)[offs], hdr_size - offs)) return -EFAULT; if (count < header.len) { printk(KERN_ERR "Maui warning: Host command record too short (%d<%d)\n", count, (int) header.len); header.len = count; } left = header.len; src_offs = 0; for (i = 0; i < left; i++) { unsigned char data; if(get_user(*(unsigned char *) &data, (unsigned char __user *) &((addr)[hdr_size + i]))) return -EFAULT; if (i == 0 && !(data & 0x80)) return -EINVAL; if (maui_write(data) == -1) return -EIO; } if ((i = maui_read()) != 0x80) { if (i != -1) printk("Maui: Error status %02x\n", i); return -EIO; } return 0; }
static int __init probe_maui(struct address_info *hw_config) { struct resource *ports; int this_dev; int i; int tmp1, tmp2, ret; ports = request_region(hw_config->io_base, 2, "mpu401"); if (!ports) return 0; if (!request_region(hw_config->io_base + 2, 6, "Maui")) goto out; maui_base = hw_config->io_base; maui_osp = hw_config->osp; if (request_irq(hw_config->irq, mauiintr, 0, "Maui", NULL) < 0) goto out2; /* * Initialize the processor if necessary */ if (maui_osLen > 0) { if (!(inb(HOST_STAT_PORT) & STAT_TX_AVAIL) || !maui_write(0x9F) || /* Report firmware version */ !maui_short_wait(STAT_RX_AVAIL) || maui_read() == -1 || maui_read() == -1) if (!maui_init(hw_config->irq)) goto out3; } if (!maui_write(0xCF)) /* Report hardware version */ { printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n"); goto out3; } if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) { printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n"); goto out3; } if (tmp1 == 0xff || tmp2 == 0xff) goto out3; printk(KERN_DEBUG "WaveFront hardware version %d.%d\n", tmp1, tmp2); if (!maui_write(0x9F)) /* Report firmware version */ goto out3; if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) goto out3; printk(KERN_DEBUG "WaveFront firmware version %d.%d\n", tmp1, tmp2); if (!maui_write(0x85)) /* Report free DRAM */ goto out3; tmp1 = 0; for (i = 0; i < 4; i++) { tmp1 |= maui_read() << (7 * i); } printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024); for (i = 0; i < 1000; i++) if (probe_mpu401(hw_config, ports)) break; ret = probe_mpu401(hw_config, ports); if (!ret) goto out3; conf_printf("Maui", hw_config); hw_config->irq *= -1; hw_config->name = "Maui"; attach_mpu401(hw_config, THIS_MODULE); if (hw_config->slots[1] != -1) /* The MPU401 driver installed itself */ { struct synth_operations *synth; this_dev = hw_config->slots[1]; /* * Intercept patch loading calls so that they can be handled * by the Maui driver. */ synth = midi_devs[this_dev]->converter; if (synth != NULL) { synth->id = "MAUI"; orig_load_patch = synth->load_patch; synth->load_patch = &maui_load_patch; } else printk(KERN_ERR "Maui: Can't install patch loader\n"); } return 1; out3: free_irq(hw_config->irq, NULL); out2: release_region(hw_config->io_base + 2, 6); out: release_region(hw_config->io_base, 2); return 0; }
static int __init probe_maui(struct address_info *hw_config) { int i; int tmp1, tmp2, ret; if (check_region(hw_config->io_base, 8)) return 0; maui_base = hw_config->io_base; maui_osp = hw_config->osp; if (request_irq(hw_config->irq, mauiintr, 0, "Maui", NULL) < 0) return 0; /* * Initialize the processor if necessary */ if (maui_osLen > 0) { if (!(inb(HOST_STAT_PORT) & STAT_TX_AVAIL) || !maui_write(0x9F) || /* Report firmware version */ !maui_short_wait(STAT_RX_AVAIL) || maui_read() == -1 || maui_read() == -1) if (!maui_init(hw_config->irq)) { free_irq(hw_config->irq, NULL); return 0; } } if (!maui_write(0xCF)) /* Report hardware version */ { printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n"); free_irq(hw_config->irq, NULL); return 0; } if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) { printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n"); free_irq(hw_config->irq, NULL); return 0; } if (tmp1 == 0xff || tmp2 == 0xff) { free_irq(hw_config->irq, NULL); return 0; } printk(KERN_DEBUG "WaveFront hardware version %d.%d\n", tmp1, tmp2); if (!maui_write(0x9F)) /* Report firmware version */ return 0; if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) return 0; printk(KERN_DEBUG "WaveFront firmware version %d.%d\n", tmp1, tmp2); if (!maui_write(0x85)) /* Report free DRAM */ return 0; tmp1 = 0; for (i = 0; i < 4; i++) { tmp1 |= maui_read() << (7 * i); } printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024); for (i = 0; i < 1000; i++) if (probe_mpu401(hw_config)) break; ret = probe_mpu401(hw_config); if (ret) request_region(hw_config->io_base + 2, 6, "Maui"); return ret; }