| 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; | 
|  | 151 | /*struct platform_device	*pdev;*/ | 
|  | 152 |  | 
|  | 153 | uint32_t				bus_client_handle; | 
|  | 154 |  | 
|  | 155 | struct vcap_client_data *vc_client; | 
|  | 156 | struct vcap_client_data *vp_client; | 
|  | 157 |  | 
|  | 158 | atomic_t			    vc_enabled; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 159 | atomic_t			    vp_enabled; | 
|  | 160 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 161 | atomic_t				vc_resource; | 
|  | 162 | atomic_t				vp_resource; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 163 |  | 
|  | 164 | struct workqueue_struct	*vcap_wq; | 
|  | 165 | struct vp_work_t		vp_work; | 
|  | 166 | struct vp_work_t		vc_to_vp_work; | 
|  | 167 | struct vp_work_t		vp_to_vc_work; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 168 | }; | 
|  | 169 |  | 
|  | 170 | struct vp_format_data { | 
|  | 171 | unsigned int		width, height; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 172 | unsigned int		pixfmt; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 173 | }; | 
|  | 174 |  | 
|  | 175 | struct vcap_buffer { | 
|  | 176 | /* common v4l buffer stuff -- must be first */ | 
|  | 177 | struct vb2_buffer	vb; | 
|  | 178 | struct list_head	list; | 
|  | 179 | unsigned long		paddr; | 
|  | 180 | struct ion_handle   *ion_handle; | 
|  | 181 | }; | 
|  | 182 |  | 
|  | 183 | struct vcap_client_data { | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 184 | bool set_cap, set_decode, set_vp_o; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 185 | struct vcap_dev *dev; | 
|  | 186 |  | 
|  | 187 | struct vb2_queue		vc_vidq; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 188 | struct vb2_queue		vp_in_vidq; | 
|  | 189 | struct vb2_queue		vp_out_vidq; | 
|  | 190 |  | 
|  | 191 | enum vcap_op_mode		op_mode; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 192 |  | 
|  | 193 | struct v4l2_format_vc_ext vc_format; | 
|  | 194 |  | 
|  | 195 | enum v4l2_buf_type		vp_buf_type_field; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 196 | struct vp_format_data	vp_in_fmt; | 
|  | 197 | struct vp_format_data	vp_out_fmt; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 198 |  | 
|  | 199 | struct vcap_action		vid_vc_action; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 200 | struct vp_action		vid_vp_action; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 201 | struct workqueue_struct *vcap_work_q; | 
|  | 202 | struct ion_handle			*vc_ion_handle; | 
|  | 203 |  | 
|  | 204 | uint32_t				hold_vc; | 
|  | 205 | uint32_t				hold_vp; | 
|  | 206 |  | 
|  | 207 | spinlock_t				cap_slock; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 208 | bool					streaming; | 
| Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame^] | 209 |  | 
|  | 210 | struct v4l2_fh			vfh; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 211 | }; | 
|  | 212 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 213 | struct vcap_hacked_vals { | 
|  | 214 | uint32_t	value; | 
|  | 215 | uint32_t	offset; | 
|  | 216 | }; | 
|  | 217 |  | 
|  | 218 | extern struct vcap_hacked_vals hacked_buf[]; | 
|  | 219 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 220 | #endif | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 221 | int free_ion_handle(struct vcap_dev *dev, struct vb2_queue *q, | 
|  | 222 | struct v4l2_buffer *b); | 
|  | 223 |  | 
|  | 224 | int get_phys_addr(struct vcap_dev *dev, struct vb2_queue *q, | 
|  | 225 | struct v4l2_buffer *b); | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 226 | #endif |