serio.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef _SERIO_H
  2. #define _SERIO_H
  3. /*
  4. * Copyright (C) 1999-2002 Vojtech Pavlik
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #include <linux/ioctl.h>
  11. #define SPIOCSTYPE _IOW('q', 0x01, unsigned long)
  12. #ifdef __KERNEL__
  13. #include <linux/interrupt.h>
  14. #include <linux/list.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/device.h>
  17. #include <linux/mod_devicetable.h>
  18. struct serio {
  19. void *port_data;
  20. char name[32];
  21. char phys[32];
  22. unsigned int manual_bind;
  23. struct serio_device_id id;
  24. spinlock_t lock; /* protects critical sections from port's interrupt handler */
  25. int (*write)(struct serio *, unsigned char);
  26. int (*open)(struct serio *);
  27. void (*close)(struct serio *);
  28. int (*start)(struct serio *);
  29. void (*stop)(struct serio *);
  30. struct serio *parent, *child;
  31. struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */
  32. struct semaphore drv_sem; /* protects serio->drv so attributes can pin driver */
  33. struct device dev;
  34. unsigned int registered; /* port has been fully registered with driver core */
  35. struct list_head node;
  36. };
  37. #define to_serio_port(d) container_of(d, struct serio, dev)
  38. struct serio_driver {
  39. void *private;
  40. char *description;
  41. struct serio_device_id *id_table;
  42. unsigned int manual_bind;
  43. void (*write_wakeup)(struct serio *);
  44. irqreturn_t (*interrupt)(struct serio *, unsigned char,
  45. unsigned int, struct pt_regs *);
  46. int (*connect)(struct serio *, struct serio_driver *drv);
  47. int (*reconnect)(struct serio *);
  48. void (*disconnect)(struct serio *);
  49. void (*cleanup)(struct serio *);
  50. struct device_driver driver;
  51. };
  52. #define to_serio_driver(d) container_of(d, struct serio_driver, driver)
  53. int serio_open(struct serio *serio, struct serio_driver *drv);
  54. void serio_close(struct serio *serio);
  55. void serio_rescan(struct serio *serio);
  56. void serio_reconnect(struct serio *serio);
  57. irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs);
  58. void __serio_register_port(struct serio *serio, struct module *owner);
  59. static inline void serio_register_port(struct serio *serio)
  60. {
  61. __serio_register_port(serio, THIS_MODULE);
  62. }
  63. void serio_unregister_port(struct serio *serio);
  64. void __serio_unregister_port_delayed(struct serio *serio, struct module *owner);
  65. static inline void serio_unregister_port_delayed(struct serio *serio)
  66. {
  67. __serio_unregister_port_delayed(serio, THIS_MODULE);
  68. }
  69. void __serio_register_driver(struct serio_driver *drv, struct module *owner);
  70. static inline void serio_register_driver(struct serio_driver *drv)
  71. {
  72. __serio_register_driver(drv, THIS_MODULE);
  73. }
  74. void serio_unregister_driver(struct serio_driver *drv);
  75. static inline int serio_write(struct serio *serio, unsigned char data)
  76. {
  77. if (serio->write)
  78. return serio->write(serio, data);
  79. else
  80. return -1;
  81. }
  82. static inline void serio_drv_write_wakeup(struct serio *serio)
  83. {
  84. if (serio->drv && serio->drv->write_wakeup)
  85. serio->drv->write_wakeup(serio);
  86. }
  87. static inline void serio_cleanup(struct serio *serio)
  88. {
  89. if (serio->drv && serio->drv->cleanup)
  90. serio->drv->cleanup(serio);
  91. }
  92. /*
  93. * Use the following fucntions to manipulate serio's per-port
  94. * driver-specific data.
  95. */
  96. static inline void *serio_get_drvdata(struct serio *serio)
  97. {
  98. return dev_get_drvdata(&serio->dev);
  99. }
  100. static inline void serio_set_drvdata(struct serio *serio, void *data)
  101. {
  102. dev_set_drvdata(&serio->dev, data);
  103. }
  104. /*
  105. * Use the following fucntions to protect critical sections in
  106. * driver code from port's interrupt handler
  107. */
  108. static inline void serio_pause_rx(struct serio *serio)
  109. {
  110. spin_lock_irq(&serio->lock);
  111. }
  112. static inline void serio_continue_rx(struct serio *serio)
  113. {
  114. spin_unlock_irq(&serio->lock);
  115. }
  116. /*
  117. * Use the following fucntions to pin serio's driver in process context
  118. */
  119. static inline int serio_pin_driver(struct serio *serio)
  120. {
  121. return down_interruptible(&serio->drv_sem);
  122. }
  123. static inline void serio_unpin_driver(struct serio *serio)
  124. {
  125. up(&serio->drv_sem);
  126. }
  127. #endif
  128. /*
  129. * bit masks for use in "interrupt" flags (3rd argument)
  130. */
  131. #define SERIO_TIMEOUT 1
  132. #define SERIO_PARITY 2
  133. #define SERIO_FRAME 4
  134. /*
  135. * Serio types
  136. */
  137. #define SERIO_XT 0x00
  138. #define SERIO_8042 0x01
  139. #define SERIO_RS232 0x02
  140. #define SERIO_HIL_MLC 0x03
  141. #define SERIO_PS_PSTHRU 0x05
  142. #define SERIO_8042_XL 0x06
  143. /*
  144. * Serio types
  145. */
  146. #define SERIO_UNKNOWN 0x00
  147. #define SERIO_MSC 0x01
  148. #define SERIO_SUN 0x02
  149. #define SERIO_MS 0x03
  150. #define SERIO_MP 0x04
  151. #define SERIO_MZ 0x05
  152. #define SERIO_MZP 0x06
  153. #define SERIO_MZPP 0x07
  154. #define SERIO_VSXXXAA 0x08
  155. #define SERIO_SUNKBD 0x10
  156. #define SERIO_WARRIOR 0x18
  157. #define SERIO_SPACEORB 0x19
  158. #define SERIO_MAGELLAN 0x1a
  159. #define SERIO_SPACEBALL 0x1b
  160. #define SERIO_GUNZE 0x1c
  161. #define SERIO_IFORCE 0x1d
  162. #define SERIO_STINGER 0x1e
  163. #define SERIO_NEWTON 0x1f
  164. #define SERIO_STOWAWAY 0x20
  165. #define SERIO_H3600 0x21
  166. #define SERIO_PS2SER 0x22
  167. #define SERIO_TWIDKBD 0x23
  168. #define SERIO_TWIDJOY 0x24
  169. #define SERIO_HIL 0x25
  170. #define SERIO_SNES232 0x26
  171. #define SERIO_SEMTECH 0x27
  172. #define SERIO_LKKBD 0x28
  173. #define SERIO_ELO 0x29
  174. #define SERIO_MICROTOUCH 0x30
  175. #endif