[PATCH SQUASH v7 08/18] media: rppx1: exm: Expose coefficients, RGB mode and channel selection
From: Jai Luthra
Date: Fri Apr 10 2026 - 05:22:40 EST
Compared to RkISP, Dreamchip's RPP-X1's exposure measurement module
supports following extra features:
1. Measurement modes (bayer or RGB domain)
2. Programmable coefficients for RGB or Bayer channels
3. Choice for sampling point (channel selector) in the pipeline
Expose these features in the uAPI and support them in the driver.
Note: This commit's changes will be squashed into the relevant uAPI and
driver commits. It is separate for now to ease review and highlight the
differences.
Signed-off-by: Jai Luthra <jai.luthra+renesas@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/dreamchip/rppx1/rppx1_exm.c | 47 ++++++++----------
include/uapi/linux/media/dreamchip/rppx1-config.h | 57 ++++++++++++++++++++--
2 files changed, 73 insertions(+), 31 deletions(-)
diff --git a/drivers/media/platform/dreamchip/rppx1/rppx1_exm.c b/drivers/media/platform/dreamchip/rppx1/rppx1_exm.c
index f756f7f882a124850a0908d9efa564443de01b2a..839aa8a18b895c71305c44c317b7125882af3c97 100644
--- a/drivers/media/platform/dreamchip/rppx1/rppx1_exm.c
+++ b/drivers/media/platform/dreamchip/rppx1/rppx1_exm.c
@@ -14,7 +14,10 @@
#define EXM_CTRL_EXM_UPDATE_ENABLE BIT(0)
#define EXM_MODE_REG 0x000c
+
#define EXM_CHANNEL_SEL_REG 0x0010
+#define EXM_CHANNEL_SEL_CHANNEL_SELECT_MASK GENMASK(2, 0)
+
#define EXM_LAST_MEAS_LINE_REG 0x0014
#define EXM_COEFF_R_REG 0x0018
#define EXM_COEFF_G_GR_REG 0x001c
@@ -61,37 +64,27 @@ rppx1_exm_fill_params(struct rpp_module *mod,
return 0;
}
- /* RGB bayer exposure measurement */
- write(priv, mod->base + EXM_MODE_REG, 2);
+ switch (cfg->mode) {
+ case RPPX1_EXP_MEASURING_MODE_RGB:
+ case RPPX1_EXP_MEASURING_MODE_BAYER:
+ write(priv, mod->base + EXM_MODE_REG, cfg->mode);
+ break;
+ default:
+ write(priv, mod->base + EXM_MODE_REG, 0);
+ return 0;
+ }
+
+ write(priv, mod->base + EXM_COEFF_R_REG, cfg->coeff.red);
+ write(priv, mod->base + EXM_COEFF_G_GR_REG, cfg->coeff.green_r);
+ write(priv, mod->base + EXM_COEFF_GB_REG, cfg->coeff.green_b);
+ write(priv, mod->base + EXM_COEFF_B_REG, cfg->coeff.blue);
write(priv, mod->base + EXM_CTRL_REG, EXM_CTRL_EXM_UPDATE_ENABLE |
cfg->autostop ? EXM_CTRL_EXM_AUTOSTOP : 0);
- /*
- * Select where to sample.
- * 0 - after input acquisition
- * 1 - after black level subtraction
- * 2 - after input linearization
- * 3 - after lens shade correction
- * 4 - after white balance gain stage
- * 5 - after defect pixel correction
- * 6 - after denoising
- */
- write(priv, mod->base + EXM_CHANNEL_SEL_REG, 6);
-
- if (cfg->mode == RPPX1_EXP_MEASURING_MODE_0) {
- /* Coefficients for a BT.601 BAYER (from datasheet). */
- write(priv, mod->base + EXM_COEFF_R_REG, 38);
- write(priv, mod->base + EXM_COEFF_G_GR_REG, 75);
- write(priv, mod->base + EXM_COEFF_B_REG, 15);
- write(priv, mod->base + EXM_COEFF_GB_REG, 75);
- } else {
- /* Y = (R + Gr + B + Gb) / 4*/
- write(priv, mod->base + EXM_COEFF_R_REG, 128);
- write(priv, mod->base + EXM_COEFF_G_GR_REG, 128);
- write(priv, mod->base + EXM_COEFF_B_REG, 128);
- write(priv, mod->base + EXM_COEFF_GB_REG, 128);
- }
+ /* Select sample point */
+ write(priv, mod->base + EXM_CHANNEL_SEL_REG,
+ cfg->channel_sel & EXM_CHANNEL_SEL_CHANNEL_SELECT_MASK);
/*
* Adjust and set measurement window to hardware limitations,
diff --git a/include/uapi/linux/media/dreamchip/rppx1-config.h b/include/uapi/linux/media/dreamchip/rppx1-config.h
index b9083e6f32b15329333eb13491b50c0aea8d1a32..2adf5f9e083b89c0308a8728f8468f326ab87c48 100644
--- a/include/uapi/linux/media/dreamchip/rppx1-config.h
+++ b/include/uapi/linux/media/dreamchip/rppx1-config.h
@@ -537,6 +537,36 @@ struct rppx1_params_awb_meas_config {
__u8 enable_ymax_cmp;
};
+/**
+ * enum rppx1_pre_meas_chan - Measurement point for PRE1/2 modules
+ * @RPPX1_PRE_MEASURE_AFTER_ACQ: after input acquisition
+ * @RPPX1_PRE_MEASURE_AFTER_BLS: after black level subtraction
+ * @RPPX1_PRE_MEASURE_AFTER_LIN: after sensor gamma linearization
+ * @RPPX1_PRE_MEASURE_AFTER_LSC: after lens shading correction
+ * @RPPX1_PRE_MEASURE_AFTER_AWBG: after auto white balance gains
+ * @RPPX1_PRE_MEASURE_AFTER_DPCC: after defect pixel correction
+ * @RPPX1_PRE_MEASURE_AFTER_DPF: after denoise pre-filter
+ */
+enum rppx1_pre_meas_chan {
+ RPPX1_PRE_MEASURE_AFTER_ACQ,
+ RPPX1_PRE_MEASURE_AFTER_BLS,
+ RPPX1_PRE_MEASURE_AFTER_LIN,
+ RPPX1_PRE_MEASURE_AFTER_LSC,
+ RPPX1_PRE_MEASURE_AFTER_AWBG,
+ RPPX1_PRE_MEASURE_AFTER_DPCC,
+ RPPX1_PRE_MEASURE_AFTER_DPF,
+};
+
+/**
+ * enum rppx1_post_meas_chan - Measurement point for POST modules
+ * @RPPX1_PRE_MEASURE_AFTER_AWBG: after auto white balance gains
+ * @RPPX1_PRE_MEASURE_AFTER_DEMOSAIC: after demosaicing
+ */
+enum rppx1_post_meas_chan {
+ RPPX1_POST_MEASURE_AFTER_AWBG = 4,
+ RPPX1_POST_MEASURE_AFTER_DEMOSAIC = 7,
+};
+
/**
* enum rppx1_histogram_mode - Histogram measurement mode
* @RPPX1_HISTOGRAM_MODE_DISABLE: histogram disabled
@@ -574,14 +604,29 @@ struct rppx1_params_hst_config {
__u8 hist_weight[RPPX1_HISTOGRAM_WEIGHT_GRIDS_SIZE];
};
+/**
+ * struct rppx1_aec_coeff - Coefficients for exposure measurement
+ *
+ * @red: Coefficient for weighting Red sample/channel (Q1.7)
+ * @green_r: Coefficient for weighting GreenRed bayer sample or Green channel (Q1.7)
+ * @green_b: Coefficient for weighting GreenBlue bayer sample (Q1.7)
+ * @blue: Coefficient for weighting Blue sample/channel (Q1.7)
+ */
+struct rppx1_aec_coeff {
+ __u8 red;
+ __u8 green_r;
+ __u8 green_b;
+ __u8 blue;
+};
+
/**
* enum rppx1_exp_meas_mode - Exposure measurement mode
- * @RPPX1_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B
- * @RPPX1_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256)
+ * @RPPX1_EXP_MEASURING_MODE_RGB: out_sample = coeff_r * R + coeff_gr * G + coeff_b * B
+ * @RPPX1_EXP_MEASURING_MODE_BAYER: out_sample = coeff_[r|gr|gb|b] * [R|Gr|Gb|B]
*/
enum rppx1_exp_meas_mode {
- RPPX1_EXP_MEASURING_MODE_0,
- RPPX1_EXP_MEASURING_MODE_1,
+ RPPX1_EXP_MEASURING_MODE_RGB = 1,
+ RPPX1_EXP_MEASURING_MODE_BAYER,
};
/**
@@ -591,12 +636,16 @@ enum rppx1_exp_meas_mode {
* @mode: exposure measure mode (from enum rppx1_exp_meas_mode)
* @autostop: 0 = continuous, 1 = stop after one frame
* @meas_window: measurement window coordinates
+ * @coeff: weighting coefficients for R/Gr/Gb/B
+ * @channel_sel: measurement point (see enum rppx1_[pre|post]_meas_chan)
*/
struct rppx1_params_aec_config {
struct v4l2_isp_params_block_header header;
__u32 mode;
__u32 autostop;
struct rppx1_window meas_window;
+ struct rppx1_aec_coeff coeff;
+ __u8 channel_sel;
};
/**
--
2.53.0