⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sscape.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	set_host_mode_unsafe(s->io_base);	/*	 * Boot the board ... (I think)	 */	sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40);	spin_unlock_irqrestore(&s->lock, flags);	/*	 * If all has gone well, then the board should acknowledge	 * the new upload and tell us that it has rebooted OK. We	 * give it 5 seconds (max) ...	 */	ret = 0;	if (!obp_startup_ack(s, 5)) {		snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n");		ret = -EAGAIN;	} else if (!host_startup_ack(s, 5)) {		snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n");		ret = -EAGAIN;	}_release_dma:	/*	 * NOTE!!! We are NOT holding any spinlocks at this point !!!	 */	sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_ODIE ? 0x70 : 0x40));	free_dmabuf(&dma);	return ret;}/* * Upload the bootblock(?) into the SoundScape. The only * purpose of this block of code seems to be to tell * us which version of the microcode we should be using. * * NOTE: The boot-block data resides in USER-SPACE!!! *       However, we have already verified its memory *       addresses by the time we get here. */static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb){	unsigned long flags;	int data = 0;	int ret;	ret = upload_dma_data(sscape, bb->code, sizeof(bb->code));	spin_lock_irqsave(&sscape->lock, flags);	if (ret == 0) {		data = host_read_ctrl_unsafe(sscape->io_base, 100);	}	set_midi_mode_unsafe(sscape->io_base);	spin_unlock_irqrestore(&sscape->lock, flags);	if (ret == 0) {		if (data < 0) {			snd_printk(KERN_ERR "sscape: timeout reading firmware version\n");			ret = -EAGAIN;		}		else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) {			ret = -EFAULT;		}	}	return ret;}/* * Upload the microcode into the SoundScape. The * microcode is 64K of data, and if we try to copy * it into a local variable then we will SMASH THE * KERNEL'S STACK! We therefore leave it in USER * SPACE, and save ourselves from copying it at all. */static int sscape_upload_microcode(struct soundscape *sscape,                                   const struct sscape_microcode __user *mc){	unsigned long flags;	char __user *code;	int err;	/*	 * We are going to have to copy this data into a special	 * DMA-able buffer before we can upload it. We shall therefore	 * just check that the data pointer is valid for now.	 *	 * NOTE: This buffer is 64K long! That's WAY too big to	 *       copy into a stack-temporary anyway.	 */	if ( get_user(code, &mc->code) ||	     !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) )		return -EFAULT;	if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) {		snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n");	}	spin_lock_irqsave(&sscape->lock, flags);	set_midi_mode_unsafe(sscape->io_base);	spin_unlock_irqrestore(&sscape->lock, flags);	initialise_mpu401(sscape->mpu);	return err;}/* * Hardware-specific device functions, to implement special * IOCTLs for the SoundScape card. This is how we upload * the microcode into the card, for example, and so we * must ensure that no two processes can open this device * simultaneously, and that we can't open it at all if * someone is using the MIDI device. */static int sscape_hw_open(struct snd_hwdep * hw, struct file *file){	register struct soundscape *sscape = get_hwdep_soundscape(hw);	unsigned long flags;	int err;	spin_lock_irqsave(&sscape->fwlock, flags);	if ((sscape->midi_usage != 0) || sscape->hw_in_use) {		err = -EBUSY;	} else {		sscape->hw_in_use = 1;		err = 0;	}	spin_unlock_irqrestore(&sscape->fwlock, flags);	return err;}static int sscape_hw_release(struct snd_hwdep * hw, struct file *file){	register struct soundscape *sscape = get_hwdep_soundscape(hw);	unsigned long flags;	spin_lock_irqsave(&sscape->fwlock, flags);	sscape->hw_in_use = 0;	spin_unlock_irqrestore(&sscape->fwlock, flags);	return 0;}static int sscape_hw_ioctl(struct snd_hwdep * hw, struct file *file,                           unsigned int cmd, unsigned long arg){	struct soundscape *sscape = get_hwdep_soundscape(hw);	int err = -EBUSY;	switch (cmd) {	case SND_SSCAPE_LOAD_BOOTB:		{			register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg;			/*			 * We are going to have to copy this data into a special			 * DMA-able buffer before we can upload it. We shall therefore			 * just check that the data pointer is valid for now ...			 */			if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) )				return -EFAULT;			/*			 * Now check that we can write the firmware version number too...			 */			if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) )				return -EFAULT;			err = sscape_upload_bootblock(sscape, bb);		}		break;	case SND_SSCAPE_LOAD_MCODE:		{			register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg;			err = sscape_upload_microcode(sscape, mc);		}		break;	default:		err = -EINVAL;		break;	} /* switch */	return err;}/* * Mixer control for the SoundScape's MIDI device. */static int sscape_midi_info(struct snd_kcontrol *ctl,                            struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 1;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = 127;	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_cs4231 *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));      __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;}static struct snd_kcontrol_new midi_mixer_ctl = {	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,	.name = "MIDI",	.info = sscape_midi_info,	.get = sscape_midi_get,	.put = sscape_midi_put};/* * The SoundScape can use two IRQs from a possible set of four. * These IRQs are encoded as bit patterns so that they can be * written to the control registers. */static unsigned __devinit get_irq_config(int irq){	static const int valid_irq[] = { 9, 5, 7, 10 };	unsigned cfg;	for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg) {		if (irq == valid_irq[cfg])			return cfg;	} /* for */	return INVALID_IRQ;}/* * Perform certain arcane port-checks to see whether there * is a SoundScape board lurking behind the given ports. */static int __devinit detect_sscape(struct soundscape *s){	unsigned long flags;	unsigned d;	int retval = 0;	int codec = s->wss_base;	spin_lock_irqsave(&s->lock, flags);	/*	 * The following code is lifted from the original OSS driver,	 * and as I don't have a datasheet I cannot really comment	 * on what it is doing...	 */	if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0)		goto _done;	d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0;	if ((d & 0x80) != 0)		goto _done;	if (d == 0) {		s->codec_type = 1;		s->ic_type = IC_ODIE;	} else if ((d & 0x60) != 0) {		s->codec_type = 2;		s->ic_type = IC_OPUS;	} else		goto _done;	outb(0xfa, ODIE_ADDR_IO(s->io_base));	if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a)		goto _done;	outb(0xfe, ODIE_ADDR_IO(s->io_base));	if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e)		goto _done;	outb(0xfe, ODIE_ADDR_IO(s->io_base));	d = inb(ODIE_DATA_IO(s->io_base));	if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)		goto _done;	d  = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;	sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);	if (s->type == SSCAPE_VIVO)		codec += 4;	/* wait for WSS codec */	for (d = 0; d < 500; d++) {		if ((inb(codec) & 0x80) == 0)			break;		spin_unlock_irqrestore(&s->lock, flags);		msleep(1);		spin_lock_irqsave(&s->lock, flags);	}	snd_printd(KERN_INFO "init delay = %d ms\n", d);	/*	 * SoundScape successfully detected!	 */	retval = 1;	_done:	spin_unlock_irqrestore(&s->lock, flags);	return retval;}/* * ALSA callback function, called when attempting to open the MIDI device. * Check that the MIDI firmware has been loaded, because we don't want * to crash the machine. Also check that someone isn't using the hardware * IOCTL device. */static int mpu401_open(struct snd_mpu401 * mpu){	int err;	if (!verify_mpu401(mpu)) {		snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n");		err = -ENODEV;	} else {		register struct soundscape *sscape = get_mpu401_soundscape(mpu);		unsigned long flags;		spin_lock_irqsave(&sscape->fwlock, flags);		if (sscape->hw_in_use || (sscape->midi_usage == ULONG_MAX)) {			err = -EBUSY;		} else {			++(sscape->midi_usage);			err = 0;		}		spin_unlock_irqrestore(&sscape->fwlock, flags);	}	return err;}static void mpu401_close(struct snd_mpu401 * mpu){	register struct soundscape *sscape = get_mpu401_soundscape(mpu);	unsigned long flags;	spin_lock_irqsave(&sscape->fwlock, flags);	--(sscape->midi_usage);	spin_unlock_irqrestore(&sscape->fwlock, flags);}/* * 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;}/* * Override for the CS4231 playback format function. * The AD1845 has much simpler format and rate selection. */static void ad1845_playback_format(struct snd_cs4231 * chip, struct snd_pcm_hw_params *params, unsigned char format){	unsigned long flags;	unsigned rate = params_rate(params);	/*	 * The AD1845 can't handle sample frequencies	 * outside of 4 kHZ to 50 kHZ	 */	if (rate > 50000)		rate = 50000;	else if (rate < 4000)		rate = 4000;	spin_lock_irqsave(&chip->reg_lock, flags);	/*	 * Program the AD1845 correctly for the playback stream.	 * Note that we do NOT need to toggle the MCE bit because	 * the PLAYBACK_ENABLE bit of the Interface Configuration	 * register is set.	 * 	 * NOTE: We seem to need to write to the MSB before the LSB	 *       to get the correct sample frequency.	 */	snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, (format & 0xf0));	snd_cs4231_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));	snd_cs4231_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);	spin_unlock_irqrestore(&chip->reg_lock, flags);}/* * Override for the CS4231 capture format function.  * The AD1845 has much simpler format and rate selection. */static void ad1845_capture_format(struct snd_cs4231 * chip, struct snd_pcm_hw_params *params, unsigned char format){	unsigned long flags;	unsigned rate = params_rate(params);	/*	 * The AD1845 can't handle sample frequencies 	 * outside of 4 kHZ to 50 kHZ	 */	if (rate > 50000)		rate = 50000;	else if (rate < 4000)		rate = 4000;	spin_lock_irqsave(&chip->reg_lock, flags);	/*	 * Program the AD1845 correctly for the playback stream.	 * Note that we do NOT need to toggle the MCE bit because	 * the CAPTURE_ENABLE bit of the Interface Configuration	 * register is set.	 *	 * NOTE: We seem to need to write to the MSB before the LSB	 *       to get the correct sample frequency.	 */	snd_cs4231_out(chip, CS4231_REC_FORMAT, (format & 0xf0));	snd_cs4231_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));	snd_cs4231_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);	spin_unlock_irqrestore(&chip->reg_lock, flags);}/* * 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_cs4231 *chip;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -