From patchwork Fri Apr 1 22:38:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 8728271 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9E2E49F36E for ; Fri, 1 Apr 2016 22:38:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A52002039E for ; Fri, 1 Apr 2016 22:38:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD4A7203A1 for ; Fri, 1 Apr 2016 22:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754188AbcDAWis (ORCPT ); Fri, 1 Apr 2016 18:38:48 -0400 Received: from mail-qg0-f47.google.com ([209.85.192.47]:36165 "EHLO mail-qg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753797AbcDAWir (ORCPT ); Fri, 1 Apr 2016 18:38:47 -0400 Received: by mail-qg0-f47.google.com with SMTP id f52so11795846qga.3 for ; Fri, 01 Apr 2016 15:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UVqkJIIEBct0Wn5XUQwvo3+Qx1gWMyU6lpmp4iQf0ec=; b=QwL5mZAwJ87zRk5B4d60XpjmGMF67JGEQ2DwlKf+lfSnYueG3V6mVT1HcaJ/NRNHH+ 3hLVeom6ujLDn6zSC/BuXpAPFIUBVawGSOaP7FczVWCWxyoABuDgdwjvXcnW/K+b0IBl tsMey0nG992wmN8TTTGwxSupPNRoYIG6bIfUV2TNHbVYmaUbCJfP36ZoEp6JaI4uNJxo e9e8FYizW+AW8ydPDVUjJA4TlXbY/rhNp5ZKefQS8sq9q9ZGv8ZeUWEqAq0SOM8B2fu8 QEu22ClXoEKHjImheHZ2wjsFTOfmM9FhsscLTJf1oJzuKEUhfwgajJ6U2y88tZrjppjX fENw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UVqkJIIEBct0Wn5XUQwvo3+Qx1gWMyU6lpmp4iQf0ec=; b=j+bD0oVUr75r9eMeeqi6kesB418sMRmlWz40Ru/6IaHQh5NpTns5Rj9oTjQpdu9bja /JXRqcFVCgouLeXNXL0EvpyD9A/4yfhiNl0V8NGav+EW3OVTgCh+2lgwgzj7ZtuCIfaJ qoZhod/KFTuAANlJsosRk8ynvvwbotzTH7eFlynX/k8XGnPJKxpfdyj0664heHT3KXlC i/S2wuysyBEDpBfJ+kzkKzQ/sPueb5EtVVgCkeW/AzhKTL9neayNE9Kb5xhPdk7XIdsu Mk1ed853ca/LrA02ptr9FoohaAGeJYQNciCNHVHSchP2g4DvPuqfhYdbvdaOB3SlmhJM aOGg== X-Gm-Message-State: AD7BkJKVtMb3UJU1gOsqiK5t2nxEUgSGtdNMznksWw8Jp0ep2aEjXpS4dnCsf40UpCIDxA== X-Received: by 10.140.248.8 with SMTP id t8mr737603qhc.50.1459550326451; Fri, 01 Apr 2016 15:38:46 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id k25sm7091105qkl.29.2016.04.01.15.38.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Apr 2016 15:38:45 -0700 (PDT) From: Ezequiel Garcia To: Cc: Hans Verkuil , Ezequiel Garcia Subject: [PATCH 3/7] tw686x: Add support for DMA contiguous interlaced frame mode Date: Fri, 1 Apr 2016 19:38:23 -0300 Message-Id: <1459550307-688-4-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1459550307-688-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1459550307-688-1-git-send-email-ezequiel@vanguardiasur.com.ar> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,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 Now that the driver has the infrastructure to support more DMA modes, let's add the DMA contiguous interlaced frame mode. In this mode, the DMA P and B buffers are programmed with the user-provided buffers. When a P (or B) frame is ready, a new buffer is dequeued into P (or B). In addition to interlaced fields, the device can also be programmed to deliver alternate fields. Only interlaced mode is supported for now. Signed-off-by: Ezequiel Garcia Tested-by: Tim Harvey --- drivers/media/pci/tw686x/Kconfig | 1 + drivers/media/pci/tw686x/tw686x-core.c | 4 +++ drivers/media/pci/tw686x/tw686x-video.c | 50 +++++++++++++++++++++++++++++++++ drivers/media/pci/tw686x/tw686x.h | 1 + 4 files changed, 56 insertions(+) diff --git a/drivers/media/pci/tw686x/Kconfig b/drivers/media/pci/tw686x/Kconfig index fb8536974052..ef8ca85522f8 100644 --- a/drivers/media/pci/tw686x/Kconfig +++ b/drivers/media/pci/tw686x/Kconfig @@ -3,6 +3,7 @@ config VIDEO_TW686X depends on PCI && VIDEO_DEV && VIDEO_V4L2 && SND depends on HAS_DMA select VIDEOBUF2_VMALLOC + select VIDEOBUF2_DMA_CONTIG select SND_PCM help Support for Intersil/Techwell TW686x-based frame grabber cards. diff --git a/drivers/media/pci/tw686x/tw686x-core.c b/drivers/media/pci/tw686x/tw686x-core.c index 01c06bb59e78..9a7646c0f9f6 100644 --- a/drivers/media/pci/tw686x/tw686x-core.c +++ b/drivers/media/pci/tw686x/tw686x-core.c @@ -63,6 +63,8 @@ static const char *dma_mode_name(unsigned int mode) switch (mode) { case TW686X_DMA_MODE_MEMCPY: return "memcpy"; + case TW686X_DMA_MODE_CONTIG: + return "contig"; default: return "unknown"; } @@ -77,6 +79,8 @@ static int tw686x_dma_mode_set(const char *val, struct kernel_param *kp) { if (!strcasecmp(val, dma_mode_name(TW686X_DMA_MODE_MEMCPY))) dma_mode = TW686X_DMA_MODE_MEMCPY; + else if (!strcasecmp(val, dma_mode_name(TW686X_DMA_MODE_CONTIG))) + dma_mode = TW686X_DMA_MODE_CONTIG; else return -EINVAL; return 0; diff --git a/drivers/media/pci/tw686x/tw686x-video.c b/drivers/media/pci/tw686x/tw686x-video.c index 82ae607b1d01..ed6abb4c41c2 100644 --- a/drivers/media/pci/tw686x/tw686x-video.c +++ b/drivers/media/pci/tw686x/tw686x-video.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "tw686x.h" #include "tw686x-regs.h" @@ -148,6 +149,53 @@ const struct tw686x_dma_ops memcpy_dma_ops = { .field = V4L2_FIELD_INTERLACED, }; +static void tw686x_contig_buf_refill(struct tw686x_video_channel *vc, + unsigned int pb) +{ + struct tw686x_v4l2_buf *buf; + + while (!list_empty(&vc->vidq_queued)) { + u32 reg = pb ? VDMA_B_ADDR[vc->ch] : VDMA_P_ADDR[vc->ch]; + dma_addr_t phys; + + buf = list_first_entry(&vc->vidq_queued, + struct tw686x_v4l2_buf, list); + list_del(&buf->list); + + phys = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); + reg_write(vc->dev, reg, phys); + + buf->vb.vb2_buf.state = VB2_BUF_STATE_ACTIVE; + vc->curr_bufs[pb] = buf; + return; + } + vc->curr_bufs[pb] = NULL; +} + +static void tw686x_contig_cleanup(struct tw686x_dev *dev) +{ + vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); +} + +static int tw686x_contig_setup(struct tw686x_dev *dev) +{ + dev->alloc_ctx = vb2_dma_contig_init_ctx(&dev->pci_dev->dev); + if (IS_ERR(dev->alloc_ctx)) { + dev_err(&dev->pci_dev->dev, "unable to init DMA context\n"); + return PTR_ERR(dev->alloc_ctx); + } + return 0; +} + +const struct tw686x_dma_ops contig_dma_ops = { + .setup = tw686x_contig_setup, + .cleanup = tw686x_contig_cleanup, + .buf_refill = tw686x_contig_buf_refill, + .mem_ops = &vb2_dma_contig_memops, + .hw_dma_mode = TW686X_FRAME_MODE, + .field = V4L2_FIELD_INTERLACED, +}; + static unsigned int tw686x_fields_map(v4l2_std_id std, unsigned int fps) { static const unsigned int map[15] = { @@ -832,6 +880,8 @@ int tw686x_video_init(struct tw686x_dev *dev) if (dev->dma_mode == TW686X_DMA_MODE_MEMCPY) dev->dma_ops = &memcpy_dma_ops; + else if (dev->dma_mode == TW686X_DMA_MODE_CONTIG) + dev->dma_ops = &contig_dma_ops; else return -EINVAL; diff --git a/drivers/media/pci/tw686x/tw686x.h b/drivers/media/pci/tw686x/tw686x.h index 2b9884b709e0..938f16b2449a 100644 --- a/drivers/media/pci/tw686x/tw686x.h +++ b/drivers/media/pci/tw686x/tw686x.h @@ -33,6 +33,7 @@ #define TW686X_AUDIO_PERIODS_MAX TW686X_AUDIO_PAGE_MAX #define TW686X_DMA_MODE_MEMCPY 0 +#define TW686X_DMA_MODE_CONTIG 1 struct tw686x_format { char *name;