History

media: rppx1: bls: Add support for black level compensation

Extend the RPPX1 driver to allow setting the black level measurement and gain configuration. 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.

Niklas Söderlund committed 3 months ago

Commit 3f8a2a81 parent 9a52f7d4 files · +209 −1Browse files

Unified · Split

4 files
  1. drivers/media/platform/dreamchip/rppx1/rpp_module.h +1 −0
  2. drivers/media/platform/dreamchip/rppx1/rpp_params.c +5 −0
  3. drivers/media/platform/dreamchip/rppx1/rppx1_bls.c +97 −0
  4. include/uapi/linux/media/dreamchip/rppx1-config.h +106 −1
drivers/media/platform/dreamchip/rppx1/rpp_module.h+1−0
@@ -47,6 +47,7 @@ void rpp_module_clrset(struct rpp_module *mod, u32 offset, u32 mask, u32 value); · 46 unmodified lines
47 47
48union rppx1_params_block {48union rppx1_params_block {
49 struct v4l2_isp_block_header header;49 struct v4l2_isp_block_header header;
50 struct rppx1_bls_params bls;
50 struct rppx1_awbg_params awbg;51 struct rppx1_awbg_params awbg;
51 struct rppx1_hist_params hist;52 struct rppx1_hist_params hist;
52 struct rppx1_exm_params exm;53 struct rppx1_exm_params exm;
drivers/media/platform/dreamchip/rppx1/rpp_params.c+5−0
@@ -17,6 +17,8 @@ · 16 unmodified lines
17 17
18static const struct v4l2_isp_params_block_type_info18static const struct v4l2_isp_params_block_type_info
19rppx1_ext_params_blocks_info[] = {19rppx1_ext_params_blocks_info[] = {
20 RPPX1_PARAMS_BLOCK_INFO(BLS_PRE1, bls),
21 RPPX1_PARAMS_BLOCK_INFO(BLS_PRE2, bls),
20 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE1, awbg),22 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE1, awbg),
21 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE2, awbg),23 RPPX1_PARAMS_BLOCK_INFO(AWBG_PRE2, awbg),
22 RPPX1_PARAMS_BLOCK_INFO(HIST_PRE1, hist),24 RPPX1_PARAMS_BLOCK_INFO(HIST_PRE1, hist),
@@ -58,6 +60,9 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size, · 35 unmodified lines
58 block_offset += block->header.size;60 block_offset += block->header.size;
59 61
60 switch (block->header.type) {62 switch (block->header.type) {
63 case RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1:
64 module = &rpp->pre1.bls;
65 break;
61 case RPPX1_PARAMS_BLOCK_TYPE_AWBG_PRE1:66 case RPPX1_PARAMS_BLOCK_TYPE_AWBG_PRE1:
62 module = &rpp->pre1.awbg;67 module = &rpp->pre1.awbg;
63 break;68 break;
drivers/media/platform/dreamchip/rppx1/rppx1_bls.c+97−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6 */6 */
7 7
8#include "rpp_module.h"8#include "rpp_module.h"
9#include "rppx1.h"
9 10
10#define BLS_VERSION_REG 0x000011#define BLS_VERSION_REG 0x0000
11 12
@@ -32,6 +33,8 @@ · 20 unmodified lines
32#define BLS_B_MEASURED_REG 0x004033#define BLS_B_MEASURED_REG 0x0040
33#define BLS_C_MEASURED_REG 0x004434#define BLS_C_MEASURED_REG 0x0044
34#define BLS_D_MEASURED_REG 0x004835#define BLS_D_MEASURED_REG 0x0048
36#define BLS_PRE1_FIXED_MASK GENMASK(24, 0)
37#define BLS_PRE2_FIXED_MASK GENMASK(12, 0)
35 38
36static int rppx1_bls_probe(struct rpp_module *mod)39static int rppx1_bls_probe(struct rpp_module *mod)
37{40{
@@ -55,6 +58,100 @@ static int rppx1_bls_probe(struct rpp_module *mod) · 17 unmodified lines
55 return 0;58 return 0;
56}59}
57 60
61static void
62rppx1_bls_swap_regs(struct rpp_module *mod, const u32 input[4], u32 output[4])
63{
64 static const unsigned int swap[4][4] = {
65 [RPP_RGGB] = { 0, 1, 2, 3 },
66 [RPP_GRBG] = { 1, 0, 3, 2 },
67 [RPP_GBRG] = { 2, 3, 0, 1 },
68 [RPP_BGGR] = { 3, 2, 1, 0 },
69 };
70
71 /* Swap to pattern used in our path, PRE1 or PRE2. */
72 struct rpp_module *acq = mod == &mod->rpp->pre1.bls ?
73 &mod->rpp->pre1.acq : &mod->rpp->pre2.bls;
74 enum rpp_raw_pattern pattern = acq->info.acq.raw_pattern;
75
76 for (unsigned int i = 0; i < 4; ++i)
77 output[i] = input[swap[pattern][i]];
78}
79
80static int
81rppx1_bls_fill_params(struct rpp_module *mod,
82 const union rppx1_params_block *block,
83 rppx1_reg_write write, void *priv)
84{
85 const struct rppx1_bls_params *cfg = &block->bls;
86
87 /* If the modules is disabled, simply bypass it. */
88 if (cfg->header.flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) {
89 write(priv, mod->base + BLS_CTRL_REG, 0);
90 return 0;
91 }
92
93 u32 ctrl = BLS_CTRL_BLS_EN;
94
95 if (cfg->mode == RPPX1_BLS_MODE_FIXED) {
96 static const u32 regs[] = {
97 BLS_A_FIXED_REG,
98 BLS_B_FIXED_REG,
99 BLS_C_FIXED_REG,
100 BLS_D_FIXED_REG,
101 };
102 u32 swapped[4];
103
104 rppx1_bls_swap_regs(mod, regs, swapped);
105
106 /*
107 * The PRE1 pipe fixed values are 24-bits + 1 sign bit, while
108 * the PRE2 pipe values are 12-bits + 1 sign bit.
109 */
110 u32 mask;
111
112 switch (cfg->header.type) {
113 case RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1:
114 mask = BLS_PRE1_FIXED_MASK;
115 break;
116 case RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE2:
117 mask = BLS_PRE2_FIXED_MASK;
118 break;
119 default:
120 return -EINVAL;
121 }
122
123 write(priv, mod->base + swapped[0], cfg->fixed.a & mask);
124 write(priv, mod->base + swapped[1], cfg->fixed.b & mask);
125 write(priv, mod->base + swapped[2], cfg->fixed.c & mask);
126 write(priv, mod->base + swapped[3], cfg->fixed.d & mask);
127 } else {
128 write(priv, mod->base + BLS_SAMPLES_REG, cfg->samples);
129
130 if (cfg->en_windows & RPPX1_BLS_WIN_EN_WIN1) {
131 write(priv, mod->base + BLS_H1_START_REG, cfg->window1.h_offs);
132 write(priv, mod->base + BLS_H1_STOP_REG, cfg->window1.h_size);
133 write(priv, mod->base + BLS_V1_START_REG, cfg->window1.v_offs);
134 write(priv, mod->base + BLS_V1_STOP_REG, cfg->window1.v_size);
135 ctrl |= BLS_CTRL_BLS_WIN1;
136 }
137
138 if (cfg->en_windows & RPPX1_BLS_WIN_EN_WIN2) {
139 write(priv, mod->base + BLS_H2_START_REG, cfg->window2.h_offs);
140 write(priv, mod->base + BLS_H2_STOP_REG, cfg->window2.h_size);
141 write(priv, mod->base + BLS_V2_START_REG, cfg->window2.v_offs);
142 write(priv, mod->base + BLS_V2_STOP_REG, cfg->window2.v_size);
143 ctrl |= BLS_CTRL_BLS_WIN2;
144 }
145
146 ctrl |= BLS_CTRL_BLS_MODE_MEASURED;
147 }
148
149 write(priv, mod->base + BLS_CTRL_REG, ctrl);
150
151 return 0;
152}
153
58const struct rpp_module_ops rppx1_bls_ops = {154const struct rpp_module_ops rppx1_bls_ops = {
59 .probe = rppx1_bls_probe,155 .probe = rppx1_bls_probe,
156 .fill_params = rppx1_bls_fill_params,
60};157};
include/uapi/linux/media/dreamchip/rppx1-config.h+106−1
@@ -85,6 +85,8 @@ enum rppx1_meas_chan { · 84 unmodified lines
85 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE1: PRE1 pipe Histogram Measurement85 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE1: PRE1 pipe Histogram Measurement
86 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE2: PRE2 pipe Histogram Measurement86 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE2: PRE2 pipe Histogram Measurement
87 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_POST: POST pipe Histogram Measurement87 * @RPPX1_PARAMS_BLOCK_TYPE_HIST_POST: POST pipe Histogram Measurement
88 * @RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1: PRE1 pipe Black Level Subtraction
89 * @RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE2: PRE2 pipe Black Level Subtraction
88 */90 */
89enum rppx1_params_block_type {91enum rppx1_params_block_type {
90 RPPX1_PARAMS_BLOCK_TYPE_WBMEAS_POST,92 RPPX1_PARAMS_BLOCK_TYPE_WBMEAS_POST,
@@ -96,6 +98,8 @@ enum rppx1_params_block_type { · 5 unmodified lines
96 RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE1,98 RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE1,
97 RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE2,99 RPPX1_PARAMS_BLOCK_TYPE_HIST_PRE2,
98 RPPX1_PARAMS_BLOCK_TYPE_HIST_POST,100 RPPX1_PARAMS_BLOCK_TYPE_HIST_POST,
101 RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1,
102 RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE2,
99};103};
100 104
101/**105/**
@@ -330,6 +334,105 @@ struct rppx1_hist_params { · 228 unmodified lines
330 __u8 reserved;334 __u8 reserved;
331};335};
332 336
337/**
338 * struct rppx1_bls_fixed - BLS fixed subtraction values
339 *
340 * Fixed black level values subtracted from sensor data per Bayer channel.
341 * Negative values result in addition.
342 *
343 * The PRE1 pipe BLS module operates on a 24-bits input data and fixed black
344 * levels are stored as a signed 2's complement representation ranging from
345 * -2^24 to 2^24-1.
346 *
347 * The PRE2 pipe BLS module operates on a 12-bits input data and fixed black
348 * levels are stored as a signed 2's complement representation ranging from
349 * -2^12 to 2^12-1.
350 *
351 * Userspace is expected to provide fixed black level values with a bit-depth
352 * matching the one of pipe in use.
353 *
354 * These subtraction values are matched with the sensor native Bayer components
355 * ordering according to the cropping configuration on the input port.
356 *
357 * @a: subtraction value for channel A
358 * @b: subtraction value for channel B
359 * @c: subtraction value for channel C
360 * @d: subtraction value for channel D
361 */
362struct rppx1_bls_fixed {
363 __u32 a;
364 __u32 b;
365 __u32 c;
366 __u32 d;
367};
368
369/**
370 * enum rppx1_bls_mode - BLS subtraction mode
371 *
372 * Select if subtracted black level come from fixed or measured values.
373 *
374 * @RPPX1_BLS_MODE_FIXED: subtract fixed values
375 * @RPPX1_BLS_MODE_MEAS: subtract measured values
376 */
377enum rppx1_bls_mode {
378 RPPX1_BLS_MODE_FIXED,
379 RPPX1_BLS_MODE_MEAS,
380};
381
382/**
383 * enum rppx1_bls_win_en: BLS measurement configuration
384 *
385 * Select the measurement window to use for measured black level values.
386 *
387 * @RPPX1_BLS_WIN_EN_OFF: disable measurement
388 * @RPPX1_BLS_WIN_EN_WIN1: Enable measurement from window 1
389 * @RPPX1_BLS_WIN_EN_WIN2: enable measurement from window 2
390 * @RPPX1_BLS_WIN_EN_WIN12: enable measurement from window 1 and window 2
391 */
392enum rppx1_bls_win_en {
393 RPPX1_BLS_WIN_EN_OFF,
394 RPPX1_BLS_WIN_EN_WIN1,
395 RPPX1_BLS_WIN_EN_WIN2,
396 RPPX1_BLS_WIN_EN_WIN12,
397};
398
399/**
400 * struct rppx1_bls_params - RPP-X1 Black Level Subtraction Module
401 *
402 * The RPP-X1 Black Level Subtraction module is available on the PRE1 and PRE2
403 * pre-fusion pipes. Userspace selects which pipe to operate by setting the
404 * @header.type field to RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1 or
405 * RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE2.
406 *
407 * The BLS module operates on fixed or measured data according to the setting of
408 * the @mode field. When RPPX1_BLS_MODE_FIXED is used userspace shall provide
409 * the per-channel black levels in @fixed. When RPPX1_BLS_MODE_MEAS is used
410 * userspace shall configure the measurement windows @window1 and optionally
411 * @window2 to select the optically black pixels region in the input frame. The
412 * @samples fields controls how many measure samples are used for averaging the
413 * measured black levels.
414 *
415 * @header: block header (type = RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE1 or
416 * type == RPPX1_PARAMS_BLOCK_TYPE_BLS_PRE2)
417 * @window1: BLS measurement window 1 (14 bits)
418 * @window2: BLS measurement window 2 (14 bits)
419 * @fixed: fixed subtraction values (see enum rppx1_bls_fixed)
420 * @mode: BLS subtraction mode (see enum rppx1_bls_mode)
421 * @en_windows: BLS measurement mode (see rppx1_bls_win_en)
422 * @samples: log2 of the number of measured pixels per Bayer position
423 * @reserved: padding
424 */
425struct rppx1_bls_params {
426 struct v4l2_isp_params_block_header header;
427 struct rppx1_window window1;
428 struct rppx1_window window2;
429 struct rppx1_bls_fixed fixed;
430 __u8 mode;
431 __u8 en_windows;
432 __u8 samples;
433 __u8 reserved[5];
434};
435
333/**436/**
334 * RPPX1_PARAMS_MAX_SIZE - Maximum size of all RPP-X1 parameter blocks437 * RPPX1_PARAMS_MAX_SIZE - Maximum size of all RPP-X1 parameter blocks
335 *438 *
@@ -345,7 +448,9 @@ struct rppx1_hist_params { · 9 unmodified lines
345 sizeof(struct rppx1_exm_params) + \448 sizeof(struct rppx1_exm_params) + \
346 sizeof(struct rppx1_hist_params) + \449 sizeof(struct rppx1_hist_params) + \
347 sizeof(struct rppx1_hist_params) + \450 sizeof(struct rppx1_hist_params) + \
348 sizeof(struct rppx1_hist_params))451 sizeof(struct rppx1_hist_params) + \
452 sizeof(struct rppx1_bls_params) + \
453 sizeof(struct rppx1_bls_params))
349 454
350/* ---------------------------------------------------------------------------455/* ---------------------------------------------------------------------------
351 * Statistics Structures456 * Statistics Structures

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t