x86: unmask CPUID levels on Intel CPUs
[linux-2.6/mini2440.git] / drivers / staging / meilhaus / me8100_device.c
blob1fb79e49026157ca0cebacb710a30636ab121230
1 /**
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
7 */
9 /*
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.
27 #ifndef __KERNEL__
28 # define __KERNEL__
29 #endif
31 #ifndef MODULE
32 # define MODULE
33 #endif
35 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/slab.h>
40 #include "meids.h"
41 #include "meerror.h"
42 #include "mecommon.h"
43 #include "meinternal.h"
45 #include "medebug.h"
46 #include "medevice.h"
47 #include "me8100_device.h"
48 #include "mesubdevice.h"
49 #include "me8100_di.h"
50 #include "me8100_do.h"
51 #include "me8254.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;
58 int err;
59 int i;
61 PDEBUG("executed.\n");
63 // Allocate structure for device instance.
64 me8100_device = kmalloc(sizeof(me8100_device_t), GFP_KERNEL);
66 if (!me8100_device) {
67 PERROR("Cannot get memory for device instance.\n");
68 return NULL;
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);
76 if (err) {
77 kfree(me8100_device);
78 PERROR("Cannot initialize device base class.\n");
79 return NULL;
82 /* Get the index in the device version information table. */
83 version_idx =
84 me8100_versions_get_device_index(me8100_device->base.info.pci.
85 device_id);
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++) {
95 subdevice =
96 (me_subdevice_t *) me8100_di_constructor(me8100_device->
97 base.info.pci.
98 reg_bases[2],
99 me8100_device->
100 base.info.pci.
101 reg_bases[1], i,
102 me8100_device->
103 base.irq,
104 &me8100_device->
105 dio_ctrl_reg_lock);
107 if (!subdevice) {
108 me_device_deinit((me_device_t *) me8100_device);
109 kfree(me8100_device);
110 PERROR("Cannot get memory for subdevice.\n");
111 return NULL;
114 me_slist_add_subdevice_tail(&me8100_device->base.slist,
115 subdevice);
118 for (i = 0; i < me8100_versions[version_idx].do_subdevices; i++) {
119 subdevice =
120 (me_subdevice_t *) me8100_do_constructor(me8100_device->
121 base.info.pci.
122 reg_bases[2], i,
123 &me8100_device->
124 dio_ctrl_reg_lock);
126 if (!subdevice) {
127 me_device_deinit((me_device_t *) me8100_device);
128 kfree(me8100_device);
129 PERROR("Cannot get memory for subdevice.\n");
130 return NULL;
133 me_slist_add_subdevice_tail(&me8100_device->base.slist,
134 subdevice);
137 for (i = 0; i < me8100_versions[version_idx].ctr_subdevices; i++) {
138 subdevice =
139 (me_subdevice_t *) me8254_constructor(me8100_device->base.
140 info.pci.device_id,
141 me8100_device->base.
142 info.pci.reg_bases[2],
143 0, i,
144 &me8100_device->
145 ctr_ctrl_reg_lock,
146 &me8100_device->
147 clk_src_reg_lock);
149 if (!subdevice) {
150 me_device_deinit((me_device_t *) me8100_device);
151 kfree(me8100_device);
152 PERROR("Cannot get memory for subdevice.\n");
153 return NULL;
156 me_slist_add_subdevice_tail(&me8100_device->base.slist,
157 subdevice);
160 return (me_device_t *) me8100_device;
163 // Init and exit of module.
165 static int __init me8100_init(void)
167 PDEBUG("executed.\n.");
168 return ME_ERRNO_SUCCESS;
171 static void __exit me8100_exit(void)
173 PDEBUG("executed.\n.");
176 module_init(me8100_init);
178 module_exit(me8100_exit);
180 // Administrative stuff for modinfo.
181 MODULE_AUTHOR("Guenter Gebhardt <g.gebhardt@meilhaus.de>");
182 MODULE_DESCRIPTION("Device Driver Module for Template Device");
183 MODULE_SUPPORTED_DEVICE("Meilhaus Template Devices");
184 MODULE_LICENSE("GPL");
186 // Export the constructor.
187 EXPORT_SYMBOL(me8100_pci_constructor);