diff options
Diffstat (limited to 'drivers/staging/comedi/drivers/serial2002.c')
-rw-r--r-- | drivers/staging/comedi/drivers/serial2002.c | 202 |
1 files changed, 115 insertions, 87 deletions
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c index db18b11b9d30..82aa86e718b2 100644 --- a/drivers/staging/comedi/drivers/serial2002.c +++ b/drivers/staging/comedi/drivers/serial2002.c @@ -35,6 +35,7 @@ Status: in development #include <linux/delay.h> #include <linux/ioport.h> +#include <linux/sched.h> #include <asm/termios.h> #include <asm/ioctls.h> @@ -52,7 +53,7 @@ struct serial2002_board { static const struct serial2002_board serial2002_boards[] = { { - .name = "serial2002"} + .name = "serial2002"} }; /* @@ -67,7 +68,6 @@ struct serial2002_range_table_t { struct comedi_krange range; }; - struct serial2002_private { int port; /* /dev/ttyS<port> */ @@ -82,14 +82,14 @@ struct serial2002_private { struct serial2002_range_table_t in_range[32], out_range[32]; }; - /* * most drivers define the following macro to make it easy to * access the private structure. */ #define devpriv ((struct serial2002_private *)dev->private) -static int serial2002_attach(struct comedi_device *dev, struct comedi_devconfig *it); +static int serial2002_attach(struct comedi_device *dev, + struct comedi_devconfig *it); static int serial2002_detach(struct comedi_device *dev); struct comedi_driver driver_serial2002 = { .driver_name = "serial2002", @@ -101,16 +101,21 @@ struct comedi_driver driver_serial2002 = { .num_names = ARRAY_SIZE(serial2002_boards), }; -static int serial2002_di_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); -static int serial2002_do_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); -static int serial2002_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); -static int serial2002_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); -static int serial2002_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data); +static int serial2002_di_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data); +static int serial2002_do_winsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data); +static int serial2002_ai_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data); +static int serial2002_ao_winsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data); +static int serial2002_ao_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data); struct serial_data { enum { is_invalid, is_digital, is_channel } kind; @@ -184,28 +189,28 @@ static int tty_read(struct file *f, int timeout) mask = f->f_op->poll(f, &table.pt); if (mask & (POLLRDNORM | POLLRDBAND | POLLIN | - POLLHUP | POLLERR)) { + POLLHUP | POLLERR)) { break; } do_gettimeofday(&now); elapsed = - (1000000 * (now.tv_sec - start.tv_sec) + - now.tv_usec - start.tv_usec); + (1000000 * (now.tv_sec - start.tv_sec) + + now.tv_usec - start.tv_usec); if (elapsed > timeout) { break; } set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(((timeout - - elapsed) * HZ) / 10000); + elapsed) * HZ) / 10000); } poll_freewait(&table); { - unsigned char ch; + unsigned char ch; - f->f_pos = 0; - if (f->f_op->read(f, &ch, 1, &f->f_pos) == 1) { - result = ch; - } + f->f_pos = 0; + if (f->f_op->read(f, &ch, 1, &f->f_pos) == 1) { + result = ch; + } } } else { /* Device does not support poll, busy wait */ @@ -348,8 +353,7 @@ static struct serial_data serial_read(struct file *f, int timeout) } } else { result.value = - (result. - value << 2) | ((data & 0x60) >> 5); + (result.value << 2) | ((data & 0x60) >> 5); result.kind = is_channel; } result.index = data & 0x1f; @@ -364,7 +368,7 @@ static void serial_write(struct file *f, struct serial_data data) { if (data.kind == is_digital) { unsigned char ch = - ((data.value << 5) & 0x20) | (data.index & 0x1f); + ((data.value << 5) & 0x20) | (data.index & 0x1f); tty_write(f, &ch, 1); } else { unsigned char ch[6]; @@ -401,7 +405,7 @@ static void serial_2002_open(struct comedi_device *dev) devpriv->tty = filp_open(port, 0, O_RDWR); if (IS_ERR(devpriv->tty)) { printk("serial_2002: file open error = %ld\n", - PTR_ERR(devpriv->tty)); + PTR_ERR(devpriv->tty)); } else { struct config_t { @@ -443,7 +447,7 @@ static void serial_2002_open(struct comedi_device *dev) data = serial_read(devpriv->tty, 1000); if (data.kind != is_channel || data.index != 31 - || !(data.value & 0xe0)) { + || !(data.value & 0xe0)) { break; } else { int command, channel, kind; @@ -479,77 +483,92 @@ static void serial_2002_open(struct comedi_device *dev) cur_config[channel].kind = kind; switch (command) { case 0:{ - cur_config[channel]. - bits = - (data. - value >> 10) & - 0x3f; + cur_config[channel].bits + = + (data.value >> 10) & + 0x3f; } break; case 1:{ int unit, sign, min; - unit = (data. - value >> 10) & - 0x7; - sign = (data. - value >> 13) & - 0x1; - min = (data. - value >> 14) & - 0xfffff; + unit = + (data.value >> 10) & + 0x7; + sign = + (data.value >> 13) & + 0x1; + min = + (data.value >> 14) & + 0xfffff; switch (unit) { case 0:{ - min = min * 1000000; + min = + min + * + 1000000; } break; case 1:{ - min = min * 1000; + min = + min + * + 1000; } break; case 2:{ - min = min * 1; + min = + min + * 1; } break; } if (sign) { min = -min; } - cur_config[channel]. - min = min; + cur_config[channel].min + = min; } break; case 2:{ int unit, sign, max; - unit = (data. - value >> 10) & - 0x7; - sign = (data. - value >> 13) & - 0x1; - max = (data. - value >> 14) & - 0xfffff; + unit = + (data.value >> 10) & + 0x7; + sign = + (data.value >> 13) & + 0x1; + max = + (data.value >> 14) & + 0xfffff; switch (unit) { case 0:{ - max = max * 1000000; + max = + max + * + 1000000; } break; case 1:{ - max = max * 1000; + max = + max + * + 1000; } break; case 2:{ - max = max * 1; + max = + max + * 1; } break; } if (sign) { max = -max; } - cur_config[channel]. - max = max; + cur_config[channel].max + = max; } break; } @@ -604,7 +623,8 @@ static void serial_2002_open(struct comedi_device *dev) } if (c) { struct comedi_subdevice *s; - const struct comedi_lrange **range_table_list = NULL; + const struct comedi_lrange **range_table_list = + NULL; unsigned int *maxdata_list; int j, chan; @@ -620,17 +640,18 @@ static void serial_2002_open(struct comedi_device *dev) kfree(s->maxdata_list); } s->maxdata_list = maxdata_list = - kmalloc(sizeof(unsigned int) * s->n_chan, - GFP_KERNEL); + kmalloc(sizeof(unsigned int) * s->n_chan, + GFP_KERNEL); if (s->range_table_list) { kfree(s->range_table_list); } if (range) { s->range_table = 0; s->range_table_list = range_table_list = - kmalloc(sizeof - (struct serial2002_range_table_t) * - s->n_chan, GFP_KERNEL); + kmalloc(sizeof + (struct + serial2002_range_table_t) * + s->n_chan, GFP_KERNEL); } for (chan = 0, j = 0; j < 32; j++) { if (c[j].kind == kind) { @@ -640,17 +661,17 @@ static void serial_2002_open(struct comedi_device *dev) if (range) { range[j].length = 1; range[j].range.min = - c[j].min; + c[j].min; range[j].range.max = - c[j].max; + c[j].max; range_table_list[chan] = - (const struct - comedi_lrange *) - &range[j]; + (const struct + comedi_lrange *) + &range[j]; } maxdata_list[chan] = - ((long long)1 << c[j]. - bits) - 1; + ((long long)1 << c[j].bits) + - 1; chan++; } } @@ -666,8 +687,9 @@ static void serial_2002_close(struct comedi_device *dev) } } -static int serial2002_di_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_di_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan; @@ -688,8 +710,9 @@ static int serial2002_di_rinsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_do_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_do_winsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan; @@ -706,8 +729,9 @@ static int serial2002_do_winsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_ai_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan; @@ -728,8 +752,9 @@ static int serial2002_ai_rinsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_ao_winsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan; @@ -747,8 +772,9 @@ static int serial2002_ao_winsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_ao_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan = CR_CHAN(insn->chanspec); @@ -760,8 +786,9 @@ static int serial2002_ao_rinsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_ei_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int serial2002_ei_rinsn(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, unsigned int *data) { int n; int chan; @@ -782,7 +809,8 @@ static int serial2002_ei_rinsn(struct comedi_device *dev, struct comedi_subdevic return n; } -static int serial2002_attach(struct comedi_device *dev, struct comedi_devconfig *it) +static int serial2002_attach(struct comedi_device *dev, + struct comedi_devconfig *it) { struct comedi_subdevice *s; |