1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * cec-notifier.h - notify CEC drivers of physical address changes
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.
9 #ifndef LINUX_CEC_NOTIFIER_H
10 #define LINUX_CEC_NOTIFIER_H
12 #include <linux/err.h>
13 #include <media/cec.h>
20 #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
23 * cec_notifier_get_conn - find or create a new cec_notifier for the given
24 * device and connector tuple.
25 * @dev: device that sends the events.
26 * @conn: the connector name from which the event occurs
28 * If a notifier for device @dev already exists, then increase the refcount
29 * and return that notifier.
31 * If it doesn't exist, then allocate a new notifier struct and return a
32 * pointer to that new struct.
34 * Return NULL if the memory could not be allocated.
36 struct cec_notifier *cec_notifier_get_conn(struct device *dev,
40 * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
43 void cec_notifier_put(struct cec_notifier *n);
46 * cec_notifier_conn_register - find or create a new cec_notifier for the given
47 * HDMI device and connector tuple.
48 * @hdmi_dev: HDMI device that sends the events.
49 * @conn_name: the connector name from which the event occurs. May be NULL
50 * if there is always only one HDMI connector created by the HDMI device.
51 * @conn_info: the connector info from which the event occurs (may be NULL)
53 * If a notifier for device @dev and connector @conn_name already exists, then
54 * increase the refcount and return that notifier.
56 * If it doesn't exist, then allocate a new notifier struct and return a
57 * pointer to that new struct.
59 * Return NULL if the memory could not be allocated.
62 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
63 const struct cec_connector_info *conn_info);
66 * cec_notifier_conn_unregister - decrease refcount and delete when the
68 * @n: notifier. If NULL, then this function does nothing.
70 void cec_notifier_conn_unregister(struct cec_notifier *n);
73 * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
75 * @hdmi_dev: HDMI device that sends the events.
76 * @conn_name: the connector name from which the event occurs. May be NULL
77 * if there is always only one HDMI connector created by the HDMI device.
78 * @adap: the cec adapter that registered this notifier.
80 * If a notifier for device @dev and connector @conn_name already exists, then
81 * increase the refcount and return that notifier.
83 * If it doesn't exist, then allocate a new notifier struct and return a
84 * pointer to that new struct.
86 * Return NULL if the memory could not be allocated.
89 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
90 struct cec_adapter *adap);
93 * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
95 * @n: notifier. If NULL, then this function does nothing.
97 void cec_notifier_cec_adap_unregister(struct cec_notifier *n);
100 * cec_notifier_set_phys_addr - set a new physical address.
101 * @n: the CEC notifier
102 * @pa: the CEC physical address
104 * Set a new CEC physical address.
105 * Does nothing if @n == NULL.
107 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
110 * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
111 * @n: the CEC notifier
112 * @edid: the struct edid pointer
114 * Parses the EDID to obtain the new CEC physical address and set it.
115 * Does nothing if @n == NULL.
117 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
118 const struct edid *edid);
121 * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
122 * @dev: the device with the "hdmi-phandle" device tree property
124 * Returns the device pointer referenced by the "hdmi-phandle" property.
125 * Note that the refcount of the returned device is not incremented.
126 * This device pointer is only used as a key value in the notifier
127 * list, but it is never accessed by the CEC driver.
129 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
132 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
135 /* A non-NULL pointer is expected on success */
136 return (struct cec_notifier *)0xdeadfeed;
139 static inline void cec_notifier_put(struct cec_notifier *n)
143 static inline struct cec_notifier *
144 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
145 const struct cec_connector_info *conn_info)
147 /* A non-NULL pointer is expected on success */
148 return (struct cec_notifier *)0xdeadfeed;
151 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
155 static inline struct cec_notifier *
156 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
157 struct cec_adapter *adap)
159 /* A non-NULL pointer is expected on success */
160 return (struct cec_notifier *)0xdeadfeed;
163 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
167 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
171 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
172 const struct edid *edid)
176 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
178 return ERR_PTR(-ENODEV);
184 * cec_notifier_get - find or create a new cec_notifier for the given device.
185 * @dev: device that sends the events.
187 * If a notifier for device @dev already exists, then increase the refcount
188 * and return that notifier.
190 * If it doesn't exist, then allocate a new notifier struct and return a
191 * pointer to that new struct.
193 * Return NULL if the memory could not be allocated.
195 static inline struct cec_notifier *cec_notifier_get(struct device *dev)
197 return cec_notifier_get_conn(dev, NULL);
201 * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
203 * @n: the CEC notifier
205 * This is a simple helper function to invalidate the physical
206 * address. Does nothing if @n == NULL.
208 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
210 cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);