1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Support for Medifield PNW Camera Imaging ISP subsystem. 4 * 5 * Copyright (c) 2010 Intel Corporation. All Rights Reserved. 6 * 7 * Copyright (c) 2010 Silicon Hive www.siliconhive.com. 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License version 11 * 2 as published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * 19 */ 20 #ifndef __ATOMISP_INTERNAL_H__ 21 #define __ATOMISP_INTERNAL_H__ 22 23 #include "../../include/linux/atomisp_platform.h" 24 #include <linux/firmware.h> 25 #include <linux/kernel.h> 26 #include <linux/pm_qos.h> 27 #include <linux/idr.h> 28 29 #include <media/media-device.h> 30 #include <media/v4l2-async.h> 31 #include <media/v4l2-subdev.h> 32 33 /* ISP2400*/ 34 #include "ia_css_types.h" 35 #include "sh_css_legacy.h" 36 37 #include "atomisp_csi2.h" 38 #include "atomisp_subdev.h" 39 #include "atomisp_compat.h" 40 41 #include "gp_device.h" 42 #include "irq.h" 43 #include <linux/vmalloc.h> 44 45 #define V4L2_EVENT_FRAME_END 5 46 47 #define IS_HWREVISION(isp, rev) \ 48 (((isp)->media_dev.hw_revision & ATOMISP_HW_REVISION_MASK) == \ 49 ((rev) << ATOMISP_HW_REVISION_SHIFT)) 50 51 #define ATOMISP_PCI_DEVICE_SOC_BYT 0x0f38 52 /* MRFLD with 0x1178: ISP freq can burst to 457MHz */ 53 #define ATOMISP_PCI_DEVICE_SOC_MRFLD 0x1178 54 /* MRFLD with 0x1179: max ISP freq limited to 400MHz */ 55 #define ATOMISP_PCI_DEVICE_SOC_MRFLD_1179 0x1179 56 /* MRFLD with 0x117a: max ISP freq is 400MHz and max freq at Vmin is 200MHz */ 57 #define ATOMISP_PCI_DEVICE_SOC_MRFLD_117A 0x117a 58 #define ATOMISP_PCI_DEVICE_SOC_ANN 0x1478 59 #define ATOMISP_PCI_DEVICE_SOC_CHT 0x22b8 60 61 #define ATOMISP_PCI_REV_MRFLD_A0_MAX 0 62 #define ATOMISP_PCI_REV_BYT_A0_MAX 4 63 64 #define ATOM_ISP_STEP_WIDTH 2 65 #define ATOM_ISP_STEP_HEIGHT 2 66 67 #define ATOM_ISP_MIN_WIDTH 4 68 #define ATOM_ISP_MIN_HEIGHT 4 69 #define ATOM_ISP_MAX_WIDTH UINT_MAX 70 #define ATOM_ISP_MAX_HEIGHT UINT_MAX 71 72 /* sub-QCIF resolution */ 73 #define ATOM_RESOLUTION_SUBQCIF_WIDTH 128 74 #define ATOM_RESOLUTION_SUBQCIF_HEIGHT 96 75 76 #define ATOM_ISP_I2C_BUS_1 4 77 #define ATOM_ISP_I2C_BUS_2 5 78 79 #define ATOM_ISP_POWER_DOWN 0 80 #define ATOM_ISP_POWER_UP 1 81 82 #define ATOM_ISP_MAX_INPUTS 3 83 84 #define ATOMISP_SC_TYPE_SIZE 2 85 86 #define ATOMISP_ISP_TIMEOUT_DURATION (2 * HZ) 87 #define ATOMISP_EXT_ISP_TIMEOUT_DURATION (6 * HZ) 88 #define ATOMISP_WDT_KEEP_CURRENT_DELAY 0 89 #define ATOMISP_ISP_MAX_TIMEOUT_COUNT 2 90 #define ATOMISP_CSS_STOP_TIMEOUT_US 200000 91 92 #define ATOMISP_CSS_Q_DEPTH 3 93 #define ATOMISP_CSS_EVENTS_MAX 16 94 #define ATOMISP_CONT_RAW_FRAMES 15 95 #define ATOMISP_METADATA_QUEUE_DEPTH_FOR_HAL 8 96 #define ATOMISP_S3A_BUF_QUEUE_DEPTH_FOR_HAL 8 97 98 /* 99 * Define how fast CPU should be able to serve ISP interrupts. 100 * The bigger the value, the higher risk that the ISP is not 101 * triggered sufficiently fast for it to process image during 102 * vertical blanking time, increasing risk of dropped frames. 103 * 1000 us is a reasonable value considering that the processing 104 * time is typically ~2000 us. 105 */ 106 #define ATOMISP_MAX_ISR_LATENCY 1000 107 108 /* Add new YUVPP pipe for SOC sensor. */ 109 #define ATOMISP_CSS_SUPPORT_YUVPP 1 110 111 #define ATOMISP_CSS_OUTPUT_SECOND_INDEX 1 112 #define ATOMISP_CSS_OUTPUT_DEFAULT_INDEX 0 113 114 /* ISP2401 */ 115 #define ATOMISP_ION_DEVICE_FD_OFFSET 16 116 #define ATOMISP_ION_SHARED_FD_MASK (0xFFFF) 117 #define ATOMISP_ION_DEVICE_FD_MASK (~ATOMISP_ION_SHARED_FD_MASK) 118 #define ION_FD_UNSET (-1) 119 120 #define DIV_NEAREST_STEP(n, d, step) \ 121 round_down((2 * (n) + (d) * (step)) / (2 * (d)), (step)) 122 123 struct atomisp_input_subdev { 124 enum atomisp_camera_port port; 125 u32 code; /* MEDIA_BUS_FMT_* */ 126 bool binning_support; 127 bool crop_support; 128 bool camera_on; 129 struct v4l2_subdev *camera; 130 struct v4l2_subdev *csi_port; 131 /* Sensor rects for sensors which support crop */ 132 struct v4l2_rect native_rect; 133 struct v4l2_rect active_rect; 134 /* Sensor state for which == V4L2_SUBDEV_FORMAT_TRY calls */ 135 struct v4l2_subdev_state *try_sd_state; 136 }; 137 138 enum atomisp_dfs_mode { 139 ATOMISP_DFS_MODE_AUTO = 0, 140 ATOMISP_DFS_MODE_LOW, 141 ATOMISP_DFS_MODE_MAX, 142 }; 143 144 struct atomisp_regs { 145 /* PCI config space info */ 146 u16 pcicmdsts; 147 u32 ispmmadr; 148 u32 msicap; 149 u32 msi_addr; 150 u16 msi_data; 151 u8 intr; 152 u32 interrupt_control; 153 u32 pmcs; 154 u32 cg_dis; 155 u32 i_control; 156 157 /* I-Unit PHY related info */ 158 u32 csi_rcomp_config; 159 u32 csi_afe_dly; 160 u32 csi_control; 161 162 /* New for MRFLD */ 163 u32 csi_afe_rcomp_config; 164 u32 csi_afe_hs_control; 165 u32 csi_deadline_control; 166 u32 csi_access_viol; 167 }; 168 169 /* 170 * ci device struct 171 */ 172 struct atomisp_device { 173 struct device *dev; 174 struct v4l2_device v4l2_dev; 175 struct media_device media_dev; 176 struct atomisp_sub_device asd; 177 struct v4l2_async_notifier notifier; 178 void *mmu_l1_base; 179 void __iomem *base; 180 const struct firmware *firmware; 181 182 struct dev_pm_domain pm_domain; 183 struct pm_qos_request pm_qos; 184 s32 max_isr_latency; 185 bool pm_only; 186 187 struct atomisp_mipi_csi2_device csi2_port[ATOMISP_CAMERA_NR_PORTS]; 188 189 /* Purpose of mutex is to protect and serialize use of isp data 190 * structures and css API calls. */ 191 struct mutex mutex; 192 193 /* 194 * Number of lanes used by each sensor per port. 195 * Note this is indexed by mipi_port_id not atomisp_camera_port. 196 */ 197 int sensor_lanes[N_MIPI_PORT_ID]; 198 struct v4l2_subdev *sensor_subdevs[ATOMISP_CAMERA_NR_PORTS]; 199 unsigned int input_cnt; 200 struct atomisp_input_subdev inputs[ATOM_ISP_MAX_INPUTS]; 201 202 struct atomisp_regs saved_regs; 203 struct atomisp_css_env css_env; 204 205 bool isp_fatal_error; 206 struct work_struct assert_recovery_work; 207 208 spinlock_t lock; /* Protects asd.streaming */ 209 210 const struct atomisp_dfs_config *dfs; 211 unsigned int hpll_freq; 212 unsigned int running_freq; 213 214 bool css_initialized; 215 }; 216 217 #define v4l2_dev_to_atomisp_device(dev) \ 218 container_of(dev, struct atomisp_device, v4l2_dev) 219 220 extern struct device *atomisp_dev; 221 222 #endif /* __ATOMISP_INTERNAL_H__ */ 223