xref: /openbmc/linux/include/media/cec-notifier.h (revision cbdf59ad)
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 
9 #ifndef LINUX_CEC_NOTIFIER_H
10 #define LINUX_CEC_NOTIFIER_H
11 
12 #include <linux/err.h>
13 #include <media/cec.h>
14 
15 struct device;
16 struct edid;
17 struct cec_adapter;
18 struct cec_notifier;
19 
20 #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
21 
22 /**
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
27  *
28  * If a notifier for device @dev already exists, then increase the refcount
29  * and return that notifier.
30  *
31  * If it doesn't exist, then allocate a new notifier struct and return a
32  * pointer to that new struct.
33  *
34  * Return NULL if the memory could not be allocated.
35  */
36 struct cec_notifier *cec_notifier_get_conn(struct device *dev,
37 					   const char *conn);
38 
39 /**
40  * cec_notifier_put - decrease refcount and delete when the refcount reaches 0.
41  * @n: notifier
42  */
43 void cec_notifier_put(struct cec_notifier *n);
44 
45 /**
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)
52  *
53  * If a notifier for device @dev and connector @conn_name already exists, then
54  * increase the refcount and return that notifier.
55  *
56  * If it doesn't exist, then allocate a new notifier struct and return a
57  * pointer to that new struct.
58  *
59  * Return NULL if the memory could not be allocated.
60  */
61 struct cec_notifier *
62 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
63 			   const struct cec_connector_info *conn_info);
64 
65 /**
66  * cec_notifier_conn_unregister - decrease refcount and delete when the
67  * refcount reaches 0.
68  * @n: notifier. If NULL, then this function does nothing.
69  */
70 void cec_notifier_conn_unregister(struct cec_notifier *n);
71 
72 /**
73  * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
74  * given device.
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.
79  *
80  * If a notifier for device @dev and connector @conn_name already exists, then
81  * increase the refcount and return that notifier.
82  *
83  * If it doesn't exist, then allocate a new notifier struct and return a
84  * pointer to that new struct.
85  *
86  * Return NULL if the memory could not be allocated.
87  */
88 struct cec_notifier *
89 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
90 			       struct cec_adapter *adap);
91 
92 /**
93  * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
94  * refcount reaches 0.
95  * @n: notifier. If NULL, then this function does nothing.
96  */
97 void cec_notifier_cec_adap_unregister(struct cec_notifier *n);
98 
99 /**
100  * cec_notifier_set_phys_addr - set a new physical address.
101  * @n: the CEC notifier
102  * @pa: the CEC physical address
103  *
104  * Set a new CEC physical address.
105  * Does nothing if @n == NULL.
106  */
107 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
108 
109 /**
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
113  *
114  * Parses the EDID to obtain the new CEC physical address and set it.
115  * Does nothing if @n == NULL.
116  */
117 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
118 					  const struct edid *edid);
119 
120 /**
121  * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
122  * @dev: the device with the "hdmi-phandle" device tree property
123  *
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.
128  */
129 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
130 
131 #else
132 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
133 							 const char *conn)
134 {
135 	/* A non-NULL pointer is expected on success */
136 	return (struct cec_notifier *)0xdeadfeed;
137 }
138 
139 static inline void cec_notifier_put(struct cec_notifier *n)
140 {
141 }
142 
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)
146 {
147 	/* A non-NULL pointer is expected on success */
148 	return (struct cec_notifier *)0xdeadfeed;
149 }
150 
151 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
152 {
153 }
154 
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)
158 {
159 	/* A non-NULL pointer is expected on success */
160 	return (struct cec_notifier *)0xdeadfeed;
161 }
162 
163 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n)
164 {
165 }
166 
167 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
168 {
169 }
170 
171 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
172 							const struct edid *edid)
173 {
174 }
175 
176 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
177 {
178 	return ERR_PTR(-ENODEV);
179 }
180 
181 #endif
182 
183 /**
184  * cec_notifier_get - find or create a new cec_notifier for the given device.
185  * @dev: device that sends the events.
186  *
187  * If a notifier for device @dev already exists, then increase the refcount
188  * and return that notifier.
189  *
190  * If it doesn't exist, then allocate a new notifier struct and return a
191  * pointer to that new struct.
192  *
193  * Return NULL if the memory could not be allocated.
194  */
195 static inline struct cec_notifier *cec_notifier_get(struct device *dev)
196 {
197 	return cec_notifier_get_conn(dev, NULL);
198 }
199 
200 /**
201  * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
202  *
203  * @n: the CEC notifier
204  *
205  * This is a simple helper function to invalidate the physical
206  * address. Does nothing if @n == NULL.
207  */
208 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
209 {
210 	cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
211 }
212 
213 #endif
214