blob: 3f6c835ae005d2327fd04141e6f696ecc1254316 [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
Grant Likely4ebb24f2011-02-22 20:01:33 -070052static int __devinit sparc_i8042_probe(struct platform_device *op)
David S. Millerf57caae2006-06-29 15:42:29 -070053{
Grant Likely61c7a082010-04-13 16:12:29 -070054 struct device_node *dp = op->dev.of_node;
David S. Millerf57caae2006-06-29 15:42:29 -070055
56 dp = dp->child;
57 while (dp) {
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
Grant Likely2dc11582010-08-06 09:25:50 -060060 struct platform_device *kbd = of_find_device_by_node(dp);
Grant Likely1636f8a2010-06-18 11:09:58 -060061 unsigned int irq = kbd->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070062 if (irq == 0xffffffff)
Grant Likely1636f8a2010-06-18 11:09:58 -060063 irq = op->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070064 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)) {
Grant Likely2dc11582010-08-06 09:25:50 -060070 struct platform_device *ms = of_find_device_by_node(dp);
Grant Likely1636f8a2010-06-18 11:09:58 -060071 unsigned int irq = ms->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070072 if (irq == 0xffffffff)
Grant Likely1636f8a2010-06-18 11:09:58 -060073 irq = op->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070074 i8042_aux_irq = irq;
75 }
76
77 dp = dp->sibling;
78 }
79
80 return 0;
81}
82
Grant Likely2dc11582010-08-06 09:25:50 -060083static int __devexit sparc_i8042_remove(struct platform_device *op)
David S. Millerf57caae2006-06-29 15:42:29 -070084{
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
David S. Millerfd098312008-08-31 01:23:17 -070090static const struct of_device_id sparc_i8042_match[] = {
David S. Millerf57caae2006-06-29 15:42:29 -070091 {
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
Grant Likely4ebb24f2011-02-22 20:01:33 -070098static struct platform_driver sparc_i8042_driver = {
Grant Likely40182942010-04-13 16:13:02 -070099 .driver = {
100 .name = "i8042",
101 .owner = THIS_MODULE,
102 .of_match_table = sparc_i8042_match,
103 },
David S. Millerf57caae2006-06-29 15:42:29 -0700104 .probe = sparc_i8042_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800105 .remove = sparc_i8042_remove,
David S. Millerf57caae2006-06-29 15:42:29 -0700106};
107
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500108static int __init i8042_platform_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
David S. Millerf57caae2006-06-29 15:42:29 -0700110 struct device_node *root = of_find_node_by_path("/");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
David S. Millerf57caae2006-06-29 15:42:29 -0700112 if (!strcmp(root->name, "SUNW,JavaStation-1")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 /* Hardcoded values for MrCoffee. */
114 i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
115 kbd_iobase = ioremap(0x71300060, 8);
116 if (!kbd_iobase)
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500117 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 } else {
Grant Likely4ebb24f2011-02-22 20:01:33 -0700119 int err = platform_driver_register(&sparc_i8042_driver);
David S. Millerf57caae2006-06-29 15:42:29 -0700120 if (err)
121 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (i8042_kbd_irq == -1 ||
124 i8042_aux_irq == -1) {
David S. Millerf57caae2006-06-29 15:42:29 -0700125 if (kbd_iobase) {
David S. Millere3a411a32006-12-28 21:01:32 -0800126 of_iounmap(kbd_res, kbd_iobase, 8);
David S. Millerf57caae2006-06-29 15:42:29 -0700127 kbd_iobase = (void __iomem *) NULL;
128 }
Dmitry Torokhov8d5987a2005-09-04 01:41:38 -0500129 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131 }
132
133 i8042_reset = 1;
134
135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
138static inline void i8042_platform_exit(void)
139{
David S. Millerf57caae2006-06-29 15:42:29 -0700140 struct device_node *root = of_find_node_by_path("/");
141
142 if (strcmp(root->name, "SUNW,JavaStation-1"))
Grant Likely4ebb24f2011-02-22 20:01:33 -0700143 platform_driver_unregister(&sparc_i8042_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Alexander Beregalov8c6a5ca2008-08-06 02:43:24 -0700146#else /* !CONFIG_PCI */
147static int __init i8042_platform_init(void)
148{
149 return -ENODEV;
150}
151
152static inline void i8042_platform_exit(void)
153{
154}
155#endif /* !CONFIG_PCI */
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif /* _I8042_SPARCIO_H */