2 * @file me4600_device.c
4 * @brief ME-4600 device class 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"
48 #include "me4600_device.h"
49 #include "meplx_reg.h"
51 #include "mefirmware.h"
53 #include "mesubdevice.h"
54 #include "me4600_do.h"
55 #include "me4600_di.h"
56 #include "me4600_dio.h"
58 #include "me4600_ai.h"
59 #include "me4600_ao.h"
60 #include "me4600_ext_irq.h"
63 * @brief Global variable.
64 * This is working queue for runing a separate atask that will be responsible for work status (start, stop, timeouts).
66 static struct workqueue_struct
*me4600_workqueue
;
69 me_device_t
*me4600_pci_constructor(struct pci_dev
*pci_device
, int me_bosch_fw
)
71 me_device_t
*me4600_pci_constructor(struct pci_dev
*pci_device
)
74 me4600_device_t
*me4600_device
;
75 me_subdevice_t
*subdevice
;
76 unsigned int version_idx
;
80 PDEBUG("executed.\n");
82 // Allocate structure for device instance.
83 me4600_device
= kmalloc(sizeof(me4600_device_t
), GFP_KERNEL
);
86 PERROR("Cannot get memory for ME-4600 device instance.\n");
90 memset(me4600_device
, 0, sizeof(me4600_device_t
));
92 // Initialize base class structure.
93 err
= me_device_pci_init((me_device_t
*) me4600_device
, pci_device
);
97 PERROR("Cannot initialize device base class.\n");
100 // Download the xilinx firmware.
101 if (me4600_device
->base
.info
.pci
.device_id
== PCI_DEVICE_ID_MEILHAUS_ME4610
) { //Jekyll <=> me4610
103 me_xilinx_download(me4600_device
->base
.info
.pci
.
105 me4600_device
->base
.info
.pci
.
106 reg_bases
[5], &pci_device
->dev
,
108 } else { // General me4600 firmware
111 me_xilinx_download(me4600_device
->base
.info
.pci
.
113 me4600_device
->base
.info
.pci
.
114 reg_bases
[5], &pci_device
->dev
,
115 (me_bosch_fw
) ? "me4600_bosch.bin" :
119 me_xilinx_download(me4600_device
->base
.info
.pci
.
121 me4600_device
->base
.info
.pci
.
122 reg_bases
[5], &pci_device
->dev
,
128 me_device_deinit((me_device_t
*) me4600_device
);
129 kfree(me4600_device
);
130 PERROR("Cannot download firmware.\n");
133 // Get the index in the device version information table.
135 me4600_versions_get_device_index(me4600_device
->base
.info
.pci
.
138 // Initialize spin locks.
139 spin_lock_init(&me4600_device
->preload_reg_lock
);
141 me4600_device
->preload_flags
= 0;
143 spin_lock_init(&me4600_device
->dio_lock
);
144 spin_lock_init(&me4600_device
->ai_ctrl_lock
);
145 spin_lock_init(&me4600_device
->ctr_ctrl_reg_lock
);
146 spin_lock_init(&me4600_device
->ctr_clk_src_reg_lock
);
148 // Create digital input instances.
149 for (i
= 0; i
< me4600_versions
[version_idx
].di_subdevices
; i
++) {
151 (me_subdevice_t
*) me4600_di_constructor(me4600_device
->
158 me_device_deinit((me_device_t
*) me4600_device
);
159 kfree(me4600_device
);
160 PERROR("Cannot get memory for subdevice.\n");
164 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
168 // Create digital output instances.
169 for (i
= 0; i
< me4600_versions
[version_idx
].do_subdevices
; i
++) {
171 (me_subdevice_t
*) me4600_do_constructor(me4600_device
->
178 me_device_deinit((me_device_t
*) me4600_device
);
179 kfree(me4600_device
);
180 PERROR("Cannot get memory for subdevice.\n");
184 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
188 // Create digital input/output instances.
189 for (i
= 0; i
< me4600_versions
[version_idx
].dio_subdevices
; i
++) {
191 (me_subdevice_t
*) me4600_dio_constructor(me4600_device
->
204 me_device_deinit((me_device_t
*) me4600_device
);
205 kfree(me4600_device
);
206 PERROR("Cannot get memory for subdevice.\n");
210 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
214 // Create analog input instances.
215 for (i
= 0; i
< me4600_versions
[version_idx
].ai_subdevices
; i
++) {
217 (me_subdevice_t
*) me4600_ai_constructor(me4600_device
->
239 me_device_deinit((me_device_t
*) me4600_device
);
240 kfree(me4600_device
);
241 PERROR("Cannot get memory for subdevice.\n");
245 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
249 // Create analog output instances.
250 for (i
= 0; i
< me4600_versions
[version_idx
].ao_subdevices
; i
++) {
253 (me_subdevice_t
*) me4600_ao_constructor(me4600_device
->
267 (me_subdevice_t
*) me4600_ao_constructor(me4600_device
->
283 me_device_deinit((me_device_t
*) me4600_device
);
284 kfree(me4600_device
);
285 PERROR("Cannot get memory for subdevice.\n");
289 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
293 // Create counter instances.
294 for (i
= 0; i
< me4600_versions
[version_idx
].ctr_subdevices
; i
++) {
296 (me_subdevice_t
*) me8254_constructor(me4600_device
->base
.
299 info
.pci
.reg_bases
[3],
304 ctr_clk_src_reg_lock
);
307 me_device_deinit((me_device_t
*) me4600_device
);
308 kfree(me4600_device
);
309 PERROR("Cannot get memory for subdevice.\n");
313 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
317 // Create external interrupt instances.
318 for (i
= 0; i
< me4600_versions
[version_idx
].ext_irq_subdevices
; i
++) {
321 me4600_ext_irq_constructor(me4600_device
->base
.info
.pci
.
323 me4600_device
->base
.irq
,
324 &me4600_device
->ai_ctrl_lock
);
327 me_device_deinit((me_device_t
*) me4600_device
);
328 kfree(me4600_device
);
329 PERROR("Cannot get memory for subdevice.\n");
333 me_slist_add_subdevice_tail(&me4600_device
->base
.slist
,
337 return (me_device_t
*) me4600_device
;
340 // Init and exit of module.
342 static int __init
me4600_init(void)
344 PDEBUG("executed.\n");
347 me4600_workqueue
= create_singlethread_workqueue("me4600");
352 static void __exit
me4600_exit(void)
354 PDEBUG("executed.\n");
357 flush_workqueue(me4600_workqueue
);
358 destroy_workqueue(me4600_workqueue
);
362 module_init(me4600_init
);
363 module_exit(me4600_exit
);
365 // Administrative stuff for modinfo.
367 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
368 MODULE_DESCRIPTION("Device Driver Module for ME-46xx Devices");
369 MODULE_SUPPORTED_DEVICE("Meilhaus ME-46xx Devices");
370 MODULE_LICENSE("GPL");
372 // Export the constructor.
373 EXPORT_SYMBOL(me4600_pci_constructor
);