Terence Hampson | aeb793e | 2012-05-11 11:41:16 -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 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/kthread.h> |
| 17 | #include <linux/freezer.h> |
| 18 | #include <mach/camera.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <mach/clk.h> |
| 21 | #include <linux/clk.h> |
| 22 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 23 | #include <media/v4l2-event.h> |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 24 | #include <media/vcap_v4l2.h> |
| 25 | #include <media/vcap_fmt.h> |
| 26 | #include "vcap_vp.h" |
| 27 | |
| 28 | static unsigned debug; |
| 29 | |
| 30 | #define dprintk(level, fmt, arg...) \ |
| 31 | do { \ |
| 32 | if (debug >= level) \ |
| 33 | printk(KERN_DEBUG "VP: " fmt, ## arg); \ |
| 34 | } while (0) |
| 35 | |
| 36 | void config_nr_buffer(struct vcap_client_data *c_data, |
| 37 | struct vcap_buffer *buf) |
| 38 | { |
| 39 | struct vcap_dev *dev = c_data->dev; |
| 40 | int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 41 | |
| 42 | writel_relaxed(buf->paddr, VCAP_VP_NR_T2_Y_BASE_ADDR); |
| 43 | writel_relaxed(buf->paddr + size, VCAP_VP_NR_T2_C_BASE_ADDR); |
| 44 | } |
| 45 | |
| 46 | void config_in_buffer(struct vcap_client_data *c_data, |
| 47 | struct vcap_buffer *buf) |
| 48 | { |
| 49 | struct vcap_dev *dev = c_data->dev; |
| 50 | int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 51 | |
| 52 | writel_relaxed(buf->paddr, VCAP_VP_T2_Y_BASE_ADDR); |
| 53 | writel_relaxed(buf->paddr + size, VCAP_VP_T2_C_BASE_ADDR); |
| 54 | } |
| 55 | |
| 56 | void config_out_buffer(struct vcap_client_data *c_data, |
| 57 | struct vcap_buffer *buf) |
| 58 | { |
| 59 | struct vcap_dev *dev = c_data->dev; |
| 60 | int size; |
| 61 | size = c_data->vp_out_fmt.height * c_data->vp_out_fmt.width; |
| 62 | writel_relaxed(buf->paddr, VCAP_VP_OUT_Y_BASE_ADDR); |
| 63 | writel_relaxed(buf->paddr + size, VCAP_VP_OUT_C_BASE_ADDR); |
| 64 | } |
| 65 | |
| 66 | int vp_setup_buffers(struct vcap_client_data *c_data) |
| 67 | { |
| 68 | struct vp_action *vp_act; |
| 69 | struct vcap_dev *dev; |
| 70 | unsigned long flags = 0; |
| 71 | |
| 72 | if (!c_data->streaming) |
| 73 | return -ENOEXEC; |
| 74 | dev = c_data->dev; |
| 75 | dprintk(2, "Start setup buffers\n"); |
| 76 | |
| 77 | /* No need to verify vp_client is not NULL caller does so */ |
| 78 | vp_act = &dev->vp_client->vid_vp_action; |
| 79 | |
| 80 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 81 | if (list_empty(&vp_act->in_active)) { |
| 82 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 83 | dprintk(1, "%s: VP We have no more input buffers\n", |
| 84 | __func__); |
| 85 | return -EAGAIN; |
| 86 | } |
| 87 | |
| 88 | if (list_empty(&vp_act->out_active)) { |
| 89 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, |
| 90 | flags); |
| 91 | dprintk(1, "%s: VP We have no more output buffers\n", |
| 92 | __func__); |
| 93 | return -EAGAIN; |
| 94 | } |
| 95 | |
| 96 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 97 | struct vcap_buffer, list); |
| 98 | list_del(&vp_act->bufT2->list); |
| 99 | |
| 100 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 101 | struct vcap_buffer, list); |
| 102 | list_del(&vp_act->bufOut->list); |
| 103 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 104 | |
| 105 | config_in_buffer(c_data, vp_act->bufT2); |
| 106 | config_out_buffer(c_data, vp_act->bufOut); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static void mov_buf_to_vc(struct work_struct *work) |
| 111 | { |
| 112 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 113 | struct v4l2_buffer p; |
| 114 | struct vb2_buffer *vb_vc; |
| 115 | struct vcap_buffer *buf_vc; |
| 116 | struct vb2_buffer *vb_vp; |
| 117 | struct vcap_buffer *buf_vp; |
| 118 | int rc; |
| 119 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 120 | p.memory = V4L2_MEMORY_USERPTR; |
| 121 | |
| 122 | /* This loop exits when there is no more buffers left */ |
| 123 | while (1) { |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 124 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 125 | if (!vp_work->cd->streaming) |
| 126 | return; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 127 | rc = vcvp_dqbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 128 | if (rc < 0) |
| 129 | return; |
| 130 | |
| 131 | vb_vc = vp_work->cd->vc_vidq.bufs[p.index]; |
| 132 | if (NULL == vb_vc) { |
| 133 | dprintk(1, "%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 134 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | buf_vc = container_of(vb_vc, struct vcap_buffer, vb); |
| 138 | |
| 139 | vb_vp = vp_work->cd->vp_in_vidq.bufs[p.index]; |
| 140 | if (NULL == vb_vp) { |
| 141 | dprintk(1, "%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 142 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | buf_vp = container_of(vb_vp, struct vcap_buffer, vb); |
| 146 | buf_vc->ion_handle = buf_vp->ion_handle; |
| 147 | buf_vc->paddr = buf_vp->paddr; |
| 148 | buf_vp->ion_handle = NULL; |
| 149 | buf_vp->paddr = 0; |
| 150 | |
| 151 | p.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 152 | /* This call should not fail */ |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 153 | rc = vcvp_qbuf(&vp_work->cd->vc_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 154 | if (rc < 0) { |
| 155 | dprintk(1, "%s: qbuf to vc failed\n", __func__); |
| 156 | buf_vp->ion_handle = buf_vc->ion_handle; |
| 157 | buf_vp->paddr = buf_vc->paddr; |
| 158 | buf_vc->ion_handle = NULL; |
| 159 | buf_vc->paddr = 0; |
| 160 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 161 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void vp_wq_fnc(struct work_struct *work) |
| 167 | { |
| 168 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 169 | struct vcap_dev *dev; |
| 170 | struct vp_action *vp_act; |
| 171 | uint32_t irq; |
| 172 | int rc; |
| 173 | #ifndef TOP_FIELD_FIX |
| 174 | bool top_field; |
| 175 | #endif |
| 176 | |
| 177 | if (vp_work && vp_work->cd && vp_work->cd->dev) |
| 178 | dev = vp_work->cd->dev; |
| 179 | else |
| 180 | return; |
| 181 | |
| 182 | vp_act = &dev->vp_client->vid_vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 183 | |
| 184 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 185 | while (!(rc & 0x00000100)) |
| 186 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 187 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 188 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
| 189 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 190 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 191 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 192 | |
| 193 | /* Queue the done buffers */ |
| 194 | if (vp_act->vp_state == VP_NORMAL && |
| 195 | vp_act->bufNR.nr_pos != TM1_BUF) { |
| 196 | vb2_buffer_done(&vp_act->bufTm1->vb, VB2_BUF_STATE_DONE); |
| 197 | if (vp_work->cd->op_mode == VC_AND_VP_VCAP_OP) |
| 198 | queue_work(dev->vcap_wq, &dev->vp_to_vc_work.work); |
| 199 | } |
| 200 | |
| 201 | vb2_buffer_done(&vp_act->bufOut->vb, VB2_BUF_STATE_DONE); |
| 202 | |
| 203 | /* Cycle to next state */ |
| 204 | if (vp_act->vp_state != VP_NORMAL) |
| 205 | vp_act->vp_state++; |
| 206 | #ifdef TOP_FIELD_FIX |
| 207 | vp_act->top_field = !vp_act->top_field; |
| 208 | #endif |
| 209 | |
| 210 | /* Cycle Buffers*/ |
| 211 | if (vp_work->cd->vid_vp_action.nr_enabled) { |
| 212 | if (vp_act->bufNR.nr_pos == TM1_BUF) |
| 213 | vp_act->bufNR.nr_pos = BUF_NOT_IN_USE; |
| 214 | |
| 215 | if (vp_act->bufNR.nr_pos != BUF_NOT_IN_USE) |
| 216 | vp_act->bufNR.nr_pos++; |
| 217 | |
| 218 | vp_act->bufTm1 = vp_act->bufT0; |
| 219 | vp_act->bufT0 = vp_act->bufT1; |
| 220 | vp_act->bufT1 = vp_act->bufNRT2; |
| 221 | vp_act->bufNRT2 = vp_act->bufT2; |
| 222 | config_nr_buffer(vp_work->cd, vp_act->bufNRT2); |
| 223 | } else { |
| 224 | vp_act->bufTm1 = vp_act->bufT0; |
| 225 | vp_act->bufT0 = vp_act->bufT1; |
| 226 | vp_act->bufT1 = vp_act->bufT2; |
| 227 | } |
| 228 | |
| 229 | rc = vp_setup_buffers(vp_work->cd); |
| 230 | if (rc < 0) { |
| 231 | /* setup_buf failed because we are waiting for buffers */ |
| 232 | writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE); |
| 233 | writel_iowmb(irq, VCAP_VP_INT_CLEAR); |
| 234 | atomic_set(&dev->vp_enabled, 0); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | /* Config VP */ |
| 239 | #ifndef TOP_FIELD_FIX |
| 240 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 241 | top_field = 1; |
| 242 | #endif |
| 243 | |
| 244 | #ifdef TOP_FIELD_FIX |
| 245 | writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 246 | writel_iowmb(0x00030000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 247 | #else |
| 248 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
| 249 | writel_iowmb(0x00030000 | top_field, VCAP_VP_CTRL); |
| 250 | #endif |
| 251 | enable_irq(dev->vpirq->start); |
| 252 | writel_iowmb(irq, VCAP_VP_INT_CLEAR); |
| 253 | } |
| 254 | |
| 255 | irqreturn_t vp_handler(struct vcap_dev *dev) |
| 256 | { |
| 257 | struct vcap_client_data *c_data; |
| 258 | struct vp_action *vp_act; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 259 | struct v4l2_event v4l2_evt; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 260 | uint32_t irq; |
| 261 | int rc; |
| 262 | |
| 263 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame^] | 264 | if (dev->vp_dummy_event == true) { |
| 265 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 266 | dev->vp_dummy_complete = true; |
| 267 | wake_up(&dev->vp_dummy_waitq); |
| 268 | return IRQ_HANDLED; |
| 269 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 270 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 271 | if (irq & 0x02000000) { |
| 272 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 273 | VCAP_VP_REG_R_ERR_EVENT; |
| 274 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 275 | } |
| 276 | if (irq & 0x01000000) { |
| 277 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 278 | VCAP_VC_LINE_ERR_EVENT; |
| 279 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 280 | } |
| 281 | if (irq & 0x00020000) { |
| 282 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 283 | VCAP_VP_IN_HEIGHT_ERR_EVENT; |
| 284 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 285 | } |
| 286 | if (irq & 0x00010000) { |
| 287 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 288 | VCAP_VP_IN_WIDTH_ERR_EVENT; |
| 289 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 290 | } |
| 291 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 292 | dprintk(1, "%s: irq=0x%08x\n", __func__, irq); |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 293 | if (!(irq & (VP_PIC_DONE || VP_MODE_CHANGE))) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 294 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 295 | pr_err("VP IRQ shows some error\n"); |
| 296 | return IRQ_HANDLED; |
| 297 | } |
| 298 | |
| 299 | if (dev->vp_client == NULL) { |
| 300 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 301 | pr_err("VC: There is no active vp client\n"); |
| 302 | return IRQ_HANDLED; |
| 303 | } |
| 304 | |
| 305 | vp_act = &dev->vp_client->vid_vp_action; |
| 306 | c_data = dev->vp_client; |
| 307 | |
| 308 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 309 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 310 | pr_err("%s: VP is in an unknown state\n", |
| 311 | __func__); |
| 312 | return -EAGAIN; |
| 313 | } |
| 314 | |
| 315 | INIT_WORK(&dev->vp_work.work, vp_wq_fnc); |
| 316 | dev->vp_work.cd = c_data; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 317 | rc = queue_work(dev->vcap_wq, &dev->vp_work.work); |
| 318 | |
| 319 | disable_irq_nosync(dev->vpirq->start); |
| 320 | return IRQ_HANDLED; |
| 321 | } |
| 322 | |
| 323 | void vp_stop_capture(struct vcap_client_data *c_data) |
| 324 | { |
| 325 | struct vcap_dev *dev = c_data->dev; |
| 326 | |
| 327 | writel_iowmb(0x00000000, VCAP_VP_CTRL); |
| 328 | flush_workqueue(dev->vcap_wq); |
| 329 | |
| 330 | if (atomic_read(&dev->vp_enabled) == 1) |
| 331 | disable_irq(dev->vpirq->start); |
| 332 | |
| 333 | writel_iowmb(0x00000001, VCAP_VP_SW_RESET); |
| 334 | writel_iowmb(0x00000000, VCAP_VP_SW_RESET); |
| 335 | } |
| 336 | |
| 337 | int config_vp_format(struct vcap_client_data *c_data) |
| 338 | { |
| 339 | struct vcap_dev *dev = c_data->dev; |
| 340 | |
| 341 | INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc); |
| 342 | dev->vp_to_vc_work.cd = c_data; |
| 343 | |
| 344 | /* SW restart VP */ |
| 345 | writel_iowmb(0x00000001, VCAP_VP_SW_RESET); |
| 346 | writel_iowmb(0x00000000, VCAP_VP_SW_RESET); |
| 347 | |
| 348 | /* Film Mode related settings */ |
| 349 | writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0); |
| 350 | writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2); |
| 351 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ); |
| 352 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ); |
| 353 | writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST); |
| 354 | writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE); |
| 355 | |
| 356 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 357 | writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION); |
| 358 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 359 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA); |
| 360 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA); |
| 361 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA); |
| 362 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA); |
| 363 | writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND); |
| 364 | writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST); |
| 365 | writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG); |
| 366 | writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG); |
| 367 | writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG); |
| 368 | writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2); |
| 369 | writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG); |
| 370 | writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG); |
| 371 | writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2); |
| 372 | writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3); |
| 373 | writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG); |
| 374 | writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG); |
| 375 | writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG); |
| 376 | writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG); |
| 377 | writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG); |
| 378 | writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG); |
| 379 | writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG); |
| 380 | writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG); |
| 381 | writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB); |
| 382 | writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG); |
| 383 | writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2); |
| 384 | writel_relaxed((c_data->vp_out_fmt.height-1)<<16 | |
| 385 | (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE); |
| 386 | writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL); |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | int init_motion_buf(struct vcap_client_data *c_data) |
| 392 | { |
| 393 | struct vcap_dev *dev = c_data->dev; |
| 394 | void *buf; |
| 395 | unsigned long motion_base_addr; |
| 396 | uint32_t size = ((c_data->vp_out_fmt.width + 63) >> 6) * |
| 397 | ((c_data->vp_out_fmt.height + 7) >> 3) * 16; |
| 398 | |
| 399 | if (c_data->vid_vp_action.bufMotion) { |
| 400 | pr_err("Motion buffer has already been created"); |
| 401 | return -ENOEXEC; |
| 402 | } |
| 403 | |
| 404 | buf = kzalloc(size, GFP_KERNEL); |
| 405 | if (!buf) |
| 406 | return -ENOMEM; |
| 407 | |
| 408 | c_data->vid_vp_action.bufMotion = buf; |
| 409 | motion_base_addr = virt_to_phys(buf); |
| 410 | writel_iowmb(motion_base_addr, VCAP_VP_MOTION_EST_ADDR); |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | void deinit_motion_buf(struct vcap_client_data *c_data) |
| 415 | { |
| 416 | struct vcap_dev *dev = c_data->dev; |
| 417 | void *buf; |
| 418 | |
| 419 | if (!c_data->vid_vp_action.bufMotion) { |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 420 | pr_err("Motion buffer has not been created"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | |
| 424 | buf = c_data->vid_vp_action.bufMotion; |
| 425 | |
| 426 | writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR); |
| 427 | c_data->vid_vp_action.bufMotion = NULL; |
| 428 | kfree(buf); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | int init_nr_buf(struct vcap_client_data *c_data) |
| 433 | { |
| 434 | struct vcap_dev *dev = c_data->dev; |
| 435 | struct nr_buffer *buf; |
| 436 | uint32_t frame_size, tot_size, rc; |
| 437 | |
| 438 | if (c_data->vid_vp_action.bufNR.vaddr) { |
| 439 | pr_err("NR buffer has already been created"); |
| 440 | return -ENOEXEC; |
| 441 | } |
| 442 | buf = &c_data->vid_vp_action.bufNR; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame^] | 443 | if (!buf) |
| 444 | return -ENOMEM; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 445 | |
| 446 | frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height; |
| 447 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 448 | tot_size = frame_size * 2; |
| 449 | else |
| 450 | tot_size = frame_size / 2 * 3; |
| 451 | |
| 452 | buf->vaddr = kzalloc(tot_size, GFP_KERNEL); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame^] | 453 | if (!buf->vaddr) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 454 | return -ENOMEM; |
| 455 | |
| 456 | buf->paddr = virt_to_phys(buf->vaddr); |
| 457 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
| 458 | rc |= 0x02D00001; |
| 459 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
| 460 | writel_relaxed(buf->paddr, VCAP_VP_NR_T2_Y_BASE_ADDR); |
| 461 | writel_relaxed(buf->paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR); |
| 462 | buf->nr_pos = NRT2_BUF; |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | void deinit_nr_buf(struct vcap_client_data *c_data) |
| 467 | { |
| 468 | struct vcap_dev *dev = c_data->dev; |
| 469 | struct nr_buffer *buf; |
| 470 | uint32_t rc; |
| 471 | |
| 472 | if (!c_data->vid_vp_action.bufNR.vaddr) { |
| 473 | pr_err("NR buffer has not been created"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | buf = &c_data->vid_vp_action.bufNR; |
| 478 | |
| 479 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
| 480 | rc &= !(0x02D00001); |
| 481 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
| 482 | |
| 483 | kfree(buf->vaddr); |
| 484 | buf->paddr = 0; |
| 485 | buf->vaddr = NULL; |
| 486 | return; |
| 487 | } |
| 488 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame^] | 489 | int vp_dummy_event(struct vcap_client_data *c_data) |
| 490 | { |
| 491 | struct vcap_dev *dev = c_data->dev; |
| 492 | unsigned int width, height; |
| 493 | unsigned long paddr; |
| 494 | void *temp; |
| 495 | uint32_t reg; |
| 496 | int rc = 0; |
| 497 | |
| 498 | dprintk(2, "%s: Start VP dummy event\n", __func__); |
| 499 | temp = kzalloc(0x1200, GFP_KERNEL); |
| 500 | if (!temp) { |
| 501 | pr_err("%s: Failed to alloc mem", __func__); |
| 502 | return -ENOMEM; |
| 503 | } |
| 504 | paddr = virt_to_phys(temp); |
| 505 | |
| 506 | width = c_data->vp_out_fmt.width; |
| 507 | height = c_data->vp_out_fmt.height; |
| 508 | |
| 509 | c_data->vp_out_fmt.width = 0x3F; |
| 510 | c_data->vp_out_fmt.height = 0x16; |
| 511 | |
| 512 | config_vp_format(c_data); |
| 513 | writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 514 | writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR); |
| 515 | writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR); |
| 516 | writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR); |
| 517 | writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR); |
| 518 | writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR); |
| 519 | writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR); |
| 520 | writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 521 | writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 522 | |
| 523 | dev->vp_dummy_event = true; |
| 524 | |
| 525 | writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE); |
| 526 | writel_iowmb(0x00000000, VCAP_VP_CTRL); |
| 527 | writel_iowmb(0x00030000, VCAP_VP_CTRL); |
| 528 | |
| 529 | enable_irq(dev->vpirq->start); |
| 530 | rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq, |
| 531 | dev->vp_dummy_complete, msecs_to_jiffies(50)); |
| 532 | if (!rc && !dev->vp_dummy_complete) { |
| 533 | pr_err("%s: VP dummy event timeout", __func__); |
| 534 | rc = -ETIME; |
| 535 | writel_iowmb(0x00000000, VCAP_VP_CTRL); |
| 536 | |
| 537 | writel_iowmb(0x00000001, VCAP_VP_SW_RESET); |
| 538 | writel_iowmb(0x00000000, VCAP_VP_SW_RESET); |
| 539 | dev->vp_dummy_complete = false; |
| 540 | } |
| 541 | |
| 542 | writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE); |
| 543 | disable_irq(dev->vpirq->start); |
| 544 | dev->vp_dummy_event = false; |
| 545 | |
| 546 | reg = readl_relaxed(VCAP_OFFSET(0x0D94)); |
| 547 | writel_relaxed(reg, VCAP_OFFSET(0x0D9C)); |
| 548 | |
| 549 | c_data->vp_out_fmt.width = width; |
| 550 | c_data->vp_out_fmt.height = height; |
| 551 | kfree(temp); |
| 552 | |
| 553 | dprintk(2, "%s: Exit VP dummy event\n", __func__); |
| 554 | return rc; |
| 555 | } |
| 556 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 557 | int kickoff_vp(struct vcap_client_data *c_data) |
| 558 | { |
| 559 | struct vcap_dev *dev; |
| 560 | struct vp_action *vp_act; |
| 561 | unsigned long flags = 0; |
| 562 | unsigned int chroma_fmt = 0; |
| 563 | int size; |
| 564 | #ifndef TOP_FIELD_FIX |
| 565 | bool top_field; |
| 566 | #endif |
| 567 | |
| 568 | if (!c_data->streaming) |
| 569 | return -ENOEXEC; |
| 570 | |
| 571 | dev = c_data->dev; |
| 572 | dprintk(2, "Start Kickoff\n"); |
| 573 | |
| 574 | if (dev->vp_client == NULL) { |
| 575 | pr_err("No active vp client\n"); |
| 576 | return -ENODEV; |
| 577 | } |
| 578 | vp_act = &dev->vp_client->vid_vp_action; |
| 579 | |
| 580 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 581 | if (list_empty(&vp_act->in_active)) { |
| 582 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 583 | pr_err("%s: VP We have no more input buffers\n", |
| 584 | __func__); |
| 585 | return -EAGAIN; |
| 586 | } |
| 587 | |
| 588 | vp_act->bufT1 = list_entry(vp_act->in_active.next, |
| 589 | struct vcap_buffer, list); |
| 590 | list_del(&vp_act->bufT1->list); |
| 591 | |
| 592 | if (list_empty(&vp_act->in_active)) { |
| 593 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 594 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 595 | pr_err("%s: VP We have no more input buffers\n", |
| 596 | __func__); |
| 597 | return -EAGAIN; |
| 598 | } |
| 599 | |
| 600 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 601 | struct vcap_buffer, list); |
| 602 | list_del(&vp_act->bufT2->list); |
| 603 | |
| 604 | if (list_empty(&vp_act->out_active)) { |
| 605 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 606 | list_add(&vp_act->bufT2->list, &vp_act->in_active); |
| 607 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 608 | pr_err("%s: VP We have no more output buffers\n", |
| 609 | __func__); |
| 610 | return -EAGAIN; |
| 611 | } |
| 612 | |
| 613 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 614 | struct vcap_buffer, list); |
| 615 | list_del(&vp_act->bufOut->list); |
| 616 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 617 | |
| 618 | size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 619 | writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 620 | writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR); |
| 621 | |
| 622 | config_in_buffer(c_data, vp_act->bufT2); |
| 623 | config_out_buffer(c_data, vp_act->bufOut); |
| 624 | |
| 625 | /* Config VP */ |
| 626 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 627 | chroma_fmt = 1; |
| 628 | writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 | |
| 629 | chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 630 | |
| 631 | chroma_fmt = 0; |
Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 632 | if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 633 | chroma_fmt = 1; |
| 634 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 635 | writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 636 | chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 637 | |
| 638 | /* Enable Interrupt */ |
| 639 | #ifdef TOP_FIELD_FIX |
| 640 | vp_act->top_field = 1; |
| 641 | #else |
| 642 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 643 | top_field = 1; |
| 644 | #endif |
| 645 | vp_act->vp_state = VP_FRAME2; |
| 646 | writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE); |
| 647 | #ifdef TOP_FIELD_FIX |
| 648 | writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 649 | writel_iowmb(0x00030000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 650 | #else |
| 651 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
| 652 | writel_iowmb(0x00030000 | top_field, VCAP_VP_CTRL); |
| 653 | #endif |
| 654 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 655 | enable_irq(dev->vpirq->start); |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | int continue_vp(struct vcap_client_data *c_data) |
| 660 | { |
| 661 | struct vcap_dev *dev; |
| 662 | struct vp_action *vp_act; |
| 663 | int rc; |
| 664 | #ifndef TOP_FIELD_FIX |
| 665 | bool top_field; |
| 666 | #endif |
| 667 | |
| 668 | dprintk(2, "Start Continue\n"); |
| 669 | dev = c_data->dev; |
| 670 | |
| 671 | if (dev->vp_client == NULL) { |
| 672 | pr_err("No active vp client\n"); |
| 673 | return -ENODEV; |
| 674 | } |
| 675 | vp_act = &dev->vp_client->vid_vp_action; |
| 676 | |
| 677 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 678 | pr_err("%s: VP is in an unknown state\n", |
| 679 | __func__); |
| 680 | return -EAGAIN; |
| 681 | } |
| 682 | |
| 683 | rc = vp_setup_buffers(c_data); |
| 684 | if (rc < 0) |
| 685 | return rc; |
| 686 | |
| 687 | #ifndef TOP_FIELD_FIX |
| 688 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 689 | top_field = 1; |
| 690 | #endif |
| 691 | |
| 692 | /* Config VP & Enable Interrupt */ |
| 693 | writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE); |
| 694 | #ifdef TOP_FIELD_FIX |
| 695 | writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 696 | writel_iowmb(0x00030000 | vp_act->top_field << 0, VCAP_VP_CTRL); |
| 697 | #else |
| 698 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
| 699 | writel_iowmb(0x00030000 | top_field, VCAP_VP_CTRL); |
| 700 | #endif |
| 701 | |
| 702 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 703 | enable_irq(dev->vpirq->start); |
| 704 | return 0; |
| 705 | } |