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-edid.h>
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49struct cec_devnode {
50
51 struct device dev;
52 struct cdev cdev;
53
54
55 int minor;
56 bool registered;
57 bool unregistered;
58 struct list_head fhs;
59 struct mutex lock;
60};
61
62struct cec_adapter;
63struct cec_data;
64
65struct cec_data {
66 struct list_head list;
67 struct list_head xfer_list;
68 struct cec_adapter *adap;
69 struct cec_msg msg;
70 struct cec_fh *fh;
71 struct delayed_work work;
72 struct completion c;
73 u8 attempts;
74 bool new_initiator;
75 bool blocking;
76 bool completed;
77};
78
79struct cec_msg_entry {
80 struct list_head list;
81 struct cec_msg msg;
82};
83
84#define CEC_NUM_EVENTS CEC_EVENT_LOST_MSGS
85
86struct cec_fh {
87 struct list_head list;
88 struct list_head xfer_list;
89 struct cec_adapter *adap;
90 u8 mode_initiator;
91 u8 mode_follower;
92
93
94 wait_queue_head_t wait;
95 unsigned int pending_events;
96 struct cec_event events[CEC_NUM_EVENTS];
97 struct mutex lock;
98 struct list_head msgs;
99 unsigned int queued_msgs;
100};
101
102#define CEC_SIGNAL_FREE_TIME_RETRY 3
103#define CEC_SIGNAL_FREE_TIME_NEW_INITIATOR 5
104#define CEC_SIGNAL_FREE_TIME_NEXT_XFER 7
105
106
107#define CEC_FREE_TIME_TO_USEC(ft) ((ft) * 2400)
108
109struct cec_adap_ops {
110
111 int (*adap_enable)(struct cec_adapter *adap, bool enable);
112 int (*adap_monitor_all_enable)(struct cec_adapter *adap, bool enable);
113 int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr);
114 int (*adap_transmit)(struct cec_adapter *adap, u8 attempts,
115 u32 signal_free_time, struct cec_msg *msg);
116 void (*adap_status)(struct cec_adapter *adap, struct seq_file *file);
117
118
119 int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
120};
121
122
123
124
125
126
127
128
129
130
131
132#define CEC_MAX_MSG_RX_QUEUE_SZ (18 * 3)
133
134
135
136
137
138
139
140#define CEC_MAX_MSG_TX_QUEUE_SZ (18 * 1)
141
142struct cec_adapter {
143 struct module *owner;
144 char name[32];
145 struct cec_devnode devnode;
146 struct mutex lock;
147 struct rc_dev *rc;
148
149 struct list_head transmit_queue;
150 unsigned int transmit_queue_sz;
151 struct list_head wait_queue;
152 struct cec_data *transmitting;
153
154 struct task_struct *kthread_config;
155 struct completion config_completion;
156
157 struct task_struct *kthread;
158 wait_queue_head_t kthread_waitq;
159 wait_queue_head_t waitq;
160
161 const struct cec_adap_ops *ops;
162 void *priv;
163 u32 capabilities;
164 u8 available_log_addrs;
165
166 u16 phys_addr;
167 bool is_configuring;
168 bool is_configured;
169 u32 monitor_all_cnt;
170 u32 follower_cnt;
171 struct cec_fh *cec_follower;
172 struct cec_fh *cec_initiator;
173 bool passthrough;
174 struct cec_log_addrs log_addrs;
175
176 struct dentry *cec_dir;
177 struct dentry *status_file;
178
179 u16 phys_addrs[15];
180 u32 sequence;
181
182 char input_name[32];
183 char input_phys[32];
184 char input_drv[32];
185};
186
187static inline bool cec_has_log_addr(const struct cec_adapter *adap, u8 log_addr)
188{
189 return adap->log_addrs.log_addr_mask & (1 << log_addr);
190}
191
192static inline bool cec_is_sink(const struct cec_adapter *adap)
193{
194 return adap->phys_addr == 0;
195}
196
197#if IS_ENABLED(CONFIG_MEDIA_CEC_SUPPORT)
198struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
199 void *priv, const char *name, u32 caps, u8 available_las);
200int cec_register_adapter(struct cec_adapter *adap, struct device *parent);
201void cec_unregister_adapter(struct cec_adapter *adap);
202void cec_delete_adapter(struct cec_adapter *adap);
203
204int cec_s_log_addrs(struct cec_adapter *adap, struct cec_log_addrs *log_addrs,
205 bool block);
206void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
207 bool block);
208int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
209 bool block);
210
211
212void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt,
213 u8 nack_cnt, u8 low_drive_cnt, u8 error_cnt);
214void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg);
215
216#else
217
218static inline int cec_register_adapter(struct cec_adapter *adap,
219 struct device *parent)
220{
221 return 0;
222}
223
224static inline void cec_unregister_adapter(struct cec_adapter *adap)
225{
226}
227
228static inline void cec_delete_adapter(struct cec_adapter *adap)
229{
230}
231
232static inline void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr,
233 bool block)
234{
235}
236
237#endif
238
239#endif
240