^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * cec-notifier.h - notify CEC drivers of physical address changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2016 Russell King.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef LINUX_CEC_NOTIFIER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define LINUX_CEC_NOTIFIER_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <media/cec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct edid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct cec_adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct cec_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * cec_notifier_conn_register - find or create a new cec_notifier for the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * HDMI device and connector tuple.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @hdmi_dev: HDMI device that sends the events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @port_name: the connector name from which the event occurs. May be NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * if there is always only one HDMI connector created by the HDMI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @conn_info: the connector info from which the event occurs (may be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * If a notifier for device @dev and connector @port_name already exists, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * increase the refcount and return that notifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * If it doesn't exist, then allocate a new notifier struct and return a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * pointer to that new struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Return NULL if the memory could not be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct cec_notifier *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) const struct cec_connector_info *conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * cec_notifier_conn_unregister - decrease refcount and delete when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * refcount reaches 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @n: notifier. If NULL, then this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void cec_notifier_conn_unregister(struct cec_notifier *n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * given device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * @hdmi_dev: HDMI device that sends the events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * @port_name: the connector name from which the event occurs. May be NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * if there is always only one HDMI connector created by the HDMI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @adap: the cec adapter that registered this notifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * If a notifier for device @dev and connector @port_name already exists, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * increase the refcount and return that notifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * If it doesn't exist, then allocate a new notifier struct and return a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * pointer to that new struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Return NULL if the memory could not be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct cec_notifier *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct cec_adapter *adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * refcount reaches 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @n: notifier. If NULL, then this function does nothing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @adap: the cec adapter that registered this notifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct cec_adapter *adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * cec_notifier_set_phys_addr - set a new physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @n: the CEC notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @pa: the CEC physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Set a new CEC physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Does nothing if @n == NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * @n: the CEC notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * @edid: the struct edid pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Parses the EDID to obtain the new CEC physical address and set it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Does nothing if @n == NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const struct edid *edid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @dev: the device with the "hdmi-phandle" device tree property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Returns the device pointer referenced by the "hdmi-phandle" property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Note that the refcount of the returned device is not incremented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * This device pointer is only used as a key value in the notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * list, but it is never accessed by the CEC driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static inline struct cec_notifier *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) const struct cec_connector_info *conn_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* A non-NULL pointer is expected on success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return (struct cec_notifier *)0xdeadfeed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static inline struct cec_notifier *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct cec_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* A non-NULL pointer is expected on success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return (struct cec_notifier *)0xdeadfeed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct cec_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) const struct edid *edid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @n: the CEC notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * This is a simple helper function to invalidate the physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * address. Does nothing if @n == NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #endif