rpckbd.c 4.3 KB

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