2 * @file me6000_device.c
4 * @brief Device class template implementation.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
13 * This file is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/slab.h>
44 #include "meinternal.h"
46 #include "mefirmware.h"
48 #include "mesubdevice.h"
51 #include "me6000_reg.h"
52 #include "me6000_device.h"
53 #include "meplx_reg.h"
54 #include "me6000_dio.h"
55 #include "me6000_ao.h"
58 * @brief Global variable.
59 * This is working queue for runing a separate atask that will be responsible for work status (start, stop, timeouts).
61 static struct workqueue_struct *me6000_workqueue;
63 me_device_t *me6000_pci_constructor(struct pci_dev *pci_device)
65 me6000_device_t *me6000_device;
66 me_subdevice_t *subdevice;
67 unsigned int version_idx;
73 PDEBUG("executed.\n");
75 // Allocate structure for device instance.
76 me6000_device = kmalloc(sizeof(me6000_device_t), GFP_KERNEL);
79 PERROR("Cannot get memory for device instance.\n");
83 memset(me6000_device, 0, sizeof(me6000_device_t));
85 // Initialize base class structure.
86 err = me_device_pci_init((me_device_t *) me6000_device, pci_device);
90 PERROR("Cannot initialize device base class.\n");
94 /* Download the xilinx firmware */
95 err = me_xilinx_download(me6000_device->base.info.pci.reg_bases[1],
96 me6000_device->base.info.pci.reg_bases[2],
97 &pci_device->dev, "me6000.bin");
100 me_device_deinit((me_device_t *) me6000_device);
101 kfree(me6000_device);
102 PERROR("Can't download firmware.\n");
106 /* Get the index in the device version information table. */
108 me6000_versions_get_device_index(me6000_device->base.info.pci.
111 // Initialize spin lock .
112 spin_lock_init(&me6000_device->preload_reg_lock);
113 spin_lock_init(&me6000_device->dio_ctrl_reg_lock);
115 /* Create digital input/output instances. */
116 for (i = 0; i < me6000_versions[version_idx].dio_subdevices; i++) {
118 (me_subdevice_t *) me6000_dio_constructor(me6000_device->
125 me_device_deinit((me_device_t *) me6000_device);
126 kfree(me6000_device);
127 PERROR("Cannot get memory for subdevice.\n");
131 me_slist_add_subdevice_tail(&me6000_device->base.slist,
135 /* Create analog output instances. */
136 for (i = 0; i < me6000_versions[version_idx].ao_subdevices; i++) {
137 high_range = ((i == 8)
139 ((me6000_device->base.info.pci.device_id ==
140 PCI_DEVICE_ID_MEILHAUS_ME6359)
141 || (me6000_device->base.info.pci.device_id ==
142 PCI_DEVICE_ID_MEILHAUS_ME6259)
148 me6000_versions[version_idx].
149 ao_fifo) ? ME6000_AO_HAS_FIFO : 0x0;
150 fifo |= (i < 4) ? ME6000_AO_EXTRA_HARDWARE : 0x0;
153 (me_subdevice_t *) me6000_ao_constructor(me6000_device->
169 me_device_deinit((me_device_t *) me6000_device);
170 kfree(me6000_device);
171 PERROR("Cannot get memory for subdevice.\n");
175 me_slist_add_subdevice_tail(&me6000_device->base.slist,
179 return (me_device_t *) me6000_device;
182 // Init and exit of module.
184 static int __init me6000_init(void)
186 PDEBUG("executed.\n");
188 me6000_workqueue = create_singlethread_workqueue("me6000");
192 static void __exit me6000_exit(void)
194 PDEBUG("executed.\n");
196 flush_workqueue(me6000_workqueue);
197 destroy_workqueue(me6000_workqueue);
200 module_init(me6000_init);
201 module_exit(me6000_exit);
203 // Administrative stuff for modinfo.
205 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
206 MODULE_DESCRIPTION("Device Driver Module for ME-6000 Device");
207 MODULE_SUPPORTED_DEVICE("Meilhaus ME-6000 Devices");
208 MODULE_LICENSE("GPL");
210 // Export the constructor.
211 EXPORT_SYMBOL(me6000_pci_constructor);