aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLad, Prabhakar <prabhakar.lad@ti.com>2012-10-22 08:27:13 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-11-21 10:55:10 -0500
commit13fc23d3067e996c03d8b602266f47d27d205d36 (patch)
treeec983e5755979653c1e19720092a1b940046873a
parentbaa29837a76d5738837602ff249a0c371591d7c7 (diff)
[media] media: davinci: vpbe: migrate driver to videobuf2
This patch migrates VPBE display driver to videobuf2 framework. Signed-off-by: Lad, Prabhakar <prabhakar.lad@ti.com> Signed-off-by: Manjunath Hadli <manjunath.hadli@ti.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/platform/davinci/Kconfig2
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c294
-rw-r--r--include/media/davinci/vpbe_display.h15
3 files changed, 187 insertions, 124 deletions
diff --git a/drivers/media/platform/davinci/Kconfig b/drivers/media/platform/davinci/Kconfig
index 78e26d24f637..3c56037c82fc 100644
--- a/drivers/media/platform/davinci/Kconfig
+++ b/drivers/media/platform/davinci/Kconfig
@@ -101,7 +101,7 @@ config VIDEO_DM644X_VPBE
101 tristate "DM644X VPBE HW module" 101 tristate "DM644X VPBE HW module"
102 depends on ARCH_DAVINCI_DM644x 102 depends on ARCH_DAVINCI_DM644x
103 select VIDEO_VPSS_SYSTEM 103 select VIDEO_VPSS_SYSTEM
104 select VIDEOBUF_DMA_CONTIG 104 select VIDEOBUF2_DMA_CONTIG
105 help 105 help
106 Enables VPBE modules used for display on a DM644x 106 Enables VPBE modules used for display on a DM644x
107 SoC. 107 SoC.
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 161c77650e2f..974957fd7f71 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -47,6 +47,9 @@ static int debug;
47 47
48module_param(debug, int, 0644); 48module_param(debug, int, 0644);
49 49
50static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
51 struct vpbe_layer *layer);
52
50static int venc_is_second_field(struct vpbe_display *disp_dev) 53static int venc_is_second_field(struct vpbe_display *disp_dev)
51{ 54{
52 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; 55 struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev;
@@ -73,10 +76,11 @@ static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
73 if (layer->cur_frm == layer->next_frm) 76 if (layer->cur_frm == layer->next_frm)
74 return; 77 return;
75 ktime_get_ts(&timevalue); 78 ktime_get_ts(&timevalue);
76 layer->cur_frm->ts.tv_sec = timevalue.tv_sec; 79 layer->cur_frm->vb.v4l2_buf.timestamp.tv_sec =
77 layer->cur_frm->ts.tv_usec = timevalue.tv_nsec / NSEC_PER_USEC; 80 timevalue.tv_sec;
78 layer->cur_frm->state = VIDEOBUF_DONE; 81 layer->cur_frm->vb.v4l2_buf.timestamp.tv_usec =
79 wake_up_interruptible(&layer->cur_frm->done); 82 timevalue.tv_nsec / NSEC_PER_USEC;
83 vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE);
80 /* Make cur_frm pointing to next_frm */ 84 /* Make cur_frm pointing to next_frm */
81 layer->cur_frm = layer->next_frm; 85 layer->cur_frm = layer->next_frm;
82} 86}
@@ -99,16 +103,14 @@ static void vpbe_isr_odd_field(struct vpbe_display *disp_obj,
99 * otherwise hold on current frame 103 * otherwise hold on current frame
100 * Get next from the buffer queue 104 * Get next from the buffer queue
101 */ 105 */
102 layer->next_frm = list_entry( 106 layer->next_frm = list_entry(layer->dma_queue.next,
103 layer->dma_queue.next, 107 struct vpbe_disp_buffer, list);
104 struct videobuf_buffer,
105 queue);
106 /* Remove that from the buffer queue */ 108 /* Remove that from the buffer queue */
107 list_del(&layer->next_frm->queue); 109 list_del(&layer->next_frm->list);
108 spin_unlock(&disp_obj->dma_queue_lock); 110 spin_unlock(&disp_obj->dma_queue_lock);
109 /* Mark state of the frame to active */ 111 /* Mark state of the frame to active */
110 layer->next_frm->state = VIDEOBUF_ACTIVE; 112 layer->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
111 addr = videobuf_to_dma_contig(layer->next_frm); 113 addr = vb2_dma_contig_plane_dma_addr(&layer->next_frm->vb, 0);
112 osd_device->ops.start_layer(osd_device, 114 osd_device->ops.start_layer(osd_device,
113 layer->layer_info.id, 115 layer->layer_info.id,
114 addr, 116 addr,
@@ -199,39 +201,29 @@ static irqreturn_t venc_isr(int irq, void *arg)
199 201
200/* 202/*
201 * vpbe_buffer_prepare() 203 * vpbe_buffer_prepare()
202 * This is the callback function called from videobuf_qbuf() function 204 * This is the callback function called from vb2_qbuf() function
203 * the buffer is prepared and user space virtual address is converted into 205 * the buffer is prepared and user space virtual address is converted into
204 * physical address 206 * physical address
205 */ 207 */
206static int vpbe_buffer_prepare(struct videobuf_queue *q, 208static int vpbe_buffer_prepare(struct vb2_buffer *vb)
207 struct videobuf_buffer *vb,
208 enum v4l2_field field)
209{ 209{
210 struct vpbe_fh *fh = q->priv_data; 210 struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
211 struct vb2_queue *q = vb->vb2_queue;
211 struct vpbe_layer *layer = fh->layer; 212 struct vpbe_layer *layer = fh->layer;
212 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 213 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
213 unsigned long addr; 214 unsigned long addr;
214 int ret;
215 215
216 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 216 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
217 "vpbe_buffer_prepare\n"); 217 "vpbe_buffer_prepare\n");
218 218
219 /* If buffer is not initialized, initialize it */ 219 if (vb->state != VB2_BUF_STATE_ACTIVE &&
220 if (VIDEOBUF_NEEDS_INIT == vb->state) { 220 vb->state != VB2_BUF_STATE_PREPARED) {
221 vb->width = layer->pix_fmt.width; 221 vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
222 vb->height = layer->pix_fmt.height; 222 if (vb2_plane_vaddr(vb, 0) &&
223 vb->size = layer->pix_fmt.sizeimage; 223 vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
224 vb->field = field;
225
226 ret = videobuf_iolock(q, vb, NULL);
227 if (ret < 0) {
228 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to map \
229 user address\n");
230 return -EINVAL; 224 return -EINVAL;
231 }
232
233 addr = videobuf_to_dma_contig(vb);
234 225
226 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
235 if (q->streaming) { 227 if (q->streaming) {
236 if (!IS_ALIGNED(addr, 8)) { 228 if (!IS_ALIGNED(addr, 8)) {
237 v4l2_err(&vpbe_dev->v4l2_dev, 229 v4l2_err(&vpbe_dev->v4l2_dev,
@@ -240,7 +232,6 @@ static int vpbe_buffer_prepare(struct videobuf_queue *q,
240 return -EINVAL; 232 return -EINVAL;
241 } 233 }
242 } 234 }
243 vb->state = VIDEOBUF_PREPARED;
244 } 235 }
245 return 0; 236 return 0;
246} 237}
@@ -249,22 +240,26 @@ static int vpbe_buffer_prepare(struct videobuf_queue *q,
249 * vpbe_buffer_setup() 240 * vpbe_buffer_setup()
250 * This function allocates memory for the buffers 241 * This function allocates memory for the buffers
251 */ 242 */
252static int vpbe_buffer_setup(struct videobuf_queue *q, 243static int
253 unsigned int *count, 244vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
254 unsigned int *size) 245 unsigned int *nbuffers, unsigned int *nplanes,
246 unsigned int sizes[], void *alloc_ctxs[])
247
255{ 248{
256 /* Get the file handle object and layer object */ 249 /* Get the file handle object and layer object */
257 struct vpbe_fh *fh = q->priv_data; 250 struct vpbe_fh *fh = vb2_get_drv_priv(vq);
258 struct vpbe_layer *layer = fh->layer; 251 struct vpbe_layer *layer = fh->layer;
259 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 252 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
260 253
261 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n"); 254 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n");
262 255
263 *size = layer->pix_fmt.sizeimage;
264
265 /* Store number of buffers allocated in numbuffer member */ 256 /* Store number of buffers allocated in numbuffer member */
266 if (*count < VPBE_DEFAULT_NUM_BUFS) 257 if (*nbuffers < VPBE_DEFAULT_NUM_BUFS)
267 *count = layer->numbuffers = VPBE_DEFAULT_NUM_BUFS; 258 *nbuffers = layer->numbuffers = VPBE_DEFAULT_NUM_BUFS;
259
260 *nplanes = 1;
261 sizes[0] = layer->pix_fmt.sizeimage;
262 alloc_ctxs[0] = layer->alloc_ctx;
268 263
269 return 0; 264 return 0;
270} 265}
@@ -273,11 +268,12 @@ static int vpbe_buffer_setup(struct videobuf_queue *q,
273 * vpbe_buffer_queue() 268 * vpbe_buffer_queue()
274 * This function adds the buffer to DMA queue 269 * This function adds the buffer to DMA queue
275 */ 270 */
276static void vpbe_buffer_queue(struct videobuf_queue *q, 271static void vpbe_buffer_queue(struct vb2_buffer *vb)
277 struct videobuf_buffer *vb)
278{ 272{
279 /* Get the file handle object and layer object */ 273 /* Get the file handle object and layer object */
280 struct vpbe_fh *fh = q->priv_data; 274 struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
275 struct vpbe_disp_buffer *buf = container_of(vb,
276 struct vpbe_disp_buffer, vb);
281 struct vpbe_layer *layer = fh->layer; 277 struct vpbe_layer *layer = fh->layer;
282 struct vpbe_display *disp = fh->disp_dev; 278 struct vpbe_display *disp = fh->disp_dev;
283 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 279 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
@@ -288,39 +284,125 @@ static void vpbe_buffer_queue(struct videobuf_queue *q,
288 284
289 /* add the buffer to the DMA queue */ 285 /* add the buffer to the DMA queue */
290 spin_lock_irqsave(&disp->dma_queue_lock, flags); 286 spin_lock_irqsave(&disp->dma_queue_lock, flags);
291 list_add_tail(&vb->queue, &layer->dma_queue); 287 list_add_tail(&buf->list, &layer->dma_queue);
292 spin_unlock_irqrestore(&disp->dma_queue_lock, flags); 288 spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
293 /* Change state of the buffer */
294 vb->state = VIDEOBUF_QUEUED;
295} 289}
296 290
297/* 291/*
298 * vpbe_buffer_release() 292 * vpbe_buf_cleanup()
299 * This function is called from the videobuf layer to free memory allocated to 293 * This function is called from the vb2 layer to free memory allocated to
300 * the buffers 294 * the buffers
301 */ 295 */
302static void vpbe_buffer_release(struct videobuf_queue *q, 296static void vpbe_buf_cleanup(struct vb2_buffer *vb)
303 struct videobuf_buffer *vb)
304{ 297{
305 /* Get the file handle object and layer object */ 298 /* Get the file handle object and layer object */
306 struct vpbe_fh *fh = q->priv_data; 299 struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
307 struct vpbe_layer *layer = fh->layer; 300 struct vpbe_layer *layer = fh->layer;
308 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 301 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
302 struct vpbe_disp_buffer *buf = container_of(vb,
303 struct vpbe_disp_buffer, vb);
304 unsigned long flags;
309 305
310 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 306 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
311 "vpbe_buffer_release\n"); 307 "vpbe_buf_cleanup\n");
308
309 spin_lock_irqsave(&layer->irqlock, flags);
310 if (vb->state == VB2_BUF_STATE_ACTIVE)
311 list_del_init(&buf->list);
312 spin_unlock_irqrestore(&layer->irqlock, flags);
313}
314
315static void vpbe_wait_prepare(struct vb2_queue *vq)
316{
317 struct vpbe_fh *fh = vb2_get_drv_priv(vq);
318 struct vpbe_layer *layer = fh->layer;
319
320 mutex_unlock(&layer->opslock);
321}
322
323static void vpbe_wait_finish(struct vb2_queue *vq)
324{
325 struct vpbe_fh *fh = vb2_get_drv_priv(vq);
326 struct vpbe_layer *layer = fh->layer;
327
328 mutex_lock(&layer->opslock);
329}
330
331static int vpbe_buffer_init(struct vb2_buffer *vb)
332{
333 struct vpbe_disp_buffer *buf = container_of(vb,
334 struct vpbe_disp_buffer, vb);
335
336 INIT_LIST_HEAD(&buf->list);
337 return 0;
338}
339
340static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count)
341{
342 struct vpbe_fh *fh = vb2_get_drv_priv(vq);
343 struct vpbe_layer *layer = fh->layer;
344 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
345 int ret;
346
347 /* If buffer queue is empty, return error */
348 if (list_empty(&layer->dma_queue)) {
349 v4l2_err(&vpbe_dev->v4l2_dev, "buffer queue is empty\n");
350 return -EINVAL;
351 }
352 /* Get the next frame from the buffer queue */
353 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
354 struct vpbe_disp_buffer, list);
355 /* Remove buffer from the buffer queue */
356 list_del(&layer->cur_frm->list);
357 /* Mark state of the current frame to active */
358 layer->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
359 /* Initialize field_id and started member */
360 layer->field_id = 0;
361
362 /* Set parameters in OSD and VENC */
363 ret = vpbe_set_osd_display_params(fh->disp_dev, layer);
364 if (ret < 0)
365 return ret;
312 366
313 if (V4L2_MEMORY_USERPTR != layer->memory) 367 /*
314 videobuf_dma_contig_free(q, vb); 368 * if request format is yuv420 semiplanar, need to
369 * enable both video windows
370 */
371 layer->started = 1;
372 layer->layer_first_int = 1;
373
374 return ret;
375}
376
377static int vpbe_stop_streaming(struct vb2_queue *vq)
378{
379 struct vpbe_fh *fh = vb2_get_drv_priv(vq);
380 struct vpbe_layer *layer = fh->layer;
381
382 if (!vb2_is_streaming(vq))
383 return 0;
384
385 /* release all active buffers */
386 while (!list_empty(&layer->dma_queue)) {
387 layer->next_frm = list_entry(layer->dma_queue.next,
388 struct vpbe_disp_buffer, list);
389 list_del(&layer->next_frm->list);
390 vb2_buffer_done(&layer->next_frm->vb, VB2_BUF_STATE_ERROR);
391 }
315 392
316 vb->state = VIDEOBUF_NEEDS_INIT; 393 return 0;
317} 394}
318 395
319static struct videobuf_queue_ops video_qops = { 396static struct vb2_ops video_qops = {
320 .buf_setup = vpbe_buffer_setup, 397 .queue_setup = vpbe_buffer_queue_setup,
398 .wait_prepare = vpbe_wait_prepare,
399 .wait_finish = vpbe_wait_finish,
400 .buf_init = vpbe_buffer_init,
321 .buf_prepare = vpbe_buffer_prepare, 401 .buf_prepare = vpbe_buffer_prepare,
402 .start_streaming = vpbe_start_streaming,
403 .stop_streaming = vpbe_stop_streaming,
404 .buf_cleanup = vpbe_buf_cleanup,
322 .buf_queue = vpbe_buffer_queue, 405 .buf_queue = vpbe_buffer_queue,
323 .buf_release = vpbe_buffer_release,
324}; 406};
325 407
326static 408static
@@ -345,7 +427,7 @@ static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev,
345 unsigned long addr; 427 unsigned long addr;
346 int ret; 428 int ret;
347 429
348 addr = videobuf_to_dma_contig(layer->cur_frm); 430 addr = vb2_dma_contig_plane_dma_addr(&layer->cur_frm->vb, 0);
349 /* Set address in the display registers */ 431 /* Set address in the display registers */
350 osd_device->ops.start_layer(osd_device, 432 osd_device->ops.start_layer(osd_device,
351 layer->layer_info.id, 433 layer->layer_info.id,
@@ -1161,7 +1243,7 @@ static int vpbe_display_streamoff(struct file *file, void *priv,
1161 osd_device->ops.disable_layer(osd_device, 1243 osd_device->ops.disable_layer(osd_device,
1162 layer->layer_info.id); 1244 layer->layer_info.id);
1163 layer->started = 0; 1245 layer->started = 0;
1164 ret = videobuf_streamoff(&layer->buffer_queue); 1246 ret = vb2_streamoff(&layer->buffer_queue, buf_type);
1165 1247
1166 return ret; 1248 return ret;
1167} 1249}
@@ -1199,46 +1281,15 @@ static int vpbe_display_streamon(struct file *file, void *priv,
1199 } 1281 }
1200 1282
1201 /* 1283 /*
1202 * Call videobuf_streamon to start streaming 1284 * Call vb2_streamon to start streaming
1203 * in videobuf 1285 * in videobuf
1204 */ 1286 */
1205 ret = videobuf_streamon(&layer->buffer_queue); 1287 ret = vb2_streamon(&layer->buffer_queue, buf_type);
1206 if (ret) { 1288 if (ret) {
1207 v4l2_err(&vpbe_dev->v4l2_dev, 1289 v4l2_err(&vpbe_dev->v4l2_dev,
1208 "error in videobuf_streamon\n"); 1290 "error in vb2_streamon\n");
1209 return ret; 1291 return ret;
1210 } 1292 }
1211 /* If buffer queue is empty, return error */
1212 if (list_empty(&layer->dma_queue)) {
1213 v4l2_err(&vpbe_dev->v4l2_dev, "buffer queue is empty\n");
1214 goto streamoff;
1215 }
1216 /* Get the next frame from the buffer queue */
1217 layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next,
1218 struct videobuf_buffer, queue);
1219 /* Remove buffer from the buffer queue */
1220 list_del(&layer->cur_frm->queue);
1221 /* Mark state of the current frame to active */
1222 layer->cur_frm->state = VIDEOBUF_ACTIVE;
1223 /* Initialize field_id and started member */
1224 layer->field_id = 0;
1225
1226 /* Set parameters in OSD and VENC */
1227 ret = vpbe_set_osd_display_params(disp_dev, layer);
1228 if (ret < 0)
1229 goto streamoff;
1230
1231 /*
1232 * if request format is yuv420 semiplanar, need to
1233 * enable both video windows
1234 */
1235 layer->started = 1;
1236
1237 layer->layer_first_int = 1;
1238
1239 return ret;
1240streamoff:
1241 ret = videobuf_streamoff(&layer->buffer_queue);
1242 return ret; 1293 return ret;
1243} 1294}
1244 1295
@@ -1265,10 +1316,10 @@ static int vpbe_display_dqbuf(struct file *file, void *priv,
1265 } 1316 }
1266 if (file->f_flags & O_NONBLOCK) 1317 if (file->f_flags & O_NONBLOCK)
1267 /* Call videobuf_dqbuf for non blocking mode */ 1318 /* Call videobuf_dqbuf for non blocking mode */
1268 ret = videobuf_dqbuf(&layer->buffer_queue, buf, 1); 1319 ret = vb2_dqbuf(&layer->buffer_queue, buf, 1);
1269 else 1320 else
1270 /* Call videobuf_dqbuf for blocking mode */ 1321 /* Call videobuf_dqbuf for blocking mode */
1271 ret = videobuf_dqbuf(&layer->buffer_queue, buf, 0); 1322 ret = vb2_dqbuf(&layer->buffer_queue, buf, 0);
1272 1323
1273 return ret; 1324 return ret;
1274} 1325}
@@ -1295,7 +1346,7 @@ static int vpbe_display_qbuf(struct file *file, void *priv,
1295 return -EACCES; 1346 return -EACCES;
1296 } 1347 }
1297 1348
1298 return videobuf_qbuf(&layer->buffer_queue, p); 1349 return vb2_qbuf(&layer->buffer_queue, p);
1299} 1350}
1300 1351
1301static int vpbe_display_querybuf(struct file *file, void *priv, 1352static int vpbe_display_querybuf(struct file *file, void *priv,
@@ -1304,7 +1355,6 @@ static int vpbe_display_querybuf(struct file *file, void *priv,
1304 struct vpbe_fh *fh = file->private_data; 1355 struct vpbe_fh *fh = file->private_data;
1305 struct vpbe_layer *layer = fh->layer; 1356 struct vpbe_layer *layer = fh->layer;
1306 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1357 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1307 int ret;
1308 1358
1309 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 1359 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
1310 "VIDIOC_QUERYBUF, layer id = %d\n", 1360 "VIDIOC_QUERYBUF, layer id = %d\n",
@@ -1314,11 +1364,8 @@ static int vpbe_display_querybuf(struct file *file, void *priv,
1314 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n"); 1364 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buffer type\n");
1315 return -EINVAL; 1365 return -EINVAL;
1316 } 1366 }
1317 1367 /* Call vb2_querybuf to get information */
1318 /* Call videobuf_querybuf to get information */ 1368 return vb2_querybuf(&layer->buffer_queue, buf);
1319 ret = videobuf_querybuf(&layer->buffer_queue, buf);
1320
1321 return ret;
1322} 1369}
1323 1370
1324static int vpbe_display_reqbufs(struct file *file, void *priv, 1371static int vpbe_display_reqbufs(struct file *file, void *priv,
@@ -1327,8 +1374,8 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1327 struct vpbe_fh *fh = file->private_data; 1374 struct vpbe_fh *fh = file->private_data;
1328 struct vpbe_layer *layer = fh->layer; 1375 struct vpbe_layer *layer = fh->layer;
1329 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 1376 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1377 struct vb2_queue *q;
1330 int ret; 1378 int ret;
1331
1332 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n"); 1379 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n");
1333 1380
1334 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != req_buf->type) { 1381 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != req_buf->type) {
@@ -1342,15 +1389,26 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1342 return -EBUSY; 1389 return -EBUSY;
1343 } 1390 }
1344 /* Initialize videobuf queue as per the buffer type */ 1391 /* Initialize videobuf queue as per the buffer type */
1345 videobuf_queue_dma_contig_init(&layer->buffer_queue, 1392 layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev);
1346 &video_qops, 1393 if (!layer->alloc_ctx) {
1347 vpbe_dev->pdev, 1394 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n");
1348 &layer->irqlock, 1395 return -EINVAL;
1349 V4L2_BUF_TYPE_VIDEO_OUTPUT, 1396 }
1350 layer->pix_fmt.field, 1397 q = &layer->buffer_queue;
1351 sizeof(struct videobuf_buffer), 1398 memset(q, 0, sizeof(*q));
1352 fh, NULL); 1399 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1400 q->io_modes = VB2_MMAP | VB2_USERPTR;
1401 q->drv_priv = fh;
1402 q->ops = &video_qops;
1403 q->mem_ops = &vb2_dma_contig_memops;
1404 q->buf_struct_size = sizeof(struct vpbe_disp_buffer);
1353 1405
1406 ret = vb2_queue_init(q);
1407 if (ret) {
1408 v4l2_err(&vpbe_dev->v4l2_dev, "vb2_queue_init() failed\n");
1409 vb2_dma_contig_cleanup_ctx(layer->alloc_ctx);
1410 return ret;
1411 }
1354 /* Set io allowed member of file handle to TRUE */ 1412 /* Set io allowed member of file handle to TRUE */
1355 fh->io_allowed = 1; 1413 fh->io_allowed = 1;
1356 /* Increment io usrs member of layer object to 1 */ 1414 /* Increment io usrs member of layer object to 1 */
@@ -1360,9 +1418,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1360 /* Initialize buffer queue */ 1418 /* Initialize buffer queue */
1361 INIT_LIST_HEAD(&layer->dma_queue); 1419 INIT_LIST_HEAD(&layer->dma_queue);
1362 /* Allocate buffers */ 1420 /* Allocate buffers */
1363 ret = videobuf_reqbufs(&layer->buffer_queue, req_buf); 1421 return vb2_reqbufs(q, req_buf);
1364
1365 return ret;
1366} 1422}
1367 1423
1368/* 1424/*
@@ -1381,7 +1437,7 @@ static int vpbe_display_mmap(struct file *filep, struct vm_area_struct *vma)
1381 1437
1382 if (mutex_lock_interruptible(&layer->opslock)) 1438 if (mutex_lock_interruptible(&layer->opslock))
1383 return -ERESTARTSYS; 1439 return -ERESTARTSYS;
1384 ret = videobuf_mmap_mapper(&layer->buffer_queue, vma); 1440 ret = vb2_mmap(&layer->buffer_queue, vma);
1385 mutex_unlock(&layer->opslock); 1441 mutex_unlock(&layer->opslock);
1386 return ret; 1442 return ret;
1387} 1443}
@@ -1398,7 +1454,7 @@ static unsigned int vpbe_display_poll(struct file *filep, poll_table *wait)
1398 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_poll\n"); 1454 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_poll\n");
1399 if (layer->started) { 1455 if (layer->started) {
1400 mutex_lock(&layer->opslock); 1456 mutex_lock(&layer->opslock);
1401 err = videobuf_poll_stream(filep, &layer->buffer_queue, wait); 1457 err = vb2_poll(&layer->buffer_queue, filep, wait);
1402 mutex_unlock(&layer->opslock); 1458 mutex_unlock(&layer->opslock);
1403 } 1459 }
1404 return err; 1460 return err;
@@ -1488,8 +1544,8 @@ static int vpbe_display_release(struct file *file)
1488 layer->layer_info.id); 1544 layer->layer_info.id);
1489 layer->started = 0; 1545 layer->started = 0;
1490 /* Free buffers allocated */ 1546 /* Free buffers allocated */
1491 videobuf_queue_cancel(&layer->buffer_queue); 1547 vb2_queue_release(&layer->buffer_queue);
1492 videobuf_mmap_free(&layer->buffer_queue); 1548 vb2_dma_contig_cleanup_ctx(&layer->buffer_queue);
1493 } 1549 }
1494 1550
1495 /* Decrement layer usrs counter */ 1551 /* Decrement layer usrs counter */
diff --git a/include/media/davinci/vpbe_display.h b/include/media/davinci/vpbe_display.h
index dbf6b37682cd..8dffffedbb59 100644
--- a/include/media/davinci/vpbe_display.h
+++ b/include/media/davinci/vpbe_display.h
@@ -16,7 +16,7 @@
16/* Header files */ 16/* Header files */
17#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <media/v4l2-common.h> 18#include <media/v4l2-common.h>
19#include <media/videobuf-dma-contig.h> 19#include <media/videobuf2-dma-contig.h>
20#include <media/davinci/vpbe_types.h> 20#include <media/davinci/vpbe_types.h>
21#include <media/davinci/vpbe_osd.h> 21#include <media/davinci/vpbe_osd.h>
22#include <media/davinci/vpbe.h> 22#include <media/davinci/vpbe.h>
@@ -62,6 +62,11 @@ struct display_layer_info {
62 enum osd_v_exp_ratio v_exp; 62 enum osd_v_exp_ratio v_exp;
63}; 63};
64 64
65struct vpbe_disp_buffer {
66 struct vb2_buffer vb;
67 struct list_head list;
68};
69
65/* vpbe display object structure */ 70/* vpbe display object structure */
66struct vpbe_layer { 71struct vpbe_layer {
67 /* number of buffers in fbuffers */ 72 /* number of buffers in fbuffers */
@@ -69,13 +74,15 @@ struct vpbe_layer {
69 /* Pointer to the vpbe_display */ 74 /* Pointer to the vpbe_display */
70 struct vpbe_display *disp_dev; 75 struct vpbe_display *disp_dev;
71 /* Pointer pointing to current v4l2_buffer */ 76 /* Pointer pointing to current v4l2_buffer */
72 struct videobuf_buffer *cur_frm; 77 struct vpbe_disp_buffer *cur_frm;
73 /* Pointer pointing to next v4l2_buffer */ 78 /* Pointer pointing to next v4l2_buffer */
74 struct videobuf_buffer *next_frm; 79 struct vpbe_disp_buffer *next_frm;
75 /* videobuf specific parameters 80 /* videobuf specific parameters
76 * Buffer queue used in video-buf 81 * Buffer queue used in video-buf
77 */ 82 */
78 struct videobuf_queue buffer_queue; 83 struct vb2_queue buffer_queue;
84 /* allocator-specific contexts for each plane */
85 struct vb2_alloc_ctx *alloc_ctx;
79 /* Queue of filled frames */ 86 /* Queue of filled frames */
80 struct list_head dma_queue; 87 struct list_head dma_queue;
81 /* Used in video-buf */ 88 /* Used in video-buf */