1 /* 2 * Rockchip isp1 driver 3 * 4 * Copyright (C) 2017 Rockchip Electronics Co., Ltd. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 #ifndef _RKISP_DEV_H 36 #define _RKISP_DEV_H 37 38 #include "capture.h" 39 #include "csi.h" 40 #include "dmarx.h" 41 #include "bridge.h" 42 #include "hw.h" 43 #include "rkisp.h" 44 #include "isp_params.h" 45 #include "isp_stats.h" 46 #include "isp_mipi_luma.h" 47 #include "procfs.h" 48 #include "isp_external.h" 49 50 #define DRIVER_NAME "rkisp" 51 #define ISP_VDEV_NAME DRIVER_NAME "_ispdev" 52 53 #define GRP_ID_SENSOR BIT(0) 54 #define GRP_ID_MIPIPHY BIT(1) 55 #define GRP_ID_ISP BIT(2) 56 #define GRP_ID_ISP_MP BIT(3) 57 #define GRP_ID_ISP_SP BIT(4) 58 #define GRP_ID_ISP_DMARX BIT(5) 59 #define GRP_ID_ISP_BRIDGE BIT(6) 60 #define GRP_ID_CSI BIT(7) 61 62 #define RKISP_MAX_SENSOR 2 63 #define RKISP_MAX_PIPELINE 4 64 65 #define RKISP_MEDIA_BUS_FMT_MASK 0xF000 66 #define RKISP_MEDIA_BUS_FMT_BAYER 0x3000 67 68 #define RKISP_CONTI_ERR_MAX 50 69 70 enum rkisp_isp_state { 71 ISP_FRAME_END = BIT(0), 72 ISP_FRAME_IN = BIT(1), 73 ISP_FRAME_VS = BIT(2), 74 ISP_FRAME_MP = BIT(3), 75 ISP_FRAME_SP = BIT(4), 76 ISP_FRAME_MPFBC = BIT(5), 77 ISP_FRAME_BP = BIT(6), 78 79 ISP_STOP = BIT(8), 80 ISP_START = BIT(9), 81 ISP_ERROR = BIT(10), 82 ISP_MIPI_ERROR = BIT(11), 83 }; 84 85 enum rkisp_isp_inp { 86 INP_INVAL = 0, 87 INP_RAWRD0 = BIT(0), 88 INP_RAWRD1 = BIT(1), 89 INP_RAWRD2 = BIT(2), 90 INP_CSI = BIT(4), 91 INP_DVP = BIT(5), 92 INP_DMARX_ISP = BIT(6), 93 INP_LVDS = BIT(7), 94 INP_CIF = BIT(8), 95 }; 96 97 enum rkisp_rdbk_filt { 98 RDBK_F_VS, 99 RDBK_F_RD0, 100 RDBK_F_RD1, 101 RDBK_F_RD2, 102 RDBK_F_MAX 103 }; 104 105 /* 106 * struct rkisp_pipeline - An ISP hardware pipeline 107 * 108 * Capture device call other devices via pipeline 109 * 110 * @num_subdevs: number of linked subdevs 111 * @power_cnt: pipeline power count 112 * @stream_cnt: stream power count 113 */ 114 struct rkisp_pipeline { 115 struct media_pipeline pipe; 116 int num_subdevs; 117 atomic_t power_cnt; 118 atomic_t stream_cnt; 119 struct v4l2_subdev *subdevs[RKISP_MAX_PIPELINE]; 120 int (*open)(struct rkisp_pipeline *p, 121 struct media_entity *me, bool prepare); 122 int (*close)(struct rkisp_pipeline *p); 123 int (*set_stream)(struct rkisp_pipeline *p, bool on); 124 }; 125 126 /* 127 * struct rkisp_sensor_info - Sensor infomations 128 * @mbus: media bus configuration 129 */ 130 struct rkisp_sensor_info { 131 struct v4l2_subdev *sd; 132 struct v4l2_mbus_config mbus; 133 struct v4l2_subdev_frame_interval fi; 134 struct v4l2_subdev_format fmt[CSI_PAD_MAX - 1]; 135 struct v4l2_subdev_pad_config cfg; 136 }; 137 138 /* struct rkisp_hdr - hdr configured 139 * @op_mode: hdr optional mode 140 * @esp_mode: hdr especial mode 141 * @index: hdr dma index 142 * @refcnt: open counter 143 * @q_tx: dmatx buf list 144 * @q_rx: dmarx buf list 145 * @rx_cur_buf: rawrd current buf 146 * @dummy_buf: hdr dma internal buf 147 */ 148 struct rkisp_hdr { 149 u8 op_mode; 150 u8 esp_mode; 151 u8 index[HDR_DMA_MAX]; 152 atomic_t refcnt; 153 struct v4l2_subdev *sensor; 154 struct list_head q_tx[HDR_DMA_MAX]; 155 struct list_head q_rx[HDR_DMA_MAX]; 156 struct rkisp_dummy_buffer *rx_cur_buf[HDR_DMA_MAX]; 157 struct rkisp_dummy_buffer dummy_buf[HDR_DMA_MAX][HDR_MAX_DUMMY_BUF]; 158 }; 159 160 /* 161 * struct rkisp_device - ISP platform device 162 * @base_addr: base register address 163 * @active_sensor: sensor in-use, set when streaming on 164 * @isp_sdev: ISP sub-device 165 * @cap_dev: image capture device 166 * @stats_vdev: ISP statistics output device 167 * @params_vdev: ISP input parameters device 168 * @dmarx_dev: image input device 169 * @csi_dev: mipi csi device 170 * @br_dev: bridge of isp and ispp device 171 */ 172 struct rkisp_device { 173 struct list_head list; 174 void __iomem *base_addr; 175 struct device *dev; 176 char name[128]; 177 void *sw_base_addr; 178 struct rkisp_hw_dev *hw_dev; 179 struct v4l2_device v4l2_dev; 180 struct v4l2_ctrl_handler ctrl_handler; 181 struct media_device media_dev; 182 struct v4l2_async_notifier notifier; 183 struct v4l2_subdev *subdevs[RKISP_SD_MAX]; 184 struct rkisp_sensor_info *active_sensor; 185 struct rkisp_sensor_info sensors[RKISP_MAX_SENSOR]; 186 int num_sensors; 187 struct rkisp_isp_subdev isp_sdev; 188 struct rkisp_capture_device cap_dev; 189 struct rkisp_isp_stats_vdev stats_vdev; 190 struct rkisp_isp_params_vdev params_vdev; 191 struct rkisp_dmarx_device dmarx_dev; 192 struct rkisp_csi_device csi_dev; 193 struct rkisp_bridge_device br_dev; 194 struct rkisp_luma_vdev luma_vdev; 195 struct proc_dir_entry *procfs; 196 struct rkisp_pipeline pipe; 197 enum rkisp_isp_ver isp_ver; 198 struct rkisp_emd_data emd_data_fifo[RKISP_EMDDATA_FIFO_MAX]; 199 unsigned int emd_data_idx; 200 unsigned int emd_vc; 201 unsigned int emd_dt; 202 int vs_irq; 203 struct gpio_desc *vs_irq_gpio; 204 struct rkisp_hdr hdr; 205 unsigned int isp_state; 206 unsigned int isp_err_cnt; 207 unsigned int isp_isr_cnt; 208 unsigned int isp_inp; 209 struct mutex apilock; /* mutex to serialize the calls of stream */ 210 struct mutex iqlock; /* mutex to serialize the calls of iq */ 211 wait_queue_head_t sync_onoff; 212 dma_addr_t resmem_addr; 213 phys_addr_t resmem_pa; 214 size_t resmem_size; 215 int dev_id; 216 unsigned int skip_frame; 217 unsigned int irq_ends; 218 unsigned int irq_ends_mask; 219 bool send_fbcgain; 220 struct rkisp_ispp_buf *cur_fbcgain; 221 struct rkisp_buffer *cur_spbuf; 222 223 struct kfifo rdbk_kfifo; 224 spinlock_t rdbk_lock; 225 int rdbk_cnt; 226 int rdbk_cnt_x1; 227 int rdbk_cnt_x2; 228 int rdbk_cnt_x3; 229 u32 rd_mode; 230 u8 filt_state[RDBK_F_MAX]; 231 232 struct rkisp_rx_buf_pool pv_pool[RKISP_RX_BUF_POOL_MAX]; 233 234 spinlock_t cmsk_lock; 235 struct rkisp_cmsk_cfg cmsk_cfg; 236 bool is_cmsk_upd; 237 }; 238 #endif 239