2 * @file me0600_device.c
4 * @brief ME-630 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 "me0600_device.h"
49 #include "mesubdevice.h"
50 #include "me0600_relay.h"
51 #include "me0600_ttli.h"
52 #include "me0600_optoi.h"
53 #include "me0600_dio.h"
54 #include "me0600_ext_irq.h"
56 me_device_t *me0600_pci_constructor(struct pci_dev *pci_device)
58 me0600_device_t *me0600_device;
59 me_subdevice_t *subdevice;
60 unsigned int version_idx;
64 PDEBUG("executed.\n");
66 // Allocate structure for device instance.
67 me0600_device = kmalloc(sizeof(me0600_device_t), GFP_KERNEL);
70 PERROR("Cannot get memory for device instance.\n");
74 memset(me0600_device, 0, sizeof(me0600_device_t));
76 // Initialize base class structure.
77 err = me_device_pci_init((me_device_t *) me0600_device, pci_device);
81 PERROR("Cannot initialize device base class.\n");
85 /* Get the index in the device version information table. */
87 me0600_versions_get_device_index(me0600_device->base.info.pci.
90 // Initialize spin lock .
91 spin_lock_init(&me0600_device->dio_ctrl_reg_lock);
92 spin_lock_init(&me0600_device->intcsr_lock);
94 // Create subdevice instances.
96 for (i = 0; i < me0600_versions[version_idx].optoi_subdevices; i++) {
98 (me_subdevice_t *) me0600_optoi_constructor(me0600_device->
103 me_device_deinit((me_device_t *) me0600_device);
104 kfree(me0600_device);
105 PERROR("Cannot get memory for subdevice.\n");
109 me_slist_add_subdevice_tail(&me0600_device->base.slist,
113 for (i = 0; i < me0600_versions[version_idx].relay_subdevices; i++) {
115 (me_subdevice_t *) me0600_relay_constructor(me0600_device->
120 me_device_deinit((me_device_t *) me0600_device);
121 kfree(me0600_device);
122 PERROR("Cannot get memory for subdevice.\n");
126 me_slist_add_subdevice_tail(&me0600_device->base.slist,
130 for (i = 0; i < me0600_versions[version_idx].ttli_subdevices; i++) {
132 (me_subdevice_t *) me0600_ttli_constructor(me0600_device->
137 me_device_deinit((me_device_t *) me0600_device);
138 kfree(me0600_device);
139 PERROR("Cannot get memory for subdevice.\n");
143 me_slist_add_subdevice_tail(&me0600_device->base.slist,
147 for (i = 0; i < me0600_versions[version_idx].dio_subdevices; i++) {
149 (me_subdevice_t *) me0600_dio_constructor(me0600_device->
156 me_device_deinit((me_device_t *) me0600_device);
157 kfree(me0600_device);
158 PERROR("Cannot get memory for subdevice.\n");
162 me_slist_add_subdevice_tail(&me0600_device->base.slist,
166 for (i = 0; i < me0600_versions[version_idx].ext_irq_subdevices; i++) {
169 me0600_ext_irq_constructor(me0600_device->base.info.pci.
171 me0600_device->base.info.pci.
173 &me0600_device->intcsr_lock, i,
174 me0600_device->base.irq);
177 me_device_deinit((me_device_t *) me0600_device);
178 kfree(me0600_device);
179 PERROR("Cannot get memory for subdevice.\n");
183 me_slist_add_subdevice_tail(&me0600_device->base.slist,
187 return (me_device_t *) me0600_device;
190 // Init and exit of module.
192 static int __init me0600_init(void)
194 PDEBUG("executed.\n");
198 static void __exit me0600_exit(void)
200 PDEBUG("executed.\n");
203 module_init(me0600_init);
205 module_exit(me0600_exit);
207 // Administrative stuff for modinfo.
209 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
210 MODULE_DESCRIPTION("Device Driver Module for ME-6xx Device");
211 MODULE_SUPPORTED_DEVICE("Meilhaus ME-6xx Devices");
212 MODULE_LICENSE("GPL");
214 // Export the constructor.
215 EXPORT_SYMBOL(me0600_pci_constructor);