5 Copyright (C) 2013 Silicon Image, Inc.
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.
17 #if !defined(MHL_LINUX_TX_H)
18 #define MHL_LINUX_TX_H
25 /* No event worth reporting */
26 #define MHL_TX_EVENT_NONE 0x00
28 /* MHL connection has been lost */
29 #define MHL_TX_EVENT_DISCONNECTION 0x01
31 /* MHL connection has been established */
32 #define MHL_TX_EVENT_CONNECTION 0x02
34 /* Received an RCP key code */
35 #define MHL_TX_EVENT_RCP_RECEIVED 0x04
37 /* Received an RCPK message */
38 #define MHL_TX_EVENT_RCPK_RECEIVED 0x05
40 /* Received an RCPE message */
41 #define MHL_TX_EVENT_RCPE_RECEIVED 0x06
43 /* Received an UTF-8 key code */
44 #define MHL_TX_EVENT_UCP_RECEIVED 0x07
46 /* Received an UCPK message */
47 #define MHL_TX_EVENT_UCPK_RECEIVED 0x08
49 /* Received an UCPE message */
50 #define MHL_TX_EVENT_UCPE_RECEIVED 0x09
52 /* Scratch Pad Data received */
53 #define MHL_TX_EVENT_SPAD_RECEIVED 0x0A
55 /* Peer's power capability has changed */
56 #define MHL_TX_EVENT_POW_BIT_CHG 0x0B
58 /* Received a Request Action Protocol (RAP) message */
59 #define MHL_TX_EVENT_RAP_RECEIVED 0x0C
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
69 #define ADOPTER_ID_SIZE 2
70 #define MAX_SCRATCH_PAD_TRANSFER_SIZE 16
71 #define SCRATCH_PAD_SIZE 64
73 #define SCRATCHPAD_SIZE 16
75 MHL2_video_format_data_t videoFormatData
;
76 uint8_t asBytes
[SCRATCHPAD_SIZE
];
81 struct list_head list_link
;
82 struct work_struct work_item
;
83 struct hrtimer hr_timer
;
84 struct mhl_dev_context
*dev_context
;
86 #define TIMER_OBJ_FLAG_WORK_IP 0x01
87 #define TIMER_OBJ_FLAG_DEL_REQ 0x02
89 void (*timer_callback_handler
)(void *callback_param
);
92 /* Convert a value specified in milliseconds to nanoseconds */
93 #define MSEC_TO_NSEC(x) (x * 1000000UL)
97 unsigned scratchpad_busy
:1;
98 unsigned req_wrt_pending
:1;
99 unsigned write_burst_pending
:1;
100 unsigned rcp_ready
:1;
102 unsigned have_complete_devcap
:1;
103 unsigned sent_dcap_rdy
:1;
104 unsigned sent_path_en
:1;
105 unsigned rap_content_on
:1;
108 unsigned mhl_rsen
:1;
109 unsigned edid_loop_active
:1;
110 unsigned cbus_abort_delay_active
:1;
112 unsigned reserved
:20;
118 * structure used by interrupt handler to return
119 * information about an interrupt.
121 struct interrupt_info
{
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
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 */
144 #define NUM_CBUS_EVENT_QUEUE_EVENTS 50
146 #define MHL_DEV_CONTEXT_SIGNATURE ( ('M' << 24) | ('H' << 16) | ('L' << 8) | ' ')
148 struct mhl_dev_context
{
149 uint32_t signature
; /* identifies an instance of
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
159 #define DEV_FLAG_SHUTDOWN 0x01 /* Device is shutting down */
160 #define DEV_FLAG_COMM_MODE 0x02 /* user wants to peek/poke at registers */
162 u16 mhl_flags
; /* various state flags */
163 #define MHL_STATE_FLAG_CONNECTED 0x0001 /* MHL connection
165 #ifndef RCP_INPUTDEV_SUPPORT
166 #define MHL_STATE_FLAG_RCP_SENT 0x0002 /* last RCP event was a key
168 #define MHL_STATE_FLAG_RCP_RECEIVED 0x0004 /* last RCP event was a key
170 #define MHL_STATE_FLAG_RCP_ACK 0x0008 /* last RCP key code sent was
172 #define MHL_STATE_FLAG_RCP_NAK 0x0010 /* last RCP key code sent was
175 #define MHL_STATE_FLAG_UCP_SENT 0x0020 /* last UCP event was a key
177 #define MHL_STATE_FLAG_UCP_RECEIVED 0x0040 /* last UCP event was a key
179 #define MHL_STATE_FLAG_UCP_ACK 0x0080 /* last UCP key code sent was
181 #define MHL_STATE_FLAG_UCP_NAK 0x0100 /* last UCP key code sent was
183 #define MHL_STATE_FLAG_SPAD_SENT 0x0200 /* scratch pad send in
185 #define MHL_STATE_APPLICATION_RAP_BUSY 0x0400 /* application has indicated
186 that it is processing an
187 outstanding request */
197 u8 pending_event
; /* event data wait for retrieval */
198 u8 pending_event_data
; /* by user mode application */
202 u8 debug_i2c_address
;
204 u8 debug_i2c_xfer_length
;
206 #ifdef MEDIA_DATA_TUNNEL_SUPPORT
207 struct mdt_inputdevs mdt_devs
;
210 #ifdef RCP_INPUTDEV_SUPPORT
212 struct input_dev
*rcp_input_dev
;
214 struct semaphore isr_lock
; /* semaphore used to prevent driver access
215 from user mode from colliding with the
216 threaded interrupt handler */
218 u8 status_0
; /* Received status from peer saved here */
220 bool msc_msg_arrived
;
221 u8 msc_msg_sub_command
;
224 u8 msc_msg_last_data
;
225 u8 msc_save_rcp_key_code
;
226 u8 msc_save_ucp_key_code
;
228 u8 link_mode
; /* local MHL LINK_MODE register value */
229 bool mhl_connection_event
;
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
;
247 union misc_flags_u misc_flags
;
249 uint8_t numEdidExtensions
;
251 void *drv_context
; /* pointer aligned start of mhl transmitter driver context area */
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))
259 enum scratch_pad_status
{
261 ,SCRATCHPAD_BAD_PARAM
= -3
262 ,SCRATCHPAD_NOT_SUPPORTED
= -2
263 ,SCRATCHPAD_BUSY
= -1
264 ,SCRATCHPAD_SUCCESS
= 0
267 struct drv_hw_context
;
269 struct mhl_drv_info
{
270 int drv_context_size
;
274 } mhl_version_support
;
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
);
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
);
287 int mhl_tx_remove(struct i2c_client
*client
);
289 void mhl_event_notify(struct mhl_dev_context
*dev_context
, u32 event
, u32 event_param
, void *data
);
291 struct mhl_dev_context
*get_mhl_device_context(void *context
);
293 uint8_t calculate_generic_checksum(uint8_t *info_frame_data
, uint8_t checksum
, uint8_t length
);
295 void *si_mhl_tx_get_drv_context(void *dev_context
);
297 int mhl_tx_create_timer(void *context
,
298 void (*callback_handler
)(void *callback_param
),
299 void *callback_param
,
300 void **timer_handle
);
302 int mhl_tx_delete_timer(void *context
, void *timer_handle
);
304 int mhl_tx_start_timer(void *context
, void *timer_handle
, uint32_t time_msec
);
306 int mhl_tx_stop_timer(void *context
, void *timer_handle
);
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
);
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
);
314 enum scratch_pad_status
si_get_scratch_pad_vector(
315 struct mhl_dev_context
*dev_context
,
316 uint8_t offset
,uint8_t length
,
318 #endif /* if !defined(MHL_LINUX_TX_H) */