Message ID | 20170609161026.7582-1-khilman@baylibre.com (mailing list archive) |
---|---|
State | Accepted, archived |
Delegated to: | Hans Verkuil |
Headers |
Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from <linux-media-owner@vger.kernel.org>) id 1dJMUh-00026l-Mc; Fri, 09 Jun 2017 16:10:39 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.89/mailfrontend-6) with esmtp id 1dJMUf-0003Gr-4B; Fri, 09 Jun 2017 18:10:39 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751965AbdFIQKe (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Fri, 9 Jun 2017 12:10:34 -0400 Received: from mail-pg0-f52.google.com ([74.125.83.52]:36125 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751956AbdFIQKd (ORCPT <rfc822; linux-media@vger.kernel.org>); Fri, 9 Jun 2017 12:10:33 -0400 Received: by mail-pg0-f52.google.com with SMTP id a70so27962751pge.3 for <linux-media@vger.kernel.org>; Fri, 09 Jun 2017 09:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IY6AT+WRY7UkQyJf1tVZvx2hLc7uzzrcCpRW7QP/EzA=; b=1gj/EJgGB9yRYqHEA0L/N8EShTAodjWY+dzgFIQxsWzqHcjzfD9AsPsqYLpPbKLYEy QghrxOGCk+pj8gk5JglowFp68niksfedXgCZRdd1a6R1MDahK98UHe9zEzv84/I7Ussl qnm8hBVaCsp4UxoP1JH4R8xeaoo9pdcfir9Hq0Op+cA7Zoi39GoDRcrPhWUGiKS6OkJR vt3tcS8DAtakVU3k/TFTiQDWUt7I9Bu+23LvLj1osFSSsojsaMl5aF75uLuhbZub0WEY hus1EOED64taF5CqWq9coOvhM4Iesup/gay7VrP2LsAd3a4s+BPPGMtFS2TFV2M8xlRW tudA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IY6AT+WRY7UkQyJf1tVZvx2hLc7uzzrcCpRW7QP/EzA=; b=tsh53pjmUGRJZk8X9iRBqWt3XGI7ycy13xHUDhX52u6eadzPrVbMVrhY5Ev0PiqIy+ dmgqe0k83xoFiqj1gGoxt0rXDza4XMol39B4Gj4OBGPeBspJVEv6j0XG4VyasjLy8DAd Z1VMZ9Ul7WpJ0+8+bZsE/ROzfaon2aW748/c8dqQr4KKCYyYFlcosQCHtEh5RYk8DA5L yLypdeYQtAyXdjG+yz5q3BuJKY+UIyKW2Gvpfvf75GreIL2c/aWFV2TdkI8ph7Zztx6o t9gpuO4LgmpUnWMmRj6DO7hal4gIdyllhCeJkf3MyAy/QujQi5snrhcx8VI5R85Msa5H pASA== X-Gm-Message-State: AODbwcDcCgmL6WJd1tg/7Rhn50OVdTZxEn1IMWyWyl4lZKEiOEYwxtgf UcV6eZm9kkcLIKn9 X-Received: by 10.99.99.134 with SMTP id x128mr4898996pgb.81.1497024632535; Fri, 09 Jun 2017 09:10:32 -0700 (PDT) Received: from localhost (c-98-203-232-209.hsd1.wa.comcast.net. [98.203.232.209]) by smtp.gmail.com with ESMTPSA id u85sm4239622pfg.73.2017.06.09.09.10.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jun 2017 09:10:32 -0700 (PDT) From: Kevin Hilman <khilman@baylibre.com> To: Mauro Carvalho Chehab <mchehab@s-opensource.com>, Hans Verkuil <hverkuil@xs4all.nl>, linux-media@vger.kernel.org Cc: Sekhar Nori <nsekhar@ti.com>, David Lechner <david@lechnology.com>, Patrick Titiano <ptitiano@baylibre.com>, Benoit Parrot <bparrot@ti.com>, Prabhakar Lad <prabhakar.csengg@gmail.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] [media] davinci: vpif: adaptions for DT support Date: Fri, 9 Jun 2017 09:10:26 -0700 Message-Id: <20170609161026.7582-1-khilman@baylibre.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2017.6.9.155417 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, DKIM_SIGNATURE 0, LEGITIMATE_SIGNS 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __CTE 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_LIST_ID 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __NO_HTML_TAG_RAW 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_REAL_NAMES 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' |
Commit Message
Kevin Hilman
June 9, 2017, 4:10 p.m. UTC
The davinci VPIF is a single hardware block, but the existing driver
is broken up into a common library (vpif.c), output (vpif_display.c) and
intput (vpif_capture.c).
When migrating to DT, to better model the hardware, and because
registers, interrupts, etc. are all common,it was decided to
have a single VPIF hardware node[1].
Because davinci uses legacy, non-DT boot on several SoCs still, the
platform_drivers need to remain. But they are also needed in DT boot.
Since there are no DT nodes for the display/capture parts in DT
boot (there is a single node for the parent/common device) we need to
create platform_devices somewhere to instansiate the platform_drivers.
When VPIF display/capture are needed for a DT boot, the VPIF node
will have endpoints defined for its subdevs. Therefore, vpif_probe()
checks for the presence of endpoints, and if detected manually creates
the platform_devices for the display and capture platform_drivers.
[1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt
Signed-off-by: Kevin Hilman <khilman@baylibre.com>
---
Changes since v1:
- added proper error checking to kzalloc calls
- rebased onto media/master
drivers/media/platform/davinci/vpif.c | 57 ++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
Comments
Hi Hans, Mauro, On Fri, Jun 9, 2017 at 9:10 AM, Kevin Hilman <khilman@baylibre.com> wrote: > The davinci VPIF is a single hardware block, but the existing driver > is broken up into a common library (vpif.c), output (vpif_display.c) and > intput (vpif_capture.c). > > When migrating to DT, to better model the hardware, and because > registers, interrupts, etc. are all common,it was decided to > have a single VPIF hardware node[1]. > > Because davinci uses legacy, non-DT boot on several SoCs still, the > platform_drivers need to remain. But they are also needed in DT boot. > Since there are no DT nodes for the display/capture parts in DT > boot (there is a single node for the parent/common device) we need to > create platform_devices somewhere to instansiate the platform_drivers. > > When VPIF display/capture are needed for a DT boot, the VPIF node > will have endpoints defined for its subdevs. Therefore, vpif_probe() > checks for the presence of endpoints, and if detected manually creates > the platform_devices for the display and capture platform_drivers. > > [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt > > Signed-off-by: Kevin Hilman <khilman@baylibre.com> Can this one make it for v4.13 along with the rest of the series that it was initially sent with? This one needed a respin for some error checking, but is otherwise unchanged, and has been tested on top of media/next. Thanks, Kevin
Hi Kevin, On Fri, Jun 09, 2017 at 09:10:26AM -0700, Kevin Hilman wrote: > The davinci VPIF is a single hardware block, but the existing driver > is broken up into a common library (vpif.c), output (vpif_display.c) and > intput (vpif_capture.c). > > When migrating to DT, to better model the hardware, and because > registers, interrupts, etc. are all common,it was decided to > have a single VPIF hardware node[1]. > > Because davinci uses legacy, non-DT boot on several SoCs still, the > platform_drivers need to remain. But they are also needed in DT boot. > Since there are no DT nodes for the display/capture parts in DT > boot (there is a single node for the parent/common device) we need to > create platform_devices somewhere to instansiate the platform_drivers. > > When VPIF display/capture are needed for a DT boot, the VPIF node > will have endpoints defined for its subdevs. Therefore, vpif_probe() > checks for the presence of endpoints, and if detected manually creates > the platform_devices for the display and capture platform_drivers. > > [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt > > Signed-off-by: Kevin Hilman <khilman@baylibre.com> > --- > Changes since v1: > - added proper error checking to kzalloc calls > - rebased onto media/master > > drivers/media/platform/davinci/vpif.c | 57 ++++++++++++++++++++++++++++++++++- > 1 file changed, 56 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c > index 1b02a6363f77..c2d214dfaa3e 100644 > --- a/drivers/media/platform/davinci/vpif.c > +++ b/drivers/media/platform/davinci/vpif.c > @@ -26,6 +26,7 @@ > #include <linux/pm_runtime.h> > #include <linux/spinlock.h> > #include <linux/v4l2-dv-timings.h> > +#include <linux/of_graph.h> > > #include "vpif.h" > > @@ -423,7 +424,9 @@ EXPORT_SYMBOL(vpif_channel_getfid); > > static int vpif_probe(struct platform_device *pdev) > { > - static struct resource *res; > + static struct resource *res, *res_irq; > + struct platform_device *pdev_capture, *pdev_display; > + struct device_node *endpoint = NULL; > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > vpif_base = devm_ioremap_resource(&pdev->dev, res); > @@ -435,6 +438,58 @@ static int vpif_probe(struct platform_device *pdev) > > spin_lock_init(&vpif_lock); > dev_info(&pdev->dev, "vpif probe success\n"); > + > + /* > + * If VPIF Node has endpoints, assume "new" DT support, > + * where capture and display drivers don't have DT nodes > + * so their devices need to be registered manually here > + * for their legacy platform_drivers to work. > + */ > + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, > + endpoint); > + if (!endpoint) > + return 0; > + > + /* > + * For DT platforms, manually create platform_devices for > + * capture/display drivers. > + */ > + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); > + if (!res_irq) { > + dev_warn(&pdev->dev, "Missing IRQ resource.\n"); > + return -EINVAL; > + } > + > + pdev_capture = devm_kzalloc(&pdev->dev, sizeof(*pdev_capture), > + GFP_KERNEL); > + if (pdev_capture) { > + pdev_capture->name = "vpif_capture"; > + pdev_capture->id = -1; > + pdev_capture->resource = res_irq; > + pdev_capture->num_resources = 1; > + pdev_capture->dev.dma_mask = pdev->dev.dma_mask; > + pdev_capture->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; > + pdev_capture->dev.parent = &pdev->dev; > + platform_device_register(pdev_capture); Don't both of these (vpif_capture and vpif_display) depend on platform data? Or do I miss something? > + } else { > + dev_warn(&pdev->dev, "Unable to allocate memory for pdev_capture.\n"); > + } > + > + pdev_display = devm_kzalloc(&pdev->dev, sizeof(*pdev_display), > + GFP_KERNEL); > + if (pdev_display) { > + pdev_display->name = "vpif_display"; > + pdev_display->id = -1; > + pdev_display->resource = res_irq; > + pdev_display->num_resources = 1; > + pdev_display->dev.dma_mask = pdev->dev.dma_mask; > + pdev_display->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; > + pdev_display->dev.parent = &pdev->dev; > + platform_device_register(pdev_display); > + } else { > + dev_warn(&pdev->dev, "Unable to allocate memory for pdev_display.\n"); > + } > + > return 0; > } >
Sakari Ailus <sakari.ailus@iki.fi> writes: > Hi Kevin, > > On Fri, Jun 09, 2017 at 09:10:26AM -0700, Kevin Hilman wrote: >> The davinci VPIF is a single hardware block, but the existing driver >> is broken up into a common library (vpif.c), output (vpif_display.c) and >> intput (vpif_capture.c). >> >> When migrating to DT, to better model the hardware, and because >> registers, interrupts, etc. are all common,it was decided to >> have a single VPIF hardware node[1]. >> >> Because davinci uses legacy, non-DT boot on several SoCs still, the >> platform_drivers need to remain. But they are also needed in DT boot. >> Since there are no DT nodes for the display/capture parts in DT >> boot (there is a single node for the parent/common device) we need to >> create platform_devices somewhere to instansiate the platform_drivers. >> >> When VPIF display/capture are needed for a DT boot, the VPIF node >> will have endpoints defined for its subdevs. Therefore, vpif_probe() >> checks for the presence of endpoints, and if detected manually creates >> the platform_devices for the display and capture platform_drivers. >> >> [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt >> >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >> --- >> Changes since v1: >> - added proper error checking to kzalloc calls >> - rebased onto media/master >> >> drivers/media/platform/davinci/vpif.c | 57 ++++++++++++++++++++++++++++++++++- >> 1 file changed, 56 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c >> index 1b02a6363f77..c2d214dfaa3e 100644 >> --- a/drivers/media/platform/davinci/vpif.c >> +++ b/drivers/media/platform/davinci/vpif.c >> @@ -26,6 +26,7 @@ >> #include <linux/pm_runtime.h> >> #include <linux/spinlock.h> >> #include <linux/v4l2-dv-timings.h> >> +#include <linux/of_graph.h> >> >> #include "vpif.h" >> >> @@ -423,7 +424,9 @@ EXPORT_SYMBOL(vpif_channel_getfid); >> >> static int vpif_probe(struct platform_device *pdev) >> { >> - static struct resource *res; >> + static struct resource *res, *res_irq; >> + struct platform_device *pdev_capture, *pdev_display; >> + struct device_node *endpoint = NULL; >> >> res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> vpif_base = devm_ioremap_resource(&pdev->dev, res); >> @@ -435,6 +438,58 @@ static int vpif_probe(struct platform_device *pdev) >> >> spin_lock_init(&vpif_lock); >> dev_info(&pdev->dev, "vpif probe success\n"); >> + >> + /* >> + * If VPIF Node has endpoints, assume "new" DT support, >> + * where capture and display drivers don't have DT nodes >> + * so their devices need to be registered manually here >> + * for their legacy platform_drivers to work. >> + */ >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, >> + endpoint); >> + if (!endpoint) >> + return 0; >> + >> + /* >> + * For DT platforms, manually create platform_devices for >> + * capture/display drivers. >> + */ >> + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); >> + if (!res_irq) { >> + dev_warn(&pdev->dev, "Missing IRQ resource.\n"); >> + return -EINVAL; >> + } >> + >> + pdev_capture = devm_kzalloc(&pdev->dev, sizeof(*pdev_capture), >> + GFP_KERNEL); >> + if (pdev_capture) { >> + pdev_capture->name = "vpif_capture"; >> + pdev_capture->id = -1; >> + pdev_capture->resource = res_irq; >> + pdev_capture->num_resources = 1; >> + pdev_capture->dev.dma_mask = pdev->dev.dma_mask; >> + pdev_capture->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; >> + pdev_capture->dev.parent = &pdev->dev; >> + platform_device_register(pdev_capture); > > Don't both of these (vpif_capture and vpif_display) depend on platform data? > Or do I miss something? The driver can (continue to) work in legacy mode with platform_data. In that case, there is no VPIF DT node (or a node without endpoints). However, with recent changes, it can also work in DT mode, where the VPIF node and endpoints used for display/capture come from DT, in which case these nodes are created an don't depend on platform_data at all. Hope that clarifies things, and thanks for the review, Kevin
On Fri, Jun 16, 2017 at 10:49:24AM -0700, Kevin Hilman wrote: > Sakari Ailus <sakari.ailus@iki.fi> writes: > > > Hi Kevin, > > > > On Fri, Jun 09, 2017 at 09:10:26AM -0700, Kevin Hilman wrote: > >> The davinci VPIF is a single hardware block, but the existing driver > >> is broken up into a common library (vpif.c), output (vpif_display.c) and > >> intput (vpif_capture.c). > >> > >> When migrating to DT, to better model the hardware, and because > >> registers, interrupts, etc. are all common,it was decided to > >> have a single VPIF hardware node[1]. > >> > >> Because davinci uses legacy, non-DT boot on several SoCs still, the > >> platform_drivers need to remain. But they are also needed in DT boot. > >> Since there are no DT nodes for the display/capture parts in DT > >> boot (there is a single node for the parent/common device) we need to > >> create platform_devices somewhere to instansiate the platform_drivers. > >> > >> When VPIF display/capture are needed for a DT boot, the VPIF node > >> will have endpoints defined for its subdevs. Therefore, vpif_probe() > >> checks for the presence of endpoints, and if detected manually creates > >> the platform_devices for the display and capture platform_drivers. > >> > >> [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt > >> > >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> > >> --- > >> Changes since v1: > >> - added proper error checking to kzalloc calls > >> - rebased onto media/master > >> > >> drivers/media/platform/davinci/vpif.c | 57 ++++++++++++++++++++++++++++++++++- > >> 1 file changed, 56 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c > >> index 1b02a6363f77..c2d214dfaa3e 100644 > >> --- a/drivers/media/platform/davinci/vpif.c > >> +++ b/drivers/media/platform/davinci/vpif.c > >> @@ -26,6 +26,7 @@ > >> #include <linux/pm_runtime.h> > >> #include <linux/spinlock.h> > >> #include <linux/v4l2-dv-timings.h> > >> +#include <linux/of_graph.h> > >> > >> #include "vpif.h" > >> > >> @@ -423,7 +424,9 @@ EXPORT_SYMBOL(vpif_channel_getfid); > >> > >> static int vpif_probe(struct platform_device *pdev) > >> { > >> - static struct resource *res; > >> + static struct resource *res, *res_irq; > >> + struct platform_device *pdev_capture, *pdev_display; > >> + struct device_node *endpoint = NULL; > >> > >> res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > >> vpif_base = devm_ioremap_resource(&pdev->dev, res); > >> @@ -435,6 +438,58 @@ static int vpif_probe(struct platform_device *pdev) > >> > >> spin_lock_init(&vpif_lock); > >> dev_info(&pdev->dev, "vpif probe success\n"); > >> + > >> + /* > >> + * If VPIF Node has endpoints, assume "new" DT support, > >> + * where capture and display drivers don't have DT nodes > >> + * so their devices need to be registered manually here > >> + * for their legacy platform_drivers to work. > >> + */ > >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, > >> + endpoint); > >> + if (!endpoint) > >> + return 0; > >> + > >> + /* > >> + * For DT platforms, manually create platform_devices for > >> + * capture/display drivers. > >> + */ > >> + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); > >> + if (!res_irq) { > >> + dev_warn(&pdev->dev, "Missing IRQ resource.\n"); > >> + return -EINVAL; > >> + } > >> + > >> + pdev_capture = devm_kzalloc(&pdev->dev, sizeof(*pdev_capture), > >> + GFP_KERNEL); > >> + if (pdev_capture) { > >> + pdev_capture->name = "vpif_capture"; > >> + pdev_capture->id = -1; > >> + pdev_capture->resource = res_irq; > >> + pdev_capture->num_resources = 1; > >> + pdev_capture->dev.dma_mask = pdev->dev.dma_mask; > >> + pdev_capture->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; > >> + pdev_capture->dev.parent = &pdev->dev; > >> + platform_device_register(pdev_capture); > > > > Don't both of these (vpif_capture and vpif_display) depend on platform data? > > Or do I miss something? > > The driver can (continue to) work in legacy mode with platform_data. In > that case, there is no VPIF DT node (or a node without endpoints). > > However, with recent changes, it can also work in DT mode, where the > VPIF node and endpoints used for display/capture come from DT, in which > case these nodes are created an don't depend on platform_data at all. > > Hope that clarifies things, and thanks for the review, Oh, I think I missed the fact that what is parsed from DT is still referred to as platform data in the driver. (Both of the drivers are testing if dev->platform_data is non-NULL twice in a row. Unrelated to this patch, just FYI.) How do the newly created child devices get their OF nodes? If endpoint is non-NULL, it needs to be put using of_node_put().
On 06/09/2017 06:10 PM, Kevin Hilman wrote: > The davinci VPIF is a single hardware block, but the existing driver > is broken up into a common library (vpif.c), output (vpif_display.c) and > intput (vpif_capture.c). > > When migrating to DT, to better model the hardware, and because > registers, interrupts, etc. are all common,it was decided to > have a single VPIF hardware node[1]. > > Because davinci uses legacy, non-DT boot on several SoCs still, the > platform_drivers need to remain. But they are also needed in DT boot. > Since there are no DT nodes for the display/capture parts in DT > boot (there is a single node for the parent/common device) we need to > create platform_devices somewhere to instansiate the platform_drivers. > > When VPIF display/capture are needed for a DT boot, the VPIF node > will have endpoints defined for its subdevs. Therefore, vpif_probe() > checks for the presence of endpoints, and if detected manually creates > the platform_devices for the display and capture platform_drivers. > > [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt > > Signed-off-by: Kevin Hilman <khilman@baylibre.com> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
On Fri, Jun 9, 2017 at 5:10 PM, Kevin Hilman <khilman@baylibre.com> wrote: > The davinci VPIF is a single hardware block, but the existing driver > is broken up into a common library (vpif.c), output (vpif_display.c) and > intput (vpif_capture.c). > > When migrating to DT, to better model the hardware, and because > registers, interrupts, etc. are all common,it was decided to > have a single VPIF hardware node[1]. > > Because davinci uses legacy, non-DT boot on several SoCs still, the > platform_drivers need to remain. But they are also needed in DT boot. > Since there are no DT nodes for the display/capture parts in DT > boot (there is a single node for the parent/common device) we need to > create platform_devices somewhere to instansiate the platform_drivers. > > When VPIF display/capture are needed for a DT boot, the VPIF node > will have endpoints defined for its subdevs. Therefore, vpif_probe() > checks for the presence of endpoints, and if detected manually creates > the platform_devices for the display and capture platform_drivers. > > [1] Documentation/devicetree/bindings/media/ti,da850-vpif.txt > > Signed-off-by: Kevin Hilman <khilman@baylibre.com> Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> Cheers, --Prabhakar Lad
diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c index 1b02a6363f77..c2d214dfaa3e 100644 --- a/drivers/media/platform/davinci/vpif.c +++ b/drivers/media/platform/davinci/vpif.c @@ -26,6 +26,7 @@ #include <linux/pm_runtime.h> #include <linux/spinlock.h> #include <linux/v4l2-dv-timings.h> +#include <linux/of_graph.h> #include "vpif.h" @@ -423,7 +424,9 @@ EXPORT_SYMBOL(vpif_channel_getfid); static int vpif_probe(struct platform_device *pdev) { - static struct resource *res; + static struct resource *res, *res_irq; + struct platform_device *pdev_capture, *pdev_display; + struct device_node *endpoint = NULL; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); vpif_base = devm_ioremap_resource(&pdev->dev, res); @@ -435,6 +438,58 @@ static int vpif_probe(struct platform_device *pdev) spin_lock_init(&vpif_lock); dev_info(&pdev->dev, "vpif probe success\n"); + + /* + * If VPIF Node has endpoints, assume "new" DT support, + * where capture and display drivers don't have DT nodes + * so their devices need to be registered manually here + * for their legacy platform_drivers to work. + */ + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, + endpoint); + if (!endpoint) + return 0; + + /* + * For DT platforms, manually create platform_devices for + * capture/display drivers. + */ + res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res_irq) { + dev_warn(&pdev->dev, "Missing IRQ resource.\n"); + return -EINVAL; + } + + pdev_capture = devm_kzalloc(&pdev->dev, sizeof(*pdev_capture), + GFP_KERNEL); + if (pdev_capture) { + pdev_capture->name = "vpif_capture"; + pdev_capture->id = -1; + pdev_capture->resource = res_irq; + pdev_capture->num_resources = 1; + pdev_capture->dev.dma_mask = pdev->dev.dma_mask; + pdev_capture->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; + pdev_capture->dev.parent = &pdev->dev; + platform_device_register(pdev_capture); + } else { + dev_warn(&pdev->dev, "Unable to allocate memory for pdev_capture.\n"); + } + + pdev_display = devm_kzalloc(&pdev->dev, sizeof(*pdev_display), + GFP_KERNEL); + if (pdev_display) { + pdev_display->name = "vpif_display"; + pdev_display->id = -1; + pdev_display->resource = res_irq; + pdev_display->num_resources = 1; + pdev_display->dev.dma_mask = pdev->dev.dma_mask; + pdev_display->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; + pdev_display->dev.parent = &pdev->dev; + platform_device_register(pdev_display); + } else { + dev_warn(&pdev->dev, "Unable to allocate memory for pdev_display.\n"); + } + return 0; }