1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _MEDIA_CEC_H
21#define _MEDIA_CEC_H
22
23#include <linux/poll.h>
24#include <linux/fs.h>
25#include <linux/debugfs.h>
26#include <linux/device.h>
27#include <linux/cdev.h>
28#include <linux/kthread.h>
29#include <linux/timer.h>
30#include <linux/cec-funcs.h>
31#include <media/rc-core.h>
32#include <media/cec-notifier.h>
33
34#define CEC_CAP_DEFAULTS (CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT | \
35 CEC_CAP_PASSTHROUGH | CEC_CAP_RC)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52struct cec_devnode {
53
54 struct device dev;
55 struct cdev cdev;
56
57
58 int minor;
59 bool registered;
60 bool unregistered;
61 struct list_head fhs;
62 struct mutex lock;
63};
64
65struct cec_adapter;
66struct cec_data;
67struct cec_pin;
68
69struct cec_data {
70 struct list_head list;
71 struct list_head xfer_list;
72 struct cec_adapter *adap;
73 struct cec_msg msg;
74 struct cec_fh *fh;
75 struct delayed_work work;
76 struct completion c;
77 u8 attempts;
78 bool new_initiator;
79 bool blocking;
80 bool completed;
81};
82
83struct cec_msg_entry {
84 struct list_head list;
85 struct cec_msg msg;
86};
87
88struct cec_event_entry {
89 struct list_head list;
90 struct cec_event ev;
91};
92
93#define CEC_NUM_CORE_EVENTS 2
94#define CEC_NUM_EVENTS CEC_EVENT_PIN_CEC_HIGH
95
96struct cec_fh {
97 struct list_head list;
98 struct list_head xfer_list;
99 struct cec_adapter *adap;
100 u8 mode_initiator;
101 u8 mode_follower;
102
103
104 wait_queue_head_t wait;
105 struct mutex lock;
106 struct list_head events[CEC_NUM_EVENTS];
107 u8 queued_events[CEC_NUM_EVENTS];
108 unsigned int total_queued_events;
109 struct cec_event_entry core_events[CEC_NUM_CORE_EVENTS];
110 struct list_head msgs;
111 unsigned int queued_msgs;
112};
113
114#define CEC_SIGNAL_FREE_TIME_RETRY 3
115#define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5
116#define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7
117
118
119#define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400)
120
121struct cec_adap_ops {
122
123 int (*adap_enable)(struct cec_adapter *adap, bool enable);
124 int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable);
125 int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr);
126 int (*adap_transmit)(struct cec_adapter *adap, u8 attempts,
127 u32 signal_free_time, struct cec_msg *msg);
128 void (*adap_status)(struct cec_adapter *adap, struct seq_file *file);
129 void (*adap_free)(struct cec_adapter *adap);
130
131
132 int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
133};
134
135
136
137
138
139
140
141
142
143
144
145#define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3)
146
147
148
149
150
151
152
153#define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1)
154
155struct cec_adapter {
156 struct module *owner;
157 char name[32];
158 struct cec_devnode devnode;
159 struct mutex lock;
160 struct rc_dev *rc;
161
162 struct list_head transmit_queue;
163 unsigned int transmit_queue_sz;
164 struct list_head wait_queue;
165 struct cec_data *transmitting;
166
167 struct task_struct *kthread_config;
168 struct completion config_completion;
169
170 struct task_struct *kthread;
171 wait_queue_head_t kthread_waitq;
172 wait_queue_head_t waitq;
173
174 const struct cec_adap_ops *ops;
175 void *priv;
176 u32 capabilities;
177 u8 available_log_addrs;
178
179 u16 phys_addr;
180 bool needs_hpd;
181 bool is_configuring;
182 bool is_configured;
183 bool cec_pin_is_high;
184 u32 monitor_all_cnt;
185 u32 monitor_pin_cnt;
186 u32 follower_cnt;
187 struct cec_fh *cec_follower;
188 struct cec_fh *cec_initiator;
189 bool passthrough;
190 struct cec_log_addrs log_addrs;
191
192 u32 tx_timeouts;
193
194#ifdef CONFIG_MEDIA_CEC_RC
195 bool rc_repeating;
196 int rc_last_scancode;
197 u64 rc_last_keypress;
198#endif
199#ifdef CONFIG_CEC_NOTIFIER
200 struct cec_notifier *notifier;
201#endif
202#ifdef CONFIG_CEC_PIN
203 struct cec_pin *pin;
204#endif
205
206 struct dentry *cec_dir;
207 struct dentry *status_file;
208
209 u16 phys_addrs[15];
210 u32 sequence;
211
212 char device_name[32];
213 char input_phys[32];
214 char input_drv[32];
215};
216
217static inline void *cec_get_drvdata(const struct cec_adapter *adap)
218{
219 return adap->priv;
220}
221
222static inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr)
223{
224 return adap->log_addrs.log_addr_mask & (1 << log_addr);
225}
226
227static inline bool cec_is_sink(const struct cec_adapter *adap)
228{
229 return adap->phys_addr == 0;
230}
231
232#define cec_phys_addr_exp(pa) \
233 ((pa) >> 12), ((pa) >> 8) & 0xf, ((pa) >> 4) & 0xf, (pa) & 0xf
234
235struct edid;
236
237#if IS_REACHABLE(CONFIG_CEC_CORE)
238struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
239 void *priv, const char *name, u32 caps, u8 available_las);
240int cec_register_adapter(struct cec_adapter *adap, struct device *parent);
241void cec_unregister_adapter(struct cec_adapter *adap);
242void cec_delete_adapter(struct cec_adapter *adap);
243
244int cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs,
245 bool block);
246void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
247 bool block);
248void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
249 const struct edid *edid);
250int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
251 bool block);
252
253
254void cec_transmit_done_ts(struct cec_adapter *adap, u8 status,
255 u8 arb_lost_cnt, u8 nack_cnt, u8 low_drive_cnt,
256 u8 error_cnt, ktime_t ts);
257
258static inline void cec_transmit_done(struct cec_adapter *adap, u8 status,
259 u8 arb_lost_cnt, u8 nack_cnt,
260 u8 low_drive_cnt, u8 error_cnt)
261{
262 cec_transmit_done_ts(adap, status, arb_lost_cnt, nack_cnt,
263 low_drive_cnt, error_cnt, ktime_get());
264}
265
266
267
268
269
270void cec_transmit_attempt_done_ts(struct cec_adapter *adap,
271 u8 status, ktime_t ts);
272
273static inline void cec_transmit_attempt_done(struct cec_adapter *adap,
274 u8 status)
275{
276 cec_transmit_attempt_done_ts(adap, status, ktime_get());
277}
278
279void cec_received_msg_ts(struct cec_adapter *adap,
280 struct cec_msg *msg, ktime_t ts);
281
282static inline void cec_received_msg(struct cec_adapter *adap,
283 struct cec_msg *msg)
284{
285 cec_received_msg_ts(adap, msg, ktime_get());
286}
287
288
289
290
291
292
293
294
295
296void cec_queue_pin_cec_event(struct cec_adapter *adap,
297 bool is_high, ktime_t ts);
298
299
300
301
302
303
304
305
306
307
308
309
310u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
311 unsigned int *offset);
312
313
314
315
316
317
318
319
320
321
322
323
324
325void cec_set_edid_phys_addr(u8 *edid, unsigned int size, u16 phys_addr);
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346u16 cec_phys_addr_for_input(u16 phys_addr, u8 input);
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372int cec_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port);
373
374#else
375
376static inline int cec_register_adapter(struct cec_adapter *adap,
377 struct device *parent)
378{
379 return 0;
380}
381
382static inline void cec_unregister_adapter(struct cec_adapter *adap)
383{
384}
385
386static inline void cec_delete_adapter(struct cec_adapter *adap)
387{
388}
389
390static inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
391 bool block)
392{
393}
394
395static inline void cec_s_phys_addr_from_edid(struct cec_adapter *adap,
396 const struct edid *edid)
397{
398}
399
400static inline u16 cec_get_edid_phys_addr(const u8 *edid, unsigned int size,
401 unsigned int *offset)
402{
403 if (offset)
404 *offset = 0;
405 return CEC_PHYS_ADDR_INVALID;
406}
407
408static inline void cec_set_edid_phys_addr(u8 *edid, unsigned int size,
409 u16 phys_addr)
410{
411}
412
413static inline u16 cec_phys_addr_for_input(u16 phys_addr, u8 input)
414{
415 return CEC_PHYS_ADDR_INVALID;
416}
417
418static inline int cec_phys_addr_validate(u16 phys_addr, u16 *parent, u16 *port)
419{
420 return 0;
421}
422
423#endif
424
425
426
427
428
429
430
431
432
433static inline void cec_phys_addr_invalidate(struct cec_adapter *adap)
434{
435 cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false);
436}
437
438#endif
439