vcap_v4l2.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #ifndef VCAP_V4L2_H
  14. #define VCAP_V4L2_H
  15. #ifdef __KERNEL__
  16. #include <linux/types.h>
  17. #include <linux/videodev2.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/workqueue.h>
  20. #include <media/videobuf2-vmalloc.h>
  21. #include <media/v4l2-device.h>
  22. #include <media/v4l2-ioctl.h>
  23. #include <media/v4l2-ctrls.h>
  24. #include <media/v4l2-fh.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/vcap_fmt.h>
  27. #include <mach/board.h>
  28. #include <mach/iommu_domains.h>
  29. #define to_client_data(val) container_of(val, struct vcap_client_data, vfh)
  30. #define writel_iowmb(val, addr) \
  31. do { \
  32. __iowmb(); \
  33. writel_relaxed(val, addr); \
  34. } while (0)
  35. #define VCAP_USEC (1000000)
  36. #define VCAP_STRIDE_ALIGN_16 0x10
  37. #define VCAP_STRIDE_ALIGN_32 0x20
  38. #define VCAP_STRIDE_CALC(x, align) (((x / align) + \
  39. (!(!(x % align)))) * align)
  40. #define VCAP_BASE (dev->vcapbase)
  41. #define VCAP_OFFSET(off) (VCAP_BASE + off)
  42. struct reg_range {
  43. u32 min_val;
  44. u32 max_val;
  45. };
  46. #define VCAP_REG_RANGE_1_MIN 0x0
  47. #define VCAP_REG_RANGE_1_MAX 0x48
  48. #define VCAP_REG_RANGE_2_MIN 0x100
  49. #define VCAP_REG_RANGE_2_MAX 0x104
  50. #define VCAP_REG_RANGE_3_MIN 0x400
  51. #define VCAP_REG_RANGE_3_MAX 0x7F0
  52. #define VCAP_REG_RANGE_4_MIN 0x800
  53. #define VCAP_REG_RANGE_4_MAX 0x8A0
  54. #define VCAP_REG_RANGE_5_MIN 0xC00
  55. #define VCAP_REG_RANGE_5_MAX 0xDF0
  56. #define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024)
  57. #define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028)
  58. #define VCAP_VP_MIN_BUF 4
  59. #define VCAP_VC_MAX_BUF 6
  60. #define VCAP_VC_MIN_BUF 2
  61. struct vcap_client_data;
  62. enum vp_state {
  63. VP_UNKNOWN = 0,
  64. VP_FRAME1,
  65. VP_FRAME2,
  66. VP_FRAME3,
  67. VP_NORMAL,
  68. };
  69. enum nr_buf_pos {
  70. BUF_NOT_IN_USE = 0,
  71. NRT2_BUF,
  72. T1_BUF,
  73. T0_BUF,
  74. TM1_BUF,
  75. };
  76. struct vcap_buf_info {
  77. unsigned long vaddr;
  78. unsigned long size;
  79. };
  80. enum vcap_op_mode {
  81. UNKNOWN_VCAP_OP = 0,
  82. VC_VCAP_OP,
  83. VP_VCAP_OP,
  84. VC_AND_VP_VCAP_OP,
  85. };
  86. struct vc_action {
  87. struct list_head active;
  88. /* thread for generating video stream*/
  89. wait_queue_head_t wq;
  90. /* Buffer index */
  91. uint8_t tot_buf;
  92. uint8_t buf_num;
  93. bool field1;
  94. bool field_dropped;
  95. struct timeval vc_ts;
  96. uint32_t last_ts;
  97. /* Buffers inside vc */
  98. struct vcap_buffer *buf[6];
  99. };
  100. struct nr_buffer {
  101. struct ion_handle *nr_handle;
  102. unsigned long paddr;
  103. enum nr_buf_pos nr_pos;
  104. };
  105. struct vp_action {
  106. struct list_head in_active;
  107. struct list_head out_active;
  108. /* Buffer index */
  109. enum vp_state vp_state;
  110. /* Buffers inside vc */
  111. struct vcap_buffer *bufTm1;
  112. struct vcap_buffer *bufT0;
  113. struct vcap_buffer *bufT1;
  114. struct vcap_buffer *bufT2;
  115. struct vcap_buffer *bufNRT2;
  116. struct vcap_buffer *bufOut;
  117. struct ion_handle *motionHandle;
  118. void *bufMotion;
  119. struct nr_buffer bufNR;
  120. };
  121. struct vp_work_t {
  122. struct work_struct work;
  123. struct vcap_client_data *cd;
  124. };
  125. struct vcap_debugfs_params {
  126. atomic_t vc_drop_count;
  127. uint32_t vc_timestamp;
  128. uint32_t vp_timestamp;
  129. uint32_t vp_ewma;/* Exponential moving average */
  130. uint32_t clk_rate;
  131. uint32_t bw_request;
  132. uint32_t reg_addr;
  133. };
  134. struct vcap_dev {
  135. struct v4l2_device v4l2_dev;
  136. struct video_device *vfd;
  137. struct ion_client *ion_client;
  138. struct resource *vcirq;
  139. struct resource *vpirq;
  140. struct resource *vcapmem;
  141. struct resource *vcapio;
  142. void __iomem *vcapbase;
  143. struct vcap_platform_data *vcap_pdata;
  144. struct regulator *fs_vcap;
  145. struct clk *vcap_clk;
  146. struct clk *vcap_p_clk;
  147. struct clk *vcap_npl_clk;
  148. struct device *ddev;
  149. /*struct platform_device *pdev;*/
  150. uint32_t bus_client_handle;
  151. int domain_num;
  152. struct device *vc_iommu_ctx;
  153. struct device *vp_iommu_ctx;
  154. struct iommu_domain *iommu_vcap_domain;
  155. struct vcap_client_data *vc_client;
  156. struct vcap_client_data *vp_client;
  157. atomic_t vc_enabled;
  158. atomic_t vp_enabled;
  159. struct mutex dev_mutex;
  160. atomic_t open_clients;
  161. bool vc_resource;
  162. bool vp_resource;
  163. bool vp_dummy_event;
  164. bool vp_dummy_complete;
  165. bool vp_shutdown;
  166. wait_queue_head_t vp_dummy_waitq;
  167. uint8_t vc_tot_buf;
  168. struct workqueue_struct *vcap_wq;
  169. struct vp_work_t vp_work;
  170. struct vp_work_t vc_to_vp_work;
  171. struct vp_work_t vp_to_vc_work;
  172. struct nr_param nr_param;
  173. bool nr_update;
  174. struct vcap_debugfs_params dbg_p;
  175. };
  176. struct vp_format_data {
  177. unsigned int width, height;
  178. unsigned int pixfmt;
  179. };
  180. struct vcap_buffer {
  181. /* common v4l buffer stuff -- must be first */
  182. struct vb2_buffer vb;
  183. struct list_head list;
  184. unsigned long paddr;
  185. struct ion_handle *ion_handle;
  186. };
  187. struct vcap_client_data {
  188. bool set_cap, set_decode, set_vp_o;
  189. struct vcap_dev *dev;
  190. struct vb2_queue vc_vidq;
  191. struct vb2_queue vp_in_vidq;
  192. struct vb2_queue vp_out_vidq;
  193. enum vcap_op_mode op_mode;
  194. struct v4l2_format_vc_ext vc_format;
  195. enum vcap_stride stride;
  196. enum v4l2_buf_type vp_buf_type_field;
  197. struct vp_format_data vp_in_fmt;
  198. struct vp_format_data vp_out_fmt;
  199. struct vc_action vc_action;
  200. struct vp_action vp_action;
  201. struct workqueue_struct *vcap_work_q;
  202. struct ion_handle *vc_ion_handle;
  203. uint32_t hold_vc;
  204. uint32_t hold_vp;
  205. /* Mutex ensures only one thread is dq buffer or turning streamoff */
  206. struct mutex mutex;
  207. spinlock_t cap_slock;
  208. bool streaming;
  209. struct v4l2_fh vfh;
  210. };
  211. struct vcap_hacked_vals {
  212. uint32_t value;
  213. uint32_t offset;
  214. };
  215. extern struct vcap_hacked_vals hacked_buf[];
  216. #endif
  217. int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
  218. int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
  219. #endif