| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _I8042_SPARCIO_H | 
|  | 2 | #define _I8042_SPARCIO_H | 
|  | 3 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <asm/io.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <asm/oplib.h> | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 6 | #include <asm/prom.h> | 
|  | 7 | #include <asm/of_device.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  | 
|  | 9 | static int i8042_kbd_irq = -1; | 
|  | 10 | static int i8042_aux_irq = -1; | 
|  | 11 | #define I8042_KBD_IRQ i8042_kbd_irq | 
|  | 12 | #define I8042_AUX_IRQ i8042_aux_irq | 
|  | 13 |  | 
|  | 14 | #define I8042_KBD_PHYS_DESC "sparcps2/serio0" | 
|  | 15 | #define I8042_AUX_PHYS_DESC "sparcps2/serio1" | 
|  | 16 | #define I8042_MUX_PHYS_DESC "sparcps2/serio%d" | 
|  | 17 |  | 
|  | 18 | static void __iomem *kbd_iobase; | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 19 | static struct resource *kbd_res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
|  | 21 | #define I8042_COMMAND_REG	(kbd_iobase + 0x64UL) | 
|  | 22 | #define I8042_DATA_REG		(kbd_iobase + 0x60UL) | 
|  | 23 |  | 
|  | 24 | static inline int i8042_read_data(void) | 
|  | 25 | { | 
|  | 26 | return readb(kbd_iobase + 0x60UL); | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | static inline int i8042_read_status(void) | 
|  | 30 | { | 
|  | 31 | return readb(kbd_iobase + 0x64UL); | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | static inline void i8042_write_data(int val) | 
|  | 35 | { | 
|  | 36 | writeb(val, kbd_iobase + 0x60UL); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | static inline void i8042_write_command(int val) | 
|  | 40 | { | 
|  | 41 | writeb(val, kbd_iobase + 0x64UL); | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | #define OBP_PS2KBD_NAME1	"kb_ps2" | 
|  | 45 | #define OBP_PS2KBD_NAME2	"keyboard" | 
|  | 46 | #define OBP_PS2MS_NAME1		"kdmouse" | 
|  | 47 | #define OBP_PS2MS_NAME2		"mouse" | 
|  | 48 |  | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 49 | static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match) | 
|  | 50 | { | 
|  | 51 | struct device_node *dp = op->node; | 
|  | 52 |  | 
|  | 53 | dp = dp->child; | 
|  | 54 | while (dp) { | 
|  | 55 | if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || | 
|  | 56 | !strcmp(dp->name, OBP_PS2KBD_NAME2)) { | 
|  | 57 | struct of_device *kbd = of_find_device_by_node(dp); | 
|  | 58 | unsigned int irq = kbd->irqs[0]; | 
|  | 59 | if (irq == 0xffffffff) | 
|  | 60 | irq = op->irqs[0]; | 
|  | 61 | i8042_kbd_irq = irq; | 
|  | 62 | kbd_iobase = of_ioremap(&kbd->resource[0], | 
|  | 63 | 0, 8, "kbd"); | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 64 | kbd_res = &kbd->resource[0]; | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 65 | } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || | 
|  | 66 | !strcmp(dp->name, OBP_PS2MS_NAME2)) { | 
|  | 67 | struct of_device *ms = of_find_device_by_node(dp); | 
|  | 68 | unsigned int irq = ms->irqs[0]; | 
|  | 69 | if (irq == 0xffffffff) | 
|  | 70 | irq = op->irqs[0]; | 
|  | 71 | i8042_aux_irq = irq; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | dp = dp->sibling; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | return 0; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | static int __devexit sparc_i8042_remove(struct of_device *op) | 
|  | 81 | { | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 82 | of_iounmap(kbd_res, kbd_iobase, 8); | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 83 |  | 
|  | 84 | return 0; | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | static struct of_device_id sparc_i8042_match[] = { | 
|  | 88 | { | 
|  | 89 | .name = "8042", | 
|  | 90 | }, | 
|  | 91 | {}, | 
|  | 92 | }; | 
| Andrew Morton | 6b8f3ef | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 93 | MODULE_DEVICE_TABLE(of, sparc_i8042_match); | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 94 |  | 
|  | 95 | static struct of_platform_driver sparc_i8042_driver = { | 
|  | 96 | .name		= "i8042", | 
|  | 97 | .match_table	= sparc_i8042_match, | 
|  | 98 | .probe		= sparc_i8042_probe, | 
|  | 99 | .remove		= __devexit_p(sparc_i8042_remove), | 
|  | 100 | }; | 
|  | 101 |  | 
| Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 102 | static int __init i8042_platform_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { | 
|  | 104 | #ifndef CONFIG_PCI | 
| Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 105 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #else | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 107 | struct device_node *root = of_find_node_by_path("/"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 109 | if (!strcmp(root->name, "SUNW,JavaStation-1")) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* Hardcoded values for MrCoffee.  */ | 
|  | 111 | i8042_kbd_irq = i8042_aux_irq = 13 | 0x20; | 
|  | 112 | kbd_iobase = ioremap(0x71300060, 8); | 
|  | 113 | if (!kbd_iobase) | 
| Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 114 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } else { | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 116 | int err = of_register_driver(&sparc_i8042_driver, | 
|  | 117 | &of_bus_type); | 
|  | 118 | if (err) | 
|  | 119 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (i8042_kbd_irq == -1 || | 
|  | 122 | i8042_aux_irq == -1) { | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 123 | if (kbd_iobase) { | 
| David S. Miller | e3a411a | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 124 | of_iounmap(kbd_res, kbd_iobase, 8); | 
| David S. Miller | f57caae | 2006-06-29 15:42:29 -0700 | [diff] [blame] | 125 | kbd_iobase = (void __iomem *) NULL; | 
|  | 126 | } | 
| Dmitry Torokhov | 8d5987a | 2005-09-04 01:41:38 -0500 | [diff] [blame] | 127 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | i8042_reset = 1; | 
|  | 132 |  | 
|  | 133 | return 0; | 
|  | 134 | #endif /* CONFIG_PCI */ | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | static inline void i8042_platform_exit(void) | 
|  | 138 | { | 
|  | 139 | #ifdef CONFIG_PCI | 
| 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")) | 
|  | 143 | of_unregister_driver(&sparc_i8042_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #endif | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | #endif /* _I8042_SPARCIO_H */ |