| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. 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 | |
| 14 | #ifndef VCAP_V4L2_H |
| 15 | #define VCAP_V4L2_H |
| 16 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 17 | #define TOP_FIELD_FIX |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 18 | #ifdef __KERNEL__ |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/videodev2.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/workqueue.h> |
| 23 | #include <media/videobuf2-vmalloc.h> |
| 24 | #include <media/v4l2-device.h> |
| 25 | #include <media/v4l2-ioctl.h> |
| 26 | #include <media/v4l2-ctrls.h> |
| 27 | #include <media/v4l2-fh.h> |
| 28 | #include <media/v4l2-common.h> |
| 29 | #include <media/vcap_fmt.h> |
| 30 | #include <mach/board.h> |
| Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 31 | #include <mach/iommu_domains.h> |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 32 | |
| Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 33 | #define to_client_data(val) container_of(val, struct vcap_client_data, vfh) |
| 34 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 35 | #define writel_iowmb(val, addr) \ |
| 36 | do { \ |
| 37 | __iowmb(); \ |
| 38 | writel_relaxed(val, addr); \ |
| 39 | } while (0) |
| 40 | |
| Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 41 | #define VCAP_BASE (dev->vcapbase) |
| 42 | #define VCAP_OFFSET(off) (VCAP_BASE + off) |
| 43 | |
| 44 | #define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024) |
| 45 | #define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028) |
| 46 | |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 47 | struct vcap_client_data; |
| 48 | |
| 49 | enum rdy_buf { |
| 50 | VC_NO_BUF = 0, |
| 51 | VC_BUF1 = 1 << 1, |
| 52 | VC_BUF2 = 1 << 2, |
| 53 | VC_BUF1N2 = 0x11 << 1, |
| 54 | }; |
| 55 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 56 | enum vp_state { |
| 57 | VP_UNKNOWN = 0, |
| 58 | VP_FRAME1, |
| 59 | VP_FRAME2, |
| 60 | VP_FRAME3, |
| 61 | VP_NORMAL, |
| 62 | }; |
| 63 | |
| 64 | enum nr_buf_pos { |
| 65 | BUF_NOT_IN_USE = 0, |
| 66 | NRT2_BUF, |
| 67 | T1_BUF, |
| 68 | T0_BUF, |
| 69 | TM1_BUF, |
| 70 | }; |
| 71 | |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 72 | struct vcap_buf_info { |
| 73 | unsigned long vaddr; |
| 74 | unsigned long size; |
| 75 | }; |
| 76 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 77 | enum vcap_op_mode { |
| 78 | UNKNOWN_VCAP_OP = 0, |
| 79 | VC_VCAP_OP, |
| 80 | VP_VCAP_OP, |
| 81 | VC_AND_VP_VCAP_OP, |
| 82 | }; |
| 83 | |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 84 | struct vcap_action { |
| 85 | struct list_head active; |
| 86 | |
| 87 | /* thread for generating video stream*/ |
| 88 | struct task_struct *kthread; |
| 89 | wait_queue_head_t wq; |
| 90 | |
| 91 | /* Buffer index */ |
| 92 | enum rdy_buf buf_ind; |
| 93 | |
| 94 | /* Buffers inside vc */ |
| 95 | struct vcap_buffer *buf1; |
| 96 | struct vcap_buffer *buf2; |
| 97 | |
| 98 | /* Counters to control fps rate */ |
| 99 | int frame; |
| 100 | int ini_jiffies; |
| 101 | }; |
| 102 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 103 | struct nr_buffer { |
| Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 104 | struct ion_handle *nr_handle; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 105 | unsigned long paddr; |
| 106 | enum nr_buf_pos nr_pos; |
| 107 | }; |
| 108 | |
| 109 | struct vp_action { |
| 110 | struct list_head in_active; |
| 111 | struct list_head out_active; |
| 112 | |
| 113 | /* Buffer index */ |
| 114 | enum vp_state vp_state; |
| 115 | #ifdef TOP_FIELD_FIX |
| 116 | bool top_field; |
| 117 | #endif |
| 118 | |
| 119 | /* Buffers inside vc */ |
| 120 | struct vcap_buffer *bufTm1; |
| 121 | struct vcap_buffer *bufT0; |
| 122 | struct vcap_buffer *bufT1; |
| 123 | struct vcap_buffer *bufT2; |
| 124 | struct vcap_buffer *bufNRT2; |
| 125 | |
| 126 | struct vcap_buffer *bufOut; |
| 127 | |
| Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 128 | struct ion_handle *motionHandle; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 129 | void *bufMotion; |
| 130 | struct nr_buffer bufNR; |
| Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 131 | struct nr_param nr_param; |
| 132 | bool nr_update; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | struct vp_work_t { |
| 136 | struct work_struct work; |
| 137 | struct vcap_client_data *cd; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 138 | }; |
| 139 | |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 140 | struct vcap_dev { |
| 141 | struct v4l2_device v4l2_dev; |
| 142 | |
| 143 | struct video_device *vfd; |
| 144 | struct ion_client *ion_client; |
| 145 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 146 | struct resource *vcirq; |
| 147 | struct resource *vpirq; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 148 | |
| 149 | struct resource *vcapmem; |
| 150 | struct resource *vcapio; |
| 151 | void __iomem *vcapbase; |
| 152 | |
| 153 | struct vcap_platform_data *vcap_pdata; |
| 154 | |
| 155 | struct regulator *fs_vcap; |
| 156 | struct clk *vcap_clk; |
| 157 | struct clk *vcap_p_clk; |
| 158 | struct clk *vcap_npl_clk; |
| Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 159 | struct device *ddev; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 160 | /*struct platform_device *pdev;*/ |
| 161 | |
| 162 | uint32_t bus_client_handle; |
| 163 | |
| 164 | struct vcap_client_data *vc_client; |
| 165 | struct vcap_client_data *vp_client; |
| 166 | |
| 167 | atomic_t vc_enabled; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 168 | atomic_t vp_enabled; |
| 169 | |
| Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 170 | struct mutex dev_mutex; |
| Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 171 | atomic_t open_clients; |
| 172 | bool vc_resource; |
| 173 | bool vp_resource; |
| Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 174 | bool vp_dummy_event; |
| 175 | bool vp_dummy_complete; |
| Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 176 | bool vp_shutdown; |
| Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 177 | wait_queue_head_t vp_dummy_waitq; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 178 | |
| 179 | struct workqueue_struct *vcap_wq; |
| 180 | struct vp_work_t vp_work; |
| 181 | struct vp_work_t vc_to_vp_work; |
| 182 | struct vp_work_t vp_to_vc_work; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | struct vp_format_data { |
| 186 | unsigned int width, height; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 187 | unsigned int pixfmt; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | struct vcap_buffer { |
| 191 | /* common v4l buffer stuff -- must be first */ |
| 192 | struct vb2_buffer vb; |
| 193 | struct list_head list; |
| 194 | unsigned long paddr; |
| 195 | struct ion_handle *ion_handle; |
| 196 | }; |
| 197 | |
| 198 | struct vcap_client_data { |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 199 | bool set_cap, set_decode, set_vp_o; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 200 | struct vcap_dev *dev; |
| 201 | |
| 202 | struct vb2_queue vc_vidq; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 203 | struct vb2_queue vp_in_vidq; |
| 204 | struct vb2_queue vp_out_vidq; |
| 205 | |
| 206 | enum vcap_op_mode op_mode; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 207 | |
| 208 | struct v4l2_format_vc_ext vc_format; |
| 209 | |
| 210 | enum v4l2_buf_type vp_buf_type_field; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 211 | struct vp_format_data vp_in_fmt; |
| 212 | struct vp_format_data vp_out_fmt; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 213 | |
| 214 | struct vcap_action vid_vc_action; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 215 | struct vp_action vid_vp_action; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 216 | struct workqueue_struct *vcap_work_q; |
| 217 | struct ion_handle *vc_ion_handle; |
| 218 | |
| 219 | uint32_t hold_vc; |
| 220 | uint32_t hold_vp; |
| 221 | |
| 222 | spinlock_t cap_slock; |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 223 | bool streaming; |
| Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 224 | |
| 225 | struct v4l2_fh vfh; |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 226 | }; |
| 227 | |
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 228 | struct vcap_hacked_vals { |
| 229 | uint32_t value; |
| 230 | uint32_t offset; |
| 231 | }; |
| 232 | |
| 233 | extern struct vcap_hacked_vals hacked_buf[]; |
| 234 | |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 235 | #endif |
| Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 236 | int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
| 237 | int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b); |
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 238 | #endif |