1ab15d248SHans Verkuil /* SPDX-License-Identifier: GPL-2.0-only */
26917a7b7SHans Verkuil /*
36917a7b7SHans Verkuil * cec-notifier.h - notify CEC drivers of physical address changes
46917a7b7SHans Verkuil *
5*4f39467eSRussell King * Copyright 2016 Russell King.
66917a7b7SHans Verkuil * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
76917a7b7SHans Verkuil */
86917a7b7SHans Verkuil
96917a7b7SHans Verkuil #ifndef LINUX_CEC_NOTIFIER_H
106917a7b7SHans Verkuil #define LINUX_CEC_NOTIFIER_H
116917a7b7SHans Verkuil
12fbbd403bSHans Verkuil #include <linux/err.h>
13ee7e9871SHans Verkuil #include <media/cec.h>
146917a7b7SHans Verkuil
156917a7b7SHans Verkuil struct device;
166917a7b7SHans Verkuil struct edid;
176917a7b7SHans Verkuil struct cec_adapter;
186917a7b7SHans Verkuil struct cec_notifier;
196917a7b7SHans Verkuil
20e94c3281SHans Verkuil #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
216917a7b7SHans Verkuil
226917a7b7SHans Verkuil /**
23b48cb35cSHans Verkuil * cec_notifier_conn_register - find or create a new cec_notifier for the given
24b48cb35cSHans Verkuil * HDMI device and connector tuple.
25b48cb35cSHans Verkuil * @hdmi_dev: HDMI device that sends the events.
2680f13a08SHans Verkuil * @port_name: the connector name from which the event occurs. May be NULL
27b48cb35cSHans Verkuil * if there is always only one HDMI connector created by the HDMI device.
28b48cb35cSHans Verkuil * @conn_info: the connector info from which the event occurs (may be NULL)
29b48cb35cSHans Verkuil *
3080f13a08SHans Verkuil * If a notifier for device @dev and connector @port_name already exists, then
31b48cb35cSHans Verkuil * increase the refcount and return that notifier.
32b48cb35cSHans Verkuil *
33b48cb35cSHans Verkuil * If it doesn't exist, then allocate a new notifier struct and return a
34b48cb35cSHans Verkuil * pointer to that new struct.
35b48cb35cSHans Verkuil *
36b48cb35cSHans Verkuil * Return NULL if the memory could not be allocated.
37b48cb35cSHans Verkuil */
38b48cb35cSHans Verkuil struct cec_notifier *
3980f13a08SHans Verkuil cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
40b48cb35cSHans Verkuil const struct cec_connector_info *conn_info);
41b48cb35cSHans Verkuil
42b48cb35cSHans Verkuil /**
43b48cb35cSHans Verkuil * cec_notifier_conn_unregister - decrease refcount and delete when the
44b48cb35cSHans Verkuil * refcount reaches 0.
45b48cb35cSHans Verkuil * @n: notifier. If NULL, then this function does nothing.
46b48cb35cSHans Verkuil */
47b48cb35cSHans Verkuil void cec_notifier_conn_unregister(struct cec_notifier *n);
48b48cb35cSHans Verkuil
49b48cb35cSHans Verkuil /**
50b48cb35cSHans Verkuil * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
51b48cb35cSHans Verkuil * given device.
52b48cb35cSHans Verkuil * @hdmi_dev: HDMI device that sends the events.
5380f13a08SHans Verkuil * @port_name: the connector name from which the event occurs. May be NULL
54b48cb35cSHans Verkuil * if there is always only one HDMI connector created by the HDMI device.
55b48cb35cSHans Verkuil * @adap: the cec adapter that registered this notifier.
56b48cb35cSHans Verkuil *
5780f13a08SHans Verkuil * If a notifier for device @dev and connector @port_name already exists, then
58b48cb35cSHans Verkuil * increase the refcount and return that notifier.
59b48cb35cSHans Verkuil *
60b48cb35cSHans Verkuil * If it doesn't exist, then allocate a new notifier struct and return a
61b48cb35cSHans Verkuil * pointer to that new struct.
62b48cb35cSHans Verkuil *
63b48cb35cSHans Verkuil * Return NULL if the memory could not be allocated.
64b48cb35cSHans Verkuil */
65b48cb35cSHans Verkuil struct cec_notifier *
6680f13a08SHans Verkuil cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
67b48cb35cSHans Verkuil struct cec_adapter *adap);
68b48cb35cSHans Verkuil
69b48cb35cSHans Verkuil /**
70b48cb35cSHans Verkuil * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
71b48cb35cSHans Verkuil * refcount reaches 0.
72b48cb35cSHans Verkuil * @n: notifier. If NULL, then this function does nothing.
7310d8f308SHans Verkuil * @adap: the cec adapter that registered this notifier.
74b48cb35cSHans Verkuil */
7510d8f308SHans Verkuil void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
7610d8f308SHans Verkuil struct cec_adapter *adap);
77b48cb35cSHans Verkuil
78b48cb35cSHans Verkuil /**
796917a7b7SHans Verkuil * cec_notifier_set_phys_addr - set a new physical address.
806917a7b7SHans Verkuil * @n: the CEC notifier
816917a7b7SHans Verkuil * @pa: the CEC physical address
826917a7b7SHans Verkuil *
836917a7b7SHans Verkuil * Set a new CEC physical address.
84fc1ff45aSHans Verkuil * Does nothing if @n == NULL.
856917a7b7SHans Verkuil */
866917a7b7SHans Verkuil void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
876917a7b7SHans Verkuil
886917a7b7SHans Verkuil /**
896917a7b7SHans Verkuil * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
906917a7b7SHans Verkuil * @n: the CEC notifier
916917a7b7SHans Verkuil * @edid: the struct edid pointer
926917a7b7SHans Verkuil *
936917a7b7SHans Verkuil * Parses the EDID to obtain the new CEC physical address and set it.
94fc1ff45aSHans Verkuil * Does nothing if @n == NULL.
956917a7b7SHans Verkuil */
966917a7b7SHans Verkuil void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
976917a7b7SHans Verkuil const struct edid *edid);
986917a7b7SHans Verkuil
996917a7b7SHans Verkuil /**
100fbbd403bSHans Verkuil * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
101fbbd403bSHans Verkuil * @dev: the device with the "hdmi-phandle" device tree property
102fbbd403bSHans Verkuil *
103fbbd403bSHans Verkuil * Returns the device pointer referenced by the "hdmi-phandle" property.
104fbbd403bSHans Verkuil * Note that the refcount of the returned device is not incremented.
105fbbd403bSHans Verkuil * This device pointer is only used as a key value in the notifier
106fbbd403bSHans Verkuil * list, but it is never accessed by the CEC driver.
107fbbd403bSHans Verkuil */
108fbbd403bSHans Verkuil struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
109fbbd403bSHans Verkuil
1106917a7b7SHans Verkuil #else
1116917a7b7SHans Verkuil
112b48cb35cSHans Verkuil static inline struct cec_notifier *
cec_notifier_conn_register(struct device * hdmi_dev,const char * port_name,const struct cec_connector_info * conn_info)11380f13a08SHans Verkuil cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
114b48cb35cSHans Verkuil const struct cec_connector_info *conn_info)
115b48cb35cSHans Verkuil {
116b48cb35cSHans Verkuil /* A non-NULL pointer is expected on success */
117b48cb35cSHans Verkuil return (struct cec_notifier *)0xdeadfeed;
118b48cb35cSHans Verkuil }
119b48cb35cSHans Verkuil
cec_notifier_conn_unregister(struct cec_notifier * n)120b48cb35cSHans Verkuil static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
121b48cb35cSHans Verkuil {
122b48cb35cSHans Verkuil }
123b48cb35cSHans Verkuil
124b48cb35cSHans Verkuil static inline struct cec_notifier *
cec_notifier_cec_adap_register(struct device * hdmi_dev,const char * port_name,struct cec_adapter * adap)12580f13a08SHans Verkuil cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
126b48cb35cSHans Verkuil struct cec_adapter *adap)
127b48cb35cSHans Verkuil {
128b48cb35cSHans Verkuil /* A non-NULL pointer is expected on success */
129b48cb35cSHans Verkuil return (struct cec_notifier *)0xdeadfeed;
130b48cb35cSHans Verkuil }
131b48cb35cSHans Verkuil
cec_notifier_cec_adap_unregister(struct cec_notifier * n,struct cec_adapter * adap)13210d8f308SHans Verkuil static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
13310d8f308SHans Verkuil struct cec_adapter *adap)
134b48cb35cSHans Verkuil {
135b48cb35cSHans Verkuil }
136b48cb35cSHans Verkuil
cec_notifier_set_phys_addr(struct cec_notifier * n,u16 pa)1376917a7b7SHans Verkuil static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
1386917a7b7SHans Verkuil {
1396917a7b7SHans Verkuil }
1406917a7b7SHans Verkuil
cec_notifier_set_phys_addr_from_edid(struct cec_notifier * n,const struct edid * edid)1416917a7b7SHans Verkuil static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
1426917a7b7SHans Verkuil const struct edid *edid)
1436917a7b7SHans Verkuil {
1446917a7b7SHans Verkuil }
1456917a7b7SHans Verkuil
cec_notifier_parse_hdmi_phandle(struct device * dev)146fbbd403bSHans Verkuil static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
147fbbd403bSHans Verkuil {
148fbbd403bSHans Verkuil return ERR_PTR(-ENODEV);
149fbbd403bSHans Verkuil }
150fbbd403bSHans Verkuil
1516917a7b7SHans Verkuil #endif
1526917a7b7SHans Verkuil
153fc1ff45aSHans Verkuil /**
154fc1ff45aSHans Verkuil * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
155fc1ff45aSHans Verkuil *
156fc1ff45aSHans Verkuil * @n: the CEC notifier
157fc1ff45aSHans Verkuil *
158fc1ff45aSHans Verkuil * This is a simple helper function to invalidate the physical
159fc1ff45aSHans Verkuil * address. Does nothing if @n == NULL.
160fc1ff45aSHans Verkuil */
cec_notifier_phys_addr_invalidate(struct cec_notifier * n)161fc1ff45aSHans Verkuil static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
162fc1ff45aSHans Verkuil {
163fc1ff45aSHans Verkuil cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
164fc1ff45aSHans Verkuil }
165fc1ff45aSHans Verkuil
1666917a7b7SHans Verkuil #endif
167