From nobody Tue Feb 10 01:23:07 2026 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2CD425A353; Sun, 2 Nov 2025 22:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762124241; cv=none; b=AEgt14C/Hfw0ANALRTJ1XkDnYOSVxBgAs3BblhAM2kaY5nAR6gGeI+90ZIJKvEE8I/0bAUlupuVqb8srpmUeH2PYaKlJimXp5uISGN7DPHZHz0VGNgYCU/CO5SIneM3kiI9WFzqBDESUpOqBbaS4hM2D1OdDZKD2hOhXg13d52c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762124241; c=relaxed/simple; bh=lYXS9/lUH6//2nYfOZQHGlPEvt5Tm6w5TkrDxRCvjHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NWssr5ogyDIl1y49ZIB7OEU7Q7BMJopIZTacbxCMm2szisTcAXD9FQwGieLQWu1UAeqixFJHEVYp2+1jRCmiIg7g4XICyUIpCoBg1Yiicq5BOuONMzNmMS5m7eM8NO4lRmKSa3EomXBqDWBh6B/kitC6fCh/ziUGfcDddsTX/cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=FwTgSHdr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=1BRhjhm+; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="FwTgSHdr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="1BRhjhm+" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 2ED44EC00C2; Sun, 2 Nov 2025 17:57:19 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Sun, 02 Nov 2025 17:57:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1762124239; x=1762210639; bh=eLLX04wS2mhvdK1hmgdmNBjfDXAIqyEsiwM2vHP4UQw=; b= FwTgSHdreZ/NnGWdVzppv0uRFXl4FIVcYp0H59CsW2+stsSdWkAG3RY14i+Uzz/n MrZ2T+lPyEWTBgXuEhJA1tOLArWaJ73Anp+9pKGnsXZG5k60M2Nw3iexpcGeePUX CfSIiHnR5BdER4LvLrjNLtaW7COVOmXJLDXbCjfYJ52SjcNDS/HTP35Icb9tyWiU Fm1JTU7Jp5ibkWBLXERIBjX5JMZMTPrzfvOQ3HBuUq6X7+phS3SrTIqgT2hZeNQe aMTjiOGJzElvKxhYa8TSqXu2zmy9R083ogr4ihAd3uJ4AllSgpDqOnm2zeJ4USkE +z+LJfO8iZYCf44+1KoAwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1762124239; x= 1762210639; bh=eLLX04wS2mhvdK1hmgdmNBjfDXAIqyEsiwM2vHP4UQw=; b=1 BRhjhm+5ZSGrL2a1sLg/vOmD8RK/WfHDjS5h0nMbwX0Hf1qURAx5W7AZEP2Yl84a JOHLXTFarSKD104G2WDqnIKkITUYTZp87cfvsRpbcCg1IJy61RkT1gQwQDsfGZSG +W4dDDBNgj5MMc5NRI05fgCo0+3DPGcE+uHY0+/OydWgf0ctR0C2+L9iie6JMgvK 9Xgs2Pf9bzMSTN5Tmzs05bWK5d7Tjq17/s4ejLJf/hswt8VZQs+3KPRr3LRvuiaf 0v+aE3KGkbNV/T/L/JyNEbaDOD9GaKc5mUpcTpfJGq9dbH1/ph8ATEovLtYoC/A5 tbh3bk5tUtwJ8rkW5VxzQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddujeeiheduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihhklhgr shcuufpnuggvrhhluhhnugcuoehnihhklhgrshdrshhouggvrhhluhhnugdorhgvnhgvsh grshesrhgrghhnrghtvggthhdrshgvqeenucggtffrrghtthgvrhhnpeekheetffdukedt keeijeevieehlefgfeekvdejueelheekfedutedvudetfeefieenucffohhmrghinhepfh higigvuggpvhgrlhdrghhrpdhfihigvggupghvrghlrdhgsgenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehnihhklhgrshdrshhouggvrhhluh hnugesrhgrghhnrghtvggthhdrshgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehmtghhvghhrggssehkvghrnhgvlhdrohhrghdprhgtph htthhopehjrggtohhpohdrmhhonhguihesihguvggrshhonhgsohgrrhgurdgtohhmpdhr tghpthhtoheplhgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghrug drtghomhdprhgtphhtthhopehlihhnuhigqdhmvgguihgrsehvghgvrhdrkhgvrhhnvghl rdhorhhgpdhrtghpthhtoheplhhinhhugidqrhgvnhgvshgrshdqshhotgesvhhgvghrrd hkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehnihhklhgrshdrshhouggvrhhluhhnug dorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgv X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 2 Nov 2025 17:57:18 -0500 (EST) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: Mauro Carvalho Chehab , Jacopo Mondi , Laurent Pinchart , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v3 07/12] media: rppx1: Add support for Black Level Subtraction Date: Sun, 2 Nov 2025 23:56:37 +0100 Message-ID: <20251102225642.3125325-8-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251102225642.3125325-1-niklas.soderlund+renesas@ragnatech.se> References: <20251102225642.3125325-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Extend the RPPX1 driver to allow setting the Black Level Subtraction (BLS) configuration using the RkISP1 parameter buffer format. It uses the RPPX1 framework for parameters and its writer abstraction to allow the user to control how (and when) configuration is applied to the RPPX1. As the RkISP1 parameters buffer have lower precision then the RPPX1 hardware the values needs to be scaled. The behavior matches the RkISP1 hardware. Signed-off-by: Niklas S=C3=B6derlund --- .../platform/dreamchip/rppx1/rpp_params.c | 3 + .../platform/dreamchip/rppx1/rpp_stats.c | 5 +- .../platform/dreamchip/rppx1/rppx1_bls.c | 116 ++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/dreamchip/rppx1/rpp_params.c b/drivers/= media/platform/dreamchip/rppx1/rpp_params.c index 15e476d2fa1c..afc80a480d42 100644 --- a/drivers/media/platform/dreamchip/rppx1/rpp_params.c +++ b/drivers/media/platform/dreamchip/rppx1/rpp_params.c @@ -24,6 +24,9 @@ int rppx1_params_rkisp1(struct rppx1 *rpp, struct rkisp1_= ext_params_cfg *cfg, block_offset +=3D block->header.size; =20 switch (block->header.type) { + case RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: + module =3D &rpp->pre1.bls; + break; case RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: module =3D &rpp->pre1.awbg; break; diff --git a/drivers/media/platform/dreamchip/rppx1/rpp_stats.c b/drivers/m= edia/platform/dreamchip/rppx1/rpp_stats.c index 059bd76ecf64..1bffa6dd35f8 100644 --- a/drivers/media/platform/dreamchip/rppx1/rpp_stats.c +++ b/drivers/media/platform/dreamchip/rppx1/rpp_stats.c @@ -20,8 +20,11 @@ void rppx1_stats_fill_isr(struct rppx1 *rpp, u32 isc, vo= id *buf) if (!rpp_module_call(&rpp->post.hist, stats_rkisp1, &stats->params)) stats->meas_type |=3D RKISP1_CIF_ISP_STAT_HIST; =20 - if (isc & RPPX1_IRQ_ID_PRE1_EXM) + if (isc & RPPX1_IRQ_ID_PRE1_EXM) { if (!rpp_module_call(&rpp->pre1.exm, stats_rkisp1, &stats->params)) stats->meas_type |=3D RKISP1_CIF_ISP_STAT_AUTOEXP; + + rpp_module_call(&rpp->pre1.bls, stats_rkisp1, &stats->params); + } } EXPORT_SYMBOL_GPL(rppx1_stats_fill_isr); diff --git a/drivers/media/platform/dreamchip/rppx1/rppx1_bls.c b/drivers/m= edia/platform/dreamchip/rppx1/rppx1_bls.c index de7008befd8e..164bc4a63c23 100644 --- a/drivers/media/platform/dreamchip/rppx1/rppx1_bls.c +++ b/drivers/media/platform/dreamchip/rppx1/rppx1_bls.c @@ -5,6 +5,7 @@ */ =20 #include "rpp_module.h" +#include "rppx1.h" =20 #define BLS_VERSION_REG 0x0000 =20 @@ -54,6 +55,121 @@ static int rppx1_bls_probe(struct rpp_module *mod) return 0; } =20 +static void +rppx1_bls_swap_regs(struct rpp_module *mod, const u32 input[4], u32 output= [4]) +{ + static const unsigned int swap[4][4] =3D { + [RPP_RGGB] =3D { 0, 1, 2, 3 }, + [RPP_GRBG] =3D { 1, 0, 3, 2 }, + [RPP_GBRG] =3D { 2, 3, 0, 1 }, + [RPP_BGGR] =3D { 3, 2, 1, 0 }, + }; + + /* Swap to pattern used in our path, PRE1 or PRE2. */ + struct rpp_module *acq =3D mod =3D=3D &mod->rpp->pre1.bls ? + &mod->rpp->pre1.acq : &mod->rpp->pre2.bls; + enum rpp_raw_pattern pattern =3D acq->info.acq.raw_pattern; + + for (unsigned int i =3D 0; i < 4; ++i) + output[i] =3D input[swap[pattern][i]]; +} + +static int +rppx1_bls_param_rkisp1(struct rpp_module *mod, + const union rppx1_params_rkisp1_config *block, + rppx1_reg_write write, void *priv) +{ + const struct rkisp1_ext_params_bls_config *cfg =3D &block->bls; + + /* If the modules is disabled, simply bypass it. */ + if (cfg->header.flags & RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE) { + write(priv, mod->base + BLS_CTRL_REG, 0); + return 0; + } + + u32 ctrl =3D BLS_CTRL_BLS_EN; + + if (!cfg->config.enable_auto) { + static const u32 regs[] =3D { + BLS_A_FIXED_REG, + BLS_B_FIXED_REG, + BLS_C_FIXED_REG, + BLS_D_FIXED_REG, + }; + u32 swapped[4]; + + rppx1_bls_swap_regs(mod, regs, swapped); + + /* + * The RkISP params are 12-bit + 1 signed bit, while the RPP can + * be 12, 20 or 24 bit + 1 signed bit. Figure out how much we + * need to adjust the input parameters. + */ + const unsigned int shift =3D mod->info.bls.colorbits - 12; + + write(priv, mod->base + swapped[0], cfg->config.fixed_val.r << shift); + write(priv, mod->base + swapped[1], cfg->config.fixed_val.gr << shift); + write(priv, mod->base + swapped[2], cfg->config.fixed_val.gb << shift); + write(priv, mod->base + swapped[3], cfg->config.fixed_val.b << shift); + } else { + write(priv, mod->base + BLS_SAMPLES_REG, cfg->config.bls_samples); + + if (cfg->config.en_windows & BIT(0)) { + write(priv, mod->base + BLS_H1_START_REG, cfg->config.bls_window1.h_off= s); + write(priv, mod->base + BLS_H1_STOP_REG, cfg->config.bls_window1.h_size= ); + write(priv, mod->base + BLS_V1_START_REG, cfg->config.bls_window1.v_off= s); + write(priv, mod->base + BLS_V1_STOP_REG, cfg->config.bls_window1.v_size= ); + ctrl |=3D BLS_CTRL_BLS_WIN1; + } + + if (cfg->config.en_windows & BIT(1)) { + write(priv, mod->base + BLS_H2_START_REG, cfg->config.bls_window2.h_off= s); + write(priv, mod->base + BLS_H2_STOP_REG, cfg->config.bls_window2.h_size= ); + write(priv, mod->base + BLS_V2_START_REG, cfg->config.bls_window2.v_off= s); + write(priv, mod->base + BLS_V2_STOP_REG, cfg->config.bls_window2.v_size= ); + ctrl |=3D BLS_CTRL_BLS_WIN2; + } + + ctrl |=3D BLS_CTRL_BLS_MODE_MEASURED; + } + + write(priv, mod->base + BLS_CTRL_REG, ctrl); + + return 0; +} + +static int rppx1_bls_stats_rkisp1(struct rpp_module *mod, + struct rkisp1_cif_isp_stat *stats) +{ + struct rkisp1_cif_isp_bls_meas_val *bls =3D &stats->ae.bls_val; + + static const u32 regs[] =3D { + BLS_A_MEASURED_REG, + BLS_B_MEASURED_REG, + BLS_C_MEASURED_REG, + BLS_D_MEASURED_REG, + }; + u32 swapped[4]; + + rppx1_bls_swap_regs(mod, regs, swapped); + + /* + * The RkISP BLS stats are 12-bit while the RPP can be 8, 20 + * or 24 bit. Figure out how much we need to adjust the output + * statistics. + */ + const unsigned int shift =3D mod->info.bls.colorbits - 12; + + bls->meas_r =3D rpp_module_read(mod, swapped[0]) >> shift; + bls->meas_gr =3D rpp_module_read(mod, swapped[1]) >> shift; + bls->meas_gb =3D rpp_module_read(mod, swapped[2]) >> shift; + bls->meas_b =3D rpp_module_read(mod, swapped[3]) >> shift; + + return 0; +} + const struct rpp_module_ops rppx1_bls_ops =3D { .probe =3D rppx1_bls_probe, + .param_rkisp1 =3D rppx1_bls_param_rkisp1, + .stats_rkisp1 =3D rppx1_bls_stats_rkisp1 }; --=20 2.51.1