Skip to content

Commit 2e7ee8b

Browse files
ehristevmchehab
authored andcommitted
media: atmel: atmel-isc: rework component offsets
The component offsets were computed in a negative way: they were subtracted from the actual color component value. So, a higher offset was reducing the component value. This is not really desirable, as the offset is a 2's complements number with 1 bit for sign and 12 value bits, so we would like to be able to also add to the component, not only subtract. The reported number in v4l2 is fine, a range from -4095 to +4095. However when configuring a negative value for the offset, this would in fact not function, because with the old code, the number was subtracted from the max value. By setting something negative, it was overflowing in fact. Reworked the component offsets by placing the real value as the v4l2 ctrls. Now, the values are the real number that is added or subtracted from the component. The negative values received from v4l2 are already in 2's complements, so there is no need for conversion. This actually simplifies a lot the computation procedure, eliminating the need for the macros that convert from v4l2 values to ISC values and viceversa. Also the ZERO_VAL is eliminated, as 0 is now 0, as it's supposed to be. Example after this change: # v4l2-ctl --set-ctrl=red_component_offset=-150 -L User Controls brightness 0x00980900 (int) : min=-1024 max=1023 step=1 default=0 value=0 flags=slider contrast 0x00980901 (int) : min=-2048 max=2047 step=1 default=16 value=20 flags=slider white_balance_automatic 0x0098090c (bool) : default=1 value=0 flags=update do_white_balance 0x0098090d (button) : flags=inactive, write-only, execute-on-write gamma 0x00980910 (int) : min=0 max=3 step=1 default=3 value=3 flags=slider red_component_gain 0x009819c0 (int) : min=0 max=8191 step=1 default=512 value=512 flags=slider blue_component_gain 0x009819c1 (int) : min=0 max=8191 step=1 default=512 value=512 flags=slider green_red_component_gain 0x009819c2 (int) : min=0 max=8191 step=1 default=512 value=512 flags=slider green_blue_component_gain 0x009819c3 (int) : min=0 max=8191 step=1 default=512 value=512 flags=slider red_component_offset 0x009819c4 (int) : min=-4095 max=4095 step=1 default=0 value=-150 flags=slider blue_component_offset 0x009819c5 (int) : min=-4095 max=4095 step=1 default=0 value=0 flags=slider green_red_component_offset 0x009819c6 (int) : min=-4095 max=4095 step=1 default=0 value=0 flags=slider green_blue_component_offset 0x009819c7 (int) : min=-4095 max=4095 step=1 default=0 value=0 flags=slider The auto white balance algorithm is unchanged, but the obtained value to 'subtract' is now converted to negative and saved as a v4l2 control and displayed properly. Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent bb79974 commit 2e7ee8b

3 files changed

Lines changed: 25 additions & 39 deletions

File tree

‎drivers/media/platform/atmel/atmel-isc-base.c‎

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ const u32 isc_gamma_table[GAMMA_MAX + 1][GAMMA_ENTRIES] = {
225225
(((mbus_code) == MEDIA_BUS_FMT_Y10_1X10) | \
226226
(((mbus_code) == MEDIA_BUS_FMT_Y8_1X8)))
227227

228-
#define ISC_CTRL_ISC_TO_V4L2(x) ((x) == ISC_WB_O_ZERO_VAL ? 0 : (x))
229-
#define ISC_CTRL_V4L2_TO_ISC(x) ((x) ? (x) : ISC_WB_O_ZERO_VAL)
230-
231228
static inline void isc_update_v4l2_ctrls(struct isc_device *isc)
232229
{
233230
struct isc_ctrls *ctrls = &isc->ctrls;
@@ -238,14 +235,10 @@ static inline void isc_update_v4l2_ctrls(struct isc_device *isc)
238235
v4l2_ctrl_s_ctrl(isc->gr_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GR]);
239236
v4l2_ctrl_s_ctrl(isc->gb_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GB]);
240237

241-
v4l2_ctrl_s_ctrl(isc->r_off_ctrl,
242-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_R]));
243-
v4l2_ctrl_s_ctrl(isc->b_off_ctrl,
244-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_B]));
245-
v4l2_ctrl_s_ctrl(isc->gr_off_ctrl,
246-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_GR]));
247-
v4l2_ctrl_s_ctrl(isc->gb_off_ctrl,
248-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_GB]));
238+
v4l2_ctrl_s_ctrl(isc->r_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_R]);
239+
v4l2_ctrl_s_ctrl(isc->b_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_B]);
240+
v4l2_ctrl_s_ctrl(isc->gr_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GR]);
241+
v4l2_ctrl_s_ctrl(isc->gb_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GB]);
249242
}
250243

251244
static inline void isc_update_awb_ctrls(struct isc_device *isc)
@@ -255,11 +248,11 @@ static inline void isc_update_awb_ctrls(struct isc_device *isc)
255248
/* In here we set our actual hw pipeline config */
256249

