blob: 692a79ec2a22327e98c94ef4946fe2f69b6747da [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _I8042_SPARCIO_H
2#define _I8042_SPARCIO_H
3
Stephen Rothwellc6ed4132008-08-11 14:30:53 -07004#include <linux/of_device.h>
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/oplib.h>
David S. Millerf57caae2006-06-29 15:42:29 -07008#include <asm/prom.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;
David S. Millere3a411a32006-12-28 21:01:32 -080020static struct resource *kbd_res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#define I8042_COMMAND_REG (kbd_iobase + 0x64UL)
23#define I8042_DATA_REG (kbd_iobase + 0x60UL)
24
25static inline int i8042_read_data(void)
26{
27 return readb(kbd_iobase + 0x60UL);
28}
29
30static inline int i8042_read_status(void)
31{
32 return readb(kbd_iobase + 0x64UL);
33}
34
35static inline void i8042_write_data(int val)
36{
37 writeb(val, kbd_iobase + 0x60UL);
38}
39
40static inline void i8042_write_command(int val)
41{
42 writeb(val, kbd_iobase + 0x64UL);
43}
44
Alexander Beregalov8c6a5ca2008-08-06 02:43:24 -070045#ifdef CONFIG_PCI
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define OBP_PS2KBD_NAME1 "kb_ps2"
48#define OBP_PS2KBD_NAME2 "keyboard"
49#define OBP_PS2MS_NAME1 "kdmouse"
50#define OBP_PS2MS_NAME2 "mouse"
51
David S. Millerf57caae2006-06-29 15:42:29 -070052static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match)
53{
54 struct device_node *dp = op->node;
55
56 dp = dp->child;
57 while (dp) {
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
60 struct of_device *kbd = of_find_device_by_node(dp);
61 unsigned int irq = kbd->irqs[0];
62 if (irq == 0xffffffff)
63 irq = op->irqs[0];
64 i8042_kbd_irq = irq;
65 kbd_iobase = of_ioremap(&kbd->resource[0],
66 0, 8, "kbd");
David S. Millere3a411a32006-12-28 21:01:32 -080067 kbd_res = &kbd->resource[0];
David S. Millerf57caae2006-06-29 15:42:29 -070068 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
69 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
70 struct of_device *ms = of_find_device_by_node(dp);
71 unsigned int irq = ms->irqs[0];
72 if (irq == 0xffffffff)
73 irq = op->irqs[0];
74 i8042_aux_irq = irq;
75 }
76
77 dp = dp->sibling;
78 }
79
80 return 0;
81}
82
83static int __devexit sparc_i8042_remove(struct of_device *op)
84{
David S. Millere3a411a32006-12-28 21:01:32 -080085 of_iounmap(kbd_res, kbd_iobase, 8);
David S. Millerf57caae2006-06-29 15:42:29 -070086
87 return 0;
88}
89
90static struct of_device_id sparc_i8042_match[] = {
91 {
92 .name = "8042",
93 },
94 {},
95};
Andrew Morton6b8f3ef2006-07-03 00:24:21 -070096MODULE_DEVICE_TABLE(of, sparc_i8042_match);
David S. Millerf57caae2006-06-29 15:42:29 -070097
98static struct of_platform_driver sparc_i8042_driver = {
99 .name = "i8042",
100 .match_table = sparc_i8042_match,
101 .probe = sparc_i8042_probe,
102 .remove = __devexit_p(sparc_i8042_remove),
103};
104
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500105static int __init i8042_platform_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
David S. Millerf57caae2006-06-29 15:42:29 -0700107 struct device_node *root = of_find_node_by_path("/");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
David S. Millerf57caae2006-06-29 15:42:29 -0700109 if (!strcmp(root->name, "SUNW,JavaStation-1")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* Hardcoded values for MrCoffee. */
111 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
112 kbd_iobase = ioremap(0x71300060, 8);
113 if (!kbd_iobase)
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500114 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 } else {
David S. Millerf57caae2006-06-29 15:42:29 -0700116 int err = of_register_driver(&sparc_i8042_driver,
117 &of_bus_type);
118 if (err)
119 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (i8042_kbd_irq == -1 ||
122 i8042_aux_irq == -1) {
David S. Millerf57caae2006-06-29 15:42:29 -0700123 if (kbd_iobase) {
David S. Millere3a411a32006-12-28 21:01:32 -0800124 of_iounmap(kbd_res, kbd_iobase, 8);
David S. Millerf57caae2006-06-29 15:42:29 -0700125 kbd_iobase = (void __iomem *) NULL;
126 }
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500127 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129 }
130
131 i8042_reset = 1;
132
133 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136static inline void i8042_platform_exit(void)
137{
David S. Millerf57caae2006-06-29 15:42:29 -0700138 struct device_node *root = of_find_node_by_path("/");
139
140 if (strcmp(root->name, "SUNW,JavaStation-1"))
141 of_unregister_driver(&sparc_i8042_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
Alexander Beregalov8c6a5ca2008-08-06 02:43:24 -0700144#else /* !CONFIG_PCI */
145static int __init i8042_platform_init(void)
146{
147 return -ENODEV;
148}
149
150static inline void i8042_platform_exit(void)
151{
152}
153#endif /* !CONFIG_PCI */
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#endif /* _I8042_SPARCIO_H */