Message ID | 20161122155244.802-4-khilman@baylibre.com (mailing list archive) |
---|---|
State | Superseded, 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 1c9DNf-0003x8-9J; Tue, 22 Nov 2016 15:53:11 +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.84_2/mailfrontend-6) with esmtp id 1c9DNc-0005yU-5y; Tue, 22 Nov 2016 16:53:11 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933013AbcKVPw5 (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Tue, 22 Nov 2016 10:52:57 -0500 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33507 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755480AbcKVPwu (ORCPT <rfc822;linux-media@vger.kernel.org>); Tue, 22 Nov 2016 10:52:50 -0500 Received: by mail-pg0-f49.google.com with SMTP id 3so8905902pgd.0 for <linux-media@vger.kernel.org>; Tue, 22 Nov 2016 07:52:49 -0800 (PST) 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:in-reply-to:references :mime-version:content-transfer-encoding; bh=nqgxUpO5Bzmqrq2P91yNd9zyWckoXoHfNFFknHe7QrI=; b=L/o7tvOpHL6yCqcdDVnl3Aopy8/vz+Nm8tFTpA5ZC8T8ulQcgL29z4TqdORlVCifod 9GUNi5baqsilRG5Wbh/zGi9C099bq+SETaNDWE0FvmVE9t+GM7Wbcs5hCR/PtoLMu9Pf 5tArMgzTdFrSJVCYcTcpXzeS4YqyRZ+s89VLKxE6jDBoTk+cPFmdrbo/gUNoZetCnQa7 TlbnnuwaqBm1lYT7QcvPEn2YOA5zAk9LDXRx8PfQd0mYH8L4j5uPkMb8TYvDkykJTVMQ e3Pw5XOfV2rfuCpD4QQg2vLGAEOEZx5qJe+sYiMrdISYAkslAgEpbvLpo+9tC10+O7HR fgNg== 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:mime-version:content-transfer-encoding; bh=nqgxUpO5Bzmqrq2P91yNd9zyWckoXoHfNFFknHe7QrI=; b=I8G8Lj1bLhqvOSZKKf3MQhNbJCfDIutoOlHXssUbh68D4srUvYS2mLp+XnLuN95pJd P0ssFgDqoznoeMV8sXhaqRIp8t8kKSe24zRBqAiWKGdNOsijHD3C1rNj2lIk1dkh5sKD DaN7BaFsEEoC8SNfd7ftrakc+5RgBdab1AejzfFKEmKAAoQGH7YuH/6OnQ6cID1eqeMt t3To7PF582ZmezU0yLffWhXVga5qq033S1qWATjbeJVHTDmAuCNhxEkNAKNcGbR32R6L 1KIBOM8QMQUpD3D3JPkD/HBQV2UXVQ2ItbQ7RbkpOQ+ovgCcyp/yXO2lSkdPviqEUIqJ kjBg== X-Gm-Message-State: AKaTC00LdAs5iY+EL9tC+kaV2GmgF9tq77yD17FqnFwe2BcF0GfV7mlotiEw2XQOzaw5/a+X X-Received: by 10.99.140.77 with SMTP id q13mr45374874pgn.109.1479829969035; Tue, 22 Nov 2016 07:52:49 -0800 (PST) Received: from localhost (c-98-203-232-209.hsd1.wa.comcast.net. [98.203.232.209]) by smtp.gmail.com with ESMTPSA id 74sm28289162pge.2.2016.11.22.07.52.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Nov 2016 07:52:48 -0800 (PST) From: Kevin Hilman <khilman@baylibre.com> To: linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl> Cc: devicetree@vger.kernel.org, Sekhar Nori <nsekhar@ti.com>, Axel Haslam <ahaslam@baylibre.com>, =?UTF-8?q?Bartosz=20Go=C5=82aszewski?= <bgolaszewski@baylibre.com>, Alexandre Bailon <abailon@baylibre.com>, David Lechner <david@lechnology.com> Subject: [PATCH v3 3/4] [media] davinci: vpif_capture: get subdevs from DT Date: Tue, 22 Nov 2016 07:52:43 -0800 Message-Id: <20161122155244.802-4-khilman@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161122155244.802-1-khilman@baylibre.com> References: <20161122155244.802-1-khilman@baylibre.com> 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: 2016.11.22.154817 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, DATE_TZ_NA 0, DKIM_SIGNATURE 0, IN_REP_TO 0, LEGITIMATE_NEGATE 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, SINGLE_URI_IN_BODY 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __CTE 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __LINES_OF_YELLING 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, __REFERENCES 0, __SANE_MSGID 0, __SINGLE_URI_TEXT 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_NO_NAME 0, __TO_REAL_NAMES 0, __URI_IN_BODY 0, __URI_NO_WWW 0, __URI_NS , __URI_WITH_PATH 0, __YOUTUBE_RCVD 0' |
Commit Message
Kevin Hilman
Nov. 22, 2016, 3:52 p.m. UTC
Allow getting of subdevs from DT ports and endpoints.
The _get_pdata() function was larely inspired by (i.e. stolen from)
am437x-vpfe.c
Signed-off-by: Kevin Hilman <khilman@baylibre.com>
---
drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++-
include/media/davinci/vpif_types.h | 9 +-
2 files changed, 133 insertions(+), 6 deletions(-)
Comments
Hi Kevin, On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: > Allow getting of subdevs from DT ports and endpoints. > > The _get_pdata() function was larely inspired by (i.e. stolen from) vpif_capture_get_pdata and "largely"? > am437x-vpfe.c > > Signed-off-by: Kevin Hilman <khilman@baylibre.com> > --- > drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- > include/media/davinci/vpif_types.h | 9 +- > 2 files changed, 133 insertions(+), 6 deletions(-) > > diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c > index 94ee6cf03f02..47a4699157e7 100644 > --- a/drivers/media/platform/davinci/vpif_capture.c > +++ b/drivers/media/platform/davinci/vpif_capture.c > @@ -26,6 +26,8 @@ > #include <linux/slab.h> > > #include <media/v4l2-ioctl.h> > +#include <media/v4l2-of.h> > +#include <media/i2c/tvp514x.h> Do you need this header? > > #include "vpif.h" > #include "vpif_capture.h" > @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( > > vpif_dbg(2, debug, "vpif_input_to_subdev\n"); > > + if (!chan_cfg) > + return -1; > + if (input_index >= chan_cfg->input_count) > + return -1; > subdev_name = chan_cfg->inputs[input_index].subdev_name; > if (subdev_name == NULL) > return -1; > @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( > /* loop through the sub device list to get the sub device info */ > for (i = 0; i < vpif_cfg->subdev_count; i++) { > subdev_info = &vpif_cfg->subdev_info[i]; > - if (!strcmp(subdev_info->name, subdev_name)) > + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) > return i; > } > return -1; > @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, > { > int i; > > + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { > + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; > + const struct device_node *node = _asd->match.of.node; > + > + if (node == subdev->of_node) { > + vpif_obj.sd[i] = subdev; > + vpif_obj.config->chan_config->inputs[i].subdev_name = > + (char *)subdev->of_node->full_name; > + vpif_dbg(2, debug, > + "%s: setting input %d subdev_name = %s\n", > + __func__, i, subdev->of_node->full_name); > + return 0; > + } > + } > + > for (i = 0; i < vpif_obj.config->subdev_count; i++) > if (!strcmp(vpif_obj.config->subdev_info[i].name, > subdev->name)) { > @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) > return vpif_probe_complete(); > } > > +static struct vpif_capture_config * > +vpif_capture_get_pdata(struct platform_device *pdev) > +{ > + struct device_node *endpoint = NULL; > + struct v4l2_of_endpoint bus_cfg; > + struct vpif_capture_config *pdata; > + struct vpif_subdev_info *sdinfo; > + struct vpif_capture_chan_config *chan; > + unsigned int i; > + > + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); > + > + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) > + return pdev->dev.platform_data; > + > + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > + if (!pdata) > + return NULL; > + pdata->subdev_info = > + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * > + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); > + > + if (!pdata->subdev_info) > + return NULL; > + dev_dbg(&pdev->dev, "%s\n", __func__); > + > + for (i = 0; ; i++) { > + struct device_node *rem; > + unsigned int flags; > + int err; > + > + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, > + endpoint); > + if (!endpoint) > + break; > + > + sdinfo = &pdata->subdev_info[i]; subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > + chan = &pdata->chan_config[i]; > + chan->inputs = devm_kzalloc(&pdev->dev, > + sizeof(*chan->inputs) * > + VPIF_DISPLAY_MAX_CHANNELS, > + GFP_KERNEL); > + > + chan->input_count++; > + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; I wonder what's the purpose of using index i on this array as well. If you use that to access a corresponding entry in a different array, I'd just create a struct that contains the port configuration and the async sub-device. The omap3isp driver does that, for instance; see isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're interested. Up to you. > + chan->inputs[i].input.std = V4L2_STD_ALL; > + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; > + > + /* FIXME: need a new property? ch0:composite ch1: s-video */ > + if (i == 0) Can you assume that the first endopoint has got a particular kind of input? What if it's not connected? If this is a different physical port (not in the meaning another) in the device, I'd use the reg property for this. Please see Documentation/devicetree/bindings/media/video-interfaces.txt . > + chan->inputs[i].input_route = INPUT_CVBS_VI2B; > + else > + chan->inputs[i].input_route = INPUT_SVIDEO_VI2C_VI1C; > + chan->inputs[i].output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC; > + > + err = v4l2_of_parse_endpoint(endpoint, &bus_cfg); > + if (err) { > + dev_err(&pdev->dev, "Could not parse the endpoint\n"); > + goto done; > + } > + dev_dbg(&pdev->dev, "Endpoint %s, bus_width = %d\n", > + endpoint->full_name, bus_cfg.bus.parallel.bus_width); > + flags = bus_cfg.bus.parallel.flags; > + > + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) > + chan->vpif_if.hd_pol = 1; > + > + if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) > + chan->vpif_if.vd_pol = 1; > + > + chan->vpif_if.if_type = VPIF_IF_BT656; > + rem = of_graph_get_remote_port_parent(endpoint); > + if (!rem) { > + dev_dbg(&pdev->dev, "Remote device at %s not found\n", > + endpoint->full_name); > + goto done; > + } > + > + dev_dbg(&pdev->dev, "Remote device %s, %s found\n", > + rem->name, rem->full_name); > + sdinfo->name = rem->full_name; > + > + pdata->asd[i] = devm_kzalloc(&pdev->dev, > + sizeof(struct v4l2_async_subdev), > + GFP_KERNEL); Do you ensure somewhere that i isn't overrunning the pdata->asd[] array? It's got VPIF_CAPTURE_MAX_CHANNELS entries. > + if (!pdata->asd[i]) { > + of_node_put(rem); > + pdata = NULL; > + goto done; > + } > + > + pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF; > + pdata->asd[i]->match.of.node = rem; > + of_node_put(rem); > + } > + > +done: > + pdata->asd_sizes[0] = i; > + pdata->subdev_count = i; > + pdata->card_name = "DA850/OMAP-L138 Video Capture"; > + > + return pdata; > +} > + > /** > * vpif_probe : This function probes the vpif capture driver > * @pdev: platform device pointer > @@ -1438,6 +1563,7 @@ static __init int vpif_probe(struct platform_device *pdev) > int res_idx = 0; > int i, err; > > + pdev->dev.platform_data = vpif_capture_get_pdata(pdev); > if (!pdev->dev.platform_data) { > dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); > return -EINVAL; > @@ -1480,7 +1606,7 @@ static __init int vpif_probe(struct platform_device *pdev) > goto vpif_unregister; > } > > - if (!vpif_obj.config->asd_sizes) { > + if (!vpif_obj.config->asd_sizes[0]) { > i2c_adap = i2c_get_adapter(1); > for (i = 0; i < subdev_count; i++) { > subdevdata = &vpif_obj.config->subdev_info[i]; > diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h > index 3cb1704a0650..4ee3b41975db 100644 > --- a/include/media/davinci/vpif_types.h > +++ b/include/media/davinci/vpif_types.h > @@ -65,14 +65,14 @@ struct vpif_display_config { > > struct vpif_input { > struct v4l2_input input; > - const char *subdev_name; > + char *subdev_name; > u32 input_route; > u32 output_route; > }; > > struct vpif_capture_chan_config { > struct vpif_interface vpif_if; > - const struct vpif_input *inputs; > + struct vpif_input *inputs; > int input_count; > }; > > @@ -83,7 +83,8 @@ struct vpif_capture_config { > struct vpif_subdev_info *subdev_info; > int subdev_count; > const char *card_name; > - struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */ > - int *asd_sizes; /* 0-terminated array of asd group sizes */ > + > + struct v4l2_async_subdev *asd[VPIF_CAPTURE_MAX_CHANNELS]; > + int asd_sizes[VPIF_CAPTURE_MAX_CHANNELS]; > }; > #endif /* _VPIF_TYPES_H */
Hi Sakari, Sakari Ailus <sakari.ailus@iki.fi> writes: > On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >> Allow getting of subdevs from DT ports and endpoints. >> >> The _get_pdata() function was larely inspired by (i.e. stolen from) > > vpif_capture_get_pdata and "largely"? Yes, thanks. >> am437x-vpfe.c >> >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >> --- >> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- >> include/media/davinci/vpif_types.h | 9 +- >> 2 files changed, 133 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c >> index 94ee6cf03f02..47a4699157e7 100644 >> --- a/drivers/media/platform/davinci/vpif_capture.c >> +++ b/drivers/media/platform/davinci/vpif_capture.c >> @@ -26,6 +26,8 @@ >> #include <linux/slab.h> >> >> #include <media/v4l2-ioctl.h> >> +#include <media/v4l2-of.h> >> +#include <media/i2c/tvp514x.h> > > Do you need this header? > Yes, based on discussion with Hans, since there is no DT binding for selecting the input pins of the TVP514x, I have to select it in the driver, so I need the defines from this header. More on this below... >> >> #include "vpif.h" >> #include "vpif_capture.h" >> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >> >> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >> >> + if (!chan_cfg) >> + return -1; >> + if (input_index >= chan_cfg->input_count) >> + return -1; >> subdev_name = chan_cfg->inputs[input_index].subdev_name; >> if (subdev_name == NULL) >> return -1; >> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >> /* loop through the sub device list to get the sub device info */ >> for (i = 0; i < vpif_cfg->subdev_count; i++) { >> subdev_info = &vpif_cfg->subdev_info[i]; >> - if (!strcmp(subdev_info->name, subdev_name)) >> + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) >> return i; >> } >> return -1; >> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, >> { >> int i; >> >> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >> + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; >> + const struct device_node *node = _asd->match.of.node; >> + >> + if (node == subdev->of_node) { >> + vpif_obj.sd[i] = subdev; >> + vpif_obj.config->chan_config->inputs[i].subdev_name = >> + (char *)subdev->of_node->full_name; >> + vpif_dbg(2, debug, >> + "%s: setting input %d subdev_name = %s\n", >> + __func__, i, subdev->of_node->full_name); >> + return 0; >> + } >> + } >> + >> for (i = 0; i < vpif_obj.config->subdev_count; i++) >> if (!strcmp(vpif_obj.config->subdev_info[i].name, >> subdev->name)) { >> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) >> return vpif_probe_complete(); >> } >> >> +static struct vpif_capture_config * >> +vpif_capture_get_pdata(struct platform_device *pdev) >> +{ >> + struct device_node *endpoint = NULL; >> + struct v4l2_of_endpoint bus_cfg; >> + struct vpif_capture_config *pdata; >> + struct vpif_subdev_info *sdinfo; >> + struct vpif_capture_chan_config *chan; >> + unsigned int i; >> + >> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >> + >> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >> + return pdev->dev.platform_data; >> + >> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >> + if (!pdata) >> + return NULL; >> + pdata->subdev_info = >> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >> + >> + if (!pdata->subdev_info) >> + return NULL; >> + dev_dbg(&pdev->dev, "%s\n", __func__); >> + >> + for (i = 0; ; i++) { >> + struct device_node *rem; >> + unsigned int flags; >> + int err; >> + >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, >> + endpoint); >> + if (!endpoint) >> + break; >> + >> + sdinfo = &pdata->subdev_info[i]; > > subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > Right, I need to make the loop only go for a max of VPIF_CAPTURE_MAX_CHANNELS iterations. >> + chan = &pdata->chan_config[i]; >> + chan->inputs = devm_kzalloc(&pdev->dev, >> + sizeof(*chan->inputs) * >> + VPIF_DISPLAY_MAX_CHANNELS, >> + GFP_KERNEL); >> + >> + chan->input_count++; >> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > > I wonder what's the purpose of using index i on this array as well. The number of endpoints in DT is the number of input channels configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > If you use that to access a corresponding entry in a different array, I'd > just create a struct that contains the port configuration and the async > sub-device. The omap3isp driver does that, for instance; see > isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're > interested. Up to you. OK, I'll have a look at that driver. The goal here with this series is just to get this working with DT, but also not break the existing legacy platform_device support, so I'm trying not to mess with the driver-interal data structures too much. >> + chan->inputs[i].input.std = V4L2_STD_ALL; >> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >> + >> + /* FIXME: need a new property? ch0:composite ch1: s-video */ >> + if (i == 0) > > Can you assume that the first endopoint has got a particular kind of input? > What if it's not connected? On all the boards I know of (there aren't many using this SoC), it's a safe assumption. > If this is a different physical port (not in the meaning another) in the > device, I'd use the reg property for this. Please see > Documentation/devicetree/bindings/media/video-interfaces.txt . My understanding (which is admittedly somewhat fuzzy) of the TVP514x is that it's not physically a different port. Instead, it's just telling the TVP514x which pin(s) will be active inputs (and what kind of signal will be present.) I'm open to a better way to describe this input select from DT, but based on what I heard from Hans, there isn't currently a good way to do that except for in the driver: (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) Based on further discussion in that thread, it sounds like there may be a way forward coming soon, and I'll be glad to switch to that when it arrives. >> + chan->inputs[i].input_route = INPUT_CVBS_VI2B; >> + else >> + chan->inputs[i].input_route = INPUT_SVIDEO_VI2C_VI1C; >> + chan->inputs[i].output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC; >> + >> + err = v4l2_of_parse_endpoint(endpoint, &bus_cfg); >> + if (err) { >> + dev_err(&pdev->dev, "Could not parse the endpoint\n"); >> + goto done; >> + } >> + dev_dbg(&pdev->dev, "Endpoint %s, bus_width = %d\n", >> + endpoint->full_name, bus_cfg.bus.parallel.bus_width); >> + flags = bus_cfg.bus.parallel.flags; >> + >> + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) >> + chan->vpif_if.hd_pol = 1; >> + >> + if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) >> + chan->vpif_if.vd_pol = 1; >> + >> + chan->vpif_if.if_type = VPIF_IF_BT656; >> + rem = of_graph_get_remote_port_parent(endpoint); >> + if (!rem) { >> + dev_dbg(&pdev->dev, "Remote device at %s not found\n", >> + endpoint->full_name); >> + goto done; >> + } >> + >> + dev_dbg(&pdev->dev, "Remote device %s, %s found\n", >> + rem->name, rem->full_name); >> + sdinfo->name = rem->full_name; >> + >> + pdata->asd[i] = devm_kzalloc(&pdev->dev, >> + sizeof(struct v4l2_async_subdev), >> + GFP_KERNEL); > > Do you ensure somewhere that i isn't overrunning the pdata->asd[] array? > It's got VPIF_CAPTURE_MAX_CHANNELS entries. Oops, no. That will be fixed by making the outer for loop only iterate for i = i..VPIF_CAPTURE_MAX_CHANNELS. Thanks for the review, Kevin -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Sakari, Sakari Ailus <sakari.ailus@iki.fi> writes: > On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >> Allow getting of subdevs from DT ports and endpoints. >> >> The _get_pdata() function was larely inspired by (i.e. stolen from) > > vpif_capture_get_pdata and "largely"? Yes, thanks. >> am437x-vpfe.c >> >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >> --- >> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- >> include/media/davinci/vpif_types.h | 9 +- >> 2 files changed, 133 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c >> index 94ee6cf03f02..47a4699157e7 100644 >> --- a/drivers/media/platform/davinci/vpif_capture.c >> +++ b/drivers/media/platform/davinci/vpif_capture.c >> @@ -26,6 +26,8 @@ >> #include <linux/slab.h> >> >> #include <media/v4l2-ioctl.h> >> +#include <media/v4l2-of.h> >> +#include <media/i2c/tvp514x.h> > > Do you need this header? > Yes, based on discussion with Hans, since there is no DT binding for selecting the input pins of the TVP514x, I have to select it in the driver, so I need the defines from this header. More on this below... >> >> #include "vpif.h" >> #include "vpif_capture.h" >> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >> >> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >> >> + if (!chan_cfg) >> + return -1; >> + if (input_index >= chan_cfg->input_count) >> + return -1; >> subdev_name = chan_cfg->inputs[input_index].subdev_name; >> if (subdev_name == NULL) >> return -1; >> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >> /* loop through the sub device list to get the sub device info */ >> for (i = 0; i < vpif_cfg->subdev_count; i++) { >> subdev_info = &vpif_cfg->subdev_info[i]; >> - if (!strcmp(subdev_info->name, subdev_name)) >> + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) >> return i; >> } >> return -1; >> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, >> { >> int i; >> >> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >> + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; >> + const struct device_node *node = _asd->match.of.node; >> + >> + if (node == subdev->of_node) { >> + vpif_obj.sd[i] = subdev; >> + vpif_obj.config->chan_config->inputs[i].subdev_name = >> + (char *)subdev->of_node->full_name; >> + vpif_dbg(2, debug, >> + "%s: setting input %d subdev_name = %s\n", >> + __func__, i, subdev->of_node->full_name); >> + return 0; >> + } >> + } >> + >> for (i = 0; i < vpif_obj.config->subdev_count; i++) >> if (!strcmp(vpif_obj.config->subdev_info[i].name, >> subdev->name)) { >> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) >> return vpif_probe_complete(); >> } >> >> +static struct vpif_capture_config * >> +vpif_capture_get_pdata(struct platform_device *pdev) >> +{ >> + struct device_node *endpoint = NULL; >> + struct v4l2_of_endpoint bus_cfg; >> + struct vpif_capture_config *pdata; >> + struct vpif_subdev_info *sdinfo; >> + struct vpif_capture_chan_config *chan; >> + unsigned int i; >> + >> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >> + >> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >> + return pdev->dev.platform_data; >> + >> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >> + if (!pdata) >> + return NULL; >> + pdata->subdev_info = >> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >> + >> + if (!pdata->subdev_info) >> + return NULL; >> + dev_dbg(&pdev->dev, "%s\n", __func__); >> + >> + for (i = 0; ; i++) { >> + struct device_node *rem; >> + unsigned int flags; >> + int err; >> + >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, >> + endpoint); >> + if (!endpoint) >> + break; >> + >> + sdinfo = &pdata->subdev_info[i]; > > subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > Right, I need to make the loop only go for a max of VPIF_CAPTURE_MAX_CHANNELS iterations. >> + chan = &pdata->chan_config[i]; >> + chan->inputs = devm_kzalloc(&pdev->dev, >> + sizeof(*chan->inputs) * >> + VPIF_DISPLAY_MAX_CHANNELS, >> + GFP_KERNEL); >> + >> + chan->input_count++; >> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > > I wonder what's the purpose of using index i on this array as well. The number of endpoints in DT is the number of input channels configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > If you use that to access a corresponding entry in a different array, I'd > just create a struct that contains the port configuration and the async > sub-device. The omap3isp driver does that, for instance; see > isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're > interested. Up to you. OK, I'll have a look at that driver. The goal here with this series is just to get this working with DT, but also not break the existing legacy platform_device support, so I'm trying not to mess with the driver-interal data structures too much. >> + chan->inputs[i].input.std = V4L2_STD_ALL; >> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >> + >> + /* FIXME: need a new property? ch0:composite ch1: s-video */ >> + if (i == 0) > > Can you assume that the first endopoint has got a particular kind of input? > What if it's not connected? On all the boards I know of (there aren't many using this SoC), it's a safe assumption. > If this is a different physical port (not in the meaning another) in the > device, I'd use the reg property for this. Please see > Documentation/devicetree/bindings/media/video-interfaces.txt . My understanding (which is admittedly somewhat fuzzy) of the TVP514x is that it's not physically a different port. Instead, it's just telling the TVP514x which pin(s) will be active inputs (and what kind of signal will be present.) I'm open to a better way to describe this input select from DT, but based on what I heard from Hans, there isn't currently a good way to do that except for in the driver: (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) Based on further discussion in that thread, it sounds like there may be a way forward coming soon, and I'll be glad to switch to that when it arrives. >> + chan->inputs[i].input_route = INPUT_CVBS_VI2B; >> + else >> + chan->inputs[i].input_route = INPUT_SVIDEO_VI2C_VI1C; >> + chan->inputs[i].output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC; >> + >> + err = v4l2_of_parse_endpoint(endpoint, &bus_cfg); >> + if (err) { >> + dev_err(&pdev->dev, "Could not parse the endpoint\n"); >> + goto done; >> + } >> + dev_dbg(&pdev->dev, "Endpoint %s, bus_width = %d\n", >> + endpoint->full_name, bus_cfg.bus.parallel.bus_width); >> + flags = bus_cfg.bus.parallel.flags; >> + >> + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) >> + chan->vpif_if.hd_pol = 1; >> + >> + if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) >> + chan->vpif_if.vd_pol = 1; >> + >> + chan->vpif_if.if_type = VPIF_IF_BT656; >> + rem = of_graph_get_remote_port_parent(endpoint); >> + if (!rem) { >> + dev_dbg(&pdev->dev, "Remote device at %s not found\n", >> + endpoint->full_name); >> + goto done; >> + } >> + >> + dev_dbg(&pdev->dev, "Remote device %s, %s found\n", >> + rem->name, rem->full_name); >> + sdinfo->name = rem->full_name; >> + >> + pdata->asd[i] = devm_kzalloc(&pdev->dev, >> + sizeof(struct v4l2_async_subdev), >> + GFP_KERNEL); > > Do you ensure somewhere that i isn't overrunning the pdata->asd[] array? > It's got VPIF_CAPTURE_MAX_CHANNELS entries. Oops, no. That will be fixed by making the outer for loop only iterate for i = i..VPIF_CAPTURE_MAX_CHANNELS. Thanks for the review, Kevin -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Kevin, On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: > Hi Sakari, > > Sakari Ailus <sakari.ailus@iki.fi> writes: > > > On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: > >> Allow getting of subdevs from DT ports and endpoints. > >> > >> The _get_pdata() function was larely inspired by (i.e. stolen from) > > > > vpif_capture_get_pdata and "largely"? > > Yes, thanks. > > >> am437x-vpfe.c > >> > >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> > >> --- > >> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- > >> include/media/davinci/vpif_types.h | 9 +- > >> 2 files changed, 133 insertions(+), 6 deletions(-) > >> > >> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c > >> index 94ee6cf03f02..47a4699157e7 100644 > >> --- a/drivers/media/platform/davinci/vpif_capture.c > >> +++ b/drivers/media/platform/davinci/vpif_capture.c > >> @@ -26,6 +26,8 @@ > >> #include <linux/slab.h> > >> > >> #include <media/v4l2-ioctl.h> > >> +#include <media/v4l2-of.h> > >> +#include <media/i2c/tvp514x.h> > > > > Do you need this header? > > > > Yes, based on discussion with Hans, since there is no DT binding for > selecting the input pins of the TVP514x, I have to select it in the > driver, so I need the defines from this header. More on this below... > > >> > >> #include "vpif.h" > >> #include "vpif_capture.h" > >> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( > >> > >> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); > >> > >> + if (!chan_cfg) > >> + return -1; > >> + if (input_index >= chan_cfg->input_count) > >> + return -1; > >> subdev_name = chan_cfg->inputs[input_index].subdev_name; > >> if (subdev_name == NULL) > >> return -1; > >> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( > >> /* loop through the sub device list to get the sub device info */ > >> for (i = 0; i < vpif_cfg->subdev_count; i++) { > >> subdev_info = &vpif_cfg->subdev_info[i]; > >> - if (!strcmp(subdev_info->name, subdev_name)) > >> + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) > >> return i; > >> } > >> return -1; > >> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, > >> { > >> int i; > >> > >> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { > >> + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; > >> + const struct device_node *node = _asd->match.of.node; > >> + > >> + if (node == subdev->of_node) { > >> + vpif_obj.sd[i] = subdev; > >> + vpif_obj.config->chan_config->inputs[i].subdev_name = > >> + (char *)subdev->of_node->full_name; > >> + vpif_dbg(2, debug, > >> + "%s: setting input %d subdev_name = %s\n", > >> + __func__, i, subdev->of_node->full_name); > >> + return 0; > >> + } > >> + } > >> + > >> for (i = 0; i < vpif_obj.config->subdev_count; i++) > >> if (!strcmp(vpif_obj.config->subdev_info[i].name, > >> subdev->name)) { > >> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) > >> return vpif_probe_complete(); > >> } > >> > >> +static struct vpif_capture_config * > >> +vpif_capture_get_pdata(struct platform_device *pdev) > >> +{ > >> + struct device_node *endpoint = NULL; > >> + struct v4l2_of_endpoint bus_cfg; > >> + struct vpif_capture_config *pdata; > >> + struct vpif_subdev_info *sdinfo; > >> + struct vpif_capture_chan_config *chan; > >> + unsigned int i; > >> + > >> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); > >> + > >> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) > >> + return pdev->dev.platform_data; > >> + > >> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > >> + if (!pdata) > >> + return NULL; > >> + pdata->subdev_info = > >> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * > >> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); > >> + > >> + if (!pdata->subdev_info) > >> + return NULL; > >> + dev_dbg(&pdev->dev, "%s\n", __func__); > >> + > >> + for (i = 0; ; i++) { > >> + struct device_node *rem; > >> + unsigned int flags; > >> + int err; > >> + > >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, > >> + endpoint); > >> + if (!endpoint) > >> + break; > >> + > >> + sdinfo = &pdata->subdev_info[i]; > > > > subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > > > > Right, I need to make the loop only go for a max of > VPIF_CAPTURE_MAX_CHANNELS iterations. > > >> + chan = &pdata->chan_config[i]; > >> + chan->inputs = devm_kzalloc(&pdev->dev, > >> + sizeof(*chan->inputs) * > >> + VPIF_DISPLAY_MAX_CHANNELS, > >> + GFP_KERNEL); > >> + > >> + chan->input_count++; > >> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > > > > I wonder what's the purpose of using index i on this array as well. > > The number of endpoints in DT is the number of input channels configured > (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > > > If you use that to access a corresponding entry in a different array, I'd > > just create a struct that contains the port configuration and the async > > sub-device. The omap3isp driver does that, for instance; see > > isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're > > interested. Up to you. > > OK, I'll have a look at that driver. The goal here with this series is > just to get this working with DT, but also not break the existing legacy > platform_device support, so I'm trying not to mess with the > driver-interal data structures too much. Ack. > > >> + chan->inputs[i].input.std = V4L2_STD_ALL; > >> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; > >> + > >> + /* FIXME: need a new property? ch0:composite ch1: s-video */ > >> + if (i == 0) > > > > Can you assume that the first endopoint has got a particular kind of input? > > What if it's not connected? > > On all the boards I know of (there aren't many using this SoC), it's a > safe assumption. > > > If this is a different physical port (not in the meaning another) in the > > device, I'd use the reg property for this. Please see > > Documentation/devicetree/bindings/media/video-interfaces.txt . > > My understanding (which is admittedly somewhat fuzzy) of the TVP514x is > that it's not physically a different port. Instead, it's just telling > the TVP514x which pin(s) will be active inputs (and what kind of signal > will be present.) > > I'm open to a better way to describe this input select from DT, but > based on what I heard from Hans, there isn't currently a good way to do > that except for in the driver: > (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) > > Based on further discussion in that thread, it sounds like there may be > a way forward coming soon, and I'll be glad to switch to that when it > arrives. I'm not sure that properly supporting connectors will provide any help here. Looking at the s_routing() API, it's the calling driver that has to be aware of sub-device specific function parameters. As such it's not a very good idea to require that a driver is aware of the value range of another driver's parameter. I wonder if a simple enumeration interface would help here --- if I understand correctly, the purpose is just to provide a way to choose the input using VIDIOC_S_INPUT. I guess that's somehow ok as long as you have no other combinations of these devices but this is hardly future-proof. (And certainly not a problem created by this patch.) It'd be still nice to fix that as presumably we don't have the option of reworking how we expect the device tree to look like. Cc Laurent.
Sakari Ailus <sakari.ailus@iki.fi> writes: > Hi Kevin, > > On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: >> Hi Sakari, >> >> Sakari Ailus <sakari.ailus@iki.fi> writes: >> >> > On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >> >> Allow getting of subdevs from DT ports and endpoints. >> >> >> >> The _get_pdata() function was larely inspired by (i.e. stolen from) >> > >> > vpif_capture_get_pdata and "largely"? >> >> Yes, thanks. >> >> >> am437x-vpfe.c >> >> >> >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >> >> --- >> >> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- >> >> include/media/davinci/vpif_types.h | 9 +- >> >> 2 files changed, 133 insertions(+), 6 deletions(-) >> >> >> >> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c >> >> index 94ee6cf03f02..47a4699157e7 100644 >> >> --- a/drivers/media/platform/davinci/vpif_capture.c >> >> +++ b/drivers/media/platform/davinci/vpif_capture.c >> >> @@ -26,6 +26,8 @@ >> >> #include <linux/slab.h> >> >> >> >> #include <media/v4l2-ioctl.h> >> >> +#include <media/v4l2-of.h> >> >> +#include <media/i2c/tvp514x.h> >> > >> > Do you need this header? >> > >> >> Yes, based on discussion with Hans, since there is no DT binding for >> selecting the input pins of the TVP514x, I have to select it in the >> driver, so I need the defines from this header. More on this below... >> >> >> >> >> #include "vpif.h" >> >> #include "vpif_capture.h" >> >> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >> >> >> >> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >> >> >> >> + if (!chan_cfg) >> >> + return -1; >> >> + if (input_index >= chan_cfg->input_count) >> >> + return -1; >> >> subdev_name = chan_cfg->inputs[input_index].subdev_name; >> >> if (subdev_name == NULL) >> >> return -1; >> >> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >> >> /* loop through the sub device list to get the sub device info */ >> >> for (i = 0; i < vpif_cfg->subdev_count; i++) { >> >> subdev_info = &vpif_cfg->subdev_info[i]; >> >> - if (!strcmp(subdev_info->name, subdev_name)) >> >> + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) >> >> return i; >> >> } >> >> return -1; >> >> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, >> >> { >> >> int i; >> >> >> >> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >> >> + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; >> >> + const struct device_node *node = _asd->match.of.node; >> >> + >> >> + if (node == subdev->of_node) { >> >> + vpif_obj.sd[i] = subdev; >> >> + vpif_obj.config->chan_config->inputs[i].subdev_name = >> >> + (char *)subdev->of_node->full_name; >> >> + vpif_dbg(2, debug, >> >> + "%s: setting input %d subdev_name = %s\n", >> >> + __func__, i, subdev->of_node->full_name); >> >> + return 0; >> >> + } >> >> + } >> >> + >> >> for (i = 0; i < vpif_obj.config->subdev_count; i++) >> >> if (!strcmp(vpif_obj.config->subdev_info[i].name, >> >> subdev->name)) { >> >> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) >> >> return vpif_probe_complete(); >> >> } >> >> >> >> +static struct vpif_capture_config * >> >> +vpif_capture_get_pdata(struct platform_device *pdev) >> >> +{ >> >> + struct device_node *endpoint = NULL; >> >> + struct v4l2_of_endpoint bus_cfg; >> >> + struct vpif_capture_config *pdata; >> >> + struct vpif_subdev_info *sdinfo; >> >> + struct vpif_capture_chan_config *chan; >> >> + unsigned int i; >> >> + >> >> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >> >> + >> >> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >> >> + return pdev->dev.platform_data; >> >> + >> >> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >> >> + if (!pdata) >> >> + return NULL; >> >> + pdata->subdev_info = >> >> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >> >> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >> >> + >> >> + if (!pdata->subdev_info) >> >> + return NULL; >> >> + dev_dbg(&pdev->dev, "%s\n", __func__); >> >> + >> >> + for (i = 0; ; i++) { >> >> + struct device_node *rem; >> >> + unsigned int flags; >> >> + int err; >> >> + >> >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, >> >> + endpoint); >> >> + if (!endpoint) >> >> + break; >> >> + >> >> + sdinfo = &pdata->subdev_info[i]; >> > >> > subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. >> > >> >> Right, I need to make the loop only go for a max of >> VPIF_CAPTURE_MAX_CHANNELS iterations. >> >> >> + chan = &pdata->chan_config[i]; >> >> + chan->inputs = devm_kzalloc(&pdev->dev, >> >> + sizeof(*chan->inputs) * >> >> + VPIF_DISPLAY_MAX_CHANNELS, >> >> + GFP_KERNEL); >> >> + >> >> + chan->input_count++; >> >> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; >> > >> > I wonder what's the purpose of using index i on this array as well. >> >> The number of endpoints in DT is the number of input channels configured >> (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) >> >> > If you use that to access a corresponding entry in a different array, I'd >> > just create a struct that contains the port configuration and the async >> > sub-device. The omap3isp driver does that, for instance; see >> > isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're >> > interested. Up to you. >> >> OK, I'll have a look at that driver. The goal here with this series is >> just to get this working with DT, but also not break the existing legacy >> platform_device support, so I'm trying not to mess with the >> driver-interal data structures too much. > > Ack. > >> >> >> + chan->inputs[i].input.std = V4L2_STD_ALL; >> >> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >> >> + >> >> + /* FIXME: need a new property? ch0:composite ch1: s-video */ >> >> + if (i == 0) >> > >> > Can you assume that the first endopoint has got a particular kind of input? >> > What if it's not connected? >> >> On all the boards I know of (there aren't many using this SoC), it's a >> safe assumption. >> >> > If this is a different physical port (not in the meaning another) in the >> > device, I'd use the reg property for this. Please see >> > Documentation/devicetree/bindings/media/video-interfaces.txt . >> >> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is >> that it's not physically a different port. Instead, it's just telling >> the TVP514x which pin(s) will be active inputs (and what kind of signal >> will be present.) >> >> I'm open to a better way to describe this input select from DT, but >> based on what I heard from Hans, there isn't currently a good way to do >> that except for in the driver: >> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) >> >> Based on further discussion in that thread, it sounds like there may be >> a way forward coming soon, and I'll be glad to switch to that when it >> arrives. > > I'm not sure that properly supporting connectors will provide any help here. > > Looking at the s_routing() API, it's the calling driver that has to be aware > of sub-device specific function parameters. As such it's not a very good > idea to require that a driver is aware of the value range of another > driver's parameter. I wonder if a simple enumeration interface would help > here --- if I understand correctly, the purpose is just to provide a way to > choose the input using VIDIOC_S_INPUT. > > I guess that's somehow ok as long as you have no other combinations of these > devices but this is hardly future-proof. (And certainly not a problem > created by this patch.) Yeah, this is far from future proof. > It'd be still nice to fix that as presumably we don't have the option of > reworking how we expect the device tree to look like. Agreed. I'm just hoping someone can shed som light on "how we expect the device tree to look". ;) Kevin -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: > Sakari Ailus <sakari.ailus@iki.fi> writes: > > > Hi Kevin, > > > > On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: > >> Hi Sakari, > >> > >> Sakari Ailus <sakari.ailus@iki.fi> writes: > >> > >> > On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: > >> >> Allow getting of subdevs from DT ports and endpoints. > >> >> > >> >> The _get_pdata() function was larely inspired by (i.e. stolen from) > >> > > >> > vpif_capture_get_pdata and "largely"? > >> > >> Yes, thanks. > >> > >> >> am437x-vpfe.c > >> >> > >> >> Signed-off-by: Kevin Hilman <khilman@baylibre.com> > >> >> --- > >> >> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++++++++++++- > >> >> include/media/davinci/vpif_types.h | 9 +- > >> >> 2 files changed, 133 insertions(+), 6 deletions(-) > >> >> > >> >> diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c > >> >> index 94ee6cf03f02..47a4699157e7 100644 > >> >> --- a/drivers/media/platform/davinci/vpif_capture.c > >> >> +++ b/drivers/media/platform/davinci/vpif_capture.c > >> >> @@ -26,6 +26,8 @@ > >> >> #include <linux/slab.h> > >> >> > >> >> #include <media/v4l2-ioctl.h> > >> >> +#include <media/v4l2-of.h> > >> >> +#include <media/i2c/tvp514x.h> > >> > > >> > Do you need this header? > >> > > >> > >> Yes, based on discussion with Hans, since there is no DT binding for > >> selecting the input pins of the TVP514x, I have to select it in the > >> driver, so I need the defines from this header. More on this below... > >> > >> >> > >> >> #include "vpif.h" > >> >> #include "vpif_capture.h" > >> >> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( > >> >> > >> >> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); > >> >> > >> >> + if (!chan_cfg) > >> >> + return -1; > >> >> + if (input_index >= chan_cfg->input_count) > >> >> + return -1; > >> >> subdev_name = chan_cfg->inputs[input_index].subdev_name; > >> >> if (subdev_name == NULL) > >> >> return -1; > >> >> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( > >> >> /* loop through the sub device list to get the sub device info */ > >> >> for (i = 0; i < vpif_cfg->subdev_count; i++) { > >> >> subdev_info = &vpif_cfg->subdev_info[i]; > >> >> - if (!strcmp(subdev_info->name, subdev_name)) > >> >> + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) > >> >> return i; > >> >> } > >> >> return -1; > >> >> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, > >> >> { > >> >> int i; > >> >> > >> >> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { > >> >> + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; > >> >> + const struct device_node *node = _asd->match.of.node; > >> >> + > >> >> + if (node == subdev->of_node) { > >> >> + vpif_obj.sd[i] = subdev; > >> >> + vpif_obj.config->chan_config->inputs[i].subdev_name = > >> >> + (char *)subdev->of_node->full_name; > >> >> + vpif_dbg(2, debug, > >> >> + "%s: setting input %d subdev_name = %s\n", > >> >> + __func__, i, subdev->of_node->full_name); > >> >> + return 0; > >> >> + } > >> >> + } > >> >> + > >> >> for (i = 0; i < vpif_obj.config->subdev_count; i++) > >> >> if (!strcmp(vpif_obj.config->subdev_info[i].name, > >> >> subdev->name)) { > >> >> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) > >> >> return vpif_probe_complete(); > >> >> } > >> >> > >> >> +static struct vpif_capture_config * > >> >> +vpif_capture_get_pdata(struct platform_device *pdev) > >> >> +{ > >> >> + struct device_node *endpoint = NULL; > >> >> + struct v4l2_of_endpoint bus_cfg; > >> >> + struct vpif_capture_config *pdata; > >> >> + struct vpif_subdev_info *sdinfo; > >> >> + struct vpif_capture_chan_config *chan; > >> >> + unsigned int i; > >> >> + > >> >> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); > >> >> + > >> >> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) > >> >> + return pdev->dev.platform_data; > >> >> + > >> >> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > >> >> + if (!pdata) > >> >> + return NULL; > >> >> + pdata->subdev_info = > >> >> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * > >> >> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); > >> >> + > >> >> + if (!pdata->subdev_info) > >> >> + return NULL; > >> >> + dev_dbg(&pdev->dev, "%s\n", __func__); > >> >> + > >> >> + for (i = 0; ; i++) { > >> >> + struct device_node *rem; > >> >> + unsigned int flags; > >> >> + int err; > >> >> + > >> >> + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, > >> >> + endpoint); > >> >> + if (!endpoint) > >> >> + break; > >> >> + > >> >> + sdinfo = &pdata->subdev_info[i]; > >> > > >> > subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > >> > > >> > >> Right, I need to make the loop only go for a max of > >> VPIF_CAPTURE_MAX_CHANNELS iterations. > >> > >> >> + chan = &pdata->chan_config[i]; > >> >> + chan->inputs = devm_kzalloc(&pdev->dev, > >> >> + sizeof(*chan->inputs) * > >> >> + VPIF_DISPLAY_MAX_CHANNELS, > >> >> + GFP_KERNEL); > >> >> + > >> >> + chan->input_count++; > >> >> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > >> > > >> > I wonder what's the purpose of using index i on this array as well. > >> > >> The number of endpoints in DT is the number of input channels configured > >> (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > >> > >> > If you use that to access a corresponding entry in a different array, I'd > >> > just create a struct that contains the port configuration and the async > >> > sub-device. The omap3isp driver does that, for instance; see > >> > isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if you're > >> > interested. Up to you. > >> > >> OK, I'll have a look at that driver. The goal here with this series is > >> just to get this working with DT, but also not break the existing legacy > >> platform_device support, so I'm trying not to mess with the > >> driver-interal data structures too much. > > > > Ack. > > > >> > >> >> + chan->inputs[i].input.std = V4L2_STD_ALL; > >> >> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; > >> >> + > >> >> + /* FIXME: need a new property? ch0:composite ch1: s-video */ > >> >> + if (i == 0) > >> > > >> > Can you assume that the first endopoint has got a particular kind of input? > >> > What if it's not connected? > >> > >> On all the boards I know of (there aren't many using this SoC), it's a > >> safe assumption. > >> > >> > If this is a different physical port (not in the meaning another) in the > >> > device, I'd use the reg property for this. Please see > >> > Documentation/devicetree/bindings/media/video-interfaces.txt . > >> > >> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is > >> that it's not physically a different port. Instead, it's just telling > >> the TVP514x which pin(s) will be active inputs (and what kind of signal > >> will be present.) > >> > >> I'm open to a better way to describe this input select from DT, but > >> based on what I heard from Hans, there isn't currently a good way to do > >> that except for in the driver: > >> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) > >> > >> Based on further discussion in that thread, it sounds like there may be > >> a way forward coming soon, and I'll be glad to switch to that when it > >> arrives. > > > > I'm not sure that properly supporting connectors will provide any help here. > > > > Looking at the s_routing() API, it's the calling driver that has to be aware > > of sub-device specific function parameters. As such it's not a very good > > idea to require that a driver is aware of the value range of another > > driver's parameter. I wonder if a simple enumeration interface would help > > here --- if I understand correctly, the purpose is just to provide a way to > > choose the input using VIDIOC_S_INPUT. > > > > I guess that's somehow ok as long as you have no other combinations of these > > devices but this is hardly future-proof. (And certainly not a problem > > created by this patch.) > > Yeah, this is far from future proof. > > > It'd be still nice to fix that as presumably we don't have the option of > > reworking how we expect the device tree to look like. > > Agreed. > > I'm just hoping someone can shed som light on "how we expect the device > tree to look". ;) :-) For the tvp514x, do you need more than a single endpoint on the receiver side? Does the input that's selected affect the bus parameters? If it doesn't, you could create a custom endpoint property for the possible input values. The s_routing() really should be fixed though, but that could be postponed I guess. There are quite a few drivers using it.
Hello, On Thursday 01 Dec 2016 09:57:31 Sakari Ailus wrote: > On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: > > Sakari Ailus <sakari.ailus@iki.fi> writes: > >> On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: > >>> Sakari Ailus <sakari.ailus@iki.fi> writes: > >>>> On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: > >>>>> Allow getting of subdevs from DT ports and endpoints. > >>>>> > >>>>> The _get_pdata() function was larely inspired by (i.e. stolen from) > >>>>> am437x-vpfe.c > >>>>> > >>>>> Signed-off-by: Kevin Hilman <khilman@baylibre.com> > >>>>> --- > >>>>> > >>>>> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++- > >>>>> include/media/davinci/vpif_types.h > >>>>> | 9 +- > >>>>> 2 files changed, 133 insertions(+), 6 deletions(-) > >>>>> > >>>>> diff --git a/drivers/media/platform/davinci/vpif_capture.c > >>>>> b/drivers/media/platform/davinci/vpif_capture.c index > >>>>> 94ee6cf03f02..47a4699157e7 100644 > >>>>> --- a/drivers/media/platform/davinci/vpif_capture.c > >>>>> +++ b/drivers/media/platform/davinci/vpif_capture.c > >>>>> @@ -26,6 +26,8 @@ > >>>>> #include <linux/slab.h> > >>>>> > >>>>> #include <media/v4l2-ioctl.h> > >>>>> +#include <media/v4l2-of.h> > >>>>> +#include <media/i2c/tvp514x.h> > >>>> > >>>> Do you need this header? > >>> > >>> Yes, based on discussion with Hans, since there is no DT binding for > >>> selecting the input pins of the TVP514x, I have to select it in the > >>> driver, so I need the defines from this header. More on this below... That's really ugly :-( The problem should be fixed properly instead of adding one more offender. > >>>>> #include "vpif.h" > >>>>> #include "vpif_capture.h" > >>>>> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( > >>>>> > >>>>> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); > >>>>> > >>>>> + if (!chan_cfg) > >>>>> + return -1; > >>>>> + if (input_index >= chan_cfg->input_count) > >>>>> + return -1; > >>>>> subdev_name = chan_cfg->inputs[input_index].subdev_name; > >>>>> if (subdev_name == NULL) > >>>>> return -1; > >>>>> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( > >>>>> /* loop through the sub device list to get the sub device info > >>>>> */ > >>>>> for (i = 0; i < vpif_cfg->subdev_count; i++) { > >>>>> subdev_info = &vpif_cfg->subdev_info[i]; > >>>>> - if (!strcmp(subdev_info->name, subdev_name)) > >>>>> + if (subdev_info && !strcmp(subdev_info->name, > >>>>> subdev_name)) > >>>>> return i; > >>>>> } > >>>>> return -1; > >>>>> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct > >>>>> v4l2_async_notifier *notifier,> >> >> > >>>>> { > >>>>> int i; > >>>>> > >>>>> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { > >>>>> + struct v4l2_async_subdev *_asd = vpif_obj.config > >>>>> ->asd[i]; > >>>>> + const struct device_node *node = _asd->match.of.node; > >>>>> + > >>>>> + if (node == subdev->of_node) { > >>>>> + vpif_obj.sd[i] = subdev; > >>>>> + vpif_obj.config->chan_config > >>>>> ->inputs[i].subdev_name = > >>>>> + (char *)subdev->of_node->full_name; Can subdev_name be made const instead of blindly casting the full_name pointer ? If not this is probably unsafe, and if yes it should be done :-) > >>>>> + vpif_dbg(2, debug, > >>>>> + "%s: setting input %d subdev_name = > >>>>> %s\n", > >>>>> + __func__, i, subdev->of_node > >>>>> ->full_name); > >>>>> + return 0; > >>>>> + } > >>>>> + } > >>>>> + > >>>>> for (i = 0; i < vpif_obj.config->subdev_count; i++) > >>>>> if (!strcmp(vpif_obj.config->subdev_info[i].name, > >>>>> subdev->name)) { > >>>>> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct > >>>>> v4l2_async_notifier *notifier) > >>>>> return vpif_probe_complete(); > >>>>> } > >>>>> > >>>>> +static struct vpif_capture_config * > >>>>> +vpif_capture_get_pdata(struct platform_device *pdev) > >>>>> +{ > >>>>> + struct device_node *endpoint = NULL; > >>>>> + struct v4l2_of_endpoint bus_cfg; > >>>>> + struct vpif_capture_config *pdata; > >>>>> + struct vpif_subdev_info *sdinfo; > >>>>> + struct vpif_capture_chan_config *chan; > >>>>> + unsigned int i; > >>>>> + > >>>>> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); > >>>>> + > >>>>> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) > >>>>> + return pdev->dev.platform_data; > >>>>> + > >>>>> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > >>>>> + if (!pdata) > >>>>> + return NULL; > >>>>> + pdata->subdev_info = > >>>>> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * > >>>>> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); > >>>>> + > >>>>> + if (!pdata->subdev_info) > >>>>> + return NULL; > >>>>> + dev_dbg(&pdev->dev, "%s\n", __func__); > >>>>> + > >>>>> + for (i = 0; ; i++) { > >>>>> + struct device_node *rem; > >>>>> + unsigned int flags; > >>>>> + int err; > >>>>> + > >>>>> + endpoint = of_graph_get_next_endpoint(pdev > >>>>> ->dev.of_node, > >>>>> + endpoint); > >>>>> + if (!endpoint) > >>>>> + break; > >>>>> + > >>>>> + sdinfo = &pdata->subdev_info[i]; > >>>> > >>>> subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > >>> > >>> Right, I need to make the loop only go for a max of > >>> VPIF_CAPTURE_MAX_CHANNELS iterations. > >>> > >>>>> + chan = &pdata->chan_config[i]; > >>>>> + chan->inputs = devm_kzalloc(&pdev->dev, > >>>>> + sizeof(*chan->inputs) * > >>>>> + VPIF_DISPLAY_MAX_CHANNELS, > >>>>> + GFP_KERNEL); > >>>>> + > >>>>> + chan->input_count++; > >>>>> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > >>>> > >>>> I wonder what's the purpose of using index i on this array as well. > >>> > >>> The number of endpoints in DT is the number of input channels > >>> configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > >>> > >>>> If you use that to access a corresponding entry in a different array, > >>>> I'd just create a struct that contains the port configuration and the > >>>> async sub-device. The omap3isp driver does that, for instance; see > >>>> isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if > >>>> you're interested. Up to you. > >>> > >>> OK, I'll have a look at that driver. The goal here with this series is > >>> just to get this working with DT, but also not break the existing > >>> legacy platform_device support, so I'm trying not to mess with the > >>> driver-interal data structures too much. > >> > >> Ack. > >> > >>>>> + chan->inputs[i].input.std = V4L2_STD_ALL; > >>>>> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; > >>>>> + > >>>>> + /* FIXME: need a new property? ch0:composite ch1: > >>>>> s-video */ > >>>>> + if (i == 0) > >>>> > >>>> Can you assume that the first endopoint has got a particular kind of > >>>> input? What if it's not connected? > >>> > >>> On all the boards I know of (there aren't many using this SoC), it's a > >>> safe assumption. > >>> > >>>> If this is a different physical port (not in the meaning another) in > >>>> the device, I'd use the reg property for this. Please see > >>>> Documentation/devicetree/bindings/media/video-interfaces.txt . > >>> > >>> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is > >>> that it's not physically a different port. Instead, it's just telling > >>> the TVP514x which pin(s) will be active inputs (and what kind of signal > >>> will be present.) > >>> > >>> I'm open to a better way to describe this input select from DT, but > >>> based on what I heard from Hans, there isn't currently a good way to do > >>> that except for in the driver: > >>> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) > >>> > >>> Based on further discussion in that thread, it sounds like there may be > >>> a way forward coming soon, and I'll be glad to switch to that when it > >>> arrives. I'm afraid I have to disappoint Hans here, I don't have code for that yet. > >> I'm not sure that properly supporting connectors will provide any help > >> here. > >> > >> Looking at the s_routing() API, it's the calling driver that has to be > >> aware of sub-device specific function parameters. As such it's not a > >> very good idea to require that a driver is aware of the value range of > >> another driver's parameter. I wonder if a simple enumeration interface > >> would help here --- if I understand correctly, the purpose is just to > >> provide a way to choose the input using VIDIOC_S_INPUT. > >> > >> I guess that's somehow ok as long as you have no other combinations of > >> these devices but this is hardly future-proof. (And certainly not a > >> problem created by this patch.) > > > > Yeah, this is far from future proof. > > > >> It'd be still nice to fix that as presumably we don't have the option of > >> reworking how we expect the device tree to look like. > > > > Agreed. > > > > I'm just hoping someone can shed som light on "how we expect the device > > tree to look". ;) > > :-) > > For the tvp514x, do you need more than a single endpoint on the receiver > side? Does the input that's selected affect the bus parameters? > > If it doesn't, you could create a custom endpoint property for the possible > input values. The s_routing() really should be fixed though, but that could > be postponed I guess. There are quite a few drivers using it. There's two ways to look at s_routing() in my opinion, as the calling driver should really not hardcode any knowledge specific to a particular subdev. We can either have the calling driver discover the possible routing options at runtime through the subdev API, or modify the s_routing() API.
On 12/01/2016 10:16 AM, Laurent Pinchart wrote: > Hello, > > On Thursday 01 Dec 2016 09:57:31 Sakari Ailus wrote: >> On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: >>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>> On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: >>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>>>> On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >>>>>>> Allow getting of subdevs from DT ports and endpoints. >>>>>>> >>>>>>> The _get_pdata() function was larely inspired by (i.e. stolen from) >>>>>>> am437x-vpfe.c >>>>>>> >>>>>>> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >>>>>>> --- >>>>>>> >>>>>>> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++- >>>>>>> include/media/davinci/vpif_types.h >>>>>>> | 9 +- >>>>>>> 2 files changed, 133 insertions(+), 6 deletions(-) >>>>>>> >>>>>>> diff --git a/drivers/media/platform/davinci/vpif_capture.c >>>>>>> b/drivers/media/platform/davinci/vpif_capture.c index >>>>>>> 94ee6cf03f02..47a4699157e7 100644 >>>>>>> --- a/drivers/media/platform/davinci/vpif_capture.c >>>>>>> +++ b/drivers/media/platform/davinci/vpif_capture.c >>>>>>> @@ -26,6 +26,8 @@ >>>>>>> #include <linux/slab.h> >>>>>>> >>>>>>> #include <media/v4l2-ioctl.h> >>>>>>> +#include <media/v4l2-of.h> >>>>>>> +#include <media/i2c/tvp514x.h> >>>>>> >>>>>> Do you need this header? >>>>> >>>>> Yes, based on discussion with Hans, since there is no DT binding for >>>>> selecting the input pins of the TVP514x, I have to select it in the >>>>> driver, so I need the defines from this header. More on this below... > > That's really ugly :-( The problem should be fixed properly instead of adding > one more offender. Do you have time for that, Laurent? I don't. Until that time we just need to make do with this workaround. > >>>>>>> #include "vpif.h" >>>>>>> #include "vpif_capture.h" >>>>>>> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >>>>>>> >>>>>>> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >>>>>>> >>>>>>> + if (!chan_cfg) >>>>>>> + return -1; >>>>>>> + if (input_index >= chan_cfg->input_count) >>>>>>> + return -1; >>>>>>> subdev_name = chan_cfg->inputs[input_index].subdev_name; >>>>>>> if (subdev_name == NULL) >>>>>>> return -1; >>>>>>> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >>>>>>> /* loop through the sub device list to get the sub device info >>>>>>> */ >>>>>>> for (i = 0; i < vpif_cfg->subdev_count; i++) { >>>>>>> subdev_info = &vpif_cfg->subdev_info[i]; >>>>>>> - if (!strcmp(subdev_info->name, subdev_name)) >>>>>>> + if (subdev_info && !strcmp(subdev_info->name, >>>>>>> subdev_name)) >>>>>>> return i; >>>>>>> } >>>>>>> return -1; >>>>>>> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct >>>>>>> v4l2_async_notifier *notifier,> >> >> >>>>>>> { >>>>>>> int i; >>>>>>> >>>>>>> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >>>>>>> + struct v4l2_async_subdev *_asd = vpif_obj.config >>>>>>> ->asd[i]; >>>>>>> + const struct device_node *node = _asd->match.of.node; >>>>>>> + >>>>>>> + if (node == subdev->of_node) { >>>>>>> + vpif_obj.sd[i] = subdev; >>>>>>> + vpif_obj.config->chan_config >>>>>>> ->inputs[i].subdev_name = >>>>>>> + (char *)subdev->of_node->full_name; > > Can subdev_name be made const instead of blindly casting the full_name pointer > ? If not this is probably unsafe, and if yes it should be done :-) > >>>>>>> + vpif_dbg(2, debug, >>>>>>> + "%s: setting input %d subdev_name = >>>>>>> %s\n", >>>>>>> + __func__, i, subdev->of_node >>>>>>> ->full_name); >>>>>>> + return 0; >>>>>>> + } >>>>>>> + } >>>>>>> + >>>>>>> for (i = 0; i < vpif_obj.config->subdev_count; i++) >>>>>>> if (!strcmp(vpif_obj.config->subdev_info[i].name, >>>>>>> subdev->name)) { >>>>>>> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct >>>>>>> v4l2_async_notifier *notifier) >>>>>>> return vpif_probe_complete(); >>>>>>> } >>>>>>> >>>>>>> +static struct vpif_capture_config * >>>>>>> +vpif_capture_get_pdata(struct platform_device *pdev) >>>>>>> +{ >>>>>>> + struct device_node *endpoint = NULL; >>>>>>> + struct v4l2_of_endpoint bus_cfg; >>>>>>> + struct vpif_capture_config *pdata; >>>>>>> + struct vpif_subdev_info *sdinfo; >>>>>>> + struct vpif_capture_chan_config *chan; >>>>>>> + unsigned int i; >>>>>>> + >>>>>>> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >>>>>>> + >>>>>>> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >>>>>>> + return pdev->dev.platform_data; >>>>>>> + >>>>>>> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >>>>>>> + if (!pdata) >>>>>>> + return NULL; >>>>>>> + pdata->subdev_info = >>>>>>> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >>>>>>> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >>>>>>> + >>>>>>> + if (!pdata->subdev_info) >>>>>>> + return NULL; >>>>>>> + dev_dbg(&pdev->dev, "%s\n", __func__); >>>>>>> + >>>>>>> + for (i = 0; ; i++) { >>>>>>> + struct device_node *rem; >>>>>>> + unsigned int flags; >>>>>>> + int err; >>>>>>> + >>>>>>> + endpoint = of_graph_get_next_endpoint(pdev >>>>>>> ->dev.of_node, >>>>>>> + endpoint); >>>>>>> + if (!endpoint) >>>>>>> + break; >>>>>>> + >>>>>>> + sdinfo = &pdata->subdev_info[i]; >>>>>> >>>>>> subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. >>>>> >>>>> Right, I need to make the loop only go for a max of >>>>> VPIF_CAPTURE_MAX_CHANNELS iterations. >>>>> >>>>>>> + chan = &pdata->chan_config[i]; >>>>>>> + chan->inputs = devm_kzalloc(&pdev->dev, >>>>>>> + sizeof(*chan->inputs) * >>>>>>> + VPIF_DISPLAY_MAX_CHANNELS, >>>>>>> + GFP_KERNEL); >>>>>>> + >>>>>>> + chan->input_count++; >>>>>>> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; >>>>>> >>>>>> I wonder what's the purpose of using index i on this array as well. >>>>> >>>>> The number of endpoints in DT is the number of input channels >>>>> configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) >>>>> >>>>>> If you use that to access a corresponding entry in a different array, >>>>>> I'd just create a struct that contains the port configuration and the >>>>>> async sub-device. The omap3isp driver does that, for instance; see >>>>>> isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if >>>>>> you're interested. Up to you. >>>>> >>>>> OK, I'll have a look at that driver. The goal here with this series is >>>>> just to get this working with DT, but also not break the existing >>>>> legacy platform_device support, so I'm trying not to mess with the >>>>> driver-interal data structures too much. >>>> >>>> Ack. >>>> >>>>>>> + chan->inputs[i].input.std = V4L2_STD_ALL; >>>>>>> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >>>>>>> + >>>>>>> + /* FIXME: need a new property? ch0:composite ch1: >>>>>>> s-video */ >>>>>>> + if (i == 0) >>>>>> >>>>>> Can you assume that the first endopoint has got a particular kind of >>>>>> input? What if it's not connected? >>>>> >>>>> On all the boards I know of (there aren't many using this SoC), it's a >>>>> safe assumption. >>>>> >>>>>> If this is a different physical port (not in the meaning another) in >>>>>> the device, I'd use the reg property for this. Please see >>>>>> Documentation/devicetree/bindings/media/video-interfaces.txt . >>>>> >>>>> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is >>>>> that it's not physically a different port. Instead, it's just telling >>>>> the TVP514x which pin(s) will be active inputs (and what kind of signal >>>>> will be present.) >>>>> >>>>> I'm open to a better way to describe this input select from DT, but >>>>> based on what I heard from Hans, there isn't currently a good way to do >>>>> that except for in the driver: >>>>> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) >>>>> >>>>> Based on further discussion in that thread, it sounds like there may be >>>>> a way forward coming soon, and I'll be glad to switch to that when it >>>>> arrives. > > I'm afraid I have to disappoint Hans here, I don't have code for that yet. > >>>> I'm not sure that properly supporting connectors will provide any help >>>> here. >>>> >>>> Looking at the s_routing() API, it's the calling driver that has to be >>>> aware of sub-device specific function parameters. As such it's not a >>>> very good idea to require that a driver is aware of the value range of >>>> another driver's parameter. I wonder if a simple enumeration interface >>>> would help here --- if I understand correctly, the purpose is just to >>>> provide a way to choose the input using VIDIOC_S_INPUT. >>>> >>>> I guess that's somehow ok as long as you have no other combinations of >>>> these devices but this is hardly future-proof. (And certainly not a >>>> problem created by this patch.) >>> >>> Yeah, this is far from future proof. >>> >>>> It'd be still nice to fix that as presumably we don't have the option of >>>> reworking how we expect the device tree to look like. >>> >>> Agreed. >>> >>> I'm just hoping someone can shed som light on "how we expect the device >>> tree to look". ;) >> >> :-) >> >> For the tvp514x, do you need more than a single endpoint on the receiver >> side? Does the input that's selected affect the bus parameters? >> >> If it doesn't, you could create a custom endpoint property for the possible >> input values. The s_routing() really should be fixed though, but that could >> be postponed I guess. There are quite a few drivers using it. > > There's two ways to look at s_routing() in my opinion, as the calling driver > should really not hardcode any knowledge specific to a particular subdev. We > can either have the calling driver discover the possible routing options at > runtime through the subdev API, or modify the s_routing() API. > Some historical perspective: s_routing was added well before the device tree was ever used for ARM. And at that time the vast majority of drivers were PCI or USB drivers, very few platform drivers existed (and those typically used sensors, not video receivers). Before s_routing existed the situation was even worse. Basically what s_routing does is a poor-man's device tree entry, telling the subdev how to route video or audio from connector to the output of the chip. Typically the card tables in PCI or USB drivers contain the correct arguments for s_routing. Of course, today we'd do that with the DT, but that was not an option years ago. Regards, Hans -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hans Verkuil <hverkuil@xs4all.nl> writes: > On 12/01/2016 10:16 AM, Laurent Pinchart wrote: >> Hello, >> >> On Thursday 01 Dec 2016 09:57:31 Sakari Ailus wrote: >>> On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: >>>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>>> On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: >>>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>>>>> On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >>>>>>>> Allow getting of subdevs from DT ports and endpoints. >>>>>>>> >>>>>>>> The _get_pdata() function was larely inspired by (i.e. stolen from) >>>>>>>> am437x-vpfe.c >>>>>>>> >>>>>>>> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >>>>>>>> --- >>>>>>>> >>>>>>>> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++- >>>>>>>> include/media/davinci/vpif_types.h >>>>>>>> | 9 +- >>>>>>>> 2 files changed, 133 insertions(+), 6 deletions(-) >>>>>>>> >>>>>>>> diff --git a/drivers/media/platform/davinci/vpif_capture.c >>>>>>>> b/drivers/media/platform/davinci/vpif_capture.c index >>>>>>>> 94ee6cf03f02..47a4699157e7 100644 >>>>>>>> --- a/drivers/media/platform/davinci/vpif_capture.c >>>>>>>> +++ b/drivers/media/platform/davinci/vpif_capture.c >>>>>>>> @@ -26,6 +26,8 @@ >>>>>>>> #include <linux/slab.h> >>>>>>>> >>>>>>>> #include <media/v4l2-ioctl.h> >>>>>>>> +#include <media/v4l2-of.h> >>>>>>>> +#include <media/i2c/tvp514x.h> >>>>>>> >>>>>>> Do you need this header? >>>>>> >>>>>> Yes, based on discussion with Hans, since there is no DT binding for >>>>>> selecting the input pins of the TVP514x, I have to select it in the >>>>>> driver, so I need the defines from this header. More on this below... >> >> That's really ugly :-( The problem should be fixed properly instead of adding >> one more offender. > > Do you have time for that, Laurent? I don't. Until that time we just need to > make do with this workaround. > >> >>>>>>>> #include "vpif.h" >>>>>>>> #include "vpif_capture.h" >>>>>>>> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >>>>>>>> >>>>>>>> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >>>>>>>> >>>>>>>> + if (!chan_cfg) >>>>>>>> + return -1; >>>>>>>> + if (input_index >= chan_cfg->input_count) >>>>>>>> + return -1; >>>>>>>> subdev_name = chan_cfg->inputs[input_index].subdev_name; >>>>>>>> if (subdev_name == NULL) >>>>>>>> return -1; >>>>>>>> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >>>>>>>> /* loop through the sub device list to get the sub device info >>>>>>>> */ >>>>>>>> for (i = 0; i < vpif_cfg->subdev_count; i++) { >>>>>>>> subdev_info = &vpif_cfg->subdev_info[i]; >>>>>>>> - if (!strcmp(subdev_info->name, subdev_name)) >>>>>>>> + if (subdev_info && !strcmp(subdev_info->name, >>>>>>>> subdev_name)) >>>>>>>> return i; >>>>>>>> } >>>>>>>> return -1; >>>>>>>> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct >>>>>>>> v4l2_async_notifier *notifier,> >> >> >>>>>>>> { >>>>>>>> int i; >>>>>>>> >>>>>>>> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >>>>>>>> + struct v4l2_async_subdev *_asd = vpif_obj.config >>>>>>>> ->asd[i]; >>>>>>>> + const struct device_node *node = _asd->match.of.node; >>>>>>>> + >>>>>>>> + if (node == subdev->of_node) { >>>>>>>> + vpif_obj.sd[i] = subdev; >>>>>>>> + vpif_obj.config->chan_config >>>>>>>> ->inputs[i].subdev_name = >>>>>>>> + (char *)subdev->of_node->full_name; >> >> Can subdev_name be made const instead of blindly casting the full_name pointer >> ? If not this is probably unsafe, and if yes it should be done :-) >> >>>>>>>> + vpif_dbg(2, debug, >>>>>>>> + "%s: setting input %d subdev_name = >>>>>>>> %s\n", >>>>>>>> + __func__, i, subdev->of_node >>>>>>>> ->full_name); >>>>>>>> + return 0; >>>>>>>> + } >>>>>>>> + } >>>>>>>> + >>>>>>>> for (i = 0; i < vpif_obj.config->subdev_count; i++) >>>>>>>> if (!strcmp(vpif_obj.config->subdev_info[i].name, >>>>>>>> subdev->name)) { >>>>>>>> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct >>>>>>>> v4l2_async_notifier *notifier) >>>>>>>> return vpif_probe_complete(); >>>>>>>> } >>>>>>>> >>>>>>>> +static struct vpif_capture_config * >>>>>>>> +vpif_capture_get_pdata(struct platform_device *pdev) >>>>>>>> +{ >>>>>>>> + struct device_node *endpoint = NULL; >>>>>>>> + struct v4l2_of_endpoint bus_cfg; >>>>>>>> + struct vpif_capture_config *pdata; >>>>>>>> + struct vpif_subdev_info *sdinfo; >>>>>>>> + struct vpif_capture_chan_config *chan; >>>>>>>> + unsigned int i; >>>>>>>> + >>>>>>>> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >>>>>>>> + >>>>>>>> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >>>>>>>> + return pdev->dev.platform_data; >>>>>>>> + >>>>>>>> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >>>>>>>> + if (!pdata) >>>>>>>> + return NULL; >>>>>>>> + pdata->subdev_info = >>>>>>>> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >>>>>>>> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >>>>>>>> + >>>>>>>> + if (!pdata->subdev_info) >>>>>>>> + return NULL; >>>>>>>> + dev_dbg(&pdev->dev, "%s\n", __func__); >>>>>>>> + >>>>>>>> + for (i = 0; ; i++) { >>>>>>>> + struct device_node *rem; >>>>>>>> + unsigned int flags; >>>>>>>> + int err; >>>>>>>> + >>>>>>>> + endpoint = of_graph_get_next_endpoint(pdev >>>>>>>> ->dev.of_node, >>>>>>>> + endpoint); >>>>>>>> + if (!endpoint) >>>>>>>> + break; >>>>>>>> + >>>>>>>> + sdinfo = &pdata->subdev_info[i]; >>>>>>> >>>>>>> subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. >>>>>> >>>>>> Right, I need to make the loop only go for a max of >>>>>> VPIF_CAPTURE_MAX_CHANNELS iterations. >>>>>> >>>>>>>> + chan = &pdata->chan_config[i]; >>>>>>>> + chan->inputs = devm_kzalloc(&pdev->dev, >>>>>>>> + sizeof(*chan->inputs) * >>>>>>>> + VPIF_DISPLAY_MAX_CHANNELS, >>>>>>>> + GFP_KERNEL); >>>>>>>> + >>>>>>>> + chan->input_count++; >>>>>>>> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; >>>>>>> >>>>>>> I wonder what's the purpose of using index i on this array as well. >>>>>> >>>>>> The number of endpoints in DT is the number of input channels >>>>>> configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) >>>>>> >>>>>>> If you use that to access a corresponding entry in a different array, >>>>>>> I'd just create a struct that contains the port configuration and the >>>>>>> async sub-device. The omap3isp driver does that, for instance; see >>>>>>> isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if >>>>>>> you're interested. Up to you. >>>>>> >>>>>> OK, I'll have a look at that driver. The goal here with this series is >>>>>> just to get this working with DT, but also not break the existing >>>>>> legacy platform_device support, so I'm trying not to mess with the >>>>>> driver-interal data structures too much. >>>>> >>>>> Ack. >>>>> >>>>>>>> + chan->inputs[i].input.std = V4L2_STD_ALL; >>>>>>>> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >>>>>>>> + >>>>>>>> + /* FIXME: need a new property? ch0:composite ch1: >>>>>>>> s-video */ >>>>>>>> + if (i == 0) >>>>>>> >>>>>>> Can you assume that the first endopoint has got a particular kind of >>>>>>> input? What if it's not connected? >>>>>> >>>>>> On all the boards I know of (there aren't many using this SoC), it's a >>>>>> safe assumption. >>>>>> >>>>>>> If this is a different physical port (not in the meaning another) in >>>>>>> the device, I'd use the reg property for this. Please see >>>>>>> Documentation/devicetree/bindings/media/video-interfaces.txt . >>>>>> >>>>>> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is >>>>>> that it's not physically a different port. Instead, it's just telling >>>>>> the TVP514x which pin(s) will be active inputs (and what kind of signal >>>>>> will be present.) >>>>>> >>>>>> I'm open to a better way to describe this input select from DT, but >>>>>> based on what I heard from Hans, there isn't currently a good way to do >>>>>> that except for in the driver: >>>>>> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) >>>>>> >>>>>> Based on further discussion in that thread, it sounds like there may be >>>>>> a way forward coming soon, and I'll be glad to switch to that when it >>>>>> arrives. >> >> I'm afraid I have to disappoint Hans here, I don't have code for that yet. >> >>>>> I'm not sure that properly supporting connectors will provide any help >>>>> here. >>>>> >>>>> Looking at the s_routing() API, it's the calling driver that has to be >>>>> aware of sub-device specific function parameters. As such it's not a >>>>> very good idea to require that a driver is aware of the value range of >>>>> another driver's parameter. I wonder if a simple enumeration interface >>>>> would help here --- if I understand correctly, the purpose is just to >>>>> provide a way to choose the input using VIDIOC_S_INPUT. >>>>> >>>>> I guess that's somehow ok as long as you have no other combinations of >>>>> these devices but this is hardly future-proof. (And certainly not a >>>>> problem created by this patch.) >>>> >>>> Yeah, this is far from future proof. >>>> >>>>> It'd be still nice to fix that as presumably we don't have the option of >>>>> reworking how we expect the device tree to look like. >>>> >>>> Agreed. >>>> >>>> I'm just hoping someone can shed som light on "how we expect the device >>>> tree to look". ;) >>> >>> :-) >>> >>> For the tvp514x, do you need more than a single endpoint on the receiver >>> side? Does the input that's selected affect the bus parameters? >>> >>> If it doesn't, you could create a custom endpoint property for the possible >>> input values. The s_routing() really should be fixed though, but that could >>> be postponed I guess. There are quite a few drivers using it. >> >> There's two ways to look at s_routing() in my opinion, as the calling driver >> should really not hardcode any knowledge specific to a particular subdev. We >> can either have the calling driver discover the possible routing options at >> runtime through the subdev API, or modify the s_routing() API. >> > > Some historical perspective: s_routing was added well before the device tree > was ever used for ARM. And at that time the vast majority of drivers were PCI > or USB drivers, very few platform drivers existed (and those typically used > sensors, not video receivers). > > Before s_routing existed the situation was even worse. > > Basically what s_routing does is a poor-man's device tree entry, telling the > subdev how to route video or audio from connector to the output of the chip. > Typically the card tables in PCI or USB drivers contain the correct arguments > for s_routing. Of course, today we'd do that with the DT, but that was not an > option years ago. So I'm still confused on the path forward here. I do not have the time (or the V4L2 knowledge/experience) to rework the V4L2 internals to make this work, but I'm happy to test if someone else is working on it. In the meantime, what do we do with this series? I have a couple minor things to fixup based on review comments, but other than that, the s_routing decision is blocking this from getting an update for use on DT platforms. The alternative is to go the OMAP route for legacy drivers like this and just use pdata quirks for passing the legacy pdata (which has the input and output routes hard-coded in platform_data). Kevin -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Dec 6, 2016 at 9:40 AM, Kevin Hilman <khilman@baylibre.com> wrote: > Hans Verkuil <hverkuil@xs4all.nl> writes: > >> On 12/01/2016 10:16 AM, Laurent Pinchart wrote: >>> Hello, >>> >>> On Thursday 01 Dec 2016 09:57:31 Sakari Ailus wrote: >>>> On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: >>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>>>> On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: >>>>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: >>>>>>>> On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: >>>>>>>>> Allow getting of subdevs from DT ports and endpoints. >>>>>>>>> >>>>>>>>> The _get_pdata() function was larely inspired by (i.e. stolen from) >>>>>>>>> am437x-vpfe.c >>>>>>>>> >>>>>>>>> Signed-off-by: Kevin Hilman <khilman@baylibre.com> >>>>>>>>> --- >>>>>>>>> >>>>>>>>> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++- >>>>>>>>> include/media/davinci/vpif_types.h >>>>>>>>> | 9 +- >>>>>>>>> 2 files changed, 133 insertions(+), 6 deletions(-) >>>>>>>>> >>>>>>>>> diff --git a/drivers/media/platform/davinci/vpif_capture.c >>>>>>>>> b/drivers/media/platform/davinci/vpif_capture.c index >>>>>>>>> 94ee6cf03f02..47a4699157e7 100644 >>>>>>>>> --- a/drivers/media/platform/davinci/vpif_capture.c >>>>>>>>> +++ b/drivers/media/platform/davinci/vpif_capture.c >>>>>>>>> @@ -26,6 +26,8 @@ >>>>>>>>> #include <linux/slab.h> >>>>>>>>> >>>>>>>>> #include <media/v4l2-ioctl.h> >>>>>>>>> +#include <media/v4l2-of.h> >>>>>>>>> +#include <media/i2c/tvp514x.h> >>>>>>>> >>>>>>>> Do you need this header? >>>>>>> >>>>>>> Yes, based on discussion with Hans, since there is no DT binding for >>>>>>> selecting the input pins of the TVP514x, I have to select it in the >>>>>>> driver, so I need the defines from this header. More on this below... >>> >>> That's really ugly :-( The problem should be fixed properly instead of adding >>> one more offender. >> >> Do you have time for that, Laurent? I don't. Until that time we just need to >> make do with this workaround. >> >>> >>>>>>>>> #include "vpif.h" >>>>>>>>> #include "vpif_capture.h" >>>>>>>>> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( >>>>>>>>> >>>>>>>>> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); >>>>>>>>> >>>>>>>>> + if (!chan_cfg) >>>>>>>>> + return -1; >>>>>>>>> + if (input_index >= chan_cfg->input_count) >>>>>>>>> + return -1; >>>>>>>>> subdev_name = chan_cfg->inputs[input_index].subdev_name; >>>>>>>>> if (subdev_name == NULL) >>>>>>>>> return -1; >>>>>>>>> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( >>>>>>>>> /* loop through the sub device list to get the sub device info >>>>>>>>> */ >>>>>>>>> for (i = 0; i < vpif_cfg->subdev_count; i++) { >>>>>>>>> subdev_info = &vpif_cfg->subdev_info[i]; >>>>>>>>> - if (!strcmp(subdev_info->name, subdev_name)) >>>>>>>>> + if (subdev_info && !strcmp(subdev_info->name, >>>>>>>>> subdev_name)) >>>>>>>>> return i; >>>>>>>>> } >>>>>>>>> return -1; >>>>>>>>> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct >>>>>>>>> v4l2_async_notifier *notifier,> >> >> >>>>>>>>> { >>>>>>>>> int i; >>>>>>>>> >>>>>>>>> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { >>>>>>>>> + struct v4l2_async_subdev *_asd = vpif_obj.config >>>>>>>>> ->asd[i]; >>>>>>>>> + const struct device_node *node = _asd->match.of.node; >>>>>>>>> + >>>>>>>>> + if (node == subdev->of_node) { >>>>>>>>> + vpif_obj.sd[i] = subdev; >>>>>>>>> + vpif_obj.config->chan_config >>>>>>>>> ->inputs[i].subdev_name = >>>>>>>>> + (char *)subdev->of_node->full_name; >>> >>> Can subdev_name be made const instead of blindly casting the full_name pointer >>> ? If not this is probably unsafe, and if yes it should be done :-) >>> >>>>>>>>> + vpif_dbg(2, debug, >>>>>>>>> + "%s: setting input %d subdev_name = >>>>>>>>> %s\n", >>>>>>>>> + __func__, i, subdev->of_node >>>>>>>>> ->full_name); >>>>>>>>> + return 0; >>>>>>>>> + } >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> for (i = 0; i < vpif_obj.config->subdev_count; i++) >>>>>>>>> if (!strcmp(vpif_obj.config->subdev_info[i].name, >>>>>>>>> subdev->name)) { >>>>>>>>> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct >>>>>>>>> v4l2_async_notifier *notifier) >>>>>>>>> return vpif_probe_complete(); >>>>>>>>> } >>>>>>>>> >>>>>>>>> +static struct vpif_capture_config * >>>>>>>>> +vpif_capture_get_pdata(struct platform_device *pdev) >>>>>>>>> +{ >>>>>>>>> + struct device_node *endpoint = NULL; >>>>>>>>> + struct v4l2_of_endpoint bus_cfg; >>>>>>>>> + struct vpif_capture_config *pdata; >>>>>>>>> + struct vpif_subdev_info *sdinfo; >>>>>>>>> + struct vpif_capture_chan_config *chan; >>>>>>>>> + unsigned int i; >>>>>>>>> + >>>>>>>>> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); >>>>>>>>> + >>>>>>>>> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) >>>>>>>>> + return pdev->dev.platform_data; >>>>>>>>> + >>>>>>>>> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); >>>>>>>>> + if (!pdata) >>>>>>>>> + return NULL; >>>>>>>>> + pdata->subdev_info = >>>>>>>>> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * >>>>>>>>> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); >>>>>>>>> + >>>>>>>>> + if (!pdata->subdev_info) >>>>>>>>> + return NULL; >>>>>>>>> + dev_dbg(&pdev->dev, "%s\n", __func__); >>>>>>>>> + >>>>>>>>> + for (i = 0; ; i++) { >>>>>>>>> + struct device_node *rem; >>>>>>>>> + unsigned int flags; >>>>>>>>> + int err; >>>>>>>>> + >>>>>>>>> + endpoint = of_graph_get_next_endpoint(pdev >>>>>>>>> ->dev.of_node, >>>>>>>>> + endpoint); >>>>>>>>> + if (!endpoint) >>>>>>>>> + break; >>>>>>>>> + >>>>>>>>> + sdinfo = &pdata->subdev_info[i]; >>>>>>>> >>>>>>>> subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. >>>>>>> >>>>>>> Right, I need to make the loop only go for a max of >>>>>>> VPIF_CAPTURE_MAX_CHANNELS iterations. >>>>>>> >>>>>>>>> + chan = &pdata->chan_config[i]; >>>>>>>>> + chan->inputs = devm_kzalloc(&pdev->dev, >>>>>>>>> + sizeof(*chan->inputs) * >>>>>>>>> + VPIF_DISPLAY_MAX_CHANNELS, >>>>>>>>> + GFP_KERNEL); >>>>>>>>> + >>>>>>>>> + chan->input_count++; >>>>>>>>> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; >>>>>>>> >>>>>>>> I wonder what's the purpose of using index i on this array as well. >>>>>>> >>>>>>> The number of endpoints in DT is the number of input channels >>>>>>> configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) >>>>>>> >>>>>>>> If you use that to access a corresponding entry in a different array, >>>>>>>> I'd just create a struct that contains the port configuration and the >>>>>>>> async sub-device. The omap3isp driver does that, for instance; see >>>>>>>> isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if >>>>>>>> you're interested. Up to you. >>>>>>> >>>>>>> OK, I'll have a look at that driver. The goal here with this series is >>>>>>> just to get this working with DT, but also not break the existing >>>>>>> legacy platform_device support, so I'm trying not to mess with the >>>>>>> driver-interal data structures too much. >>>>>> >>>>>> Ack. >>>>>> >>>>>>>>> + chan->inputs[i].input.std = V4L2_STD_ALL; >>>>>>>>> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; >>>>>>>>> + >>>>>>>>> + /* FIXME: need a new property? ch0:composite ch1: >>>>>>>>> s-video */ >>>>>>>>> + if (i == 0) >>>>>>>> >>>>>>>> Can you assume that the first endopoint has got a particular kind of >>>>>>>> input? What if it's not connected? >>>>>>> >>>>>>> On all the boards I know of (there aren't many using this SoC), it's a >>>>>>> safe assumption. >>>>>>> >>>>>>>> If this is a different physical port (not in the meaning another) in >>>>>>>> the device, I'd use the reg property for this. Please see >>>>>>>> Documentation/devicetree/bindings/media/video-interfaces.txt . >>>>>>> >>>>>>> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is >>>>>>> that it's not physically a different port. Instead, it's just telling >>>>>>> the TVP514x which pin(s) will be active inputs (and what kind of signal >>>>>>> will be present.) >>>>>>> >>>>>>> I'm open to a better way to describe this input select from DT, but >>>>>>> based on what I heard from Hans, there isn't currently a good way to do >>>>>>> that except for in the driver: >>>>>>> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) >>>>>>> >>>>>>> Based on further discussion in that thread, it sounds like there may be >>>>>>> a way forward coming soon, and I'll be glad to switch to that when it >>>>>>> arrives. >>> >>> I'm afraid I have to disappoint Hans here, I don't have code for that yet. >>> >>>>>> I'm not sure that properly supporting connectors will provide any help >>>>>> here. >>>>>> >>>>>> Looking at the s_routing() API, it's the calling driver that has to be >>>>>> aware of sub-device specific function parameters. As such it's not a >>>>>> very good idea to require that a driver is aware of the value range of >>>>>> another driver's parameter. I wonder if a simple enumeration interface >>>>>> would help here --- if I understand correctly, the purpose is just to >>>>>> provide a way to choose the input using VIDIOC_S_INPUT. >>>>>> >>>>>> I guess that's somehow ok as long as you have no other combinations of >>>>>> these devices but this is hardly future-proof. (And certainly not a >>>>>> problem created by this patch.) >>>>> >>>>> Yeah, this is far from future proof. >>>>> >>>>>> It'd be still nice to fix that as presumably we don't have the option of >>>>>> reworking how we expect the device tree to look like. >>>>> >>>>> Agreed. >>>>> >>>>> I'm just hoping someone can shed som light on "how we expect the device >>>>> tree to look". ;) >>>> >>>> :-) >>>> >>>> For the tvp514x, do you need more than a single endpoint on the receiver >>>> side? Does the input that's selected affect the bus parameters? >>>> >>>> If it doesn't, you could create a custom endpoint property for the possible >>>> input values. The s_routing() really should be fixed though, but that could >>>> be postponed I guess. There are quite a few drivers using it. >>> >>> There's two ways to look at s_routing() in my opinion, as the calling driver >>> should really not hardcode any knowledge specific to a particular subdev. We >>> can either have the calling driver discover the possible routing options at >>> runtime through the subdev API, or modify the s_routing() API. >>> >> >> Some historical perspective: s_routing was added well before the device tree >> was ever used for ARM. And at that time the vast majority of drivers were PCI >> or USB drivers, very few platform drivers existed (and those typically used >> sensors, not video receivers). >> >> Before s_routing existed the situation was even worse. >> >> Basically what s_routing does is a poor-man's device tree entry, telling the >> subdev how to route video or audio from connector to the output of the chip. >> Typically the card tables in PCI or USB drivers contain the correct arguments >> for s_routing. Of course, today we'd do that with the DT, but that was not an >> option years ago. > > So I'm still confused on the path forward here. > > I do not have the time (or the V4L2 knowledge/experience) to rework the > V4L2 internals to make this work, but I'm happy to test if someone else > is working on it. > > In the meantime, what do we do with this series? I have a couple minor > things to fixup based on review comments, but other than that, the > s_routing decision is blocking this from getting an update for use on DT > platforms. > > The alternative is to go the OMAP route for legacy drivers like this and > just use pdata quirks for passing the legacy pdata (which has the input > and output routes hard-coded in platform_data). Also, FYI, I have the same issue with the output/display side of this controller. It's using an I2C-connected adv7343, where the input and output routes are configured by the driver using s_routing, and the current code passes the routes in using platform_data. Kevin -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Kevin, On Tue, Dec 06, 2016 at 11:50:58AM -0800, Kevin Hilman wrote: > On Tue, Dec 6, 2016 at 9:40 AM, Kevin Hilman <khilman@baylibre.com> wrote: > > Hans Verkuil <hverkuil@xs4all.nl> writes: > > > >> On 12/01/2016 10:16 AM, Laurent Pinchart wrote: > >>> Hello, > >>> > >>> On Thursday 01 Dec 2016 09:57:31 Sakari Ailus wrote: > >>>> On Wed, Nov 30, 2016 at 04:14:11PM -0800, Kevin Hilman wrote: > >>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: > >>>>>> On Wed, Nov 23, 2016 at 03:25:32PM -0800, Kevin Hilman wrote: > >>>>>>> Sakari Ailus <sakari.ailus@iki.fi> writes: > >>>>>>>> On Tue, Nov 22, 2016 at 07:52:43AM -0800, Kevin Hilman wrote: > >>>>>>>>> Allow getting of subdevs from DT ports and endpoints. > >>>>>>>>> > >>>>>>>>> The _get_pdata() function was larely inspired by (i.e. stolen from) > >>>>>>>>> am437x-vpfe.c > >>>>>>>>> > >>>>>>>>> Signed-off-by: Kevin Hilman <khilman@baylibre.com> > >>>>>>>>> --- > >>>>>>>>> > >>>>>>>>> drivers/media/platform/davinci/vpif_capture.c | 130 +++++++++++++++- > >>>>>>>>> include/media/davinci/vpif_types.h > >>>>>>>>> | 9 +- > >>>>>>>>> 2 files changed, 133 insertions(+), 6 deletions(-) > >>>>>>>>> > >>>>>>>>> diff --git a/drivers/media/platform/davinci/vpif_capture.c > >>>>>>>>> b/drivers/media/platform/davinci/vpif_capture.c index > >>>>>>>>> 94ee6cf03f02..47a4699157e7 100644 > >>>>>>>>> --- a/drivers/media/platform/davinci/vpif_capture.c > >>>>>>>>> +++ b/drivers/media/platform/davinci/vpif_capture.c > >>>>>>>>> @@ -26,6 +26,8 @@ > >>>>>>>>> #include <linux/slab.h> > >>>>>>>>> > >>>>>>>>> #include <media/v4l2-ioctl.h> > >>>>>>>>> +#include <media/v4l2-of.h> > >>>>>>>>> +#include <media/i2c/tvp514x.h> > >>>>>>>> > >>>>>>>> Do you need this header? > >>>>>>> > >>>>>>> Yes, based on discussion with Hans, since there is no DT binding for > >>>>>>> selecting the input pins of the TVP514x, I have to select it in the > >>>>>>> driver, so I need the defines from this header. More on this below... > >>> > >>> That's really ugly :-( The problem should be fixed properly instead of adding > >>> one more offender. > >> > >> Do you have time for that, Laurent? I don't. Until that time we just need to > >> make do with this workaround. > >> > >>> > >>>>>>>>> #include "vpif.h" > >>>>>>>>> #include "vpif_capture.h" > >>>>>>>>> @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( > >>>>>>>>> > >>>>>>>>> vpif_dbg(2, debug, "vpif_input_to_subdev\n"); > >>>>>>>>> > >>>>>>>>> + if (!chan_cfg) > >>>>>>>>> + return -1; > >>>>>>>>> + if (input_index >= chan_cfg->input_count) > >>>>>>>>> + return -1; > >>>>>>>>> subdev_name = chan_cfg->inputs[input_index].subdev_name; > >>>>>>>>> if (subdev_name == NULL) > >>>>>>>>> return -1; > >>>>>>>>> @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( > >>>>>>>>> /* loop through the sub device list to get the sub device info > >>>>>>>>> */ > >>>>>>>>> for (i = 0; i < vpif_cfg->subdev_count; i++) { > >>>>>>>>> subdev_info = &vpif_cfg->subdev_info[i]; > >>>>>>>>> - if (!strcmp(subdev_info->name, subdev_name)) > >>>>>>>>> + if (subdev_info && !strcmp(subdev_info->name, > >>>>>>>>> subdev_name)) > >>>>>>>>> return i; > >>>>>>>>> } > >>>>>>>>> return -1; > >>>>>>>>> @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct > >>>>>>>>> v4l2_async_notifier *notifier,> >> >> > >>>>>>>>> { > >>>>>>>>> int i; > >>>>>>>>> > >>>>>>>>> + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { > >>>>>>>>> + struct v4l2_async_subdev *_asd = vpif_obj.config > >>>>>>>>> ->asd[i]; > >>>>>>>>> + const struct device_node *node = _asd->match.of.node; > >>>>>>>>> + > >>>>>>>>> + if (node == subdev->of_node) { > >>>>>>>>> + vpif_obj.sd[i] = subdev; > >>>>>>>>> + vpif_obj.config->chan_config > >>>>>>>>> ->inputs[i].subdev_name = > >>>>>>>>> + (char *)subdev->of_node->full_name; > >>> > >>> Can subdev_name be made const instead of blindly casting the full_name pointer > >>> ? If not this is probably unsafe, and if yes it should be done :-) > >>> > >>>>>>>>> + vpif_dbg(2, debug, > >>>>>>>>> + "%s: setting input %d subdev_name = > >>>>>>>>> %s\n", > >>>>>>>>> + __func__, i, subdev->of_node > >>>>>>>>> ->full_name); > >>>>>>>>> + return 0; > >>>>>>>>> + } > >>>>>>>>> + } > >>>>>>>>> + > >>>>>>>>> for (i = 0; i < vpif_obj.config->subdev_count; i++) > >>>>>>>>> if (!strcmp(vpif_obj.config->subdev_info[i].name, > >>>>>>>>> subdev->name)) { > >>>>>>>>> @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct > >>>>>>>>> v4l2_async_notifier *notifier) > >>>>>>>>> return vpif_probe_complete(); > >>>>>>>>> } > >>>>>>>>> > >>>>>>>>> +static struct vpif_capture_config * > >>>>>>>>> +vpif_capture_get_pdata(struct platform_device *pdev) > >>>>>>>>> +{ > >>>>>>>>> + struct device_node *endpoint = NULL; > >>>>>>>>> + struct v4l2_of_endpoint bus_cfg; > >>>>>>>>> + struct vpif_capture_config *pdata; > >>>>>>>>> + struct vpif_subdev_info *sdinfo; > >>>>>>>>> + struct vpif_capture_chan_config *chan; > >>>>>>>>> + unsigned int i; > >>>>>>>>> + > >>>>>>>>> + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); > >>>>>>>>> + > >>>>>>>>> + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) > >>>>>>>>> + return pdev->dev.platform_data; > >>>>>>>>> + > >>>>>>>>> + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); > >>>>>>>>> + if (!pdata) > >>>>>>>>> + return NULL; > >>>>>>>>> + pdata->subdev_info = > >>>>>>>>> + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * > >>>>>>>>> + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); > >>>>>>>>> + > >>>>>>>>> + if (!pdata->subdev_info) > >>>>>>>>> + return NULL; > >>>>>>>>> + dev_dbg(&pdev->dev, "%s\n", __func__); > >>>>>>>>> + > >>>>>>>>> + for (i = 0; ; i++) { > >>>>>>>>> + struct device_node *rem; > >>>>>>>>> + unsigned int flags; > >>>>>>>>> + int err; > >>>>>>>>> + > >>>>>>>>> + endpoint = of_graph_get_next_endpoint(pdev > >>>>>>>>> ->dev.of_node, > >>>>>>>>> + endpoint); > >>>>>>>>> + if (!endpoint) > >>>>>>>>> + break; > >>>>>>>>> + > >>>>>>>>> + sdinfo = &pdata->subdev_info[i]; > >>>>>>>> > >>>>>>>> subdev_info[] has got VPIF_CAPTURE_MAX_CHANNELS entries only. > >>>>>>> > >>>>>>> Right, I need to make the loop only go for a max of > >>>>>>> VPIF_CAPTURE_MAX_CHANNELS iterations. > >>>>>>> > >>>>>>>>> + chan = &pdata->chan_config[i]; > >>>>>>>>> + chan->inputs = devm_kzalloc(&pdev->dev, > >>>>>>>>> + sizeof(*chan->inputs) * > >>>>>>>>> + VPIF_DISPLAY_MAX_CHANNELS, > >>>>>>>>> + GFP_KERNEL); > >>>>>>>>> + > >>>>>>>>> + chan->input_count++; > >>>>>>>>> + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; > >>>>>>>> > >>>>>>>> I wonder what's the purpose of using index i on this array as well. > >>>>>>> > >>>>>>> The number of endpoints in DT is the number of input channels > >>>>>>> configured (up to a max of VPIF_CAPTURE_MAX_CHANNELS.) > >>>>>>> > >>>>>>>> If you use that to access a corresponding entry in a different array, > >>>>>>>> I'd just create a struct that contains the port configuration and the > >>>>>>>> async sub-device. The omap3isp driver does that, for instance; see > >>>>>>>> isp_of_parse_nodes() in drivers/media/platform/omap3isp/isp.c if > >>>>>>>> you're interested. Up to you. > >>>>>>> > >>>>>>> OK, I'll have a look at that driver. The goal here with this series is > >>>>>>> just to get this working with DT, but also not break the existing > >>>>>>> legacy platform_device support, so I'm trying not to mess with the > >>>>>>> driver-interal data structures too much. > >>>>>> > >>>>>> Ack. > >>>>>> > >>>>>>>>> + chan->inputs[i].input.std = V4L2_STD_ALL; > >>>>>>>>> + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; > >>>>>>>>> + > >>>>>>>>> + /* FIXME: need a new property? ch0:composite ch1: > >>>>>>>>> s-video */ > >>>>>>>>> + if (i == 0) > >>>>>>>> > >>>>>>>> Can you assume that the first endopoint has got a particular kind of > >>>>>>>> input? What if it's not connected? > >>>>>>> > >>>>>>> On all the boards I know of (there aren't many using this SoC), it's a > >>>>>>> safe assumption. > >>>>>>> > >>>>>>>> If this is a different physical port (not in the meaning another) in > >>>>>>>> the device, I'd use the reg property for this. Please see > >>>>>>>> Documentation/devicetree/bindings/media/video-interfaces.txt . > >>>>>>> > >>>>>>> My understanding (which is admittedly somewhat fuzzy) of the TVP514x is > >>>>>>> that it's not physically a different port. Instead, it's just telling > >>>>>>> the TVP514x which pin(s) will be active inputs (and what kind of signal > >>>>>>> will be present.) > >>>>>>> > >>>>>>> I'm open to a better way to describe this input select from DT, but > >>>>>>> based on what I heard from Hans, there isn't currently a good way to do > >>>>>>> that except for in the driver: > >>>>>>> (c.f. https://marc.info/?l=linux-arm-kernel&m=147887871615788) > >>>>>>> > >>>>>>> Based on further discussion in that thread, it sounds like there may be > >>>>>>> a way forward coming soon, and I'll be glad to switch to that when it > >>>>>>> arrives. > >>> > >>> I'm afraid I have to disappoint Hans here, I don't have code for that yet. > >>> > >>>>>> I'm not sure that properly supporting connectors will provide any help > >>>>>> here. > >>>>>> > >>>>>> Looking at the s_routing() API, it's the calling driver that has to be > >>>>>> aware of sub-device specific function parameters. As such it's not a > >>>>>> very good idea to require that a driver is aware of the value range of > >>>>>> another driver's parameter. I wonder if a simple enumeration interface > >>>>>> would help here --- if I understand correctly, the purpose is just to > >>>>>> provide a way to choose the input using VIDIOC_S_INPUT. > >>>>>> > >>>>>> I guess that's somehow ok as long as you have no other combinations of > >>>>>> these devices but this is hardly future-proof. (And certainly not a > >>>>>> problem created by this patch.) > >>>>> > >>>>> Yeah, this is far from future proof. > >>>>> > >>>>>> It'd be still nice to fix that as presumably we don't have the option of > >>>>>> reworking how we expect the device tree to look like. > >>>>> > >>>>> Agreed. > >>>>> > >>>>> I'm just hoping someone can shed som light on "how we expect the device > >>>>> tree to look". ;) > >>>> > >>>> :-) > >>>> > >>>> For the tvp514x, do you need more than a single endpoint on the receiver > >>>> side? Does the input that's selected affect the bus parameters? > >>>> > >>>> If it doesn't, you could create a custom endpoint property for the possible > >>>> input values. The s_routing() really should be fixed though, but that could > >>>> be postponed I guess. There are quite a few drivers using it. > >>> > >>> There's two ways to look at s_routing() in my opinion, as the calling driver > >>> should really not hardcode any knowledge specific to a particular subdev. We > >>> can either have the calling driver discover the possible routing options at > >>> runtime through the subdev API, or modify the s_routing() API. > >>> > >> > >> Some historical perspective: s_routing was added well before the device tree > >> was ever used for ARM. And at that time the vast majority of drivers were PCI > >> or USB drivers, very few platform drivers existed (and those typically used > >> sensors, not video receivers). > >> > >> Before s_routing existed the situation was even worse. > >> > >> Basically what s_routing does is a poor-man's device tree entry, telling the > >> subdev how to route video or audio from connector to the output of the chip. > >> Typically the card tables in PCI or USB drivers contain the correct arguments > >> for s_routing. Of course, today we'd do that with the DT, but that was not an > >> option years ago. > > > > So I'm still confused on the path forward here. > > > > I do not have the time (or the V4L2 knowledge/experience) to rework the > > V4L2 internals to make this work, but I'm happy to test if someone else > > is working on it. > > > > In the meantime, what do we do with this series? I have a couple minor > > things to fixup based on review comments, but other than that, the > > s_routing decision is blocking this from getting an update for use on DT > > platforms. > > > > The alternative is to go the OMAP route for legacy drivers like this and > > just use pdata quirks for passing the legacy pdata (which has the input > > and output routes hard-coded in platform_data). > > Also, FYI, I have the same issue with the output/display side of this > controller. It's using an I2C-connected adv7343, where the input and > output routes are configured by the driver using s_routing, and the > current code passes the routes in using platform_data. A quick and dirty way to get forward would be to add a davinci specific property to tell the valid arguments for the s_routing() in DT. That's quite ugly, but would avoid adding a dependency to the tvp514x driver. A better solution would be to provide the davinci driver with an enumeration of which routes the tvp514x supports, a bit like the enum_mbus_code() pad op does. It'd be an additional sub-device operation next to s_routing(). The valid values could be found that way. Only the tvp514x would need to support that from the beginning so we'd know which values are valid here. If there's a need to limit what should be actually allowed on that board it'd be found in the tvp514x DT node, not davinci's. There are many, many drivers using s_routing() so there would be a lot more work in changing how s_routing() works. An enumeration of what's possible is also a cleaner way to achieve what's needed IMO. Laurent, Hans; let me know if you agree / disagree.
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c index 94ee6cf03f02..47a4699157e7 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -26,6 +26,8 @@ #include <linux/slab.h> #include <media/v4l2-ioctl.h> +#include <media/v4l2-of.h> +#include <media/i2c/tvp514x.h> #include "vpif.h" #include "vpif_capture.h" @@ -650,6 +652,10 @@ static int vpif_input_to_subdev( vpif_dbg(2, debug, "vpif_input_to_subdev\n"); + if (!chan_cfg) + return -1; + if (input_index >= chan_cfg->input_count) + return -1; subdev_name = chan_cfg->inputs[input_index].subdev_name; if (subdev_name == NULL) return -1; @@ -657,7 +663,7 @@ static int vpif_input_to_subdev( /* loop through the sub device list to get the sub device info */ for (i = 0; i < vpif_cfg->subdev_count; i++) { subdev_info = &vpif_cfg->subdev_info[i]; - if (!strcmp(subdev_info->name, subdev_name)) + if (subdev_info && !strcmp(subdev_info->name, subdev_name)) return i; } return -1; @@ -1327,6 +1333,21 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, { int i; + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { + struct v4l2_async_subdev *_asd = vpif_obj.config->asd[i]; + const struct device_node *node = _asd->match.of.node; + + if (node == subdev->of_node) { + vpif_obj.sd[i] = subdev; + vpif_obj.config->chan_config->inputs[i].subdev_name = + (char *)subdev->of_node->full_name; + vpif_dbg(2, debug, + "%s: setting input %d subdev_name = %s\n", + __func__, i, subdev->of_node->full_name); + return 0; + } + } + for (i = 0; i < vpif_obj.config->subdev_count; i++) if (!strcmp(vpif_obj.config->subdev_info[i].name, subdev->name)) { @@ -1422,6 +1443,110 @@ static int vpif_async_complete(struct v4l2_async_notifier *notifier) return vpif_probe_complete(); } +static struct vpif_capture_config * +vpif_capture_get_pdata(struct platform_device *pdev) +{ + struct device_node *endpoint = NULL; + struct v4l2_of_endpoint bus_cfg; + struct vpif_capture_config *pdata; + struct vpif_subdev_info *sdinfo; + struct vpif_capture_chan_config *chan; + unsigned int i; + + dev_dbg(&pdev->dev, "vpif_get_pdata\n"); + + if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) + return pdev->dev.platform_data; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + pdata->subdev_info = + devm_kzalloc(&pdev->dev, sizeof(*pdata->subdev_info) * + VPIF_CAPTURE_MAX_CHANNELS, GFP_KERNEL); + + if (!pdata->subdev_info) + return NULL; + dev_dbg(&pdev->dev, "%s\n", __func__); + + for (i = 0; ; i++) { + struct device_node *rem; + unsigned int flags; + int err; + + endpoint = of_graph_get_next_endpoint(pdev->dev.of_node, + endpoint); + if (!endpoint) + break; + + sdinfo = &pdata->subdev_info[i]; + chan = &pdata->chan_config[i]; + chan->inputs = devm_kzalloc(&pdev->dev, + sizeof(*chan->inputs) * + VPIF_DISPLAY_MAX_CHANNELS, + GFP_KERNEL); + + chan->input_count++; + chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA; + chan->inputs[i].input.std = V4L2_STD_ALL; + chan->inputs[i].input.capabilities = V4L2_IN_CAP_STD; + + /* FIXME: need a new property? ch0:composite ch1: s-video */ + if (i == 0) + chan->inputs[i].input_route = INPUT_CVBS_VI2B; + else + chan->inputs[i].input_route = INPUT_SVIDEO_VI2C_VI1C; + chan->inputs[i].output_route = OUTPUT_10BIT_422_EMBEDDED_SYNC; + + err = v4l2_of_parse_endpoint(endpoint, &bus_cfg); + if (err) { + dev_err(&pdev->dev, "Could not parse the endpoint\n"); + goto done; + } + dev_dbg(&pdev->dev, "Endpoint %s, bus_width = %d\n", + endpoint->full_name, bus_cfg.bus.parallel.bus_width); + flags = bus_cfg.bus.parallel.flags; + + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) + chan->vpif_if.hd_pol = 1; + + if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) + chan->vpif_if.vd_pol = 1; + + chan->vpif_if.if_type = VPIF_IF_BT656; + rem = of_graph_get_remote_port_parent(endpoint); + if (!rem) { + dev_dbg(&pdev->dev, "Remote device at %s not found\n", + endpoint->full_name); + goto done; + } + + dev_dbg(&pdev->dev, "Remote device %s, %s found\n", + rem->name, rem->full_name); + sdinfo->name = rem->full_name; + + pdata->asd[i] = devm_kzalloc(&pdev->dev, + sizeof(struct v4l2_async_subdev), + GFP_KERNEL); + if (!pdata->asd[i]) { + of_node_put(rem); + pdata = NULL; + goto done; + } + + pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF; + pdata->asd[i]->match.of.node = rem; + of_node_put(rem); + } + +done: + pdata->asd_sizes[0] = i; + pdata->subdev_count = i; + pdata->card_name = "DA850/OMAP-L138 Video Capture"; + + return pdata; +} + /** * vpif_probe : This function probes the vpif capture driver * @pdev: platform device pointer @@ -1438,6 +1563,7 @@ static __init int vpif_probe(struct platform_device *pdev) int res_idx = 0; int i, err; + pdev->dev.platform_data = vpif_capture_get_pdata(pdev); if (!pdev->dev.platform_data) { dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); return -EINVAL; @@ -1480,7 +1606,7 @@ static __init int vpif_probe(struct platform_device *pdev) goto vpif_unregister; } - if (!vpif_obj.config->asd_sizes) { + if (!vpif_obj.config->asd_sizes[0]) { i2c_adap = i2c_get_adapter(1); for (i = 0; i < subdev_count; i++) { subdevdata = &vpif_obj.config->subdev_info[i]; diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h index 3cb1704a0650..4ee3b41975db 100644 --- a/include/media/davinci/vpif_types.h +++ b/include/media/davinci/vpif_types.h @@ -65,14 +65,14 @@ struct vpif_display_config { struct vpif_input { struct v4l2_input input; - const char *subdev_name; + char *subdev_name; u32 input_route; u32 output_route; }; struct vpif_capture_chan_config { struct vpif_interface vpif_if; - const struct vpif_input *inputs; + struct vpif_input *inputs; int input_count; }; @@ -83,7 +83,8 @@ struct vpif_capture_config { struct vpif_subdev_info *subdev_info; int subdev_count; const char *card_name; - struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */ - int *asd_sizes; /* 0-terminated array of asd group sizes */ + + struct v4l2_async_subdev *asd[VPIF_CAPTURE_MAX_CHANNELS]; + int asd_sizes[VPIF_CAPTURE_MAX_CHANNELS]; }; #endif /* _VPIF_TYPES_H */