/* * Do the necessary ALSA-level cleanup to deallocate our driver ... */ static void soundscape_free(snd_card_t * c) { register struct soundscape *sscape = get_card_soundscape(c); release_resource(sscape->io_res); kfree_nocheck(sscape->io_res); free_dma(sscape->chip->dma1); }
/* * Initialse an MPU-401 subdevice for MIDI support on the SoundScape. */ static int __devinit create_mpu401(snd_card_t * card, int devnum, unsigned long port, int irq) { struct soundscape *sscape = get_card_soundscape(card); snd_rawmidi_t *rawmidi; int err; #define MPU401_SHARE_HARDWARE 1 if ((err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port, MPU401_SHARE_HARDWARE, irq, SA_INTERRUPT, &rawmidi)) == 0) { mpu401_t *mpu = (mpu401_t *) rawmidi->private_data; mpu->open_input = mpu401_open; mpu->open_output = mpu401_open; mpu->close_input = mpu401_close; mpu->close_output = mpu401_close; mpu->private_data = sscape; sscape->mpu = mpu; initialise_mpu401(mpu); } return err; }
static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev) { struct snd_card *card; struct soundscape *sscape; int ret; card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct soundscape)); if (!card) return -ENOMEM; sscape = get_card_soundscape(card); sscape->type = SSCAPE; dma[dev] &= 0x03; ret = create_sscape(dev, card); if (ret < 0) goto _release_card; snd_card_set_dev(card, pdev); if ((ret = snd_card_register(card)) < 0) { printk(KERN_ERR "sscape: Failed to register sound card\n"); goto _release_card; } dev_set_drvdata(pdev, card); return 0; _release_card: snd_card_free(card); return ret; }
/* * Do the necessary ALSA-level cleanup to deallocate our driver ... */ static void soundscape_free(struct snd_card *c) { struct soundscape *sscape = get_card_soundscape(c); release_and_free_resource(sscape->io_res); release_and_free_resource(sscape->wss_res); free_dma(sscape->chip->dma1); }
static int sscape_midi_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct snd_wss *chip = snd_kcontrol_chip(kctl); struct snd_card *card = chip->card; register struct soundscape *s = get_card_soundscape(card); unsigned long flags; spin_lock_irqsave(&s->lock, flags); uctl->value.integer.value[0] = s->midi_vol; spin_unlock_irqrestore(&s->lock, flags); return 0; }
static int sscape_midi_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct snd_cs4231 *chip = snd_kcontrol_chip(kctl); struct snd_card *card = chip->card; register struct soundscape *s = get_card_soundscape(card); unsigned long flags; spin_lock_irqsave(&s->lock, flags); set_host_mode_unsafe(s->io_base); if (host_write_ctrl_unsafe(s->io_base, CMD_GET_MIDI_VOL, 100)) { uctl->value.integer.value[0] = host_read_ctrl_unsafe(s->io_base, 100); } set_midi_mode_unsafe(s->io_base); spin_unlock_irqrestore(&s->lock, flags); return 0; }
static int sscape_midi_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct snd_wss *chip = snd_kcontrol_chip(kctl); struct snd_card *card = chip->card; register struct soundscape *s = get_card_soundscape(card); unsigned long flags; int change; spin_lock_irqsave(&s->lock, flags); /* * We need to put the board into HOST mode before we * can send any volume-changing HOST commands ... */ set_host_mode_unsafe(s->io_base); /* * To successfully change the MIDI volume setting, you seem to * have to write a volume command, write the new volume value, * and then perform another volume-related command. Perhaps the * first command is an "open" and the second command is a "close"? */ if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) { change = 0; goto __skip_change; } change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100) && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)); s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127; __skip_change: /* * Take the board out of HOST mode and back into MIDI mode ... */ set_midi_mode_unsafe(s->io_base); spin_unlock_irqrestore(&s->lock, flags); return change; }
/* * Initialse an MPU-401 subdevice for MIDI support on the SoundScape. */ static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq) { struct soundscape *sscape = get_card_soundscape(card); struct snd_rawmidi *rawmidi; int err; if ((err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port, MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED, &rawmidi)) == 0) { struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data; mpu->open_input = mpu401_open; mpu->open_output = mpu401_open; mpu->close_input = mpu401_close; mpu->close_output = mpu401_close; mpu->private_data = sscape; sscape->mpu = mpu; initialise_mpu401(mpu); } return err; }
/* * Create an AD1845 PCM subdevice on the SoundScape. The AD1845 * is very much like a CS4231, with a few extra bits. We will * try to support at least some of the extra bits by overriding * some of the CS4231 callback. */ static int __devinit create_ad1845(struct snd_card *card, unsigned port, int irq, int dma1) { register struct soundscape *sscape = get_card_soundscape(card); struct snd_cs4231 *chip; int err; #define CS4231_SHARE_HARDWARE (CS4231_HWSHARE_DMA1 | CS4231_HWSHARE_DMA2) /* * The AD1845 PCM device is only half-duplex, and so * we only give it one DMA channel ... */ if ((err = snd_cs4231_create(card, port, -1, irq, dma1, dma1, CS4231_HW_DETECT, CS4231_HWSHARE_DMA1, &chip)) == 0) { unsigned long flags; struct snd_pcm *pcm; #define AD1845_FREQ_SEL_ENABLE 0x08 #define AD1845_PWR_DOWN_CTRL 0x1b #define AD1845_CRYS_CLOCK_SEL 0x1d /* * It turns out that the PLAYBACK_ENABLE bit is set * by the lowlevel driver ... * #define AD1845_IFACE_CONFIG \ (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE) snd_cs4231_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_cs4231_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_cs4231_mce_down(chip); */ /* * The input clock frequency on the SoundScape must * be 14.31818 MHz, because we must set this register * to get the playback to sound correct ... */ snd_cs4231_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_cs4231_out(chip, AD1845_CRYS_CLOCK_SEL, 0x20); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_cs4231_mce_down(chip); /* * More custom configuration: * a) select "mode 2", and provide a current drive of 8 mA * b) enable frequency selection (for capture/playback) */ spin_lock_irqsave(&chip->reg_lock, flags); snd_cs4231_out(chip, CS4231_MISC_INFO, (CS4231_MODE2 | 0x10)); snd_cs4231_out(chip, AD1845_PWR_DOWN_CTRL, snd_cs4231_in(chip, AD1845_PWR_DOWN_CTRL) | AD1845_FREQ_SEL_ENABLE); spin_unlock_irqrestore(&chip->reg_lock, flags); if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) { snd_printk(KERN_ERR "sscape: No PCM device for AD1845 chip\n"); goto _error; } if ((err = snd_cs4231_mixer(chip)) < 0) { snd_printk(KERN_ERR "sscape: No mixer device for AD1845 chip\n"); goto _error; } if ((err = snd_ctl_add(card, snd_ctl_new1(&midi_mixer_ctl, chip))) < 0) { snd_printk(KERN_ERR "sscape: Could not create MIDI mixer control\n"); goto _error; } strcpy(card->driver, "SoundScape"); strcpy(card->shortname, pcm->name); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, IRQ %d, DMA %d\n", pcm->name, chip->port, chip->irq, chip->dma1); chip->set_playback_format = ad1845_playback_format; chip->set_capture_format = ad1845_capture_format; sscape->chip = chip; } _error: return err; }
/* * Create an ALSA soundcard entry for the SoundScape, using * the given list of port, IRQ and DMA resources. */ static int __devinit create_sscape(int dev, struct snd_card **rcardp) { struct snd_card *card; register struct soundscape *sscape; register unsigned dma_cfg; unsigned irq_cfg; unsigned mpu_irq_cfg; unsigned xport; struct resource *io_res; unsigned long flags; int err; /* * Check that the user didn't pass us garbage data ... */ irq_cfg = get_irq_config(irq[dev]); if (irq_cfg == INVALID_IRQ) { snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]); return -ENXIO; } mpu_irq_cfg = get_irq_config(mpu_irq[dev]); if (mpu_irq_cfg == INVALID_IRQ) { printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); return -ENXIO; } xport = port[dev]; /* * Grab IO ports that we will need to probe so that we * can detect and control this hardware ... */ if ((io_res = request_region(xport, 8, "SoundScape")) == NULL) { snd_printk(KERN_ERR "sscape: can't grab port 0x%x\n", xport); return -EBUSY; } /* * Grab both DMA channels (OK, only one for now) ... */ if ((err = request_dma(dma[dev], "SoundScape")) < 0) { snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]); goto _release_region; } /* * Create a new ALSA sound card entry, in anticipation * of detecting our hardware ... */ if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct soundscape))) == NULL) { err = -ENOMEM; goto _release_dma; } sscape = get_card_soundscape(card); spin_lock_init(&sscape->lock); spin_lock_init(&sscape->fwlock); sscape->io_res = io_res; sscape->io_base = xport; if (!detect_sscape(sscape)) { printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base); err = -ENODEV; goto _release_card; } printk(KERN_INFO "sscape: hardware detected at 0x%x, using IRQ %d, DMA %d\n", sscape->io_base, irq[dev], dma[dev]); /* * Now create the hardware-specific device so that we can * load the microcode into the on-board processor. * We cannot use the MPU-401 MIDI system until this firmware * has been loaded into the card. */ if ((err = snd_hwdep_new(card, "MC68EC000", 0, &(sscape->hw))) < 0) { printk(KERN_ERR "sscape: Failed to create firmware device\n"); goto _release_card; } strlcpy(sscape->hw->name, "SoundScape M68K", sizeof(sscape->hw->name)); sscape->hw->name[sizeof(sscape->hw->name) - 1] = '\0'; sscape->hw->iface = SNDRV_HWDEP_IFACE_SSCAPE; sscape->hw->ops.open = sscape_hw_open; sscape->hw->ops.release = sscape_hw_release; sscape->hw->ops.ioctl = sscape_hw_ioctl; sscape->hw->private_data = sscape; /* * Tell the on-board devices where their resources are (I think - * I can't be sure without a datasheet ... So many magic values!) */ spin_lock_irqsave(&sscape->lock, flags); activate_ad1845_unsafe(sscape->io_base); sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */ sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); /* * Enable and configure the DMA channels ... */ sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); dma_cfg = (sscape->ic_type == IC_ODIE ? 0x70 : 0x40); sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | (mpu_irq_cfg << 2) | mpu_irq_cfg); sscape_write_unsafe(sscape->io_base, GA_CDCFG_REG, 0x09 | DMA_8BIT | (dma[dev] << 4) | (irq_cfg << 1)); spin_unlock_irqrestore(&sscape->lock, flags); /* * We have now enabled the codec chip, and so we should * detect the AD1845 device ... */ if ((err = create_ad1845(card, CODEC_IO(xport), irq[dev], dma[dev])) < 0) { printk(KERN_ERR "sscape: No AD1845 device at 0x%x, IRQ %d\n", CODEC_IO(xport), irq[dev]); goto _release_card; } #define MIDI_DEVNUM 0 if ((err = create_mpu401(card, MIDI_DEVNUM, MPU401_IO(xport), mpu_irq[dev])) < 0) { printk(KERN_ERR "sscape: Failed to create MPU-401 device at 0x%x\n", MPU401_IO(xport)); goto _release_card; } /* * Enable the master IRQ ... */ sscape_write(sscape, GA_INTENA_REG, 0x80); /* * Initialize mixer */ sscape->midi_vol = 0; host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100); host_write_ctrl_unsafe(sscape->io_base, 0, 100); host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100); /* * Now that we have successfully created this sound card, * it is safe to store the pointer. * NOTE: we only register the sound card's "destructor" * function now that our "constructor" has completed. */ card->private_free = soundscape_free; *rcardp = card; return 0; _release_card: snd_card_free(card); _release_dma: free_dma(dma[dev]); _release_region: release_and_free_resource(io_res); return err; }
static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard, const struct pnp_card_device_id *pid) { static int idx = 0; struct pnp_dev *dev; struct snd_card *card; struct soundscape *sscape; int ret; /* * Allow this function to fail *quietly* if all the ISA PnP * devices were configured using module parameters instead. */ if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS) return -ENOSPC; /* * We have found a candidate ISA PnP card. Now we * have to check that it has the devices that we * expect it to have. * * We will NOT try and autoconfigure all of the resources * needed and then activate the card as we are assuming that * has already been done at boot-time using /proc/isapnp. * We shall simply try to give each active card the resources * that it wants. This is a sensible strategy for a modular * system where unused modules are unloaded regularly. * * This strategy is utterly useless if we compile the driver * into the kernel, of course. */ // printk(KERN_INFO "sscape: %s\n", card->name); /* * Check that we still have room for another sound card ... */ dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); if (! dev) return -ENODEV; if (!pnp_is_active(dev)) { if (pnp_activate_dev(dev) < 0) { printk(KERN_INFO "sscape: device is inactive\n"); return -EBUSY; } } /* * Create a new ALSA sound card entry, in anticipation * of detecting our hardware ... */ card = snd_card_new(index[idx], id[idx], THIS_MODULE, sizeof(struct soundscape)); if (!card) return -ENOMEM; sscape = get_card_soundscape(card); /* * Identify card model ... */ if (!strncmp("ENS4081", pid->id, 7)) sscape->type = SSCAPE_VIVO; else sscape->type = SSCAPE_PNP; /* * Read the correct parameters off the ISA PnP bus ... */ port[idx] = pnp_port_start(dev, 0); irq[idx] = pnp_irq(dev, 0); mpu_irq[idx] = pnp_irq(dev, 1); dma[idx] = pnp_dma(dev, 0) & 0x03; if (sscape->type == SSCAPE_PNP) { dma2[idx] = dma[idx]; wss_port[idx] = CODEC_IO(port[idx]); } else { wss_port[idx] = pnp_port_start(dev, 1); dma2[idx] = pnp_dma(dev, 1); } ret = create_sscape(idx, card); if (ret < 0) goto _release_card; snd_card_set_dev(card, &pcard->card->dev); if ((ret = snd_card_register(card)) < 0) { printk(KERN_ERR "sscape: Failed to register sound card\n"); goto _release_card; } pnp_set_card_drvdata(pcard, card); ++idx; return 0; _release_card: snd_card_free(card); return ret; }
/* * Create an AD1845 PCM subdevice on the SoundScape. The AD1845 * is very much like a CS4231, with a few extra bits. We will * try to support at least some of the extra bits by overriding * some of the CS4231 callback. */ static int __devinit create_ad1845(struct snd_card *card, unsigned port, int irq, int dma1, int dma2) { register struct soundscape *sscape = get_card_soundscape(card); struct snd_wss *chip; int err; if (sscape->type == SSCAPE_VIVO) port += 4; if (dma1 == dma2) dma2 = -1; err = snd_wss_create(card, port, -1, irq, dma1, dma2, WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip); if (!err) { unsigned long flags; struct snd_pcm *pcm; #define AD1845_FREQ_SEL_ENABLE 0x08 #define AD1845_PWR_DOWN_CTRL 0x1b #define AD1845_CRYS_CLOCK_SEL 0x1d /* * It turns out that the PLAYBACK_ENABLE bit is set * by the lowlevel driver ... * #define AD1845_IFACE_CONFIG \ (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE) snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); */ if (sscape->type != SSCAPE_VIVO) { int val; /* * The input clock frequency on the SoundScape must * be 14.31818 MHz, because we must set this register * to get the playback to sound correct ... */ snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_wss_out(chip, AD1845_CRYS_CLOCK_SEL, 0x20); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); /* * More custom configuration: * a) select "mode 2" and provide a current drive of 8mA * b) enable frequency selection (for capture/playback) */ spin_lock_irqsave(&chip->reg_lock, flags); snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2 | 0x10); val = snd_wss_in(chip, AD1845_PWR_DOWN_CTRL); snd_wss_out(chip, AD1845_PWR_DOWN_CTRL, val | AD1845_FREQ_SEL_ENABLE); spin_unlock_irqrestore(&chip->reg_lock, flags); } err = snd_wss_pcm(chip, 0, &pcm); if (err < 0) { snd_printk(KERN_ERR "sscape: No PCM device " "for AD1845 chip\n"); goto _error; } err = snd_wss_mixer(chip); if (err < 0) { snd_printk(KERN_ERR "sscape: No mixer device " "for AD1845 chip\n"); goto _error; } err = snd_wss_timer(chip, 0, NULL); if (err < 0) { snd_printk(KERN_ERR "sscape: No timer device " "for AD1845 chip\n"); goto _error; } if (sscape->type != SSCAPE_VIVO) { err = snd_ctl_add(card, snd_ctl_new1(&midi_mixer_ctl, chip)); if (err < 0) { snd_printk(KERN_ERR "sscape: Could not create " "MIDI mixer control\n"); goto _error; } chip->set_playback_format = ad1845_playback_format; chip->set_capture_format = ad1845_capture_format; } strcpy(card->driver, "SoundScape"); strcpy(card->shortname, pcm->name); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n", pcm->name, chip->port, chip->irq, chip->dma1, chip->dma2); sscape->chip = chip; } _error: return err; }
/* * Create an AD1845 PCM subdevice on the SoundScape. The AD1845 * is very much like a CS4231, with a few extra bits. We will * try to support at least some of the extra bits by overriding * some of the CS4231 callback. */ static int __devinit create_ad1845(struct snd_card *card, unsigned port, int irq, int dma1, int dma2) { register struct soundscape *sscape = get_card_soundscape(card); struct snd_wss *chip; int err; if (sscape->type == SSCAPE_VIVO) port += 4; if (dma1 == dma2) dma2 = -1; err = snd_wss_create(card, port, -1, irq, dma1, dma2, WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip); if (!err) { unsigned long flags; struct snd_pcm *pcm; /* * It turns out that the PLAYBACK_ENABLE bit is set * by the lowlevel driver ... * #define AD1845_IFACE_CONFIG \ (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE) snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); */ if (sscape->type != SSCAPE_VIVO) { /* * The input clock frequency on the SoundScape must * be 14.31818 MHz, because we must set this register * to get the playback to sound correct ... */ snd_wss_mce_up(chip); spin_lock_irqsave(&chip->reg_lock, flags); snd_wss_out(chip, AD1845_CLOCK, 0x20); spin_unlock_irqrestore(&chip->reg_lock, flags); snd_wss_mce_down(chip); } err = snd_wss_pcm(chip, 0, &pcm); if (err < 0) { snd_printk(KERN_ERR "sscape: No PCM device " "for AD1845 chip\n"); goto _error; } err = snd_wss_mixer(chip); if (err < 0) { snd_printk(KERN_ERR "sscape: No mixer device " "for AD1845 chip\n"); goto _error; } if (chip->hardware != WSS_HW_AD1848) { err = snd_wss_timer(chip, 0, NULL); if (err < 0) { snd_printk(KERN_ERR "sscape: No timer device " "for AD1845 chip\n"); goto _error; } } if (sscape->type != SSCAPE_VIVO) { err = snd_ctl_add(card, snd_ctl_new1(&midi_mixer_ctl, chip)); if (err < 0) { snd_printk(KERN_ERR "sscape: Could not create " "MIDI mixer control\n"); goto _error; } } strcpy(card->driver, "SoundScape"); strcpy(card->shortname, pcm->name); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n", pcm->name, chip->port, chip->irq, chip->dma1, chip->dma2); sscape->chip = chip; } _error: return err; }