Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include "cam_sensor_util.h" |
Jigarkumar Zala | 5b016ad | 2019-08-09 12:56:12 -0700 | [diff] [blame] | 8 | #include "cam_mem_mgr.h" |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 9 | #include "cam_res_mgr_api.h" |
| 10 | |
| 11 | #define CAM_SENSOR_PINCTRL_STATE_SLEEP "cam_suspend" |
| 12 | #define CAM_SENSOR_PINCTRL_STATE_DEFAULT "cam_default" |
| 13 | |
| 14 | #define VALIDATE_VOLTAGE(min, max, config_val) ((config_val) && \ |
| 15 | (config_val >= min) && (config_val <= max)) |
| 16 | |
| 17 | static struct i2c_settings_list* |
| 18 | cam_sensor_get_i2c_ptr(struct i2c_settings_array *i2c_reg_settings, |
| 19 | uint32_t size) |
| 20 | { |
| 21 | struct i2c_settings_list *tmp; |
| 22 | |
| 23 | tmp = kzalloc(sizeof(struct i2c_settings_list), GFP_KERNEL); |
| 24 | |
| 25 | if (tmp != NULL) |
| 26 | list_add_tail(&(tmp->list), |
| 27 | &(i2c_reg_settings->list_head)); |
| 28 | else |
| 29 | return NULL; |
| 30 | |
| 31 | tmp->i2c_settings.reg_setting = (struct cam_sensor_i2c_reg_array *) |
| 32 | vzalloc(size * sizeof(struct cam_sensor_i2c_reg_array)); |
| 33 | if (tmp->i2c_settings.reg_setting == NULL) { |
| 34 | list_del(&(tmp->list)); |
| 35 | kfree(tmp); |
| 36 | return NULL; |
| 37 | } |
| 38 | tmp->i2c_settings.size = size; |
| 39 | |
| 40 | return tmp; |
| 41 | } |
| 42 | |
| 43 | int32_t delete_request(struct i2c_settings_array *i2c_array) |
| 44 | { |
| 45 | struct i2c_settings_list *i2c_list = NULL, *i2c_next = NULL; |
| 46 | int32_t rc = 0; |
| 47 | |
| 48 | if (i2c_array == NULL) { |
| 49 | CAM_ERR(CAM_SENSOR, "FATAL:: Invalid argument"); |
| 50 | return -EINVAL; |
| 51 | } |
| 52 | |
| 53 | list_for_each_entry_safe(i2c_list, i2c_next, |
| 54 | &(i2c_array->list_head), list) { |
| 55 | vfree(i2c_list->i2c_settings.reg_setting); |
| 56 | list_del(&(i2c_list->list)); |
| 57 | kfree(i2c_list); |
| 58 | } |
| 59 | INIT_LIST_HEAD(&(i2c_array->list_head)); |
| 60 | i2c_array->is_settings_valid = 0; |
| 61 | |
| 62 | return rc; |
| 63 | } |
| 64 | |
| 65 | int32_t cam_sensor_handle_delay( |
| 66 | uint32_t **cmd_buf, |
| 67 | uint16_t generic_op_code, |
| 68 | struct i2c_settings_array *i2c_reg_settings, |
| 69 | uint32_t offset, uint32_t *byte_cnt, |
| 70 | struct list_head *list_ptr) |
| 71 | { |
| 72 | int32_t rc = 0; |
| 73 | struct cam_cmd_unconditional_wait *cmd_uncond_wait = |
| 74 | (struct cam_cmd_unconditional_wait *) *cmd_buf; |
| 75 | struct i2c_settings_list *i2c_list = NULL; |
| 76 | |
| 77 | if (list_ptr == NULL) { |
| 78 | CAM_ERR(CAM_SENSOR, "Invalid list ptr"); |
| 79 | return -EINVAL; |
| 80 | } |
| 81 | |
| 82 | if (offset > 0) { |
| 83 | i2c_list = |
| 84 | list_entry(list_ptr, struct i2c_settings_list, list); |
| 85 | if (generic_op_code == |
| 86 | CAMERA_SENSOR_WAIT_OP_HW_UCND) |
| 87 | i2c_list->i2c_settings.reg_setting[offset - 1].delay = |
| 88 | cmd_uncond_wait->delay; |
| 89 | else |
| 90 | i2c_list->i2c_settings.delay = cmd_uncond_wait->delay; |
| 91 | (*cmd_buf) += |
| 92 | sizeof( |
| 93 | struct cam_cmd_unconditional_wait) / sizeof(uint32_t); |
| 94 | (*byte_cnt) += |
| 95 | sizeof( |
| 96 | struct cam_cmd_unconditional_wait); |
| 97 | } else { |
| 98 | CAM_ERR(CAM_SENSOR, "Delay Rxed Before any buffer: %d", offset); |
| 99 | return -EINVAL; |
| 100 | } |
| 101 | |
| 102 | return rc; |
| 103 | } |
| 104 | |
| 105 | int32_t cam_sensor_handle_poll( |
| 106 | uint32_t **cmd_buf, |
| 107 | struct i2c_settings_array *i2c_reg_settings, |
| 108 | uint32_t *byte_cnt, int32_t *offset, |
| 109 | struct list_head **list_ptr) |
| 110 | { |
| 111 | struct i2c_settings_list *i2c_list; |
| 112 | int32_t rc = 0; |
| 113 | struct cam_cmd_conditional_wait *cond_wait |
| 114 | = (struct cam_cmd_conditional_wait *) *cmd_buf; |
| 115 | |
| 116 | i2c_list = |
| 117 | cam_sensor_get_i2c_ptr(i2c_reg_settings, 1); |
| 118 | if (!i2c_list || !i2c_list->i2c_settings.reg_setting) { |
| 119 | CAM_ERR(CAM_SENSOR, "Failed in allocating mem for list"); |
| 120 | return -ENOMEM; |
| 121 | } |
| 122 | |
| 123 | i2c_list->op_code = CAM_SENSOR_I2C_POLL; |
| 124 | i2c_list->i2c_settings.data_type = |
| 125 | cond_wait->data_type; |
| 126 | i2c_list->i2c_settings.addr_type = |
| 127 | cond_wait->addr_type; |
| 128 | i2c_list->i2c_settings.reg_setting->reg_addr = |
| 129 | cond_wait->reg_addr; |
| 130 | i2c_list->i2c_settings.reg_setting->reg_data = |
| 131 | cond_wait->reg_data; |
| 132 | i2c_list->i2c_settings.reg_setting->delay = |
| 133 | cond_wait->timeout; |
| 134 | |
| 135 | (*cmd_buf) += sizeof(struct cam_cmd_conditional_wait) / |
| 136 | sizeof(uint32_t); |
| 137 | (*byte_cnt) += sizeof(struct cam_cmd_conditional_wait); |
| 138 | |
| 139 | *offset = 1; |
| 140 | *list_ptr = &(i2c_list->list); |
| 141 | |
| 142 | return rc; |
| 143 | } |
| 144 | |
| 145 | int32_t cam_sensor_handle_random_write( |
| 146 | struct cam_cmd_i2c_random_wr *cam_cmd_i2c_random_wr, |
| 147 | struct i2c_settings_array *i2c_reg_settings, |
| 148 | uint32_t *cmd_length_in_bytes, int32_t *offset, |
| 149 | struct list_head **list) |
| 150 | { |
| 151 | struct i2c_settings_list *i2c_list; |
| 152 | int32_t rc = 0, cnt; |
| 153 | |
| 154 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 155 | cam_cmd_i2c_random_wr->header.count); |
| 156 | if (i2c_list == NULL || |
| 157 | i2c_list->i2c_settings.reg_setting == NULL) { |
| 158 | CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list"); |
| 159 | return -ENOMEM; |
| 160 | } |
| 161 | |
| 162 | *cmd_length_in_bytes = (sizeof(struct i2c_rdwr_header) + |
| 163 | sizeof(struct i2c_random_wr_payload) * |
| 164 | (cam_cmd_i2c_random_wr->header.count)); |
| 165 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_RANDOM; |
| 166 | i2c_list->i2c_settings.addr_type = |
| 167 | cam_cmd_i2c_random_wr->header.addr_type; |
| 168 | i2c_list->i2c_settings.data_type = |
| 169 | cam_cmd_i2c_random_wr->header.data_type; |
| 170 | |
| 171 | for (cnt = 0; cnt < (cam_cmd_i2c_random_wr->header.count); |
| 172 | cnt++) { |
| 173 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 174 | cam_cmd_i2c_random_wr->random_wr_payload[cnt].reg_addr; |
| 175 | i2c_list->i2c_settings.reg_setting[cnt].reg_data = |
| 176 | cam_cmd_i2c_random_wr->random_wr_payload[cnt].reg_data; |
| 177 | i2c_list->i2c_settings.reg_setting[cnt].data_mask = 0; |
| 178 | } |
| 179 | *offset = cnt; |
| 180 | *list = &(i2c_list->list); |
| 181 | |
| 182 | return rc; |
| 183 | } |
| 184 | |
| 185 | static int32_t cam_sensor_handle_continuous_write( |
| 186 | struct cam_cmd_i2c_continuous_wr *cam_cmd_i2c_continuous_wr, |
| 187 | struct i2c_settings_array *i2c_reg_settings, |
| 188 | uint32_t *cmd_length_in_bytes, int32_t *offset, |
| 189 | struct list_head **list) |
| 190 | { |
| 191 | struct i2c_settings_list *i2c_list; |
| 192 | int32_t rc = 0, cnt; |
| 193 | |
| 194 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 195 | cam_cmd_i2c_continuous_wr->header.count); |
| 196 | if (i2c_list == NULL || |
| 197 | i2c_list->i2c_settings.reg_setting == NULL) { |
| 198 | CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list"); |
| 199 | return -ENOMEM; |
| 200 | } |
| 201 | |
| 202 | *cmd_length_in_bytes = (sizeof(struct i2c_rdwr_header) + |
| 203 | sizeof(cam_cmd_i2c_continuous_wr->reg_addr) + |
| 204 | sizeof(struct cam_cmd_read) * |
| 205 | (cam_cmd_i2c_continuous_wr->header.count)); |
| 206 | if (cam_cmd_i2c_continuous_wr->header.op_code == |
| 207 | CAMERA_SENSOR_I2C_OP_CONT_WR_BRST) |
| 208 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_BURST; |
| 209 | else if (cam_cmd_i2c_continuous_wr->header.op_code == |
| 210 | CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN) |
| 211 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_SEQ; |
| 212 | else |
| 213 | return -EINVAL; |
| 214 | |
| 215 | i2c_list->i2c_settings.addr_type = |
| 216 | cam_cmd_i2c_continuous_wr->header.addr_type; |
| 217 | i2c_list->i2c_settings.data_type = |
| 218 | cam_cmd_i2c_continuous_wr->header.data_type; |
| 219 | i2c_list->i2c_settings.size = |
| 220 | cam_cmd_i2c_continuous_wr->header.count; |
| 221 | |
| 222 | for (cnt = 0; cnt < (cam_cmd_i2c_continuous_wr->header.count); |
| 223 | cnt++) { |
| 224 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 225 | cam_cmd_i2c_continuous_wr->reg_addr; |
| 226 | i2c_list->i2c_settings.reg_setting[cnt].reg_data = |
| 227 | cam_cmd_i2c_continuous_wr->data_read[cnt].reg_data; |
| 228 | i2c_list->i2c_settings.reg_setting[cnt].data_mask = 0; |
| 229 | } |
| 230 | *offset = cnt; |
| 231 | *list = &(i2c_list->list); |
| 232 | |
| 233 | return rc; |
| 234 | } |
| 235 | |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 236 | static int32_t cam_sensor_get_io_buffer( |
| 237 | struct cam_buf_io_cfg *io_cfg, |
| 238 | struct cam_sensor_i2c_reg_setting *i2c_settings) |
| 239 | { |
| 240 | uintptr_t buf_addr = 0x0; |
| 241 | size_t buf_size = 0; |
| 242 | int32_t rc = 0; |
| 243 | |
Shravan Nevatia | d59ca83 | 2019-12-03 21:39:28 +0530 | [diff] [blame] | 244 | if (io_cfg == NULL || i2c_settings == NULL) { |
| 245 | CAM_ERR(CAM_SENSOR, |
| 246 | "Invalid args, io buf or i2c settings is NULL"); |
| 247 | return -EINVAL; |
| 248 | } |
| 249 | |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 250 | if (io_cfg->direction == CAM_BUF_OUTPUT) { |
| 251 | rc = cam_mem_get_cpu_buf(io_cfg->mem_handle[0], |
| 252 | &buf_addr, &buf_size); |
| 253 | if ((rc < 0) || (!buf_addr)) { |
| 254 | CAM_ERR(CAM_SENSOR, |
| 255 | "invalid buffer, rc: %d, buf_addr: %pK", |
| 256 | rc, buf_addr); |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | CAM_DBG(CAM_SENSOR, |
| 260 | "buf_addr: %pK, buf_size: %zu, offsetsize: %d", |
| 261 | (void *)buf_addr, buf_size, io_cfg->offsets[0]); |
| 262 | if (io_cfg->offsets[0] >= buf_size) { |
| 263 | CAM_ERR(CAM_SENSOR, |
| 264 | "invalid size:io_cfg->offsets[0]: %d, buf_size: %d", |
| 265 | io_cfg->offsets[0], buf_size); |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | i2c_settings->read_buff = |
| 269 | (uint8_t *)buf_addr + io_cfg->offsets[0]; |
| 270 | i2c_settings->read_buff_len = |
| 271 | buf_size - io_cfg->offsets[0]; |
| 272 | } else { |
| 273 | CAM_ERR(CAM_SENSOR, "Invalid direction: %d", |
| 274 | io_cfg->direction); |
| 275 | rc = -EINVAL; |
| 276 | } |
| 277 | return rc; |
| 278 | } |
| 279 | |
| 280 | static int32_t cam_sensor_handle_random_read( |
| 281 | struct cam_cmd_i2c_random_rd *cmd_i2c_random_rd, |
| 282 | struct i2c_settings_array *i2c_reg_settings, |
| 283 | uint16_t *cmd_length_in_bytes, |
| 284 | int32_t *offset, |
| 285 | struct list_head **list, |
| 286 | struct cam_buf_io_cfg *io_cfg) |
| 287 | { |
| 288 | struct i2c_settings_list *i2c_list; |
| 289 | int32_t rc = 0, cnt = 0; |
| 290 | |
| 291 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 292 | cmd_i2c_random_rd->header.count); |
| 293 | if ((i2c_list == NULL) || |
| 294 | (i2c_list->i2c_settings.reg_setting == NULL)) { |
| 295 | CAM_ERR(CAM_SENSOR, |
| 296 | "Failed in allocating i2c_list: %pK", |
| 297 | i2c_list); |
| 298 | return -ENOMEM; |
| 299 | } |
| 300 | |
| 301 | rc = cam_sensor_get_io_buffer(io_cfg, &(i2c_list->i2c_settings)); |
| 302 | if (rc) { |
| 303 | CAM_ERR(CAM_SENSOR, "Failed to get read buffer: %d", rc); |
| 304 | } else { |
| 305 | *cmd_length_in_bytes = sizeof(struct i2c_rdwr_header) + |
| 306 | (sizeof(struct cam_cmd_read) * |
| 307 | (cmd_i2c_random_rd->header.count)); |
| 308 | i2c_list->op_code = CAM_SENSOR_I2C_READ_RANDOM; |
| 309 | i2c_list->i2c_settings.addr_type = |
| 310 | cmd_i2c_random_rd->header.addr_type; |
| 311 | i2c_list->i2c_settings.data_type = |
| 312 | cmd_i2c_random_rd->header.data_type; |
| 313 | i2c_list->i2c_settings.size = |
| 314 | cmd_i2c_random_rd->header.count; |
| 315 | |
| 316 | for (cnt = 0; cnt < (cmd_i2c_random_rd->header.count); |
| 317 | cnt++) { |
| 318 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 319 | cmd_i2c_random_rd->data_read[cnt].reg_data; |
| 320 | } |
| 321 | *offset = cnt; |
| 322 | *list = &(i2c_list->list); |
| 323 | } |
| 324 | |
| 325 | return rc; |
| 326 | } |
| 327 | |
| 328 | static int32_t cam_sensor_handle_continuous_read( |
| 329 | struct cam_cmd_i2c_continuous_rd *cmd_i2c_continuous_rd, |
| 330 | struct i2c_settings_array *i2c_reg_settings, |
| 331 | uint16_t *cmd_length_in_bytes, int32_t *offset, |
| 332 | struct list_head **list, |
| 333 | struct cam_buf_io_cfg *io_cfg) |
| 334 | { |
| 335 | struct i2c_settings_list *i2c_list; |
| 336 | int32_t rc = 0, cnt = 0; |
| 337 | |
| 338 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, 1); |
| 339 | if ((i2c_list == NULL) || |
| 340 | (i2c_list->i2c_settings.reg_setting == NULL)) { |
| 341 | CAM_ERR(CAM_SENSOR, |
| 342 | "Failed in allocating i2c_list: %pK", |
| 343 | i2c_list); |
| 344 | return -ENOMEM; |
| 345 | } |
| 346 | |
| 347 | rc = cam_sensor_get_io_buffer(io_cfg, &(i2c_list->i2c_settings)); |
| 348 | if (rc) { |
| 349 | CAM_ERR(CAM_SENSOR, "Failed to get read buffer: %d", rc); |
| 350 | } else { |
| 351 | *cmd_length_in_bytes = sizeof(struct cam_cmd_i2c_continuous_rd); |
| 352 | i2c_list->op_code = CAM_SENSOR_I2C_READ_SEQ; |
| 353 | |
| 354 | i2c_list->i2c_settings.addr_type = |
| 355 | cmd_i2c_continuous_rd->header.addr_type; |
| 356 | i2c_list->i2c_settings.data_type = |
| 357 | cmd_i2c_continuous_rd->header.data_type; |
| 358 | i2c_list->i2c_settings.size = |
| 359 | cmd_i2c_continuous_rd->header.count; |
| 360 | i2c_list->i2c_settings.reg_setting[0].reg_addr = |
| 361 | cmd_i2c_continuous_rd->reg_addr; |
| 362 | |
| 363 | *offset = cnt; |
| 364 | *list = &(i2c_list->list); |
| 365 | } |
| 366 | |
| 367 | return rc; |
| 368 | } |
| 369 | |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 370 | static int cam_sensor_handle_slave_info( |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 371 | uint32_t *cmd_buf, |
| 372 | struct i2c_settings_array *i2c_reg_settings, |
| 373 | struct list_head **list_ptr) |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 374 | { |
| 375 | int rc = 0; |
| 376 | struct cam_cmd_i2c_info *i2c_info = (struct cam_cmd_i2c_info *)cmd_buf; |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 377 | struct i2c_settings_list *i2c_list; |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 378 | |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 379 | i2c_list = |
| 380 | cam_sensor_get_i2c_ptr(i2c_reg_settings, 1); |
| 381 | if (!i2c_list || !i2c_list->i2c_settings.reg_setting) { |
| 382 | CAM_ERR(CAM_SENSOR, "Failed in allocating mem for list"); |
| 383 | return -ENOMEM; |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 386 | i2c_list->op_code = CAM_SENSOR_I2C_SET_I2C_INFO; |
| 387 | i2c_list->slave_info = *i2c_info; |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 388 | |
| 389 | return rc; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Name : cam_sensor_i2c_command_parser |
| 394 | * Description : Parse CSL CCI packet and apply register settings |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 395 | * Parameters : io_master input master information |
| 396 | * i2c_reg_settings output register settings to fill |
| 397 | * cmd_desc input command description |
| 398 | * num_cmd_buffers input number of command buffers to process |
| 399 | * io_cfg input buffer details for read operation only |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 400 | * Description : |
| 401 | * Handle multiple I2C RD/WR and WAIT cmd formats in one command |
| 402 | * buffer, for example, a command buffer of m x RND_WR + 1 x HW_ |
| 403 | * WAIT + n x RND_WR with num_cmd_buf = 1. Do not exepect RD/WR |
| 404 | * with different cmd_type and op_code in one command buffer. |
| 405 | */ |
| 406 | int cam_sensor_i2c_command_parser( |
| 407 | struct camera_io_master *io_master, |
| 408 | struct i2c_settings_array *i2c_reg_settings, |
| 409 | struct cam_cmd_buf_desc *cmd_desc, |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 410 | int32_t num_cmd_buffers, |
| 411 | struct cam_buf_io_cfg *io_cfg) |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 412 | { |
| 413 | int16_t rc = 0, i = 0; |
| 414 | size_t len_of_buff = 0; |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 415 | uintptr_t generic_ptr; |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 416 | uint16_t cmd_length_in_bytes = 0; |
| 417 | size_t remain_len = 0; |
| 418 | size_t tot_size = 0; |
| 419 | |
| 420 | for (i = 0; i < num_cmd_buffers; i++) { |
| 421 | uint32_t *cmd_buf = NULL; |
| 422 | struct common_header *cmm_hdr; |
| 423 | uint16_t generic_op_code; |
| 424 | uint32_t byte_cnt = 0; |
| 425 | uint32_t j = 0; |
| 426 | struct list_head *list = NULL; |
| 427 | |
| 428 | /* |
| 429 | * It is not expected the same settings to |
| 430 | * be spread across multiple cmd buffers |
| 431 | */ |
| 432 | CAM_DBG(CAM_SENSOR, "Total cmd Buf in Bytes: %d", |
| 433 | cmd_desc[i].length); |
| 434 | |
| 435 | if (!cmd_desc[i].length) |
| 436 | continue; |
| 437 | |
| 438 | rc = cam_mem_get_cpu_buf(cmd_desc[i].mem_handle, |
| 439 | &generic_ptr, &len_of_buff); |
| 440 | if (rc < 0) { |
| 441 | CAM_ERR(CAM_SENSOR, |
| 442 | "cmd hdl failed:%d, Err: %d, Buffer_len: %zd", |
| 443 | cmd_desc[i].mem_handle, rc, len_of_buff); |
| 444 | return rc; |
| 445 | } |
| 446 | |
| 447 | remain_len = len_of_buff; |
| 448 | if ((len_of_buff < sizeof(struct common_header)) || |
| 449 | (cmd_desc[i].offset > |
| 450 | (len_of_buff - sizeof(struct common_header)))) { |
| 451 | CAM_ERR(CAM_SENSOR, "buffer provided too small"); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | cmd_buf = (uint32_t *)generic_ptr; |
| 455 | cmd_buf += cmd_desc[i].offset / sizeof(uint32_t); |
| 456 | |
| 457 | remain_len -= cmd_desc[i].offset; |
| 458 | if (remain_len < cmd_desc[i].length) { |
| 459 | CAM_ERR(CAM_SENSOR, "buffer provided too small"); |
| 460 | return -EINVAL; |
| 461 | } |
| 462 | |
| 463 | while (byte_cnt < cmd_desc[i].length) { |
| 464 | if ((remain_len - byte_cnt) < |
| 465 | sizeof(struct common_header)) { |
| 466 | CAM_ERR(CAM_SENSOR, "Not enough buffer"); |
| 467 | rc = -EINVAL; |
| 468 | goto end; |
| 469 | } |
| 470 | cmm_hdr = (struct common_header *)cmd_buf; |
| 471 | generic_op_code = cmm_hdr->fifth_byte; |
| 472 | switch (cmm_hdr->cmd_type) { |
| 473 | case CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_WR: { |
| 474 | uint32_t cmd_length_in_bytes = 0; |
| 475 | struct cam_cmd_i2c_random_wr |
| 476 | *cam_cmd_i2c_random_wr = |
| 477 | (struct cam_cmd_i2c_random_wr *)cmd_buf; |
| 478 | |
| 479 | if ((remain_len - byte_cnt) < |
| 480 | sizeof(struct cam_cmd_i2c_random_wr)) { |
| 481 | CAM_ERR(CAM_SENSOR, |
| 482 | "Not enough buffer provided"); |
| 483 | rc = -EINVAL; |
| 484 | goto end; |
| 485 | } |
| 486 | tot_size = sizeof(struct i2c_rdwr_header) + |
| 487 | (sizeof(struct i2c_random_wr_payload) * |
| 488 | cam_cmd_i2c_random_wr->header.count); |
| 489 | |
| 490 | if (tot_size > (remain_len - byte_cnt)) { |
| 491 | CAM_ERR(CAM_SENSOR, |
| 492 | "Not enough buffer provided"); |
| 493 | rc = -EINVAL; |
| 494 | goto end; |
| 495 | } |
| 496 | |
| 497 | rc = cam_sensor_handle_random_write( |
| 498 | cam_cmd_i2c_random_wr, |
| 499 | i2c_reg_settings, |
| 500 | &cmd_length_in_bytes, &j, &list); |
| 501 | if (rc < 0) { |
| 502 | CAM_ERR(CAM_SENSOR, |
| 503 | "Failed in random write %d", rc); |
| 504 | rc = -EINVAL; |
| 505 | goto end; |
| 506 | } |
| 507 | |
| 508 | cmd_buf += cmd_length_in_bytes / |
| 509 | sizeof(uint32_t); |
| 510 | byte_cnt += cmd_length_in_bytes; |
| 511 | break; |
| 512 | } |
| 513 | case CAMERA_SENSOR_CMD_TYPE_I2C_CONT_WR: { |
| 514 | uint32_t cmd_length_in_bytes = 0; |
| 515 | struct cam_cmd_i2c_continuous_wr |
| 516 | *cam_cmd_i2c_continuous_wr = |
| 517 | (struct cam_cmd_i2c_continuous_wr *) |
| 518 | cmd_buf; |
| 519 | |
| 520 | if ((remain_len - byte_cnt) < |
| 521 | sizeof(struct cam_cmd_i2c_continuous_wr)) { |
| 522 | CAM_ERR(CAM_SENSOR, |
| 523 | "Not enough buffer provided"); |
| 524 | rc = -EINVAL; |
| 525 | goto end; |
| 526 | } |
| 527 | |
| 528 | tot_size = sizeof(struct i2c_rdwr_header) + |
| 529 | sizeof(cam_cmd_i2c_continuous_wr->reg_addr) + |
| 530 | (sizeof(struct cam_cmd_read) * |
| 531 | cam_cmd_i2c_continuous_wr->header.count); |
| 532 | |
| 533 | if (tot_size > (remain_len - byte_cnt)) { |
| 534 | CAM_ERR(CAM_SENSOR, |
| 535 | "Not enough buffer provided"); |
| 536 | rc = -EINVAL; |
| 537 | goto end; |
| 538 | } |
| 539 | |
| 540 | rc = cam_sensor_handle_continuous_write( |
| 541 | cam_cmd_i2c_continuous_wr, |
| 542 | i2c_reg_settings, |
| 543 | &cmd_length_in_bytes, &j, &list); |
| 544 | if (rc < 0) { |
| 545 | CAM_ERR(CAM_SENSOR, |
| 546 | "Failed in continuous write %d", rc); |
| 547 | goto end; |
| 548 | } |
| 549 | |
| 550 | cmd_buf += cmd_length_in_bytes / |
| 551 | sizeof(uint32_t); |
| 552 | byte_cnt += cmd_length_in_bytes; |
| 553 | break; |
| 554 | } |
| 555 | case CAMERA_SENSOR_CMD_TYPE_WAIT: { |
| 556 | if ((remain_len - byte_cnt) < |
| 557 | sizeof(struct cam_cmd_unconditional_wait)) { |
| 558 | CAM_ERR(CAM_SENSOR, |
| 559 | "Not enough buffer space"); |
| 560 | rc = -EINVAL; |
| 561 | goto end; |
| 562 | } |
| 563 | if (generic_op_code == |
| 564 | CAMERA_SENSOR_WAIT_OP_HW_UCND || |
| 565 | generic_op_code == |
| 566 | CAMERA_SENSOR_WAIT_OP_SW_UCND) { |
| 567 | rc = cam_sensor_handle_delay( |
| 568 | &cmd_buf, generic_op_code, |
| 569 | i2c_reg_settings, j, &byte_cnt, |
| 570 | list); |
| 571 | if (rc < 0) { |
| 572 | CAM_ERR(CAM_SENSOR, |
| 573 | "delay hdl failed: %d", |
| 574 | rc); |
| 575 | goto end; |
| 576 | } |
| 577 | |
| 578 | } else if (generic_op_code == |
| 579 | CAMERA_SENSOR_WAIT_OP_COND) { |
| 580 | rc = cam_sensor_handle_poll( |
| 581 | &cmd_buf, i2c_reg_settings, |
| 582 | &byte_cnt, &j, &list); |
| 583 | if (rc < 0) { |
| 584 | CAM_ERR(CAM_SENSOR, |
| 585 | "Random read fail: %d", |
| 586 | rc); |
| 587 | goto end; |
| 588 | } |
| 589 | } else { |
| 590 | CAM_ERR(CAM_SENSOR, |
| 591 | "Wrong Wait Command: %d", |
| 592 | generic_op_code); |
| 593 | rc = -EINVAL; |
| 594 | goto end; |
| 595 | } |
| 596 | break; |
| 597 | } |
| 598 | case CAMERA_SENSOR_CMD_TYPE_I2C_INFO: { |
| 599 | if (remain_len - byte_cnt < |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 600 | sizeof(struct cam_cmd_i2c_info)) { |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 601 | CAM_ERR(CAM_SENSOR, |
| 602 | "Not enough buffer space"); |
| 603 | rc = -EINVAL; |
| 604 | goto end; |
| 605 | } |
| 606 | rc = cam_sensor_handle_slave_info( |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 607 | cmd_buf, i2c_reg_settings, &list); |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 608 | if (rc) { |
| 609 | CAM_ERR(CAM_SENSOR, |
| 610 | "Handle slave info failed with rc: %d", |
| 611 | rc); |
| 612 | goto end; |
| 613 | } |
| 614 | cmd_length_in_bytes = |
| 615 | sizeof(struct cam_cmd_i2c_info); |
| 616 | cmd_buf += |
| 617 | cmd_length_in_bytes / sizeof(uint32_t); |
| 618 | byte_cnt += cmd_length_in_bytes; |
| 619 | break; |
| 620 | } |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 621 | case CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_RD: { |
| 622 | uint16_t cmd_length_in_bytes = 0; |
| 623 | struct cam_cmd_i2c_random_rd *i2c_random_rd = |
| 624 | (struct cam_cmd_i2c_random_rd *)cmd_buf; |
| 625 | |
| 626 | if (remain_len - byte_cnt < |
| 627 | sizeof(struct cam_cmd_i2c_random_rd)) { |
| 628 | CAM_ERR(CAM_SENSOR, |
| 629 | "Not enough buffer space"); |
| 630 | rc = -EINVAL; |
| 631 | goto end; |
| 632 | } |
| 633 | |
| 634 | tot_size = sizeof(struct i2c_rdwr_header) + |
| 635 | (sizeof(struct cam_cmd_read) * |
| 636 | i2c_random_rd->header.count); |
| 637 | |
| 638 | if (tot_size > (remain_len - byte_cnt)) { |
| 639 | CAM_ERR(CAM_SENSOR, |
| 640 | "Not enough buffer provided %d, %d, %d", |
| 641 | tot_size, remain_len, byte_cnt); |
| 642 | rc = -EINVAL; |
| 643 | goto end; |
| 644 | } |
| 645 | |
| 646 | rc = cam_sensor_handle_random_read( |
| 647 | i2c_random_rd, |
| 648 | i2c_reg_settings, |
| 649 | &cmd_length_in_bytes, &j, &list, |
| 650 | io_cfg); |
| 651 | if (rc < 0) { |
| 652 | CAM_ERR(CAM_SENSOR, |
| 653 | "Failed in random read %d", rc); |
| 654 | goto end; |
| 655 | } |
| 656 | |
| 657 | cmd_buf += cmd_length_in_bytes / |
| 658 | sizeof(uint32_t); |
| 659 | byte_cnt += cmd_length_in_bytes; |
| 660 | break; |
| 661 | } |
| 662 | case CAMERA_SENSOR_CMD_TYPE_I2C_CONT_RD: { |
| 663 | uint16_t cmd_length_in_bytes = 0; |
| 664 | struct cam_cmd_i2c_continuous_rd |
| 665 | *i2c_continuous_rd = |
| 666 | (struct cam_cmd_i2c_continuous_rd *)cmd_buf; |
| 667 | |
| 668 | if (remain_len - byte_cnt < |
| 669 | sizeof(struct cam_cmd_i2c_continuous_rd)) { |
| 670 | CAM_ERR(CAM_SENSOR, |
| 671 | "Not enough buffer space"); |
| 672 | rc = -EINVAL; |
| 673 | goto end; |
| 674 | } |
| 675 | |
| 676 | tot_size = |
| 677 | sizeof(struct cam_cmd_i2c_continuous_rd); |
| 678 | |
| 679 | if (tot_size > (remain_len - byte_cnt)) { |
| 680 | CAM_ERR(CAM_SENSOR, |
| 681 | "Not enough buffer provided %d, %d, %d", |
| 682 | tot_size, remain_len, byte_cnt); |
| 683 | rc = -EINVAL; |
| 684 | goto end; |
| 685 | } |
| 686 | |
| 687 | rc = cam_sensor_handle_continuous_read( |
| 688 | i2c_continuous_rd, |
| 689 | i2c_reg_settings, |
| 690 | &cmd_length_in_bytes, &j, &list, |
| 691 | io_cfg); |
| 692 | if (rc < 0) { |
| 693 | CAM_ERR(CAM_SENSOR, |
| 694 | "Failed in continuous read %d", rc); |
| 695 | goto end; |
| 696 | } |
| 697 | |
| 698 | cmd_buf += cmd_length_in_bytes / |
| 699 | sizeof(uint32_t); |
| 700 | byte_cnt += cmd_length_in_bytes; |
| 701 | break; |
| 702 | } |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 703 | default: |
| 704 | CAM_ERR(CAM_SENSOR, "Invalid Command Type:%d", |
| 705 | cmm_hdr->cmd_type); |
| 706 | rc = -EINVAL; |
| 707 | goto end; |
| 708 | } |
| 709 | } |
| 710 | i2c_reg_settings->is_settings_valid = 1; |
| 711 | } |
| 712 | |
| 713 | end: |
| 714 | return rc; |
| 715 | } |
| 716 | |
| 717 | int cam_sensor_util_i2c_apply_setting( |
| 718 | struct camera_io_master *io_master_info, |
| 719 | struct i2c_settings_list *i2c_list) |
| 720 | { |
| 721 | int32_t rc = 0; |
| 722 | uint32_t i, size; |
| 723 | |
| 724 | switch (i2c_list->op_code) { |
| 725 | case CAM_SENSOR_I2C_WRITE_RANDOM: { |
| 726 | rc = camera_io_dev_write(io_master_info, |
| 727 | &(i2c_list->i2c_settings)); |
| 728 | if (rc < 0) { |
| 729 | CAM_ERR(CAM_SENSOR, |
| 730 | "Failed to random write I2C settings: %d", |
| 731 | rc); |
| 732 | return rc; |
| 733 | } |
| 734 | break; |
| 735 | } |
| 736 | case CAM_SENSOR_I2C_WRITE_SEQ: { |
| 737 | rc = camera_io_dev_write_continuous( |
| 738 | io_master_info, &(i2c_list->i2c_settings), 0); |
| 739 | if (rc < 0) { |
| 740 | CAM_ERR(CAM_SENSOR, |
| 741 | "Failed to seq write I2C settings: %d", |
| 742 | rc); |
| 743 | return rc; |
| 744 | } |
| 745 | break; |
| 746 | } |
| 747 | case CAM_SENSOR_I2C_WRITE_BURST: { |
| 748 | rc = camera_io_dev_write_continuous( |
| 749 | io_master_info, &(i2c_list->i2c_settings), 1); |
| 750 | if (rc < 0) { |
| 751 | CAM_ERR(CAM_SENSOR, |
| 752 | "Failed to burst write I2C settings: %d", |
| 753 | rc); |
| 754 | return rc; |
| 755 | } |
| 756 | break; |
| 757 | } |
| 758 | case CAM_SENSOR_I2C_POLL: { |
| 759 | size = i2c_list->i2c_settings.size; |
| 760 | for (i = 0; i < size; i++) { |
| 761 | rc = camera_io_dev_poll( |
| 762 | io_master_info, |
| 763 | i2c_list->i2c_settings.reg_setting[i].reg_addr, |
| 764 | i2c_list->i2c_settings.reg_setting[i].reg_data, |
| 765 | i2c_list->i2c_settings.reg_setting[i].data_mask, |
| 766 | i2c_list->i2c_settings.addr_type, |
| 767 | i2c_list->i2c_settings.data_type, |
| 768 | i2c_list->i2c_settings.reg_setting[i].delay); |
| 769 | if (rc < 0) { |
| 770 | CAM_ERR(CAM_SENSOR, |
| 771 | "i2c poll apply setting Fail: %d", rc); |
| 772 | return rc; |
| 773 | } |
| 774 | } |
| 775 | break; |
| 776 | } |
| 777 | default: |
| 778 | CAM_ERR(CAM_SENSOR, "Wrong Opcode: %d", i2c_list->op_code); |
| 779 | rc = -EINVAL; |
| 780 | break; |
| 781 | } |
| 782 | |
| 783 | return rc; |
| 784 | } |
| 785 | |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 786 | int32_t cam_sensor_i2c_read_data( |
| 787 | struct i2c_settings_array *i2c_settings, |
| 788 | struct camera_io_master *io_master_info) |
| 789 | { |
| 790 | int32_t rc = 0; |
| 791 | struct i2c_settings_list *i2c_list; |
| 792 | uint32_t cnt = 0; |
| 793 | uint8_t *read_buff = NULL; |
| 794 | uint32_t buff_length = 0; |
| 795 | uint32_t read_length = 0; |
| 796 | |
| 797 | list_for_each_entry(i2c_list, |
| 798 | &(i2c_settings->list_head), list) { |
Zhaohong Chen | 9591ccf | 2020-03-30 02:22:15 +0800 | [diff] [blame] | 799 | if (i2c_list->op_code == CAM_SENSOR_I2C_SET_I2C_INFO) { |
| 800 | CAM_DBG(CAM_SENSOR, |
| 801 | "CAM_SENSOR_I2C_SET_I2C_INFO continue"); |
| 802 | continue; |
| 803 | } |
| 804 | |
Sureshnaidu Laveti | 50e8323 | 2019-11-18 14:00:11 -0800 | [diff] [blame] | 805 | read_buff = i2c_list->i2c_settings.read_buff; |
| 806 | buff_length = i2c_list->i2c_settings.read_buff_len; |
| 807 | if ((read_buff == NULL) || (buff_length == 0)) { |
| 808 | CAM_ERR(CAM_SENSOR, |
| 809 | "Invalid input buffer, buffer: %pK, length: %d", |
| 810 | read_buff, buff_length); |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | |
| 814 | if (i2c_list->op_code == CAM_SENSOR_I2C_READ_RANDOM) { |
| 815 | read_length = i2c_list->i2c_settings.data_type * |
| 816 | i2c_list->i2c_settings.size; |
| 817 | if ((read_length > buff_length) || |
| 818 | (read_length < i2c_list->i2c_settings.size)) { |
| 819 | CAM_ERR(CAM_SENSOR, |
| 820 | "Invalid size, readLen:%d, bufLen:%d, size: %d", |
| 821 | read_length, buff_length, |
| 822 | i2c_list->i2c_settings.size); |
| 823 | return -EINVAL; |
| 824 | } |
| 825 | for (cnt = 0; cnt < (i2c_list->i2c_settings.size); |
| 826 | cnt++) { |
| 827 | struct cam_sensor_i2c_reg_array *reg_setting = |
| 828 | &(i2c_list->i2c_settings.reg_setting[cnt]); |
| 829 | rc = camera_io_dev_read(io_master_info, |
| 830 | reg_setting->reg_addr, |
| 831 | ®_setting->reg_data, |
| 832 | i2c_list->i2c_settings.addr_type, |
| 833 | i2c_list->i2c_settings.data_type); |
| 834 | if (rc < 0) { |
| 835 | CAM_ERR(CAM_SENSOR, |
| 836 | "Failed: random read I2C settings: %d", |
| 837 | rc); |
| 838 | return rc; |
| 839 | } |
| 840 | if (i2c_list->i2c_settings.data_type < |
| 841 | CAMERA_SENSOR_I2C_TYPE_MAX) { |
| 842 | memcpy(read_buff, |
| 843 | ®_setting->reg_data, |
| 844 | i2c_list->i2c_settings.data_type); |
| 845 | read_buff += |
| 846 | i2c_list->i2c_settings.data_type; |
| 847 | } |
| 848 | } |
| 849 | } else if (i2c_list->op_code == CAM_SENSOR_I2C_READ_SEQ) { |
| 850 | read_length = i2c_list->i2c_settings.size; |
| 851 | if (read_length > buff_length) { |
| 852 | CAM_ERR(CAM_SENSOR, |
| 853 | "Invalid buffer size, readLen: %d, bufLen: %d", |
| 854 | read_length, buff_length); |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | rc = camera_io_dev_read_seq( |
| 858 | io_master_info, |
| 859 | i2c_list->i2c_settings.reg_setting[0].reg_addr, |
| 860 | read_buff, |
| 861 | i2c_list->i2c_settings.addr_type, |
| 862 | i2c_list->i2c_settings.data_type, |
| 863 | i2c_list->i2c_settings.size); |
| 864 | if (rc < 0) { |
| 865 | CAM_ERR(CAM_SENSOR, |
| 866 | "failed: seq read I2C settings: %d", |
| 867 | rc); |
| 868 | return rc; |
| 869 | } |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | return rc; |
| 874 | } |
| 875 | |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 876 | int32_t msm_camera_fill_vreg_params( |
| 877 | struct cam_hw_soc_info *soc_info, |
| 878 | struct cam_sensor_power_setting *power_setting, |
| 879 | uint16_t power_setting_size) |
| 880 | { |
| 881 | int32_t rc = 0, j = 0, i = 0; |
| 882 | int num_vreg; |
| 883 | |
| 884 | /* Validate input parameters */ |
| 885 | if (!soc_info || !power_setting) { |
| 886 | CAM_ERR(CAM_SENSOR, "failed: soc_info %pK power_setting %pK", |
| 887 | soc_info, power_setting); |
| 888 | return -EINVAL; |
| 889 | } |
| 890 | |
| 891 | num_vreg = soc_info->num_rgltr; |
| 892 | |
| 893 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
| 894 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | for (i = 0; i < power_setting_size; i++) { |
| 899 | |
| 900 | if (power_setting[i].seq_type < SENSOR_MCLK || |
| 901 | power_setting[i].seq_type >= SENSOR_SEQ_TYPE_MAX) { |
| 902 | CAM_ERR(CAM_SENSOR, "failed: Invalid Seq type: %d", |
| 903 | power_setting[i].seq_type); |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | |
| 907 | switch (power_setting[i].seq_type) { |
| 908 | case SENSOR_VDIG: |
| 909 | for (j = 0; j < num_vreg; j++) { |
| 910 | if (!strcmp(soc_info->rgltr_name[j], |
| 911 | "cam_vdig")) { |
| 912 | |
| 913 | CAM_DBG(CAM_SENSOR, |
| 914 | "i: %d j: %d cam_vdig", i, j); |
| 915 | power_setting[i].seq_val = j; |
| 916 | |
| 917 | if (VALIDATE_VOLTAGE( |
| 918 | soc_info->rgltr_min_volt[j], |
| 919 | soc_info->rgltr_max_volt[j], |
| 920 | power_setting[i].config_val)) { |
| 921 | soc_info->rgltr_min_volt[j] = |
| 922 | soc_info->rgltr_max_volt[j] = |
| 923 | power_setting[i].config_val; |
| 924 | } |
| 925 | break; |
| 926 | } |
| 927 | } |
| 928 | if (j == num_vreg) |
| 929 | power_setting[i].seq_val = INVALID_VREG; |
| 930 | break; |
| 931 | |
| 932 | case SENSOR_VIO: |
| 933 | for (j = 0; j < num_vreg; j++) { |
| 934 | |
| 935 | if (!strcmp(soc_info->rgltr_name[j], |
| 936 | "cam_vio")) { |
| 937 | CAM_DBG(CAM_SENSOR, |
| 938 | "i: %d j: %d cam_vio", i, j); |
| 939 | power_setting[i].seq_val = j; |
| 940 | |
| 941 | if (VALIDATE_VOLTAGE( |
| 942 | soc_info->rgltr_min_volt[j], |
| 943 | soc_info->rgltr_max_volt[j], |
| 944 | power_setting[i].config_val)) { |
| 945 | soc_info->rgltr_min_volt[j] = |
| 946 | soc_info->rgltr_max_volt[j] = |
| 947 | power_setting[i].config_val; |
| 948 | } |
| 949 | break; |
| 950 | } |
| 951 | |
| 952 | } |
| 953 | if (j == num_vreg) |
| 954 | power_setting[i].seq_val = INVALID_VREG; |
| 955 | break; |
| 956 | |
| 957 | case SENSOR_VANA: |
| 958 | for (j = 0; j < num_vreg; j++) { |
| 959 | |
| 960 | if (!strcmp(soc_info->rgltr_name[j], |
| 961 | "cam_vana")) { |
| 962 | CAM_DBG(CAM_SENSOR, |
| 963 | "i: %d j: %d cam_vana", i, j); |
| 964 | power_setting[i].seq_val = j; |
| 965 | |
| 966 | if (VALIDATE_VOLTAGE( |
| 967 | soc_info->rgltr_min_volt[j], |
| 968 | soc_info->rgltr_max_volt[j], |
| 969 | power_setting[i].config_val)) { |
| 970 | soc_info->rgltr_min_volt[j] = |
| 971 | soc_info->rgltr_max_volt[j] = |
| 972 | power_setting[i].config_val; |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | |
| 977 | } |
| 978 | if (j == num_vreg) |
| 979 | power_setting[i].seq_val = INVALID_VREG; |
| 980 | break; |
| 981 | |
| 982 | case SENSOR_VAF: |
| 983 | for (j = 0; j < num_vreg; j++) { |
| 984 | |
| 985 | if (!strcmp(soc_info->rgltr_name[j], |
| 986 | "cam_vaf")) { |
| 987 | CAM_DBG(CAM_SENSOR, |
| 988 | "i: %d j: %d cam_vaf", i, j); |
| 989 | power_setting[i].seq_val = j; |
| 990 | |
| 991 | if (VALIDATE_VOLTAGE( |
| 992 | soc_info->rgltr_min_volt[j], |
| 993 | soc_info->rgltr_max_volt[j], |
| 994 | power_setting[i].config_val)) { |
| 995 | soc_info->rgltr_min_volt[j] = |
| 996 | soc_info->rgltr_max_volt[j] = |
| 997 | power_setting[i].config_val; |
| 998 | } |
| 999 | |
| 1000 | break; |
| 1001 | } |
| 1002 | |
| 1003 | } |
| 1004 | if (j == num_vreg) |
| 1005 | power_setting[i].seq_val = INVALID_VREG; |
| 1006 | break; |
| 1007 | |
| 1008 | case SENSOR_CUSTOM_REG1: |
| 1009 | for (j = 0; j < num_vreg; j++) { |
| 1010 | |
| 1011 | if (!strcmp(soc_info->rgltr_name[j], |
| 1012 | "cam_v_custom1")) { |
| 1013 | CAM_DBG(CAM_SENSOR, |
| 1014 | "i:%d j:%d cam_vcustom1", i, j); |
| 1015 | power_setting[i].seq_val = j; |
| 1016 | |
| 1017 | if (VALIDATE_VOLTAGE( |
| 1018 | soc_info->rgltr_min_volt[j], |
| 1019 | soc_info->rgltr_max_volt[j], |
| 1020 | power_setting[i].config_val)) { |
| 1021 | soc_info->rgltr_min_volt[j] = |
| 1022 | soc_info->rgltr_max_volt[j] = |
| 1023 | power_setting[i].config_val; |
| 1024 | } |
| 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | } |
| 1029 | if (j == num_vreg) |
| 1030 | power_setting[i].seq_val = INVALID_VREG; |
| 1031 | break; |
| 1032 | case SENSOR_CUSTOM_REG2: |
| 1033 | for (j = 0; j < num_vreg; j++) { |
| 1034 | |
| 1035 | if (!strcmp(soc_info->rgltr_name[j], |
| 1036 | "cam_v_custom2")) { |
| 1037 | CAM_DBG(CAM_SENSOR, |
| 1038 | "i:%d j:%d cam_vcustom2", i, j); |
| 1039 | power_setting[i].seq_val = j; |
| 1040 | |
| 1041 | if (VALIDATE_VOLTAGE( |
| 1042 | soc_info->rgltr_min_volt[j], |
| 1043 | soc_info->rgltr_max_volt[j], |
| 1044 | power_setting[i].config_val)) { |
| 1045 | soc_info->rgltr_min_volt[j] = |
| 1046 | soc_info->rgltr_max_volt[j] = |
| 1047 | power_setting[i].config_val; |
| 1048 | } |
| 1049 | break; |
| 1050 | } |
| 1051 | } |
| 1052 | if (j == num_vreg) |
| 1053 | power_setting[i].seq_val = INVALID_VREG; |
| 1054 | break; |
| 1055 | default: |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | return rc; |
| 1061 | } |
| 1062 | |
| 1063 | int cam_sensor_util_request_gpio_table( |
| 1064 | struct cam_hw_soc_info *soc_info, int gpio_en) |
| 1065 | { |
| 1066 | int rc = 0, i = 0; |
| 1067 | uint8_t size = 0; |
| 1068 | struct cam_soc_gpio_data *gpio_conf = |
| 1069 | soc_info->gpio_data; |
| 1070 | struct gpio *gpio_tbl = NULL; |
| 1071 | |
| 1072 | if (!gpio_conf) { |
| 1073 | CAM_INFO(CAM_SENSOR, "No GPIO data"); |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
| 1077 | if (gpio_conf->cam_gpio_common_tbl_size <= 0) { |
| 1078 | CAM_INFO(CAM_SENSOR, "No GPIO entry"); |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | |
| 1082 | gpio_tbl = gpio_conf->cam_gpio_req_tbl; |
| 1083 | size = gpio_conf->cam_gpio_req_tbl_size; |
| 1084 | |
| 1085 | if (!gpio_tbl || !size) { |
| 1086 | CAM_ERR(CAM_SENSOR, "invalid gpio_tbl %pK / size %d", |
| 1087 | gpio_tbl, size); |
| 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
| 1091 | for (i = 0; i < size; i++) { |
| 1092 | CAM_DBG(CAM_SENSOR, "i: %d, gpio %d dir %ld", i, |
| 1093 | gpio_tbl[i].gpio, gpio_tbl[i].flags); |
| 1094 | } |
| 1095 | |
| 1096 | if (gpio_en) { |
| 1097 | for (i = 0; i < size; i++) { |
| 1098 | rc = cam_res_mgr_gpio_request(soc_info->dev, |
| 1099 | gpio_tbl[i].gpio, |
| 1100 | gpio_tbl[i].flags, gpio_tbl[i].label); |
| 1101 | if (rc) { |
| 1102 | /* |
| 1103 | * After GPIO request fails, contine to |
| 1104 | * apply new gpios, outout a error message |
| 1105 | * for driver bringup debug |
| 1106 | */ |
| 1107 | CAM_ERR(CAM_SENSOR, "gpio %d:%s request fails", |
| 1108 | gpio_tbl[i].gpio, gpio_tbl[i].label); |
| 1109 | } |
| 1110 | } |
| 1111 | } else { |
| 1112 | cam_res_mgr_gpio_free_arry(soc_info->dev, gpio_tbl, size); |
| 1113 | } |
| 1114 | |
| 1115 | return rc; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | static int32_t cam_sensor_validate(void *ptr, size_t remain_buf) |
| 1120 | { |
| 1121 | struct common_header *cmm_hdr = (struct common_header *)ptr; |
| 1122 | size_t validate_size = 0; |
| 1123 | |
| 1124 | if (remain_buf < sizeof(struct common_header)) |
| 1125 | return -EINVAL; |
| 1126 | |
| 1127 | if (cmm_hdr->cmd_type == CAMERA_SENSOR_CMD_TYPE_PWR_UP || |
| 1128 | cmm_hdr->cmd_type == CAMERA_SENSOR_CMD_TYPE_PWR_DOWN) |
| 1129 | validate_size = sizeof(struct cam_cmd_power); |
| 1130 | else if (cmm_hdr->cmd_type == CAMERA_SENSOR_CMD_TYPE_WAIT) |
| 1131 | validate_size = sizeof(struct cam_cmd_unconditional_wait); |
| 1132 | |
| 1133 | if (remain_buf < validate_size) { |
| 1134 | CAM_ERR(CAM_SENSOR, "Invalid cmd_buf len %zu min %zu", |
| 1135 | remain_buf, validate_size); |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | int32_t cam_sensor_update_power_settings(void *cmd_buf, |
| 1142 | uint32_t cmd_length, struct cam_sensor_power_ctrl_t *power_info, |
| 1143 | size_t cmd_buf_len) |
| 1144 | { |
| 1145 | int32_t rc = 0, tot_size = 0, last_cmd_type = 0; |
| 1146 | int32_t i = 0, pwr_up = 0, pwr_down = 0; |
| 1147 | struct cam_sensor_power_setting *pwr_settings; |
| 1148 | void *ptr = cmd_buf, *scr; |
| 1149 | struct cam_cmd_power *pwr_cmd = (struct cam_cmd_power *)cmd_buf; |
| 1150 | struct common_header *cmm_hdr = (struct common_header *)cmd_buf; |
| 1151 | |
| 1152 | if (!pwr_cmd || !cmd_length || cmd_buf_len < (size_t)cmd_length || |
| 1153 | cam_sensor_validate(cmd_buf, cmd_buf_len)) { |
| 1154 | CAM_ERR(CAM_SENSOR, "Invalid Args: pwr_cmd %pK, cmd_length: %d", |
| 1155 | pwr_cmd, cmd_length); |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | |
| 1159 | power_info->power_setting_size = 0; |
| 1160 | power_info->power_setting = |
| 1161 | kzalloc(sizeof(struct cam_sensor_power_setting) * |
| 1162 | MAX_POWER_CONFIG, GFP_KERNEL); |
| 1163 | if (!power_info->power_setting) |
| 1164 | return -ENOMEM; |
| 1165 | |
| 1166 | power_info->power_down_setting_size = 0; |
| 1167 | power_info->power_down_setting = |
| 1168 | kzalloc(sizeof(struct cam_sensor_power_setting) * |
| 1169 | MAX_POWER_CONFIG, GFP_KERNEL); |
| 1170 | if (!power_info->power_down_setting) { |
| 1171 | kfree(power_info->power_setting); |
| 1172 | power_info->power_setting = NULL; |
| 1173 | power_info->power_setting_size = 0; |
| 1174 | return -ENOMEM; |
| 1175 | } |
| 1176 | |
| 1177 | while (tot_size < cmd_length) { |
| 1178 | if (cam_sensor_validate(ptr, (cmd_length - tot_size))) { |
| 1179 | rc = -EINVAL; |
| 1180 | goto free_power_settings; |
| 1181 | } |
| 1182 | if (cmm_hdr->cmd_type == |
| 1183 | CAMERA_SENSOR_CMD_TYPE_PWR_UP) { |
| 1184 | struct cam_cmd_power *pwr_cmd = |
| 1185 | (struct cam_cmd_power *)ptr; |
| 1186 | |
| 1187 | if ((U16_MAX - power_info->power_setting_size) < |
| 1188 | pwr_cmd->count) { |
| 1189 | CAM_ERR(CAM_SENSOR, "ERR: Overflow occurs"); |
| 1190 | rc = -EINVAL; |
| 1191 | goto free_power_settings; |
| 1192 | } |
| 1193 | |
| 1194 | power_info->power_setting_size += pwr_cmd->count; |
| 1195 | if ((power_info->power_setting_size > MAX_POWER_CONFIG) |
| 1196 | || (pwr_cmd->count >= SENSOR_SEQ_TYPE_MAX)) { |
| 1197 | CAM_ERR(CAM_SENSOR, |
| 1198 | "pwr_up setting size %d, pwr_cmd->count: %d", |
| 1199 | power_info->power_setting_size, |
| 1200 | pwr_cmd->count); |
| 1201 | rc = -EINVAL; |
| 1202 | goto free_power_settings; |
| 1203 | } |
| 1204 | scr = ptr + sizeof(struct cam_cmd_power); |
| 1205 | tot_size = tot_size + sizeof(struct cam_cmd_power); |
| 1206 | |
| 1207 | if (pwr_cmd->count == 0) |
| 1208 | CAM_WARN(CAM_SENSOR, "pwr_up_size is zero"); |
| 1209 | |
| 1210 | for (i = 0; i < pwr_cmd->count; i++, pwr_up++) { |
| 1211 | power_info->power_setting[pwr_up].seq_type = |
| 1212 | pwr_cmd->power_settings[i].power_seq_type; |
| 1213 | power_info->power_setting[pwr_up].config_val = |
| 1214 | pwr_cmd->power_settings[i].config_val_low; |
| 1215 | power_info->power_setting[pwr_up].delay = 0; |
| 1216 | if (i) { |
| 1217 | scr = scr + |
| 1218 | sizeof( |
| 1219 | struct cam_power_settings); |
| 1220 | tot_size = tot_size + |
| 1221 | sizeof( |
| 1222 | struct cam_power_settings); |
| 1223 | } |
| 1224 | if (tot_size > cmd_length) { |
| 1225 | CAM_ERR(CAM_SENSOR, |
| 1226 | "Error: Cmd Buffer is wrong"); |
| 1227 | rc = -EINVAL; |
| 1228 | goto free_power_settings; |
| 1229 | } |
| 1230 | CAM_DBG(CAM_SENSOR, |
| 1231 | "Seq Type[%d]: %d Config_val: %ld", pwr_up, |
| 1232 | power_info->power_setting[pwr_up].seq_type, |
| 1233 | power_info->power_setting[pwr_up].config_val); |
| 1234 | } |
| 1235 | last_cmd_type = CAMERA_SENSOR_CMD_TYPE_PWR_UP; |
| 1236 | ptr = (void *) scr; |
| 1237 | cmm_hdr = (struct common_header *)ptr; |
| 1238 | } else if (cmm_hdr->cmd_type == CAMERA_SENSOR_CMD_TYPE_WAIT) { |
| 1239 | struct cam_cmd_unconditional_wait *wait_cmd = |
| 1240 | (struct cam_cmd_unconditional_wait *)ptr; |
| 1241 | if ((wait_cmd->op_code == |
| 1242 | CAMERA_SENSOR_WAIT_OP_SW_UCND) && |
| 1243 | (last_cmd_type == |
| 1244 | CAMERA_SENSOR_CMD_TYPE_PWR_UP)) { |
| 1245 | if (pwr_up > 0) { |
| 1246 | pwr_settings = |
| 1247 | &power_info->power_setting[pwr_up - 1]; |
| 1248 | pwr_settings->delay += |
| 1249 | wait_cmd->delay; |
| 1250 | } else { |
| 1251 | CAM_ERR(CAM_SENSOR, |
| 1252 | "Delay is expected only after valid power up setting"); |
| 1253 | } |
| 1254 | } else if ((wait_cmd->op_code == |
| 1255 | CAMERA_SENSOR_WAIT_OP_SW_UCND) && |
| 1256 | (last_cmd_type == |
| 1257 | CAMERA_SENSOR_CMD_TYPE_PWR_DOWN)) { |
| 1258 | if (pwr_down > 0) { |
| 1259 | pwr_settings = |
| 1260 | &power_info->power_down_setting[ |
| 1261 | pwr_down - 1]; |
| 1262 | pwr_settings->delay += |
| 1263 | wait_cmd->delay; |
| 1264 | } else { |
| 1265 | CAM_ERR(CAM_SENSOR, |
| 1266 | "Delay is expected only after valid power up setting"); |
| 1267 | } |
| 1268 | } else { |
| 1269 | CAM_DBG(CAM_SENSOR, "Invalid op code: %d", |
| 1270 | wait_cmd->op_code); |
| 1271 | } |
| 1272 | |
| 1273 | tot_size = tot_size + |
| 1274 | sizeof(struct cam_cmd_unconditional_wait); |
| 1275 | if (tot_size > cmd_length) { |
| 1276 | CAM_ERR(CAM_SENSOR, "Command Buffer is wrong"); |
| 1277 | return -EINVAL; |
| 1278 | } |
| 1279 | scr = (void *) (wait_cmd); |
| 1280 | ptr = (void *) |
| 1281 | (scr + |
| 1282 | sizeof(struct cam_cmd_unconditional_wait)); |
| 1283 | CAM_DBG(CAM_SENSOR, "ptr: %pK sizeof: %d Next: %pK", |
| 1284 | scr, (int32_t)sizeof( |
| 1285 | struct cam_cmd_unconditional_wait), ptr); |
| 1286 | |
| 1287 | cmm_hdr = (struct common_header *)ptr; |
| 1288 | } else if (cmm_hdr->cmd_type == |
| 1289 | CAMERA_SENSOR_CMD_TYPE_PWR_DOWN) { |
| 1290 | struct cam_cmd_power *pwr_cmd = |
| 1291 | (struct cam_cmd_power *)ptr; |
| 1292 | |
| 1293 | scr = ptr + sizeof(struct cam_cmd_power); |
| 1294 | tot_size = tot_size + sizeof(struct cam_cmd_power); |
| 1295 | if ((U16_MAX - power_info->power_down_setting_size) < |
| 1296 | pwr_cmd->count) { |
| 1297 | CAM_ERR(CAM_SENSOR, "ERR: Overflow"); |
| 1298 | rc = -EINVAL; |
| 1299 | goto free_power_settings; |
| 1300 | } |
| 1301 | |
| 1302 | power_info->power_down_setting_size += pwr_cmd->count; |
| 1303 | if ((power_info->power_down_setting_size > |
| 1304 | MAX_POWER_CONFIG) || (pwr_cmd->count >= |
| 1305 | SENSOR_SEQ_TYPE_MAX)) { |
| 1306 | CAM_ERR(CAM_SENSOR, |
| 1307 | "pwr_down_setting_size %d, pwr_cmd->count: %d", |
| 1308 | power_info->power_down_setting_size, |
| 1309 | pwr_cmd->count); |
| 1310 | rc = -EINVAL; |
| 1311 | goto free_power_settings; |
| 1312 | } |
| 1313 | |
| 1314 | if (pwr_cmd->count == 0) |
| 1315 | CAM_ERR(CAM_SENSOR, "pwr_down size is zero"); |
| 1316 | |
| 1317 | for (i = 0; i < pwr_cmd->count; i++, pwr_down++) { |
| 1318 | pwr_settings = |
| 1319 | &power_info->power_down_setting[pwr_down]; |
| 1320 | pwr_settings->seq_type = |
| 1321 | pwr_cmd->power_settings[i].power_seq_type; |
| 1322 | pwr_settings->config_val = |
| 1323 | pwr_cmd->power_settings[i].config_val_low; |
| 1324 | power_info->power_down_setting[pwr_down].delay |
| 1325 | = 0; |
| 1326 | if (i) { |
| 1327 | scr = scr + |
| 1328 | sizeof( |
| 1329 | struct cam_power_settings); |
| 1330 | tot_size = |
| 1331 | tot_size + |
| 1332 | sizeof( |
| 1333 | struct cam_power_settings); |
| 1334 | } |
| 1335 | if (tot_size > cmd_length) { |
| 1336 | CAM_ERR(CAM_SENSOR, |
| 1337 | "Command Buffer is wrong"); |
| 1338 | rc = -EINVAL; |
| 1339 | goto free_power_settings; |
| 1340 | } |
| 1341 | CAM_DBG(CAM_SENSOR, |
| 1342 | "Seq Type[%d]: %d Config_val: %ld", |
| 1343 | pwr_down, pwr_settings->seq_type, |
| 1344 | pwr_settings->config_val); |
| 1345 | } |
| 1346 | last_cmd_type = CAMERA_SENSOR_CMD_TYPE_PWR_DOWN; |
| 1347 | ptr = (void *) scr; |
| 1348 | cmm_hdr = (struct common_header *)ptr; |
| 1349 | } else { |
| 1350 | CAM_ERR(CAM_SENSOR, |
| 1351 | "Error: Un expected Header Type: %d", |
| 1352 | cmm_hdr->cmd_type); |
| 1353 | rc = -EINVAL; |
| 1354 | goto free_power_settings; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | return rc; |
| 1359 | free_power_settings: |
| 1360 | kfree(power_info->power_down_setting); |
| 1361 | kfree(power_info->power_setting); |
| 1362 | power_info->power_down_setting = NULL; |
| 1363 | power_info->power_setting = NULL; |
| 1364 | power_info->power_down_setting_size = 0; |
| 1365 | power_info->power_setting_size = 0; |
| 1366 | return rc; |
| 1367 | } |
| 1368 | |
| 1369 | int cam_get_dt_power_setting_data(struct device_node *of_node, |
| 1370 | struct cam_hw_soc_info *soc_info, |
| 1371 | struct cam_sensor_power_ctrl_t *power_info) |
| 1372 | { |
| 1373 | int rc = 0, i; |
| 1374 | int count = 0; |
| 1375 | const char *seq_name = NULL; |
| 1376 | uint32_t *array = NULL; |
| 1377 | struct cam_sensor_power_setting *ps; |
| 1378 | int c, end; |
| 1379 | |
| 1380 | if (!power_info) |
| 1381 | return -EINVAL; |
| 1382 | |
| 1383 | count = of_property_count_strings(of_node, "qcom,cam-power-seq-type"); |
| 1384 | power_info->power_setting_size = count; |
| 1385 | |
| 1386 | CAM_DBG(CAM_SENSOR, "qcom,cam-power-seq-type count %d", count); |
| 1387 | |
| 1388 | if (count <= 0) |
| 1389 | return 0; |
| 1390 | |
| 1391 | ps = kcalloc(count, sizeof(*ps), GFP_KERNEL); |
| 1392 | if (!ps) |
| 1393 | return -ENOMEM; |
| 1394 | power_info->power_setting = ps; |
| 1395 | |
| 1396 | for (i = 0; i < count; i++) { |
| 1397 | rc = of_property_read_string_index(of_node, |
| 1398 | "qcom,cam-power-seq-type", i, &seq_name); |
| 1399 | if (rc < 0) { |
| 1400 | CAM_ERR(CAM_SENSOR, "failed"); |
| 1401 | goto ERROR1; |
| 1402 | } |
| 1403 | CAM_DBG(CAM_SENSOR, "seq_name[%d] = %s", i, seq_name); |
| 1404 | if (!strcmp(seq_name, "cam_vio")) { |
| 1405 | ps[i].seq_type = SENSOR_VIO; |
| 1406 | } else if (!strcmp(seq_name, "cam_vana")) { |
| 1407 | ps[i].seq_type = SENSOR_VANA; |
| 1408 | } else if (!strcmp(seq_name, "cam_clk")) { |
| 1409 | ps[i].seq_type = SENSOR_MCLK; |
| 1410 | } else { |
| 1411 | CAM_ERR(CAM_SENSOR, "unrecognized seq-type %s", |
| 1412 | seq_name); |
| 1413 | rc = -EILSEQ; |
| 1414 | goto ERROR1; |
| 1415 | } |
| 1416 | CAM_DBG(CAM_SENSOR, "seq_type[%d] %d", i, ps[i].seq_type); |
| 1417 | } |
| 1418 | |
| 1419 | array = kcalloc(count, sizeof(uint32_t), GFP_KERNEL); |
| 1420 | if (!array) { |
| 1421 | rc = -ENOMEM; |
| 1422 | goto ERROR1; |
| 1423 | } |
| 1424 | |
| 1425 | rc = of_property_read_u32_array(of_node, "qcom,cam-power-seq-cfg-val", |
| 1426 | array, count); |
| 1427 | if (rc < 0) { |
| 1428 | CAM_ERR(CAM_SENSOR, "failed "); |
| 1429 | goto ERROR2; |
| 1430 | } |
| 1431 | |
| 1432 | for (i = 0; i < count; i++) { |
| 1433 | ps[i].config_val = array[i]; |
| 1434 | CAM_DBG(CAM_SENSOR, "power_setting[%d].config_val = %ld", i, |
| 1435 | ps[i].config_val); |
| 1436 | } |
| 1437 | |
| 1438 | rc = of_property_read_u32_array(of_node, "qcom,cam-power-seq-delay", |
| 1439 | array, count); |
| 1440 | if (rc < 0) { |
| 1441 | CAM_ERR(CAM_SENSOR, "failed"); |
| 1442 | goto ERROR2; |
| 1443 | } |
| 1444 | for (i = 0; i < count; i++) { |
| 1445 | ps[i].delay = array[i]; |
| 1446 | CAM_DBG(CAM_SENSOR, "power_setting[%d].delay = %d", i, |
| 1447 | ps[i].delay); |
| 1448 | } |
| 1449 | kfree(array); |
| 1450 | |
| 1451 | power_info->power_down_setting = |
| 1452 | kcalloc(count, sizeof(*ps), GFP_KERNEL); |
| 1453 | |
| 1454 | if (!power_info->power_down_setting) { |
| 1455 | CAM_ERR(CAM_SENSOR, "failed"); |
| 1456 | rc = -ENOMEM; |
| 1457 | goto ERROR1; |
| 1458 | } |
| 1459 | |
| 1460 | power_info->power_down_setting_size = count; |
| 1461 | |
| 1462 | end = count - 1; |
| 1463 | |
| 1464 | for (c = 0; c < count; c++) { |
| 1465 | power_info->power_down_setting[c] = ps[end]; |
| 1466 | end--; |
| 1467 | } |
| 1468 | return rc; |
| 1469 | ERROR2: |
| 1470 | kfree(array); |
| 1471 | ERROR1: |
| 1472 | kfree(ps); |
| 1473 | return rc; |
| 1474 | } |
| 1475 | |
| 1476 | int cam_sensor_util_init_gpio_pin_tbl( |
| 1477 | struct cam_hw_soc_info *soc_info, |
| 1478 | struct msm_camera_gpio_num_info **pgpio_num_info) |
| 1479 | { |
| 1480 | int rc = 0, val = 0; |
| 1481 | uint32_t gpio_array_size; |
| 1482 | struct device_node *of_node = NULL; |
| 1483 | struct cam_soc_gpio_data *gconf = NULL; |
| 1484 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
| 1485 | |
| 1486 | if (!soc_info->dev) { |
| 1487 | CAM_ERR(CAM_SENSOR, "device node NULL"); |
| 1488 | return -EINVAL; |
| 1489 | } |
| 1490 | |
| 1491 | of_node = soc_info->dev->of_node; |
| 1492 | |
| 1493 | gconf = soc_info->gpio_data; |
| 1494 | if (!gconf) { |
| 1495 | CAM_ERR(CAM_SENSOR, "No gpio_common_table is found"); |
| 1496 | return -EINVAL; |
| 1497 | } |
| 1498 | |
| 1499 | if (!gconf->cam_gpio_common_tbl) { |
| 1500 | CAM_ERR(CAM_SENSOR, "gpio_common_table is not initialized"); |
| 1501 | return -EINVAL; |
| 1502 | } |
| 1503 | |
| 1504 | gpio_array_size = gconf->cam_gpio_common_tbl_size; |
| 1505 | |
| 1506 | if (!gpio_array_size) { |
| 1507 | CAM_ERR(CAM_SENSOR, "invalid size of gpio table"); |
| 1508 | return -EINVAL; |
| 1509 | } |
| 1510 | |
| 1511 | *pgpio_num_info = kzalloc(sizeof(struct msm_camera_gpio_num_info), |
| 1512 | GFP_KERNEL); |
| 1513 | if (!*pgpio_num_info) |
| 1514 | return -ENOMEM; |
| 1515 | gpio_num_info = *pgpio_num_info; |
| 1516 | |
| 1517 | rc = of_property_read_u32(of_node, "gpio-vana", &val); |
| 1518 | if (rc != -EINVAL) { |
| 1519 | if (rc < 0) { |
| 1520 | CAM_ERR(CAM_SENSOR, "read gpio-vana failed rc %d", rc); |
| 1521 | goto free_gpio_info; |
| 1522 | } else if (val >= gpio_array_size) { |
| 1523 | CAM_ERR(CAM_SENSOR, "gpio-vana invalid %d", val); |
| 1524 | rc = -EINVAL; |
| 1525 | goto free_gpio_info; |
| 1526 | } |
| 1527 | gpio_num_info->gpio_num[SENSOR_VANA] = |
| 1528 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1529 | gpio_num_info->valid[SENSOR_VANA] = 1; |
| 1530 | |
| 1531 | CAM_DBG(CAM_SENSOR, "gpio-vana %d", |
| 1532 | gpio_num_info->gpio_num[SENSOR_VANA]); |
| 1533 | } |
| 1534 | |
| 1535 | rc = of_property_read_u32(of_node, "gpio-vio", &val); |
| 1536 | if (rc != -EINVAL) { |
| 1537 | if (rc < 0) { |
| 1538 | CAM_ERR(CAM_SENSOR, "read gpio-vio failed rc %d", rc); |
| 1539 | goto free_gpio_info; |
| 1540 | } else if (val >= gpio_array_size) { |
| 1541 | CAM_ERR(CAM_SENSOR, "gpio-vio invalid %d", val); |
| 1542 | goto free_gpio_info; |
| 1543 | } |
| 1544 | gpio_num_info->gpio_num[SENSOR_VIO] = |
| 1545 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1546 | gpio_num_info->valid[SENSOR_VIO] = 1; |
| 1547 | |
| 1548 | CAM_DBG(CAM_SENSOR, "gpio-vio %d", |
| 1549 | gpio_num_info->gpio_num[SENSOR_VIO]); |
| 1550 | } |
| 1551 | |
| 1552 | rc = of_property_read_u32(of_node, "gpio-vaf", &val); |
| 1553 | if (rc != -EINVAL) { |
| 1554 | if (rc < 0) { |
| 1555 | CAM_ERR(CAM_SENSOR, "read gpio-vaf failed rc %d", rc); |
| 1556 | goto free_gpio_info; |
| 1557 | } else if (val >= gpio_array_size) { |
| 1558 | CAM_ERR(CAM_SENSOR, "gpio-vaf invalid %d", val); |
| 1559 | rc = -EINVAL; |
| 1560 | goto free_gpio_info; |
| 1561 | } |
| 1562 | gpio_num_info->gpio_num[SENSOR_VAF] = |
| 1563 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1564 | gpio_num_info->valid[SENSOR_VAF] = 1; |
| 1565 | |
| 1566 | CAM_DBG(CAM_SENSOR, "gpio-vaf %d", |
| 1567 | gpio_num_info->gpio_num[SENSOR_VAF]); |
| 1568 | } |
| 1569 | |
| 1570 | rc = of_property_read_u32(of_node, "gpio-vdig", &val); |
| 1571 | if (rc != -EINVAL) { |
| 1572 | if (rc < 0) { |
| 1573 | CAM_ERR(CAM_SENSOR, "read gpio-vdig failed rc %d", rc); |
| 1574 | goto free_gpio_info; |
| 1575 | } else if (val >= gpio_array_size) { |
| 1576 | CAM_ERR(CAM_SENSOR, "gpio-vdig invalid %d", val); |
| 1577 | rc = -EINVAL; |
| 1578 | goto free_gpio_info; |
| 1579 | } |
| 1580 | gpio_num_info->gpio_num[SENSOR_VDIG] = |
| 1581 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1582 | gpio_num_info->valid[SENSOR_VDIG] = 1; |
| 1583 | |
| 1584 | CAM_DBG(CAM_SENSOR, "gpio-vdig %d", |
| 1585 | gpio_num_info->gpio_num[SENSOR_VDIG]); |
| 1586 | } |
| 1587 | |
| 1588 | rc = of_property_read_u32(of_node, "gpio-reset", &val); |
| 1589 | if (rc != -EINVAL) { |
| 1590 | if (rc < 0) { |
| 1591 | CAM_ERR(CAM_SENSOR, "read gpio-reset failed rc %d", rc); |
| 1592 | goto free_gpio_info; |
| 1593 | } else if (val >= gpio_array_size) { |
| 1594 | CAM_ERR(CAM_SENSOR, "gpio-reset invalid %d", val); |
| 1595 | rc = -EINVAL; |
| 1596 | goto free_gpio_info; |
| 1597 | } |
| 1598 | gpio_num_info->gpio_num[SENSOR_RESET] = |
| 1599 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1600 | gpio_num_info->valid[SENSOR_RESET] = 1; |
| 1601 | |
| 1602 | CAM_DBG(CAM_SENSOR, "gpio-reset %d", |
| 1603 | gpio_num_info->gpio_num[SENSOR_RESET]); |
| 1604 | } |
| 1605 | |
| 1606 | rc = of_property_read_u32(of_node, "gpio-standby", &val); |
| 1607 | if (rc != -EINVAL) { |
| 1608 | if (rc < 0) { |
| 1609 | CAM_ERR(CAM_SENSOR, |
| 1610 | "read gpio-standby failed rc %d", rc); |
| 1611 | goto free_gpio_info; |
| 1612 | } else if (val >= gpio_array_size) { |
| 1613 | CAM_ERR(CAM_SENSOR, "gpio-standby invalid %d", val); |
| 1614 | rc = -EINVAL; |
| 1615 | goto free_gpio_info; |
| 1616 | } |
| 1617 | gpio_num_info->gpio_num[SENSOR_STANDBY] = |
| 1618 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1619 | gpio_num_info->valid[SENSOR_STANDBY] = 1; |
| 1620 | |
| 1621 | CAM_DBG(CAM_SENSOR, "gpio-standby %d", |
| 1622 | gpio_num_info->gpio_num[SENSOR_STANDBY]); |
| 1623 | } |
| 1624 | |
| 1625 | rc = of_property_read_u32(of_node, "gpio-af-pwdm", &val); |
| 1626 | if (rc != -EINVAL) { |
| 1627 | if (rc < 0) { |
| 1628 | CAM_ERR(CAM_SENSOR, |
| 1629 | "read gpio-af-pwdm failed rc %d", rc); |
| 1630 | goto free_gpio_info; |
| 1631 | } else if (val >= gpio_array_size) { |
| 1632 | CAM_ERR(CAM_SENSOR, "gpio-af-pwdm invalid %d", val); |
| 1633 | rc = -EINVAL; |
| 1634 | goto free_gpio_info; |
| 1635 | } |
| 1636 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM] = |
| 1637 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1638 | gpio_num_info->valid[SENSOR_VAF_PWDM] = 1; |
| 1639 | |
| 1640 | CAM_DBG(CAM_SENSOR, "gpio-af-pwdm %d", |
| 1641 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM]); |
| 1642 | } |
| 1643 | |
| 1644 | rc = of_property_read_u32(of_node, "gpio-custom1", &val); |
| 1645 | if (rc != -EINVAL) { |
| 1646 | if (rc < 0) { |
| 1647 | CAM_ERR(CAM_SENSOR, |
| 1648 | "read gpio-custom1 failed rc %d", rc); |
| 1649 | goto free_gpio_info; |
| 1650 | } else if (val >= gpio_array_size) { |
| 1651 | CAM_ERR(CAM_SENSOR, "gpio-custom1 invalid %d", val); |
| 1652 | rc = -EINVAL; |
| 1653 | goto free_gpio_info; |
| 1654 | } |
| 1655 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1] = |
| 1656 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1657 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO1] = 1; |
| 1658 | |
| 1659 | CAM_DBG(CAM_SENSOR, "gpio-custom1 %d", |
| 1660 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1]); |
| 1661 | } |
| 1662 | |
| 1663 | rc = of_property_read_u32(of_node, "gpio-custom2", &val); |
| 1664 | if (rc != -EINVAL) { |
| 1665 | if (rc < 0) { |
| 1666 | CAM_ERR(CAM_SENSOR, |
| 1667 | "read gpio-custom2 failed rc %d", rc); |
| 1668 | goto free_gpio_info; |
| 1669 | } else if (val >= gpio_array_size) { |
| 1670 | CAM_ERR(CAM_SENSOR, "gpio-custom2 invalid %d", val); |
| 1671 | rc = -EINVAL; |
| 1672 | goto free_gpio_info; |
| 1673 | } |
| 1674 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2] = |
| 1675 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1676 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO2] = 1; |
| 1677 | |
| 1678 | CAM_DBG(CAM_SENSOR, "gpio-custom2 %d", |
| 1679 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2]); |
| 1680 | } else { |
| 1681 | rc = 0; |
| 1682 | } |
| 1683 | |
yixiang.wu | 68f25e9 | 2021-01-05 18:05:58 +0800 | [diff] [blame] | 1684 | /* MODIFIED-BEGIN by yixiang.wu, 2021-01-05,BUG-10277816*/ |
| 1685 | rc = of_property_read_u32(of_node, "gpio-custom3", &val); |
| 1686 | if (rc != -EINVAL) { |
| 1687 | if (rc < 0) { |
| 1688 | CAM_ERR(CAM_SENSOR, |
| 1689 | "read gpio-custom3 failed rc %d", rc); |
| 1690 | goto free_gpio_info; |
| 1691 | } else if (val >= gpio_array_size) { |
| 1692 | CAM_ERR(CAM_SENSOR, "gpio-custom3 invalid %d", val); |
| 1693 | rc = -EINVAL; |
| 1694 | goto free_gpio_info; |
| 1695 | } |
| 1696 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO3] = |
| 1697 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1698 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO3] = 1; |
| 1699 | |
| 1700 | CAM_DBG(CAM_SENSOR, "gpio-custom3 %d", |
| 1701 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO3]); |
| 1702 | } else { |
| 1703 | rc = 0; |
| 1704 | } |
| 1705 | /* MODIFIED-END by yixiang.wu,BUG-10277816*/ |
| 1706 | |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 1707 | return rc; |
| 1708 | |
| 1709 | free_gpio_info: |
| 1710 | kfree(gpio_num_info); |
| 1711 | gpio_num_info = NULL; |
| 1712 | return rc; |
| 1713 | } |
| 1714 | |
| 1715 | int msm_camera_pinctrl_init( |
| 1716 | struct msm_pinctrl_info *sensor_pctrl, struct device *dev) |
| 1717 | { |
| 1718 | |
| 1719 | sensor_pctrl->pinctrl = devm_pinctrl_get(dev); |
| 1720 | if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) { |
| 1721 | CAM_DBG(CAM_SENSOR, "Getting pinctrl handle failed"); |
| 1722 | return -EINVAL; |
| 1723 | } |
| 1724 | sensor_pctrl->gpio_state_active = |
| 1725 | pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 1726 | CAM_SENSOR_PINCTRL_STATE_DEFAULT); |
| 1727 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_active)) { |
| 1728 | CAM_ERR(CAM_SENSOR, |
| 1729 | "Failed to get the active state pinctrl handle"); |
| 1730 | return -EINVAL; |
| 1731 | } |
| 1732 | sensor_pctrl->gpio_state_suspend |
| 1733 | = pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 1734 | CAM_SENSOR_PINCTRL_STATE_SLEEP); |
| 1735 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_suspend)) { |
| 1736 | CAM_ERR(CAM_SENSOR, |
| 1737 | "Failed to get the suspend state pinctrl handle"); |
| 1738 | return -EINVAL; |
| 1739 | } |
| 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | int cam_sensor_bob_pwm_mode_switch(struct cam_hw_soc_info *soc_info, |
| 1745 | int bob_reg_idx, bool flag) |
| 1746 | { |
| 1747 | int rc = 0; |
| 1748 | uint32_t op_current = |
| 1749 | (flag == true) ? soc_info->rgltr_op_mode[bob_reg_idx] : 0; |
| 1750 | |
| 1751 | if (soc_info->rgltr[bob_reg_idx] != NULL) { |
| 1752 | rc = regulator_set_load(soc_info->rgltr[bob_reg_idx], |
| 1753 | op_current); |
| 1754 | if (rc) |
| 1755 | CAM_WARN(CAM_SENSOR, |
| 1756 | "BoB PWM SetLoad failed rc: %d", rc); |
| 1757 | } |
| 1758 | |
| 1759 | return rc; |
| 1760 | } |
| 1761 | |
| 1762 | int msm_cam_sensor_handle_reg_gpio(int seq_type, |
| 1763 | struct msm_camera_gpio_num_info *gpio_num_info, int val) |
| 1764 | { |
| 1765 | int gpio_offset = -1; |
| 1766 | |
| 1767 | if (!gpio_num_info) { |
| 1768 | CAM_INFO(CAM_SENSOR, "Input Parameters are not proper"); |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | CAM_DBG(CAM_SENSOR, "Seq type: %d, config: %d", seq_type, val); |
| 1773 | |
| 1774 | gpio_offset = seq_type; |
| 1775 | |
| 1776 | if (gpio_num_info->valid[gpio_offset] == 1) { |
| 1777 | CAM_DBG(CAM_SENSOR, "VALID GPIO offset: %d, seqtype: %d", |
| 1778 | gpio_offset, seq_type); |
| 1779 | cam_res_mgr_gpio_set_value( |
| 1780 | gpio_num_info->gpio_num |
| 1781 | [gpio_offset], val); |
| 1782 | } |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
| 1787 | static int cam_config_mclk_reg(struct cam_sensor_power_ctrl_t *ctrl, |
| 1788 | struct cam_hw_soc_info *soc_info, int32_t index) |
| 1789 | { |
| 1790 | int32_t num_vreg = 0, j = 0, rc = 0, idx = 0; |
| 1791 | struct cam_sensor_power_setting *ps = NULL; |
| 1792 | struct cam_sensor_power_setting *pd = NULL; |
| 1793 | |
| 1794 | num_vreg = soc_info->num_rgltr; |
| 1795 | |
| 1796 | pd = &ctrl->power_down_setting[index]; |
| 1797 | |
| 1798 | for (j = 0; j < num_vreg; j++) { |
| 1799 | if (!strcmp(soc_info->rgltr_name[j], "cam_clk")) { |
| 1800 | ps = NULL; |
| 1801 | for (idx = 0; idx < ctrl->power_setting_size; idx++) { |
| 1802 | if (ctrl->power_setting[idx].seq_type == |
| 1803 | pd->seq_type) { |
| 1804 | ps = &ctrl->power_setting[idx]; |
| 1805 | break; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | if (ps != NULL) { |
| 1810 | CAM_DBG(CAM_SENSOR, "Disable MCLK Regulator"); |
| 1811 | rc = cam_soc_util_regulator_disable( |
| 1812 | soc_info->rgltr[j], |
| 1813 | soc_info->rgltr_name[j], |
| 1814 | soc_info->rgltr_min_volt[j], |
| 1815 | soc_info->rgltr_max_volt[j], |
| 1816 | soc_info->rgltr_op_mode[j], |
| 1817 | soc_info->rgltr_delay[j]); |
| 1818 | |
| 1819 | if (rc) { |
| 1820 | CAM_ERR(CAM_SENSOR, |
| 1821 | "MCLK REG DISALBE FAILED: %d", |
| 1822 | rc); |
| 1823 | return rc; |
| 1824 | } |
| 1825 | |
| 1826 | ps->data[0] = |
| 1827 | soc_info->rgltr[j]; |
| 1828 | |
| 1829 | regulator_put( |
| 1830 | soc_info->rgltr[j]); |
| 1831 | soc_info->rgltr[j] = NULL; |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | return rc; |
| 1837 | } |
| 1838 | |
| 1839 | int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl, |
| 1840 | struct cam_hw_soc_info *soc_info) |
| 1841 | { |
| 1842 | int rc = 0, index = 0, no_gpio = 0, ret = 0, num_vreg, j = 0, i = 0; |
| 1843 | int32_t vreg_idx = -1; |
| 1844 | struct cam_sensor_power_setting *power_setting = NULL; |
| 1845 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
| 1846 | |
| 1847 | CAM_DBG(CAM_SENSOR, "Enter"); |
| 1848 | if (!ctrl) { |
| 1849 | CAM_ERR(CAM_SENSOR, "Invalid ctrl handle"); |
| 1850 | return -EINVAL; |
| 1851 | } |
| 1852 | |
| 1853 | gpio_num_info = ctrl->gpio_num_info; |
| 1854 | num_vreg = soc_info->num_rgltr; |
| 1855 | |
| 1856 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
| 1857 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
| 1858 | return -EINVAL; |
| 1859 | } |
| 1860 | |
| 1861 | if (soc_info->use_shared_clk) |
| 1862 | cam_res_mgr_shared_clk_config(true); |
| 1863 | |
junwen.ye | 0b68938 | 2022-08-04 17:20:04 +0800 | [diff] [blame] | 1864 | if (!strcmp(soc_info->dev_name,"ac4a000.qcom,cci0:qcom,ois@0")) { |
| 1865 | CAM_DBG(CAM_SENSOR, "OIS no need power up again!"); |
| 1866 | return 0; |
| 1867 | } |
| 1868 | |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 1869 | ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev); |
| 1870 | if (ret < 0) { |
| 1871 | /* Some sensor subdev no pinctrl. */ |
| 1872 | CAM_DBG(CAM_SENSOR, "Initialization of pinctrl failed"); |
| 1873 | ctrl->cam_pinctrl_status = 0; |
| 1874 | } else { |
| 1875 | ctrl->cam_pinctrl_status = 1; |
| 1876 | } |
| 1877 | |
| 1878 | if (cam_res_mgr_shared_pinctrl_init()) { |
| 1879 | CAM_ERR(CAM_SENSOR, |
| 1880 | "Failed to init shared pinctrl"); |
| 1881 | return -EINVAL; |
| 1882 | } |
| 1883 | |
| 1884 | rc = cam_sensor_util_request_gpio_table(soc_info, 1); |
| 1885 | if (rc < 0) |
| 1886 | no_gpio = rc; |
| 1887 | |
| 1888 | if (ctrl->cam_pinctrl_status) { |
| 1889 | ret = pinctrl_select_state( |
| 1890 | ctrl->pinctrl_info.pinctrl, |
| 1891 | ctrl->pinctrl_info.gpio_state_active); |
| 1892 | if (ret) |
| 1893 | CAM_ERR(CAM_SENSOR, "cannot set pin to active state"); |
| 1894 | } |
| 1895 | |
| 1896 | ret = cam_res_mgr_shared_pinctrl_select_state(true); |
| 1897 | if (ret) |
| 1898 | CAM_ERR(CAM_SENSOR, |
| 1899 | "Cannot set shared pin to active state"); |
| 1900 | |
| 1901 | CAM_DBG(CAM_SENSOR, "power setting size: %d", ctrl->power_setting_size); |
| 1902 | |
| 1903 | for (index = 0; index < ctrl->power_setting_size; index++) { |
| 1904 | CAM_DBG(CAM_SENSOR, "index: %d", index); |
| 1905 | power_setting = &ctrl->power_setting[index]; |
| 1906 | if (!power_setting) { |
| 1907 | CAM_ERR(CAM_SENSOR, |
| 1908 | "Invalid power up settings for index %d", |
| 1909 | index); |
| 1910 | return -EINVAL; |
| 1911 | } |
| 1912 | |
| 1913 | CAM_DBG(CAM_SENSOR, "seq_type %d", power_setting->seq_type); |
| 1914 | |
| 1915 | switch (power_setting->seq_type) { |
| 1916 | case SENSOR_MCLK: |
| 1917 | if (power_setting->seq_val >= soc_info->num_clk) { |
| 1918 | CAM_ERR(CAM_SENSOR, "clk index %d >= max %u", |
| 1919 | power_setting->seq_val, |
| 1920 | soc_info->num_clk); |
| 1921 | goto power_up_failed; |
| 1922 | } |
| 1923 | for (j = 0; j < num_vreg; j++) { |
| 1924 | if (!strcmp(soc_info->rgltr_name[j], |
| 1925 | "cam_clk")) { |
| 1926 | CAM_DBG(CAM_SENSOR, |
| 1927 | "Enable cam_clk: %d", j); |
| 1928 | |
| 1929 | soc_info->rgltr[j] = |
| 1930 | regulator_get( |
| 1931 | soc_info->dev, |
| 1932 | soc_info->rgltr_name[j]); |
| 1933 | |
| 1934 | if (IS_ERR_OR_NULL( |
| 1935 | soc_info->rgltr[j])) { |
| 1936 | rc = PTR_ERR( |
| 1937 | soc_info->rgltr[j]); |
| 1938 | rc = rc ? rc : -EINVAL; |
| 1939 | CAM_ERR(CAM_SENSOR, |
| 1940 | "vreg %s %d", |
| 1941 | soc_info->rgltr_name[j], |
| 1942 | rc); |
| 1943 | soc_info->rgltr[j] = NULL; |
| 1944 | goto power_up_failed; |
| 1945 | } |
| 1946 | |
| 1947 | rc = cam_soc_util_regulator_enable( |
| 1948 | soc_info->rgltr[j], |
| 1949 | soc_info->rgltr_name[j], |
| 1950 | soc_info->rgltr_min_volt[j], |
| 1951 | soc_info->rgltr_max_volt[j], |
| 1952 | soc_info->rgltr_op_mode[j], |
| 1953 | soc_info->rgltr_delay[j]); |
| 1954 | if (rc) { |
| 1955 | CAM_ERR(CAM_SENSOR, |
| 1956 | "Reg enable failed"); |
| 1957 | goto power_up_failed; |
| 1958 | } |
| 1959 | power_setting->data[0] = |
| 1960 | soc_info->rgltr[j]; |
| 1961 | } |
| 1962 | } |
| 1963 | if (power_setting->config_val) |
| 1964 | soc_info->clk_rate[0][power_setting->seq_val] = |
| 1965 | power_setting->config_val; |
| 1966 | |
| 1967 | for (j = 0; j < soc_info->num_clk; j++) { |
| 1968 | rc = cam_soc_util_clk_enable(soc_info->clk[j], |
| 1969 | soc_info->clk_name[j], |
| 1970 | soc_info->clk_rate[0][j]); |
| 1971 | if (rc) |
| 1972 | break; |
| 1973 | } |
| 1974 | |
| 1975 | if (rc < 0) { |
| 1976 | CAM_ERR(CAM_SENSOR, "clk enable failed"); |
| 1977 | goto power_up_failed; |
| 1978 | } |
| 1979 | break; |
| 1980 | case SENSOR_RESET: |
| 1981 | case SENSOR_STANDBY: |
| 1982 | case SENSOR_CUSTOM_GPIO1: |
| 1983 | case SENSOR_CUSTOM_GPIO2: |
yixiang.wu | 68f25e9 | 2021-01-05 18:05:58 +0800 | [diff] [blame] | 1984 | case SENSOR_CUSTOM_GPIO3: // MODIFIED by yixiang.wu, 2021-01-05,BUG-10277816 |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 1985 | if (no_gpio) { |
| 1986 | CAM_ERR(CAM_SENSOR, "request gpio failed"); |
Jigarkumar Zala | a89607a | 2019-07-11 20:15:40 +0800 | [diff] [blame] | 1987 | goto power_up_failed; |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 1988 | } |
| 1989 | if (!gpio_num_info) { |
| 1990 | CAM_ERR(CAM_SENSOR, "Invalid gpio_num_info"); |
| 1991 | goto power_up_failed; |
| 1992 | } |
| 1993 | CAM_DBG(CAM_SENSOR, "gpio set val %d", |
| 1994 | gpio_num_info->gpio_num |
| 1995 | [power_setting->seq_type]); |
| 1996 | |
| 1997 | rc = msm_cam_sensor_handle_reg_gpio( |
| 1998 | power_setting->seq_type, |
| 1999 | gpio_num_info, |
| 2000 | (int) power_setting->config_val); |
| 2001 | if (rc < 0) { |
| 2002 | CAM_ERR(CAM_SENSOR, |
| 2003 | "Error in handling VREG GPIO"); |
| 2004 | goto power_up_failed; |
| 2005 | } |
| 2006 | break; |
| 2007 | case SENSOR_VANA: |
| 2008 | case SENSOR_VDIG: |
| 2009 | case SENSOR_VIO: |
| 2010 | case SENSOR_VAF: |
| 2011 | case SENSOR_VAF_PWDM: |
| 2012 | case SENSOR_CUSTOM_REG1: |
| 2013 | case SENSOR_CUSTOM_REG2: |
| 2014 | if (power_setting->seq_val == INVALID_VREG) |
| 2015 | break; |
| 2016 | |
| 2017 | if (power_setting->seq_val >= CAM_VREG_MAX) { |
| 2018 | CAM_ERR(CAM_SENSOR, "vreg index %d >= max %d", |
| 2019 | power_setting->seq_val, |
| 2020 | CAM_VREG_MAX); |
| 2021 | goto power_up_failed; |
| 2022 | } |
| 2023 | if (power_setting->seq_val < num_vreg) { |
| 2024 | CAM_DBG(CAM_SENSOR, "Enable Regulator"); |
| 2025 | vreg_idx = power_setting->seq_val; |
| 2026 | |
| 2027 | soc_info->rgltr[vreg_idx] = |
| 2028 | regulator_get(soc_info->dev, |
| 2029 | soc_info->rgltr_name[vreg_idx]); |
| 2030 | if (IS_ERR_OR_NULL( |
| 2031 | soc_info->rgltr[vreg_idx])) { |
| 2032 | rc = PTR_ERR(soc_info->rgltr[vreg_idx]); |
| 2033 | rc = rc ? rc : -EINVAL; |
| 2034 | |
| 2035 | CAM_ERR(CAM_SENSOR, "%s get failed %d", |
| 2036 | soc_info->rgltr_name[vreg_idx], |
| 2037 | rc); |
| 2038 | |
| 2039 | soc_info->rgltr[vreg_idx] = NULL; |
| 2040 | goto power_up_failed; |
| 2041 | } |
| 2042 | |
| 2043 | rc = cam_soc_util_regulator_enable( |
| 2044 | soc_info->rgltr[vreg_idx], |
| 2045 | soc_info->rgltr_name[vreg_idx], |
| 2046 | soc_info->rgltr_min_volt[vreg_idx], |
| 2047 | soc_info->rgltr_max_volt[vreg_idx], |
| 2048 | soc_info->rgltr_op_mode[vreg_idx], |
| 2049 | soc_info->rgltr_delay[vreg_idx]); |
| 2050 | if (rc) { |
| 2051 | CAM_ERR(CAM_SENSOR, |
| 2052 | "Reg Enable failed for %s", |
| 2053 | soc_info->rgltr_name[vreg_idx]); |
| 2054 | goto power_up_failed; |
| 2055 | } |
| 2056 | power_setting->data[0] = |
| 2057 | soc_info->rgltr[vreg_idx]; |
| 2058 | } else { |
| 2059 | CAM_ERR(CAM_SENSOR, "usr_idx:%d dts_idx:%d", |
| 2060 | power_setting->seq_val, num_vreg); |
| 2061 | } |
| 2062 | |
| 2063 | rc = msm_cam_sensor_handle_reg_gpio( |
| 2064 | power_setting->seq_type, |
| 2065 | gpio_num_info, 1); |
| 2066 | if (rc < 0) { |
| 2067 | CAM_ERR(CAM_SENSOR, |
| 2068 | "Error in handling VREG GPIO"); |
| 2069 | goto power_up_failed; |
| 2070 | } |
| 2071 | break; |
| 2072 | default: |
| 2073 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 2074 | power_setting->seq_type); |
| 2075 | break; |
| 2076 | } |
| 2077 | if (power_setting->delay > 20) |
| 2078 | msleep(power_setting->delay); |
| 2079 | else if (power_setting->delay) |
| 2080 | usleep_range(power_setting->delay * 1000, |
| 2081 | (power_setting->delay * 1000) + 1000); |
| 2082 | } |
| 2083 | |
| 2084 | ret = cam_res_mgr_shared_pinctrl_post_init(); |
| 2085 | if (ret) |
| 2086 | CAM_ERR(CAM_SENSOR, |
| 2087 | "Failed to post init shared pinctrl"); |
| 2088 | |
| 2089 | return 0; |
| 2090 | power_up_failed: |
| 2091 | CAM_ERR(CAM_SENSOR, "failed"); |
| 2092 | for (index--; index >= 0; index--) { |
| 2093 | CAM_DBG(CAM_SENSOR, "index %d", index); |
| 2094 | power_setting = &ctrl->power_setting[index]; |
| 2095 | CAM_DBG(CAM_SENSOR, "type %d", |
| 2096 | power_setting->seq_type); |
| 2097 | switch (power_setting->seq_type) { |
| 2098 | case SENSOR_MCLK: |
| 2099 | for (i = soc_info->num_clk - 1; i >= 0; i--) { |
| 2100 | cam_soc_util_clk_disable(soc_info->clk[i], |
| 2101 | soc_info->clk_name[i]); |
| 2102 | } |
| 2103 | ret = cam_config_mclk_reg(ctrl, soc_info, index); |
| 2104 | if (ret < 0) { |
| 2105 | CAM_ERR(CAM_SENSOR, |
| 2106 | "config clk reg failed rc: %d", ret); |
| 2107 | continue; |
| 2108 | } |
| 2109 | break; |
| 2110 | case SENSOR_RESET: |
| 2111 | case SENSOR_STANDBY: |
| 2112 | case SENSOR_CUSTOM_GPIO1: |
| 2113 | case SENSOR_CUSTOM_GPIO2: |
yixiang.wu | 68f25e9 | 2021-01-05 18:05:58 +0800 | [diff] [blame] | 2114 | case SENSOR_CUSTOM_GPIO3: // MODIFIED by yixiang.wu, 2021-01-05,BUG-10277816 |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 2115 | if (!gpio_num_info) |
| 2116 | continue; |
| 2117 | if (!gpio_num_info->valid |
| 2118 | [power_setting->seq_type]) |
| 2119 | continue; |
| 2120 | cam_res_mgr_gpio_set_value( |
| 2121 | gpio_num_info->gpio_num |
| 2122 | [power_setting->seq_type], GPIOF_OUT_INIT_LOW); |
| 2123 | break; |
| 2124 | case SENSOR_VANA: |
| 2125 | case SENSOR_VDIG: |
| 2126 | case SENSOR_VIO: |
| 2127 | case SENSOR_VAF: |
| 2128 | case SENSOR_VAF_PWDM: |
| 2129 | case SENSOR_CUSTOM_REG1: |
| 2130 | case SENSOR_CUSTOM_REG2: |
| 2131 | if (power_setting->seq_val < num_vreg) { |
| 2132 | CAM_DBG(CAM_SENSOR, "Disable Regulator"); |
| 2133 | vreg_idx = power_setting->seq_val; |
| 2134 | |
| 2135 | rc = cam_soc_util_regulator_disable( |
| 2136 | soc_info->rgltr[vreg_idx], |
| 2137 | soc_info->rgltr_name[vreg_idx], |
| 2138 | soc_info->rgltr_min_volt[vreg_idx], |
| 2139 | soc_info->rgltr_max_volt[vreg_idx], |
| 2140 | soc_info->rgltr_op_mode[vreg_idx], |
| 2141 | soc_info->rgltr_delay[vreg_idx]); |
| 2142 | |
| 2143 | if (rc) { |
| 2144 | CAM_ERR(CAM_SENSOR, |
| 2145 | "Fail to disalbe reg: %s", |
| 2146 | soc_info->rgltr_name[vreg_idx]); |
| 2147 | soc_info->rgltr[vreg_idx] = NULL; |
| 2148 | msm_cam_sensor_handle_reg_gpio( |
| 2149 | power_setting->seq_type, |
| 2150 | gpio_num_info, |
| 2151 | GPIOF_OUT_INIT_LOW); |
| 2152 | continue; |
| 2153 | } |
| 2154 | power_setting->data[0] = |
| 2155 | soc_info->rgltr[vreg_idx]; |
| 2156 | |
| 2157 | regulator_put(soc_info->rgltr[vreg_idx]); |
| 2158 | soc_info->rgltr[vreg_idx] = NULL; |
| 2159 | } else { |
| 2160 | CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d", |
| 2161 | power_setting->seq_val, num_vreg); |
| 2162 | } |
| 2163 | |
| 2164 | msm_cam_sensor_handle_reg_gpio(power_setting->seq_type, |
| 2165 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 2166 | |
| 2167 | break; |
| 2168 | default: |
| 2169 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 2170 | power_setting->seq_type); |
| 2171 | break; |
| 2172 | } |
| 2173 | if (power_setting->delay > 20) { |
| 2174 | msleep(power_setting->delay); |
| 2175 | } else if (power_setting->delay) { |
| 2176 | usleep_range(power_setting->delay * 1000, |
| 2177 | (power_setting->delay * 1000) + 1000); |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | if (ctrl->cam_pinctrl_status) { |
| 2182 | ret = pinctrl_select_state( |
| 2183 | ctrl->pinctrl_info.pinctrl, |
| 2184 | ctrl->pinctrl_info.gpio_state_suspend); |
| 2185 | if (ret) |
| 2186 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
| 2187 | devm_pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 2188 | } |
| 2189 | |
| 2190 | if (soc_info->use_shared_clk) |
| 2191 | cam_res_mgr_shared_clk_config(false); |
| 2192 | |
| 2193 | cam_res_mgr_shared_pinctrl_select_state(false); |
| 2194 | cam_res_mgr_shared_pinctrl_put(); |
| 2195 | |
| 2196 | ctrl->cam_pinctrl_status = 0; |
| 2197 | |
| 2198 | cam_sensor_util_request_gpio_table(soc_info, 0); |
| 2199 | |
| 2200 | return rc; |
| 2201 | } |
| 2202 | |
| 2203 | static struct cam_sensor_power_setting* |
| 2204 | msm_camera_get_power_settings(struct cam_sensor_power_ctrl_t *ctrl, |
| 2205 | enum msm_camera_power_seq_type seq_type, |
| 2206 | uint16_t seq_val) |
| 2207 | { |
| 2208 | struct cam_sensor_power_setting *power_setting, *ps = NULL; |
| 2209 | int idx; |
| 2210 | |
| 2211 | for (idx = 0; idx < ctrl->power_setting_size; idx++) { |
| 2212 | power_setting = &ctrl->power_setting[idx]; |
| 2213 | if (power_setting->seq_type == seq_type && |
| 2214 | power_setting->seq_val == seq_val) { |
| 2215 | ps = power_setting; |
| 2216 | return ps; |
| 2217 | } |
| 2218 | |
| 2219 | } |
| 2220 | |
| 2221 | return ps; |
| 2222 | } |
| 2223 | |
| 2224 | int cam_sensor_util_power_down(struct cam_sensor_power_ctrl_t *ctrl, |
| 2225 | struct cam_hw_soc_info *soc_info) |
| 2226 | { |
| 2227 | int index = 0, ret = 0, num_vreg = 0, i; |
| 2228 | struct cam_sensor_power_setting *pd = NULL; |
| 2229 | struct cam_sensor_power_setting *ps = NULL; |
| 2230 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
| 2231 | |
| 2232 | CAM_DBG(CAM_SENSOR, "Enter"); |
| 2233 | if (!ctrl || !soc_info) { |
| 2234 | CAM_ERR(CAM_SENSOR, "failed ctrl %pK", ctrl); |
| 2235 | return -EINVAL; |
| 2236 | } |
| 2237 | |
| 2238 | gpio_num_info = ctrl->gpio_num_info; |
| 2239 | num_vreg = soc_info->num_rgltr; |
| 2240 | |
| 2241 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
| 2242 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
| 2243 | return -EINVAL; |
| 2244 | } |
| 2245 | |
| 2246 | if (ctrl->power_down_setting_size > MAX_POWER_CONFIG) { |
| 2247 | CAM_ERR(CAM_SENSOR, "Invalid: power setting size %d", |
| 2248 | ctrl->power_setting_size); |
| 2249 | return -EINVAL; |
| 2250 | } |
| 2251 | |
| 2252 | for (index = 0; index < ctrl->power_down_setting_size; index++) { |
| 2253 | CAM_DBG(CAM_SENSOR, "power_down_index %d", index); |
| 2254 | pd = &ctrl->power_down_setting[index]; |
| 2255 | if (!pd) { |
| 2256 | CAM_ERR(CAM_SENSOR, |
| 2257 | "Invalid power down settings for index %d", |
| 2258 | index); |
| 2259 | return -EINVAL; |
| 2260 | } |
| 2261 | |
| 2262 | ps = NULL; |
| 2263 | CAM_DBG(CAM_SENSOR, "seq_type %d", pd->seq_type); |
| 2264 | switch (pd->seq_type) { |
| 2265 | case SENSOR_MCLK: |
| 2266 | for (i = soc_info->num_clk - 1; i >= 0; i--) { |
| 2267 | cam_soc_util_clk_disable(soc_info->clk[i], |
| 2268 | soc_info->clk_name[i]); |
| 2269 | } |
| 2270 | |
| 2271 | ret = cam_config_mclk_reg(ctrl, soc_info, index); |
| 2272 | if (ret < 0) { |
| 2273 | CAM_ERR(CAM_SENSOR, |
| 2274 | "config clk reg failed rc: %d", ret); |
| 2275 | continue; |
| 2276 | } |
| 2277 | break; |
| 2278 | case SENSOR_RESET: |
| 2279 | case SENSOR_STANDBY: |
| 2280 | case SENSOR_CUSTOM_GPIO1: |
| 2281 | case SENSOR_CUSTOM_GPIO2: |
yixiang.wu | 68f25e9 | 2021-01-05 18:05:58 +0800 | [diff] [blame] | 2282 | case SENSOR_CUSTOM_GPIO3: // MODIFIED by yixiang.wu, 2021-01-05,BUG-10277816 |
Jigarkumar Zala | 05349fe | 2019-05-24 17:56:58 -0700 | [diff] [blame] | 2283 | |
| 2284 | if (!gpio_num_info->valid[pd->seq_type]) |
| 2285 | continue; |
| 2286 | |
| 2287 | cam_res_mgr_gpio_set_value( |
| 2288 | gpio_num_info->gpio_num |
| 2289 | [pd->seq_type], |
| 2290 | (int) pd->config_val); |
| 2291 | |
| 2292 | break; |
| 2293 | case SENSOR_VANA: |
| 2294 | case SENSOR_VDIG: |
| 2295 | case SENSOR_VIO: |
| 2296 | case SENSOR_VAF: |
| 2297 | case SENSOR_VAF_PWDM: |
| 2298 | case SENSOR_CUSTOM_REG1: |
| 2299 | case SENSOR_CUSTOM_REG2: |
| 2300 | if (pd->seq_val == INVALID_VREG) |
| 2301 | break; |
| 2302 | |
| 2303 | ps = msm_camera_get_power_settings( |
| 2304 | ctrl, pd->seq_type, |
| 2305 | pd->seq_val); |
| 2306 | if (ps) { |
| 2307 | if (pd->seq_val < num_vreg) { |
| 2308 | CAM_DBG(CAM_SENSOR, |
| 2309 | "Disable Regulator"); |
| 2310 | ret = cam_soc_util_regulator_disable( |
| 2311 | soc_info->rgltr[ps->seq_val], |
| 2312 | soc_info->rgltr_name[ps->seq_val], |
| 2313 | soc_info->rgltr_min_volt[ps->seq_val], |
| 2314 | soc_info->rgltr_max_volt[ps->seq_val], |
| 2315 | soc_info->rgltr_op_mode[ps->seq_val], |
| 2316 | soc_info->rgltr_delay[ps->seq_val]); |
| 2317 | if (ret) { |
| 2318 | CAM_ERR(CAM_SENSOR, |
| 2319 | "Reg: %s disable failed", |
| 2320 | soc_info->rgltr_name[ |
| 2321 | ps->seq_val]); |
| 2322 | soc_info->rgltr[ps->seq_val] = |
| 2323 | NULL; |
| 2324 | msm_cam_sensor_handle_reg_gpio( |
| 2325 | pd->seq_type, |
| 2326 | gpio_num_info, |
| 2327 | GPIOF_OUT_INIT_LOW); |
| 2328 | continue; |
| 2329 | } |
| 2330 | ps->data[0] = |
| 2331 | soc_info->rgltr[ps->seq_val]; |
| 2332 | regulator_put( |
| 2333 | soc_info->rgltr[ps->seq_val]); |
| 2334 | soc_info->rgltr[ps->seq_val] = NULL; |
| 2335 | } else { |
| 2336 | CAM_ERR(CAM_SENSOR, |
| 2337 | "seq_val:%d > num_vreg: %d", |
| 2338 | pd->seq_val, |
| 2339 | num_vreg); |
| 2340 | } |
| 2341 | } else |
| 2342 | CAM_ERR(CAM_SENSOR, |
| 2343 | "error in power up/down seq"); |
| 2344 | |
| 2345 | ret = msm_cam_sensor_handle_reg_gpio(pd->seq_type, |
| 2346 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 2347 | |
| 2348 | if (ret < 0) |
| 2349 | CAM_ERR(CAM_SENSOR, |
| 2350 | "Error disabling VREG GPIO"); |
| 2351 | break; |
| 2352 | default: |
| 2353 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 2354 | pd->seq_type); |
| 2355 | break; |
| 2356 | } |
| 2357 | if (pd->delay > 20) |
| 2358 | msleep(pd->delay); |
| 2359 | else if (pd->delay) |
| 2360 | usleep_range(pd->delay * 1000, |
| 2361 | (pd->delay * 1000) + 1000); |
| 2362 | } |
| 2363 | |
| 2364 | if (ctrl->cam_pinctrl_status) { |
| 2365 | ret = pinctrl_select_state( |
| 2366 | ctrl->pinctrl_info.pinctrl, |
| 2367 | ctrl->pinctrl_info.gpio_state_suspend); |
| 2368 | if (ret) |
| 2369 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
| 2370 | |
| 2371 | devm_pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 2372 | } |
| 2373 | |
| 2374 | if (soc_info->use_shared_clk) |
| 2375 | cam_res_mgr_shared_clk_config(false); |
| 2376 | |
| 2377 | cam_res_mgr_shared_pinctrl_select_state(false); |
| 2378 | cam_res_mgr_shared_pinctrl_put(); |
| 2379 | |
| 2380 | ctrl->cam_pinctrl_status = 0; |
| 2381 | |
| 2382 | cam_sensor_util_request_gpio_table(soc_info, 0); |
| 2383 | |
| 2384 | return 0; |
| 2385 | } |