treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / include / media / cec-notifier.h
blob139e93be13b003906c9766478089a8564d780389
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
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.
7 */
9 #ifndef LINUX_CEC_NOTIFIER_H
10 #define LINUX_CEC_NOTIFIER_H
12 #include <linux/err.h>
13 #include <media/cec.h>
15 struct device;
16 struct edid;
17 struct cec_adapter;
18 struct cec_notifier;
20 #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
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
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,
37 const char *conn);
39 /**
40 * cec_notifier_conn_register - find or create a new cec_notifier for the given
41 * HDMI device and connector tuple.
42 * @hdmi_dev: HDMI device that sends the events.
43 * @conn_name: the connector name from which the event occurs. May be NULL
44 * if there is always only one HDMI connector created by the HDMI device.
45 * @conn_info: the connector info from which the event occurs (may be NULL)
47 * If a notifier for device @dev and connector @conn_name already exists, then
48 * increase the refcount and return that notifier.
50 * If it doesn't exist, then allocate a new notifier struct and return a
51 * pointer to that new struct.
53 * Return NULL if the memory could not be allocated.
55 struct cec_notifier *
56 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
57 const struct cec_connector_info *conn_info);
59 /**
60 * cec_notifier_conn_unregister - decrease refcount and delete when the
61 * refcount reaches 0.
62 * @n: notifier. If NULL, then this function does nothing.
64 void cec_notifier_conn_unregister(struct cec_notifier *n);
66 /**
67 * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
68 * given device.
69 * @hdmi_dev: HDMI device that sends the events.
70 * @conn_name: the connector name from which the event occurs. May be NULL
71 * if there is always only one HDMI connector created by the HDMI device.
72 * @adap: the cec adapter that registered this notifier.
74 * If a notifier for device @dev and connector @conn_name already exists, then
75 * increase the refcount and return that notifier.
77 * If it doesn't exist, then allocate a new notifier struct and return a
78 * pointer to that new struct.
80 * Return NULL if the memory could not be allocated.
82 struct cec_notifier *
83 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
84 struct cec_adapter *adap);
86 /**
87 * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
88 * refcount reaches 0.
89 * @n: notifier. If NULL, then this function does nothing.
90 * @adap: the cec adapter that registered this notifier.
92 void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
93 struct cec_adapter *adap);
95 /**
96 * cec_notifier_set_phys_addr - set a new physical address.
97 * @n: the CEC notifier
98 * @pa: the CEC physical address
100 * Set a new CEC physical address.
101 * Does nothing if @n == NULL.
103 void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
106 * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
107 * @n: the CEC notifier
108 * @edid: the struct edid pointer
110 * Parses the EDID to obtain the new CEC physical address and set it.
111 * Does nothing if @n == NULL.
113 void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
114 const struct edid *edid);
117 * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
118 * @dev: the device with the "hdmi-phandle" device tree property
120 * Returns the device pointer referenced by the "hdmi-phandle" property.
121 * Note that the refcount of the returned device is not incremented.
122 * This device pointer is only used as a key value in the notifier
123 * list, but it is never accessed by the CEC driver.
125 struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
127 #else
128 static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev,
129 const char *conn)
131 /* A non-NULL pointer is expected on success */
132 return (struct cec_notifier *)0xdeadfeed;
135 static inline struct cec_notifier *
136 cec_notifier_conn_register(struct device *hdmi_dev, const char *conn_name,
137 const struct cec_connector_info *conn_info)
139 /* A non-NULL pointer is expected on success */
140 return (struct cec_notifier *)0xdeadfeed;
143 static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
147 static inline struct cec_notifier *
148 cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *conn_name,
149 struct cec_adapter *adap)
151 /* A non-NULL pointer is expected on success */
152 return (struct cec_notifier *)0xdeadfeed;
155 static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
156 struct cec_adapter *adap)
160 static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
164 static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
165 const struct edid *edid)
169 static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
171 return ERR_PTR(-ENODEV);
174 #endif
177 * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
179 * @n: the CEC notifier
181 * This is a simple helper function to invalidate the physical
182 * address. Does nothing if @n == NULL.
184 static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
186 cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
189 #endif