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.
96 * @adap: the cec adapter that registered this notifier.
98 void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
99 struct cec_adapter *adap);
102 * cec_notifier_set_phys_addr - set a new physical address.
103 * @n: the CEC notifier
104 * @pa: the CEC physical address
106 * Set a new CEC physical address.
107 * Does nothing if @n == NULL.
109 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
112 * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
113 * @n: the CEC notifier
114 * @edid: the struct edid pointer
116 * Parses the EDID to obtain the new CEC physical address and set it.
117 * Does nothing if @n == NULL.
119 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
120 const struct edid *edid);
123 * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
124 * @dev: the device with the "hdmi-phandle" device tree property
126 * Returns the device pointer referenced by the "hdmi-phandle" property.
127 * Note that the refcount of the returned device is not incremented.
128 * This device pointer is only used as a key value in the notifier
129 * list, but it is never accessed by the CEC driver.
131 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
134 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
137 /* A non-NULL pointer is expected on success */
138 return (struct cec_notifier *)0xdeadfeed;
141 static inline void cec_notifier_put(struct cec_notifier *n)
145 static inline struct cec_notifier *
146 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
147 const struct cec_connector_info *conn_info)
149 /* A non-NULL pointer is expected on success */
150 return (struct cec_notifier *)0xdeadfeed;
153 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
157 static inline struct cec_notifier *
158 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
159 struct cec_adapter *adap)
161 /* A non-NULL pointer is expected on success */
162 return (struct cec_notifier *)0xdeadfeed;
165 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
166 struct cec_adapter *adap)
170 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
174 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
175 const struct edid *edid)
179 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
181 return ERR_PTR(-ENODEV);
187 * cec_notifier_get - find or create a new cec_notifier for the given device.
188 * @dev: device that sends the events.
190 * If a notifier for device @dev already exists, then increase the refcount
191 * and return that notifier.
193 * If it doesn't exist, then allocate a new notifier struct and return a
194 * pointer to that new struct.
196 * Return NULL if the memory could not be allocated.
198 static inline struct cec_notifier *cec_notifier_get(struct device *dev)
200 return cec_notifier_get_conn(dev, NULL);
204 * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
206 * @n: the CEC notifier
208 * This is a simple helper function to invalidate the physical
209 * address. Does nothing if @n == NULL.
211 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
213 cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);