分享

android / kernel/omap / android-omap-steelhead-3.0-ics-aah / . / drivers / video / omap2 / hdcp / hd

 WUCANADA 2015-06-18
  1. /*
  2. * hdcp.h
  3. *
  4. * HDCP interface DSS driver setting for TI's OMAP4 family of processor.
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www./
  6. * Authors: Fabrice Olivero
  7. * Fabrice Olivero <f-olivero@>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www./licenses/>.
  20. */
  21. #ifndef _HDCP_H_
  22. #define _HDCP_H_
  23. /********************************/
  24. /* Structures related to ioctl */
  25. /********************************/
  26. /* HDCP key size in 32-bit words */
  27. #define DESHDCP_KEY_SIZE 160
  28. /* HDCP ioctl */
  29. #include <linux/ioctl.h>
  30. #include <linux/types.h>
  31. struct hdcp_encrypt_control {
  32. uint32_t in_key[DESHDCP_KEY_SIZE];
  33. uint32_t *out_key;
  34. };
  35. struct hdcp_enable_control {
  36. uint32_t key[DESHDCP_KEY_SIZE];
  37. int nb_retry;
  38. };
  39. #define MAX_SHA_DATA_SIZE 645
  40. #define MAX_SHA_VPRIME_SIZE 20
  41. struct hdcp_sha_in {
  42. uint8_t data[MAX_SHA_DATA_SIZE];
  43. uint32_t byte_counter;
  44. uint8_t vprime[MAX_SHA_VPRIME_SIZE];
  45. };
  46. struct hdcp_wait_control {
  47. uint32_t event;
  48. struct hdcp_sha_in *data;
  49. };
  50. /* HDCP ioctl */
  51. #define HDCP_IOCTL_MAGIC 'h'
  52. #define HDCP_ENABLE _IOW(HDCP_IOCTL_MAGIC, 0, \
  53. struct hdcp_enable_control)
  54. #define HDCP_DISABLE _IO(HDCP_IOCTL_MAGIC, 1)
  55. #define HDCP_ENCRYPT_KEY _IOWR(HDCP_IOCTL_MAGIC, 2, \
  56. struct hdcp_encrypt_control)
  57. #define HDCP_QUERY_STATUS _IOWR(HDCP_IOCTL_MAGIC, 3, uint32_t)
  58. #define HDCP_WAIT_EVENT _IOWR(HDCP_IOCTL_MAGIC, 4, \
  59. struct hdcp_wait_control)
  60. #define HDCP_DONE _IOW(HDCP_IOCTL_MAGIC, 5, uint32_t)
  61. /* HDCP state */
  62. #define HDCP_STATE_DISABLED 0
  63. #define HDCP_STATE_INIT 1
  64. #define HDCP_STATE_AUTH_1ST_STEP 2
  65. #define HDCP_STATE_AUTH_2ND_STEP 3
  66. #define HDCP_STATE_AUTH_3RD_STEP 4
  67. #define HDCP_STATE_AUTH_FAIL_RESTARTING 5
  68. #define HDCP_STATE_AUTH_FAILURE 6
  69. /* HDCP events */
  70. #define HDCP_EVENT_STEP1 (1 << 0x0)
  71. #define HDCP_EVENT_STEP2 (1 << 0x1)
  72. #define HDCP_EVENT_EXIT (1 << 0x2)
  73. /* HDCP user space status */
  74. #define HDCP_US_NO_ERR (0 << 8)
  75. #define HDCP_US_FAILURE (1 << 8)
  76. #ifdef __KERNEL__
  77. #include <linux/mutex.h>
  78. #include <linux/workqueue.h>
  79. #include <linux/init.h>
  80. #include <linux/kernel.h>
  81. #include <linux/io.h>
  82. #include <linux/slab.h>
  83. #include <linux/fs.h>
  84. #define _9032_AUTO_RI_ /* Auto Ri mode */
  85. #define _9032_BCAP_ /* BCAP polling */
  86. #undef _9032_AN_STOP_FIX_
  87. /***************************/
  88. /* HW specific definitions */
  89. /***************************/
  90. /* DESHDCP base address */
  91. /*----------------------*/
  92. #define DSS_SS_FROM_L3__DESHDCP 0x58007000
  93. /* DESHDCP registers */
  94. #define DESHDCP__DHDCP_CTRL 0x020
  95. #define DESHDCP__DHDCP_DATA_L 0x024
  96. #define DESHDCP__DHDCP_DATA_H 0x028
  97. /* DESHDCP CTRL bits */
  98. #define DESHDCP__DHDCP_CTRL__DIRECTION_POS_F 2
  99. #define DESHDCP__DHDCP_CTRL__DIRECTION_POS_L 2
  100. #define DESHDCP__DHDCP_CTRL__OUTPUT_READY_POS_F 0
  101. #define DESHDCP__DHDCP_CTRL__OUTPUT_READY_POS_L 0
  102. /* HDMI WP base address */
  103. /*----------------------*/
  104. #define HDMI_WP 0x58006000
  105. /* HDMI CORE SYSTEM base address */
  106. /*-------------------------------*/
  107. #define HDMI_IP_CORE_SYSTEM 0x400
  108. /* HDMI CORE registers */
  109. #define HDMI_IP_CORE_SYSTEM__DCTL 0x034
  110. #define HDMI_IP_CORE_SYSTEM__HDCP_CTRL 0x03C
  111. #define HDMI_IP_CORE_SYSTEM__BKSV0 0x040
  112. #define HDMI_IP_CORE_SYSTEM__AN0 0x054
  113. #define HDMI_IP_CORE_SYSTEM__AKSV0 0x074
  114. #define HDMI_IP_CORE_SYSTEM__R1 0x088
  115. #define HDMI_IP_CORE_SYSTEM__R2 0x08C
  116. #define HDMI_IP_CORE_SYSTEM__RI_CMD 0x09C
  117. #define HDMI_IP_CORE_SYSTEM__RI_STAT 0x098
  118. #define HDMI_IP_CORE_SYSTEM__INTR2 0x1C8
  119. #define HDMI_IP_CORE_SYSTEM__INTR3 0x1CC
  120. #define HDMI_IP_CORE_SYSTEM__INT_UNMASK2 0x1D8
  121. #define HDMI_IP_CORE_SYSTEM__INT_UNMASK3 0x1DC
  122. #define HDMI_IP_CORE_SYSTEM__SHA_CTRL 0x330
  123. #define HDMI_IP_CORE_SYSTEM__INTR2__BCAP 0x80
  124. #define HDMI_IP_CORE_SYSTEM__INTR3__RI_ERR 0xF0
  125. enum hdcp_repeater {
  126. HDCP_RECEIVER = 0,
  127. HDCP_REPEATER = 1
  128. };
  129. enum encryption_state {
  130. HDCP_ENC_OFF = 0x0,
  131. HDCP_ENC_ON = 0x1
  132. };
  133. /* HDMI CORE AV base address */
  134. /*---------------------------*/
  135. #define HDMI_CORE_AV_BASE 0x900
  136. #ifndef HDMI_CORE_AV_HDMI_CTRL
  137. #define HDMI_CORE_AV_HDMI_CTRL 0x0BC
  138. #define HDMI_CORE_AV_PB_CTRL2 0x0FC
  139. #define HDMI_CORE_AV_CP_BYTE1 0x37C
  140. #endif
  141. #define HDMI_CORE_AV_HDMI_CTRL__HDMI_MODE 0x01
  142. enum av_mute {
  143. AV_MUTE_SET = 0x01,
  144. AV_MUTE_CLEAR = 0x10
  145. };
  146. /***************************/
  147. /* Definitions */
  148. /***************************/
  149. /* Status / error codes */
  150. #define HDCP_OK 0
  151. #define HDCP_DDC_ERROR 1
  152. #define HDCP_AUTH_FAILURE 2
  153. #define HDCP_AKSV_ERROR 3
  154. #define HDCP_3DES_ERROR 4
  155. #define HDCP_SHA1_ERROR 5
  156. #define HDCP_DRIVER_ERROR 6
  157. #define HDCP_CANCELLED_AUTH 7
  158. #define HDCP_INFINITE_REAUTH 0x100
  159. #define HDCP_MAX_FAIL_MESSAGES 3
  160. /* FIXME: should be 300ms delay between HDMI start frame event and HDCP enable
  161. * (to respect 7 VSYNC delay in 24 Hz)
  162. */
  163. #define HDCP_ENABLE_DELAY 300
  164. #define HDCP_R0_DELAY 110
  165. #define HDCP_KSV_TIMEOUT_DELAY 5000
  166. #define HDCP_REAUTH_DELAY 1000
  167. /* Event source */
  168. #define HDCP_SRC_SHIFT 8
  169. #define HDCP_IOCTL_SRC (0x1 << HDCP_SRC_SHIFT)
  170. #define HDCP_HDMI_SRC (0x2 << HDCP_SRC_SHIFT)
  171. #define HDCP_IRQ_SRC (0x4 << HDCP_SRC_SHIFT)
  172. #define HDCP_WORKQUEUE_SRC (0x8 << HDCP_SRC_SHIFT)
  173. /* Workqueue events */
  174. /* Note: HDCP_ENABLE_CTL, HDCP_R0_EXP_EVENT, HDCP_KSV_TIMEOUT_EVENT and
  175. * HDCP_AUTH_REATT_EVENT can be cancelled by HDCP disabling
  176. */
  177. #define HDCP_ENABLE_CTL (HDCP_IOCTL_SRC | 0)
  178. #define HDCP_DISABLE_CTL (HDCP_IOCTL_SRC | 1)
  179. #define HDCP_START_FRAME_EVENT (HDCP_HDMI_SRC | 2)
  180. #define HDCP_STOP_FRAME_EVENT (HDCP_HDMI_SRC | 3)
  181. #define HDCP_HPD_LOW_EVENT (HDCP_IRQ_SRC | 4)
  182. #define HDCP_RI_FAIL_EVENT (HDCP_IRQ_SRC | 5)
  183. #define HDCP_KSV_LIST_RDY_EVENT (HDCP_IRQ_SRC | 6)
  184. #define HDCP_R0_EXP_EVENT (HDCP_WORKQUEUE_SRC | 7)
  185. #define HDCP_KSV_TIMEOUT_EVENT (HDCP_WORKQUEUE_SRC | 8)
  186. #define HDCP_AUTH_REATT_EVENT (HDCP_WORKQUEUE_SRC | 9)
  187. /* IRQ status */
  188. #define HDCP_IRQ_RI_FAIL 0x01
  189. #define HDCP_IRQ_KSV_RDY 0x02
  190. enum hdcp_states {
  191. HDCP_DISABLED,
  192. HDCP_ENABLE_PENDING,
  193. HDCP_AUTHENTICATION_START,
  194. HDCP_WAIT_R0_DELAY,
  195. HDCP_WAIT_KSV_LIST,
  196. HDCP_LINK_INTEGRITY_CHECK,
  197. HDCP_KEY_ENCRYPTION_ONGOING
  198. };
  199. enum hdmi_states {
  200. HDMI_STOPPED,
  201. HDMI_STARTED
  202. };
  203. struct hdcp_delayed_work {
  204. struct delayed_work work;
  205. int event;
  206. };
  207. struct hdcp {
  208. void __iomem *hdmi_wp_base_addr;
  209. void __iomem *deshdcp_base_addr;
  210. struct mutex lock;
  211. struct hdcp_enable_control *en_ctrl;
  212. dev_t dev_id;
  213. struct class *hdcp_class;
  214. enum hdmi_states hdmi_state;
  215. enum hdcp_states hdcp_state;
  216. int auth_state;
  217. struct delayed_work *pending_start;
  218. /* Following variable should store works submitted from workqueue
  219. * context
  220. * WARNING: only ONE work at a time can be stored (no conflict
  221. * should happen). It is used to allow cancelled pending works when
  222. * disabling HDCP
  223. */
  224. struct delayed_work *pending_wq_event;
  225. int retry_cnt;
  226. int fail_cnt;
  227. int av_mute_needed;
  228. int print_messages;
  229. int dss_state;
  230. int hdmi_restart;
  231. int hpd_low;
  232. spinlock_t spinlock;
  233. struct workqueue_struct *workqueue;
  234. int hdcp_up_event;
  235. int hdcp_down_event;
  236. bool hdcp_keys_loaded;
  237. };
  238. extern struct hdcp hdcp;
  239. extern struct hdcp_sha_in sha_input;
  240. /***************************/
  241. /* Macros for accessing HW */
  242. /***************************/
  243. #define WR_REG_32(base, offset, val) __raw_writel(val, base + offset)
  244. #define RD_REG_32(base, offset) __raw_readl(base + offset)
  245. #undef FLD_MASK
  246. #define FLD_MASK(start, end) (((1 << (start - end + 1)) - 1) << (end))
  247. #undef FLD_VAL
  248. #define FLD_VAL(val, start, end) (((val) << end) & FLD_MASK(start, end))
  249. #define FLD_GET(val, start, end) (((val) & FLD_MASK(start, end)) >> (end))
  250. #define FLD_MOD(orig, val, start, end) \
  251. (((orig) & ~FLD_MASK(start, end)) | FLD_VAL(val, start, end))
  252. #define WR_FIELD_32(base, offset, start, end, val) \
  253. WR_REG_32(base, offset, FLD_MOD(RD_REG_32(base, offset), val, \
  254. start, end))
  255. #define RD_FIELD_32(base, offset, start, end) \
  256. ((RD_REG_32(base, offset) & FLD_MASK(start, end)) >> (end))
  257. #undef DBG
  258. #ifdef HDCP_DEBUG
  259. #define DBG(format, ...) \
  260. printk(KERN_DEBUG "HDCP: " format "\n", ## __VA_ARGS__)
  261. #else
  262. #define DBG(format, ...)
  263. #endif
  264. /***************************/
  265. /* Function prototypes */
  266. /***************************/
  267. int hdcp_user_space_task(int flags);
  268. /* 3DES */
  269. int hdcp_3des_load_key(uint32_t *deshdcp_encrypted_key);
  270. void hdcp_3des_encrypt_key(struct hdcp_encrypt_control *enc_ctrl,
  271. uint32_t out_key[DESHDCP_KEY_SIZE]);
  272. /* IP control */
  273. int hdcp_lib_disable(void);
  274. int hdcp_lib_step1_start(void);
  275. int hdcp_lib_step1_r0_check(void);
  276. int hdcp_lib_step2(void);
  277. int hdcp_lib_irq(void);
  278. void hdcp_lib_auto_ri_check(bool state);
  279. void hdcp_lib_auto_bcaps_rdy_check(bool state);
  280. void hdcp_lib_set_av_mute(enum av_mute av_mute_state);
  281. void hdcp_lib_set_encryption(enum encryption_state enc_state);
  282. u8 hdcp_lib_check_repeater_bit_in_tx(void);
  283. #endif /* __KERNEL__ */
  284. #endif /* _HDCP_H_ */

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多