From patchwork Sun Oct 12 20:40:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 5071721 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B4F409F1EE for ; Sun, 12 Oct 2014 20:42:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85DBC20179 for ; Sun, 12 Oct 2014 20:42:17 +0000 (UTC) Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27CD520176 for ; Sun, 12 Oct 2014 20:42:16 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9CKf0Ml010330; Sun, 12 Oct 2014 15:41:00 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9CKevNh028190; Sun, 12 Oct 2014 15:40:59 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Sun, 12 Oct 2014 15:40:58 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9CKewBs032311; Sun, 12 Oct 2014 15:40:58 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id F12BA8062A; Sun, 12 Oct 2014 15:40:57 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflxv17.itg.ti.com (dflxv17.itg.ti.com [128.247.5.93]) by linux.omap.com (Postfix) with ESMTP id 2FEB08062A for ; Sun, 12 Oct 2014 15:40:56 -0500 (CDT) Received: from neches.ext.ti.com (neches.ext.ti.com [192.91.81.29]) by dflxv17.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9CKeutw029780 for ; Sun, 12 Oct 2014 15:40:56 -0500 Received: from mail6.bemta8.messagelabs.com (mail6.bemta8.messagelabs.com [216.82.243.55]) by neches.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9CKetft002734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 12 Oct 2014 15:40:55 -0500 Received: from [216.82.242.147:57837] by server-4.bemta-8.messagelabs.com id 7E/FC-02474-757EA345; Sun, 12 Oct 2014 20:40:55 +0000 X-Env-Sender: prabhakar.csengg@gmail.com X-Msg-Ref: server-4.tower-95.messagelabs.com!1413146453!32060846!1 X-Originating-IP: [209.85.212.182] X-SpamReason: No, hits=0.2 required=7.0 tests=RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 6.12.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9158 invoked from network); 12 Oct 2014 20:40:54 -0000 Received: from mail-wi0-f182.google.com (HELO mail-wi0-f182.google.com) (209.85.212.182) by server-4.tower-95.messagelabs.com with RC4-SHA encrypted SMTP; 12 Oct 2014 20:40:54 -0000 Received: by mail-wi0-f182.google.com with SMTP id n3so5942900wiv.3 for ; Sun, 12 Oct 2014 13:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AUDYtJCWDLhhzqRin4h7ti/h+fteAGACnc8g1HuRb/M=; b=jrLyp0kcLR7Q92SqCvFcAUnRawm9mt2SgLMTjF1d0tJe5A46bH7YLXZ3RIrujjGbHd 8PUCMqIAFXFP7SioxIcQMokvPQYUcaqGYzO40H1Kzg2a4k3I4uAWKdvldiOk5busWaOC Hofuj+XYQKxv53qF19A4h/wgd/Hvs76JknW1jZiVZVhdgJqMrUoTM5EnAZlICf5xvEMk Bdzh7ARqsSGn+6+jCiMhTsMK7jXW7UA3nzwS5/HJa0r4cIiVOmiBcLuqC6Qg1cLSNLVX +XmjpNrxbz9lT3UAPldGKQxMiLEQfoMNqgrAGnSEQnKogz9RhuIkJ7kQeq+rl6JxPYVp FvQQ== X-Received: by 10.194.189.82 with SMTP id gg18mr17144614wjc.2.1413146453089; Sun, 12 Oct 2014 13:40:53 -0700 (PDT) Received: from tango-charlie.Home ([2.127.193.40]) by mx.google.com with ESMTPSA id y5sm9970930wix.10.2014.10.12.13.40.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Oct 2014 13:40:51 -0700 (PDT) From: "Lad, Prabhakar" To: LMML Subject: [PATCH 01/15] media: davinci: vpbe: initialize vb2 queue and DMA context in probe Date: Sun, 12 Oct 2014 21:40:31 +0100 Message-ID: <1413146445-7304-2-git-send-email-prabhakar.csengg@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1413146445-7304-1-git-send-email-prabhakar.csengg@gmail.com> References: <1413146445-7304-1-git-send-email-prabhakar.csengg@gmail.com> CC: DLOS , LKML X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP this patch moves the initialization of vb2 queue and the DMA context to probe() and clean up in remove() callback respectively. Signed-off-by: Lad, Prabhakar --- drivers/media/platform/davinci/vpbe_display.c | 128 ++++++++++++-------------- 1 file changed, 60 insertions(+), 68 deletions(-) diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c index 73496d9..ff9eac4 100644 --- a/drivers/media/platform/davinci/vpbe_display.c +++ b/drivers/media/platform/davinci/vpbe_display.c @@ -207,10 +207,9 @@ static irqreturn_t venc_isr(int irq, void *arg) */ static int vpbe_buffer_prepare(struct vb2_buffer *vb) { - struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue); struct vb2_queue *q = vb->vb2_queue; - struct vpbe_layer *layer = fh->layer; - struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; + struct vpbe_layer *layer = vb2_get_drv_priv(q); + struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; unsigned long addr; v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, @@ -247,9 +246,8 @@ vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, { /* Get the file handle object and layer object */ - struct vpbe_fh *fh = vb2_get_drv_priv(vq); - struct vpbe_layer *layer = fh->layer; - struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; + struct vpbe_layer *layer = vb2_get_drv_priv(vq); + struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_buffer_setup\n"); @@ -271,12 +269,11 @@ vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, static void vpbe_buffer_queue(struct vb2_buffer *vb) { /* Get the file handle object and layer object */ - struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue); struct vpbe_disp_buffer *buf = container_of(vb, struct vpbe_disp_buffer, vb); - struct vpbe_layer *layer = fh->layer; - struct vpbe_display *disp = fh->disp_dev; - struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; + struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue); + struct vpbe_display *disp = layer->disp_dev; + struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; unsigned long flags; v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, @@ -296,9 +293,8 @@ static void vpbe_buffer_queue(struct vb2_buffer *vb) static void vpbe_buf_cleanup(struct vb2_buffer *vb) { /* Get the file handle object and layer object */ - struct vpbe_fh *fh = vb2_get_drv_priv(vb->vb2_queue); - struct vpbe_layer *layer = fh->layer; - struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; + struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue); + struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev; struct vpbe_disp_buffer *buf = container_of(vb, struct vpbe_disp_buffer, vb); unsigned long flags; @@ -314,16 +310,14 @@ static void vpbe_buf_cleanup(struct vb2_buffer *vb) static void vpbe_wait_prepare(struct vb2_queue *vq) { - struct vpbe_fh *fh = vb2_get_drv_priv(vq); - struct vpbe_layer *layer = fh->layer; + struct vpbe_layer *layer = vb2_get_drv_priv(vq); mutex_unlock(&layer->opslock); } static void vpbe_wait_finish(struct vb2_queue *vq) { - struct vpbe_fh *fh = vb2_get_drv_priv(vq); - struct vpbe_layer *layer = fh->layer; + struct vpbe_layer *layer = vb2_get_drv_priv(vq); mutex_lock(&layer->opslock); } @@ -339,8 +333,7 @@ static int vpbe_buffer_init(struct vb2_buffer *vb) static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count) { - struct vpbe_fh *fh = vb2_get_drv_priv(vq); - struct vpbe_layer *layer = fh->layer; + struct vpbe_layer *layer = vb2_get_drv_priv(vq); int ret; /* Get the next frame from the buffer queue */ @@ -354,7 +347,7 @@ static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count) layer->field_id = 0; /* Set parameters in OSD and VENC */ - ret = vpbe_set_osd_display_params(fh->disp_dev, layer); + ret = vpbe_set_osd_display_params(layer->disp_dev, layer); if (ret < 0) { struct vpbe_disp_buffer *buf, *tmp; @@ -379,9 +372,8 @@ static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count) static void vpbe_stop_streaming(struct vb2_queue *vq) { - struct vpbe_fh *fh = vb2_get_drv_priv(vq); - struct vpbe_layer *layer = fh->layer; - struct vpbe_display *disp = fh->disp_dev; + struct vpbe_layer *layer = vb2_get_drv_priv(vq); + struct vpbe_display *disp = layer->disp_dev; unsigned long flags; if (!vb2_is_streaming(vq)) @@ -1380,8 +1372,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv, struct vpbe_fh *fh = file->private_data; struct vpbe_layer *layer = fh->layer; struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; - struct vb2_queue *q; - int ret; + v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, "vpbe_display_reqbufs\n"); if (V4L2_BUF_TYPE_VIDEO_OUTPUT != req_buf->type) { @@ -1394,39 +1385,14 @@ static int vpbe_display_reqbufs(struct file *file, void *priv, v4l2_err(&vpbe_dev->v4l2_dev, "not IO user\n"); return -EBUSY; } - /* Initialize videobuf queue as per the buffer type */ - layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev); - if (IS_ERR(layer->alloc_ctx)) { - v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n"); - return PTR_ERR(layer->alloc_ctx); - } - q = &layer->buffer_queue; - memset(q, 0, sizeof(*q)); - q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; - q->io_modes = VB2_MMAP | VB2_USERPTR; - q->drv_priv = fh; - q->ops = &video_qops; - q->mem_ops = &vb2_dma_contig_memops; - q->buf_struct_size = sizeof(struct vpbe_disp_buffer); - q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - q->min_buffers_needed = 1; - - ret = vb2_queue_init(q); - if (ret) { - v4l2_err(&vpbe_dev->v4l2_dev, "vb2_queue_init() failed\n"); - vb2_dma_contig_cleanup_ctx(layer->alloc_ctx); - return ret; - } /* Set io allowed member of file handle to TRUE */ fh->io_allowed = 1; /* Increment io usrs member of layer object to 1 */ layer->io_usrs = 1; /* Store type of memory requested in layer object */ layer->memory = req_buf->memory; - /* Initialize buffer queue */ - INIT_LIST_HEAD(&layer->dma_queue); /* Allocate buffers */ - return vb2_reqbufs(q, req_buf); + return vb2_reqbufs(&layer->buffer_queue, req_buf); } /* @@ -1551,9 +1517,6 @@ static int vpbe_display_release(struct file *file) osd_device->ops.disable_layer(osd_device, layer->layer_info.id); layer->started = 0; - /* Free buffers allocated */ - vb2_queue_release(&layer->buffer_queue); - vb2_dma_contig_cleanup_ctx(&layer->buffer_queue); } /* Decrement layer usrs counter */ @@ -1724,9 +1687,10 @@ static int register_device(struct vpbe_layer *vpbe_display_layer, */ static int vpbe_display_probe(struct platform_device *pdev) { - struct vpbe_layer *vpbe_display_layer; struct vpbe_display *disp_dev; + struct v4l2_device *v4l2_dev; struct resource *res = NULL; + struct vb2_queue *q; int k; int i; int err; @@ -1748,13 +1712,14 @@ static int vpbe_display_probe(struct platform_device *pdev) vpbe_device_get); if (err < 0) return err; + + v4l2_dev = &disp_dev->vpbe_dev->v4l2_dev; /* Initialize the vpbe display controller */ if (NULL != disp_dev->vpbe_dev->ops.initialize) { err = disp_dev->vpbe_dev->ops.initialize(&pdev->dev, disp_dev->vpbe_dev); if (err) { - v4l2_err(&disp_dev->vpbe_dev->v4l2_dev, - "Error initing vpbe\n"); + v4l2_err(v4l2_dev, "Error initing vpbe\n"); err = -ENOMEM; goto probe_out; } @@ -1769,8 +1734,7 @@ static int vpbe_display_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { - v4l2_err(&disp_dev->vpbe_dev->v4l2_dev, - "Unable to get VENC interrupt resource\n"); + v4l2_err(v4l2_dev, "Unable to get VENC interrupt resource\n"); err = -ENODEV; goto probe_out; } @@ -1779,30 +1743,57 @@ static int vpbe_display_probe(struct platform_device *pdev) err = devm_request_irq(&pdev->dev, irq, venc_isr, 0, VPBE_DISPLAY_DRIVER, disp_dev); if (err) { - v4l2_err(&disp_dev->vpbe_dev->v4l2_dev, - "Unable to request interrupt\n"); + v4l2_err(v4l2_dev, "VPBE IRQ request failed\n"); goto probe_out; } for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { + /* initialize vb2 queue */ + q = &disp_dev->dev[i]->buffer_queue; + memset(q, 0, sizeof(*q)); + q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + q->io_modes = VB2_MMAP | VB2_USERPTR; + q->drv_priv = disp_dev->dev[i]; + q->ops = &video_qops; + q->mem_ops = &vb2_dma_contig_memops; + q->buf_struct_size = sizeof(struct vpbe_disp_buffer); + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->min_buffers_needed = 1; + + err = vb2_queue_init(q); + if (err) { + v4l2_err(v4l2_dev, "vb2_queue_init() failed\n"); + goto probe_out; + } + + disp_dev->dev[i]->alloc_ctx = + vb2_dma_contig_init_ctx(disp_dev->vpbe_dev->pdev); + if (IS_ERR(disp_dev->dev[i]->alloc_ctx)) { + v4l2_err(v4l2_dev, "Failed to get the context\n"); + err = PTR_ERR(disp_dev->dev[i]->alloc_ctx); + goto probe_out; + } + + INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue); + if (register_device(disp_dev->dev[i], disp_dev, pdev)) { err = -ENODEV; goto probe_out; } } - printk(KERN_DEBUG "Successfully completed the probing of vpbe v4l2 device\n"); + v4l2_dbg(1, debug, v4l2_dev, + "Successfully completed the probing of vpbe v4l2 device\n"); + return 0; probe_out: for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) { - /* Get the pointer to the layer object */ - vpbe_display_layer = disp_dev->dev[k]; /* Unregister video device */ - if (vpbe_display_layer) { - video_unregister_device( - &vpbe_display_layer->video_dev); - kfree(disp_dev->dev[k]); + if (disp_dev->dev[k] != NULL) { + vb2_dma_contig_cleanup_ctx(disp_dev->dev[k]->alloc_ctx); + video_unregister_device(&disp_dev->dev[k]->video_dev); + kfree(disp_dev->dev[k]); } } return err; @@ -1828,6 +1819,7 @@ static int vpbe_display_remove(struct platform_device *pdev) for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) { /* Get the pointer to the layer object */ vpbe_display_layer = disp_dev->dev[i]; + vb2_dma_contig_cleanup_ctx(vpbe_display_layer->alloc_ctx); /* Unregister video device */ video_unregister_device(&vpbe_display_layer->video_dev);