2 * @file me8200_device.c
4 * @brief ME-8200 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"
47 #include "meplx_reg.h"
49 #include "me8200_device.h"
50 #include "mesubdevice.h"
51 #include "me8200_di.h"
52 #include "me8200_do.h"
53 #include "me8200_dio.h"
55 me_device_t
*me8200_pci_constructor(struct pci_dev
*pci_device
)
57 me8200_device_t
*me8200_device
;
58 me_subdevice_t
*subdevice
;
59 unsigned int version_idx
;
63 PDEBUG("executed.\n");
65 // Allocate structure for device instance.
66 me8200_device
= kmalloc(sizeof(me8200_device_t
), GFP_KERNEL
);
69 PERROR("Cannot get memory for device instance.\n");
73 memset(me8200_device
, 0, sizeof(me8200_device_t
));
75 // Initialize base class structure.
76 err
= me_device_pci_init((me_device_t
*) me8200_device
, pci_device
);
80 PERROR("Cannot initialize device base class.\n");
84 /* Get the index in the device version information table. */
86 me8200_versions_get_device_index(me8200_device
->base
.info
.pci
.
89 // Initialize spin lock .
90 spin_lock_init(&me8200_device
->irq_ctrl_lock
);
91 spin_lock_init(&me8200_device
->irq_mode_lock
);
92 spin_lock_init(&me8200_device
->dio_ctrl_lock
);
94 /* Setup the PLX interrupt configuration */
95 outl(PLX_INTCSR_LOCAL_INT1_EN
|
96 PLX_INTCSR_LOCAL_INT1_POL
|
97 PLX_INTCSR_LOCAL_INT2_EN
|
98 PLX_INTCSR_LOCAL_INT2_POL
|
99 PLX_INTCSR_PCI_INT_EN
,
100 me8200_device
->base
.info
.pci
.reg_bases
[1] + PLX_INTCSR
);
102 // Create subdevice instances.
104 for (i
= 0; i
< me8200_versions
[version_idx
].di_subdevices
; i
++) {
106 (me_subdevice_t
*) me8200_di_constructor(me8200_device
->
117 me_device_deinit((me_device_t
*) me8200_device
);
118 kfree(me8200_device
);
119 PERROR("Cannot get memory for subdevice.\n");
123 me_slist_add_subdevice_tail(&me8200_device
->base
.slist
,
127 for (i
= 0; i
< me8200_versions
[version_idx
].do_subdevices
; i
++) {
129 (me_subdevice_t
*) me8200_do_constructor(me8200_device
->
138 me_device_deinit((me_device_t
*) me8200_device
);
139 kfree(me8200_device
);
140 PERROR("Cannot get memory for subdevice.\n");
144 me_slist_add_subdevice_tail(&me8200_device
->base
.slist
,
148 for (i
= 0; i
< me8200_versions
[version_idx
].dio_subdevices
; i
++) {
150 (me_subdevice_t
*) me8200_dio_constructor(me8200_device
->
157 me_device_deinit((me_device_t
*) me8200_device
);
158 kfree(me8200_device
);
159 PERROR("Cannot get memory for subdevice.\n");
163 me_slist_add_subdevice_tail(&me8200_device
->base
.slist
,
167 return (me_device_t
*) me8200_device
;
169 EXPORT_SYMBOL(me8200_pci_constructor
);
171 // Init and exit of module.
173 static int __init
me8200_init(void)
175 PDEBUG("executed.\n.");
179 static void __exit
me8200_exit(void)
181 PDEBUG("executed.\n.");
184 module_init(me8200_init
);
186 module_exit(me8200_exit
);
188 // Administrative stuff for modinfo.
189 MODULE_AUTHOR("Guenter Gebhardt <g.gebhardt@meilhaus.de>");
190 MODULE_DESCRIPTION("Device Driver Module for Template Device");
191 MODULE_SUPPORTED_DEVICE("Meilhaus Template Devices");
192 MODULE_LICENSE("GPL");