cec-notifier.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * cec-notifier.h - notify CEC drivers of physical address changes
  4. *
  5. * Copyright 2016 Russell King <rmk+kernel@arm.linux.org.uk>
  6. * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  7. */
  8. #ifndef LINUX_CEC_NOTIFIER_H
  9. #define LINUX_CEC_NOTIFIER_H
  10. #include <linux/types.h>
  11. #include <media/cec.h>
  12. struct device;
  13. struct edid;
  14. struct cec_adapter;
  15. struct cec_notifier;
  16. #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
  17. /**
  18. * cec_notifier_get_conn - find or create a new cec_notifier for the given
  19. * device and connector tuple.
  20. * @dev: device that sends the events.
  21. * @conn: the connector name from which the event occurs
  22. *
  23. * If a notifier for device @dev already exists, then increase the refcount
  24. * and return that notifier.
  25. *
  26. * If it doesn't exist, then allocate a new notifier struct and return a
  27. * pointer to that new struct.
  28. *
  29. * Return NULL if the memory could not be allocated.
  30. */
  31. struct cec_notifier *cec_notifier_get_conn(struct device *dev,
  32. const char *conn);
  33. /**
  34. * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
  35. * @n: notifier
  36. */
  37. void cec_notifier_put(struct cec_notifier *n);
  38. /**
  39. * cec_notifier_set_phys_addr - set a new physical address.
  40. * @n: the CEC notifier
  41. * @pa: the CEC physical address
  42. *
  43. * Set a new CEC physical address.
  44. * Does nothing if @n == NULL.
  45. */
  46. void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
  47. /**
  48. * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
  49. * @n: the CEC notifier
  50. * @edid: the struct edid pointer
  51. *
  52. * Parses the EDID to obtain the new CEC physical address and set it.
  53. * Does nothing if @n == NULL.
  54. */
  55. void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
  56. const struct edid *edid);
  57. /**
  58. * cec_notifier_register - register a callback with the notifier
  59. * @n: the CEC notifier
  60. * @adap: the CEC adapter, passed as argument to the callback function
  61. * @callback: the callback function
  62. */
  63. void cec_notifier_register(struct cec_notifier *n,
  64. struct cec_adapter *adap,
  65. void (*callback)(struct cec_adapter *adap, u16 pa));
  66. /**
  67. * cec_notifier_unregister - unregister the callback from the notifier.
  68. * @n: the CEC notifier
  69. */
  70. void cec_notifier_unregister(struct cec_notifier *n);
  71. /**
  72. * cec_register_cec_notifier - register the notifier with the cec adapter.
  73. * @adap: the CEC adapter
  74. * @notifier: the CEC notifier
  75. */
  76. void cec_register_cec_notifier(struct cec_adapter *adap,
  77. struct cec_notifier *notifier);
  78. #else
  79. static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
  80. const char *conn)
  81. {
  82. /* A non-NULL pointer is expected on success */
  83. return (struct cec_notifier *)0xdeadfeed;
  84. }
  85. static inline void cec_notifier_put(struct cec_notifier *n)
  86. {
  87. }
  88. static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
  89. {
  90. }
  91. static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
  92. const struct edid *edid)
  93. {
  94. }
  95. static inline void cec_notifier_register(struct cec_notifier *n,
  96. struct cec_adapter *adap,
  97. void (*callback)(struct cec_adapter *adap, u16 pa))
  98. {
  99. }
  100. static inline void cec_notifier_unregister(struct cec_notifier *n)
  101. {
  102. }
  103. static inline void cec_register_cec_notifier(struct cec_adapter *adap,
  104. struct cec_notifier *notifier)
  105. {
  106. }
  107. #endif
  108. /**
  109. * cec_notifier_get - find or create a new cec_notifier for the given device.
  110. * @dev: device that sends the events.
  111. *
  112. * If a notifier for device @dev already exists, then increase the refcount
  113. * and return that notifier.
  114. *
  115. * If it doesn't exist, then allocate a new notifier struct and return a
  116. * pointer to that new struct.
  117. *
  118. * Return NULL if the memory could not be allocated.
  119. */
  120. static inline struct cec_notifier *cec_notifier_get(struct device *dev)
  121. {
  122. return cec_notifier_get_conn(dev, NULL);
  123. }
  124. /**
  125. * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
  126. *
  127. * @n: the CEC notifier
  128. *
  129. * This is a simple helper function to invalidate the physical
  130. * address. Does nothing if @n == NULL.
  131. */
  132. static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
  133. {
  134. cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
  135. }
  136. #endif