cec-notifier.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.
  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/err.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_conn_register - find or create a new cec_notifier for the given
  19. * HDMI device and connector tuple.
  20. * @hdmi_dev: HDMI device that sends the events.
  21. * @port_name: the connector name from which the event occurs. May be NULL
  22. * if there is always only one HDMI connector created by the HDMI device.
  23. * @conn_info: the connector info from which the event occurs (may be NULL)
  24. *
  25. * If a notifier for device @dev and connector @port_name already exists, then
  26. * increase the refcount and return that notifier.
  27. *
  28. * If it doesn't exist, then allocate a new notifier struct and return a
  29. * pointer to that new struct.
  30. *
  31. * Return NULL if the memory could not be allocated.
  32. */
  33. struct cec_notifier *
  34. cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
  35. const struct cec_connector_info *conn_info);
  36. /**
  37. * cec_notifier_conn_unregister - decrease refcount and delete when the
  38. * refcount reaches 0.
  39. * @n: notifier. If NULL, then this function does nothing.
  40. */
  41. void cec_notifier_conn_unregister(struct cec_notifier *n);
  42. /**
  43. * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
  44. * given device.
  45. * @hdmi_dev: HDMI device that sends the events.
  46. * @port_name: the connector name from which the event occurs. May be NULL
  47. * if there is always only one HDMI connector created by the HDMI device.
  48. * @adap: the cec adapter that registered this notifier.
  49. *
  50. * If a notifier for device @dev and connector @port_name already exists, then
  51. * increase the refcount and return that notifier.
  52. *
  53. * If it doesn't exist, then allocate a new notifier struct and return a
  54. * pointer to that new struct.
  55. *
  56. * Return NULL if the memory could not be allocated.
  57. */
  58. struct cec_notifier *
  59. cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
  60. struct cec_adapter *adap);
  61. /**
  62. * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
  63. * refcount reaches 0.
  64. * @n: notifier. If NULL, then this function does nothing.
  65. * @adap: the cec adapter that registered this notifier.
  66. */
  67. void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
  68. struct cec_adapter *adap);
  69. /**
  70. * cec_notifier_set_phys_addr - set a new physical address.
  71. * @n: the CEC notifier
  72. * @pa: the CEC physical address
  73. *
  74. * Set a new CEC physical address.
  75. * Does nothing if @n == NULL.
  76. */
  77. void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
  78. /**
  79. * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
  80. * @n: the CEC notifier
  81. * @edid: the struct edid pointer
  82. *
  83. * Parses the EDID to obtain the new CEC physical address and set it.
  84. * Does nothing if @n == NULL.
  85. */
  86. void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
  87. const struct edid *edid);
  88. /**
  89. * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
  90. * @dev: the device with the "hdmi-phandle" device tree property
  91. *
  92. * Returns the device pointer referenced by the "hdmi-phandle" property.
  93. * Note that the refcount of the returned device is not incremented.
  94. * This device pointer is only used as a key value in the notifier
  95. * list, but it is never accessed by the CEC driver.
  96. */
  97. struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
  98. #else
  99. static inline struct cec_notifier *
  100. cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
  101. const struct cec_connector_info *conn_info)
  102. {
  103. /* A non-NULL pointer is expected on success */
  104. return (struct cec_notifier *)0xdeadfeed;
  105. }
  106. static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
  107. {
  108. }
  109. static inline struct cec_notifier *
  110. cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
  111. struct cec_adapter *adap)
  112. {
  113. /* A non-NULL pointer is expected on success */
  114. return (struct cec_notifier *)0xdeadfeed;
  115. }
  116. static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
  117. struct cec_adapter *adap)
  118. {
  119. }
  120. static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
  121. {
  122. }
  123. static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
  124. const struct edid *edid)
  125. {
  126. }
  127. static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
  128. {
  129. return ERR_PTR(-ENODEV);
  130. }
  131. #endif
  132. /**
  133. * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
  134. *
  135. * @n: the CEC notifier
  136. *
  137. * This is a simple helper function to invalidate the physical
  138. * address. Does nothing if @n == NULL.
  139. */
  140. static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
  141. {
  142. cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
  143. }
  144. #endif