mouse_rpc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/drivers/char/mouse_rpc.c
  3.  *
  4.  *  Copyright (C) 1996-1998 Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  *
  10.  *  This handles the Acorn RiscPCs mouse.  We basically have a couple
  11.  *  of hardware registers that track the sensor count for the X-Y movement
  12.  *  and another register holding the button state.  On every VSYNC interrupt
  13.  *  we read the complete state and then work out if something has changed.
  14.  */
  15. #include <linux/module.h>
  16. #include <linux/sched.h>
  17. #include <linux/ptrace.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/init.h>
  20. #include <asm/hardware.h>
  21. #include <asm/irq.h>
  22. #include <asm/io.h>
  23. #include <asm/hardware/iomd.h>
  24. #include "../../char/busmouse.h"
  25. static short old_x, old_y, old_b;
  26. static int mousedev;
  27. void
  28. mouse_rpc_irq(int irq, void *dev_id, struct pt_regs *regs)
  29. {
  30. short x, y, dx, dy;
  31. int buttons;
  32. x = (short)iomd_readl(IOMD_MOUSEX);
  33. y = (short)iomd_readl(IOMD_MOUSEY);
  34. buttons = (__raw_readl(0xe0310000) >> 4) & 7;
  35. dx = x - old_x;
  36. old_x = x;
  37. dy = y - old_y;
  38. old_y = y;
  39. if (dx || dy || buttons != old_b) {
  40. busmouse_add_movementbuttons(mousedev, dx, dy, buttons);
  41. old_b = buttons;
  42. }
  43. }
  44. static struct busmouse rpcmouse = {
  45. 6, "arcmouse", NULL, NULL, NULL, 7
  46. };
  47. static int __init mouse_rpc_init(void)
  48. {
  49. mousedev = register_busmouse(&rpcmouse);
  50. if (mousedev < 0)
  51. printk("rpcmouse: could not register mouse drivern");
  52. else {
  53. old_x = (short)iomd_readl(IOMD_MOUSEX);
  54. old_y = (short)iomd_readl(IOMD_MOUSEY);
  55. old_b = (__raw_readl(0xe0310000) >> 4) & 7;
  56. if (request_irq(IRQ_VSYNCPULSE, mouse_rpc_irq, SA_SHIRQ, "mouse", &mousedev)) {
  57. printk("rpcmouse: unable to allocate VSYNC interruptn");
  58. unregister_busmouse(mousedev);
  59. mousedev = -1;
  60. }
  61. }
  62. return mousedev >= 0 ? 0 : -ENODEV;
  63. }
  64. static void __exit mouse_rpc_exit(void)
  65. {
  66. if (mousedev >= 0) {
  67. unregister_busmouse(mousedev);
  68. free_irq(IRQ_VSYNCPULSE, &mousedev);
  69. }
  70. }
  71. module_init(mouse_rpc_init);
  72. module_exit(mouse_rpc_exit);
  73. MODULE_AUTHOR("Russell King");
  74. MODULE_DESCRIPTION("RiscPC mouse driver");
  75. MODULE_LICENSE("GPL");
  76. EXPORT_NO_SYMBOLS;