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)
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__.
37 * This must be defined before module.h is included. Not needed, when
38 * it is a built in driver.
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>
55 #include "meinternal.h"
59 #include "me1400_device.h"
61 #include "me8254_reg.h"
63 #include "me1400_ext_irq.h"
65 me_device_t
*me1400_pci_constructor(struct pci_dev
*pci_device
)
68 me1400_device_t
*me1400_device
;
69 me_subdevice_t
*subdevice
;
70 unsigned int version_idx
;
71 unsigned int me8255_idx
;
73 unsigned int me8254_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
);
83 PERROR("Cannot get memory for 1400ate device instance.\n");
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
);
94 PERROR("Cannot initialize device base class.\n");
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
) {
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
);
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);
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. */
142 me1400_versions_get_device_index(me1400_device
->base
.info
.pci
.
145 /* Generate DIO subdevice instances. */
147 me8255_idx
< me1400_versions
[version_idx
].dio_chips
;
149 for (dio_idx
= 0; dio_idx
< 3; dio_idx
++) {
152 me8255_constructor(me1400_versions
[version_idx
].
154 me1400_device
->base
.info
.pci
.
155 reg_bases
[2], me8255_idx
,
158 dio_current_mode
[me8255_idx
],
160 dio_ctrl_reg_lock
[me8255_idx
]);
163 me_device_deinit((me_device_t
*) me1400_device
);
164 kfree(me1400_device
);
165 PERROR("Cannot get memory for subdevice.\n");
169 me_slist_add_subdevice_tail(&me1400_device
->base
.slist
,
174 /* Generate counter subdevice instances. */
176 me8254_idx
< me1400_versions
[version_idx
].ctr_chips
;
178 for (ctr_idx
= 0; ctr_idx
< 3; ctr_idx
++) {
181 me8254_constructor(me1400_device
->base
.info
.pci
.
183 me1400_device
->base
.info
.pci
.
184 reg_bases
[2], me8254_idx
,
187 ctr_ctrl_reg_lock
[me8254_idx
],
192 me_device_deinit((me_device_t
*) me1400_device
);
193 kfree(me1400_device
);
194 PERROR("Cannot get memory for subdevice.\n");
198 me_slist_add_subdevice_tail(&me1400_device
->base
.slist
,
203 /* Generate external interrupt subdevice instances. */
204 for (ext_irq_idx
= 0;
205 ext_irq_idx
< me1400_versions
[version_idx
].ext_irq_subdevices
;
209 me1400_ext_irq_constructor(me1400_device
->base
.info
.pci
.
211 me1400_device
->base
.info
.pci
.
213 me1400_device
->base
.info
.pci
.
215 &me1400_device
->clk_src_reg_lock
,
216 me1400_device
->base
.irq
);
219 me_device_deinit((me_device_t
*) me1400_device
);
220 kfree(me1400_device
);
221 PERROR("Cannot get memory for subdevice.\n");
225 me_slist_add_subdevice_tail(&me1400_device
->base
.slist
,
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");
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.
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");