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