Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17

Linux/drivers/staging/comedi/drivers/addi_apci_3120.c

  1 #include <linux/module.h>
  2 #include <linux/pci.h>
  3 
  4 #include "../comedidev.h"
  5 #include "comedi_fc.h"
  6 #include "amcc_s5933.h"
  7 
  8 #include "addi-data/addi_common.h"
  9 
 10 #include "addi-data/hwdrv_apci3120.c"
 11 
 12 enum apci3120_boardid {
 13         BOARD_APCI3120,
 14         BOARD_APCI3001,
 15 };
 16 
 17 static const struct addi_board apci3120_boardtypes[] = {
 18         [BOARD_APCI3120] = {
 19                 .pc_DriverName          = "apci3120",
 20                 .i_NbrAiChannel         = 16,
 21                 .i_NbrAiChannelDiff     = 8,
 22                 .i_AiChannelList        = 16,
 23                 .i_NbrAoChannel         = 8,
 24                 .i_AiMaxdata            = 0xffff,
 25                 .i_AoMaxdata            = 0x3fff,
 26                 .i_NbrDiChannel         = 4,
 27                 .i_NbrDoChannel         = 4,
 28                 .i_DoMaxdata            = 0x0f,
 29                 .interrupt              = apci3120_interrupt,
 30         },
 31         [BOARD_APCI3001] = {
 32                 .pc_DriverName          = "apci3001",
 33                 .i_NbrAiChannel         = 16,
 34                 .i_NbrAiChannelDiff     = 8,
 35                 .i_AiChannelList        = 16,
 36                 .i_AiMaxdata            = 0xfff,
 37                 .i_NbrDiChannel         = 4,
 38                 .i_NbrDoChannel         = 4,
 39                 .i_DoMaxdata            = 0x0f,
 40                 .interrupt              = apci3120_interrupt,
 41         },
 42 };
 43 
 44 static irqreturn_t v_ADDI_Interrupt(int irq, void *d)
 45 {
 46         struct comedi_device *dev = d;
 47         const struct addi_board *this_board = comedi_board(dev);
 48 
 49         this_board->interrupt(irq, d);
 50         return IRQ_RETVAL(1);
 51 }
 52 
 53 static int apci3120_auto_attach(struct comedi_device *dev,
 54                                 unsigned long context)
 55 {
 56         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 57         const struct addi_board *this_board = NULL;
 58         struct addi_private *devpriv;
 59         struct comedi_subdevice *s;
 60         int ret, pages, i;
 61 
 62         if (context < ARRAY_SIZE(apci3120_boardtypes))
 63                 this_board = &apci3120_boardtypes[context];
 64         if (!this_board)
 65                 return -ENODEV;
 66         dev->board_ptr = this_board;
 67         dev->board_name = this_board->pc_DriverName;
 68 
 69         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
 70         if (!devpriv)
 71                 return -ENOMEM;
 72 
 73         ret = comedi_pci_enable(dev);
 74         if (ret)
 75                 return ret;
 76         pci_set_master(pcidev);
 77 
 78         dev->iobase = pci_resource_start(pcidev, 1);
 79         devpriv->iobase = dev->iobase;
 80         devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0);
 81         devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2);
 82         devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3);
 83 
 84         if (pcidev->irq > 0) {
 85                 ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED,
 86                                   dev->board_name, dev);
 87                 if (ret == 0)
 88                         dev->irq = pcidev->irq;
 89         }
 90 
 91         devpriv->us_UseDma = 1;
 92 
 93         /* Allocate DMA buffers */
 94         devpriv->b_DmaDoubleBuffer = 0;
 95         for (i = 0; i < 2; i++) {
 96                 for (pages = 4; pages >= 0; pages--) {
 97                         devpriv->ul_DmaBufferVirtual[i] =
 98                                 (void *) __get_free_pages(GFP_KERNEL, pages);
 99 
100                         if (devpriv->ul_DmaBufferVirtual[i])
101                                 break;
102                 }
103                 if (devpriv->ul_DmaBufferVirtual[i]) {
104                         devpriv->ui_DmaBufferPages[i] = pages;
105                         devpriv->ui_DmaBufferSize[i] = PAGE_SIZE * pages;
106                         devpriv->ul_DmaBufferHw[i] =
107                                 virt_to_bus((void *)devpriv->
108                                 ul_DmaBufferVirtual[i]);
109                 }
110         }
111         if (!devpriv->ul_DmaBufferVirtual[0])
112                 devpriv->us_UseDma = 0;
113 
114         if (devpriv->ul_DmaBufferVirtual[1])
115                 devpriv->b_DmaDoubleBuffer = 1;
116 
117         ret = comedi_alloc_subdevices(dev, 5);
118         if (ret)
119                 return ret;
120 
121         /*  Allocate and Initialise AI Subdevice Structures */
122         s = &dev->subdevices[0];
123         dev->read_subdev = s;
124         s->type = COMEDI_SUBD_AI;
125         s->subdev_flags =
126                 SDF_READABLE | SDF_COMMON | SDF_GROUND
127                 | SDF_DIFF;
128         if (this_board->i_NbrAiChannel)
129                 s->n_chan = this_board->i_NbrAiChannel;
130         else
131                 s->n_chan = this_board->i_NbrAiChannelDiff;
132         s->maxdata = this_board->i_AiMaxdata;
133         s->len_chanlist = this_board->i_AiChannelList;
134         s->range_table = &range_apci3120_ai;
135 
136         s->insn_config = apci3120_ai_insn_config;
137         s->insn_read = apci3120_ai_insn_read;
138         s->do_cmdtest = apci3120_ai_cmdtest;
139         s->do_cmd = apci3120_ai_cmd;
140         s->cancel = apci3120_cancel;
141 
142         /*  Allocate and Initialise AO Subdevice Structures */
143         s = &dev->subdevices[1];
144         if (this_board->i_NbrAoChannel) {
145                 s->type = COMEDI_SUBD_AO;
146                 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
147                 s->n_chan = this_board->i_NbrAoChannel;
148                 s->maxdata = this_board->i_AoMaxdata;
149                 s->len_chanlist = this_board->i_NbrAoChannel;
150                 s->range_table = &range_apci3120_ao;
151                 s->insn_write = apci3120_ao_insn_write;
152         } else {
153                 s->type = COMEDI_SUBD_UNUSED;
154         }
155 
156         /*  Allocate and Initialise DI Subdevice Structures */
157         s = &dev->subdevices[2];
158         s->type = COMEDI_SUBD_DI;
159         s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
160         s->n_chan = this_board->i_NbrDiChannel;
161         s->maxdata = 1;
162         s->len_chanlist = this_board->i_NbrDiChannel;
163         s->range_table = &range_digital;
164         s->insn_bits = apci3120_di_insn_bits;
165 
166         /*  Allocate and Initialise DO Subdevice Structures */
167         s = &dev->subdevices[3];
168         s->type = COMEDI_SUBD_DO;
169         s->subdev_flags =
170                 SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
171         s->n_chan = this_board->i_NbrDoChannel;
172         s->maxdata = this_board->i_DoMaxdata;
173         s->len_chanlist = this_board->i_NbrDoChannel;
174         s->range_table = &range_digital;
175         s->insn_bits = apci3120_do_insn_bits;
176 
177         /*  Allocate and Initialise Timer Subdevice Structures */
178         s = &dev->subdevices[4];
179         s->type = COMEDI_SUBD_TIMER;
180         s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
181         s->n_chan = 1;
182         s->maxdata = 0;
183         s->len_chanlist = 1;
184         s->range_table = &range_digital;
185 
186         s->insn_write = apci3120_write_insn_timer;
187         s->insn_read = apci3120_read_insn_timer;
188         s->insn_config = apci3120_config_insn_timer;
189 
190         apci3120_reset(dev);
191         return 0;
192 }
193 
194 static void apci3120_detach(struct comedi_device *dev)
195 {
196         struct addi_private *devpriv = dev->private;
197 
198         if (devpriv) {
199                 if (dev->iobase)
200                         apci3120_reset(dev);
201                 if (dev->irq)
202                         free_irq(dev->irq, dev);
203                 if (devpriv->ul_DmaBufferVirtual[0]) {
204                         free_pages((unsigned long)devpriv->
205                                 ul_DmaBufferVirtual[0],
206                                 devpriv->ui_DmaBufferPages[0]);
207                 }
208                 if (devpriv->ul_DmaBufferVirtual[1]) {
209                         free_pages((unsigned long)devpriv->
210                                 ul_DmaBufferVirtual[1],
211                                 devpriv->ui_DmaBufferPages[1]);
212                 }
213         }
214         comedi_pci_disable(dev);
215 }
216 
217 static struct comedi_driver apci3120_driver = {
218         .driver_name    = "addi_apci_3120",
219         .module         = THIS_MODULE,
220         .auto_attach    = apci3120_auto_attach,
221         .detach         = apci3120_detach,
222 };
223 
224 static int apci3120_pci_probe(struct pci_dev *dev,
225                               const struct pci_device_id *id)
226 {
227         return comedi_pci_auto_config(dev, &apci3120_driver, id->driver_data);
228 }
229 
230 static const struct pci_device_id apci3120_pci_table[] = {
231         { PCI_VDEVICE(AMCC, 0x818d), BOARD_APCI3120 },
232         { PCI_VDEVICE(AMCC, 0x828d), BOARD_APCI3001 },
233         { 0 }
234 };
235 MODULE_DEVICE_TABLE(pci, apci3120_pci_table);
236 
237 static struct pci_driver apci3120_pci_driver = {
238         .name           = "addi_apci_3120",
239         .id_table       = apci3120_pci_table,
240         .probe          = apci3120_pci_probe,
241         .remove         = comedi_pci_auto_unconfig,
242 };
243 module_comedi_pci_driver(apci3120_driver, apci3120_pci_driver);
244 
245 MODULE_AUTHOR("Comedi http://www.comedi.org");
246 MODULE_DESCRIPTION("ADDI-DATA APCI-3120, Analog input board");
247 MODULE_LICENSE("GPL");
248 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us