Version:  2.0.40 2.2.26 2.4.37 2.6.39 3.0 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

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 = ADDI_ENABLE;
 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 = ADDI_DISABLE;
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                 devpriv->b_SingelDiff = 0;
131         } else {
132                 s->n_chan = this_board->i_NbrAiChannelDiff;
133                 devpriv->b_SingelDiff = 1;
134         }
135         s->maxdata = this_board->i_AiMaxdata;
136         s->len_chanlist = this_board->i_AiChannelList;
137         s->range_table = &range_apci3120_ai;
138 
139         s->insn_config = apci3120_ai_insn_config;
140         s->insn_read = apci3120_ai_insn_read;
141         s->do_cmdtest = apci3120_ai_cmdtest;
142         s->do_cmd = apci3120_ai_cmd;
143         s->cancel = apci3120_cancel;
144 
145         /*  Allocate and Initialise AO Subdevice Structures */
146         s = &dev->subdevices[1];
147         if (this_board->i_NbrAoChannel) {
148                 s->type = COMEDI_SUBD_AO;
149                 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
150                 s->n_chan = this_board->i_NbrAoChannel;
151                 s->maxdata = this_board->i_AoMaxdata;
152                 s->len_chanlist = this_board->i_NbrAoChannel;
153                 s->range_table = &range_apci3120_ao;
154                 s->insn_write = apci3120_ao_insn_write;
155         } else {
156                 s->type = COMEDI_SUBD_UNUSED;
157         }
158 
159         /*  Allocate and Initialise DI Subdevice Structures */
160         s = &dev->subdevices[2];
161         s->type = COMEDI_SUBD_DI;
162         s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
163         s->n_chan = this_board->i_NbrDiChannel;
164         s->maxdata = 1;
165         s->len_chanlist = this_board->i_NbrDiChannel;
166         s->range_table = &range_digital;
167         s->insn_bits = apci3120_di_insn_bits;
168 
169         /*  Allocate and Initialise DO Subdevice Structures */
170         s = &dev->subdevices[3];
171         s->type = COMEDI_SUBD_DO;
172         s->subdev_flags =
173                 SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
174         s->n_chan = this_board->i_NbrDoChannel;
175         s->maxdata = this_board->i_DoMaxdata;
176         s->len_chanlist = this_board->i_NbrDoChannel;
177         s->range_table = &range_digital;
178         s->insn_bits = apci3120_do_insn_bits;
179 
180         /*  Allocate and Initialise Timer Subdevice Structures */
181         s = &dev->subdevices[4];
182         s->type = COMEDI_SUBD_TIMER;
183         s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
184         s->n_chan = 1;
185         s->maxdata = 0;
186         s->len_chanlist = 1;
187         s->range_table = &range_digital;
188 
189         s->insn_write = apci3120_write_insn_timer;
190         s->insn_read = apci3120_read_insn_timer;
191         s->insn_config = apci3120_config_insn_timer;
192 
193         apci3120_reset(dev);
194         return 0;
195 }
196 
197 static void apci3120_detach(struct comedi_device *dev)
198 {
199         struct addi_private *devpriv = dev->private;
200 
201         if (devpriv) {
202                 if (dev->iobase)
203                         apci3120_reset(dev);
204                 if (dev->irq)
205                         free_irq(dev->irq, dev);
206                 if (devpriv->ul_DmaBufferVirtual[0]) {
207                         free_pages((unsigned long)devpriv->
208                                 ul_DmaBufferVirtual[0],
209                                 devpriv->ui_DmaBufferPages[0]);
210                 }
211                 if (devpriv->ul_DmaBufferVirtual[1]) {
212                         free_pages((unsigned long)devpriv->
213                                 ul_DmaBufferVirtual[1],
214                                 devpriv->ui_DmaBufferPages[1]);
215                 }
216         }
217         comedi_pci_disable(dev);
218 }
219 
220 static struct comedi_driver apci3120_driver = {
221         .driver_name    = "addi_apci_3120",
222         .module         = THIS_MODULE,
223         .auto_attach    = apci3120_auto_attach,
224         .detach         = apci3120_detach,
225 };
226 
227 static int apci3120_pci_probe(struct pci_dev *dev,
228                               const struct pci_device_id *id)
229 {
230         return comedi_pci_auto_config(dev, &apci3120_driver, id->driver_data);
231 }
232 
233 static const struct pci_device_id apci3120_pci_table[] = {
234         { PCI_VDEVICE(AMCC, 0x818d), BOARD_APCI3120 },
235         { PCI_VDEVICE(AMCC, 0x828d), BOARD_APCI3001 },
236         { 0 }
237 };
238 MODULE_DEVICE_TABLE(pci, apci3120_pci_table);
239 
240 static struct pci_driver apci3120_pci_driver = {
241         .name           = "addi_apci_3120",
242         .id_table       = apci3120_pci_table,
243         .probe          = apci3120_pci_probe,
244         .remove         = comedi_pci_auto_unconfig,
245 };
246 module_comedi_pci_driver(apci3120_driver, apci3120_pci_driver);
247 
248 MODULE_AUTHOR("Comedi http://www.comedi.org");
249 MODULE_DESCRIPTION("Comedi low-level driver");
250 MODULE_LICENSE("GPL");
251 

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