media: atmel: atmel-isc: new features
Subsystems (2)
v2 cover media: atmel: atmel-isc: new features
From: Eugen Hristev <[email protected]>
This series is based on top of my previous commits/series, namely:
media: atmel: atmel-isc: fix asd memory allocation
media: atmel: atmel-isc: fix INIT_WORK misplacement
media: atmel: atmel-isc: limit incoming pixels per frame
media: atmel: atmel-isc: removed ARGB32 added ABGR32 and XBGR32
media: atmel: atmel-isc: reworked driver and formats
it will not build if applied directly
This series include the rework of the white balance,
the one time white balance adjustment, and a change in try_fmt error message handling.
Changes in v2:
- reworked error messages for do_white_balance according to review from Hans
v4l2-compliance:
~# v4l2-compliance
v4l2-compliance SHA: 32cf495ff5da24df54936fae3bf0eb91fba77f3a, 32 bits
Compliance test for atmel_isc device /devatmelo0:_isc f0008000.isc: ================= START STATUS =================
atDriver Info:
Driver name : atmel_isc
Card type : Atmel Image Sensor Controller
Bus info : platform:atmel_isc f0008000.isc
Driver version : 5.1.0
Capabilities : 0x84200001 Video Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Required ioctls:
test VIDIOC_QUERYCAP: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)mel_isc f0008000.isc: Brightness: 0atmel_isc f0008000.isc: Contrast: 256atmel_isc f0008000.isc: Gamma: 2atmel_isc f0008000.isc: White Balance, Automatic: true atmel_isc f0008000.isc: ================== END STATUS ==================
test VIDIOC_LOG_STATUS: OK
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 6 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)
Total for atmel_isc device /dev/video0: 44, Succeeded: 44, Failed: 0, Warnings: 0 root@sama5d2-xplained:~#
Eugen Hristev (4):
media: atmel: atmel-isc: reworked white balance feature
media: v4l2-ctrl: fix flags for DO_WHITE_BALANCE
media: atmel: atmel-isc: add support for DO_WHITE_BALANCE
media: atmel: atmel-isc: make try_fmt error less verbose
drivers/media/platform/atmel/atmel-isc-regs.h | 6 +- drivers/media/platform/atmel/atmel-isc.c | 263 +++++++++++++++++++++++--- drivers/media/v4l2-core/v4l2-ctrls.c | 1 + 3 files changed, 240 insertions(+), 30 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/4 media: atmel: atmel-isc: reworked white balance feature
From: Eugen Hristev <[email protected]>
Reworked auto white balance feature (awb) to cope with all four channels. Implemented stretching and grey world algorithms.
Using the histogram, the ISC will auto adjust the white balance during frame captures.
Because each histogram needs a frame, it will take 4 frames for one adjustment. When the gains were updated by previous code, the registers for the gains were updated only on new streaming start. Now, after each full histogram the registers are updated with new gains.
Also, on previous code, if the streaming stopped but not all 3 histograms finished, a new histogram was started either way. This used to lead to an error "timeout to update profile" when streaming was stopped. According to the hardware, histogram can only work together with the capture, not independently.
--- drivers/media/platform/atmel/atmel-isc-regs.h | 6 +- drivers/media/platform/atmel/atmel-isc.c | 200 +++++++++++++++++++++++--- 2 files changed, 181 insertions(+), 25 deletions(-)
drivers/media/platform/atmel/atmel-isc-regs.h +4 -2
@@ -100,13 +100,15 @@#define ISC_WB_O_RGR 0x00000060/* ISC White Balance Offset for B, GB Register */ -#define ISC_WB_O_BGR 0x00000064 +#define ISC_WB_O_BGB 0x00000064/* ISC White Balance Gain for R, GR Register */ #define ISC_WB_G_RGR 0x00000068/* ISC White Balance Gain for B, GB Register */ -#define ISC_WB_G_BGR 0x0000006c +#define ISC_WB_G_BGB 0x0000006c + +#define ISC_WB_O_ZERO_VAL (1 << 13)/* ISC Color Filter Array Control Register */ #define ISC_CFA_CTRL 0x00000070
drivers/media/platform/atmel/atmel-isc.c +177 -23
330 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/4 media: v4l2-ctrl: fix flags for DO_WHITE_BALANCE
In reply to [email protected]From: Eugen Hristev <[email protected]>
Control DO_WHITE_BALANCE is a button, with read only and execute-on-write flags. Adding this control in the proper list in the fill function.
After adding it here, we can see output of v4l2-ctl -L do_white_balance 0x0098090d (button) : flags=write-only, execute-on-write
--- drivers/media/v4l2-core/v4l2-ctrls.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-ctrls.c +1 -0
@@ -1153,6 +1153,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_FLASH_STROBE_STOP :case V4L2_CID_AUTO_FOCUS_START :case V4L2_CID_AUTO_FOCUS_STOP : +case V4L2_CID_DO_WHITE_BALANCE : *type =V4L2_CTRL_TYPE_BUTTON ; *flags |=V4L2_CTRL_FLAG_WRITE_ONLY |V4L2_CTRL_FLAG_EXECUTE_ON_WRITE ;
Signature · 1 line
2.7.4
PATCH v2 3/4 media: atmel: atmel-isc: add support for DO_WHITE_BALANCE
In reply to [email protected]From: Eugen Hristev <[email protected]>
This adds support for the 'button' control DO_WHITE_BALANCE
This feature will enable the ISC to compute the white balance coefficients in a one time shot, at the user discretion.
This can be used if a color chart/grey chart is present in front of the camera. The ISC will adjust the coefficients and have them fixed until next balance or until sensor mode is changed.
This is particularly useful for white balance adjustment in different lighting scenarios, and then taking photos to similar scenery.
The old auto white balance stays in place, where the ISC will adjust every 4 frames to the current scenery lighting, if the scenery is approximately grey in average, otherwise grey world algorithm fails.
One time white balance adjustments needs streaming to be enabled, such that capture is enabled and the histogram has data to work with. Histogram without capture does not work in this hardware module.
To start the one time white balance procedure:
v4l2-ctl --set-ctrl=do_white_balance=1
This feature works only if the sensor is streaming RAW data, as the hardware supports a histogram only for RAW bayer components.
If the auto white balance is enabled, do_white_balance does nothing. If the streaming is disabled, or the sensor does not output RAW data, the control is inactive.
User controls now include the do_white_balance ctrl:
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=256 value=256 flags=slider
white_balance_automatic 0x0098090c (bool) : default=1 value=0
do_white_balance 0x0098090d (button) : flags=write-only, execute-on-write
gamma 0x00980910 (int) : min=0 max=2 step=1 default=2 value=2 flags=slider---
Changes in v2:
- changed according to review by Hans: DO_WB works evne if AWB is enabled and
does nothing; use active/inactive on do_wb ctrl to make it inactive if not streaming or not raw; do not do anything on inactive ctrls in ctrls callback.
drivers/media/platform/atmel/atmel-isc.c | 66 ++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-)
drivers/media/platform/atmel/atmel-isc.c +59 -7
@@ -167,6 +167,9 @@ struct isc_ctrls {u32 brightness;u32 contrast;u8 gamma_index; +#define ISC_WB_NONE 0 +#define ISC_WB_AUTO 1 +#define ISC_WB_ONETIME 2u8 awb;/* one for each component : GR, R, GB, B */
@@ -210,6 +213,7 @@ struct isc_device {struct fmt_config try_config;struct isc_ctrls ctrls; +struct v4l2_ctrl *do_wb_ctrl;struct work_struct awb_work;struct mutex lock;
@@ -838,7 +842,7 @@ static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) bay_cfg = isc->config.sd_format->cfa_baycfg; -if (!ctrls->awb) +if (ctrls->awb ==ISC_WB_NONE )isc_reset_awb_ctrls (isc);regmap_write (regmap,ISC_WB_CFG , bay_cfg);
@@ -993,6 +997,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)spin_unlock_irqrestore (&isc->dma_queue_lock, flags); +/* if we streaming from RAW, we can do one-shot white balance adj */ +if (ISC_IS_FORMAT_RAW (isc->config.sd_format->mbus_code)) +v4l2_ctrl_activate (isc->do_wb_ctrl, true); +return 0 ; err_configure:
@@ -1017,6 +1025,8 @@ static void isc_stop_streaming(struct vb2_queue *vq)struct isc_buffer *buf;int ret; +v4l2_ctrl_activate (isc->do_wb_ctrl, false); + isc->stop = true;/* Wait until the end of the current frame */
@@ -1941,7 +1951,7 @@ static void isc_awb_work(struct work_struct *w) baysel = isc->config.sd_format->cfa_baycfg <<ISC_HIS_CFG_BAYSEL_SHIFT ;/* if no more auto white balance, reset controls. */ -if (!ctrls->awb) +if (ctrls->awb ==ISC_WB_NONE )isc_reset_awb_ctrls (isc);pm_runtime_get_sync (isc->dev);
@@ -1950,7 +1960,7 @@ static void isc_awb_work(struct work_struct *w)* only update if we have all the required histograms and controls * if awb has been disabled, we need to reset registers as well. */ -if (hist_id ==ISC_HIS_CFG_MODE_GR || !ctrls->awb) { +if (hist_id ==ISC_HIS_CFG_MODE_GR || ctrls->awb ==ISC_WB_NONE ) {/* * It may happen that DMA Done IRQ will trigger while we are * updating white balance registers here.
@@ -1960,6 +1970,16 @@ static void isc_awb_work(struct work_struct *w)spin_lock_irqsave (&isc->awb_lock, flags);isc_update_awb_ctrls (isc);spin_unlock_irqrestore (&isc->awb_lock, flags); + +/* +* if we are doing just the one time white balance adjustment, +* we are basically done. +*/ +if (ctrls->awb ==ISC_WB_ONETIME ) { +v4l2_info (&isc->v4l2_dev, +"Completed one time white-balance adjustment.\n" ); + ctrls->awb =ISC_WB_NONE ; + } }regmap_write (regmap,ISC_HIS_CFG , hist_id | baysel |ISC_HIS_CFG_RAR );isc_update_profile (isc);
@@ -1976,6 +1996,9 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) struct isc_device, ctrls.handler);struct isc_ctrls *ctrls = &isc->ctrls; +if (ctrl->flags &V4L2_CTRL_FLAG_INACTIVE ) +return 0 ; +switch (ctrl->id) {case V4L2_CID_BRIGHTNESS : ctrls->brightness = ctrl->val &ISC_CBC_BRIGHT_MASK ;
@@ -1987,10 +2010,33 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) ctrls->gamma_index = ctrl->val;break ;case V4L2_CID_AUTO_WHITE_BALANCE : - ctrls->awb = ctrl->val; -if (ctrls->hist_stat !=HIST_ENABLED ) { +if (ctrl->val ==1 ) + ctrls->awb =ISC_WB_AUTO ; +else + ctrls->awb =ISC_WB_NONE ; + +/* we did not configure ISC yet */ +if (!isc->config.sd_format) +break ; + +if (ctrls->hist_stat !=HIST_ENABLED )isc_reset_awb_ctrls (isc); - } + +if (isc->ctrls.awb ==ISC_WB_AUTO && +vb2_is_streaming (&isc->vb2_vidq) && +ISC_IS_FORMAT_RAW (isc->config.sd_format->mbus_code)) +isc_set_histogram (isc, true); + +break ; +case V4L2_CID_DO_WHITE_BALANCE : +/* if AWB is enabled, do nothing */ +if (ctrls->awb ==ISC_WB_AUTO ) +return 0 ; + + ctrls->awb =ISC_WB_ONETIME ; +isc_set_histogram (isc, true); +v4l2_dbg (1 , debug, &isc->v4l2_dev, +"One time white-balance started.\n" );break ;default :return -EINVAL ;
@@ -2013,7 +2059,7 @@ static int isc_ctrl_init(struct isc_device *isc) ctrls->hist_stat =HIST_INIT ;isc_reset_awb_ctrls (isc); - ret =v4l2_ctrl_handler_init (hdl,4 ); + ret =v4l2_ctrl_handler_init (hdl,5 );if (ret <0 )return ret;
@@ -2025,6 +2071,12 @@ static int isc_ctrl_init(struct isc_device *isc)v4l2_ctrl_new_std (hdl, ops,V4L2_CID_GAMMA ,0 ,GAMMA_MAX ,1 ,2 );v4l2_ctrl_new_std (hdl, ops,V4L2_CID_AUTO_WHITE_BALANCE ,0 ,1 ,1 ,1 ); +/* do_white_balance is a button, so min,max,step,default are ignored */ + isc->do_wb_ctrl =v4l2_ctrl_new_std (hdl, ops,V4L2_CID_DO_WHITE_BALANCE , +0 ,0 ,0 ,0 ); + +v4l2_ctrl_activate (isc->do_wb_ctrl, false); +v4l2_ctrl_handler_setup (hdl);return 0 ;
Signature · 1 line
2.7.4
PATCH v2 4/4 media: atmel: atmel-isc: make try_fmt error less verbose
In reply to [email protected]From: Eugen Hristev <[email protected]>
In case the sensor refuses to set the format, avoid printing the error message that no compatible format was found.
This means that the try_fmt will be less verbose.
The error will be printed only if really a format cannot be found. Some application try all possible formats in a row (gstreamer e.g.) which will flood the console with error messages until a working one is found.
--- drivers/media/platform/atmel/atmel-isc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/atmel/atmel-isc.c +2 -1
@@ -1487,7 +1487,7 @@ static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f, ret =v4l2_subdev_call (isc->current_subdev->sd, pad, set_fmt, &pad_cfg, &format);if (ret <0 ) - goto isc_try_fmt_err; + goto isc_try_fmt_subdev_err;v4l2_fill_pix_format (pixfmt, &format.format);
@@ -1502,6 +1502,7 @@ static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f, isc_try_fmt_err:v4l2_err (&isc->v4l2_dev,"Could not find any possible format for a working pipeline\n" ); +isc_try_fmt_subdev_err:memset (&isc->try_config,0 ,sizeof (isc->try_config));return ret;
Signature · 1 line
2.7.4