Merge tag 'sound-5.5-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-microblaze.git] / include / media / cec-notifier.h
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  * @adap: the cec adapter that registered this notifier.
97  */
98 void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
99                                       struct cec_adapter *adap);
100
101 /**
102  * cec_notifier_set_phys_addr - set a new physical address.
103  * @n: the CEC notifier
104  * @pa: the CEC physical address
105  *
106  * Set a new CEC physical address.
107  * Does nothing if @n == NULL.
108  */
109 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
110
111 /**
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
115  *
116  * Parses the EDID to obtain the new CEC physical address and set it.
117  * Does nothing if @n == NULL.
118  */
119 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
120                                           const struct edid *edid);
121
122 /**
123  * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
124  * @dev: the device with the "hdmi-phandle" device tree property
125  *
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.
130  */
131 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
132
133 #else
134 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
135                                                          const char *conn)
136 {
137         /* A non-NULL pointer is expected on success */
138         return (struct cec_notifier *)0xdeadfeed;
139 }
140
141 static inline void cec_notifier_put(struct cec_notifier *n)
142 {
143 }
144
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)
148 {
149         /* A non-NULL pointer is expected on success */
150         return (struct cec_notifier *)0xdeadfeed;
151 }
152
153 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
154 {
155 }
156
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)
160 {
161         /* A non-NULL pointer is expected on success */
162         return (struct cec_notifier *)0xdeadfeed;
163 }
164
165 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
166                                                     struct cec_adapter *adap)
167 {
168 }
169
170 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
171 {
172 }
173
174 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
175                                                         const struct edid *edid)
176 {
177 }
178
179 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
180 {
181         return ERR_PTR(-ENODEV);
182 }
183
184 #endif
185
186 /**
187  * cec_notifier_get - find or create a new cec_notifier for the given device.
188  * @dev: device that sends the events.
189  *
190  * If a notifier for device @dev already exists, then increase the refcount
191  * and return that notifier.
192  *
193  * If it doesn't exist, then allocate a new notifier struct and return a
194  * pointer to that new struct.
195  *
196  * Return NULL if the memory could not be allocated.
197  */
198 static inline struct cec_notifier *cec_notifier_get(struct device *dev)
199 {
200         return cec_notifier_get_conn(dev, NULL);
201 }
202
203 /**
204  * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
205  *
206  * @n: the CEC notifier
207  *
208  * This is a simple helper function to invalidate the physical
209  * address. Does nothing if @n == NULL.
210  */
211 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
212 {
213         cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
214 }
215
216 #endif