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