rpckbd.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * $Id: rpckbd.c,v 1.7 2001/09/25 10:12:07 vojtech Exp $
  3. *
  4. * Copyright (c) 2000-2001 Vojtech Pavlik
  5. * Copyright (c) 2002 Russell King
  6. */
  7. /*
  8. * Acorn RiscPC PS/2 keyboard controller driver for Linux/ARM
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. * Should you need to contact me, the author, you can do so either by
  26. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  27. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  28. */
  29. #include <linux/module.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/init.h>
  32. #include <linux/serio.h>
  33. #include <linux/err.h>
  34. #include <linux/platform_device.h>
  35. #include <asm/irq.h>
  36. #include <asm/hardware.h>
  37. #include <asm/io.h>
  38. #include <asm/hardware/iomd.h>
  39. #include <asm/system.h>
  40. MODULE_AUTHOR("Vojtech Pavlik, Russell King");
  41. MODULE_DESCRIPTION("Acorn RiscPC PS/2 keyboard controller driver");
  42. MODULE_LICENSE("GPL");
  43. MODULE_ALIAS("platform:kart");
  44. static int rpckbd_write(struct serio *port, unsigned char val)
  45. {
  46. while (!(iomd_readb(IOMD_KCTRL) & (1 << 7)))
  47. cpu_relax();
  48. iomd_writeb(val, IOMD_KARTTX);
  49. return 0;
  50. }
  51. static irqreturn_t rpckbd_rx(int irq, void *dev_id)
  52. {
  53. struct serio *port = dev_id;
  54. unsigned int byte;
  55. int handled = IRQ_NONE;
  56. while (iomd_readb(IOMD_KCTRL) & (1 << 5)) {
  57. byte = iomd_readb(IOMD_KARTRX);
  58. serio_interrupt(port, byte, 0);
  59. handled = IRQ_HANDLED;
  60. }
  61. return handled;
  62. }
  63. static irqreturn_t rpckbd_tx(int irq, void *dev_id)
  64. {
  65. return IRQ_HANDLED;
  66. }
  67. static int rpckbd_open(struct serio *port)
  68. {
  69. /* Reset the keyboard state machine. */
  70. iomd_writeb(0, IOMD_KCTRL);
  71. iomd_writeb(8, IOMD_KCTRL);
  72. iomd_readb(IOMD_KARTRX);
  73. if (request_irq(IRQ_KEYBOARDRX, rpckbd_rx, 0, "rpckbd", port) != 0) {
  74. printk(KERN_ERR "rpckbd.c: Could not allocate keyboard receive IRQ\n");
  75. return -EBUSY;
  76. }
  77. if (request_irq(IRQ_KEYBOARDTX, rpckbd_tx, 0, "rpckbd", port) != 0) {
  78. printk(KERN_ERR "rpckbd.c: Could not allocate keyboard transmit IRQ\n");
  79. free_irq(IRQ_KEYBOARDRX, NULL);
  80. return -EBUSY;
  81. }
  82. return 0;
  83. }
  84. static void rpckbd_close(struct serio *port)
  85. {
  86. free_irq(IRQ_KEYBOARDRX, port);
  87. free_irq(IRQ_KEYBOARDTX, port);
  88. }
  89. /*
  90. * Allocate and initialize serio structure for subsequent registration
  91. * with serio core.
  92. */
  93. static int __devinit rpckbd_probe(struct platform_device *dev)
  94. {
  95. struct serio *serio;
  96. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  97. if (!serio)
  98. return -ENOMEM;
  99. serio->id.type = SERIO_8042;
  100. serio->write = rpckbd_write;
  101. serio->open = rpckbd_open;
  102. serio->close = rpckbd_close;
  103. serio->dev.parent = &dev->dev;
  104. strlcpy(serio->name, "RiscPC PS/2 kbd port", sizeof(serio->name));
  105. strlcpy(serio->phys, "rpckbd/serio0", sizeof(serio->phys));
  106. platform_set_drvdata(dev, serio);
  107. serio_register_port(serio);
  108. return 0;
  109. }
  110. static int __devexit rpckbd_remove(struct platform_device *dev)
  111. {
  112. struct serio *serio = platform_get_drvdata(dev);
  113. serio_unregister_port(serio);
  114. return 0;
  115. }
  116. static struct platform_driver rpckbd_driver = {
  117. .probe = rpckbd_probe,
  118. .remove = __devexit_p(rpckbd_remove),
  119. .driver = {
  120. .name = "kart",
  121. .owner = THIS_MODULE,
  122. },
  123. };
  124. static int __init rpckbd_init(void)
  125. {
  126. return platform_driver_register(&rpckbd_driver);
  127. }
  128. static void __exit rpckbd_exit(void)
  129. {
  130. platform_driver_unregister(&rpckbd_driver);
  131. }
  132. module_init(rpckbd_init);
  133. module_exit(rpckbd_exit);