serio.h 5.1 KB

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