Rockchip ISP1 Driver
Subsystems (5)
v3 cover Rockchip ISP1 Driver
changes in V3:
- add some comments
- fix wrong use of v4l2_async_subdev_notifier_register
- optimize two paths capture at a time
- remove compose
- re-struct headers
- add a tmp wiki page: http://opensource.rock-chips.com/wiki_Rockchip-isp1
changes in V2:
mipi-phy:
- use async probing
- make it be a child device of the GRF
isp:
- add dummy buffer
- change the way to get bus configuration, which make it possible to add parallel sensor support in the future(without mipi-phy driver).
This patch series add a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.
Kernel Branch:
https://github.com/wzyy2/linux/tree/rkisp1/drivers/media/platform/rockchip/isp1
Wiki Pages:
http://opensource.rock-chips.com/wiki_Rockchip-isp1
Jacob Chen (8):
media: doc: add document for rkisp1 meta buffer format
media: rkisp1: add rockchip isp1 driver
media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
dt-bindings: Document the Rockchip ISP1 bindings
dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
ARM: dts: rockchip: add isp node for rk3288
ARM: dts: rockchip: add rx0 mipi-phy for rk3288
MAINTAINERS: add entry for Rockchip ISP1 driver
Jeffy Chen (1):
media: rkisp1: Add user space ABI definitions
Shunqian Zheng (3):
media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format
arm64: dts: rockchip: add isp0 node for rk3399
arm64: dts: rockchip: add rx0 mipi-phy for rk3399
.../devicetree/bindings/media/rockchip-isp1.txt | 57 + .../bindings/media/rockchip-mipi-dphy.txt | 71 + Documentation/media/uapi/v4l/meta-formats.rst | 2 + .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst | 17 + .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 + MAINTAINERS | 10 + arch/arm/boot/dts/rk3288.dtsi | 24 + arch/arm64/boot/dts/rockchip/rk3399.dtsi | 26 + drivers/media/platform/Kconfig | 10 + drivers/media/platform/Makefile | 1 + drivers/media/platform/rockchip/isp1/Makefile | 8 + drivers/media/platform/rockchip/isp1/capture.c | 1684 ++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 194 +++ drivers/media/platform/rockchip/isp1/common.h | 137 ++ drivers/media/platform/rockchip/isp1/dev.c | 655 ++++++++ drivers/media/platform/rockchip/isp1/dev.h | 120 ++ drivers/media/platform/rockchip/isp1/isp_params.c | 1543 ++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 76 + drivers/media/platform/rockchip/isp1/isp_stats.c | 521 ++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 85 + .../media/platform/rockchip/isp1/mipi_dphy_sy.c | 787 +++++++++ drivers/media/platform/rockchip/isp1/regs.c | 264 +++ drivers/media/platform/rockchip/isp1/regs.h | 1582 ++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1201 ++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 131 ++ drivers/media/v4l2-core/v4l2-ioctl.c | 2 + include/uapi/linux/rkisp1-config.h | 785 +++++++++ include/uapi/linux/videodev2.h | 4 + 28 files changed, 10015 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt create mode 100644 Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst create mode 100644 drivers/media/platform/rockchip/isp1/Makefile create mode 100644 drivers/media/platform/rockchip/isp1/capture.c create mode 100644 drivers/media/platform/rockchip/isp1/capture.h create mode 100644 drivers/media/platform/rockchip/isp1/common.h create mode 100644 drivers/media/platform/rockchip/isp1/dev.c create mode 100644 drivers/media/platform/rockchip/isp1/dev.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c create mode 100644 drivers/media/platform/rockchip/isp1/regs.c create mode 100644 drivers/media/platform/rockchip/isp1/regs.h create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h create mode 100644 include/uapi/linux/rkisp1-config.h
Signature · 1 line
2.15.0
PATCH v3 1/12 media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format
From: Shunqian Zheng <[email protected]>
Add the Rockchip ISP1 specific processing parameter format V4L2_META_FMT_RK_ISP1_PARAMS and metadata format V4L2_META_FMT_RK_ISP1_STAT_3A for 3A.
--- drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ include/uapi/linux/videodev2.h | 4 ++++ 2 files changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
@@ -1252,6 +1252,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_TCH_FMT_TU08 : descr ="8-bit unsigned touch data" ;break ;case V4L2_META_FMT_VSP1_HGO : descr ="R-Car VSP1 1-D Histogram" ;break ;case V4L2_META_FMT_VSP1_HGT : descr ="R-Car VSP1 2-D Histogram" ;break ; +case V4L2_META_FMT_RK_ISP1_PARAMS : descr ="Rockchip ISP1 3A params" ;break ; +case V4L2_META_FMT_RK_ISP1_STAT_3A : descr ="Rockchip ISP1 3A statistics" ;break ;default :/* Compressed formats */
include/uapi/linux/videodev2.h +4 -0
@@ -691,6 +691,10 @@ struct v4l2_pix_format {#define V4L2_META_FMT_VSP1_HGO v4l2_fourcc('V', 'S', 'P', 'H')/* R-Car VSP1 1-D Histogram */ #define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T')/* R-Car VSP1 2-D Histogram */ +/* Vendor specific - used for IPU3 camera sub-system */ +#define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P')/* Rockchip ISP1 params */ +#define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S')/* Rockchip ISP1 3A statistics */ +/* priv field value to indicates that subsequent fields are valid. */ #define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe
Signature · 1 line
2.15.0
PATCH v3 2/12 media: doc: add document for rkisp1 meta buffer format
In reply to Jacob Chen--- Documentation/media/uapi/v4l/meta-formats.rst | 2 ++ .../media/uapi/v4l/pixfmt-meta-rkisp1-params.rst | 17 +++++++++++++++++ .../media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst
Documentation/media/uapi/v4l/meta-formats.rst +2 -0
@@ -14,3 +14,5 @@ These formats are used for the :ref:`metadata` interface only. pixfmt-meta-vsp1-hgo pixfmt-meta-vsp1-hgt + pixfmt-meta-rkisp1-params + pixfmt-meta-rkisp1-stat
Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-params.rst new file +17 -0
@@ -0,0 +1,17 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _v4l2-meta-fmt-rkisp1-params: + +******************************* +V4L2_META_FMT_RK_ISP1_PARAMS +******************************* + +Rockchip ISP1 Parameters Data + +Description +=========== + +This format describes input parameters for the Rockchip ISP1. + +The data use c-struct :c:type:`rkisp1_isp_params_cfg`, which is defined in +the ``linux/rkisp1-config.h`` header file, See it for details.
Documentation/media/uapi/v4l/pixfmt-meta-rkisp1-stat.rst new file +18 -0
@@ -0,0 +1,18 @@ +.. -*- coding: utf-8; mode: rst -*- + +.. _v4l2-meta-fmt-rkisp1-stat: + +******************************* +V4L2_META_FMT_RK_ISP1_STAT_3A +******************************* + +Rockchip ISP1 Statistics Data + +Description +=========== + +This format describes image color statistics information generated by the Rockchip +ISP1. + +The data use c-struct :c:type:`rkisp1_stat_buffer`, which is defined in +the ``linux/cifisp_stat.h`` header file, See it for details.
Signature · 1 line
2.15.0
PATCH v3 3/12 media: rkisp1: Add user space ABI definitions
In reply to Jacob ChenFrom: Jeffy Chen <[email protected]>
Add the header for userspace
--- include/uapi/linux/rkisp1-config.h | 785 +++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 include/uapi/linux/rkisp1-config.h
include/uapi/linux/rkisp1-config.h new file +785 -0
@@ -0,0 +1,785 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _UAPI_RKISP1_CONFIG_H +#define _UAPI_RKISP1_CONFIG_H + +#include <linux/types.h> +#include <linux/v4l2-controls.h> + +#define CIFISP_MODULE_DPCC (1 << 0) +#define CIFISP_MODULE_BLS (1 << 1) +#define CIFISP_MODULE_SDG (1 << 2) +#define CIFISP_MODULE_HST (1 << 3) +#define CIFISP_MODULE_LSC (1 << 4) +#define CIFISP_MODULE_AWB_GAIN (1 << 5) +#define CIFISP_MODULE_FLT (1 << 6) +#define CIFISP_MODULE_BDM (1 << 7) +#define CIFISP_MODULE_CTK (1 << 8) +#define CIFISP_MODULE_GOC (1 << 9) +#define CIFISP_MODULE_CPROC (1 << 10) +#define CIFISP_MODULE_AFC (1 << 11) +#define CIFISP_MODULE_AWB (1 << 12) +#define CIFISP_MODULE_IE (1 << 13) +#define CIFISP_MODULE_AEC (1 << 14) +#define CIFISP_MODULE_WDR (1 << 15) +#define CIFISP_MODULE_DPF (1 << 16) +#define CIFISP_MODULE_DPF_STRENGTH (1 << 17) + +#define CIFISP_CTK_COEFF_MAX 0x100 +#define CIFISP_CTK_OFFSET_MAX 0x800 + +#define CIFISP_AE_MEAN_MAX 25 +#define CIFISP_HIST_BIN_N_MAX 16 +#define CIFISP_AFM_MAX_WINDOWS 3 +#define CIFISP_DEGAMMA_CURVE_SIZE 17 + +#define CIFISP_BDM_MAX_TH 0xFF + +/* +* Black level compensation +*/ +/* maximum value for horizontal start address */ +#define CIFISP_BLS_START_H_MAX 0x00000FFF +/* maximum value for horizontal stop address */ +#define CIFISP_BLS_STOP_H_MAX 0x00000FFF +/* maximum value for vertical start address */ +#define CIFISP_BLS_START_V_MAX 0x00000FFF +/* maximum value for vertical stop address */ +#define CIFISP_BLS_STOP_V_MAX 0x00000FFF +/* maximum is 2^18 = 262144*/ +#define CIFISP_BLS_SAMPLES_MAX 0x00000012 +/* maximum value for fixed black level */ +#define CIFISP_BLS_FIX_SUB_MAX 0x00000FFF +/* minimum value for fixed black level */ +#define CIFISP_BLS_FIX_SUB_MIN 0xFFFFF000 +/* 13 bit range (signed)*/ +#define CIFISP_BLS_FIX_MASK 0x00001FFF + +/* +* Automatic white balance measurments +*/ +#define CIFISP_AWB_MAX_GRID 1 +#define CIFISP_AWB_MAX_FRAMES 7 + +/* +* Gamma out +*/ +/* Maximum number of color samples supported */ +#define CIFISP_GAMMA_OUT_MAX_SAMPLES 17 + +/* +* Lens shade correction +*/ +#define CIFISP_LSC_GRAD_TBL_SIZE 8 +#define CIFISP_LSC_SIZE_TBL_SIZE 8 +/* +* The following matches the tuning process, +* not the max capabilities of the chip. +* Last value unused. +*/ +#define CIFISP_LSC_DATA_TBL_SIZE 290 + +/* +* Histogram calculation +*/ +/* Last 3 values unused. */ +#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 + +/* +* Defect Pixel Cluster Correction +*/ +#define CIFISP_DPCC_METHODS_MAX 3 + +/* +* Denoising pre filter +*/ +#define CIFISP_DPF_MAX_NLF_COEFFS 17 +#define CIFISP_DPF_MAX_SPATIAL_COEFFS 6 + +/* +* Measurement types +*/ +#define CIFISP_STAT_AWB (1 << 0) +#define CIFISP_STAT_AUTOEXP (1 << 1) +#define CIFISP_STAT_AFM_FIN (1 << 2) +#define CIFISP_STAT_HIST (1 << 3) + +enum cifisp_histogram_mode { +CIFISP_HISTOGRAM_MODE_DISABLE , +CIFISP_HISTOGRAM_MODE_RGB_COMBINED , +CIFISP_HISTOGRAM_MODE_R_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_G_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_B_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM +}; + +enum cifisp_awb_mode_type { +CIFISP_AWB_MODE_MANUAL , +CIFISP_AWB_MODE_RGB , +CIFISP_AWB_MODE_YCBCR +}; + +enum cifisp_flt_mode { +CIFISP_FLT_STATIC_MODE , +CIFISP_FLT_DYNAMIC_MODE +}; + +/** +* enum cifisp_exp_ctrl_auotostop - stop modes +* @CIFISP_EXP_CTRL_AUTOSTOP_0: continuous measurement +* @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame +*/ +enum cifisp_exp_ctrl_auotostop { +CIFISP_EXP_CTRL_AUTOSTOP_0 =0 , +CIFISP_EXP_CTRL_AUTOSTOP_1 =1 , +}; + +/** +* enum cifisp_exp_meas_mode - Exposure measure mode +* @CIFISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B +* @CIFISP_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256) +*/ +enum cifisp_exp_meas_mode { +CIFISP_EXP_MEASURING_MODE_0 , +CIFISP_EXP_MEASURING_MODE_1 , +}; + +/*---------- PART1: Input Parameters ------------*/ + +struct cifisp_window { +unsigned short h_offs; +unsigned short v_offs; +unsigned short h_size; +unsigned short v_size; +} __attribute__ ((packed)); + +/** +* struct cifisp_bls_fixed_val - BLS fixed subtraction values +* +* The values will be subtracted from the sensor +* values. Therefore a negative value means addition instead of subtraction! +* +* @r: Fixed (signed!) subtraction value for Bayer pattern R +* @gr: Fixed (signed!) subtraction value for Bayer pattern Gr +* @gb: Fixed (signed!) subtraction value for Bayer pattern Gb +* @b: Fixed (signed!) subtraction value for Bayer pattern B +*/ +struct cifisp_bls_fixed_val { +signed short r; +signed short gr; +signed short gb; +signed short b; +} __attribute__ ((packed)); + +/** +* struct cifisp_bls_config - Configuration used by black level subtraction +* +* @enable_auto: Automatic mode activated means that the measured values +* are subtracted.Otherwise the fixed subtraction +* values will be subtracted. +* @en_windows: enabled window +* @bls_window1: Measurement window 1 size +* @bls_window2: Measurement window 2 size +* @bls_samples: Set amount of measured pixels for each Bayer position +* (A, B,C and D) to 2^bls_samples. +* @cifisp_bls_fixed_val: Fixed subtraction values +*/ +struct cifisp_bls_config { +bool enable_auto; +unsigned char en_windows; +struct cifisp_window bls_window1; +struct cifisp_window bls_window2; +unsigned char bls_samples; +struct cifisp_bls_fixed_val fixed_val; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpcc_methods_config - Methods Configuration used by Defect Pixel Cluster Correction +* +* @method: +* @line_thresh: +* @line_mad_fac: +* @pg_fac: +* @rnd_thresh: +* @rg_fac: +*/ +struct cifisp_dpcc_methods_config { +unsigned int method; +unsigned int line_thresh; +unsigned int line_mad_fac; +unsigned int pg_fac; +unsigned int rnd_thresh; +unsigned int rg_fac; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpcc_methods_config - Configuration used by Defect Pixel Cluster Correction +* +* @mode: dpcc output mode +* @output_mode: whether use hard coded methods +* @set_use: stage1 methods set +* @methods: methods config +* @ro_limits: rank order limits +* @rnd_offs: differential rank offsets for rank neighbor difference +*/ +struct cifisp_dpcc_config { +unsigned int mode; +unsigned int output_mode; +unsigned int set_use; +struct cifisp_dpcc_methods_config methods[CIFISP_DPCC_METHODS_MAX ]; +unsigned int ro_limits; +unsigned int rnd_offs; +} __attribute__ ((packed)); + +struct cifisp_gamma_corr_curve { +unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE ]; +} __attribute__ ((packed)); + +struct cifisp_gamma_curve_x_axis_pnts { +unsigned int gamma_dx0; +unsigned int gamma_dx1; +} __attribute__ ((packed)); + +/** +* struct cifisp_gamma_corr_curve - Configuration used by sensor degamma +* +* @curve_x: gamma curve point defintion axis for x +* @xa_pnts: x increments +*/ +struct cifisp_sdg_config { +struct cifisp_gamma_corr_curve curve_r; +struct cifisp_gamma_corr_curve curve_g; +struct cifisp_gamma_corr_curve curve_b; +struct cifisp_gamma_curve_x_axis_pnts xa_pnts; +} __attribute__ ((packed)); + +/** +* struct cifisp_lsc_config - Configuration used by Lens shading correction +* +* refer to datasheet for details +*/ +struct cifisp_lsc_config { +unsigned int r_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int gr_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int gb_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int b_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; + +unsigned int x_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE ]; +unsigned int y_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE ]; + +unsigned int x_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE ]; +unsigned int y_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE ]; +unsigned short config_width; +unsigned short config_height; +} __attribute__ ((packed)); + +/** +* struct cifisp_ie_config - Configuration used by image effects +* +* @eff_mat_1: 3x3 Matrix Coefficients for Emboss Effect 1 +* @eff_mat_2: 3x3 Matrix Coefficients for Emboss Effect 2 +* @eff_mat_3: 3x3 Matrix Coefficients for Emboss 3/Sketch 1 +* @eff_mat_4: 3x3 Matrix Coefficients for Sketch Effect 2 +* @eff_mat_5: 3x3 Matrix Coefficients for Sketch Effect 3 +* @eff_tint: Chrominance increment values of tint (used for sepia effect) +*/ +struct cifisp_ie_config { +enum v4l2_colorfx effect; +unsigned short color_sel; +unsigned short eff_mat_1; +unsigned short eff_mat_2; +unsigned short eff_mat_3; +unsigned short eff_mat_4; +unsigned short eff_mat_5; +unsigned short eff_tint; +} __attribute__ ((packed)); + +/** +* struct cifisp_cproc_config - Configuration used by Color Processing +* +* @c_out_range: Chrominance pixel clippping range at output. (0 for limit, 1 for full) +* @y_in_range: Luminance pixel clippping range at output. +* @y_out_range: Luminance pixel clippping range@output. +* @contrast: 00~ff, 0.0~1.992 +* @brightness: 80~7F, -128~+127 +* @sat: saturation, 00~FF, 0.0~1.992 +* @hue: 80~7F, -90~+87.188 +*/ +struct cifisp_cproc_config { +unsigned char c_out_range; +unsigned char y_in_range; +unsigned char y_out_range; +unsigned char contrast; +unsigned char brightness; +unsigned char sat; +unsigned char hue; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_meas_config - Configuration used by auto white balance +* +* @awb_wnd: white balance measurement window (in pixels) +* @max_y: only pixels values < max_y contribute to awb measurement, set to 0 to disable this feature +* @min_y: only pixels values > min_y contribute to awb measurement +* @max_csum: Chrominance sum maximum value, only consider pixels with Cb+Cr, smaller than threshold for awb measurements +* @min_c: Chrominance minimum value, only consider pixels with Cb/Cr each greater than threshold value for awb measurements +* @frames: number of frames - 1 used for mean value calculation(ucFrames=0 means 1 Frame) +* @awb_ref_cr: reference Cr value for AWB regulation, target for AWB +* @awb_ref_cb: reference Cb value for AWB regulation, target for AWB +*/ +struct cifisp_awb_meas_config { +/* +* Note: currently the h and v offsets are mapped to grid offsets +*/ +struct cifisp_window awb_wnd; +enum cifisp_awb_mode_type awb_mode; +unsigned char max_y; +unsigned char min_y; +unsigned char max_csum; +unsigned char min_c; +unsigned char frames; +unsigned char awb_ref_cr; +unsigned char awb_ref_cb; +bool enable_ymax_cmp; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_gain_config - Configuration used by auto white balance gain +* +* out_data_x = ( AWB_GEAIN_X * in_data + 128) >> 8 +*/ +struct cifisp_awb_gain_config { +unsigned short gain_red; +unsigned short gain_green_r; +unsigned short gain_blue; +unsigned short gain_green_b; +} __attribute__ ((packed)); + +/** +* struct cifisp_flt_config - Configuration used by ISP filtering +* +* @mode: ISP_FILT_MODE register fields +* @grn_stage1: ISP_FILT_MODE register fields +* @chr_h_mode: ISP_FILT_MODE register fields +* @chr_v_mode: ISP_FILT_MODE register fields +* +* refer to datasheet for details. +*/ +struct cifisp_flt_config { +enum cifisp_flt_mode mode; +unsigned char grn_stage1; +unsigned char chr_h_mode; +unsigned char chr_v_mode; +unsigned int thresh_bl0; +unsigned int thresh_bl1; +unsigned int thresh_sh0; +unsigned int thresh_sh1; +unsigned int lum_weight; +unsigned int fac_sh1; +unsigned int fac_sh0; +unsigned int fac_mid; +unsigned int fac_bl0; +unsigned int fac_bl1; +} __attribute__ ((packed)); + +/** +* struct cifisp_bdm_config - Configuration used by Bayer DeMosaic +* +* @demosaic_th: threshod for bayer demosaicing texture detection +*/ +struct cifisp_bdm_config { +unsigned char demosaic_th; +} __attribute__ ((packed)); + +/** +* struct cifisp_ctk_config - Configuration used by Cross Talk correction +* +* @coeff: color correction matrix +* @ct_offset_b: offset for the crosstalk correction matrix +*/ +struct cifisp_ctk_config { +unsigned short coeff0; +unsigned short coeff1; +unsigned short coeff2; +unsigned short coeff3; +unsigned short coeff4; +unsigned short coeff5; +unsigned short coeff6; +unsigned short coeff7; +unsigned short coeff8; +unsigned short ct_offset_r; +unsigned short ct_offset_g; +unsigned short ct_offset_b; +} __attribute__ ((packed)); + +enum cifisp_goc_mode { +CIFISP_GOC_MODE_LOGARITHMIC , +CIFISP_GOC_MODE_EQUIDISTANT +} __attribute__ ((packed)); + +/** +* struct cifisp_goc_config - Configuration used by Gamma Out correction +* +* @mode: goc mode +* @gamma_y: gamma out curve y-axis for all color components +*/ +struct cifisp_goc_config { +enum cifisp_goc_mode mode; +unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_hst_config - Configuration used by Histogram +* +* @mode: histogram mode +* @histogram_predivider: process every stepsize pixel, all other pixels are skipped +* @meas_window: coordinates of the meas window +* @hist_weight: weighting factor for sub-windows +*/ +struct cifisp_hst_config { +enum cifisp_histogram_mode mode; +unsigned char histogram_predivider; +struct cifisp_window meas_window; +unsigned char hist_weight[CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_aec_config - Configuration used by Auto Exposure Control +* +* @mode: Exposure measure mode +* @autostop: stop mode (from enum cifisp_exp_ctrl_auotostop) +* @meas_window: coordinates of the meas window +*/ +struct cifisp_aec_config { +enum cifisp_exp_meas_mode mode; +__u32 autostop; +struct cifisp_window meas_window; +} __attribute__ ((packed)); + +/** +* struct cifisp_afc_config - Configuration used by Auto Focus Control +* +* @num_afm_win: max CIFISP_AFM_MAX_WINDOWS +* @afm_win: coordinates of the meas window +* @thres: threshold used for minimizing the influence of noise +* @var_shift: the number of bits for the shift operation at the end of the calculaton chain. +*/ +struct cifisp_afc_config { +unsigned char num_afm_win; +struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS ]; +unsigned int thres; +unsigned int var_shift; +} __attribute__ ((packed)); + +/** +* enum cifisp_dpf_gain_usage - dpf gain usage +* @CIFISP_DPF_GAIN_USAGE_DISABLED: don't use any gains in preprocessing stage +* @CIFISP_DPF_GAIN_USAGE_NF_GAINS: use only the noise function gains from registers DPF_NF_GAIN_R, ... +* @CIFISP_DPF_GAIN_USAGE_LSC_GAINS: use only the gains from LSC module +* @CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS: use the moise function gains and the gains from LSC module +* @CIFISP_DPF_GAIN_USAGE_AWB_GAINS: use only the gains from AWB module +* @CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS: use the gains from AWB and LSC module +* @CIFISP_DPF_GAIN_USAGE_MAX: upper border (only for an internal evaluation) +*/ +enum cifisp_dpf_gain_usage { +CIFISP_DPF_GAIN_USAGE_DISABLED , +CIFISP_DPF_GAIN_USAGE_NF_GAINS , +CIFISP_DPF_GAIN_USAGE_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_AWB_GAINS , +CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_MAX +}; + +/** +* enum cifisp_dpf_gain_usage - dpf gain usage +* @CIFISP_DPF_RB_FILTERSIZE_13x9: red and blue filter kernel size 13x9 (means 7x5 active pixel) +* @CIFISP_DPF_RB_FILTERSIZE_9x9: red and blue filter kernel size 9x9 (means 5x5 active pixel) +*/ +enum cifisp_dpf_rb_filtersize { + CIFISP_DPF_RB_FILTERSIZE_13x9, + CIFISP_DPF_RB_FILTERSIZE_9x9, +}; + +/** +* enum cifisp_dpf_nll_scale_mode - dpf noise level scale mode +* @CIFISP_NLL_SCALE_LINEAR: use a linear scaling +* @CIFISP_NLL_SCALE_LOGARITHMIC: use a logarithmic scaling +*/ +enum cifisp_dpf_nll_scale_mode { +CIFISP_NLL_SCALE_LINEAR , +CIFISP_NLL_SCALE_LOGARITHMIC , +}; + +struct cifisp_dpf_nll { +unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS ]; +enum cifisp_dpf_nll_scale_mode scale_mode; +} __attribute__ ((packed)); + +struct cifisp_dpf_rb_flt { +enum cifisp_dpf_rb_filtersize fltsize; +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool r_enable; +bool b_enable; +} __attribute__ ((packed)); + +struct cifisp_dpf_g_flt { +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool gr_enable; +bool gb_enable; +} __attribute__ ((packed)); + +struct cifisp_dpf_gain { +enum cifisp_dpf_gain_usage mode; +unsigned short nf_r_gain; +unsigned short nf_b_gain; +unsigned short nf_gr_gain; +unsigned short nf_gb_gain; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpf_config - Configuration used by De-noising pre-filiter +* +* @gain: noise function gain +* @g_flt: green filiter config +* @rb_flt: red blue filiter config +* @nll: noise level lookup +*/ +struct cifisp_dpf_config { +struct cifisp_dpf_gain gain; +struct cifisp_dpf_g_flt g_flt; +struct cifisp_dpf_rb_flt rb_flt; +struct cifisp_dpf_nll nll; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpf_strength_config - strength of the filiter +* +* @r: filter strength of the RED filter +* @g: filter strength of the GREEN filter +* @b: filter strength of the BLUE filter +*/ +struct cifisp_dpf_strength_config { +unsigned char r; +unsigned char g; +unsigned char b; +} __attribute__ ((packed)); + +/** +* struct cifisp_isp_other_cfg - Parameters for some blocks in rockchip isp1 +* +* @dpcc_config: Defect Pixel Cluster Correction config +* @bls_config: Black Level Subtraction config +* @sdg_config: sensor degamma config +* @lsc_config: Lens Shade config +* @awb_gain_config: Auto White balance gain config +* @flt_config: filter config +* @bdm_config: demosaic config +* @ctk_config: cross talk config +* @goc_config: gamma out config +* @bls_config: black level suntraction config +* @dpf_config: De-noising pre-filiter config +* @dpf_strength_config: dpf strength config +* @cproc_config: color process config +* @ie_config: image effects config +*/ +struct cifisp_isp_other_cfg { +struct cifisp_dpcc_config dpcc_config; +struct cifisp_bls_config bls_config; +struct cifisp_sdg_config sdg_config; +struct cifisp_lsc_config lsc_config; +struct cifisp_awb_gain_config awb_gain_config; +struct cifisp_flt_config flt_config; +struct cifisp_bdm_config bdm_config; +struct cifisp_ctk_config ctk_config; +struct cifisp_goc_config goc_config; +struct cifisp_dpf_config dpf_config; +struct cifisp_dpf_strength_config dpf_strength_config; +struct cifisp_cproc_config cproc_config; +struct cifisp_ie_config ie_config; +} __attribute__ ((packed)); + +/** +* struct cifisp_isp_meas_cfg - Rockchip ISP1 Measure Parameters +* +* @awb_meas_config: auto white balance config +* @hst_config: histogram config +* @aec_config: auto exposure config +* @afc_config: auto focus config +*/ +struct cifisp_isp_meas_cfg { +struct cifisp_awb_meas_config awb_meas_config; +struct cifisp_hst_config hst_config; +struct cifisp_aec_config aec_config; +struct cifisp_afc_config afc_config; +} __attribute__ ((packed)); + +/** +* struct rkisp1_isp_params_cfg - Rockchip ISP1 Input Parameters Meta Data +* +* @module_en_update: mask the enable bits of which module should be updated +* @module_ens: mask the enable value of each module, only update the module +* which correspond bit was set in module_en_update +* @module_cfg_update: mask the config bits of which module should be updated +* @meas: measurement config +* @others: other config +*/ +struct rkisp1_isp_params_cfg { +unsigned int module_en_update; +unsigned int module_ens; +unsigned int module_cfg_update; + +struct cifisp_isp_meas_cfg meas; +struct cifisp_isp_other_cfg others; +} __attribute__ ((packed)); + +/*---------- PART2: Measurement Statistics ------------*/ + +/** +* struct cifisp_bls_meas_val - AWB measured values +* +* @cnt: White pixel count, number of "white pixels" found during laster measurement +* @mean_y_or_g: Mean value of Y within window and frames, Green if RGB is selected. +* @mean_cb_or_b: Mean value of Cb within window and frames, Blue if RGB is selected. +* @mean_cr_or_r: Mean value of Cr within window and frames, Red if RGB is selected. +*/ +struct cifisp_awb_meas { +unsigned int cnt; +unsigned char mean_y_or_g; +unsigned char mean_cb_or_b; +unsigned char mean_cr_or_r; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_stat - statistics automatic white balance data +* +* @awb_mean: Mean measured data +*/ +struct cifisp_awb_stat { +struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_bls_meas_val - BLS measured values +* +* @meas_r: Mean measured value for Bayer pattern R +* @meas_gr: Mean measured value for Bayer pattern Gr +* @meas_gb: Mean measured value for Bayer pattern Gb +* @meas_b: Mean measured value for Bayer pattern B +*/ +struct cifisp_bls_meas_val { +unsigned short meas_r; +unsigned short meas_gr; +unsigned short meas_gb; +unsigned short meas_b; +} __attribute__ ((packed)); + +/** +* struct cifisp_ae_stat - statistics auto exposure data +* +* @exp_mean: Mean luminance value of block xx +* @bls_val: available wit exposure results +* +* Image is divided into 5x5 blocks. +*/ +struct cifisp_ae_stat { +unsigned char exp_mean[CIFISP_AE_MEAN_MAX ]; +struct cifisp_bls_meas_val bls_val; +} __attribute__ ((packed)); + +/** +* struct cifisp_af_meas_val - AF measured values +* +* @sum: sharpness, refer to datasheet for definition +* @lum: luminance, refer to datasheet for definition +*/ +struct cifisp_af_meas_val { +unsigned int sum; +unsigned int lum; +} __attribute__ ((packed)); + +/** +* struct cifisp_af_stat - statistics auto focus data +* +* @window: AF measured value of window x +* +* The module measures the sharpness in 3 windows of selectable size via +* register settings(ISP_AFM_*_A/B/C) +*/ +struct cifisp_af_stat { +struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_hist_stat - statistics histogram data +* +* @hist_bins: measured bin counters +* +* Measurement window divided into 25 sub-windows, set +* with ISP_HIST_XXX +*/ +struct cifisp_hist_stat { +unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX ]; +} __attribute__ ((packed)); + +/** +* struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Data +* +* @cifisp_awb_stat: statistics data for automatic white balance +* @cifisp_ae_stat: statistics data for auto exposure +* @cifisp_af_stat: statistics data for auto focus +* @cifisp_hist_stat: statistics histogram data +*/ +struct cifisp_stat { +struct cifisp_awb_stat awb; +struct cifisp_ae_stat ae; +struct cifisp_af_stat af; +struct cifisp_hist_stat hist; +} __attribute__ ((packed)); + +/** +* struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Meta Data +* +* @meas_type: measurement types (CIFISP_STAT_ definitions) +* @frame_id: frame ID for sync +* @params: statistics data +*/ +struct rkisp1_stat_buffer { +unsigned int meas_type; +unsigned int frame_id; +struct cifisp_stat params; +} __attribute__ ((packed)); + +#endif /* _UAPI_RKISP1_CONFIG_H */
Signature · 1 line
2.15.0
Re: [PATCH v3 03/12] media: rkisp1: Add user space ABI definitions
Quoted 39 lines · Jacob Chen
From: Jeffy Chen <[email protected]>
Add the header for userspace
Signed-off-by Jeffy Chen <[email protected]>Signed-off-by Jacob Chen <[email protected]>--- include/uapi/linux/rkisp1-config.h | 785 +++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 include/uapi/linux/rkisp1-config.hinclude/uapi/linux/rkisp1-config.h new file +22
-0@@ -0,0 +1,785 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials
include/uapi/linux/rkisp1-config.h line 32
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE.
Please use the new SPDX license identifier.
Quoted 143 lines
include/uapi/linux/rkisp1-config.h new file +143
-0+*/ + +#ifndef _UAPI_RKISP1_CONFIG_H +#define _UAPI_RKISP1_CONFIG_H + +#include <linux/types.h> +#include <linux/v4l2-controls.h> + +#define CIFISP_MODULE_DPCC (1 << 0) +#define CIFISP_MODULE_BLS (1 << 1) +#define CIFISP_MODULE_SDG (1 << 2) +#define CIFISP_MODULE_HST (1 << 3) +#define CIFISP_MODULE_LSC (1 << 4) +#define CIFISP_MODULE_AWB_GAIN (1 << 5) +#define CIFISP_MODULE_FLT (1 << 6) +#define CIFISP_MODULE_BDM (1 << 7) +#define CIFISP_MODULE_CTK (1 << 8) +#define CIFISP_MODULE_GOC (1 << 9) +#define CIFISP_MODULE_CPROC (1 << 10) +#define CIFISP_MODULE_AFC (1 << 11) +#define CIFISP_MODULE_AWB (1 << 12) +#define CIFISP_MODULE_IE (1 << 13) +#define CIFISP_MODULE_AEC (1 << 14) +#define CIFISP_MODULE_WDR (1 << 15) +#define CIFISP_MODULE_DPF (1 << 16) +#define CIFISP_MODULE_DPF_STRENGTH (1 << 17) + +#define CIFISP_CTK_COEFF_MAX 0x100 +#define CIFISP_CTK_OFFSET_MAX 0x800 + +#define CIFISP_AE_MEAN_MAX 25 +#define CIFISP_HIST_BIN_N_MAX 16 +#define CIFISP_AFM_MAX_WINDOWS 3 +#define CIFISP_DEGAMMA_CURVE_SIZE 17 + +#define CIFISP_BDM_MAX_TH 0xFF + +/* +* Black level compensation +*/ +/* maximum value for horizontal start address */ +#define CIFISP_BLS_START_H_MAX 0x00000FFF +/* maximum value for horizontal stop address */ +#define CIFISP_BLS_STOP_H_MAX 0x00000FFF +/* maximum value for vertical start address */ +#define CIFISP_BLS_START_V_MAX 0x00000FFF +/* maximum value for vertical stop address */ +#define CIFISP_BLS_STOP_V_MAX 0x00000FFF +/* maximum is 2^18 = 262144*/ +#define CIFISP_BLS_SAMPLES_MAX 0x00000012 +/* maximum value for fixed black level */ +#define CIFISP_BLS_FIX_SUB_MAX 0x00000FFF +/* minimum value for fixed black level */ +#define CIFISP_BLS_FIX_SUB_MIN 0xFFFFF000 +/* 13 bit range (signed)*/ +#define CIFISP_BLS_FIX_MASK 0x00001FFF + +/* +* Automatic white balance measurments +*/ +#define CIFISP_AWB_MAX_GRID 1 +#define CIFISP_AWB_MAX_FRAMES 7 + +/* +* Gamma out +*/ +/* Maximum number of color samples supported */ +#define CIFISP_GAMMA_OUT_MAX_SAMPLES 17 + +/* +* Lens shade correction +*/ +#define CIFISP_LSC_GRAD_TBL_SIZE 8 +#define CIFISP_LSC_SIZE_TBL_SIZE 8 +/* +* The following matches the tuning process, +* not the max capabilities of the chip. +* Last value unused. +*/ +#define CIFISP_LSC_DATA_TBL_SIZE 290 + +/* +* Histogram calculation +*/ +/* Last 3 values unused. */ +#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 + +/* +* Defect Pixel Cluster Correction +*/ +#define CIFISP_DPCC_METHODS_MAX 3 + +/* +* Denoising pre filter +*/ +#define CIFISP_DPF_MAX_NLF_COEFFS 17 +#define CIFISP_DPF_MAX_SPATIAL_COEFFS 6 + +/* +* Measurement types +*/ +#define CIFISP_STAT_AWB (1 << 0) +#define CIFISP_STAT_AUTOEXP (1 << 1) +#define CIFISP_STAT_AFM_FIN (1 << 2) +#define CIFISP_STAT_HIST (1 << 3) + +enum cifisp_histogram_mode { +CIFISP_HISTOGRAM_MODE_DISABLE , +CIFISP_HISTOGRAM_MODE_RGB_COMBINED , +CIFISP_HISTOGRAM_MODE_R_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_G_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_B_HISTOGRAM , +CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM +}; + +enum cifisp_awb_mode_type { +CIFISP_AWB_MODE_MANUAL , +CIFISP_AWB_MODE_RGB , +CIFISP_AWB_MODE_YCBCR +}; + +enum cifisp_flt_mode { +CIFISP_FLT_STATIC_MODE , +CIFISP_FLT_DYNAMIC_MODE +}; + +/** +* enum cifisp_exp_ctrl_auotostop - stop modes +* @CIFISP_EXP_CTRL_AUTOSTOP_0: continuous measurement +* @CIFISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame +*/ +enum cifisp_exp_ctrl_auotostop { +CIFISP_EXP_CTRL_AUTOSTOP_0 =0 , +CIFISP_EXP_CTRL_AUTOSTOP_1 =1 , +}; + +/** +* enum cifisp_exp_meas_mode - Exposure measure mode +* @CIFISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B +* @CIFISP_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256) +*/ +enum cifisp_exp_meas_mode { + CIFISP_EXP_MEASURING_MODE_0,
include/uapi/linux/rkisp1-config.h line 185
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+ CIFISP_EXP_MEASURING_MODE_1, +}; + +/*---------- PART1: Input Parameters ------------*/ + +struct cifisp_window { +unsigned short h_offs; +unsigned short v_offs; +unsigned short h_size; +unsigned short v_size;
Use __u16 et al instead of unsigned short etc. It's the safest way to do this.
Quoted 15 lines
include/uapi/linux/rkisp1-config.h new file +15
-0+} __attribute__ ((packed)); + +/** +* struct cifisp_bls_fixed_val - BLS fixed subtraction values +* +* The values will be subtracted from the sensor +* values. Therefore a negative value means addition instead of subtraction! +* +* @r: Fixed (signed!) subtraction value for Bayer pattern R +* @gr: Fixed (signed!) subtraction value for Bayer pattern Gr +* @gb: Fixed (signed!) subtraction value for Bayer pattern Gb +* @b: Fixed (signed!) subtraction value for Bayer pattern B +*/ +struct cifisp_bls_fixed_val { +signed short r;
include/uapi/linux/rkisp1-config.h line 210
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+signed short gr; +signed short gb; +signed short b; +} __attribute__ ((packed)); + +/** +* struct cifisp_bls_config - Configuration used by black level subtraction +* +* @enable_auto: Automatic mode activated means that the measured values +* are subtracted.Otherwise the fixed subtraction
Space after '.'
include/uapi/linux/rkisp1-config.h line 220
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+* values will be subtracted. +* @en_windows: enabled window +* @bls_window1: Measurement window 1 size +* @bls_window2: Measurement window 2 size +* @bls_samples: Set amount of measured pixels for each Bayer position +* (A, B,C and D) to 2^bls_samples. +* @cifisp_bls_fixed_val: Fixed subtraction values +*/ +struct cifisp_bls_config { +bool enable_auto;
Don't use bool, use __u8.
Quoted 43 lines
include/uapi/linux/rkisp1-config.h new file +43
-0+unsigned char en_windows; +struct cifisp_window bls_window1; +struct cifisp_window bls_window2; +unsigned char bls_samples; +struct cifisp_bls_fixed_val fixed_val; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpcc_methods_config - Methods Configuration used by Defect Pixel Cluster Correction +* +* @method: +* @line_thresh: +* @line_mad_fac: +* @pg_fac: +* @rnd_thresh: +* @rg_fac: +*/ +struct cifisp_dpcc_methods_config { +unsigned int method; +unsigned int line_thresh; +unsigned int line_mad_fac; +unsigned int pg_fac; +unsigned int rnd_thresh; +unsigned int rg_fac; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpcc_methods_config - Configuration used by Defect Pixel Cluster Correction +* +* @mode: dpcc output mode +* @output_mode: whether use hard coded methods +* @set_use: stage1 methods set +* @methods: methods config +* @ro_limits: rank order limits +* @rnd_offs: differential rank offsets for rank neighbor difference +*/ +struct cifisp_dpcc_config { +unsigned int mode; +unsigned int output_mode; +unsigned int set_use; +struct cifisp_dpcc_methods_config methods[CIFISP_DPCC_METHODS_MAX ]; +unsigned int ro_limits; +unsigned int rnd_offs;
include/uapi/linux/rkisp1-config.h line 273
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+} __attribute__ ((packed)); + +struct cifisp_gamma_corr_curve { +unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE ]; +} __attribute__ ((packed)); + +struct cifisp_gamma_curve_x_axis_pnts { +unsigned int gamma_dx0; +unsigned int gamma_dx1; +} __attribute__ ((packed));
Can add a short description of the two structs above?
include/uapi/linux/rkisp1-config.h line 278
Quoted 5 lines
include/uapi/linux/rkisp1-config.h new file +5
-0+ +/** +* struct cifisp_gamma_corr_curve - Configuration used by sensor degamma +* +* @curve_x: gamma curve point defintion axis for x
defintion -> definition
Quoted 31 lines
include/uapi/linux/rkisp1-config.h new file +31
-0+* @xa_pnts: x increments +*/ +struct cifisp_sdg_config { +struct cifisp_gamma_corr_curve curve_r; +struct cifisp_gamma_corr_curve curve_g; +struct cifisp_gamma_corr_curve curve_b; +struct cifisp_gamma_curve_x_axis_pnts xa_pnts; +} __attribute__ ((packed)); + +/** +* struct cifisp_lsc_config - Configuration used by Lens shading correction +* +* refer to datasheet for details +*/ +struct cifisp_lsc_config { +unsigned int r_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int gr_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int gb_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; +unsigned int b_data_tbl[CIFISP_LSC_DATA_TBL_SIZE ]; + +unsigned int x_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE ]; +unsigned int y_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE ]; + +unsigned int x_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE ]; +unsigned int y_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE ]; +unsigned short config_width; +unsigned short config_height; +} __attribute__ ((packed)); + +/** +* struct cifisp_ie_config - Configuration used by image effects
include/uapi/linux/rkisp1-config.h line 319
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+* +* @eff_mat_1: 3x3 Matrix Coefficients for Emboss Effect 1 +* @eff_mat_2: 3x3 Matrix Coefficients for Emboss Effect 2 +* @eff_mat_3: 3x3 Matrix Coefficients for Emboss 3/Sketch 1 +* @eff_mat_4: 3x3 Matrix Coefficients for Sketch Effect 2 +* @eff_mat_5: 3x3 Matrix Coefficients for Sketch Effect 3 +* @eff_tint: Chrominance increment values of tint (used for sepia effect) +*/ +struct cifisp_ie_config { +enum v4l2_colorfx effect;
Avoid enums, use __u16 here.
Quoted 5 lines
include/uapi/linux/rkisp1-config.h new file +5
-0+unsigned short color_sel; +unsigned short eff_mat_1; +unsigned short eff_mat_2; +unsigned short eff_mat_3; +unsigned short eff_mat_4;
include/uapi/linux/rkisp1-config.h
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+unsigned short eff_mat_5; +unsigned short eff_tint; +} __attribute__ ((packed)); + +/** +* struct cifisp_cproc_config - Configuration used by Color Processing +* +* @c_out_range: Chrominance pixel clippping range at output. (0 for limit, 1 for full) +* @y_in_range: Luminance pixel clippping range at output. +* @y_out_range: Luminance pixel clippping range at output.
clippping -> clipping (three times)
Quoted 153 lines
include/uapi/linux/rkisp1-config.h new file +153
-0+* @contrast: 00~ff, 0.0~1.992 +* @brightness: 80~7F, -128~+127 +* @sat: saturation, 00~FF, 0.0~1.992 +* @hue: 80~7F, -90~+87.188 +*/ +struct cifisp_cproc_config { +unsigned char c_out_range; +unsigned char y_in_range; +unsigned char y_out_range; +unsigned char contrast; +unsigned char brightness; +unsigned char sat; +unsigned char hue; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_meas_config - Configuration used by auto white balance +* +* @awb_wnd: white balance measurement window (in pixels) +* @max_y: only pixels values < max_y contribute to awb measurement, set to 0 to disable this feature +* @min_y: only pixels values > min_y contribute to awb measurement +* @max_csum: Chrominance sum maximum value, only consider pixels with Cb+Cr, smaller than threshold for awb measurements +* @min_c: Chrominance minimum value, only consider pixels with Cb/Cr each greater than threshold value for awb measurements +* @frames: number of frames - 1 used for mean value calculation(ucFrames=0 means 1 Frame) +* @awb_ref_cr: reference Cr value for AWB regulation, target for AWB +* @awb_ref_cb: reference Cb value for AWB regulation, target for AWB +*/ +struct cifisp_awb_meas_config { +/* +* Note: currently the h and v offsets are mapped to grid offsets +*/ +struct cifisp_window awb_wnd; +enum cifisp_awb_mode_type awb_mode; +unsigned char max_y; +unsigned char min_y; +unsigned char max_csum; +unsigned char min_c; +unsigned char frames; +unsigned char awb_ref_cr; +unsigned char awb_ref_cb; +bool enable_ymax_cmp; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_gain_config - Configuration used by auto white balance gain +* +* out_data_x = ( AWB_GEAIN_X * in_data + 128) >> 8 +*/ +struct cifisp_awb_gain_config { +unsigned short gain_red; +unsigned short gain_green_r; +unsigned short gain_blue; +unsigned short gain_green_b; +} __attribute__ ((packed)); + +/** +* struct cifisp_flt_config - Configuration used by ISP filtering +* +* @mode: ISP_FILT_MODE register fields +* @grn_stage1: ISP_FILT_MODE register fields +* @chr_h_mode: ISP_FILT_MODE register fields +* @chr_v_mode: ISP_FILT_MODE register fields +* +* refer to datasheet for details. +*/ +struct cifisp_flt_config { +enum cifisp_flt_mode mode; +unsigned char grn_stage1; +unsigned char chr_h_mode; +unsigned char chr_v_mode; +unsigned int thresh_bl0; +unsigned int thresh_bl1; +unsigned int thresh_sh0; +unsigned int thresh_sh1; +unsigned int lum_weight; +unsigned int fac_sh1; +unsigned int fac_sh0; +unsigned int fac_mid; +unsigned int fac_bl0; +unsigned int fac_bl1; +} __attribute__ ((packed)); + +/** +* struct cifisp_bdm_config - Configuration used by Bayer DeMosaic +* +* @demosaic_th: threshod for bayer demosaicing texture detection +*/ +struct cifisp_bdm_config { +unsigned char demosaic_th; +} __attribute__ ((packed)); + +/** +* struct cifisp_ctk_config - Configuration used by Cross Talk correction +* +* @coeff: color correction matrix +* @ct_offset_b: offset for the crosstalk correction matrix +*/ +struct cifisp_ctk_config { +unsigned short coeff0; +unsigned short coeff1; +unsigned short coeff2; +unsigned short coeff3; +unsigned short coeff4; +unsigned short coeff5; +unsigned short coeff6; +unsigned short coeff7; +unsigned short coeff8; +unsigned short ct_offset_r; +unsigned short ct_offset_g; +unsigned short ct_offset_b; +} __attribute__ ((packed)); + +enum cifisp_goc_mode { +CIFISP_GOC_MODE_LOGARITHMIC , +CIFISP_GOC_MODE_EQUIDISTANT +} __attribute__ ((packed)); + +/** +* struct cifisp_goc_config - Configuration used by Gamma Out correction +* +* @mode: goc mode +* @gamma_y: gamma out curve y-axis for all color components +*/ +struct cifisp_goc_config { +enum cifisp_goc_mode mode; +unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_hst_config - Configuration used by Histogram +* +* @mode: histogram mode +* @histogram_predivider: process every stepsize pixel, all other pixels are skipped +* @meas_window: coordinates of the meas window +* @hist_weight: weighting factor for sub-windows +*/ +struct cifisp_hst_config { +enum cifisp_histogram_mode mode; +unsigned char histogram_predivider; +struct cifisp_window meas_window; +unsigned char hist_weight[CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_aec_config - Configuration used by Auto Exposure Control +* +* @mode: Exposure measure mode +* @autostop: stop mode (from enum cifisp_exp_ctrl_auotostop) +* @meas_window: coordinates of the meas window +*/ +struct cifisp_aec_config { +enum cifisp_exp_meas_mode mode; +__u32 autostop;
include/uapi/linux/rkisp1-config.h line 497
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+struct cifisp_window meas_window; +} __attribute__ ((packed)); + +/** +* struct cifisp_afc_config - Configuration used by Auto Focus Control +* +* @num_afm_win: max CIFISP_AFM_MAX_WINDOWS +* @afm_win: coordinates of the meas window +* @thres: threshold used for minimizing the influence of noise +* @var_shift: the number of bits for the shift operation at the end of the calculaton chain.
calculaton -> calculation
Quoted 4 lines
include/uapi/linux/rkisp1-config.h new file +4
-0+*/ +struct cifisp_afc_config { +unsigned char num_afm_win; +struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS ];
include/uapi/linux/rkisp1-config.h line 511
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+unsigned int thres; +unsigned int var_shift; +} __attribute__ ((packed)); + +/** +* enum cifisp_dpf_gain_usage - dpf gain usage +* @CIFISP_DPF_GAIN_USAGE_DISABLED: don't use any gains in preprocessing stage +* @CIFISP_DPF_GAIN_USAGE_NF_GAINS: use only the noise function gains from registers DPF_NF_GAIN_R, ... +* @CIFISP_DPF_GAIN_USAGE_LSC_GAINS: use only the gains from LSC module +* @CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS: use the moise function gains and the gains from LSC module
moise -> noise
Quoted 56 lines
include/uapi/linux/rkisp1-config.h new file +56
-0+* @CIFISP_DPF_GAIN_USAGE_AWB_GAINS: use only the gains from AWB module +* @CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS: use the gains from AWB and LSC module +* @CIFISP_DPF_GAIN_USAGE_MAX: upper border (only for an internal evaluation) +*/ +enum cifisp_dpf_gain_usage { +CIFISP_DPF_GAIN_USAGE_DISABLED , +CIFISP_DPF_GAIN_USAGE_NF_GAINS , +CIFISP_DPF_GAIN_USAGE_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_AWB_GAINS , +CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS , +CIFISP_DPF_GAIN_USAGE_MAX +}; + +/** +* enum cifisp_dpf_gain_usage - dpf gain usage +* @CIFISP_DPF_RB_FILTERSIZE_13x9: red and blue filter kernel size 13x9 (means 7x5 active pixel) +* @CIFISP_DPF_RB_FILTERSIZE_9x9: red and blue filter kernel size 9x9 (means 5x5 active pixel) +*/ +enum cifisp_dpf_rb_filtersize { + CIFISP_DPF_RB_FILTERSIZE_13x9, + CIFISP_DPF_RB_FILTERSIZE_9x9, +}; + +/** +* enum cifisp_dpf_nll_scale_mode - dpf noise level scale mode +* @CIFISP_NLL_SCALE_LINEAR: use a linear scaling +* @CIFISP_NLL_SCALE_LOGARITHMIC: use a logarithmic scaling +*/ +enum cifisp_dpf_nll_scale_mode { +CIFISP_NLL_SCALE_LINEAR , +CIFISP_NLL_SCALE_LOGARITHMIC , +}; + +struct cifisp_dpf_nll { +unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS ]; +enum cifisp_dpf_nll_scale_mode scale_mode; +} __attribute__ ((packed)); + +struct cifisp_dpf_rb_flt { +enum cifisp_dpf_rb_filtersize fltsize; +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool r_enable; +bool b_enable; +} __attribute__ ((packed)); + +struct cifisp_dpf_g_flt { +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool gr_enable; +bool gb_enable; +} __attribute__ ((packed)); + +struct cifisp_dpf_gain { +enum cifisp_dpf_gain_usage mode; +unsigned short nf_r_gain; +unsigned short nf_b_gain;
include/uapi/linux/rkisp1-config.h line 577
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+unsigned short nf_gr_gain; +unsigned short nf_gb_gain; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpf_config - Configuration used by De-noising pre-filiter +* +* @gain: noise function gain +* @g_flt: green filiter config +* @rb_flt: red blue filiter config
filiter -> filter (2x)
include/uapi/linux/rkisp1-config.h line 588
Quoted 11 lines
include/uapi/linux/rkisp1-config.h new file +11
-0+* @nll: noise level lookup +*/ +struct cifisp_dpf_config { +struct cifisp_dpf_gain gain; +struct cifisp_dpf_g_flt g_flt; +struct cifisp_dpf_rb_flt rb_flt; +struct cifisp_dpf_nll nll; +} __attribute__ ((packed)); + +/** +* struct cifisp_dpf_strength_config - strength of the filiter
Ditto.
Quoted 188 lines
include/uapi/linux/rkisp1-config.h new file +187
-0+* +* @r: filter strength of the RED filter +* @g: filter strength of the GREEN filter +* @b: filter strength of the BLUE filter +*/ +struct cifisp_dpf_strength_config { +unsigned char r; +unsigned char g; +unsigned char b; +} __attribute__ ((packed)); + +/** +* struct cifisp_isp_other_cfg - Parameters for some blocks in rockchip isp1 +* +* @dpcc_config: Defect Pixel Cluster Correction config +* @bls_config: Black Level Subtraction config +* @sdg_config: sensor degamma config +* @lsc_config: Lens Shade config +* @awb_gain_config: Auto White balance gain config +* @flt_config: filter config +* @bdm_config: demosaic config +* @ctk_config: cross talk config +* @goc_config: gamma out config +* @bls_config: black level suntraction config +* @dpf_config: De-noising pre-filiter config +* @dpf_strength_config: dpf strength config +* @cproc_config: color process config +* @ie_config: image effects config +*/ +struct cifisp_isp_other_cfg { +struct cifisp_dpcc_config dpcc_config; +struct cifisp_bls_config bls_config; +struct cifisp_sdg_config sdg_config; +struct cifisp_lsc_config lsc_config; +struct cifisp_awb_gain_config awb_gain_config; +struct cifisp_flt_config flt_config; +struct cifisp_bdm_config bdm_config; +struct cifisp_ctk_config ctk_config; +struct cifisp_goc_config goc_config; +struct cifisp_dpf_config dpf_config; +struct cifisp_dpf_strength_config dpf_strength_config; +struct cifisp_cproc_config cproc_config; +struct cifisp_ie_config ie_config; +} __attribute__ ((packed)); + +/** +* struct cifisp_isp_meas_cfg - Rockchip ISP1 Measure Parameters +* +* @awb_meas_config: auto white balance config +* @hst_config: histogram config +* @aec_config: auto exposure config +* @afc_config: auto focus config +*/ +struct cifisp_isp_meas_cfg { +struct cifisp_awb_meas_config awb_meas_config; +struct cifisp_hst_config hst_config; +struct cifisp_aec_config aec_config; +struct cifisp_afc_config afc_config; +} __attribute__ ((packed)); + +/** +* struct rkisp1_isp_params_cfg - Rockchip ISP1 Input Parameters Meta Data +* +* @module_en_update: mask the enable bits of which module should be updated +* @module_ens: mask the enable value of each module, only update the module +* which correspond bit was set in module_en_update +* @module_cfg_update: mask the config bits of which module should be updated +* @meas: measurement config +* @others: other config +*/ +struct rkisp1_isp_params_cfg { +unsigned int module_en_update; +unsigned int module_ens; +unsigned int module_cfg_update; + +struct cifisp_isp_meas_cfg meas; +struct cifisp_isp_other_cfg others; +} __attribute__ ((packed)); + +/*---------- PART2: Measurement Statistics ------------*/ + +/** +* struct cifisp_bls_meas_val - AWB measured values +* +* @cnt: White pixel count, number of "white pixels" found during laster measurement +* @mean_y_or_g: Mean value of Y within window and frames, Green if RGB is selected. +* @mean_cb_or_b: Mean value of Cb within window and frames, Blue if RGB is selected. +* @mean_cr_or_r: Mean value of Cr within window and frames, Red if RGB is selected. +*/ +struct cifisp_awb_meas { +unsigned int cnt; +unsigned char mean_y_or_g; +unsigned char mean_cb_or_b; +unsigned char mean_cr_or_r; +} __attribute__ ((packed)); + +/** +* struct cifisp_awb_stat - statistics automatic white balance data +* +* @awb_mean: Mean measured data +*/ +struct cifisp_awb_stat { +struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_bls_meas_val - BLS measured values +* +* @meas_r: Mean measured value for Bayer pattern R +* @meas_gr: Mean measured value for Bayer pattern Gr +* @meas_gb: Mean measured value for Bayer pattern Gb +* @meas_b: Mean measured value for Bayer pattern B +*/ +struct cifisp_bls_meas_val { +unsigned short meas_r; +unsigned short meas_gr; +unsigned short meas_gb; +unsigned short meas_b; +} __attribute__ ((packed)); + +/** +* struct cifisp_ae_stat - statistics auto exposure data +* +* @exp_mean: Mean luminance value of block xx +* @bls_val: available wit exposure results +* +* Image is divided into 5x5 blocks. +*/ +struct cifisp_ae_stat { +unsigned char exp_mean[CIFISP_AE_MEAN_MAX ]; +struct cifisp_bls_meas_val bls_val; +} __attribute__ ((packed)); + +/** +* struct cifisp_af_meas_val - AF measured values +* +* @sum: sharpness, refer to datasheet for definition +* @lum: luminance, refer to datasheet for definition +*/ +struct cifisp_af_meas_val { +unsigned int sum; +unsigned int lum; +} __attribute__ ((packed)); + +/** +* struct cifisp_af_stat - statistics auto focus data +* +* @window: AF measured value of window x +* +* The module measures the sharpness in 3 windows of selectable size via +* register settings(ISP_AFM_*_A/B/C) +*/ +struct cifisp_af_stat { +struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS ]; +} __attribute__ ((packed)); + +/** +* struct cifisp_hist_stat - statistics histogram data +* +* @hist_bins: measured bin counters +* +* Measurement window divided into 25 sub-windows, set +* with ISP_HIST_XXX +*/ +struct cifisp_hist_stat { +unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX ]; +} __attribute__ ((packed)); + +/** +* struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Data +* +* @cifisp_awb_stat: statistics data for automatic white balance +* @cifisp_ae_stat: statistics data for auto exposure +* @cifisp_af_stat: statistics data for auto focus +* @cifisp_hist_stat: statistics histogram data +*/ +struct cifisp_stat { +struct cifisp_awb_stat awb; +struct cifisp_ae_stat ae; +struct cifisp_af_stat af; +struct cifisp_hist_stat hist; +} __attribute__ ((packed)); + +/** +* struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Meta Data +* +* @meas_type: measurement types (CIFISP_STAT_ definitions)
include/uapi/linux/rkisp1-config.h line 785
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+* @frame_id: frame ID for sync +* @params: statistics data +*/ +struct rkisp1_stat_buffer { +unsigned int meas_type; +unsigned int frame_id; +struct cifisp_stat params; +} __attribute__ ((packed)); + +#endif /* _UAPI_RKISP1_CONFIG_H */
So it is very hard to tell whether there are 32 vs 64 bit issues from reading this header.
For the daily build of V4L2 I've made a little script to test if the ABI changed.
The scripts I use are part of this archive:
https://hverkuil.home.xs4all.nl/logs/scripts.tar.bz2
Specifically stabs-parser.pl and build.sh. The build.sh script is the main shell script that builds media for all the various architectures. At line 499 it creates a little test.c source that is basically a union with all the various top-level data structs used by v4l2.
It then compiles it using the -gstabs compiler option and feeds the test.s to the stabs-parser. The output looks like this:
v4l2_bt_timings: struct(124) { width at 0(4) height at 4(4) interlaced at 8(4) polarities at 12(4) pixelclock at 16(8) hfrontporch at 24(4) hsync at 28(4) hbackporch at 32(4) vfrontporch at 36(4) vsync at 40(4) vbackporch at 44(4)il_vfrontporch at 48(4) il_vsync at 52(4) il_vbackporch at 56(4) standards at 60(4) flags at 64(4) picture_aspect at 68(8) cea861_vic at 76(1) hdmi_vic at 77(1) reserved[]@78(46) }v4l2_bt_timings_cap: struct(104) { min_width at 0(4) max_width at 4(4) min_height at 8(4) max_height at 12(4) min_pixelclock at 16(8) max_pixelclock at 24(8) standards at 32(4) capabilities at 36(4) reserved[]@40(64) } v4l2_buf_type:T0=eV4L2_BUF_TYPE_VIDEO_CAPTURE:1,V4L2_BUF_TYPE_VIDEO_OUTPUT:2,V4L2_BUF_TYPE_VIDEO_OVERLAY:3,V4L2_BUF_TYPE_VBI_CAPTURE:4,V4L2_BUF_TYPE_VBI_OUTPUT:5,V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:6,V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:7,V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:8,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:9,V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:10,V4L2_BUF_TYPE_SDR_CAPTURE:11,V4L2_BUF_TYPE_SDR_OUTPUT:12,V4L2_BUF_TYPE_META_CAPTURE:13,V4L2_BUF_TYPE_PRIVATE:128,}v4l2_buffer: struct(68) { index at 0(4) type at 4(4) bytesused at 8(4) flags at 12(4) field at 16(4) timestamp at 20(8) timecode at 28(16) sequence at 44(4) memory at 48(4) m union(4) { offset at 0(4) userptr at 0(4) planes*@0(4)
fd at 0(4) }@52(4) } length at 56(4) reserved2 at 60(4) reserved at 64(4) }v4l2_capability: struct(104) { driver[]@0(16) card[]@16(32) bus_info at 48(32) version at 80(4) capabilities at 84(4) device_caps at 88(4) reserved[]@92(12) }
It shows the sizes and offsets of all the fields. In your case compiling this program for 32 bit and 64 bit and parsing the stabs info should result in the same layout.
It's not elegant perhaps, but it works well.
Regards,
Hans
PATCH v3 4/12 media: rkisp1: add rockchip isp1 driver
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
This commit adds a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.
--- drivers/media/platform/Kconfig | 10 + drivers/media/platform/Makefile | 1 + drivers/media/platform/rockchip/isp1/Makefile | 7 + drivers/media/platform/rockchip/isp1/capture.c | 1684 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 194 +++ drivers/media/platform/rockchip/isp1/common.h | 137 ++ drivers/media/platform/rockchip/isp1/dev.c | 655 ++++++++ drivers/media/platform/rockchip/isp1/dev.h | 120 ++ drivers/media/platform/rockchip/isp1/isp_params.c | 1543 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 76 + drivers/media/platform/rockchip/isp1/isp_stats.c | 521 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 85 ++ drivers/media/platform/rockchip/isp1/regs.c | 264 ++++ drivers/media/platform/rockchip/isp1/regs.h | 1582 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1201 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 131 ++ 16 files changed, 8211 insertions(+) create mode 100644 drivers/media/platform/rockchip/isp1/Makefile create mode 100644 drivers/media/platform/rockchip/isp1/capture.c create mode 100644 drivers/media/platform/rockchip/isp1/capture.h create mode 100644 drivers/media/platform/rockchip/isp1/common.h create mode 100644 drivers/media/platform/rockchip/isp1/dev.c create mode 100644 drivers/media/platform/rockchip/isp1/dev.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h create mode 100644 drivers/media/platform/rockchip/isp1/regs.c create mode 100644 drivers/media/platform/rockchip/isp1/regs.h create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.h
drivers/media/platform/Kconfig +10 -0
@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS select VIDEOBUF2_DMA_SG select V4L2_FWNODE +config VIDEO_ROCKCHIP_ISP1 + tristate "Rockchip Image Signal Processing v1 Unit driver" + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API + depends on ARCH_ROCKCHIP || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + default n + ---help--- + Support for ISP1 on the rockchip SoC. + config VIDEO_S3C_CAMIF tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver" depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
drivers/media/platform/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1) += rcar_fdp1.o obj-$(CONFIG_VIDEO_RENESAS_JPU) += rcar_jpu.o obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += rockchip/isp1/ obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip/rga/ obj-y += omap/
drivers/media/platform/rockchip/isp1/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += video_rkisp1.o +video_rkisp1-objs += rkisp1.o \ + dev.o \ + regs.o \ + isp_stats.o \ + isp_params.o \ + capture.o
drivers/media/platform/rockchip/isp1/capture.c new file +1684 -0
1,684 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/capture.h new file +194 -0
194 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/common.h new file +137 -0
137 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/dev.c new file +655 -0
655 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/dev.h new file +120 -0
120 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_params.c new file +1543 -0
180 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_params.h new file +76 -0
76 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_stats.c new file +521 -0
521 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_stats.h new file +85 -0
85 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/regs.c new file +264 -0
264 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/regs.h new file +1582 -0
1,582 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/rkisp1.c new file +1201 -0
1,201 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/rkisp1.h new file +131 -0
131 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.15.0
Part of the diff is not shown here. View the raw message.
Re: [PATCH v3 04/12] media: rkisp1: add rockchip isp1 driver
Quoted 97 lines · Jacob Chen
From: Jacob Chen <[email protected]>
This commit adds a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.
Signed-off-by Jacob Chen <[email protected]>Signed-off-by Shunqian Zheng <[email protected]>Signed-off-by Yichong Zhong <[email protected]>Signed-off-by Jacob Chen <[email protected]>Signed-off-by Eddie Cai <[email protected]>Signed-off-by Jeffy Chen <[email protected]>Signed-off-by Allon Huang <[email protected]>Signed-off-by Tomasz Figa <[email protected]>--- drivers/media/platform/Kconfig | 10 + drivers/media/platform/Makefile | 1 + drivers/media/platform/rockchip/isp1/Makefile | 7 + drivers/media/platform/rockchip/isp1/capture.c | 1684 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 194 +++ drivers/media/platform/rockchip/isp1/common.h | 137 ++ drivers/media/platform/rockchip/isp1/dev.c | 655 ++++++++ drivers/media/platform/rockchip/isp1/dev.h | 120 ++ drivers/media/platform/rockchip/isp1/isp_params.c | 1543 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 76 + drivers/media/platform/rockchip/isp1/isp_stats.c | 521 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 85 ++ drivers/media/platform/rockchip/isp1/regs.c | 264 ++++ drivers/media/platform/rockchip/isp1/regs.h | 1582 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1201 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 131 ++ 16 files changed, 8211 insertions(+) create mode 100644 drivers/media/platform/rockchip/isp1/Makefile create mode 100644 drivers/media/platform/rockchip/isp1/capture.c create mode 100644 drivers/media/platform/rockchip/isp1/capture.h create mode 100644 drivers/media/platform/rockchip/isp1/common.h create mode 100644 drivers/media/platform/rockchip/isp1/dev.c create mode 100644 drivers/media/platform/rockchip/isp1/dev.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h create mode 100644 drivers/media/platform/rockchip/isp1/regs.c create mode 100644 drivers/media/platform/rockchip/isp1/regs.h create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.hdrivers/media/platform/Kconfig +10
-0@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS select VIDEOBUF2_DMA_SG select V4L2_FWNODE +config VIDEO_ROCKCHIP_ISP1 + tristate "Rockchip Image Signal Processing v1 Unit driver" + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API + depends on ARCH_ROCKCHIP || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + default n + ---help--- + Support for ISP1 on the rockchip SoC. + config VIDEO_S3C_CAMIF tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver" depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_APIdrivers/media/platform/Makefile +1
-0@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1) += rcar_fdp1.o obj-$(CONFIG_VIDEO_RENESAS_JPU) += rcar_jpu.o obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += rockchip/isp1/ obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip/rga/ obj-y += omap/drivers/media/platform/rockchip/isp1/Makefile new file +7
-0@@ -0,0 +1,7 @@ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += video_rkisp1.o +video_rkisp1-objs += rkisp1.o \ + dev.o \ + regs.o \ + isp_stats.o \ + isp_params.o \ + capture.odrivers/media/platform/rockchip/isp1/capture.c new file +0
-0@@ -0,0 +1,1684 @@
<snip>
Quoted 15 lines
drivers/media/platform/rockchip/isp1/capture.c new file +15
-0+static void rkisp1_destroy_dummy_buf (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; +struct rkisp1_device *dev = stream->ispdev; + +dma_free_coherent (dev->dev, dummy_buf->size, + dummy_buf->vaddr, dummy_buf->dma_addr); +} + +static void rkisp1_stop_streaming (struct vb2_queue *queue) +{ +struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_vdev_node *node = &stream->vnode; +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
drivers/media/platform/rockchip/isp1/capture.c line 1117
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+struct rkisp1_buffer *buf; +unsigned long lock_flags =0 ; +int ret; + +rkisp1_stream_stop (stream); +/* call to the other devices */ +media_pipeline_stop (&node->vdev.entity); + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ;
Shouldn't it release buffers in this error case as well? It's generally a bad design if a close/release/stop-like function can return an error, after all, what should you do with that?
Quoted 13 lines
drivers/media/platform/rockchip/isp1/capture.c new file +13
-0+ +/* release buffers */ +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +if (stream->curr_buf) { +list_add_tail (&stream->curr_buf->queue, &stream->buf_queue); + stream->curr_buf =NULL ; + } +if (stream->next_buf) { +list_add_tail (&stream->next_buf->queue, &stream->buf_queue); + stream->next_buf =NULL ; + } +while (!list_empty (&stream->buf_queue)) { + buf = list_first_entry(&stream->buf_queue,
drivers/media/platform/rockchip/isp1/capture.c line 1140
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ struct rkisp1_buffer, queue); +list_del (&buf->queue); +vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_ERROR ); + } +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); + + ret = dev->pipe.close (&dev->pipe); +if (ret <0 ) { +v4l2_err (v4l2_dev,"pipeline close failed error:%d\n" , ret); +return ;
Same here, are you sure you can skip the rkisp1_destroy_dummy_buf call here?
Quoted 28 lines
drivers/media/platform/rockchip/isp1/capture.c new file +28
-0+ } + +rkisp1_destroy_dummy_buf (stream); +} + +static int rkisp1_stream_start (struct rkisp1_stream *stream) +{ +struct v4l2_device *v4l2_dev = &stream->ispdev->v4l2_dev; +int ret; + + ret =rkisp1_config_rsz (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"config rsz failed with error %d\n" , ret); +return ret; + } + + ret =rkisp1_config_dcrop (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"config dcrop failed with error %d\n" , ret); +return ret; + } + +return rkisp1_start (stream); +} + +static int +rkisp1_start_streaming (struct vb2_queue *queue,unsigned int count) +{
drivers/media/platform/rockchip/isp1/capture.c line 1178
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_vdev_node *node = &stream->vnode; +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +int ret; + +if (stream->state !=RKISP1_STATE_READY ) { +v4l2_err (v4l2_dev,"stream %d in bad state(%d) for streaming\n" , + stream->id, stream->state); +return -EBUSY ;
This feels like more of a WARN_ON to me. It should never happen, right?
drivers/media/platform/rockchip/isp1/capture.c line 1183
Quoted 5 lines
drivers/media/platform/rockchip/isp1/capture.c new file +5
-0+ } + + ret =rkisp1_create_dummy_buf (stream); +if (ret <0 ) +return ret;
If start_streaming fails, then you need to return all buffers back to vb2 with vb2_buffer_done(..., VB2_BUF_STATE_QUEUED). Just like in stop_streaming, but with a different state. So please check all the error paths in this function.
Quoted 203 lines
drivers/media/platform/rockchip/isp1/capture.c new file +203
-0+ +/* enable clocks/power-domains */ + ret = dev->pipe.open (&dev->pipe, &node->vdev.entity, true); +if (ret <0 ) { +v4l2_err (v4l2_dev,"open cif pipeline failed %d\n" , ret); + goto destroy_dummy_buf; + } + +/* configure stream hardware to start */ + ret =rkisp1_stream_start (stream); +if (ret <0 ) { +v4l2_err (v4l2_dev,"start streaming failed\n" ); + goto close_pipe; + } + +/* start sub-devices */ + ret = dev->pipe.set_stream (&dev->pipe, true); +if (ret <0 ) + goto stop_stream; + + ret =media_pipeline_start (&node->vdev.entity, &dev->pipe.pipe); +if (ret <0 ) { +v4l2_err (&dev->v4l2_dev,"start pipeline failed %d\n" , ret); + goto pipe_stream_off; + } + +return 0 ; + +pipe_stream_off: + dev->pipe.set_stream (&dev->pipe, false); +stop_stream: +rkisp1_stream_stop (stream); +close_pipe: + dev->pipe.close (&dev->pipe); +destroy_dummy_buf: +rkisp1_destroy_dummy_buf (stream); + +return ret; +} + +static struct vb2_ops rkisp1_vb2_ops = { + .queue_setup = rkisp1_queue_setup, + .buf_queue = rkisp1_buf_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .stop_streaming = rkisp1_stop_streaming, + .start_streaming = rkisp1_start_streaming, +}; + +static int rkisp_init_vb2_queue (struct vb2_queue *q, +struct rkisp1_stream *stream, +enum v4l2_buf_type buf_type) +{ +struct rkisp1_vdev_node *node; + + node =queue_to_node (q); + + q->type = buf_type; + q->io_modes =VB2_MMAP |VB2_DMABUF ; + q->drv_priv = stream; + q->ops = &rkisp1_vb2_ops; + q->mem_ops = &vb2_dma_contig_memops; + q->buf_struct_size =sizeof (struct rkisp1_buffer ); + q->min_buffers_needed =CIF_ISP_REQ_BUFS_MIN ; + q->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + q->lock = &node->vlock; + q->dev = stream->ispdev->dev; + +return vb2_queue_init (q); +} + +static void rkisp1_set_fmt (struct rkisp1_stream *stream, +struct v4l2_pix_format_mplane *pixm, +bool try) +{ +const struct capture_fmt *fmt; +const struct stream_config *config = stream->config; +struct rkisp1_stream *other_stream = + &stream->ispdev->stream[!stream->id]; +unsigned int imagsize =0 ; +unsigned int planes; +u32 xsubs =1 , ysubs =1 ; +int i; + + fmt =find_fmt (stream, pixm->pixelformat); +if (!fmt) + fmt = config->fmts; + +/* do checks on resolution */ + pixm->width =clamp_t (u32, pixm->width, config->min_rsz_width, + config->max_rsz_width); + pixm->height =clamp_t (u32, pixm->height, config->min_rsz_height, + config->max_rsz_height); + pixm->num_planes = fmt->mplanes; + pixm->field =V4L2_FIELD_NONE ; + +/* output full range by default, take effect in isp_params */ +if (!pixm->quantization) + pixm->quantization =V4L2_QUANTIZATION_FULL_RANGE ; +/* can not change quantization when stream-on */ +if (other_stream->state ==RKISP1_STATE_STREAMING ) + pixm->quantization = other_stream->out_fmt.quantization; + +/* calculate size */ +fcc_xysubs (fmt->fourcc, &xsubs, &ysubs); + planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes; +for (i =0 ; i < planes; i++) { +struct v4l2_plane_pix_format *plane_fmt; +int width, height, bytesperline; + + plane_fmt = pixm->plane_fmt + i; + +if (i ==0 ) { + width = pixm->width; + height = pixm->height; + }else { + width = pixm->width / xsubs; + height = pixm->height / ysubs; + } + + bytesperline = width *DIV_ROUND_UP (fmt->bpp[i],8 ); +/* stride is only available for sp stream and y plane */ +if (stream->id !=RKISP1_STREAM_SP || i !=0 || + plane_fmt->bytesperline < bytesperline) + plane_fmt->bytesperline = bytesperline; + + plane_fmt->sizeimage = plane_fmt->bytesperline * height; + + imagsize += plane_fmt->sizeimage; + } + +/* convert to non-MPLANE format. +* it's important since we want to unify none-MPLANE +* and MPLANE. +*/ +if (fmt->mplanes ==1 ) + pixm->plane_fmt[0 ].sizeimage = imagsize; + +if (!try) { + stream->out_isp_fmt = *fmt; + stream->out_fmt = *pixm; + +if (stream->id ==RKISP1_STREAM_SP ) { + stream->u.sp.y_stride = + pixm->plane_fmt[0 ].bytesperline / +DIV_ROUND_UP (fmt->bpp[0 ],8 ); + }else { + stream->u.mp.raw_enable = (fmt->fmt_type ==FMT_BAYER ); + } +v4l2_dbg (1 , rkisp1_debug, &stream->ispdev->v4l2_dev, +"%s: stream: %d req(%d, %d) out(%d, %d)\n" , __func__, + stream->id, pixm->width, pixm->height, + stream->out_fmt.width, stream->out_fmt.height); + +/* set quantization to isp_params */ +rkisp1_configure_isp (NULL ,NULL , pixm->quantization); + } +} + +/************************* v4l2_file_operations***************************/ +void rkisp1_stream_init (struct rkisp1_device *dev,u32 id) +{ +struct rkisp1_stream *stream = &dev->stream[id]; +struct v4l2_pix_format_mplane pixm; + +memset (stream,0 ,sizeof (*stream)); + stream->id = id; + stream->ispdev = dev; + +INIT_LIST_HEAD (&stream->buf_queue); +init_waitqueue_head (&stream->done); +spin_lock_init (&stream->vbq_lock); +if (stream->id ==RKISP1_STREAM_SP ) { + stream->ops = &rkisp1_sp_streams_ops; + stream->config = &rkisp1_sp_stream_config; + }else { + stream->ops = &rkisp1_mp_streams_ops; + stream->config = &rkisp1_mp_stream_config; + } + + stream->state =RKISP1_STATE_READY ; + +memset (&pixm,0 ,sizeof (pixm)); + pixm.pixelformat =V4L2_PIX_FMT_YUYV ; + pixm.width =RKISP1_DEFAULT_WIDTH ; + pixm.height =RKISP1_DEFAULT_HEIGHT ; +rkisp1_set_fmt (stream, &pixm, false); + + stream->dcrop.left =0 ; + stream->dcrop.top =0 ; + stream->dcrop.width =RKISP1_DEFAULT_WIDTH ; + stream->dcrop.height =RKISP1_DEFAULT_HEIGHT ; +} + +static const struct v4l2_file_operations rkisp1_fops = { + .open = v4l2_fh_open, + .release = vb2_fop_release, + .unlocked_ioctl = video_ioctl2, + .poll = vb2_fop_poll, + .mmap = vb2_fop_mmap, +}; + +/*
drivers/media/platform/rockchip/isp1/capture.c line 1396
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+* mp and sp v4l2_ioctl_ops +*/ + +/* keep for compatibility */ +static int rkisp1_enum_input (struct file *file,void *priv, +struct v4l2_input *input) +{ +if (input->index >0 ) +return -EINVAL ; +
Please fill in v4l2_input.
Quoted 108 lines
drivers/media/platform/rockchip/isp1/capture.c new file +108
-0+return 0 ; +} + +static int rkisp1_try_fmt_vid_cap_mplane (struct file *file,void *fh, +struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); + +rkisp1_set_fmt (stream, &f->fmt.pix_mp, true); + +return 0 ; +} + +static int rkisp1_enum_fmt_vid_cap_mplane (struct file *file,void *priv, +struct v4l2_fmtdesc *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); +const struct capture_fmt *fmt =NULL ; + +if (f->index >= stream->config->fmt_size) +return -EINVAL ; + + fmt = &stream->config->fmts[f->index]; + f->pixelformat = fmt->fourcc; + +return 0 ; +} + +static int rkisp1_s_fmt_vid_cap_mplane (struct file *file, +void *priv,struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct video_device *vdev = &stream->vnode.vdev; +struct rkisp1_vdev_node *node =vdev_to_node (vdev); +struct rkisp1_device *dev = stream->ispdev; + +if (vb2_is_busy (&node->buf_queue)) { +v4l2_err (&dev->v4l2_dev,"%s queue busy\n" , __func__); +return -EBUSY ; + } + +rkisp1_set_fmt (stream, &f->fmt.pix_mp, false); + +return 0 ; +} + +static int rkisp1_g_fmt_vid_cap_mplane (struct file *file,void *fh, +struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); + + f->fmt.pix_mp = stream->out_fmt; + +return 0 ; +} + +static int rkisp1_g_selection (struct file *file,void *prv, +struct v4l2_selection *sel) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_rect *dcrop = &stream->dcrop; +struct v4l2_rect *input_win; + + input_win =rkisp1_get_isp_sd_win (&dev->isp_sdev); + +switch (sel->target) { +case V4L2_SEL_TGT_CROP_BOUNDS : + sel->r.width = input_win->width; + sel->r.height = input_win->height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +case V4L2_SEL_TGT_CROP : + sel->r = *dcrop; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static struct v4l2_rect *rkisp1_update_crop (struct rkisp1_stream *stream, +struct v4l2_rect *sel, +const struct v4l2_rect *in) +{ +/* Not crop for MP bayer raw data */ +if (stream->id ==RKISP1_STREAM_MP && + stream->out_isp_fmt.fmt_type ==FMT_BAYER ) { + sel->left =0 ; + sel->top =0 ; + sel->width = in->width; + sel->height = in->height; +return sel; + } + + sel->left =ALIGN (sel->left,2 ); + sel->width =ALIGN (sel->width,2 ); + sel->left =clamp_t (u32, sel->left,0 , + in->width -STREAM_MIN_MP_SP_INPUT_WIDTH ); + sel->top =clamp_t (u32, sel->top,0 , + in->height -STREAM_MIN_MP_SP_INPUT_HEIGHT ); + sel->width =clamp_t (u32, sel->width,STREAM_MIN_MP_SP_INPUT_WIDTH , + in->width - sel->left); + sel->height =clamp_t (u32, sel->height,STREAM_MIN_MP_SP_INPUT_HEIGHT , + in->height - sel->top); +return sel;
drivers/media/platform/rockchip/isp1/capture.c line 1514
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+} + +static int rkisp1_s_selection (struct file *file,void *prv, +struct v4l2_selection *sel) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_rect *dcrop = &stream->dcrop; +const struct v4l2_rect *input_win; +
You probably need a vb2_is_busy() call here. Normally you cannot change the selection while streaming.
Quoted 2,135 lines
drivers/media/platform/rockchip/isp1/capture.c new file +170
-0+ input_win =rkisp1_get_isp_sd_win (&dev->isp_sdev); + +if (sel->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ; + +if (sel->flags !=0 ) +return -EINVAL ; + +if (sel->target ==V4L2_SEL_TGT_CROP ) { + *dcrop = *rkisp1_update_crop (stream, &sel->r, input_win); +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream %d crop(%d,%d)/%dx%d\n" , stream->id, + dcrop->left, dcrop->top, dcrop->width, dcrop->height); + } + +return 0 ; +} + +static int rkisp1_querycap (struct file *file,void *priv, +struct v4l2_capability *cap) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct device *dev = stream->ispdev->dev; + +strlcpy (cap->driver, dev->driver->name,sizeof (cap->driver)); +strlcpy (cap->card, dev->driver->name,sizeof (cap->card)); +snprintf (cap->bus_info,sizeof (cap->bus_info), +"platform:%s" ,dev_name (dev)); + +return 0 ; +} + +static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = { + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_enum_input = rkisp1_enum_input, + .vidioc_try_fmt_vid_cap_mplane = rkisp1_try_fmt_vid_cap_mplane, + .vidioc_enum_fmt_vid_cap_mplane = rkisp1_enum_fmt_vid_cap_mplane, + .vidioc_s_fmt_vid_cap_mplane = rkisp1_s_fmt_vid_cap_mplane, + .vidioc_g_fmt_vid_cap_mplane = rkisp1_g_fmt_vid_cap_mplane, + .vidioc_s_selection = rkisp1_s_selection, + .vidioc_g_selection = rkisp1_g_selection, + .vidioc_querycap = rkisp1_querycap, +}; + +static void rkisp1_unregister_stream_vdev (struct rkisp1_stream *stream) +{ +media_entity_cleanup (&stream->vnode.vdev.entity); +video_unregister_device (&stream->vnode.vdev); +} + +void rkisp1_unregister_stream_vdevs (struct rkisp1_device *dev) +{ +struct rkisp1_stream *mp_stream = &dev->stream[RKISP1_STREAM_MP ]; +struct rkisp1_stream *sp_stream = &dev->stream[RKISP1_STREAM_SP ]; + +rkisp1_unregister_stream_vdev (mp_stream); +rkisp1_unregister_stream_vdev (sp_stream); +} + +static int rkisp1_register_stream_vdev (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +struct video_device *vdev = &stream->vnode.vdev; +struct rkisp1_vdev_node *node; +int ret; + +strlcpy (vdev->name, + stream->id ==RKISP1_STREAM_SP ?SP_VDEV_NAME :MP_VDEV_NAME , +sizeof (vdev->name)); + node =vdev_to_node (vdev); +mutex_init (&node->vlock); + + vdev->ioctl_ops = &rkisp1_v4l2_ioctl_ops; + vdev->release = video_device_release_empty; + vdev->fops = &rkisp1_fops; + vdev->minor =-1 ; + vdev->v4l2_dev = v4l2_dev; + vdev->lock = &node->vlock; + vdev->device_caps =V4L2_CAP_VIDEO_CAPTURE_MPLANE | +V4L2_CAP_STREAMING ; +video_set_drvdata (vdev, stream); + vdev->vfl_dir =VFL_DIR_RX ; + node->pad.flags =MEDIA_PAD_FL_SINK ; + +rkisp_init_vb2_queue (&node->buf_queue, stream, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); + vdev->queue = &node->buf_queue; + + ret =video_register_device (vdev,VFL_TYPE_GRABBER ,-1 ); +if (ret <0 ) { +v4l2_err (v4l2_dev, +"video_register_device failed with error %d\n" , ret); +return ret; + } + + vdev->entity.function =MEDIA_ENT_F_IO_V4L ; + ret =media_entity_pads_init (&vdev->entity,1 , &node->pad); +if (ret <0 ) + goto unreg; + +return 0 ; +unreg: +video_unregister_device (vdev); +return ret; +} + +int rkisp1_register_stream_vdevs (struct rkisp1_device *dev) +{ +struct rkisp1_stream *stream; +int i, j, ret; + +for (i =0 ; i <RKISP1_MAX_STREAM ; i++) { + stream = &dev->stream[i]; + stream->ispdev = dev; + ret =rkisp1_register_stream_vdev (stream); +if (ret <0 ) + goto err; + } + +return 0 ; +err: +for (j =0 ; j < i; j++) { + stream = &dev->stream[j]; +rkisp1_unregister_stream_vdev (stream); + } + +return ret; +} + +/**************** Interrupter Handler ****************/ + +void rkisp1_mi_isr (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +void __iomem *base = stream->ispdev->base_addr; +u32 val; + + stream->ops->clr_frame_end_int (base); +if (stream->ops->is_frame_end_int_masked (base)) { + val =mi_get_masked_int_status (base); +v4l2_err (&dev->v4l2_dev,"icr err: 0x%x\n" , val); + } + +if (stream->stopping) { +/* Make sure stream is actually stopped, whose state +* can be read from the shadow register, before wake_up() +* thread which would immediately free all frame buffers. +* stop_mi() takes effect at the next frame end +* that sync the configurations to shadow regs. +*/ +if (stream->ops->is_stream_stopped (dev->base_addr)) { + stream->stopping = false; + stream->state =RKISP1_STATE_READY ; +wake_up (&stream->done); + }else { + stream->ops->stop_mi (stream); + } + }else { +mi_frame_end (stream); + } +}drivers/media/platform/rockchip/isp1/capture.h new file +194
-0@@ -0,0 +1,194 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_PATH_VIDEO_H +#define _RKISP1_PATH_VIDEO_H + +#include "common.h" + +struct rkisp1_stream ; + +/* +* @fourcc: pixel format +* @mbus_code: pixel format over bus +* @fmt_type: helper filed for pixel format +* @bpp: bits per pixel +* @bayer_pat: bayer patten type +* @cplanes: number of colour planes +* @mplanes: number of stored memory planes +* @uv_swap: if cb cr swaped, for yuv +* @write_format: defines how YCbCr self picture data is written to memory +* @input_format: defines sp input format +* @output_format: defines sp output format +*/ +struct capture_fmt { +u32 fourcc; +u32 mbus_code; +u8 fmt_type; +u8 cplanes; +u8 mplanes; +u8 uv_swap; +u32 write_format; +u32 output_format; +u8 bpp[VIDEO_MAX_PLANES ]; +}; + +enum rkisp1_sp_inp { +RKISP1_SP_INP_ISP , +RKISP1_SP_INP_DMA_SP , +RKISP1_SP_INP_MAX +}; + +struct rkisp1_stream_sp { +int y_stride; +enum rkisp1_sp_inp input_sel; +}; + +struct rkisp1_stream_mp { +bool raw_enable; +}; + +/* Different config between selfpath and mainpath */ +struct stream_config { +const struct capture_fmt *fmts; +int fmt_size; +/* constrains */ +const int max_rsz_width; +const int max_rsz_height; +const int min_rsz_width; +const int min_rsz_height; +/* registers */ +struct { +u32 ctrl; +u32 ctrl_shd; +u32 scale_hy; +u32 scale_hcr; +u32 scale_hcb; +u32 scale_vy; +u32 scale_vc; +u32 scale_lut; +u32 scale_lut_addr; +u32 scale_hy_shd; +u32 scale_hcr_shd; +u32 scale_hcb_shd; +u32 scale_vy_shd; +u32 scale_vc_shd; +u32 phase_hy; +u32 phase_hc; +u32 phase_vy; +u32 phase_vc; +u32 phase_hy_shd; +u32 phase_hc_shd; +u32 phase_vy_shd; +u32 phase_vc_shd; + } rsz; +struct { +u32 ctrl; +u32 yuvmode_mask; +u32 rawmode_mask; +u32 h_offset; +u32 v_offset; +u32 h_size; +u32 v_size; + } dual_crop; +struct { +u32 y_size_init; +u32 cb_size_init; +u32 cr_size_init; +u32 y_base_ad_init; +u32 cb_base_ad_init; +u32 cr_base_ad_init; +u32 y_offs_cnt_init; +u32 cb_offs_cnt_init; +u32 cr_offs_cnt_init; + } mi; +}; + +/* Different reg ops between selfpath and mainpath */ +struct streams_ops { +int (*config_mi)(struct rkisp1_stream *stream); +void (*stop_mi)(struct rkisp1_stream *stream); +void (*enable_mi)(struct rkisp1_stream *stream); +void (*disable_mi)(struct rkisp1_stream *stream); +void (*set_data_path)(void __iomem *base); +void (*clr_frame_end_int)(void __iomem *base); +bool (*is_frame_end_int_masked)(void __iomem *base); +bool (*is_stream_stopped)(void __iomem *base); +}; + +/* +* struct rkisp1_stream - ISP capture video device +* +* @out_isp_fmt: output isp format +* @out_fmt: output buffer size +* @dcrop: coordinates of dual-crop +* +* @vbq_lock: lock to protect buf_queue +* @buf_queue: queued buffer list +* @dummy_buf: dummy space to store dropped data +* +* rkisp1 use shadowsock registers, so it need two buffer at a time +* @curr_buf: the buffer used for current frame +* @next_buf: the buffer used for next frame +*/ +struct rkisp1_stream { +u32 id; +struct rkisp1_device *ispdev; +struct rkisp1_vdev_node vnode; +enum rkisp1_state state; +enum rkisp1_state saved_state; +struct capture_fmt out_isp_fmt; +struct v4l2_pix_format_mplane out_fmt; +struct v4l2_rect dcrop; +struct streams_ops *ops; +struct stream_config *config; +spinlock_t vbq_lock; +struct list_head buf_queue; +struct rkisp1_dummy_buffer dummy_buf; +struct rkisp1_buffer *curr_buf; +struct rkisp1_buffer *next_buf; +bool stopping; +wait_queue_head_t done; +union { +struct rkisp1_stream_sp sp; +struct rkisp1_stream_mp mp; + } u; +}; + +void rkisp1_unregister_stream_vdevs (struct rkisp1_device *dev); +int rkisp1_register_stream_vdevs (struct rkisp1_device *dev); +void rkisp1_mi_isr (struct rkisp1_stream *stream); +void rkisp1_stream_init (struct rkisp1_device *dev,u32 id); + +#endif /* _RKISP1_PATH_VIDEO_H */ drivers/media/platform/rockchip/isp1/common.h new file +137
-0@@ -0,0 +1,137 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_COMMON_H +#define _RKISP1_COMMON_H + +#include <linux/mutex.h> +#include <media/media-device.h> +#include <media/media-entity.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/videobuf2-v4l2.h> + +#define RKISP1_DEFAULT_WIDTH 800 +#define RKISP1_DEFAULT_HEIGHT 600 + +#define RKISP1_MAX_STREAM 2 +#define RKISP1_STREAM_SP 0 +#define RKISP1_STREAM_MP 1 + +#define RKISP1_PLANE_Y 0 +#define RKISP1_PLANE_CB 1 +#define RKISP1_PLANE_CR 2 + +enum rkisp1_sd_type { +RKISP1_SD_SENSOR , +RKISP1_SD_PHY_CSI , +RKISP1_SD_VCM , +RKISP1_SD_FLASH , +RKISP1_SD_MAX , +}; + +/* One structure per video node */ +struct rkisp1_vdev_node { +struct vb2_queue buf_queue; +/* vfd lock */ +struct mutex vlock; +struct video_device vdev; +struct media_pad pad; +}; + +enum rkisp1_fmt_pix_type { +FMT_YUV , +FMT_RGB , +FMT_BAYER , +FMT_JPEG , +FMT_MAX +}; + +enum rkisp1_fmt_raw_pat_type { +RAW_RGGB =0 , +RAW_GRBG , +RAW_GBRG , +RAW_BGGR , +}; + +enum rkisp1_state { +/* path not yet opened: */ +RKISP1_STATE_DISABLED , +/* path opened and configured, ready for streaming: */ +RKISP1_STATE_READY , +/* path is streaming: */ +RKISP1_STATE_STREAMING +}; + +struct rkisp1_buffer { +struct vb2_v4l2_buffer vb; +struct list_head queue; +union { +u32 buff_addr[VIDEO_MAX_PLANES ]; +void *vaddr[VIDEO_MAX_PLANES ]; + }; +}; + +struct rkisp1_dummy_buffer { +void *vaddr; +dma_addr_t dma_addr; +u32 size; +}; + +extern int rkisp1_debug; + +static inline +struct rkisp1_vdev_node *vdev_to_node (struct video_device *vdev) +{ + return container_of(vdev, struct rkisp1_vdev_node, vdev); +} + +static inline struct rkisp1_vdev_node *queue_to_node (struct vb2_queue *q) +{ + return container_of(q, struct rkisp1_vdev_node, buf_queue); +} + +static inline struct rkisp1_buffer *to_rkisp1_buffer (struct vb2_v4l2_buffer *vb) +{ + return container_of(vb, struct rkisp1_buffer, vb); +} + +static inline struct vb2_queue *to_vb2_queue (struct file *file) +{ +struct rkisp1_vdev_node *vnode =video_drvdata (file); + +return &vnode->buf_queue; +} + +#endif /* _RKISP1_COMMON_H */ drivers/media/platform/rockchip/isp1/dev.c new file +655
-0@@ -0,0 +1,655 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_graph.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/pinctrl/consumer.h> +#include "common.h" +#include "regs.h" + +struct isp_match_data { +const char *const *clks; +int size; +}; + +int rkisp1_debug; +module_param_named (debug, rkisp1_debug, int,0644 ); +MODULE_PARM_DESC (debug,"Debug level (0-1)" ); + +/***************************** pipeline operations*******************************/ + +static int __isp_pipeline_prepare (struct rkisp1_pipeline *p, +struct media_entity *me) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +struct v4l2_subdev *sd; +int i; + + p->num_subdevs =0 ; +memset (p->subdevs,0 ,sizeof (p->subdevs)); + +while (1 ) { +struct media_pad *pad =NULL ; + +/* Find remote source pad */ +for (i =0 ; i < me->num_pads; i++) { +struct media_pad *spad = &me->pads[i]; + +if (!(spad->flags &MEDIA_PAD_FL_SINK )) +continue ; + pad =media_entity_remote_pad (spad); +if (pad) +break ; + } + +if (!pad) +break ; + + sd =media_entity_to_v4l2_subdev (pad->entity); +if (sd != &dev->isp_sdev.sd) + p->subdevs[p->num_subdevs++] = sd; + + me = &sd->entity; +if (me->num_pads ==1 ) +break ; + } +return 0 ; +} + +static int __subdev_set_power (struct v4l2_subdev *sd,int on) +{ +int ret; + +if (!sd) +return -ENXIO ; + + ret =v4l2_subdev_call (sd, core, s_power, on); + +return ret != -ENOIOCTLCMD ? ret :0 ; +} + +static int __isp_pipeline_s_power (struct rkisp1_pipeline *p,bool on) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +int i, ret; + +if (on) { +__subdev_set_power (&dev->isp_sdev.sd, true); + +for (i = p->num_subdevs -1 ; i >=0 ; --i) { + ret =__subdev_set_power (p->subdevs[i], true); +if (ret <0 && ret != -ENXIO ) + goto err_power_off; + } + }else { +for (i =0 ; i < p->num_subdevs; ++i) +__subdev_set_power (p->subdevs[i], false); + +__subdev_set_power (&dev->isp_sdev.sd, false); + } + +return 0 ; + +err_power_off: +for (++i; i < p->num_subdevs; ++i) +__subdev_set_power (p->subdevs[i], false); +__subdev_set_power (&dev->isp_sdev.sd, true); +return ret; +} + +static int rkisp1_pipeline_open (struct rkisp1_pipeline *p, +struct media_entity *me, +bool prepare) +{ +int ret; + +if (WARN_ON (!p || !me)) +return -EINVAL ; +if (atomic_inc_return (&p->power_cnt) >1 ) +return 0 ; + +/* go through media graphic and get subdevs */ +if (prepare) +__isp_pipeline_prepare (p, me); + +if (!p->num_subdevs) +return -EINVAL ; + + ret =__isp_pipeline_s_power (p,1 ); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int rkisp1_pipeline_close (struct rkisp1_pipeline *p) +{ +int ret; + +if (atomic_dec_return (&p->power_cnt) >0 ) +return 0 ; + ret =__isp_pipeline_s_power (p,0 ); + +return ret == -ENXIO ?0 : ret; +} + +/* +* stream-on order: isp_subdev, mipi dphy, sensor +* stream-off order: mipi dphy, sensor, isp_subdev +*/ +static int rkisp1_pipeline_set_stream (struct rkisp1_pipeline *p,bool on) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +int i, ret; + +if ((on &&atomic_inc_return (&p->stream_cnt) >1 ) || + (!on &&atomic_dec_return (&p->stream_cnt) >0 )) +return 0 ; + +if (on) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, true); + +/* phy -> sensor */ +for (i =0 ; i < p->num_subdevs; ++i) { + ret =v4l2_subdev_call (p->subdevs[i], video, s_stream, on); +if (on && ret <0 && ret != -ENOIOCTLCMD && ret != -ENODEV ) + goto err_stream_off; + } + +if (!on) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, false); + +return 0 ; + +err_stream_off: +for (--i; i >=0 ; --i) +v4l2_subdev_call (p->subdevs[i], video, s_stream, false); +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, false); +return ret; +} + +/***************************** media controller *******************************/ +/* See http://opensource.rock-chips.com/wiki_Rockchip-isp1 for Topology */ + +static int rkisp1_create_links (struct rkisp1_device *dev) +{ +struct media_entity *source, *sink; +unsigned int flags, s, pad; +int ret; + +/* sensor links(or mipi-phy) */ +for (s =0 ; s < dev->num_sensors; ++s) { +struct rkisp1_sensor_info *sensor = &dev->sensors[s]; + +for (pad =0 ; pad < sensor->sd->entity.num_pads; pad++) +if (sensor->sd->entity.pads[pad].flags & +MEDIA_PAD_FL_SOURCE ) +break ; + +if (pad == sensor->sd->entity.num_pads) { +dev_err (dev->dev, +"failed to find src pad for %s\n" , + sensor->sd->name); + +return -ENXIO ; + } + + ret =media_create_pad_link ( + &sensor->sd->entity, pad, + &dev->isp_sdev.sd.entity, +RKISP1_ISP_PAD_SINK + s, + s ?0 :MEDIA_LNK_FL_ENABLED ); +if (ret) { +dev_err (dev->dev, +"failed to create link for %s\n" , + sensor->sd->name); +return ret; + } + } + +/* params links */ + source = &dev->params_vdev.vnode.vdev.entity; + sink = &dev->isp_sdev.sd.entity; + flags =MEDIA_LNK_FL_ENABLED ; + ret =media_create_pad_link (source,0 , sink, +RKISP1_ISP_PAD_SINK_PARAMS , flags); +if (ret <0 ) +return ret; + +/* create isp internal links */ +/* SP links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stream[RKISP1_STREAM_SP ].vnode.vdev.entity; + ret =media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_PATH , + sink,0 , flags); +if (ret <0 ) +return ret; + +/* MP links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stream[RKISP1_STREAM_MP ].vnode.vdev.entity; + ret =media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_PATH , + sink,0 , flags); +if (ret <0 ) +return ret; + +/* 3A stats links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stats_vdev.vnode.vdev.entity; +return media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_STATS , + sink,0 , flags); +} + +static int subdev_notifier_complete (struct v4l2_async_notifier *notifier) +{ +struct rkisp1_device *dev; +int ret; + + dev = container_of(notifier, struct rkisp1_device, notifier); + +mutex_lock (&dev->media_dev.graph_mutex); + ret =rkisp1_create_links (dev); +if (ret <0 ) + goto unlock; + ret =v4l2_device_register_subdev_nodes (&dev->v4l2_dev); +if (ret <0 ) + goto unlock; + +v4l2_info (&dev->v4l2_dev,"Async subdev notifier completed\n" ); + +unlock: +mutex_unlock (&dev->media_dev.graph_mutex); +return ret; +} + +struct rkisp1_async_subdev { +struct v4l2_async_subdev asd; +struct v4l2_mbus_config mbus; +}; + +static int subdev_notifier_bound (struct v4l2_async_notifier *notifier, +struct v4l2_subdev *subdev, +struct v4l2_async_subdev *asd) +{ +struct rkisp1_device *isp_dev =container_of (notifier, + struct rkisp1_device, notifier); +struct rkisp1_async_subdev *s_asd =container_of (asd, + struct rkisp1_async_subdev, asd); + +if (isp_dev->num_sensors ==ARRAY_SIZE (isp_dev->sensors)) +return -EBUSY ; + + isp_dev->sensors[isp_dev->num_sensors].mbus = s_asd->mbus; + isp_dev->sensors[isp_dev->num_sensors].sd = subdev; + ++isp_dev->num_sensors; + +v4l2_dbg (1 , rkisp1_debug, subdev,"Async registered subdev\n" ); + +return 0 ; +} + +static int rkisp1_fwnode_parse (struct device *dev, +struct v4l2_fwnode_endpoint *vep, +struct v4l2_async_subdev *asd) +{ +struct rkisp1_async_subdev *rk_asd = + container_of(asd, struct rkisp1_async_subdev, asd); +struct v4l2_fwnode_bus_parallel *bus = &vep->bus.parallel; + +/* +* MIPI sensor is linked with a mipi dphy and its media bus config can +* not be get in here +*/ +if (vep->bus_type !=V4L2_MBUS_BT656 && + vep->bus_type !=V4L2_MBUS_PARALLEL ) +return 0 ; + + rk_asd->mbus.flags = bus->flags; + rk_asd->mbus.type = vep->bus_type; + +return 0 ; +} + +static const struct v4l2_async_notifier_operations subdev_notifier_ops = { + .bound = subdev_notifier_bound, + .complete = subdev_notifier_complete, +}; + +static int isp_subdev_notifier (struct rkisp1_device *isp_dev) +{ +struct v4l2_async_notifier *ntf = &isp_dev->notifier; +struct device *dev = isp_dev->dev; +int ret; + + ret =v4l2_async_notifier_parse_fwnode_endpoints ( + dev, ntf,sizeof (struct rkisp1_async_subdev ), + rkisp1_fwnode_parse); +if (ret <0 ) +return ret; + +if (!ntf->num_subdevs) +return -ENODEV ;/* no endpoint */ + + ntf->ops = &subdev_notifier_ops; + +return v4l2_async_notifier_register (&isp_dev->v4l2_dev, ntf); +} + +/***************************** platform deive *******************************/ + +static int rkisp1_register_platform_subdevs (struct rkisp1_device *dev) +{ +int ret; + + ret =rkisp1_register_isp_subdev (dev, &dev->v4l2_dev); +if (ret <0 ) +return ret; + + ret =rkisp1_register_stream_vdevs (dev); +if (ret <0 ) + goto err_unreg_isp_subdev; + + ret =rkisp1_register_stats_vdev (&dev->stats_vdev, &dev->v4l2_dev, dev); +if (ret <0 ) + goto err_unreg_stream_vdev; + + ret =rkisp1_register_params_vdev (&dev->params_vdev, &dev->v4l2_dev, + dev); +if (ret <0 ) + goto err_unreg_stats_vdev; + + ret =isp_subdev_notifier (dev); +if (ret <0 ) { +v4l2_err (&dev->v4l2_dev, +"Failed to register subdev notifier(%d)\n" , ret); + goto err_unreg_params_vdev; + } + +return 0 ; +err_unreg_params_vdev: +rkisp1_unregister_params_vdev (&dev->params_vdev); +err_unreg_stats_vdev: +rkisp1_unregister_stats_vdev (&dev->stats_vdev); +err_unreg_stream_vdev: +rkisp1_unregister_stream_vdevs (dev); +err_unreg_isp_subdev: +rkisp1_unregister_isp_subdev (dev); +return ret; +} + +static const char *const rk3399_isp_clks[] = { +"clk_isp" , +"aclk_isp" , +"hclk_isp" , +"aclk_isp_wrap" , +"hclk_isp_wrap" , +}; + +static const char *const rk3288_isp_clks[] = { +"clk_isp" , +"aclk_isp" , +"hclk_isp" , +"pclk_isp_in" , +"sclk_isp_jpe" , +}; + +static const struct isp_match_data rk3288_isp_clk_data = { + .clks = rk3288_isp_clks, + .size =ARRAY_SIZE (rk3288_isp_clks), +}; + +static const struct isp_match_data rk3399_isp_clk_data = { + .clks = rk3399_isp_clks, + .size =ARRAY_SIZE (rk3399_isp_clks), +}; + +static const struct of_device_id rkisp1_plat_of_match[] = { + { + .compatible ="rockchip,rk3288-cif-isp" , + .data = &rk3288_isp_clk_data, + }, { + .compatible ="rockchip,rk3399-cif-isp" , + .data = &rk3399_isp_clk_data, + }, + {}, +}; + +static irqreturn_t rkisp1_irq_handler (int irq,void *cntxt) +{ +struct device *dev = cntxt; +struct rkisp1_device *rkisp1_dev =dev_get_drvdata (dev); +void __iomem *base = rkisp1_dev->base_addr; +unsigned int mis_val, i; + + mis_val =readl (rkisp1_dev->base_addr +CIF_ISP_MIS ); +if (mis_val) +rkisp1_isp_isr (mis_val, rkisp1_dev); + + mis_val =readl (rkisp1_dev->base_addr +CIF_MIPI_MIS ); +if (mis_val) +rkisp1_mipi_isr (mis_val, rkisp1_dev); + +for (i =0 ; i <RKISP1_MAX_STREAM ; ++i) { +struct rkisp1_stream *stream = &rkisp1_dev->stream[i]; + +if (stream->ops->is_frame_end_int_masked (base)) +rkisp1_mi_isr (stream); + } + +clr_all_int (base); + +return IRQ_HANDLED ; +} + +static void rkisp1_disable_sys_clk (struct rkisp1_device *rkisp1_dev) +{ +int i; + +for (i = rkisp1_dev->clk_size -1 ; i >=0 ; i--) +clk_disable_unprepare (rkisp1_dev->clks[i]); +} + +static int rkisp1_enable_sys_clk (struct rkisp1_device *rkisp1_dev) +{ +int i, ret = -EINVAL ; + +for (i =0 ; i < rkisp1_dev->clk_size; i++) { + ret =clk_prepare_enable (rkisp1_dev->clks[i]); +if (ret <0 ) + goto err; + } +return 0 ; +err: +for (--i; i >=0 ; --i) +clk_disable_unprepare (rkisp1_dev->clks[i]); +return ret; +} + +static int rkisp1_plat_probe (struct platform_device *pdev) +{ +const struct of_device_id *match; +struct device_node *node = pdev->dev.of_node; +struct device *dev = &pdev->dev; +struct v4l2_device *v4l2_dev; +struct rkisp1_device *isp_dev; +const struct isp_match_data *clk_data; + +struct resource *res; +int i, ret, irq; + + match =of_match_node (rkisp1_plat_of_match, node); + isp_dev =devm_kzalloc (dev,sizeof (*isp_dev),GFP_KERNEL ); +if (!isp_dev) +return -ENOMEM ; + +dev_set_drvdata (dev, isp_dev); + isp_dev->dev = dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + isp_dev->base_addr =devm_ioremap_resource (dev, res); +if (IS_ERR (isp_dev->base_addr)) +return PTR_ERR (isp_dev->base_addr); + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_irq (dev, irq, rkisp1_irq_handler,IRQF_SHARED , +dev_driver_string (dev), dev); +if (ret <0 ) { +dev_err (dev,"request irq failed: %d\n" , ret); +return ret; + } + + isp_dev->irq = irq; + clk_data = match->data; +for (i =0 ; i < clk_data->size; i++) { +struct clk *clk =devm_clk_get (dev, clk_data->clks[i]); + +if (IS_ERR (clk)) { +dev_err (dev,"failed to get %s\n" , clk_data->clks[i]); +return PTR_ERR (clk); + } + isp_dev->clks[i] = clk; + } + isp_dev->clk_size = clk_data->size; + +atomic_set (&isp_dev->pipe.power_cnt,0 ); +atomic_set (&isp_dev->pipe.stream_cnt,0 ); + isp_dev->pipe.open = rkisp1_pipeline_open; + isp_dev->pipe.close = rkisp1_pipeline_close; + isp_dev->pipe.set_stream = rkisp1_pipeline_set_stream; + +rkisp1_stream_init (isp_dev,RKISP1_STREAM_SP ); +rkisp1_stream_init (isp_dev,RKISP1_STREAM_MP ); + +strlcpy (isp_dev->media_dev.model,"rkisp1" , +sizeof (isp_dev->media_dev.model)); + isp_dev->media_dev.dev = &pdev->dev; +media_device_init (&isp_dev->media_dev); + + v4l2_dev = &isp_dev->v4l2_dev; + v4l2_dev->mdev = &isp_dev->media_dev; +strlcpy (v4l2_dev->name,"rkisp1" ,sizeof (v4l2_dev->name)); +v4l2_ctrl_handler_init (&isp_dev->ctrl_handler,5 ); + v4l2_dev->ctrl_handler = &isp_dev->ctrl_handler; + + ret =v4l2_device_register (isp_dev->dev, &isp_dev->v4l2_dev); +if (ret <0 ) +return ret; + + ret =media_device_register (&isp_dev->media_dev); +if (ret <0 ) { +v4l2_err (v4l2_dev,"Failed to register media device: %d\n" , + ret); + goto err_unreg_v4l2_dev; + } + +/* create & register platefom subdev (from of_node) */ + ret =rkisp1_register_platform_subdevs (isp_dev); +if (ret <0 ) + goto err_unreg_media_dev; + +pm_runtime_enable (&pdev->dev); + +return 0 ; + +err_unreg_media_dev: +media_device_unregister (&isp_dev->media_dev); +err_unreg_v4l2_dev: +v4l2_device_unregister (&isp_dev->v4l2_dev); +return ret; +} + +static int rkisp1_plat_remove (struct platform_device *pdev) +{ +struct rkisp1_device *isp_dev =platform_get_drvdata (pdev); + +pm_runtime_disable (&pdev->dev); +media_device_unregister (&isp_dev->media_dev); +v4l2_device_unregister (&isp_dev->v4l2_dev); +rkisp1_unregister_params_vdev (&isp_dev->params_vdev); +rkisp1_unregister_stats_vdev (&isp_dev->stats_vdev); +rkisp1_unregister_stream_vdevs (isp_dev); +rkisp1_unregister_isp_subdev (isp_dev); + +return 0 ; +} + +static int __maybe_unused rkisp1_runtime_suspend (struct device *dev) +{ +struct rkisp1_device *isp_dev =dev_get_drvdata (dev); + +rkisp1_disable_sys_clk (isp_dev); +return pinctrl_pm_select_sleep_state (dev); +} + +static int __maybe_unused rkisp1_runtime_resume (struct device *dev) +{ +struct rkisp1_device *isp_dev =dev_get_drvdata (dev); +int ret; + + ret =pinctrl_pm_select_default_state (dev); +if (ret <0 ) +return ret; +rkisp1_enable_sys_clk (isp_dev); + +return 0 ; +} + +static const struct dev_pm_ops rkisp1_plat_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) +SET_RUNTIME_PM_OPS (rkisp1_runtime_suspend, rkisp1_runtime_resume,NULL ) +}; + +static struct platform_driver rkisp1_plat_drv = { + .driver = { + .name =DRIVER_NAME , + .of_match_table =of_match_ptr (rkisp1_plat_of_match), + .pm = &rkisp1_plat_pm_ops, + }, + .probe = rkisp1_plat_probe, + .remove = rkisp1_plat_remove, +}; + +module_platform_driver (rkisp1_plat_drv); +MODULE_AUTHOR ("Rockchip Camera/ISP team" ); +MODULE_DESCRIPTION ("Rockchip ISP1 platform driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );drivers/media/platform/rockchip/isp1/dev.h new file +120
-0@@ -0,0 +1,120 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_DEV_H +#define _RKISP1_DEV_H + +#include "capture.h" +#include "rkisp1.h" +#include "isp_params.h" +#include "isp_stats.h" + +#define DRIVER_NAME "rkisp1" +#define ISP_VDEV_NAME DRIVER_NAME "_ispdev" +#define SP_VDEV_NAME DRIVER_NAME "_selfpath" +#define MP_VDEV_NAME DRIVER_NAME "_mainpath" +#define DMA_VDEV_NAME DRIVER_NAME "_dmapath" + +#define GRP_ID_SENSOR BIT(0) +#define GRP_ID_MIPIPHY BIT(1) +#define GRP_ID_ISP BIT(2) +#define GRP_ID_ISP_MP BIT(3) +#define GRP_ID_ISP_SP BIT(4) + +#define RKISP1_MAX_BUS_CLK 8 +#define RKISP1_MAX_SENSOR 2 +#define RKISP1_MAX_PIPELINE 4 + +/* +* struct rkisp1_pipeline - An ISP hardware pipeline +* +* Capture device call other devices via pipeline +* +* @num_subdevs: number of linked subdevs +* @power_cnt: pipeline power count +* @stream_cnt: stream power count +*/ +struct rkisp1_pipeline { +struct media_pipeline pipe; +int num_subdevs; +atomic_t power_cnt; +atomic_t stream_cnt; +struct v4l2_subdev *subdevs[RKISP1_MAX_PIPELINE ]; +int (*open)(struct rkisp1_pipeline *p, +struct media_entity *me,bool prepare); +int (*close)(struct rkisp1_pipeline *p); +int (*set_stream)(struct rkisp1_pipeline *p,bool on); +}; + +/* +* struct rkisp1_sensor_info - Sensor infomations +* @mbus: media bus configuration +*/ +struct rkisp1_sensor_info { +struct v4l2_subdev *sd; +struct v4l2_mbus_config mbus; +}; + +/* +* struct rkisp1_device - ISP platform device +* @base_addr: base register address +* @active_sensor: sensor in-use, set when streaming on +* @isp_sdev: ISP sub-device +* @rkisp1_stream: capture video device +* @stats_vdev: ISP statistics output device +* @params_vdev: ISP input parameters device +*/ +struct rkisp1_device { +void __iomem *base_addr; +int irq; +struct device *dev; +struct clk *clks[RKISP1_MAX_BUS_CLK ]; +int clk_size; +struct v4l2_device v4l2_dev; +struct v4l2_ctrl_handler ctrl_handler; +struct media_device media_dev; +struct v4l2_async_notifier notifier; +struct v4l2_subdev *subdevs[RKISP1_SD_MAX ]; +struct rkisp1_sensor_info *active_sensor; +struct rkisp1_sensor_info sensors[RKISP1_MAX_SENSOR ]; +int num_sensors; +struct rkisp1_isp_subdev isp_sdev; +struct rkisp1_stream stream[RKISP1_MAX_STREAM ]; +struct rkisp1_isp_stats_vdev stats_vdev; +struct rkisp1_isp_params_vdev params_vdev; +struct rkisp1_pipeline pipe; +struct vb2_alloc_ctx *alloc_ctx; +}; + +#endif drivers/media/platform/rockchip/isp1/isp_params.c new file +829
-0@@ -0,0 +1,1543 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/videobuf2-core.h> +#include <media/videobuf2-vmalloc.h> /* for ISP params */ +#include "dev.h" +#include "regs.h" + +#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2 +#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8 + +#define BLS_START_H_MAX_IS_VALID (val) ((val) < CIFISP_BLS_START_H_MAX) +#define BLS_STOP_H_MAX_IS_VALID (val) ((val) < CIFISP_BLS_STOP_H_MAX) + +#define BLS_START_V_MAX_IS_VALID (val) ((val) < CIFISP_BLS_START_V_MAX) +#define BLS_STOP_V_MAX_IS_VALID (val) ((val) < CIFISP_BLS_STOP_V_MAX) + +#define BLS_SAMPLE_MAX_IS_VALID (val) ((val) < CIFISP_BLS_SAMPLES_MAX) + +#define BLS_FIX_SUB_IS_VALID (val) \ + ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX) + +#define RKISP1_ISP_DPCC_LINE_THRESH (n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_LINE_MAD_FAC (n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_PG_FAC (n) (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_RND_THRESH (n) (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_RG_FAC (n) (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_CC_COEFF (n) (CIF_ISP_CC_COEFF_0 + (n) * 4) + +static inline void rkisp1_iowrite32 (struct rkisp1_isp_params_vdev *params_vdev, +u32 value,u32 addr) +{ +iowrite32 (value, params_vdev->dev->base_addr + addr); +} + +static inline u32 rkisp1_ioread32 (struct rkisp1_isp_params_vdev *params_vdev, +u32 addr) +{ +return ioread32 (params_vdev->dev->base_addr + addr); +} + +static inline void isp_param_set_bits (struct rkisp1_isp_params_vdev + *params_vdev, +u32 reg,u32 bit_mask) +{ +u32 val; + + val =rkisp1_ioread32 (params_vdev, reg); +rkisp1_iowrite32 (params_vdev, val | bit_mask, reg); +} + +static inline void isp_param_clear_bits (struct rkisp1_isp_params_vdev + *params_vdev, +u32 reg,u32 bit_mask) +{ +u32 val; + + val =rkisp1_ioread32 (params_vdev, reg); +rkisp1_iowrite32 (params_vdev, val & ~bit_mask, reg); +} + +/* ISP BP interface function */ +static void dpcc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpcc_config *arg) +{ +unsigned int i; + +rkisp1_iowrite32 (params_vdev, arg->mode,CIF_ISP_DPCC_MODE ); +rkisp1_iowrite32 (params_vdev, arg->output_mode, +CIF_ISP_DPCC_OUTPUT_MODE ); +rkisp1_iowrite32 (params_vdev, arg->set_use,CIF_ISP_DPCC_SET_USE ); + +rkisp1_iowrite32 (params_vdev, arg->methods[0 ].method, +CIF_ISP_DPCC_METHODS_SET_1 ); +rkisp1_iowrite32 (params_vdev, arg->methods[1 ].method, +CIF_ISP_DPCC_METHODS_SET_2 ); +rkisp1_iowrite32 (params_vdev, arg->methods[2 ].method, +CIF_ISP_DPCC_METHODS_SET_3 ); +for (i =0 ; i <CIFISP_DPCC_METHODS_MAX ; i++) { +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_thresh, +RKISP1_ISP_DPCC_LINE_THRESH (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_mad_fac, +RKISP1_ISP_DPCC_LINE_MAD_FAC (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].pg_fac, +RKISP1_ISP_DPCC_PG_FAC (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rnd_thresh, +RKISP1_ISP_DPCC_RND_THRESH (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rg_fac, +RKISP1_ISP_DPCC_RG_FAC (i)); + } + +rkisp1_iowrite32 (params_vdev, arg->rnd_offs,CIF_ISP_DPCC_RND_OFFS ); +rkisp1_iowrite32 (params_vdev, arg->ro_limits,CIF_ISP_DPCC_RO_LIMITS ); +} + +/* ISP black level subtraction interface function */ +static void bls_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_bls_config *arg) +{ +u32 new_control =0 ; + +/* fixed subtraction values */ +if (!arg->enable_auto) { +const struct cifisp_bls_fixed_val *pval = &arg->fixed_val; + +switch (params_vdev->raw_type) { +case RAW_BGGR : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_A_FIXED ); +break ; +case RAW_GBRG : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_B_FIXED ); +break ; +case RAW_GRBG : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_C_FIXED ); +break ; +case RAW_RGGB : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_D_FIXED ); +break ; +default : +break ; + } + + new_control =CIF_ISP_BLS_MODE_FIXED ; + }else { +if (arg->en_windows &BIT (1 )) { +rkisp1_iowrite32 (params_vdev, arg->bls_window2.h_offs, +CIF_ISP_BLS_H2_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.h_size, +CIF_ISP_BLS_H2_STOP ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.v_offs, +CIF_ISP_BLS_V2_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.v_size, +CIF_ISP_BLS_V2_STOP ); + new_control |=CIF_ISP_BLS_WINDOW_2 ; + } + +if (arg->en_windows &BIT (0 )) { +rkisp1_iowrite32 (params_vdev, arg->bls_window1.h_offs, +CIF_ISP_BLS_H1_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.h_size, +CIF_ISP_BLS_H1_STOP ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.v_offs, +CIF_ISP_BLS_V1_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.v_size, +CIF_ISP_BLS_V1_STOP ); + new_control |=CIF_ISP_BLS_WINDOW_1 ; + } + +rkisp1_iowrite32 (params_vdev, arg->bls_samples, +CIF_ISP_BLS_SAMPLES ); + + new_control |=CIF_ISP_BLS_MODE_MEASURED ; + } +rkisp1_iowrite32 (params_vdev, new_control,CIF_ISP_BLS_CTRL ); +} + +/* ISP LS correction interface function */ +static void +__lsc_correct_matrix_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_lsc_config *pconfig) +{ +int i, j; +unsigned int isp_lsc_status, sram_addr, isp_lsc_table_sel; +unsigned int data; + + isp_lsc_status =rkisp1_ioread32 (params_vdev,CIF_ISP_LSC_STATUS ); + +/* CIF_ISP_LSC_TABLE_ADDRESS_153 = ( 17 * 18 ) >> 1 */ + sram_addr = (isp_lsc_status &CIF_ISP_LSC_ACTIVE_TABLE ) ? +CIF_ISP_LSC_TABLE_ADDRESS_0 : +CIF_ISP_LSC_TABLE_ADDRESS_153 ; +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_R_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_GR_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_GB_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_B_TABLE_ADDR ); + +/* program data tables (table size is 9 * 17 = 153) */ +for (i =0 ; i < ((CIF_ISP_LSC_SECTORS_MAX +1 ) * + (CIF_ISP_LSC_SECTORS_MAX +1 )); + i +=CIF_ISP_LSC_SECTORS_MAX +1 ) { +/* +* 17 sectors with 2 values in one DWORD = 9 +* DWORDs (2nd value of last DWORD unused) +*/ +for (j =0 ; j < (CIF_ISP_LSC_SECTORS_MAX +1 ); j +=2 ) { + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->r_data_tbl[i + j], + pconfig->r_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_R_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->gr_data_tbl[i + j], + pconfig->gr_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_GR_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->gb_data_tbl[i + j], + pconfig->gb_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_GB_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->b_data_tbl[i + j], + pconfig->b_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_B_TABLE_DATA ); + } + } + + isp_lsc_table_sel = (isp_lsc_status &CIF_ISP_LSC_ACTIVE_TABLE ) ? +CIF_ISP_LSC_TABLE_0 :CIF_ISP_LSC_TABLE_1 ; +rkisp1_iowrite32 (params_vdev, isp_lsc_table_sel,CIF_ISP_LSC_TABLE_SEL ); +} + +static void lsc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_lsc_config *arg) +{ +int i; +u32 lsc_ctrl; +unsigned int data; + +/* To config must be off , store the current status firstly */ + lsc_ctrl =rkisp1_ioread32 (params_vdev,CIF_ISP_LSC_CTRL ); +isp_param_clear_bits (params_vdev,CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +__lsc_correct_matrix_config (params_vdev, arg); + +for (i =0 ; i <4 ; i++) { +/* program x size tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->x_size_tbl[i *2 ], + arg->x_size_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_XSIZE_01 + i *4 ); + +/* program x grad tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->x_grad_tbl[i *2 ], + arg->x_grad_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_XGRAD_01 + i *4 ); + +/* program y size tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->y_size_tbl[i *2 ], + arg->y_size_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_YSIZE_01 + i *4 ); + +/* program y grad tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->y_grad_tbl[i *2 ], + arg->y_grad_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_YGRAD_01 + i *4 ); + } + +/* restore the bls ctrl status */ +if (lsc_ctrl &CIF_ISP_LSC_CTRL_ENA ) { +isp_param_set_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + }else { +isp_param_clear_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + } +} + +/* ISP Filtering function */ +static void flt_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_flt_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->thresh_bl0,CIF_ISP_FILT_THRESH_BL0 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_bl1,CIF_ISP_FILT_THRESH_BL1 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_sh0,CIF_ISP_FILT_THRESH_SH0 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_sh1,CIF_ISP_FILT_THRESH_SH1 ); +rkisp1_iowrite32 (params_vdev, arg->fac_bl0,CIF_ISP_FILT_FAC_BL0 ); +rkisp1_iowrite32 (params_vdev, arg->fac_bl1,CIF_ISP_FILT_FAC_BL1 ); +rkisp1_iowrite32 (params_vdev, arg->fac_mid,CIF_ISP_FILT_FAC_MID ); +rkisp1_iowrite32 (params_vdev, arg->fac_sh0,CIF_ISP_FILT_FAC_SH0 ); +rkisp1_iowrite32 (params_vdev, arg->fac_sh1,CIF_ISP_FILT_FAC_SH1 ); +rkisp1_iowrite32 (params_vdev, arg->lum_weight,CIF_ISP_FILT_LUM_WEIGHT ); + +rkisp1_iowrite32 (params_vdev, (arg->mode ?CIF_ISP_FLT_MODE_DNR :0 ) | +CIF_ISP_FLT_CHROMA_V_MODE (arg->chr_v_mode) | +CIF_ISP_FLT_CHROMA_H_MODE (arg->chr_h_mode) | +CIF_ISP_FLT_GREEN_STAGE1 (arg->grn_stage1), +CIF_ISP_FILT_MODE ); +} + +/* ISP demosaic interface function */ +static int bdm_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_bdm_config *arg) +{ +/* set demosaic threshold */ +rkisp1_iowrite32 (params_vdev, arg->demosaic_th,CIF_ISP_DEMOSAIC ); +return 0 ; +} + +/* ISP GAMMA correction interface function */ +static void sdg_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_sdg_config *arg) +{ +int i; + +rkisp1_iowrite32 (params_vdev, + arg->xa_pnts.gamma_dx0,CIF_ISP_GAMMA_DX_LO ); +rkisp1_iowrite32 (params_vdev, + arg->xa_pnts.gamma_dx1,CIF_ISP_GAMMA_DX_HI ); + +for (i =0 ; i <CIFISP_DEGAMMA_CURVE_SIZE ; i++) { +rkisp1_iowrite32 (params_vdev, arg->curve_r.gamma_y[i], +CIF_ISP_GAMMA_R_Y0 + i *4 ); +rkisp1_iowrite32 (params_vdev, arg->curve_g.gamma_y[i], +CIF_ISP_GAMMA_G_Y0 + i *4 ); +rkisp1_iowrite32 (params_vdev, arg->curve_b.gamma_y[i], +CIF_ISP_GAMMA_B_Y0 + i *4 ); + } +} + +/* ISP GAMMA correction interface function */ +static void goc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_goc_config *arg) +{ +int i; + +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +rkisp1_iowrite32 (params_vdev, arg->mode,CIF_ISP_GAMMA_OUT_MODE ); + +for (i =0 ; i <CIFISP_GAMMA_OUT_MAX_SAMPLES ; i++) +rkisp1_iowrite32 (params_vdev, arg->gamma_y[i], +CIF_ISP_GAMMA_OUT_Y_0 + i *4 ); +} + +/* ISP Cross Talk */ +static void ctk_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_ctk_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->coeff0,CIF_ISP_CT_COEFF_0 ); +rkisp1_iowrite32 (params_vdev, arg->coeff1,CIF_ISP_CT_COEFF_1 ); +rkisp1_iowrite32 (params_vdev, arg->coeff2,CIF_ISP_CT_COEFF_2 ); +rkisp1_iowrite32 (params_vdev, arg->coeff3,CIF_ISP_CT_COEFF_3 ); +rkisp1_iowrite32 (params_vdev, arg->coeff4,CIF_ISP_CT_COEFF_4 ); +rkisp1_iowrite32 (params_vdev, arg->coeff5,CIF_ISP_CT_COEFF_5 ); +rkisp1_iowrite32 (params_vdev, arg->coeff6,CIF_ISP_CT_COEFF_6 ); +rkisp1_iowrite32 (params_vdev, arg->coeff7,CIF_ISP_CT_COEFF_7 ); +rkisp1_iowrite32 (params_vdev, arg->coeff8,CIF_ISP_CT_COEFF_8 ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_r,CIF_ISP_CT_OFFSET_R ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_g,CIF_ISP_CT_OFFSET_G ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_b,CIF_ISP_CT_OFFSET_B ); +} + +static void ctk_enable (struct rkisp1_isp_params_vdev *params_vdev,bool en) +{ +if (en) +return ; + +/* Write back the default values. */ +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_0 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_1 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_2 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_3 ); +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_4 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_5 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_6 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_7 ); +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_8 ); + +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_R ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_G ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_B ); +} + +/* ISP White Balance Mode */ +static void awb_meas_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_meas_config *arg) +{ +/* based on the mode,configure the awb module */ +if (arg->awb_mode ==CIFISP_AWB_MODE_YCBCR ) { +/* Reference Cb and Cr */ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_REF_CR_SET (arg->awb_ref_cr) | + arg->awb_ref_cb,CIF_ISP_AWB_REF ); +/* Yc Threshold */ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_MAX_Y_SET (arg->max_y) | +CIF_ISP_AWB_MIN_Y_SET (arg->min_y) | +CIF_ISP_AWB_MAX_CS_SET (arg->max_csum) | + arg->min_c,CIF_ISP_AWB_THRESH ); + } + +/* window offset */ +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.v_offs,CIF_ISP_AWB_WND_V_OFFS ); +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.h_offs,CIF_ISP_AWB_WND_H_OFFS ); +/* AWB window size */ +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.v_size,CIF_ISP_AWB_WND_V_SIZE ); +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.h_size,CIF_ISP_AWB_WND_H_SIZE ); +/* Number of frames */ +rkisp1_iowrite32 (params_vdev, + arg->frames,CIF_ISP_AWB_FRAMES ); +} + +static void awb_meas_enable (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_meas_config *arg,bool en) +{ +u32 reg_val =rkisp1_ioread32 (params_vdev,CIF_ISP_AWB_PROP ); + +/* switch off */ + reg_val &=CIF_ISP_AWB_MODE_MASK_NONE ; + +if (en) { +if (arg->awb_mode ==CIFISP_AWB_MODE_RGB ) + reg_val |=CIF_ISP_AWB_MODE_RGB_EN ; +else + reg_val |=CIF_ISP_AWB_MODE_YCBCR_EN ; + +rkisp1_iowrite32 (params_vdev, reg_val,CIF_ISP_AWB_PROP ); + +/* Measurements require AWB block be active. */ +/* TODO: need to enable here ? awb_gain_enable has done this */ +isp_param_set_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + }else { +rkisp1_iowrite32 (params_vdev, + reg_val,CIF_ISP_AWB_PROP ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + } +} + +static void awb_gain_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_gain_config *arg) +{ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_GAIN_R_SET (arg->gain_green_r) | + arg->gain_green_b,CIF_ISP_AWB_GAIN_G ); + +rkisp1_iowrite32 (params_vdev,CIF_ISP_AWB_GAIN_R_SET (arg->gain_red) | + arg->gain_blue,CIF_ISP_AWB_GAIN_RB ); +} + +static void aec_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_aec_config *arg) +{ +unsigned int block_hsize, block_vsize; + +rkisp1_iowrite32 (params_vdev, + ((arg->autostop) ?CIF_ISP_EXP_CTRL_AUTOSTOP :0 ) | + ((arg->mode ==CIFISP_EXP_MEASURING_MODE_1 ) ? +CIF_ISP_EXP_CTRL_MEASMODE_1 :0 ),CIF_ISP_EXP_CTRL ); + +rkisp1_iowrite32 (params_vdev, + arg->meas_window.h_offs,CIF_ISP_EXP_H_OFFSET ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.v_offs,CIF_ISP_EXP_V_OFFSET ); + + block_hsize = arg->meas_window.h_size /CIF_ISP_EXP_COLUMN_NUM -1 ; + block_vsize = arg->meas_window.v_size /CIF_ISP_EXP_ROW_NUM -1 ; + +rkisp1_iowrite32 (params_vdev,CIF_ISP_EXP_H_SIZE_SET (block_hsize), +CIF_ISP_EXP_H_SIZE ); +rkisp1_iowrite32 (params_vdev,CIF_ISP_EXP_V_SIZE_SET (block_vsize), +CIF_ISP_EXP_V_SIZE ); +} + +static void cproc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_cproc_config *arg) +{ +struct cifisp_isp_other_cfg *cur_other_cfg = ¶ms_vdev->cur_params.others; +struct cifisp_ie_config *cur_ie_config = &cur_other_cfg->ie_config; +u32 effect = cur_ie_config->effect; +u32 quantization = params_vdev->quantization; + +rkisp1_iowrite32 (params_vdev, arg->contrast,CIF_C_PROC_CONTRAST ); +rkisp1_iowrite32 (params_vdev, arg->hue,CIF_C_PROC_HUE ); +rkisp1_iowrite32 (params_vdev, arg->sat,CIF_C_PROC_SATURATION ); +rkisp1_iowrite32 (params_vdev, arg->brightness,CIF_C_PROC_BRIGHTNESS ); + +if (quantization !=V4L2_QUANTIZATION_FULL_RANGE || + effect !=V4L2_COLORFX_NONE ) { +isp_param_clear_bits (params_vdev,CIF_C_PROC_CTRL , +CIF_C_PROC_YOUT_FULL | +CIF_C_PROC_YIN_FULL | +CIF_C_PROC_COUT_FULL ); + }else { +isp_param_set_bits (params_vdev,CIF_C_PROC_CTRL , +CIF_C_PROC_YOUT_FULL | +CIF_C_PROC_YIN_FULL | +CIF_C_PROC_COUT_FULL ); + } +} + +static void hst_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_hst_config *arg) +{ +unsigned int block_hsize, block_vsize; +static const u32 hist_weight_regs[] = { +CIF_ISP_HIST_WEIGHT_00TO30 ,CIF_ISP_HIST_WEIGHT_40TO21 , +CIF_ISP_HIST_WEIGHT_31TO12 ,CIF_ISP_HIST_WEIGHT_22TO03 , +CIF_ISP_HIST_WEIGHT_13TO43 ,CIF_ISP_HIST_WEIGHT_04TO34 , +CIF_ISP_HIST_WEIGHT_44 , + }; +int i; +const u8 *weight; + +rkisp1_iowrite32 (params_vdev, +CIF_ISP_HIST_PREDIV_SET (arg->histogram_predivider), +CIF_ISP_HIST_PROP ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.h_offs, +CIF_ISP_HIST_H_OFFS ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.v_offs, +CIF_ISP_HIST_V_OFFS ); + + block_hsize = arg->meas_window.h_size /CIF_ISP_HIST_COLUMN_NUM -1 ; + block_vsize = arg->meas_window.v_size /CIF_ISP_HIST_ROW_NUM -1 ; + +rkisp1_iowrite32 (params_vdev, block_hsize,CIF_ISP_HIST_H_SIZE ); +rkisp1_iowrite32 (params_vdev, block_vsize,CIF_ISP_HIST_V_SIZE ); + + weight = arg->hist_weight; +for (i =0 ; i <ARRAY_SIZE (hist_weight_regs); ++i, weight +=4 ) +rkisp1_iowrite32 (params_vdev,CIF_ISP_HIST_WEIGHT_SET ( + weight[0 ], weight[1 ], weight[2 ], weight[3 ]), + hist_weight_regs[i]); +} + +static void hst_enable (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_hst_config *arg,bool en) +{ +if (en) { +u32 hist_prop =rkisp1_ioread32 (params_vdev,CIF_ISP_HIST_PROP ); + + hist_prop &= ~CIF_ISP_HIST_PROP_MODE_MASK ; + hist_prop |= arg->mode; +isp_param_set_bits (params_vdev,CIF_ISP_HIST_PROP , hist_prop); + }else { +isp_param_clear_bits (params_vdev,CIF_ISP_HIST_PROP , +CIF_ISP_HIST_PROP_MODE_MASK ); + } +} + +static void afm_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_afc_config *arg) +{ +int i; +size_t num_of_win =min_t (size_t,ARRAY_SIZE (arg->afm_win), + arg->num_afm_win); + +/* Switch off to configure. Enabled during normal flow in frame isr. */ +isp_param_clear_bits (params_vdev,CIF_ISP_AFM_CTRL ,CIF_ISP_AFM_ENA ); + +for (i =0 ; i < num_of_win; i++) { +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AFM_WINDOW_X (arg->afm_win[i].h_offs) | +CIF_ISP_AFM_WINDOW_Y (arg->afm_win[i].v_offs), +CIF_ISP_AFM_LT_A + i *8 ); +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AFM_WINDOW_X (arg->afm_win[i].h_size + + arg->afm_win[i].h_offs) | +CIF_ISP_AFM_WINDOW_Y (arg->afm_win[i].v_size + + arg->afm_win[i].v_offs), +CIF_ISP_AFM_RB_A + i *8 ); + } +rkisp1_iowrite32 (params_vdev, arg->thres,CIF_ISP_AFM_THRES ); +rkisp1_iowrite32 (params_vdev, arg->var_shift,CIF_ISP_AFM_VAR_SHIFT ); +} + +static void ie_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_ie_config *arg) +{ +u32 eff_ctrl; + + eff_ctrl =rkisp1_ioread32 (params_vdev,CIF_IMG_EFF_CTRL ); + eff_ctrl &= ~CIF_IMG_EFF_CTRL_MODE_MASK ; + +if (params_vdev->quantization ==V4L2_QUANTIZATION_FULL_RANGE ) + eff_ctrl |=CIF_IMG_EFF_CTRL_YCBCR_FULL ; + +switch (arg->effect) { +case V4L2_COLORFX_SEPIA : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SEPIA ; +break ; +case V4L2_COLORFX_SET_CBCR : +rkisp1_iowrite32 (params_vdev, arg->eff_tint,CIF_IMG_EFF_TINT ); + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SEPIA ; +break ; +/* +* Color selection is similar to water color(AQUA): +* grayscale + selected color w threshold +*/ +case V4L2_COLORFX_AQUA : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_COLOR_SEL ; +rkisp1_iowrite32 (params_vdev, arg->color_sel, +CIF_IMG_EFF_COLOR_SEL ); +break ; +case V4L2_COLORFX_EMBOSS : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_EMBOSS ; +rkisp1_iowrite32 (params_vdev, arg->eff_mat_1, +CIF_IMG_EFF_MAT_1 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_2, +CIF_IMG_EFF_MAT_2 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_3, +CIF_IMG_EFF_MAT_3 ); +break ; +case V4L2_COLORFX_SKETCH : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SKETCH ; +rkisp1_iowrite32 (params_vdev, arg->eff_mat_3, +CIF_IMG_EFF_MAT_3 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_4, +CIF_IMG_EFF_MAT_4 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_5, +CIF_IMG_EFF_MAT_5 ); +break ; +case V4L2_COLORFX_BW : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_BLACKWHITE ; +break ; +case V4L2_COLORFX_NEGATIVE : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_NEGATIVE ; +break ; +default : +break ; + } + +rkisp1_iowrite32 (params_vdev, eff_ctrl,CIF_IMG_EFF_CTRL ); +} + +static void ie_enable (struct rkisp1_isp_params_vdev *params_vdev,bool en) +{ +if (en) { +isp_param_set_bits (params_vdev,CIF_ICCL ,CIF_ICCL_IE_CLK ); +rkisp1_iowrite32 (params_vdev,CIF_IMG_EFF_CTRL_ENABLE , +CIF_IMG_EFF_CTRL ); +isp_param_set_bits (params_vdev,CIF_IMG_EFF_CTRL , +CIF_IMG_EFF_CTRL_CFG_UPD ); + }else { +/* Disable measurement */ +isp_param_clear_bits (params_vdev,CIF_IMG_EFF_CTRL , +CIF_IMG_EFF_CTRL_ENABLE ); +isp_param_clear_bits (params_vdev,CIF_ICCL ,CIF_ICCL_IE_CLK ); + } +} + +static void csm_config (struct rkisp1_isp_params_vdev *params_vdev, +bool full_range) +{ +static const u16 full_range_coeff[] = { +0x0026 ,0x004b ,0x000f , +0x01ea ,0x01d6 ,0x0040 , +0x0040 ,0x01ca ,0x01f6 + }; +static const u16 limited_range_coeff[] = { +0x0021 ,0x0040 ,0x000d , +0x01ed ,0x01db ,0x0038 , +0x0038 ,0x01d1 ,0x01f7 , + }; +int i; + +if (full_range) { +for (i =0 ; i <ARRAY_SIZE (full_range_coeff); i++) +rkisp1_iowrite32 (params_vdev, full_range_coeff[i], +CIF_ISP_CC_COEFF_0 + i *4 ); + +isp_param_set_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | +CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA ); + }else { +for (i =0 ; i <ARRAY_SIZE (limited_range_coeff); i++) +rkisp1_iowrite32 (params_vdev, limited_range_coeff[i], +CIF_ISP_CC_COEFF_0 + i *4 ); + +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | +CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA ); + } +} + +/* ISP De-noise Pre-Filter(DPF) function */ +static void dpf_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpf_config *arg) +{ +unsigned int isp_dpf_mode; +unsigned int spatial_coeff; +unsigned int i; + +switch (arg->gain.mode) { +case CIFISP_DPF_GAIN_USAGE_NF_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_USE_NF_GAIN | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_LSC_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_USE_NF_GAIN | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP | +CIF_ISP_DPF_MODE_LSC_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_AWB_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_LSC_GAIN_COMP | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_DISABLED : +default : + isp_dpf_mode =0 ; +break ; + } + +if (arg->nll.scale_mode ==CIFISP_NLL_SCALE_LOGARITHMIC ) + isp_dpf_mode |=CIF_ISP_DPF_MODE_NLL_SEGMENTATION ; +if (arg->rb_flt.fltsize == CIFISP_DPF_RB_FILTERSIZE_9x9) + isp_dpf_mode |= CIF_ISP_DPF_MODE_RB_FLTSIZE_9x9; +if (!arg->rb_flt.r_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_R_FLT_DIS ; +if (!arg->rb_flt.b_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_B_FLT_DIS ; +if (!arg->g_flt.gb_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_GB_FLT_DIS ; +if (!arg->g_flt.gr_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_GR_FLT_DIS ; + +isp_param_set_bits (params_vdev,CIF_ISP_DPF_MODE , isp_dpf_mode); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_b_gain, +CIF_ISP_DPF_NF_GAIN_B ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_r_gain, +CIF_ISP_DPF_NF_GAIN_R ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_gb_gain, +CIF_ISP_DPF_NF_GAIN_GB ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_gr_gain, +CIF_ISP_DPF_NF_GAIN_GR ); + +for (i =0 ; i <CIFISP_DPF_MAX_NLF_COEFFS ; i++) { +rkisp1_iowrite32 (params_vdev, arg->nll.coeff[i], +CIF_ISP_DPF_NULL_COEFF_0 + i *4 ); + } + + spatial_coeff = arg->g_flt.spatial_coeff[0 ] | + (arg->g_flt.spatial_coeff[1 ] <<8 ) | + (arg->g_flt.spatial_coeff[2 ] <<16 ) | + (arg->g_flt.spatial_coeff[3 ] <<24 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_G_1_4 ); + + spatial_coeff = arg->g_flt.spatial_coeff[4 ] | + (arg->g_flt.spatial_coeff[5 ] <<8 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_G_5_6 ); + + spatial_coeff = arg->rb_flt.spatial_coeff[0 ] | + (arg->rb_flt.spatial_coeff[1 ] <<8 ) | + (arg->rb_flt.spatial_coeff[2 ] <<16 ) | + (arg->rb_flt.spatial_coeff[3 ] <<24 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_RB_1_4 ); + + spatial_coeff = arg->rb_flt.spatial_coeff[4 ] | + (arg->rb_flt.spatial_coeff[5 ] <<8 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_RB_5_6 ); +}
drivers/media/platform/rockchip/isp1/isp_params.c line 839
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+ +static void dpf_strength_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpf_strength_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->b,CIF_ISP_DPF_STRENGTH_B ); +rkisp1_iowrite32 (params_vdev, arg->g,CIF_ISP_DPF_STRENGTH_G ); +rkisp1_iowrite32 (params_vdev, arg->r,CIF_ISP_DPF_STRENGTH_R ); +} + +static __maybe_unused
Why maybe unused? Add a comment explaining this.
Quoted 617 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +617
-0+void __isp_isr_other_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct rkisp1_isp_params_cfg *new_params) +{ +unsigned int module_en_update, module_cfg_update, module_ens; + + module_en_update = new_params->module_en_update; + module_cfg_update = new_params->module_cfg_update; + module_ens = new_params->module_ens; + +if ((module_en_update &CIFISP_MODULE_DPCC ) || + (module_cfg_update &CIFISP_MODULE_DPCC )) { +/*update dpc config */ +if ((module_cfg_update &CIFISP_MODULE_DPCC )) +dpcc_config (params_vdev, + &new_params->others.dpcc_config); + +if (module_en_update &CIFISP_MODULE_DPCC ) { +if (!!(module_ens &CIFISP_MODULE_DPCC )) +isp_param_set_bits (params_vdev, +CIF_ISP_DPCC_MODE , +CIF_ISP_DPCC_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DPCC_MODE , +CIF_ISP_DPCC_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_BLS ) || + (module_cfg_update &CIFISP_MODULE_BLS )) { +/* update bls config */ +if ((module_cfg_update &CIFISP_MODULE_BLS )) +bls_config (params_vdev, &new_params->others.bls_config); + +if (module_en_update &CIFISP_MODULE_BLS ) { +if (!!(module_ens &CIFISP_MODULE_BLS )) +isp_param_set_bits (params_vdev, +CIF_ISP_BLS_CTRL , +CIF_ISP_BLS_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_BLS_CTRL , +CIF_ISP_BLS_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_SDG ) || + (module_cfg_update &CIFISP_MODULE_SDG )) { +/* update sdg config */ +if ((module_cfg_update &CIFISP_MODULE_SDG )) +sdg_config (params_vdev, &new_params->others.sdg_config); + +if (module_en_update &CIFISP_MODULE_SDG ) { +if (!!(module_ens &CIFISP_MODULE_SDG )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_LSC ) || + (module_cfg_update &CIFISP_MODULE_LSC )) { +/* update lsc config */ +if ((module_cfg_update &CIFISP_MODULE_LSC )) +lsc_config (params_vdev, &new_params->others.lsc_config); + +if (module_en_update &CIFISP_MODULE_LSC ) { +if (!!(module_ens &CIFISP_MODULE_LSC )) +isp_param_set_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_AWB_GAIN ) || + (module_cfg_update &CIFISP_MODULE_AWB_GAIN )) { +/* update awb gains */ +if ((module_cfg_update &CIFISP_MODULE_AWB_GAIN )) +awb_gain_config (params_vdev, + &new_params->others.awb_gain_config); + +if (module_en_update &CIFISP_MODULE_AWB_GAIN ) { +if (!!(module_ens &CIFISP_MODULE_AWB_GAIN )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_BDM ) || + (module_cfg_update &CIFISP_MODULE_BDM )) { +/* update bdm config */ +if ((module_cfg_update &CIFISP_MODULE_BDM )) +bdm_config (params_vdev, &new_params->others.bdm_config); + +if (module_en_update &CIFISP_MODULE_BDM ) { +if (!!(module_ens &CIFISP_MODULE_BDM )) +isp_param_set_bits (params_vdev, +CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); + } + } + +if ((module_en_update &CIFISP_MODULE_FLT ) || + (module_cfg_update &CIFISP_MODULE_FLT )) { +/* update filter config */ +if ((module_cfg_update &CIFISP_MODULE_FLT )) +flt_config (params_vdev, &new_params->others.flt_config); + +if (module_en_update &CIFISP_MODULE_FLT ) { +if (!!(module_ens &CIFISP_MODULE_FLT )) +isp_param_set_bits (params_vdev, +CIF_ISP_FILT_MODE , +CIF_ISP_FLT_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_FILT_MODE , +CIF_ISP_FLT_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_CTK ) || + (module_cfg_update &CIFISP_MODULE_CTK )) { +/* update ctk config */ +if ((module_cfg_update &CIFISP_MODULE_CTK )) +ctk_config (params_vdev, &new_params->others.ctk_config); + +if (module_en_update &CIFISP_MODULE_CTK ) +ctk_enable (params_vdev, + !!(module_ens &CIFISP_MODULE_CTK )); + } + +if ((module_en_update &CIFISP_MODULE_GOC ) || + (module_cfg_update &CIFISP_MODULE_GOC )) { +/* update goc config */ +if ((module_cfg_update &CIFISP_MODULE_GOC )) +goc_config (params_vdev, &new_params->others.goc_config); + +if (module_en_update &CIFISP_MODULE_GOC ) { +if (!!(module_ens &CIFISP_MODULE_GOC )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_CPROC ) || + (module_cfg_update &CIFISP_MODULE_CPROC )) { +/* update cproc config */ +if ((module_cfg_update &CIFISP_MODULE_CPROC )) { +cproc_config (params_vdev, + &new_params->others.cproc_config); + + } + +if (module_en_update &CIFISP_MODULE_CPROC ) { +if (!!(module_ens &CIFISP_MODULE_CPROC )) +isp_param_set_bits (params_vdev, +CIF_C_PROC_CTRL , +CIF_C_PROC_CTR_ENABLE ); +else +isp_param_clear_bits (params_vdev, +CIF_C_PROC_CTRL , +CIF_C_PROC_CTR_ENABLE ); + } + } + + +if ((module_en_update &CIFISP_MODULE_IE ) || + (module_cfg_update &CIFISP_MODULE_IE )) { +/* update ie config */ +if ((module_cfg_update &CIFISP_MODULE_IE )) +ie_config (params_vdev, &new_params->others.ie_config); + +if (module_en_update &CIFISP_MODULE_IE ) +ie_enable (params_vdev, + !!(module_ens &CIFISP_MODULE_IE )); + } + +if ((module_en_update &CIFISP_MODULE_DPF ) || + (module_cfg_update &CIFISP_MODULE_DPF )) { +/* update dpf config */ +if ((module_cfg_update &CIFISP_MODULE_DPF )) +dpf_config (params_vdev, &new_params->others.dpf_config); + +if (module_en_update &CIFISP_MODULE_DPF ) { +if (!!(module_ens &CIFISP_MODULE_DPF )) +isp_param_set_bits (params_vdev, +CIF_ISP_DPF_MODE , +CIF_ISP_DPF_MODE_EN ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DPF_MODE , +CIF_ISP_DPF_MODE_EN ); + } + } + +if ((module_en_update &CIFISP_MODULE_DPF_STRENGTH ) || + (module_cfg_update &CIFISP_MODULE_DPF_STRENGTH )) { +/* update dpf strength config */ +dpf_strength_config (params_vdev, + &new_params->others.dpf_strength_config); + } +} + +static __maybe_unused +void __isp_isr_meas_config (struct rkisp1_isp_params_vdev *params_vdev, +struct rkisp1_isp_params_cfg *new_params) +{ +unsigned int module_en_update, module_cfg_update, module_ens; + + module_en_update = new_params->module_en_update; + module_cfg_update = new_params->module_cfg_update; + module_ens = new_params->module_ens; + +if ((module_en_update &CIFISP_MODULE_AWB ) || + (module_cfg_update &CIFISP_MODULE_AWB )) { +/* update awb config */ +if ((module_cfg_update &CIFISP_MODULE_AWB )) +awb_meas_config (params_vdev, + &new_params->meas.awb_meas_config); + +if (module_en_update &CIFISP_MODULE_AWB ) +awb_meas_enable (params_vdev, + &new_params->meas.awb_meas_config, + !!(module_ens &CIFISP_MODULE_AWB )); + } + +if ((module_en_update &CIFISP_MODULE_AFC ) || + (module_cfg_update &CIFISP_MODULE_AFC )) { +/* update afc config */ +if ((module_cfg_update &CIFISP_MODULE_AFC )) +afm_config (params_vdev, &new_params->meas.afc_config); + +if (module_en_update &CIFISP_MODULE_AFC ) { +if (!!(module_ens &CIFISP_MODULE_AFC )) +isp_param_set_bits (params_vdev, +CIF_ISP_AFM_CTRL , +CIF_ISP_AFM_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_AFM_CTRL , +CIF_ISP_AFM_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_HST ) || + (module_cfg_update &CIFISP_MODULE_HST )) { +/* update hst config */ +if ((module_cfg_update &CIFISP_MODULE_HST )) +hst_config (params_vdev, &new_params->meas.hst_config); + +if (module_en_update &CIFISP_MODULE_HST ) +hst_enable (params_vdev, + &new_params->meas.hst_config, + !!(module_ens &CIFISP_MODULE_HST )); + } + +if ((module_en_update &CIFISP_MODULE_AEC ) || + (module_cfg_update &CIFISP_MODULE_AEC )) { +/* update aec config */ +if ((module_cfg_update &CIFISP_MODULE_AEC )) +aec_config (params_vdev, &new_params->meas.aec_config); + +if (module_en_update &CIFISP_MODULE_AEC ) { +if (!!(module_ens &CIFISP_MODULE_AEC )) +isp_param_set_bits (params_vdev, +CIF_ISP_EXP_CTRL , +CIF_ISP_EXP_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_EXP_CTRL , +CIF_ISP_EXP_ENA ); + } + } +} + +void rkisp1_params_isr (struct rkisp1_isp_params_vdev *params_vdev,u32 isp_mis) +{ +struct rkisp1_isp_params_cfg *new_params; +struct rkisp1_buffer *cur_buf =NULL ; + +spin_lock (¶ms_vdev->config_lock); +if (!params_vdev->streamon) { +spin_unlock (¶ms_vdev->config_lock); +return ; + } + +/* get one empty buffer */ +if (!list_empty (¶ms_vdev->params)) + cur_buf =list_first_entry (¶ms_vdev->params, + struct rkisp1_buffer, queue); +spin_unlock (¶ms_vdev->config_lock); + +if (!cur_buf) +return ; + + new_params = (struct rkisp1_isp_params_cfg *)(cur_buf->vaddr[0 ]); + +if (isp_mis &CIF_ISP_FRAME ) { +__isp_isr_other_config (params_vdev, new_params); +__isp_isr_meas_config (params_vdev, new_params); +spin_lock (¶ms_vdev->config_lock); +list_del (&cur_buf->queue); +spin_unlock (¶ms_vdev->config_lock); +vb2_buffer_done (&cur_buf->vb.vb2_buf,VB2_BUF_STATE_DONE ); + } +} + +static const struct cifisp_awb_meas_config awb_params_default_config = { + { +0 ,0 ,RKISP1_DEFAULT_WIDTH ,RKISP1_DEFAULT_HEIGHT + }, +CIFISP_AWB_MODE_YCBCR ,200 ,30 ,20 ,20 ,0 ,128 ,128 +}; + +static const struct cifisp_aec_config aec_params_default_config = { +CIFISP_EXP_MEASURING_MODE_0 , +CIFISP_EXP_CTRL_AUTOSTOP_0 , + { +RKISP1_DEFAULT_WIDTH >>2 ,RKISP1_DEFAULT_HEIGHT >>2 , +RKISP1_DEFAULT_WIDTH >>1 ,RKISP1_DEFAULT_HEIGHT >>1 + } +}; + +static const struct cifisp_hst_config hst_params_default_config = { +CIFISP_HISTOGRAM_MODE_RGB_COMBINED , +3 , + { +RKISP1_DEFAULT_WIDTH >>2 ,RKISP1_DEFAULT_HEIGHT >>2 , +RKISP1_DEFAULT_WIDTH >>1 ,RKISP1_DEFAULT_HEIGHT >>1 + }, + { +0 ,/* To be filled in with 0x01 at runtime. */ + } +}; + +static const struct cifisp_afc_config afc_params_default_config = { +1 , + { + { +300 ,225 ,200 ,150 + } + }, +4 , +14 +}; + +static +void rkisp1_params_config_parameter (struct rkisp1_isp_params_vdev *params_vdev) +{ +struct cifisp_hst_config hst = hst_params_default_config; + +spin_lock (¶ms_vdev->config_lock); + +awb_meas_config (params_vdev, &awb_params_default_config); +awb_meas_enable (params_vdev, &awb_params_default_config, true); + +aec_config (params_vdev, &aec_params_default_config); +isp_param_set_bits (params_vdev,CIF_ISP_EXP_CTRL ,CIF_ISP_EXP_ENA ); + +afm_config (params_vdev, &afc_params_default_config); +isp_param_set_bits (params_vdev,CIF_ISP_AFM_CTRL ,CIF_ISP_AFM_ENA ); + +memset (hst.hist_weight,0x01 ,sizeof (hst.hist_weight)); +hst_config (params_vdev, &hst); +isp_param_set_bits (params_vdev,CIF_ISP_HIST_PROP , + ~CIF_ISP_HIST_PROP_MODE_MASK | + hst_params_default_config.mode); + +/* set the range */ +if (params_vdev->quantization ==V4L2_QUANTIZATION_FULL_RANGE ) +csm_config (params_vdev, true); +else +csm_config (params_vdev, false); + +/* override the default things */ +__isp_isr_other_config (params_vdev, ¶ms_vdev->cur_params); +__isp_isr_meas_config (params_vdev, ¶ms_vdev->cur_params); + +spin_unlock (¶ms_vdev->config_lock); +} + +/* Not called when the camera active, thus not isr protection. */ +void rkisp1_configure_isp (struct rkisp1_isp_params_vdev *params_vdev, +struct ispsd_in_fmt *in_fmt, +enum v4l2_quantization quantization) +{ +if (!params_vdev) +return ; + +if (quantization) + params_vdev->quantization = quantization; +if (in_fmt) + params_vdev->raw_type = in_fmt->bayer_pat; +if (params_vdev) +rkisp1_params_config_parameter (params_vdev); +} + +/* Not called when the camera active, thus not isr protection. */ +void rkisp1_disable_isp (struct rkisp1_isp_params_vdev *params_vdev) +{ +isp_param_clear_bits (params_vdev,CIF_ISP_DPCC_MODE ,CIF_ISP_DPCC_ENA );Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_params.c line 1272
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+isp_param_clear_bits (params_vdev,CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_BLS_CTRL ,CIF_ISP_BLS_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); +isp_param_clear_bits (params_vdev,CIF_ISP_FILT_MODE ,CIF_ISP_FLT_ENA );
Either add VB2_DMABUF or drop exp_buf from rkisp1_params_ioctl.
drivers/media/platform/rockchip/isp1/isp_stats.c
Quoted 375 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +77
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_params.h new file +76
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.c new file +210
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Either add VB2_DMABUF or drop expbuf from rkisp1_stats_ioctl.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 3,179 lines
drivers/media/platform/rockchip/isp1/isp_stats.c new file +311
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.h new file +85
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.c new file +264
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.h new file +1582
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.c new file +913
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
What do you use g_mbus_config for? Typically this information should come from the device tree. I want to remove this op in the not-too-distant future since it really makes no sense.
drivers/media/platform/rockchip/isp1/rkisp1.h
Quoted 426 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +288
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.h new file +131
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Perhaps when you post v4 you can split up this patch in 2 or 3 smaller patches. Certainly regs.[ch] can easily be put in a separate patch. It's hard to review a single very large patch like this.
Regards,
Hans
Part of the diff is not shown here. View the raw message.
Re: [PATCH v3 04/12] media: rkisp1: add rockchip isp1 driver
Hi Hans,
2017-12-14 0:07 GMT+08:00 Hans Verkuil <[email protected]>:
Quoted 122 lines · Jacob Chen
Quoted 97 lines
From: Jacob Chen <[email protected]>
This commit adds a ISP(Camera) v4l2 driver for rockchip rk3288/rk3399 SoC.
Signed-off-by Jacob Chen <[email protected]>Signed-off-by Shunqian Zheng <[email protected]>Signed-off-by Yichong Zhong <[email protected]>Signed-off-by Jacob Chen <[email protected]>Signed-off-by Eddie Cai <[email protected]>Signed-off-by Jeffy Chen <[email protected]>Signed-off-by Allon Huang <[email protected]>Signed-off-by Tomasz Figa <[email protected]>--- drivers/media/platform/Kconfig | 10 + drivers/media/platform/Makefile | 1 + drivers/media/platform/rockchip/isp1/Makefile | 7 + drivers/media/platform/rockchip/isp1/capture.c | 1684 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 194 +++ drivers/media/platform/rockchip/isp1/common.h | 137 ++ drivers/media/platform/rockchip/isp1/dev.c | 655 ++++++++ drivers/media/platform/rockchip/isp1/dev.h | 120 ++ drivers/media/platform/rockchip/isp1/isp_params.c | 1543 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 76 + drivers/media/platform/rockchip/isp1/isp_stats.c | 521 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 85 ++ drivers/media/platform/rockchip/isp1/regs.c | 264 ++++ drivers/media/platform/rockchip/isp1/regs.h | 1582 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1201 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 131 ++ 16 files changed, 8211 insertions(+) create mode 100644 drivers/media/platform/rockchip/isp1/Makefile create mode 100644 drivers/media/platform/rockchip/isp1/capture.c create mode 100644 drivers/media/platform/rockchip/isp1/capture.h create mode 100644 drivers/media/platform/rockchip/isp1/common.h create mode 100644 drivers/media/platform/rockchip/isp1/dev.c create mode 100644 drivers/media/platform/rockchip/isp1/dev.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_params.h create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.c create mode 100644 drivers/media/platform/rockchip/isp1/isp_stats.h create mode 100644 drivers/media/platform/rockchip/isp1/regs.c create mode 100644 drivers/media/platform/rockchip/isp1/regs.h create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.c create mode 100644 drivers/media/platform/rockchip/isp1/rkisp1.hdrivers/media/platform/Kconfig +10
-0@@ -117,6 +117,16 @@ config VIDEO_QCOM_CAMSS select VIDEOBUF2_DMA_SG select V4L2_FWNODE +config VIDEO_ROCKCHIP_ISP1 + tristate "Rockchip Image Signal Processing v1 Unit driver" + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API + depends on ARCH_ROCKCHIP || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + default n + ---help--- + Support for ISP1 on the rockchip SoC. + config VIDEO_S3C_CAMIF tristate "Samsung S3C24XX/S3C64XX SoC Camera Interface driver" depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_APIdrivers/media/platform/Makefile +1
-0@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1) += rcar_fdp1.o obj-$(CONFIG_VIDEO_RENESAS_JPU) += rcar_jpu.o obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += rockchip/isp1/ obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip/rga/ obj-y += omap/drivers/media/platform/rockchip/isp1/Makefile new file +7
-0@@ -0,0 +1,7 @@ +obj-$(CONFIG_VIDEO_ROCKCHIP_ISP1) += video_rkisp1.o +video_rkisp1-objs += rkisp1.o \ + dev.o \ + regs.o \ + isp_stats.o \ + isp_params.o \ + capture.odrivers/media/platform/rockchip/isp1/capture.c new file +0
-0@@ -0,0 +1,1684 @@<snip>
Quoted 21 lines
drivers/media/platform/rockchip/isp1/capture.c new file +21
-0+static void rkisp1_destroy_dummy_buf (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; +struct rkisp1_device *dev = stream->ispdev; + +dma_free_coherent (dev->dev, dummy_buf->size, + dummy_buf->vaddr, dummy_buf->dma_addr); +} + +static void rkisp1_stop_streaming (struct vb2_queue *queue) +{ +struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_vdev_node *node = &stream->vnode; +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +struct rkisp1_buffer *buf; +unsigned long lock_flags =0 ; +int ret; + +rkisp1_stream_stop (stream); +/* call to the other devices */
Quoted 9 lines
drivers/media/platform/rockchip/isp1/capture.c line 1117
Quoted 4 lines
drivers/media/platform/rockchip/isp1/capture.c new file +4
-0+media_pipeline_stop (&node->vdev.entity); + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ;Shouldn't it release buffers in this error case as well? It's generally a bad design if a close/release/stop-like function can return an error, after all, what should you do with that?
OK, so i'd like to make it just throw a warning since we can't stop stoping streaming here.
It won't failed in this driver, but it might failed in sensor driver.
Quoted 73 lines
Quoted 13 lines
drivers/media/platform/rockchip/isp1/capture.c new file +13
-0+ +/* release buffers */ +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +if (stream->curr_buf) { +list_add_tail (&stream->curr_buf->queue, &stream->buf_queue); + stream->curr_buf =NULL ; + } +if (stream->next_buf) { +list_add_tail (&stream->next_buf->queue, &stream->buf_queue); + stream->next_buf =NULL ; + } +while (!list_empty (&stream->buf_queue)) { + buf = list_first_entry(&stream->buf_queue,drivers/media/platform/rockchip/isp1/capture.c line 1140
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ struct rkisp1_buffer, queue); +list_del (&buf->queue); +vb2_buffer_done (&buf->vb.vb2_buf,VB2_BUF_STATE_ERROR ); + } +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); + + ret = dev->pipe.close (&dev->pipe); +if (ret <0 ) { +v4l2_err (v4l2_dev,"pipeline close failed error:%d\n" , ret); +return ;Same here, are you sure you can skip the
rkisp1_destroy_dummy_bufcall here?Quoted 28 lines
drivers/media/platform/rockchip/isp1/capture.c new file +28
-0+ } + +rkisp1_destroy_dummy_buf (stream); +} + +static int rkisp1_stream_start (struct rkisp1_stream *stream) +{ +struct v4l2_device *v4l2_dev = &stream->ispdev->v4l2_dev; +int ret; + + ret =rkisp1_config_rsz (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"config rsz failed with error %d\n" , ret); +return ret; + } + + ret =rkisp1_config_dcrop (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"config dcrop failed with error %d\n" , ret); +return ret; + } + +return rkisp1_start (stream); +} + +static int +rkisp1_start_streaming (struct vb2_queue *queue,unsigned int count) +{drivers/media/platform/rockchip/isp1/capture.c line 1178
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_vdev_node *node = &stream->vnode; +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +int ret; + +if (stream->state !=RKISP1_STATE_READY ) { +v4l2_err (v4l2_dev,"stream %d in bad state(%d) for streaming\n" , + stream->id, stream->state); +return -EBUSY ;This feels like more of a
WARN_ONto me. It should never happen, right?drivers/media/platform/rockchip/isp1/capture.c line 1183
Quoted 5 lines
drivers/media/platform/rockchip/isp1/capture.c new file +5
-0+ } + + ret =rkisp1_create_dummy_buf (stream); +if (ret <0 ) +return ret;
Quoted 4 lines
If
start_streamingfails, then you need to return all buffers back to vb2 withvb2_buffer_done(..., VB2_BUF_STATE_QUEUED). Just like instop_streaming, but with a different state. So please check all the error paths in this function.
Dummy bufs are not vb2, they are just a space allocated by dma_alloc_coherent.
Quoted 7,100 lines
Quoted 203 lines
drivers/media/platform/rockchip/isp1/capture.c new file +203
-0+ +/* enable clocks/power-domains */ + ret = dev->pipe.open (&dev->pipe, &node->vdev.entity, true); +if (ret <0 ) { +v4l2_err (v4l2_dev,"open cif pipeline failed %d\n" , ret); + goto destroy_dummy_buf; + } + +/* configure stream hardware to start */ + ret =rkisp1_stream_start (stream); +if (ret <0 ) { +v4l2_err (v4l2_dev,"start streaming failed\n" ); + goto close_pipe; + } + +/* start sub-devices */ + ret = dev->pipe.set_stream (&dev->pipe, true); +if (ret <0 ) + goto stop_stream; + + ret =media_pipeline_start (&node->vdev.entity, &dev->pipe.pipe); +if (ret <0 ) { +v4l2_err (&dev->v4l2_dev,"start pipeline failed %d\n" , ret); + goto pipe_stream_off; + } + +return 0 ; + +pipe_stream_off: + dev->pipe.set_stream (&dev->pipe, false); +stop_stream: +rkisp1_stream_stop (stream); +close_pipe: + dev->pipe.close (&dev->pipe); +destroy_dummy_buf: +rkisp1_destroy_dummy_buf (stream); + +return ret; +} + +static struct vb2_ops rkisp1_vb2_ops = { + .queue_setup = rkisp1_queue_setup, + .buf_queue = rkisp1_buf_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .stop_streaming = rkisp1_stop_streaming, + .start_streaming = rkisp1_start_streaming, +}; + +static int rkisp_init_vb2_queue (struct vb2_queue *q, +struct rkisp1_stream *stream, +enum v4l2_buf_type buf_type) +{ +struct rkisp1_vdev_node *node; + + node =queue_to_node (q); + + q->type = buf_type; + q->io_modes =VB2_MMAP |VB2_DMABUF ; + q->drv_priv = stream; + q->ops = &rkisp1_vb2_ops; + q->mem_ops = &vb2_dma_contig_memops; + q->buf_struct_size =sizeof (struct rkisp1_buffer ); + q->min_buffers_needed =CIF_ISP_REQ_BUFS_MIN ; + q->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + q->lock = &node->vlock; + q->dev = stream->ispdev->dev; + +return vb2_queue_init (q); +} + +static void rkisp1_set_fmt (struct rkisp1_stream *stream, +struct v4l2_pix_format_mplane *pixm, +bool try) +{ +const struct capture_fmt *fmt; +const struct stream_config *config = stream->config; +struct rkisp1_stream *other_stream = + &stream->ispdev->stream[!stream->id]; +unsigned int imagsize =0 ; +unsigned int planes; +u32 xsubs =1 , ysubs =1 ; +int i; + + fmt =find_fmt (stream, pixm->pixelformat); +if (!fmt) + fmt = config->fmts; + +/* do checks on resolution */ + pixm->width =clamp_t (u32, pixm->width, config->min_rsz_width, + config->max_rsz_width); + pixm->height =clamp_t (u32, pixm->height, config->min_rsz_height, + config->max_rsz_height); + pixm->num_planes = fmt->mplanes; + pixm->field =V4L2_FIELD_NONE ; + +/* output full range by default, take effect in isp_params */ +if (!pixm->quantization) + pixm->quantization =V4L2_QUANTIZATION_FULL_RANGE ; +/* can not change quantization when stream-on */ +if (other_stream->state ==RKISP1_STATE_STREAMING ) + pixm->quantization = other_stream->out_fmt.quantization; + +/* calculate size */ +fcc_xysubs (fmt->fourcc, &xsubs, &ysubs); + planes = fmt->cplanes ? fmt->cplanes : fmt->mplanes; +for (i =0 ; i < planes; i++) { +struct v4l2_plane_pix_format *plane_fmt; +int width, height, bytesperline; + + plane_fmt = pixm->plane_fmt + i; + +if (i ==0 ) { + width = pixm->width; + height = pixm->height; + }else { + width = pixm->width / xsubs; + height = pixm->height / ysubs; + } + + bytesperline = width *DIV_ROUND_UP (fmt->bpp[i],8 ); +/* stride is only available for sp stream and y plane */ +if (stream->id !=RKISP1_STREAM_SP || i !=0 || + plane_fmt->bytesperline < bytesperline) + plane_fmt->bytesperline = bytesperline; + + plane_fmt->sizeimage = plane_fmt->bytesperline * height; + + imagsize += plane_fmt->sizeimage; + } + +/* convert to non-MPLANE format. +* it's important since we want to unify none-MPLANE +* and MPLANE. +*/ +if (fmt->mplanes ==1 ) + pixm->plane_fmt[0 ].sizeimage = imagsize; + +if (!try) { + stream->out_isp_fmt = *fmt; + stream->out_fmt = *pixm; + +if (stream->id ==RKISP1_STREAM_SP ) { + stream->u.sp.y_stride = + pixm->plane_fmt[0 ].bytesperline / +DIV_ROUND_UP (fmt->bpp[0 ],8 ); + }else { + stream->u.mp.raw_enable = (fmt->fmt_type ==FMT_BAYER ); + } +v4l2_dbg (1 , rkisp1_debug, &stream->ispdev->v4l2_dev, +"%s: stream: %d req(%d, %d) out(%d, %d)\n" , __func__, + stream->id, pixm->width, pixm->height, + stream->out_fmt.width, stream->out_fmt.height); + +/* set quantization to isp_params */ +rkisp1_configure_isp (NULL ,NULL , pixm->quantization); + } +} + +/************************* v4l2_file_operations***************************/ +void rkisp1_stream_init (struct rkisp1_device *dev,u32 id) +{ +struct rkisp1_stream *stream = &dev->stream[id]; +struct v4l2_pix_format_mplane pixm; + +memset (stream,0 ,sizeof (*stream)); + stream->id = id; + stream->ispdev = dev; + +INIT_LIST_HEAD (&stream->buf_queue); +init_waitqueue_head (&stream->done); +spin_lock_init (&stream->vbq_lock); +if (stream->id ==RKISP1_STREAM_SP ) { + stream->ops = &rkisp1_sp_streams_ops; + stream->config = &rkisp1_sp_stream_config; + }else { + stream->ops = &rkisp1_mp_streams_ops; + stream->config = &rkisp1_mp_stream_config; + } + + stream->state =RKISP1_STATE_READY ; + +memset (&pixm,0 ,sizeof (pixm)); + pixm.pixelformat =V4L2_PIX_FMT_YUYV ; + pixm.width =RKISP1_DEFAULT_WIDTH ; + pixm.height =RKISP1_DEFAULT_HEIGHT ; +rkisp1_set_fmt (stream, &pixm, false); + + stream->dcrop.left =0 ; + stream->dcrop.top =0 ; + stream->dcrop.width =RKISP1_DEFAULT_WIDTH ; + stream->dcrop.height =RKISP1_DEFAULT_HEIGHT ; +} + +static const struct v4l2_file_operations rkisp1_fops = { + .open = v4l2_fh_open, + .release = vb2_fop_release, + .unlocked_ioctl = video_ioctl2, + .poll = vb2_fop_poll, + .mmap = vb2_fop_mmap, +}; + +/* drivers/media/platform/rockchip/isp1/capture.c line 1396
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+* mp and sp v4l2_ioctl_ops +*/ + +/* keep for compatibility */ +static int rkisp1_enum_input (struct file *file,void *priv, +struct v4l2_input *input) +{ +if (input->index >0 ) +return -EINVAL ; +Please fill in
v4l2_input.Quoted 108 lines
drivers/media/platform/rockchip/isp1/capture.c new file +108
-0+return 0 ; +} + +static int rkisp1_try_fmt_vid_cap_mplane (struct file *file,void *fh, +struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); + +rkisp1_set_fmt (stream, &f->fmt.pix_mp, true); + +return 0 ; +} + +static int rkisp1_enum_fmt_vid_cap_mplane (struct file *file,void *priv, +struct v4l2_fmtdesc *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); +const struct capture_fmt *fmt =NULL ; + +if (f->index >= stream->config->fmt_size) +return -EINVAL ; + + fmt = &stream->config->fmts[f->index]; + f->pixelformat = fmt->fourcc; + +return 0 ; +} + +static int rkisp1_s_fmt_vid_cap_mplane (struct file *file, +void *priv,struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct video_device *vdev = &stream->vnode.vdev; +struct rkisp1_vdev_node *node =vdev_to_node (vdev); +struct rkisp1_device *dev = stream->ispdev; + +if (vb2_is_busy (&node->buf_queue)) { +v4l2_err (&dev->v4l2_dev,"%s queue busy\n" , __func__); +return -EBUSY ; + } + +rkisp1_set_fmt (stream, &f->fmt.pix_mp, false); + +return 0 ; +} + +static int rkisp1_g_fmt_vid_cap_mplane (struct file *file,void *fh, +struct v4l2_format *f) +{ +struct rkisp1_stream *stream =video_drvdata (file); + + f->fmt.pix_mp = stream->out_fmt; + +return 0 ; +} + +static int rkisp1_g_selection (struct file *file,void *prv, +struct v4l2_selection *sel) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_rect *dcrop = &stream->dcrop; +struct v4l2_rect *input_win; + + input_win =rkisp1_get_isp_sd_win (&dev->isp_sdev); + +switch (sel->target) { +case V4L2_SEL_TGT_CROP_BOUNDS : + sel->r.width = input_win->width; + sel->r.height = input_win->height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +case V4L2_SEL_TGT_CROP : + sel->r = *dcrop; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static struct v4l2_rect *rkisp1_update_crop (struct rkisp1_stream *stream, +struct v4l2_rect *sel, +const struct v4l2_rect *in) +{ +/* Not crop for MP bayer raw data */ +if (stream->id ==RKISP1_STREAM_MP && + stream->out_isp_fmt.fmt_type ==FMT_BAYER ) { + sel->left =0 ; + sel->top =0 ; + sel->width = in->width; + sel->height = in->height; +return sel; + } + + sel->left =ALIGN (sel->left,2 ); + sel->width =ALIGN (sel->width,2 ); + sel->left =clamp_t (u32, sel->left,0 , + in->width -STREAM_MIN_MP_SP_INPUT_WIDTH ); + sel->top =clamp_t (u32, sel->top,0 , + in->height -STREAM_MIN_MP_SP_INPUT_HEIGHT ); + sel->width =clamp_t (u32, sel->width,STREAM_MIN_MP_SP_INPUT_WIDTH , + in->width - sel->left); + sel->height =clamp_t (u32, sel->height,STREAM_MIN_MP_SP_INPUT_HEIGHT , + in->height - sel->top); +return sel;drivers/media/platform/rockchip/isp1/capture.c line 1514
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+} + +static int rkisp1_s_selection (struct file *file,void *prv, +struct v4l2_selection *sel) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_rect *dcrop = &stream->dcrop; +const struct v4l2_rect *input_win; +You probably need a
vb2_is_busy()call here. Normally you cannot change the selection while streaming.Quoted 2,135 lines
drivers/media/platform/rockchip/isp1/capture.c new file +170
-0+ input_win =rkisp1_get_isp_sd_win (&dev->isp_sdev); + +if (sel->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ; + +if (sel->flags !=0 ) +return -EINVAL ; + +if (sel->target ==V4L2_SEL_TGT_CROP ) { + *dcrop = *rkisp1_update_crop (stream, &sel->r, input_win); +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream %d crop(%d,%d)/%dx%d\n" , stream->id, + dcrop->left, dcrop->top, dcrop->width, dcrop->height); + } + +return 0 ; +} + +static int rkisp1_querycap (struct file *file,void *priv, +struct v4l2_capability *cap) +{ +struct rkisp1_stream *stream =video_drvdata (file); +struct device *dev = stream->ispdev->dev; + +strlcpy (cap->driver, dev->driver->name,sizeof (cap->driver)); +strlcpy (cap->card, dev->driver->name,sizeof (cap->card)); +snprintf (cap->bus_info,sizeof (cap->bus_info), +"platform:%s" ,dev_name (dev)); + +return 0 ; +} + +static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = { + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_enum_input = rkisp1_enum_input, + .vidioc_try_fmt_vid_cap_mplane = rkisp1_try_fmt_vid_cap_mplane, + .vidioc_enum_fmt_vid_cap_mplane = rkisp1_enum_fmt_vid_cap_mplane, + .vidioc_s_fmt_vid_cap_mplane = rkisp1_s_fmt_vid_cap_mplane, + .vidioc_g_fmt_vid_cap_mplane = rkisp1_g_fmt_vid_cap_mplane, + .vidioc_s_selection = rkisp1_s_selection, + .vidioc_g_selection = rkisp1_g_selection, + .vidioc_querycap = rkisp1_querycap, +}; + +static void rkisp1_unregister_stream_vdev (struct rkisp1_stream *stream) +{ +media_entity_cleanup (&stream->vnode.vdev.entity); +video_unregister_device (&stream->vnode.vdev); +} + +void rkisp1_unregister_stream_vdevs (struct rkisp1_device *dev) +{ +struct rkisp1_stream *mp_stream = &dev->stream[RKISP1_STREAM_MP ]; +struct rkisp1_stream *sp_stream = &dev->stream[RKISP1_STREAM_SP ]; + +rkisp1_unregister_stream_vdev (mp_stream); +rkisp1_unregister_stream_vdev (sp_stream); +} + +static int rkisp1_register_stream_vdev (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +struct video_device *vdev = &stream->vnode.vdev; +struct rkisp1_vdev_node *node; +int ret; + +strlcpy (vdev->name, + stream->id ==RKISP1_STREAM_SP ?SP_VDEV_NAME :MP_VDEV_NAME , +sizeof (vdev->name)); + node =vdev_to_node (vdev); +mutex_init (&node->vlock); + + vdev->ioctl_ops = &rkisp1_v4l2_ioctl_ops; + vdev->release = video_device_release_empty; + vdev->fops = &rkisp1_fops; + vdev->minor =-1 ; + vdev->v4l2_dev = v4l2_dev; + vdev->lock = &node->vlock; + vdev->device_caps =V4L2_CAP_VIDEO_CAPTURE_MPLANE | +V4L2_CAP_STREAMING ; +video_set_drvdata (vdev, stream); + vdev->vfl_dir =VFL_DIR_RX ; + node->pad.flags =MEDIA_PAD_FL_SINK ; + +rkisp_init_vb2_queue (&node->buf_queue, stream, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); + vdev->queue = &node->buf_queue; + + ret =video_register_device (vdev,VFL_TYPE_GRABBER ,-1 ); +if (ret <0 ) { +v4l2_err (v4l2_dev, +"video_register_device failed with error %d\n" , ret); +return ret; + } + + vdev->entity.function =MEDIA_ENT_F_IO_V4L ; + ret =media_entity_pads_init (&vdev->entity,1 , &node->pad); +if (ret <0 ) + goto unreg; + +return 0 ; +unreg: +video_unregister_device (vdev); +return ret; +} + +int rkisp1_register_stream_vdevs (struct rkisp1_device *dev) +{ +struct rkisp1_stream *stream; +int i, j, ret; + +for (i =0 ; i <RKISP1_MAX_STREAM ; i++) { + stream = &dev->stream[i]; + stream->ispdev = dev; + ret =rkisp1_register_stream_vdev (stream); +if (ret <0 ) + goto err; + } + +return 0 ; +err: +for (j =0 ; j < i; j++) { + stream = &dev->stream[j]; +rkisp1_unregister_stream_vdev (stream); + } + +return ret; +} + +/**************** Interrupter Handler ****************/ + +void rkisp1_mi_isr (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +void __iomem *base = stream->ispdev->base_addr; +u32 val; + + stream->ops->clr_frame_end_int (base); +if (stream->ops->is_frame_end_int_masked (base)) { + val =mi_get_masked_int_status (base); +v4l2_err (&dev->v4l2_dev,"icr err: 0x%x\n" , val); + } + +if (stream->stopping) { +/* Make sure stream is actually stopped, whose state +* can be read from the shadow register, before wake_up() +* thread which would immediately free all frame buffers. +* stop_mi() takes effect at the next frame end +* that sync the configurations to shadow regs. +*/ +if (stream->ops->is_stream_stopped (dev->base_addr)) { + stream->stopping = false; + stream->state =RKISP1_STATE_READY ; +wake_up (&stream->done); + }else { + stream->ops->stop_mi (stream); + } + }else { +mi_frame_end (stream); + } +}drivers/media/platform/rockchip/isp1/capture.h new file +194
-0@@ -0,0 +1,194 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_PATH_VIDEO_H +#define _RKISP1_PATH_VIDEO_H + +#include "common.h" + +struct rkisp1_stream ; + +/* +* @fourcc: pixel format +* @mbus_code: pixel format over bus +* @fmt_type: helper filed for pixel format +* @bpp: bits per pixel +* @bayer_pat: bayer patten type +* @cplanes: number of colour planes +* @mplanes: number of stored memory planes +* @uv_swap: if cb cr swaped, for yuv +* @write_format: defines how YCbCr self picture data is written to memory +* @input_format: defines sp input format +* @output_format: defines sp output format +*/ +struct capture_fmt { +u32 fourcc; +u32 mbus_code; +u8 fmt_type; +u8 cplanes; +u8 mplanes; +u8 uv_swap; +u32 write_format; +u32 output_format; +u8 bpp[VIDEO_MAX_PLANES ]; +}; + +enum rkisp1_sp_inp { +RKISP1_SP_INP_ISP , +RKISP1_SP_INP_DMA_SP , +RKISP1_SP_INP_MAX +}; + +struct rkisp1_stream_sp { +int y_stride; +enum rkisp1_sp_inp input_sel; +}; + +struct rkisp1_stream_mp { +bool raw_enable; +}; + +/* Different config between selfpath and mainpath */ +struct stream_config { +const struct capture_fmt *fmts; +int fmt_size; +/* constrains */ +const int max_rsz_width; +const int max_rsz_height; +const int min_rsz_width; +const int min_rsz_height; +/* registers */ +struct { +u32 ctrl; +u32 ctrl_shd; +u32 scale_hy; +u32 scale_hcr; +u32 scale_hcb; +u32 scale_vy; +u32 scale_vc; +u32 scale_lut; +u32 scale_lut_addr; +u32 scale_hy_shd; +u32 scale_hcr_shd; +u32 scale_hcb_shd; +u32 scale_vy_shd; +u32 scale_vc_shd; +u32 phase_hy; +u32 phase_hc; +u32 phase_vy; +u32 phase_vc; +u32 phase_hy_shd; +u32 phase_hc_shd; +u32 phase_vy_shd; +u32 phase_vc_shd; + } rsz; +struct { +u32 ctrl; +u32 yuvmode_mask; +u32 rawmode_mask; +u32 h_offset; +u32 v_offset; +u32 h_size; +u32 v_size; + } dual_crop; +struct { +u32 y_size_init; +u32 cb_size_init; +u32 cr_size_init; +u32 y_base_ad_init; +u32 cb_base_ad_init; +u32 cr_base_ad_init; +u32 y_offs_cnt_init; +u32 cb_offs_cnt_init; +u32 cr_offs_cnt_init; + } mi; +}; + +/* Different reg ops between selfpath and mainpath */ +struct streams_ops { +int (*config_mi)(struct rkisp1_stream *stream); +void (*stop_mi)(struct rkisp1_stream *stream); +void (*enable_mi)(struct rkisp1_stream *stream); +void (*disable_mi)(struct rkisp1_stream *stream); +void (*set_data_path)(void __iomem *base); +void (*clr_frame_end_int)(void __iomem *base); +bool (*is_frame_end_int_masked)(void __iomem *base); +bool (*is_stream_stopped)(void __iomem *base); +}; + +/* +* struct rkisp1_stream - ISP capture video device +* +* @out_isp_fmt: output isp format +* @out_fmt: output buffer size +* @dcrop: coordinates of dual-crop +* +* @vbq_lock: lock to protect buf_queue +* @buf_queue: queued buffer list +* @dummy_buf: dummy space to store dropped data +* +* rkisp1 use shadowsock registers, so it need two buffer at a time +* @curr_buf: the buffer used for current frame +* @next_buf: the buffer used for next frame +*/ +struct rkisp1_stream { +u32 id; +struct rkisp1_device *ispdev; +struct rkisp1_vdev_node vnode; +enum rkisp1_state state; +enum rkisp1_state saved_state; +struct capture_fmt out_isp_fmt; +struct v4l2_pix_format_mplane out_fmt; +struct v4l2_rect dcrop; +struct streams_ops *ops; +struct stream_config *config; +spinlock_t vbq_lock; +struct list_head buf_queue; +struct rkisp1_dummy_buffer dummy_buf; +struct rkisp1_buffer *curr_buf; +struct rkisp1_buffer *next_buf; +bool stopping; +wait_queue_head_t done; +union { +struct rkisp1_stream_sp sp; +struct rkisp1_stream_mp mp; + } u; +}; + +void rkisp1_unregister_stream_vdevs (struct rkisp1_device *dev); +int rkisp1_register_stream_vdevs (struct rkisp1_device *dev); +void rkisp1_mi_isr (struct rkisp1_stream *stream); +void rkisp1_stream_init (struct rkisp1_device *dev,u32 id); + +#endif /* _RKISP1_PATH_VIDEO_H */ drivers/media/platform/rockchip/isp1/common.h new file +137
-0@@ -0,0 +1,137 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_COMMON_H +#define _RKISP1_COMMON_H + +#include <linux/mutex.h> +#include <media/media-device.h> +#include <media/media-entity.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/videobuf2-v4l2.h> + +#define RKISP1_DEFAULT_WIDTH 800 +#define RKISP1_DEFAULT_HEIGHT 600 + +#define RKISP1_MAX_STREAM 2 +#define RKISP1_STREAM_SP 0 +#define RKISP1_STREAM_MP 1 + +#define RKISP1_PLANE_Y 0 +#define RKISP1_PLANE_CB 1 +#define RKISP1_PLANE_CR 2 + +enum rkisp1_sd_type { +RKISP1_SD_SENSOR , +RKISP1_SD_PHY_CSI , +RKISP1_SD_VCM , +RKISP1_SD_FLASH , +RKISP1_SD_MAX , +}; + +/* One structure per video node */ +struct rkisp1_vdev_node { +struct vb2_queue buf_queue; +/* vfd lock */ +struct mutex vlock; +struct video_device vdev; +struct media_pad pad; +}; + +enum rkisp1_fmt_pix_type { +FMT_YUV , +FMT_RGB , +FMT_BAYER , +FMT_JPEG , +FMT_MAX +}; + +enum rkisp1_fmt_raw_pat_type { +RAW_RGGB =0 , +RAW_GRBG , +RAW_GBRG , +RAW_BGGR , +}; + +enum rkisp1_state { +/* path not yet opened: */ +RKISP1_STATE_DISABLED , +/* path opened and configured, ready for streaming: */ +RKISP1_STATE_READY , +/* path is streaming: */ +RKISP1_STATE_STREAMING +}; + +struct rkisp1_buffer { +struct vb2_v4l2_buffer vb; +struct list_head queue; +union { +u32 buff_addr[VIDEO_MAX_PLANES ]; +void *vaddr[VIDEO_MAX_PLANES ]; + }; +}; + +struct rkisp1_dummy_buffer { +void *vaddr; +dma_addr_t dma_addr; +u32 size; +}; + +extern int rkisp1_debug; + +static inline +struct rkisp1_vdev_node *vdev_to_node (struct video_device *vdev) +{ + return container_of(vdev, struct rkisp1_vdev_node, vdev); +} + +static inline struct rkisp1_vdev_node *queue_to_node (struct vb2_queue *q) +{ + return container_of(q, struct rkisp1_vdev_node, buf_queue); +} + +static inline struct rkisp1_buffer *to_rkisp1_buffer (struct vb2_v4l2_buffer *vb) +{ + return container_of(vb, struct rkisp1_buffer, vb); +} + +static inline struct vb2_queue *to_vb2_queue (struct file *file) +{ +struct rkisp1_vdev_node *vnode =video_drvdata (file); + +return &vnode->buf_queue; +} + +#endif /* _RKISP1_COMMON_H */ drivers/media/platform/rockchip/isp1/dev.c new file +655
-0@@ -0,0 +1,655 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_graph.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/pinctrl/consumer.h> +#include "common.h" +#include "regs.h" + +struct isp_match_data { +const char *const *clks; +int size; +}; + +int rkisp1_debug; +module_param_named (debug, rkisp1_debug, int,0644 ); +MODULE_PARM_DESC (debug,"Debug level (0-1)" ); + +/***************************** pipeline operations*******************************/ + +static int __isp_pipeline_prepare (struct rkisp1_pipeline *p, +struct media_entity *me) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +struct v4l2_subdev *sd; +int i; + + p->num_subdevs =0 ; +memset (p->subdevs,0 ,sizeof (p->subdevs)); + +while (1 ) { +struct media_pad *pad =NULL ; + +/* Find remote source pad */ +for (i =0 ; i < me->num_pads; i++) { +struct media_pad *spad = &me->pads[i]; + +if (!(spad->flags &MEDIA_PAD_FL_SINK )) +continue ; + pad =media_entity_remote_pad (spad); +if (pad) +break ; + } + +if (!pad) +break ; + + sd =media_entity_to_v4l2_subdev (pad->entity); +if (sd != &dev->isp_sdev.sd) + p->subdevs[p->num_subdevs++] = sd; + + me = &sd->entity; +if (me->num_pads ==1 ) +break ; + } +return 0 ; +} + +static int __subdev_set_power (struct v4l2_subdev *sd,int on) +{ +int ret; + +if (!sd) +return -ENXIO ; + + ret =v4l2_subdev_call (sd, core, s_power, on); + +return ret != -ENOIOCTLCMD ? ret :0 ; +} + +static int __isp_pipeline_s_power (struct rkisp1_pipeline *p,bool on) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +int i, ret; + +if (on) { +__subdev_set_power (&dev->isp_sdev.sd, true); + +for (i = p->num_subdevs -1 ; i >=0 ; --i) { + ret =__subdev_set_power (p->subdevs[i], true); +if (ret <0 && ret != -ENXIO ) + goto err_power_off; + } + }else { +for (i =0 ; i < p->num_subdevs; ++i) +__subdev_set_power (p->subdevs[i], false); + +__subdev_set_power (&dev->isp_sdev.sd, false); + } + +return 0 ; + +err_power_off: +for (++i; i < p->num_subdevs; ++i) +__subdev_set_power (p->subdevs[i], false); +__subdev_set_power (&dev->isp_sdev.sd, true); +return ret; +} + +static int rkisp1_pipeline_open (struct rkisp1_pipeline *p, +struct media_entity *me, +bool prepare) +{ +int ret; + +if (WARN_ON (!p || !me)) +return -EINVAL ; +if (atomic_inc_return (&p->power_cnt) >1 ) +return 0 ; + +/* go through media graphic and get subdevs */ +if (prepare) +__isp_pipeline_prepare (p, me); + +if (!p->num_subdevs) +return -EINVAL ; + + ret =__isp_pipeline_s_power (p,1 ); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int rkisp1_pipeline_close (struct rkisp1_pipeline *p) +{ +int ret; + +if (atomic_dec_return (&p->power_cnt) >0 ) +return 0 ; + ret =__isp_pipeline_s_power (p,0 ); + +return ret == -ENXIO ?0 : ret; +} + +/* +* stream-on order: isp_subdev, mipi dphy, sensor +* stream-off order: mipi dphy, sensor, isp_subdev +*/ +static int rkisp1_pipeline_set_stream (struct rkisp1_pipeline *p,bool on) +{ + struct rkisp1_device *dev = container_of(p, struct rkisp1_device, pipe); +int i, ret; + +if ((on &&atomic_inc_return (&p->stream_cnt) >1 ) || + (!on &&atomic_dec_return (&p->stream_cnt) >0 )) +return 0 ; + +if (on) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, true); + +/* phy -> sensor */ +for (i =0 ; i < p->num_subdevs; ++i) { + ret =v4l2_subdev_call (p->subdevs[i], video, s_stream, on); +if (on && ret <0 && ret != -ENOIOCTLCMD && ret != -ENODEV ) + goto err_stream_off; + } + +if (!on) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, false); + +return 0 ; + +err_stream_off: +for (--i; i >=0 ; --i) +v4l2_subdev_call (p->subdevs[i], video, s_stream, false); +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, false); +return ret; +} + +/***************************** media controller *******************************/ +/* See http://opensource.rock-chips.com/wiki_Rockchip-isp1 for Topology */ + +static int rkisp1_create_links (struct rkisp1_device *dev) +{ +struct media_entity *source, *sink; +unsigned int flags, s, pad; +int ret; + +/* sensor links(or mipi-phy) */ +for (s =0 ; s < dev->num_sensors; ++s) { +struct rkisp1_sensor_info *sensor = &dev->sensors[s]; + +for (pad =0 ; pad < sensor->sd->entity.num_pads; pad++) +if (sensor->sd->entity.pads[pad].flags & +MEDIA_PAD_FL_SOURCE ) +break ; + +if (pad == sensor->sd->entity.num_pads) { +dev_err (dev->dev, +"failed to find src pad for %s\n" , + sensor->sd->name); + +return -ENXIO ; + } + + ret =media_create_pad_link ( + &sensor->sd->entity, pad, + &dev->isp_sdev.sd.entity, +RKISP1_ISP_PAD_SINK + s, + s ?0 :MEDIA_LNK_FL_ENABLED ); +if (ret) { +dev_err (dev->dev, +"failed to create link for %s\n" , + sensor->sd->name); +return ret; + } + } + +/* params links */ + source = &dev->params_vdev.vnode.vdev.entity; + sink = &dev->isp_sdev.sd.entity; + flags =MEDIA_LNK_FL_ENABLED ; + ret =media_create_pad_link (source,0 , sink, +RKISP1_ISP_PAD_SINK_PARAMS , flags); +if (ret <0 ) +return ret; + +/* create isp internal links */ +/* SP links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stream[RKISP1_STREAM_SP ].vnode.vdev.entity; + ret =media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_PATH , + sink,0 , flags); +if (ret <0 ) +return ret; + +/* MP links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stream[RKISP1_STREAM_MP ].vnode.vdev.entity; + ret =media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_PATH , + sink,0 , flags); +if (ret <0 ) +return ret; + +/* 3A stats links */ + source = &dev->isp_sdev.sd.entity; + sink = &dev->stats_vdev.vnode.vdev.entity; +return media_create_pad_link (source,RKISP1_ISP_PAD_SOURCE_STATS , + sink,0 , flags); +} + +static int subdev_notifier_complete (struct v4l2_async_notifier *notifier) +{ +struct rkisp1_device *dev; +int ret; + + dev = container_of(notifier, struct rkisp1_device, notifier); + +mutex_lock (&dev->media_dev.graph_mutex); + ret =rkisp1_create_links (dev); +if (ret <0 ) + goto unlock; + ret =v4l2_device_register_subdev_nodes (&dev->v4l2_dev); +if (ret <0 ) + goto unlock; + +v4l2_info (&dev->v4l2_dev,"Async subdev notifier completed\n" ); + +unlock: +mutex_unlock (&dev->media_dev.graph_mutex); +return ret; +} + +struct rkisp1_async_subdev { +struct v4l2_async_subdev asd; +struct v4l2_mbus_config mbus; +}; + +static int subdev_notifier_bound (struct v4l2_async_notifier *notifier, +struct v4l2_subdev *subdev, +struct v4l2_async_subdev *asd) +{ +struct rkisp1_device *isp_dev =container_of (notifier, + struct rkisp1_device, notifier); +struct rkisp1_async_subdev *s_asd =container_of (asd, + struct rkisp1_async_subdev, asd); + +if (isp_dev->num_sensors ==ARRAY_SIZE (isp_dev->sensors)) +return -EBUSY ; + + isp_dev->sensors[isp_dev->num_sensors].mbus = s_asd->mbus; + isp_dev->sensors[isp_dev->num_sensors].sd = subdev; + ++isp_dev->num_sensors; + +v4l2_dbg (1 , rkisp1_debug, subdev,"Async registered subdev\n" ); + +return 0 ; +} + +static int rkisp1_fwnode_parse (struct device *dev, +struct v4l2_fwnode_endpoint *vep, +struct v4l2_async_subdev *asd) +{ +struct rkisp1_async_subdev *rk_asd = + container_of(asd, struct rkisp1_async_subdev, asd); +struct v4l2_fwnode_bus_parallel *bus = &vep->bus.parallel; + +/* +* MIPI sensor is linked with a mipi dphy and its media bus config can +* not be get in here +*/ +if (vep->bus_type !=V4L2_MBUS_BT656 && + vep->bus_type !=V4L2_MBUS_PARALLEL ) +return 0 ; + + rk_asd->mbus.flags = bus->flags; + rk_asd->mbus.type = vep->bus_type; + +return 0 ; +} + +static const struct v4l2_async_notifier_operations subdev_notifier_ops = { + .bound = subdev_notifier_bound, + .complete = subdev_notifier_complete, +}; + +static int isp_subdev_notifier (struct rkisp1_device *isp_dev) +{ +struct v4l2_async_notifier *ntf = &isp_dev->notifier; +struct device *dev = isp_dev->dev; +int ret; + + ret =v4l2_async_notifier_parse_fwnode_endpoints ( + dev, ntf,sizeof (struct rkisp1_async_subdev ), + rkisp1_fwnode_parse); +if (ret <0 ) +return ret; + +if (!ntf->num_subdevs) +return -ENODEV ;/* no endpoint */ + + ntf->ops = &subdev_notifier_ops; + +return v4l2_async_notifier_register (&isp_dev->v4l2_dev, ntf); +} + +/***************************** platform deive *******************************/ + +static int rkisp1_register_platform_subdevs (struct rkisp1_device *dev) +{ +int ret; + + ret =rkisp1_register_isp_subdev (dev, &dev->v4l2_dev); +if (ret <0 ) +return ret; + + ret =rkisp1_register_stream_vdevs (dev); +if (ret <0 ) + goto err_unreg_isp_subdev; + + ret =rkisp1_register_stats_vdev (&dev->stats_vdev, &dev->v4l2_dev, dev); +if (ret <0 ) + goto err_unreg_stream_vdev; + + ret =rkisp1_register_params_vdev (&dev->params_vdev, &dev->v4l2_dev, + dev); +if (ret <0 ) + goto err_unreg_stats_vdev; + + ret =isp_subdev_notifier (dev); +if (ret <0 ) { +v4l2_err (&dev->v4l2_dev, +"Failed to register subdev notifier(%d)\n" , ret); + goto err_unreg_params_vdev; + } + +return 0 ; +err_unreg_params_vdev: +rkisp1_unregister_params_vdev (&dev->params_vdev); +err_unreg_stats_vdev: +rkisp1_unregister_stats_vdev (&dev->stats_vdev); +err_unreg_stream_vdev: +rkisp1_unregister_stream_vdevs (dev); +err_unreg_isp_subdev: +rkisp1_unregister_isp_subdev (dev); +return ret; +} + +static const char *const rk3399_isp_clks[] = { +"clk_isp" , +"aclk_isp" , +"hclk_isp" , +"aclk_isp_wrap" , +"hclk_isp_wrap" , +}; + +static const char *const rk3288_isp_clks[] = { +"clk_isp" , +"aclk_isp" , +"hclk_isp" , +"pclk_isp_in" , +"sclk_isp_jpe" , +}; + +static const struct isp_match_data rk3288_isp_clk_data = { + .clks = rk3288_isp_clks, + .size =ARRAY_SIZE (rk3288_isp_clks), +}; + +static const struct isp_match_data rk3399_isp_clk_data = { + .clks = rk3399_isp_clks, + .size =ARRAY_SIZE (rk3399_isp_clks), +}; + +static const struct of_device_id rkisp1_plat_of_match[] = { + { + .compatible ="rockchip,rk3288-cif-isp" , + .data = &rk3288_isp_clk_data, + }, { + .compatible ="rockchip,rk3399-cif-isp" , + .data = &rk3399_isp_clk_data, + }, + {}, +}; + +static irqreturn_t rkisp1_irq_handler (int irq,void *cntxt) +{ +struct device *dev = cntxt; +struct rkisp1_device *rkisp1_dev =dev_get_drvdata (dev); +void __iomem *base = rkisp1_dev->base_addr; +unsigned int mis_val, i; + + mis_val =readl (rkisp1_dev->base_addr +CIF_ISP_MIS ); +if (mis_val) +rkisp1_isp_isr (mis_val, rkisp1_dev); + + mis_val =readl (rkisp1_dev->base_addr +CIF_MIPI_MIS ); +if (mis_val) +rkisp1_mipi_isr (mis_val, rkisp1_dev); + +for (i =0 ; i <RKISP1_MAX_STREAM ; ++i) { +struct rkisp1_stream *stream = &rkisp1_dev->stream[i]; + +if (stream->ops->is_frame_end_int_masked (base)) +rkisp1_mi_isr (stream); + } + +clr_all_int (base); + +return IRQ_HANDLED ; +} + +static void rkisp1_disable_sys_clk (struct rkisp1_device *rkisp1_dev) +{ +int i; + +for (i = rkisp1_dev->clk_size -1 ; i >=0 ; i--) +clk_disable_unprepare (rkisp1_dev->clks[i]); +} + +static int rkisp1_enable_sys_clk (struct rkisp1_device *rkisp1_dev) +{ +int i, ret = -EINVAL ; + +for (i =0 ; i < rkisp1_dev->clk_size; i++) { + ret =clk_prepare_enable (rkisp1_dev->clks[i]); +if (ret <0 ) + goto err; + } +return 0 ; +err: +for (--i; i >=0 ; --i) +clk_disable_unprepare (rkisp1_dev->clks[i]); +return ret; +} + +static int rkisp1_plat_probe (struct platform_device *pdev) +{ +const struct of_device_id *match; +struct device_node *node = pdev->dev.of_node; +struct device *dev = &pdev->dev; +struct v4l2_device *v4l2_dev; +struct rkisp1_device *isp_dev; +const struct isp_match_data *clk_data; + +struct resource *res; +int i, ret, irq; + + match =of_match_node (rkisp1_plat_of_match, node); + isp_dev =devm_kzalloc (dev,sizeof (*isp_dev),GFP_KERNEL ); +if (!isp_dev) +return -ENOMEM ; + +dev_set_drvdata (dev, isp_dev); + isp_dev->dev = dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + isp_dev->base_addr =devm_ioremap_resource (dev, res); +if (IS_ERR (isp_dev->base_addr)) +return PTR_ERR (isp_dev->base_addr); + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) +return irq; + + ret =devm_request_irq (dev, irq, rkisp1_irq_handler,IRQF_SHARED , +dev_driver_string (dev), dev); +if (ret <0 ) { +dev_err (dev,"request irq failed: %d\n" , ret); +return ret; + } + + isp_dev->irq = irq; + clk_data = match->data; +for (i =0 ; i < clk_data->size; i++) { +struct clk *clk =devm_clk_get (dev, clk_data->clks[i]); + +if (IS_ERR (clk)) { +dev_err (dev,"failed to get %s\n" , clk_data->clks[i]); +return PTR_ERR (clk); + } + isp_dev->clks[i] = clk; + } + isp_dev->clk_size = clk_data->size; + +atomic_set (&isp_dev->pipe.power_cnt,0 ); +atomic_set (&isp_dev->pipe.stream_cnt,0 ); + isp_dev->pipe.open = rkisp1_pipeline_open; + isp_dev->pipe.close = rkisp1_pipeline_close; + isp_dev->pipe.set_stream = rkisp1_pipeline_set_stream; + +rkisp1_stream_init (isp_dev,RKISP1_STREAM_SP ); +rkisp1_stream_init (isp_dev,RKISP1_STREAM_MP ); + +strlcpy (isp_dev->media_dev.model,"rkisp1" , +sizeof (isp_dev->media_dev.model)); + isp_dev->media_dev.dev = &pdev->dev; +media_device_init (&isp_dev->media_dev); + + v4l2_dev = &isp_dev->v4l2_dev; + v4l2_dev->mdev = &isp_dev->media_dev; +strlcpy (v4l2_dev->name,"rkisp1" ,sizeof (v4l2_dev->name)); +v4l2_ctrl_handler_init (&isp_dev->ctrl_handler,5 ); + v4l2_dev->ctrl_handler = &isp_dev->ctrl_handler; + + ret =v4l2_device_register (isp_dev->dev, &isp_dev->v4l2_dev); +if (ret <0 ) +return ret; + + ret =media_device_register (&isp_dev->media_dev); +if (ret <0 ) { +v4l2_err (v4l2_dev,"Failed to register media device: %d\n" , + ret); + goto err_unreg_v4l2_dev; + } + +/* create & register platefom subdev (from of_node) */ + ret =rkisp1_register_platform_subdevs (isp_dev); +if (ret <0 ) + goto err_unreg_media_dev; + +pm_runtime_enable (&pdev->dev); + +return 0 ; + +err_unreg_media_dev: +media_device_unregister (&isp_dev->media_dev); +err_unreg_v4l2_dev: +v4l2_device_unregister (&isp_dev->v4l2_dev); +return ret; +} + +static int rkisp1_plat_remove (struct platform_device *pdev) +{ +struct rkisp1_device *isp_dev =platform_get_drvdata (pdev); + +pm_runtime_disable (&pdev->dev); +media_device_unregister (&isp_dev->media_dev); +v4l2_device_unregister (&isp_dev->v4l2_dev); +rkisp1_unregister_params_vdev (&isp_dev->params_vdev); +rkisp1_unregister_stats_vdev (&isp_dev->stats_vdev); +rkisp1_unregister_stream_vdevs (isp_dev); +rkisp1_unregister_isp_subdev (isp_dev); + +return 0 ; +} + +static int __maybe_unused rkisp1_runtime_suspend (struct device *dev) +{ +struct rkisp1_device *isp_dev =dev_get_drvdata (dev); + +rkisp1_disable_sys_clk (isp_dev); +return pinctrl_pm_select_sleep_state (dev); +} + +static int __maybe_unused rkisp1_runtime_resume (struct device *dev) +{ +struct rkisp1_device *isp_dev =dev_get_drvdata (dev); +int ret; + + ret =pinctrl_pm_select_default_state (dev); +if (ret <0 ) +return ret; +rkisp1_enable_sys_clk (isp_dev); + +return 0 ; +} + +static const struct dev_pm_ops rkisp1_plat_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) +SET_RUNTIME_PM_OPS (rkisp1_runtime_suspend, rkisp1_runtime_resume,NULL ) +}; + +static struct platform_driver rkisp1_plat_drv = { + .driver = { + .name =DRIVER_NAME , + .of_match_table =of_match_ptr (rkisp1_plat_of_match), + .pm = &rkisp1_plat_pm_ops, + }, + .probe = rkisp1_plat_probe, + .remove = rkisp1_plat_remove, +}; + +module_platform_driver (rkisp1_plat_drv); +MODULE_AUTHOR ("Rockchip Camera/ISP team" ); +MODULE_DESCRIPTION ("Rockchip ISP1 platform driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );drivers/media/platform/rockchip/isp1/dev.h new file +120
-0@@ -0,0 +1,120 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#ifndef _RKISP1_DEV_H +#define _RKISP1_DEV_H + +#include "capture.h" +#include "rkisp1.h" +#include "isp_params.h" +#include "isp_stats.h" + +#define DRIVER_NAME "rkisp1" +#define ISP_VDEV_NAME DRIVER_NAME "_ispdev" +#define SP_VDEV_NAME DRIVER_NAME "_selfpath" +#define MP_VDEV_NAME DRIVER_NAME "_mainpath" +#define DMA_VDEV_NAME DRIVER_NAME "_dmapath" + +#define GRP_ID_SENSOR BIT(0) +#define GRP_ID_MIPIPHY BIT(1) +#define GRP_ID_ISP BIT(2) +#define GRP_ID_ISP_MP BIT(3) +#define GRP_ID_ISP_SP BIT(4) + +#define RKISP1_MAX_BUS_CLK 8 +#define RKISP1_MAX_SENSOR 2 +#define RKISP1_MAX_PIPELINE 4 + +/* +* struct rkisp1_pipeline - An ISP hardware pipeline +* +* Capture device call other devices via pipeline +* +* @num_subdevs: number of linked subdevs +* @power_cnt: pipeline power count +* @stream_cnt: stream power count +*/ +struct rkisp1_pipeline { +struct media_pipeline pipe; +int num_subdevs; +atomic_t power_cnt; +atomic_t stream_cnt; +struct v4l2_subdev *subdevs[RKISP1_MAX_PIPELINE ]; +int (*open)(struct rkisp1_pipeline *p, +struct media_entity *me,bool prepare); +int (*close)(struct rkisp1_pipeline *p); +int (*set_stream)(struct rkisp1_pipeline *p,bool on); +}; + +/* +* struct rkisp1_sensor_info - Sensor infomations +* @mbus: media bus configuration +*/ +struct rkisp1_sensor_info { +struct v4l2_subdev *sd; +struct v4l2_mbus_config mbus; +}; + +/* +* struct rkisp1_device - ISP platform device +* @base_addr: base register address +* @active_sensor: sensor in-use, set when streaming on +* @isp_sdev: ISP sub-device +* @rkisp1_stream: capture video device +* @stats_vdev: ISP statistics output device +* @params_vdev: ISP input parameters device +*/ +struct rkisp1_device { +void __iomem *base_addr; +int irq; +struct device *dev; +struct clk *clks[RKISP1_MAX_BUS_CLK ]; +int clk_size; +struct v4l2_device v4l2_dev; +struct v4l2_ctrl_handler ctrl_handler; +struct media_device media_dev; +struct v4l2_async_notifier notifier; +struct v4l2_subdev *subdevs[RKISP1_SD_MAX ]; +struct rkisp1_sensor_info *active_sensor; +struct rkisp1_sensor_info sensors[RKISP1_MAX_SENSOR ]; +int num_sensors; +struct rkisp1_isp_subdev isp_sdev; +struct rkisp1_stream stream[RKISP1_MAX_STREAM ]; +struct rkisp1_isp_stats_vdev stats_vdev; +struct rkisp1_isp_params_vdev params_vdev; +struct rkisp1_pipeline pipe; +struct vb2_alloc_ctx *alloc_ctx; +}; + +#endif drivers/media/platform/rockchip/isp1/isp_params.c new file +829
-0@@ -0,0 +1,1543 @@ +/* +* Rockchip isp1 driver +* +* Copyright (C) 2017 Rockchip Electronics Co., Ltd. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* Redistribution and use in source and binary forms, with or +* without modification, are permitted provided that the following +* conditions are met: +* +* - Redistributions of source code must retain the above +* copyright notice, this list of conditions and the following +* disclaimer. +* +* - Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/videobuf2-core.h> +#include <media/videobuf2-vmalloc.h> /* for ISP params */ +#include "dev.h" +#include "regs.h" + +#define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2 +#define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8 + +#define BLS_START_H_MAX_IS_VALID (val) ((val) < CIFISP_BLS_START_H_MAX) +#define BLS_STOP_H_MAX_IS_VALID (val) ((val) < CIFISP_BLS_STOP_H_MAX) + +#define BLS_START_V_MAX_IS_VALID (val) ((val) < CIFISP_BLS_START_V_MAX) +#define BLS_STOP_V_MAX_IS_VALID (val) ((val) < CIFISP_BLS_STOP_V_MAX) + +#define BLS_SAMPLE_MAX_IS_VALID (val) ((val) < CIFISP_BLS_SAMPLES_MAX) + +#define BLS_FIX_SUB_IS_VALID (val) \ + ((val) > (s16) CIFISP_BLS_FIX_SUB_MIN && (val) < CIFISP_BLS_FIX_SUB_MAX) + +#define RKISP1_ISP_DPCC_LINE_THRESH (n) (CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_LINE_MAD_FAC (n) (CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_PG_FAC (n) (CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_RND_THRESH (n) (CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n)) +#define RKISP1_ISP_DPCC_RG_FAC (n) (CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n)) +#define RKISP1_ISP_CC_COEFF (n) (CIF_ISP_CC_COEFF_0 + (n) * 4) + +static inline void rkisp1_iowrite32 (struct rkisp1_isp_params_vdev *params_vdev, +u32 value,u32 addr) +{ +iowrite32 (value, params_vdev->dev->base_addr + addr); +} + +static inline u32 rkisp1_ioread32 (struct rkisp1_isp_params_vdev *params_vdev, +u32 addr) +{ +return ioread32 (params_vdev->dev->base_addr + addr); +} + +static inline void isp_param_set_bits (struct rkisp1_isp_params_vdev + *params_vdev, +u32 reg,u32 bit_mask) +{ +u32 val; + + val =rkisp1_ioread32 (params_vdev, reg); +rkisp1_iowrite32 (params_vdev, val | bit_mask, reg); +} + +static inline void isp_param_clear_bits (struct rkisp1_isp_params_vdev + *params_vdev, +u32 reg,u32 bit_mask) +{ +u32 val; + + val =rkisp1_ioread32 (params_vdev, reg); +rkisp1_iowrite32 (params_vdev, val & ~bit_mask, reg); +} + +/* ISP BP interface function */ +static void dpcc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpcc_config *arg) +{ +unsigned int i; + +rkisp1_iowrite32 (params_vdev, arg->mode,CIF_ISP_DPCC_MODE ); +rkisp1_iowrite32 (params_vdev, arg->output_mode, +CIF_ISP_DPCC_OUTPUT_MODE ); +rkisp1_iowrite32 (params_vdev, arg->set_use,CIF_ISP_DPCC_SET_USE ); + +rkisp1_iowrite32 (params_vdev, arg->methods[0 ].method, +CIF_ISP_DPCC_METHODS_SET_1 ); +rkisp1_iowrite32 (params_vdev, arg->methods[1 ].method, +CIF_ISP_DPCC_METHODS_SET_2 ); +rkisp1_iowrite32 (params_vdev, arg->methods[2 ].method, +CIF_ISP_DPCC_METHODS_SET_3 ); +for (i =0 ; i <CIFISP_DPCC_METHODS_MAX ; i++) { +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_thresh, +RKISP1_ISP_DPCC_LINE_THRESH (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_mad_fac, +RKISP1_ISP_DPCC_LINE_MAD_FAC (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].pg_fac, +RKISP1_ISP_DPCC_PG_FAC (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rnd_thresh, +RKISP1_ISP_DPCC_RND_THRESH (i)); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rg_fac, +RKISP1_ISP_DPCC_RG_FAC (i)); + } + +rkisp1_iowrite32 (params_vdev, arg->rnd_offs,CIF_ISP_DPCC_RND_OFFS ); +rkisp1_iowrite32 (params_vdev, arg->ro_limits,CIF_ISP_DPCC_RO_LIMITS ); +} + +/* ISP black level subtraction interface function */ +static void bls_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_bls_config *arg) +{ +u32 new_control =0 ; + +/* fixed subtraction values */ +if (!arg->enable_auto) { +const struct cifisp_bls_fixed_val *pval = &arg->fixed_val; + +switch (params_vdev->raw_type) { +case RAW_BGGR : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_A_FIXED ); +break ; +case RAW_GBRG : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_B_FIXED ); +break ; +case RAW_GRBG : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_D_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_C_FIXED ); +break ; +case RAW_RGGB : +rkisp1_iowrite32 (params_vdev, + pval->r,CIF_ISP_BLS_A_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gr,CIF_ISP_BLS_B_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->gb,CIF_ISP_BLS_C_FIXED ); +rkisp1_iowrite32 (params_vdev, + pval->b,CIF_ISP_BLS_D_FIXED ); +break ; +default : +break ; + } + + new_control =CIF_ISP_BLS_MODE_FIXED ; + }else { +if (arg->en_windows &BIT (1 )) { +rkisp1_iowrite32 (params_vdev, arg->bls_window2.h_offs, +CIF_ISP_BLS_H2_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.h_size, +CIF_ISP_BLS_H2_STOP ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.v_offs, +CIF_ISP_BLS_V2_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window2.v_size, +CIF_ISP_BLS_V2_STOP ); + new_control |=CIF_ISP_BLS_WINDOW_2 ; + } + +if (arg->en_windows &BIT (0 )) { +rkisp1_iowrite32 (params_vdev, arg->bls_window1.h_offs, +CIF_ISP_BLS_H1_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.h_size, +CIF_ISP_BLS_H1_STOP ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.v_offs, +CIF_ISP_BLS_V1_START ); +rkisp1_iowrite32 (params_vdev, arg->bls_window1.v_size, +CIF_ISP_BLS_V1_STOP ); + new_control |=CIF_ISP_BLS_WINDOW_1 ; + } + +rkisp1_iowrite32 (params_vdev, arg->bls_samples, +CIF_ISP_BLS_SAMPLES ); + + new_control |=CIF_ISP_BLS_MODE_MEASURED ; + } +rkisp1_iowrite32 (params_vdev, new_control,CIF_ISP_BLS_CTRL ); +} + +/* ISP LS correction interface function */ +static void +__lsc_correct_matrix_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_lsc_config *pconfig) +{ +int i, j; +unsigned int isp_lsc_status, sram_addr, isp_lsc_table_sel; +unsigned int data; + + isp_lsc_status =rkisp1_ioread32 (params_vdev,CIF_ISP_LSC_STATUS ); + +/* CIF_ISP_LSC_TABLE_ADDRESS_153 = ( 17 * 18 ) >> 1 */ + sram_addr = (isp_lsc_status &CIF_ISP_LSC_ACTIVE_TABLE ) ? +CIF_ISP_LSC_TABLE_ADDRESS_0 : +CIF_ISP_LSC_TABLE_ADDRESS_153 ; +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_R_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_GR_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_GB_TABLE_ADDR ); +rkisp1_iowrite32 (params_vdev, sram_addr,CIF_ISP_LSC_B_TABLE_ADDR ); + +/* program data tables (table size is 9 * 17 = 153) */ +for (i =0 ; i < ((CIF_ISP_LSC_SECTORS_MAX +1 ) * + (CIF_ISP_LSC_SECTORS_MAX +1 )); + i +=CIF_ISP_LSC_SECTORS_MAX +1 ) { +/* +* 17 sectors with 2 values in one DWORD = 9 +* DWORDs (2nd value of last DWORD unused) +*/ +for (j =0 ; j < (CIF_ISP_LSC_SECTORS_MAX +1 ); j +=2 ) { + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->r_data_tbl[i + j], + pconfig->r_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_R_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->gr_data_tbl[i + j], + pconfig->gr_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_GR_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->gb_data_tbl[i + j], + pconfig->gb_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_GB_TABLE_DATA ); + + data =CIF_ISP_LSC_TABLE_DATA ( + pconfig->b_data_tbl[i + j], + pconfig->b_data_tbl[i + j +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_B_TABLE_DATA ); + } + } + + isp_lsc_table_sel = (isp_lsc_status &CIF_ISP_LSC_ACTIVE_TABLE ) ? +CIF_ISP_LSC_TABLE_0 :CIF_ISP_LSC_TABLE_1 ; +rkisp1_iowrite32 (params_vdev, isp_lsc_table_sel,CIF_ISP_LSC_TABLE_SEL ); +} + +static void lsc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_lsc_config *arg) +{ +int i; +u32 lsc_ctrl; +unsigned int data; + +/* To config must be off , store the current status firstly */ + lsc_ctrl =rkisp1_ioread32 (params_vdev,CIF_ISP_LSC_CTRL ); +isp_param_clear_bits (params_vdev,CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +__lsc_correct_matrix_config (params_vdev, arg); + +for (i =0 ; i <4 ; i++) { +/* program x size tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->x_size_tbl[i *2 ], + arg->x_size_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_XSIZE_01 + i *4 ); + +/* program x grad tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->x_grad_tbl[i *2 ], + arg->x_grad_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_XGRAD_01 + i *4 ); + +/* program y size tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->y_size_tbl[i *2 ], + arg->y_size_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_YSIZE_01 + i *4 ); + +/* program y grad tables */ + data =CIF_ISP_LSC_SECT_SIZE (arg->y_grad_tbl[i *2 ], + arg->y_grad_tbl[i *2 +1 ]); +rkisp1_iowrite32 (params_vdev, data, +CIF_ISP_LSC_YGRAD_01 + i *4 ); + } + +/* restore the bls ctrl status */ +if (lsc_ctrl &CIF_ISP_LSC_CTRL_ENA ) { +isp_param_set_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + }else { +isp_param_clear_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + } +} + +/* ISP Filtering function */ +static void flt_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_flt_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->thresh_bl0,CIF_ISP_FILT_THRESH_BL0 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_bl1,CIF_ISP_FILT_THRESH_BL1 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_sh0,CIF_ISP_FILT_THRESH_SH0 ); +rkisp1_iowrite32 (params_vdev, arg->thresh_sh1,CIF_ISP_FILT_THRESH_SH1 ); +rkisp1_iowrite32 (params_vdev, arg->fac_bl0,CIF_ISP_FILT_FAC_BL0 ); +rkisp1_iowrite32 (params_vdev, arg->fac_bl1,CIF_ISP_FILT_FAC_BL1 ); +rkisp1_iowrite32 (params_vdev, arg->fac_mid,CIF_ISP_FILT_FAC_MID ); +rkisp1_iowrite32 (params_vdev, arg->fac_sh0,CIF_ISP_FILT_FAC_SH0 ); +rkisp1_iowrite32 (params_vdev, arg->fac_sh1,CIF_ISP_FILT_FAC_SH1 ); +rkisp1_iowrite32 (params_vdev, arg->lum_weight,CIF_ISP_FILT_LUM_WEIGHT ); + +rkisp1_iowrite32 (params_vdev, (arg->mode ?CIF_ISP_FLT_MODE_DNR :0 ) | +CIF_ISP_FLT_CHROMA_V_MODE (arg->chr_v_mode) | +CIF_ISP_FLT_CHROMA_H_MODE (arg->chr_h_mode) | +CIF_ISP_FLT_GREEN_STAGE1 (arg->grn_stage1), +CIF_ISP_FILT_MODE ); +} + +/* ISP demosaic interface function */ +static int bdm_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_bdm_config *arg) +{ +/* set demosaic threshold */ +rkisp1_iowrite32 (params_vdev, arg->demosaic_th,CIF_ISP_DEMOSAIC ); +return 0 ; +} + +/* ISP GAMMA correction interface function */ +static void sdg_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_sdg_config *arg) +{ +int i; + +rkisp1_iowrite32 (params_vdev, + arg->xa_pnts.gamma_dx0,CIF_ISP_GAMMA_DX_LO ); +rkisp1_iowrite32 (params_vdev, + arg->xa_pnts.gamma_dx1,CIF_ISP_GAMMA_DX_HI ); + +for (i =0 ; i <CIFISP_DEGAMMA_CURVE_SIZE ; i++) { +rkisp1_iowrite32 (params_vdev, arg->curve_r.gamma_y[i], +CIF_ISP_GAMMA_R_Y0 + i *4 ); +rkisp1_iowrite32 (params_vdev, arg->curve_g.gamma_y[i], +CIF_ISP_GAMMA_G_Y0 + i *4 ); +rkisp1_iowrite32 (params_vdev, arg->curve_b.gamma_y[i], +CIF_ISP_GAMMA_B_Y0 + i *4 ); + } +} + +/* ISP GAMMA correction interface function */ +static void goc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_goc_config *arg) +{ +int i; + +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +rkisp1_iowrite32 (params_vdev, arg->mode,CIF_ISP_GAMMA_OUT_MODE ); + +for (i =0 ; i <CIFISP_GAMMA_OUT_MAX_SAMPLES ; i++) +rkisp1_iowrite32 (params_vdev, arg->gamma_y[i], +CIF_ISP_GAMMA_OUT_Y_0 + i *4 ); +} + +/* ISP Cross Talk */ +static void ctk_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_ctk_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->coeff0,CIF_ISP_CT_COEFF_0 ); +rkisp1_iowrite32 (params_vdev, arg->coeff1,CIF_ISP_CT_COEFF_1 ); +rkisp1_iowrite32 (params_vdev, arg->coeff2,CIF_ISP_CT_COEFF_2 ); +rkisp1_iowrite32 (params_vdev, arg->coeff3,CIF_ISP_CT_COEFF_3 ); +rkisp1_iowrite32 (params_vdev, arg->coeff4,CIF_ISP_CT_COEFF_4 ); +rkisp1_iowrite32 (params_vdev, arg->coeff5,CIF_ISP_CT_COEFF_5 ); +rkisp1_iowrite32 (params_vdev, arg->coeff6,CIF_ISP_CT_COEFF_6 ); +rkisp1_iowrite32 (params_vdev, arg->coeff7,CIF_ISP_CT_COEFF_7 ); +rkisp1_iowrite32 (params_vdev, arg->coeff8,CIF_ISP_CT_COEFF_8 ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_r,CIF_ISP_CT_OFFSET_R ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_g,CIF_ISP_CT_OFFSET_G ); +rkisp1_iowrite32 (params_vdev, arg->ct_offset_b,CIF_ISP_CT_OFFSET_B ); +} + +static void ctk_enable (struct rkisp1_isp_params_vdev *params_vdev,bool en) +{ +if (en) +return ; + +/* Write back the default values. */ +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_0 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_1 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_2 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_3 ); +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_4 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_5 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_6 ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_COEFF_7 ); +rkisp1_iowrite32 (params_vdev,0x80 ,CIF_ISP_CT_COEFF_8 ); + +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_R ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_G ); +rkisp1_iowrite32 (params_vdev,0 ,CIF_ISP_CT_OFFSET_B ); +} + +/* ISP White Balance Mode */ +static void awb_meas_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_meas_config *arg) +{ +/* based on the mode,configure the awb module */ +if (arg->awb_mode ==CIFISP_AWB_MODE_YCBCR ) { +/* Reference Cb and Cr */ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_REF_CR_SET (arg->awb_ref_cr) | + arg->awb_ref_cb,CIF_ISP_AWB_REF ); +/* Yc Threshold */ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_MAX_Y_SET (arg->max_y) | +CIF_ISP_AWB_MIN_Y_SET (arg->min_y) | +CIF_ISP_AWB_MAX_CS_SET (arg->max_csum) | + arg->min_c,CIF_ISP_AWB_THRESH ); + } + +/* window offset */ +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.v_offs,CIF_ISP_AWB_WND_V_OFFS ); +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.h_offs,CIF_ISP_AWB_WND_H_OFFS ); +/* AWB window size */ +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.v_size,CIF_ISP_AWB_WND_V_SIZE ); +rkisp1_iowrite32 (params_vdev, + arg->awb_wnd.h_size,CIF_ISP_AWB_WND_H_SIZE ); +/* Number of frames */ +rkisp1_iowrite32 (params_vdev, + arg->frames,CIF_ISP_AWB_FRAMES ); +} + +static void awb_meas_enable (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_meas_config *arg,bool en) +{ +u32 reg_val =rkisp1_ioread32 (params_vdev,CIF_ISP_AWB_PROP ); + +/* switch off */ + reg_val &=CIF_ISP_AWB_MODE_MASK_NONE ; + +if (en) { +if (arg->awb_mode ==CIFISP_AWB_MODE_RGB ) + reg_val |=CIF_ISP_AWB_MODE_RGB_EN ; +else + reg_val |=CIF_ISP_AWB_MODE_YCBCR_EN ; + +rkisp1_iowrite32 (params_vdev, reg_val,CIF_ISP_AWB_PROP ); + +/* Measurements require AWB block be active. */ +/* TODO: need to enable here ? awb_gain_enable has done this */ +isp_param_set_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + }else { +rkisp1_iowrite32 (params_vdev, + reg_val,CIF_ISP_AWB_PROP ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + } +} + +static void awb_gain_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_awb_gain_config *arg) +{ +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AWB_GAIN_R_SET (arg->gain_green_r) | + arg->gain_green_b,CIF_ISP_AWB_GAIN_G ); + +rkisp1_iowrite32 (params_vdev,CIF_ISP_AWB_GAIN_R_SET (arg->gain_red) | + arg->gain_blue,CIF_ISP_AWB_GAIN_RB ); +} + +static void aec_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_aec_config *arg) +{ +unsigned int block_hsize, block_vsize; + +rkisp1_iowrite32 (params_vdev, + ((arg->autostop) ?CIF_ISP_EXP_CTRL_AUTOSTOP :0 ) | + ((arg->mode ==CIFISP_EXP_MEASURING_MODE_1 ) ? +CIF_ISP_EXP_CTRL_MEASMODE_1 :0 ),CIF_ISP_EXP_CTRL ); + +rkisp1_iowrite32 (params_vdev, + arg->meas_window.h_offs,CIF_ISP_EXP_H_OFFSET ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.v_offs,CIF_ISP_EXP_V_OFFSET ); + + block_hsize = arg->meas_window.h_size /CIF_ISP_EXP_COLUMN_NUM -1 ; + block_vsize = arg->meas_window.v_size /CIF_ISP_EXP_ROW_NUM -1 ; + +rkisp1_iowrite32 (params_vdev,CIF_ISP_EXP_H_SIZE_SET (block_hsize), +CIF_ISP_EXP_H_SIZE ); +rkisp1_iowrite32 (params_vdev,CIF_ISP_EXP_V_SIZE_SET (block_vsize), +CIF_ISP_EXP_V_SIZE ); +} + +static void cproc_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_cproc_config *arg) +{ +struct cifisp_isp_other_cfg *cur_other_cfg = ¶ms_vdev->cur_params.others; +struct cifisp_ie_config *cur_ie_config = &cur_other_cfg->ie_config; +u32 effect = cur_ie_config->effect; +u32 quantization = params_vdev->quantization; + +rkisp1_iowrite32 (params_vdev, arg->contrast,CIF_C_PROC_CONTRAST ); +rkisp1_iowrite32 (params_vdev, arg->hue,CIF_C_PROC_HUE ); +rkisp1_iowrite32 (params_vdev, arg->sat,CIF_C_PROC_SATURATION ); +rkisp1_iowrite32 (params_vdev, arg->brightness,CIF_C_PROC_BRIGHTNESS ); + +if (quantization !=V4L2_QUANTIZATION_FULL_RANGE || + effect !=V4L2_COLORFX_NONE ) { +isp_param_clear_bits (params_vdev,CIF_C_PROC_CTRL , +CIF_C_PROC_YOUT_FULL | +CIF_C_PROC_YIN_FULL | +CIF_C_PROC_COUT_FULL ); + }else { +isp_param_set_bits (params_vdev,CIF_C_PROC_CTRL , +CIF_C_PROC_YOUT_FULL | +CIF_C_PROC_YIN_FULL | +CIF_C_PROC_COUT_FULL ); + } +} + +static void hst_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_hst_config *arg) +{ +unsigned int block_hsize, block_vsize; +static const u32 hist_weight_regs[] = { +CIF_ISP_HIST_WEIGHT_00TO30 ,CIF_ISP_HIST_WEIGHT_40TO21 , +CIF_ISP_HIST_WEIGHT_31TO12 ,CIF_ISP_HIST_WEIGHT_22TO03 , +CIF_ISP_HIST_WEIGHT_13TO43 ,CIF_ISP_HIST_WEIGHT_04TO34 , +CIF_ISP_HIST_WEIGHT_44 , + }; +int i; +const u8 *weight; + +rkisp1_iowrite32 (params_vdev, +CIF_ISP_HIST_PREDIV_SET (arg->histogram_predivider), +CIF_ISP_HIST_PROP ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.h_offs, +CIF_ISP_HIST_H_OFFS ); +rkisp1_iowrite32 (params_vdev, + arg->meas_window.v_offs, +CIF_ISP_HIST_V_OFFS ); + + block_hsize = arg->meas_window.h_size /CIF_ISP_HIST_COLUMN_NUM -1 ; + block_vsize = arg->meas_window.v_size /CIF_ISP_HIST_ROW_NUM -1 ; + +rkisp1_iowrite32 (params_vdev, block_hsize,CIF_ISP_HIST_H_SIZE ); +rkisp1_iowrite32 (params_vdev, block_vsize,CIF_ISP_HIST_V_SIZE ); + + weight = arg->hist_weight; +for (i =0 ; i <ARRAY_SIZE (hist_weight_regs); ++i, weight +=4 ) +rkisp1_iowrite32 (params_vdev,CIF_ISP_HIST_WEIGHT_SET ( + weight[0 ], weight[1 ], weight[2 ], weight[3 ]), + hist_weight_regs[i]); +} + +static void hst_enable (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_hst_config *arg,bool en) +{ +if (en) { +u32 hist_prop =rkisp1_ioread32 (params_vdev,CIF_ISP_HIST_PROP ); + + hist_prop &= ~CIF_ISP_HIST_PROP_MODE_MASK ; + hist_prop |= arg->mode; +isp_param_set_bits (params_vdev,CIF_ISP_HIST_PROP , hist_prop); + }else { +isp_param_clear_bits (params_vdev,CIF_ISP_HIST_PROP , +CIF_ISP_HIST_PROP_MODE_MASK ); + } +} + +static void afm_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_afc_config *arg) +{ +int i; +size_t num_of_win =min_t (size_t,ARRAY_SIZE (arg->afm_win), + arg->num_afm_win); + +/* Switch off to configure. Enabled during normal flow in frame isr. */ +isp_param_clear_bits (params_vdev,CIF_ISP_AFM_CTRL ,CIF_ISP_AFM_ENA ); + +for (i =0 ; i < num_of_win; i++) { +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AFM_WINDOW_X (arg->afm_win[i].h_offs) | +CIF_ISP_AFM_WINDOW_Y (arg->afm_win[i].v_offs), +CIF_ISP_AFM_LT_A + i *8 ); +rkisp1_iowrite32 (params_vdev, +CIF_ISP_AFM_WINDOW_X (arg->afm_win[i].h_size + + arg->afm_win[i].h_offs) | +CIF_ISP_AFM_WINDOW_Y (arg->afm_win[i].v_size + + arg->afm_win[i].v_offs), +CIF_ISP_AFM_RB_A + i *8 ); + } +rkisp1_iowrite32 (params_vdev, arg->thres,CIF_ISP_AFM_THRES ); +rkisp1_iowrite32 (params_vdev, arg->var_shift,CIF_ISP_AFM_VAR_SHIFT ); +} + +static void ie_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_ie_config *arg) +{ +u32 eff_ctrl; + + eff_ctrl =rkisp1_ioread32 (params_vdev,CIF_IMG_EFF_CTRL ); + eff_ctrl &= ~CIF_IMG_EFF_CTRL_MODE_MASK ; + +if (params_vdev->quantization ==V4L2_QUANTIZATION_FULL_RANGE ) + eff_ctrl |=CIF_IMG_EFF_CTRL_YCBCR_FULL ; + +switch (arg->effect) { +case V4L2_COLORFX_SEPIA : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SEPIA ; +break ; +case V4L2_COLORFX_SET_CBCR : +rkisp1_iowrite32 (params_vdev, arg->eff_tint,CIF_IMG_EFF_TINT ); + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SEPIA ; +break ; +/* +* Color selection is similar to water color(AQUA): +* grayscale + selected color w threshold +*/ +case V4L2_COLORFX_AQUA : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_COLOR_SEL ; +rkisp1_iowrite32 (params_vdev, arg->color_sel, +CIF_IMG_EFF_COLOR_SEL ); +break ; +case V4L2_COLORFX_EMBOSS : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_EMBOSS ; +rkisp1_iowrite32 (params_vdev, arg->eff_mat_1, +CIF_IMG_EFF_MAT_1 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_2, +CIF_IMG_EFF_MAT_2 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_3, +CIF_IMG_EFF_MAT_3 ); +break ; +case V4L2_COLORFX_SKETCH : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_SKETCH ; +rkisp1_iowrite32 (params_vdev, arg->eff_mat_3, +CIF_IMG_EFF_MAT_3 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_4, +CIF_IMG_EFF_MAT_4 ); +rkisp1_iowrite32 (params_vdev, arg->eff_mat_5, +CIF_IMG_EFF_MAT_5 ); +break ; +case V4L2_COLORFX_BW : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_BLACKWHITE ; +break ; +case V4L2_COLORFX_NEGATIVE : + eff_ctrl |=CIF_IMG_EFF_CTRL_MODE_NEGATIVE ; +break ; +default : +break ; + } + +rkisp1_iowrite32 (params_vdev, eff_ctrl,CIF_IMG_EFF_CTRL ); +} + +static void ie_enable (struct rkisp1_isp_params_vdev *params_vdev,bool en) +{ +if (en) { +isp_param_set_bits (params_vdev,CIF_ICCL ,CIF_ICCL_IE_CLK ); +rkisp1_iowrite32 (params_vdev,CIF_IMG_EFF_CTRL_ENABLE , +CIF_IMG_EFF_CTRL ); +isp_param_set_bits (params_vdev,CIF_IMG_EFF_CTRL , +CIF_IMG_EFF_CTRL_CFG_UPD ); + }else { +/* Disable measurement */ +isp_param_clear_bits (params_vdev,CIF_IMG_EFF_CTRL , +CIF_IMG_EFF_CTRL_ENABLE ); +isp_param_clear_bits (params_vdev,CIF_ICCL ,CIF_ICCL_IE_CLK ); + } +} + +static void csm_config (struct rkisp1_isp_params_vdev *params_vdev, +bool full_range) +{ +static const u16 full_range_coeff[] = { +0x0026 ,0x004b ,0x000f , +0x01ea ,0x01d6 ,0x0040 , +0x0040 ,0x01ca ,0x01f6 + }; +static const u16 limited_range_coeff[] = { +0x0021 ,0x0040 ,0x000d , +0x01ed ,0x01db ,0x0038 , +0x0038 ,0x01d1 ,0x01f7 , + }; +int i; + +if (full_range) { +for (i =0 ; i <ARRAY_SIZE (full_range_coeff); i++) +rkisp1_iowrite32 (params_vdev, full_range_coeff[i], +CIF_ISP_CC_COEFF_0 + i *4 ); + +isp_param_set_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | +CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA ); + }else { +for (i =0 ; i <ARRAY_SIZE (limited_range_coeff); i++) +rkisp1_iowrite32 (params_vdev, limited_range_coeff[i], +CIF_ISP_CC_COEFF_0 + i *4 ); + +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | +CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA ); + } +} + +/* ISP De-noise Pre-Filter(DPF) function */ +static void dpf_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpf_config *arg) +{ +unsigned int isp_dpf_mode; +unsigned int spatial_coeff; +unsigned int i; + +switch (arg->gain.mode) { +case CIFISP_DPF_GAIN_USAGE_NF_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_USE_NF_GAIN | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_LSC_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_USE_NF_GAIN | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP | +CIF_ISP_DPF_MODE_LSC_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_AWB_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS : + isp_dpf_mode =CIF_ISP_DPF_MODE_LSC_GAIN_COMP | +CIF_ISP_DPF_MODE_AWB_GAIN_COMP ; +break ; +case CIFISP_DPF_GAIN_USAGE_DISABLED : +default : + isp_dpf_mode =0 ; +break ; + } + +if (arg->nll.scale_mode ==CIFISP_NLL_SCALE_LOGARITHMIC ) + isp_dpf_mode |=CIF_ISP_DPF_MODE_NLL_SEGMENTATION ; +if (arg->rb_flt.fltsize == CIFISP_DPF_RB_FILTERSIZE_9x9) + isp_dpf_mode |= CIF_ISP_DPF_MODE_RB_FLTSIZE_9x9; +if (!arg->rb_flt.r_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_R_FLT_DIS ; +if (!arg->rb_flt.b_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_B_FLT_DIS ; +if (!arg->g_flt.gb_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_GB_FLT_DIS ; +if (!arg->g_flt.gr_enable) + isp_dpf_mode |=CIF_ISP_DPF_MODE_GR_FLT_DIS ; + +isp_param_set_bits (params_vdev,CIF_ISP_DPF_MODE , isp_dpf_mode); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_b_gain, +CIF_ISP_DPF_NF_GAIN_B ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_r_gain, +CIF_ISP_DPF_NF_GAIN_R ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_gb_gain, +CIF_ISP_DPF_NF_GAIN_GB ); +rkisp1_iowrite32 (params_vdev, arg->gain.nf_gr_gain, +CIF_ISP_DPF_NF_GAIN_GR ); + +for (i =0 ; i <CIFISP_DPF_MAX_NLF_COEFFS ; i++) { +rkisp1_iowrite32 (params_vdev, arg->nll.coeff[i], +CIF_ISP_DPF_NULL_COEFF_0 + i *4 ); + } + + spatial_coeff = arg->g_flt.spatial_coeff[0 ] | + (arg->g_flt.spatial_coeff[1 ] <<8 ) | + (arg->g_flt.spatial_coeff[2 ] <<16 ) | + (arg->g_flt.spatial_coeff[3 ] <<24 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_G_1_4 ); + + spatial_coeff = arg->g_flt.spatial_coeff[4 ] | + (arg->g_flt.spatial_coeff[5 ] <<8 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_G_5_6 ); + + spatial_coeff = arg->rb_flt.spatial_coeff[0 ] | + (arg->rb_flt.spatial_coeff[1 ] <<8 ) | + (arg->rb_flt.spatial_coeff[2 ] <<16 ) | + (arg->rb_flt.spatial_coeff[3 ] <<24 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_RB_1_4 ); + + spatial_coeff = arg->rb_flt.spatial_coeff[4 ] | + (arg->rb_flt.spatial_coeff[5 ] <<8 ); +rkisp1_iowrite32 (params_vdev, spatial_coeff, +CIF_ISP_DPF_S_WEIGHT_RB_5_6 ); +}drivers/media/platform/rockchip/isp1/isp_params.c line 839
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+ +static void dpf_strength_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct cifisp_dpf_strength_config *arg) +{ +rkisp1_iowrite32 (params_vdev, arg->b,CIF_ISP_DPF_STRENGTH_B ); +rkisp1_iowrite32 (params_vdev, arg->g,CIF_ISP_DPF_STRENGTH_G ); +rkisp1_iowrite32 (params_vdev, arg->r,CIF_ISP_DPF_STRENGTH_R ); +} + +static __maybe_unusedWhy maybe unused? Add a comment explaining this.
Quoted 617 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +617
-0+void __isp_isr_other_config (struct rkisp1_isp_params_vdev *params_vdev, +const struct rkisp1_isp_params_cfg *new_params) +{ +unsigned int module_en_update, module_cfg_update, module_ens; + + module_en_update = new_params->module_en_update; + module_cfg_update = new_params->module_cfg_update; + module_ens = new_params->module_ens; + +if ((module_en_update &CIFISP_MODULE_DPCC ) || + (module_cfg_update &CIFISP_MODULE_DPCC )) { +/*update dpc config */ +if ((module_cfg_update &CIFISP_MODULE_DPCC )) +dpcc_config (params_vdev, + &new_params->others.dpcc_config); + +if (module_en_update &CIFISP_MODULE_DPCC ) { +if (!!(module_ens &CIFISP_MODULE_DPCC )) +isp_param_set_bits (params_vdev, +CIF_ISP_DPCC_MODE , +CIF_ISP_DPCC_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DPCC_MODE , +CIF_ISP_DPCC_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_BLS ) || + (module_cfg_update &CIFISP_MODULE_BLS )) { +/* update bls config */ +if ((module_cfg_update &CIFISP_MODULE_BLS )) +bls_config (params_vdev, &new_params->others.bls_config); + +if (module_en_update &CIFISP_MODULE_BLS ) { +if (!!(module_ens &CIFISP_MODULE_BLS )) +isp_param_set_bits (params_vdev, +CIF_ISP_BLS_CTRL , +CIF_ISP_BLS_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_BLS_CTRL , +CIF_ISP_BLS_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_SDG ) || + (module_cfg_update &CIFISP_MODULE_SDG )) { +/* update sdg config */ +if ((module_cfg_update &CIFISP_MODULE_SDG )) +sdg_config (params_vdev, &new_params->others.sdg_config); + +if (module_en_update &CIFISP_MODULE_SDG ) { +if (!!(module_ens &CIFISP_MODULE_SDG )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_LSC ) || + (module_cfg_update &CIFISP_MODULE_LSC )) { +/* update lsc config */ +if ((module_cfg_update &CIFISP_MODULE_LSC )) +lsc_config (params_vdev, &new_params->others.lsc_config); + +if (module_en_update &CIFISP_MODULE_LSC ) { +if (!!(module_ens &CIFISP_MODULE_LSC )) +isp_param_set_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_AWB_GAIN ) || + (module_cfg_update &CIFISP_MODULE_AWB_GAIN )) { +/* update awb gains */ +if ((module_cfg_update &CIFISP_MODULE_AWB_GAIN )) +awb_gain_config (params_vdev, + &new_params->others.awb_gain_config); + +if (module_en_update &CIFISP_MODULE_AWB_GAIN ) { +if (!!(module_ens &CIFISP_MODULE_AWB_GAIN )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_AWB_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_BDM ) || + (module_cfg_update &CIFISP_MODULE_BDM )) { +/* update bdm config */ +if ((module_cfg_update &CIFISP_MODULE_BDM )) +bdm_config (params_vdev, &new_params->others.bdm_config); + +if (module_en_update &CIFISP_MODULE_BDM ) { +if (!!(module_ens &CIFISP_MODULE_BDM )) +isp_param_set_bits (params_vdev, +CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); + } + } + +if ((module_en_update &CIFISP_MODULE_FLT ) || + (module_cfg_update &CIFISP_MODULE_FLT )) { +/* update filter config */ +if ((module_cfg_update &CIFISP_MODULE_FLT )) +flt_config (params_vdev, &new_params->others.flt_config); + +if (module_en_update &CIFISP_MODULE_FLT ) { +if (!!(module_ens &CIFISP_MODULE_FLT )) +isp_param_set_bits (params_vdev, +CIF_ISP_FILT_MODE , +CIF_ISP_FLT_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_FILT_MODE , +CIF_ISP_FLT_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_CTK ) || + (module_cfg_update &CIFISP_MODULE_CTK )) { +/* update ctk config */ +if ((module_cfg_update &CIFISP_MODULE_CTK )) +ctk_config (params_vdev, &new_params->others.ctk_config); + +if (module_en_update &CIFISP_MODULE_CTK ) +ctk_enable (params_vdev, + !!(module_ens &CIFISP_MODULE_CTK )); + } + +if ((module_en_update &CIFISP_MODULE_GOC ) || + (module_cfg_update &CIFISP_MODULE_GOC )) { +/* update goc config */ +if ((module_cfg_update &CIFISP_MODULE_GOC )) +goc_config (params_vdev, &new_params->others.goc_config); + +if (module_en_update &CIFISP_MODULE_GOC ) { +if (!!(module_ens &CIFISP_MODULE_GOC )) +isp_param_set_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_CPROC ) || + (module_cfg_update &CIFISP_MODULE_CPROC )) { +/* update cproc config */ +if ((module_cfg_update &CIFISP_MODULE_CPROC )) { +cproc_config (params_vdev, + &new_params->others.cproc_config); + + } + +if (module_en_update &CIFISP_MODULE_CPROC ) { +if (!!(module_ens &CIFISP_MODULE_CPROC )) +isp_param_set_bits (params_vdev, +CIF_C_PROC_CTRL , +CIF_C_PROC_CTR_ENABLE ); +else +isp_param_clear_bits (params_vdev, +CIF_C_PROC_CTRL , +CIF_C_PROC_CTR_ENABLE ); + } + } + + +if ((module_en_update &CIFISP_MODULE_IE ) || + (module_cfg_update &CIFISP_MODULE_IE )) { +/* update ie config */ +if ((module_cfg_update &CIFISP_MODULE_IE )) +ie_config (params_vdev, &new_params->others.ie_config); + +if (module_en_update &CIFISP_MODULE_IE ) +ie_enable (params_vdev, + !!(module_ens &CIFISP_MODULE_IE )); + } + +if ((module_en_update &CIFISP_MODULE_DPF ) || + (module_cfg_update &CIFISP_MODULE_DPF )) { +/* update dpf config */ +if ((module_cfg_update &CIFISP_MODULE_DPF )) +dpf_config (params_vdev, &new_params->others.dpf_config); + +if (module_en_update &CIFISP_MODULE_DPF ) { +if (!!(module_ens &CIFISP_MODULE_DPF )) +isp_param_set_bits (params_vdev, +CIF_ISP_DPF_MODE , +CIF_ISP_DPF_MODE_EN ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_DPF_MODE , +CIF_ISP_DPF_MODE_EN ); + } + } + +if ((module_en_update &CIFISP_MODULE_DPF_STRENGTH ) || + (module_cfg_update &CIFISP_MODULE_DPF_STRENGTH )) { +/* update dpf strength config */ +dpf_strength_config (params_vdev, + &new_params->others.dpf_strength_config); + } +} + +static __maybe_unused +void __isp_isr_meas_config (struct rkisp1_isp_params_vdev *params_vdev, +struct rkisp1_isp_params_cfg *new_params) +{ +unsigned int module_en_update, module_cfg_update, module_ens; + + module_en_update = new_params->module_en_update; + module_cfg_update = new_params->module_cfg_update; + module_ens = new_params->module_ens; + +if ((module_en_update &CIFISP_MODULE_AWB ) || + (module_cfg_update &CIFISP_MODULE_AWB )) { +/* update awb config */ +if ((module_cfg_update &CIFISP_MODULE_AWB )) +awb_meas_config (params_vdev, + &new_params->meas.awb_meas_config); + +if (module_en_update &CIFISP_MODULE_AWB ) +awb_meas_enable (params_vdev, + &new_params->meas.awb_meas_config, + !!(module_ens &CIFISP_MODULE_AWB )); + } + +if ((module_en_update &CIFISP_MODULE_AFC ) || + (module_cfg_update &CIFISP_MODULE_AFC )) { +/* update afc config */ +if ((module_cfg_update &CIFISP_MODULE_AFC )) +afm_config (params_vdev, &new_params->meas.afc_config); + +if (module_en_update &CIFISP_MODULE_AFC ) { +if (!!(module_ens &CIFISP_MODULE_AFC )) +isp_param_set_bits (params_vdev, +CIF_ISP_AFM_CTRL , +CIF_ISP_AFM_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_AFM_CTRL , +CIF_ISP_AFM_ENA ); + } + } + +if ((module_en_update &CIFISP_MODULE_HST ) || + (module_cfg_update &CIFISP_MODULE_HST )) { +/* update hst config */ +if ((module_cfg_update &CIFISP_MODULE_HST )) +hst_config (params_vdev, &new_params->meas.hst_config); + +if (module_en_update &CIFISP_MODULE_HST ) +hst_enable (params_vdev, + &new_params->meas.hst_config, + !!(module_ens &CIFISP_MODULE_HST )); + } + +if ((module_en_update &CIFISP_MODULE_AEC ) || + (module_cfg_update &CIFISP_MODULE_AEC )) { +/* update aec config */ +if ((module_cfg_update &CIFISP_MODULE_AEC )) +aec_config (params_vdev, &new_params->meas.aec_config); + +if (module_en_update &CIFISP_MODULE_AEC ) { +if (!!(module_ens &CIFISP_MODULE_AEC )) +isp_param_set_bits (params_vdev, +CIF_ISP_EXP_CTRL , +CIF_ISP_EXP_ENA ); +else +isp_param_clear_bits (params_vdev, +CIF_ISP_EXP_CTRL , +CIF_ISP_EXP_ENA ); + } + } +} + +void rkisp1_params_isr (struct rkisp1_isp_params_vdev *params_vdev,u32 isp_mis) +{ +struct rkisp1_isp_params_cfg *new_params; +struct rkisp1_buffer *cur_buf =NULL ; + +spin_lock (¶ms_vdev->config_lock); +if (!params_vdev->streamon) { +spin_unlock (¶ms_vdev->config_lock); +return ; + } + +/* get one empty buffer */ +if (!list_empty (¶ms_vdev->params)) + cur_buf =list_first_entry (¶ms_vdev->params, + struct rkisp1_buffer, queue); +spin_unlock (¶ms_vdev->config_lock); + +if (!cur_buf) +return ; + + new_params = (struct rkisp1_isp_params_cfg *)(cur_buf->vaddr[0 ]); + +if (isp_mis &CIF_ISP_FRAME ) { +__isp_isr_other_config (params_vdev, new_params); +__isp_isr_meas_config (params_vdev, new_params); +spin_lock (¶ms_vdev->config_lock); +list_del (&cur_buf->queue); +spin_unlock (¶ms_vdev->config_lock); +vb2_buffer_done (&cur_buf->vb.vb2_buf,VB2_BUF_STATE_DONE ); + } +} + +static const struct cifisp_awb_meas_config awb_params_default_config = { + { +0 ,0 ,RKISP1_DEFAULT_WIDTH ,RKISP1_DEFAULT_HEIGHT + }, +CIFISP_AWB_MODE_YCBCR ,200 ,30 ,20 ,20 ,0 ,128 ,128 +}; + +static const struct cifisp_aec_config aec_params_default_config = { +CIFISP_EXP_MEASURING_MODE_0 , +CIFISP_EXP_CTRL_AUTOSTOP_0 , + { +RKISP1_DEFAULT_WIDTH >>2 ,RKISP1_DEFAULT_HEIGHT >>2 , +RKISP1_DEFAULT_WIDTH >>1 ,RKISP1_DEFAULT_HEIGHT >>1 + } +}; + +static const struct cifisp_hst_config hst_params_default_config = { +CIFISP_HISTOGRAM_MODE_RGB_COMBINED , +3 , + { +RKISP1_DEFAULT_WIDTH >>2 ,RKISP1_DEFAULT_HEIGHT >>2 , +RKISP1_DEFAULT_WIDTH >>1 ,RKISP1_DEFAULT_HEIGHT >>1 + }, + { +0 ,/* To be filled in with 0x01 at runtime. */ + } +}; + +static const struct cifisp_afc_config afc_params_default_config = { +1 , + { + { +300 ,225 ,200 ,150 + } + }, +4 , +14 +}; + +static +void rkisp1_params_config_parameter (struct rkisp1_isp_params_vdev *params_vdev) +{ +struct cifisp_hst_config hst = hst_params_default_config; + +spin_lock (¶ms_vdev->config_lock); + +awb_meas_config (params_vdev, &awb_params_default_config); +awb_meas_enable (params_vdev, &awb_params_default_config, true); + +aec_config (params_vdev, &aec_params_default_config); +isp_param_set_bits (params_vdev,CIF_ISP_EXP_CTRL ,CIF_ISP_EXP_ENA ); + +afm_config (params_vdev, &afc_params_default_config); +isp_param_set_bits (params_vdev,CIF_ISP_AFM_CTRL ,CIF_ISP_AFM_ENA ); + +memset (hst.hist_weight,0x01 ,sizeof (hst.hist_weight)); +hst_config (params_vdev, &hst); +isp_param_set_bits (params_vdev,CIF_ISP_HIST_PROP , + ~CIF_ISP_HIST_PROP_MODE_MASK | + hst_params_default_config.mode); + +/* set the range */ +if (params_vdev->quantization ==V4L2_QUANTIZATION_FULL_RANGE ) +csm_config (params_vdev, true); +else +csm_config (params_vdev, false); + +/* override the default things */ +__isp_isr_other_config (params_vdev, ¶ms_vdev->cur_params); +__isp_isr_meas_config (params_vdev, ¶ms_vdev->cur_params); + +spin_unlock (¶ms_vdev->config_lock); +} + +/* Not called when the camera active, thus not isr protection. */ +void rkisp1_configure_isp (struct rkisp1_isp_params_vdev *params_vdev, +struct ispsd_in_fmt *in_fmt, +enum v4l2_quantization quantization) +{ +if (!params_vdev) +return ; + +if (quantization) + params_vdev->quantization = quantization; +if (in_fmt) + params_vdev->raw_type = in_fmt->bayer_pat; +if (params_vdev) +rkisp1_params_config_parameter (params_vdev); +} + +/* Not called when the camera active, thus not isr protection. */ +void rkisp1_disable_isp (struct rkisp1_isp_params_vdev *params_vdev) +{ +isp_param_clear_bits (params_vdev,CIF_ISP_DPCC_MODE ,CIF_ISP_DPCC_ENA );Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_params.c line 1272
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+isp_param_clear_bits (params_vdev,CIF_ISP_LSC_CTRL , +CIF_ISP_LSC_CTRL_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_BLS_CTRL ,CIF_ISP_BLS_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_IN_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_CTRL , +CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA ); +isp_param_clear_bits (params_vdev,CIF_ISP_DEMOSAIC , +CIF_ISP_DEMOSAIC_BYPASS ); +isp_param_clear_bits (params_vdev,CIF_ISP_FILT_MODE ,CIF_ISP_FLT_ENA );Either add
VB2_DMABUFor dropexp_buffromrkisp1_params_ioctl.drivers/media/platform/rockchip/isp1/isp_stats.c
Quoted 375 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +77
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_params.h new file +76
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.c new file +210
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Either add
VB2_DMABUFor drop expbuf fromrkisp1_stats_ioctl.drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 3,179 lines
drivers/media/platform/rockchip/isp1/isp_stats.c new file +311
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.h new file +85
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.c new file +264
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.h new file +1582
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.c new file +913
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
What do you use
g_mbus_configfor? Typically this information should come from the device tree. I want to remove this op in the not-too-distant future since it really makes no sense.Quoted 422 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +288
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.h new file +128
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Quoted 8 lines
drivers/media/platform/rockchip/isp1/rkisp1.h
Quoted 4 lines
drivers/media/platform/rockchip/isp1/rkisp1.h new file +3
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Perhaps when you post v4 you can split up this patch in 2 or 3 smaller patches. Certainly regs.[ch] can easily be put in a separate patch. It's hard to review a single very large patch like this.
Done, have put them in a separate patch.
Quoted 4 lines
Regards,
Hans
Part of the diff is not shown here. View the raw message.
PATCH v3 5/12 media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver.
--- drivers/media/platform/rockchip/isp1/Makefile | 1 + .../media/platform/rockchip/isp1/mipi_dphy_sy.c | 787 +++++++++++++++++++++ 2 files changed, 788 insertions(+) create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
drivers/media/platform/rockchip/isp1/Makefile +1 -0
@@ -4,4 +4,5 @@ video_rkisp1-objs += rkisp1.o \ regs.o \ isp_stats.o \ isp_params.o \ + mipi_dphy_sy.o \ capture.o
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +787 -0
787 lines not on this page · raw message
Signature · 1 line
2.15.0
PATCH v3 6/12 dt-bindings: Document the Rockchip ISP1 bindings
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip ISP1
--- .../devicetree/bindings/media/rockchip-isp1.txt | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txt
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +57 -0
@@ -0,0 +1,57 @@ +Rockchip SoC Image Signal Processing unit v1 +---------------------------------------------- + +Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs +which contains image processing, scaling, and compression funcitons. + +Required properties: + - compatible: value should be one of the following + "rockchip,rk3288-cif-isp"; + "rockchip,rk3399-cif-isp"; + - reg : offset and length of the register set for the device. + - interrupts: should contain ISP interrupt. + - clocks: phandle to the required clocks. + - clock-names: required clock name. + - iommus: required a iommu node. + +The device node should contain one 'port' child node with child 'endpoint' +nodes, according to the bindings defined in Documentation/devicetree/bindings/ +media/video-interfaces.txt. + +For sensor with a parallel video bus, it could be linked directly to the isp. +For sensor with a MIPI CSI-2 video bus, it should be linked through the +MIPI-DPHY, which is defined in rockchip-mipi-dphy.txt. + +Device node example +------------------- + + isp0: isp0 at ff910000 { + compatible = "rockchip,rk3399-cif-isp"; + reg = <0x0 0xff910000 0x0 0x4000>; + interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru SCLK_ISP0>, + <&cru ACLK_ISP0>, <&cru ACLK_ISP0_WRAPPER>, + <&cru HCLK_ISP0>, <&cru HCLK_ISP0_WRAPPER>; + clock-names = "clk_isp", + "aclk_isp", "aclk_isp_wrap", + "hclk_isp", "hclk_isp_wrap"; + power-domains = <&power RK3399_PD_ISP0>; + iommus = <&isp0_mmu>; + + port { + #address-cells = <1>; + #size-cells = <0>; + + /* mipi */ + isp0_mipi_in: endpoint at 0 { + reg = <0>; + remote-endpoint = <&dphy_rx0_out>; + }; + + /* parallel */ + isp0_parallel_in: endpoint at 1 { + reg = <1>; + remote-endpoint = <&ov5640_out>; + }; + }; + };
Signature · 1 line
2.15.0
Rob Herring
maintainerRe: [PATCH v3 06/12] dt-bindings: Document the Rockchip ISP1 bindings
Quoted 29 lines · Jacob Chen
From: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip ISP1
Signed-off-by Jacob Chen <[email protected]>--- .../devicetree/bindings/media/rockchip-isp1.txt | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/rockchip-isp1.txtDocumentation/devicetree/bindings/media/rockchip-isp1.txt new file +13
-0@@ -0,0 +1,57 @@ +Rockchip SoC Image Signal Processing unit v1 +---------------------------------------------- + +Rockchip ISP1 is the Camera interface for the Rockchip series of SoCs +which contains image processing, scaling, and compression funcitons. + +Required properties: + - compatible: value should be one of the following + "rockchip,rk3288-cif-isp"; + "rockchip,rk3399-cif-isp"; + - reg : offset and length of the register set for the device. + - interrupts: should contain ISP interrupt. + - clocks: phandle to the required clocks.
Documentation/devicetree/bindings/media/rockchip-isp1.txt line 23
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-isp1.txt new file +10
-0+ - clock-names: required clock name. + - iommus: required a iommu node. + +The device node should contain one 'port' child node with child 'endpoint' +nodes, according to the bindings defined in Documentation/devicetree/bindings/ +media/video-interfaces.txt. + +For sensor with a parallel video bus, it could be linked directly to the isp. +For sensor with a MIPI CSI-2 video bus, it should be linked through the +MIPI-DPHY, which is defined in rockchip-mipi-dphy.txt.
As I mentioned on the last version, you need to list that there are 2 endpoints for the port and what their assignment is.
Rob
PATCH v3 7/12 dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip MIPI D-PHY RX
--- .../bindings/media/rockchip-mipi-dphy.txt | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +71 -0
@@ -0,0 +1,71 @@ +Rockchip SoC MIPI RX D-PHY +------------------------------------------------------------- + +Required properties: + +- compatible: value should be one of the following + "rockchip,rk3288-mipi-dphy"; + "rockchip,rk3399-mipi-dphy"; +- rockchip,grf: GRF regs. +- bus-width : maximum number of data lanes supported (SoC specific); +- clocks : list of clock specifiers, corresponding to entries in + clock-names property; +- clock-names: required clock name. + +The device node should contain two 'port' child node, according to the bindings +defined in Documentation/devicetree/bindings/media/video-interfaces.txt. +The first port should be connected to sensor nodes, and the second port should be +connected to isp node. The following are properties specific to those nodes. + +endpoint node +------------- + +- data-lanes : (required) an array specifying active physical MIPI-CSI2 + data input lanes and their mapping to logical lanes; the + array's content is unused, only its length is meaningful; + +Device node example +------------------- + + mipi_dphy_rx0: mipi-dphy-rx0 { + compatible = "rockchip,rk3399-mipi-dphy"; + clocks = <&cru SCLK_MIPIDPHY_REF>, + <&cru SCLK_DPHY_RX0_CFG>, + <&cru PCLK_VIO_GRF>; + clock-names = "dphy-ref", "dphy-cfg", "grf"; + power-domains = <&power RK3399_PD_VIO>; + bus-width = <4>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + mipi_in_wcam: endpoint at 0 { + reg = <0>; + remote-endpoint = <&wcam_out>; + data-lanes = <1 2>; + }; + mipi_in_ucam: endpoint at 1 { + reg = <1>; + remote-endpoint = <&ucam_out>; + data-lanes = <1>; + }; + }; + + port at 1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + dphy_rx0_out: endpoint at 0 { + reg = <0>; + remote-endpoint = <&isp0_mipi_in>; + }; + }; + }; + };
Signature · 1 line
2.15.0
Rob Herring
maintainerRe: [PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
Quoted 16 lines · Jacob Chen
From: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip MIPI D-PHY RX
Signed-off-by Jacob Chen <[email protected]>--- .../bindings/media/rockchip-mipi-dphy.txt | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txtDocumentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +0
-0
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 8
Quoted 8 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +8
-0@@ -0,0 +1,71 @@ +Rockchip SoC MIPI RX D-PHY +------------------------------------------------------------- + +Required properties: + +- compatible: value should be one of the following + "rockchip,rk3288-mipi-dphy"; + "rockchip,rk3399-mipi-dphy";
Drop the ';'
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 18
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +10
-0+- rockchip,grf: GRF regs. +- bus-width : maximum number of data lanes supported (SoC specific); +- clocks : list of clock specifiers, corresponding to entries in + clock-names property; +- clock-names: required clock name. + +The device node should contain two 'port' child node, according to the bindings +defined in Documentation/devicetree/bindings/media/video-interfaces.txt. +The first port should be connected to sensor nodes, and the second port should be +connected to isp node. The following are properties specific to those nodes.
Need to list how many endpoints if there are more than 1.
Quoted 9 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +9
-0+ +endpoint node +------------- + +- data-lanes : (required) an array specifying active physical MIPI-CSI2 + data input lanes and their mapping to logical lanes; the + array's content is unused, only its length is meaningful; + +Device node example
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 37
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +10
-0+------------------- + + mipi_dphy_rx0: mipi-dphy-rx0 { + compatible = "rockchip,rk3399-mipi-dphy"; + clocks = <&cru SCLK_MIPIDPHY_REF>, + <&cru SCLK_DPHY_RX0_CFG>, + <&cru PCLK_VIO_GRF>; + clock-names = "dphy-ref", "dphy-cfg", "grf"; + power-domains = <&power RK3399_PD_VIO>; + bus-width = <4>;
rockchip,grf?
No other registers? Can you just make this a child of the grf block with a proper reg property for the range of dphy registers?
Quoted 19 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +19
-0+ + ports { + #address-cells = <1>; + #size-cells = <0>; + + port at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + mipi_in_wcam: endpoint at 0 { + reg = <0>; + remote-endpoint = <&wcam_out>; + data-lanes = <1 2>; + }; + mipi_in_ucam: endpoint at 1 { + reg = <1>; + remote-endpoint = <&ucam_out>; + data-lanes = <1>;
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 66
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +10
-0+ }; + }; + + port at 1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + dphy_rx0_out: endpoint at 0 { + reg = <0>;
Don't need reg and everything associated with it if there's only 1 endpoint.
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 71
Quoted 6 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0+ remote-endpoint = <&isp0_mipi_in>; + }; + }; + }; + };
Please fix.
Rob
Laurent Pinchart
maintainerRe: [PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
In reply to Jacob ChenHello Jacob,
Thank you for the patch.
Quoted 18 lines · On Wednesday, 6 December 2017 13:19:34 EET Jacob Chen wrote:
From: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip MIPI D-PHY RX
Signed-off-by Jacob Chen <[email protected]>--- .../bindings/media/rockchip-mipi-dphy.txt | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txtnew file mode 100644
index 000000000000..cef9450db051
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 10
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +10
-0@@ -0,0 +1,71 @@ +Rockchip SoC MIPI RX D-PHY +------------------------------------------------------------- + +Required properties: + +- compatible: value should be one of the following + "rockchip,rk3288-mipi-dphy"; + "rockchip,rk3399-mipi-dphy"; +- rockchip,grf: GRF regs. +- bus-width : maximum number of data lanes supported (SoC specific);
Bus width isn't a standard property, should this be rockchip,data-lanes or rockchip,#data-lanes ?
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
Quoted 5 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0+- clocks : list of clock specifiers, corresponding to entries in + clock-names property; +- clock-names: required clock name. + +The device node should contain two 'port' child node, according to the
s/child node/child nodes/
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 25
Quoted 13 lines
bindings
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +2
-0+defined in Documentation/devicetree/bindings/media/video-interfaces.txt. +The first port should be connected to sensor nodes, and the second portshould be
+connected to isp node. The following are properties specific to those nodes.Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +7
-0+ +endpoint node +------------- + +- data-lanes : (required) an array specifying active physical MIPI-CSI2 + data input lanes and their mapping to logical lanes; the + array's content is unused, only its length is meaningful;
I assume this means that the D-PHY can't reroute lanes. I would mention that explicitly, and require that the data-lanes values start at one at are consecutive instead of ignoring them.
Quoted 21 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +21
-0+Device node example +------------------- + + mipi_dphy_rx0: mipi-dphy-rx0 { + compatible = "rockchip,rk3399-mipi-dphy"; + clocks = <&cru SCLK_MIPIDPHY_REF>, + <&cru SCLK_DPHY_RX0_CFG>, + <&cru PCLK_VIO_GRF>; + clock-names = "dphy-ref", "dphy-cfg", "grf"; + power-domains = <&power RK3399_PD_VIO>; + bus-width = <4>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; +
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 57
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +10
-0+ mipi_in_wcam: endpoint@0 { + reg = <0>; + remote-endpoint = <&wcam_out>; + data-lanes = <1 2>; + }; + mipi_in_ucam: endpoint@1 { + reg = <1>; + remote-endpoint = <&ucam_out>; + data-lanes = <1>; + };
What do those two camera correspond to ? Can they be active at the same time, or do they use the same data lanes ? If they use the same data lanes, how does this work, is there a multiplexer on the board ?
Quoted 15 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +14
-0+ }; + + port@1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + dphy_rx0_out: endpoint@0 { + reg = <0>; + remote-endpoint = <&isp0_mipi_in>; + }; + }; + }; + };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v3 07/12] dt-bindings: Document the Rockchip MIPI RX D-PHY bindings
Hi all,
2017-12-12 0:45 GMT+08:00 Laurent Pinchart <[email protected]>:
Quoted 28 lines
Hello Jacob,
Thank you for the patch.
Quoted 23 lines · On Wednesday, 6 December 2017 13:19:34 EET Jacob Chen wrote:
From: Jacob Chen <[email protected]>
Add DT bindings documentation for Rockchip MIPI D-PHY RX
Signed-off-by Jacob Chen <[email protected]>--- .../bindings/media/rockchip-mipi-dphy.txt | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txtnew file mode 100644
index 000000000000..cef9450db051Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0@@ -0,0 +1,71 @@ +Rockchip SoC MIPI RX D-PHY +------------------------------------------------------------- + +Required properties: +
Quoted 8 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 10
Quoted 5 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0+- compatible: value should be one of the following + "rockchip,rk3288-mipi-dphy"; + "rockchip,rk3399-mipi-dphy"; +- rockchip,grf: GRF regs. +- bus-width : maximum number of data lanes supported (SoC specific);Bus width isn't a standard property, should this be rockchip,data-lanes or rockchip,#data-lanes ?
I forgot to remove it, it's no unnecessary now.
Quoted 54 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt
Quoted 6 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0+- clocks : list of clock specifiers, corresponding to entries in + clock-names property; +- clock-names: required clock name. + +The device node should contain two 'port' child node, according to thes/child node/child nodes/
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 25
Quoted 13 lines
bindings
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +2
-0+defined in Documentation/devicetree/bindings/media/video-interfaces.txt. +The first port should be connected to sensor nodes, and the second portshould be
+connected to isp node. The following are properties specific to those nodes.Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +7
-0+ +endpoint node +------------- + +- data-lanes : (required) an array specifying active physical MIPI-CSI2 + data input lanes and their mapping to logical lanes; the + array's content is unused, only its length is meaningful;I assume this means that the D-PHY can't reroute lanes. I would mention that explicitly, and require that the data-lanes values start at one at are consecutive instead of ignoring them.
Quoted 27 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +27
-0+Device node example +------------------- + + mipi_dphy_rx0: mipi-dphy-rx0 { + compatible = "rockchip,rk3399-mipi-dphy"; + clocks = <&cru SCLK_MIPIDPHY_REF>, + <&cru SCLK_DPHY_RX0_CFG>, + <&cru PCLK_VIO_GRF>; + clock-names = "dphy-ref", "dphy-cfg", "grf"; + power-domains = <&power RK3399_PD_VIO>; + bus-width = <4>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + mipi_in_wcam: endpoint at 0 { + reg = <0>; + remote-endpoint = <&wcam_out>; + data-lanes = <1 2>; + }; + mipi_in_ucam: endpoint at 1 {
Quoted 9 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 57
Quoted 4 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +4
-0+ reg = <1>; + remote-endpoint = <&ucam_out>; + data-lanes = <1>; + };What do those two camera correspond to ? Can they be active at the same time, or do they use the same data lanes ? If they use the same data lanes, how does this work, is there a multiplexer on the board ?
They can not be active at the same time, and there is no multiplexer. If they use the same mipi phy, then only one sensor is allowed to be actived.
See "MIPI Details" chapter
http://opensource.rock-chips.com/wiki_Rockchip-isp1
Let me enumerates soime hardware connections that is common in rockchip tablet desgin.
rk3288:
-
ISP0 --> mipi TX1/RX1 --> front sensor
--> mipi RX0 --> rear sensor
-
ISP0 --> parallel --> front sensor
--> mipi RX0 --> rear sensor
rk3399
-
mipi TX1/RX1 , mipi TX0 --> dual-mipi screen
ISP0 --> mipi RX0 --> front sensor
--> rear sensor
-
ISP1 --> mipi TX1/RX1 --> front sensor
ISP0 --> mipi RX0 --> rear sensor
Only the last connection allow two sensor work at same time.
Quoted 21 lines
Quoted 5 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +5
-0+ }; + + port at 1 { + reg = <1>; + #address-cells = <1>;Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt line 71
Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt new file +9
-0+ #size-cells = <0>; + + dphy_rx0_out: endpoint at 0 { + reg = <0>; + remote-endpoint = <&isp0_mipi_in>; + }; + }; + }; + };--
Regards,Laurent Pinchart
PATCH v3 8/12 ARM: dts: rockchip: add isp node for rk3288
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
rk3288 have a Embedded 13M ISP
--- arch/arm/boot/dts/rk3288.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +17 -0
@@ -962,6 +962,23 @@ status = "disabled"; }; + isp: isp at ff910000 { + compatible = "rockchip,rk3288-cif-isp"; + reg = <0x0 0xff910000 0x0 0x4000>; + interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru SCLK_ISP>, <&cru ACLK_ISP>, + <&cru HCLK_ISP>, <&cru PCLK_ISP_IN>, + <&cru SCLK_ISP_JPE>; + clock-names = "clk_isp", "aclk_isp", + "hclk_isp", "pclk_isp_in", + "sclk_isp_jpe"; + assigned-clocks = <&cru SCLK_ISP>, <&cru SCLK_ISP_JPE>; + assigned-clock-rates = <400000000>, <400000000>; + power-domains = <&power RK3288_PD_VIO>; + iommus = <&isp_mmu>; + status = "disabled"; + }; + isp_mmu: iommu at ff914000 { compatible = "rockchip,iommu"; reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
Signature · 1 line
2.15.0
PATCH v3 9/12 ARM: dts: rockchip: add rx0 mipi-phy for rk3288
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
It's a Designware MIPI D-PHY, used by ISP in rk3288.
--- arch/arm/boot/dts/rk3288.dtsi | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +7 -0
@@ -864,6 +864,13 @@ status = "disabled"; }; + mipi_phy_rx0: mipi-phy-rx0 { + compatible = "rockchip,rk3288-mipi-dphy"; + clocks = <&cru SCLK_MIPIDSI_24M>, <&cru PCLK_MIPI_CSI>; + clock-names = "dphy-ref", "pclk"; + status = "disabled"; + }; + io_domains: io-domains { compatible = "rockchip,rk3288-io-voltage-domain"; status = "disabled";
Signature · 1 line
2.15.0
PATCH v3 10/12 arm64: dts: rockchip: add isp0 node for rk3399
In reply to Jacob ChenFrom: Shunqian Zheng <[email protected]>
rk3399 have two ISP, but we havn't test isp1, so just add isp0 at present.
--- arch/arm64/boot/dts/rockchip/rk3399.dtsi | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +15 -0
@@ -1588,6 +1588,21 @@ status = "disabled"; }; + isp0: isp0 at ff910000 { + compatible = "rockchip,rk3399-cif-isp"; + reg = <0x0 0xff910000 0x0 0x4000>; + interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru SCLK_ISP0>, + <&cru ACLK_ISP0>, <&cru ACLK_ISP0_WRAPPER>, + <&cru HCLK_ISP0>, <&cru HCLK_ISP0_WRAPPER>; + clock-names = "clk_isp", + "aclk_isp", "aclk_isp_wrap", + "hclk_isp", "hclk_isp_wrap"; + power-domains = <&power RK3399_PD_ISP0>; + iommus = <&isp0_mmu>; + status = "disabled"; + }; + isp0_mmu: iommu at ff914000 { compatible = "rockchip,iommu"; reg = <0x0 0xff914000 0x0 0x100>, <0x0 0xff915000 0x0 0x100>;
Signature · 1 line
2.15.0
PATCH v3 11/12 arm64: dts: rockchip: add rx0 mipi-phy for rk3399
In reply to Jacob ChenFrom: Shunqian Zheng <[email protected]>
It's a Designware MIPI D-PHY, used for ISP0 in rk3399.
--- arch/arm64/boot/dts/rockchip/rk3399.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +11 -0
@@ -1292,6 +1292,17 @@ status = "disabled"; }; + mipi_dphy_rx0: mipi-dphy-rx0 { + compatible = "rockchip,rk3399-mipi-dphy"; + clocks = <&cru SCLK_MIPIDPHY_REF>, + <&cru SCLK_DPHY_RX0_CFG>, + <&cru PCLK_VIO_GRF>; + clock-names = "dphy-ref", "dphy-cfg", "grf"; + power-domains = <&power RK3399_PD_VIO>; + bus-width = <4>; + status = "disabled"; + }; + u2phy0: usb2-phy at e450 { compatible = "rockchip,rk3399-usb2phy"; reg = <0xe450 0x10>;
Signature · 1 line
2.15.0
PATCH v3 12/12 MAINTAINERS: add entry for Rockchip ISP1 driver
In reply to Jacob ChenFrom: Jacob Chen <[email protected]>
Add MAINTAINERS entry for the rockchip isp1 driver. This driver is maintained by rockchip officially and it will be used for rockchip SoC on all linux-kernel based OS.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -11665,6 +11665,16 @@ F: drivers/hid/hid-roccat* F: include/linux/hid-roccat* F: Documentation/ABI/*/sysfs-driver-hid-roccat* +ROCKCHIP ISP V1 DRIVER +M: Jacob chen <[email protected]> +M: Shunqian Zheng <[email protected]> +M: Yichong Zhong <[email protected]> +L: linux-media at vger.kernel.org +S: Maintained +F: drivers/media/platform/rockchip/isp1/ +F: Documentation/devicetree/bindings/media/rockchip-isp1.txt +F: Documentation/devicetree/bindings/media/rockchip-mipi-dphy.txt + ROCKCHIP RASTER 2D GRAPHIC ACCELERATION UNIT DRIVER M: Jacob chen <[email protected]> L: linux-media at vger.kernel.org
Signature · 1 line
2.15.0