From patchwork Tue Jun 6 23:37:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 9770187 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 DE0876034B for ; Tue, 6 Jun 2017 23:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE807284E4 for ; Tue, 6 Jun 2017 23:38:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B24F72851F; Tue, 6 Jun 2017 23:38: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1FBEB284E4 for ; Tue, 6 Jun 2017 23:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M9nP9GpdGZKJOp8xfJDeWiuFEu/nIpJUxCr1puweJNQ=; b=qN8wM3AIIaYBq0 YG3tdPJwOXzytCsmCdd0FQjw8bkvg9Po3hxuM4W63cZvpyS9rbJO9dGRTw4pfUN6m12JVxkkoG0y4 fulWNwr6+jnh9UcnOHgVM5enrYjfLHoN2c7GIi4Puz6JyjIWUk6x4/ovWXqo9f4xj/mo2vwgVXSud Bnz/xJYG4i8c/nGmsZX7qrWu2LHEG5EnleUWB8EyslntdttCN4Fhyy+jNb1Ifv0ZUoev7FXD0QMz1 62jeH5we0fY2mX6EkFhOcgJfRzVuh/i9VhfRmmUEExovVJTtkPMnmquHuwRzwXPKJY75kJ18qgGQY kv/EH1cFCCdE4XdYALTA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIO3H-00083Q-I4; Tue, 06 Jun 2017 23:38:19 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIO33-0007pf-Lq for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2017 23:38:08 +0000 Received: by mail-pf0-x230.google.com with SMTP id 83so45304313pfr.0 for ; Tue, 06 Jun 2017 16:37:45 -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=YeYFloQ2YZAKo6YQqzmOKy96oIvhxI3T39FDeB6MPZ4=; b=KaytFunt/d0K8/A3X4ALgVlbl64mX+mjIP/JQk79uNGDLq2Me31kUwAQVTHtvrWyS0 JYWelH7NL2RDpgMmFvqKtzAtfFHLIgTRbcDj1fc3B7p+hKBPaFs9+PL3OfpMmRMttAO3 B4SvF6Rs1ey3GZjXkRC3Y5c6Vy77QTAreW3Voin23zEKVqsQMBq1uE2DV+QiaL+ytFJb gD4G01I4z4zwT9SQYzZDBYjiYr95X1iSghP3sKKjdFF3CJzpR4oS+lZkRTMNdLjb+vOu 6zGmhBhWiQR7fEl07w9VFcXfmzuhXgd8aQeQvyS01Cs7x24t6A9EqqOxYu2BgTULawK0 H8YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YeYFloQ2YZAKo6YQqzmOKy96oIvhxI3T39FDeB6MPZ4=; b=m7reBv72xlEPFz0CDSh+06YWkXLAiHZlkxsgFQh3Nlmy9U7HMIIb+UIPtOF6DDc613 kLLaJt9L3l+A3S9hvb/X34lj3KIRBSTXAJRK2z8npaR/qQEh/rmhPvHU0yy02MtYmiAD WgP+MWFm4a0Kfx0SoqcNMyKjqaIm9cUf5S8D6rDJZ3kAORkl87mYs9oPhOrFx1dHhBtK W/VYfnmQL1mjEHmcBjXybFkbACAHVfTU8VPAiqQtYF64bZBeu4ek2tJn7QG/+3YLWxIT dxMLeMP+xtIf7VttewITClBgoSA3sLQdpFTT8wgG2e8aIPHGr0+WptO0iOK+96bNdiPm MzUA== X-Gm-Message-State: AODbwcAZcPlDUuqjI2FbhLFTnz05Fi5LwPMJoQaCt37VhbkCb7Sq3znP 871q6tJB1humfaaN X-Received: by 10.84.225.2 with SMTP id t2mr24252845plj.108.1496792264808; Tue, 06 Jun 2017 16:37:44 -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 u85sm13960229pfg.73.2017.06.06.16.37.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Jun 2017 16:37:44 -0700 (PDT) From: Kevin Hilman To: Hans Verkuil , Laurent Pinchart , linux-media@vger.kernel.org Subject: [PATCH v2 2/4] [media] davinci: vpif_capture: get subdevs from DT when available Date: Tue, 6 Jun 2017 16:37:39 -0700 Message-Id: <20170606233741.26718-3-khilman@baylibre.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170606233741.26718-1-khilman@baylibre.com> References: <20170606233741.26718-1-khilman@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170606_163805_746281_67888BA7 X-CRM114-Status: GOOD ( 20.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Lechner , Sekhar Nori , Benoit Parrot , Prabhakar Lad , Patrick Titiano , 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 Enable 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 --- drivers/media/platform/davinci/vpif_capture.c | 126 +++++++++++++++++++++++++- drivers/media/platform/davinci/vpif_display.c | 5 + include/media/davinci/vpif_types.h | 9 +- 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c index fc5c7622660c..b9d927d1e5a8 100644 --- a/drivers/media/platform/davinci/vpif_capture.c +++ b/drivers/media/platform/davinci/vpif_capture.c @@ -22,6 +22,8 @@ #include #include +#include +#include #include "vpif.h" #include "vpif_capture.h" @@ -655,7 +657,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; @@ -1308,6 +1310,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)) { @@ -1403,6 +1420,105 @@ 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; + + /* + * DT boot: OF node from parent device contains + * video ports & endpoints data. + */ + if (pdev->dev.parent && pdev->dev.parent->of_node) + pdev->dev.of_node = pdev->dev.parent->of_node; + 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_NUM_CHANNELS, GFP_KERNEL); + + if (!pdata->subdev_info) + return NULL; + + for (i = 0; i < VPIF_CAPTURE_NUM_CHANNELS; 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_CAPTURE_NUM_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; + + 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; + + 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 @@ -1419,6 +1535,12 @@ 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; + } + if (!pdev->dev.platform_data) { dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); return -EINVAL; @@ -1459,7 +1581,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]) { int i2c_id = vpif_obj.config->i2c_adapter_id; i2c_adap = i2c_get_adapter(i2c_id); diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c index 7e5cf9923c8d..b5ac6ce626b3 100644 --- a/drivers/media/platform/davinci/vpif_display.c +++ b/drivers/media/platform/davinci/vpif_display.c @@ -1250,6 +1250,11 @@ static __init int vpif_probe(struct platform_device *pdev) return -EINVAL; } + if (!pdev->dev.platform_data) { + dev_warn(&pdev->dev, "Missing platform data. Giving up.\n"); + return -EINVAL; + } + vpif_dev = &pdev->dev; err = initialize_vpif(); diff --git a/include/media/davinci/vpif_types.h b/include/media/davinci/vpif_types.h index 385597da20dc..eae23e4e9b93 100644 --- a/include/media/davinci/vpif_types.h +++ b/include/media/davinci/vpif_types.h @@ -62,14 +62,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; }; @@ -81,7 +81,8 @@ struct vpif_capture_config { int subdev_count; int i2c_adapter_id; 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 */