Applied comedi_indent script to source.
authorIan Abbott <abbotti@mev.co.uk>
Tue, 25 Mar 2008 12:10:13 +0000 (12:10 +0000)
committerIan Abbott <abbotti@mev.co.uk>
Tue, 25 Mar 2008 12:10:13 +0000 (12:10 +0000)
comedi/drivers/adv_pci1723.c

index bf3efa149eb73da9af35828b7ca6817c8346b52d..66db550f9a1d4fab9b24d88498e6cacd0a660f6e 100644 (file)
@@ -1,4 +1,4 @@
-/***************************************************************************************************
+/*******************************************************************************
    comedi/drivers/pci1723.c
 
    COMEDI - Linux Control and Measurement Device Interface
@@ -18,7 +18,7 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-**************************************************************************************************/
+*******************************************************************************/
 /*
 Driver:       adv_pci1723
 Description:  the driver of adv pci-1723
@@ -31,12 +31,11 @@ Status:       works
 Configuration Options:  none
 */
 
-
 #include <linux/comedidev.h>
 
-#include <linux/pci.h>                  /* for PCI devices */
+#include <linux/pci.h>         /* for PCI devices */
 
-#define ADVANTECH_VENDOR        0x13fe  /* Advantech PCI vendor ID */
+#define ADVANTECH_VENDOR        0x13fe /* Advantech PCI vendor ID */
 
 // hardware types of the cards
 #define TYPE_PCI1723 0
@@ -44,80 +43,79 @@ Configuration Options:  none
 #define IORANGE_1723  0x2A
 
 /* all the registers for the pci1723 board */
-#define PCI1723_DA(N)   ((N)<<1)                /* W:   D/A register N (0 to 7) */
+#define PCI1723_DA(N)   ((N)<<1)       /* W:   D/A register N (0 to 7) */
 
-#define PCI1723_SYN_SET  0x12                   /*synchronized set register       */
-#define PCI1723_ALL_CHNNELE_SYN_STROBE  0x12    /*synchronized status register    */
+#define PCI1723_SYN_SET  0x12  /*synchronized set register       */
+#define PCI1723_ALL_CHNNELE_SYN_STROBE  0x12   /*synchronized status register    */
 
-#define PCI1723_RANGE_CALIBRATION_MODE 0x14     /* range and calibration mode   */
-#define PCI1723_RANGE_CALIBRATION_STATUS 0x14   /* range and calibration status */
+#define PCI1723_RANGE_CALIBRATION_MODE 0x14    /* range and calibration mode   */
+#define PCI1723_RANGE_CALIBRATION_STATUS 0x14  /* range and calibration status */
 
-#define PCI1723_CONTROL_CMD_CALIBRATION_FUN 0x16 /* SADC control command for calibration function */
-#define PCI1723_STATUS_CMD_CALIBRATION_FUN 0x16  /* SADC control status for calibration function */
+#define PCI1723_CONTROL_CMD_CALIBRATION_FUN 0x16       /* SADC control command for calibration function */
+#define PCI1723_STATUS_CMD_CALIBRATION_FUN 0x16        /* SADC control status for calibration function */
 
-#define PCI1723_CALIBRATION_PARA_STROBE 0x18    /* Calibration parameter strobe */
+#define PCI1723_CALIBRATION_PARA_STROBE 0x18   /* Calibration parameter strobe */
 
-#define PCI1723_DIGITAL_IO_PORT_SET 0x1A        /* Digital I/O port setting */
-#define PCI1723_DIGITAL_IO_PORT_MODE 0x1A       /* Digital I/O port mode*/
+#define PCI1723_DIGITAL_IO_PORT_SET 0x1A       /* Digital I/O port setting */
+#define PCI1723_DIGITAL_IO_PORT_MODE 0x1A      /* Digital I/O port mode */
 
-#define PCI1723_WRITE_DIGITAL_OUTPUT_CMD 0x1C   /* Write digital output command */
-#define PCI1723_READ_DIGITAL_INPUT_DATA 0x1C    /* Read digital input data */
+#define PCI1723_WRITE_DIGITAL_OUTPUT_CMD 0x1C  /* Write digital output command */
+#define PCI1723_READ_DIGITAL_INPUT_DATA 0x1C   /* Read digital input data */
 
