2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* The DSP56001 Device Driver, saviour of the Free World(tm)
|
|
|
|
*
|
|
|
|
* Authors: Fredrik Noring <noring@nocrew.org>
|
|
|
|
* lars brinkhoff <lars@nocrew.org>
|
|
|
|
* Tomas Berndtsson <tomas@nocrew.org>
|
|
|
|
*
|
|
|
|
* First version May 1996
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
* 97-01-29 Tomas Berndtsson,
|
|
|
|
* Integrated with Linux 2.1.21 kernel sources.
|
|
|
|
* 97-02-15 Tomas Berndtsson,
|
|
|
|
* Fixed for kernel 2.1.26
|
|
|
|
*
|
|
|
|
* BUGS:
|
|
|
|
* Hmm... there must be something here :)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996,1997 Fredrik Noring, lars brinkhoff & Tomas Berndtsson
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file COPYING in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/delay.h> /* guess what */
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/device.h>
|
2010-06-02 12:28:52 +00:00
|
|
|
#include <linux/mutex.h>
|
2008-07-05 09:58:30 +00:00
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/platform_device.h>
|
2008-07-25 08:48:17 +00:00
|
|
|
#include <linux/uaccess.h> /* For put_user and get_user */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/atarihw.h>
|
|
|
|
#include <asm/traps.h>
|
|
|
|
|
|
|
|
#include <asm/dsp56k.h>
|
|
|
|
|
|
|
|
/* minor devices */
|
|
|
|
#define DSP56K_DEV_56001 0 /* The only device so far */
|
|
|
|
|
|
|
|
#define TIMEOUT 10 /* Host port timeout in number of tries */
|
|
|
|
#define MAXIO 2048 /* Maximum number of words before sleep */
|
|
|
|
#define DSP56K_MAX_BINARY_LENGTH (3*64*1024)
|
|
|
|
|
|
|
|
#define DSP56K_TX_INT_ON dsp56k_host_interface.icr |= DSP56K_ICR_TREQ
|
|
|
|
#define DSP56K_RX_INT_ON dsp56k_host_interface.icr |= DSP56K_ICR_RREQ
|
|
|
|
#define DSP56K_TX_INT_OFF dsp56k_host_interface.icr &= ~DSP56K_ICR_TREQ
|
|
|
|
#define DSP56K_RX_INT_OFF dsp56k_host_interface.icr &= ~DSP56K_ICR_RREQ
|
|
|
|
|
|
|
|
#define DSP56K_TRANSMIT (dsp56k_host_interface.isr & DSP56K_ISR_TXDE)
|
|
|
|
#define DSP56K_RECEIVE (dsp56k_host_interface.isr & DSP56K_ISR_RXDF)
|
|
|
|
|
|
|
|
#define handshake(count, maxio, timeout, ENABLE, f) \
|
|
|
|
{ \
|
|
|
|
long i, t, m; \
|
|
|
|
while (count > 0) { \
|
|
|
|
m = min_t(unsigned long, count, maxio); \
|
|
|
|
for (i = 0; i < m; i++) { \
|
|
|
|
for (t = 0; t < timeout && !ENABLE; t++) \
|
|
|
|
msleep(20); \
|
|
|
|
if(!ENABLE) \
|
|
|
|
return -EIO; \
|
|
|
|
f; \
|
|
|
|
} \
|
|
|
|
count -= m; \
|
|
|
|
if (m == maxio) msleep(20); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define tx_wait(n) \
|
|
|
|
{ \
|
|
|
|
int t; \
|
|
|
|
for(t = 0; t < n && !DSP56K_TRANSMIT; t++) \
|
|
|
|
msleep(10); \
|
|
|
|
if(!DSP56K_TRANSMIT) { \
|
|
|
|
return -EIO; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define rx_wait(n) \
|
|
|
|
{ \
|
|
|
|
int t; \
|
|
|
|
for(t = 0; t < n && !DSP56K_RECEIVE; t++) \
|
|
|
|
msleep(10); \
|
|
|
|
if(!DSP56K_RECEIVE) { \
|
|
|
|
return -EIO; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
static DEFINE_MUTEX(dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct dsp56k_device {
|
2007-10-14 18:35:20 +00:00
|
|
|
unsigned long in_use;
|
2005-04-16 22:20:36 +00:00
|
|
|
long maxio, timeout;
|
|
|
|
int tx_wsize, rx_wsize;
|
|
|
|
} dsp56k;
|
|
|
|
|
2023-06-20 14:37:53 +00:00
|
|
|
static const struct class dsp56k_class = {
|
|
|
|
.name = "dsp56k",
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int dsp56k_reset(void)
|
|
|
|
{
|
|
|
|
u_char status;
|
|
|
|
|
|
|
|
/* Power down the DSP */
|
|
|
|
sound_ym.rd_data_reg_sel = 14;
|
|
|
|
status = sound_ym.rd_data_reg_sel & 0xef;
|
|
|
|
sound_ym.wd_data = status;
|
|
|
|
sound_ym.wd_data = status | 0x10;
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
|
|
|
|
/* Power up the DSP */
|
|
|
|
sound_ym.rd_data_reg_sel = 14;
|
|
|
|
sound_ym.wd_data = sound_ym.rd_data_reg_sel & 0xef;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-12 09:06:31 +00:00
|
|
|
static int dsp56k_upload(u_char __user *bin, int len)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-07-05 09:58:30 +00:00
|
|
|
struct platform_device *pdev;
|
|
|
|
const struct firmware *fw;
|
|
|
|
const char fw_name[] = "dsp56k/bootstrap.bin";
|
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
int i;
|
2008-07-05 09:58:30 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
dsp56k_reset();
|
2008-07-05 09:58:30 +00:00
|
|
|
|
|
|
|
pdev = platform_device_register_simple("dsp56k", 0, NULL, 0);
|
|
|
|
if (IS_ERR(pdev)) {
|
|
|
|
printk(KERN_ERR "Failed to register device for \"%s\"\n",
|
|
|
|
fw_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
err = request_firmware(&fw, fw_name, &pdev->dev);
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
|
|
|
|
fw_name, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (fw->size % 3) {
|
|
|
|
printk(KERN_ERR "Bogus length %d in image \"%s\"\n",
|
|
|
|
fw->size, fw_name);
|
|
|
|
release_firmware(fw);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < fw->size; i = i + 3) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* tx_wait(10); */
|
2008-07-05 09:58:30 +00:00
|
|
|
dsp56k_host_interface.data.b[1] = fw->data[i];
|
|
|
|
dsp56k_host_interface.data.b[2] = fw->data[i + 1];
|
|
|
|
dsp56k_host_interface.data.b[3] = fw->data[i + 2];
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-07-05 09:58:30 +00:00
|
|
|
release_firmware(fw);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (; i < 512; i++) {
|
|
|
|
/* tx_wait(10); */
|
|
|
|
dsp56k_host_interface.data.b[1] = 0;
|
|
|
|
dsp56k_host_interface.data.b[2] = 0;
|
|
|
|
dsp56k_host_interface.data.b[3] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
tx_wait(10);
|
|
|
|
get_user(dsp56k_host_interface.data.b[1], bin++);
|
|
|
|
get_user(dsp56k_host_interface.data.b[2], bin++);
|
|
|
|
get_user(dsp56k_host_interface.data.b[3], bin++);
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_wait(10);
|
|
|
|
dsp56k_host_interface.data.l = 3; /* Magic execute */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-12 09:06:31 +00:00
|
|
|
static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
|
2005-04-16 22:20:36 +00:00
|
|
|
loff_t *ppos)
|
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(file);
|
2005-04-16 22:20:36 +00:00
|
|
|
int dev = iminor(inode) & 0x0f;
|
|
|
|
|
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
{
|
|
|
|
|
|
|
|
long n;
|
|
|
|
|
|
|
|
/* Don't do anything if nothing is to be done */
|
|
|
|
if (!count) return 0;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
switch (dsp56k.rx_wsize) {
|
|
|
|
case 1: /* 8 bit */
|
|
|
|
{
|
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
|
|
|
|
put_user(dsp56k_host_interface.data.b[3], buf+n++));
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
case 2: /* 16 bit */
|
|
|
|
{
|
2006-01-12 09:06:31 +00:00
|
|
|
short __user *data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
count /= 2;
|
2006-01-12 09:06:31 +00:00
|
|
|
data = (short __user *) buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
|
|
|
|
put_user(dsp56k_host_interface.data.w[1], data+n++));
|
|
|
|
return 2*n;
|
|
|
|
}
|
|
|
|
case 3: /* 24 bit */
|
|
|
|
{
|
|
|
|
count /= 3;
|
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
|
|
|
|
put_user(dsp56k_host_interface.data.b[1], buf+n++);
|
|
|
|
put_user(dsp56k_host_interface.data.b[2], buf+n++);
|
|
|
|
put_user(dsp56k_host_interface.data.b[3], buf+n++));
|
|
|
|
return 3*n;
|
|
|
|
}
|
|
|
|
case 4: /* 32 bit */
|
|
|
|
{
|
2006-01-12 09:06:31 +00:00
|
|
|
long __user *data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
count /= 4;
|
2006-01-12 09:06:31 +00:00
|
|
|
data = (long __user *) buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_RECEIVE,
|
|
|
|
put_user(dsp56k_host_interface.data.l, data+n++));
|
|
|
|
return 4*n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 09:06:31 +00:00
|
|
|
static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count,
|
2005-04-16 22:20:36 +00:00
|
|
|
loff_t *ppos)
|
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
struct inode *inode = file_inode(file);
|
2005-04-16 22:20:36 +00:00
|
|
|
int dev = iminor(inode) & 0x0f;
|
|
|
|
|
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
{
|
|
|
|
long n;
|
|
|
|
|
|
|
|
/* Don't do anything if nothing is to be done */
|
|
|
|
if (!count) return 0;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
switch (dsp56k.tx_wsize) {
|
|
|
|
case 1: /* 8 bit */
|
|
|
|
{
|
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
|
|
|
|
get_user(dsp56k_host_interface.data.b[3], buf+n++));
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
case 2: /* 16 bit */
|
|
|
|
{
|
2006-01-12 09:06:31 +00:00
|
|
|
const short __user *data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
count /= 2;
|
2006-01-12 09:06:31 +00:00
|
|
|
data = (const short __user *)buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
|
|
|
|
get_user(dsp56k_host_interface.data.w[1], data+n++));
|
|
|
|
return 2*n;
|
|
|
|
}
|
|
|
|
case 3: /* 24 bit */
|
|
|
|
{
|
|
|
|
count /= 3;
|
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
|
|
|
|
get_user(dsp56k_host_interface.data.b[1], buf+n++);
|
|
|
|
get_user(dsp56k_host_interface.data.b[2], buf+n++);
|
|
|
|
get_user(dsp56k_host_interface.data.b[3], buf+n++));
|
|
|
|
return 3*n;
|
|
|
|
}
|
|
|
|
case 4: /* 32 bit */
|
|
|
|
{
|
2006-01-12 09:06:31 +00:00
|
|
|
const long __user *data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
count /= 4;
|
2006-01-12 09:06:31 +00:00
|
|
|
data = (const long __user *)buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
handshake(count, dsp56k.maxio, dsp56k.timeout, DSP56K_TRANSMIT,
|
|
|
|
get_user(dsp56k_host_interface.data.l, data+n++));
|
|
|
|
return 4*n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 08:48:17 +00:00
|
|
|
static long dsp56k_ioctl(struct file *file, unsigned int cmd,
|
2008-07-26 15:15:05 +00:00
|
|
|
unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
int dev = iminor(file_inode(file)) & 0x0f;
|
2006-01-12 09:06:31 +00:00
|
|
|
void __user *argp = (void __user *)arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case DSP56K_UPLOAD:
|
|
|
|
{
|
2006-01-12 09:06:31 +00:00
|
|
|
char __user *bin;
|
2005-04-16 22:20:36 +00:00
|
|
|
int r, len;
|
2006-01-12 09:06:31 +00:00
|
|
|
struct dsp56k_upload __user *binary = argp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if(get_user(len, &binary->len) < 0)
|
|
|
|
return -EFAULT;
|
|
|
|
if(get_user(bin, &binary->bin) < 0)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2016-07-13 10:11:19 +00:00
|
|
|
if (len <= 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL; /* nothing to upload?!? */
|
|
|
|
}
|
|
|
|
if (len > DSP56K_MAX_BINARY_LENGTH) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
r = dsp56k_upload(bin, len);
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (r < 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DSP56K_SET_TX_WSIZE:
|
|
|
|
if (arg > 4 || arg < 1)
|
|
|
|
return -EINVAL;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
dsp56k.tx_wsize = (int) arg;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case DSP56K_SET_RX_WSIZE:
|
|
|
|
if (arg > 4 || arg < 1)
|
|
|
|
return -EINVAL;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
dsp56k.rx_wsize = (int) arg;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case DSP56K_HOST_FLAGS:
|
|
|
|
{
|
|
|
|
int dir, out, status;
|
2006-01-12 09:06:31 +00:00
|
|
|
struct dsp56k_host_flags __user *hf = argp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if(get_user(dir, &hf->dir) < 0)
|
|
|
|
return -EFAULT;
|
|
|
|
if(get_user(out, &hf->out) < 0)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((dir & 0x1) && (out & 0x1))
|
|
|
|
dsp56k_host_interface.icr |= DSP56K_ICR_HF0;
|
|
|
|
else if (dir & 0x1)
|
|
|
|
dsp56k_host_interface.icr &= ~DSP56K_ICR_HF0;
|
|
|
|
if ((dir & 0x2) && (out & 0x2))
|
|
|
|
dsp56k_host_interface.icr |= DSP56K_ICR_HF1;
|
|
|
|
else if (dir & 0x2)
|
|
|
|
dsp56k_host_interface.icr &= ~DSP56K_ICR_HF1;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
if (dsp56k_host_interface.icr & DSP56K_ICR_HF0) status |= 0x1;
|
|
|
|
if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2;
|
|
|
|
if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4;
|
|
|
|
if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return put_user(status, &hf->status);
|
|
|
|
}
|
|
|
|
case DSP56K_HOST_CMD:
|
2014-07-17 12:18:53 +00:00
|
|
|
if (arg > 31)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) |
|
|
|
|
DSP56K_CVR_HC);
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* As of 2.1.26 this should be dsp56k_poll,
|
|
|
|
* but how do I then check device minor number?
|
|
|
|
* Do I need this function at all???
|
|
|
|
*/
|
|
|
|
#if 0
|
2017-07-03 10:39:46 +00:00
|
|
|
static __poll_t dsp56k_poll(struct file *file, poll_table *wait)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-01-23 22:07:38 +00:00
|
|
|
int dev = iminor(file_inode(file)) & 0x0f;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
/* poll_wait(file, ???, wait); */
|
2018-02-11 22:34:03 +00:00
|
|
|
return EPOLLIN | EPOLLRDNORM | EPOLLOUT;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
printk("DSP56k driver: Unknown minor device: %d\n", dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int dsp56k_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int dev = iminor(inode) & 0x0f;
|
2008-05-16 19:57:31 +00:00
|
|
|
int ret = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&dsp56k_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
|
2008-05-16 19:57:31 +00:00
|
|
|
if (test_and_set_bit(0, &dsp56k.in_use)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dsp56k.timeout = TIMEOUT;
|
|
|
|
dsp56k.maxio = MAXIO;
|
|
|
|
dsp56k.rx_wsize = dsp56k.tx_wsize = 4;
|
|
|
|
|
|
|
|
DSP56K_TX_INT_OFF;
|
|
|
|
DSP56K_RX_INT_OFF;
|
|
|
|
|
|
|
|
/* Zero host flags */
|
|
|
|
dsp56k_host_interface.icr &= ~DSP56K_ICR_HF0;
|
|
|
|
dsp56k_host_interface.icr &= ~DSP56K_ICR_HF1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-05-16 19:57:31 +00:00
|
|
|
ret = -ENODEV;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-05-16 19:57:31 +00:00
|
|
|
out:
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&dsp56k_mutex);
|
2008-05-16 19:57:31 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dsp56k_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int dev = iminor(inode) & 0x0f;
|
|
|
|
|
|
|
|
switch(dev)
|
|
|
|
{
|
|
|
|
case DSP56K_DEV_56001:
|
|
|
|
clear_bit(0, &dsp56k.in_use);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "DSP56k driver: Unknown minor device: %d\n", dev);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-03 07:24:21 +00:00
|
|
|
static const struct file_operations dsp56k_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.read = dsp56k_read,
|
|
|
|
.write = dsp56k_write,
|
2008-07-25 08:48:17 +00:00
|
|
|
.unlocked_ioctl = dsp56k_ioctl,
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = dsp56k_open,
|
|
|
|
.release = dsp56k_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = noop_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/****** Init and module functions ******/
|
|
|
|
|
2017-05-08 22:59:05 +00:00
|
|
|
static const char banner[] __initconst = KERN_INFO "DSP56k driver installed\n";
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init dsp56k_init_driver(void)
|
|
|
|
{
|
2023-06-20 14:37:53 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if(!MACH_IS_ATARI || !ATARIHW_PRESENT(DSP56K)) {
|
|
|
|
printk("DSP56k driver: Hardware not present\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(register_chrdev(DSP56K_MAJOR, "dsp56k", &dsp56k_fops)) {
|
|
|
|
printk("DSP56k driver: Unable to register driver\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2023-06-20 14:37:53 +00:00
|
|
|
err = class_register(&dsp56k_class);
|
|
|
|
if (err)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out_chrdev;
|
2023-06-20 14:37:53 +00:00
|
|
|
device_create(&dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), NULL,
|
2008-07-22 03:03:34 +00:00
|
|
|
"dsp56k");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
printk(banner);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out_chrdev:
|
|
|
|
unregister_chrdev(DSP56K_MAJOR, "dsp56k");
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
module_init(dsp56k_init_driver);
|
|
|
|
|
|
|
|
static void __exit dsp56k_cleanup_driver(void)
|
|
|
|
{
|
2023-06-20 14:37:53 +00:00
|
|
|
device_destroy(&dsp56k_class, MKDEV(DSP56K_MAJOR, 0));
|
|
|
|
class_unregister(&dsp56k_class);
|
2005-04-16 22:20:36 +00:00
|
|
|
unregister_chrdev(DSP56K_MAJOR, "dsp56k");
|
|
|
|
}
|
|
|
|
module_exit(dsp56k_cleanup_driver);
|
|
|
|
|
2024-06-18 05:02:11 +00:00
|
|
|
MODULE_DESCRIPTION("Atari DSP56001 Device Driver");
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
2008-07-05 09:58:30 +00:00
|
|
|
MODULE_FIRMWARE("dsp56k/bootstrap.bin");
|