From: David Schleef Date: Sun, 4 Mar 2001 08:39:26 +0000 (+0000) Subject: converted all drivers to use comedi_recognize() with name info X-Git-Tag: r0_7_58~74 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8ffc1eee8a513e47eac9f0950f1a54364f969cd0;p=comedi.git converted all drivers to use comedi_recognize() with name info pulled from board structures. removed dev->board in all drivers in favor of dev->board_ptr 8255: removed way-old strcmp() cb_pcidas: fixed PCI code for 2.4 mpc8260cpm: removed comments, replaced skel with mpc8260cpm pcl726: changed way subdevices are allocated pcl818: changed way subdevices are allocated --- diff --git a/comedi/drivers/8255.c b/comedi/drivers/8255.c index 04a56adc..25e18aee 100644 --- a/comedi/drivers/8255.c +++ b/comedi/drivers/8255.c @@ -241,9 +241,6 @@ static int dev_8255_attach(comedi_device *dev,comedi_devconfig *it) int iobase; int i; - if(strcmp("8255",it->board_name)) - return 0; - printk("comedi%d: 8255:",dev->minor); dev->board_name="8255"; diff --git a/comedi/drivers/adl_pci9118.c b/comedi/drivers/adl_pci9118.c index b08304e4..caf9d1da 100644 --- a/comedi/drivers/adl_pci9118.c +++ b/comedi/drivers/adl_pci9118.c @@ -123,8 +123,6 @@ comedi_lrange range_pci9118hg={ 8, { static int pci9118_attach(comedi_device *dev,comedi_devconfig *it); static int pci9118_detach(comedi_device *dev); -static int pci9118_recognize(char *name); -static void pci9118_register_boards(void); typedef struct { char *name; // driver name @@ -171,9 +169,9 @@ comedi_driver driver_pci9118={ module: THIS_MODULE, attach: pci9118_attach, detach: pci9118_detach, - recognize: pci9118_recognize, - register_boards: pci9118_register_boards, num_names: n_boardtypes, + board_name: boardtypes, + offset: sizeof(boardtype), }; typedef struct{ @@ -223,7 +221,7 @@ typedef struct{ }pci9118_private; #define devpriv ((pci9118_private *)dev->private) -#define this_board (boardtypes+dev->board) +#define this_board ((boardtype *)dev->board_ptr) /* ============================================================================== @@ -1242,22 +1240,20 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; int ret,pages,i; - unsigned int board,iobase_a,iobase_9,irq; + unsigned int iobase_a,iobase_9,irq; struct amcc_struct *card=NULL; unsigned char pci_bus,pci_slot,pci_func; unsigned int master; - board=dev->board; - - rt_printk("comedi%d: adl_pci9118: board=%s",dev->minor,boardtypes[board].name); + printk("comedi%d: adl_pci9118: board=%s",dev->minor,this_board->name); if ((it->options[0]<1)&(it->options[1]<1)) { // use autodetection - if ((card=find_free_card_by_device(boardtypes[board].device_id))==NULL) { + if ((card=find_free_card_by_device(this_board->device_id))==NULL) { rt_printk(" - Unused card not found in system!\n"); return -EIO; } } else { - switch (find_free_card_by_position(boardtypes[board].device_id,it->options[0],it->options[1],&card)) { + switch (find_free_card_by_position(this_board->device_id,it->options[0],it->options[1],&card)) { case 1: rt_printk(" - Card not found on requested position!\n"); return -EIO; @@ -1281,16 +1277,16 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) rt_printk(", b:s:f=%d:%d:%d, io=0x%4x, 0x%4x",pci_bus,pci_slot,pci_func,iobase_9,iobase_a); - if (check_region(iobase_9, boardtypes[board].iorange_9118) < 0) { + if (check_region(iobase_9, this_board->iorange_9118) < 0) { rt_printk("I/O port conflict\n"); return -EIO; } dev->iobase=iobase_9; - dev->iosize=boardtypes[board].iorange_9118; + dev->iosize=this_board->iorange_9118; request_region(dev->iobase, dev->iosize, "ADLink PCI-9118"); - dev->board_name = boardtypes[board].name; + dev->board_name = this_board->name; if((ret=alloc_private(dev,sizeof(pci9118_private)))<0) return -ENOMEM; @@ -1298,7 +1294,7 @@ static int pci9118_attach(comedi_device *dev,comedi_devconfig *it) devpriv->amcc=card; devpriv->master=master; devpriv->iobase_a=iobase_a; - devpriv->iosize_a=boardtypes[board].iorange_amcc; + devpriv->iosize_a=this_board->iorange_amcc; request_region(devpriv->iobase_a, devpriv->iosize_a, "ADLink PCI-9118"); if (irq>0) { @@ -1459,33 +1455,6 @@ static int pci9118_detach(comedi_device *dev) return 0; } -/* -============================================================================== -*/ -static int pci9118_recognize(char *name) -{ - int i; - - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { - return i; - } - } - - return -1; -} - -void pci9118_register_boards(void) -{ - int i; - - for (i = 0; i < driver_pci9118.num_names; i++) { - driver_pci9118.board_name[i] = boardtypes[i].name; - driver_pci9118.board_id[i] = i; - } - -} - #ifdef MODULE /* ============================================================================== diff --git a/comedi/drivers/cb_pcidas.c b/comedi/drivers/cb_pcidas.c index e69fc4ec..aa56194d 100644 --- a/comedi/drivers/cb_pcidas.c +++ b/comedi/drivers/cb_pcidas.c @@ -46,7 +46,7 @@ #include #include -#define CB_ID 0x1307 // PCI vendor number of ComputerBoards +#define PCI_VENDOR_CB 0x1307 // PCI vendor number of ComputerBoards #define N_BOARDS 10 // Number of boards in cb_pcidas_boards /* PCI-DAS base addresses */ @@ -249,6 +249,9 @@ comedi_driver driver_cb_pcidas={ module: THIS_MODULE, attach: cb_pcidas_attach, detach: cb_pcidas_detach, + board_name: cb_pcidas_boards, + num_names: sizeof(cb_pcidas_boards)/sizeof(cb_pcidas_board), + offset: sizeof(cb_pcidas_board), }; static int cb_pcidas_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); @@ -260,13 +263,12 @@ static int cb_pcidas_ns_to_timer(unsigned int *ns,int round); /* * Attach is called by the Comedi core to configure the driver - * for a particular board. _recognize() has already been called, - * and dev->board contains whatever _recognize returned. + * for a particular board. */ static int cb_pcidas_attach(comedi_device *dev, comedi_devconfig *it) { comedi_subdevice *s; - struct pci_dev* pci_dev_temp; + struct pci_dev* pcidev; int index; printk("comedi%d: cb_pcidas: ",dev->minor); @@ -280,76 +282,67 @@ static int cb_pcidas_attach(comedi_device *dev, comedi_devconfig *it) /* * Probe the device to determine what device in the series it is. */ - devpriv->pci_dev = NULL; - pci_dev_temp = pci_devices; - printk("\n"); - while(pci_dev_temp && !devpriv->pci_dev) - { - if ((pci_dev_temp->bus->number == it->options[0]) && - (PCI_SLOT(pci_dev_temp->devfn) == it->options[1])) - { - devpriv->pci_dev = pci_dev_temp; - if (pci_dev_temp->vendor == CB_ID) - { - index = 0; - while((index < N_BOARDS) && - (cb_pcidas_boards[index].device_id != - pci_dev_temp->device)) - index++; - if (index < N_BOARDS) - { - dev->board = index; - printk("Found %s at requested position\n", - cb_pcidas_boards[dev->board].name); - } - else - { - rt_printk("Not a supported ComputerBoards card on requested " - "position\n"); - return -EIO; + pci_for_each_dev(pcidev){ + if(pcidev->vendor==PCI_VENDOR_CB){ + if(it->options[0] && it->options[1]){ + if(pcidev->bus->number==it->options[0] && + PCI_SLOT(pcidev->devfn)==it->options[1]){ + break; } - } - else - { - rt_printk("Not a ComputerBoards card on requested position\n"); - return -EIO; + }else{ + break; } } - pci_dev_temp = pci_dev_temp->next; } - if (!devpriv->pci_dev) - { - rt_printk("No card on requested position\n"); + if(!pcidev){ + printk("Not a ComputerBoards card on requested position\n"); return -EIO; } -/* - * Initialize devpriv->control_status and devpriv->adc_fifo to point to - * their base address. - */ + for(index=0;indexdevice){ + goto found; + } + } + printk("Not a supported ComputerBoards card on requested position\n"); + return -EIO; + +found: + devpriv->pci_dev = pcidev; + dev->board_ptr = cb_pcidas_boards+index; + printk("Found %s at requested position\n",cb_pcidas_boards[index].name); + + /* + * Initialize devpriv->control_status and devpriv->adc_fifo to point to + * their base address. + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) devpriv->control_status = devpriv->pci_dev->base_address[CONT_STAT_BADRINDEX] & PCI_BASE_ADDRESS_IO_MASK; - devpriv->adc_fifo = devpriv->pci_dev->base_address[ADC_FIFO_BADRINDEX] & + devpriv->adc_fifo = + devpriv->pci_dev->base_address[ADC_FIFO_BADRINDEX] & + PCI_BASE_ADDRESS_IO_MASK; +#else + devpriv->control_status = + devpriv->pci_dev->resource[CONT_STAT_BADRINDEX].start & + PCI_BASE_ADDRESS_IO_MASK; + devpriv->adc_fifo = + devpriv->pci_dev->resource[ADC_FIFO_BADRINDEX].start & PCI_BASE_ADDRESS_IO_MASK; +#endif /* * Warn about the status of the driver. */ - if (cb_pcidas_boards[dev->board].status == 2) + if (thisboard->status == 2) printk("WARNING: DRIVER FOR THIS BOARD NOT CHECKED WITH MANUAL. " "WORKS ASSUMING FULL COMPATIBILITY WITH PCI-DAS1200. " "PLEASE REPORT USAGE TO .\n"); -/* - * Initialize dev->board_ptr. This can point to an element in the - * cb_pcidas_boards array, for quick access to board-specific information. - */ - dev->board_ptr = cb_pcidas_boards + dev->board; - /* * Initialize dev->board_name. Note that we can use the "thisboard" * macro now, since we just initialized it in the last line. diff --git a/comedi/drivers/daqboard2000.c b/comedi/drivers/daqboard2000.c index 65167003..04700e20 100644 --- a/comedi/drivers/daqboard2000.c +++ b/comedi/drivers/daqboard2000.c @@ -299,6 +299,16 @@ comedi_driver driver_daqboard2000 = { detach: daqboard2000_detach, }; +typedef struct { + char *name; + int id; +}boardtype; +static boardtype boardtypes[]={ + { "ids2", DAQBOARD2000_SUBSYSTEM_IDS2 }, + { "ids4", DAQBOARD2000_SUBSYSTEM_IDS4 }, +}; +#define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) +#define this_board ((boardtype *)dev->board_ptr) typedef struct { enum { @@ -659,21 +669,17 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) if (card->hdr_type == PCI_HEADER_TYPE_NORMAL) { u32 id; + int i; pci_read_config_dword(card, PCI_SUBSYSTEM_VENDOR_ID, &id); - switch(id){ - case DAQBOARD2000_SUBSYSTEM_IDS2: - printk(" ids2"); - dev->board=0; - break; - case DAQBOARD2000_SUBSYSTEM_IDS4: - printk(" ids4"); - dev->board=1; - break; - default: - printk(" unknown subsystem id %08x\n", id); - printk(" (pretend it is an ids2)"); - dev->board=0; - break; + for(i=0;iboard_ptr=boardtypes+i; + } + } + if(!dev->board_ptr){ + printk(" unknown subsystem id %08x (pretend it is an ids2)",id); + dev->board_ptr=boardtypes; } }else{ printk(" abnormal pci header type !?!?\n"); @@ -742,12 +748,7 @@ static int daqboard2000_attach(comedi_device *dev, comedi_devconfig *it) dev->iobase = (int)devpriv->daq; - switch(dev->board){ - case card_daqboard_2000: - default: - dev->board_name = "daqboard/2000"; - break; - } + dev->board_name = this_board->name; s = dev->subdevices + 0; /* ai subdevice */ diff --git a/comedi/drivers/das08-new.c b/comedi/drivers/das08-new.c index a8418a7e..47cce6aa 100644 --- a/comedi/drivers/das08-new.c +++ b/comedi/drivers/das08-new.c @@ -326,7 +326,7 @@ static struct das08_board_struct das08_boards[]={ }, #endif }; -static int n_boardtypes = sizeof(das08_boards)/sizeof(das08_boards[0]); +#define n_boardtypes sizeof(das08_boards)/sizeof(das08_boards[0]) struct das08_private_struct{ @@ -335,7 +335,7 @@ struct das08_private_struct{ }; #define devpriv ((struct das08_private_struct *)dev->private) -#define thisboard (das08_boards+dev->board) +#define thisboard ((struct das08_board_struct *)dev->board_ptr) #define TIMEOUT 1000 @@ -489,17 +489,15 @@ static int das08ao_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn * static int das08_attach(comedi_device *dev,comedi_devconfig *it); static int das08_detach(comedi_device *dev); -static int das08_recognize(char *name); -static void das08_register_boards(void); comedi_driver driver_das08={ driver_name: "das08", module: THIS_MODULE, attach: das08_attach, detach: das08_detach, - recognize: das08_recognize, - register_boards: das08_register_boards, - num_names: sizeof(das08_boards) / sizeof(das08_board), + board_name: das08_boards, + num_names: sizeof(das08_boards)/sizeof(struct das08_board_struct), + offset: sizeof(struct das08_board_struct), }; static int das08_attach(comedi_device *dev,comedi_devconfig *it) @@ -514,7 +512,6 @@ static int das08_attach(comedi_device *dev,comedi_devconfig *it) return -EIO; } - dev->board_ptr = das08_boards+dev->board; dev->board_name = thisboard->name; dev->iosize = DAS08_SIZE; @@ -600,30 +597,5 @@ static int das08_detach(comedi_device *dev) return 0; } -static int das08_recognize(char *name) -{ - int i; - - for(i=0;iboardtype]) #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtypes[0])) +static int das08_attach(comedi_device *dev,comedi_devconfig *it); +static int das08_detach(comedi_device *dev); +comedi_driver driver_das08={ + driver_name: "das08", + module: THIS_MODULE, + attach: das08_attach, + detach: das08_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(struct boardtype_struct), +}; + + static int das08_ai(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { @@ -281,16 +282,6 @@ static int das08_di(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) return di_unpack(bits,it); } -static int das08_recognize(char *name) -{ - int i; - - for(i=0;iboard = das16_probe(dev, it); - - dev->board_ptr = das16_boards + dev->board; + dev->board_ptr = das16_boards + das16_probe(dev, it); dev->board_name = thisboard->name; - if(thisboard->size<0x400){ printk(" 0x%04x-0x%04x\n", diff --git a/comedi/drivers/das1600.c b/comedi/drivers/das1600.c index 2a02996b..59131571 100644 --- a/comedi/drivers/das1600.c +++ b/comedi/drivers/das1600.c @@ -130,22 +130,43 @@ static comedi_lrange _range_unipolar5 = { 1, { RANGE( 0, 5 ) }}; +typedef struct{ + char *name; + int ai_bits; + comedi_lrange *bip_range; + comedi_lrange *unip_range; +}boardtype; +static boardtype boardtypes[]={ + { "das1601/12", 12, + bip_range: &range_das1601_ai_10_bipolar, + unip_range: &range_das1601_ai_10_unipolar, + }, + { "das1602/12", 12, + bip_range: &range_das1602_ai_10_bipolar, + unip_range: &range_das1602_ai_10_unipolar, + }, + { "das1602/16", 16, + bip_range: &range_das1602_ai_10_bipolar, + unip_range: &range_das1602_ai_10_unipolar, + }, +}; +#define n_boardtypes sizeof(boardtypes)/sizeof(boardtype) +#define this_board ((boardtype *)dev->board_ptr) + static int das1600_attach(comedi_device *dev,comedi_devconfig *it); static int das1600_detach(comedi_device *dev); -static int das1600_recognize(char *name); comedi_driver driver_das1600={ driver_name: "das1600", module: THIS_MODULE, attach: das1600_attach, detach: das1600_detach, - recognize: das1600_recognize, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), }; typedef struct { - enum { - card_1601_12, card_1602_12, card_1602_16 - } card; int dma; int crystal; enum { @@ -229,14 +250,10 @@ static int das1600_ai(comedi_device * dev, comedi_subdevice * s, comedi_trig * i rt_printk("das1600: timeout\n"); } - switch (devpriv->card) { - case card_1601_12: - case card_1602_12: - it->data[i] = (hi << 4) | (lo >> 4); - break; - case card_1602_16: - it->data[i] = (hi << 8) | lo; - break; + if(this_board->ai_bits==12){ + it->data[i] = (hi << 4) | (lo >> 4); + }else{ + it->data[i] = (hi << 8) | lo; } } return i; @@ -359,14 +376,6 @@ static int das1600_do(comedi_device * dev, comedi_subdevice * s, comedi_trig * i 4 == unipolar 5V (0V -- +5V) 5 == unipolar user supplied (0V -- +xV) */ -static int das1600_recognize(char *name) -{ - if (!strcmp("das1601/12", name)) return card_1601_12; - if (!strcmp("das1602/12", name)) return card_1602_12; - if (!strcmp("das1602/16", name)) return card_1602_16; - - return -1; -} static int das1600_attach(comedi_device * dev, comedi_devconfig * it) { @@ -384,18 +393,7 @@ static int das1600_attach(comedi_device * dev, comedi_devconfig * it) request_region(dev->iobase, DAS1600_BASE_SIZE, "das1600"); request_region(dev->iobase + 0x400, DAS1600_DIO_SIZE, "das1600"); - switch(dev->board){ - case card_1601_12: - default: - dev->board_name = "das1601/12"; - break; - case card_1602_12: - dev->board_name = "das1601/12"; - break; - case card_1602_16: - dev->board_name = "das1602/16"; - break; - } + dev->board_name=*(char **)dev->board_ptr; dev->n_subdevices=5; @@ -404,7 +402,6 @@ static int das1600_attach(comedi_device * dev, comedi_devconfig * it) if((result=alloc_subdevices(dev))<0) return result; - devpriv->card = dev->board; devpriv->dma = it->options[2]; devpriv->crystal = it->options[3]; devpriv->adc_mux = (it->options[4] == 1) ? adc_singleended : adc_diff; @@ -417,29 +414,14 @@ static int das1600_attach(comedi_device * dev, comedi_devconfig * it) s->type = COMEDI_SUBD_AI; s->subdev_flags = SDF_READABLE|SDF_RT; s->n_chan = (devpriv->adc_mux == adc_singleended) ? 16 : 8; - s->maxdata = (dev->board == card_1602_16) ? 0xffff : 0xfff; + s->maxdata = (1<ai_bits)-1; s->trig[0] = das1600_ai; - switch (dev->board) { - case card_1601_12: - switch (devpriv->adc_range) { - case adc_bipolar10: - s->range_table = &range_das1601_ai_10_bipolar; - break; - case adc_unipolar10: - s->range_table = &range_das1601_ai_10_unipolar; - break; - }; + switch (devpriv->adc_range) { + case adc_bipolar10: + s->range_table = this_board->bip_range; break; - case card_1602_12: - case card_1602_16: - switch (devpriv->adc_range) { - case adc_bipolar10: - s->range_table = &range_das1602_ai_10_bipolar; - break; - case adc_unipolar10: - s->range_table = &range_das1602_ai_10_unipolar; - break; - }; + case adc_unipolar10: + s->range_table = this_board->unip_range; break; } diff --git a/comedi/drivers/das1800.c b/comedi/drivers/das1800.c index 2c66da45..aa69a31f 100644 --- a/comedi/drivers/das1800.c +++ b/comedi/drivers/das1800.c @@ -147,8 +147,6 @@ enum{ static int das1800_attach(comedi_device *dev, comedi_devconfig *it); static int das1800_detach(comedi_device *dev); -static int das1800_recognize(char *name); -static void das1800_register_boards(void); int das1800_probe(comedi_device *dev); static int das1800_cancel(comedi_device *dev, comedi_subdevice *s); static void das1800_interrupt(int irq, void *d, struct pt_regs *regs); @@ -465,9 +463,9 @@ comedi_driver driver_das1800={ module: THIS_MODULE, attach: das1800_attach, detach: das1800_detach, - recognize: das1800_recognize, - register_boards: das1800_register_boards, - num_names: sizeof(das1800_boards) / sizeof(das1800_board), + num_names: sizeof(das1800_boards) / sizeof(das1800_board), + board_name: das1800_boards, + offset: sizeof(das1800_board), }; /* @@ -484,6 +482,7 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) int irq = it->options[1]; int dma0, dma1; int iobase2; + int board; // disable unsafe isa dma if we are using real time kernel #ifdef CONFIG_COMEDI_RT @@ -527,14 +526,14 @@ static int das1800_attach(comedi_device *dev, comedi_devconfig *it) dev->iobase = iobase; dev->iosize = DAS1800_SIZE; - dev->board = das1800_probe(dev); - if(dev->board < 0) + board = das1800_probe(dev); + if(board < 0) { printk("unable to determine board type\n"); return -ENODEV; } - dev->board_ptr = das1800_boards + dev->board; + dev->board_ptr = das1800_boards + board; dev->board_name = thisboard->name; // if it is an 'ao' board with fancy analog out then we need extra io ports @@ -760,129 +759,80 @@ static int das1800_detach(comedi_device *dev) return 0; }; -static int das1800_recognize(char *name) -{ - if(!strcmp(name, "das-1701st")) - return das1701st; - if(!strcmp(name, "das-1701st-da")) - return das1701st_da; - if(!strcmp(name, "das-1702st")) - return das1702st; - if(!strcmp(name, "das-1702st-da")) - return das1702st_da; - if(!strcmp(name, "das-1702hr")) - return das1702hr; - if(!strcmp(name, "das-1702hr-da")) - return das1702hr_da; - if(!strcmp(name, "das-1701ao")) - return das1701ao; - if(!strcmp(name, "das-1702ao")) - return das1702ao; - if(!strcmp(name, "das-1801st")) - return das1801st; - if(!strcmp(name, "das-1801st-da")) - return das1801st_da; - if(!strcmp(name, "das-1802st")) - return das1802st; - if(!strcmp(name, "das-1802st-da")) - return das1802st_da; - if(!strcmp(name, "das-1802hr")) - return das1802hr; - if(!strcmp(name, "das-1802hr-da")) - return das1802hr_da; - if(!strcmp(name, "das-1801hc")) - return das1801hc; - if(!strcmp(name, "das-1802hc")) - return das1802hc; - if(!strcmp(name, "das-1801ao")) - return das1801ao; - if(!strcmp(name, "das-1802ao")) - return das1802ao; - - return -1; -} -void das1800_register_boards(void) -{ - int i; - - for(i = 0; i < driver_das1800.num_names; i++) - { - driver_das1800.board_name[i] = das1800_boards[i].name; - driver_das1800.board_id[i] = i; - } - return; -} - /* probes and checks das-1800 series board type */ int das1800_probe(comedi_device *dev) { int id; + int board; + id = (inb(dev->iobase + DAS1800_DIGITAL) >> 4) & 0xf; /* get id bits */ + board = ((das1800_board *)dev->board_ptr) - das1800_boards; + switch(id) { // das-1800st-da case 0x3: - if(dev->board == das1801st_da || dev->board == das1802st_da || - dev->board == das1701st_da || dev->board == das1702st_da) + if(board == das1801st_da || board == das1802st_da || + board == das1701st_da || board == das1702st_da) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1800st-da series\n"); return das1801st; break; // das-1800hr-da case 0x4: - if(dev->board == das1802hr_da || dev->board == das1702hr_da) + if(board == das1802hr_da || board == das1702hr_da) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1802hr-da\n"); return das1802hr; break; case 0x5: - if(dev->board == das1801ao || dev->board == das1802ao || - dev->board == das1701ao || dev->board == das1702ao) + if(board == das1801ao || board == das1802ao || + board == das1701ao || board == das1702ao) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1800ao series\n"); return das1801ao; break; case 0x6: - if(dev->board == das1802hr || dev->board == das1702hr) + if(board == das1802hr || board == das1702hr) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1802hr\n"); return das1802hr; break; case 0x7: - if(dev->board == das1801st || dev->board == das1802st || - dev->board == das1701st || dev->board == das1702st) + if(board == das1801st || board == das1802st || + board == das1701st || board == das1702st) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1800st series\n"); return das1801st; break; case 0x8: - if(dev->board == das1801hc || dev->board == das1802hc) + if(board == das1801hc || board == das1802hc) { - printk(" Board model: %s\n", (das1800_boards + dev->board)->name); - return dev->board; + printk(" Board model: %s\n", das1800_boards[board].name); + return board; } printk(" Board model (probed, not recommended): das-1800hc series\n"); return das1801hc; break; default : printk(" Board model: probe returned 0x%x (unknown)\n", id); - return dev->board; + return board; break; } return -1; diff --git a/comedi/drivers/das800.c b/comedi/drivers/das800.c index 259afc70..b93a318d 100644 --- a/comedi/drivers/das800.c +++ b/comedi/drivers/das800.c @@ -212,8 +212,6 @@ static comedi_lrange *das800_range_lkup[] = { static int das800_attach(comedi_device *dev,comedi_devconfig *it); static int das800_detach(comedi_device *dev); -static int das800_recognize(char *name); -static void das800_register_boards(void); static int das800_cancel(comedi_device *dev, comedi_subdevice *s); comedi_driver driver_das800={ @@ -221,9 +219,9 @@ comedi_driver driver_das800={ module: THIS_MODULE, attach: das800_attach, detach: das800_detach, - recognize: das800_recognize, - register_boards: das800_register_boards, - num_names: sizeof(das800_boards) / sizeof(das800_board), + num_names: sizeof(das800_boards) / sizeof(das800_board), + board_name: (char **)das800_boards, + offset: sizeof(das800_board), }; static void das800_interrupt(int irq, void *d, struct pt_regs *regs); @@ -240,42 +238,12 @@ int das800_probe(comedi_device *dev); int das800_set_frequency(comedi_device *dev); int das800_load_counter(unsigned int counterNumber, unsigned int counterValue, comedi_device *dev); -static void das800_register_boards(void) -{ - unsigned int i; - - for(i = 0; i < driver_das800.num_names; i++) - { - driver_das800.board_name[i] = das800_boards[i].name; - driver_das800.board_id[i] = i; - } - - return; -} - -static int das800_recognize(char *name) -{ - if(!strcmp(name, "das-800") || !strcmp(name, "das800")) - return das800; - if(!strcmp(name, "cio-das800")) - return ciodas800; - if(!strcmp(name, "das-801")) - return das801; - if(!strcmp(name, "cio-das801")) - return ciodas801; - if(!strcmp(name, "das-802")) - return das802; - if(!strcmp(name, "cio-das802")) - return ciodas802; - - return -1; -} - /* checks and probes das-800 series board type */ int das800_probe(comedi_device *dev) { int id_bits; unsigned long irq_flags; + int board; // 'comedi spin lock irqsave' disables even rt interrupts, we use them to protect indirect addressing comedi_spin_lock_irqsave(&devpriv->spinlock, irq_flags); @@ -283,46 +251,48 @@ int das800_probe(comedi_device *dev) id_bits = inb(dev->iobase + DAS800_ID) & 0x3; /* get id bits */ comedi_spin_unlock_irqrestore(&devpriv->spinlock, irq_flags); + board = thisboard - das800_boards; + switch(id_bits) { case 0x0: - if(dev->board == das800) + if(board == das800) { printk(" Board model: DAS-800\n"); - return dev->board; + return board; } - if(dev->board == ciodas800) + if(board == ciodas800) { printk(" Board model: CIO-DAS800\n"); - return dev->board; + return board; } printk(" Board model (probed): DAS-800\n"); return das800; break; case 0x2: - if(dev->board == das801) + if(board == das801) { printk(" Board model: DAS-801\n"); - return dev->board; + return board; } - if(dev->board == ciodas801) + if(board == ciodas801) { printk(" Board model: CIO-DAS801\n"); - return dev->board; + return board; } printk(" Board model (probed): DAS-801\n"); return das801; break; case 0x3: - if(dev->board == das802) + if(board == das802) { printk(" Board model: DAS-802\n"); - return dev->board; + return board; } - if(dev->board == ciodas802) + if(board == ciodas802) { printk(" Board model: CIO-DAS802\n"); - return dev->board; + return board; } printk(" Board model (probed): DAS-802\n"); return das802; @@ -426,6 +396,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) int iobase = it->options[0]; int irq = it->options[1]; unsigned long irq_flags; + int board; printk("comedi%d: das800: io 0x%x", dev->minor, iobase); if(irq) @@ -450,12 +421,13 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) dev->iobase = iobase; dev->iosize = DAS800_SIZE; - dev->board = das800_probe(dev); - if(dev->board < 0) + board = das800_probe(dev); + if(board < 0) { printk("unable to determine board type\n"); return -ENODEV; } + dev->board_ptr = das800_boards + board; /* grab our IRQ */ if(irq == 1 || irq > 7 || irq < 0) @@ -473,7 +445,6 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) } dev->irq = irq; - dev->board_ptr = das800_boards + dev->board; dev->board_name = thisboard->name; /* allocate and initialize dev->private */ @@ -492,7 +463,7 @@ static int das800_attach(comedi_device *dev, comedi_devconfig *it) s->n_chan = 8; s->len_chanlist = 8; s->maxdata = 0xfff; - s->range_table = das800_range_lkup[dev->board]; + s->range_table = das800_range_lkup[board]; s->do_cmd = das800_ai_do_cmd; s->do_cmdtest = das800_ai_do_cmdtest; s->insn_read = das800_ai_rinsn; diff --git a/comedi/drivers/dt2801.c b/comedi/drivers/dt2801.c index cccf27e9..b8fbb67a 100644 --- a/comedi/drivers/dt2801.c +++ b/comedi/drivers/dt2801.c @@ -197,14 +197,13 @@ static boardtype_t boardtypes[] = }, }; #define n_boardtypes ((sizeof(boardtypes))/(sizeof(boardtypes[0]))) +#define boardtype (*(boardtype_t *)dev->board_ptr) typedef struct{ - boardtype_t *board; comedi_lrange *dac_range_types[2]; }dt2801_private; #define devpriv ((dt2801_private *)dev->private) -#define boardtype (*devpriv->board) static int dt2801_ai_mode0(comedi_device *dev,comedi_subdevice *s,comedi_trig *it); @@ -492,7 +491,8 @@ static int dt2801_attach(comedi_device *dev,comedi_devconfig *it) type=0; havetype: - printk("dt2801: %s at port 0x%x",boardtypes[type].name,iobase); + dev->board_ptr = boardtypes+type; + printk("dt2801: %s at port 0x%x",boardtype.name,iobase); n_ai_chans=probe_number_of_ai_chans(dev); printk(" (ai channels = %d)",n_ai_chans); @@ -505,8 +505,7 @@ havetype: if((ret=alloc_private(dev,sizeof(dt2801_private)))<0) goto out; - devpriv->board=boardtypes+type; - dev->board_name = devpriv->board->name; + dev->board_name = boardtype.name; s=dev->subdevices+0; /* ai subdevice */ diff --git a/comedi/drivers/dt2811.c b/comedi/drivers/dt2811.c index 1b5f8fbe..ffc6370e 100644 --- a/comedi/drivers/dt2811.c +++ b/comedi/drivers/dt2811.c @@ -172,15 +172,36 @@ comedi_lrange range_dt2811_pgl_ai_5_bipolar = { 4, { #define DT2811_INTENB 0x04 #define DT2811_ADMODE 0x03 +typedef struct { + char *name; + comedi_lrange *bip_5; + comedi_lrange *bip_2_5; + comedi_lrange *unip_5; +}boardtype; +static boardtype boardtypes[]={ + { "dt2811-pgh", + &range_dt2811_pgh_ai_5_bipolar, + &range_dt2811_pgh_ai_2_5_bipolar, + &range_dt2811_pgh_ai_5_unipolar, + }, + { "dt2811-pgl", + &range_dt2811_pgl_ai_5_bipolar, + &range_dt2811_pgl_ai_2_5_bipolar, + &range_dt2811_pgl_ai_5_unipolar, + }, +}; +#define this_board ((boardtype *)dev->board_ptr) + static int dt2811_attach(comedi_device *dev,comedi_devconfig *it); static int dt2811_detach(comedi_device *dev); -static int dt2811_recognize(char *name); comedi_driver driver_dt2811={ driver_name: "dt2811", module: THIS_MODULE, attach: dt2811_attach, detach: dt2811_detach, - recognize: dt2811_recognize, + board_name: boardtypes, + num_names: sizeof(boardtypes)/sizeof(boardtype), + offset: sizeof(boardtype), }; static int dt2811_ai(comedi_device * dev, comedi_subdevice * s, comedi_trig * it); @@ -198,9 +219,6 @@ typedef struct { enum { adc_singleended, adc_diff, adc_pseudo_diff } adc_mux; - enum { - adc_bipolar_5, adc_bipolar_2_5, adc_unipolar_5 - } adc_range; enum { dac_bipolar_5, dac_bipolar_2_5, dac_unipolar_5 } dac_range[2]; @@ -209,13 +227,6 @@ typedef struct { #define devpriv ((dt2811_private *)dev->private) -static comedi_lrange *adc_range_types[][2] = -{ - /* dt2811-pgh dt2811-pgl */ - { &range_dt2811_pgh_ai_5_bipolar, &range_dt2811_pgl_ai_5_bipolar }, - { &range_dt2811_pgh_ai_2_5_bipolar, &range_dt2811_pgl_ai_2_5_bipolar }, - { &range_dt2811_pgh_ai_5_unipolar, &range_dt2811_pgl_ai_5_unipolar } -}; static comedi_lrange *dac_range_types[] = { &range_bipolar5, @@ -263,13 +274,6 @@ static void dt2811_interrupt(int irq, void *d, struct pt_regs *regs) 1 == bipolar 2.5V (-2.5V -- +2.5V) 2 == unipolar 5V (0V -- +5V) */ -static int dt2811_recognize(char *name) -{ - if(!strcmp("dt2811-pgh", name))return card_2811_pgh; - if(!strcmp("dt2811-pgl", name))return card_2811_pgl; - - return -1; -} static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) { @@ -277,7 +281,6 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) long flags; int ret; comedi_subdevice *s; - int board = -1; dev->iobase = it->options[0]; @@ -289,12 +292,7 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) } request_region(dev->iobase, DT2811_SIZE, driver_name); - board = dev->board; - if (board == card_2811_pgh) { - dev->board_name = "dt2811-pgh"; - } else if (board == card_2811_pgl) { - dev->board_name = "dt2811-pgl"; - } + dev->board_name = this_board->name; dev->iosize = DT2811_SIZE; #if 0 @@ -350,12 +348,6 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) case 2: devpriv->adc_mux = adc_pseudo_diff; break; default:devpriv->adc_mux = adc_singleended; break; } - switch (it->options[3]) { - case 0: devpriv->adc_range = adc_bipolar_5; break; - case 1: devpriv->adc_range = adc_bipolar_2_5; break; - case 2: devpriv->adc_range = adc_unipolar_5; break; - default:devpriv->adc_range = adc_bipolar_5; break; - } switch (it->options[4]) { case 0: devpriv->dac_range[0] = dac_bipolar_5; break; case 1: devpriv->dac_range[0] = dac_bipolar_2_5; break; @@ -376,7 +368,18 @@ static int dt2811_attach(comedi_device * dev, comedi_devconfig * it) s->n_chan = devpriv->adc_mux == adc_diff ? 8 : 16; s->trig[0] = dt2811_ai; s->maxdata = 0xfff; - s->range_table = adc_range_types[devpriv->adc_range][board]; + switch(it->options[3]){ + case 0: + default: + s->range_table = this_board->bip_5; + break; + case 1: + s->range_table = this_board->bip_2_5; + break; + case 2: + s->range_table = this_board->unip_5; + break; + } s = dev->subdevices + 1; /* ao subdevice */ diff --git a/comedi/drivers/dt282x.c b/comedi/drivers/dt282x.c index 1e99d0e2..abf27fc7 100644 --- a/comedi/drivers/dt282x.c +++ b/comedi/drivers/dt282x.c @@ -279,7 +279,8 @@ static boardtype_t boardtypes[] = dabits: 0, }, }; -static int n_boardtypes = sizeof(boardtypes)/sizeof(boardtype_t); +#define n_boardtypes sizeof(boardtypes)/sizeof(boardtype_t) +#define this_board ((boardtype_t *)dev->board_ptr) typedef struct { @@ -338,13 +339,14 @@ typedef struct { static int dt282x_attach(comedi_device * dev, comedi_devconfig * it); static int dt282x_detach(comedi_device * dev); -static int dt282x_recognize(char *name); comedi_driver driver_dt282x={ driver_name: "dt282x", module: THIS_MODULE, attach: dt282x_attach, detach: dt282x_detach, - recognize: dt282x_recognize, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype_t), }; COMEDI_INITCLEANUP(driver_dt282x); @@ -1354,18 +1356,6 @@ enum{ opt_iobase=0, opt_irq, opt_dma1, opt_dma2, /* i/o base, irq, dma channels }; -static int dt282x_recognize(char *name) -{ - int i; - - for(i=0;iboard_ptr = boardtypes+dev->board; - dev->board_name = boardtypes[dev->board].name; + dev->board_name = this_board->name; if (it->options[opt_iobase]) dev->iobase = it->options[opt_iobase]; diff --git a/comedi/drivers/dt3000.c b/comedi/drivers/dt3000.c index 95c800fc..433a2a5d 100644 --- a/comedi/drivers/dt3000.c +++ b/comedi/drivers/dt3000.c @@ -127,7 +127,8 @@ static dt3k_boardtype dt3k_boardtypes[]={ dabits: 12, }, }; -static int n_dt3k_boards=sizeof(dt3k_boardtypes)/sizeof(dt3k_boardtype); +#define n_dt3k_boards sizeof(dt3k_boardtypes)/sizeof(dt3k_boardtype) +#define this_board ((dt3k_boardtype *)dev->board_ptr) #define DT3000_SIZE (4*0x1000) @@ -429,7 +430,7 @@ static int dt3000_attach(comedi_device *dev,comedi_devconfig *it) return -ENODEV; } - dev->board_name=dt3k_boardtypes[dev->board].name; + dev->board_name=this_board->name; dev->n_subdevices=4; if((ret=alloc_subdevices(dev))<0) @@ -440,9 +441,9 @@ static int dt3000_attach(comedi_device *dev,comedi_devconfig *it) /* ai subdevice */ s->type=COMEDI_SUBD_AI; s->subdev_flags=SDF_READABLE; - s->n_chan=dt3k_boardtypes[dev->board].adchan; + s->n_chan=this_board->adchan; s->trig[0]=dt3k_ai_mode0; - s->maxdata=(1<board].adbits)-1; + s->maxdata=(1<adbits)-1; s->len_chanlist=512; s->range_table=&range_dt3000_ai; /* XXX */ @@ -452,7 +453,7 @@ static int dt3000_attach(comedi_device *dev,comedi_devconfig *it) s->subdev_flags=SDF_WRITEABLE; s->n_chan=2; s->trig[0]=dt3k_ao_mode0; - s->maxdata=(1<board].dabits)-1; + s->maxdata=(1<dabits)-1; s->len_chanlist=1; s->range_table=&range_bipolar10; @@ -528,7 +529,7 @@ static int dt_pci_find_device(comedi_device *dev) { devpriv->pci_bus=pci_bus; devpriv->pci_dev_fn=pci_dev_fn; - dev->board=i; + dev->board_ptr=dt3k_boards+i; return 1; } } @@ -565,7 +566,7 @@ static int dt_pci_probe(comedi_device *dev) int board; devpriv->pci_dev=dt_pci_find_device(NULL,&board); - dev->board=board; + dev->board_ptr=dt3k_boardtypes+board; if(!devpriv->pci_dev) return 0; diff --git a/comedi/drivers/ii_pci20kc.c b/comedi/drivers/ii_pci20kc.c index 9075cab9..a9f1d20e 100644 --- a/comedi/drivers/ii_pci20kc.c +++ b/comedi/drivers/ii_pci20kc.c @@ -176,7 +176,7 @@ static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it) comedi_subdevice *s; pci20xxx_subdev_private *sdp; - dev->n_subdevices = PCI20000_MODULES+1; + dev->n_subdevices = 1+PCI20000_MODULES; if ((ret = alloc_subdevices(dev)) < 0) return ret; if ((ret = alloc_private(dev, sizeof(pci20xxx_private))) < 0) diff --git a/comedi/drivers/mpc8260cpm.c b/comedi/drivers/mpc8260cpm.c index b0e78c75..bed1f4e4 100644 --- a/comedi/drivers/mpc8260cpm.c +++ b/comedi/drivers/mpc8260cpm.c @@ -36,96 +36,38 @@ #include -/* - * Board descriptions for two imaginary boards. Describing the - * boards in this way is optional, and completely driver-dependent. - * Some drivers use arrays such as this, other do not. - */ -typedef struct skel_board_struct{ - char *name; - int ai_chans; - int ai_bits; - int have_dio; -}skel_board; -skel_board skel_boards[] = { - { - name: "mpc8260cpm", - }, -}; -/* - * Useful for shorthand access to the particular board structure - */ -#define thisboard ((skel_board *)dev->board_ptr) - -/* this structure is for data unique to this hardware driver. If - several hardware drivers keep similar information in this structure, - feel free to suggest moving the variable to the comedi_device struct. */ typedef struct{ int data; - /* would be useful for a PCI device */ - struct pci_dev *pci_dev; +}mpc8260cpm_private; +#define devpriv ((mpc8260cpm_private *)dev->private) -}skel_private; -/* - * most drivers define the following macro to make it easy to - * access the private structure. - */ -#define devpriv ((skel_private *)dev->private) - -/* - * The comedi_driver structure tells the Comedi core module - * which functions to call to configure/deconfigure (attach/detach) - * the board, and also about the kernel module that contains - * the device code. - */ -static int skel_attach(comedi_device *dev,comedi_devconfig *it); -static int skel_detach(comedi_device *dev); -static int skel_register_boards(void); -comedi_driver driver_skel={ +static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it); +static int mpc8260cpm_detach(comedi_device *dev); +comedi_driver driver_mpc8260cpm={ driver_name: "dummy", module: THIS_MODULE, - attach: skel_attach, - detach: skel_detach, - register_boards: skel_register_boards, // replacement for recognize + attach: mpc8260cpm_attach, + detach: mpc8260cpm_detach, }; -static int skel_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int skel_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); +static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -/* - * Attach is called by the Comedi core to configure the driver - * for a particular board. _recognize() has already been called, - * and dev->board contains whatever _recognize returned. - */ -static int skel_attach(comedi_device *dev,comedi_devconfig *it) +static int mpc8260cpm_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; int i; - printk("comedi%d: mpc8260: ",dev->minor); + printk("comedi%d: mpc8260cpm: ",dev->minor); -/* - * Initialize dev->board_ptr. This can point to an element in the - * skel_boards array, for quick access to board-specific information. - */ - dev->board_ptr = skel_boards + dev->board; + dev->board_ptr = mpc8260cpm_boards + dev->board; -/* - * Initialize dev->board_name. Note that we can use the "thisboard" - * macro now, since we just initialized it in the last line. - */ dev->board_name = thisboard->name; -/* - * Allocate the private structure area. - */ - if(alloc_private(dev,sizeof(skel_private))<0) + if(alloc_private(dev,sizeof(mpc8260cpm_private))<0) return -ENOMEM; -/* - * Allocate the subdevice structures. - */ dev->n_subdevices=4; if(alloc_subdevices(dev)<0) return -ENOMEM; @@ -137,34 +79,21 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) s->n_chan=32; s->maxdata=1; s->range_table=&range_digital; - s->insn_config = &skel_dio_config; - s->insn_bits = &skel_dio_bits; + s->insn_config = &mpc8260cpm_dio_config; + s->insn_bits = &mpc8260cpm_dio_bits; } return 1; } - -/* - * _detach is called to deconfigure a device. It should deallocate - * resources. - * This function is also called when _attach() fails, so it should be - * careful not to release resources that were not necessarily - * allocated by _attach(). dev->private and dev->subdevices are - * deallocated automatically by the core. - */ -static int skel_detach(comedi_device *dev) +static int mpc8260cpm_detach(comedi_device *dev) { - printk("comedi%d: skel: remove\n",dev->minor); + printk("comedi%d: mpc8260cpm: remove\n",dev->minor); return 0; } -/* - * "instructions" read/write data in "one-shot" or "software-triggered" - * mode. - */ -static int skel_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int mpc8260cpm_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) { int n; unsigned int d; @@ -173,7 +102,7 @@ static int skel_dio_config(comedi_device *dev,comedi_subdevice *s,comedi_insn *i return 2; } -static int skel_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) +static int mpc8260cpm_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data) { int n; unsigned int d; @@ -182,11 +111,5 @@ static int skel_dio_bits(comedi_device *dev,comedi_subdevice *s,comedi_insn *ins return 2; } - - -/* - * A convenient macro that defines init_module() and cleanup_module(), - * as necessary. - */ -COMEDI_INITCLEANUP(driver_skel); +COMEDI_INITCLEANUP(driver_mpc8260cpm); diff --git a/comedi/drivers/ni_atmio.c b/comedi/drivers/ni_atmio.c index 4dffd595..14177807 100644 --- a/comedi/drivers/ni_atmio.c +++ b/comedi/drivers/ni_atmio.c @@ -257,33 +257,17 @@ typedef struct{ static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it); static int ni_atmio_detach(comedi_device *dev); -static int ni_atmio_recognize(char *name); comedi_driver driver_atmio={ driver_name: "ni_atmio", module: THIS_MODULE, attach: ni_atmio_attach, detach: ni_atmio_detach, - recognize: ni_atmio_recognize, }; COMEDI_INITCLEANUP(driver_atmio); #include "ni_mio_common.c" -static int ni_atmio_recognize(char *name) -{ - if(!strcmp(name,"atmio-E")){ - printk("Driver name 'atmio-E' deprecated. Please use 'ni_atmio'.\n"); - return 0; - } - if(!strcmp(name,"ni_atmio")){ - return 0; - } - - return -1; -} - - static int ni_getboardtype(comedi_device *dev); /* clean up allocated resources */ @@ -379,9 +363,11 @@ static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it) board=ni_getboardtype(dev); if(board<0)return -EIO; + + dev->board_ptr=ni_boards + board; - printk(" %s",ni_boards[board].name); - dev->board_name=ni_boards[board].name; + printk(" %s",boardtype.name); + dev->board_name=boardtype.name; /* irq stuff */ @@ -402,8 +388,6 @@ static int ni_atmio_attach(comedi_device *dev,comedi_devconfig *it) if((ret=alloc_private(dev,sizeof(ni_private)))<0) return ret; - - dev->board=board; /* generic E series stuff in ni_mio_common.c */ diff --git a/comedi/drivers/ni_atmio16d.c b/comedi/drivers/ni_atmio16d.c index 5328f5c3..3e575864 100644 --- a/comedi/drivers/ni_atmio16d.c +++ b/comedi/drivers/ni_atmio16d.c @@ -121,15 +121,14 @@ static atmio16_board_t atmio16_boards[]={ has_8255: 1, }, }; -static int n_atmio16_boards=sizeof(atmio16_boards)/sizeof(atmio16_boards[0]); +#define n_atmio16_boards sizeof(atmio16_boards)/sizeof(atmio16_boards[0]) -#define boardtype (atmio16_boards+dev->board) +#define boardtype ((atmio16_board_t *)dev->board_ptr) /* function prototypes */ static int atmio16d_attach(comedi_device *dev,comedi_devconfig *it); static int atmio16d_detach(comedi_device *dev); -static int atmio16d_recognize(char *name); static void atmio16d_interrupt(int irq, void *d, struct pt_regs *regs); static int atmio16d_ai_cmdtest(comedi_device *dev, comedi_subdevice *s, comedi_cmd *cmd); static int atmio16d_ai_cmd(comedi_device *dev, comedi_subdevice *s); @@ -143,7 +142,9 @@ comedi_driver driver_atmio16d={ module: THIS_MODULE, attach: atmio16d_attach, detach: atmio16d_detach, - recognize: atmio16d_recognize, + board_name: atmio16_boards, + num_names: n_atmio16_boards, + offset: sizeof(atmio16_board_t), }; /* range structs */ @@ -655,17 +656,6 @@ static int atmio16d_dio(comedi_device * dev, comedi_subdevice *s, comedi_trig * } -static int atmio16d_recognize(char *name) -{ - int i; - - for(i=0;iiobase = iobase; dev->iosize = ATMIO16D_SIZE; /* board name */ - if (dev->board == 0) - dev->board_name = "at-mio16d"; - else - dev->board_name = "unknown"; - + dev->board_name = boardtype->name; /* set number of subdevices */ - if(dev->board == 0) - dev->n_subdevices=4; - else - dev->n_subdevices=4; + dev->n_subdevices=4; if((ret=alloc_subdevices(dev))<0) return ret; diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index fa21a30a..f031881b 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -176,7 +176,9 @@ static void caldac_setup(comedi_device *dev,comedi_subdevice *s); static int ni_read_eeprom(comedi_device *dev,int addr); static void ni_mio_print_status_a(int status); +#ifdef DEBUG_INTERRUPT static void ni_mio_print_status_b(int status); +#endif static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s); static void ni_handle_fifo_half_full(comedi_device *dev); diff --git a/comedi/drivers/ni_mio_cs.c b/comedi/drivers/ni_mio_cs.c index 05338d80..c3972762 100644 --- a/comedi/drivers/ni_mio_cs.c +++ b/comedi/drivers/ni_mio_cs.c @@ -491,11 +491,10 @@ static int mio_cs_attach(comedi_device *dev,comedi_devconfig *it) } #endif - dev->board=ni_getboardtype(dev,link); + dev->board_ptr = ni_boards + ni_getboardtype(dev,link); - printk(" %s",ni_boards[dev->board].name); - dev->board_name=ni_boards[dev->board].name; - dev->board_ptr = ni_boards+dev->board; + printk(" %s",boardtype.name); + dev->board_name=boardtype.name; if( (ret=comedi_request_irq(dev->irq,ni_E_interrupt,NI_E_IRQ_FLAGS,"ni_mio_cs",dev))<0 ){ printk(" irq not available\n"); diff --git a/comedi/drivers/ni_pcidio.c b/comedi/drivers/ni_pcidio.c index adb90821..10d0ca71 100644 --- a/comedi/drivers/ni_pcidio.c +++ b/comedi/drivers/ni_pcidio.c @@ -146,13 +146,11 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it); static int nidio_detach(comedi_device *dev); -static int nidio_recognize(char *name); comedi_driver driver_pcidio={ driver_name: "ni_pcidio", module: THIS_MODULE, attach: nidio_attach, detach: nidio_detach, - recognize: nidio_recognize, }; typedef struct{ @@ -212,6 +210,7 @@ static nidio_board nidio_boards[]={ }, }; #define n_nidio_boards (sizeof(nidio_boards)/sizeof(nidio_boards[0])) +#define this_board ((nidio_board *)dev->board_ptr) typedef struct{ struct mite_struct *mite; @@ -225,17 +224,6 @@ static int nidio_find_device(comedi_device *dev,int bus,int slot); static int setup_mite(comedi_device *dev); #endif -static int nidio_recognize(char *name) -{ - if(!strcmp(name,"nidio")){ - printk("name \"nidio\" deprecated. Use \"ni_pcidio\"\n"); - return 0; - } - if(!strcmp(name,"ni_pcidio")) - return 0; - return -1; -} - static int nidio96_8255_cb(int dir,int port,int data,void *arg) { int iobase=(int)arg; @@ -425,20 +413,20 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase=mite_setup(devpriv->mite); - dev->board_name=nidio_boards[dev->board].name; + dev->board_name=this_board->name; dev->irq=mite_irq(devpriv->mite); printk(" %s",dev->board_name); - if(!nidio_boards[dev->board].is_diodaq){ - dev->n_subdevices=nidio_boards[dev->board].n_8255; + if(!this_board->is_diodaq){ + dev->n_subdevices=this_board->n_8255; }else{ dev->n_subdevices=1; } if((ret=alloc_subdevices(dev))<0) return ret; - if(!nidio_boards[dev->board].is_diodaq){ - for(i=0;iboard].n_8255;i++){ + if(!this_board->is_diodaq){ + for(i=0;in_8255;i++){ subdev_8255_init(dev,dev->subdevices+i, nidio96_8255_cb,(void *)(dev->iobase+NIDIO_8255_BASE(i))); } @@ -510,7 +498,7 @@ static int nidio_find_device(comedi_device *dev,int bus,int slot) } for(i=0;iboard=i; + dev->board_ptr=nidio_boards+i; devpriv->mite=mite; return 0; diff --git a/comedi/drivers/ni_pcimio.c b/comedi/drivers/ni_pcimio.c index f5b5fde8..f469cc5c 100644 --- a/comedi/drivers/ni_pcimio.c +++ b/comedi/drivers/ni_pcimio.c @@ -350,11 +350,9 @@ static ni_board ni_boards[]={ static int pcimio_attach(comedi_device *dev,comedi_devconfig *it); static int pcimio_detach(comedi_device *dev); -static int pcimio_recognize(char *name); comedi_driver driver_pcimio={ driver_name: "ni_pcimio", module: THIS_MODULE, - recognize: pcimio_recognize, attach: pcimio_attach, detach: pcimio_detach, }; @@ -416,18 +414,6 @@ static int pcimio_detach(comedi_device *dev) return 0; } -static int pcimio_recognize(char *name) -{ - if(!strcmp(name,"pcimio-E")){ - printk("name \"pcimio-E\" deprecated. Use \"ni_pcimio\"\n"); - return 0; - } - if(!strcmp(name,"ni_pcimio")) - return 0; - - return -1; -} - static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) { int ret; @@ -440,8 +426,8 @@ static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) ret=pcimio_find_device(dev,it->options[0],it->options[1]); if(ret<0)return ret; - printk(" %s",ni_boards[dev->board].name); - dev->board_name=ni_boards[dev->board].name; + printk(" %s",boardtype.name); + dev->board_name=boardtype.name; dev->iobase=mite_setup(devpriv->mite); @@ -473,7 +459,7 @@ static int pcimio_find_device(comedi_device *dev,int bus,int slot) slot!=PCI_SLOT(mite->pci_device_fn)) continue; #else - if(bus!=mite->pcidev->bus->number<<8 || + if(bus!=mite->pcidev->bus->number || slot!=PCI_SLOT(mite->pcidev->devfn)) continue; #endif @@ -481,7 +467,7 @@ static int pcimio_find_device(comedi_device *dev,int bus,int slot) for(i=0;iboard=i; + dev->board_ptr=ni_boards+i; devpriv->mite=mite; return 0; diff --git a/comedi/drivers/ni_stc.h b/comedi/drivers/ni_stc.h index 538f8cf4..d50958fc 100644 --- a/comedi/drivers/ni_stc.h +++ b/comedi/drivers/ni_stc.h @@ -564,7 +564,7 @@ typedef struct ni_board_struct{ static ni_board ni_boards[]; #define n_ni_boards (sizeof(ni_boards)/sizeof(ni_board)) -#define boardtype ni_boards[dev->board] +#define boardtype (*(ni_board *)dev->board_ptr) #define NI_PRIVATE_COMMON \ unsigned short dio_output; \ diff --git a/comedi/drivers/pcl711.c b/comedi/drivers/pcl711.c index bf1b915a..005ac94c 100644 --- a/comedi/drivers/pcl711.c +++ b/comedi/drivers/pcl711.c @@ -118,17 +118,6 @@ static comedi_lrange range_acl8112dg_ai = { 9, { BIP_RANGE( 10 ) }}; -static int pcl711_attach(comedi_device *dev,comedi_devconfig *it); -static int pcl711_detach(comedi_device *dev); -static int pcl711_recognize(char *name); -comedi_driver driver_pcl711={ - driver_name: "pcl711", - module: THIS_MODULE, - attach: pcl711_attach, - detach: pcl711_detach, - recognize: pcl711_recognize, -}; - typedef int bool; /* @@ -160,6 +149,19 @@ 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) + +static int pcl711_attach(comedi_device *dev,comedi_devconfig *it); +static int pcl711_detach(comedi_device *dev); +comedi_driver driver_pcl711={ + driver_name: "pcl711", + module: THIS_MODULE, + attach: pcl711_attach, + detach: pcl711_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), +}; typedef struct { int board; @@ -170,7 +172,6 @@ typedef struct { } pcl711_private; #define devpriv ((pcl711_private *)dev->private) -#define this_board (boardtypes+dev->board) static void pcl711_interrupt(int irq, void *d, struct pt_regs *regs) { @@ -390,18 +391,6 @@ static void free_resources(comedi_device * dev) release_region(dev->iobase, dev->iosize); } -static int pcl711_recognize(char *name) -{ - int i; - - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { - return i; - } - } - return -1; -} - /* Initialization */ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) { @@ -425,11 +414,11 @@ static int pcl711_attach(comedi_device * dev, comedi_devconfig * it) /* there should be a sanity check here */ /* set up some name stuff */ - dev->board_name = boardtypes[dev->board].name; + dev->board_name = this_board->name; /* grab our IRQ */ irq = it->options[1]; - if (irq < 0 || irq > boardtypes[dev->board].maxirq) { + if (irq < 0 || irq > this_board->maxirq) { printk("irq out of range\n"); free_resources(dev); return -EINVAL; @@ -527,16 +516,5 @@ static int pcl711_detach(comedi_device * dev) return 0; } -#ifdef MODULE -int init_module(void) -{ - comedi_driver_register(&driver_pcl711); - - return 0; -} +COMEDI_INITCLEANUP(driver_pcl711); -void cleanup_module(void) -{ - comedi_driver_unregister(&driver_pcl711); -} -#endif diff --git a/comedi/drivers/pcl724.c b/comedi/drivers/pcl724.c index 558fe446..932977e6 100644 --- a/comedi/drivers/pcl724.c +++ b/comedi/drivers/pcl724.c @@ -48,15 +48,6 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it); static int pcl724_detach(comedi_device *dev); -static int pcl724_recognize(char *name); - -comedi_driver driver_pcl724={ - driver_name: "pcl724", - module: THIS_MODULE, - attach: pcl724_attach, - detach: pcl724_detach, - recognize: pcl724_recognize, -}; typedef struct { char *name; // driver name @@ -79,6 +70,18 @@ static boardtype boardtypes[] = }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) +#define this_board ((boardtype *)dev->board_ptr) + +comedi_driver driver_pcl724={ + driver_name: "pcl724", + module: THIS_MODULE, + attach: pcl724_attach, + detach: pcl724_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), +}; + static int subdev_8255_cb(int dir,int port,int data,void *arg) { @@ -111,16 +114,15 @@ static int subdev_8255mapped_cb(int dir,int port,int data,void *arg) static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) { - int board,iobase,iorange; + int iobase,iorange; int ret,i; - board=dev->board; - iobase=it->options[0]; - iorange=boardtypes[board].io_range; - if ((boardtypes[board].can_have96)&&((it->options[1]==1)||(it->options[1]==96))) + iorange=this_board->io_range; + if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) iorange=PCL722_96_SIZE; // PCL-724 in 96 DIO configuration - printk("comedi%d: pcl724: board=%s, 0x%03x ",dev->minor,boardtypes[board].name,iobase); + printk("comedi%d: pcl724: board=%s, 0x%03x ",dev->minor, + this_board->name,iobase); if(check_region(iobase,iorange)<0){ printk("I/O port conflict\n"); return -EIO; @@ -130,14 +132,14 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase=iobase; dev->iosize=iorange; - dev->board_name = boardtypes[board].name; + dev->board_name = this_board->name; #ifdef PCL724_IRQ irq=0; - if (boardtypes[board].IRQbits!=0) { /* board support IRQ */ + if (this_board->IRQbits!=0) { /* board support IRQ */ irq=it->options[1]; if (irq>0) {/* we want to use IRQ */ - if (((1<IRQbits)==0) { rt_printk(", IRQ %d is out of allowed range, DISABLING IT",irq); irq=0; /* Bad IRQ */ } else { @@ -156,16 +158,15 @@ static int pcl724_attach(comedi_device *dev,comedi_devconfig *it) printk("\n"); - dev->n_subdevices=boardtypes[board].numofports; - if ((boardtypes[board].can_have96)&&((it->options[1]==1)||(it->options[1]==96))) + dev->n_subdevices=this_board->numofports; + if ((this_board->can_have96)&&((it->options[1]==1)||(it->options[1]==96))) dev->n_subdevices=4; // PCL-724 in 96 DIO configuration - if((ret=alloc_subdevices(dev))<0) return ret; for(i=0;in_subdevices;i++){ - if (boardtypes[board].is_pet48) { + if (this_board->is_pet48) { subdev_8255_init(dev,dev->subdevices+i, subdev_8255mapped_cb,(void *)(dev->iobase+i*0x1000)); } else @@ -192,31 +193,6 @@ static int pcl724_detach(comedi_device *dev) return 0; } -static int pcl724_recognize(char *name) -{ - int i; - - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { - return i; - } - } - - return -1; -} - +COMEDI_INITCLEANUP(driver_pcl724); -#ifdef MODULE -int init_module(void) -{ - comedi_driver_register(&driver_pcl724); - - return 0; -} - -void cleanup_module(void) -{ - comedi_driver_unregister(&driver_pcl724); -} -#endif diff --git a/comedi/drivers/pcl726.c b/comedi/drivers/pcl726.c index 80caf7ae..33ea3046 100644 --- a/comedi/drivers/pcl726.c +++ b/comedi/drivers/pcl726.c @@ -30,19 +30,19 @@ /* Options for PCL-726: [0] - IO Base - [1]...[6] - D/A output range for channel 1-6: + [2]...[7] - D/A output range for channel 1-6: 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V, 4: 4-20mA, 5: unknow (external reference) Options for PCL-727: [0] - IO Base - [1]...[12] - D/A output range for channel 1-12: + [2]...[13] - D/A output range for channel 1-12: 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: 4-20mA Options for PCL-728 and ACL-6128: [0] - IO Base - [1], [2] - D/A output range for channel 1 and 2: + [2], [3] - D/A output range for channel 1 and 2: 0: 0-5V, 1: 0-10V, 2: +/-5V, 3: +/-10V, 4: 4-20mA, 5: 0-20mA @@ -120,15 +120,6 @@ static comedi_lrange *rangelist_728[]={ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it); static int pcl726_detach(comedi_device *dev); -static int pcl726_recognize(char *name); - -comedi_driver driver_pcl726={ - driver_name: "pcl726", - module: THIS_MODULE, - attach: pcl726_attach, - detach: pcl726_detach, - recognize: pcl726_recognize, -}; typedef struct { char *name; // driver name @@ -163,6 +154,17 @@ static boardtype boardtypes[] = &rangelist_728[0], }, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) +#define this_board ((boardtype *)dev->board_ptr) + +comedi_driver driver_pcl726={ + driver_name: "pcl726", + module: THIS_MODULE, + attach: pcl726_attach, + detach: pcl726_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), +}; typedef struct{ int bipolar[12]; @@ -193,8 +195,8 @@ static int pcl726_di(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { unsigned int bits; - bits=inb(dev->iobase+boardtypes[dev->board].di_lo)| - (inb(dev->iobase+boardtypes[dev->board].di_hi)<<8); + bits=inb(dev->iobase+this_board->di_lo)| + (inb(dev->iobase+this_board->di_hi)<<8); return di_unpack(bits,it); } @@ -203,8 +205,8 @@ static int pcl726_do(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) { do_pack(&s->state,it); - outb(s->state&0xff,dev->iobase+boardtypes[dev->board].do_lo); - outb((s->state>>8),dev->iobase+boardtypes[dev->board].do_hi); + outb(s->state&0xff,dev->iobase+this_board->do_lo); + outb((s->state>>8),dev->iobase+this_board->do_hi); return it->n_chan; } @@ -212,14 +214,12 @@ static int pcl726_do(comedi_device *dev,comedi_subdevice *s,comedi_trig *it) static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) { comedi_subdevice *s; - int board,iobase,iorange; - int ret,i,fstch; + int iobase,iorange; + int ret,i; - board=dev->board; - iobase=it->options[0]; - iorange=boardtypes[board].io_range; - printk("comedi%d: pcl726: board=%s, 0x%03x ",dev->minor,boardtypes[board].name,iobase); + iorange=this_board->io_range; + printk("comedi%d: pcl726: board=%s, 0x%03x ",dev->minor,this_board->name,iobase); if(check_region(iobase,iorange)<0){ printk("I/O port conflict\n"); return -EIO; @@ -229,7 +229,7 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) dev->iobase=iobase; dev->iosize=iorange; - dev->board_name = boardtypes[board].name; + dev->board_name = this_board->name; if((ret=alloc_private(dev,sizeof(pcl726_private)))<0) return -ENOMEM; @@ -264,9 +264,7 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) printk("\n"); - dev->n_subdevices=1; - if (boardtypes[board].have_dio) - dev->n_subdevices=3; + dev->n_subdevices=3; if((ret=alloc_subdevices(dev))<0) return ret; @@ -275,51 +273,55 @@ static int pcl726_attach(comedi_device *dev,comedi_devconfig *it) /* ao */ s->type=COMEDI_SUBD_AO; s->subdev_flags=SDF_WRITEABLE|SDF_GROUND; - s->n_chan=boardtypes[board].n_aochan; + s->n_chan=this_board->n_aochan; s->maxdata=0xfff; s->len_chanlist=1; s->trig[0]=pcl726_ao; /*s->range_table=&range_unknown;*/ /* XXX */ s->range_table_list = devpriv->rangelist; - fstch=1; - if (board==3) fstch=2; - for (i=0; ioptions[fstch+i]<0)||(it->options[fstch+i]>=boardtypes[board].num_of_ranges)) { - printk("Invalid range for channel %d! Must be 0<=%d<%d\n",i+1,it->options[fstch+i],boardtypes[board].num_of_ranges-1); - it->options[fstch+i]=0; + for (i=0; in_aochan; i++) { + int j; + + j = it->options[2+1]; + if ((j<0)||(j>=this_board->num_of_ranges)) { + printk("Invalid range for channel %d! Must be 0<=%d<%d\n", + i,j,this_board->num_of_ranges-1); + j=0; } - devpriv->rangelist[i]=boardtypes[board].range_type_list[it->options[fstch+i]]; + devpriv->rangelist[i]=this_board->range_type_list[j]; if (devpriv->rangelist[i]->range[0].min==-devpriv->rangelist[i]->range[0].max) devpriv->bipolar[i]=1; /* bipolar range */ } - if (dev->n_subdevices<2) { - return 0; - } + s=dev->subdevices+1; /* di */ - s->type=COMEDI_SUBD_DI; - s->subdev_flags=SDF_READABLE|SDF_GROUND; - s->n_chan=16; - s->maxdata=1; - s->len_chanlist=1; - s->trig[0]=pcl726_di; - s->range_table=&range_digital; - - if (dev->n_subdevices<3) { - return 0; + if (!this_board->have_dio){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type=COMEDI_SUBD_DI; + s->subdev_flags=SDF_READABLE|SDF_GROUND; + s->n_chan=16; + s->maxdata=1; + s->len_chanlist=1; + s->trig[0]=pcl726_di; + s->range_table=&range_digital; } s=dev->subdevices+2; /* do */ - s->type=COMEDI_SUBD_DO; - s->subdev_flags=SDF_WRITEABLE|SDF_GROUND; - s->n_chan=16; - s->maxdata=1; - s->len_chanlist=1; - s->trig[0]=pcl726_do; - s->range_table=&range_digital; + if (!this_board->have_dio){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type=COMEDI_SUBD_DO; + s->subdev_flags=SDF_WRITEABLE|SDF_GROUND; + s->n_chan=16; + s->maxdata=1; + s->len_chanlist=1; + s->trig[0]=pcl726_do; + s->range_table=&range_digital; + } return 0; } @@ -340,20 +342,6 @@ static int pcl726_detach(comedi_device *dev) return 0; } -static int pcl726_recognize(char *name) -{ - int i; - - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { - return i; - } - } - - return -1; -} - - COMEDI_INITCLEANUP(driver_pcl726); diff --git a/comedi/drivers/pcl812.c b/comedi/drivers/pcl812.c index 8ad035ec..526a42b9 100644 --- a/comedi/drivers/pcl812.c +++ b/comedi/drivers/pcl812.c @@ -117,21 +117,14 @@ static comedi_lrange range_pcl813b2_ai = { 4, { static int pcl812_attach(comedi_device *dev,comedi_devconfig *it); static int pcl812_detach(comedi_device *dev); -static int pcl812_recognize(char *name); static int i8253_osc_base = 500; /* 2 Mhz */ -comedi_driver driver_pcl812={ - driver_name: "pcl812", - module: THIS_MODULE, - attach: pcl812_attach, - detach: pcl812_detach, - recognize: pcl812_recognize, -}; - typedef struct { char *name; + int is_812pg; + int is_813b; int n_ranges; int n_aichan; int ai_maxsample; @@ -153,6 +146,7 @@ static boardtype boardtypes[] = { { name: "pcl812pg", + is_812pg: 1, n_ranges: 5, n_aichan: 16, ai_maxsample: 30, @@ -169,6 +163,7 @@ static boardtype boardtypes[] = }, { name: "pcl813b", + is_813b: 1, n_ranges: 4, n_aichan: 32, ai_maxsample: 25, @@ -186,6 +181,17 @@ static boardtype boardtypes[] = }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) +#define this_board ((boardtype *)dev->board_ptr) + +comedi_driver driver_pcl812={ + driver_name: "pcl812", + module: THIS_MODULE, + attach: pcl812_attach, + detach: pcl812_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), +}; typedef struct { #ifdef USE_DMA @@ -211,7 +217,6 @@ typedef struct { } pcl812_private; #define devpriv ((pcl812_private *)dev->private) -#define this_board (boardtypes+dev->board) // *INDENT-ON* /* @@ -563,7 +568,7 @@ static void free_resources(comedi_device * dev) */ static void pcl812_reset(comedi_device * dev) { - if (dev->board == boardPCL812PG) { + if (this_board->is_812pg){ outb(0, dev->iobase + PCL812_DA1_LO); outb(0, dev->iobase + PCL812_DA1_HI); outb(0, dev->iobase + PCL812_DA2_LO); @@ -576,7 +581,7 @@ static void pcl812_reset(comedi_device * dev) outb(0, dev->iobase + PCL812_GAIN); outb(0, dev->iobase + PCL812_MUX); udelay(5); - if (dev->board == boardPCL813B) { + if (this_board->is_813b){ #ifdef PCL813_MICROSECS udelay(5); #else @@ -602,22 +607,20 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) int dma; unsigned long pages; #endif - int board; comedi_subdevice *s; int num_of_subdevs, subdevs[5]; - board = dev->board; /* inicialized from pcl812_recognize()? */ - /* claim our I/O space */ iobase = it->options[0]; - printk("comedi%d: pcl812: board=%s, ioport=0x%03x", dev->minor, boardtypes[board].name, iobase); - if (check_region(iobase, boardtypes[board].io_range) < 0) { + printk("comedi%d: pcl812: board=%s, ioport=0x%03x", dev->minor, + this_board->name, iobase); + if (check_region(iobase, this_board->io_range) < 0) { printk("I/O port conflict\n"); return -EIO; } - request_region(iobase, boardtypes[board].io_range, "pcl812"); + request_region(iobase, this_board->io_range, "pcl812"); dev->iobase = iobase; - dev->iosize = boardtypes[board].io_range; + dev->iosize = this_board->io_range; /* there should be a sanity check here */ @@ -625,14 +628,14 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) return ret; /* Can't alloc mem */ /* set up some name stuff */ - dev->board_name = boardtypes[board].name; + dev->board_name = this_board->name; /* grab our IRQ */ irq = 0; - if (boardtypes[board].IRQbits != 0) { /* board support IRQ */ + if (this_board->IRQbits != 0) { /* board support IRQ */ irq = it->options[1]; if (irq) { /* we want to use IRQ */ - if (((1 << irq) & boardtypes[board].IRQbits) == 0) { + if (((1 << irq) & this_board->IRQbits) == 0) { printk(", IRQ %d is out of allowed range, DISABLING IT", irq); irq = 0; /* Bad IRQ */ } else { @@ -724,10 +727,9 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = 0xfff; s->len_chanlist = 1024; s->range_table = this_board->ai_range_type; - switch (board) { - case boardPCL812PG: - s->subdev_flags |= SDF_GROUND; - s->trig[0] = pcl812_ai_mode0; + s->subdev_flags |= SDF_GROUND; + s->trig[0] = pcl812_ai_mode0; + if(this_board->is_812pg){ if (it->options[3] == 1) s->range_table = &range_pcl812pg2_ai; if (dev->irq) { @@ -737,13 +739,9 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->trig[3] = pcl812_ai_mode3_int; } } - break; - case boardPCL813B: - s->subdev_flags |= SDF_GROUND; + }else{ if (it->options[1] == 1) s->range_table = &range_pcl813b2_ai; - s->trig[0] = pcl812_ai_mode0; - break; } } @@ -758,8 +756,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = 0xfff; s->len_chanlist = 1; s->range_table = this_board->ao_range_type; - switch (board) { - case boardPCL812PG: + if(this_board->is_812pg){ s->subdev_flags |= SDF_GROUND; s->trig[0] = pcl812_ao_mode0; //s->trig[1] = pcl812_ao_mode1; @@ -767,7 +764,6 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->range_table = &range_unipolar5; if (it->options[4] == 2) s->range_table = &range_unknown; - break; } } @@ -782,11 +778,7 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = 1; s->len_chanlist = this_board->n_dichan; s->range_table = &range_digital; - switch (board) { - case boardPCL812PG: - s->trig[0] = pcl812_di_mode0; - break; - } + s->trig[0] = pcl812_di_mode0; } /* digital output */ @@ -800,25 +792,17 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) s->maxdata = 1; s->len_chanlist = this_board->n_dochan; s->range_table = &range_digital; - switch (board) { - case boardPCL812PG: - s->trig[0] = pcl812_do_mode0; - break; - } + s->trig[0] = pcl812_do_mode0; } - /*dev->rem = pcl812_rem; */ - - switch (dev->board) { - case boardPCL812PG: - pcl812_reset(dev); + pcl812_reset(dev); + if(this_board->is_812pg){ devpriv->max_812_ai_mode0_samples = 32; devpriv->max_812_ai_mode0_rangewait = 1; devpriv->max_812_ai_mode0_chanset = 1; devpriv->max_812_ai_mode0_convstart = 5; - break; - case boardPCL813B: - pcl812_reset(dev); + } + if(this_board->is_813b){ if (it->options[2] < 2) { devpriv->max_812_ai_mode0_samples = 1; } else { @@ -833,7 +817,6 @@ static int pcl812_attach(comedi_device * dev, comedi_devconfig * it) devpriv->max_812_ai_mode0_chanset = 5000; devpriv->max_812_ai_mode0_convstart = 20000; #endif - break; } printk("\n"); return 0; @@ -854,25 +837,6 @@ static int pcl812_detach(comedi_device * dev) return 0; } -static int pcl812_recognize(char *name) -{ - - int i; - -#ifdef MD_DEBUG - printk("comedi: pcl812: recognize code '%s'\n", name); -#endif - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { -#ifdef MD_DEBUG - printk("comedi: pcl812: recognize found '%s'\n", boardtypes[i].name); -#endif - return i; - } - } - return -1; -} - /* ============================================================================== */ diff --git a/comedi/drivers/pcl818.c b/comedi/drivers/pcl818.c index 049bd6b3..14177002 100644 --- a/comedi/drivers/pcl818.c +++ b/comedi/drivers/pcl818.c @@ -204,19 +204,10 @@ static comedi_lrange range718_unipolar1 = { 1, { BIP_RANGE(1), }}; static int pcl818_attach(comedi_device *dev,comedi_devconfig *it); static int pcl818_detach(comedi_device *dev); -static int pcl818_recognize(char *name); static int RTC_lock = 0; /* RTC lock */ static int RTC_timer_lock = 0; /* RTC int lock */ -comedi_driver driver_pcl818={ - driver_name: "pcl818", - module: THIS_MODULE, - attach: pcl818_attach, - detach: pcl818_detach, - recognize: pcl818_recognize, -}; - typedef struct { char *name; // driver name int n_ranges; // len of range list @@ -236,29 +227,41 @@ typedef struct { int ai_chanlist; // allowed len of channel list A/D int ao_chanlist; // allowed len of channel list D/A unsigned char fifo; // 1=board've FIFO + int is_818; } boardtype; static boardtype boardtypes[] = { {"pcl818l", 4, 16, 8, 25000, 1, 16, 16, &range_pcl818l_l_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 1, 0 }, + 0x0a, 0xfff, 0xfff, 1024, 1, 0, 1 }, {"pcl818h", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 1, 0 }, + 0x0a, 0xfff, 0xfff, 1024, 1, 0, 1 }, {"pcl818hd", 9, 16, 8, 10000, 1, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 1, 1 }, + 0x0a, 0xfff, 0xfff, 1024, 1, 1, 1 }, {"pcl818hg", 12, 16, 8, 10000, 1, 16, 16, &range_pcl818hg_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 1, 1 }, + 0x0a, 0xfff, 0xfff, 1024, 1, 1, 1 }, {"pcl818", 9, 16, 8, 10000, 2, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 2, 0 }, + 0x0a, 0xfff, 0xfff, 1024, 2, 0, 1 }, {"pcl718", 1, 16, 8, 16000, 2, 16, 16, &range_unipolar5, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 2, 0 }, + 0x0a, 0xfff, 0xfff, 1024, 2, 0, 0 }, /* pcm3718 */ {"pcm3718", 9, 16, 8, 10000, 0, 16, 16, &range_pcl818h_ai, &range_unipolar5, PCLx1x_RANGE, 0x00fc, - 0x0a, 0xfff, 0xfff, 1024, 0, 0 }, + 0x0a, 0xfff, 0xfff, 1024, 0, 0, 1 /* XXX ? */ }, }; #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype)) +comedi_driver driver_pcl818={ + driver_name: "pcl818", + module: THIS_MODULE, + attach: pcl818_attach, + detach: pcl818_detach, + board_name: boardtypes, + num_names: n_boardtypes, + offset: sizeof(boardtype), +}; + + typedef struct { int dma; // used DMA, 0=don't use DMA int dma_rtc; // 1=RTC used with DMA, 0=no RTC alloc @@ -300,7 +303,7 @@ static unsigned int muxonechan[] ={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; #define devpriv ((pcl818_private *)dev->private) -#define this_board (boardtypes+dev->board) +#define this_board ((boardtype *)dev->board_ptr) /* ============================================================================== @@ -1196,19 +1199,11 @@ void pcl818_reset(comedi_device * dev) outb(0xb0, dev->iobase + PCL818_CTRCTL);/* Stop pacer */ outb(0x70, dev->iobase + PCL818_CTRCTL); outb(0x30, dev->iobase + PCL818_CTRCTL); - switch (dev->board) { - case boardPCL818L: - case boardPCL818H: - case boardPCL818HD: - case boardPCL818HG: + if(this_board->is_818){ outb(0, dev->iobase + PCL818_RANGE); - break; - case boardPCL818: - outb(0, dev->iobase + PCL818_RANGE); - case boardPCL718: + }else{ outb(0, dev->iobase + PCL718_DA2_LO); outb(0, dev->iobase + PCL718_DA2_HI); - break; } } @@ -1328,18 +1323,15 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) int iobase; int irq,dma; unsigned long pages; - int i; - int board,io_range; + int io_range; comedi_subdevice *s; - int num_of_subdevs, subdevs[5]; - board = dev->board; /* inicialized from pcl812_recognize()? */ - /* claim our I/O space */ iobase = it->options[0]; - rt_printk("comedi%d: pcl818: board=%s, ioport=0x%03x", dev->minor, boardtypes[board].name, iobase); - io_range=boardtypes[board].io_range; - if ((boardtypes[board].fifo)&&(it->options[2]==0)) // we've board with FIFO and we want to use FIFO + printk("comedi%d: pcl818: board=%s, ioport=0x%03x", + dev->minor, this_board->name, iobase); + io_range=this_board->io_range; + if ((this_board->fifo)&&(it->options[2]==0)) // we've board with FIFO and we want to use FIFO io_range=PCLx1xFIFO_RANGE; if (check_region(iobase, io_range) < 0) { rt_printk("I/O port conflict\n"); @@ -1351,7 +1343,7 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) dev->iosize=io_range; if (pcl818_check(iobase)) { - rt_printk(", I cann't detect board. FAIL!\n"); + rt_printk(", I can't detect board. FAIL!\n"); return -EIO; } @@ -1359,14 +1351,14 @@ static int pcl818_attach(comedi_device * dev, comedi_devconfig * it) return ret; /* Can't alloc mem */ /* set up some name stuff */ - dev->board_name = boardtypes[board].name; + dev->board_name = this_board->name; if (io_range==PCLx1xFIFO_RANGE) devpriv->usefifo=1; /* grab our IRQ */ irq=0; - if (boardtypes[board].IRQbits!=0) { /* board support IRQ */ + if (this_board->IRQbits!=0) { /* board support IRQ */ irq=it->options[1]; if (irq>0) {/* we want to use IRQ */ - if (((1<IRQbits)==0) { rt_printk(", IRQ %d is out of allowed range, DISABLING IT",irq); irq=0; /* Bad IRQ */ } else { @@ -1415,10 +1407,10 @@ no_rtc: dma=0; devpriv->dma=dma; if ((devpriv->irq_free==0)&&(devpriv->dma_rtc==0)) goto no_dma; /* if we haven't IRQ, we can't use DMA */ - if (boardtypes[board].DMAbits!=0) { /* board support DMA */ + if (this_board->DMAbits!=0) { /* board support DMA */ dma=it->options[2]; if (dma<1) goto no_dma; /* DMA disabled */ - if (((1<DMAbits)==0) { rt_printk(", DMA is out of allowed range, FAIL!\n"); return -EINVAL; /* Bad DMA */ } @@ -1454,116 +1446,107 @@ no_rtc: no_dma: - num_of_subdevs=0; - - if ((this_board->n_aichan_se>0)||(this_board->n_aichan_diff>0)) subdevs[num_of_subdevs++]=COMEDI_SUBD_AI; - if (this_board->n_aochan>0) subdevs[num_of_subdevs++]=COMEDI_SUBD_AO; - if (this_board->n_dichan>0) subdevs[num_of_subdevs++]=COMEDI_SUBD_DI; - if (this_board->n_dochan>0) subdevs[num_of_subdevs++]=COMEDI_SUBD_DO; - - dev->n_subdevices = num_of_subdevs; - if((ret=alloc_subdevices(dev))<0) - return ret; + dev->n_subdevices = 4; + if((ret=alloc_subdevices(dev))<0) return ret; s = dev->subdevices + 0; - for (i = 0; i < num_of_subdevs; i++) { - s->type = subdevs[i]; - switch (s->type) { - case COMEDI_SUBD_AI: - devpriv->sub_ai=s; - s->subdev_flags = SDF_READABLE|SDF_RT; - if (check_single_ended(dev->iobase)) { - s->n_chan = this_board->n_aichan_se; - s->subdev_flags|=SDF_COMMON|SDF_GROUND; - rt_printk(", %dchans S.E. DAC",s->n_chan); - } else { - s->n_chan = this_board->n_aichan_diff; - s->subdev_flags|=SDF_DIFF; - rt_printk(", %dchans DIFF DAC",s->n_chan); + if(!this_board->n_aichan_se){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type = COMEDI_SUBD_AI; + devpriv->sub_ai=s; + s->subdev_flags = SDF_READABLE|SDF_RT; + if (check_single_ended(dev->iobase)) { + s->n_chan = this_board->n_aichan_se; + s->subdev_flags|=SDF_COMMON|SDF_GROUND; + rt_printk(", %dchans S.E. DAC",s->n_chan); + } else { + s->n_chan = this_board->n_aichan_diff; + s->subdev_flags|=SDF_DIFF; + rt_printk(", %dchans DIFF DAC",s->n_chan); + } + s->maxdata = this_board->ai_maxdata; + s->len_chanlist = this_board->ai_chanlist; + s->range_table = this_board->ai_range_type; + s->cancel=pcl818_ai_cancel; + s->trig[0] = pcl818_ai_mode0; + if ((irq)||(devpriv->dma_rtc)) { + s->trig[1] = pcl818_ai_mode1; + s->trig[3] = pcl818_ai_mode3; + } + if(this_board->is_818){ + if ((it->options[4]==1)||(it->options[4]==10)) + s->range_table=&range_pcl818l_h_ai; // secondary range list jumper selectable + }else{ + switch (it->options[4]) { + case 0: s->range_table=&range_bipolar10; break; + case 1: s->range_table=&range_bipolar5; break; + case 2: s->range_table=&range_bipolar2_5; break; + case 3: s->range_table=&range718_bipolar1; break; + case 4: s->range_table=&range718_bipolar0_5; break; + case 6: s->range_table=&range_unipolar10; break; + case 7: s->range_table=&range_unipolar5; break; + case 8: s->range_table=&range718_unipolar2; break; + case 9: s->range_table=&range718_unipolar1; break; + default: s->range_table=&range_unknown; break; } - s->maxdata = this_board->ai_maxdata; - s->len_chanlist = this_board->ai_chanlist; - s->range_table = this_board->ai_range_type; - s->cancel=pcl818_ai_cancel; - s->trig[0] = pcl818_ai_mode0; - if ((irq)||(devpriv->dma_rtc)) { - s->trig[1] = pcl818_ai_mode1; - s->trig[3] = pcl818_ai_mode3; - } - switch (board) { - case boardPCL818L: - if ((it->options[4]==1)||(it->options[4]==10)) - s->range_table=&range_pcl818l_h_ai; // secondary range list jumper selectable - break; - case boardPCL718: - switch (it->options[4]) { - case 0: s->range_table=&range_bipolar10; break; - case 1: s->range_table=&range_bipolar5; break; - case 2: s->range_table=&range_bipolar2_5; break; - case 3: s->range_table=&range718_bipolar1; break; - case 4: s->range_table=&range718_bipolar0_5; break; - case 6: s->range_table=&range_unipolar10; break; - case 7: s->range_table=&range_unipolar5; break; - case 8: s->range_table=&range718_unipolar2; break; - case 9: s->range_table=&range718_unipolar1; break; - default: s->range_table=&range_unknown; break; - } - break; - } - break; - - case COMEDI_SUBD_AO: - s->subdev_flags = SDF_WRITEABLE|SDF_GROUND|SDF_RT; - s->n_chan = this_board->n_aochan; - s->maxdata = this_board->ao_maxdata; - s->len_chanlist = this_board->ao_chanlist; - s->range_table = this_board->ao_range_type; - s->trig[0] = pcl818_ao_mode0; + } + } + + s = dev->subdevices + 1; + if(!this_board->n_aochan){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type = COMEDI_SUBD_AO; + s->subdev_flags = SDF_WRITEABLE|SDF_GROUND|SDF_RT; + s->n_chan = this_board->n_aochan; + s->maxdata = this_board->ao_maxdata; + s->len_chanlist = this_board->ao_chanlist; + s->range_table = this_board->ao_range_type; + s->trig[0] = pcl818_ao_mode0; #ifdef PCL818_MODE13_AO - if (irq) { - s->trig[1] = pcl818_ao_mode1; - s->trig[3] = pcl818_ao_mode3; - } + if (irq) { + s->trig[1] = pcl818_ao_mode1; + s->trig[3] = pcl818_ao_mode3; + } #endif - switch (board) { - case boardPCL818: - case boardPCL818H: - case boardPCL818HD: - case boardPCL818HG: - if ((it->options[4]==1)||(it->options[4]==10)) - s->range_table=&range_unipolar10; - if (it->options[4]==2) - s->range_table=&range_unknown; - break; - case boardPCL718: - case boardPCL818L: - if ((it->options[5]==1)||(it->options[5]==10)) - s->range_table=&range_unipolar10; - if (it->options[5]==2) - s->range_table=&range_unknown; - break; - } - break; + if(this_board->is_818){ + if ((it->options[4]==1)||(it->options[4]==10)) + s->range_table=&range_unipolar10; + if (it->options[4]==2) + s->range_table=&range_unknown; + }else{ + if ((it->options[5]==1)||(it->options[5]==10)) + s->range_table=&range_unipolar10; + if (it->options[5]==2) + s->range_table=&range_unknown; + } + } - case COMEDI_SUBD_DI: - s->subdev_flags = SDF_READABLE|SDF_RT; - s->n_chan = this_board->n_dichan; - s->maxdata = 1; - s->len_chanlist = this_board->n_dichan; - s->range_table = &range_digital; - s->trig[0] = pcl818_di_mode0; - break; + s = dev->subdevices + 2; + if(!this_board->n_dichan){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type = COMEDI_SUBD_DI; + s->subdev_flags = SDF_READABLE|SDF_RT; + s->n_chan = this_board->n_dichan; + s->maxdata = 1; + s->len_chanlist = this_board->n_dichan; + s->range_table = &range_digital; + s->trig[0] = pcl818_di_mode0; + } - case COMEDI_SUBD_DO: - s->subdev_flags = SDF_WRITEABLE|SDF_RT; - s->n_chan = this_board->n_dochan; - s->maxdata = 1; - s->len_chanlist = this_board->n_dochan; - s->range_table = &range_digital; - s->trig[0] = pcl818_do_mode0; - break; - } - s++; + s = dev->subdevices + 3; + if(!this_board->n_dochan){ + s->type = COMEDI_SUBD_UNUSED; + }else{ + s->type = COMEDI_SUBD_DO; + s->subdev_flags = SDF_WRITEABLE|SDF_RT; + s->n_chan = this_board->n_dochan; + s->maxdata = 1; + s->len_chanlist = this_board->n_dochan; + s->range_table = &range_digital; + s->trig[0] = pcl818_do_mode0; } /* select 1/10MHz oscilator */ @@ -1574,13 +1557,11 @@ no_dma: } /* max sampling speed */ - devpriv->ns_min=boardtypes[dev->board].ns_min; + devpriv->ns_min=this_board->ns_min; - switch (dev->board) { - case boardPCL718: + if(!this_board->is_818){ if ((it->options[6]==1)||(it->options[6]==100)) devpriv->ns_min=10000; /* extended PCL718 to 100kHz DAC */ - break; } pcl818_reset(dev); @@ -1604,21 +1585,6 @@ static int pcl818_detach(comedi_device * dev) return 0; } -static int pcl818_recognize(char *name) -{ - int i; - - // rt_printk("comedi: pcl818: recognize code '%s'\n",name); - for (i = 0; i < n_boardtypes; i++) { - if (!strcmp(boardtypes[i].name, name)) { - // rt_printk("comedi: pcl818: recognize found %d '%s'\n", i,boardtypes[i].name); - return i; - } - } - - return -1; -} - /* ============================================================================== */ diff --git a/comedi/drivers/poc.c b/comedi/drivers/poc.c index 1e3366ad..073a0b64 100644 --- a/comedi/drivers/poc.c +++ b/comedi/drivers/poc.c @@ -54,7 +54,6 @@ static int poc_attach(comedi_device *dev,comedi_devconfig *it); static int poc_detach(comedi_device *dev); static int dac02_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); static int readback_insn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); -static int poc_recognize(char *name); struct boarddef_struct{ char *name; @@ -79,6 +78,7 @@ static struct boarddef_struct boards[]={ } }; #define n_boards (sizeof(boards)/sizeof(boards[0])) +#define this_board ((struct boarddef_struct *)dev->board_ptr) comedi_driver driver_poc= { @@ -86,7 +86,9 @@ comedi_driver driver_poc= module: THIS_MODULE, attach: poc_attach, detach: poc_detach, - recognize: poc_recognize, + board_name: boards, + num_names: n_boards, + offset: sizeof(boards[0]), }; // analog output ranges @@ -100,18 +102,6 @@ static comedi_lrange range_dac02 = { } }; -static int poc_recognize(char *name) -{ - int i; - - for(i=0;ioptions[0]; printk("comedi%d: poc: using %s iobase 0x%x\n", dev->minor, - boards[dev->board].name, iobase); + this_board->name, iobase); - dev->board_name = boards[dev->board].name; + dev->board_name = this_board->name; if(iobase == 0) { @@ -129,7 +119,7 @@ static int poc_attach(comedi_device *dev, comedi_devconfig *it) return -EINVAL; } - iosize = boards[dev->board].iosize; + iosize = this_board->iosize; /* check if io addresses are available */ if(check_region(iobase, iosize) < 0) { @@ -144,17 +134,17 @@ static int poc_attach(comedi_device *dev, comedi_devconfig *it) dev->n_subdevices = 1; if(alloc_subdevices(dev) < 0) return -ENOMEM; - if(alloc_private(dev,sizeof(lsampl_t)*boards[dev->board].n_chan) < 0) + if(alloc_private(dev,sizeof(lsampl_t)*this_board->n_chan) < 0) return -ENOMEM; /* analog output subdevice */ s=dev->subdevices + 0; - s->type = boards[dev->board].type; - s->n_chan = boards[dev->board].n_chan; - s->maxdata = (1<board].n_bits)-1; + s->type = this_board->type; + s->n_chan = this_board->n_chan; + s->maxdata = (1<n_bits)-1; s->range_table = &range_dac02; // XXX - s->insn_write = boards[dev->board].winsn; - s->insn_write = boards[dev->board].rinsn; + s->insn_write = this_board->winsn; + s->insn_write = this_board->rinsn; if(s->type==COMEDI_SUBD_AO || s->type==COMEDI_SUBD_DO){ s->subdev_flags = SDF_WRITEABLE; } diff --git a/comedi/drivers/quatech_daqp_cs.c b/comedi/drivers/quatech_daqp_cs.c index 696a8ef1..0877d6a7 100644 --- a/comedi/drivers/quatech_daqp_cs.c +++ b/comedi/drivers/quatech_daqp_cs.c @@ -233,7 +233,7 @@ static int daqp_attach(comedi_device *dev,comedi_devconfig *it); static int daqp_detach(comedi_device *dev); comedi_driver driver_daqp={ driver_name: "daqp", - module: &__this_module, + module: THIS_MODULE, attach: daqp_attach, detach: daqp_detach, }; diff --git a/comedi/drivers/rti800.c b/comedi/drivers/rti800.c index c06574e8..8bd3f640 100644 --- a/comedi/drivers/rti800.c +++ b/comedi/drivers/rti800.c @@ -96,15 +96,26 @@ static comedi_lrange range_rti800_ai_unipolar = { 4, { UNI_RANGE( 0.02 ) }}; +typedef struct{ + char *name; + int has_ao; +}boardtype; +static boardtype boardtypes[]={ + { "rti800", 0 }, + { "rti815", 1 }, +}; +#define this_board ((boardtype *)dev->board_ptr) + static int rti800_attach(comedi_device *dev,comedi_devconfig *it); static int rti800_detach(comedi_device *dev); -static int rti800_recognize(char *name); comedi_driver driver_rti800={ driver_name: "rti800", module: THIS_MODULE, attach: rti800_attach, detach: rti800_detach, - recognize: rti800_recognize, + num_names: sizeof(boardtypes)/sizeof(boardtype), + board_name: boardtypes, + offset: sizeof(boardtype), }; static void rti800_interrupt(int irq, void *dev, struct pt_regs *regs); @@ -270,14 +281,6 @@ static int rti800_do(comedi_device * dev, comedi_subdevice *s, comedi_trig * it) options[8] - dac1 coding */ -static int rti800_recognize(char *name) -{ - if (!strcmp("rti800", name))return 0; - if (!strcmp("rti815", name))return 1; - - return -1; -} - static int rti800_attach(comedi_device * dev, comedi_devconfig * it) { int irq; @@ -318,17 +321,9 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) printk("( no irq )"); } - if (dev->board == 0) - dev->board_name = "rti800"; - else - dev->board_name = "rti815"; + dev->board_name = this_board->name; - - if (dev->board != 0) { - dev->n_subdevices=4; - }else{ - dev->n_subdevices=3; - } + dev->n_subdevices=4; if((ret=alloc_subdevices(dev))<0) return ret; if((ret=alloc_private(dev,sizeof(rti800_private)))<0) @@ -362,8 +357,8 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) break; } - if (dev->board == 1) { - s++; + s++; + if (this_board->has_ao){ /* ao subdevice (only on rti815) */ s->type=COMEDI_SUBD_AO; s->subdev_flags=SDF_WRITEABLE; @@ -387,6 +382,8 @@ static int rti800_attach(comedi_device * dev, comedi_devconfig * it) devpriv->ao_range_type_list[1] = &range_unipolar10; break; } + }else{ + s->type=COMEDI_SUBD_UNUSED; } s++; diff --git a/comedi/drivers/skel.c b/comedi/drivers/skel.c index 60905587..a231c823 100644 --- a/comedi/drivers/skel.c +++ b/comedi/drivers/skel.c @@ -97,22 +97,32 @@ typedef struct{ */ static int skel_attach(comedi_device *dev,comedi_devconfig *it); static int skel_detach(comedi_device *dev); -//static int skel_recognize(char *name); -static void skel_register_boards(void); comedi_driver driver_skel={ driver_name: "dummy", module: THIS_MODULE, attach: skel_attach, detach: skel_detach, /* It is not necessary to implement the following members if you are - * writing a driver for a plug and play card. - */ -// recognize: skel_recognize, - register_boards: skel_register_boards, // replacement for recognize - /* comedi uses num_names to allocate the board_name and board_id members - * of this struct + * writing a driver for a ISA PnP or PCI card */ + /* Most drivers will support multiple types of boards by + * having an array of board structures. These were defined + * in skel_boards[] above. Note that the element 'name' + * was first in the structure -- Comedi uses this fact to + * extract the name of the board without knowing any details + * about the structure except for its length. + * When a device is attached (by comedi_config), the name + * of the device is given to Comedi, and Comedi tries to + * match it by going through the list of board names. If + * there is a match, the address of the pointer is put + * into dev->board_ptr and driver->attach() is called. + * + * Note that these are not necessary if you can determine + * the type of board in software. ISA PnP, PCI, and PCMCIA + * devices are such boards. */ - num_names: sizeof(skel_boards) / sizeof(skel_board), + board_name: skel_boards, + offset: sizeof(skel_board), + num_names: sizeof(skel_boards) / sizeof(skel_board), }; static int skel_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data); @@ -121,51 +131,11 @@ static int skel_ai_cmdtest(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd); static int skel_ns_to_timer(unsigned int *ns,int round); -/* - * The function skel_recognize() is called when the Comedi core - * gets a request to configure a device. If the name of the device - * being configured matches with one of the devices that this - * driver can service, then a non-negative index should be returned. - * This index is put into dev->board, and then _attach() is called. - */ - -/* -static int skel_recognize(char *name) -{ - if(!strcmp("skel-100",name))return 0; - if(!strcmp("skel-200",name))return 1; - - return -1; -} -*/ - -/* The function register_boards() is a replacement for recognize - * that allows comedi to report back valid board names when it doesn't - * recognize a board name. The job of register_boards is to - * initialize the board_name and board_id members of - * the the comedi_driver_struct for this driver. The arrays - * will have already been allocated with num_names elements - * (your driver must initialize the num_names member of your - * comedi_driver struct) by comedi_driver_register() - * in the drivers.c file. - */ -static void skel_register_boards(void) -{ - unsigned int i; - - for(i = 0; i < driver_skel.num_names; i++) - { - driver_skel.board_name[i] = skel_boards[i].name; - driver_skel.board_id[i] = i; - } - - return; -} - /* * Attach is called by the Comedi core to configure the driver - * for a particular board. _recognize() has already been called, - * and dev->board contains whatever _recognize returned. + * for a particular board. If you specified a board_name array + * in the driver structure, dev->board_ptr contains that + * address. */ static int skel_attach(comedi_device *dev,comedi_devconfig *it) { @@ -175,16 +145,10 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) /* * If you can probe the device to determine what device in a series - * it is, this is the place to do it. Otherwise, you should use the - * _recognize method, and use the value in dev->board. - */ - //dev->board = skel_recognize(dev); - -/* - * Initialize dev->board_ptr. This can point to an element in the - * skel_boards array, for quick access to board-specific information. + * it is, this is the place to do it. Otherwise, dev->board_ptr + * should already be initialized. */ - dev->board_ptr = skel_boards + dev->board; + //dev->board_ptr = skel_probe(dev); /* * Initialize dev->board_name. Note that we can use the "thisboard" @@ -193,13 +157,16 @@ static int skel_attach(comedi_device *dev,comedi_devconfig *it) dev->board_name = thisboard->name; /* - * Allocate the private structure area. + * Allocate the private structure area. alloc_private() is a + * convenient macro defined in comedidev.h. */ if(alloc_private(dev,sizeof(skel_private))<0) return -ENOMEM; /* - * Allocate the subdevice structures. + * Allocate the subdevice structures. alloc_subdevice() is a + * convenient macro defined in comedidev.h. It relies on + * n_subdevices being set correctly. */ dev->n_subdevices=3; if(alloc_subdevices(dev)<0)