-#define PCI1723_WRITE_CAL_CMD 0x1E              /* Write calibration command */
-#define PCI1723_READ_CAL_STATUS 0x1E            /* Read calibration status */
+#define PCI1723_WRITE_CAL_CMD 0x1E     /* Write calibration command */
+#define PCI1723_READ_CAL_STATUS 0x1E   /* Read calibration status */
 
-#define PCI1723_SYN_STROBE 0x20                 /* Synchronized strobe */
+#define PCI1723_SYN_STROBE 0x20        /* Synchronized strobe */
 
-#define PCI1723_RESET_ALL_CHN_STROBE 0x22       /* Reset all D/A channels strobe */
+#define PCI1723_RESET_ALL_CHN_STROBE 0x22      /* Reset all D/A channels strobe */
 
-#define PCI1723_RESET_CAL_CONTROL_STROBE 0x24   /* Reset the calibration controller strobe */
+#define PCI1723_RESET_CAL_CONTROL_STROBE 0x24  /* Reset the calibration controller strobe */
 
-#define PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE 0x26/* Change D/A channels output type strobe */
+#define PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE 0x26     /* Change D/A channels output type strobe */
 
-#define PCI1723_SELECT_CALIBRATION 0x28         /* Select the calibration Ref_V */
+#define PCI1723_SELECT_CALIBRATION 0x28        /* Select the calibration Ref_V */
 
 //static unsigned short pci_list_builded=0;     /*=1 list of card is know */
 
