From patchwork Fri Sep 14 02:13:43 2018 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: 10600249 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-2.web.codeaurora.org (Postfix) with ESMTP id A53B0933 for ; Fri, 14 Sep 2018 02:14:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2AE62B6AF for ; Fri, 14 Sep 2018 02:14:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C74D32B6B3; Fri, 14 Sep 2018 02:14:29 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 D78242B6AF for ; Fri, 14 Sep 2018 02:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728239AbeINH0g (ORCPT ); Fri, 14 Sep 2018 03:26:36 -0400 Received: from vsp-unauthed02.binero.net ([195.74.38.227]:41012 "EHLO vsp-unauthed02.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeINH0g (ORCPT ); Fri, 14 Sep 2018 03:26:36 -0400 X-Halon-ID: e66fba2e-b7c3-11e8-b628-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id e66fba2e-b7c3-11e8-b628-0050569116f7; Fri, 14 Sep 2018 04:14:24 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 1/3] rcar-vin: align format width with hardware limits Date: Fri, 14 Sep 2018 04:13:43 +0200 Message-Id: <20180914021345.9277-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180914021345.9277-1-niklas.soderlund+renesas@ragnatech.se> References: <20180914021345.9277-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 The Gen3 datasheets lists specific alignment restrictions compared to Gen2. This was overlooked when adding Gen3 support as no problematic configuration was encountered. However when adding support for Gen3 Up Down Scaler (UDS) strange issues could be observed for odd widths without taking this limit into consideration. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-v4l2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index dc77682b47857c97..2fc2a05eaeacb134 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -673,6 +673,21 @@ static void rvin_mc_try_format(struct rvin_dev *vin, pix->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, pix->colorspace, pix->ycbcr_enc); + switch (vin->format.pixelformat) { + case V4L2_PIX_FMT_NV16: + pix->width = ALIGN(pix->width, 0x80); + break; + case V4L2_PIX_FMT_YUYV: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_RGB565: + case V4L2_PIX_FMT_XRGB555: + pix->width = ALIGN(pix->width, 0x40); + break; + default: + pix->width = ALIGN(pix->width, 0x20); + break; + } + rvin_format_align(vin, pix); } From patchwork Fri Sep 14 02:13:44 2018 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: 10600253 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-2.web.codeaurora.org (Postfix) with ESMTP id 30BCB17D5 for ; Fri, 14 Sep 2018 02:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E7282B6AE for ; Fri, 14 Sep 2018 02:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 531502B6B7; Fri, 14 Sep 2018 02:14:36 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 449972B6AF for ; Fri, 14 Sep 2018 02:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728267AbeINH0h (ORCPT ); Fri, 14 Sep 2018 03:26:37 -0400 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:40975 "EHLO bin-mail-out-05.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728225AbeINH0h (ORCPT ); Fri, 14 Sep 2018 03:26:37 -0400 X-Halon-ID: e6cb6323-b7c3-11e8-b628-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id e6cb6323-b7c3-11e8-b628-0050569116f7; Fri, 14 Sep 2018 04:14:25 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 2/3] rcar-vin: add support for UDS (Up Down Scaler) Date: Fri, 14 Sep 2018 04:13:44 +0200 Message-Id: <20180914021345.9277-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180914021345.9277-1-niklas.soderlund+renesas@ragnatech.se> References: <20180914021345.9277-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 Some VIN instances have access to a Up Down Scaler (UDS). The UDS are on most SoCs shared between two VINs, the UDS can of course only be used by one VIN at a time. Add support to configure the UDS registers which are mapped to both VINs sharing the UDS address-space. While validations the format at stream start make sure the companion VIN is not already using the scaler. If the scaler already is in use return -EBUSY. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-dma.c | 134 ++++++++++++++++++++- drivers/media/platform/rcar-vin/rcar-vin.h | 24 ++++ 2 files changed, 152 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index 92323310f7352147..673034f0f735dbb0 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -74,6 +74,10 @@ /* Register offsets specific for Gen3 */ #define VNCSI_IFMD_REG 0x20 /* Video n CSI2 Interface Mode Register */ +#define VNUDS_CTRL_REG 0x80 /* Video n scaling control register */ +#define VNUDS_SCALE_REG 0x84 /* Video n scaling factor register */ +#define VNUDS_PASS_BWIDTH_REG 0x90 /* Video n passband register */ +#define VNUDS_CLIP_SIZE_REG 0xa4 /* Video n UDS output size clipping reg */ /* Register bit fields for R-Car VIN */ /* Video n Main Control Register bits */ @@ -129,6 +133,9 @@ #define VNCSI_IFMD_CSI_CHSEL(n) (((n) & 0xf) << 0) #define VNCSI_IFMD_CSI_CHSEL_MASK 0xf +/* Video n scaling control register (Gen3) */ +#define VNUDS_CTRL_AMD (1 << 30) + struct rvin_buffer { struct vb2_v4l2_buffer vb; struct list_head list; @@ -572,6 +579,78 @@ static void rvin_crop_scale_comp_gen2(struct rvin_dev *vin) 0, 0); } +static unsigned int rvin_scale_ratio(unsigned int in, unsigned int out) +{ + unsigned int ratio; + + ratio = in * 4096 / out; + return ratio >= 0x10000 ? 0xffff : ratio; +} + +static unsigned int rvin_ratio_to_bwidth(unsigned int ratio) +{ + unsigned int mant, frac; + + mant = (ratio & 0xF000) >> 12; + frac = ratio & 0x0FFF; + if (mant) + return 64 * 4096 * mant / (4096 * mant + frac); + + return 64; +} + +static bool rvin_gen3_need_scaling(struct rvin_dev *vin) +{ + if (vin->info->model != RCAR_GEN3) + return false; + + return vin->crop.width != vin->format.width || + vin->crop.height != vin->format.height; +} + +static void rvin_crop_scale_comp_gen3(struct rvin_dev *vin) +{ + unsigned int ratio_h, ratio_v; + unsigned int bwidth_h, bwidth_v; + u32 vnmc, clip_size; + + if (!rvin_gen3_need_scaling(vin)) + return; + + ratio_h = rvin_scale_ratio(vin->crop.width, vin->format.width); + bwidth_h = rvin_ratio_to_bwidth(ratio_h); + + ratio_v = rvin_scale_ratio(vin->crop.height, vin->format.height); + bwidth_v = rvin_ratio_to_bwidth(ratio_v); + + clip_size = vin->format.width << 16; + + switch (vin->format.field) { + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_SEQ_TB: + case V4L2_FIELD_SEQ_BT: + clip_size |= vin->format.height / 2; + break; + default: + clip_size |= vin->format.height; + break; + } + + vnmc = rvin_read(vin, VNMC_REG); + rvin_write(vin, (vnmc & ~VNMC_VUP) | VNMC_SCLE, VNMC_REG); + rvin_write(vin, VNUDS_CTRL_AMD, VNUDS_CTRL_REG); + rvin_write(vin, (ratio_h << 16) | ratio_v, VNUDS_SCALE_REG); + rvin_write(vin, (bwidth_h << 16) | bwidth_v, VNUDS_PASS_BWIDTH_REG); + rvin_write(vin, clip_size, VNUDS_CLIP_SIZE_REG); + rvin_write(vin, vnmc, VNMC_REG); + + vin_dbg(vin, "Pre-Clip: %ux%u@%u:%u Post-Clip: %ux%u@%u:%u\n", + vin->crop.width, vin->crop.height, vin->crop.left, + vin->crop.top, vin->format.width, vin->format.height, 0, 0); +} + void rvin_crop_scale_comp(struct rvin_dev *vin) { /* Set Start/End Pixel/Line Pre-Clip */ @@ -593,8 +672,9 @@ void rvin_crop_scale_comp(struct rvin_dev *vin) break; } - /* TODO: Add support for the UDS scaler. */ - if (vin->info->model != RCAR_GEN3) + if (vin->info->model == RCAR_GEN3) + rvin_crop_scale_comp_gen3(vin); + else rvin_crop_scale_comp_gen2(vin); if (vin->format.pixelformat == V4L2_PIX_FMT_NV16) @@ -751,6 +831,9 @@ static int rvin_setup(struct rvin_dev *vin) vnmc |= VNMC_DPINE; } + if (rvin_gen3_need_scaling(vin)) + vnmc |= VNMC_SCLE; + /* Progressive or interlaced mode */ interrupts = progressive ? VNIE_FIE : VNIE_EFE; @@ -1081,10 +1164,42 @@ static int rvin_mc_validate_format(struct rvin_dev *vin, struct v4l2_subdev *sd, return -EPIPE; } - if (fmt.format.width != vin->format.width || - fmt.format.height != vin->format.height || - fmt.format.code != vin->mbus_code) - return -EPIPE; + vin->crop.width = fmt.format.width; + vin->crop.height = fmt.format.height; + + if (rvin_gen3_need_scaling(vin)) { + const struct rvin_group_scaler *scaler; + struct rvin_dev *companion; + + if (fmt.format.code != vin->mbus_code) + return -EPIPE; + + if (!vin->info->scalers) + return -EPIPE; + + for (scaler = vin->info->scalers; + scaler->vin || scaler->companion; scaler++) + if (scaler->vin == vin->id) + break; + + /* No scaler found for VIN. */ + if (!scaler->vin && !scaler->companion) + return -EPIPE; + + /* Make sure companion not using scaler. */ + if (scaler->companion != -1) { + companion = vin->group->vin[scaler->companion]; + if (companion && + companion->state != STOPPED && + rvin_gen3_need_scaling(companion)) + return -EBUSY; + } + } else { + if (fmt.format.width != vin->format.width || + fmt.format.height != vin->format.height || + fmt.format.code != vin->mbus_code) + return -EPIPE; + } return 0; } @@ -1192,6 +1307,7 @@ static void rvin_stop_streaming(struct vb2_queue *vq) struct rvin_dev *vin = vb2_get_drv_priv(vq); unsigned long flags; int retries = 0; + u32 vnmc; spin_lock_irqsave(&vin->qlock, flags); @@ -1223,6 +1339,12 @@ static void rvin_stop_streaming(struct vb2_queue *vq) vin->state = STOPPED; } + /* Clear UDS usage after we have stopped */ + if (vin->info->model == RCAR_GEN3) { + vnmc = rvin_read(vin, VNMC_REG) & ~(VNMC_SCLE | VNMC_VUP); + rvin_write(vin, vnmc, VNMC_REG); + } + /* Release all active buffers */ return_all_buffers(vin, VB2_BUF_STATE_ERROR); diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index 0b13b34d03e3dce4..5a617a30ba8c9a5a 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -122,6 +122,28 @@ struct rvin_group_route { unsigned int mask; }; +/** + * struct rvin_group_scaler - describes a scaler attached to a VIN + * + * @vin: Numerical VIN id that have access to a UDS. + * @companion: Numerical VIN id that @vin share the UDS with. + * + * -- note:: + * Some R-Car VIN instances have access to a Up Down Scaler (UDS). + * If a VIN have a UDS attached it's almost always shared between + * two VIN instances. The UDS can only be used by one VIN at a time, + * so the companion relationship needs to be described as well. + * + * There are at most two VINs sharing a UDS. For each UDS shared + * between two VINs there needs to be two instances of struct + * rvin_group_scaler describing each of the VINs individually. If + * a VIN do not share its UDS set companion to -1. + */ +struct rvin_group_scaler { + int vin; + int companion; +}; + /** * struct rvin_info - Information about the particular VIN implementation * @model: VIN model @@ -130,6 +152,7 @@ struct rvin_group_route { * @max_height: max input height the VIN supports * @routes: list of possible routes from the CSI-2 recivers to * all VINs. The list mush be NULL terminated. + * @scalers: List of available scalers, must be NULL terminated. */ struct rvin_info { enum model_id model; @@ -138,6 +161,7 @@ struct rvin_info { unsigned int max_width; unsigned int max_height; const struct rvin_group_route *routes; + const struct rvin_group_scaler *scalers; }; /** From patchwork Fri Sep 14 02:13:45 2018 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: 10600257 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-2.web.codeaurora.org (Postfix) with ESMTP id 70A4A933 for ; Fri, 14 Sep 2018 02:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E9372B6AF for ; Fri, 14 Sep 2018 02:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 930192B6B3; Fri, 14 Sep 2018 02:14:36 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8FEC62B6B1 for ; Fri, 14 Sep 2018 02:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728288AbeINH0i (ORCPT ); Fri, 14 Sep 2018 03:26:38 -0400 Received: from bin-mail-out-06.binero.net ([195.74.38.229]:32142 "EHLO bin-mail-out-06.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728250AbeINH0h (ORCPT ); Fri, 14 Sep 2018 03:26:37 -0400 X-Halon-ID: e769a367-b7c3-11e8-b628-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id e769a367-b7c3-11e8-b628-0050569116f7; Fri, 14 Sep 2018 04:14:26 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 3/3] rcar-vin: declare which VINs can use a Up Down Scaler (UDS) Date: Fri, 14 Sep 2018 04:13:45 +0200 Message-Id: <20180914021345.9277-4-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180914021345.9277-1-niklas.soderlund+renesas@ragnatech.se> References: <20180914021345.9277-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 Add information about which VINs on which SoC have access to a UDS scaler. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 5dd16af3625c333b..64f74dfebbedbf78 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -920,12 +920,21 @@ static const struct rvin_group_route rcar_info_r8a7795_routes[] = { { /* Sentinel */ } }; +static const struct rvin_group_scaler rcar_info_h3_m3w_m3n_scalers[] = { + { .vin = 0, .companion = 1 }, + { .vin = 1, .companion = 0 }, + { .vin = 4, .companion = 5 }, + { .vin = 5, .companion = 4 }, + { /* Sentinel */ } +}; + static const struct rvin_info rcar_info_r8a7795 = { .model = RCAR_GEN3, .use_mc = true, .max_width = 4096, .max_height = 4096, .routes = rcar_info_r8a7795_routes, + .scalers = rcar_info_h3_m3w_m3n_scalers, }; static const struct rvin_group_route rcar_info_r8a7795es1_routes[] = { @@ -980,6 +989,7 @@ static const struct rvin_info rcar_info_r8a7795es1 = { .max_width = 4096, .max_height = 4096, .routes = rcar_info_r8a7795es1_routes, + .scalers = rcar_info_h3_m3w_m3n_scalers, }; static const struct rvin_group_route rcar_info_r8a7796_routes[] = { @@ -1020,6 +1030,7 @@ static const struct rvin_info rcar_info_r8a7796 = { .max_width = 4096, .max_height = 4096, .routes = rcar_info_r8a7796_routes, + .scalers = rcar_info_h3_m3w_m3n_scalers, }; static const struct rvin_group_route rcar_info_r8a77965_routes[] = { @@ -1064,6 +1075,7 @@ static const struct rvin_info rcar_info_r8a77965 = { .max_width = 4096, .max_height = 4096, .routes = rcar_info_r8a77965_routes, + .scalers = rcar_info_h3_m3w_m3n_scalers, }; static const struct rvin_group_route rcar_info_r8a77970_routes[] = { @@ -1089,12 +1101,18 @@ static const struct rvin_group_route rcar_info_r8a77995_routes[] = { { /* Sentinel */ } }; +static const struct rvin_group_scaler rcar_info_r8a77995_scalers[] = { + { .vin = 4, .companion = -1 }, + { /* Sentinel */ } +}; + static const struct rvin_info rcar_info_r8a77995 = { .model = RCAR_GEN3, .use_mc = true, .max_width = 4096, .max_height = 4096, .routes = rcar_info_r8a77995_routes, + .scalers = rcar_info_r8a77995_scalers, }; static const struct of_device_id rvin_of_id_table[] = {