i8042-sparcio.h 3.2 KB

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