-static const comedi_lrange range_pci1723={ 1, {
-       BIP_RANGE(10)
-       }
+static const comedi_lrange range_pci1723 = { 1, {
+                       BIP_RANGE(10)
+       }
 };
 
 /*
  * Board descriptions for pci1723 boards.
  */
 typedef struct pci1723_board_struct {
-       const char *name;
-       int     vendor_id;      // PCI vendor a device ID of card
-       int     device_id;
-       int   iorange;
-       char  cardtype;
-       int     n_aochan;       // num of D/A chans
-       int     n_diochan;      // num of DIO chans
-       int   ao_maxdata;       // resolution of D/A
-     const comedi_lrange *rangelist_ao; // rangelist for D/A
-}boardtype;
-
-static const boardtype boardtypes[] =
-{
-   {
-       name: "pci1723",
-       vendor_id: ADVANTECH_VENDOR,
-       device_id: 0x1723,
-       iorange: IORANGE_1723,
-       cardtype: TYPE_PCI1723,
-       n_aochan: 8,
-       n_diochan: 16,
-       ao_maxdata: 0xffff,
-       rangelist_ao: &range_pci1723
-   },
+       const char *name;
+       int vendor_id;          // PCI vendor a device ID of card
+       int device_id;
+       int iorange;
+       char cardtype;
+       int n_aochan;           // num of D/A chans
+       int n_diochan;          // num of DIO chans
+       int ao_maxdata;         // resolution of D/A
+       const comedi_lrange *rangelist_ao;      // rangelist for D/A
+} boardtype;
+
+static const boardtype boardtypes[] = {
+       {
+             name:     "pci1723",
+             vendor_id:ADVANTECH_VENDOR,
+             device_id:0x1723,
+             iorange:  IORANGE_1723,
+             cardtype:TYPE_PCI1723,
+             n_aochan:8,
+             n_diochan:16,
+             ao_maxdata:0xffff,
+             rangelist_ao:&range_pci1723,
+               },
 };
 
 /* This is used by modprobe to translate PCI IDs to drivers.  Should
  * only be used for PCI and ISA-PnP devices */
-static struct pci_device_id pci1723_pci_table[] = __devinitdata{
-       {PCI_VENDOR_ID_ADVANTECH, 0x1723, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {0}
+static struct pci_device_id pci1723_pci_table[] = __devinitdata {
+       {PCI_VENDOR_ID_ADVANTECH, 0x1723, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       {0}
 };
 
 MODULE_DEVICE_TABLE(pci, pci1723_pci_table);
@@ -134,26 +132,25 @@ static int pci1723_detach(comedi_device * dev);
 #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype))
 
 static comedi_driver driver_pci1723 = {
-     driver_name:"adv_pci1723",
-     module:THIS_MODULE,
-     attach:pci1723_attach,
-     detach:pci1723_detach,
-     num_names:n_boardtypes,
-     board_name:&boardtypes[0].name,
-     offset:sizeof(boardtype),
+      driver_name:"adv_pci1723",
+      module:THIS_MODULE,
+      attach:pci1723_attach,
+      detach:pci1723_detach,
+      num_names:n_boardtypes,
+      board_name:&boardtypes[0].name,
+      offset:sizeof(boardtype),
 };
 
 /* this structure is for data unique to this hardware driver. */
 typedef struct {
-       int valid;                      //card is usable;
+       int valid;              //card is usable;
 
-       struct pci_dev *pcidev;
-       unsigned char  da_range[8];     // D/A output range for each channel
+       struct pci_dev *pcidev;
+       unsigned char da_range[8];      // D/A output range for each channel
 
-       sampl_t ao_data[8];             // data output buffer
+       sampl_t ao_data[8];     // data output buffer
 } pci1723_private;
 
-
 /*the following macro to make it easy to
 * access the private structure.
 */
@@ -161,123 +158,122 @@ typedef struct {
 
 #define this_board ((const boardtype *)dev->board_ptr)
 
-
-
 /*
  *   the pci1723 card reset;
  */
 static int pci1723_reset(comedi_device * dev)
 {
-       int i;
-       rt_printk("adv_pci1723 EDBG: BGN: pci1723_reset(...)\n");
+       int i;
+       rt_printk("adv_pci1723 EDBG: BGN: pci1723_reset(...)\n");
 
-       outw(0x01, dev->iobase + PCI1723_SYN_SET);                      // set synchronous output mode
+       outw(0x01, dev->iobase + PCI1723_SYN_SET);      // set synchronous output mode
 
-       for (i = 0; i < 8; i++) {
-               // set all outputs to 0V
-               devpriv->ao_data[i] = 0x8000;
-               outw(devpriv->ao_data[i], dev->iobase + PCI1723_DA(i));
-               // set all ranges to +/- 10V
-               devpriv->da_range[i] = 0;
-               outw(((devpriv->da_range[i] << 4) | i), PCI1723_RANGE_CALIBRATION_MODE);
-       }
+       for (i = 0; i < 8; i++) {
+               // set all outputs to 0V
+               devpriv->ao_data[i] = 0x8000;
+               outw(devpriv->ao_data[i], dev->iobase + PCI1723_DA(i));
+               // set all ranges to +/- 10V
+               devpriv->da_range[i] = 0;
+               outw(((devpriv->da_range[i] << 4) | i),
+                       PCI1723_RANGE_CALIBRATION_MODE);
+       }
 
-       outw(0, dev->iobase + PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE); // update ranges
-       outw(0, dev->iobase + PCI1723_SYN_STROBE);      // update outputs
+       outw(0, dev->iobase + PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE);   // update ranges
+       outw(0, dev->iobase + PCI1723_SYN_STROBE);      // update outputs
 
-       // set asynchronous output mode
-       outw(0, dev->iobase + PCI1723_SYN_SET);
+       // set asynchronous output mode
+       outw(0, dev->iobase + PCI1723_SYN_SET);
 
-       rt_printk("adv_pci1723 EDBG: END: pci1723_reset(...)\n");
-       return 0;
+       rt_printk("adv_pci1723 EDBG: END: pci1723_reset(...)\n");
+       return 0;
 }
 
-static int pci1723_insn_read_ao(comedi_device * dev, comedi_subdevice * s, comedi_insn *insn, lsampl_t *data)
+static int pci1723_insn_read_ao(comedi_device * dev, comedi_subdevice * s,
+       comedi_insn * insn, lsampl_t * data)
 {
-       int n,chan;
+       int n, chan;
 
-       chan=CR_CHAN(insn->chanspec);
-       rt_printk(" adv_PCI1723 DEBUG: pci1723_insn_read_ao() ----- \n");
-       for (n=0; n<insn->n; n++)
-               data[n]=devpriv->ao_data[chan];
+       chan = CR_CHAN(insn->chanspec);
+       rt_printk(" adv_PCI1723 DEBUG: pci1723_insn_read_ao() ----- \n");
+       for (n = 0; n < insn->n; n++)
+               data[n] = devpriv->ao_data[chan];
 
-       return n;
+       return n;
 }
 
 /*
   analog data output;
 */
 static int pci1723_ao_write_winsn(comedi_device * dev, comedi_subdevice * s,
-       comedi_insn * insn, lsampl_t * data)
+       comedi_insn * insn, lsampl_t * data)
 {
-     int n,chan;
-     chan=CR_CHAN(insn->chanspec);
+       int n, chan;
+       chan = CR_CHAN(insn->chanspec);
+
+       rt_printk("PCI1723: the pci1723_ao_write_winsn() ------\n");
 
-     rt_printk("PCI1723: the pci1723_ao_write_winsn() ------\n");
+       for (n = 0; n < insn->n; n++) {
 
-     for (n=0; n<insn->n; n++)
-      {
-       
-          devpriv->ao_data[chan]=data[n];
-          outw(data[n], dev->iobase+PCI1723_DA(chan));
-       }
+               devpriv->ao_data[chan] = data[n];
+               outw(data[n], dev->iobase + PCI1723_DA(chan));
+       }
 
-     return n;
+       return n;
 }
 
 /*
   digital i/o config/query
 */
-static int pci1723_dio_insn_config(comedi_device *dev, comedi_subdevice *s,
-       comedi_insn *insn, lsampl_t *data)
+static int pci1723_dio_insn_config(comedi_device * dev, comedi_subdevice * s,
+       comedi_insn * insn, lsampl_t * data)
 {
-       unsigned int mask;
-       unsigned int bits;
-       unsigned short dio_mode;
-
-       mask = 1 << CR_CHAN(insn->chanspec);
-       if (mask & 0x00FF) {
-               bits = 0x00FF;
-       } else {
-               bits = 0xFF00;
-       }
-       switch (data[0]) {
-       case INSN_CONFIG_DIO_INPUT:
-               s->io_bits &= ~bits;
-               break;
-       case INSN_CONFIG_DIO_OUTPUT:
-               s->io_bits |= bits;
-               break;
-       case INSN_CONFIG_DIO_QUERY:
-               data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
-               return insn->n;
-       default:
-               return -EINVAL;
-       }
-
-       // update hardware DIO mode
-       dio_mode = 0x0000;      // low byte output, high byte output
-       if ((s->io_bits & 0x00FF) == 0)
-               dio_mode |= 0x0001;     // low byte input
-       if ((s->io_bits & 0xFF00) == 0)
-               dio_mode |= 0x0002;     // high byte input
-       outw(dio_mode, dev->iobase + PCI1723_DIGITAL_IO_PORT_SET);
-       return 1;
+       unsigned int mask;
+       unsigned int bits;
+       unsigned short dio_mode;
+
+       mask = 1 << CR_CHAN(insn->chanspec);
+       if (mask & 0x00FF) {
+               bits = 0x00FF;
+       } else {
+               bits = 0xFF00;
+       }
+       switch (data[0]) {
+       case INSN_CONFIG_DIO_INPUT:
+               s->io_bits &= ~bits;
+               break;
+       case INSN_CONFIG_DIO_OUTPUT:
+               s->io_bits |= bits;
+               break;
+       case INSN_CONFIG_DIO_QUERY:
+               data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
+               return insn->n;
+       default:
+               return -EINVAL;
+       }
+
+       // update hardware DIO mode
+       dio_mode = 0x0000;      // low byte output, high byte output
+       if ((s->io_bits & 0x00FF) == 0)
+               dio_mode |= 0x0001;     // low byte input
+       if ((s->io_bits & 0xFF00) == 0)
+               dio_mode |= 0x0002;     // high byte input
+       outw(dio_mode, dev->iobase + PCI1723_DIGITAL_IO_PORT_SET);
+       return 1;
 }
 
 /*
   digital i/o bits read/write
 */
-static int pci1723_dio_insn_bits(comedi_device *dev, comedi_subdevice *s,
-       comedi_insn *insn, lsampl_t *data)
+static int pci1723_dio_insn_bits(comedi_device * dev, comedi_subdevice * s,
+       comedi_insn * insn, lsampl_t * data)
 {
-       if (data[0]) {
-               s->state &= ~data[0];
-               s->state |= (data[0] & data[1]);
-               outw(s->state, dev->iobase + PCI1723_WRITE_DIGITAL_OUTPUT_CMD);
-       }
-       data[1] = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
-       return 2;
+       if (data[0]) {
+               s->state &= ~data[0];
+               s->state |= (data[0] & data[1]);
+               outw(s->state, dev->iobase + PCI1723_WRITE_DIGITAL_OUTPUT_CMD);
+       }
+       data[1] = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
+       return 2;
 }
 
 /*
@@ -286,147 +282,148 @@ static int pci1723_dio_insn_bits(comedi_device *dev, comedi_subdevice *s,
  */
 static int pci1723_attach(comedi_device * dev, comedi_devconfig * it)
 {
-       comedi_subdevice *s;
-       int ret,subdev,n_subdevices;
-       //unsigned short io_addr[5],master,irq;
-       //struct pcilst_struct *card=NULL;
-     struct pci_dev *pcidev;
-     unsigned int iobase;
-       unsigned char pci_bus,pci_slot,pci_func;
-       //int dma;
-       //unsigned long pages;
-       //unsigned long physLas0,physLas1,physLcfg;
-     int opt_bus, opt_slot;
-       const char *errstr;
-
-     rt_printk("comedi%d: adv_pci1723: board=%s",dev->minor,this_board->name);
-
-     opt_bus = it->options[0];
-       opt_slot = it->options[1];
-
-       if((ret=alloc_private(dev,sizeof(pci1723_private)))<0)
-       {
-               rt_printk(" - Allocation failed!\n");
-               return -ENOMEM;
-       }
-
-       /* Look for matching PCI device */
-       errstr = "not found!";
-       pcidev = NULL;
-       while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH,this_board->device_id, pcidev)))
-       {
-               /* Found matching vendor/device. */
-               if (opt_bus || opt_slot) {
-                       /* Check bus/slot. */
-                       if (opt_bus != pcidev->bus->number
-                                       || opt_slot != PCI_SLOT(pcidev->devfn))
-                               continue;       /* no match */
-               }
-               /*
-                * Look for device that isn't in use.
-                * Enable PCI device and request regions.
-                */
-               if (pci_enable_device(pcidev)) {
-                       errstr = "failed to enable PCI device!";
-                       continue;
-               }
-               if (pci_request_regions(pcidev, "adl_pci1723")) {
-                       errstr = "in use or I/O port conflict!";
-                       continue;
-               }
-               break;
-       }
-
-       if (!pcidev) {
-               if (opt_bus || opt_slot) {
-                       rt_printk(" - Card at b:s %d:%d %s\n",
-                                       opt_bus, opt_slot, errstr);
-               } else {
-                       rt_printk(" - Card %s\n", errstr);
-               }
-               return -EIO;
-       }
-
-       pci_bus = pcidev->bus->number;
-       pci_slot = PCI_SLOT(pcidev->devfn);
-       pci_func = PCI_FUNC(pcidev->devfn);
-       iobase = pci_resource_start(pcidev, 2);
-
-       rt_printk(", b:s:f=%d:%d:%d, io=0x%4x",pci_bus,pci_slot,pci_func,iobase);
-
-     dev->iobase=iobase;
-
-       dev->board_name = this_board->name;
-       devpriv->pcidev = pcidev;
-
-
-     n_subdevices = 0;
-
-     if (this_board->n_aochan) n_subdevices++;
-     if (this_board->n_diochan) n_subdevices++;
-
-     if((ret=alloc_subdevices(dev, n_subdevices))<0)
-       {
-             rt_printk(" - Allocation failed!\n");
-             return ret;
-       }
-
-       pci1723_reset(dev);
-       subdev = 0;
-       if (this_board->n_aochan)
-       {
-               s = dev->subdevices + subdev;
-               dev->write_subdev = s;
-               s->type = COMEDI_SUBD_AO;
-               s->subdev_flags = SDF_WRITEABLE|SDF_GROUND|SDF_COMMON;
-               s->n_chan = this_board->n_aochan;
-               s->maxdata = this_board->ao_maxdata;
-               s->len_chanlist = this_board->n_aochan;
-            s->range_table = this_board->rangelist_ao;
-
-               s->insn_write=pci1723_ao_write_winsn;
-            s->insn_read=pci1723_insn_read_ao;
-
-               // read DIO config
-               switch (inw(dev->iobase + PCI1723_DIGITAL_IO_PORT_MODE) & 0x03) {
-               case 0x00:      // low byte output, high byte output
-                       s->io_bits = 0xFFFF;
-                       break;
-               case 0x01:      // low byte input, high byte output
-                       s->io_bits = 0xFF00;
-                       break;
-               case 0x02:      // low byte output, high byte input
-                       s->io_bits = 0x00FF;
-                       break;
-               case 0x03:      // low byte input, high byte input
-                       s->io_bits = 0x0000;
-                       break;
-               }
-               // read DIO port state
-               s->state = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
-
-               subdev++;
-       }
-
-       if (this_board->n_diochan)
-       {
-               s = dev->subdevices + subdev;
-               s->type = COMEDI_SUBD_DIO;
-               s->subdev_flags = SDF_READABLE|SDF_WRITABLE|SDF_GROUND|SDF_COMMON;
-               s->n_chan = this_board->n_diochan;
-               s->maxdata = 1;
-               s->len_chanlist = this_board->n_diochan;
-               s->range_table = &range_digital;
-               s->insn_config = pci1723_dio_insn_config;
-               s->insn_bits = pci1723_dio_insn_bits;
-               subdev++;
-       }
-
-       devpriv->valid=1;
-
-       pci1723_reset(dev);
-
-       return 0;
+       comedi_subdevice *s;
+       int ret, subdev, n_subdevices;
+       //unsigned short io_addr[5],master,irq;
+       //struct pcilst_struct *card=NULL;
+       struct pci_dev *pcidev;
+       unsigned int iobase;
+       unsigned char pci_bus, pci_slot, pci_func;
+       //int dma;
+       //unsigned long pages;
+       //unsigned long physLas0,physLas1,physLcfg;
+       int opt_bus, opt_slot;
+       const char *errstr;
+
+       rt_printk("comedi%d: adv_pci1723: board=%s", dev->minor,
+               this_board->name);
+
+       opt_bus = it->options[0];
+       opt_slot = it->options[1];
+
+       if ((ret = alloc_private(dev, sizeof(pci1723_private))) < 0) {
+               rt_printk(" - Allocation failed!\n");
+               return -ENOMEM;
+       }
+
+       /* Look for matching PCI device */
+       errstr = "not found!";
+       pcidev = NULL;
+       while (NULL != (pcidev =
+                       pci_get_device(PCI_VENDOR_ID_ADVANTECH,
+                               this_board->device_id, pcidev))) {
+               /* Found matching vendor/device. */
+               if (opt_bus || opt_slot) {
+                       /* Check bus/slot. */
+                       if (opt_bus != pcidev->bus->number
+                               || opt_slot != PCI_SLOT(pcidev->devfn))
+                               continue;       /* no match */
+               }
+               /*
+                * Look for device that isn't in use.
+                * Enable PCI device and request regions.
+                */
+               if (pci_enable_device(pcidev)) {
+                       errstr = "failed to enable PCI device!";
+                       continue;
+               }
+               if (pci_request_regions(pcidev, "adl_pci1723")) {
+                       errstr = "in use or I/O port conflict!";
+                       continue;
+               }
+               break;
+       }
+
+       if (!pcidev) {
+               if (opt_bus || opt_slot) {
+                       rt_printk(" - Card at b:s %d:%d %s\n",
+                               opt_bus, opt_slot, errstr);
+               } else {
+                       rt_printk(" - Card %s\n", errstr);
+               }
+               return -EIO;
+       }
+
+       pci_bus = pcidev->bus->number;
+       pci_slot = PCI_SLOT(pcidev->devfn);
+       pci_func = PCI_FUNC(pcidev->devfn);
+       iobase = pci_resource_start(pcidev, 2);
+
+       rt_printk(", b:s:f=%d:%d:%d, io=0x%4x", pci_bus, pci_slot, pci_func,
+               iobase);
+
+       dev->iobase = iobase;
+
+       dev->board_name = this_board->name;
+       devpriv->pcidev = pcidev;
+
+       n_subdevices = 0;
+
+       if (this_board->n_aochan)
+               n_subdevices++;
+       if (this_board->n_diochan)
+               n_subdevices++;
+
+       if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) {
+               rt_printk(" - Allocation failed!\n");
+               return ret;
+       }
+
+       pci1723_reset(dev);
+       subdev = 0;
+       if (this_board->n_aochan) {
+               s = dev->subdevices + subdev;
+               dev->write_subdev = s;
+               s->type = COMEDI_SUBD_AO;
+               s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
+               s->n_chan = this_board->n_aochan;
+               s->maxdata = this_board->ao_maxdata;
+               s->len_chanlist = this_board->n_aochan;
+               s->range_table = this_board->rangelist_ao;
+
+               s->insn_write = pci1723_ao_write_winsn;
+               s->insn_read = pci1723_insn_read_ao;
+
+               // read DIO config
+               switch (inw(dev->iobase + PCI1723_DIGITAL_IO_PORT_MODE) & 0x03) {
+               case 0x00:      // low byte output, high byte output
+                       s->io_bits = 0xFFFF;
+                       break;
+               case 0x01:      // low byte input, high byte output
+                       s->io_bits = 0xFF00;
+                       break;
+               case 0x02:      // low byte output, high byte input
+                       s->io_bits = 0x00FF;
+                       break;
+               case 0x03:      // low byte input, high byte input
+                       s->io_bits = 0x0000;
+                       break;
+               }
+               // read DIO port state
+               s->state = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
+
+               subdev++;
+       }
+
+       if (this_board->n_diochan) {
+               s = dev->subdevices + subdev;
+               s->type = COMEDI_SUBD_DIO;
+               s->subdev_flags =
+                       SDF_READABLE | SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
+               s->n_chan = this_board->n_diochan;
+               s->maxdata = 1;
+               s->len_chanlist = this_board->n_diochan;
+               s->range_table = &range_digital;
+               s->insn_config = pci1723_dio_insn_config;
+               s->insn_bits = pci1723_dio_insn_bits;
+               subdev++;
+       }
+
+       devpriv->valid = 1;
+
+       pci1723_reset(dev);
+
+       return 0;
 }
 
 /*
@@ -439,25 +436,22 @@ static int pci1723_attach(comedi_device * dev, comedi_devconfig * it)
  */
 static int pci1723_detach(comedi_device * dev)
 {
-       printk("comedi%d: pci1723: remove\n", dev->minor);
-
-       if (dev->private)
-       {
-               if (devpriv->valid)
-                       pci1723_reset(dev);
-
-               if (devpriv->pcidev)
-               {
-                       if (dev->iobase)
-                       {
-                        pci_release_regions(devpriv->pcidev);
-                               pci_disable_device(devpriv->pcidev);
-                       }
-                       pci_dev_put(devpriv->pcidev);
-               }
-       }
-
-       return 0;
+       printk("comedi%d: pci1723: remove\n", dev->minor);
+
+       if (dev->private) {
+               if (devpriv->valid)
+                       pci1723_reset(dev);
+
+               if (devpriv->pcidev) {
+                       if (dev->iobase) {
+                               pci_release_regions(devpriv->pcidev);
+                               pci_disable_device(devpriv->pcidev);
+                       }
+                       pci_dev_put(devpriv->pcidev);
+               }
+       }
+
+       return 0;
 }
 
 /*