Constified ranges, board structures, and miscellaneous data.
[comedi.git] / comedi / drivers / pcl711.c
index 1b444b94d0503edc51ef106c6b50cacfaeffeec6..70c0961a38b3c8b2e9899935260dd87171a02e5d 100644 (file)
@@ -58,19 +58,11 @@ supported.
 
  */
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
+#include <linux/comedidev.h>
+
 #include <linux/ioport.h>
 #include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/timex.h>
-#include <linux/timer.h>
-#include <asm/io.h>
-#include <linux/comedidev.h>
+
 #include "8253.h"
 
 
@@ -97,14 +89,14 @@ supported.
 #define PCL711_DO_LO 13
 #define PCL711_DO_HI 14
 
-static comedi_lrange range_pcl711b_ai = { 5, {
+static const comedi_lrange range_pcl711b_ai = { 5, {
         BIP_RANGE( 5 ),
         BIP_RANGE( 2.5 ),
         BIP_RANGE( 1.25 ),
         BIP_RANGE( 0.625 ),
         BIP_RANGE( 0.3125 )
 }};
-static comedi_lrange range_acl8112hg_ai = { 12, {
+static const comedi_lrange range_acl8112hg_ai = { 12, {
        BIP_RANGE( 5 ),
        BIP_RANGE( 0.5 ),
        BIP_RANGE( 0.05 ),
@@ -118,7 +110,7 @@ static comedi_lrange range_acl8112hg_ai = { 12, {
        BIP_RANGE( 0.1 ),
        BIP_RANGE( 0.01 )
 }};
-static comedi_lrange range_acl8112dg_ai = { 9, {
+static const comedi_lrange range_acl8112dg_ai = { 9, {
         BIP_RANGE( 5 ),
         BIP_RANGE( 2.5 ),
         BIP_RANGE( 1.25 ),
@@ -130,8 +122,6 @@ static comedi_lrange range_acl8112dg_ai = { 9, {
        BIP_RANGE( 10 )
 }};
 
-typedef int bool;
-
 /*
  * flags
  */
@@ -139,10 +129,10 @@ typedef int bool;
 #define PCL711_TIMEOUT 100
 #define PCL711_DRDY 0x10
 
-static int i8253_osc_base = 500;       /* 2 Mhz */
+static const int i8253_osc_base = 500; /* 2 Mhz */
 
 typedef struct {
-       char *name;
+       const char *name;
        int is_pcl711b;
        int is_8112;
        int is_dg;
@@ -150,10 +140,10 @@ typedef struct {
        int n_aichan;
        int n_aochan;
        int maxirq;
-       comedi_lrange * ai_range_type;
+       const comedi_lrange * ai_range_type;
 } boardtype;
 
-static boardtype boardtypes[] =
+static const boardtype boardtypes[] =
 {
        {"pcl711", 0, 0, 0, 5, 8, 1, 0, &range_bipolar5},
        {"pcl711b", 1, 0, 0, 5, 8, 1, 7, &range_pcl711b_ai},
@@ -161,7 +151,7 @@ static boardtype boardtypes[] =
        {"acl8112dg", 0, 1, 1, 9, 16, 2, 15, &range_acl8112dg_ai},
 };
 #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype))
-#define this_board ((boardtype *)dev->board_ptr)
+#define this_board ((const boardtype *)dev->board_ptr)
 
 static int pcl711_attach(comedi_device *dev,comedi_devconfig *it);
 static int pcl711_detach(comedi_device *dev);
@@ -170,7 +160,7 @@ static comedi_driver driver_pcl711={
        module:         THIS_MODULE,
        attach:         pcl711_attach,
        detach:         pcl711_detach,
-       board_name:     boardtypes,
+       board_name:     &boardtypes[0].name,
        num_names:      n_boardtypes,
        offset:         sizeof(boardtype),
 };
@@ -189,7 +179,7 @@ typedef struct {
 
 #define devpriv ((pcl711_private *)dev->private)
 
-static void pcl711_interrupt(int irq, void *d, struct pt_regs *regs)
+static irqreturn_t pcl711_interrupt(int irq, void *d PT_REGS_ARG)
 {
        int lo, hi;
        int data;
@@ -212,6 +202,7 @@ static void pcl711_interrupt(int irq, void *d, struct pt_regs *regs)
                s->async->events |= COMEDI_CB_EOA;
        }
        comedi_event(dev, s, s->async->events);
+       return IRQ_HANDLED;
 }
 
 static void pcl711_set_changain(comedi_device * dev, int chan)
@@ -219,7 +210,7 @@ static void pcl711_set_changain(comedi_device * dev, int chan)
        int chan_register;
 
        outb(CR_RANGE(chan), dev->iobase + PCL711_GAIN);
-       
+
        chan_register=CR_CHAN(chan);
 
        if (this_board->is_8112) {
@@ -266,11 +257,11 @@ static int pcl711_ai_insn(comedi_device *dev,comedi_subdevice *s,
                        hi = inb(dev->iobase + PCL711_AD_HI);
                        if (!(hi & PCL711_DRDY))
                                goto ok;
-                       udelay(1);
+                       comedi_udelay(1);
                }
                rt_printk("comedi%d: pcl711: A/D timeout\n", dev->minor);
                return -ETIME;
-       
+
 ok:
                lo = inb(dev->iobase + PCL711_AD_LO);
 
@@ -498,19 +489,18 @@ static int pcl711_detach(comedi_device * dev)
 static int pcl711_attach(comedi_device * dev, comedi_devconfig * it)
 {
        int ret;
-       int iobase;
-       int irq;
+       unsigned long iobase;
+       unsigned int irq;
        comedi_subdevice *s;
 
        /* claim our I/O space */
 
        iobase = it->options[0];
-       printk("comedi%d: pcl711: 0x%04x ", dev->minor, iobase);
-       if (check_region(iobase, PCL711_SIZE) < 0) {
+       printk("comedi%d: pcl711: 0x%04lx ", dev->minor, iobase);
+       if (!request_region(iobase, PCL711_SIZE, "pcl711")) {
                printk("I/O port conflict\n");
                return -EIO;
        }
-       request_region(iobase, PCL711_SIZE, "pcl711");
        dev->iobase = iobase;
 
        /* there should be a sanity check here */
@@ -520,22 +510,21 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it)
 
        /* grab our IRQ */
        irq = it->options[1];
-       if (irq < 0 || irq > this_board->maxirq) {
+       if (irq > this_board->maxirq) {
                printk("irq out of range\n");
                return -EINVAL;
        }
        if (irq) {
                if (comedi_request_irq(irq, pcl711_interrupt, 0, "pcl711", dev)) {
-                       printk("unable to allocate irq %d\n", irq);
+                       printk("unable to allocate irq %u\n", irq);
                        return -EINVAL;
                } else {
-                       printk("( irq = %d )\n", irq);
+                       printk("( irq = %u )\n", irq);
                }
        }
        dev->irq = irq;
 
-       dev->n_subdevices = 4;
-       if((ret=alloc_subdevices(dev))<0)
+       if((ret=alloc_subdevices(dev, 4))<0)
                return ret;
        if((ret=alloc_private(dev,sizeof(pcl711_private)))<0)
                return ret;
@@ -543,13 +532,15 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it)
        s = dev->subdevices + 0;
        /* AI subdevice */
        s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND;
        s->n_chan = this_board->n_aichan;
        s->maxdata = 0xfff;
        s->len_chanlist = 1;
        s->range_table = this_board->ai_range_type;
        s->insn_read = pcl711_ai_insn;
        if(irq){
+               dev->read_subdev = s;
+               s->subdev_flags |= SDF_CMD_READ;
                s->do_cmdtest = pcl711_ai_cmdtest;
                s->do_cmd = pcl711_ai_cmd;
        }
@@ -557,7 +548,7 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it)
        s++;
        /* AO subdevice */
        s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITEABLE;
+       s->subdev_flags = SDF_WRITABLE;
        s->n_chan = this_board->n_aochan;
        s->maxdata = 0xfff;
        s->len_chanlist = 1;
@@ -578,7 +569,7 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it)
        s++;
        /* 16-bit digital out */
        s->type = COMEDI_SUBD_DO;
-       s->subdev_flags = SDF_WRITEABLE;
+       s->subdev_flags = SDF_WRITABLE;
        s->n_chan = 16;
        s->maxdata = 1;
        s->len_chanlist = 16;