Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _I8042_SPARCIO_H |
| 2 | #define _I8042_SPARCIO_H |
| 3 | |
Stephen Rothwell | c6ed413 | 2008-08-11 14:30:53 -0700 | [diff] [blame] | 4 | #include <linux/of_device.h> |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <asm/oplib.h> |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 8 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | static int i8042_kbd_irq = -1; |
| 11 | static 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 | |
| 19 | static void __iomem *kbd_iobase; |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 20 | static struct resource *kbd_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Alexander Beregalov | 8c6a5ca | 2008-08-06 02:43:24 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_PCI |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #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 Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 52 | static int __devinit sparc_i8042_probe(struct platform_device *op) |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 53 | { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 54 | struct device_node *dp = op->dev.of_node; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 55 | |
| 56 | dp = dp->child; |
| 57 | while (dp) { |
| 58 | if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || |
| 59 | !strcmp(dp->name, OBP_PS2KBD_NAME2)) { |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 60 | struct platform_device *kbd = of_find_device_by_node(dp); |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 61 | unsigned int irq = kbd->archdata.irqs[0]; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 62 | if (irq == 0xffffffff) |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 63 | irq = op->archdata.irqs[0]; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 64 | i8042_kbd_irq = irq; |
| 65 | kbd_iobase = of_ioremap(&kbd->resource[0], |
| 66 | 0, 8, "kbd"); |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 67 | kbd_res = &kbd->resource[0]; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 68 | } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || |
| 69 | !strcmp(dp->name, OBP_PS2MS_NAME2)) { |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 70 | struct platform_device *ms = of_find_device_by_node(dp); |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 71 | unsigned int irq = ms->archdata.irqs[0]; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 72 | if (irq == 0xffffffff) |
Grant Likely | 1636f8a | 2010-06-18 11:09:58 -0600 | [diff] [blame] | 73 | irq = op->archdata.irqs[0]; |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 74 | i8042_aux_irq = irq; |
| 75 | } |
| 76 | |
| 77 | dp = dp->sibling; |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 83 | static int __devexit sparc_i8042_remove(struct platform_device *op) |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 84 | { |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 85 | of_iounmap(kbd_res, kbd_iobase, 8); |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
David S. Miller | fd09831 | 2008-08-31 01:23:17 -0700 | [diff] [blame] | 90 | static const struct of_device_id sparc_i8042_match[] = { |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 91 | { |
| 92 | .name = "8042", |
| 93 | }, |
| 94 | {}, |
| 95 | }; |
Andrew Morton | 6b8f3ef | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 96 | MODULE_DEVICE_TABLE(of, sparc_i8042_match); |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 97 | |
Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 98 | static struct platform_driver sparc_i8042_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 99 | .driver = { |
| 100 | .name = "i8042", |
| 101 | .owner = THIS_MODULE, |
| 102 | .of_match_table = sparc_i8042_match, |
| 103 | }, |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 104 | .probe = sparc_i8042_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 105 | .remove = sparc_i8042_remove, |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 108 | static int __init i8042_platform_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 110 | struct device_node *root = of_find_node_by_path("/"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 112 | if (!strcmp(root->name, "SUNW,JavaStation-1")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* Hardcoded values for MrCoffee. */ |
| 114 | i8042_kbd_irq = i8042_aux_irq = 13 | 0x20; |
| 115 | kbd_iobase = ioremap(0x71300060, 8); |
| 116 | if (!kbd_iobase) |
Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 117 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } else { |
Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 119 | int err = platform_driver_register(&sparc_i8042_driver); |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 120 | if (err) |
| 121 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | if (i8042_kbd_irq == -1 || |
| 124 | i8042_aux_irq == -1) { |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 125 | if (kbd_iobase) { |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 126 | of_iounmap(kbd_res, kbd_iobase, 8); |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 127 | kbd_iobase = (void __iomem *) NULL; |
| 128 | } |
Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 129 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | i8042_reset = 1; |
| 134 | |
| 135 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static inline void i8042_platform_exit(void) |
| 139 | { |
David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 140 | struct device_node *root = of_find_node_by_path("/"); |
| 141 | |
| 142 | if (strcmp(root->name, "SUNW,JavaStation-1")) |
Grant Likely | 4ebb24f | 2011-02-22 20:01:33 -0700 | [diff] [blame] | 143 | platform_driver_unregister(&sparc_i8042_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Alexander Beregalov | 8c6a5ca | 2008-08-06 02:43:24 -0700 | [diff] [blame] | 146 | #else /* !CONFIG_PCI */ |
| 147 | static int __init i8042_platform_init(void) |
| 148 | { |
| 149 | return -ENODEV; |
| 150 | } |
| 151 | |
| 152 | static inline void i8042_platform_exit(void) |
| 153 | { |
| 154 | } |
| 155 | #endif /* !CONFIG_PCI */ |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #endif /* _I8042_SPARCIO_H */ |