mhl_linux_tx.h 10 KB

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