blob: 9cad197a4e685f8f4ade42abe1bcb28a4100e8bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _I8042_SPARCIO_H
2#define _I8042_SPARCIO_H
3
4#include <linux/config.h>
5#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/oplib.h>
David S. Millerf57caae2006-06-29 15:42:29 -07007#include <asm/prom.h>
8#include <asm/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10static int i8042_kbd_irq = -1;
11static int i8042_aux_irq = -1;
12#define I8042_KBD_IRQ i8042_kbd_irq
13#define I8042_AUX_IRQ i8042_aux_irq
14
15#define I8042_KBD_PHYS_DESC "sparcps2/serio0"
16#define I8042_AUX_PHYS_DESC "sparcps2/serio1"
17#define I8042_MUX_PHYS_DESC "sparcps2/serio%d"
18
19static void __iomem *kbd_iobase;
20
21#define I8042_COMMAND_REG (kbd_iobase + 0x64UL)
22#define I8042_DATA_REG (kbd_iobase + 0x60UL)
23
24static inline int i8042_read_data(void)
25{
26 return readb(kbd_iobase + 0x60UL);
27}
28
29static inline int i8042_read_status(void)
30{
31 return readb(kbd_iobase + 0x64UL);
32}
33
34static inline void i8042_write_data(int val)
35{
36 writeb(val, kbd_iobase + 0x60UL);
37}
38
39static inline void i8042_write_command(int val)
40{
41 writeb(val, kbd_iobase + 0x64UL);
42}
43
44#define OBP_PS2KBD_NAME1 "kb_ps2"
45#define OBP_PS2KBD_NAME2 "keyboard"
46#define OBP_PS2MS_NAME1 "kdmouse"
47#define OBP_PS2MS_NAME2 "mouse"
48
David S. Millerf57caae2006-06-29 15:42:29 -070049static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match)
50{
51 struct device_node *dp = op->node;
52
53 dp = dp->child;
54 while (dp) {
55 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
56 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
57 struct of_device *kbd = of_find_device_by_node(dp);
58 unsigned int irq = kbd->irqs[0];
59 if (irq == 0xffffffff)
60 irq = op->irqs[0];
61 i8042_kbd_irq = irq;
62 kbd_iobase = of_ioremap(&kbd->resource[0],
63 0, 8, "kbd");
64 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
65 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
66 struct of_device *ms = of_find_device_by_node(dp);
67 unsigned int irq = ms->irqs[0];
68 if (irq == 0xffffffff)
69 irq = op->irqs[0];
70 i8042_aux_irq = irq;
71 }
72
73 dp = dp->sibling;
74 }
75
76 return 0;
77}
78
79static int __devexit sparc_i8042_remove(struct of_device *op)
80{
81 of_iounmap(kbd_iobase, 8);
82
83 return 0;
84}
85
86static struct of_device_id sparc_i8042_match[] = {
87 {
88 .name = "8042",
89 },
90 {},
91};
92MODULE_DEVICE_TABLE(of, i8042_match);
93
94static struct of_platform_driver sparc_i8042_driver = {
95 .name = "i8042",
96 .match_table = sparc_i8042_match,
97 .probe = sparc_i8042_probe,
98 .remove = __devexit_p(sparc_i8042_remove),
99};
100
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500101static int __init i8042_platform_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103#ifndef CONFIG_PCI
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500104 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#else
David S. Millerf57caae2006-06-29 15:42:29 -0700106 struct device_node *root = of_find_node_by_path("/");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
David S. Millerf57caae2006-06-29 15:42:29 -0700108 if (!strcmp(root->name, "SUNW,JavaStation-1")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* Hardcoded values for MrCoffee. */
110 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
111 kbd_iobase = ioremap(0x71300060, 8);
112 if (!kbd_iobase)
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500113 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 } else {
David S. Millerf57caae2006-06-29 15:42:29 -0700115 int err = of_register_driver(&sparc_i8042_driver,
116 &of_bus_type);
117 if (err)
118 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (i8042_kbd_irq == -1 ||
121 i8042_aux_irq == -1) {
David S. Millerf57caae2006-06-29 15:42:29 -0700122 if (kbd_iobase) {
123 of_iounmap(kbd_iobase, 8);
124 kbd_iobase = (void __iomem *) NULL;
125 }
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500126 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128 }
129
130 i8042_reset = 1;
131
132 return 0;
133#endif /* CONFIG_PCI */
134}
135
136static inline void i8042_platform_exit(void)
137{
138#ifdef CONFIG_PCI
David S. Millerf57caae2006-06-29 15:42:29 -0700139 struct device_node *root = of_find_node_by_path("/");
140
141 if (strcmp(root->name, "SUNW,JavaStation-1"))
142 of_unregister_driver(&sparc_i8042_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif
144}
145
146#endif /* _I8042_SPARCIO_H */