2 * @file me0900_device.c
4 * @brief ME-9x 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 "me0900_device.h"
49 #include "me0900_reg.h"
50 #include "mesubdevice.h"
51 #include "me0900_do.h"
52 #include "me0900_di.h"
54 me_device_t *me0900_pci_constructor(struct pci_dev *pci_device)
56 me0900_device_t *me0900_device;
57 me_subdevice_t *subdevice;
58 unsigned int version_idx;
63 PDEBUG("executed.\n");
65 // Allocate structure for device instance.
66 me0900_device = kmalloc(sizeof(me0900_device_t), GFP_KERNEL);
69 PERROR("Cannot get memory for device instance.\n");
73 memset(me0900_device, 0, sizeof(me0900_device_t));
75 // Initialize base class structure.
76 err = me_device_pci_init((me_device_t *) me0900_device, pci_device);
80 PERROR("Cannot initialize device base class.\n");
84 /* Get the index in the device version information table. */
86 me0900_versions_get_device_index(me0900_device->base.info.pci.
89 /* Initialize 8255 chip to desired mode */
90 if (me0900_device->base.info.pci.device_id ==
91 PCI_DEVICE_ID_MEILHAUS_ME0940) {
93 me0900_device->base.info.pci.reg_bases[2] +
95 } else if (me0900_device->base.info.pci.device_id ==
96 PCI_DEVICE_ID_MEILHAUS_ME0950) {
98 me0900_device->base.info.pci.reg_bases[2] +
101 me0900_device->base.info.pci.reg_bases[2] +
102 ME0900_WRITE_ENABLE_REG);
103 } else if (me0900_device->base.info.pci.device_id ==
104 PCI_DEVICE_ID_MEILHAUS_ME0960) {
106 me0900_device->base.info.pci.reg_bases[2] +
109 me0900_device->base.info.pci.reg_bases[2] +
110 ME0900_WRITE_ENABLE_REG);
114 (me0900_device->base.info.pci.device_id ==
115 PCI_DEVICE_ID_MEILHAUS_ME0960) ? 1 : 0;
116 // Create subdevice instances.
118 for (i = 0; i < me0900_versions[version_idx].di_subdevices; i++) {
120 (me_subdevice_t *) me0900_di_constructor(me0900_device->
126 me_device_deinit((me_device_t *) me0900_device);
127 kfree(me0900_device);
128 PERROR("Cannot get memory for subdevice.\n");
132 me_slist_add_subdevice_tail(&me0900_device->base.slist,
136 for (i = 0; i < me0900_versions[version_idx].do_subdevices; i++) {
138 (me_subdevice_t *) me0900_do_constructor(me0900_device->
143 me_device_deinit((me_device_t *) me0900_device);
144 kfree(me0900_device);
145 PERROR("Cannot get memory for subdevice.\n");
149 me_slist_add_subdevice_tail(&me0900_device->base.slist,
153 return (me_device_t *) me0900_device;
155 EXPORT_SYMBOL(me0900_pci_constructor);
157 // Init and exit of module.
159 static int __init me0900_init(void)
161 PDEBUG("executed.\n.");
165 static void __exit me0900_exit(void)
167 PDEBUG("executed.\n.");
170 module_init(me0900_init);
171 module_exit(me0900_exit);
173 // Administrative stuff for modinfo.
175 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
176 MODULE_DESCRIPTION("Device Driver Module for ME-9x Device");
177 MODULE_SUPPORTED_DEVICE("Meilhaus ME-9x Devices");
178 MODULE_LICENSE("GPL");