Merge tag 'hsi-for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-hsi
[cascardo/linux.git] / drivers / staging / comedi / drivers / ni_atmio.c
index d039352..2bd9f69 100644 (file)
@@ -98,233 +98,135 @@ are not supported.
 #include "ni_stc.h"
 #include "8255.h"
 
-#define ATMIO 1
-#undef PCIMIO
-
 /*
  *  AT specific setup
  */
 
-#define NI_SIZE 0x20
-
-#define MAX_N_CALDACS 32
-
 static const struct ni_board_struct ni_boards[] = {
-       {.device_id = 44,
-        .isapnp_id = 0x0000,   /* XXX unknown */
-        .name = "at-mio-16e-1",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 8192,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .has_8255 = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {mb88341},
-        },
-       {.device_id = 25,
-        .isapnp_id = 0x1900,
-        .name = "at-mio-16e-2",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 2048,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 2000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .has_8255 = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {mb88341},
-        },
-       {.device_id = 36,
-        .isapnp_id = 0x2400,
-        .name = "at-mio-16e-10",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {.device_id = 37,
-        .isapnp_id = 0x2500,
-        .name = "at-mio-16de-10",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 1,
-        },
-       {.device_id = 38,
-        .isapnp_id = 0x2600,
-        .name = "at-mio-64e-3",
-        .n_adchan = 64,
-        .adbits = 12,
-        .ai_fifo_depth = 2048,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 2000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .has_8255 = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        },
-       {.device_id = 39,
-        .isapnp_id = 0x2700,
-        .name = "at-mio-16xe-50",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_8,
-        .ai_speed = 50000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 50000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043},
-        .has_8255 = 0,
-        },
-       {.device_id = 50,
-        .isapnp_id = 0x0000,   /* XXX unknown */
-        .name = "at-mio-16xe-10",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {.device_id = 51,
-        .isapnp_id = 0x0000,   /* XXX unknown */
-        .name = "at-ai-16xe-10",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,     /* unknown */
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        }
+       {
+               .name           = "at-mio-16e-1",
+               .device_id      = 44,
+               .isapnp_id      = 0x0000,       /* XXX unknown */
+               .n_adchan       = 16,
+               .ai_maxdata     = 0x0fff,
+               .ai_fifo_depth  = 8192,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 1000,
+               .caldac         = { mb88341 },
+       }, {
+               .name           = "at-mio-16e-2",
+               .device_id      = 25,
+               .isapnp_id      = 0x1900,
+               .n_adchan       = 16,
+               .ai_maxdata     = 0x0fff,
+               .ai_fifo_depth  = 2048,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 2000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 1000,
+               .caldac         = { mb88341 },
+       }, {
+               .name           = "at-mio-16e-10",
+               .device_id      = 36,
+               .isapnp_id      = 0x2400,
+               .n_adchan       = 16,
+               .ai_maxdata     = 0x0fff,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 10000,
+               .caldac         = { ad8804_debug },
+       }, {
+               .name           = "at-mio-16de-10",
+               .device_id      = 37,
+               .isapnp_id      = 0x2500,
+               .n_adchan       = 16,
+               .ai_maxdata     = 0x0fff,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 10000,
+               .caldac         = { ad8804_debug },
+               .has_8255       = 1,
+       }, {
+               .name           = "at-mio-64e-3",
+               .device_id      = 38,
+               .isapnp_id      = 0x2600,
+               .n_adchan       = 64,
+               .ai_maxdata     = 0x0fff,
+               .ai_fifo_depth  = 2048,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 2000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 1000,
+               .caldac         = { ad8804_debug },
+       }, {
+               .name           = "at-mio-16xe-50",
+               .device_id      = 39,
+               .isapnp_id      = 0x2700,
+               .n_adchan       = 16,
+               .ai_maxdata     = 0xffff,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_8,
+               .ai_speed       = 50000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0x0fff,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 50000,
+               .caldac         = { dac8800, dac8043 },
+       }, {
+               .name           = "at-mio-16xe-10",
+               .device_id      = 50,
+               .isapnp_id      = 0x0000,       /* XXX unknown */
+               .n_adchan       = 16,
+               .ai_maxdata     = 0xffff,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .ao_maxdata     = 0xffff,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 1000,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       }, {
+               .name           = "at-ai-16xe-10",
+               .device_id      = 51,
+               .isapnp_id      = 0x0000,       /* XXX unknown */
+               .n_adchan       = 16,
+               .ai_maxdata     = 0xffff,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,    /* unknown */
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
 };
 
 static const int ni_irqpin[] = {
        -1, -1, -1, 0, 1, 2, -1, 3, -1, -1, 4, 5, 6, -1, -1, 7
 };
 
-#define interrupt_pin(a)       (ni_irqpin[(a)])
-
-#define IRQ_POLARITY 0
-
-#define NI_E_IRQ_FLAGS         0
-
-struct ni_private {
-       struct pnp_dev *isapnp_dev;
-       NI_PRIVATE_COMMON
-
-};
-
-/* How we access registers */
-
-#define ni_writel(a, b)                (outl((a), (b)+dev->iobase))
-#define ni_readl(a)            (inl((a)+dev->iobase))
-#define ni_writew(a, b)                (outw((a), (b)+dev->iobase))
-#define ni_readw(a)            (inw((a)+dev->iobase))
-#define ni_writeb(a, b)                (outb((a), (b)+dev->iobase))
-#define ni_readb(a)            (inb((a)+dev->iobase))
-
-/* How we access windowed registers */
-
-/* We automatically take advantage of STC registers that can be
- * read/written directly in the I/O space of the board.  The
- * AT-MIO devices map the low 8 STC registers to iobase+addr*2. */
-
-static void ni_atmio_win_out(struct comedi_device *dev, uint16_t data, int addr)
-{
-       struct ni_private *devpriv = dev->private;
-       unsigned long flags;
-
-       spin_lock_irqsave(&devpriv->window_lock, flags);
-       if ((addr) < 8) {
-               ni_writew(data, addr * 2);
-       } else {
-               ni_writew(addr, Window_Address);
-               ni_writew(data, Window_Data);
-       }
-       spin_unlock_irqrestore(&devpriv->window_lock, flags);
-}
-
-static uint16_t ni_atmio_win_in(struct comedi_device *dev, int addr)
-{
-       struct ni_private *devpriv = dev->private;
-       unsigned long flags;
-       uint16_t ret;
-
-       spin_lock_irqsave(&devpriv->window_lock, flags);
-       if (addr < 8) {
-               ret = ni_readw(addr * 2);
-       } else {
-               ni_writew(addr, Window_Address);
-               ret = ni_readw(Window_Data);
-       }
-       spin_unlock_irqrestore(&devpriv->window_lock, flags);
-
-       return ret;
-}
+#include "ni_mio_common.c"
 
 static struct pnp_device_id device_ids[] = {
        {.id = "NIC1900", .driver_data = 0},
@@ -337,8 +239,6 @@ static struct pnp_device_id device_ids[] = {
 
 MODULE_DEVICE_TABLE(pnp, device_ids);
 
-#include "ni_mio_common.c"
-
 static int ni_isapnp_find_board(struct pnp_dev **dev)
 {
        struct pnp_dev *isapnp_dev = NULL;
@@ -353,20 +253,17 @@ static int ni_isapnp_find_board(struct pnp_dev **dev)
                if (isapnp_dev == NULL || isapnp_dev->card == NULL)
                        continue;
 
-               if (pnp_device_attach(isapnp_dev) < 0) {
-                       printk
-                        ("ni_atmio: %s found but already active, skipping.\n",
-                         ni_boards[i].name);
+               if (pnp_device_attach(isapnp_dev) < 0)
                        continue;
-               }
+
                if (pnp_activate_dev(isapnp_dev) < 0) {
                        pnp_device_detach(isapnp_dev);
                        return -EAGAIN;
                }
-               if (!pnp_port_valid(isapnp_dev, 0)
-                   || !pnp_irq_valid(isapnp_dev, 0)) {
+
+               if (!pnp_port_valid(isapnp_dev, 0) ||
+                   !pnp_irq_valid(isapnp_dev, 0)) {
                        pnp_device_detach(isapnp_dev);
-                       printk("ni_atmio: pnp invalid port or irq, aborting\n");
                        return -ENOMEM;
                }
                break;
@@ -388,11 +285,13 @@ static int ni_getboardtype(struct comedi_device *dev)
 
        }
        if (device_id == 255)
-               printk(" can't find board\n");
+               dev_err(dev->class_dev, "can't find board\n");
         else if (device_id == 0)
-               printk(" EEPROM read error (?) or device not found\n");
+               dev_err(dev->class_dev,
+                       "EEPROM read error (?) or device not found\n");
         else
-               printk(" unknown device ID %d -- contact author\n", device_id);
+               dev_err(dev->class_dev,
+                       "unknown device ID %d -- contact author\n", device_id);
 
        return -1;
 }
@@ -413,11 +312,6 @@ static int ni_atmio_attach(struct comedi_device *dev,
                return ret;
        devpriv = dev->private;
 
-       devpriv->stc_writew = &ni_atmio_win_out;
-       devpriv->stc_readw = &ni_atmio_win_in;
-       devpriv->stc_writel = &win_out2;
-       devpriv->stc_readl = &win_in2;
-
        iobase = it->options[0];
        irq = it->options[1];
        isapnp_dev = NULL;
@@ -428,10 +322,10 @@ static int ni_atmio_attach(struct comedi_device *dev,
 
                iobase = pnp_port_start(isapnp_dev, 0);
                irq = pnp_irq(isapnp_dev, 0);
-               devpriv->isapnp_dev = isapnp_dev;
+               comedi_set_hw_dev(dev, &isapnp_dev->dev);
        }
 
-       ret = comedi_request_region(dev, iobase, NI_SIZE);
+       ret = comedi_request_region(dev, iobase, 0x20);
        if (ret)
                return ret;
 
@@ -443,31 +337,23 @@ static int ni_atmio_attach(struct comedi_device *dev,
 
        dev->board_ptr = ni_boards + board;
        boardtype = comedi_board(dev);
-
-       printk(" %s", boardtype->name);
        dev->board_name = boardtype->name;
 
        /* irq stuff */
 
        if (irq != 0) {
-               if (irq > 15 || ni_irqpin[irq] == -1) {
-                       printk(" invalid irq %u\n", irq);
+               if (irq > 15 || ni_irqpin[irq] == -1)
                        return -EINVAL;
-               }
-               printk(" ( irq = %u )", irq);
-               ret = request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
-                                 "ni_atmio", dev);
-
-               if (ret < 0) {
-                       printk(" irq not available\n");
+               ret = request_irq(irq, ni_E_interrupt, 0,
+                                 dev->board_name, dev);
+               if (ret < 0)
                        return -EINVAL;
-               }
                dev->irq = irq;
        }
 
        /* generic E series stuff in ni_mio_common.c */
 
-       ret = ni_E_init(dev);
+       ret = ni_E_init(dev, ni_irqpin[dev->irq], 0);
        if (ret < 0)
                return ret;
 
@@ -477,12 +363,14 @@ static int ni_atmio_attach(struct comedi_device *dev,
 
 static void ni_atmio_detach(struct comedi_device *dev)
 {
-       struct ni_private *devpriv = dev->private;
+       struct pnp_dev *isapnp_dev;
 
        mio_common_detach(dev);
        comedi_legacy_detach(dev);
-       if (devpriv->isapnp_dev)
-               pnp_device_detach(devpriv->isapnp_dev);
+
+       isapnp_dev = dev->hw_dev ? to_pnp_dev(dev->hw_dev) : NULL;
+       if (isapnp_dev)
+               pnp_device_detach(isapnp_dev);
 }
 
 static struct comedi_driver ni_atmio_driver = {