xref: /OK3568_Linux_fs/kernel/include/media/cec-notifier.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * cec-notifier.h - notify CEC drivers of physical address changes
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2016 Russell King.
6*4882a593Smuzhiyun  * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef LINUX_CEC_NOTIFIER_H
10*4882a593Smuzhiyun #define LINUX_CEC_NOTIFIER_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/err.h>
13*4882a593Smuzhiyun #include <media/cec.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct device;
16*4882a593Smuzhiyun struct edid;
17*4882a593Smuzhiyun struct cec_adapter;
18*4882a593Smuzhiyun struct cec_notifier;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER)
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /**
23*4882a593Smuzhiyun  * cec_notifier_conn_register - find or create a new cec_notifier for the given
24*4882a593Smuzhiyun  * HDMI device and connector tuple.
25*4882a593Smuzhiyun  * @hdmi_dev: HDMI device that sends the events.
26*4882a593Smuzhiyun  * @port_name: the connector name from which the event occurs. May be NULL
27*4882a593Smuzhiyun  * if there is always only one HDMI connector created by the HDMI device.
28*4882a593Smuzhiyun  * @conn_info: the connector info from which the event occurs (may be NULL)
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * If a notifier for device @dev and connector @port_name already exists, then
31*4882a593Smuzhiyun  * increase the refcount and return that notifier.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * If it doesn't exist, then allocate a new notifier struct and return a
34*4882a593Smuzhiyun  * pointer to that new struct.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * Return NULL if the memory could not be allocated.
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun struct cec_notifier *
39*4882a593Smuzhiyun cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
40*4882a593Smuzhiyun 			   const struct cec_connector_info *conn_info);
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /**
43*4882a593Smuzhiyun  * cec_notifier_conn_unregister - decrease refcount and delete when the
44*4882a593Smuzhiyun  * refcount reaches 0.
45*4882a593Smuzhiyun  * @n: notifier. If NULL, then this function does nothing.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun void cec_notifier_conn_unregister(struct cec_notifier *n);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /**
50*4882a593Smuzhiyun  * cec_notifier_cec_adap_register - find or create a new cec_notifier for the
51*4882a593Smuzhiyun  * given device.
52*4882a593Smuzhiyun  * @hdmi_dev: HDMI device that sends the events.
53*4882a593Smuzhiyun  * @port_name: the connector name from which the event occurs. May be NULL
54*4882a593Smuzhiyun  * if there is always only one HDMI connector created by the HDMI device.
55*4882a593Smuzhiyun  * @adap: the cec adapter that registered this notifier.
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  * If a notifier for device @dev and connector @port_name already exists, then
58*4882a593Smuzhiyun  * increase the refcount and return that notifier.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * If it doesn't exist, then allocate a new notifier struct and return a
61*4882a593Smuzhiyun  * pointer to that new struct.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * Return NULL if the memory could not be allocated.
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun struct cec_notifier *
66*4882a593Smuzhiyun cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
67*4882a593Smuzhiyun 			       struct cec_adapter *adap);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun /**
70*4882a593Smuzhiyun  * cec_notifier_cec_adap_unregister - decrease refcount and delete when the
71*4882a593Smuzhiyun  * refcount reaches 0.
72*4882a593Smuzhiyun  * @n: notifier. If NULL, then this function does nothing.
73*4882a593Smuzhiyun  * @adap: the cec adapter that registered this notifier.
74*4882a593Smuzhiyun  */
75*4882a593Smuzhiyun void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
76*4882a593Smuzhiyun 				      struct cec_adapter *adap);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun  * cec_notifier_set_phys_addr - set a new physical address.
80*4882a593Smuzhiyun  * @n: the CEC notifier
81*4882a593Smuzhiyun  * @pa: the CEC physical address
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * Set a new CEC physical address.
84*4882a593Smuzhiyun  * Does nothing if @n == NULL.
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /**
89*4882a593Smuzhiyun  * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID.
90*4882a593Smuzhiyun  * @n: the CEC notifier
91*4882a593Smuzhiyun  * @edid: the struct edid pointer
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * Parses the EDID to obtain the new CEC physical address and set it.
94*4882a593Smuzhiyun  * Does nothing if @n == NULL.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
97*4882a593Smuzhiyun 					  const struct edid *edid);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /**
100*4882a593Smuzhiyun  * cec_notifier_parse_hdmi_phandle - find the hdmi device from "hdmi-phandle"
101*4882a593Smuzhiyun  * @dev: the device with the "hdmi-phandle" device tree property
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * Returns the device pointer referenced by the "hdmi-phandle" property.
104*4882a593Smuzhiyun  * Note that the refcount of the returned device is not incremented.
105*4882a593Smuzhiyun  * This device pointer is only used as a key value in the notifier
106*4882a593Smuzhiyun  * list, but it is never accessed by the CEC driver.
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun struct device *cec_notifier_parse_hdmi_phandle(struct device *dev);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #else
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun static inline struct cec_notifier *
cec_notifier_conn_register(struct device * hdmi_dev,const char * port_name,const struct cec_connector_info * conn_info)113*4882a593Smuzhiyun cec_notifier_conn_register(struct device *hdmi_dev, const char *port_name,
114*4882a593Smuzhiyun 			   const struct cec_connector_info *conn_info)
115*4882a593Smuzhiyun {
116*4882a593Smuzhiyun 	/* A non-NULL pointer is expected on success */
117*4882a593Smuzhiyun 	return (struct cec_notifier *)0xdeadfeed;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
cec_notifier_conn_unregister(struct cec_notifier * n)120*4882a593Smuzhiyun static inline void cec_notifier_conn_unregister(struct cec_notifier *n)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun static inline struct cec_notifier *
cec_notifier_cec_adap_register(struct device * hdmi_dev,const char * port_name,struct cec_adapter * adap)125*4882a593Smuzhiyun cec_notifier_cec_adap_register(struct device *hdmi_dev, const char *port_name,
126*4882a593Smuzhiyun 			       struct cec_adapter *adap)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun 	/* A non-NULL pointer is expected on success */
129*4882a593Smuzhiyun 	return (struct cec_notifier *)0xdeadfeed;
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun 
cec_notifier_cec_adap_unregister(struct cec_notifier * n,struct cec_adapter * adap)132*4882a593Smuzhiyun static inline void cec_notifier_cec_adap_unregister(struct cec_notifier *n,
133*4882a593Smuzhiyun 						    struct cec_adapter *adap)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun 
cec_notifier_set_phys_addr(struct cec_notifier * n,u16 pa)137*4882a593Smuzhiyun static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
cec_notifier_set_phys_addr_from_edid(struct cec_notifier * n,const struct edid * edid)141*4882a593Smuzhiyun static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n,
142*4882a593Smuzhiyun 							const struct edid *edid)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
cec_notifier_parse_hdmi_phandle(struct device * dev)146*4882a593Smuzhiyun static inline struct device *cec_notifier_parse_hdmi_phandle(struct device *dev)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun 	return ERR_PTR(-ENODEV);
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun #endif
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /**
154*4882a593Smuzhiyun  * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID
155*4882a593Smuzhiyun  *
156*4882a593Smuzhiyun  * @n: the CEC notifier
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * This is a simple helper function to invalidate the physical
159*4882a593Smuzhiyun  * address. Does nothing if @n == NULL.
160*4882a593Smuzhiyun  */
cec_notifier_phys_addr_invalidate(struct cec_notifier * n)161*4882a593Smuzhiyun static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun 	cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID);
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun #endif
167