From patchwork Sat Nov 12 13:12:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9424153 X-Patchwork-Delegate: geert@linux-m68k.org 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 AB2E260720 for ; Sat, 12 Nov 2016 13:14:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A033A296DC for ; Sat, 12 Nov 2016 13:14:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9523E296F1; Sat, 12 Nov 2016 13:14:11 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A2DF296E2 for ; Sat, 12 Nov 2016 13:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965881AbcKLNOK (ORCPT ); Sat, 12 Nov 2016 08:14:10 -0500 Received: from smtp-4.sys.kth.se ([130.237.48.193]:33626 "EHLO smtp-4.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966102AbcKLNNy (ORCPT ); Sat, 12 Nov 2016 08:13:54 -0500 Received: from smtp-4.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-4.sys.kth.se (Postfix) with ESMTP id 2C1073065; Sat, 12 Nov 2016 14:13:51 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-4.sys.kth.se ([127.0.0.1]) by smtp-4.sys.kth.se (smtp-4.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gVbShJ4jC5dc; Sat, 12 Nov 2016 14:13:50 +0100 (CET) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by smtp-4.sys.kth.se (Postfix) with ESMTPSA id 0C81A32AE; Sat, 12 Nov 2016 14:13:49 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Laurent Pinchart , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, tomoharu.fukawa.eb@renesas.com, Sakari Ailus , Geert Uytterhoeven , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCHv2 25/32] media: rcar-vin: enable CSI2 group subdevices in lookup helpers Date: Sat, 12 Nov 2016 14:12:09 +0100 Message-Id: <20161112131216.22635-26-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161112131216.22635-1-niklas.soderlund+renesas@ragnatech.se> References: <20161112131216.22635-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the subdevice helpers look not only at the local digital subdevice but also for the CSI2 group subdevices which can be present on Gen3. Which CSI2 group subdevices are found depends on the CSI2 subgroup routing which is stored in the CHSEL register of the subgroup master (VIN0 for VIN0-3 and VIN4 for VIN4-7). The lookup functions look at this value and returns the correct information or NULL if there is no attached subdevices for the current routing for this device. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-core.c | 70 ++++++++++++++++++++++++++++- drivers/media/platform/rcar-vin/rcar-vin.h | 2 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 0092ab4..0b3882a 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -330,9 +330,77 @@ static void rvin_group_delete(struct rvin_dev *vin) * Subdevice helpers */ +static int rvin_group_vin_to_csi(struct rvin_dev *vin) +{ + int i, vin_num, vin_master, chsel, csi; + + /* Only valid on Gen3 */ + if (vin->info->chip != RCAR_GEN3) + return -1; + + /* + * Only try to translate to a CSI2 number if there is a enabled + * link from the VIN sink pad. However if there are no links at + * all we are at probe time so ignore the need for enabled links + * to be able to make a better guess of initial format + */ + if (vin->pads[RVIN_SINK].entity->num_links && + !media_entity_remote_pad(&vin->pads[RVIN_SINK])) + return -1; + + /* Find which VIN we are */ + vin_num = -1; + for (i = 0; i < RCAR_VIN_NUM; i++) + if (vin == vin->group->vin[i]) + vin_num = i; + + if (vin_num == -1) + return -1; + + vin_master = vin_num < 4 ? 0 : 4; + if (!vin->group->vin[vin_master]) + return -1; + + chsel = rvin_get_chsel(vin->group->vin[vin_master]); + + csi = vin->info->chsels[vin_num][chsel].csi; + if (csi >= RVIN_CSI_MAX) + return -1; + + if (!vin->group->source[csi].subdev || !vin->group->bridge[csi].subdev) + return -1; + + return csi; +} + struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin) { - return &vin->digital; + int csi; + + /* If there is a digital subdev use it */ + if (vin->digital.subdev) + return &vin->digital; + + csi = rvin_group_vin_to_csi(vin); + if (csi < 0) + return NULL; + + return &vin->group->source[csi]; +} + +struct v4l2_subdev *vin_to_source(struct rvin_dev *vin) +{ + int csi; + + /* If there is a digital subdev use it */ + if (vin->digital.subdev) + return vin->digital.subdev; + + csi = rvin_group_vin_to_csi(vin); + if (csi < 0) + return NULL; + + return vin->group->source[csi].subdev; } /* ----------------------------------------------------------------------------- diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index cd7d959..2f1e087 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -207,7 +207,7 @@ struct rvin_dev { }; struct rvin_graph_entity *vin_to_entity(struct rvin_dev *vin); -#define vin_to_source(vin) vin->digital.subdev +struct v4l2_subdev *vin_to_source(struct rvin_dev *vin); /* Debug */ #define vin_dbg(d, fmt, arg...) dev_dbg(d->dev, fmt, ##arg)