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 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 77 | if (dev->vp_shutdown) { |
| 78 | dprintk(1, "%s: VP shutting down, no buf setup\n", |
| 79 | __func__); |
| 80 | return -EPERM; |
| 81 | } |
| 82 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 83 | /* No need to verify vp_client is not NULL caller does so */ |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 84 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 85 | |
| 86 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 87 | if (list_empty(&vp_act->in_active)) { |
| 88 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 89 | dprintk(1, "%s: VP We have no more input buffers\n", |
| 90 | __func__); |
| 91 | return -EAGAIN; |
| 92 | } |
| 93 | |
| 94 | if (list_empty(&vp_act->out_active)) { |
| 95 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, |
| 96 | flags); |
| 97 | dprintk(1, "%s: VP We have no more output buffers\n", |
| 98 | __func__); |
| 99 | return -EAGAIN; |
| 100 | } |
| 101 | |
| 102 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 103 | struct vcap_buffer, list); |
| 104 | list_del(&vp_act->bufT2->list); |
| 105 | |
| 106 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 107 | struct vcap_buffer, list); |
| 108 | list_del(&vp_act->bufOut->list); |
| 109 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 110 | |
| 111 | config_in_buffer(c_data, vp_act->bufT2); |
| 112 | config_out_buffer(c_data, vp_act->bufOut); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static void mov_buf_to_vc(struct work_struct *work) |
| 117 | { |
| 118 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 119 | struct v4l2_buffer p; |
| 120 | struct vb2_buffer *vb_vc; |
| 121 | struct vcap_buffer *buf_vc; |
| 122 | struct vb2_buffer *vb_vp; |
| 123 | struct vcap_buffer *buf_vp; |
| 124 | int rc; |
| 125 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 126 | p.memory = V4L2_MEMORY_USERPTR; |
| 127 | |
| 128 | /* This loop exits when there is no more buffers left */ |
| 129 | while (1) { |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 130 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 131 | if (!vp_work->cd->streaming) |
| 132 | return; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 133 | rc = vcvp_dqbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 134 | if (rc < 0) |
| 135 | return; |
| 136 | |
| 137 | vb_vc = vp_work->cd->vc_vidq.bufs[p.index]; |
| 138 | if (NULL == vb_vc) { |
| 139 | dprintk(1, "%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 140 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | buf_vc = container_of(vb_vc, struct vcap_buffer, vb); |
| 144 | |
| 145 | vb_vp = vp_work->cd->vp_in_vidq.bufs[p.index]; |
| 146 | if (NULL == vb_vp) { |
| 147 | dprintk(1, "%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 148 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 149 | return; |
| 150 | } |
| 151 | buf_vp = container_of(vb_vp, struct vcap_buffer, vb); |
| 152 | buf_vc->ion_handle = buf_vp->ion_handle; |
| 153 | buf_vc->paddr = buf_vp->paddr; |
| 154 | buf_vp->ion_handle = NULL; |
| 155 | buf_vp->paddr = 0; |
| 156 | |
| 157 | p.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 158 | /* This call should not fail */ |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 159 | rc = vcvp_qbuf(&vp_work->cd->vc_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 160 | if (rc < 0) { |
| 161 | dprintk(1, "%s: qbuf to vc failed\n", __func__); |
| 162 | buf_vp->ion_handle = buf_vc->ion_handle; |
| 163 | buf_vp->paddr = buf_vc->paddr; |
| 164 | buf_vc->ion_handle = NULL; |
| 165 | buf_vc->paddr = 0; |
| 166 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 167 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 172 | void update_nr_value(struct vcap_dev *dev) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 173 | { |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 174 | struct nr_param *par; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 175 | par = &dev->nr_param; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 176 | if (par->mode == NR_MANUAL) { |
| 177 | writel_relaxed(par->window << 24 | par->decay_ratio << 20, |
| 178 | VCAP_VP_NR_CONFIG); |
| 179 | writel_relaxed(par->luma.max_blend_ratio << 24 | |
| 180 | par->luma.scale_diff_ratio << 12 | |
| 181 | par->luma.diff_limit_ratio << 8 | |
| 182 | par->luma.scale_motion_ratio << 4 | |
| 183 | par->luma.blend_limit_ratio << 0, |
| 184 | VCAP_VP_NR_LUMA_CONFIG); |
| 185 | writel_relaxed(par->chroma.max_blend_ratio << 24 | |
| 186 | par->chroma.scale_diff_ratio << 12 | |
| 187 | par->chroma.diff_limit_ratio << 8 | |
| 188 | par->chroma.scale_motion_ratio << 4 | |
| 189 | par->chroma.blend_limit_ratio << 0, |
| 190 | VCAP_VP_NR_CHROMA_CONFIG); |
| 191 | } |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 192 | dev->nr_update = false; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 195 | static void vp_wq_fnc(struct work_struct *work) |
| 196 | { |
| 197 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 198 | struct vcap_dev *dev; |
| 199 | struct vp_action *vp_act; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 200 | unsigned long flags = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 201 | uint32_t irq; |
| 202 | int rc; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 203 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 204 | |
| 205 | if (vp_work && vp_work->cd && vp_work->cd->dev) |
| 206 | dev = vp_work->cd->dev; |
| 207 | else |
| 208 | return; |
| 209 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 210 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 211 | |
| 212 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 213 | while (!(rc & 0x00000100)) |
| 214 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 215 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 216 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
| 217 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 218 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 219 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 220 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 221 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 222 | if (dev->nr_update == true) |
| 223 | update_nr_value(dev); |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 224 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 225 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 226 | /* Queue the done buffers */ |
| 227 | if (vp_act->vp_state == VP_NORMAL && |
| 228 | vp_act->bufNR.nr_pos != TM1_BUF) { |
| 229 | vb2_buffer_done(&vp_act->bufTm1->vb, VB2_BUF_STATE_DONE); |
| 230 | if (vp_work->cd->op_mode == VC_AND_VP_VCAP_OP) |
| 231 | queue_work(dev->vcap_wq, &dev->vp_to_vc_work.work); |
| 232 | } |
| 233 | |
Terence Hampson | 3af95c0 | 2012-09-18 16:43:38 -0400 | [diff] [blame] | 234 | if (vp_act->bufT0 != NULL && vp_act->vp_state == VP_NORMAL) { |
| 235 | vp_act->bufOut->vb.v4l2_buf.timestamp = |
| 236 | vp_act->bufT0->vb.v4l2_buf.timestamp; |
| 237 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 238 | vb2_buffer_done(&vp_act->bufOut->vb, VB2_BUF_STATE_DONE); |
| 239 | |
| 240 | /* Cycle to next state */ |
| 241 | if (vp_act->vp_state != VP_NORMAL) |
| 242 | vp_act->vp_state++; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 243 | |
| 244 | /* Cycle Buffers*/ |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 245 | if (dev->nr_param.mode) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 246 | if (vp_act->bufNR.nr_pos == TM1_BUF) |
| 247 | vp_act->bufNR.nr_pos = BUF_NOT_IN_USE; |
| 248 | |
| 249 | if (vp_act->bufNR.nr_pos != BUF_NOT_IN_USE) |
| 250 | vp_act->bufNR.nr_pos++; |
| 251 | |
| 252 | vp_act->bufTm1 = vp_act->bufT0; |
| 253 | vp_act->bufT0 = vp_act->bufT1; |
| 254 | vp_act->bufT1 = vp_act->bufNRT2; |
| 255 | vp_act->bufNRT2 = vp_act->bufT2; |
| 256 | config_nr_buffer(vp_work->cd, vp_act->bufNRT2); |
| 257 | } else { |
| 258 | vp_act->bufTm1 = vp_act->bufT0; |
| 259 | vp_act->bufT0 = vp_act->bufT1; |
| 260 | vp_act->bufT1 = vp_act->bufT2; |
| 261 | } |
| 262 | |
| 263 | rc = vp_setup_buffers(vp_work->cd); |
| 264 | if (rc < 0) { |
| 265 | /* setup_buf failed because we are waiting for buffers */ |
| 266 | writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE); |
| 267 | writel_iowmb(irq, VCAP_VP_INT_CLEAR); |
| 268 | atomic_set(&dev->vp_enabled, 0); |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 269 | if (dev->vp_shutdown) |
| 270 | wake_up(&dev->vp_dummy_waitq); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | |
| 274 | /* Config VP */ |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 275 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 276 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 277 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 278 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 279 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 280 | enable_irq(dev->vpirq->start); |
| 281 | writel_iowmb(irq, VCAP_VP_INT_CLEAR); |
| 282 | } |
| 283 | |
| 284 | irqreturn_t vp_handler(struct vcap_dev *dev) |
| 285 | { |
| 286 | struct vcap_client_data *c_data; |
| 287 | struct vp_action *vp_act; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 288 | struct v4l2_event v4l2_evt; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 289 | uint32_t irq; |
| 290 | int rc; |
| 291 | |
| 292 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 293 | if (dev->vp_dummy_event == true) { |
| 294 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 295 | dev->vp_dummy_complete = true; |
| 296 | wake_up(&dev->vp_dummy_waitq); |
| 297 | return IRQ_HANDLED; |
| 298 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 299 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 300 | if (irq & 0x02000000) { |
| 301 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 302 | VCAP_VP_REG_R_ERR_EVENT; |
| 303 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 304 | } |
| 305 | if (irq & 0x01000000) { |
| 306 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
Terence Hampson | f3cd9a1 | 2012-09-21 11:18:02 -0400 | [diff] [blame^] | 307 | VCAP_VP_REG_W_ERR_EVENT; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 308 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 309 | } |
| 310 | if (irq & 0x00020000) { |
| 311 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 312 | VCAP_VP_IN_HEIGHT_ERR_EVENT; |
| 313 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 314 | } |
| 315 | if (irq & 0x00010000) { |
| 316 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 317 | VCAP_VP_IN_WIDTH_ERR_EVENT; |
| 318 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 319 | } |
| 320 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 321 | dprintk(1, "%s: irq=0x%08x\n", __func__, irq); |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 322 | if (!(irq & (VP_PIC_DONE | VP_MODE_CHANGE))) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 323 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 324 | pr_err("VP IRQ shows some error\n"); |
| 325 | return IRQ_HANDLED; |
| 326 | } |
| 327 | |
| 328 | if (dev->vp_client == NULL) { |
| 329 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 330 | pr_err("VC: There is no active vp client\n"); |
| 331 | return IRQ_HANDLED; |
| 332 | } |
| 333 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 334 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 335 | c_data = dev->vp_client; |
| 336 | |
| 337 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 338 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 339 | pr_err("%s: VP is in an unknown state\n", |
| 340 | __func__); |
| 341 | return -EAGAIN; |
| 342 | } |
| 343 | |
| 344 | INIT_WORK(&dev->vp_work.work, vp_wq_fnc); |
| 345 | dev->vp_work.cd = c_data; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 346 | rc = queue_work(dev->vcap_wq, &dev->vp_work.work); |
| 347 | |
| 348 | disable_irq_nosync(dev->vpirq->start); |
| 349 | return IRQ_HANDLED; |
| 350 | } |
| 351 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 352 | int vp_sw_reset(struct vcap_dev *dev) |
| 353 | { |
| 354 | int timeout; |
| 355 | writel_iowmb(0x00000010, VCAP_SW_RESET_REQ); |
| 356 | timeout = 10000; |
| 357 | while (1) { |
| 358 | if (!(readl_relaxed(VCAP_SW_RESET_STATUS) & 0x10)) |
| 359 | break; |
| 360 | timeout--; |
| 361 | if (timeout == 0) { |
| 362 | /* This should not happen */ |
| 363 | pr_err("VP is not resetting properly\n"); |
| 364 | writel_iowmb(0x00000000, VCAP_SW_RESET_REQ); |
| 365 | return -EINVAL; |
| 366 | } |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 371 | void vp_stop_capture(struct vcap_client_data *c_data) |
| 372 | { |
| 373 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 374 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 375 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 376 | dev->vp_shutdown = true; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 377 | flush_workqueue(dev->vcap_wq); |
| 378 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 379 | if (atomic_read(&dev->vp_enabled) == 1) { |
| 380 | rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq, |
| 381 | !atomic_read(&dev->vp_enabled), |
| 382 | msecs_to_jiffies(50)); |
| 383 | if (rc == 0 && atomic_read(&dev->vp_enabled) == 1) { |
| 384 | /* This should not happen, if it does hw is stuck */ |
| 385 | pr_err("%s: VP Timeout and VP still running\n", |
| 386 | __func__); |
| 387 | } |
| 388 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 389 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 390 | vp_sw_reset(dev); |
| 391 | dev->vp_shutdown = false; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | int config_vp_format(struct vcap_client_data *c_data) |
| 395 | { |
| 396 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 397 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 398 | |
| 399 | INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc); |
| 400 | dev->vp_to_vc_work.cd = c_data; |
| 401 | |
| 402 | /* SW restart VP */ |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 403 | rc = vp_sw_reset(dev); |
| 404 | if (rc < 0) |
| 405 | return rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 406 | |
| 407 | /* Film Mode related settings */ |
| 408 | writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0); |
| 409 | writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2); |
| 410 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ); |
| 411 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ); |
| 412 | writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST); |
| 413 | writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE); |
| 414 | |
| 415 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 416 | writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION); |
| 417 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 418 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA); |
| 419 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA); |
| 420 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA); |
| 421 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA); |
| 422 | writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND); |
| 423 | writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST); |
| 424 | writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG); |
| 425 | writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG); |
| 426 | writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG); |
| 427 | writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2); |
| 428 | writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG); |
| 429 | writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG); |
| 430 | writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2); |
| 431 | writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3); |
| 432 | writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG); |
| 433 | writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG); |
| 434 | writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG); |
| 435 | writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG); |
| 436 | writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG); |
| 437 | writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG); |
| 438 | writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG); |
| 439 | writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG); |
| 440 | writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB); |
| 441 | writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG); |
| 442 | writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2); |
| 443 | writel_relaxed((c_data->vp_out_fmt.height-1)<<16 | |
| 444 | (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE); |
| 445 | writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL); |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | int init_motion_buf(struct vcap_client_data *c_data) |
| 451 | { |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 452 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 453 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 454 | struct ion_handle *handle = NULL; |
| 455 | unsigned long paddr, ionflag = 0; |
| 456 | void *vaddr; |
| 457 | size_t len; |
| 458 | size_t size = ((c_data->vp_out_fmt.width + 63) >> 6) * |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 459 | ((c_data->vp_out_fmt.height + 7) >> 3) * 16; |
| 460 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 461 | if (c_data->vp_action.motionHandle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 462 | pr_err("Motion buffer has already been created"); |
| 463 | return -ENOEXEC; |
| 464 | } |
| 465 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 466 | handle = ion_alloc(dev->ion_client, size, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 467 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 468 | if (IS_ERR_OR_NULL(handle)) { |
| 469 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 470 | return -ENOMEM; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 471 | } |
| 472 | rc = ion_phys(dev->ion_client, handle, &paddr, &len); |
| 473 | if (rc < 0) { |
| 474 | pr_err("%s: ion_phys failed\n", __func__); |
| 475 | ion_free(dev->ion_client, handle); |
| 476 | return rc; |
| 477 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 478 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 479 | rc = ion_handle_get_flags(dev->ion_client, handle, &ionflag); |
| 480 | if (rc) { |
| 481 | pr_err("%s: get flags ion handle failed\n", __func__); |
| 482 | ion_free(dev->ion_client, handle); |
| 483 | return rc; |
| 484 | } |
| 485 | |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 486 | vaddr = ion_map_kernel(dev->ion_client, handle); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 487 | if (IS_ERR(vaddr)) { |
| 488 | pr_err("%s: Map motion buffer failed\n", __func__); |
| 489 | ion_free(dev->ion_client, handle); |
| 490 | rc = -ENOMEM; |
| 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | memset(vaddr, 0, size); |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 495 | c_data->vp_action.motionHandle = handle; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 496 | |
| 497 | vaddr = NULL; |
| 498 | ion_unmap_kernel(dev->ion_client, handle); |
| 499 | |
| 500 | writel_iowmb(paddr, VCAP_VP_MOTION_EST_ADDR); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | void deinit_motion_buf(struct vcap_client_data *c_data) |
| 505 | { |
| 506 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 507 | if (!c_data->vp_action.motionHandle) { |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 508 | pr_err("Motion buffer has not been created"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 509 | return; |
| 510 | } |
| 511 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 512 | writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR); |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 513 | ion_free(dev->ion_client, c_data->vp_action.motionHandle); |
| 514 | c_data->vp_action.motionHandle = NULL; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | |
| 518 | int init_nr_buf(struct vcap_client_data *c_data) |
| 519 | { |
| 520 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 521 | struct ion_handle *handle = NULL; |
| 522 | size_t frame_size, tot_size, len; |
| 523 | unsigned long paddr; |
| 524 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 525 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 526 | if (c_data->vp_action.bufNR.nr_handle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 527 | pr_err("NR buffer has already been created"); |
| 528 | return -ENOEXEC; |
| 529 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 530 | |
| 531 | frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height; |
| 532 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 533 | tot_size = frame_size * 2; |
| 534 | else |
| 535 | tot_size = frame_size / 2 * 3; |
| 536 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 537 | handle = ion_alloc(dev->ion_client, tot_size, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 538 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 539 | if (IS_ERR_OR_NULL(handle)) { |
| 540 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 541 | return -ENOMEM; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 542 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 543 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 544 | rc = ion_phys(dev->ion_client, handle, &paddr, &len); |
| 545 | if (rc < 0) { |
| 546 | pr_err("%s: ion_phys failed\n", __func__); |
| 547 | ion_free(dev->ion_client, handle); |
| 548 | return rc; |
| 549 | } |
| 550 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 551 | c_data->vp_action.bufNR.nr_handle = handle; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 552 | update_nr_value(dev); |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 553 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 554 | c_data->vp_action.bufNR.paddr = paddr; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 555 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 556 | rc |= (((c_data->vp_out_fmt.width / 16) << 20) | 0x1); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 557 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 558 | writel_relaxed(paddr, VCAP_VP_NR_T2_Y_BASE_ADDR); |
| 559 | writel_relaxed(paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR); |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 560 | c_data->vp_action.bufNR.nr_pos = NRT2_BUF; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | void deinit_nr_buf(struct vcap_client_data *c_data) |
| 565 | { |
| 566 | struct vcap_dev *dev = c_data->dev; |
| 567 | struct nr_buffer *buf; |
| 568 | uint32_t rc; |
| 569 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 570 | if (!c_data->vp_action.bufNR.nr_handle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 571 | pr_err("NR buffer has not been created"); |
| 572 | return; |
| 573 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 574 | buf = &c_data->vp_action.bufNR; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 575 | |
| 576 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 577 | rc &= !(0x0FF00001); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 578 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
| 579 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 580 | ion_free(dev->ion_client, buf->nr_handle); |
| 581 | buf->nr_handle = NULL; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 582 | buf->paddr = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 583 | return; |
| 584 | } |
| 585 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 586 | int nr_s_param(struct vcap_client_data *c_data, struct nr_param *param) |
| 587 | { |
| 588 | if (param->mode != NR_MANUAL) |
| 589 | return 0; |
| 590 | |
| 591 | /* Verify values in range */ |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 592 | if (param->window > VP_NR_MAX_WINDOW) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 593 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 594 | if (param->luma.max_blend_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 595 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 596 | if (param->luma.scale_diff_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 597 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 598 | if (param->luma.diff_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 599 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 600 | if (param->luma.scale_motion_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 601 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 602 | if (param->luma.blend_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 603 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 604 | if (param->chroma.max_blend_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 605 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 606 | if (param->chroma.scale_diff_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 607 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 608 | if (param->chroma.diff_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 609 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 610 | if (param->chroma.scale_motion_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 611 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 612 | if (param->chroma.blend_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 613 | return -EINVAL; |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | void nr_g_param(struct vcap_client_data *c_data, struct nr_param *param) |
| 618 | { |
| 619 | struct vcap_dev *dev = c_data->dev; |
| 620 | uint32_t rc; |
| 621 | rc = readl_relaxed(VCAP_VP_NR_CONFIG); |
| 622 | param->window = BITS_VALUE(rc, 24, 4); |
| 623 | param->decay_ratio = BITS_VALUE(rc, 20, 3); |
| 624 | |
| 625 | rc = readl_relaxed(VCAP_VP_NR_LUMA_CONFIG); |
| 626 | param->luma.max_blend_ratio = BITS_VALUE(rc, 24, 4); |
| 627 | param->luma.scale_diff_ratio = BITS_VALUE(rc, 12, 4); |
| 628 | param->luma.diff_limit_ratio = BITS_VALUE(rc, 8, 4); |
| 629 | param->luma.scale_motion_ratio = BITS_VALUE(rc, 4, 4); |
| 630 | param->luma.blend_limit_ratio = BITS_VALUE(rc, 0, 4); |
| 631 | |
| 632 | rc = readl_relaxed(VCAP_VP_NR_CHROMA_CONFIG); |
| 633 | param->chroma.max_blend_ratio = BITS_VALUE(rc, 24, 4); |
| 634 | param->chroma.scale_diff_ratio = BITS_VALUE(rc, 12, 4); |
| 635 | param->chroma.diff_limit_ratio = BITS_VALUE(rc, 8, 4); |
| 636 | param->chroma.scale_motion_ratio = BITS_VALUE(rc, 4, 4); |
| 637 | param->chroma.blend_limit_ratio = BITS_VALUE(rc, 0, 4); |
| 638 | } |
| 639 | |
| 640 | void s_default_nr_val(struct nr_param *param) |
| 641 | { |
| 642 | param->window = 10; |
| 643 | param->decay_ratio = 0; |
| 644 | param->luma.max_blend_ratio = 0; |
| 645 | param->luma.scale_diff_ratio = 4; |
| 646 | param->luma.diff_limit_ratio = 1; |
| 647 | param->luma.scale_motion_ratio = 4; |
| 648 | param->luma.blend_limit_ratio = 9; |
| 649 | param->chroma.max_blend_ratio = 0; |
| 650 | param->chroma.scale_diff_ratio = 4; |
| 651 | param->chroma.diff_limit_ratio = 1; |
| 652 | param->chroma.scale_motion_ratio = 4; |
| 653 | param->chroma.blend_limit_ratio = 9; |
| 654 | } |
| 655 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 656 | int vp_dummy_event(struct vcap_client_data *c_data) |
| 657 | { |
| 658 | struct vcap_dev *dev = c_data->dev; |
| 659 | unsigned int width, height; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 660 | struct ion_handle *handle = NULL; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 661 | unsigned long paddr; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 662 | size_t len; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 663 | uint32_t reg; |
| 664 | int rc = 0; |
| 665 | |
| 666 | dprintk(2, "%s: Start VP dummy event\n", __func__); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 667 | handle = ion_alloc(dev->ion_client, 0x1200, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 668 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 669 | if (IS_ERR_OR_NULL(handle)) { |
| 670 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 671 | return -ENOMEM; |
| 672 | } |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 673 | |
| 674 | rc = ion_phys(dev->ion_client, handle, &paddr, &len); |
| 675 | if (rc < 0) { |
| 676 | pr_err("%s: ion_phys failed\n", __func__); |
| 677 | ion_free(dev->ion_client, handle); |
| 678 | return rc; |
| 679 | } |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 680 | |
| 681 | width = c_data->vp_out_fmt.width; |
| 682 | height = c_data->vp_out_fmt.height; |
| 683 | |
| 684 | c_data->vp_out_fmt.width = 0x3F; |
| 685 | c_data->vp_out_fmt.height = 0x16; |
| 686 | |
| 687 | config_vp_format(c_data); |
| 688 | writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 689 | writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR); |
| 690 | writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR); |
| 691 | writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR); |
| 692 | writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR); |
| 693 | writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR); |
| 694 | writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR); |
| 695 | writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 696 | writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 697 | |
| 698 | dev->vp_dummy_event = true; |
| 699 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 700 | enable_irq(dev->vpirq->start); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 701 | writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE); |
| 702 | writel_iowmb(0x00000000, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 703 | writel_iowmb(0x00010000, VCAP_VP_CTRL); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 704 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 705 | rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq, |
| 706 | dev->vp_dummy_complete, msecs_to_jiffies(50)); |
| 707 | if (!rc && !dev->vp_dummy_complete) { |
| 708 | pr_err("%s: VP dummy event timeout", __func__); |
| 709 | rc = -ETIME; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 710 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 711 | vp_sw_reset(dev); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 712 | dev->vp_dummy_complete = false; |
| 713 | } |
| 714 | |
| 715 | writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE); |
| 716 | disable_irq(dev->vpirq->start); |
| 717 | dev->vp_dummy_event = false; |
| 718 | |
| 719 | reg = readl_relaxed(VCAP_OFFSET(0x0D94)); |
| 720 | writel_relaxed(reg, VCAP_OFFSET(0x0D9C)); |
| 721 | |
| 722 | c_data->vp_out_fmt.width = width; |
| 723 | c_data->vp_out_fmt.height = height; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 724 | ion_free(dev->ion_client, handle); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 725 | |
| 726 | dprintk(2, "%s: Exit VP dummy event\n", __func__); |
| 727 | return rc; |
| 728 | } |
| 729 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 730 | int kickoff_vp(struct vcap_client_data *c_data) |
| 731 | { |
| 732 | struct vcap_dev *dev; |
| 733 | struct vp_action *vp_act; |
| 734 | unsigned long flags = 0; |
| 735 | unsigned int chroma_fmt = 0; |
| 736 | int size; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 737 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 738 | |
| 739 | if (!c_data->streaming) |
| 740 | return -ENOEXEC; |
| 741 | |
| 742 | dev = c_data->dev; |
| 743 | dprintk(2, "Start Kickoff\n"); |
| 744 | |
| 745 | if (dev->vp_client == NULL) { |
| 746 | pr_err("No active vp client\n"); |
| 747 | return -ENODEV; |
| 748 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 749 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 750 | |
| 751 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 752 | if (list_empty(&vp_act->in_active)) { |
| 753 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 754 | pr_err("%s: VP We have no more input buffers\n", |
| 755 | __func__); |
| 756 | return -EAGAIN; |
| 757 | } |
| 758 | |
| 759 | vp_act->bufT1 = list_entry(vp_act->in_active.next, |
| 760 | struct vcap_buffer, list); |
| 761 | list_del(&vp_act->bufT1->list); |
| 762 | |
| 763 | if (list_empty(&vp_act->in_active)) { |
| 764 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 765 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 766 | pr_err("%s: VP We have no more input buffers\n", |
| 767 | __func__); |
| 768 | return -EAGAIN; |
| 769 | } |
| 770 | |
| 771 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 772 | struct vcap_buffer, list); |
| 773 | list_del(&vp_act->bufT2->list); |
| 774 | |
| 775 | if (list_empty(&vp_act->out_active)) { |
| 776 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 777 | list_add(&vp_act->bufT2->list, &vp_act->in_active); |
| 778 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 779 | pr_err("%s: VP We have no more output buffers\n", |
| 780 | __func__); |
| 781 | return -EAGAIN; |
| 782 | } |
| 783 | |
| 784 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 785 | struct vcap_buffer, list); |
| 786 | list_del(&vp_act->bufOut->list); |
| 787 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 788 | |
| 789 | size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 790 | writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 791 | writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR); |
| 792 | |
| 793 | config_in_buffer(c_data, vp_act->bufT2); |
| 794 | config_out_buffer(c_data, vp_act->bufOut); |
| 795 | |
| 796 | /* Config VP */ |
| 797 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 798 | chroma_fmt = 1; |
| 799 | writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 | |
| 800 | chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 801 | |
| 802 | chroma_fmt = 0; |
Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 803 | if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 804 | chroma_fmt = 1; |
| 805 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 806 | writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 807 | chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 808 | |
| 809 | /* Enable Interrupt */ |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 810 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 811 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 812 | vp_act->vp_state = VP_FRAME2; |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 813 | writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 814 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 815 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 816 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 817 | enable_irq(dev->vpirq->start); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | int continue_vp(struct vcap_client_data *c_data) |
| 822 | { |
| 823 | struct vcap_dev *dev; |
| 824 | struct vp_action *vp_act; |
| 825 | int rc; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 826 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 827 | |
| 828 | dprintk(2, "Start Continue\n"); |
| 829 | dev = c_data->dev; |
| 830 | |
| 831 | if (dev->vp_client == NULL) { |
| 832 | pr_err("No active vp client\n"); |
| 833 | return -ENODEV; |
| 834 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 835 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 836 | |
| 837 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 838 | pr_err("%s: VP is in an unknown state\n", |
| 839 | __func__); |
| 840 | return -EAGAIN; |
| 841 | } |
| 842 | |
| 843 | rc = vp_setup_buffers(c_data); |
| 844 | if (rc < 0) |
| 845 | return rc; |
| 846 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 847 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP) |
| 848 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 849 | |
| 850 | /* Config VP & Enable Interrupt */ |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 851 | writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 852 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 853 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 854 | |
| 855 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 856 | enable_irq(dev->vpirq->start); |
| 857 | return 0; |
| 858 | } |