| 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 | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 32 | #define writel_iowmb(val, addr)		\ | 
|  | 33 | do {							\ | 
|  | 34 | __iowmb();					\ | 
|  | 35 | writel_relaxed(val, addr);	\ | 
|  | 36 | } while (0) | 
|  | 37 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 38 | struct vcap_client_data; | 
|  | 39 |  | 
|  | 40 | enum rdy_buf { | 
|  | 41 | VC_NO_BUF = 0, | 
|  | 42 | VC_BUF1 = 1 << 1, | 
|  | 43 | VC_BUF2 = 1 << 2, | 
|  | 44 | VC_BUF1N2 = 0x11 << 1, | 
|  | 45 | }; | 
|  | 46 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 47 | enum vp_state { | 
|  | 48 | VP_UNKNOWN = 0, | 
|  | 49 | VP_FRAME1, | 
|  | 50 | VP_FRAME2, | 
|  | 51 | VP_FRAME3, | 
|  | 52 | VP_NORMAL, | 
|  | 53 | }; | 
|  | 54 |  | 
|  | 55 | enum nr_buf_pos { | 
|  | 56 | BUF_NOT_IN_USE = 0, | 
|  | 57 | NRT2_BUF, | 
|  | 58 | T1_BUF, | 
|  | 59 | T0_BUF, | 
|  | 60 | TM1_BUF, | 
|  | 61 | }; | 
|  | 62 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 63 | struct vcap_buf_info { | 
|  | 64 | unsigned long vaddr; | 
|  | 65 | unsigned long size; | 
|  | 66 | }; | 
|  | 67 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 68 | enum vcap_op_mode { | 
|  | 69 | UNKNOWN_VCAP_OP = 0, | 
|  | 70 | VC_VCAP_OP, | 
|  | 71 | VP_VCAP_OP, | 
|  | 72 | VC_AND_VP_VCAP_OP, | 
|  | 73 | }; | 
|  | 74 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 75 | struct vcap_action { | 
|  | 76 | struct list_head		active; | 
|  | 77 |  | 
|  | 78 | /* thread for generating video stream*/ | 
|  | 79 | struct task_struct		*kthread; | 
|  | 80 | wait_queue_head_t		wq; | 
|  | 81 |  | 
|  | 82 | /* Buffer index */ | 
|  | 83 | enum rdy_buf            buf_ind; | 
|  | 84 |  | 
|  | 85 | /* Buffers inside vc */ | 
|  | 86 | struct vcap_buffer      *buf1; | 
|  | 87 | struct vcap_buffer      *buf2; | 
|  | 88 |  | 
|  | 89 | /* Counters to control fps rate */ | 
|  | 90 | int						frame; | 
|  | 91 | int						ini_jiffies; | 
|  | 92 | }; | 
|  | 93 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 94 | struct nr_buffer { | 
|  | 95 | void						*vaddr; | 
|  | 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 |  | 
|  | 119 | void					*bufMotion; | 
|  | 120 | struct nr_buffer		bufNR; | 
|  | 121 | bool					nr_enabled; | 
|  | 122 | }; | 
|  | 123 |  | 
|  | 124 | struct vp_work_t { | 
|  | 125 | struct work_struct work; | 
|  | 126 | struct vcap_client_data *cd; | 
|  | 127 | uint32_t irq; | 
|  | 128 | }; | 
|  | 129 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 130 | struct vcap_dev { | 
|  | 131 | struct v4l2_device		v4l2_dev; | 
|  | 132 |  | 
|  | 133 | struct video_device		*vfd; | 
|  | 134 | struct ion_client       *ion_client; | 
|  | 135 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 136 | struct resource         *vcirq; | 
|  | 137 | struct resource         *vpirq; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 138 |  | 
|  | 139 | struct resource			*vcapmem; | 
|  | 140 | struct resource			*vcapio; | 
|  | 141 | void __iomem			*vcapbase; | 
|  | 142 |  | 
|  | 143 | struct vcap_platform_data	*vcap_pdata; | 
|  | 144 |  | 
|  | 145 | struct regulator		*fs_vcap; | 
|  | 146 | struct clk				*vcap_clk; | 
|  | 147 | struct clk				*vcap_p_clk; | 
|  | 148 | struct clk				*vcap_npl_clk; | 
|  | 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 | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 159 | atomic_t				vc_resource; | 
|  | 160 | atomic_t				vp_resource; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 161 |  | 
|  | 162 | struct workqueue_struct	*vcap_wq; | 
|  | 163 | struct vp_work_t		vp_work; | 
|  | 164 | struct vp_work_t		vc_to_vp_work; | 
|  | 165 | struct vp_work_t		vp_to_vc_work; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 166 | }; | 
|  | 167 |  | 
|  | 168 | struct vp_format_data { | 
|  | 169 | unsigned int		width, height; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 170 | unsigned int		pixfmt; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 171 | }; | 
|  | 172 |  | 
|  | 173 | struct vcap_buffer { | 
|  | 174 | /* common v4l buffer stuff -- must be first */ | 
|  | 175 | struct vb2_buffer	vb; | 
|  | 176 | struct list_head	list; | 
|  | 177 | unsigned long		paddr; | 
|  | 178 | struct ion_handle   *ion_handle; | 
|  | 179 | }; | 
|  | 180 |  | 
|  | 181 | struct vcap_client_data { | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 182 | bool set_cap, set_decode, set_vp_o; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 183 | struct vcap_dev *dev; | 
|  | 184 |  | 
|  | 185 | struct vb2_queue		vc_vidq; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 186 | struct vb2_queue		vp_in_vidq; | 
|  | 187 | struct vb2_queue		vp_out_vidq; | 
|  | 188 |  | 
|  | 189 | enum vcap_op_mode		op_mode; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 190 |  | 
|  | 191 | struct v4l2_format_vc_ext vc_format; | 
|  | 192 |  | 
|  | 193 | enum v4l2_buf_type		vp_buf_type_field; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 194 | struct vp_format_data	vp_in_fmt; | 
|  | 195 | struct vp_format_data	vp_out_fmt; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 196 |  | 
|  | 197 | struct vcap_action		vid_vc_action; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 198 | struct vp_action		vid_vp_action; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 199 | struct workqueue_struct *vcap_work_q; | 
|  | 200 | struct ion_handle			*vc_ion_handle; | 
|  | 201 |  | 
|  | 202 | uint32_t				hold_vc; | 
|  | 203 | uint32_t				hold_vp; | 
|  | 204 |  | 
|  | 205 | spinlock_t				cap_slock; | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 206 | bool					streaming; | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 207 | }; | 
|  | 208 |  | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 209 | struct vcap_hacked_vals { | 
|  | 210 | uint32_t	value; | 
|  | 211 | uint32_t	offset; | 
|  | 212 | }; | 
|  | 213 |  | 
|  | 214 | extern struct vcap_hacked_vals hacked_buf[]; | 
|  | 215 |  | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 216 | #endif | 
| Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame^] | 217 | int free_ion_handle(struct vcap_dev *dev, struct vb2_queue *q, | 
|  | 218 | struct v4l2_buffer *b); | 
|  | 219 |  | 
|  | 220 | int get_phys_addr(struct vcap_dev *dev, struct vb2_queue *q, | 
|  | 221 | struct v4l2_buffer *b); | 
| Terence Hampson | a6914ca | 2012-04-09 14:06:50 -0400 | [diff] [blame] | 222 | #endif |