serio.h 5.2 KB

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