2 * @file me8100_device.c
4 * @brief ME-8100 device class implementation.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
10 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/slab.h>
43 #include "meinternal.h"
47 #include "me8100_device.h"
48 #include "mesubdevice.h"
49 #include "me8100_di.h"
50 #include "me8100_do.h"
53 me_device_t
*me8100_pci_constructor(struct pci_dev
*pci_device
)
55 me8100_device_t
*me8100_device
;
56 me_subdevice_t
*subdevice
;
57 unsigned int version_idx
;
61 PDEBUG("executed.\n");
63 // Allocate structure for device instance.
64 me8100_device
= kmalloc(sizeof(me8100_device_t
), GFP_KERNEL
);
67 PERROR("Cannot get memory for device instance.\n");
71 memset(me8100_device
, 0, sizeof(me8100_device_t
));
73 // Initialize base class structure.
74 err
= me_device_pci_init((me_device_t
*) me8100_device
, pci_device
);
78 PERROR("Cannot initialize device base class.\n");
82 /* Get the index in the device version information table. */
84 me8100_versions_get_device_index(me8100_device
->base
.info
.pci
.
87 // Initialize spin lock .
88 spin_lock_init(&me8100_device
->dio_ctrl_reg_lock
);
89 spin_lock_init(&me8100_device
->ctr_ctrl_reg_lock
);
90 spin_lock_init(&me8100_device
->clk_src_reg_lock
);
92 // Create subdevice instances.
94 for (i
= 0; i
< me8100_versions
[version_idx
].di_subdevices
; i
++) {
96 (me_subdevice_t
*) me8100_di_constructor(me8100_device
->
108 me_device_deinit((me_device_t
*) me8100_device
);
109 kfree(me8100_device
);
110 PERROR("Cannot get memory for subdevice.\n");
114 me_slist_add_subdevice_tail(&me8100_device
->base
.slist
,
118 for (i
= 0; i
< me8100_versions
[version_idx
].do_subdevices
; i
++) {
120 (me_subdevice_t
*) me8100_do_constructor(me8100_device
->
127 me_device_deinit((me_device_t
*) me8100_device
);
128 kfree(me8100_device
);
129 PERROR("Cannot get memory for subdevice.\n");
133 me_slist_add_subdevice_tail(&me8100_device
->base
.slist
,
137 for (i
= 0; i
< me8100_versions
[version_idx
].ctr_subdevices
; i
++) {
139 (me_subdevice_t
*) me8254_constructor(me8100_device
->base
.
142 info
.pci
.reg_bases
[2],
150 me_device_deinit((me_device_t
*) me8100_device
);
151 kfree(me8100_device
);
152 PERROR("Cannot get memory for subdevice.\n");
156 me_slist_add_subdevice_tail(&me8100_device
->base
.slist
,
160 return (me_device_t
*) me8100_device
;
162 EXPORT_SYMBOL(me8100_pci_constructor
);
164 // Init and exit of module.
166 static int __init
me8100_init(void)
168 PDEBUG("executed.\n.");
169 return ME_ERRNO_SUCCESS
;
172 static void __exit
me8100_exit(void)
174 PDEBUG("executed.\n.");
177 module_init(me8100_init
);
179 module_exit(me8100_exit
);
181 // Administrative stuff for modinfo.
182 MODULE_AUTHOR("Guenter Gebhardt <g.gebhardt@meilhaus.de>");
183 MODULE_DESCRIPTION("Device Driver Module for Template Device");
184 MODULE_SUPPORTED_DEVICE("Meilhaus Template Devices");
185 MODULE_LICENSE("GPL");