serio.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. static inline void serio_register_port(struct serio *serio)
  62. {
  63. __serio_register_port(serio, THIS_MODULE);
  64. }
  65. void serio_unregister_port(struct serio *serio);
  66. void serio_unregister_child_port(struct serio *serio);
  67. int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name);
  68. static inline int __must_check serio_register_driver(struct serio_driver *drv)
  69. {
  70. return __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
  71. }
  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. #endif
  110. /*
  111. * bit masks for use in "interrupt" flags (3rd argument)
  112. */
  113. #define SERIO_TIMEOUT 1
  114. #define SERIO_PARITY 2
  115. #define SERIO_FRAME 4
  116. /*
  117. * Serio types
  118. */
  119. #define SERIO_XT 0x00
  120. #define SERIO_8042 0x01
  121. #define SERIO_RS232 0x02
  122. #define SERIO_HIL_MLC 0x03
  123. #define SERIO_PS_PSTHRU 0x05
  124. #define SERIO_8042_XL 0x06
  125. /*
  126. * Serio protocols
  127. */
  128. #define SERIO_UNKNOWN 0x00
  129. #define SERIO_MSC 0x01
  130. #define SERIO_SUN 0x02
  131. #define SERIO_MS 0x03
  132. #define SERIO_MP 0x04
  133. #define SERIO_MZ 0x05
  134. #define SERIO_MZP 0x06
  135. #define SERIO_MZPP 0x07
  136. #define SERIO_VSXXXAA 0x08
  137. #define SERIO_SUNKBD 0x10
  138. #define SERIO_WARRIOR 0x18
  139. #define SERIO_SPACEORB 0x19
  140. #define SERIO_MAGELLAN 0x1a
  141. #define SERIO_SPACEBALL 0x1b
  142. #define SERIO_GUNZE 0x1c
  143. #define SERIO_IFORCE 0x1d
  144. #define SERIO_STINGER 0x1e
  145. #define SERIO_NEWTON 0x1f
  146. #define SERIO_STOWAWAY 0x20
  147. #define SERIO_H3600 0x21
  148. #define SERIO_PS2SER 0x22
  149. #define SERIO_TWIDKBD 0x23
  150. #define SERIO_TWIDJOY 0x24
  151. #define SERIO_HIL 0x25
  152. #define SERIO_SNES232 0x26
  153. #define SERIO_SEMTECH 0x27
  154. #define SERIO_LKKBD 0x28
  155. #define SERIO_ELO 0x29
  156. #define SERIO_MICROTOUCH 0x30
  157. #define SERIO_PENMOUNT 0x31
  158. #define SERIO_TOUCHRIGHT 0x32
  159. #define SERIO_TOUCHWIN 0x33
  160. #define SERIO_TAOSEVM 0x34
  161. #define SERIO_FUJITSU 0x35
  162. #define SERIO_ZHENHUA 0x36
  163. #define SERIO_INEXIO 0x37
  164. #define SERIO_TOUCHIT213 0x38
  165. #define SERIO_W8001 0x39
  166. #define SERIO_DYNAPRO 0x3a
  167. #define SERIO_HAMPSHIRE 0x3b
  168. #endif