hp680_ts_input.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include <linux/input.h>
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/interrupt.h>
  5. #include <asm/io.h>
  6. #include <asm/delay.h>
  7. #include <asm/adc.h>
  8. #include <mach/hp6xx.h>
  9. #define MODNAME "hp680_ts_input"
  10. #define HP680_TS_ABS_X_MIN 40
  11. #define HP680_TS_ABS_X_MAX 950
  12. #define HP680_TS_ABS_Y_MIN 80
  13. #define HP680_TS_ABS_Y_MAX 910
  14. #define PHDR 0xa400012e
  15. #define SCPDR 0xa4000136
  16. static void do_softint(struct work_struct *work);
  17. static struct input_dev *hp680_ts_dev;
  18. static DECLARE_DELAYED_WORK(work, do_softint);
  19. static void do_softint(struct work_struct *work)
  20. {
  21. int absx = 0, absy = 0;
  22. u8 scpdr;
  23. int touched = 0;
  24. if (__raw_readb(PHDR) & PHDR_TS_PEN_DOWN) {
  25. scpdr = __raw_readb(SCPDR);
  26. scpdr |= SCPDR_TS_SCAN_ENABLE;
  27. scpdr &= ~SCPDR_TS_SCAN_Y;
  28. __raw_writeb(scpdr, SCPDR);
  29. udelay(30);
  30. absy = adc_single(ADC_CHANNEL_TS_Y);
  31. scpdr = __raw_readb(SCPDR);
  32. scpdr |= SCPDR_TS_SCAN_Y;
  33. scpdr &= ~SCPDR_TS_SCAN_X;
  34. __raw_writeb(scpdr, SCPDR);
  35. udelay(30);
  36. absx = adc_single(ADC_CHANNEL_TS_X);
  37. scpdr = __raw_readb(SCPDR);
  38. scpdr |= SCPDR_TS_SCAN_X;
  39. scpdr &= ~SCPDR_TS_SCAN_ENABLE;
  40. __raw_writeb(scpdr, SCPDR);
  41. udelay(100);
  42. touched = __raw_readb(PHDR) & PHDR_TS_PEN_DOWN;
  43. }
  44. if (touched) {
  45. input_report_key(hp680_ts_dev, BTN_TOUCH, 1);
  46. input_report_abs(hp680_ts_dev, ABS_X, absx);
  47. input_report_abs(hp680_ts_dev, ABS_Y, absy);
  48. } else {
  49. input_report_key(hp680_ts_dev, BTN_TOUCH, 0);
  50. }
  51. input_sync(hp680_ts_dev);
  52. enable_irq(HP680_TS_IRQ);
  53. }
  54. static irqreturn_t hp680_ts_interrupt(int irq, void *dev)
  55. {
  56. disable_irq_nosync(irq);
  57. schedule_delayed_work(&work, HZ / 20);
  58. return IRQ_HANDLED;
  59. }
  60. static int __init hp680_ts_init(void)
  61. {
  62. int err;
  63. hp680_ts_dev = input_allocate_device();
  64. if (!hp680_ts_dev)
  65. return -ENOMEM;
  66. hp680_ts_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
  67. hp680_ts_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  68. input_set_abs_params(hp680_ts_dev, ABS_X,
  69. HP680_TS_ABS_X_MIN, HP680_TS_ABS_X_MAX, 0, 0);
  70. input_set_abs_params(hp680_ts_dev, ABS_Y,
  71. HP680_TS_ABS_Y_MIN, HP680_TS_ABS_Y_MAX, 0, 0);
  72. hp680_ts_dev->name = "HP Jornada touchscreen";
  73. hp680_ts_dev->phys = "hp680_ts/input0";
  74. if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
  75. 0, MODNAME, NULL) < 0) {
  76. printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
  77. HP680_TS_IRQ);
  78. err = -EBUSY;
  79. goto fail1;
  80. }
  81. err = input_register_device(hp680_ts_dev);
  82. if (err)
  83. goto fail2;
  84. return 0;
  85. fail2: free_irq(HP680_TS_IRQ, NULL);
  86. cancel_delayed_work_sync(&work);
  87. fail1: input_free_device(hp680_ts_dev);
  88. return err;
  89. }
  90. static void __exit hp680_ts_exit(void)
  91. {
  92. free_irq(HP680_TS_IRQ, NULL);
  93. cancel_delayed_work_sync(&work);
  94. input_unregister_device(hp680_ts_dev);
  95. }
  96. module_init(hp680_ts_init);
  97. module_exit(hp680_ts_exit);
  98. MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua");
  99. MODULE_DESCRIPTION("HP Jornada 680 touchscreen driver");
  100. MODULE_LICENSE("GPL");