]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _I8042_SPARCIO_H |
3 | #define _I8042_SPARCIO_H | |
4 | ||
c6ed413d SR |
5 | #include <linux/of_device.h> |
6 | ||
1da177e4 | 7 | #include <asm/io.h> |
1da177e4 | 8 | #include <asm/oplib.h> |
f57caaef | 9 | #include <asm/prom.h> |
1da177e4 LT |
10 | |
11 | static int i8042_kbd_irq = -1; | |
12 | static int i8042_aux_irq = -1; | |
13 | #define I8042_KBD_IRQ i8042_kbd_irq | |
14 | #define I8042_AUX_IRQ i8042_aux_irq | |
15 | ||
16 | #define I8042_KBD_PHYS_DESC "sparcps2/serio0" | |
17 | #define I8042_AUX_PHYS_DESC "sparcps2/serio1" | |
18 | #define I8042_MUX_PHYS_DESC "sparcps2/serio%d" | |
19 | ||
20 | static void __iomem *kbd_iobase; | |
21 | ||
22 | #define I8042_COMMAND_REG (kbd_iobase + 0x64UL) | |
23 | #define I8042_DATA_REG (kbd_iobase + 0x60UL) | |
24 | ||
25 | static inline int i8042_read_data(void) | |
26 | { | |
27 | return readb(kbd_iobase + 0x60UL); | |
28 | } | |
29 | ||
30 | static inline int i8042_read_status(void) | |
31 | { | |
32 | return readb(kbd_iobase + 0x64UL); | |
33 | } | |
34 | ||
35 | static inline void i8042_write_data(int val) | |
36 | { | |
37 | writeb(val, kbd_iobase + 0x60UL); | |
38 | } | |
39 | ||
40 | static inline void i8042_write_command(int val) | |
41 | { | |
42 | writeb(val, kbd_iobase + 0x64UL); | |
43 | } | |
44 | ||
8c6a5cad AB |
45 | #ifdef CONFIG_PCI |
46 | ||
fb92be7b VS |
47 | static struct resource *kbd_res; |
48 | ||
1da177e4 LT |
49 | #define OBP_PS2KBD_NAME1 "kb_ps2" |
50 | #define OBP_PS2KBD_NAME2 "keyboard" | |
51 | #define OBP_PS2MS_NAME1 "kdmouse" | |
52 | #define OBP_PS2MS_NAME2 "mouse" | |
53 | ||
5298cc4c | 54 | static int sparc_i8042_probe(struct platform_device *op) |
f57caaef | 55 | { |
61c7a080 | 56 | struct device_node *dp = op->dev.of_node; |
f57caaef DM |
57 | |
58 | dp = dp->child; | |
59 | while (dp) { | |
60 | if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || | |
61 | !strcmp(dp->name, OBP_PS2KBD_NAME2)) { | |
2dc11581 | 62 | struct platform_device *kbd = of_find_device_by_node(dp); |
1636f8ac | 63 | unsigned int irq = kbd->archdata.irqs[0]; |
f57caaef | 64 | if (irq == 0xffffffff) |
1636f8ac | 65 | irq = op->archdata.irqs[0]; |
f57caaef DM |
66 | i8042_kbd_irq = irq; |
67 | kbd_iobase = of_ioremap(&kbd->resource[0], | |
68 | 0, 8, "kbd"); | |
e3a411a3 | 69 | kbd_res = &kbd->resource[0]; |
f57caaef DM |
70 | } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || |
71 | !strcmp(dp->name, OBP_PS2MS_NAME2)) { | |
2dc11581 | 72 | struct platform_device *ms = of_find_device_by_node(dp); |
1636f8ac | 73 | unsigned int irq = ms->archdata.irqs[0]; |
f57caaef | 74 | if (irq == 0xffffffff) |
1636f8ac | 75 | irq = op->archdata.irqs[0]; |
f57caaef DM |
76 | i8042_aux_irq = irq; |
77 | } | |
78 | ||
79 | dp = dp->sibling; | |
80 | } | |
81 | ||
82 | return 0; | |
83 | } | |
84 | ||
e2619cf7 | 85 | static int sparc_i8042_remove(struct platform_device *op) |
f57caaef | 86 | { |
e3a411a3 | 87 | of_iounmap(kbd_res, kbd_iobase, 8); |
f57caaef DM |
88 | |
89 | return 0; | |
90 | } | |
91 | ||
fd098316 | 92 | static const struct of_device_id sparc_i8042_match[] = { |
f57caaef DM |
93 | { |
94 | .name = "8042", | |
95 | }, | |
96 | {}, | |
97 | }; | |
6b8f3ef4 | 98 | MODULE_DEVICE_TABLE(of, sparc_i8042_match); |
f57caaef | 99 | |
4ebb24f7 | 100 | static struct platform_driver sparc_i8042_driver = { |
4018294b GL |
101 | .driver = { |
102 | .name = "i8042", | |
4018294b GL |
103 | .of_match_table = sparc_i8042_match, |
104 | }, | |
f57caaef | 105 | .probe = sparc_i8042_probe, |
1cb0aa88 | 106 | .remove = sparc_i8042_remove, |
f57caaef DM |
107 | }; |
108 | ||
8d5987a6 | 109 | static int __init i8042_platform_init(void) |
1da177e4 | 110 | { |
f57caaef | 111 | struct device_node *root = of_find_node_by_path("/"); |
1da177e4 | 112 | |
f57caaef | 113 | if (!strcmp(root->name, "SUNW,JavaStation-1")) { |
1da177e4 LT |
114 | /* Hardcoded values for MrCoffee. */ |
115 | i8042_kbd_irq = i8042_aux_irq = 13 | 0x20; | |
116 | kbd_iobase = ioremap(0x71300060, 8); | |
117 | if (!kbd_iobase) | |
8d5987a6 | 118 | return -ENODEV; |
1da177e4 | 119 | } else { |
4ebb24f7 | 120 | int err = platform_driver_register(&sparc_i8042_driver); |
f57caaef DM |
121 | if (err) |
122 | return err; | |
123 | ||
1da177e4 LT |
124 | if (i8042_kbd_irq == -1 || |
125 | i8042_aux_irq == -1) { | |
f57caaef | 126 | if (kbd_iobase) { |
e3a411a3 | 127 | of_iounmap(kbd_res, kbd_iobase, 8); |
f57caaef DM |
128 | kbd_iobase = (void __iomem *) NULL; |
129 | } | |
8d5987a6 | 130 | return -ENODEV; |
1da177e4 LT |
131 | } |
132 | } | |
133 | ||
930e1924 | 134 | i8042_reset = I8042_RESET_ALWAYS; |
1da177e4 LT |
135 | |
136 | return 0; | |
1da177e4 LT |
137 | } |
138 | ||
139 | static inline void i8042_platform_exit(void) | |
140 | { | |
f57caaef DM |
141 | struct device_node *root = of_find_node_by_path("/"); |
142 | ||
143 | if (strcmp(root->name, "SUNW,JavaStation-1")) | |
4ebb24f7 | 144 | platform_driver_unregister(&sparc_i8042_driver); |
1da177e4 LT |
145 | } |
146 | ||
8c6a5cad AB |
147 | #else /* !CONFIG_PCI */ |
148 | static int __init i8042_platform_init(void) | |
149 | { | |
150 | return -ENODEV; | |
151 | } | |
152 | ||
153 | static inline void i8042_platform_exit(void) | |
154 | { | |
155 | } | |
156 | #endif /* !CONFIG_PCI */ | |
157 | ||
1da177e4 | 158 | #endif /* _I8042_SPARCIO_H */ |