Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _CAM_SENSOR_CMN_HEADER_ |
| 14 | #define _CAM_SENSOR_CMN_HEADER_ |
| 15 | |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/timer.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <media/cam_sensor.h> |
| 24 | #include <media/cam_req_mgr.h> |
| 25 | |
| 26 | #define MAX_REGULATOR 5 |
| 27 | #define MAX_POWER_CONFIG 12 |
| 28 | |
| 29 | #define MAX_PER_FRAME_ARRAY 8 |
| 30 | |
| 31 | #define CAM_SENSOR_NAME "cam-sensor" |
| 32 | #define CAM_ACTUATOR_NAME "cam-actuator" |
| 33 | #define CAM_CSIPHY_NAME "cam-csiphy" |
Jigarkumar Zala | 3522627 | 2017-04-19 16:05:24 -0700 | [diff] [blame] | 34 | #define CAM_FLASH_NAME "cam-flash" |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 35 | #define CAM_EEPROM_NAME "cam-eeprom" |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 36 | |
| 37 | #define MAX_SYSTEM_PIPELINE_DELAY 2 |
| 38 | |
| 39 | #define CAM_PKT_NOP_OPCODE 127 |
| 40 | |
| 41 | enum camera_sensor_cmd_type { |
| 42 | CAMERA_SENSOR_CMD_TYPE_INVALID, |
| 43 | CAMERA_SENSOR_CMD_TYPE_PROBE, |
| 44 | CAMERA_SENSOR_CMD_TYPE_PWR_UP, |
| 45 | CAMERA_SENSOR_CMD_TYPE_PWR_DOWN, |
| 46 | CAMERA_SENSOR_CMD_TYPE_I2C_INFO, |
| 47 | CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_WR, |
| 48 | CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_RD, |
| 49 | CAMERA_SENSOR_CMD_TYPE_I2C_CONT_WR, |
| 50 | CAMERA_SENSOR_CMD_TYPE_I2C_CONT_RD, |
| 51 | CAMERA_SENSOR_CMD_TYPE_WAIT, |
Jigarkumar Zala | 3522627 | 2017-04-19 16:05:24 -0700 | [diff] [blame] | 52 | CAMERA_SENSOR_FLASH_CMD_TYPE_INIT, |
| 53 | CAMERA_SENSOR_FLASH_CMD_TYPE_FIRE, |
| 54 | CAMERA_SENSOR_FLASH_CMD_TYPE_RER, |
| 55 | CAMERA_SENSOR_FLASH_CMD_TYPE_QUERYCURR, |
| 56 | CAMERA_SENSOR_FLASH_CMD_TYPE_WIDGET, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 57 | CAMERA_SENSOR_CMD_TYPE_MAX, |
| 58 | }; |
| 59 | |
| 60 | enum camera_sensor_i2c_op_code { |
| 61 | CAMERA_SENSOR_I2C_OP_INVALID, |
| 62 | CAMERA_SENSOR_I2C_OP_RNDM_WR, |
| 63 | CAMERA_SENSOR_I2C_OP_RNDM_WR_VERF, |
| 64 | CAMERA_SENSOR_I2C_OP_CONT_WR_BRST, |
| 65 | CAMERA_SENSOR_I2C_OP_CONT_WR_BRST_VERF, |
| 66 | CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN, |
| 67 | CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN_VERF, |
| 68 | CAMERA_SENSOR_I2C_OP_MAX, |
| 69 | }; |
| 70 | |
| 71 | enum camera_sensor_wait_op_code { |
| 72 | CAMERA_SENSOR_WAIT_OP_INVALID, |
| 73 | CAMERA_SENSOR_WAIT_OP_COND, |
| 74 | CAMERA_SENSOR_WAIT_OP_HW_UCND, |
| 75 | CAMERA_SENSOR_WAIT_OP_SW_UCND, |
| 76 | CAMERA_SENSOR_WAIT_OP_MAX, |
| 77 | }; |
| 78 | |
Jigarkumar Zala | 3522627 | 2017-04-19 16:05:24 -0700 | [diff] [blame] | 79 | enum camera_flash_opcode { |
| 80 | CAMERA_SENSOR_FLASH_OP_INVALID, |
| 81 | CAMERA_SENSOR_FLASH_OP_OFF, |
| 82 | CAMERA_SENSOR_FLASH_OP_FIRELOW, |
| 83 | CAMERA_SENSOR_FLASH_OP_FIREHIGH, |
| 84 | CAMERA_SENSOR_FLASH_OP_MAX, |
| 85 | }; |
| 86 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 87 | enum camera_sensor_i2c_type { |
| 88 | CAMERA_SENSOR_I2C_TYPE_INVALID, |
| 89 | CAMERA_SENSOR_I2C_TYPE_BYTE, |
| 90 | CAMERA_SENSOR_I2C_TYPE_WORD, |
| 91 | CAMERA_SENSOR_I2C_TYPE_3B, |
| 92 | CAMERA_SENSOR_I2C_TYPE_DWORD, |
| 93 | CAMERA_SENSOR_I2C_TYPE_MAX, |
| 94 | }; |
| 95 | |
| 96 | enum i2c_freq_mode { |
| 97 | I2C_STANDARD_MODE, |
| 98 | I2C_FAST_MODE, |
| 99 | I2C_CUSTOM_MODE, |
| 100 | I2C_FAST_PLUS_MODE, |
| 101 | I2C_MAX_MODES, |
| 102 | }; |
| 103 | |
| 104 | enum position_roll { |
| 105 | ROLL_0 = 0, |
| 106 | ROLL_90 = 90, |
| 107 | ROLL_180 = 180, |
| 108 | ROLL_270 = 270, |
| 109 | ROLL_INVALID = 360, |
| 110 | }; |
| 111 | |
| 112 | enum position_yaw { |
| 113 | FRONT_CAMERA_YAW = 0, |
| 114 | REAR_CAMERA_YAW = 180, |
| 115 | INVALID_YAW = 360, |
| 116 | }; |
| 117 | |
| 118 | enum position_pitch { |
| 119 | LEVEL_PITCH = 0, |
| 120 | INVALID_PITCH = 360, |
| 121 | }; |
| 122 | |
| 123 | enum sensor_sub_module { |
| 124 | SUB_MODULE_SENSOR, |
| 125 | SUB_MODULE_ACTUATOR, |
| 126 | SUB_MODULE_EEPROM, |
| 127 | SUB_MODULE_LED_FLASH, |
| 128 | SUB_MODULE_CSID, |
| 129 | SUB_MODULE_CSIPHY, |
| 130 | SUB_MODULE_OIS, |
| 131 | SUB_MODULE_EXT, |
| 132 | SUB_MODULE_MAX, |
| 133 | }; |
| 134 | |
| 135 | enum msm_camera_power_seq_type { |
| 136 | SENSOR_MCLK, |
| 137 | SENSOR_VANA, |
| 138 | SENSOR_VDIG, |
| 139 | SENSOR_VIO, |
| 140 | SENSOR_VAF, |
| 141 | SENSOR_VAF_PWDM, |
| 142 | SENSOR_CUSTOM_REG1, |
| 143 | SENSOR_CUSTOM_REG2, |
| 144 | SENSOR_RESET, |
| 145 | SENSOR_STANDBY, |
| 146 | SENSOR_CUSTOM_GPIO1, |
| 147 | SENSOR_CUSTOM_GPIO2, |
| 148 | SENSOR_SEQ_TYPE_MAX, |
| 149 | }; |
| 150 | |
| 151 | enum cam_sensor_packet_opcodes { |
| 152 | CAM_SENSOR_PACKET_OPCODE_SENSOR_STREAMON, |
| 153 | CAM_SENSOR_PACKET_OPCODE_SENSOR_UPDATE, |
| 154 | CAM_SENSOR_PACKET_OPCODE_SENSOR_INITIAL_CONFIG, |
| 155 | CAM_SENSOR_PACKET_OPCODE_SENSOR_PROBE |
| 156 | }; |
| 157 | |
| 158 | enum cam_actuator_packet_opcodes { |
| 159 | CAM_ACTUATOR_PACKET_OPCODE_INIT, |
| 160 | CAM_ACTUATOR_PACKET_AUTO_MOVE_LENS, |
| 161 | CAM_ACTUATOR_PACKET_MANUAL_MOVE_LENS |
| 162 | }; |
| 163 | |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 164 | enum cam_eeprom_packet_opcodes { |
| 165 | CAM_EEPROM_PACKET_OPCODE_INIT |
| 166 | }; |
| 167 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 168 | enum msm_bus_perf_setting { |
| 169 | S_INIT, |
| 170 | S_PREVIEW, |
| 171 | S_VIDEO, |
| 172 | S_CAPTURE, |
| 173 | S_ZSL, |
| 174 | S_STEREO_VIDEO, |
| 175 | S_STEREO_CAPTURE, |
| 176 | S_DEFAULT, |
| 177 | S_LIVESHOT, |
| 178 | S_DUAL, |
| 179 | S_EXIT |
| 180 | }; |
| 181 | |
| 182 | enum msm_camera_device_type_t { |
| 183 | MSM_CAMERA_I2C_DEVICE, |
| 184 | MSM_CAMERA_PLATFORM_DEVICE, |
| 185 | MSM_CAMERA_SPI_DEVICE, |
| 186 | }; |
| 187 | |
Jigarkumar Zala | 3522627 | 2017-04-19 16:05:24 -0700 | [diff] [blame] | 188 | enum cam_flash_device_type { |
| 189 | CAMERA_FLASH_DEVICE_TYPE_PMIC = 0, |
| 190 | CAMERA_FLASH_DEVICE_TYPE_I2C, |
| 191 | CAMERA_FLASH_DEVICE_TYPE_GPIO, |
| 192 | }; |
| 193 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 194 | enum cci_i2c_master_t { |
| 195 | MASTER_0, |
| 196 | MASTER_1, |
| 197 | MASTER_MAX, |
| 198 | }; |
| 199 | |
| 200 | enum camera_vreg_type { |
| 201 | VREG_TYPE_DEFAULT, |
| 202 | VREG_TYPE_CUSTOM, |
| 203 | }; |
| 204 | |
| 205 | enum cam_sensor_i2c_cmd_type { |
| 206 | CAM_SENSOR_I2C_WRITE_RANDOM, |
| 207 | CAM_SENSOR_I2C_READ, |
| 208 | CAM_SENSOR_I2C_POLL |
| 209 | }; |
| 210 | |
| 211 | struct common_header { |
| 212 | uint16_t first_word; |
| 213 | uint8_t third_byte; |
| 214 | uint8_t cmd_type; |
| 215 | }; |
| 216 | |
| 217 | struct camera_vreg_t { |
| 218 | const char *reg_name; |
| 219 | int min_voltage; |
| 220 | int max_voltage; |
| 221 | int op_mode; |
| 222 | uint32_t delay; |
| 223 | const char *custom_vreg_name; |
| 224 | enum camera_vreg_type type; |
| 225 | }; |
| 226 | |
| 227 | struct cam_sensor_module_power_setting { |
| 228 | enum msm_camera_power_seq_type seq_type; |
| 229 | unsigned short seq_val; |
| 230 | uint32_t config_val_low; |
| 231 | uint32_t config_val_high; |
| 232 | unsigned short delay; |
| 233 | }; |
| 234 | |
| 235 | struct msm_camera_gpio_num_info { |
| 236 | uint16_t gpio_num[SENSOR_SEQ_TYPE_MAX]; |
| 237 | uint8_t valid[SENSOR_SEQ_TYPE_MAX]; |
| 238 | }; |
| 239 | |
| 240 | struct msm_cam_clk_info { |
| 241 | const char *clk_name; |
| 242 | long clk_rate; |
| 243 | uint32_t delay; |
| 244 | }; |
| 245 | |
| 246 | struct msm_pinctrl_info { |
| 247 | struct pinctrl *pinctrl; |
| 248 | struct pinctrl_state *gpio_state_active; |
| 249 | struct pinctrl_state *gpio_state_suspend; |
| 250 | bool use_pinctrl; |
| 251 | }; |
| 252 | |
| 253 | struct cam_sensor_i2c_reg_array { |
| 254 | uint32_t reg_addr; |
| 255 | uint32_t reg_data; |
| 256 | uint32_t delay; |
| 257 | uint32_t data_mask; |
| 258 | }; |
| 259 | |
| 260 | struct cam_sensor_i2c_reg_setting { |
| 261 | struct cam_sensor_i2c_reg_array *reg_setting; |
| 262 | unsigned short size; |
| 263 | enum camera_sensor_i2c_type addr_type; |
| 264 | enum camera_sensor_i2c_type data_type; |
| 265 | unsigned short delay; |
| 266 | }; |
| 267 | |
| 268 | struct i2c_settings_list { |
| 269 | struct cam_sensor_i2c_reg_setting i2c_settings; |
| 270 | enum cam_sensor_i2c_cmd_type op_code; |
| 271 | struct list_head list; |
| 272 | }; |
| 273 | |
| 274 | struct i2c_settings_array { |
| 275 | struct list_head list_head; |
| 276 | int32_t is_settings_valid; |
| 277 | int64_t request_id; |
| 278 | }; |
| 279 | |
| 280 | struct i2c_data_settings { |
| 281 | struct i2c_settings_array init_settings; |
| 282 | struct i2c_settings_array *per_frame; |
| 283 | }; |
| 284 | |
| 285 | struct cam_sensor_power_ctrl_t { |
| 286 | struct device *dev; |
| 287 | struct cam_sensor_power_setting *power_setting; |
| 288 | uint16_t power_setting_size; |
| 289 | struct cam_sensor_power_setting *power_down_setting; |
| 290 | uint16_t power_down_setting_size; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 291 | struct msm_camera_gpio_num_info *gpio_num_info; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 292 | struct msm_pinctrl_info pinctrl_info; |
| 293 | uint8_t cam_pinctrl_status; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | struct cam_camera_slave_info { |
| 297 | uint16_t sensor_slave_addr; |
| 298 | uint16_t sensor_id_reg_addr; |
| 299 | uint16_t sensor_id; |
| 300 | uint16_t sensor_id_mask; |
| 301 | }; |
| 302 | |
| 303 | struct msm_sensor_init_params { |
| 304 | int modes_supported; |
| 305 | unsigned int sensor_mount_angle; |
| 306 | }; |
| 307 | |
| 308 | enum msm_sensor_camera_id_t { |
| 309 | CAMERA_0, |
| 310 | CAMERA_1, |
| 311 | CAMERA_2, |
| 312 | CAMERA_3, |
| 313 | MAX_CAMERAS, |
| 314 | }; |
| 315 | |
| 316 | struct msm_sensor_id_info_t { |
| 317 | unsigned short sensor_id_reg_addr; |
| 318 | unsigned short sensor_id; |
| 319 | unsigned short sensor_id_mask; |
| 320 | }; |
| 321 | |
| 322 | enum msm_sensor_output_format_t { |
| 323 | MSM_SENSOR_BAYER, |
| 324 | MSM_SENSOR_YCBCR, |
| 325 | MSM_SENSOR_META, |
| 326 | }; |
| 327 | |
| 328 | struct cam_sensor_power_setting { |
| 329 | enum msm_camera_power_seq_type seq_type; |
| 330 | unsigned short seq_val; |
| 331 | long config_val; |
| 332 | unsigned short delay; |
| 333 | void *data[10]; |
| 334 | }; |
| 335 | |
| 336 | struct cam_sensor_power_setting_array { |
| 337 | struct cam_sensor_power_setting power_setting_a[MAX_POWER_CONFIG]; |
| 338 | struct cam_sensor_power_setting *power_setting; |
| 339 | unsigned short size; |
| 340 | struct cam_sensor_power_setting power_down_setting_a[MAX_POWER_CONFIG]; |
| 341 | struct cam_sensor_power_setting *power_down_setting; |
| 342 | unsigned short size_down; |
| 343 | }; |
| 344 | |
| 345 | struct msm_camera_sensor_slave_info { |
| 346 | enum msm_sensor_camera_id_t camera_id; |
| 347 | unsigned short slave_addr; |
| 348 | enum i2c_freq_mode i2c_freq_mode; |
| 349 | enum camera_sensor_i2c_type addr_type; |
| 350 | struct msm_sensor_id_info_t sensor_id_info; |
| 351 | struct cam_sensor_power_setting_array power_setting_array; |
| 352 | unsigned char is_init_params_valid; |
| 353 | enum msm_sensor_output_format_t output_format; |
| 354 | }; |
| 355 | |
| 356 | struct cam_sensor_board_info { |
| 357 | struct cam_camera_slave_info slave_info; |
| 358 | int32_t sensor_mount_angle; |
| 359 | int32_t secure_mode; |
| 360 | int modes_supported; |
| 361 | int32_t pos_roll; |
| 362 | int32_t pos_yaw; |
| 363 | int32_t pos_pitch; |
| 364 | int32_t subdev_id[SUB_MODULE_MAX]; |
| 365 | int32_t subdev_intf[SUB_MODULE_MAX]; |
| 366 | const char *misc_regulator; |
| 367 | struct cam_sensor_power_ctrl_t power_info; |
| 368 | }; |
| 369 | |
| 370 | enum msm_camera_vreg_name_t { |
| 371 | CAM_VDIG, |
| 372 | CAM_VIO, |
| 373 | CAM_VANA, |
| 374 | CAM_VAF, |
| 375 | CAM_V_CUSTOM1, |
| 376 | CAM_V_CUSTOM2, |
| 377 | CAM_VREG_MAX, |
| 378 | }; |
| 379 | |
| 380 | struct msm_camera_gpio_conf { |
| 381 | void *cam_gpiomux_conf_tbl; |
| 382 | uint8_t cam_gpiomux_conf_tbl_size; |
| 383 | struct gpio *cam_gpio_common_tbl; |
| 384 | uint8_t cam_gpio_common_tbl_size; |
| 385 | struct gpio *cam_gpio_req_tbl; |
| 386 | uint8_t cam_gpio_req_tbl_size; |
| 387 | uint32_t gpio_no_mux; |
| 388 | uint32_t *camera_off_table; |
| 389 | uint8_t camera_off_table_size; |
| 390 | uint32_t *camera_on_table; |
| 391 | uint8_t camera_on_table_size; |
| 392 | struct msm_camera_gpio_num_info *gpio_num_info; |
| 393 | }; |
| 394 | |
| 395 | #endif /* _CAM_SENSOR_CMN_HEADER_ */ |