From patchwork Tue Oct 25 23:55:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 9395745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E4F560231 for ; Wed, 26 Oct 2016 00:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E94B2296A7 for ; Wed, 26 Oct 2016 00:00:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDD14296B2; Wed, 26 Oct 2016 00:00:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 92F40296A7 for ; Wed, 26 Oct 2016 00:00:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzBcH-0003ev-8L; Tue, 25 Oct 2016 23:58:49 +0000 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzBZc-0001lj-NS for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2016 23:56:08 +0000 Received: by mail-pf0-x232.google.com with SMTP id n85so11119831pfi.1 for ; Tue, 25 Oct 2016 16:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hdHMTJvF3J/IDcHbGcH5zECG9AiQPR6kjq4fCkUimk8=; b=vVQ0E5wPuUro3hUvNc8EDpllM+WygBaNyeuDyxcW+te3DZCu9X6NY7ebc9hujyw+0H dJeLyRZOVfW0X9OdVLW2JkMwgXub48xZ0p+xSJhQ7thhd6xJ/+oExwzAZuUxkHdYTB16 6FpHfQkBqtwjRmdhh1iJiM44IdHsn6Oupetjtu6Ag7DC7L8u3/sGpMyiodsAfu6E01Xx ZWnCwRbgZcbA/J8vN/VdhJ9JfZjQHTmZ6ExKQ1l0o8DZuzfEcayPK9jN7SBCBXvar9sy +/WuOWbRoxkqeqpC+rAP2cGEZuc7tx4XmE4Nd9w3iUDc49WuOMTivWH1FUzufa+34TUN jBLQ== 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=hdHMTJvF3J/IDcHbGcH5zECG9AiQPR6kjq4fCkUimk8=; b=O+lfgcs2w/rAGgt8wLPSOm4+KXJfIib4zH7y8cnaxA9h1RJ5IRcDeGjZdeuxkXuptD 9drCVq4cUeiw6gbJDj3eth/FLCw9dH8Z92jTtp9n/TLFXrFYLk7UQQYoSF12L1C8WnDT WKsECbDxG9aTRvuXDFJScTfM8hNsd6K+sYIhulO+MVGeMUKsEIFUWw4LczNljZe4sAqR ItyQJ2tV4ZS45s8MzYS/JrAyHCPF+Pme9QuEQxm6AM6R/GdAmrFEePauW0t9jBti371L P4hL8nQOiWfnzCvLyc1GS+iH5zCKETLDo+Q60QBH/Kzg/feL2OyeO2XhP2WE4aYJVhE0 zFTQ== X-Gm-Message-State: ABUngvcU9usvTec+3B5Jmtv7q/IkU+TzDLBWg7l5vkB7G2CVYwbNdFGbvPZerrNisBm0HL/p X-Received: by 10.99.226.83 with SMTP id y19mr14745015pgj.147.1477439743487; Tue, 25 Oct 2016 16:55:43 -0700 (PDT) Received: from localhost (c-98-203-232-209.hsd1.wa.comcast.net. [98.203.232.209]) by smtp.gmail.com with ESMTPSA id t6sm35974726paa.45.2016.10.25.16.55.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2016 16:55:43 -0700 (PDT) From: Kevin Hilman To: Hans Verkuil , Laurent Pinchart , linux-media@vger.kernel.org Subject: [RFC PATCH 6/6] [media] davinci: vpif_capture: get subdevs from DT Date: Tue, 25 Oct 2016 16:55:36 -0700 Message-Id: <20161025235536.7342-7-khilman@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161025235536.7342-1-khilman@baylibre.com> References: <20161025235536.7342-1-khilman@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161025_165604_994730_6DE022BB X-CRM114-Status: GOOD ( 20.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lechner , Axel Haslam , Sekhar Nori , =?UTF-8?q?Bartosz=20Go=C5=82aszewski?= , Alexandre Bailon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP First pass at getting subdevs from DT ports and endpoints. The _get_pdata() function was larely inspired by (i.e. stolen from) am437x-vpfe.c Questions: - Legacy board file passes subdev input & output routes via pdata (e.g. tvp514x svideo or composite selection.) How is this supposed to be done via DT? Not-Yet-Signed-off-by: Kevin Hilman --- drivers/media/platform/davinci/vpif_capture.c | 132 +++++++++++++++++++++++++- include/media/davinci/vpif_types.h | 9 +- 2 files changed, 134 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c index becc3e63b472..df2af5cda37a 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -26,6 +26,8 @@ #include #include +#include +#include /* FIXME: how to pass the INPUT_* OUTPUT* fields? */ #include "vpif.h" #include "vpif_capture.h" @@ -651,6 +653,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; @@ -658,7 +664,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; @@ -1328,13 +1334,25 @@ static int vpif_async_bound(struct v4l2_async_notifier *notifier, { int i; + for (i = 0; i < vpif_obj.config->asd_sizes[0]; i++) { + const struct device_node *node = vpif_obj.config->asd[i]->match.of.node; + + if (node == subdev->of_node) { + vpif_obj.sd[i] = subdev; + vpif_obj.config->chan_config->inputs[i].subdev_name = 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)) { vpif_obj.sd[i] = subdev; return 0; } - + return -EINVAL; } @@ -1423,6 +1441,113 @@ 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; + + dev_dbg(&pdev->dev, "found endpoint %s, %s\n", + endpoint->name, endpoint->full_name); + + 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); + + /* sdinfo->name = devm_kzalloc(&pdev->dev, 16, GFP_KERNEL); */ + /* snprintf(sdinfo->name, 16, "VPIF input %d", i); */ + 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 @@ -1439,6 +1564,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; @@ -1481,7 +1607,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 */