import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / hdmi / Sii8348 / mhl_linux_tx.h
1 /*
2
3 SiI8348 Linux Driver
4
5 Copyright (C) 2013 Silicon Image, Inc.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation version 2.
10 This program is distributed AS-IS WITHOUT ANY WARRANTY of any
11 kind, whether express or implied; INCLUDING without the implied warranty
12 of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE or NON-INFRINGEMENT. See
13 the GNU General Public License for more details at http://www.gnu.org/licenses/gpl-2.0.html.
14
15 */
16
17 #if !defined(MHL_LINUX_TX_H)
18 #define MHL_LINUX_TX_H
19
20 #include "sii_hal.h"
21 /*
22 * Event codes
23 *
24 */
25 /* No event worth reporting */
26 #define MHL_TX_EVENT_NONE 0x00
27
28 /* MHL connection has been lost */
29 #define MHL_TX_EVENT_DISCONNECTION 0x01
30
31 /* MHL connection has been established */
32 #define MHL_TX_EVENT_CONNECTION 0x02
33
34 /* Received an RCP key code */
35 #define MHL_TX_EVENT_RCP_RECEIVED 0x04
36
37 /* Received an RCPK message */
38 #define MHL_TX_EVENT_RCPK_RECEIVED 0x05
39
40 /* Received an RCPE message */
41 #define MHL_TX_EVENT_RCPE_RECEIVED 0x06
42
43 /* Received an UTF-8 key code */
44 #define MHL_TX_EVENT_UCP_RECEIVED 0x07
45
46 /* Received an UCPK message */
47 #define MHL_TX_EVENT_UCPK_RECEIVED 0x08
48
49 /* Received an UCPE message */
50 #define MHL_TX_EVENT_UCPE_RECEIVED 0x09
51
52 /* Scratch Pad Data received */
53 #define MHL_TX_EVENT_SPAD_RECEIVED 0x0A
54
55 /* Peer's power capability has changed */
56 #define MHL_TX_EVENT_POW_BIT_CHG 0x0B
57
58 /* Received a Request Action Protocol (RAP) message */
59 #define MHL_TX_EVENT_RAP_RECEIVED 0x0C
60
61 //we li
62 #define MHL_TX_EVENT_SMB_DATA 0x40
63 #define MHL_TX_EVENT_HPD_CLEAR 0x41
64 #define MHL_TX_EVENT_HPD_GOT 0x42
65 #define MHL_TX_EVENT_DEV_CAP_UPDATE 0x43
66 #define MHL_TX_EVENT_EDID_UPDATE 0x44
67 #define MHL_TX_EVENT_EDID_DONE 0x45
68
69 #define ADOPTER_ID_SIZE 2
70 #define MAX_SCRATCH_PAD_TRANSFER_SIZE 16
71 #define SCRATCH_PAD_SIZE 64
72
73 #define SCRATCHPAD_SIZE 16
74 typedef union {
75 MHL2_video_format_data_t videoFormatData;
76 uint8_t asBytes[SCRATCHPAD_SIZE];
77 } scratch_pad_u;
78
79
80 struct timer_obj {
81 struct list_head list_link;
82 struct work_struct work_item;
83 struct hrtimer hr_timer;
84 struct mhl_dev_context *dev_context;
85 uint8_t flags;
86 #define TIMER_OBJ_FLAG_WORK_IP 0x01
87 #define TIMER_OBJ_FLAG_DEL_REQ 0x02
88 void *callback_param;
89 void (*timer_callback_handler)(void *callback_param);
90 };
91
92 /* Convert a value specified in milliseconds to nanoseconds */
93 #define MSEC_TO_NSEC(x) (x * 1000000UL)
94
95 union misc_flags_u {
96 struct {
97 unsigned scratchpad_busy :1;
98 unsigned req_wrt_pending :1;
99 unsigned write_burst_pending :1;
100 unsigned rcp_ready :1;
101
102 unsigned have_complete_devcap :1;
103 unsigned sent_dcap_rdy :1;
104 unsigned sent_path_en :1;
105 unsigned rap_content_on :1;
106
107 unsigned mhl_hpd :1;
108 unsigned mhl_rsen :1;
109 unsigned edid_loop_active :1;
110 unsigned cbus_abort_delay_active :1;
111
112 unsigned reserved :20;
113 } flags;
114 uint32_t as_uint32;
115 };
116
117 /*
118 * structure used by interrupt handler to return
119 * information about an interrupt.
120 */
121 struct interrupt_info {
122 uint16_t flags;
123 /* Flags returned by low level driver interrupt handler */
124 #define DRV_INTR_FLAG_MSC_DONE 0x0001 /* message send done */
125 #define DRV_INTR_FLAG_MSC_RECVD 0x0002 /* MSC message received */
126 #define DRV_INTR_FLAG_MSC_NAK 0x0004 /* message send unsuccessful */
127 #define DRV_INTR_FLAG_WRITE_STAT 0x0008 /* write stat msg received */
128 #define DRV_INTR_FLAG_SET_INT 0x0010 /* set int message received */
129 #define DRV_INTR_FLAG_WRITE_BURST 0x0020 /* write burst received */
130 #define DRV_INTR_FLAG_HPD_CHANGE 0x0040 /* Hot plug detect has changed */
131 #define DRV_INTR_FLAG_CONNECT 0x0080 /* MHL connection established */
132 #define DRV_INTR_FLAG_DISCONNECT 0x0100 /* MHL connection lost */
133 #define DRV_INTR_FLAG_CBUS_ABORT 0x0200 /* A CBUS message transfer was
134 aborted */
135
136 void *edid_parser_context;
137 uint8_t msc_done_data;
138 uint8_t hpd_status; /* status of hot plug detect */
139 uint8_t write_stat[2]; /* received write stat data */
140 uint8_t msc_msg[2]; /* received msc message data */
141 uint8_t int_msg[2]; /* received SET INT message data */
142 };
143
144 #define NUM_CBUS_EVENT_QUEUE_EVENTS 50
145
146 #define MHL_DEV_CONTEXT_SIGNATURE ( ('M' << 24) | ('H' << 16) | ('L' << 8) | ' ')
147
148 struct mhl_dev_context {
149 uint32_t signature; /* identifies an instance of
150 this struct */
151 struct mhl_drv_info const *drv_info;
152 struct i2c_client *client;
153 struct cdev mhl_cdev;
154 struct device *mhl_dev;
155 struct interrupt_info intr_info;
156 void *edid_parser_context;
157 bool edid_parse_done; // TODO: FD, TBU, just parse done, not parse successfully
158 u8 dev_flags;
159 #define DEV_FLAG_SHUTDOWN 0x01 /* Device is shutting down */
160 #define DEV_FLAG_COMM_MODE 0x02 /* user wants to peek/poke at registers */
161
162 u16 mhl_flags; /* various state flags */
163 #define MHL_STATE_FLAG_CONNECTED 0x0001 /* MHL connection
164 established */
165 #ifndef RCP_INPUTDEV_SUPPORT
166 #define MHL_STATE_FLAG_RCP_SENT 0x0002 /* last RCP event was a key
167 send */
168 #define MHL_STATE_FLAG_RCP_RECEIVED 0x0004 /* last RCP event was a key
169 code receive */
170 #define MHL_STATE_FLAG_RCP_ACK 0x0008 /* last RCP key code sent was
171 ACK'd */
172 #define MHL_STATE_FLAG_RCP_NAK 0x0010 /* last RCP key code sent was
173 NAK'd */
174 #endif
175 #define MHL_STATE_FLAG_UCP_SENT 0x0020 /* last UCP event was a key
176 send */
177 #define MHL_STATE_FLAG_UCP_RECEIVED 0x0040 /* last UCP event was a key
178 code receive */
179 #define MHL_STATE_FLAG_UCP_ACK 0x0080 /* last UCP key code sent was
180 ACK'd */
181 #define MHL_STATE_FLAG_UCP_NAK 0x0100 /* last UCP key code sent was
182 NAK'd */
183 #define MHL_STATE_FLAG_SPAD_SENT 0x0200 /* scratch pad send in
184 process */
185 #define MHL_STATE_APPLICATION_RAP_BUSY 0x0400 /* application has indicated
186 that it is processing an
187 outstanding request */
188
189 u8 dev_cap_offset;
190 u8 rap_sub_command;
191 u8 rcp_key_code;
192 u8 rcp_err_code;
193 u8 rcp_send_status;
194 u8 ucp_key_code;
195 u8 ucp_err_code;
196 u8 ucp_send_status;
197 u8 pending_event; /* event data wait for retrieval */
198 u8 pending_event_data; /* by user mode application */
199 u8 spad_offset;
200 u8 spad_xfer_length;
201 u8 spad_send_status;
202 u8 debug_i2c_address;
203 u8 debug_i2c_offset;
204 u8 debug_i2c_xfer_length;
205
206 #ifdef MEDIA_DATA_TUNNEL_SUPPORT
207 struct mdt_inputdevs mdt_devs;
208 #endif
209
210 #ifdef RCP_INPUTDEV_SUPPORT
211 u8 error_key;
212 struct input_dev *rcp_input_dev;
213 #endif
214 struct semaphore isr_lock; /* semaphore used to prevent driver access
215 from user mode from colliding with the
216 threaded interrupt handler */
217
218 u8 status_0; /* Received status from peer saved here */
219 u8 status_1;
220 bool msc_msg_arrived;
221 u8 msc_msg_sub_command;
222 u8 msc_msg_data;
223
224 u8 msc_msg_last_data;
225 u8 msc_save_rcp_key_code;
226 u8 msc_save_ucp_key_code;
227
228 u8 link_mode; /* local MHL LINK_MODE register value */
229 bool mhl_connection_event;
230 u8 mhl_connected;
231 struct workqueue_struct *timer_work_queue;
232 struct list_head timer_list;
233 struct list_head cbus_queue;
234 struct list_head cbus_free_list;
235 struct cbus_req cbus_req_entries[NUM_CBUS_EVENT_QUEUE_EVENTS];
236 struct cbus_req *current_cbus_req;
237 void *cbus_abort_timer;
238 void *cbus_dpi_timer;
239 MHLDevCap_u dev_cap_cache;
240 MHLDevCap_u dev_cap_cache_new;
241 u8 dev_cap_cache_index;
242 u8 preferred_clk_mode;
243 bool scratch_pad_read_done;
244 scratch_pad_u incoming_scratch_pad;
245 scratch_pad_u outgoing_scratch_pad;
246
247 union misc_flags_u misc_flags;
248
249 uint8_t numEdidExtensions;
250
251 void *drv_context; /* pointer aligned start of mhl transmitter driver context area */
252 };
253
254 #define PACKED_PIXEL_AVAILABLE(dev_context) \
255 ((MHL_DEV_VID_LINK_SUPP_PPIXEL & \
256 dev_context->dev_cap_cache.devcap_cache[DEVCAP_OFFSET_VID_LINK_MODE]) && \
257 (MHL_DEV_VID_LINK_SUPP_PPIXEL & DEVCAP_VAL_VID_LINK_MODE))
258
259 enum scratch_pad_status {
260 SCRATCHPAD_FAIL= -4
261 ,SCRATCHPAD_BAD_PARAM = -3
262 ,SCRATCHPAD_NOT_SUPPORTED = -2
263 ,SCRATCHPAD_BUSY = -1
264 ,SCRATCHPAD_SUCCESS = 0
265 };
266
267 struct drv_hw_context;
268
269 struct mhl_drv_info {
270 int drv_context_size;
271 struct {
272 uint8_t major : 4;
273 uint8_t minor : 4;
274 } mhl_version_support;
275
276 /* APIs required to be supported by the low level MHL transmitter driver */
277 int (* mhl_device_initialize) (struct drv_hw_context *hw_context);
278 void (*mhl_device_isr) (struct drv_hw_context *hw_context, struct interrupt_info *intr_info);
279 int (* mhl_device_dbg_i2c_reg_xfer) (void *dev_context, u8 page, u8 offset, u8 count, bool rw_flag, u8 *buffer);
280 void (*mhl_start_video) (struct drv_hw_context *hw_context);
281 };
282
283
284 /* APIs provided by the Linux layer to the lower level driver */
285 int mhl_tx_init(struct mhl_drv_info const *drv_info, struct i2c_client *client);
286
287 int mhl_tx_remove(struct i2c_client *client);
288
289 void mhl_event_notify(struct mhl_dev_context *dev_context, u32 event, u32 event_param, void *data);
290
291 struct mhl_dev_context *get_mhl_device_context(void *context);
292
293 uint8_t calculate_generic_checksum(uint8_t *info_frame_data, uint8_t checksum, uint8_t length);
294
295 void *si_mhl_tx_get_drv_context(void *dev_context);
296
297 int mhl_tx_create_timer(void *context,
298 void (*callback_handler)(void *callback_param),
299 void *callback_param,
300 void **timer_handle);
301
302 int mhl_tx_delete_timer(void *context, void *timer_handle);
303
304 int mhl_tx_start_timer(void *context, void *timer_handle, uint32_t time_msec);
305
306 int mhl_tx_stop_timer(void *context, void *timer_handle);
307
308 void si_mhl_tx_request_first_edid_block(struct mhl_dev_context *dev_context);
309 void si_mhl_tx_handle_atomic_hw_edid_read_complete(edid_3d_data_p mhl_edid_3d_data,struct cbus_req *req);
310
311 /* APIs used within the Linux layer of the driver. */
312 uint8_t si_mhl_tx_get_peer_dev_cap_entry(struct mhl_dev_context *dev_context, uint8_t index, uint8_t *data);
313
314 enum scratch_pad_status si_get_scratch_pad_vector(
315 struct mhl_dev_context *dev_context,
316 uint8_t offset,uint8_t length,
317 uint8_t *data);
318 #endif /* if !defined(MHL_LINUX_TX_H) */