Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * The DSP56001 Device Driver, saviour of the Free World(tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Authors: Fredrik Noring   <noring@nocrew.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *          lars brinkhoff   <lars@nocrew.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *          Tomas Berndtsson <tomas@nocrew.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * First version May 1996
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * History:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  97-01-29   Tomas Berndtsson,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *               Integrated with Linux 2.1.21 kernel sources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  97-02-15   Tomas Berndtsson,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *               Fixed for kernel 2.1.26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * BUGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  Hmm... there must be something here :)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Copyright (C) 1996,1997 Fredrik Noring, lars brinkhoff & Tomas Berndtsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * License.  See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/delay.h>	/* guess what */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/uaccess.h>	/* For put_user and get_user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/atarihw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/dsp56k.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* minor devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define DSP56K_DEV_56001        0    /* The only device so far */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define TIMEOUT    10   /* Host port timeout in number of tries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define MAXIO    2048   /* Maximum number of words before sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define DSP56K_MAX_BINARY_LENGTH (3*64*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define DSP56K_TX_INT_ON	dsp56k_host_interface.icr |=  DSP56K_ICR_TREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define DSP56K_RX_INT_ON	dsp56k_host_interface.icr |=  DSP56K_ICR_RREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define DSP56K_TX_INT_OFF	dsp56k_host_interface.icr &= ~DSP56K_ICR_TREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define DSP56K_RX_INT_OFF	dsp56k_host_interface.icr &= ~DSP56K_ICR_RREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define DSP56K_TRANSMIT		(dsp56k_host_interface.isr & DSP56K_ISR_TXDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define DSP56K_RECEIVE		(dsp56k_host_interface.isr & DSP56K_ISR_RXDF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define handshake(count, maxio, timeout, ENABLE, f) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	long i, t, m; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	while (count > 0) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		m = min_t(unsigned long, count, maxio); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		for (i = 0; i < m; i++) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			for (t = 0; t < timeout && !ENABLE; t++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				msleep(20); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			if(!ENABLE) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				return -EIO; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			f; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		count -= m; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (m == maxio) msleep(20); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define tx_wait(n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int t; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	for(t = 0; t < n && !DSP56K_TRANSMIT; t++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		msleep(10); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if(!DSP56K_TRANSMIT) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -EIO; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define rx_wait(n) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int t; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	for(t = 0; t < n && !DSP56K_RECEIVE; t++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		msleep(10); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if(!DSP56K_RECEIVE) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		return -EIO; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static DEFINE_MUTEX(dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static struct dsp56k_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	unsigned long in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	long maxio, timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int tx_wsize, rx_wsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) } dsp56k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct class *dsp56k_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int dsp56k_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u_char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* Power down the DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	sound_ym.rd_data_reg_sel = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	status = sound_ym.rd_data_reg_sel & 0xef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	sound_ym.wd_data = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	sound_ym.wd_data = status | 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* Power up the DSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	sound_ym.rd_data_reg_sel = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	sound_ym.wd_data = sound_ym.rd_data_reg_sel & 0xef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int dsp56k_upload(u_char __user *bin, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	const char fw_name[] = "dsp56k/bootstrap.bin";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	dsp56k_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	pdev = platform_device_register_simple("dsp56k", 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (IS_ERR(pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		printk(KERN_ERR "Failed to register device for \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		       fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	err = request_firmware(&fw, fw_name, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		       fw_name, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (fw->size % 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		printk(KERN_ERR "Bogus length %d in image \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		       fw->size, fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	for (i = 0; i < fw->size; i = i + 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/* tx_wait(10); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		dsp56k_host_interface.data.b[1] = fw->data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		dsp56k_host_interface.data.b[2] = fw->data[i + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		dsp56k_host_interface.data.b[3] = fw->data[i + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (; i < 512; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		/* tx_wait(10); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		dsp56k_host_interface.data.b[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		dsp56k_host_interface.data.b[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dsp56k_host_interface.data.b[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		tx_wait(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		get_user(dsp56k_host_interface.data.b[1], bin++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		get_user(dsp56k_host_interface.data.b[2], bin++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		get_user(dsp56k_host_interface.data.b[3], bin++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	tx_wait(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	dsp56k_host_interface.data.l = 3;    /* Magic execute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			   loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	int dev = iminor(inode) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		/* Don't do anything if nothing is to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (!count) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		switch (dsp56k.rx_wsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		case 1:  /* 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				  put_user(dsp56k_host_interface.data.b[3], buf+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		case 2:  /* 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			short __user *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			count /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			data = (short __user *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				  put_user(dsp56k_host_interface.data.w[1], data+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			return 2*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		case 3:  /* 24 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			count /= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				  put_user(dsp56k_host_interface.data.b[1], buf+n++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				  put_user(dsp56k_host_interface.data.b[2], buf+n++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				  put_user(dsp56k_host_interface.data.b[3], buf+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			return 3*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		case 4:  /* 32 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			long __user *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			count /= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			data = (long __user *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				  put_user(dsp56k_host_interface.data.l, data+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			return 4*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			    loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	int dev = iminor(inode) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		/* Don't do anything if nothing is to be done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (!count) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		switch (dsp56k.tx_wsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		case 1:  /* 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				  get_user(dsp56k_host_interface.data.b[3], buf+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		case 2:  /* 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			const short __user *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			count /= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			data = (const short __user *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				  get_user(dsp56k_host_interface.data.w[1], data+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			return 2*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		case 3:  /* 24 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			count /= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				  get_user(dsp56k_host_interface.data.b[1], buf+n++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 				  get_user(dsp56k_host_interface.data.b[2], buf+n++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				  get_user(dsp56k_host_interface.data.b[3], buf+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			return 3*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		case 4:  /* 32 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			const long __user *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			count /= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			data = (const long __user *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 				  get_user(dsp56k_host_interface.data.l, data+n++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			return 4*n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static long dsp56k_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			 unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int dev = iminor(file_inode(file)) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		switch(cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		case DSP56K_UPLOAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			char __user *bin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			int r, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			struct dsp56k_upload __user *binary = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			if(get_user(len, &binary->len) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			if(get_user(bin, &binary->bin) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			if (len <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				return -EINVAL;      /* nothing to upload?!? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			if (len > DSP56K_MAX_BINARY_LENGTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			r = dsp56k_upload(bin, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 				return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		case DSP56K_SET_TX_WSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			if (arg > 4 || arg < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			dsp56k.tx_wsize = (int) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		case DSP56K_SET_RX_WSIZE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			if (arg > 4 || arg < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			dsp56k.rx_wsize = (int) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		case DSP56K_HOST_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			int dir, out, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			struct dsp56k_host_flags __user *hf = argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			if(get_user(dir, &hf->dir) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			if(get_user(out, &hf->out) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			if ((dir & 0x1) && (out & 0x1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				dsp56k_host_interface.icr |= DSP56K_ICR_HF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			else if (dir & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 				dsp56k_host_interface.icr &= ~DSP56K_ICR_HF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			if ((dir & 0x2) && (out & 0x2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				dsp56k_host_interface.icr |= DSP56K_ICR_HF1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			else if (dir & 0x2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				dsp56k_host_interface.icr &= ~DSP56K_ICR_HF1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			if (dsp56k_host_interface.icr & DSP56K_ICR_HF0) status |= 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			return put_user(status, &hf->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		case DSP56K_HOST_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			if (arg > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 							     DSP56K_CVR_HC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* As of 2.1.26 this should be dsp56k_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * but how do I then check device minor number?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * Do I need this function at all???
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static __poll_t dsp56k_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	int dev = iminor(file_inode(file)) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		/* poll_wait(file, ???, wait); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		return EPOLLIN | EPOLLRDNORM | EPOLLOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		printk("DSP56k driver: Unknown minor device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static int dsp56k_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	int dev = iminor(inode) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	mutex_lock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		if (test_and_set_bit(0, &dsp56k.in_use)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		dsp56k.timeout = TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		dsp56k.maxio = MAXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		dsp56k.rx_wsize = dsp56k.tx_wsize = 4; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		DSP56K_TX_INT_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		DSP56K_RX_INT_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		/* Zero host flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		dsp56k_host_interface.icr &= ~DSP56K_ICR_HF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		dsp56k_host_interface.icr &= ~DSP56K_ICR_HF1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	mutex_unlock(&dsp56k_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static int dsp56k_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	int dev = iminor(inode) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	switch(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	case DSP56K_DEV_56001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		clear_bit(0, &dsp56k.in_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static const struct file_operations dsp56k_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	.read		= dsp56k_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.write		= dsp56k_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	.unlocked_ioctl	= dsp56k_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	.open		= dsp56k_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	.release	= dsp56k_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	.llseek		= noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /****** Init and module functions ******/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static const char banner[] __initconst = KERN_INFO "DSP56k driver installed\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static int __init dsp56k_init_driver(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	if(!MACH_IS_ATARI || !ATARIHW_PRESENT(DSP56K)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		printk("DSP56k driver: Hardware not present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if(register_chrdev(DSP56K_MAJOR, "dsp56k", &dsp56k_fops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		printk("DSP56k driver: Unable to register driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	dsp56k_class = class_create(THIS_MODULE, "dsp56k");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	if (IS_ERR(dsp56k_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		err = PTR_ERR(dsp56k_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		goto out_chrdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	device_create(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		      "dsp56k");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	printk(banner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) out_chrdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	unregister_chrdev(DSP56K_MAJOR, "dsp56k");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) module_init(dsp56k_init_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static void __exit dsp56k_cleanup_driver(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	device_destroy(dsp56k_class, MKDEV(DSP56K_MAJOR, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	class_destroy(dsp56k_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	unregister_chrdev(DSP56K_MAJOR, "dsp56k");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) module_exit(dsp56k_cleanup_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) MODULE_FIRMWARE("dsp56k/bootstrap.bin");