serio.h 4.4 KB

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