ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / input / serio / i8042-sparcio.h
1 #ifndef _I8042_SPARCIO_H
2 #define _I8042_SPARCIO_H
3
4 #include <linux/config.h>
5 #include <asm/io.h>
6
7 #ifdef CONFIG_PCI
8 #include <asm/oplib.h>
9 #include <asm/ebus.h>
10 #endif
11
12 static int i8042_kbd_irq = -1;
13 static int i8042_aux_irq = -1;
14 #define I8042_KBD_IRQ i8042_kbd_irq
15 #define I8042_AUX_IRQ i8042_aux_irq
16
17 #define I8042_KBD_PHYS_DESC "sparcps2/serio0"
18 #define I8042_AUX_PHYS_DESC "sparcps2/serio1"
19 #define I8042_MUX_PHYS_DESC "sparcps2/serio%d"
20
21 static unsigned long kbd_iobase;
22
23 #define I8042_COMMAND_REG       (kbd_iobase + 0x64UL)
24 #define I8042_DATA_REG          (kbd_iobase + 0x60UL)
25
26 static inline int i8042_read_data(void)
27 {
28         return readb(kbd_iobase + 0x60UL);
29 }
30
31 static inline int i8042_read_status(void)
32 {
33         return readb(kbd_iobase + 0x64UL);
34 }
35
36 static inline void i8042_write_data(int val)
37 {
38         writeb(val, kbd_iobase + 0x60UL);
39 }
40
41 static inline void i8042_write_command(int val)
42 {
43         writeb(val, kbd_iobase + 0x64UL);
44 }
45
46 #define OBP_PS2KBD_NAME1        "kb_ps2"
47 #define OBP_PS2KBD_NAME2        "keyboard"
48 #define OBP_PS2MS_NAME1         "kdmouse"
49 #define OBP_PS2MS_NAME2         "mouse"
50
51 static int i8042_platform_init(void)
52 {
53 #ifndef CONFIG_PCI
54         return -1;
55 #else
56         char prop[128];
57         int len;
58
59         len = prom_getproperty(prom_root_node, "name", prop, sizeof(prop));
60         if (len < 0) {
61                 printk("i8042: Cannot get name property of root OBP node.\n");
62                 return -1;
63         }
64         if (strncmp(prop, "SUNW,JavaStation-1", len) == 0) {
65                 /* Hardcoded values for MrCoffee.  */
66                 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
67                 kbd_iobase = (unsigned long) ioremap(0x71300060, 8);
68                 if (!kbd_iobase)
69                         return -1;
70         } else {
71                 struct linux_ebus *ebus;
72                 struct linux_ebus_device *edev;
73                 struct linux_ebus_child *child;
74
75                 for_each_ebus(ebus) {
76                         for_each_ebusdev(edev, ebus) {
77                                 if (!strcmp(edev->prom_name, "8042"))
78                                         goto edev_found;
79                         }
80                 }
81                 return -1;
82
83         edev_found:
84                 for_each_edevchild(edev, child) {
85                         if (!strcmp(child->prom_name, OBP_PS2KBD_NAME1) ||
86                             !strcmp(child->prom_name, OBP_PS2KBD_NAME2)) {
87                                 i8042_kbd_irq = child->irqs[0];
88                                 kbd_iobase = (unsigned long)
89                                         ioremap(child->resource[0].start, 8);
90                         }
91                         if (!strcmp(child->prom_name, OBP_PS2MS_NAME1) ||
92                             !strcmp(child->prom_name, OBP_PS2MS_NAME2))
93                                 i8042_aux_irq = child->irqs[0];
94                 }
95                 if (i8042_kbd_irq == -1 ||
96                     i8042_aux_irq == -1) {
97                         printk("i8042: Error, 8042 device lacks both kbd and "
98                                "mouse nodes.\n");
99                         return -1;
100                 }
101         }
102
103         i8042_reset = 1;
104
105         return 0;
106 #endif /* CONFIG_PCI */
107 }
108
109 static inline void i8042_platform_exit(void)
110 {
111 #ifdef CONFIG_PCI
112         iounmap((void *)kbd_iobase);
113 #endif
114 }
115
116 #endif /* _I8042_SPARCIO_H */