serio.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 1999-2002 Vojtech Pavlik
  4. */
  5. #ifndef _SERIO_H
  6. #define _SERIO_H
  7. #include <linux/types.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/list.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/mutex.h>
  12. #include <linux/device.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/android_kabi.h>
  15. #include <uapi/linux/serio.h>
  16. extern struct bus_type serio_bus;
  17. struct serio {
  18. void *port_data;
  19. char name[32];
  20. char phys[32];
  21. char firmware_id[128];
  22. bool manual_bind;
  23. struct serio_device_id id;
  24. /* Protects critical sections from port's interrupt handler */
  25. spinlock_t lock;
  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;
  32. /* Entry in parent->children list */
  33. struct list_head child_node;
  34. struct list_head children;
  35. /* Level of nesting in serio hierarchy */
  36. unsigned int depth;
  37. /*
  38. * serio->drv is accessed from interrupt handlers; when modifying
  39. * caller should acquire serio->drv_mutex and serio->lock.
  40. */
  41. struct serio_driver *drv;
  42. /* Protects serio->drv so attributes can pin current driver */
  43. struct mutex drv_mutex;
  44. struct device dev;
  45. struct list_head node;
  46. /*
  47. * For use by PS/2 layer when several ports share hardware and
  48. * may get indigestion when exposed to concurrent access (i8042).
  49. */
  50. struct mutex *ps2_cmd_mutex;
  51. ANDROID_KABI_RESERVE(1);
  52. };
  53. #define to_serio_port(d) container_of(d, struct serio, dev)
  54. struct serio_driver {
  55. const char *description;
  56. const struct serio_device_id *id_table;
  57. bool manual_bind;
  58. void (*write_wakeup)(struct serio *);
  59. irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
  60. int (*connect)(struct serio *, struct serio_driver *drv);
  61. int (*reconnect)(struct serio *);
  62. int (*fast_reconnect)(struct serio *);
  63. void (*disconnect)(struct serio *);
  64. void (*cleanup)(struct serio *);
  65. struct device_driver driver;
  66. ANDROID_KABI_RESERVE(1);
  67. };
  68. #define to_serio_driver(d) container_of(d, struct serio_driver, driver)
  69. int serio_open(struct serio *serio, struct serio_driver *drv);
  70. void serio_close(struct serio *serio);
  71. void serio_rescan(struct serio *serio);
  72. void serio_reconnect(struct serio *serio);
  73. irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
  74. void __serio_register_port(struct serio *serio, struct module *owner);
  75. /* use a define to avoid include chaining to get THIS_MODULE */
  76. #define serio_register_port(serio) \
  77. __serio_register_port(serio, THIS_MODULE)
  78. void serio_unregister_port(struct serio *serio);
  79. void serio_unregister_child_port(struct serio *serio);
  80. int __must_check __serio_register_driver(struct serio_driver *drv,
  81. struct module *owner, const char *mod_name);
  82. /* use a define to avoid include chaining to get THIS_MODULE & friends */
  83. #define serio_register_driver(drv) \
  84. __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
  85. void serio_unregister_driver(struct serio_driver *drv);
  86. /**
  87. * module_serio_driver() - Helper macro for registering a serio driver
  88. * @__serio_driver: serio_driver struct
  89. *
  90. * Helper macro for serio drivers which do not do anything special in
  91. * module init/exit. This eliminates a lot of boilerplate. Each module
  92. * may only use this macro once, and calling it replaces module_init()
  93. * and module_exit().
  94. */
  95. #define module_serio_driver(__serio_driver) \
  96. module_driver(__serio_driver, serio_register_driver, \
  97. serio_unregister_driver)
  98. static inline int serio_write(struct serio *serio, unsigned char data)
  99. {
  100. if (serio->write)
  101. return serio->write(serio, data);
  102. else
  103. return -1;
  104. }
  105. static inline void serio_drv_write_wakeup(struct serio *serio)
  106. {
  107. if (serio->drv && serio->drv->write_wakeup)
  108. serio->drv->write_wakeup(serio);
  109. }
  110. /*
  111. * Use the following functions to manipulate serio's per-port
  112. * driver-specific data.
  113. */
  114. static inline void *serio_get_drvdata(struct serio *serio)
  115. {
  116. return dev_get_drvdata(&serio->dev);
  117. }
  118. static inline void serio_set_drvdata(struct serio *serio, void *data)
  119. {
  120. dev_set_drvdata(&serio->dev, data);
  121. }
  122. /*
  123. * Use the following functions to protect critical sections in
  124. * driver code from port's interrupt handler
  125. */
  126. static inline void serio_pause_rx(struct serio *serio)
  127. {
  128. spin_lock_irq(&serio->lock);
  129. }
  130. static inline void serio_continue_rx(struct serio *serio)
  131. {
  132. spin_unlock_irq(&serio->lock);
  133. }
  134. #endif