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 | #include <linux/kernel.h> |
| 14 | #include "cam_sensor_util.h" |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 15 | #include <cam_mem_mgr.h> |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 16 | #include "cam_res_mgr_api.h" |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 17 | |
| 18 | #define CAM_SENSOR_PINCTRL_STATE_SLEEP "cam_suspend" |
| 19 | #define CAM_SENSOR_PINCTRL_STATE_DEFAULT "cam_default" |
| 20 | |
| 21 | #define VALIDATE_VOLTAGE(min, max, config_val) ((config_val) && \ |
| 22 | (config_val >= min) && (config_val <= max)) |
| 23 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 24 | static struct i2c_settings_list* |
| 25 | cam_sensor_get_i2c_ptr(struct i2c_settings_array *i2c_reg_settings, |
| 26 | uint32_t size) |
| 27 | { |
| 28 | struct i2c_settings_list *tmp; |
| 29 | |
| 30 | tmp = (struct i2c_settings_list *) |
| 31 | kzalloc(sizeof(struct i2c_settings_list), GFP_KERNEL); |
| 32 | |
| 33 | if (tmp != NULL) |
| 34 | list_add_tail(&(tmp->list), |
| 35 | &(i2c_reg_settings->list_head)); |
| 36 | else |
| 37 | return NULL; |
| 38 | |
| 39 | tmp->i2c_settings.reg_setting = (struct cam_sensor_i2c_reg_array *) |
| 40 | kzalloc(sizeof(struct cam_sensor_i2c_reg_array) * |
| 41 | size, GFP_KERNEL); |
| 42 | if (tmp->i2c_settings.reg_setting == NULL) { |
| 43 | list_del(&(tmp->list)); |
| 44 | kfree(tmp); |
| 45 | return NULL; |
| 46 | } |
| 47 | tmp->i2c_settings.size = size; |
| 48 | |
| 49 | return tmp; |
| 50 | } |
| 51 | |
| 52 | int32_t delete_request(struct i2c_settings_array *i2c_array) |
| 53 | { |
| 54 | struct i2c_settings_list *i2c_list = NULL, *i2c_next = NULL; |
| 55 | int32_t rc = 0; |
| 56 | |
| 57 | if (i2c_array == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 58 | CAM_ERR(CAM_SENSOR, "FATAL:: Invalid argument"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | } |
| 61 | |
| 62 | list_for_each_entry_safe(i2c_list, i2c_next, |
| 63 | &(i2c_array->list_head), list) { |
| 64 | kfree(i2c_list->i2c_settings.reg_setting); |
| 65 | list_del(&(i2c_list->list)); |
| 66 | kfree(i2c_list); |
| 67 | } |
| 68 | INIT_LIST_HEAD(&(i2c_array->list_head)); |
| 69 | i2c_array->is_settings_valid = 0; |
| 70 | |
| 71 | return rc; |
| 72 | } |
| 73 | |
| 74 | int32_t cam_sensor_handle_delay( |
| 75 | uint32_t **cmd_buf, |
| 76 | uint16_t generic_op_code, |
| 77 | struct i2c_settings_array *i2c_reg_settings, |
| 78 | uint32_t offset, uint32_t *byte_cnt, |
| 79 | struct list_head *list_ptr) |
| 80 | { |
| 81 | int32_t rc = 0; |
| 82 | struct cam_cmd_unconditional_wait *cmd_uncond_wait = |
| 83 | (struct cam_cmd_unconditional_wait *) *cmd_buf; |
| 84 | struct i2c_settings_list *i2c_list = NULL; |
| 85 | |
Viswanadha Raju Thotakura | 3bf35c2 | 2017-08-31 10:48:30 -0700 | [diff] [blame] | 86 | if (list_ptr == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 87 | CAM_ERR(CAM_SENSOR, "Invalid list ptr"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | if (offset > 0) { |
| 92 | i2c_list = |
| 93 | list_entry(list_ptr, struct i2c_settings_list, list); |
| 94 | if (generic_op_code == |
| 95 | CAMERA_SENSOR_WAIT_OP_HW_UCND) |
| 96 | i2c_list->i2c_settings. |
| 97 | reg_setting[offset - 1].delay = |
| 98 | cmd_uncond_wait->delay; |
| 99 | else |
| 100 | i2c_list->i2c_settings.delay = |
| 101 | cmd_uncond_wait->delay; |
| 102 | (*cmd_buf) += |
| 103 | sizeof( |
| 104 | struct cam_cmd_unconditional_wait) / sizeof(uint32_t); |
| 105 | (*byte_cnt) += |
| 106 | sizeof( |
| 107 | struct cam_cmd_unconditional_wait); |
| 108 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 109 | CAM_ERR(CAM_SENSOR, "Delay Rxed Before any buffer: %d", offset); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 110 | return -EINVAL; |
| 111 | } |
| 112 | |
| 113 | return rc; |
| 114 | } |
| 115 | |
| 116 | int32_t cam_sensor_handle_poll( |
| 117 | uint32_t **cmd_buf, |
| 118 | struct i2c_settings_array *i2c_reg_settings, |
| 119 | uint32_t *byte_cnt, int32_t *offset, |
| 120 | struct list_head **list_ptr) |
| 121 | { |
| 122 | struct i2c_settings_list *i2c_list; |
| 123 | int32_t rc = 0; |
| 124 | struct cam_cmd_conditional_wait *cond_wait |
| 125 | = (struct cam_cmd_conditional_wait *) *cmd_buf; |
| 126 | |
| 127 | i2c_list = |
| 128 | cam_sensor_get_i2c_ptr(i2c_reg_settings, 1); |
| 129 | if (!i2c_list || !i2c_list->i2c_settings.reg_setting) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 130 | CAM_ERR(CAM_SENSOR, "Failed in allocating mem for list"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 131 | return -ENOMEM; |
| 132 | } |
| 133 | |
| 134 | i2c_list->op_code = CAM_SENSOR_I2C_POLL; |
| 135 | i2c_list->i2c_settings.data_type = |
| 136 | cond_wait->data_type; |
| 137 | i2c_list->i2c_settings.addr_type = |
| 138 | cond_wait->addr_type; |
| 139 | i2c_list->i2c_settings.reg_setting->reg_addr = |
| 140 | cond_wait->reg_addr; |
| 141 | i2c_list->i2c_settings.reg_setting->reg_data = |
| 142 | cond_wait->reg_data; |
| 143 | i2c_list->i2c_settings.reg_setting->delay = |
| 144 | cond_wait->timeout; |
| 145 | |
| 146 | (*cmd_buf) += sizeof(struct cam_cmd_conditional_wait) / |
| 147 | sizeof(uint32_t); |
| 148 | (*byte_cnt) += sizeof(struct cam_cmd_conditional_wait); |
| 149 | |
| 150 | (*offset) += 1; |
| 151 | *list_ptr = &(i2c_list->list); |
| 152 | |
| 153 | return rc; |
| 154 | } |
| 155 | |
| 156 | int32_t cam_sensor_handle_random_write( |
| 157 | struct cam_cmd_i2c_random_wr *cam_cmd_i2c_random_wr, |
| 158 | struct i2c_settings_array *i2c_reg_settings, |
| 159 | uint16_t *cmd_length_in_bytes, int32_t *offset, |
| 160 | struct list_head **list) |
| 161 | { |
| 162 | struct i2c_settings_list *i2c_list; |
| 163 | int32_t rc = 0, cnt; |
| 164 | |
| 165 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 166 | cam_cmd_i2c_random_wr->header.count); |
| 167 | if (i2c_list == NULL || |
| 168 | i2c_list->i2c_settings.reg_setting == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 169 | CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 170 | return -ENOMEM; |
| 171 | } |
| 172 | |
| 173 | *cmd_length_in_bytes = (sizeof(struct i2c_rdwr_header) + |
| 174 | sizeof(struct i2c_random_wr_payload) * |
| 175 | (cam_cmd_i2c_random_wr->header.count)); |
| 176 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_RANDOM; |
| 177 | i2c_list->i2c_settings.addr_type = |
| 178 | cam_cmd_i2c_random_wr->header.addr_type; |
| 179 | i2c_list->i2c_settings.data_type = |
| 180 | cam_cmd_i2c_random_wr->header.data_type; |
| 181 | |
| 182 | for (cnt = 0; cnt < (cam_cmd_i2c_random_wr->header.count); |
| 183 | cnt++) { |
| 184 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 185 | cam_cmd_i2c_random_wr-> |
| 186 | random_wr_payload[cnt].reg_addr; |
| 187 | i2c_list->i2c_settings. |
| 188 | reg_setting[cnt].reg_data = |
| 189 | cam_cmd_i2c_random_wr-> |
| 190 | random_wr_payload[cnt].reg_data; |
| 191 | i2c_list->i2c_settings. |
| 192 | reg_setting[cnt].data_mask = 0; |
| 193 | } |
| 194 | (*offset) += cnt; |
| 195 | *list = &(i2c_list->list); |
| 196 | |
| 197 | return rc; |
| 198 | } |
| 199 | |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 200 | static int32_t cam_sensor_handle_continuous_write( |
| 201 | struct cam_cmd_i2c_continuous_wr *cam_cmd_i2c_continuous_wr, |
| 202 | struct i2c_settings_array *i2c_reg_settings, |
| 203 | uint16_t *cmd_length_in_bytes, int32_t *offset, |
| 204 | struct list_head **list) |
| 205 | { |
| 206 | struct i2c_settings_list *i2c_list; |
| 207 | int32_t rc = 0, cnt; |
| 208 | |
| 209 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 210 | cam_cmd_i2c_continuous_wr->header.count); |
| 211 | if (i2c_list == NULL || |
| 212 | i2c_list->i2c_settings.reg_setting == NULL) { |
| 213 | CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list"); |
| 214 | return -ENOMEM; |
| 215 | } |
| 216 | |
| 217 | *cmd_length_in_bytes = (sizeof(struct i2c_rdwr_header) + |
| 218 | sizeof(cam_cmd_i2c_continuous_wr->reg_addr) + |
| 219 | sizeof(struct cam_cmd_read) * |
| 220 | (cam_cmd_i2c_continuous_wr->header.count)); |
Karthik Anantha Ram | 3d846ad | 2017-09-26 10:21:33 -0700 | [diff] [blame] | 221 | if (cam_cmd_i2c_continuous_wr->header.op_code == |
| 222 | CAMERA_SENSOR_I2C_OP_CONT_WR_BRST) |
| 223 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_BURST; |
| 224 | else if (cam_cmd_i2c_continuous_wr->header.op_code == |
| 225 | CAMERA_SENSOR_I2C_OP_CONT_WR_SEQN) |
| 226 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_SEQ; |
| 227 | else |
| 228 | return -EINVAL; |
| 229 | |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 230 | i2c_list->i2c_settings.addr_type = |
| 231 | cam_cmd_i2c_continuous_wr->header.addr_type; |
Karthik Anantha Ram | 3d846ad | 2017-09-26 10:21:33 -0700 | [diff] [blame] | 232 | i2c_list->i2c_settings.data_type = |
| 233 | cam_cmd_i2c_continuous_wr->header.data_type; |
Jigarkumar Zala | 75fd425 | 2017-11-14 12:44:58 -0800 | [diff] [blame] | 234 | i2c_list->i2c_settings.size = |
| 235 | cam_cmd_i2c_continuous_wr->header.count; |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 236 | |
| 237 | for (cnt = 0; cnt < (cam_cmd_i2c_continuous_wr->header.count); |
| 238 | cnt++) { |
| 239 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 240 | cam_cmd_i2c_continuous_wr-> |
| 241 | reg_addr; |
| 242 | i2c_list->i2c_settings. |
| 243 | reg_setting[cnt].reg_data = |
| 244 | cam_cmd_i2c_continuous_wr-> |
| 245 | data_read[cnt].reg_data; |
| 246 | i2c_list->i2c_settings. |
| 247 | reg_setting[cnt].data_mask = 0; |
| 248 | } |
| 249 | (*offset) += cnt; |
| 250 | *list = &(i2c_list->list); |
| 251 | |
| 252 | return rc; |
| 253 | } |
| 254 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 255 | /** |
Soundrapandian Jeyaprakash | 320e75e | 2017-10-08 07:06:54 -0700 | [diff] [blame] | 256 | * Name : cam_sensor_i2c_command_parser |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 257 | * Description : Parse CSL CCI packet and apply register settings |
| 258 | * Parameters : s_ctrl input/output sub_device |
| 259 | * arg input cam_control |
| 260 | * Description : |
| 261 | * Handle multiple I2C RD/WR and WAIT cmd formats in one command |
| 262 | * buffer, for example, a command buffer of m x RND_WR + 1 x HW_ |
| 263 | * WAIT + n x RND_WR with num_cmd_buf = 1. Do not exepect RD/WR |
| 264 | * with different cmd_type and op_code in one command buffer. |
| 265 | */ |
Soundrapandian Jeyaprakash | 320e75e | 2017-10-08 07:06:54 -0700 | [diff] [blame] | 266 | int cam_sensor_i2c_command_parser(struct i2c_settings_array *i2c_reg_settings, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 267 | struct cam_cmd_buf_desc *cmd_desc, int32_t num_cmd_buffers) |
| 268 | { |
| 269 | int16_t rc = 0, i = 0; |
| 270 | size_t len_of_buff = 0; |
| 271 | uint64_t generic_ptr; |
| 272 | |
| 273 | for (i = 0; i < num_cmd_buffers; i++) { |
| 274 | uint32_t *cmd_buf = NULL; |
| 275 | struct common_header *cmm_hdr; |
| 276 | uint16_t generic_op_code; |
| 277 | uint32_t byte_cnt = 0; |
| 278 | uint32_t j = 0; |
| 279 | struct list_head *list = NULL; |
| 280 | |
| 281 | /* |
| 282 | * It is not expected the same settings to |
| 283 | * be spread across multiple cmd buffers |
| 284 | */ |
| 285 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 286 | CAM_DBG(CAM_SENSOR, "Total cmd Buf in Bytes: %d", |
| 287 | cmd_desc[i].length); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 288 | |
| 289 | if (!cmd_desc[i].length) |
| 290 | continue; |
| 291 | |
| 292 | rc = cam_mem_get_cpu_buf(cmd_desc[i].mem_handle, |
| 293 | (uint64_t *)&generic_ptr, &len_of_buff); |
| 294 | cmd_buf = (uint32_t *)generic_ptr; |
| 295 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 296 | CAM_ERR(CAM_SENSOR, |
| 297 | "cmd hdl failed:%d, Err: %d, Buffer_len: %ld", |
| 298 | cmd_desc[i].mem_handle, rc, len_of_buff); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 299 | return rc; |
| 300 | } |
| 301 | cmd_buf += cmd_desc[i].offset / sizeof(uint32_t); |
| 302 | |
| 303 | while (byte_cnt < cmd_desc[i].length) { |
| 304 | cmm_hdr = (struct common_header *)cmd_buf; |
| 305 | generic_op_code = cmm_hdr->third_byte; |
| 306 | switch (cmm_hdr->cmd_type) { |
| 307 | case CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_WR: { |
| 308 | uint16_t cmd_length_in_bytes = 0; |
| 309 | struct cam_cmd_i2c_random_wr |
| 310 | *cam_cmd_i2c_random_wr = |
| 311 | (struct cam_cmd_i2c_random_wr *)cmd_buf; |
| 312 | |
| 313 | rc = cam_sensor_handle_random_write( |
| 314 | cam_cmd_i2c_random_wr, |
| 315 | i2c_reg_settings, |
| 316 | &cmd_length_in_bytes, &j, &list); |
| 317 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 318 | CAM_ERR(CAM_SENSOR, |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 319 | "Failed in random write %d", rc); |
| 320 | return rc; |
| 321 | } |
| 322 | |
| 323 | cmd_buf += cmd_length_in_bytes / |
| 324 | sizeof(uint32_t); |
| 325 | byte_cnt += cmd_length_in_bytes; |
| 326 | break; |
| 327 | } |
| 328 | case CAMERA_SENSOR_CMD_TYPE_I2C_CONT_WR: { |
| 329 | uint16_t cmd_length_in_bytes = 0; |
| 330 | struct cam_cmd_i2c_continuous_wr |
| 331 | *cam_cmd_i2c_continuous_wr = |
| 332 | (struct cam_cmd_i2c_continuous_wr *) |
| 333 | cmd_buf; |
| 334 | |
| 335 | rc = cam_sensor_handle_continuous_write( |
| 336 | cam_cmd_i2c_continuous_wr, |
| 337 | i2c_reg_settings, |
| 338 | &cmd_length_in_bytes, &j, &list); |
| 339 | if (rc < 0) { |
| 340 | CAM_ERR(CAM_SENSOR, |
| 341 | "Failed in continuous write %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 342 | return rc; |
| 343 | } |
| 344 | |
| 345 | cmd_buf += cmd_length_in_bytes / |
| 346 | sizeof(uint32_t); |
| 347 | byte_cnt += cmd_length_in_bytes; |
| 348 | break; |
| 349 | } |
| 350 | case CAMERA_SENSOR_CMD_TYPE_WAIT: { |
| 351 | if (generic_op_code == |
| 352 | CAMERA_SENSOR_WAIT_OP_HW_UCND || |
| 353 | generic_op_code == |
| 354 | CAMERA_SENSOR_WAIT_OP_SW_UCND) { |
| 355 | |
| 356 | rc = cam_sensor_handle_delay( |
| 357 | &cmd_buf, generic_op_code, |
| 358 | i2c_reg_settings, j, &byte_cnt, |
| 359 | list); |
| 360 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 361 | CAM_ERR(CAM_SENSOR, |
| 362 | "delay hdl failed: %d", |
| 363 | rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 364 | return rc; |
| 365 | } |
| 366 | |
| 367 | } else if (generic_op_code == |
| 368 | CAMERA_SENSOR_WAIT_OP_COND) { |
| 369 | rc = cam_sensor_handle_poll( |
| 370 | &cmd_buf, i2c_reg_settings, |
| 371 | &byte_cnt, &j, &list); |
| 372 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 373 | CAM_ERR(CAM_SENSOR, |
| 374 | "Random read fail: %d", |
| 375 | rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 376 | return rc; |
| 377 | } |
| 378 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 379 | CAM_ERR(CAM_SENSOR, |
| 380 | "Wrong Wait Command: %d", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 381 | generic_op_code); |
| 382 | return -EINVAL; |
| 383 | } |
| 384 | break; |
| 385 | } |
| 386 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 387 | CAM_ERR(CAM_SENSOR, "Invalid Command Type:%d", |
| 388 | cmm_hdr->cmd_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 389 | return -EINVAL; |
| 390 | } |
| 391 | } |
| 392 | i2c_reg_settings->is_settings_valid = 1; |
| 393 | } |
| 394 | |
| 395 | return rc; |
| 396 | } |
| 397 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 398 | int32_t msm_camera_fill_vreg_params( |
| 399 | struct cam_hw_soc_info *soc_info, |
| 400 | struct cam_sensor_power_setting *power_setting, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 401 | uint16_t power_setting_size) |
| 402 | { |
| 403 | int32_t rc = 0, j = 0, i = 0; |
Jigarkumar Zala | c6c090b | 2017-09-21 15:04:56 -0700 | [diff] [blame] | 404 | int num_vreg; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 405 | |
| 406 | /* Validate input parameters */ |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 407 | if (!soc_info || !power_setting) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 408 | CAM_ERR(CAM_SENSOR, "failed: soc_info %pK power_setting %pK", |
| 409 | soc_info, power_setting); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 410 | return -EINVAL; |
| 411 | } |
| 412 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 413 | num_vreg = soc_info->num_rgltr; |
| 414 | |
Jigarkumar Zala | c6c090b | 2017-09-21 15:04:56 -0700 | [diff] [blame] | 415 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 416 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | for (i = 0; i < power_setting_size; i++) { |
Viswanadha Raju Thotakura | 2c5c1a1 | 2017-08-23 15:56:22 -0700 | [diff] [blame] | 421 | |
| 422 | if (power_setting[i].seq_type < SENSOR_MCLK || |
| 423 | power_setting[i].seq_type >= SENSOR_SEQ_TYPE_MAX) { |
| 424 | CAM_ERR(CAM_SENSOR, "failed: Invalid Seq type\n", |
| 425 | power_setting[i].seq_type); |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 429 | switch (power_setting[i].seq_type) { |
| 430 | case SENSOR_VDIG: |
| 431 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 432 | if (!strcmp(soc_info->rgltr_name[j], |
| 433 | "cam_vdig")) { |
| 434 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 435 | CAM_DBG(CAM_SENSOR, |
| 436 | "i: %d j: %d cam_vdig", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 437 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 438 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 439 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 440 | soc_info->rgltr_min_volt[j], |
| 441 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 442 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 443 | soc_info->rgltr_min_volt[j] = |
| 444 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 445 | power_setting[i].config_val; |
| 446 | } |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | if (j == num_vreg) |
| 451 | power_setting[i].seq_val = INVALID_VREG; |
| 452 | break; |
| 453 | |
| 454 | case SENSOR_VIO: |
| 455 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 456 | |
| 457 | if (!strcmp(soc_info->rgltr_name[j], |
| 458 | "cam_vio")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 459 | CAM_DBG(CAM_SENSOR, |
| 460 | "i: %d j: %d cam_vio", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 461 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 462 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 463 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 464 | soc_info->rgltr_min_volt[j], |
| 465 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 466 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 467 | soc_info->rgltr_min_volt[j] = |
| 468 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 469 | power_setting[i].config_val; |
| 470 | } |
| 471 | break; |
| 472 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 473 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 474 | } |
| 475 | if (j == num_vreg) |
| 476 | power_setting[i].seq_val = INVALID_VREG; |
| 477 | break; |
| 478 | |
| 479 | case SENSOR_VANA: |
| 480 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 481 | |
| 482 | if (!strcmp(soc_info->rgltr_name[j], |
| 483 | "cam_vana")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 484 | CAM_DBG(CAM_SENSOR, |
| 485 | "i: %d j: %d cam_vana", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 486 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 487 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 488 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 489 | soc_info->rgltr_min_volt[j], |
| 490 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 491 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 492 | soc_info->rgltr_min_volt[j] = |
| 493 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 494 | power_setting[i].config_val; |
| 495 | } |
| 496 | break; |
| 497 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 498 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 499 | } |
| 500 | if (j == num_vreg) |
| 501 | power_setting[i].seq_val = INVALID_VREG; |
| 502 | break; |
| 503 | |
| 504 | case SENSOR_VAF: |
| 505 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 506 | |
| 507 | if (!strcmp(soc_info->rgltr_name[j], |
| 508 | "cam_vaf")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 509 | CAM_DBG(CAM_SENSOR, |
| 510 | "i: %d j: %d cam_vaf", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 511 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 512 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 513 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 514 | soc_info->rgltr_min_volt[j], |
| 515 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 516 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 517 | soc_info->rgltr_min_volt[j] = |
| 518 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 519 | power_setting[i].config_val; |
| 520 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 521 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 522 | break; |
| 523 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 524 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 525 | } |
| 526 | if (j == num_vreg) |
| 527 | power_setting[i].seq_val = INVALID_VREG; |
| 528 | break; |
| 529 | |
| 530 | case SENSOR_CUSTOM_REG1: |
| 531 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 532 | |
| 533 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 534 | "cam_v_custom1")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 535 | CAM_DBG(CAM_SENSOR, |
| 536 | "i:%d j:%d cam_vcustom1", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 537 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 538 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 539 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 540 | soc_info->rgltr_min_volt[j], |
| 541 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 542 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 543 | soc_info->rgltr_min_volt[j] = |
| 544 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 545 | power_setting[i].config_val; |
| 546 | } |
| 547 | break; |
| 548 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 549 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 550 | } |
| 551 | if (j == num_vreg) |
| 552 | power_setting[i].seq_val = INVALID_VREG; |
| 553 | break; |
| 554 | case SENSOR_CUSTOM_REG2: |
| 555 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 556 | |
| 557 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 558 | "cam_v_custom2")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 559 | CAM_DBG(CAM_SENSOR, |
| 560 | "i:%d j:%d cam_vcustom2", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 561 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 562 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 563 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 564 | soc_info->rgltr_min_volt[j], |
| 565 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 566 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 567 | soc_info->rgltr_min_volt[j] = |
| 568 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 569 | power_setting[i].config_val; |
| 570 | } |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | if (j == num_vreg) |
| 575 | power_setting[i].seq_val = INVALID_VREG; |
| 576 | break; |
Viswanadha Raju Thotakura | 2c5c1a1 | 2017-08-23 15:56:22 -0700 | [diff] [blame] | 577 | default: |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 578 | break; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
| 582 | return rc; |
| 583 | } |
| 584 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 585 | int cam_sensor_util_request_gpio_table( |
| 586 | struct cam_hw_soc_info *soc_info, int gpio_en) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 587 | { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 588 | int rc = 0, i = 0; |
| 589 | uint8_t size = 0; |
| 590 | struct cam_soc_gpio_data *gpio_conf = |
| 591 | soc_info->gpio_data; |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 592 | struct gpio *gpio_tbl = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 593 | |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 594 | if (!gpio_conf) { |
| 595 | CAM_INFO(CAM_SENSOR, "No GPIO data"); |
| 596 | return 0; |
| 597 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 598 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 599 | if (gpio_conf->cam_gpio_common_tbl_size <= 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 600 | CAM_INFO(CAM_SENSOR, "No GPIO entry"); |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 601 | return -EINVAL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 604 | gpio_tbl = gpio_conf->cam_gpio_req_tbl; |
| 605 | size = gpio_conf->cam_gpio_req_tbl_size; |
| 606 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 607 | if (!gpio_tbl || !size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 608 | CAM_ERR(CAM_SENSOR, "invalid gpio_tbl %pK / size %d", |
| 609 | gpio_tbl, size); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 610 | return -EINVAL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 613 | for (i = 0; i < size; i++) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 614 | CAM_DBG(CAM_SENSOR, "i: %d, gpio %d dir %ld", i, |
| 615 | gpio_tbl[i].gpio, gpio_tbl[i].flags); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if (gpio_en) { |
| 619 | for (i = 0; i < size; i++) { |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 620 | rc = cam_res_mgr_gpio_request(soc_info->dev, |
| 621 | gpio_tbl[i].gpio, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 622 | gpio_tbl[i].flags, gpio_tbl[i].label); |
| 623 | if (rc) { |
| 624 | /* |
| 625 | * After GPIO request fails, contine to |
| 626 | * apply new gpios, outout a error message |
| 627 | * for driver bringup debug |
| 628 | */ |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 629 | CAM_ERR(CAM_SENSOR, "gpio %d:%s request fails", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 630 | gpio_tbl[i].gpio, gpio_tbl[i].label); |
| 631 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 632 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 633 | } else { |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 634 | cam_res_mgr_gpio_free_arry(soc_info->dev, gpio_tbl, size); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 637 | return rc; |
| 638 | } |
| 639 | |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 640 | int32_t cam_sensor_update_power_settings(void *cmd_buf, |
| 641 | int cmd_length, struct cam_sensor_power_ctrl_t *power_info) |
| 642 | { |
| 643 | int32_t rc = 0, tot_size = 0, last_cmd_type = 0; |
| 644 | int32_t i = 0, pwr_up = 0, pwr_down = 0; |
| 645 | void *ptr = cmd_buf, *scr; |
| 646 | struct cam_cmd_power *pwr_cmd = (struct cam_cmd_power *)cmd_buf; |
| 647 | struct common_header *cmm_hdr = (struct common_header *)cmd_buf; |
| 648 | |
| 649 | if (!pwr_cmd || !cmd_length) { |
| 650 | CAM_ERR(CAM_SENSOR, "Invalid Args: pwr_cmd %pK, cmd_length: %d", |
| 651 | pwr_cmd, cmd_length); |
| 652 | return -EINVAL; |
| 653 | } |
| 654 | |
| 655 | power_info->power_setting_size = 0; |
| 656 | power_info->power_setting = |
| 657 | (struct cam_sensor_power_setting *) |
| 658 | kzalloc(sizeof(struct cam_sensor_power_setting) * |
| 659 | MAX_POWER_CONFIG, GFP_KERNEL); |
| 660 | if (!power_info->power_setting) |
| 661 | return -ENOMEM; |
| 662 | |
Soundrapandian Jeyaprakash | 687b32e | 2017-07-28 14:38:56 -0700 | [diff] [blame] | 663 | power_info->power_down_setting_size = 0; |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 664 | power_info->power_down_setting = |
| 665 | (struct cam_sensor_power_setting *) |
| 666 | kzalloc(sizeof(struct cam_sensor_power_setting) * |
| 667 | MAX_POWER_CONFIG, GFP_KERNEL); |
| 668 | if (!power_info->power_down_setting) { |
| 669 | rc = -ENOMEM; |
| 670 | goto free_power_settings; |
| 671 | } |
| 672 | |
| 673 | while (tot_size < cmd_length) { |
| 674 | if (cmm_hdr->cmd_type == |
| 675 | CAMERA_SENSOR_CMD_TYPE_PWR_UP) { |
| 676 | struct cam_cmd_power *pwr_cmd = |
| 677 | (struct cam_cmd_power *)ptr; |
| 678 | |
| 679 | power_info-> |
| 680 | power_setting_size += |
| 681 | pwr_cmd->count; |
| 682 | scr = ptr + sizeof(struct cam_cmd_power); |
| 683 | tot_size = tot_size + sizeof(struct cam_cmd_power); |
| 684 | |
| 685 | if (pwr_cmd->count == 0) |
| 686 | CAM_DBG(CAM_SENSOR, "Un expected Command"); |
| 687 | |
| 688 | for (i = 0; i < pwr_cmd->count; i++, pwr_up++) { |
| 689 | power_info-> |
| 690 | power_setting[pwr_up].seq_type = |
| 691 | pwr_cmd->power_settings[i]. |
| 692 | power_seq_type; |
| 693 | power_info-> |
| 694 | power_setting[pwr_up].config_val = |
| 695 | pwr_cmd->power_settings[i]. |
| 696 | config_val_low; |
| 697 | power_info->power_setting[pwr_up].delay = 0; |
| 698 | if (i) { |
| 699 | scr = scr + |
| 700 | sizeof( |
| 701 | struct cam_power_settings); |
| 702 | tot_size = tot_size + |
| 703 | sizeof( |
| 704 | struct cam_power_settings); |
| 705 | } |
| 706 | if (tot_size > cmd_length) { |
| 707 | CAM_ERR(CAM_SENSOR, |
| 708 | "Error: Cmd Buffer is wrong"); |
| 709 | rc = -EINVAL; |
| 710 | goto free_power_down_settings; |
| 711 | } |
| 712 | CAM_DBG(CAM_SENSOR, |
| 713 | "Seq Type[%d]: %d Config_val: %ld", |
| 714 | pwr_up, |
| 715 | power_info-> |
| 716 | power_setting[pwr_up].seq_type, |
| 717 | power_info-> |
| 718 | power_setting[pwr_up]. |
| 719 | config_val); |
| 720 | } |
| 721 | last_cmd_type = CAMERA_SENSOR_CMD_TYPE_PWR_UP; |
| 722 | ptr = (void *) scr; |
| 723 | cmm_hdr = (struct common_header *)ptr; |
| 724 | } else if (cmm_hdr->cmd_type == CAMERA_SENSOR_CMD_TYPE_WAIT) { |
| 725 | struct cam_cmd_unconditional_wait *wait_cmd = |
| 726 | (struct cam_cmd_unconditional_wait *)ptr; |
| 727 | if (wait_cmd->op_code == |
| 728 | CAMERA_SENSOR_WAIT_OP_SW_UCND) { |
| 729 | if (last_cmd_type == |
| 730 | CAMERA_SENSOR_CMD_TYPE_PWR_UP) { |
| 731 | if (pwr_up > 0) |
| 732 | power_info-> |
| 733 | power_setting |
| 734 | [pwr_up - 1].delay += |
| 735 | wait_cmd->delay; |
| 736 | else |
| 737 | CAM_ERR(CAM_SENSOR, |
| 738 | "Delay is expected only after valid power up setting"); |
| 739 | } else if (last_cmd_type == |
| 740 | CAMERA_SENSOR_CMD_TYPE_PWR_DOWN) { |
| 741 | if (pwr_down > 0) |
| 742 | power_info-> |
| 743 | power_down_setting |
| 744 | [pwr_down - 1].delay += |
| 745 | wait_cmd->delay; |
| 746 | else |
| 747 | CAM_ERR(CAM_SENSOR, |
| 748 | "Delay is expected only after valid power up setting"); |
| 749 | } |
| 750 | } else |
| 751 | CAM_DBG(CAM_SENSOR, "Invalid op code: %d", |
| 752 | wait_cmd->op_code); |
| 753 | tot_size = tot_size + |
| 754 | sizeof(struct cam_cmd_unconditional_wait); |
| 755 | if (tot_size > cmd_length) { |
| 756 | CAM_ERR(CAM_SENSOR, "Command Buffer is wrong"); |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | scr = (void *) (wait_cmd); |
| 760 | ptr = (void *) |
| 761 | (scr + |
| 762 | sizeof(struct cam_cmd_unconditional_wait)); |
| 763 | CAM_DBG(CAM_SENSOR, "ptr: %pK sizeof: %d Next: %pK", |
| 764 | scr, (int32_t)sizeof( |
| 765 | struct cam_cmd_unconditional_wait), ptr); |
| 766 | |
| 767 | cmm_hdr = (struct common_header *)ptr; |
| 768 | } else if (cmm_hdr->cmd_type == |
| 769 | CAMERA_SENSOR_CMD_TYPE_PWR_DOWN) { |
| 770 | struct cam_cmd_power *pwr_cmd = |
| 771 | (struct cam_cmd_power *)ptr; |
| 772 | |
| 773 | scr = ptr + sizeof(struct cam_cmd_power); |
| 774 | tot_size = tot_size + sizeof(struct cam_cmd_power); |
| 775 | power_info->power_down_setting_size += pwr_cmd->count; |
| 776 | |
| 777 | if (pwr_cmd->count == 0) |
| 778 | CAM_ERR(CAM_SENSOR, "Invalid Command"); |
| 779 | |
| 780 | for (i = 0; i < pwr_cmd->count; i++, pwr_down++) { |
| 781 | power_info-> |
| 782 | power_down_setting[pwr_down]. |
| 783 | seq_type = |
| 784 | pwr_cmd->power_settings[i]. |
| 785 | power_seq_type; |
| 786 | power_info-> |
| 787 | power_down_setting[pwr_down]. |
| 788 | config_val = |
| 789 | pwr_cmd->power_settings[i]. |
| 790 | config_val_low; |
| 791 | power_info-> |
| 792 | power_down_setting[pwr_down].delay = 0; |
| 793 | if (i) { |
| 794 | scr = scr + |
| 795 | sizeof( |
| 796 | struct cam_power_settings); |
| 797 | tot_size = |
| 798 | tot_size + |
| 799 | sizeof( |
| 800 | struct cam_power_settings); |
| 801 | } |
| 802 | if (tot_size > cmd_length) { |
| 803 | CAM_ERR(CAM_SENSOR, |
| 804 | "Command Buffer is wrong"); |
| 805 | rc = -EINVAL; |
| 806 | goto free_power_down_settings; |
| 807 | } |
| 808 | CAM_DBG(CAM_SENSOR, |
| 809 | "Seq Type[%d]: %d Config_val: %ld", |
| 810 | pwr_down, |
| 811 | power_info-> |
| 812 | power_down_setting[pwr_down]. |
| 813 | seq_type, |
| 814 | power_info-> |
| 815 | power_down_setting[pwr_down]. |
| 816 | config_val); |
| 817 | } |
| 818 | last_cmd_type = CAMERA_SENSOR_CMD_TYPE_PWR_DOWN; |
| 819 | ptr = (void *) scr; |
| 820 | cmm_hdr = (struct common_header *)ptr; |
| 821 | } else { |
| 822 | CAM_ERR(CAM_SENSOR, |
| 823 | "Error: Un expected Header Type: %d", |
| 824 | cmm_hdr->cmd_type); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | return rc; |
| 829 | free_power_down_settings: |
| 830 | kfree(power_info->power_down_setting); |
| 831 | free_power_settings: |
| 832 | kfree(power_info->power_setting); |
| 833 | return rc; |
| 834 | } |
| 835 | |
| 836 | int cam_get_dt_power_setting_data(struct device_node *of_node, |
| 837 | struct cam_hw_soc_info *soc_info, |
| 838 | struct cam_sensor_power_ctrl_t *power_info) |
| 839 | { |
| 840 | int rc = 0, i; |
| 841 | int count = 0; |
| 842 | const char *seq_name = NULL; |
| 843 | uint32_t *array = NULL; |
| 844 | struct cam_sensor_power_setting *ps; |
| 845 | int c, end; |
| 846 | |
| 847 | if (!power_info) |
| 848 | return -EINVAL; |
| 849 | |
| 850 | count = of_property_count_strings(of_node, "qcom,cam-power-seq-type"); |
| 851 | power_info->power_setting_size = count; |
| 852 | |
| 853 | CAM_DBG(CAM_SENSOR, "qcom,cam-power-seq-type count %d", count); |
| 854 | |
| 855 | if (count <= 0) |
| 856 | return 0; |
| 857 | |
| 858 | ps = kcalloc(count, sizeof(*ps), GFP_KERNEL); |
| 859 | if (!ps) |
| 860 | return -ENOMEM; |
| 861 | power_info->power_setting = ps; |
| 862 | |
| 863 | for (i = 0; i < count; i++) { |
| 864 | rc = of_property_read_string_index(of_node, |
| 865 | "qcom,cam-power-seq-type", i, &seq_name); |
| 866 | if (rc < 0) { |
| 867 | CAM_ERR(CAM_SENSOR, "failed"); |
| 868 | goto ERROR1; |
| 869 | } |
| 870 | CAM_DBG(CAM_SENSOR, "seq_name[%d] = %s", i, seq_name); |
| 871 | if (!strcmp(seq_name, "cam_vio")) { |
| 872 | ps[i].seq_type = SENSOR_VIO; |
| 873 | } else if (!strcmp(seq_name, "cam_vana")) { |
| 874 | ps[i].seq_type = SENSOR_VANA; |
| 875 | } else if (!strcmp(seq_name, "cam_clk")) { |
| 876 | ps[i].seq_type = SENSOR_MCLK; |
| 877 | } else { |
| 878 | CAM_ERR(CAM_SENSOR, "unrecognized seq-type %s", |
| 879 | seq_name); |
| 880 | rc = -EILSEQ; |
| 881 | goto ERROR1; |
| 882 | } |
| 883 | CAM_DBG(CAM_SENSOR, "seq_type[%d] %d", i, ps[i].seq_type); |
| 884 | } |
| 885 | |
| 886 | array = kcalloc(count, sizeof(uint32_t), GFP_KERNEL); |
| 887 | if (!array) { |
| 888 | rc = -ENOMEM; |
| 889 | goto ERROR1; |
| 890 | } |
| 891 | |
| 892 | rc = of_property_read_u32_array(of_node, "qcom,cam-power-seq-cfg-val", |
| 893 | array, count); |
| 894 | if (rc < 0) { |
| 895 | CAM_ERR(CAM_SENSOR, "failed "); |
| 896 | goto ERROR2; |
| 897 | } |
| 898 | |
| 899 | for (i = 0; i < count; i++) { |
| 900 | ps[i].config_val = array[i]; |
| 901 | CAM_DBG(CAM_SENSOR, "power_setting[%d].config_val = %ld", i, |
| 902 | ps[i].config_val); |
| 903 | } |
| 904 | |
| 905 | rc = of_property_read_u32_array(of_node, "qcom,cam-power-seq-delay", |
| 906 | array, count); |
| 907 | if (rc < 0) { |
| 908 | CAM_ERR(CAM_SENSOR, "failed"); |
| 909 | goto ERROR2; |
| 910 | } |
| 911 | for (i = 0; i < count; i++) { |
| 912 | ps[i].delay = array[i]; |
| 913 | CAM_DBG(CAM_SENSOR, "power_setting[%d].delay = %d", i, |
| 914 | ps[i].delay); |
| 915 | } |
| 916 | kfree(array); |
| 917 | |
| 918 | power_info->power_down_setting = |
| 919 | kzalloc(sizeof(*ps) * count, GFP_KERNEL); |
| 920 | |
| 921 | if (!power_info->power_down_setting) { |
| 922 | CAM_ERR(CAM_SENSOR, "failed"); |
| 923 | rc = -ENOMEM; |
| 924 | goto ERROR1; |
| 925 | } |
| 926 | |
| 927 | power_info->power_down_setting_size = count; |
| 928 | |
| 929 | end = count - 1; |
| 930 | |
| 931 | for (c = 0; c < count; c++) { |
| 932 | power_info->power_down_setting[c] = ps[end]; |
| 933 | end--; |
| 934 | } |
| 935 | return rc; |
| 936 | ERROR2: |
| 937 | kfree(array); |
| 938 | ERROR1: |
| 939 | kfree(ps); |
| 940 | return rc; |
| 941 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 942 | |
| 943 | int cam_sensor_util_init_gpio_pin_tbl( |
| 944 | struct cam_hw_soc_info *soc_info, |
| 945 | struct msm_camera_gpio_num_info **pgpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 946 | { |
| 947 | int rc = 0, val = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 948 | uint32_t gpio_array_size; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 949 | struct device_node *of_node = NULL; |
| 950 | struct cam_soc_gpio_data *gconf = NULL; |
| 951 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 952 | |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 953 | if (!soc_info->dev) { |
| 954 | CAM_ERR(CAM_SENSOR, "device node NULL"); |
| 955 | return -EINVAL; |
| 956 | } |
| 957 | |
| 958 | of_node = soc_info->dev->of_node; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 959 | |
| 960 | gconf = soc_info->gpio_data; |
| 961 | if (!gconf) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 962 | CAM_ERR(CAM_SENSOR, "No gpio_common_table is found"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 963 | return -EINVAL; |
| 964 | } |
| 965 | |
| 966 | if (!gconf->cam_gpio_common_tbl) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 967 | CAM_ERR(CAM_SENSOR, "gpio_common_table is not initialized"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 968 | return -EINVAL; |
| 969 | } |
| 970 | |
| 971 | gpio_array_size = gconf->cam_gpio_common_tbl_size; |
| 972 | |
| 973 | if (!gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 974 | CAM_ERR(CAM_SENSOR, "invalid size of gpio table"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 975 | return -EINVAL; |
| 976 | } |
| 977 | |
| 978 | *pgpio_num_info = kzalloc(sizeof(struct msm_camera_gpio_num_info), |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 979 | GFP_KERNEL); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 980 | if (!*pgpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 981 | return -ENOMEM; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 982 | gpio_num_info = *pgpio_num_info; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 983 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 984 | rc = of_property_read_u32(of_node, "gpio-vana", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 985 | if (rc != -EINVAL) { |
| 986 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 987 | CAM_ERR(CAM_SENSOR, "read gpio-vana failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 988 | goto free_gpio_info; |
| 989 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 990 | CAM_ERR(CAM_SENSOR, "gpio-vana invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 991 | rc = -EINVAL; |
| 992 | goto free_gpio_info; |
| 993 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 994 | gpio_num_info->gpio_num[SENSOR_VANA] = |
| 995 | gconf->cam_gpio_common_tbl[val].gpio; |
| 996 | gpio_num_info->valid[SENSOR_VANA] = 1; |
| 997 | |
Jigarkumar Zala | 22223f9 | 2017-07-28 12:46:27 -0700 | [diff] [blame] | 998 | CAM_DBG(CAM_SENSOR, "gpio-vana %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 999 | gpio_num_info->gpio_num[SENSOR_VANA]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1002 | rc = of_property_read_u32(of_node, "gpio-vio", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1003 | if (rc != -EINVAL) { |
| 1004 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1005 | CAM_ERR(CAM_SENSOR, "read gpio-vio failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1006 | goto free_gpio_info; |
| 1007 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1008 | CAM_ERR(CAM_SENSOR, "gpio-vio invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1009 | goto free_gpio_info; |
| 1010 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1011 | gpio_num_info->gpio_num[SENSOR_VIO] = |
| 1012 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1013 | gpio_num_info->valid[SENSOR_VIO] = 1; |
| 1014 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1015 | CAM_DBG(CAM_SENSOR, "gpio-vio %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1016 | gpio_num_info->gpio_num[SENSOR_VIO]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1019 | rc = of_property_read_u32(of_node, "gpio-vaf", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1020 | if (rc != -EINVAL) { |
| 1021 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1022 | CAM_ERR(CAM_SENSOR, "read gpio-vaf failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1023 | goto free_gpio_info; |
| 1024 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1025 | CAM_ERR(CAM_SENSOR, "gpio-vaf invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1026 | rc = -EINVAL; |
| 1027 | goto free_gpio_info; |
| 1028 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1029 | gpio_num_info->gpio_num[SENSOR_VAF] = |
| 1030 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1031 | gpio_num_info->valid[SENSOR_VAF] = 1; |
| 1032 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1033 | CAM_DBG(CAM_SENSOR, "gpio-vaf %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1034 | gpio_num_info->gpio_num[SENSOR_VAF]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1037 | rc = of_property_read_u32(of_node, "gpio-vdig", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1038 | if (rc != -EINVAL) { |
| 1039 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1040 | CAM_ERR(CAM_SENSOR, "read gpio-vdig failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1041 | goto free_gpio_info; |
| 1042 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1043 | CAM_ERR(CAM_SENSOR, "gpio-vdig invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1044 | rc = -EINVAL; |
| 1045 | goto free_gpio_info; |
| 1046 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1047 | gpio_num_info->gpio_num[SENSOR_VDIG] = |
| 1048 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1049 | gpio_num_info->valid[SENSOR_VDIG] = 1; |
| 1050 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1051 | CAM_DBG(CAM_SENSOR, "gpio-vdig %d", |
| 1052 | gpio_num_info->gpio_num[SENSOR_VDIG]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1055 | rc = of_property_read_u32(of_node, "gpio-reset", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1056 | if (rc != -EINVAL) { |
| 1057 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1058 | CAM_ERR(CAM_SENSOR, "read gpio-reset failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1059 | goto free_gpio_info; |
| 1060 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1061 | CAM_ERR(CAM_SENSOR, "gpio-reset invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1062 | rc = -EINVAL; |
| 1063 | goto free_gpio_info; |
| 1064 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1065 | gpio_num_info->gpio_num[SENSOR_RESET] = |
| 1066 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1067 | gpio_num_info->valid[SENSOR_RESET] = 1; |
| 1068 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1069 | CAM_DBG(CAM_SENSOR, "gpio-reset %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1070 | gpio_num_info->gpio_num[SENSOR_RESET]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1073 | rc = of_property_read_u32(of_node, "gpio-standby", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1074 | if (rc != -EINVAL) { |
| 1075 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1076 | CAM_ERR(CAM_SENSOR, |
| 1077 | "read gpio-standby failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1078 | goto free_gpio_info; |
| 1079 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1080 | CAM_ERR(CAM_SENSOR, "gpio-standby invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1081 | rc = -EINVAL; |
| 1082 | goto free_gpio_info; |
| 1083 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1084 | gpio_num_info->gpio_num[SENSOR_STANDBY] = |
| 1085 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1086 | gpio_num_info->valid[SENSOR_STANDBY] = 1; |
| 1087 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1088 | CAM_DBG(CAM_SENSOR, "gpio-standby %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1089 | gpio_num_info->gpio_num[SENSOR_STANDBY]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1092 | rc = of_property_read_u32(of_node, "gpio-af-pwdm", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1093 | if (rc != -EINVAL) { |
| 1094 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1095 | CAM_ERR(CAM_SENSOR, |
| 1096 | "read gpio-af-pwdm failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1097 | goto free_gpio_info; |
| 1098 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1099 | CAM_ERR(CAM_SENSOR, "gpio-af-pwdm invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1100 | rc = -EINVAL; |
| 1101 | goto free_gpio_info; |
| 1102 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1103 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM] = |
| 1104 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1105 | gpio_num_info->valid[SENSOR_VAF_PWDM] = 1; |
| 1106 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1107 | CAM_DBG(CAM_SENSOR, "gpio-af-pwdm %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1108 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1111 | rc = of_property_read_u32(of_node, "gpio-custom1", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1112 | if (rc != -EINVAL) { |
| 1113 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1114 | CAM_ERR(CAM_SENSOR, |
| 1115 | "read gpio-custom1 failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1116 | goto free_gpio_info; |
| 1117 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1118 | CAM_ERR(CAM_SENSOR, "gpio-custom1 invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1119 | rc = -EINVAL; |
| 1120 | goto free_gpio_info; |
| 1121 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1122 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1] = |
| 1123 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1124 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO1] = 1; |
| 1125 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1126 | CAM_DBG(CAM_SENSOR, "gpio-custom1 %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1127 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1130 | rc = of_property_read_u32(of_node, "gpio-custom2", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1131 | if (rc != -EINVAL) { |
| 1132 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1133 | CAM_ERR(CAM_SENSOR, |
| 1134 | "read gpio-custom2 failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1135 | goto free_gpio_info; |
| 1136 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1137 | CAM_ERR(CAM_SENSOR, "gpio-custom2 invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1138 | rc = -EINVAL; |
| 1139 | goto free_gpio_info; |
| 1140 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1141 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2] = |
| 1142 | gconf->cam_gpio_common_tbl[val].gpio; |
| 1143 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO2] = 1; |
| 1144 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1145 | CAM_DBG(CAM_SENSOR, "gpio-custom2 %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1146 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1147 | } else { |
| 1148 | rc = 0; |
| 1149 | } |
| 1150 | |
| 1151 | return rc; |
| 1152 | |
| 1153 | free_gpio_info: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1154 | kfree(gpio_num_info); |
| 1155 | gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1156 | return rc; |
| 1157 | } |
| 1158 | |
| 1159 | int msm_camera_pinctrl_init( |
| 1160 | struct msm_pinctrl_info *sensor_pctrl, struct device *dev) { |
| 1161 | |
| 1162 | sensor_pctrl->pinctrl = devm_pinctrl_get(dev); |
| 1163 | if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) { |
depengs | dfb9f0b | 2017-11-07 10:36:59 +0800 | [diff] [blame] | 1164 | CAM_DBG(CAM_SENSOR, "Getting pinctrl handle failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | sensor_pctrl->gpio_state_active = |
| 1168 | pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 1169 | CAM_SENSOR_PINCTRL_STATE_DEFAULT); |
| 1170 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_active)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1171 | CAM_ERR(CAM_SENSOR, |
| 1172 | "Failed to get the active state pinctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1173 | return -EINVAL; |
| 1174 | } |
| 1175 | sensor_pctrl->gpio_state_suspend |
| 1176 | = pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 1177 | CAM_SENSOR_PINCTRL_STATE_SLEEP); |
| 1178 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_suspend)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1179 | CAM_ERR(CAM_SENSOR, |
| 1180 | "Failed to get the suspend state pinctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1181 | return -EINVAL; |
| 1182 | } |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1183 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
depengs | dfb9f0b | 2017-11-07 10:36:59 +0800 | [diff] [blame] | 1186 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1187 | int msm_cam_sensor_handle_reg_gpio(int seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1188 | struct msm_camera_gpio_num_info *gpio_num_info, int val) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1189 | { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1190 | int gpio_offset = -1; |
| 1191 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1192 | if (!gpio_num_info) { |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 1193 | CAM_INFO(CAM_SENSOR, "Input Parameters are not proper"); |
| 1194 | return 0; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1195 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1196 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1197 | CAM_DBG(CAM_SENSOR, "Seq type: %d, config: %d", seq_type, val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1198 | |
| 1199 | gpio_offset = seq_type; |
| 1200 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1201 | if (gpio_num_info->valid[gpio_offset] == 1) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1202 | CAM_DBG(CAM_SENSOR, "VALID GPIO offset: %d, seqtype: %d", |
| 1203 | gpio_offset, seq_type); |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1204 | cam_res_mgr_gpio_set_value( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1205 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1206 | [gpio_offset], val); |
| 1207 | } |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1212 | int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl, |
| 1213 | struct cam_hw_soc_info *soc_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1214 | { |
| 1215 | int rc = 0, index = 0, no_gpio = 0, ret = 0, num_vreg, j = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1216 | int32_t vreg_idx = -1; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1217 | struct cam_sensor_power_setting *power_setting = NULL; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1218 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1219 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1220 | CAM_DBG(CAM_SENSOR, "Enter"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1221 | if (!ctrl) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1222 | CAM_ERR(CAM_SENSOR, "Invalid ctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1223 | return -EINVAL; |
| 1224 | } |
| 1225 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1226 | gpio_num_info = ctrl->gpio_num_info; |
| 1227 | num_vreg = soc_info->num_rgltr; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1228 | |
Jigarkumar Zala | c6c090b | 2017-09-21 15:04:56 -0700 | [diff] [blame] | 1229 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
Soundrapandian Jeyaprakash | 6304555 | 2017-09-20 16:55:34 -0700 | [diff] [blame] | 1230 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1231 | return -EINVAL; |
| 1232 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1233 | |
Depeng Shao | f3b03fa | 2017-11-15 19:46:09 +0800 | [diff] [blame] | 1234 | if (soc_info->use_shared_clk) |
| 1235 | cam_res_mgr_shared_clk_config(true); |
| 1236 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1237 | ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev); |
| 1238 | if (ret < 0) { |
depengs | dfb9f0b | 2017-11-07 10:36:59 +0800 | [diff] [blame] | 1239 | /* Some sensor subdev no pinctrl. */ |
| 1240 | CAM_DBG(CAM_SENSOR, "Initialization of pinctrl failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1241 | ctrl->cam_pinctrl_status = 0; |
| 1242 | } else { |
| 1243 | ctrl->cam_pinctrl_status = 1; |
| 1244 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1245 | |
Depeng Shao | 4d78788 | 2017-11-23 01:30:24 +0800 | [diff] [blame] | 1246 | if (cam_res_mgr_shared_pinctrl_init()) { |
| 1247 | CAM_ERR(CAM_SENSOR, |
| 1248 | "Failed to init shared pinctrl"); |
| 1249 | return -EINVAL; |
| 1250 | } |
| 1251 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1252 | rc = cam_sensor_util_request_gpio_table(soc_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1253 | if (rc < 0) |
| 1254 | no_gpio = rc; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1255 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1256 | if (ctrl->cam_pinctrl_status) { |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1257 | ret = pinctrl_select_state( |
| 1258 | ctrl->pinctrl_info.pinctrl, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1259 | ctrl->pinctrl_info.gpio_state_active); |
| 1260 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1261 | CAM_ERR(CAM_SENSOR, "cannot set pin to active state"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Depeng Shao | 4d78788 | 2017-11-23 01:30:24 +0800 | [diff] [blame] | 1264 | ret = cam_res_mgr_shared_pinctrl_select_state(true); |
| 1265 | if (ret) |
| 1266 | CAM_ERR(CAM_SENSOR, |
| 1267 | "Cannot set shared pin to active state"); |
| 1268 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1269 | for (index = 0; index < ctrl->power_setting_size; index++) { |
depengs | dfb9f0b | 2017-11-07 10:36:59 +0800 | [diff] [blame] | 1270 | CAM_DBG(CAM_SENSOR, "index: %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1271 | power_setting = &ctrl->power_setting[index]; |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 1272 | CAM_DBG(CAM_SENSOR, "seq_type %d", power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1273 | |
| 1274 | switch (power_setting->seq_type) { |
| 1275 | case SENSOR_MCLK: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1276 | if (power_setting->seq_val >= soc_info->num_clk) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1277 | CAM_ERR(CAM_SENSOR, "clk index %d >= max %u", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1278 | power_setting->seq_val, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1279 | soc_info->num_clk); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1280 | goto power_up_failed; |
| 1281 | } |
| 1282 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1283 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1284 | "cam_clk")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1285 | CAM_DBG(CAM_SENSOR, |
| 1286 | "Enable cam_clk: %d", j); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1287 | |
| 1288 | soc_info->rgltr[j] = |
| 1289 | regulator_get( |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 1290 | soc_info->dev, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1291 | soc_info->rgltr_name[j]); |
| 1292 | |
| 1293 | if (IS_ERR_OR_NULL( |
| 1294 | soc_info->rgltr[j])) { |
| 1295 | rc = PTR_ERR( |
| 1296 | soc_info->rgltr[j]); |
| 1297 | rc = rc ? rc : -EINVAL; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1298 | CAM_ERR(CAM_SENSOR, |
| 1299 | "vreg %s %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1300 | soc_info->rgltr_name[j], |
| 1301 | rc); |
| 1302 | soc_info->rgltr[j] = NULL; |
| 1303 | } |
| 1304 | |
| 1305 | rc = cam_soc_util_regulator_enable( |
| 1306 | soc_info->rgltr[j], |
| 1307 | soc_info->rgltr_name[j], |
| 1308 | soc_info->rgltr_min_volt[j], |
| 1309 | soc_info->rgltr_max_volt[j], |
| 1310 | soc_info->rgltr_op_mode[j], |
| 1311 | soc_info->rgltr_delay[j]); |
| 1312 | |
| 1313 | power_setting->data[0] = |
| 1314 | soc_info->rgltr[j]; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | if (power_setting->config_val) |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1318 | soc_info->clk_rate[0][power_setting->seq_val] = |
| 1319 | power_setting->config_val; |
| 1320 | |
| 1321 | for (j = 0; j < soc_info->num_clk; j++) { |
| 1322 | rc = cam_soc_util_clk_enable(soc_info->clk[j], |
| 1323 | soc_info->clk_name[j], |
| 1324 | soc_info->clk_rate[0][j]); |
| 1325 | if (rc) |
| 1326 | break; |
| 1327 | } |
| 1328 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1329 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1330 | CAM_ERR(CAM_SENSOR, "clk enable failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1331 | goto power_up_failed; |
| 1332 | } |
| 1333 | break; |
| 1334 | case SENSOR_RESET: |
| 1335 | case SENSOR_STANDBY: |
| 1336 | case SENSOR_CUSTOM_GPIO1: |
| 1337 | case SENSOR_CUSTOM_GPIO2: |
| 1338 | if (no_gpio) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1339 | CAM_ERR(CAM_SENSOR, "request gpio failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1340 | return no_gpio; |
| 1341 | } |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1342 | if (!gpio_num_info) { |
| 1343 | CAM_ERR(CAM_SENSOR, "Invalid gpio_num_info"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1344 | goto power_up_failed; |
| 1345 | } |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1346 | CAM_DBG(CAM_SENSOR, "gpio set val %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1347 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1348 | [power_setting->seq_type]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1349 | |
| 1350 | rc = msm_cam_sensor_handle_reg_gpio( |
| 1351 | power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1352 | gpio_num_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1353 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1354 | CAM_ERR(CAM_SENSOR, |
| 1355 | "Error in handling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1356 | goto power_up_failed; |
| 1357 | } |
| 1358 | break; |
| 1359 | case SENSOR_VANA: |
| 1360 | case SENSOR_VDIG: |
| 1361 | case SENSOR_VIO: |
| 1362 | case SENSOR_VAF: |
| 1363 | case SENSOR_VAF_PWDM: |
| 1364 | case SENSOR_CUSTOM_REG1: |
| 1365 | case SENSOR_CUSTOM_REG2: |
| 1366 | if (power_setting->seq_val == INVALID_VREG) |
| 1367 | break; |
| 1368 | |
| 1369 | if (power_setting->seq_val >= CAM_VREG_MAX) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1370 | CAM_ERR(CAM_SENSOR, "vreg index %d >= max %d", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1371 | power_setting->seq_val, |
| 1372 | CAM_VREG_MAX); |
| 1373 | goto power_up_failed; |
| 1374 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1375 | if (power_setting->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1376 | CAM_DBG(CAM_SENSOR, "Enable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1377 | vreg_idx = power_setting->seq_val; |
| 1378 | |
| 1379 | soc_info->rgltr[vreg_idx] = |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 1380 | regulator_get(soc_info->dev, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1381 | soc_info->rgltr_name[vreg_idx]); |
| 1382 | if (IS_ERR_OR_NULL( |
| 1383 | soc_info->rgltr[vreg_idx])) { |
| 1384 | rc = PTR_ERR(soc_info->rgltr[vreg_idx]); |
| 1385 | rc = rc ? rc : -EINVAL; |
| 1386 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1387 | CAM_ERR(CAM_SENSOR, "%s get failed %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1388 | soc_info->rgltr_name[vreg_idx], |
| 1389 | rc); |
| 1390 | |
| 1391 | soc_info->rgltr[vreg_idx] = NULL; |
| 1392 | } |
| 1393 | |
| 1394 | rc = cam_soc_util_regulator_enable( |
| 1395 | soc_info->rgltr[vreg_idx], |
| 1396 | soc_info->rgltr_name[vreg_idx], |
| 1397 | soc_info->rgltr_min_volt[vreg_idx], |
| 1398 | soc_info->rgltr_max_volt[vreg_idx], |
| 1399 | soc_info->rgltr_op_mode[vreg_idx], |
| 1400 | soc_info->rgltr_delay[vreg_idx]); |
| 1401 | |
| 1402 | power_setting->data[0] = |
| 1403 | soc_info->rgltr[vreg_idx]; |
| 1404 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1405 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1406 | CAM_ERR(CAM_SENSOR, "usr_idx:%d dts_idx:%d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1407 | power_setting->seq_val, num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1408 | |
| 1409 | rc = msm_cam_sensor_handle_reg_gpio( |
| 1410 | power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1411 | gpio_num_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1412 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1413 | CAM_ERR(CAM_SENSOR, |
| 1414 | "Error in handling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1415 | goto power_up_failed; |
| 1416 | } |
| 1417 | break; |
| 1418 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1419 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1420 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1421 | break; |
| 1422 | } |
| 1423 | if (power_setting->delay > 20) |
| 1424 | msleep(power_setting->delay); |
| 1425 | else if (power_setting->delay) |
| 1426 | usleep_range(power_setting->delay * 1000, |
| 1427 | (power_setting->delay * 1000) + 1000); |
| 1428 | } |
| 1429 | |
Depeng Shao | 4d78788 | 2017-11-23 01:30:24 +0800 | [diff] [blame] | 1430 | ret = cam_res_mgr_shared_pinctrl_post_init(); |
| 1431 | if (ret) |
| 1432 | CAM_ERR(CAM_SENSOR, |
| 1433 | "Failed to post init shared pinctrl"); |
| 1434 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1435 | return 0; |
| 1436 | power_up_failed: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1437 | CAM_ERR(CAM_SENSOR, "failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1438 | for (index--; index >= 0; index--) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1439 | CAM_DBG(CAM_SENSOR, "index %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1440 | power_setting = &ctrl->power_setting[index]; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1441 | CAM_DBG(CAM_SENSOR, "type %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1442 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1443 | switch (power_setting->seq_type) { |
| 1444 | case SENSOR_RESET: |
| 1445 | case SENSOR_STANDBY: |
| 1446 | case SENSOR_CUSTOM_GPIO1: |
| 1447 | case SENSOR_CUSTOM_GPIO2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1448 | if (!gpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1449 | continue; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1450 | if (!gpio_num_info->valid |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1451 | [power_setting->seq_type]) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1452 | continue; |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1453 | cam_res_mgr_gpio_set_value( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1454 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1455 | [power_setting->seq_type], GPIOF_OUT_INIT_LOW); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1456 | break; |
| 1457 | case SENSOR_VANA: |
| 1458 | case SENSOR_VDIG: |
| 1459 | case SENSOR_VIO: |
| 1460 | case SENSOR_VAF: |
| 1461 | case SENSOR_VAF_PWDM: |
| 1462 | case SENSOR_CUSTOM_REG1: |
| 1463 | case SENSOR_CUSTOM_REG2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1464 | if (power_setting->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1465 | CAM_DBG(CAM_SENSOR, "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1466 | vreg_idx = power_setting->seq_val; |
| 1467 | |
| 1468 | rc = cam_soc_util_regulator_disable( |
| 1469 | soc_info->rgltr[vreg_idx], |
| 1470 | soc_info->rgltr_name[vreg_idx], |
| 1471 | soc_info->rgltr_min_volt[vreg_idx], |
| 1472 | soc_info->rgltr_max_volt[vreg_idx], |
| 1473 | soc_info->rgltr_op_mode[vreg_idx], |
| 1474 | soc_info->rgltr_delay[vreg_idx]); |
| 1475 | |
| 1476 | power_setting->data[0] = |
| 1477 | soc_info->rgltr[vreg_idx]; |
| 1478 | |
| 1479 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1480 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1481 | CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1482 | power_setting->seq_val, num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1483 | |
| 1484 | msm_cam_sensor_handle_reg_gpio(power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1485 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 1486 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1487 | break; |
| 1488 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1489 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1490 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1491 | break; |
| 1492 | } |
| 1493 | if (power_setting->delay > 20) { |
| 1494 | msleep(power_setting->delay); |
| 1495 | } else if (power_setting->delay) { |
| 1496 | usleep_range(power_setting->delay * 1000, |
| 1497 | (power_setting->delay * 1000) + 1000); |
| 1498 | } |
| 1499 | } |
Depeng Shao | f3b03fa | 2017-11-15 19:46:09 +0800 | [diff] [blame] | 1500 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1501 | if (ctrl->cam_pinctrl_status) { |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1502 | ret = pinctrl_select_state( |
| 1503 | ctrl->pinctrl_info.pinctrl, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1504 | ctrl->pinctrl_info.gpio_state_suspend); |
| 1505 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1506 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1507 | cam_res_mgr_shared_pinctrl_select_state(false); |
| 1508 | pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 1509 | cam_res_mgr_shared_pinctrl_put(); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1510 | } |
Depeng Shao | f3b03fa | 2017-11-15 19:46:09 +0800 | [diff] [blame] | 1511 | |
| 1512 | if (soc_info->use_shared_clk) |
| 1513 | cam_res_mgr_shared_clk_config(false); |
| 1514 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1515 | ctrl->cam_pinctrl_status = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1516 | |
| 1517 | cam_sensor_util_request_gpio_table(soc_info, 0); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1518 | |
| 1519 | return rc; |
| 1520 | } |
| 1521 | |
| 1522 | static struct cam_sensor_power_setting* |
| 1523 | msm_camera_get_power_settings(struct cam_sensor_power_ctrl_t *ctrl, |
| 1524 | enum msm_camera_power_seq_type seq_type, |
| 1525 | uint16_t seq_val) |
| 1526 | { |
| 1527 | struct cam_sensor_power_setting *power_setting, *ps = NULL; |
| 1528 | int idx; |
| 1529 | |
| 1530 | for (idx = 0; idx < ctrl->power_setting_size; idx++) { |
| 1531 | power_setting = &ctrl->power_setting[idx]; |
| 1532 | if (power_setting->seq_type == seq_type && |
| 1533 | power_setting->seq_val == seq_val) { |
| 1534 | ps = power_setting; |
| 1535 | return ps; |
| 1536 | } |
| 1537 | |
| 1538 | } |
| 1539 | |
| 1540 | return ps; |
| 1541 | } |
| 1542 | |
| 1543 | static int cam_config_mclk_reg(struct cam_sensor_power_ctrl_t *ctrl, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1544 | struct cam_hw_soc_info *soc_info, int32_t index) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1545 | { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1546 | int32_t num_vreg = 0, j = 0, rc = 0, idx = 0; |
| 1547 | struct cam_sensor_power_setting *ps = NULL; |
| 1548 | struct cam_sensor_power_setting *pd = NULL; |
| 1549 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1550 | num_vreg = soc_info->num_rgltr; |
| 1551 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1552 | pd = &ctrl->power_down_setting[index]; |
| 1553 | |
| 1554 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1555 | if (!strcmp(soc_info->rgltr_name[j], "cam_clk")) { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1556 | |
| 1557 | ps = NULL; |
| 1558 | for (idx = 0; idx < |
| 1559 | ctrl->power_setting_size; idx++) { |
| 1560 | if (ctrl->power_setting[idx]. |
| 1561 | seq_type == pd->seq_type) { |
| 1562 | ps = &ctrl->power_setting[idx]; |
| 1563 | break; |
| 1564 | } |
| 1565 | } |
| 1566 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1567 | if (ps != NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1568 | CAM_DBG(CAM_SENSOR, "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1569 | |
| 1570 | rc = cam_soc_util_regulator_disable( |
| 1571 | soc_info->rgltr[j], |
| 1572 | soc_info->rgltr_name[j], |
| 1573 | soc_info->rgltr_min_volt[j], |
| 1574 | soc_info->rgltr_max_volt[j], |
| 1575 | soc_info->rgltr_op_mode[j], |
| 1576 | soc_info->rgltr_delay[j]); |
| 1577 | |
| 1578 | ps->data[0] = |
| 1579 | soc_info->rgltr[j]; |
| 1580 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | return rc; |
| 1585 | } |
| 1586 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1587 | int msm_camera_power_down(struct cam_sensor_power_ctrl_t *ctrl, |
| 1588 | struct cam_hw_soc_info *soc_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1589 | { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1590 | int index = 0, ret = 0, num_vreg = 0, i; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1591 | struct cam_sensor_power_setting *pd = NULL; |
| 1592 | struct cam_sensor_power_setting *ps; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1593 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1594 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1595 | CAM_DBG(CAM_SENSOR, "Enter"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1596 | if (!ctrl || !soc_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1597 | CAM_ERR(CAM_SENSOR, "failed ctrl %pK", ctrl); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1601 | gpio_num_info = ctrl->gpio_num_info; |
| 1602 | num_vreg = soc_info->num_rgltr; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1603 | |
Jigarkumar Zala | c6c090b | 2017-09-21 15:04:56 -0700 | [diff] [blame] | 1604 | if ((num_vreg <= 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
Soundrapandian Jeyaprakash | 6304555 | 2017-09-20 16:55:34 -0700 | [diff] [blame] | 1605 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
| 1606 | return -EINVAL; |
| 1607 | } |
| 1608 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1609 | for (index = 0; index < ctrl->power_down_setting_size; index++) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1610 | CAM_DBG(CAM_SENSOR, "index %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1611 | pd = &ctrl->power_down_setting[index]; |
| 1612 | ps = NULL; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1613 | CAM_DBG(CAM_SENSOR, "type %d", pd->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1614 | switch (pd->seq_type) { |
| 1615 | case SENSOR_MCLK: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1616 | ret = cam_config_mclk_reg(ctrl, soc_info, index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1617 | if (ret < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1618 | CAM_ERR(CAM_SENSOR, |
| 1619 | "config clk reg failed rc: %d", ret); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1620 | return ret; |
| 1621 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1622 | //cam_soc_util_clk_disable_default(soc_info); |
| 1623 | for (i = soc_info->num_clk - 1; i >= 0; i--) { |
| 1624 | cam_soc_util_clk_disable(soc_info->clk[i], |
| 1625 | soc_info->clk_name[i]); |
| 1626 | } |
| 1627 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1628 | break; |
| 1629 | case SENSOR_RESET: |
| 1630 | case SENSOR_STANDBY: |
| 1631 | case SENSOR_CUSTOM_GPIO1: |
| 1632 | case SENSOR_CUSTOM_GPIO2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1633 | |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1634 | if (!gpio_num_info->valid[pd->seq_type]) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1635 | continue; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1636 | |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1637 | cam_res_mgr_gpio_set_value( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1638 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 94406ce | 2017-09-01 15:20:54 -0700 | [diff] [blame] | 1639 | [pd->seq_type], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1640 | (int) pd->config_val); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1641 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1642 | break; |
| 1643 | case SENSOR_VANA: |
| 1644 | case SENSOR_VDIG: |
| 1645 | case SENSOR_VIO: |
| 1646 | case SENSOR_VAF: |
| 1647 | case SENSOR_VAF_PWDM: |
| 1648 | case SENSOR_CUSTOM_REG1: |
| 1649 | case SENSOR_CUSTOM_REG2: |
| 1650 | if (pd->seq_val == INVALID_VREG) |
| 1651 | break; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1652 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1653 | ps = msm_camera_get_power_settings( |
| 1654 | ctrl, pd->seq_type, |
| 1655 | pd->seq_val); |
| 1656 | if (ps) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1657 | if (pd->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1658 | CAM_DBG(CAM_SENSOR, |
| 1659 | "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1660 | ret = cam_soc_util_regulator_disable( |
| 1661 | soc_info->rgltr[ps->seq_val], |
| 1662 | soc_info->rgltr_name[ps->seq_val], |
| 1663 | soc_info->rgltr_min_volt[ps->seq_val], |
| 1664 | soc_info->rgltr_max_volt[ps->seq_val], |
| 1665 | soc_info->rgltr_op_mode[ps->seq_val], |
| 1666 | soc_info->rgltr_delay[ps->seq_val]); |
| 1667 | |
| 1668 | ps->data[0] = |
| 1669 | soc_info->rgltr[ps->seq_val]; |
| 1670 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1671 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1672 | CAM_ERR(CAM_SENSOR, |
| 1673 | "seq_val:%d > num_vreg: %d", |
| 1674 | pd->seq_val, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1675 | num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1676 | } else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1677 | CAM_ERR(CAM_SENSOR, |
| 1678 | "error in power up/down seq"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1679 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1680 | ret = msm_cam_sensor_handle_reg_gpio(pd->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1681 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 1682 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1683 | if (ret < 0) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1684 | CAM_ERR(CAM_SENSOR, |
| 1685 | "Error disabling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1686 | break; |
| 1687 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1688 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1689 | pd->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1690 | break; |
| 1691 | } |
| 1692 | if (pd->delay > 20) |
| 1693 | msleep(pd->delay); |
| 1694 | else if (pd->delay) |
| 1695 | usleep_range(pd->delay * 1000, |
| 1696 | (pd->delay * 1000) + 1000); |
| 1697 | } |
| 1698 | |
| 1699 | if (ctrl->cam_pinctrl_status) { |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1700 | ret = pinctrl_select_state( |
| 1701 | ctrl->pinctrl_info.pinctrl, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1702 | ctrl->pinctrl_info.gpio_state_suspend); |
| 1703 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 1704 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
Depeng Shao | 3d8ee90 | 2017-10-30 20:30:33 +0800 | [diff] [blame] | 1705 | |
| 1706 | cam_res_mgr_shared_pinctrl_select_state(false); |
| 1707 | pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 1708 | cam_res_mgr_shared_pinctrl_put(); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Depeng Shao | f3b03fa | 2017-11-15 19:46:09 +0800 | [diff] [blame] | 1711 | if (soc_info->use_shared_clk) |
| 1712 | cam_res_mgr_shared_clk_config(false); |
| 1713 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1714 | ctrl->cam_pinctrl_status = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1715 | |
| 1716 | cam_sensor_util_request_gpio_table(soc_info, 0); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |