]> err.no Git - linux-2.6/blob - drivers/input/serio/i8042-x86ia64io.h
Input: Avoid double unregistering of i8042 PnP driver. This can happen
[linux-2.6] / drivers / input / serio / i8042-x86ia64io.h
1 #ifndef _I8042_X86IA64IO_H
2 #define _I8042_X86IA64IO_H
3
4 /*
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  */
9
10 /*
11  * Names.
12  */
13
14 #define I8042_KBD_PHYS_DESC "isa0060/serio0"
15 #define I8042_AUX_PHYS_DESC "isa0060/serio1"
16 #define I8042_MUX_PHYS_DESC "isa0060/serio%d"
17
18 /*
19  * IRQs.
20  */
21
22 #if defined(__ia64__)
23 # define I8042_MAP_IRQ(x)       isa_irq_to_vector((x))
24 #else
25 # define I8042_MAP_IRQ(x)       (x)
26 #endif
27
28 #define I8042_KBD_IRQ   i8042_kbd_irq
29 #define I8042_AUX_IRQ   i8042_aux_irq
30
31 static int i8042_kbd_irq;
32 static int i8042_aux_irq;
33
34 /*
35  * Register numbers.
36  */
37
38 #define I8042_COMMAND_REG       i8042_command_reg
39 #define I8042_STATUS_REG        i8042_command_reg
40 #define I8042_DATA_REG          i8042_data_reg
41
42 static int i8042_command_reg = 0x64;
43 static int i8042_data_reg = 0x60;
44
45
46 static inline int i8042_read_data(void)
47 {
48         return inb(I8042_DATA_REG);
49 }
50
51 static inline int i8042_read_status(void)
52 {
53         return inb(I8042_STATUS_REG);
54 }
55
56 static inline void i8042_write_data(int val)
57 {
58         outb(val, I8042_DATA_REG);
59 }
60
61 static inline void i8042_write_command(int val)
62 {
63         outb(val, I8042_COMMAND_REG);
64 }
65
66 #if defined(__i386__)
67
68 #include <linux/dmi.h>
69
70 static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = {
71         {
72                 .ident = "Compaq Proliant 8500",
73                 .matches = {
74                         DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
75                         DMI_MATCH(DMI_PRODUCT_NAME , "ProLiant"),
76                         DMI_MATCH(DMI_PRODUCT_VERSION, "8500"),
77                 },
78         },
79         {
80                 .ident = "Compaq Proliant DL760",
81                 .matches = {
82                         DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
83                         DMI_MATCH(DMI_PRODUCT_NAME , "ProLiant"),
84                         DMI_MATCH(DMI_PRODUCT_VERSION, "DL760"),
85                 },
86         },
87         { }
88 };
89
90 /*
91  * Some Fujitsu notebooks are ahving trouble with touhcpads if
92  * active multiplexing mode is activated. Luckily they don't have
93  * external PS/2 ports so we can safely disable it.
94  */
95 static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
96         {
97                 .ident = "Fujitsu Lifebook P7010/P7010D",
98                 .matches = {
99                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
100                         DMI_MATCH(DMI_PRODUCT_NAME, "P7010"),
101                 },
102         },
103         {
104                 .ident = "Fujitsu Lifebook P5020D",
105                 .matches = {
106                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
107                         DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P Series"),
108                 },
109         },
110         {
111                 .ident = "Fujitsu Lifebook S2000",
112                 .matches = {
113                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
114                         DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook S Series"),
115                 },
116         },
117         {
118                 .ident = "Fujitsu T70H",
119                 .matches = {
120                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
121                         DMI_MATCH(DMI_PRODUCT_NAME, "FMVLT70H"),
122                 },
123         },
124         { }
125 };
126
127
128
129 #endif
130
131
132 #ifdef CONFIG_PNP
133 #include <linux/pnp.h>
134
135 static int i8042_pnp_kbd_registered;
136 static int i8042_pnp_aux_registered;
137
138 static int i8042_pnp_command_reg;
139 static int i8042_pnp_data_reg;
140 static int i8042_pnp_kbd_irq;
141 static int i8042_pnp_aux_irq;
142
143 static char i8042_pnp_kbd_name[32];
144 static char i8042_pnp_aux_name[32];
145
146 static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
147 {
148         if (pnp_port_valid(dev, 0) && pnp_port_len(dev, 0) == 1)
149                 i8042_pnp_data_reg = pnp_port_start(dev,0);
150
151         if (pnp_port_valid(dev, 1) && pnp_port_len(dev, 1) == 1)
152                 i8042_pnp_command_reg = pnp_port_start(dev, 1);
153
154         if (pnp_irq_valid(dev,0))
155                 i8042_pnp_kbd_irq = pnp_irq(dev, 0);
156
157         strncpy(i8042_pnp_kbd_name, did->id, sizeof(i8042_pnp_kbd_name));
158         if (strlen(pnp_dev_name(dev))) {
159                 strncat(i8042_pnp_kbd_name, ":", sizeof(i8042_pnp_kbd_name));
160                 strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
161         }
162
163         return 0;
164 }
165
166 static int i8042_pnp_aux_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
167 {
168         if (pnp_port_valid(dev, 0) && pnp_port_len(dev, 0) == 1)
169                 i8042_pnp_data_reg = pnp_port_start(dev,0);
170
171         if (pnp_port_valid(dev, 1) && pnp_port_len(dev, 1) == 1)
172                 i8042_pnp_command_reg = pnp_port_start(dev, 1);
173
174         if (pnp_irq_valid(dev, 0))
175                 i8042_pnp_aux_irq = pnp_irq(dev, 0);
176
177         strncpy(i8042_pnp_aux_name, did->id, sizeof(i8042_pnp_aux_name));
178         if (strlen(pnp_dev_name(dev))) {
179                 strncat(i8042_pnp_aux_name, ":", sizeof(i8042_pnp_aux_name));
180                 strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
181         }
182
183         return 0;
184 }
185
186 static struct pnp_device_id pnp_kbd_devids[] = {
187         { .id = "PNP0303", .driver_data = 0 },
188         { .id = "PNP030b", .driver_data = 0 },
189         { .id = "", },
190 };
191
192 static struct pnp_driver i8042_pnp_kbd_driver = {
193         .name           = "i8042 kbd",
194         .id_table       = pnp_kbd_devids,
195         .probe          = i8042_pnp_kbd_probe,
196 };
197
198 static struct pnp_device_id pnp_aux_devids[] = {
199         { .id = "PNP0f03", .driver_data = 0 },
200         { .id = "PNP0f0b", .driver_data = 0 },
201         { .id = "PNP0f0e", .driver_data = 0 },
202         { .id = "PNP0f12", .driver_data = 0 },
203         { .id = "PNP0f13", .driver_data = 0 },
204         { .id = "PNP0f19", .driver_data = 0 },
205         { .id = "PNP0f1c", .driver_data = 0 },
206         { .id = "SYN0801", .driver_data = 0 },
207         { .id = "", },
208 };
209
210 static struct pnp_driver i8042_pnp_aux_driver = {
211         .name           = "i8042 aux",
212         .id_table       = pnp_aux_devids,
213         .probe          = i8042_pnp_aux_probe,
214 };
215
216 static void i8042_pnp_exit(void)
217 {
218         if (i8042_pnp_kbd_registered) {
219                 i8042_pnp_kbd_registered = 0;
220                 pnp_unregister_driver(&i8042_pnp_kbd_driver);
221         }
222
223         if (i8042_pnp_aux_registered) {
224                 i8042_pnp_aux_registered = 0;
225                 pnp_unregister_driver(&i8042_pnp_aux_driver);
226         }
227 }
228
229 static int i8042_pnp_init(void)
230 {
231         int result_kbd, result_aux;
232
233         if (i8042_nopnp) {
234                 printk(KERN_INFO "i8042: PNP detection disabled\n");
235                 return 0;
236         }
237
238         if ((result_kbd = pnp_register_driver(&i8042_pnp_kbd_driver)) >= 0)
239                 i8042_pnp_kbd_registered = 1;
240         if ((result_aux = pnp_register_driver(&i8042_pnp_aux_driver)) >= 0)
241                 i8042_pnp_aux_registered = 1;
242
243         if (result_kbd <= 0 && result_aux <= 0) {
244                 i8042_pnp_exit();
245 #if defined(__ia64__)
246                 return -ENODEV;
247 #else
248                 printk(KERN_INFO "PNP: No PS/2 controller found. Probing ports directly.\n");
249                 return 0;
250 #endif
251         }
252
253         if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) &&
254               i8042_pnp_data_reg != i8042_data_reg) || !i8042_pnp_data_reg) {
255                 printk(KERN_WARNING "PNP: PS/2 controller has invalid data port %#x; using default %#x\n",
256                         i8042_pnp_data_reg, i8042_data_reg);
257                 i8042_pnp_data_reg = i8042_data_reg;
258         }
259
260         if (((i8042_pnp_command_reg & ~0xf) == (i8042_command_reg & ~0xf) &&
261               i8042_pnp_command_reg != i8042_command_reg) || !i8042_pnp_command_reg) {
262                 printk(KERN_WARNING "PNP: PS/2 controller has invalid command port %#x; using default %#x\n",
263                         i8042_pnp_command_reg, i8042_command_reg);
264                 i8042_pnp_command_reg = i8042_command_reg;
265         }
266
267         if (!i8042_pnp_kbd_irq) {
268                 printk(KERN_WARNING "PNP: PS/2 controller doesn't have KBD irq; using default %#x\n", i8042_kbd_irq);
269                 i8042_pnp_kbd_irq = i8042_kbd_irq;
270         }
271
272         if (!i8042_pnp_aux_irq) {
273                 printk(KERN_WARNING "PNP: PS/2 controller doesn't have AUX irq; using default %#x\n", i8042_aux_irq);
274                 i8042_pnp_aux_irq = i8042_aux_irq;
275         }
276
277 #if defined(__ia64__)
278         if (result_aux <= 0)
279                 i8042_noaux = 1;
280 #endif
281
282         i8042_data_reg = i8042_pnp_data_reg;
283         i8042_command_reg = i8042_pnp_command_reg;
284         i8042_kbd_irq = i8042_pnp_kbd_irq;
285         i8042_aux_irq = i8042_pnp_aux_irq;
286
287         printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %d%s%d\n",
288                 i8042_pnp_kbd_name, (result_kbd > 0 && result_aux > 0) ? "," : "", i8042_pnp_aux_name,
289                 i8042_data_reg, i8042_command_reg, i8042_kbd_irq,
290                 (result_aux > 0) ? "," : "", i8042_aux_irq);
291
292         return 0;
293 }
294
295 #endif
296
297 static inline int i8042_platform_init(void)
298 {
299 /*
300  * On ix86 platforms touching the i8042 data register region can do really
301  * bad things. Because of this the region is always reserved on ix86 boxes.
302  *
303  *      if (!request_region(I8042_DATA_REG, 16, "i8042"))
304  *              return -1;
305  */
306
307         i8042_kbd_irq = I8042_MAP_IRQ(1);
308         i8042_aux_irq = I8042_MAP_IRQ(12);
309
310 #ifdef CONFIG_PNP
311         if (i8042_pnp_init())
312                 return -1;
313 #endif
314
315 #if defined(__ia64__)
316         i8042_reset = 1;
317 #endif
318
319 #if defined(__i386__)
320         if (dmi_check_system(i8042_dmi_noloop_table))
321                 i8042_noloop = 1;
322
323         if (dmi_check_system(i8042_dmi_nomux_table))
324                 i8042_nomux = 1;
325 #endif
326
327         return 0;
328 }
329
330 static inline void i8042_platform_exit(void)
331 {
332 #ifdef CONFIG_PNP
333         i8042_pnp_exit();
334 #endif
335 }
336
337 #endif /* _I8042_X86IA64IO_H */