Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 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 | |
| 14 | #ifndef VCAP_V4L2_H |
| 15 | #define VCAP_V4L2_H |
| 16 | |
| 17 | #ifdef __KERNEL__ |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/videodev2.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/workqueue.h> |
| 22 | #include <media/videobuf2-vmalloc.h> |
| 23 | #include <media/v4l2-device.h> |
| 24 | #include <media/v4l2-ioctl.h> |
| 25 | #include <media/v4l2-ctrls.h> |
| 26 | #include <media/v4l2-fh.h> |
| 27 | #include <media/v4l2-common.h> |
| 28 | #include <media/vcap_fmt.h> |
| 29 | #include <mach/board.h> |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 30 | #include <mach/iommu_domains.h> |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 31 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 32 | #define to_client_data(val) container_of(val, struct vcap_client_data, vfh) |
| 33 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 34 | #define writel_iowmb(val, addr) \ |
| 35 | do { \ |
| 36 | __iowmb(); \ |
| 37 | writel_relaxed(val, addr); \ |
| 38 | } while (0) |
| 39 | |
Terence Hampson | a1e8af4 | 2012-09-18 16:41:57 -0400 | [diff] [blame] | 40 | #define VCAP_USEC (1000000) |
Terence Hampson | 9d6f89c | 2012-10-03 16:24:04 -0400 | [diff] [blame] | 41 | |
Terence Hampson | df1d4de | 2012-11-05 17:06:02 -0500 | [diff] [blame] | 42 | #define VCAP_STRIDE_ALIGN_16 0x10 |
| 43 | #define VCAP_STRIDE_ALIGN_32 0x20 |
| 44 | #define VCAP_STRIDE_CALC(x, align) (((x / align) + \ |
| 45 | (!(!(x % align)))) * align) |
Terence Hampson | 9d6f89c | 2012-10-03 16:24:04 -0400 | [diff] [blame] | 46 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 47 | #define VCAP_BASE (dev->vcapbase) |
| 48 | #define VCAP_OFFSET(off) (VCAP_BASE + off) |
| 49 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 50 | struct reg_range { |
| 51 | u32 min_val; |
| 52 | u32 max_val; |
| 53 | }; |
| 54 | |
| 55 | #define VCAP_REG_RANGE_1_MIN 0x0 |
| 56 | #define VCAP_REG_RANGE_1_MAX 0x48 |
| 57 | #define VCAP_REG_RANGE_2_MIN 0x100 |
| 58 | #define VCAP_REG_RANGE_2_MAX 0x104 |
| 59 | #define VCAP_REG_RANGE_3_MIN 0x400 |
| 60 | #define VCAP_REG_RANGE_3_MAX 0x7F0 |
| 61 | #define VCAP_REG_RANGE_4_MIN 0x800 |
| 62 | #define VCAP_REG_RANGE_4_MAX 0x8A0 |
| 63 | #define VCAP_REG_RANGE_5_MIN 0xC00 |
| 64 | #define VCAP_REG_RANGE_5_MAX 0xDF0 |
| 65 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 66 | #define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024) |
| 67 | #define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028) |
| 68 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 69 | #define VCAP_VP_MIN_BUF 4 |
| 70 | #define VCAP_VC_MAX_BUF 6 |
| 71 | #define VCAP_VC_MIN_BUF 2 |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 72 | struct vcap_client_data; |
| 73 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 74 | enum vp_state { |
| 75 | VP_UNKNOWN = 0, |
| 76 | VP_FRAME1, |
| 77 | VP_FRAME2, |
| 78 | VP_FRAME3, |
| 79 | VP_NORMAL, |
| 80 | }; |
| 81 | |
| 82 | enum nr_buf_pos { |
| 83 | BUF_NOT_IN_USE = 0, |
| 84 | NRT2_BUF, |
| 85 | T1_BUF, |
| 86 | T0_BUF, |
| 87 | TM1_BUF, |
| 88 | }; |
| 89 | |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 90 | struct vcap_buf_info { |
| 91 | unsigned long vaddr; |
| 92 | unsigned long size; |
| 93 | }; |
| 94 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 95 | enum vcap_op_mode { |
| 96 | UNKNOWN_VCAP_OP = 0, |
| 97 | VC_VCAP_OP, |
| 98 | VP_VCAP_OP, |
| 99 | VC_AND_VP_VCAP_OP, |
| 100 | }; |
| 101 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 102 | struct vc_action { |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 103 | struct list_head active; |
| 104 | |
| 105 | /* thread for generating video stream*/ |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 106 | wait_queue_head_t wq; |
| 107 | |
| 108 | /* Buffer index */ |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 109 | uint8_t tot_buf; |
| 110 | uint8_t buf_num; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 111 | |
Terence Hampson | aa64d3a | 2012-10-29 13:05:37 -0400 | [diff] [blame] | 112 | bool field1; |
Terence Hampson | f0ab1ee | 2012-10-22 12:43:36 -0400 | [diff] [blame] | 113 | bool field_dropped; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 114 | |
Terence Hampson | a1e8af4 | 2012-09-18 16:41:57 -0400 | [diff] [blame] | 115 | struct timeval vc_ts; |
| 116 | uint32_t last_ts; |
| 117 | |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 118 | /* Buffers inside vc */ |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 119 | struct vcap_buffer *buf[6]; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 120 | }; |
| 121 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 122 | struct nr_buffer { |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 123 | struct ion_handle *nr_handle; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 124 | unsigned long paddr; |
| 125 | enum nr_buf_pos nr_pos; |
| 126 | }; |
| 127 | |
| 128 | struct vp_action { |
| 129 | struct list_head in_active; |
| 130 | struct list_head out_active; |
| 131 | |
| 132 | /* Buffer index */ |
| 133 | enum vp_state vp_state; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 134 | |
| 135 | /* Buffers inside vc */ |
| 136 | struct vcap_buffer *bufTm1; |
| 137 | struct vcap_buffer *bufT0; |
| 138 | struct vcap_buffer *bufT1; |
| 139 | struct vcap_buffer *bufT2; |
| 140 | struct vcap_buffer *bufNRT2; |
| 141 | |
| 142 | struct vcap_buffer *bufOut; |
| 143 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 144 | struct ion_handle *motionHandle; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 145 | void *bufMotion; |
| 146 | struct nr_buffer bufNR; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | struct vp_work_t { |
| 150 | struct work_struct work; |
| 151 | struct vcap_client_data *cd; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 152 | }; |
| 153 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 154 | struct vcap_debugfs_params { |
| 155 | atomic_t vc_drop_count; |
| 156 | uint32_t vc_timestamp; |
| 157 | uint32_t vp_timestamp; |
| 158 | uint32_t vp_ewma;/* Exponential moving average */ |
| 159 | uint32_t clk_rate; |
| 160 | uint32_t bw_request; |
| 161 | uint32_t reg_addr; |
| 162 | }; |
| 163 | |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 164 | struct vcap_dev { |
| 165 | struct v4l2_device v4l2_dev; |
| 166 | |
| 167 | struct video_device *vfd; |
| 168 | struct ion_client *ion_client; |
| 169 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 170 | struct resource *vcirq; |
| 171 | struct resource *vpirq; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 172 | |
| 173 | struct resource *vcapmem; |
| 174 | struct resource *vcapio; |
| 175 | void __iomem *vcapbase; |
| 176 | |
| 177 | struct vcap_platform_data *vcap_pdata; |
| 178 | |
| 179 | struct regulator *fs_vcap; |
| 180 | struct clk *vcap_clk; |
| 181 | struct clk *vcap_p_clk; |
| 182 | struct clk *vcap_npl_clk; |
Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 183 | struct device *ddev; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 184 | /*struct platform_device *pdev;*/ |
| 185 | |
| 186 | uint32_t bus_client_handle; |
| 187 | |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 188 | int domain_num; |
| 189 | struct device *vc_iommu_ctx; |
| 190 | struct device *vp_iommu_ctx; |
| 191 | struct iommu_domain *iommu_vcap_domain; |
| 192 | |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 193 | struct vcap_client_data *vc_client; |
| 194 | struct vcap_client_data *vp_client; |
| 195 | |
| 196 | atomic_t vc_enabled; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 197 | atomic_t vp_enabled; |
| 198 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 199 | struct mutex dev_mutex; |
Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 200 | atomic_t open_clients; |
| 201 | bool vc_resource; |
| 202 | bool vp_resource; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 203 | bool vp_dummy_event; |
| 204 | bool vp_dummy_complete; |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 205 | bool vp_shutdown; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 206 | wait_queue_head_t vp_dummy_waitq; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 207 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 208 | uint8_t vc_tot_buf; |
| 209 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 210 | struct workqueue_struct *vcap_wq; |
| 211 | struct vp_work_t vp_work; |
| 212 | struct vp_work_t vc_to_vp_work; |
| 213 | struct vp_work_t vp_to_vc_work; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 214 | |
| 215 | struct nr_param nr_param; |
| 216 | bool nr_update; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 217 | struct vcap_debugfs_params dbg_p; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | struct vp_format_data { |
| 221 | unsigned int width, height; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 222 | unsigned int pixfmt; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | struct vcap_buffer { |
| 226 | /* common v4l buffer stuff -- must be first */ |
| 227 | struct vb2_buffer vb; |
| 228 | struct list_head list; |
| 229 | unsigned long paddr; |
| 230 | struct ion_handle *ion_handle; |
| 231 | }; |
| 232 | |
| 233 | struct vcap_client_data { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 234 | bool set_cap, set_decode, set_vp_o; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 235 | struct vcap_dev *dev; |
| 236 | |
| 237 | struct vb2_queue vc_vidq; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 238 | struct vb2_queue vp_in_vidq; |
| 239 | struct vb2_queue vp_out_vidq; |
| 240 | |
| 241 | enum vcap_op_mode op_mode; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 242 | |
| 243 | struct v4l2_format_vc_ext vc_format; |
Terence Hampson | df1d4de | 2012-11-05 17:06:02 -0500 | [diff] [blame] | 244 | enum vcap_stride stride; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 245 | |
| 246 | enum v4l2_buf_type vp_buf_type_field; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 247 | struct vp_format_data vp_in_fmt; |
| 248 | struct vp_format_data vp_out_fmt; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 249 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 250 | struct vc_action vc_action; |
| 251 | struct vp_action vp_action; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 252 | struct workqueue_struct *vcap_work_q; |
| 253 | struct ion_handle *vc_ion_handle; |
| 254 | |
| 255 | uint32_t hold_vc; |
| 256 | uint32_t hold_vp; |
| 257 | |
Terence Hampson | b0c58b1 | 2012-10-30 17:56:36 -0400 | [diff] [blame] | 258 | /* Mutex ensures only one thread is dq buffer or turning streamoff */ |
| 259 | struct mutex mutex; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 260 | spinlock_t cap_slock; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 261 | bool streaming; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 262 | |
| 263 | struct v4l2_fh vfh; |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 264 | }; |
| 265 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 266 | struct vcap_hacked_vals { |
| 267 | uint32_t value; |
| 268 | uint32_t offset; |
| 269 | }; |
| 270 | |
| 271 | extern struct vcap_hacked_vals hacked_buf[]; |
| 272 | |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 273 | #endif |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 274 | int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
| 275 | int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 276 | #endif |