257250
regmap_write(isc->regmap, ISC_WB_O_RGR,
258-
(ISC_WB_O_ZERO_VAL - (ctrls->offset[ISC_HIS_CFG_MODE_R])) |
259-
((ISC_WB_O_ZERO_VAL - ctrls->offset[ISC_HIS_CFG_MODE_GR]) << 16));
251+
((ctrls->offset[ISC_HIS_CFG_MODE_R])) |
252+
((ctrls->offset[ISC_HIS_CFG_MODE_GR]) << 16));
260253
regmap_write(isc->regmap, ISC_WB_O_BGB,
261-
(ISC_WB_O_ZERO_VAL - (ctrls->offset[ISC_HIS_CFG_MODE_B])) |
262-
((ISC_WB_O_ZERO_VAL - ctrls->offset[ISC_HIS_CFG_MODE_GB]) << 16));
254+
((ctrls->offset[ISC_HIS_CFG_MODE_B])) |
255+
((ctrls->offset[ISC_HIS_CFG_MODE_GB]) << 16));
263256
regmap_write(isc->regmap, ISC_WB_G_RGR,
264257
ctrls->gain[ISC_HIS_CFG_MODE_R] |
265258
(ctrls->gain[ISC_HIS_CFG_MODE_GR] << 16));
@@ -275,12 +268,8 @@ static inline void isc_reset_awb_ctrls(struct isc_device *isc)
275268
for (c = ISC_HIS_CFG_MODE_GR; c <= ISC_HIS_CFG_MODE_B; c++) {
276269
/* gains have a fixed point at 9 decimals */
277270
isc->ctrls.gain[c] = 1 << 9;
278-
/* offsets are in 2's complements, the value
279-
* will be substracted from ISC_WB_O_ZERO_VAL to obtain
280-
* 2's complement of a value between 0 and
281-
* ISC_WB_O_ZERO_VAL >> 1
282-
*/
283-
isc->ctrls.offset[c] = ISC_WB_O_ZERO_VAL;
271+
/* offsets are in 2's complements */
272+
isc->ctrls.offset[c] = 0;
284273
}
285274
}
286275

@@ -1774,9 +1763,12 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
17741763
*/
17751764
ctrls->offset[c] = (offset[c] - 1) << 3;
17761765

1777-
/* the offset is then taken and converted to 2's complements */
1778-
if (!ctrls->offset[c])
1779-
ctrls->offset[c] = ISC_WB_O_ZERO_VAL;
1766+
/*
1767+
* the offset is then taken and converted to 2's complements,
1768+
* and must be negative, as we subtract this value from the
1769+
* color components
1770+
*/
1771+
ctrls->offset[c] = -ctrls->offset[c];
17801772

17811773
/*
17821774
* the stretch gain is the total number of histogram bins
@@ -1938,17 +1930,13 @@ static int isc_s_awb_ctrl(struct v4l2_ctrl *ctrl)
19381930
ctrls->gain[ISC_HIS_CFG_MODE_GB] = isc->gb_gain_ctrl->val;
19391931

19401932
if (ctrl->cluster[ISC_CTRL_R_OFF]->is_new)
1941-
ctrls->offset[ISC_HIS_CFG_MODE_R] =
1942-
ISC_CTRL_V4L2_TO_ISC(isc->r_off_ctrl->val);
1933+
ctrls->offset[ISC_HIS_CFG_MODE_R] = isc->r_off_ctrl->val;
19431934
if (ctrl->cluster[ISC_CTRL_B_OFF]->is_new)
1944-
ctrls->offset[ISC_HIS_CFG_MODE_B] =
1945-
ISC_CTRL_V4L2_TO_ISC(isc->b_off_ctrl->val);
1935+
ctrls->offset[ISC_HIS_CFG_MODE_B] = isc->b_off_ctrl->val;
19461936
if (ctrl->cluster[ISC_CTRL_GR_OFF]->is_new)
1947-
ctrls->offset[ISC_HIS_CFG_MODE_GR] =
1948-
ISC_CTRL_V4L2_TO_ISC(isc->gr_off_ctrl->val);
1937+
ctrls->offset[ISC_HIS_CFG_MODE_GR] = isc->gr_off_ctrl->val;
19491938
if (ctrl->cluster[ISC_CTRL_GB_OFF]->is_new)
1950-
ctrls->offset[ISC_HIS_CFG_MODE_GB] =
1951-
ISC_CTRL_V4L2_TO_ISC(isc->gb_off_ctrl->val);
1939+
ctrls->offset[ISC_HIS_CFG_MODE_GB] = isc->gb_off_ctrl->val;
19521940

19531941
isc_update_awb_ctrls(isc);
19541942

@@ -2010,13 +1998,13 @@ static int isc_g_volatile_awb_ctrl(struct v4l2_ctrl *ctrl)
20101998
ctrls->gain[ISC_HIS_CFG_MODE_GB];
20111999

20122000
ctrl->cluster[ISC_CTRL_R_OFF]->val =
2013-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_R]);
2001+
ctrls->offset[ISC_HIS_CFG_MODE_R];
20142002
ctrl->cluster[ISC_CTRL_B_OFF]->val =
2015-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_B]);
2003+
ctrls->offset[ISC_HIS_CFG_MODE_B];
20162004
ctrl->cluster[ISC_CTRL_GR_OFF]->val =
2017-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_GR]);
2005+
ctrls->offset[ISC_HIS_CFG_MODE_GR];
20182006
ctrl->cluster[ISC_CTRL_GB_OFF]->val =
2019-
ISC_CTRL_ISC_TO_V4L2(ctrls->offset[ISC_HIS_CFG_MODE_GB]);
2007+
ctrls->offset[ISC_HIS_CFG_MODE_GB];
20202008
break;
20212009
}
20222010
return 0;

‎drivers/media/platform/atmel/atmel-isc-regs.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@
108108
/* ISC White Balance Gain for B, GB Register */
109109
#define ISC_WB_G_BGB 0x0000006c
110110

111-
#define ISC_WB_O_ZERO_VAL (1 << 13)
112-
113111
/* ISC Color Filter Array Control Register */
114112
#define ISC_CFA_CTRL 0x00000070
115113

‎drivers/media/platform/atmel/atmel-isc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct isc_ctrls {
133133

134134
/* one for each component : GR, R, GB, B */
135135
u32 gain[HIST_BAYER];
136-
u32 offset[HIST_BAYER];
136+
s32 offset[HIST_BAYER];
137137

138138
u32 hist_entry[HIST_ENTRIES];
139139
u32 hist_count[HIST_BAYER];

0 commit comments

Comments
 (0)