Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2424372ybl; Mon, 19 Aug 2019 01:42:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgi+sG7C9PzA/57rSWBtmVfvCc/5oTepWsu11Rr39WuG5dlqWLuTdKxaxyxJR8wChrIsq6 X-Received: by 2002:aa7:93cf:: with SMTP id y15mr22747910pff.251.1566204171810; Mon, 19 Aug 2019 01:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566204171; cv=none; d=google.com; s=arc-20160816; b=Dws2+0cABYtG4EMMb9PpOKAl3Rb4sDmyOq/prPBWgl6eABwNrguQoqYM3Kyy9p/XpE cg7WfPMtLsFxrl6SU6Bp94yUX8MUo4wtg33LuX8xhPSdj28GH6MLV0sK1gckmSxOZK/k SB+0Eh6qP2ma8pawVnwAJTMxd0x2HYcO/5y/vIL1trlYxqc1YiO7zrxC1IvTRlBsW/03 ypsDpbMDO7Gs3ts0s6Pb6mXzncVS583a2EE95nTTZ0He68hcJLyz6dLosBNvwdJ3BWw0 /ZYAsUyZbiAKfFtW74wD9kOvD5xc/9XT2THMbYw+LkIf7ANlj4fWuyal8pEZ/ZEorVPD lRKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=456vOzoyYmJV12KqAE0ZXVnUGuS3v8StAaKC6gXTkCQ=; b=dB9ix/qnXOFi4FLIPJlY3jdGxy7eYUwQ21Dl0ir8vchXExw1kiKO9hEb3qQE2vyJeq EC42x25QtsYrZ01tDRrlz8RH5rGI+Siyq5Fgnn9qeCf+VxBWy7S/SLfDr3z/Wnkyj4GF 6i/bATKNI13eitYW4CjPT7LhhmbXUlIZ/XflodLDk/76AkmzM5+3hxhSYynEDO0pssao LRKm5VmJP2EtQZcyl4XyV9h3hOGKgkCUZ8kbsUnWYC6Y1H6/AkGeoFruGj7+HcZ8tWf5 hOkEcFxnA4FeAqI7rZivFSypqWAZ644sBhjm2f8RHojyt6eKzMLE+UUrzA8HVcD1skhi A89Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=eQFwcGSW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si9997421pfa.232.2019.08.19.01.42.35; Mon, 19 Aug 2019 01:42:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=eQFwcGSW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfHSIll (ORCPT + 99 others); Mon, 19 Aug 2019 04:41:41 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:37430 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726661AbfHSIlk (ORCPT ); Mon, 19 Aug 2019 04:41:40 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7J8am7S002873; Mon, 19 Aug 2019 10:41:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=456vOzoyYmJV12KqAE0ZXVnUGuS3v8StAaKC6gXTkCQ=; b=eQFwcGSWO4TCH9yrlEG6xYLU2wwbdTIPHeRohZsxxoaEOfF9BAIbFfwR2rJh84FzhlZm fGA8E3/zZ4eKwtnrGxXVjPb3qYOJ8qoMTfauma0LFFXc6gKs6BbQXxyHP3NHEu318D5A y8ap9wxCcO0QhTYjFFHJs5IbOgp1gs5BHTFnmce6u58TckEh8F8zV/hwb9rjGnUMNR7y iCvJcpAzqMqZVh60KUuLHexGJE8qFmzBJigWmvxiGTOPfxN/Z61X7eAU+lo1As3R3+O8 Sc/2mJGv9PK+NTvnnDgo99+SErN8ucq6m6KMvpHgH6mhi+0PmiJuPToVhqz/SaHY/PZl zA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2ue8fghsx4-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 19 Aug 2019 10:41:29 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BDFC738; Mon, 19 Aug 2019 08:41:28 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AC0232BF4F2; Mon, 19 Aug 2019 10:41:28 +0200 (CEST) Received: from SAFEX1HUBCAS24.st.com (10.75.90.95) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 19 Aug 2019 10:41:28 +0200 Received: from localhost (10.201.23.19) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 19 Aug 2019 10:41:28 +0200 From: Hugues Fruchet To: Alexandre Torgue , Mauro Carvalho Chehab , Hans Verkuil , Sakari Ailus CC: , , , , Benjamin Gaignard , Yannick Fertre , Philippe CORNU , "Hugues Fruchet" , Mickael GUENE Subject: [PATCH v7 3/4] media: stm32-dcmi: add media controller support Date: Mon, 19 Aug 2019 10:41:20 +0200 Message-ID: <1566204081-19051-4-git-send-email-hugues.fruchet@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1566204081-19051-1-git-send-email-hugues.fruchet@st.com> References: <1566204081-19051-1-git-send-email-hugues.fruchet@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.23.19] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-19_02:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add media controller support to dcmi in order to walk within remote subdevices pipeline. Signed-off-by: Hugues Fruchet --- drivers/media/platform/Kconfig | 2 +- drivers/media/platform/stm32/stm32-dcmi.c | 52 ++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index 8a19654..de7e21f 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -121,7 +121,7 @@ config VIDEO_S3C_CAMIF config VIDEO_STM32_DCMI tristate "STM32 Digital Camera Memory Interface (DCMI) support" - depends on VIDEO_V4L2 && OF + depends on VIDEO_V4L2 && OF && MEDIA_CONTROLLER depends on ARCH_STM32 || COMPILE_TEST select VIDEOBUF2_DMA_CONTIG select V4L2_FWNODE diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index db01210..9293949 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -169,6 +169,9 @@ struct stm32_dcmi { /* Ensure DMA operations atomicity */ struct mutex dma_lock; + + struct media_device mdev; + struct media_pad vid_cap_pad; }; static inline struct stm32_dcmi *notifier_to_dcmi(struct v4l2_async_notifier *n) @@ -1560,14 +1563,6 @@ static int dcmi_graph_notify_complete(struct v4l2_async_notifier *notifier) return ret; } - ret = video_register_device(dcmi->vdev, VFL_TYPE_GRABBER, -1); - if (ret) { - dev_err(dcmi->dev, "Failed to register video device\n"); - return ret; - } - - dev_dbg(dcmi->dev, "Device registered as %s\n", - video_device_node_name(dcmi->vdev)); return 0; } @@ -1760,10 +1755,19 @@ static int dcmi_probe(struct platform_device *pdev) q = &dcmi->queue; + dcmi->v4l2_dev.mdev = &dcmi->mdev; + + /* Initialize media device */ + strscpy(dcmi->mdev.model, DRV_NAME, sizeof(dcmi->mdev.model)); + snprintf(dcmi->mdev.bus_info, sizeof(dcmi->mdev.bus_info), + "platform:%s", DRV_NAME); + dcmi->mdev.dev = &pdev->dev; + media_device_init(&dcmi->mdev); + /* Initialize the top-level structure */ ret = v4l2_device_register(&pdev->dev, &dcmi->v4l2_dev); if (ret) - goto err_dma_release; + goto err_media_device_cleanup; dcmi->vdev = video_device_alloc(); if (!dcmi->vdev) { @@ -1783,6 +1787,25 @@ static int dcmi_probe(struct platform_device *pdev) V4L2_CAP_READWRITE; video_set_drvdata(dcmi->vdev, dcmi); + /* Media entity pads */ + dcmi->vid_cap_pad.flags = MEDIA_PAD_FL_SINK; + ret = media_entity_pads_init(&dcmi->vdev->entity, + 1, &dcmi->vid_cap_pad); + if (ret) { + dev_err(dcmi->dev, "Failed to init media entity pad\n"); + goto err_device_release; + } + dcmi->vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT; + + ret = video_register_device(dcmi->vdev, VFL_TYPE_GRABBER, -1); + if (ret) { + dev_err(dcmi->dev, "Failed to register video device\n"); + goto err_media_entity_cleanup; + } + + dev_dbg(dcmi->dev, "Device registered as %s\n", + video_device_node_name(dcmi->vdev)); + /* Buffer queue */ q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; q->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF; @@ -1798,12 +1821,12 @@ static int dcmi_probe(struct platform_device *pdev) ret = vb2_queue_init(q); if (ret < 0) { dev_err(&pdev->dev, "Failed to initialize vb2 queue\n"); - goto err_device_release; + goto err_media_entity_cleanup; } ret = dcmi_graph_init(dcmi); if (ret < 0) - goto err_device_release; + goto err_media_entity_cleanup; /* Reset device */ ret = reset_control_assert(dcmi->rstc); @@ -1830,11 +1853,14 @@ static int dcmi_probe(struct platform_device *pdev) err_cleanup: v4l2_async_notifier_cleanup(&dcmi->notifier); +err_media_entity_cleanup: + media_entity_cleanup(&dcmi->vdev->entity); err_device_release: video_device_release(dcmi->vdev); err_device_unregister: v4l2_device_unregister(&dcmi->v4l2_dev); -err_dma_release: +err_media_device_cleanup: + media_device_cleanup(&dcmi->mdev); dma_release_channel(dcmi->dma_chan); return ret; @@ -1848,7 +1874,9 @@ static int dcmi_remove(struct platform_device *pdev) v4l2_async_notifier_unregister(&dcmi->notifier); v4l2_async_notifier_cleanup(&dcmi->notifier); + media_entity_cleanup(&dcmi->vdev->entity); v4l2_device_unregister(&dcmi->v4l2_dev); + media_device_cleanup(&dcmi->mdev); dma_release_channel(dcmi->dma_chan); -- 2.7.4