OMAP2/3: Add omap_type() for determining GP/EMU/HS
[linux-ginger.git] / drivers / staging / meilhaus / me1400_device.c
blobca7498b9056c2818b66371822f13620e808942b2
1 /**
2 * @file me1400_device.c
4 * @brief ME-1400 device instance.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
8 */
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.
29 * User application could also include the kernel header files. But the
30 * real kernel functions are protected by #ifdef __KERNEL__.
32 #ifndef __KERNEL__
33 # define __KERNEL__
34 #endif
37 * This must be defined before module.h is included. Not needed, when
38 * it is a built in driver.
40 #ifndef MODULE
41 # define MODULE
42 #endif
44 #include <linux/module.h>
46 #include <linux/pci.h>
47 #include <linux/slab.h>
48 #include <linux/sched.h>
49 #include <linux/interrupt.h>
50 #include <linux/version.h>
52 #include "meids.h"
53 #include "meerror.h"
54 #include "mecommon.h"
55 #include "meinternal.h"
57 #include "medebug.h"
59 #include "me1400_device.h"
60 #include "me8254.h"
61 #include "me8254_reg.h"
62 #include "me8255.h"
63 #include "me1400_ext_irq.h"
65 me_device_t *me1400_pci_constructor(struct pci_dev *pci_device)
67 int err;
68 me1400_device_t *me1400_device;
69 me_subdevice_t *subdevice;
70 unsigned int version_idx;
71 unsigned int me8255_idx;
72 unsigned int dio_idx;
73 unsigned int me8254_idx;
74 unsigned int ctr_idx;
75 unsigned int ext_irq_idx;
77 PDEBUG("executed.\n");
79 // Allocate structure for device instance.
80 me1400_device = kmalloc(sizeof(me1400_device_t), GFP_KERNEL);
82 if (!me1400_device) {
83 PERROR("Cannot get memory for 1400ate device instance.\n");
84 return NULL;
87 memset(me1400_device, 0, sizeof(me1400_device_t));
89 // Initialize base class structure.
90 err = me_device_pci_init((me_device_t *) me1400_device, pci_device);
92 if (err) {
93 kfree(me1400_device);
94 PERROR("Cannot initialize device base class.\n");
95 return NULL;
98 /* Check for ME1400 extension device. If detected we fake a ME-1400 D device id. */
99 if (me1400_device->base.info.pci.device_id ==
100 PCI_DEVICE_ID_MEILHAUS_ME140C) {
101 uint8_t ctrl;
102 ctrl =
103 inb(me1400_device->base.info.pci.reg_bases[2] +
104 ME1400D_CLK_SRC_2_REG);
105 PDEBUG_REG("xxx_reg inb(0x%X+0x%X)=0x%x\n",
106 me1400_device->base.info.pci.reg_bases[2],
107 ME1400D_CLK_SRC_2_REG, ctrl);
108 outb(ctrl | 0xF0,
109 me1400_device->base.info.pci.reg_bases[2] +
110 ME1400D_CLK_SRC_2_REG);
111 PDEBUG_REG("xxx_reg outb(0x%X+0x%X)=0x%x\n",
112 me1400_device->base.info.pci.reg_bases[2],
113 ME1400D_CLK_SRC_2_REG, ctrl | 0xF0);
114 ctrl =
115 inb(me1400_device->base.info.pci.reg_bases[2] +
116 ME1400D_CLK_SRC_2_REG);
117 PDEBUG_REG("xxx_reg inb(0x%X+0x%X)=0x%x\n",
118 me1400_device->base.info.pci.reg_bases[2],
119 ME1400D_CLK_SRC_2_REG, ctrl);
121 if ((ctrl & 0xF0) == 0xF0) {
122 PINFO("ME1400 D detected.\n");
123 me1400_device->base.info.pci.device_id =
124 PCI_DEVICE_ID_MEILHAUS_ME140D;
128 /* Initialize global stuff of digital i/o subdevices. */
129 for (me8255_idx = 0; me8255_idx < ME1400_MAX_8255; me8255_idx++) {
130 me1400_device->dio_current_mode[me8255_idx] = 0;
131 spin_lock_init(&me1400_device->dio_ctrl_reg_lock[me8255_idx]);
134 /* Initialize global stuff of counter subdevices. */
135 spin_lock_init(&me1400_device->clk_src_reg_lock);
137 for (me8254_idx = 0; me8254_idx < ME1400_MAX_8254; me8254_idx++)
138 spin_lock_init(&me1400_device->ctr_ctrl_reg_lock[me8254_idx]);
140 /* Get the index in the device version information table. */
141 version_idx =
142 me1400_versions_get_device_index(me1400_device->base.info.pci.
143 device_id);
145 /* Generate DIO subdevice instances. */
146 for (me8255_idx = 0;
147 me8255_idx < me1400_versions[version_idx].dio_chips;
148 me8255_idx++) {
149 for (dio_idx = 0; dio_idx < 3; dio_idx++) {
150 subdevice =
151 (me_subdevice_t *)
152 me8255_constructor(me1400_versions[version_idx].
153 device_id,
154 me1400_device->base.info.pci.
155 reg_bases[2], me8255_idx,
156 dio_idx,
157 &me1400_device->
158 dio_current_mode[me8255_idx],
159 &me1400_device->
160 dio_ctrl_reg_lock[me8255_idx]);
162 if (!subdevice) {
163 me_device_deinit((me_device_t *) me1400_device);
164 kfree(me1400_device);
165 PERROR("Cannot get memory for subdevice.\n");
166 return NULL;
169 me_slist_add_subdevice_tail(&me1400_device->base.slist,
170 subdevice);
174 /* Generate counter subdevice instances. */
175 for (me8254_idx = 0;
176 me8254_idx < me1400_versions[version_idx].ctr_chips;
177 me8254_idx++) {
178 for (ctr_idx = 0; ctr_idx < 3; ctr_idx++) {
179 subdevice =
180 (me_subdevice_t *)
181 me8254_constructor(me1400_device->base.info.pci.
182 device_id,
183 me1400_device->base.info.pci.
184 reg_bases[2], me8254_idx,
185 ctr_idx,
186 &me1400_device->
187 ctr_ctrl_reg_lock[me8254_idx],
188 &me1400_device->
189 clk_src_reg_lock);
191 if (!subdevice) {
192 me_device_deinit((me_device_t *) me1400_device);
193 kfree(me1400_device);
194 PERROR("Cannot get memory for subdevice.\n");
195 return NULL;
198 me_slist_add_subdevice_tail(&me1400_device->base.slist,
199 subdevice);
203 /* Generate external interrupt subdevice instances. */
204 for (ext_irq_idx = 0;
205 ext_irq_idx < me1400_versions[version_idx].ext_irq_subdevices;
206 ext_irq_idx++) {
207 subdevice =
208 (me_subdevice_t *)
209 me1400_ext_irq_constructor(me1400_device->base.info.pci.
210 device_id,
211 me1400_device->base.info.pci.
212 reg_bases[1],
213 me1400_device->base.info.pci.
214 reg_bases[2],
215 &me1400_device->clk_src_reg_lock,
216 me1400_device->base.irq);
218 if (!subdevice) {
219 me_device_deinit((me_device_t *) me1400_device);
220 kfree(me1400_device);
221 PERROR("Cannot get memory for subdevice.\n");
222 return NULL;
225 me_slist_add_subdevice_tail(&me1400_device->base.slist,
226 subdevice);
229 return (me_device_t *) me1400_device;
231 EXPORT_SYMBOL(me1400_pci_constructor);
233 // Init and exit of module.
235 static int __init me1400_init(void)
237 PDEBUG("executed.\n");
238 return 0;
241 static void __exit me1400_exit(void)
243 PDEBUG("executed.\n");
246 module_init(me1400_init);
247 module_exit(me1400_exit);
249 // Administrative stuff for modinfo.
250 MODULE_AUTHOR
251 ("Guenter Gebhardt <g.gebhardt@meilhaus.de> & Krzysztof Gantzke <k.gantzke@meilhaus.de>");
252 MODULE_DESCRIPTION("Device Driver Module for Meilhaus ME-14xx devices");
253 MODULE_SUPPORTED_DEVICE("Meilhaus ME-14xx MIO devices");
254 MODULE_LICENSE("GPL");