]>
Commit | Line | Data |
---|---|---|
ab15d248 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
6917a7b7 HV |
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. | |
6917a7b7 HV |
7 | */ |
8 | ||
9 | #ifndef LINUX_CEC_NOTIFIER_H | |
10 | #define LINUX_CEC_NOTIFIER_H | |
11 | ||
12 | #include <linux/types.h> | |
ee7e9871 | 13 | #include <media/cec.h> |
6917a7b7 HV |
14 | |
15 | struct device; | |
16 | struct edid; | |
17 | struct cec_adapter; | |
18 | struct cec_notifier; | |
19 | ||
e94c3281 | 20 | #if IS_REACHABLE(CONFIG_CEC_CORE) && IS_ENABLED(CONFIG_CEC_NOTIFIER) |
6917a7b7 HV |
21 | |
22 | /** | |
7a78c1e1 NA |
23 | * cec_notifier_get_conn - find or create a new cec_notifier for the given |
24 | * device and connector tuple. | |
6917a7b7 | 25 | * @dev: device that sends the events. |
7a78c1e1 | 26 | * @conn: the connector name from which the event occurs |
6917a7b7 HV |
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 | */ | |
7a78c1e1 NA |
36 | struct cec_notifier *cec_notifier_get_conn(struct device *dev, |
37 | const char *conn); | |
6917a7b7 HV |
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_set_phys_addr - set a new physical address. | |
47 | * @n: the CEC notifier | |
48 | * @pa: the CEC physical address | |
49 | * | |
50 | * Set a new CEC physical address. | |
fc1ff45a | 51 | * Does nothing if @n == NULL. |
6917a7b7 HV |
52 | */ |
53 | void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa); | |
54 | ||
55 | /** | |
56 | * cec_notifier_set_phys_addr_from_edid - set parse the PA from the EDID. | |
57 | * @n: the CEC notifier | |
58 | * @edid: the struct edid pointer | |
59 | * | |
60 | * Parses the EDID to obtain the new CEC physical address and set it. | |
fc1ff45a | 61 | * Does nothing if @n == NULL. |
6917a7b7 HV |
62 | */ |
63 | void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, | |
64 | const struct edid *edid); | |
65 | ||
66 | /** | |
67 | * cec_notifier_register - register a callback with the notifier | |
68 | * @n: the CEC notifier | |
69 | * @adap: the CEC adapter, passed as argument to the callback function | |
70 | * @callback: the callback function | |
71 | */ | |
72 | void cec_notifier_register(struct cec_notifier *n, | |
73 | struct cec_adapter *adap, | |
74 | void (*callback)(struct cec_adapter *adap, u16 pa)); | |
75 | ||
76 | /** | |
77 | * cec_notifier_unregister - unregister the callback from the notifier. | |
78 | * @n: the CEC notifier | |
79 | */ | |
80 | void cec_notifier_unregister(struct cec_notifier *n); | |
81 | ||
51504185 HV |
82 | /** |
83 | * cec_register_cec_notifier - register the notifier with the cec adapter. | |
84 | * @adap: the CEC adapter | |
85 | * @notifier: the CEC notifier | |
86 | */ | |
87 | void cec_register_cec_notifier(struct cec_adapter *adap, | |
88 | struct cec_notifier *notifier); | |
89 | ||
6917a7b7 | 90 | #else |
7a78c1e1 NA |
91 | static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, |
92 | const char *conn) | |
6917a7b7 HV |
93 | { |
94 | /* A non-NULL pointer is expected on success */ | |
95 | return (struct cec_notifier *)0xdeadfeed; | |
96 | } | |
97 | ||
98 | static inline void cec_notifier_put(struct cec_notifier *n) | |
99 | { | |
100 | } | |
101 | ||
102 | static inline void cec_notifier_set_phys_addr(struct cec_notifier *n, u16 pa) | |
103 | { | |
104 | } | |
105 | ||
106 | static inline void cec_notifier_set_phys_addr_from_edid(struct cec_notifier *n, | |
107 | const struct edid *edid) | |
108 | { | |
109 | } | |
110 | ||
79eddc99 AB |
111 | static inline void cec_notifier_register(struct cec_notifier *n, |
112 | struct cec_adapter *adap, | |
113 | void (*callback)(struct cec_adapter *adap, u16 pa)) | |
114 | { | |
115 | } | |
116 | ||
117 | static inline void cec_notifier_unregister(struct cec_notifier *n) | |
118 | { | |
119 | } | |
120 | ||
51504185 HV |
121 | static inline void cec_register_cec_notifier(struct cec_adapter *adap, |
122 | struct cec_notifier *notifier) | |
123 | { | |
124 | } | |
6917a7b7 HV |
125 | #endif |
126 | ||
7a78c1e1 NA |
127 | /** |
128 | * cec_notifier_get - find or create a new cec_notifier for the given device. | |
129 | * @dev: device that sends the events. | |
130 | * | |
131 | * If a notifier for device @dev already exists, then increase the refcount | |
132 | * and return that notifier. | |
133 | * | |
134 | * If it doesn't exist, then allocate a new notifier struct and return a | |
135 | * pointer to that new struct. | |
136 | * | |
137 | * Return NULL if the memory could not be allocated. | |
138 | */ | |
139 | static inline struct cec_notifier *cec_notifier_get(struct device *dev) | |
140 | { | |
141 | return cec_notifier_get_conn(dev, NULL); | |
142 | } | |
143 | ||
fc1ff45a HV |
144 | /** |
145 | * cec_notifier_phys_addr_invalidate() - set the physical address to INVALID | |
146 | * | |
147 | * @n: the CEC notifier | |
148 | * | |
149 | * This is a simple helper function to invalidate the physical | |
150 | * address. Does nothing if @n == NULL. | |
151 | */ | |
152 | static inline void cec_notifier_phys_addr_invalidate(struct cec_notifier *n) | |
153 | { | |
154 | cec_notifier_set_phys_addr(n, CEC_PHYS_ADDR_INVALID); | |
155 | } | |
156 | ||
6917a7b7 | 157 | #endif |