Rockchip ISP1 Driver
v2 cover Rockchip ISP1 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
Below are some infomations about driver/hardware:
Rockchip ISP1 have many Hardware Blocks(simplied):
MIPI --> ISP --> DCrop(Mainpath) --> RSZ(Mainpath) --> DMA(Mainpath)
DMA-Input --> --> DCrop(Selfpath) --> RSZ(Selfpath) --> DMA(Selfpath);)
(Acutally the TRM(rk3288, isp) could be found online...... which contains a more detailed block diagrams ;-P)
The funcitons of each hardware block:
Mainpath : up to 4k resolution, support raw/yuv format Selfpath : up tp 1080p, support rotate, support rgb/yuv format
RSZ: scaling
DCrop: crop
ISP: 3A, Color processing, Crop
MIPI: MIPI Camera interface
Media pipelines:
Mainpath, Selfpath <-- ISP subdev <-- MIPI <-- Sensor
3A stats <-- <-- 3A parms
Code struct:
capture.c : Mainpath, Selfpath, RSZ, DCROP : capture device. rkisp1.c : ISP : v4l2 sub-device.
isp_params.c : 3A parms : output device. isp_stats.c : 3A stats : capture device. mipi_dphy_sy.c : MIPI : sperated v4l2 sub-device.
Usage:
ChromiumOS:
use below v4l2-ctl command to capture frames.
v4l2-ctl --verbose -d /dev/video4 --stream-mmap=2
--stream-to=/tmp/stream.out --stream-count=60 --stream-poll
use below command to playback the video on your PC.
mplayer /tmp/stream.out -loop 0 --demuxer=rawvideo
--rawvideo=w=800:h=600:size=$((800*600*2)):format=yuy2
or
mplayer ./stream.out -loop 0 -demuxer rawvideo -rawvideo
w=800:h=600:size=$((800*600*2)):format=yuy2 Linux:
use rkcamsrc gstreamer plugin(just a modified v4l2src) to preview.
gst-launch-1.0 rkcamsrc device=/dev/video0 io-mode=4 disable-3A=true videoconvert ! video/x-raw,format=NV12,width=640,height=480 ! kmssink
Jacob Chen (7):
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 | 61 + .../bindings/media/rockchip-mipi-dphy.txt | 77 + 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 | 1691 ++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 46 + drivers/media/platform/rockchip/isp1/common.h | 330 ++++ drivers/media/platform/rockchip/isp1/dev.c | 632 ++++++++ drivers/media/platform/rockchip/isp1/isp_params.c | 1556 ++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 81 + drivers/media/platform/rockchip/isp1/isp_stats.c | 537 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 81 + .../media/platform/rockchip/isp1/mipi_dphy_sy.c | 805 ++++++++++ drivers/media/platform/rockchip/isp1/regs.c | 251 +++ drivers/media/platform/rockchip/isp1/regs.h | 1578 ++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1230 ++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 130 ++ drivers/media/v4l2-core/v4l2-ioctl.c | 2 + include/uapi/linux/rkisp1-config.h | 554 +++++++ include/uapi/linux/videodev2.h | 4 + 24 files changed, 9725 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 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/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 v2 1/11 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
Re: [PATCH v2 01/11] media: videodev2.h, v4l2-ioctl: add rkisp1 meta buffer format
Quoted 5 lines · Jacob Chen
From: Shunqian Zheng <[email protected]>
Add the Rockchip ISP1 specific processing parameter format
V4L2_META_FMT_RK_ISP1_PARAMSand metadata formatV4L2_META_FMT_RK_ISP1_STAT_3Afor 3A.
These formats are not documented in the V4L2 spec. I think it is documented in rkisp1-config.h, so you need to add something to meta-formats.rst. It's OK to refer to that header, as long as it is clear where the documentation of the format can be found.
Regards,
Hans
Quoted 37 lines
Signed-off-by Shunqian Zheng <[email protected]>Signed-off-by Jacob Chen <[email protected]>--- 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
PATCH v2 2/11 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 | 554 +++++++++++++++++++++++++++++++++++++ 1 file changed, 554 insertions(+) create mode 100644 include/uapi/linux/rkisp1-config.h
include/uapi/linux/rkisp1-config.h new file +554 -0
@@ -0,0 +1,554 @@ +/* +* 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 + +/* 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 +/* AWB */ +#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 + +/* LSC */ +#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 +/* HIST */ +/* Last 3 values unused. */ +#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 + +/* DPCC */ +#define CIFISP_DPCC_METHODS_MAX 3 + +/* DPF */ +#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_exp_meas_mode { +/* < Y = 16 + 0.25R + 0.5G + 0.1094B */ +CIFISP_EXP_MEASURING_MODE_0 , +/* < Y = (R + G + B) x (85/256) */ +CIFISP_EXP_MEASURING_MODE_1 , +}; + +enum cifisp_exp_ctrl_auotostop { +CIFISP_EXP_CTRL_AUTOSTOP_0 =0 , +CIFISP_EXP_CTRL_AUTOSTOP_1 =1 , +}; + +struct cifisp_window { +unsigned short h_offs; +unsigned short v_offs; +unsigned short h_size; +unsigned short v_size; +}; + +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 +}; + +/* +* BLS fixed subtraction values. The values will be subtracted from the sensor +* values. Therefore a negative value means addition instead of subtraction! +*/ +struct cifisp_bls_fixed_val { +/*! Fixed (signed!) subtraction value for Bayer pattern R. */ +signed short r; +/*! Fixed (signed!) subtraction value for Bayer pattern Gr. */ +signed short gr; +/*! Fixed (signed!) subtraction value for Bayer pattern Gb. */ +signed short gb; +/*! Fixed (signed!) subtraction value for Bayer pattern B. */ +signed short b; +}; + +/* Configuration used by black level subtraction */ +struct cifisp_bls_config { +/* +* Automatic mode activated means that the measured values +* are subtracted.Otherwise the fixed subtraction +* values will be subtracted. +*/ +bool enable_auto; +unsigned char en_windows; +struct cifisp_window bls_window1;/* < Measurement window 1. */ +struct cifisp_window bls_window2;/* !< Measurement window 2 */ +/* +* Set amount of measured pixels for each Bayer position +* (A, B,C and D) to 2^bls_samples. +*/ +unsigned char bls_samples; +/* !< Fixed subtraction values. */ +struct cifisp_bls_fixed_val fixed_val; +}; + +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; +}; + +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; +}; + +struct cifisp_gamma_corr_curve { +unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE ]; +}; + +struct cifisp_gamma_curve_x_axis_pnts { +unsigned int gamma_dx0; +unsigned int gamma_dx1; +}; + +/* Configuration used by sensor degamma */ +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; +}; + +/* Configuration used by Lens shading correction */ +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; +}; + +struct cifisp_ie_config { +enum v4l2_colorfx effect; +unsigned short color_sel; +/* 3x3 Matrix Coefficients for Emboss Effect 1 */ +unsigned short eff_mat_1; +/* 3x3 Matrix Coefficients for Emboss Effect 2 */ +unsigned short eff_mat_2; +/* 3x3 Matrix Coefficients for Emboss 3/Sketch 1 */ +unsigned short eff_mat_3; +/* 3x3 Matrix Coefficients for Sketch Effect 2 */ +unsigned short eff_mat_4; +/* 3x3 Matrix Coefficients for Sketch Effect 3 */ +unsigned short eff_mat_5; +/* Chrominance increment values of tint (used for sepia effect) */ +unsigned short eff_tint; +}; + +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; +}; + +/* Configuration used by auto white balance */ +struct cifisp_awb_meas_config { +/* +* white balance measurement window (in pixels) +* Note: currently the h and v offsets are mapped to grid offsets +*/ +struct cifisp_window awb_wnd; +enum cifisp_awb_mode_type awb_mode; +/* +* only pixels values < max_y contribute to awb measurement +* (set to 0 to disable this feature) +*/ +unsigned char max_y; +/* only pixels values > min_y contribute to awb measurement */ +unsigned char min_y; +/* +* Chrominance sum maximum value, only consider pixels with Cb+Cr +* smaller than threshold for awb measurements +*/ +unsigned char max_csum; +/* +* Chrominance minimum value, only consider pixels with Cb/Cr +* each greater than threshold value for awb measurements +*/ +unsigned char min_c; +/* +* number of frames - 1 used for mean value calculation +* (ucFrames=0 means 1 Frame) +*/ +unsigned char frames; +/* reference Cr value for AWB regulation, target for AWB */ +unsigned char awb_ref_cr; +/* reference Cb value for AWB regulation, target for AWB */ +unsigned char awb_ref_cb; +bool enable_ymax_cmp; +}; + +struct cifisp_awb_gain_config { +unsigned short gain_red; +unsigned short gain_green_r; +unsigned short gain_blue; +unsigned short gain_green_b; +}; + +/* Configuration used by ISP filtering */ +struct cifisp_flt_config { +enum cifisp_flt_mode mode;/* ISP_FILT_MODE register fields */ +unsigned char grn_stage1;/* ISP_FILT_MODE register fields */ +unsigned char chr_h_mode;/* ISP_FILT_MODE register fields */ +unsigned char chr_v_mode;/* ISP_FILT_MODE register fields */ +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; +}; + +/* Configuration used by Bayer DeMosaic */ +struct cifisp_bdm_config { +unsigned char demosaic_th; +}; + +/* Configuration used by Cross Talk correction */ +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; +/* offset for the crosstalk correction matrix */ +unsigned short ct_offset_r; +unsigned short ct_offset_g; +unsigned short ct_offset_b; +}; + +enum cifisp_goc_mode { +CIFISP_GOC_MODE_LOGARITHMIC , +CIFISP_GOC_MODE_EQUIDISTANT +}; + +/* Configuration used by Gamma Out correction */ +struct cifisp_goc_config { +enum cifisp_goc_mode mode; +unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES ]; +}; + +/* Configuration used by Histogram */ +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 ]; +}; + +/* Configuration used by Auto Exposure Control */ +struct cifisp_aec_config { +enum cifisp_exp_meas_mode mode; +__u32 autostop; +struct cifisp_window meas_window; +}; + +struct cifisp_afc_config { +unsigned char num_afm_win;/* max CIFISP_AFM_MAX_WINDOWS */ +struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS ]; +unsigned int thres; +unsigned int var_shift; +}; + +enum cifisp_dpf_gain_usage { +/* don't use any gains in preprocessing stage */ +CIFISP_DPF_GAIN_USAGE_DISABLED , +/* use only the noise function gains from registers DPF_NF_GAIN_R, ... */ +CIFISP_DPF_GAIN_USAGE_NF_GAINS , +/* use only the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_LSC_GAINS , +/* use the moise function gains and the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS , +/* use only the gains from AWB module */ +CIFISP_DPF_GAIN_USAGE_AWB_GAINS , +/* use the gains from AWB and LSC module */ +CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS , +/* upper border (only for an internal evaluation) */ +CIFISP_DPF_GAIN_USAGE_MAX +}; + +enum cifisp_dpf_rb_filtersize { +/* red and blue filter kernel size 13x9 (means 7x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_13x9, +/* red and blue filter kernel size 9x9 (means 5x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_9x9, +}; + +enum cifisp_dpf_nll_scale_mode { +/* use a linear scaling */ +CIFISP_NLL_SCALE_LINEAR , +/* use a logarithmic scaling */ +CIFISP_NLL_SCALE_LOGARITHMIC , +}; + +struct cifisp_dpf_nll { +unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS ]; +enum cifisp_dpf_nll_scale_mode scale_mode; +}; + +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; +}; + +struct cifisp_dpf_g_flt { +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool gr_enable; +bool gb_enable; +}; + +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; +}; + +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; +}; + +struct cifisp_dpf_strength_config { +unsigned char r; +unsigned char g; +unsigned char b; +}; + +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; +/* post process configs, including hue, sharpness, brightness, contrast, color effect */ +/* TODO: removed from here ? set by standard v4l2 controls ? */ +struct cifisp_cproc_config cproc_config; +struct cifisp_ie_config ie_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; +}; + +struct rkisp1_isp_params_cfg { +/* mask the enable bits of which module should be updated */ +unsigned int module_en_update; +/* mask the enable value of each module, only update the module which correspond +* bit was set in module_en_update +*/ +unsigned int module_ens; +/* mask the config bits of which module should be updated */ +unsigned int module_cfg_update; + +struct cifisp_isp_meas_cfg meas; +struct cifisp_isp_other_cfg others; +}; + +/* measurement statistics */ + +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; +}; + +struct cifisp_awb_stat { +struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID ]; +}; + +struct cifisp_hist_stat { +unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX ]; +}; + +/*! BLS mean measured values */ +struct cifisp_bls_meas_val { +/*! Mean measured value for Bayer pattern R. */ +unsigned short meas_r; +/*! Mean measured value for Bayer pattern Gr. */ +unsigned short meas_gr; +/*! Mean measured value for Bayer pattern Gb. */ +unsigned short meas_gb; +/*! Mean measured value for Bayer pattern B. */ +unsigned short meas_b; +}; + +struct cifisp_ae_stat { +unsigned char exp_mean[CIFISP_AE_MEAN_MAX ]; +struct cifisp_bls_meas_val bls_val;/* available wit exposure results */ +}; + +struct cifisp_af_meas_val { +unsigned int sum; +unsigned int lum; +}; + +struct cifisp_af_stat { +struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS ]; +}; + +struct cifisp_stat { +struct cifisp_awb_stat awb; +struct cifisp_ae_stat ae; +struct cifisp_af_stat af; +struct cifisp_hist_stat hist; +}; + +struct rkisp1_stat_buffer { +unsigned int meas_type; +unsigned int frame_id; +struct cifisp_stat params; +}; + +#endif /* _UAPI_RKISP1_CONFIG_H */
Signature · 1 line
2.15.0
Re: [PATCH v2 02/11] media: rkisp1: Add user space ABI definitions
Quoted 3 lines · Jacob Chen
From: Jeffy Chen <[email protected]>
Add the header for userspace
I gather that this effectively documents the metadata?
I recommend using kernel-doc formatting here.
One thing I immediately noticed is that these structures will have a different layout for 32 or 64 architectures. Which is a problem if you compile for 32 bit on a 64 bit kernel on the rk3399.
I think you need to be very careful how you define these structures.
Are these parameters documented in a datasheet? If so, then add a reference to that datasheet. Is it publicly available or do you need an NDA to get it?
Quoted 168 lines
Signed-off-by Jeffy Chen <[email protected]>Signed-off-by Jacob Chen <[email protected]>--- include/uapi/linux/rkisp1-config.h | 554 +++++++++++++++++++++++++++++++++++++ 1 file changed, 554 insertions(+) create mode 100644 include/uapi/linux/rkisp1-config.hinclude/uapi/linux/rkisp1-config.h new file +154
-0@@ -0,0 +1,554 @@ +/* +* 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 + +/* 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 +/* AWB */ +#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 + +/* LSC */ +#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 +/* HIST */ +/* Last 3 values unused. */ +#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 + +/* DPCC */ +#define CIFISP_DPCC_METHODS_MAX 3 + +/* DPF */ +#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_exp_meas_mode { +/* < Y = 16 + 0.25R + 0.5G + 0.1094B */ +CIFISP_EXP_MEASURING_MODE_0 , +/* < Y = (R + G + B) x (85/256) */ +CIFISP_EXP_MEASURING_MODE_1 , +}; + +enum cifisp_exp_ctrl_auotostop { +CIFISP_EXP_CTRL_AUTOSTOP_0 =0 , +CIFISP_EXP_CTRL_AUTOSTOP_1 =1 , +}; + +struct cifisp_window { +unsigned short h_offs; +unsigned short v_offs; +unsigned short h_size; +unsigned short v_size; +}; + +enum cifisp_awb_mode_type { +CIFISP_AWB_MODE_MANUAL , +CIFISP_AWB_MODE_RGB , +CIFISP_AWB_MODE_YCBCR +}; + +enum cifisp_flt_mode {
include/uapi/linux/rkisp1-config.h line 164
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+CIFISP_FLT_STATIC_MODE , +CIFISP_FLT_DYNAMIC_MODE +}; + +/* +* BLS fixed subtraction values. The values will be subtracted from the sensor +* values. Therefore a negative value means addition instead of subtraction! +*/ +struct cifisp_bls_fixed_val { +/*! Fixed (signed!) subtraction value for Bayer pattern R. */
What's the exact fixed point format used here?
Quoted 381 lines
include/uapi/linux/rkisp1-config.h new file +380
-0+signed short r; +/*! Fixed (signed!) subtraction value for Bayer pattern Gr. */ +signed short gr; +/*! Fixed (signed!) subtraction value for Bayer pattern Gb. */ +signed short gb; +/*! Fixed (signed!) subtraction value for Bayer pattern B. */ +signed short b; +}; + +/* Configuration used by black level subtraction */ +struct cifisp_bls_config { +/* +* Automatic mode activated means that the measured values +* are subtracted.Otherwise the fixed subtraction +* values will be subtracted. +*/ +bool enable_auto; +unsigned char en_windows; +struct cifisp_window bls_window1;/* < Measurement window 1. */ +struct cifisp_window bls_window2;/* !< Measurement window 2 */ +/* +* Set amount of measured pixels for each Bayer position +* (A, B,C and D) to 2^bls_samples. +*/ +unsigned char bls_samples; +/* !< Fixed subtraction values. */ +struct cifisp_bls_fixed_val fixed_val; +}; + +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; +}; + +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; +}; + +struct cifisp_gamma_corr_curve { +unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE ]; +}; + +struct cifisp_gamma_curve_x_axis_pnts { +unsigned int gamma_dx0; +unsigned int gamma_dx1; +}; + +/* Configuration used by sensor degamma */ +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; +}; + +/* Configuration used by Lens shading correction */ +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; +}; + +struct cifisp_ie_config { +enum v4l2_colorfx effect; +unsigned short color_sel; +/* 3x3 Matrix Coefficients for Emboss Effect 1 */ +unsigned short eff_mat_1; +/* 3x3 Matrix Coefficients for Emboss Effect 2 */ +unsigned short eff_mat_2; +/* 3x3 Matrix Coefficients for Emboss 3/Sketch 1 */ +unsigned short eff_mat_3; +/* 3x3 Matrix Coefficients for Sketch Effect 2 */ +unsigned short eff_mat_4; +/* 3x3 Matrix Coefficients for Sketch Effect 3 */ +unsigned short eff_mat_5; +/* Chrominance increment values of tint (used for sepia effect) */ +unsigned short eff_tint; +}; + +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; +}; + +/* Configuration used by auto white balance */ +struct cifisp_awb_meas_config { +/* +* white balance measurement window (in pixels) +* Note: currently the h and v offsets are mapped to grid offsets +*/ +struct cifisp_window awb_wnd; +enum cifisp_awb_mode_type awb_mode; +/* +* only pixels values < max_y contribute to awb measurement +* (set to 0 to disable this feature) +*/ +unsigned char max_y; +/* only pixels values > min_y contribute to awb measurement */ +unsigned char min_y; +/* +* Chrominance sum maximum value, only consider pixels with Cb+Cr +* smaller than threshold for awb measurements +*/ +unsigned char max_csum; +/* +* Chrominance minimum value, only consider pixels with Cb/Cr +* each greater than threshold value for awb measurements +*/ +unsigned char min_c; +/* +* number of frames - 1 used for mean value calculation +* (ucFrames=0 means 1 Frame) +*/ +unsigned char frames; +/* reference Cr value for AWB regulation, target for AWB */ +unsigned char awb_ref_cr; +/* reference Cb value for AWB regulation, target for AWB */ +unsigned char awb_ref_cb; +bool enable_ymax_cmp; +}; + +struct cifisp_awb_gain_config { +unsigned short gain_red; +unsigned short gain_green_r; +unsigned short gain_blue; +unsigned short gain_green_b; +}; + +/* Configuration used by ISP filtering */ +struct cifisp_flt_config { +enum cifisp_flt_mode mode;/* ISP_FILT_MODE register fields */ +unsigned char grn_stage1;/* ISP_FILT_MODE register fields */ +unsigned char chr_h_mode;/* ISP_FILT_MODE register fields */ +unsigned char chr_v_mode;/* ISP_FILT_MODE register fields */ +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; +}; + +/* Configuration used by Bayer DeMosaic */ +struct cifisp_bdm_config { +unsigned char demosaic_th; +}; + +/* Configuration used by Cross Talk correction */ +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; +/* offset for the crosstalk correction matrix */ +unsigned short ct_offset_r; +unsigned short ct_offset_g; +unsigned short ct_offset_b; +}; + +enum cifisp_goc_mode { +CIFISP_GOC_MODE_LOGARITHMIC , +CIFISP_GOC_MODE_EQUIDISTANT +}; + +/* Configuration used by Gamma Out correction */ +struct cifisp_goc_config { +enum cifisp_goc_mode mode; +unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES ]; +}; + +/* Configuration used by Histogram */ +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 ]; +}; + +/* Configuration used by Auto Exposure Control */ +struct cifisp_aec_config { +enum cifisp_exp_meas_mode mode; +__u32 autostop; +struct cifisp_window meas_window; +}; + +struct cifisp_afc_config { +unsigned char num_afm_win;/* max CIFISP_AFM_MAX_WINDOWS */ +struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS ]; +unsigned int thres; +unsigned int var_shift; +}; + +enum cifisp_dpf_gain_usage { +/* don't use any gains in preprocessing stage */ +CIFISP_DPF_GAIN_USAGE_DISABLED , +/* use only the noise function gains from registers DPF_NF_GAIN_R, ... */ +CIFISP_DPF_GAIN_USAGE_NF_GAINS , +/* use only the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_LSC_GAINS , +/* use the moise function gains and the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS , +/* use only the gains from AWB module */ +CIFISP_DPF_GAIN_USAGE_AWB_GAINS , +/* use the gains from AWB and LSC module */ +CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS , +/* upper border (only for an internal evaluation) */ +CIFISP_DPF_GAIN_USAGE_MAX +}; + +enum cifisp_dpf_rb_filtersize { +/* red and blue filter kernel size 13x9 (means 7x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_13x9, +/* red and blue filter kernel size 9x9 (means 5x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_9x9, +}; + +enum cifisp_dpf_nll_scale_mode { +/* use a linear scaling */ +CIFISP_NLL_SCALE_LINEAR , +/* use a logarithmic scaling */ +CIFISP_NLL_SCALE_LOGARITHMIC , +}; + +struct cifisp_dpf_nll { +unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS ]; +enum cifisp_dpf_nll_scale_mode scale_mode; +}; + +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; +}; + +struct cifisp_dpf_g_flt { +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool gr_enable; +bool gb_enable; +}; + +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; +}; + +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; +}; + +struct cifisp_dpf_strength_config { +unsigned char r; +unsigned char g; +unsigned char b; +}; + +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; +/* post process configs, including hue, sharpness, brightness, contrast, color effect */ +/* TODO: removed from here ? set by standard v4l2 controls ? */ +struct cifisp_cproc_config cproc_config; +struct cifisp_ie_config ie_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; +}; + +struct rkisp1_isp_params_cfg { +/* mask the enable bits of which module should be updated */ +unsigned int module_en_update; +/* mask the enable value of each module, only update the module which correspond +* bit was set in module_en_update +*/ +unsigned int module_ens; +/* mask the config bits of which module should be updated */ +unsigned int module_cfg_update; + +struct cifisp_isp_meas_cfg meas; +struct cifisp_isp_other_cfg others; +}; + +/* measurement statistics */ + +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; +}; + +struct cifisp_awb_stat { +struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID ]; +}; + +struct cifisp_hist_stat { +unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX ]; +}; + +/*! BLS mean measured values */ +struct cifisp_bls_meas_val { +/*! Mean measured value for Bayer pattern R. */ +unsigned short meas_r; +/*! Mean measured value for Bayer pattern Gr. */ +unsigned short meas_gr; +/*! Mean measured value for Bayer pattern Gb. */ +unsigned short meas_gb; +/*! Mean measured value for Bayer pattern B. */ +unsigned short meas_b; +}; + +struct cifisp_ae_stat { +unsigned char exp_mean[CIFISP_AE_MEAN_MAX ]; +struct cifisp_bls_meas_val bls_val;/* available wit exposure results */ +}; + +struct cifisp_af_meas_val { +unsigned int sum; +unsigned int lum; +}; + +struct cifisp_af_stat { +struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS ]; +}; + +struct cifisp_stat { +struct cifisp_awb_stat awb; +struct cifisp_ae_stat ae; +struct cifisp_af_stat af;
include/uapi/linux/rkisp1-config.h line 554
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+ struct cifisp_hist_stat hist; +}; + +struct rkisp1_stat_buffer { +unsigned int meas_type; +unsigned int frame_id; +struct cifisp_stat params; +}; + +#endif /* _UAPI_RKISP1_CONFIG_H */
You do need to document more of this. If the datasheet is publicly available you can get away with referring to the relevant sections of that datasheet.
Regards,
Hans
Re: [PATCH v2 02/11] media: rkisp1: Add user space ABI definitions
Hi Hans,
2017-11-27 18:26 GMT+08:00 Hans Verkuil <[email protected]>:
Quoted 5 lines · Jacob Chen
Quoted 3 lines
From: Jeffy Chen <[email protected]>
Add the header for userspace
Quoted 8 lines
I gather that this effectively documents the metadata?
I recommend using kernel-doc formatting here.
One thing I immediately noticed is that these structures will have a different layout for 32 or 64 architectures. Which is a problem if you compile for 32 bit on a 64 bit kernel on the rk3399.
Thanks.....We didn't even notice that.
I will add "__attribute__ ((packed))" to each sturct.
Quoted 5 lines
I think you need to be very careful how you define these structures.
Are these parameters documented in a datasheet? If so, then add a reference to that datasheet. Is it publicly available or do you need an NDA to get it?
It can't be published, but i will try to add document for each parameters.
Quoted 579 lines
Quoted 168 lines
Signed-off-by Jeffy Chen <[email protected]>Signed-off-by Jacob Chen <[email protected]>--- include/uapi/linux/rkisp1-config.h | 554 +++++++++++++++++++++++++++++++++++++ 1 file changed, 554 insertions(+) create mode 100644 include/uapi/linux/rkisp1-config.hinclude/uapi/linux/rkisp1-config.h new file +154
-0@@ -0,0 +1,554 @@ +/* +* 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 + +/* 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 +/* AWB */ +#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 + +/* LSC */ +#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 +/* HIST */ +/* Last 3 values unused. */ +#define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 28 + +/* DPCC */ +#define CIFISP_DPCC_METHODS_MAX 3 + +/* DPF */ +#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_exp_meas_mode { +/* < Y = 16 + 0.25R + 0.5G + 0.1094B */ +CIFISP_EXP_MEASURING_MODE_0 , +/* < Y = (R + G + B) x (85/256) */ +CIFISP_EXP_MEASURING_MODE_1 , +}; + +enum cifisp_exp_ctrl_auotostop { +CIFISP_EXP_CTRL_AUTOSTOP_0 =0 , +CIFISP_EXP_CTRL_AUTOSTOP_1 =1 , +}; + +struct cifisp_window { +unsigned short h_offs; +unsigned short v_offs; +unsigned short h_size; +unsigned short v_size; +}; + +enum cifisp_awb_mode_type { +CIFISP_AWB_MODE_MANUAL , +CIFISP_AWB_MODE_RGB , +CIFISP_AWB_MODE_YCBCR +}; + +enum cifisp_flt_mode {include/uapi/linux/rkisp1-config.h line 164
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+CIFISP_FLT_STATIC_MODE , +CIFISP_FLT_DYNAMIC_MODE +}; + +/* +* BLS fixed subtraction values. The values will be subtracted from the sensor +* values. Therefore a negative value means addition instead of subtraction! +*/ +struct cifisp_bls_fixed_val { +/*! Fixed (signed!) subtraction value for Bayer pattern R. */ What's the exact fixed point format used here?
Quoted 381 lines
include/uapi/linux/rkisp1-config.h new file +380
-0+signed short r; +/*! Fixed (signed!) subtraction value for Bayer pattern Gr. */ +signed short gr; +/*! Fixed (signed!) subtraction value for Bayer pattern Gb. */ +signed short gb; +/*! Fixed (signed!) subtraction value for Bayer pattern B. */ +signed short b; +}; + +/* Configuration used by black level subtraction */ +struct cifisp_bls_config { +/* +* Automatic mode activated means that the measured values +* are subtracted.Otherwise the fixed subtraction +* values will be subtracted. +*/ +bool enable_auto; +unsigned char en_windows; +struct cifisp_window bls_window1;/* < Measurement window 1. */ +struct cifisp_window bls_window2;/* !< Measurement window 2 */ +/* +* Set amount of measured pixels for each Bayer position +* (A, B,C and D) to 2^bls_samples. +*/ +unsigned char bls_samples; +/* !< Fixed subtraction values. */ +struct cifisp_bls_fixed_val fixed_val; +}; + +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; +}; + +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; +}; + +struct cifisp_gamma_corr_curve { +unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE ]; +}; + +struct cifisp_gamma_curve_x_axis_pnts { +unsigned int gamma_dx0; +unsigned int gamma_dx1; +}; + +/* Configuration used by sensor degamma */ +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; +}; + +/* Configuration used by Lens shading correction */ +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; +}; + +struct cifisp_ie_config { +enum v4l2_colorfx effect; +unsigned short color_sel; +/* 3x3 Matrix Coefficients for Emboss Effect 1 */ +unsigned short eff_mat_1; +/* 3x3 Matrix Coefficients for Emboss Effect 2 */ +unsigned short eff_mat_2; +/* 3x3 Matrix Coefficients for Emboss 3/Sketch 1 */ +unsigned short eff_mat_3; +/* 3x3 Matrix Coefficients for Sketch Effect 2 */ +unsigned short eff_mat_4; +/* 3x3 Matrix Coefficients for Sketch Effect 3 */ +unsigned short eff_mat_5; +/* Chrominance increment values of tint (used for sepia effect) */ +unsigned short eff_tint; +}; + +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; +}; + +/* Configuration used by auto white balance */ +struct cifisp_awb_meas_config { +/* +* white balance measurement window (in pixels) +* Note: currently the h and v offsets are mapped to grid offsets +*/ +struct cifisp_window awb_wnd; +enum cifisp_awb_mode_type awb_mode; +/* +* only pixels values < max_y contribute to awb measurement +* (set to 0 to disable this feature) +*/ +unsigned char max_y; +/* only pixels values > min_y contribute to awb measurement */ +unsigned char min_y; +/* +* Chrominance sum maximum value, only consider pixels with Cb+Cr +* smaller than threshold for awb measurements +*/ +unsigned char max_csum; +/* +* Chrominance minimum value, only consider pixels with Cb/Cr +* each greater than threshold value for awb measurements +*/ +unsigned char min_c; +/* +* number of frames - 1 used for mean value calculation +* (ucFrames=0 means 1 Frame) +*/ +unsigned char frames; +/* reference Cr value for AWB regulation, target for AWB */ +unsigned char awb_ref_cr; +/* reference Cb value for AWB regulation, target for AWB */ +unsigned char awb_ref_cb; +bool enable_ymax_cmp; +}; + +struct cifisp_awb_gain_config { +unsigned short gain_red; +unsigned short gain_green_r; +unsigned short gain_blue; +unsigned short gain_green_b; +}; + +/* Configuration used by ISP filtering */ +struct cifisp_flt_config { +enum cifisp_flt_mode mode;/* ISP_FILT_MODE register fields */ +unsigned char grn_stage1;/* ISP_FILT_MODE register fields */ +unsigned char chr_h_mode;/* ISP_FILT_MODE register fields */ +unsigned char chr_v_mode;/* ISP_FILT_MODE register fields */ +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; +}; + +/* Configuration used by Bayer DeMosaic */ +struct cifisp_bdm_config { +unsigned char demosaic_th; +}; + +/* Configuration used by Cross Talk correction */ +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; +/* offset for the crosstalk correction matrix */ +unsigned short ct_offset_r; +unsigned short ct_offset_g; +unsigned short ct_offset_b; +}; + +enum cifisp_goc_mode { +CIFISP_GOC_MODE_LOGARITHMIC , +CIFISP_GOC_MODE_EQUIDISTANT +}; + +/* Configuration used by Gamma Out correction */ +struct cifisp_goc_config { +enum cifisp_goc_mode mode; +unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES ]; +}; + +/* Configuration used by Histogram */ +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 ]; +}; + +/* Configuration used by Auto Exposure Control */ +struct cifisp_aec_config { +enum cifisp_exp_meas_mode mode; +__u32 autostop; +struct cifisp_window meas_window; +}; + +struct cifisp_afc_config { +unsigned char num_afm_win;/* max CIFISP_AFM_MAX_WINDOWS */ +struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS ]; +unsigned int thres; +unsigned int var_shift; +}; + +enum cifisp_dpf_gain_usage { +/* don't use any gains in preprocessing stage */ +CIFISP_DPF_GAIN_USAGE_DISABLED , +/* use only the noise function gains from registers DPF_NF_GAIN_R, ... */ +CIFISP_DPF_GAIN_USAGE_NF_GAINS , +/* use only the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_LSC_GAINS , +/* use the moise function gains and the gains from LSC module */ +CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS , +/* use only the gains from AWB module */ +CIFISP_DPF_GAIN_USAGE_AWB_GAINS , +/* use the gains from AWB and LSC module */ +CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS , +/* upper border (only for an internal evaluation) */ +CIFISP_DPF_GAIN_USAGE_MAX +}; + +enum cifisp_dpf_rb_filtersize { +/* red and blue filter kernel size 13x9 (means 7x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_13x9, +/* red and blue filter kernel size 9x9 (means 5x5 active pixel) */ + CIFISP_DPF_RB_FILTERSIZE_9x9, +}; + +enum cifisp_dpf_nll_scale_mode { +/* use a linear scaling */ +CIFISP_NLL_SCALE_LINEAR , +/* use a logarithmic scaling */ +CIFISP_NLL_SCALE_LOGARITHMIC , +}; + +struct cifisp_dpf_nll { +unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS ]; +enum cifisp_dpf_nll_scale_mode scale_mode; +}; + +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; +}; + +struct cifisp_dpf_g_flt { +unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS ]; +bool gr_enable; +bool gb_enable; +}; + +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; +}; + +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; +}; + +struct cifisp_dpf_strength_config { +unsigned char r; +unsigned char g; +unsigned char b; +}; + +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; +/* post process configs, including hue, sharpness, brightness, contrast, color effect */ +/* TODO: removed from here ? set by standard v4l2 controls ? */ +struct cifisp_cproc_config cproc_config; +struct cifisp_ie_config ie_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; +}; + +struct rkisp1_isp_params_cfg { +/* mask the enable bits of which module should be updated */ +unsigned int module_en_update; +/* mask the enable value of each module, only update the module which correspond +* bit was set in module_en_update +*/ +unsigned int module_ens; +/* mask the config bits of which module should be updated */ +unsigned int module_cfg_update; + +struct cifisp_isp_meas_cfg meas; +struct cifisp_isp_other_cfg others; +}; + +/* measurement statistics */ + +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; +}; + +struct cifisp_awb_stat { +struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID ]; +}; + +struct cifisp_hist_stat { +unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX ]; +}; + +/*! BLS mean measured values */ +struct cifisp_bls_meas_val { +/*! Mean measured value for Bayer pattern R. */ +unsigned short meas_r; +/*! Mean measured value for Bayer pattern Gr. */ +unsigned short meas_gr; +/*! Mean measured value for Bayer pattern Gb. */ +unsigned short meas_gb; +/*! Mean measured value for Bayer pattern B. */ +unsigned short meas_b; +}; + +struct cifisp_ae_stat { +unsigned char exp_mean[CIFISP_AE_MEAN_MAX ]; +struct cifisp_bls_meas_val bls_val;/* available wit exposure results */ +}; + +struct cifisp_af_meas_val { +unsigned int sum; +unsigned int lum; +}; + +struct cifisp_af_stat { +struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS ]; +}; + +struct cifisp_stat { +struct cifisp_awb_stat awb; +struct cifisp_ae_stat ae; +struct cifisp_af_stat af;include/uapi/linux/rkisp1-config.h line 554
Quoted 10 lines
include/uapi/linux/rkisp1-config.h new file +10
-0+ struct cifisp_hist_stat hist; +}; + +struct rkisp1_stat_buffer { +unsigned int meas_type; +unsigned int frame_id; +struct cifisp_stat params; +}; + +#endif /* _UAPI_RKISP1_CONFIG_H */ You do need to document more of this. If the datasheet is publicly available you can get away with referring to the relevant sections of that datasheet.
Regards,
Hans
PATCH v2 3/11 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 | 1691 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 46 + drivers/media/platform/rockchip/isp1/common.h | 330 ++++ drivers/media/platform/rockchip/isp1/dev.c | 632 ++++++++ drivers/media/platform/rockchip/isp1/isp_params.c | 1556 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 81 + drivers/media/platform/rockchip/isp1/isp_stats.c | 537 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 81 + drivers/media/platform/rockchip/isp1/regs.c | 251 +++ drivers/media/platform/rockchip/isp1/regs.h | 1578 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1230 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 130 ++ 15 files changed, 8161 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/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 +1691 -0
1,691 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/capture.h new file +46 -0
46 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/common.h new file +330 -0
330 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/dev.c new file +632 -0
632 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_params.c new file +1556 -0
271 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_params.h new file +81 -0
81 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_stats.c new file +537 -0
537 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/isp_stats.h new file +81 -0
81 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/regs.c new file +251 -0
251 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/regs.h new file +1578 -0
1,578 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/rkisp1.c new file +1230 -0
1,230 lines not on this page · raw message
drivers/media/platform/rockchip/isp1/rkisp1.h new file +130 -0
130 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.
kbuild test robot
build botRe: [PATCH v2 03/11] media: rkisp1: add rockchip isp1 driver
Thank you for the patch! Yet something to improve:
Hi Jacob,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20171124]
[cannot apply to rockchip/for-next v4.14]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jacob-Chen/Rockchip-ISP1-Driver/20171126-224713 base: git://linuxtv.org/media_tree.git master config: mips-allmodconfig (attached as .config) compiler: mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips
All error/warnings (new ones prefixed by >>):
drivers/media//platform/rockchip/isp1/rkisp1.c: In function 'rkisp1_isp_sd_s_stream':
>> drivers/media//platform/rockchip/isp1/rkisp1.c:136:6: warning: 'isp_ctrl' may be used uninitialized in this function [-Wmaybe-uninitialized]
u32 isp_ctrl;
^~~~~~~~
>> drivers/media//platform/rockchip/isp1/rkisp1.c:209:2: warning: 'acq_mult' may be used uninitialized in this function [-Wmaybe-uninitialized]
writel(acq_mult * in_frm->width, base + CIF_ISP_ACQ_H_SIZE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/rkisp1.c:139:6: note: 'acq_mult' was declared here
u32 acq_mult;
^~~~~~~~
--
drivers/media//platform/rockchip/isp1/dev.c: In function 'rkisp1_runtime_suspend':
drivers/media//platform/rockchip/isp1/dev.c:597:9: error: implicit declaration of function 'pinctrl_pm_select_sleep_state' [-Werror=implicit-function-declaration]
return pinctrl_pm_select_sleep_state(dev);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/dev.c: In function 'rkisp1_runtime_resume':
>> drivers/media//platform/rockchip/isp1/dev.c:605:8: error: implicit declaration of function 'pinctrl_pm_select_default_state'; did you mean 'irq_set_default_host'? [-Werror=implicit-function-declaration]
ret = pinctrl_pm_select_default_state(dev);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
irq_set_default_host
cc1: some warnings being treated as errors
--
>> drivers/media//platform/rockchip/isp1/isp_params.c:1350:3: error: 'const struct v4l2_ioctl_ops' has no member named 'vidioc_enum_fmt_meta_out'; did you mean 'vidioc_enum_fmt_meta_cap'?
.vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~~
vidioc_enum_fmt_meta_cap
drivers/media//platform/rockchip/isp1/isp_params.c:1350:30: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/isp_params.c:1350:30: note: (near initialization for 'rkisp1_params_ioctl.vidioc_g_std')
>> drivers/media//platform/rockchip/isp1/isp_params.c:1351:3: error: 'const struct v4l2_ioctl_ops' has no member named 'vidioc_g_fmt_meta_out'; did you mean 'vidioc_g_fmt_meta_cap'?
.vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~
vidioc_g_fmt_meta_cap
drivers/media//platform/rockchip/isp1/isp_params.c:1351:27: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/isp_params.c:1351:27: note: (near initialization for 'rkisp1_params_ioctl.vidioc_s_std')
>> drivers/media//platform/rockchip/isp1/isp_params.c:1352:3: error: 'const struct v4l2_ioctl_ops' has no member named 'vidioc_s_fmt_meta_out'; did you mean 'vidioc_s_fmt_meta_cap'?
.vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~
vidioc_s_fmt_meta_cap
drivers/media//platform/rockchip/isp1/isp_params.c:1352:27: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/isp_params.c:1352:27: note: (near initialization for 'rkisp1_params_ioctl.vidioc_querystd')
>> drivers/media//platform/rockchip/isp1/isp_params.c:1353:3: error: 'const struct v4l2_ioctl_ops' has no member named 'vidioc_try_fmt_meta_out'; did you mean 'vidioc_try_fmt_meta_cap'?
.vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~
vidioc_try_fmt_meta_cap
drivers/media//platform/rockchip/isp1/isp_params.c:1353:29: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media//platform/rockchip/isp1/isp_params.c:1353:29: note: (near initialization for 'rkisp1_params_ioctl.vidioc_enum_input')
drivers/media//platform/rockchip/isp1/isp_params.c: In function 'rkisp1_params_init_vb2_queue':
>> drivers/media//platform/rockchip/isp1/isp_params.c:1478:12: error: 'V4L2_BUF_TYPE_META_OUTPUT' undeclared (first use in this function); did you mean 'V4L2_BUF_TYPE_SDR_OUTPUT'?
q->type = V4L2_BUF_TYPE_META_OUTPUT;
^~~~~~~~~~~~~~~~~~~~~~~~~
V4L2_BUF_TYPE_SDR_OUTPUT
drivers/media//platform/rockchip/isp1/isp_params.c:1478:12: note: each undeclared identifier is reported only once for each function it appears in
drivers/media//platform/rockchip/isp1/isp_params.c: In function 'rkisp1_register_params_vdev':
>> drivers/media//platform/rockchip/isp1/isp_params.c:1523:43: error: 'V4L2_CAP_META_OUTPUT' undeclared (first use in this function); did you mean 'V4L2_CAP_RDS_OUTPUT'?
vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT;
^~~~~~~~~~~~~~~~~~~~
V4L2_CAP_RDS_OUTPUTcc1: some warnings being treated as errors
vim +605 drivers/media//platform/rockchip/isp1/dev.c
591
592 static int __maybe_unused rkisp1_runtime_suspend(struct device *dev)
593 {
594 struct rkisp1_device *isp_dev = dev_get_drvdata(dev);
595
596 rkisp1_disable_sys_clk(isp_dev);
> 597 return pinctrl_pm_select_sleep_state(dev);
598 }
599
600 static int __maybe_unused rkisp1_runtime_resume(struct device *dev)
601 {
602 struct rkisp1_device *isp_dev = dev_get_drvdata(dev);
603 int ret;
604
> 605 ret = pinctrl_pm_select_default_state(dev); 606 if (ret < 0)
607 return ret;
608 rkisp1_enable_sys_clk(isp_dev);
609
610 return 0;
611 }
612
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 47597 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171127/1c7765ae/attachment-0001.gz>
Re: [PATCH v2 03/11] media: rkisp1: add rockchip isp1 driver
In reply to Jacob ChenHi Jacob,
Thank you for this driver! Much appreciated.
I have a bunch of comments below, nothing big, really. The main thing is that you really need to sprinkle some more comments in the source code.
Quoted 142 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 | 1691 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 46 + drivers/media/platform/rockchip/isp1/common.h | 330 ++++ drivers/media/platform/rockchip/isp1/dev.c | 632 ++++++++ drivers/media/platform/rockchip/isp1/isp_params.c | 1556 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 81 + drivers/media/platform/rockchip/isp1/isp_stats.c | 537 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 81 + drivers/media/platform/rockchip/isp1/regs.c | 251 +++ drivers/media/platform/rockchip/isp1/regs.h | 1578 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1230 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 130 ++ 15 files changed, 8161 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/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 +47
-0@@ -0,0 +1,1691 @@ +/* +* 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/delay.h> +#include <linux/pm_runtime.h> +#include <media/v4l2-common.h> +#include <media/v4l2-event.h> +#include <media/v4l2-fh.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-subdev.h> +#include <media/videobuf2-dma-contig.h> +#include "capture.h" +#include "rkisp1.h" +#include "regs.h" + +#define CIF_ISP_REQ_BUFS_MIN 1
drivers/media/platform/rockchip/isp1/capture.c line 57
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+#define CIF_ISP_REQ_BUFS_MAX 8 + +/* +* mp sink source: isp +* sp sink source : isp, no dma now +* mp sink pad fmts: yuv 422, raw +* sp sink pad fmts: yuv422( source isp), yuv420...... +* mp source fmts: yuv, raw, no jpeg now +* sp source fmts: yuv, rgb +*/
Is this a left-over comment as a reminder to yourself? If so, remove it, if not, then it needs to be expanded since it's not clear what the purpose of this comment is.
Quoted 15 lines
drivers/media/platform/rockchip/isp1/capture.c new file +15
-0+ +#define STREAM_PAD_SINK 0 +#define STREAM_PAD_SOURCE 1 + +#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416 +#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT 3312 +#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920 +#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT 1080 +#define STREAM_MIN_RSZ_OUTPUT_WIDTH 32 +#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 16 + +#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH +#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT +#define STREAM_MIN_MP_SP_INPUT_WIDTH 32 +#define STREAM_MIN_MP_SP_INPUT_HEIGHT 32
drivers/media/platform/rockchip/isp1/capture.c line 82
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ +/* +* crop accepts only yuv422 format +* resizer can accept yuv444,yuv422,yuv420 format, can output yuv422, yuv420, +* yuv444 format +* sp resizer has two data source: DMA-reader or crop +* mp resizer has only one data source: crop +* if format is unsupported by path, crop and resizer should be bypassed +* (disabled) +*/
Same for this comment.
drivers/media/platform/rockchip/isp1/capture.c line 86
Quoted 4 lines
drivers/media/platform/rockchip/isp1/capture.c new file +4
-0+ +/* Get xsubs and ysubs for fourcc formats +* +* @xsubs: horizon color samples in a 4*4 matrix, for yuv
horizon -> horizontal
Quoted 435 lines
drivers/media/platform/rockchip/isp1/capture.c new file +435
-0+* @ysubs: vertical color samples in a 4*4 matrix, for yuv +*/ +static int fcc_xysubs (u32 fcc,u32 *xsubs,u32 *ysubs) +{ +switch (fcc) { +case V4L2_PIX_FMT_GREY : +case V4L2_PIX_FMT_YUV444M : + *xsubs =1 ; + *ysubs =1 ; +break ; +case V4L2_PIX_FMT_YUYV : +case V4L2_PIX_FMT_YVYU : +case V4L2_PIX_FMT_VYUY : +case V4L2_PIX_FMT_YUV422P : +case V4L2_PIX_FMT_NV16 : +case V4L2_PIX_FMT_NV61 : +case V4L2_PIX_FMT_YVU422M : + *xsubs =2 ; + *ysubs =1 ; +break ; +case V4L2_PIX_FMT_NV21 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21M : +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_YVU420 : + *xsubs =2 ; + *ysubs =2 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int mbus_code_xysubs (u32 code,u32 *xsubs,u32 *ysubs) +{ +switch (code) { +case MEDIA_BUS_FMT_YUYV8_2X8 : +case MEDIA_BUS_FMT_YUYV8_1X16 : +case MEDIA_BUS_FMT_YVYU8_1X16 : +case MEDIA_BUS_FMT_UYVY8_1X16 : +case MEDIA_BUS_FMT_VYUY8_1X16 : + *xsubs =2 ; + *ysubs =1 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int mbus_code_sp_in_fmt (u32 code,u32 *format) +{ +switch (code) { +case MEDIA_BUS_FMT_YUYV8_2X8 : + *format =MI_CTRL_SP_INPUT_YUV422 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct capture_fmt mp_fmts[] = { +/* yuv422 */ + { + .fourcc =V4L2_PIX_FMT_YUYV , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_YVYU , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_VYUY , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_YUV422P , + .fmt_type =FMT_YUV , + .bpp = {8 ,4 ,4 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_NV16 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV61 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_YVU422M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv420 */ + { + .fourcc =V4L2_PIX_FMT_NV21 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV12 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV21M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV12M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_YUV420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_YVU420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv444 */ + { + .fourcc =V4L2_PIX_FMT_YUV444M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv400 */ + { + .fourcc =V4L2_PIX_FMT_GREY , + .fmt_type =FMT_YUV , + .bpp = {8 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, +/* raw */ + { + .fourcc =V4L2_PIX_FMT_SRGGB8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SRGGB8 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SRGGB12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, +}; + +static const struct capture_fmt sp_fmts[] = { +/* yuv422 */ + { + .fourcc =V4L2_PIX_FMT_YUYV , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YVYU , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_VYUY , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YUV422P , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_NV16 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_NV61 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YVU422M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, +/* yuv420 */ + { + .fourcc =V4L2_PIX_FMT_NV21 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV12 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV21M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV12M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_YUV420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_YVU420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, +/* yuv444 */ + { + .fourcc =V4L2_PIX_FMT_YUV444M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV444 , + }, +/* yuv400 */ + { + .fourcc =V4L2_PIX_FMT_GREY , + .fmt_type =FMT_YUV , + .bpp = {8 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV400 , + }, +/* rgb */ + { + .fourcc =V4L2_PIX_FMT_RGB24 , + .fmt_type =FMT_RGB , + .bpp = {24 }, + .mplanes =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_RGB888 , + }, { + .fourcc =V4L2_PIX_FMT_RGB565 , + .fmt_type =FMT_RGB , + .bpp = {16 }, + .mplanes =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_RGB565 , + }, { + .fourcc =V4L2_PIX_FMT_BGR666 , + .fmt_type =FMT_RGB , + .bpp = {18 },
drivers/media/platform/rockchip/isp1/capture.c line 531
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ .mplanes = 1, + .write_format = MI_CTRL_SP_WRITE_PLA, + .output_format = MI_CTRL_SP_OUTPUT_RGB666, + }, +}; + +static struct stream_config rkisp1_mp_stream_config = { + .fmts = mp_fmts, + .fmt_size =ARRAY_SIZE (mp_fmts), + /* constrains */
constrains -> constraints
Quoted 267 lines
drivers/media/platform/rockchip/isp1/capture.c new file +267
-0+ .max_rsz_width = STREAM_MAX_MP_RSZ_OUTPUT_WIDTH, + .max_rsz_height = STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT, + .min_rsz_width = STREAM_MIN_RSZ_OUTPUT_WIDTH, + .min_rsz_height = STREAM_MIN_RSZ_OUTPUT_HEIGHT, +/* registers */ + .rsz = { + .ctrl = CIF_MRSZ_CTRL, + .scale_hy = CIF_MRSZ_SCALE_HY, + .scale_hcr = CIF_MRSZ_SCALE_HCR, + .scale_hcb = CIF_MRSZ_SCALE_HCB, + .scale_vy = CIF_MRSZ_SCALE_VY, + .scale_vc = CIF_MRSZ_SCALE_VC, + .scale_lut = CIF_MRSZ_SCALE_LUT, + .scale_lut_addr = CIF_MRSZ_SCALE_LUT_ADDR, + .scale_hy_shd = CIF_MRSZ_SCALE_HY_SHD, + .scale_hcr_shd = CIF_MRSZ_SCALE_HCR_SHD, + .scale_hcb_shd = CIF_MRSZ_SCALE_HCB_SHD, + .scale_vy_shd = CIF_MRSZ_SCALE_VY_SHD, + .scale_vc_shd = CIF_MRSZ_SCALE_VC_SHD, + .phase_hy = CIF_MRSZ_PHASE_HY, + .phase_hc = CIF_MRSZ_PHASE_HC, + .phase_vy = CIF_MRSZ_PHASE_VY, + .phase_vc = CIF_MRSZ_PHASE_VC, + .ctrl_shd = CIF_MRSZ_CTRL_SHD, + .phase_hy_shd = CIF_MRSZ_PHASE_HY_SHD, + .phase_hc_shd = CIF_MRSZ_PHASE_HC_SHD, + .phase_vy_shd = CIF_MRSZ_PHASE_VY_SHD, + .phase_vc_shd = CIF_MRSZ_PHASE_VC_SHD, + }, + .dual_crop = { + .ctrl = CIF_DUAL_CROP_CTRL, + .yuvmode_mask = CIF_DUAL_CROP_MP_MODE_YUV, + .rawmode_mask = CIF_DUAL_CROP_MP_MODE_RAW, + .h_offset = CIF_DUAL_CROP_M_H_OFFS, + .v_offset = CIF_DUAL_CROP_M_V_OFFS, + .h_size = CIF_DUAL_CROP_M_H_SIZE, + .v_size = CIF_DUAL_CROP_M_V_SIZE, + }, + .mi = { + .y_size_init = CIF_MI_MP_Y_SIZE_INIT, + .cb_size_init = CIF_MI_MP_CB_SIZE_INIT, + .cr_size_init = CIF_MI_MP_CR_SIZE_INIT, + .y_base_ad_init = CIF_MI_MP_Y_BASE_AD_INIT, + .cb_base_ad_init = CIF_MI_MP_CB_BASE_AD_INIT, + .cr_base_ad_init = CIF_MI_MP_CR_BASE_AD_INIT, + .y_offs_cnt_init = CIF_MI_MP_Y_OFFS_CNT_INIT, + .cb_offs_cnt_init = CIF_MI_MP_CB_OFFS_CNT_INIT, + .cr_offs_cnt_init = CIF_MI_MP_CR_OFFS_CNT_INIT, + }, +}; + +static struct stream_config rkisp1_sp_stream_config = { + .fmts = sp_fmts, + .fmt_size =ARRAY_SIZE (sp_fmts), +/* constrains */ + .max_rsz_width =STREAM_MAX_SP_RSZ_OUTPUT_WIDTH , + .max_rsz_height =STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT , + .min_rsz_width =STREAM_MIN_RSZ_OUTPUT_WIDTH , + .min_rsz_height =STREAM_MIN_RSZ_OUTPUT_HEIGHT , +/* registers */ + .rsz = { + .ctrl =CIF_SRSZ_CTRL , + .scale_hy =CIF_SRSZ_SCALE_HY , + .scale_hcr =CIF_SRSZ_SCALE_HCR , + .scale_hcb =CIF_SRSZ_SCALE_HCB , + .scale_vy =CIF_SRSZ_SCALE_VY , + .scale_vc =CIF_SRSZ_SCALE_VC , + .scale_lut =CIF_SRSZ_SCALE_LUT , + .scale_lut_addr =CIF_SRSZ_SCALE_LUT_ADDR , + .scale_hy_shd =CIF_SRSZ_SCALE_HY_SHD , + .scale_hcr_shd =CIF_SRSZ_SCALE_HCR_SHD , + .scale_hcb_shd =CIF_SRSZ_SCALE_HCB_SHD , + .scale_vy_shd =CIF_SRSZ_SCALE_VY_SHD , + .scale_vc_shd =CIF_SRSZ_SCALE_VC_SHD , + .phase_hy =CIF_SRSZ_PHASE_HY , + .phase_hc =CIF_SRSZ_PHASE_HC , + .phase_vy =CIF_SRSZ_PHASE_VY , + .phase_vc =CIF_SRSZ_PHASE_VC , + .ctrl_shd =CIF_SRSZ_CTRL_SHD , + .phase_hy_shd =CIF_SRSZ_PHASE_HY_SHD , + .phase_hc_shd =CIF_SRSZ_PHASE_HC_SHD , + .phase_vy_shd =CIF_SRSZ_PHASE_VY_SHD , + .phase_vc_shd =CIF_SRSZ_PHASE_VC_SHD , + }, + .dual_crop = { + .ctrl =CIF_DUAL_CROP_CTRL , + .yuvmode_mask =CIF_DUAL_CROP_SP_MODE_YUV , + .rawmode_mask =CIF_DUAL_CROP_SP_MODE_RAW , + .h_offset =CIF_DUAL_CROP_S_H_OFFS , + .v_offset =CIF_DUAL_CROP_S_V_OFFS , + .h_size =CIF_DUAL_CROP_S_H_SIZE , + .v_size =CIF_DUAL_CROP_S_V_SIZE , + }, + .mi = { + .y_size_init =CIF_MI_SP_Y_SIZE_INIT , + .cb_size_init =CIF_MI_SP_CB_SIZE_INIT , + .cr_size_init =CIF_MI_SP_CR_SIZE_INIT , + .y_base_ad_init =CIF_MI_SP_Y_BASE_AD_INIT , + .cb_base_ad_init =CIF_MI_SP_CB_BASE_AD_INIT , + .cr_base_ad_init =CIF_MI_SP_CR_BASE_AD_INIT , + .y_offs_cnt_init =CIF_MI_SP_Y_OFFS_CNT_INIT , + .cb_offs_cnt_init =CIF_MI_SP_CB_OFFS_CNT_INIT , + .cr_offs_cnt_init =CIF_MI_SP_CR_OFFS_CNT_INIT , + }, +}; + +static const +struct capture_fmt *find_fmt (struct rkisp1_stream *stream,const u32 pixelfmt) +{ +const struct capture_fmt *fmt; +int i; + +for (i =0 ; i < stream->config->fmt_size; i++) { + fmt = &stream->config->fmts[i]; +if (fmt->fourcc == pixelfmt) +return fmt; + } +return NULL ; +} + +static int rkisp1_config_dcrop (struct rkisp1_stream *stream,bool async) +{ +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); + +if (dcrop->width == input_win->width && + dcrop->height == input_win->height && + dcrop->left ==0 && dcrop->top ==0 ) { +disable_dcrop (stream, async); +return 0 ; + } + +config_dcrop (stream, dcrop, async); + +return 0 ; +} + +static int rkisp1_config_rsz (struct rkisp1_stream *stream,bool async) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_pix_format_mplane output_fmt = stream->out_fmt; +struct capture_fmt *output_isp_fmt = &stream->out_isp_fmt; +struct ispsd_out_fmt *input_isp_fmt =rkisp1_get_ispsd_out_fmt (dev); +struct v4l2_rect in_y, in_c, out_y, out_c; +u32 xsubs_in, ysubs_in, xsubs_out, ysubs_out; + +if (input_isp_fmt->fmt_type ==FMT_BAYER ) + goto disable; + +/* set input and output sizes for scale calculation */ + in_y.width = stream->dcrop.width; + in_y.height = stream->dcrop.height; + out_y.width = output_fmt.width; + out_y.height = output_fmt.height; + +if (mbus_code_xysubs (input_isp_fmt->mbus_code, &xsubs_in, &ysubs_in)) { +v4l2_err (&dev->v4l2_dev,"Not xsubs/ysubs found\n" ); +return -EINVAL ; + } + in_c.width = in_y.width / xsubs_in; + in_c.height = in_y.height / ysubs_in; + +if (output_isp_fmt->fmt_type ==FMT_YUV ) { +fcc_xysubs (output_isp_fmt->fourcc, &xsubs_out, &ysubs_out); + out_c.width = out_y.width / xsubs_out; + out_c.height = out_y.height / ysubs_out; + }else { + out_c.width = out_y.width / xsubs_in; + out_c.height = out_y.height / ysubs_in; + } + +if (in_c.width == out_c.width && in_c.height == out_c.height) + goto disable; + +/* set RSZ input and output */ +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream: %d fmt: %08x %dx%d -> fmt: %08x %dx%d\n" , + stream->id, input_isp_fmt->mbus_code, + stream->dcrop.width, stream->dcrop.height, + output_isp_fmt->fourcc, output_fmt.width, + output_fmt.height); +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"chroma scaling %dx%d -> %dx%d\n" , + in_c.width, in_c.height, out_c.width, out_c.height); + +/* calculate and set scale */ +config_rsz (stream, &in_y, &in_c, &out_y, &out_c, async); + +if (rkisp1_debug) +dump_rsz_regs (stream); + +return 0 ; + +disable: +disable_rsz (stream, async); + +return 0 ; +} + +/***************************** stream operations*******************************/ +static int mp_config_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +/* +* plane_fmt[0].sizeimage is total size of all planes for single +* memory plane formats, so calculate the size explicitly. +*/ +mi_set_y_size (stream, stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height); +mi_set_cb_size (stream, stream->out_fmt.plane_fmt[1 ].sizeimage); +mi_set_cr_size (stream, stream->out_fmt.plane_fmt[2 ].sizeimage); + +mp_frame_end_int_enable (base); +if (stream->out_isp_fmt.uv_swap) +mp_set_uv_swap (base); + +config_mi_ctrl (stream); +mp_mi_ctrl_set_format (base, stream->out_isp_fmt.write_format); +mp_mi_ctrl_autoupdate_en (base); + +return 0 ; +} + +static int sp_config_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +struct rkisp1_device *dev = stream->ispdev; +struct capture_fmt *output_isp_fmt = &stream->out_isp_fmt; +struct ispsd_out_fmt *input_isp_fmt =rkisp1_get_ispsd_out_fmt (dev); +u32 sp_in_fmt; + +if (mbus_code_sp_in_fmt (input_isp_fmt->mbus_code, &sp_in_fmt)) { +v4l2_err (&dev->v4l2_dev,"Can't find the input format\n" ); +return -EINVAL ; + } +mi_set_y_size (stream, stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height); +mi_set_cb_size (stream, stream->out_fmt.plane_fmt[1 ].sizeimage); +mi_set_cr_size (stream, stream->out_fmt.plane_fmt[2 ].sizeimage); + +sp_set_y_width (base, stream->out_fmt.width); +sp_set_y_height (base, stream->out_fmt.height); +sp_set_y_line_length (base, stream->u.sp.y_stride); + +sp_frame_end_int_enable (base); +if (output_isp_fmt->uv_swap) +sp_set_uv_swap (base); + +config_mi_ctrl (stream); +sp_mi_ctrl_set_format (base, stream->out_isp_fmt.write_format | + sp_in_fmt | output_isp_fmt->output_format); + +sp_mi_ctrl_autoupdate_en (base); + +return 0 ; +} + +static struct rkisp1_stream *get_other_stream (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; + +return &dev->stream[stream->id ^1 ]; +}
drivers/media/platform/rockchip/isp1/capture.c line 808
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ +static int mp_check_against (struct rkisp1_stream *stream) +{ +struct rkisp1_stream *sp =get_other_stream (stream); + +if (sp->state ==RKISP1_STATE_STREAMING ) +return -EAGAIN ; + +return 0 ; +}
Hmm, can you add some comments before these functions? I noticed very few comments in this driver, and it really could use some. E.g. 'mp_check_against': it's not clear what it checks against. And what's _mi in sp_config_mi?
I know, adding comments is a bit of a chore, but this driver really could use some more of that.
Quoted 227 lines
drivers/media/platform/rockchip/isp1/capture.c new file +227
-0+ +static int sp_check_against (struct rkisp1_stream *stream) +{ +struct rkisp1_stream *mp =get_other_stream (stream); +struct v4l2_device *v4l2_dev = &stream->ispdev->v4l2_dev; + +if (mp->u.mp.raw_enable && mp->state ==RKISP1_STATE_STREAMING ) { +v4l2_err (v4l2_dev,"can't start SP path when MP RAW active\n" ); +return -EBUSY ; + } + +if (mp->state ==RKISP1_STATE_STREAMING ) +return -EAGAIN ; + +return 0 ; +} + +static void mp_enable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; + +mi_ctrl_mp_disable (base); +if (isp_fmt->fmt_type ==FMT_BAYER ) +mi_ctrl_mpraw_enable (base); +else if (isp_fmt->fmt_type ==FMT_YUV ) +mi_ctrl_mpyuv_enable (base); +} + +static void sp_enable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_spyuv_enable (base); +} + +static void mp_disable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_mp_disable (base); +} + +static void sp_disable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_spyuv_disable (base); +} + +static void update_mi (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; + +if (stream->next_buf) { +mi_set_y_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_Y ]); +mi_set_cb_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_CB ]); +mi_set_cr_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_CR ]); + }else { +/* Throw data to dummy space */ +mi_set_y_addr (stream, dummy_buf->dma_addr); +mi_set_cb_addr (stream, dummy_buf->dma_addr); +mi_set_cr_addr (stream, dummy_buf->dma_addr); + } + +mi_set_y_offset (stream,0 ); +mi_set_cb_offset (stream,0 ); +mi_set_cr_offset (stream,0 ); +} + +static void mp_stop_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +if (stream->state !=RKISP1_STATE_STREAMING ) +return ; +/*mp_frame_end_int_disable(base);*/ + stream->ops->clr_frame_end_int (base); + stream->ops->disable_mi (stream); +} + +static void sp_stop_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +if (stream->state !=RKISP1_STATE_STREAMING ) +return ; +/*sp_frame_end_int_disable(base);*/ + stream->ops->clr_frame_end_int (base); + stream->ops->disable_mi (stream); +} + +static struct streams_ops rkisp1_mp_streams_ops = { + .check_against = mp_check_against, + .config_mi = mp_config_mi, + .enable_mi = mp_enable_mi, + .disable_mi = mp_disable_mi, + .stop_mi = mp_stop_mi, + .set_data_path = mp_set_data_path, + .clr_frame_end_int = mp_clr_frame_end_int, + .is_frame_end_int_masked = mp_is_frame_end_int_masked, +}; + +static struct streams_ops rkisp1_sp_streams_ops = { + .check_against = sp_check_against, + .config_mi = sp_config_mi, + .enable_mi = sp_enable_mi, + .disable_mi = sp_disable_mi, + .stop_mi = sp_stop_mi, + .set_data_path = sp_set_data_path, + .clr_frame_end_int = sp_clr_frame_end_int, + .is_frame_end_int_masked = sp_is_frame_end_int_masked, +}; + +static void rkisp1_stream_stop (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +int ret =0 ; + + stream->stop = true; + ret =wait_event_timeout (stream->done, + stream->state !=RKISP1_STATE_STREAMING , +msecs_to_jiffies (1000 )); +if (!ret) { +v4l2_warn (v4l2_dev,"waiting on event return error %d\n" , ret); + stream->ops->stop_mi (stream); + stream->stop = false; + stream->state =RKISP1_STATE_READY ; + } +disable_dcrop (stream, true); +disable_rsz (stream, true); +} + +static int mi_frame_end (struct rkisp1_stream *stream) +{ +struct rkisp1_isp_subdev *isp_sd = &stream->ispdev->isp_sdev; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +unsigned long lock_flags =0 ; +int i =0 ; + +if (stream->curr_buf) { +/* Dequeue a filled buffer */ +for (i =0 ; i < isp_fmt->mplanes; i++) { +u32 payload_size = + stream->out_fmt.plane_fmt[i].sizeimage; +vb2_set_plane_payload ( + &stream->curr_buf->vb.vb2_buf, i, + payload_size); + } + stream->curr_buf->vb.sequence = +atomic_read (&isp_sd->frm_sync_seq) -1 ; + stream->curr_buf->vb.vb2_buf.timestamp =ktime_get_ns (); +vb2_buffer_done (&stream->curr_buf->vb.vb2_buf, +VB2_BUF_STATE_DONE ); + } + +/* Next frame is writing to it */ + stream->curr_buf = stream->next_buf; + stream->next_buf =NULL ; + +/* Set up an empty buffer for the next-next frame */ +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +if (!list_empty (&stream->buf_queue)) { + stream->next_buf =list_first_entry (&stream->buf_queue, + struct rkisp1_buffer, queue); +list_del (&stream->next_buf->queue); + } + +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); + +update_mi (stream); + +return 0 ; +} + +/* +* Videobuf2 operations. +*/ +static int rkisp1_start (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +int ret; + + stream->ops->set_data_path (base); + ret = stream->ops->config_mi (stream); +if (ret) +return ret; + +/* Set up an buffer for the next frame */ +mi_frame_end (stream); +/* Update shadow register */ +force_cfg_update (base); +/* Set up an buffer for the next-next frame */ +mi_frame_end (stream); + + stream->ops->enable_mi (stream); + stream->state =RKISP1_STATE_STREAMING ; + +return 0 ; +} + +static int rkisp1_restart (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +int ret; + +rkisp1_stream_stop (stream); + + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ret; + + ret =rkisp1_start (stream); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int rkisp1_queue_setup(struct vb2_queue *queue, + unsigned int *num_buffers, + unsigned int *num_planes, + unsigned int sizes[],
drivers/media/platform/rockchip/isp1/capture.c line 1045
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ struct device *alloc_devs[]) +{ +struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_device *isp_dev = stream->ispdev; +const struct v4l2_pix_format_mplane *pixm = &stream->out_fmt; +const struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +u32 i; + + *num_buffers =clamp_t (u32, *num_buffers,CIF_ISP_REQ_BUFS_MIN , +CIF_ISP_REQ_BUFS_MAX );
Since min_buffers_needed is set to CIF_ISP_REQ_BUFS_MIN, then you don't need to check against CIF_ISP_REQ_BUFS_MIN again.
drivers/media/platform/rockchip/isp1/capture.c line 1054
Quoted 9 lines
drivers/media/platform/rockchip/isp1/capture.c new file +9
-0+ *num_planes = isp_fmt->mplanes; + +for (i =0 ; i < isp_fmt->mplanes; i++) { +const struct v4l2_plane_pix_format *plane_fmt; + + plane_fmt = &pixm->plane_fmt[i]; + + sizes[i] = plane_fmt->sizeimage; + alloc_devs[i] = isp_dev->dev;
You don't need this. Just set queue->dev to isp_dev->dev when initializing the queue.
alloc_devs[] is only needed if the device would differ per-plane (seen in weird Samsung exynos hardware).
Quoted 194 lines
drivers/media/platform/rockchip/isp1/capture.c new file +194
-0+ } + +v4l2_dbg (1 , rkisp1_debug, &isp_dev->v4l2_dev,"%s count %d, size %d\n" , + v4l2_type_names[queue->type], *num_buffers, sizes[0 ]); + +return 0 ; +} + +static void rkisp1_buf_queue (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct rkisp1_buffer *ispbuf =to_rkisp1_buffer (vbuf); +struct vb2_queue *queue = vb->vb2_queue; +struct rkisp1_stream *stream = queue->drv_priv; +unsigned long lock_flags =0 ; +struct v4l2_pix_format_mplane *pixm = &stream->out_fmt; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +int i; + +memset (ispbuf->buff_addr,0 ,sizeof (ispbuf->buff_addr)); +for (i =0 ; i < isp_fmt->mplanes; i++) + ispbuf->buff_addr[i] =vb2_dma_contig_plane_dma_addr (vb, i); + +if (isp_fmt->mplanes ==1 ) { +for (i =0 ; i < isp_fmt->cplanes -1 ; i++) { + ispbuf->buff_addr[i +1 ] = + ispbuf->buff_addr[i] + + pixm->plane_fmt[i].bytesperline * + pixm->height; + } + } + +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +list_add_tail (&ispbuf->queue, &stream->buf_queue); +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); +} + +static int rkisp1_create_dummy_buf (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; +struct rkisp1_device *dev = stream->ispdev; + +/* get a minimum size */ + dummy_buf->size =max3 (stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height, + stream->out_fmt.plane_fmt[1 ].sizeimage, + stream->out_fmt.plane_fmt[2 ].sizeimage); + + dummy_buf->vaddr =dma_alloc_coherent (dev->dev, dummy_buf->size, + &dummy_buf->dma_addr, +GFP_KERNEL ); +if (!dummy_buf->vaddr) { +v4l2_err (&dev->v4l2_dev, +"Failed to allocate the memory for dummy buffer\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +static void rkisp1_destory_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; +LIST_HEAD (queued_buffers); + +rkisp1_stream_stop (stream); + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ; + + stream->state =RKISP1_STATE_READY ; + +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, + 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 ; + } + +media_pipeline_stop (&node->vdev.entity); + +rkisp1_destory_dummy_buf (stream); +} + +static int +rkisp1_start_streaming (struct vb2_queue *queue,unsigned int count) +{ +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; + + ret =rkisp1_create_dummy_buf (stream); +if (ret <0 ) +return ret; + + 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 err; + } + + 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 err; + } + +if (stream->state !=RKISP1_STATE_READY ) { +v4l2_err (v4l2_dev,"stream not enabled\n" ); + ret = -EBUSY ; + goto err; + } + + ret = stream->ops->check_against (stream); +if (ret == -EAGAIN ) { +struct rkisp1_stream *other; + + other =get_other_stream (stream); +if (other) +rkisp1_restart (other); + }else if (ret == -EBUSY ) { + goto err; + } + + ret =rkisp1_start (stream); +if (ret <0 ) + goto err; + + ret =rkisp1_config_rsz (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"failed with error %d\n" , ret); + goto err; + } + + ret =rkisp1_config_dcrop (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"failed with error %d\n" , ret); + goto err; + } + +/* pipeline stream on */ + ret = dev->pipe.set_stream (&dev->pipe, true); +if (ret <0 ) + goto err; +return 0 ; + +err: +rkisp1_destory_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, +}; +
drivers/media/platform/rockchip/isp1/capture.c line 1258
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+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_USERPTR |VB2_DMABUF ;
Don't use VB2_USERPTR unless there is an iommu that would allow you to use a malloc()ed buffer. Usually that's not the case for dma-contig streaming. Either because there is no iommu, or because there are alignment requirements (e.g. start at the page boundary) that do not fit a malloc()ed buffer.
Quoted 271 lines
drivers/media/platform/rockchip/isp1/capture.c new file +271
-0+ 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; + +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; +unsigned int imagsize =0 ; +unsigned int planes; +u32 xsubs =1 , ysubs =1 ; +int i; + + fmt =find_fmt (stream, pixm->pixelformat); +if (!fmt) + fmt = stream->config->fmts; + +/* do checks on resolution */ + pixm->width =clamp_t (u32, pixm->width, + stream->config->min_rsz_width, + stream->config->max_rsz_width); + pixm->height =clamp_t (u32, pixm->height, + stream->config->min_rsz_height, + stream->config->max_rsz_height); + pixm->num_planes = fmt->mplanes; + pixm->colorspace =rkisp1_get_colorspace (fmt->fmt_type); + pixm->field =V4L2_FIELD_NONE ; +/* TODO: quantization */ + pixm->quantization =0 ; + +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 */ +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_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, +}; + +/* +* 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 ; + +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); + +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 ; +case V4L2_SEL_TGT_COMPOSE_BOUNDS : + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +case V4L2_SEL_TGT_COMPOSE : +/* The composing rectangles always have the same size */ + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +default : +return -EINVAL ; + } + +return 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; +struct v4l2_rect *input_win; + + input_win =rkisp1_get_isp_sd_win (dev); + +if (sel->target !=V4L2_SEL_TGT_CROP && + sel->target !=V4L2_SEL_TGT_COMPOSE ) +return -EINVAL ; + +if (sel->flags !=0 ) +return -EINVAL ; + +if (sel->target ==V4L2_SEL_TGT_CROP ) { + sel->r.left =ALIGN (sel->r.left,2 ); + sel->r.width =ALIGN (sel->r.width,2 ); + + sel->r.left = +clamp_t (u32, sel->r.left,0 , + input_win->width -STREAM_MIN_MP_SP_INPUT_WIDTH ); + sel->r.top = +clamp_t (u32, sel->r.top,0 , + input_win->height -STREAM_MIN_MP_SP_INPUT_HEIGHT ); + sel->r.width = +clamp_t (u32, sel->r.width, +STREAM_MIN_MP_SP_INPUT_WIDTH , + input_win->width - sel->r.left); + sel->r.height = +clamp_t (u32, sel->r.height, +STREAM_MIN_MP_SP_INPUT_HEIGHT , + input_win->height - sel->r.top); + +/* check whether input fmt is raw */ + if (stream->id == RKISP1_STREAM_MP &&
drivers/media/platform/rockchip/isp1/capture.c line 1539
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ stream->out_isp_fmt.fmt_type == FMT_BAYER) { + sel->r.left =0 ; + sel->r.top =0 ; + sel->r.width = input_win->width; + sel->r.height = input_win->height; + } + + *dcrop = sel->r; + }else if (sel->target ==V4L2_SEL_TGT_COMPOSE ) { +/* CamHal compatibility */
Huh? If you don't support compose, then this shouldn't be indicated. When you say "CamHal compatibility" then I assume you refer to a Rockchip Android Camera HAL implementation? I think it should be fixed there instead of adding a hack here.
Quoted 20 lines
drivers/media/platform/rockchip/isp1/capture.c new file +20
-0+ sel->r.left =0 ; + sel->r.top =0 ; + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.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)); +
drivers/media/platform/rockchip/isp1/capture.c line 1569
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+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_preparebuf is missing.
Quoted 473 lines
drivers/media/platform/rockchip/isp1/capture.c new file +122
-0+ .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; +} + +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); + val = stream->ops->is_frame_end_int_masked (base); +if (val) { + val =mi_get_masked_int_status (base); +v4l2_err (&dev->v4l2_dev,"icr err: 0x%x\n" , val); + } + +mi_frame_end (stream); + +if (stream->stop) { + stream->ops->stop_mi (stream); + stream->stop = false; + stream->state =RKISP1_STATE_READY ; +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream %d stopped\n" , stream->id); +wake_up (&stream->done); + } +}drivers/media/platform/rockchip/isp1/capture.h new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 + +struct rkisp1_device ; +struct rkisp1_stream ; + +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 +293
-0@@ -0,0 +1,330 @@ +/* +* 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 <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 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_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 + +#define RKISP1_PIPELINE_MAX 4 + +enum rkisp1_sd_type { +RKISP1_SD_SENSOR , +RKISP1_SD_PHY_CSI , +RKISP1_SD_VCM , +RKISP1_SD_FLASH , +RKISP1_SD_MAX , +}; + +struct rkisp1_pipeline ; + +/* +* struct rkisp1_pipeline - An ISP hardware pipeline +* @entities: Bitmask of entities in the pipeline (indexed by entity ID) +*/ +struct rkisp1_pipeline { +struct media_pipeline pipe; +int num_subdevs; +struct v4l2_subdev *subdevs[RKISP1_PIPELINE_MAX ]; +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); +}; + +/* 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 , +}; + +struct ispsd_in_fmt { +u32 mbus_code; +u8 fmt_type; +u32 mipi_dt; +u32 yuv_seq; +enum rkisp1_fmt_raw_pat_type bayer_pat; +u8 bus_width; +}; + +struct ispsd_out_fmt { +u32 mbus_code; +u8 fmt_type; +}; + +/* +* @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_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; +}; + +enum rkisp1_sp_inp { +RKISP1_SP_INP_ISP , +RKISP1_SP_INP_DMA_SP , +RKISP1_SP_INP_MAX +}; + +struct rkisp1_device ; +struct rkisp1_stream ; + +struct rkisp1_stream_sp { +int y_stride; +enum rkisp1_sp_inp input_sel; +}; + +struct rkisp1_stream_mp { +bool raw_enable; +}; + +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; +}; + +struct streams_ops { +int (*check_against)(struct rkisp1_stream *stream); +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); +u32 (*is_frame_end_int_masked)(void __iomem *base); +}; + +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 for videobuf queues */ +spinlock_t vbq_lock; +/* mi config */ +struct list_head buf_queue; +struct rkisp1_dummy_buffer dummy_buf; +struct rkisp1_buffer *curr_buf; +struct rkisp1_buffer *next_buf; +bool stop; +wait_queue_head_t done; +union { +struct rkisp1_stream_sp sp; +struct rkisp1_stream_mp mp; + } u; +}; + +extern int rkisp1_debug; + +static inline u32 rkisp1_get_colorspace (u32 fmt_type) +{
drivers/media/platform/rockchip/isp1/common.h line 303
Quoted 10 lines
drivers/media/platform/rockchip/isp1/common.h new file +10
-0+switch (fmt_type) { +case FMT_BAYER : +return V4L2_COLORSPACE_SRGB ; +case FMT_YUV : +case FMT_JPEG : +return V4L2_COLORSPACE_JPEG ; +case FMT_RGB : +return V4L2_COLORSPACE_RAW ; +default : +return V4L2_COLORSPACE_DEFAULT ;
This is wrong. The colorspace needs to come from the source subdevice. You can't set it here, the ISP won't know it. Instead read it from the media bus format.
Quoted 2,140 lines
drivers/media/platform/rockchip/isp1/common.h new file +27
-0+ } +} + +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 +632
-0@@ -0,0 +1,632 @@ +/* +* 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 "regs.h" +#include "rkisp1.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)" ); + +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 *use_count; +int ret; + +v4l2_info (sd,"%d: name %s,on %d\n" , __LINE__, sd->name, on); + +if (!sd) +return -ENXIO ; + + use_count = &sd->entity.use_count; +if (on && (*use_count)++ >0 ) +return 0 ; +else if (!on && (*use_count ==0 || --(*use_count) >0 )) +return 0 ; + 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 (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; + + ret =__isp_pipeline_s_power (p,0 ); + +return ret == -ENXIO ?0 : ret; +} + +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) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, true); + +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; +} + +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; + +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); +} + +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]; + + mis_val = stream->ops->is_frame_end_int_masked (base); +if (mis_val) +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); +atomic_set (&isp_dev->poweron_cnt,0 ); + 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; + + 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)); + + 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/isp_params.c new file +1469
-0@@ -0,0 +1,1556 @@ +/* +* 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 "regs.h" +#include "rkisp1.h" +#include "isp_params.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) + +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, +CIF_ISP_DPCC_LINE_THRESH_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_mad_fac, +CIF_ISP_DPCC_LINE_MAD_FAC_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].pg_fac, +CIF_ISP_DPCC_PG_FAC_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rnd_thresh, +CIF_ISP_DPCC_RND_THRESH_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rg_fac, +CIF_ISP_DPCC_RG_FAC_1 +0x14 * 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 ; +rkisp1_iowrite32 (params_vdev, new_control,CIF_ISP_BLS_CTRL ); + }else { +if (arg->en_windows &2 ) { +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 &1 ) { +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(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 271
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+ 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 );
Either add VB2_DMABUF or remove expbuf from the ioctl ops. I would just add VB2_DMABUF. It doesn't cost anything.
drivers/media/platform/rockchip/isp1/isp_stats.c
Quoted 382 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 +81
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.c new file +212
-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 remove vidioc_expbuf from the ioctl ops.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 2,946 lines
drivers/media/platform/rockchip/isp1/isp_stats.c new file +325
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.h new file +81
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.c new file +251
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.h new file +1578
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.c new file +687
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Just propagate the colorspace information from the incoming mediabus format. You can't guess it based on the mbus_code.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 14 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +14
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Ditto.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 96 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +96
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Just checking: the hardware can crop both on the sink (incoming) side and on the source (outgoing) side? I would expect it to be just on the sink side.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 84 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +84
-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 need g_mbus_config for? We have plans to remove this op in the future.
drivers/media/platform/rockchip/isp1/rkisp1.h
Quoted 486 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +349
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.h new file +130
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Regards,
Hans
Part of the diff is not shown here. View the raw message.
Re: [PATCH v2 03/11] media: rkisp1: add rockchip isp1 driver
.Hi Hans,
2017-11-27 19:40 GMT+08:00 Hans Verkuil <[email protected]>:
Quoted 1,677 lines
Hi Jacob,
Thank you for this driver! Much appreciated.
I have a bunch of comments below, nothing big, really. The main thing is that you really need to sprinkle some more comments in the source code.
Quoted 142 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 | 1691 +++++++++++++++++++++ drivers/media/platform/rockchip/isp1/capture.h | 46 + drivers/media/platform/rockchip/isp1/common.h | 330 ++++ drivers/media/platform/rockchip/isp1/dev.c | 632 ++++++++ drivers/media/platform/rockchip/isp1/isp_params.c | 1556 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/isp_params.h | 81 + drivers/media/platform/rockchip/isp1/isp_stats.c | 537 +++++++ drivers/media/platform/rockchip/isp1/isp_stats.h | 81 + drivers/media/platform/rockchip/isp1/regs.c | 251 +++ drivers/media/platform/rockchip/isp1/regs.h | 1578 +++++++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.c | 1230 +++++++++++++++ drivers/media/platform/rockchip/isp1/rkisp1.h | 130 ++ 15 files changed, 8161 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/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 +47
-0@@ -0,0 +1,1691 @@ +/* +* 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/delay.h> +#include <linux/pm_runtime.h> +#include <media/v4l2-common.h> +#include <media/v4l2-event.h> +#include <media/v4l2-fh.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-subdev.h> +#include <media/videobuf2-dma-contig.h> +#include "capture.h" +#include "rkisp1.h" +#include "regs.h" + +#define CIF_ISP_REQ_BUFS_MIN 1drivers/media/platform/rockchip/isp1/capture.c line 57
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+#define CIF_ISP_REQ_BUFS_MAX 8 + +/* +* mp sink source: isp +* sp sink source : isp, no dma now +* mp sink pad fmts: yuv 422, raw +* sp sink pad fmts: yuv422( source isp), yuv420...... +* mp source fmts: yuv, raw, no jpeg now +* sp source fmts: yuv, rgb +*/ Is this a left-over comment as a reminder to yourself? If so, remove it, if not, then it needs to be expanded since it's not clear what the purpose of this comment is.
Quoted 15 lines
drivers/media/platform/rockchip/isp1/capture.c new file +15
-0+ +#define STREAM_PAD_SINK 0 +#define STREAM_PAD_SOURCE 1 + +#define STREAM_MAX_MP_RSZ_OUTPUT_WIDTH 4416 +#define STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT 3312 +#define STREAM_MAX_SP_RSZ_OUTPUT_WIDTH 1920 +#define STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT 1080 +#define STREAM_MIN_RSZ_OUTPUT_WIDTH 32 +#define STREAM_MIN_RSZ_OUTPUT_HEIGHT 16 + +#define STREAM_MAX_MP_SP_INPUT_WIDTH STREAM_MAX_MP_RSZ_OUTPUT_WIDTH +#define STREAM_MAX_MP_SP_INPUT_HEIGHT STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT +#define STREAM_MIN_MP_SP_INPUT_WIDTH 32 +#define STREAM_MIN_MP_SP_INPUT_HEIGHT 32drivers/media/platform/rockchip/isp1/capture.c line 82
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ +/* +* crop accepts only yuv422 format +* resizer can accept yuv444,yuv422,yuv420 format, can output yuv422, yuv420, +* yuv444 format +* sp resizer has two data source: DMA-reader or crop +* mp resizer has only one data source: crop +* if format is unsupported by path, crop and resizer should be bypassed +* (disabled) +*/ Same for this comment.
drivers/media/platform/rockchip/isp1/capture.c line 86
Quoted 4 lines
drivers/media/platform/rockchip/isp1/capture.c new file +4
-0+ +/* Get xsubs and ysubs for fourcc formats +* +* @xsubs: horizon color samples in a 4*4 matrix, for yuv horizon -> horizontal
Quoted 435 lines
drivers/media/platform/rockchip/isp1/capture.c new file +435
-0+* @ysubs: vertical color samples in a 4*4 matrix, for yuv +*/ +static int fcc_xysubs (u32 fcc,u32 *xsubs,u32 *ysubs) +{ +switch (fcc) { +case V4L2_PIX_FMT_GREY : +case V4L2_PIX_FMT_YUV444M : + *xsubs =1 ; + *ysubs =1 ; +break ; +case V4L2_PIX_FMT_YUYV : +case V4L2_PIX_FMT_YVYU : +case V4L2_PIX_FMT_VYUY : +case V4L2_PIX_FMT_YUV422P : +case V4L2_PIX_FMT_NV16 : +case V4L2_PIX_FMT_NV61 : +case V4L2_PIX_FMT_YVU422M : + *xsubs =2 ; + *ysubs =1 ; +break ; +case V4L2_PIX_FMT_NV21 : +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21M : +case V4L2_PIX_FMT_NV12M : +case V4L2_PIX_FMT_YUV420 : +case V4L2_PIX_FMT_YVU420 : + *xsubs =2 ; + *ysubs =2 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int mbus_code_xysubs (u32 code,u32 *xsubs,u32 *ysubs) +{ +switch (code) { +case MEDIA_BUS_FMT_YUYV8_2X8 : +case MEDIA_BUS_FMT_YUYV8_1X16 : +case MEDIA_BUS_FMT_YVYU8_1X16 : +case MEDIA_BUS_FMT_UYVY8_1X16 : +case MEDIA_BUS_FMT_VYUY8_1X16 : + *xsubs =2 ; + *ysubs =1 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int mbus_code_sp_in_fmt (u32 code,u32 *format) +{ +switch (code) { +case MEDIA_BUS_FMT_YUYV8_2X8 : + *format =MI_CTRL_SP_INPUT_YUV422 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static const struct capture_fmt mp_fmts[] = { +/* yuv422 */ + { + .fourcc =V4L2_PIX_FMT_YUYV , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_YVYU , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_VYUY , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, { + .fourcc =V4L2_PIX_FMT_YUV422P , + .fmt_type =FMT_YUV , + .bpp = {8 ,4 ,4 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_NV16 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV61 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_YVU422M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv420 */ + { + .fourcc =V4L2_PIX_FMT_NV21 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV12 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV21M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_NV12M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_SPLA , + }, { + .fourcc =V4L2_PIX_FMT_YUV420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_YVU420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv444 */ + { + .fourcc =V4L2_PIX_FMT_YUV444M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, +/* yuv400 */ + { + .fourcc =V4L2_PIX_FMT_GREY , + .fmt_type =FMT_YUV , + .bpp = {8 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_MP_WRITE_YUVINT , + }, +/* raw */ + { + .fourcc =V4L2_PIX_FMT_SRGGB8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR8 , + .fmt_type =FMT_BAYER , + .bpp = {8 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_YUV_PLA_OR_RAW8 , + }, { + .fourcc =V4L2_PIX_FMT_SRGGB8 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR10 , + .fmt_type =FMT_BAYER , + .bpp = {10 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SRGGB12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGRBG12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SGBRG12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, { + .fourcc =V4L2_PIX_FMT_SBGGR12 , + .fmt_type =FMT_BAYER , + .bpp = {12 }, + .mplanes =1 , + .write_format =MI_CTRL_MP_WRITE_RAW12 , + }, +}; + +static const struct capture_fmt sp_fmts[] = { +/* yuv422 */ + { + .fourcc =V4L2_PIX_FMT_YUYV , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YVYU , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_VYUY , + .fmt_type =FMT_YUV , + .bpp = {16 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YUV422P , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_NV16 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_NV61 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, { + .fourcc =V4L2_PIX_FMT_YVU422M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV422 , + }, +/* yuv420 */ + { + .fourcc =V4L2_PIX_FMT_NV21 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV12 , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV21M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_NV12M , + .fmt_type =FMT_YUV , + .bpp = {8 ,16 }, + .cplanes =2 , + .mplanes =2 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_SPLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_YUV420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, { + .fourcc =V4L2_PIX_FMT_YVU420 , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =1 , + .uv_swap =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV420 , + }, +/* yuv444 */ + { + .fourcc =V4L2_PIX_FMT_YUV444M , + .fmt_type =FMT_YUV , + .bpp = {8 ,8 ,8 }, + .cplanes =3 , + .mplanes =3 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_YUV444 , + }, +/* yuv400 */ + { + .fourcc =V4L2_PIX_FMT_GREY , + .fmt_type =FMT_YUV , + .bpp = {8 }, + .cplanes =1 , + .mplanes =1 , + .uv_swap =0 , + .write_format =MI_CTRL_SP_WRITE_INT , + .output_format =MI_CTRL_SP_OUTPUT_YUV400 , + }, +/* rgb */ + { + .fourcc =V4L2_PIX_FMT_RGB24 , + .fmt_type =FMT_RGB , + .bpp = {24 }, + .mplanes =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_RGB888 , + }, { + .fourcc =V4L2_PIX_FMT_RGB565 , + .fmt_type =FMT_RGB , + .bpp = {16 }, + .mplanes =1 , + .write_format =MI_CTRL_SP_WRITE_PLA , + .output_format =MI_CTRL_SP_OUTPUT_RGB565 , + }, { + .fourcc =V4L2_PIX_FMT_BGR666 , + .fmt_type =FMT_RGB , + .bpp = {18 },drivers/media/platform/rockchip/isp1/capture.c line 531
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ .mplanes = 1, + .write_format = MI_CTRL_SP_WRITE_PLA, + .output_format = MI_CTRL_SP_OUTPUT_RGB666, + }, +}; + +static struct stream_config rkisp1_mp_stream_config = { + .fmts = mp_fmts, + .fmt_size =ARRAY_SIZE (mp_fmts), + /* constrains */constrains -> constraints
Quoted 267 lines
drivers/media/platform/rockchip/isp1/capture.c new file +267
-0+ .max_rsz_width = STREAM_MAX_MP_RSZ_OUTPUT_WIDTH, + .max_rsz_height = STREAM_MAX_MP_RSZ_OUTPUT_HEIGHT, + .min_rsz_width = STREAM_MIN_RSZ_OUTPUT_WIDTH, + .min_rsz_height = STREAM_MIN_RSZ_OUTPUT_HEIGHT, +/* registers */ + .rsz = { + .ctrl = CIF_MRSZ_CTRL, + .scale_hy = CIF_MRSZ_SCALE_HY, + .scale_hcr = CIF_MRSZ_SCALE_HCR, + .scale_hcb = CIF_MRSZ_SCALE_HCB, + .scale_vy = CIF_MRSZ_SCALE_VY, + .scale_vc = CIF_MRSZ_SCALE_VC, + .scale_lut = CIF_MRSZ_SCALE_LUT, + .scale_lut_addr = CIF_MRSZ_SCALE_LUT_ADDR, + .scale_hy_shd = CIF_MRSZ_SCALE_HY_SHD, + .scale_hcr_shd = CIF_MRSZ_SCALE_HCR_SHD, + .scale_hcb_shd = CIF_MRSZ_SCALE_HCB_SHD, + .scale_vy_shd = CIF_MRSZ_SCALE_VY_SHD, + .scale_vc_shd = CIF_MRSZ_SCALE_VC_SHD, + .phase_hy = CIF_MRSZ_PHASE_HY, + .phase_hc = CIF_MRSZ_PHASE_HC, + .phase_vy = CIF_MRSZ_PHASE_VY, + .phase_vc = CIF_MRSZ_PHASE_VC, + .ctrl_shd = CIF_MRSZ_CTRL_SHD, + .phase_hy_shd = CIF_MRSZ_PHASE_HY_SHD, + .phase_hc_shd = CIF_MRSZ_PHASE_HC_SHD, + .phase_vy_shd = CIF_MRSZ_PHASE_VY_SHD, + .phase_vc_shd = CIF_MRSZ_PHASE_VC_SHD, + }, + .dual_crop = { + .ctrl = CIF_DUAL_CROP_CTRL, + .yuvmode_mask = CIF_DUAL_CROP_MP_MODE_YUV, + .rawmode_mask = CIF_DUAL_CROP_MP_MODE_RAW, + .h_offset = CIF_DUAL_CROP_M_H_OFFS, + .v_offset = CIF_DUAL_CROP_M_V_OFFS, + .h_size = CIF_DUAL_CROP_M_H_SIZE, + .v_size = CIF_DUAL_CROP_M_V_SIZE, + }, + .mi = { + .y_size_init = CIF_MI_MP_Y_SIZE_INIT, + .cb_size_init = CIF_MI_MP_CB_SIZE_INIT, + .cr_size_init = CIF_MI_MP_CR_SIZE_INIT, + .y_base_ad_init = CIF_MI_MP_Y_BASE_AD_INIT, + .cb_base_ad_init = CIF_MI_MP_CB_BASE_AD_INIT, + .cr_base_ad_init = CIF_MI_MP_CR_BASE_AD_INIT, + .y_offs_cnt_init = CIF_MI_MP_Y_OFFS_CNT_INIT, + .cb_offs_cnt_init = CIF_MI_MP_CB_OFFS_CNT_INIT, + .cr_offs_cnt_init = CIF_MI_MP_CR_OFFS_CNT_INIT, + }, +}; + +static struct stream_config rkisp1_sp_stream_config = { + .fmts = sp_fmts, + .fmt_size =ARRAY_SIZE (sp_fmts), +/* constrains */ + .max_rsz_width =STREAM_MAX_SP_RSZ_OUTPUT_WIDTH , + .max_rsz_height =STREAM_MAX_SP_RSZ_OUTPUT_HEIGHT , + .min_rsz_width =STREAM_MIN_RSZ_OUTPUT_WIDTH , + .min_rsz_height =STREAM_MIN_RSZ_OUTPUT_HEIGHT , +/* registers */ + .rsz = { + .ctrl =CIF_SRSZ_CTRL , + .scale_hy =CIF_SRSZ_SCALE_HY , + .scale_hcr =CIF_SRSZ_SCALE_HCR , + .scale_hcb =CIF_SRSZ_SCALE_HCB , + .scale_vy =CIF_SRSZ_SCALE_VY , + .scale_vc =CIF_SRSZ_SCALE_VC , + .scale_lut =CIF_SRSZ_SCALE_LUT , + .scale_lut_addr =CIF_SRSZ_SCALE_LUT_ADDR , + .scale_hy_shd =CIF_SRSZ_SCALE_HY_SHD , + .scale_hcr_shd =CIF_SRSZ_SCALE_HCR_SHD , + .scale_hcb_shd =CIF_SRSZ_SCALE_HCB_SHD , + .scale_vy_shd =CIF_SRSZ_SCALE_VY_SHD , + .scale_vc_shd =CIF_SRSZ_SCALE_VC_SHD , + .phase_hy =CIF_SRSZ_PHASE_HY , + .phase_hc =CIF_SRSZ_PHASE_HC , + .phase_vy =CIF_SRSZ_PHASE_VY , + .phase_vc =CIF_SRSZ_PHASE_VC , + .ctrl_shd =CIF_SRSZ_CTRL_SHD , + .phase_hy_shd =CIF_SRSZ_PHASE_HY_SHD , + .phase_hc_shd =CIF_SRSZ_PHASE_HC_SHD , + .phase_vy_shd =CIF_SRSZ_PHASE_VY_SHD , + .phase_vc_shd =CIF_SRSZ_PHASE_VC_SHD , + }, + .dual_crop = { + .ctrl =CIF_DUAL_CROP_CTRL , + .yuvmode_mask =CIF_DUAL_CROP_SP_MODE_YUV , + .rawmode_mask =CIF_DUAL_CROP_SP_MODE_RAW , + .h_offset =CIF_DUAL_CROP_S_H_OFFS , + .v_offset =CIF_DUAL_CROP_S_V_OFFS , + .h_size =CIF_DUAL_CROP_S_H_SIZE , + .v_size =CIF_DUAL_CROP_S_V_SIZE , + }, + .mi = { + .y_size_init =CIF_MI_SP_Y_SIZE_INIT , + .cb_size_init =CIF_MI_SP_CB_SIZE_INIT , + .cr_size_init =CIF_MI_SP_CR_SIZE_INIT , + .y_base_ad_init =CIF_MI_SP_Y_BASE_AD_INIT , + .cb_base_ad_init =CIF_MI_SP_CB_BASE_AD_INIT , + .cr_base_ad_init =CIF_MI_SP_CR_BASE_AD_INIT , + .y_offs_cnt_init =CIF_MI_SP_Y_OFFS_CNT_INIT , + .cb_offs_cnt_init =CIF_MI_SP_CB_OFFS_CNT_INIT , + .cr_offs_cnt_init =CIF_MI_SP_CR_OFFS_CNT_INIT , + }, +}; + +static const +struct capture_fmt *find_fmt (struct rkisp1_stream *stream,const u32 pixelfmt) +{ +const struct capture_fmt *fmt; +int i; + +for (i =0 ; i < stream->config->fmt_size; i++) { + fmt = &stream->config->fmts[i]; +if (fmt->fourcc == pixelfmt) +return fmt; + } +return NULL ; +} + +static int rkisp1_config_dcrop (struct rkisp1_stream *stream,bool async) +{ +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); + +if (dcrop->width == input_win->width && + dcrop->height == input_win->height && + dcrop->left ==0 && dcrop->top ==0 ) { +disable_dcrop (stream, async); +return 0 ; + } + +config_dcrop (stream, dcrop, async); + +return 0 ; +} + +static int rkisp1_config_rsz (struct rkisp1_stream *stream,bool async) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_pix_format_mplane output_fmt = stream->out_fmt; +struct capture_fmt *output_isp_fmt = &stream->out_isp_fmt; +struct ispsd_out_fmt *input_isp_fmt =rkisp1_get_ispsd_out_fmt (dev); +struct v4l2_rect in_y, in_c, out_y, out_c; +u32 xsubs_in, ysubs_in, xsubs_out, ysubs_out; + +if (input_isp_fmt->fmt_type ==FMT_BAYER ) + goto disable; + +/* set input and output sizes for scale calculation */ + in_y.width = stream->dcrop.width; + in_y.height = stream->dcrop.height; + out_y.width = output_fmt.width; + out_y.height = output_fmt.height; + +if (mbus_code_xysubs (input_isp_fmt->mbus_code, &xsubs_in, &ysubs_in)) { +v4l2_err (&dev->v4l2_dev,"Not xsubs/ysubs found\n" ); +return -EINVAL ; + } + in_c.width = in_y.width / xsubs_in; + in_c.height = in_y.height / ysubs_in; + +if (output_isp_fmt->fmt_type ==FMT_YUV ) { +fcc_xysubs (output_isp_fmt->fourcc, &xsubs_out, &ysubs_out); + out_c.width = out_y.width / xsubs_out; + out_c.height = out_y.height / ysubs_out; + }else { + out_c.width = out_y.width / xsubs_in; + out_c.height = out_y.height / ysubs_in; + } + +if (in_c.width == out_c.width && in_c.height == out_c.height) + goto disable; + +/* set RSZ input and output */ +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream: %d fmt: %08x %dx%d -> fmt: %08x %dx%d\n" , + stream->id, input_isp_fmt->mbus_code, + stream->dcrop.width, stream->dcrop.height, + output_isp_fmt->fourcc, output_fmt.width, + output_fmt.height); +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"chroma scaling %dx%d -> %dx%d\n" , + in_c.width, in_c.height, out_c.width, out_c.height); + +/* calculate and set scale */ +config_rsz (stream, &in_y, &in_c, &out_y, &out_c, async); + +if (rkisp1_debug) +dump_rsz_regs (stream); + +return 0 ; + +disable: +disable_rsz (stream, async); + +return 0 ; +} + +/***************************** stream operations*******************************/ +static int mp_config_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +/* +* plane_fmt[0].sizeimage is total size of all planes for single +* memory plane formats, so calculate the size explicitly. +*/ +mi_set_y_size (stream, stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height); +mi_set_cb_size (stream, stream->out_fmt.plane_fmt[1 ].sizeimage); +mi_set_cr_size (stream, stream->out_fmt.plane_fmt[2 ].sizeimage); + +mp_frame_end_int_enable (base); +if (stream->out_isp_fmt.uv_swap) +mp_set_uv_swap (base); + +config_mi_ctrl (stream); +mp_mi_ctrl_set_format (base, stream->out_isp_fmt.write_format); +mp_mi_ctrl_autoupdate_en (base); + +return 0 ; +} + +static int sp_config_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +struct rkisp1_device *dev = stream->ispdev; +struct capture_fmt *output_isp_fmt = &stream->out_isp_fmt; +struct ispsd_out_fmt *input_isp_fmt =rkisp1_get_ispsd_out_fmt (dev); +u32 sp_in_fmt; + +if (mbus_code_sp_in_fmt (input_isp_fmt->mbus_code, &sp_in_fmt)) { +v4l2_err (&dev->v4l2_dev,"Can't find the input format\n" ); +return -EINVAL ; + } +mi_set_y_size (stream, stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height); +mi_set_cb_size (stream, stream->out_fmt.plane_fmt[1 ].sizeimage); +mi_set_cr_size (stream, stream->out_fmt.plane_fmt[2 ].sizeimage); + +sp_set_y_width (base, stream->out_fmt.width); +sp_set_y_height (base, stream->out_fmt.height); +sp_set_y_line_length (base, stream->u.sp.y_stride); + +sp_frame_end_int_enable (base); +if (output_isp_fmt->uv_swap) +sp_set_uv_swap (base); + +config_mi_ctrl (stream); +sp_mi_ctrl_set_format (base, stream->out_isp_fmt.write_format | + sp_in_fmt | output_isp_fmt->output_format); + +sp_mi_ctrl_autoupdate_en (base); + +return 0 ; +} + +static struct rkisp1_stream *get_other_stream (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; + +return &dev->stream[stream->id ^1 ]; +}drivers/media/platform/rockchip/isp1/capture.c line 808
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ +static int mp_check_against (struct rkisp1_stream *stream) +{ +struct rkisp1_stream *sp =get_other_stream (stream); + +if (sp->state ==RKISP1_STATE_STREAMING ) +return -EAGAIN ; + +return 0 ; +}Hmm, can you add some comments before these functions? I noticed very few comments in this driver, and it really could use some. E.g. '
mp_check_against': it's not clear what it checks against. And what's_miinsp_config_mi?I know, adding comments is a bit of a chore, but this driver really could use some more of that.
Quoted 227 lines
drivers/media/platform/rockchip/isp1/capture.c new file +227
-0+ +static int sp_check_against (struct rkisp1_stream *stream) +{ +struct rkisp1_stream *mp =get_other_stream (stream); +struct v4l2_device *v4l2_dev = &stream->ispdev->v4l2_dev; + +if (mp->u.mp.raw_enable && mp->state ==RKISP1_STATE_STREAMING ) { +v4l2_err (v4l2_dev,"can't start SP path when MP RAW active\n" ); +return -EBUSY ; + } + +if (mp->state ==RKISP1_STATE_STREAMING ) +return -EAGAIN ; + +return 0 ; +} + +static void mp_enable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; + +mi_ctrl_mp_disable (base); +if (isp_fmt->fmt_type ==FMT_BAYER ) +mi_ctrl_mpraw_enable (base); +else if (isp_fmt->fmt_type ==FMT_YUV ) +mi_ctrl_mpyuv_enable (base); +} + +static void sp_enable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_spyuv_enable (base); +} + +static void mp_disable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_mp_disable (base); +} + +static void sp_disable_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +mi_ctrl_spyuv_disable (base); +} + +static void update_mi (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; + +if (stream->next_buf) { +mi_set_y_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_Y ]); +mi_set_cb_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_CB ]); +mi_set_cr_addr (stream, + stream->next_buf->buff_addr[RKISP1_PLANE_CR ]); + }else { +/* Throw data to dummy space */ +mi_set_y_addr (stream, dummy_buf->dma_addr); +mi_set_cb_addr (stream, dummy_buf->dma_addr); +mi_set_cr_addr (stream, dummy_buf->dma_addr); + } + +mi_set_y_offset (stream,0 ); +mi_set_cb_offset (stream,0 ); +mi_set_cr_offset (stream,0 ); +} + +static void mp_stop_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +if (stream->state !=RKISP1_STATE_STREAMING ) +return ; +/*mp_frame_end_int_disable(base);*/ + stream->ops->clr_frame_end_int (base); + stream->ops->disable_mi (stream); +} + +static void sp_stop_mi (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; + +if (stream->state !=RKISP1_STATE_STREAMING ) +return ; +/*sp_frame_end_int_disable(base);*/ + stream->ops->clr_frame_end_int (base); + stream->ops->disable_mi (stream); +} + +static struct streams_ops rkisp1_mp_streams_ops = { + .check_against = mp_check_against, + .config_mi = mp_config_mi, + .enable_mi = mp_enable_mi, + .disable_mi = mp_disable_mi, + .stop_mi = mp_stop_mi, + .set_data_path = mp_set_data_path, + .clr_frame_end_int = mp_clr_frame_end_int, + .is_frame_end_int_masked = mp_is_frame_end_int_masked, +}; + +static struct streams_ops rkisp1_sp_streams_ops = { + .check_against = sp_check_against, + .config_mi = sp_config_mi, + .enable_mi = sp_enable_mi, + .disable_mi = sp_disable_mi, + .stop_mi = sp_stop_mi, + .set_data_path = sp_set_data_path, + .clr_frame_end_int = sp_clr_frame_end_int, + .is_frame_end_int_masked = sp_is_frame_end_int_masked, +}; + +static void rkisp1_stream_stop (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +struct v4l2_device *v4l2_dev = &dev->v4l2_dev; +int ret =0 ; + + stream->stop = true; + ret =wait_event_timeout (stream->done, + stream->state !=RKISP1_STATE_STREAMING , +msecs_to_jiffies (1000 )); +if (!ret) { +v4l2_warn (v4l2_dev,"waiting on event return error %d\n" , ret); + stream->ops->stop_mi (stream); + stream->stop = false; + stream->state =RKISP1_STATE_READY ; + } +disable_dcrop (stream, true); +disable_rsz (stream, true); +} + +static int mi_frame_end (struct rkisp1_stream *stream) +{ +struct rkisp1_isp_subdev *isp_sd = &stream->ispdev->isp_sdev; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +unsigned long lock_flags =0 ; +int i =0 ; + +if (stream->curr_buf) { +/* Dequeue a filled buffer */ +for (i =0 ; i < isp_fmt->mplanes; i++) { +u32 payload_size = + stream->out_fmt.plane_fmt[i].sizeimage; +vb2_set_plane_payload ( + &stream->curr_buf->vb.vb2_buf, i, + payload_size); + } + stream->curr_buf->vb.sequence = +atomic_read (&isp_sd->frm_sync_seq) -1 ; + stream->curr_buf->vb.vb2_buf.timestamp =ktime_get_ns (); +vb2_buffer_done (&stream->curr_buf->vb.vb2_buf, +VB2_BUF_STATE_DONE ); + } + +/* Next frame is writing to it */ + stream->curr_buf = stream->next_buf; + stream->next_buf =NULL ; + +/* Set up an empty buffer for the next-next frame */ +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +if (!list_empty (&stream->buf_queue)) { + stream->next_buf =list_first_entry (&stream->buf_queue, + struct rkisp1_buffer, queue); +list_del (&stream->next_buf->queue); + } + +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); + +update_mi (stream); + +return 0 ; +} + +/* +* Videobuf2 operations. +*/ +static int rkisp1_start (struct rkisp1_stream *stream) +{ +void __iomem *base = stream->ispdev->base_addr; +int ret; + + stream->ops->set_data_path (base); + ret = stream->ops->config_mi (stream); +if (ret) +return ret; + +/* Set up an buffer for the next frame */ +mi_frame_end (stream); +/* Update shadow register */ +force_cfg_update (base); +/* Set up an buffer for the next-next frame */ +mi_frame_end (stream); + + stream->ops->enable_mi (stream); + stream->state =RKISP1_STATE_STREAMING ; + +return 0 ; +} + +static int rkisp1_restart (struct rkisp1_stream *stream) +{ +struct rkisp1_device *dev = stream->ispdev; +int ret; + +rkisp1_stream_stop (stream); + + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ret; + + ret =rkisp1_start (stream); +if (ret <0 ) +return ret; + +return 0 ; +} + +static int rkisp1_queue_setup(struct vb2_queue *queue, + unsigned int *num_buffers, + unsigned int *num_planes, + unsigned int sizes[],drivers/media/platform/rockchip/isp1/capture.c line 1045
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+ struct device *alloc_devs[]) +{ +struct rkisp1_stream *stream = queue->drv_priv; +struct rkisp1_device *isp_dev = stream->ispdev; +const struct v4l2_pix_format_mplane *pixm = &stream->out_fmt; +const struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +u32 i; + + *num_buffers =clamp_t (u32, *num_buffers,CIF_ISP_REQ_BUFS_MIN , +CIF_ISP_REQ_BUFS_MAX );Since
min_buffers_neededis set toCIF_ISP_REQ_BUFS_MIN, then you don't need to check againstCIF_ISP_REQ_BUFS_MINagain.drivers/media/platform/rockchip/isp1/capture.c line 1054
Quoted 9 lines
drivers/media/platform/rockchip/isp1/capture.c new file +9
-0+ *num_planes = isp_fmt->mplanes; + +for (i =0 ; i < isp_fmt->mplanes; i++) { +const struct v4l2_plane_pix_format *plane_fmt; + + plane_fmt = &pixm->plane_fmt[i]; + + sizes[i] = plane_fmt->sizeimage; + alloc_devs[i] = isp_dev->dev;You don't need this. Just set
queue->devtoisp_dev->devwhen initializing the queue.alloc_devs[] is only needed if the device would differ per-plane (seen in weird Samsung exynos hardware).
Quoted 194 lines
drivers/media/platform/rockchip/isp1/capture.c new file +194
-0+ } + +v4l2_dbg (1 , rkisp1_debug, &isp_dev->v4l2_dev,"%s count %d, size %d\n" , + v4l2_type_names[queue->type], *num_buffers, sizes[0 ]); + +return 0 ; +} + +static void rkisp1_buf_queue (struct vb2_buffer *vb) +{ +struct vb2_v4l2_buffer *vbuf =to_vb2_v4l2_buffer (vb); +struct rkisp1_buffer *ispbuf =to_rkisp1_buffer (vbuf); +struct vb2_queue *queue = vb->vb2_queue; +struct rkisp1_stream *stream = queue->drv_priv; +unsigned long lock_flags =0 ; +struct v4l2_pix_format_mplane *pixm = &stream->out_fmt; +struct capture_fmt *isp_fmt = &stream->out_isp_fmt; +int i; + +memset (ispbuf->buff_addr,0 ,sizeof (ispbuf->buff_addr)); +for (i =0 ; i < isp_fmt->mplanes; i++) + ispbuf->buff_addr[i] =vb2_dma_contig_plane_dma_addr (vb, i); + +if (isp_fmt->mplanes ==1 ) { +for (i =0 ; i < isp_fmt->cplanes -1 ; i++) { + ispbuf->buff_addr[i +1 ] = + ispbuf->buff_addr[i] + + pixm->plane_fmt[i].bytesperline * + pixm->height; + } + } + +spin_lock_irqsave (&stream->vbq_lock, lock_flags); +list_add_tail (&ispbuf->queue, &stream->buf_queue); +spin_unlock_irqrestore (&stream->vbq_lock, lock_flags); +} + +static int rkisp1_create_dummy_buf (struct rkisp1_stream *stream) +{ +struct rkisp1_dummy_buffer *dummy_buf = &stream->dummy_buf; +struct rkisp1_device *dev = stream->ispdev; + +/* get a minimum size */ + dummy_buf->size =max3 (stream->out_fmt.plane_fmt[0 ].bytesperline * + stream->out_fmt.height, + stream->out_fmt.plane_fmt[1 ].sizeimage, + stream->out_fmt.plane_fmt[2 ].sizeimage); + + dummy_buf->vaddr =dma_alloc_coherent (dev->dev, dummy_buf->size, + &dummy_buf->dma_addr, +GFP_KERNEL ); +if (!dummy_buf->vaddr) { +v4l2_err (&dev->v4l2_dev, +"Failed to allocate the memory for dummy buffer\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +static void rkisp1_destory_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; +LIST_HEAD (queued_buffers); + +rkisp1_stream_stop (stream); + ret = dev->pipe.set_stream (&dev->pipe, false); +if (ret <0 ) +return ; + + stream->state =RKISP1_STATE_READY ; + +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, + 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 ; + } + +media_pipeline_stop (&node->vdev.entity); + +rkisp1_destory_dummy_buf (stream); +} + +static int +rkisp1_start_streaming (struct vb2_queue *queue,unsigned int count) +{ +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; + + ret =rkisp1_create_dummy_buf (stream); +if (ret <0 ) +return ret; + + 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 err; + } + + 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 err; + } + +if (stream->state !=RKISP1_STATE_READY ) { +v4l2_err (v4l2_dev,"stream not enabled\n" ); + ret = -EBUSY ; + goto err; + } + + ret = stream->ops->check_against (stream); +if (ret == -EAGAIN ) { +struct rkisp1_stream *other; + + other =get_other_stream (stream); +if (other) +rkisp1_restart (other); + }else if (ret == -EBUSY ) { + goto err; + } + + ret =rkisp1_start (stream); +if (ret <0 ) + goto err; + + ret =rkisp1_config_rsz (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"failed with error %d\n" , ret); + goto err; + } + + ret =rkisp1_config_dcrop (stream, false); +if (ret <0 ) { +v4l2_err (v4l2_dev,"failed with error %d\n" , ret); + goto err; + } + +/* pipeline stream on */ + ret = dev->pipe.set_stream (&dev->pipe, true); +if (ret <0 ) + goto err; +return 0 ; + +err: +rkisp1_destory_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, +}; +drivers/media/platform/rockchip/isp1/capture.c line 1258
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+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_USERPTR |VB2_DMABUF ;Don't use
VB2_USERPTRunless there is an iommu that would allow you to use a malloc()ed buffer. Usually that's not the case for dma-contig streaming. Either because there is no iommu, or because there are alignment requirements (e.g. start at the page boundary) that do not fit a malloc()ed buffer.Quoted 278 lines
drivers/media/platform/rockchip/isp1/capture.c new file +278
-0+ 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; + +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; +unsigned int imagsize =0 ; +unsigned int planes; +u32 xsubs =1 , ysubs =1 ; +int i; + + fmt =find_fmt (stream, pixm->pixelformat); +if (!fmt) + fmt = stream->config->fmts; + +/* do checks on resolution */ + pixm->width =clamp_t (u32, pixm->width, + stream->config->min_rsz_width, + stream->config->max_rsz_width); + pixm->height =clamp_t (u32, pixm->height, + stream->config->min_rsz_height, + stream->config->max_rsz_height); + pixm->num_planes = fmt->mplanes; + pixm->colorspace =rkisp1_get_colorspace (fmt->fmt_type); + pixm->field =V4L2_FIELD_NONE ; +/* TODO: quantization */ + pixm->quantization =0 ; + +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 */ +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_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, +}; + +/* +* 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 ; + +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); + +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 ; +case V4L2_SEL_TGT_COMPOSE_BOUNDS : + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +case V4L2_SEL_TGT_COMPOSE : +/* The composing rectangles always have the same size */ + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.height; + sel->r.left =0 ; + sel->r.top =0 ; +break ; +default : +return -EINVAL ; + } + +return 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; +struct v4l2_rect *input_win; + + input_win =rkisp1_get_isp_sd_win (dev); + +if (sel->target !=V4L2_SEL_TGT_CROP && + sel->target !=V4L2_SEL_TGT_COMPOSE ) +return -EINVAL ; + +if (sel->flags !=0 ) +return -EINVAL ; + +if (sel->target ==V4L2_SEL_TGT_CROP ) { + sel->r.left =ALIGN (sel->r.left,2 ); + sel->r.width =ALIGN (sel->r.width,2 ); + + sel->r.left = +clamp_t (u32, sel->r.left,0 , + input_win->width -STREAM_MIN_MP_SP_INPUT_WIDTH ); + sel->r.top = +clamp_t (u32, sel->r.top,0 , + input_win->height -STREAM_MIN_MP_SP_INPUT_HEIGHT ); + sel->r.width = +clamp_t (u32, sel->r.width, +STREAM_MIN_MP_SP_INPUT_WIDTH , + input_win->width - sel->r.left); + sel->r.height = +clamp_t (u32, sel->r.height, +STREAM_MIN_MP_SP_INPUT_HEIGHT , + input_win->height - sel->r.top); + +/* check whether input fmt is raw */ +if (stream->id ==RKISP1_STREAM_MP && + stream->out_isp_fmt.fmt_type ==FMT_BAYER ) { + sel->r.left =0 ; + sel->r.top =0 ; + sel->r.width = input_win->width; + sel->r.height = input_win->height; + } +
Quoted 9 lines
drivers/media/platform/rockchip/isp1/capture.c line 1539
Quoted 3 lines
drivers/media/platform/rockchip/isp1/capture.c new file +3
-0+ *dcrop = sel->r; + }else if (sel->target ==V4L2_SEL_TGT_COMPOSE ) { +/* CamHal compatibility */ Huh? If you don't support compose, then this shouldn't be indicated. When you say "CamHal compatibility" then I assume you refer to a Rockchip Android Camera HAL implementation? I think it should be fixed there instead of adding a hack here.
It's used to show that this driver support scaling, but don't support composition.
We are writing an Android Camera HAL3, which is modified from an existing HAL3. In that HAL3, it need driver support COMPOSE otherwise it think driver don't have
scaling ability.
Quoted 6,705 lines
Quoted 20 lines
drivers/media/platform/rockchip/isp1/capture.c new file +20
-0+ sel->r.left =0 ; + sel->r.top =0 ; + sel->r.width = stream->out_fmt.width; + sel->r.height = stream->out_fmt.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)); +drivers/media/platform/rockchip/isp1/capture.c line 1569
Quoted 10 lines
drivers/media/platform/rockchip/isp1/capture.c new file +10
-0+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_preparebufis missing.Quoted 473 lines
drivers/media/platform/rockchip/isp1/capture.c new file +122
-0+ .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; +} + +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); + val = stream->ops->is_frame_end_int_masked (base); +if (val) { + val =mi_get_masked_int_status (base); +v4l2_err (&dev->v4l2_dev,"icr err: 0x%x\n" , val); + } + +mi_frame_end (stream); + +if (stream->stop) { + stream->ops->stop_mi (stream); + stream->stop = false; + stream->state =RKISP1_STATE_READY ; +v4l2_dbg (1 , rkisp1_debug, &dev->v4l2_dev, +"stream %d stopped\n" , stream->id); +wake_up (&stream->done); + } +}drivers/media/platform/rockchip/isp1/capture.h new file +46
-0@@ -0,0 +1,46 @@ +/* +* 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 + +struct rkisp1_device ; +struct rkisp1_stream ; + +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 +293
-0@@ -0,0 +1,330 @@ +/* +* 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 <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 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_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 + +#define RKISP1_PIPELINE_MAX 4 + +enum rkisp1_sd_type { +RKISP1_SD_SENSOR , +RKISP1_SD_PHY_CSI , +RKISP1_SD_VCM , +RKISP1_SD_FLASH , +RKISP1_SD_MAX , +}; + +struct rkisp1_pipeline ; + +/* +* struct rkisp1_pipeline - An ISP hardware pipeline +* @entities: Bitmask of entities in the pipeline (indexed by entity ID) +*/ +struct rkisp1_pipeline { +struct media_pipeline pipe; +int num_subdevs; +struct v4l2_subdev *subdevs[RKISP1_PIPELINE_MAX ]; +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); +}; + +/* 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 , +}; + +struct ispsd_in_fmt { +u32 mbus_code; +u8 fmt_type; +u32 mipi_dt; +u32 yuv_seq; +enum rkisp1_fmt_raw_pat_type bayer_pat; +u8 bus_width; +}; + +struct ispsd_out_fmt { +u32 mbus_code; +u8 fmt_type; +}; + +/* +* @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_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; +}; + +enum rkisp1_sp_inp { +RKISP1_SP_INP_ISP , +RKISP1_SP_INP_DMA_SP , +RKISP1_SP_INP_MAX +}; + +struct rkisp1_device ; +struct rkisp1_stream ; + +struct rkisp1_stream_sp { +int y_stride; +enum rkisp1_sp_inp input_sel; +}; + +struct rkisp1_stream_mp { +bool raw_enable; +}; + +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; +}; + +struct streams_ops { +int (*check_against)(struct rkisp1_stream *stream); +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); +u32 (*is_frame_end_int_masked)(void __iomem *base); +}; + +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 for videobuf queues */ +spinlock_t vbq_lock; +/* mi config */ +struct list_head buf_queue; +struct rkisp1_dummy_buffer dummy_buf; +struct rkisp1_buffer *curr_buf; +struct rkisp1_buffer *next_buf; +bool stop; +wait_queue_head_t done; +union { +struct rkisp1_stream_sp sp; +struct rkisp1_stream_mp mp; + } u; +}; + +extern int rkisp1_debug; + +static inline u32 rkisp1_get_colorspace (u32 fmt_type) +{drivers/media/platform/rockchip/isp1/common.h line 303
Quoted 10 lines
drivers/media/platform/rockchip/isp1/common.h new file +10
-0+switch (fmt_type) { +case FMT_BAYER : +return V4L2_COLORSPACE_SRGB ; +case FMT_YUV : +case FMT_JPEG : +return V4L2_COLORSPACE_JPEG ; +case FMT_RGB : +return V4L2_COLORSPACE_RAW ; +default : +return V4L2_COLORSPACE_DEFAULT ;This is wrong. The colorspace needs to come from the source subdevice. You can't set it here, the ISP won't know it. Instead read it from the media bus format.
Quoted 2,140 lines
drivers/media/platform/rockchip/isp1/common.h new file +27
-0+ } +} + +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 +632
-0@@ -0,0 +1,632 @@ +/* +* 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 "regs.h" +#include "rkisp1.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)" ); + +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 *use_count; +int ret; + +v4l2_info (sd,"%d: name %s,on %d\n" , __LINE__, sd->name, on); + +if (!sd) +return -ENXIO ; + + use_count = &sd->entity.use_count; +if (on && (*use_count)++ >0 ) +return 0 ; +else if (!on && (*use_count ==0 || --(*use_count) >0 )) +return 0 ; + 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 (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; + + ret =__isp_pipeline_s_power (p,0 ); + +return ret == -ENXIO ?0 : ret; +} + +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) +v4l2_subdev_call (&dev->isp_sdev.sd, video, s_stream, true); + +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; +} + +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; + +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); +} + +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]; + + mis_val = stream->ops->is_frame_end_int_masked (base); +if (mis_val) +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); +atomic_set (&isp_dev->poweron_cnt,0 ); + 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; + + 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)); + + 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/isp_params.c new file +1469
-0@@ -0,0 +1,1556 @@ +/* +* 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 "regs.h" +#include "rkisp1.h" +#include "isp_params.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) + +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, +CIF_ISP_DPCC_LINE_THRESH_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].line_mad_fac, +CIF_ISP_DPCC_LINE_MAD_FAC_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].pg_fac, +CIF_ISP_DPCC_PG_FAC_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rnd_thresh, +CIF_ISP_DPCC_RND_THRESH_1 +0x14 * i); +rkisp1_iowrite32 (params_vdev, arg->methods[i].rg_fac, +CIF_ISP_DPCC_RG_FAC_1 +0x14 * 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 ; +rkisp1_iowrite32 (params_vdev, new_control,CIF_ISP_BLS_CTRL ); + }else { +if (arg->en_windows &2 ) { +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 &1 ) { +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(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 271
Quoted 10 lines
drivers/media/platform/rockchip/isp1/isp_params.c new file +10
-0+ 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 );Either add
VB2_DMABUFor remove expbuf from the ioctl ops. I would just addVB2_DMABUF. It doesn't cost anything.drivers/media/platform/rockchip/isp1/isp_stats.c
Quoted 382 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 +81
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.c new file +212
-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 removevidioc_expbuffrom the ioctl ops.drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 2,946 lines
drivers/media/platform/rockchip/isp1/isp_stats.c new file +325
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/isp_stats.h new file +81
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.c new file +251
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/regs.h new file +1578
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.c new file +687
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Just propagate the colorspace information from the incoming mediabus format. You can't guess it based on the
mbus_code.drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 14 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +14
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Ditto.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 96 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +96
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Just checking: the hardware can crop both on the sink (incoming) side and on the source (outgoing) side? I would expect it to be just on the sink side.
drivers/media/platform/rockchip/isp1/rkisp1.c
Quoted 84 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +84
-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 need
g_mbus_configfor? We have plans to remove this op in the future.drivers/media/platform/rockchip/isp1/rkisp1.h
Quoted 486 lines
drivers/media/platform/rockchip/isp1/rkisp1.c new file +349
-0Lines of this file are not shown. View the raw message.
drivers/media/platform/rockchip/isp1/rkisp1.h new file +130
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Regards,
Hans
Part of the diff is not shown here. View the raw message.
PATCH v2 4/11 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.
The phy driver is kind of independent compare to the other parts, but i'd like to keep it in rkisp1 driver, unless people want to generalize it
--- drivers/media/platform/rockchip/isp1/Makefile | 1 + .../media/platform/rockchip/isp1/mipi_dphy_sy.c | 805 +++++++++++++++++++++ 2 files changed, 806 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 +805 -0
805 lines not on this page · raw message
Signature · 1 line
2.15.0
kbuild test robot
build botRe: [PATCH v2 04/11] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
Thank you for the patch! Yet something to improve:
Hi Jacob,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20171124]
[cannot apply to rockchip/for-next v4.14]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jacob-Chen/Rockchip-ISP1-Driver/20171126-224713 base: git://linuxtv.org/media_tree.git master config: blackfin-allmodconfig (attached as .config) compiler: bfin-uclinux-gcc (GCC) 6.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=blackfin
All errors (new ones prefixed by >>):
>> drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:634:66: error: expected identifier or '(' before '=' token
struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
^
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c: In function 'rockchip_mipidphy_media_init':
>> drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:707:24: error: 'rockchip_mipidphy_async_ops' undeclared (first use in this function)
priv->notifier.ops = &rockchip_mipidphy_async_ops;
^~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:707:24: note: each undeclared identifier is reported only once for each function it appears in At top level:
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:593:1: warning: 'rockchip_mipidphy_notifier_complete' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_complete(struct v4l2_async_notifier *notifier)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:579:1: warning: 'rockchip_mipidphy_notifier_unbind' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_unbind(struct v4l2_async_notifier *notifier,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:555:1: warning: 'rockchip_mipidphy_notifier_bound' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_bound(struct v4l2_async_notifier *notifier,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +634 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
632
633 static const
> 634 struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
635 .bound = rockchip_mipidphy_notifier_bound,
636 .unbind = rockchip_mipidphy_notifier_unbind,
637 .complete = rockchip_mipidphy_notifier_complete,
638 };
639
640 static int rockchip_mipidphy_fwnode_parse(struct device *dev,
641 struct v4l2_fwnode_endpoint *vep,
642 struct v4l2_async_subdev *asd)
643 {
644 struct sensor_async_subdev *s_asd =
645 container_of(asd, struct sensor_async_subdev, asd);
646 struct v4l2_mbus_config *config = &s_asd->mbus;
647
648 if (vep->bus_type != V4L2_MBUS_CSI2) {
649 dev_err(dev, "Only CSI2 bus type is currently supported\n");
650 return -EINVAL;
651 }
652
653 if (vep->base.port != 0) {
654 dev_err(dev, "The PHY has only port 0\n");
655 return -EINVAL;
656 }
657
658 config->type = V4L2_MBUS_CSI2;
659 config->flags = vep->bus.mipi_csi2.flags;
660 s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
661
662 switch (vep->bus.mipi_csi2.num_data_lanes) {
663 case 1:
664 config->flags |= V4L2_MBUS_CSI2_1_LANE;
665 break;
666 case 2:
667 config->flags |= V4L2_MBUS_CSI2_2_LANE;
668 break;
669 case 3:
670 config->flags |= V4L2_MBUS_CSI2_3_LANE;
671 break;
672 case 4:
673 config->flags |= V4L2_MBUS_CSI2_4_LANE;
674 break;
675 default:
676 return -EINVAL;
677 }
678
679 return 0;
680 }
681
682 static int rockchip_mipidphy_media_init(struct mipidphy_priv *priv)
683 {
684 int ret;
685
686 priv->pads[MIPI_DPHY_SY_PAD_SOURCE].flags =
687 MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT;
688 priv->pads[MIPI_DPHY_SY_PAD_SINK].flags =
689 MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
690
691 ret = media_entity_pads_init(&priv->sd.entity,
692 MIPI_DPHY_SY_PADS_NUM, priv->pads);
693 if (ret < 0)
694 return ret;
695
696 ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
697 priv->dev, &priv->notifier,
698 sizeof(struct sensor_async_subdev), 0,
699 rockchip_mipidphy_fwnode_parse);
700 if (ret < 0)
701 return ret;
702
703 if (!priv->notifier.num_subdevs)
704 return -ENODEV; /* no endpoint */
705
706 priv->sd.subdev_notifier = &priv->notifier;
> 707 priv->notifier.ops = &rockchip_mipidphy_async_ops; 708 ret = v4l2_async_subdev_notifier_register(&priv->sd, &priv->notifier);
709 if (ret) {
710 dev_err(priv->dev,
711 "failed to register async notifier : %d\n", ret);
712 v4l2_async_notifier_cleanup(&priv->notifier);
713 return ret;
714 }
715
716 return v4l2_async_register_subdev(&priv->sd);
717 }
718
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 45924 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171127/2804215a/attachment-0001.gz>
kbuild test robot
build botRe: [PATCH v2 04/11] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
In reply to Jacob ChenThank you for the patch! Yet something to improve:
Hi Jacob,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20171124]
[cannot apply to rockchip/for-next v4.14]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jacob-Chen/Rockchip-ISP1-Driver/20171126-224713 base: git://linuxtv.org/media_tree.git master config: mips-allmodconfig (attached as .config) compiler: mips-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips
All errors (new ones prefixed by >>):
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:634:66: error: expected identifier or '(' before '=' token
struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
^
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c: In function 'rockchip_mipidphy_media_init':
>> drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:707:24: error: 'rockchip_mipidphy_async_ops' undeclared (first use in this function); did you mean 'rockchip_mipidphy_match_id'?
priv->notifier.ops = &rockchip_mipidphy_async_ops;
^~~~~~~~~~~~~~~~~~~~~~~~~~~
rockchip_mipidphy_match_id drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:707:24: note: each undeclared identifier is reported only once for each function it appears in At top level:
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:593:1: warning: 'rockchip_mipidphy_notifier_complete' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_complete(struct v4l2_async_notifier *notifier)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:579:1: warning: 'rockchip_mipidphy_notifier_unbind' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_unbind(struct v4l2_async_notifier *notifier,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c:555:1: warning: 'rockchip_mipidphy_notifier_bound' defined but not used [-Wunused-function]
rockchip_mipidphy_notifier_bound(struct v4l2_async_notifier *notifier,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +707 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c
632
633 static const
> 634 struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = {
635 .bound = rockchip_mipidphy_notifier_bound,
636 .unbind = rockchip_mipidphy_notifier_unbind,
637 .complete = rockchip_mipidphy_notifier_complete,
638 };
639
640 static int rockchip_mipidphy_fwnode_parse(struct device *dev,
641 struct v4l2_fwnode_endpoint *vep,
642 struct v4l2_async_subdev *asd)
643 {
644 struct sensor_async_subdev *s_asd =
645 container_of(asd, struct sensor_async_subdev, asd);
646 struct v4l2_mbus_config *config = &s_asd->mbus;
647
648 if (vep->bus_type != V4L2_MBUS_CSI2) {
649 dev_err(dev, "Only CSI2 bus type is currently supported\n");
650 return -EINVAL;
651 }
652
653 if (vep->base.port != 0) {
654 dev_err(dev, "The PHY has only port 0\n");
655 return -EINVAL;
656 }
657
658 config->type = V4L2_MBUS_CSI2;
659 config->flags = vep->bus.mipi_csi2.flags;
660 s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes;
661
662 switch (vep->bus.mipi_csi2.num_data_lanes) {
663 case 1:
664 config->flags |= V4L2_MBUS_CSI2_1_LANE;
665 break;
666 case 2:
667 config->flags |= V4L2_MBUS_CSI2_2_LANE;
668 break;
669 case 3:
670 config->flags |= V4L2_MBUS_CSI2_3_LANE;
671 break;
672 case 4:
673 config->flags |= V4L2_MBUS_CSI2_4_LANE;
674 break;
675 default:
676 return -EINVAL;
677 }
678
679 return 0;
680 }
681
682 static int rockchip_mipidphy_media_init(struct mipidphy_priv *priv)
683 {
684 int ret;
685
686 priv->pads[MIPI_DPHY_SY_PAD_SOURCE].flags =
687 MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT;
688 priv->pads[MIPI_DPHY_SY_PAD_SINK].flags =
689 MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
690
691 ret = media_entity_pads_init(&priv->sd.entity,
692 MIPI_DPHY_SY_PADS_NUM, priv->pads);
693 if (ret < 0)
694 return ret;
695
696 ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
697 priv->dev, &priv->notifier,
698 sizeof(struct sensor_async_subdev), 0,
699 rockchip_mipidphy_fwnode_parse);
700 if (ret < 0)
701 return ret;
702
703 if (!priv->notifier.num_subdevs)
704 return -ENODEV; /* no endpoint */
705
706 priv->sd.subdev_notifier = &priv->notifier;
> 707 priv->notifier.ops = &rockchip_mipidphy_async_ops; 708 ret = v4l2_async_subdev_notifier_register(&priv->sd, &priv->notifier);
709 if (ret) {
710 dev_err(priv->dev,
711 "failed to register async notifier : %d\n", ret);
712 v4l2_async_notifier_cleanup(&priv->notifier);
713 return ret;
714 }
715
716 return v4l2_async_register_subdev(&priv->sd);
717 }
718
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 47597 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171127/a16bcce3/attachment-0001.gz>
Re: [PATCH v2 04/11] media: rkisp1: add Rockchip MIPI Synopsys DPHY driver
In reply to Jacob ChenI'm CC-ing Jose Abreu from Synopsys to this. Jose, can you or a colleague take a look at this as well?
Jacob, I have some high-level questions first:
1) to what extend is this code rockchip-specific as opposed to be more synopsys-generic?
2) I don't quite see how this works when there are two sensors. Is only one active at a time? Or are they multiplexed somehow?
3) Same as for the previous patch: some more comments would be welcome.
Quoted 500 lines · Jacob Chen
From: Jacob Chen <[email protected]>
This commit adds a subdev driver for Rockchip MIPI Synopsys DPHY driver.
The phy driver is kind of independent compare to the other parts, but i'd like to keep it in rkisp1 driver, unless people want to generalize it
Signed-off-by Jacob Chen <[email protected]>Signed-off-by Shunqian Zheng <[email protected]>Signed-off-by Tomasz Figa <[email protected]>--- drivers/media/platform/rockchip/isp1/Makefile | 1 + .../media/platform/rockchip/isp1/mipi_dphy_sy.c | 805 +++++++++++++++++++++ 2 files changed, 806 insertions(+) create mode 100644 drivers/media/platform/rockchip/isp1/mipi_dphy_sy.cdrivers/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.odrivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +468
-0@@ -0,0 +1,805 @@ +/* +* Rockchip MIPI Synopsys DPHY driver +* +* Copyright (C) 2017 Fuzhou 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/delay.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <linux/mfd/syscon.h> +#include <media/media-entity.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-subdev.h> + +#define RK3288_GRF_SOC_CON6 0x025c +#define RK3288_GRF_SOC_CON8 0x0264 +#define RK3288_GRF_SOC_CON9 0x0268 +#define RK3288_GRF_SOC_CON10 0x026c +#define RK3288_GRF_SOC_CON14 0x027c +#define RK3288_GRF_SOC_STATUS21 0x02d4 +#define RK3288_GRF_IO_VSEL 0x0380 +#define RK3288_GRF_SOC_CON15 0x03a4 + +#define RK3399_GRF_SOC_CON9 0x6224 +#define RK3399_GRF_SOC_CON21 0x6254 +#define RK3399_GRF_SOC_CON22 0x6258 +#define RK3399_GRF_SOC_CON23 0x625c +#define RK3399_GRF_SOC_CON24 0x6260 +#define RK3399_GRF_SOC_CON25 0x6264 +#define RK3399_GRF_SOC_STATUS1 0xe2a4 + +#define CLOCK_LANE_HS_RX_CONTROL 0x34 +#define LANE0_HS_RX_CONTROL 0x44 +#define LANE1_HS_RX_CONTROL 0x54 +#define LANE2_HS_RX_CONTROL 0x84 +#define LANE3_HS_RX_CONTROL 0x94 +#define HS_RX_DATA_LANES_THS_SETTLE__CONTROL 0x75 + +#define HIWORD_UPDATE (val, mask, shift) \ + ((val) << (shift) | (mask) << ((shift) + 16)) + +enum mipi_dphy_sy_pads { +MIPI_DPHY_SY_PAD_SINK =0 , +MIPI_DPHY_SY_PAD_SOURCE , +MIPI_DPHY_SY_PADS_NUM , +}; + +enum dphy_reg_id { +GRF_DPHY_RX0_TURNDISABLE =0 , +GRF_DPHY_RX0_FORCERXMODE , +GRF_DPHY_RX0_FORCETXSTOPMODE , +GRF_DPHY_RX0_ENABLE , +GRF_DPHY_RX0_TESTCLR , +GRF_DPHY_RX0_TESTCLK , +GRF_DPHY_RX0_TESTEN , +GRF_DPHY_RX0_TESTDIN , +GRF_DPHY_RX0_TURNREQUEST , +GRF_DPHY_RX0_TESTDOUT , +GRF_DPHY_TX0_TURNDISABLE , +GRF_DPHY_TX0_FORCERXMODE , +GRF_DPHY_TX0_FORCETXSTOPMODE , +GRF_DPHY_TX0_TURNREQUEST , +GRF_DPHY_TX1RX1_TURNDISABLE , +GRF_DPHY_TX1RX1_FORCERXMODE , +GRF_DPHY_TX1RX1_FORCETXSTOPMODE , +GRF_DPHY_TX1RX1_ENABLE , +GRF_DPHY_TX1RX1_MASTERSLAVEZ , +GRF_DPHY_TX1RX1_BASEDIR , +GRF_DPHY_TX1RX1_ENABLECLK , +GRF_DPHY_TX1RX1_TURNREQUEST , +GRF_DPHY_RX1_SRC_SEL , +/* rk3288 only */ +GRF_CON_DISABLE_ISP , +GRF_CON_ISP_DPHY_SEL , +GRF_DSI_CSI_TESTBUS_SEL , +GRF_DVP_V18SEL , +/* below is for rk3399 only */ +GRF_DPHY_RX0_CLK_INV_SEL , +GRF_DPHY_RX1_CLK_INV_SEL , +}; + +struct dphy_reg { +u32 offset; +u32 mask; +u32 shift; +}; + +#define PHY_REG (_offset, _width, _shift) \ + { .offset = _offset, .mask = BIT(_width) - 1, .shift = _shift, } + +static const struct dphy_reg rk3399_grf_dphy_regs[] = { + [GRF_DPHY_RX0_TURNREQUEST ] =PHY_REG (RK3399_GRF_SOC_CON9 ,4 ,0 ), + [GRF_DPHY_RX0_CLK_INV_SEL ] =PHY_REG (RK3399_GRF_SOC_CON9 ,1 ,10 ), + [GRF_DPHY_RX1_CLK_INV_SEL ] =PHY_REG (RK3399_GRF_SOC_CON9 ,1 ,11 ), + [GRF_DPHY_RX0_ENABLE ] =PHY_REG (RK3399_GRF_SOC_CON21 ,4 ,0 ), + [GRF_DPHY_RX0_FORCERXMODE ] =PHY_REG (RK3399_GRF_SOC_CON21 ,4 ,4 ), + [GRF_DPHY_RX0_FORCETXSTOPMODE ] =PHY_REG (RK3399_GRF_SOC_CON21 ,4 ,8 ), + [GRF_DPHY_RX0_TURNDISABLE ] =PHY_REG (RK3399_GRF_SOC_CON21 ,4 ,12 ), + [GRF_DPHY_TX0_FORCERXMODE ] =PHY_REG (RK3399_GRF_SOC_CON22 ,4 ,0 ), + [GRF_DPHY_TX0_FORCETXSTOPMODE ] =PHY_REG (RK3399_GRF_SOC_CON22 ,4 ,4 ), + [GRF_DPHY_TX0_TURNDISABLE ] =PHY_REG (RK3399_GRF_SOC_CON22 ,4 ,8 ), + [GRF_DPHY_TX0_TURNREQUEST ] =PHY_REG (RK3399_GRF_SOC_CON22 ,4 ,12 ), + [GRF_DPHY_TX1RX1_ENABLE ] =PHY_REG (RK3399_GRF_SOC_CON23 ,4 ,0 ), + [GRF_DPHY_TX1RX1_FORCERXMODE ] =PHY_REG (RK3399_GRF_SOC_CON23 ,4 ,4 ), + [GRF_DPHY_TX1RX1_FORCETXSTOPMODE ] =PHY_REG (RK3399_GRF_SOC_CON23 ,4 ,8 ), + [GRF_DPHY_TX1RX1_TURNDISABLE ] =PHY_REG (RK3399_GRF_SOC_CON23 ,4 ,12 ), + [GRF_DPHY_TX1RX1_TURNREQUEST ] =PHY_REG (RK3399_GRF_SOC_CON24 ,4 ,0 ), + [GRF_DPHY_RX1_SRC_SEL ] =PHY_REG (RK3399_GRF_SOC_CON24 ,1 ,4 ), + [GRF_DPHY_TX1RX1_BASEDIR ] =PHY_REG (RK3399_GRF_SOC_CON24 ,1 ,5 ), + [GRF_DPHY_TX1RX1_ENABLECLK ] =PHY_REG (RK3399_GRF_SOC_CON24 ,1 ,6 ), + [GRF_DPHY_TX1RX1_MASTERSLAVEZ ] =PHY_REG (RK3399_GRF_SOC_CON24 ,1 ,7 ), + [GRF_DPHY_RX0_TESTDIN ] =PHY_REG (RK3399_GRF_SOC_CON25 ,8 ,0 ), + [GRF_DPHY_RX0_TESTEN ] =PHY_REG (RK3399_GRF_SOC_CON25 ,1 ,8 ), + [GRF_DPHY_RX0_TESTCLK ] =PHY_REG (RK3399_GRF_SOC_CON25 ,1 ,9 ), + [GRF_DPHY_RX0_TESTCLR ] =PHY_REG (RK3399_GRF_SOC_CON25 ,1 ,10 ), + [GRF_DPHY_RX0_TESTDOUT ] =PHY_REG (RK3399_GRF_SOC_STATUS1 ,8 ,0 ), +}; + +static const struct dphy_reg rk3288_grf_dphy_regs[] = { + [GRF_CON_DISABLE_ISP ] =PHY_REG (RK3288_GRF_SOC_CON6 ,1 ,0 ), + [GRF_CON_ISP_DPHY_SEL ] =PHY_REG (RK3288_GRF_SOC_CON6 ,1 ,1 ), + [GRF_DSI_CSI_TESTBUS_SEL ] =PHY_REG (RK3288_GRF_SOC_CON6 ,1 ,14 ), + [GRF_DPHY_TX0_TURNDISABLE ] =PHY_REG (RK3288_GRF_SOC_CON8 ,4 ,0 ), + [GRF_DPHY_TX0_FORCERXMODE ] =PHY_REG (RK3288_GRF_SOC_CON8 ,4 ,4 ), + [GRF_DPHY_TX0_FORCETXSTOPMODE ] =PHY_REG (RK3288_GRF_SOC_CON8 ,4 ,8 ), + [GRF_DPHY_TX1RX1_TURNDISABLE ] =PHY_REG (RK3288_GRF_SOC_CON9 ,4 ,0 ), + [GRF_DPHY_TX1RX1_FORCERXMODE ] =PHY_REG (RK3288_GRF_SOC_CON9 ,4 ,4 ), + [GRF_DPHY_TX1RX1_FORCETXSTOPMODE ] =PHY_REG (RK3288_GRF_SOC_CON9 ,4 ,8 ), + [GRF_DPHY_TX1RX1_ENABLE ] =PHY_REG (RK3288_GRF_SOC_CON9 ,4 ,12 ), + [GRF_DPHY_RX0_TURNDISABLE ] =PHY_REG (RK3288_GRF_SOC_CON10 ,4 ,0 ), + [GRF_DPHY_RX0_FORCERXMODE ] =PHY_REG (RK3288_GRF_SOC_CON10 ,4 ,4 ), + [GRF_DPHY_RX0_FORCETXSTOPMODE ] =PHY_REG (RK3288_GRF_SOC_CON10 ,4 ,8 ), + [GRF_DPHY_RX0_ENABLE ] =PHY_REG (RK3288_GRF_SOC_CON10 ,4 ,12 ), + [GRF_DPHY_RX0_TESTCLR ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,0 ), + [GRF_DPHY_RX0_TESTCLK ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,1 ), + [GRF_DPHY_RX0_TESTEN ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,2 ), + [GRF_DPHY_RX0_TESTDIN ] =PHY_REG (RK3288_GRF_SOC_CON14 ,8 ,3 ), + [GRF_DPHY_TX1RX1_ENABLECLK ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,12 ), + [GRF_DPHY_RX1_SRC_SEL ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,13 ), + [GRF_DPHY_TX1RX1_MASTERSLAVEZ ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,14 ), + [GRF_DPHY_TX1RX1_BASEDIR ] =PHY_REG (RK3288_GRF_SOC_CON14 ,1 ,15 ), + [GRF_DPHY_RX0_TURNREQUEST ] =PHY_REG (RK3288_GRF_SOC_CON15 ,4 ,0 ), + [GRF_DPHY_TX1RX1_TURNREQUEST ] =PHY_REG (RK3288_GRF_SOC_CON15 ,4 ,4 ), + [GRF_DPHY_TX0_TURNREQUEST ] =PHY_REG (RK3288_GRF_SOC_CON15 ,3 ,8 ), + [GRF_DVP_V18SEL ] =PHY_REG (RK3288_GRF_IO_VSEL ,1 ,1 ), + [GRF_DPHY_RX0_TESTDOUT ] =PHY_REG (RK3288_GRF_SOC_STATUS21 ,8 ,0 ), +}; + +struct hsfreq_range { +u32 range_h; +u8 cfg_bit; +}; + +struct dphy_drv_data { +const char *const *clks; +int num_clks; +const struct hsfreq_range *hsfreq_ranges; +int num_hsfreq_ranges; +const struct dphy_reg *regs; +}; + +struct sensor_async_subdev { +struct v4l2_async_subdev asd; +struct v4l2_mbus_config mbus; +int lanes; +}; + +#define MAX_DPHY_CLK 8 +#define MAX_DPHY_SENSORS 2 + +struct mipidphy_sensor { +struct v4l2_subdev *sd; +struct v4l2_mbus_config mbus; +int lanes; +}; + +struct mipidphy_priv { +struct device *dev; +struct regmap *regmap_grf; +const struct dphy_reg *grf_regs; +struct clk *clks[MAX_DPHY_CLK ]; +const struct dphy_drv_data *drv_data; +u64 data_rate_mbps; +struct v4l2_async_notifier notifier; +struct v4l2_subdev sd; +struct media_pad pads[MIPI_DPHY_SY_PADS_NUM ]; +struct mipidphy_sensor sensors[MAX_DPHY_SENSORS ]; +int num_sensors; +bool is_streaming; +}; + +static inline struct mipidphy_priv *to_dphy_priv (struct v4l2_subdev *subdev) +{ + return container_of(subdev, struct mipidphy_priv, sd); +} + +static inline void write_reg (struct mipidphy_priv *priv,int index,u8 value) +{ +const struct dphy_reg *reg = &priv->grf_regs[index]; +unsigned int val =HIWORD_UPDATE (value, reg->mask, reg->shift); + +WARN_ON (!reg->offset); +regmap_write (priv->regmap_grf, reg->offset, val); +} + +static void mipidphy_wr_reg (struct mipidphy_priv *priv, +u8 test_code,u8 test_data) +{ +/* +* With the falling edge on TESTCLK, the TESTDIN[7:0] signal content +* is latched internally as the current test code. Test data is +* programmed internally by rising edge on TESTCLK. +*/ +write_reg (priv,GRF_DPHY_RX0_TESTCLK ,1 ); +write_reg (priv,GRF_DPHY_RX0_TESTDIN , test_code); +write_reg (priv,GRF_DPHY_RX0_TESTEN ,1 ); +write_reg (priv,GRF_DPHY_RX0_TESTCLK ,0 ); +write_reg (priv,GRF_DPHY_RX0_TESTEN ,0 ); +write_reg (priv,GRF_DPHY_RX0_TESTDIN , test_data); +write_reg (priv,GRF_DPHY_RX0_TESTCLK ,1 ); +} + +static struct v4l2_subdev *get_remote_sensor (struct v4l2_subdev *sd) +{ +struct media_pad *local, *remote; +struct media_entity *sensor_me; + + local = &sd->entity.pads[MIPI_DPHY_SY_PAD_SINK ]; + remote =media_entity_remote_pad (local); +if (!remote) { +v4l2_warn (sd,"No link between dphy and sensor\n" ); +return NULL ; + } + + sensor_me =media_entity_remote_pad (local)->entity; +return media_entity_to_v4l2_subdev (sensor_me); +} + +static struct mipidphy_sensor *sd_to_sensor (struct mipidphy_priv *priv, +struct v4l2_subdev *sd) +{ +int i; + +for (i =0 ; i < priv->num_sensors; ++i) +if (priv->sensors[i].sd == sd) +return &priv->sensors[i]; + +return NULL ; +} + +static int mipidphy_get_sensor_data_rate (struct v4l2_subdev *sd) +{ +struct mipidphy_priv *priv =to_dphy_priv (sd); +struct v4l2_subdev *sensor_sd =get_remote_sensor (sd); +struct v4l2_ctrl *link_freq; +struct v4l2_querymenu qm = { .id =V4L2_CID_LINK_FREQ , }; +int ret; + + link_freq =v4l2_ctrl_find (sensor_sd->ctrl_handler,V4L2_CID_LINK_FREQ ); +if (!link_freq) { +v4l2_warn (sd,"No pixel rate control in subdev\n" ); +return -EPIPE ; + } + + qm.index =v4l2_ctrl_g_ctrl (link_freq); + ret =v4l2_querymenu (sensor_sd->ctrl_handler, &qm); +if (ret <0 ) { +v4l2_err (sd,"Failed to get menu item\n" ); +return ret; + } + +if (!qm.value) { +v4l2_err (sd,"Invalid link_freq\n" ); +return -EINVAL ; + } + priv->data_rate_mbps = qm.value *2 ; +do_div (priv->data_rate_mbps,1000 *1000 ); + +return 0 ; +} + +static int mipidphy_s_stream_start (struct v4l2_subdev *sd) +{ +struct mipidphy_priv *priv =to_dphy_priv (sd); +const struct dphy_drv_data *drv_data = priv->drv_data; +const struct hsfreq_range *hsfreq_ranges = drv_data->hsfreq_ranges; +int num_hsfreq_ranges = drv_data->num_hsfreq_ranges; +struct v4l2_subdev *sensor_sd =get_remote_sensor (sd); +struct mipidphy_sensor *sensor =sd_to_sensor (priv, sensor_sd); +int i, ret, hsfreq =0 ; + +if (priv->is_streaming) +return 0 ; + + ret =mipidphy_get_sensor_data_rate (sd); +if (ret <0 ) +return ret; + +for (i =0 ; i < num_hsfreq_ranges; i++) { +if (hsfreq_ranges[i].range_h >= priv->data_rate_mbps) { + hsfreq = hsfreq_ranges[i].cfg_bit; +break ; + } + } + +write_reg (priv,GRF_DPHY_RX0_FORCERXMODE ,0 ); +write_reg (priv,GRF_DPHY_RX0_FORCETXSTOPMODE ,0 ); +/* Disable lan turn around, which is ignored in receive mode */ +write_reg (priv,GRF_DPHY_RX0_TURNREQUEST ,0 ); +write_reg (priv,GRF_DPHY_RX0_TURNDISABLE ,0xf ); + +write_reg (priv,GRF_DPHY_RX0_ENABLE ,GENMASK (sensor->lanes -1 ,0 )); + +/* dphy start */ +write_reg (priv,GRF_DPHY_RX0_TESTCLK ,1 ); +write_reg (priv,GRF_DPHY_RX0_TESTCLR ,1 ); +usleep_range (100 ,150 ); +write_reg (priv,GRF_DPHY_RX0_TESTCLR ,0 ); +usleep_range (100 ,150 ); + +/* set clock lane */ +/* HS hsfreq_range & lane 0 settle bypass */ +mipidphy_wr_reg (priv,CLOCK_LANE_HS_RX_CONTROL ,0 ); +/* HS RX Control of lane0 */ +mipidphy_wr_reg (priv,LANE0_HS_RX_CONTROL , hsfreq <<1 ); +/* HS RX Control of lane1 */ +mipidphy_wr_reg (priv,LANE1_HS_RX_CONTROL ,0 ); +/* HS RX Control of lane2 */ +mipidphy_wr_reg (priv,LANE2_HS_RX_CONTROL ,0 ); +/* HS RX Control of lane3 */ +mipidphy_wr_reg (priv,LANE3_HS_RX_CONTROL ,0 ); +/* HS RX Data Lanes Settle State Time Control */ +mipidphy_wr_reg (priv,HS_RX_DATA_LANES_THS_SETTLE__CONTROL ,0x04 ); + +/* Normal operation */ +mipidphy_wr_reg (priv,0x0 ,0 ); + + priv->is_streaming = true; + +return 0 ; +} + +static int mipidphy_s_stream_stop (struct v4l2_subdev *sd) +{ +struct mipidphy_priv *priv =to_dphy_priv (sd); + +if (!priv->is_streaming) +return 0 ; + + priv->is_streaming = false; + +return 0 ; +} + +static int mipidphy_s_stream (struct v4l2_subdev *sd,int on) +{ +if (on) +return mipidphy_s_stream_start (sd); +else +return mipidphy_s_stream_stop (sd); +} + +static int mipidphy_g_mbus_config (struct v4l2_subdev *sd, +struct v4l2_mbus_config *config) +{ +struct mipidphy_priv *priv =to_dphy_priv (sd); +struct v4l2_subdev *sensor_sd =get_remote_sensor (sd); +struct mipidphy_sensor *sensor =sd_to_sensor (priv, sensor_sd); + + *config = sensor->mbus; + +return 0 ; +} + +static int mipidphy_s_power (struct v4l2_subdev *sd,int on) +{ +struct mipidphy_priv *priv =to_dphy_priv (sd); + +if (on) +return pm_runtime_get_sync (priv->dev); +else +return pm_runtime_put (priv->dev); +} + +static int mipidphy_runtime_suspend (struct device *dev) +{ +struct media_entity *me =dev_get_drvdata (dev); +struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (me); +struct mipidphy_priv *priv =to_dphy_priv (sd); +int i, num_clks; + + num_clks = priv->drv_data->num_clks; +for (i = num_clks -1 ; i >=0 ; i--) +clk_disable_unprepare (priv->clks[i]); + +return 0 ; +} + +static int mipidphy_runtime_resume (struct device *dev) +{ +struct media_entity *me =dev_get_drvdata (dev); +struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (me); +struct mipidphy_priv *priv =to_dphy_priv (sd); +int i, num_clks, ret; + + num_clks = priv->drv_data->num_clks; +for (i =0 ; i < num_clks; i++) { + ret =clk_prepare_enable (priv->clks[i]); +if (ret <0 ) + goto err; + } + +return 0 ; +err: +while (--i >=0 ) +clk_disable_unprepare (priv->clks[i]); +return ret; +} + +/* dphy accepts all fmt/size from sensor */ +static int mipidphy_get_set_fmt (struct v4l2_subdev *sd, +struct v4l2_subdev_pad_config *cfg, +struct v4l2_subdev_format *fmt) +{ +struct v4l2_subdev *sensor =get_remote_sensor (sd); + +/* +* Do not allow format changes and just relay whatever +* set currently in the sensor. +*/ +return v4l2_subdev_call (sensor, pad, get_fmt,NULL , fmt); +} + +static const struct v4l2_subdev_pad_ops mipidphy_subdev_pad_ops = {
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 478
Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10
-0+ .set_fmt = mipidphy_get_set_fmt, + .get_fmt = mipidphy_get_set_fmt, +}; + +static const struct v4l2_subdev_core_ops mipidphy_core_ops = { + .s_power = mipidphy_s_power, +}; + +static const struct v4l2_subdev_video_ops mipidphy_video_ops = { + .g_mbus_config = mipidphy_g_mbus_config,
Why do you need this?
Quoted 318 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +317
-0+ .s_stream = mipidphy_s_stream, +}; + +static const struct v4l2_subdev_ops mipidphy_subdev_ops = { + .core = &mipidphy_core_ops, + .video = &mipidphy_video_ops, + .pad = &mipidphy_subdev_pad_ops, +}; + +/* These tables must be sorted by .range_h ascending. */ +static const struct hsfreq_range rk3288_mipidphy_hsfreq_ranges[] = { + {89 ,0x00 }, {99 ,0x10 }, {109 ,0x20 }, {129 ,0x01 }, + {139 ,0x11 }, {149 ,0x21 }, {169 ,0x02 }, {179 ,0x12 }, + {199 ,0x22 }, {219 ,0x03 }, {239 ,0x13 }, {249 ,0x23 }, + {269 ,0x04 }, {299 ,0x14 }, {329 ,0x05 }, {359 ,0x15 }, + {399 ,0x25 }, {449 ,0x06 }, {499 ,0x16 }, {549 ,0x07 }, + {599 ,0x17 }, {649 ,0x08 }, {699 ,0x18 }, {749 ,0x09 }, + {799 ,0x19 }, {849 ,0x29 }, {899 ,0x39 }, {949 ,0x0a }, + {999 ,0x1a } +}; + +static const struct hsfreq_range rk3399_mipidphy_hsfreq_ranges[] = { + {89 ,0x00 }, {99 ,0x10 }, {109 ,0x20 }, {129 ,0x01 }, + {139 ,0x11 }, {149 ,0x21 }, {169 ,0x02 }, {179 ,0x12 }, + {199 ,0x22 }, {219 ,0x03 }, {239 ,0x13 }, {249 ,0x23 }, + {269 ,0x04 }, {299 ,0x14 }, {329 ,0x05 }, {359 ,0x15 }, + {399 ,0x25 }, {449 ,0x06 }, {499 ,0x16 }, {549 ,0x07 }, + {599 ,0x17 }, {649 ,0x08 }, {699 ,0x18 }, {749 ,0x09 }, + {799 ,0x19 }, {849 ,0x29 }, {899 ,0x39 }, {949 ,0x0a }, + {999 ,0x1a }, {1049 ,0x2a }, {1099 ,0x3a }, {1149 ,0x0b }, + {1199 ,0x1b }, {1249 ,0x2b }, {1299 ,0x3b }, {1349 ,0x0c }, + {1399 ,0x1c }, {1449 ,0x2c }, {1500 ,0x3c } +}; + +static const char *const rk3399_mipidphy_clks[] = { +"dphy-ref" , +"dphy-cfg" , +"grf" , +}; + +static const char *const rk3288_mipidphy_clks[] = { +"dphy-ref" , +"pclk" , +}; + +static const struct dphy_drv_data rk3288_mipidphy_drv_data = { + .clks = rk3288_mipidphy_clks, + .num_clks =ARRAY_SIZE (rk3288_mipidphy_clks), + .hsfreq_ranges = rk3288_mipidphy_hsfreq_ranges, + .num_hsfreq_ranges =ARRAY_SIZE (rk3288_mipidphy_hsfreq_ranges), + .regs = rk3288_grf_dphy_regs, +}; + +static const struct dphy_drv_data rk3399_mipidphy_drv_data = { + .clks = rk3399_mipidphy_clks, + .num_clks =ARRAY_SIZE (rk3399_mipidphy_clks), + .hsfreq_ranges = rk3399_mipidphy_hsfreq_ranges, + .num_hsfreq_ranges =ARRAY_SIZE (rk3399_mipidphy_hsfreq_ranges), + .regs = rk3399_grf_dphy_regs, +}; + +static const struct of_device_id rockchip_mipidphy_match_id[] = { + { + .compatible ="rockchip,rk3399-mipi-dphy" , + .data = &rk3399_mipidphy_drv_data, + }, + { + .compatible ="rockchip,rk3288-mipi-dphy" , + .data = &rk3288_mipidphy_drv_data, + }, + {} +}; +MODULE_DEVICE_TABLE (of, rockchip_mipidphy_match_id); + +/* The .bound() notifier callback when a match is found */ +static int +rockchip_mipidphy_notifier_bound (struct v4l2_async_notifier *notifier, +struct v4l2_subdev *sd, +struct v4l2_async_subdev *asd) +{ +struct mipidphy_priv *priv =container_of (notifier, + struct mipidphy_priv, + notifier); +struct sensor_async_subdev *s_asd =container_of (asd, + struct sensor_async_subdev, asd); +struct mipidphy_sensor *sensor; + +if (priv->num_sensors ==ARRAY_SIZE (priv->sensors)) +return -EBUSY ; + + sensor = &priv->sensors[priv->num_sensors++]; + sensor->lanes = s_asd->lanes; + sensor->mbus = s_asd->mbus; + sensor->sd = sd; + +return 0 ; +} + +/* The .unbind callback */ +static void +rockchip_mipidphy_notifier_unbind (struct v4l2_async_notifier *notifier, +struct v4l2_subdev *sd, +struct v4l2_async_subdev *asd) +{ +struct mipidphy_priv *priv =container_of (notifier, + struct mipidphy_priv, + notifier); +struct mipidphy_sensor *sensor =sd_to_sensor (priv, sd); + + sensor->sd =NULL ; +} + +/* .complete() is called after all subdevices have been located */ +static int +rockchip_mipidphy_notifier_complete (struct v4l2_async_notifier *notifier) +{ +struct mipidphy_priv *priv =container_of (notifier, + struct mipidphy_priv, + notifier); +unsigned int pad; +int ret; +int i; + +for (i =0 ; i < priv->num_sensors; ++i) { +struct mipidphy_sensor *sensor = &priv->sensors[i]; + +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 (priv->dev, +"failed to find src pad for %s\n" , + sensor->sd->name); + +return -ENXIO ; + } + + ret =media_create_pad_link ( + &sensor->sd->entity, pad, + &priv->sd.entity,MIPI_DPHY_SY_PAD_SINK , + i ?0 :MEDIA_LNK_FL_ENABLED ); +if (ret) { +dev_err (priv->dev, +"failed to create link for %s\n" , + sensor->sd->name); +return ret; + } + } + +return 0 ; +} + +static const +struct v4l2_async_notifier_operationsrockchip_mipidphy_async_ops = { + .bound = rockchip_mipidphy_notifier_bound, + .unbind = rockchip_mipidphy_notifier_unbind, + .complete = rockchip_mipidphy_notifier_complete, +}; + +static int rockchip_mipidphy_fwnode_parse (struct device *dev, +struct v4l2_fwnode_endpoint *vep, +struct v4l2_async_subdev *asd) +{ +struct sensor_async_subdev *s_asd = + container_of(asd, struct sensor_async_subdev, asd); +struct v4l2_mbus_config *config = &s_asd->mbus; + +if (vep->bus_type !=V4L2_MBUS_CSI2 ) { +dev_err (dev,"Only CSI2 bus type is currently supported\n" ); +return -EINVAL ; + } + +if (vep->base.port !=0 ) { +dev_err (dev,"The PHY has only port 0\n" ); +return -EINVAL ; + } + + config->type =V4L2_MBUS_CSI2 ; + config->flags = vep->bus.mipi_csi2.flags; + s_asd->lanes = vep->bus.mipi_csi2.num_data_lanes; + +switch (vep->bus.mipi_csi2.num_data_lanes) { +case 1 : + config->flags |=V4L2_MBUS_CSI2_1_LANE ; +break ; +case 2 : + config->flags |=V4L2_MBUS_CSI2_2_LANE ; +break ; +case 3 : + config->flags |=V4L2_MBUS_CSI2_3_LANE ; +break ; +case 4 : + config->flags |=V4L2_MBUS_CSI2_4_LANE ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int rockchip_mipidphy_media_init (struct mipidphy_priv *priv) +{ +int ret; + + priv->pads[MIPI_DPHY_SY_PAD_SOURCE ].flags = +MEDIA_PAD_FL_SOURCE |MEDIA_PAD_FL_MUST_CONNECT ; + priv->pads[MIPI_DPHY_SY_PAD_SINK ].flags = +MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_MUST_CONNECT ; + + ret =media_entity_pads_init (&priv->sd.entity, +MIPI_DPHY_SY_PADS_NUM , priv->pads); +if (ret <0 ) +return ret; + + ret =v4l2_async_notifier_parse_fwnode_endpoints_by_port ( + priv->dev, &priv->notifier, +sizeof (struct sensor_async_subdev ),0 , + rockchip_mipidphy_fwnode_parse); +if (ret <0 ) +return ret; + +if (!priv->notifier.num_subdevs) +return -ENODEV ;/* no endpoint */ + + priv->sd.subdev_notifier = &priv->notifier; + priv->notifier.ops = &rockchip_mipidphy_async_ops; + ret =v4l2_async_subdev_notifier_register (&priv->sd, &priv->notifier); +if (ret) { +dev_err (priv->dev, +"failed to register async notifier : %d\n" , ret); +v4l2_async_notifier_cleanup (&priv->notifier); +return ret; + } + +return v4l2_async_register_subdev (&priv->sd); +} + +static int rockchip_mipidphy_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct v4l2_subdev *sd; +struct mipidphy_priv *priv; +struct regmap *grf; +const struct of_device_id *of_id; +const struct dphy_drv_data *drv_data; +int i, ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + priv->dev = dev; + + of_id =of_match_device (rockchip_mipidphy_match_id, dev); +if (!of_id) +return -EINVAL ; + + grf =syscon_node_to_regmap (dev->parent->of_node); +if (IS_ERR (grf)) { +dev_err (dev,"Can't find GRF syscon\n" ); +return -ENODEV ; + } + priv->regmap_grf = grf; + + drv_data = of_id->data; +for (i =0 ; i < drv_data->num_clks; i++) { + priv->clks[i] =devm_clk_get (dev, drv_data->clks[i]); + +if (IS_ERR (priv->clks[i])) { +dev_err (dev,"Failed to get %s\n" , drv_data->clks[i]); +return PTR_ERR (priv->clks[i]); + } + } + + priv->grf_regs = drv_data->regs; + priv->drv_data = drv_data; + + sd = &priv->sd; +v4l2_subdev_init (sd, &mipidphy_subdev_ops); + sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; +snprintf (sd->name,sizeof (sd->name),"rockchip-sy-mipi-dphy" ); + sd->dev = dev; + +platform_set_drvdata (pdev, &sd->entity); + + ret =rockchip_mipidphy_media_init (priv); +if (ret <0 ) +return ret; + +pm_runtime_enable (&pdev->dev); + +return 0 ; +} + +static int rockchip_mipidphy_remove (struct platform_device *pdev) +{ +struct media_entity *me =platform_get_drvdata (pdev); +struct v4l2_subdev *sd =media_entity_to_v4l2_subdev (me); + +media_entity_cleanup (&sd->entity); + +pm_runtime_disable (&pdev->dev); + +return 0 ; +} + +static const struct dev_pm_ops rockchip_mipidphy_pm_ops = { +SET_RUNTIME_PM_OPS (mipidphy_runtime_suspend, + mipidphy_runtime_resume,NULL ) +}; + +static struct platform_driver rockchip_isp_mipidphy_driver = { + .probe = rockchip_mipidphy_probe, + .remove = rockchip_mipidphy_remove, + .driver = {
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c line 805
Quoted 10 lines
drivers/media/platform/rockchip/isp1/mipi_dphy_sy.c new file +10
-0+ .name = "rockchip-sy-mipi-dphy", + .pm = &rockchip_mipidphy_pm_ops, + .of_match_table = rockchip_mipidphy_match_id, + }, +}; + +module_platform_driver (rockchip_isp_mipidphy_driver); +MODULE_AUTHOR ("Rockchip Camera/ISP team" ); +MODULE_DESCRIPTION ("Rockchip MIPI DPHY driver" ); +MODULE_LICENSE ("Dual BSD/GPL" );
Regards,
Hans