blob: afcd1c1a05b272b1d615b481f2de9c0a812a2889 [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;
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
Alexander Beregalov8c6a5ca2008-08-06 02:43:24 -070044#ifdef CONFIG_PCI
45
Vincent Stehléfb92be72014-08-19 14:17:37 -070046static struct resource *kbd_res;
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define OBP_PS2KBD_NAME1 "kb_ps2"
49#define OBP_PS2KBD_NAME2 "keyboard"
50#define OBP_PS2MS_NAME1 "kdmouse"
51#define OBP_PS2MS_NAME2 "mouse"
52
Bill Pemberton5298cc42012-11-23 21:38:25 -080053static int sparc_i8042_probe(struct platform_device *op)
David S. Millerf57caae2006-06-29 15:42:29 -070054{
Grant Likely61c7a082010-04-13 16:12:29 -070055 struct device_node *dp = op->dev.of_node;
David S. Millerf57caae2006-06-29 15:42:29 -070056
57 dp = dp->child;
58 while (dp) {
59 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
60 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
Grant Likely2dc11582010-08-06 09:25:50 -060061 struct platform_device *kbd = of_find_device_by_node(dp);
Grant Likely1636f8a2010-06-18 11:09:58 -060062 unsigned int irq = kbd->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070063 if (irq == 0xffffffff)
Grant Likely1636f8a2010-06-18 11:09:58 -060064 irq = op->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070065 i8042_kbd_irq = irq;
66 kbd_iobase = of_ioremap(&kbd->resource[0],
67 0, 8, "kbd");
David S. Millere3a411a32006-12-28 21:01:32 -080068 kbd_res = &kbd->resource[0];
David S. Millerf57caae2006-06-29 15:42:29 -070069 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
70 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
Grant Likely2dc11582010-08-06 09:25:50 -060071 struct platform_device *ms = of_find_device_by_node(dp);
Grant Likely1636f8a2010-06-18 11:09:58 -060072 unsigned int irq = ms->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070073 if (irq == 0xffffffff)
Grant Likely1636f8a2010-06-18 11:09:58 -060074 irq = op->archdata.irqs[0];
David S. Millerf57caae2006-06-29 15:42:29 -070075 i8042_aux_irq = irq;
76 }
77
78 dp = dp->sibling;
79 }
80
81 return 0;
82}
83
Bill Pembertone2619cf2012-11-23 21:50:47 -080084static int sparc_i8042_remove(struct platform_device *op)
David S. Millerf57caae2006-06-29 15:42:29 -070085{
David S. Millere3a411a32006-12-28 21:01:32 -080086 of_iounmap(kbd_res, kbd_iobase, 8);
David S. Millerf57caae2006-06-29 15:42:29 -070087
88 return 0;
89}
90
David S. Millerfd098312008-08-31 01:23:17 -070091static const struct of_device_id sparc_i8042_match[] = {
David S. Millerf57caae2006-06-29 15:42:29 -070092 {
93 .name = "8042",
94 },
95 {},
96};
Andrew Morton6b8f3ef2006-07-03 00:24:21 -070097MODULE_DEVICE_TABLE(of, sparc_i8042_match);
David S. Millerf57caae2006-06-29 15:42:29 -070098
Grant Likely4ebb24f2011-02-22 20:01:33 -070099static struct platform_driver sparc_i8042_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700100 .driver = {
101 .name = "i8042",
Grant Likely40182942010-04-13 16:13:02 -0700102 .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 */