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" |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 15 | |
| 16 | #define CAM_SENSOR_PINCTRL_STATE_SLEEP "cam_suspend" |
| 17 | #define CAM_SENSOR_PINCTRL_STATE_DEFAULT "cam_default" |
| 18 | |
| 19 | #define VALIDATE_VOLTAGE(min, max, config_val) ((config_val) && \ |
| 20 | (config_val >= min) && (config_val <= max)) |
| 21 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 22 | static struct i2c_settings_list* |
| 23 | cam_sensor_get_i2c_ptr(struct i2c_settings_array *i2c_reg_settings, |
| 24 | uint32_t size) |
| 25 | { |
| 26 | struct i2c_settings_list *tmp; |
| 27 | |
| 28 | tmp = (struct i2c_settings_list *) |
| 29 | kzalloc(sizeof(struct i2c_settings_list), GFP_KERNEL); |
| 30 | |
| 31 | if (tmp != NULL) |
| 32 | list_add_tail(&(tmp->list), |
| 33 | &(i2c_reg_settings->list_head)); |
| 34 | else |
| 35 | return NULL; |
| 36 | |
| 37 | tmp->i2c_settings.reg_setting = (struct cam_sensor_i2c_reg_array *) |
| 38 | kzalloc(sizeof(struct cam_sensor_i2c_reg_array) * |
| 39 | size, GFP_KERNEL); |
| 40 | if (tmp->i2c_settings.reg_setting == NULL) { |
| 41 | list_del(&(tmp->list)); |
| 42 | kfree(tmp); |
| 43 | return NULL; |
| 44 | } |
| 45 | tmp->i2c_settings.size = size; |
| 46 | |
| 47 | return tmp; |
| 48 | } |
| 49 | |
| 50 | int32_t delete_request(struct i2c_settings_array *i2c_array) |
| 51 | { |
| 52 | struct i2c_settings_list *i2c_list = NULL, *i2c_next = NULL; |
| 53 | int32_t rc = 0; |
| 54 | |
| 55 | if (i2c_array == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 56 | CAM_ERR(CAM_SENSOR, "FATAL:: Invalid argument"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 57 | return -EINVAL; |
| 58 | } |
| 59 | |
| 60 | list_for_each_entry_safe(i2c_list, i2c_next, |
| 61 | &(i2c_array->list_head), list) { |
| 62 | kfree(i2c_list->i2c_settings.reg_setting); |
| 63 | list_del(&(i2c_list->list)); |
| 64 | kfree(i2c_list); |
| 65 | } |
| 66 | INIT_LIST_HEAD(&(i2c_array->list_head)); |
| 67 | i2c_array->is_settings_valid = 0; |
| 68 | |
| 69 | return rc; |
| 70 | } |
| 71 | |
| 72 | int32_t cam_sensor_handle_delay( |
| 73 | uint32_t **cmd_buf, |
| 74 | uint16_t generic_op_code, |
| 75 | struct i2c_settings_array *i2c_reg_settings, |
| 76 | uint32_t offset, uint32_t *byte_cnt, |
| 77 | struct list_head *list_ptr) |
| 78 | { |
| 79 | int32_t rc = 0; |
| 80 | struct cam_cmd_unconditional_wait *cmd_uncond_wait = |
| 81 | (struct cam_cmd_unconditional_wait *) *cmd_buf; |
| 82 | struct i2c_settings_list *i2c_list = NULL; |
| 83 | |
| 84 | if (i2c_list == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 85 | CAM_ERR(CAM_SENSOR, "Invalid list ptr"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 86 | return -EINVAL; |
| 87 | } |
| 88 | |
| 89 | if (offset > 0) { |
| 90 | i2c_list = |
| 91 | list_entry(list_ptr, struct i2c_settings_list, list); |
| 92 | if (generic_op_code == |
| 93 | CAMERA_SENSOR_WAIT_OP_HW_UCND) |
| 94 | i2c_list->i2c_settings. |
| 95 | reg_setting[offset - 1].delay = |
| 96 | cmd_uncond_wait->delay; |
| 97 | else |
| 98 | i2c_list->i2c_settings.delay = |
| 99 | cmd_uncond_wait->delay; |
| 100 | (*cmd_buf) += |
| 101 | sizeof( |
| 102 | struct cam_cmd_unconditional_wait) / sizeof(uint32_t); |
| 103 | (*byte_cnt) += |
| 104 | sizeof( |
| 105 | struct cam_cmd_unconditional_wait); |
| 106 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 107 | CAM_ERR(CAM_SENSOR, "Delay Rxed Before any buffer: %d", offset); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 108 | return -EINVAL; |
| 109 | } |
| 110 | |
| 111 | return rc; |
| 112 | } |
| 113 | |
| 114 | int32_t cam_sensor_handle_poll( |
| 115 | uint32_t **cmd_buf, |
| 116 | struct i2c_settings_array *i2c_reg_settings, |
| 117 | uint32_t *byte_cnt, int32_t *offset, |
| 118 | struct list_head **list_ptr) |
| 119 | { |
| 120 | struct i2c_settings_list *i2c_list; |
| 121 | int32_t rc = 0; |
| 122 | struct cam_cmd_conditional_wait *cond_wait |
| 123 | = (struct cam_cmd_conditional_wait *) *cmd_buf; |
| 124 | |
| 125 | i2c_list = |
| 126 | cam_sensor_get_i2c_ptr(i2c_reg_settings, 1); |
| 127 | if (!i2c_list || !i2c_list->i2c_settings.reg_setting) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 128 | CAM_ERR(CAM_SENSOR, "Failed in allocating mem for list"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 129 | return -ENOMEM; |
| 130 | } |
| 131 | |
| 132 | i2c_list->op_code = CAM_SENSOR_I2C_POLL; |
| 133 | i2c_list->i2c_settings.data_type = |
| 134 | cond_wait->data_type; |
| 135 | i2c_list->i2c_settings.addr_type = |
| 136 | cond_wait->addr_type; |
| 137 | i2c_list->i2c_settings.reg_setting->reg_addr = |
| 138 | cond_wait->reg_addr; |
| 139 | i2c_list->i2c_settings.reg_setting->reg_data = |
| 140 | cond_wait->reg_data; |
| 141 | i2c_list->i2c_settings.reg_setting->delay = |
| 142 | cond_wait->timeout; |
| 143 | |
| 144 | (*cmd_buf) += sizeof(struct cam_cmd_conditional_wait) / |
| 145 | sizeof(uint32_t); |
| 146 | (*byte_cnt) += sizeof(struct cam_cmd_conditional_wait); |
| 147 | |
| 148 | (*offset) += 1; |
| 149 | *list_ptr = &(i2c_list->list); |
| 150 | |
| 151 | return rc; |
| 152 | } |
| 153 | |
| 154 | int32_t cam_sensor_handle_random_write( |
| 155 | struct cam_cmd_i2c_random_wr *cam_cmd_i2c_random_wr, |
| 156 | struct i2c_settings_array *i2c_reg_settings, |
| 157 | uint16_t *cmd_length_in_bytes, int32_t *offset, |
| 158 | struct list_head **list) |
| 159 | { |
| 160 | struct i2c_settings_list *i2c_list; |
| 161 | int32_t rc = 0, cnt; |
| 162 | |
| 163 | i2c_list = cam_sensor_get_i2c_ptr(i2c_reg_settings, |
| 164 | cam_cmd_i2c_random_wr->header.count); |
| 165 | if (i2c_list == NULL || |
| 166 | i2c_list->i2c_settings.reg_setting == NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 167 | CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 168 | return -ENOMEM; |
| 169 | } |
| 170 | |
| 171 | *cmd_length_in_bytes = (sizeof(struct i2c_rdwr_header) + |
| 172 | sizeof(struct i2c_random_wr_payload) * |
| 173 | (cam_cmd_i2c_random_wr->header.count)); |
| 174 | i2c_list->op_code = CAM_SENSOR_I2C_WRITE_RANDOM; |
| 175 | i2c_list->i2c_settings.addr_type = |
| 176 | cam_cmd_i2c_random_wr->header.addr_type; |
| 177 | i2c_list->i2c_settings.data_type = |
| 178 | cam_cmd_i2c_random_wr->header.data_type; |
| 179 | |
| 180 | for (cnt = 0; cnt < (cam_cmd_i2c_random_wr->header.count); |
| 181 | cnt++) { |
| 182 | i2c_list->i2c_settings.reg_setting[cnt].reg_addr = |
| 183 | cam_cmd_i2c_random_wr-> |
| 184 | random_wr_payload[cnt].reg_addr; |
| 185 | i2c_list->i2c_settings. |
| 186 | reg_setting[cnt].reg_data = |
| 187 | cam_cmd_i2c_random_wr-> |
| 188 | random_wr_payload[cnt].reg_data; |
| 189 | i2c_list->i2c_settings. |
| 190 | reg_setting[cnt].data_mask = 0; |
| 191 | } |
| 192 | (*offset) += cnt; |
| 193 | *list = &(i2c_list->list); |
| 194 | |
| 195 | return rc; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Name : cam_sensor_i2c_pkt_parser |
| 200 | * Description : Parse CSL CCI packet and apply register settings |
| 201 | * Parameters : s_ctrl input/output sub_device |
| 202 | * arg input cam_control |
| 203 | * Description : |
| 204 | * Handle multiple I2C RD/WR and WAIT cmd formats in one command |
| 205 | * buffer, for example, a command buffer of m x RND_WR + 1 x HW_ |
| 206 | * WAIT + n x RND_WR with num_cmd_buf = 1. Do not exepect RD/WR |
| 207 | * with different cmd_type and op_code in one command buffer. |
| 208 | */ |
| 209 | int cam_sensor_i2c_pkt_parser(struct i2c_settings_array *i2c_reg_settings, |
| 210 | struct cam_cmd_buf_desc *cmd_desc, int32_t num_cmd_buffers) |
| 211 | { |
| 212 | int16_t rc = 0, i = 0; |
| 213 | size_t len_of_buff = 0; |
| 214 | uint64_t generic_ptr; |
| 215 | |
| 216 | for (i = 0; i < num_cmd_buffers; i++) { |
| 217 | uint32_t *cmd_buf = NULL; |
| 218 | struct common_header *cmm_hdr; |
| 219 | uint16_t generic_op_code; |
| 220 | uint32_t byte_cnt = 0; |
| 221 | uint32_t j = 0; |
| 222 | struct list_head *list = NULL; |
| 223 | |
| 224 | /* |
| 225 | * It is not expected the same settings to |
| 226 | * be spread across multiple cmd buffers |
| 227 | */ |
| 228 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 229 | CAM_DBG(CAM_SENSOR, "Total cmd Buf in Bytes: %d", |
| 230 | cmd_desc[i].length); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 231 | |
| 232 | if (!cmd_desc[i].length) |
| 233 | continue; |
| 234 | |
| 235 | rc = cam_mem_get_cpu_buf(cmd_desc[i].mem_handle, |
| 236 | (uint64_t *)&generic_ptr, &len_of_buff); |
| 237 | cmd_buf = (uint32_t *)generic_ptr; |
| 238 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 239 | CAM_ERR(CAM_SENSOR, |
| 240 | "cmd hdl failed:%d, Err: %d, Buffer_len: %ld", |
| 241 | cmd_desc[i].mem_handle, rc, len_of_buff); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 242 | return rc; |
| 243 | } |
| 244 | cmd_buf += cmd_desc[i].offset / sizeof(uint32_t); |
| 245 | |
| 246 | while (byte_cnt < cmd_desc[i].length) { |
| 247 | cmm_hdr = (struct common_header *)cmd_buf; |
| 248 | generic_op_code = cmm_hdr->third_byte; |
| 249 | switch (cmm_hdr->cmd_type) { |
| 250 | case CAMERA_SENSOR_CMD_TYPE_I2C_RNDM_WR: { |
| 251 | uint16_t cmd_length_in_bytes = 0; |
| 252 | struct cam_cmd_i2c_random_wr |
| 253 | *cam_cmd_i2c_random_wr = |
| 254 | (struct cam_cmd_i2c_random_wr *)cmd_buf; |
| 255 | |
| 256 | rc = cam_sensor_handle_random_write( |
| 257 | cam_cmd_i2c_random_wr, |
| 258 | i2c_reg_settings, |
| 259 | &cmd_length_in_bytes, &j, &list); |
| 260 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 261 | CAM_ERR(CAM_SENSOR, |
| 262 | "Failed in random read %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 263 | return rc; |
| 264 | } |
| 265 | |
| 266 | cmd_buf += cmd_length_in_bytes / |
| 267 | sizeof(uint32_t); |
| 268 | byte_cnt += cmd_length_in_bytes; |
| 269 | break; |
| 270 | } |
| 271 | case CAMERA_SENSOR_CMD_TYPE_WAIT: { |
| 272 | if (generic_op_code == |
| 273 | CAMERA_SENSOR_WAIT_OP_HW_UCND || |
| 274 | generic_op_code == |
| 275 | CAMERA_SENSOR_WAIT_OP_SW_UCND) { |
| 276 | |
| 277 | rc = cam_sensor_handle_delay( |
| 278 | &cmd_buf, generic_op_code, |
| 279 | i2c_reg_settings, j, &byte_cnt, |
| 280 | list); |
| 281 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 282 | CAM_ERR(CAM_SENSOR, |
| 283 | "delay hdl failed: %d", |
| 284 | rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 285 | return rc; |
| 286 | } |
| 287 | |
| 288 | } else if (generic_op_code == |
| 289 | CAMERA_SENSOR_WAIT_OP_COND) { |
| 290 | rc = cam_sensor_handle_poll( |
| 291 | &cmd_buf, i2c_reg_settings, |
| 292 | &byte_cnt, &j, &list); |
| 293 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 294 | CAM_ERR(CAM_SENSOR, |
| 295 | "Random read fail: %d", |
| 296 | rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 297 | return rc; |
| 298 | } |
| 299 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 300 | CAM_ERR(CAM_SENSOR, |
| 301 | "Wrong Wait Command: %d", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 302 | generic_op_code); |
| 303 | return -EINVAL; |
| 304 | } |
| 305 | break; |
| 306 | } |
| 307 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 308 | CAM_ERR(CAM_SENSOR, "Invalid Command Type:%d", |
| 309 | cmm_hdr->cmd_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 310 | return -EINVAL; |
| 311 | } |
| 312 | } |
| 313 | i2c_reg_settings->is_settings_valid = 1; |
| 314 | } |
| 315 | |
| 316 | return rc; |
| 317 | } |
| 318 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 319 | int32_t msm_camera_fill_vreg_params( |
| 320 | struct cam_hw_soc_info *soc_info, |
| 321 | struct cam_sensor_power_setting *power_setting, |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 322 | uint16_t power_setting_size) |
| 323 | { |
| 324 | int32_t rc = 0, j = 0, i = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 325 | uint32_t num_vreg; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 326 | |
| 327 | /* Validate input parameters */ |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 328 | if (!soc_info || !power_setting) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 329 | CAM_ERR(CAM_SENSOR, "failed: soc_info %pK power_setting %pK", |
| 330 | soc_info, power_setting); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 331 | return -EINVAL; |
| 332 | } |
| 333 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 334 | num_vreg = soc_info->num_rgltr; |
| 335 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 336 | if (num_vreg <= 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 337 | CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 338 | return -EINVAL; |
| 339 | } |
| 340 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 341 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 342 | for (i = 0; i < power_setting_size; i++) { |
| 343 | switch (power_setting[i].seq_type) { |
| 344 | case SENSOR_VDIG: |
| 345 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 346 | if (!strcmp(soc_info->rgltr_name[j], |
| 347 | "cam_vdig")) { |
| 348 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 349 | CAM_DBG(CAM_SENSOR, |
| 350 | "i: %d j: %d cam_vdig", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 351 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 352 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 353 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 354 | soc_info->rgltr_min_volt[j], |
| 355 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 356 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 357 | soc_info->rgltr_min_volt[j] = |
| 358 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 359 | power_setting[i].config_val; |
| 360 | } |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | if (j == num_vreg) |
| 365 | power_setting[i].seq_val = INVALID_VREG; |
| 366 | break; |
| 367 | |
| 368 | case SENSOR_VIO: |
| 369 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 370 | |
| 371 | if (!strcmp(soc_info->rgltr_name[j], |
| 372 | "cam_vio")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 373 | CAM_DBG(CAM_SENSOR, |
| 374 | "i: %d j: %d cam_vio", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 375 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 376 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 377 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 378 | soc_info->rgltr_min_volt[j], |
| 379 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 380 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 381 | soc_info->rgltr_min_volt[j] = |
| 382 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 383 | power_setting[i].config_val; |
| 384 | } |
| 385 | break; |
| 386 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 387 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 388 | } |
| 389 | if (j == num_vreg) |
| 390 | power_setting[i].seq_val = INVALID_VREG; |
| 391 | break; |
| 392 | |
| 393 | case SENSOR_VANA: |
| 394 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 395 | |
| 396 | if (!strcmp(soc_info->rgltr_name[j], |
| 397 | "cam_vana")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 398 | CAM_DBG(CAM_SENSOR, |
| 399 | "i: %d j: %d cam_vana", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 400 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 401 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 402 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 403 | soc_info->rgltr_min_volt[j], |
| 404 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 405 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 406 | soc_info->rgltr_min_volt[j] = |
| 407 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 408 | power_setting[i].config_val; |
| 409 | } |
| 410 | break; |
| 411 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 412 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 413 | } |
| 414 | if (j == num_vreg) |
| 415 | power_setting[i].seq_val = INVALID_VREG; |
| 416 | break; |
| 417 | |
| 418 | case SENSOR_VAF: |
| 419 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 420 | |
| 421 | if (!strcmp(soc_info->rgltr_name[j], |
| 422 | "cam_vaf")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 423 | CAM_DBG(CAM_SENSOR, |
| 424 | "i: %d j: %d cam_vaf", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 425 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 426 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 427 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 428 | soc_info->rgltr_min_volt[j], |
| 429 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 430 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 431 | soc_info->rgltr_min_volt[j] = |
| 432 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 433 | power_setting[i].config_val; |
| 434 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 435 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 436 | break; |
| 437 | } |
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 | } |
| 440 | if (j == num_vreg) |
| 441 | power_setting[i].seq_val = INVALID_VREG; |
| 442 | break; |
| 443 | |
| 444 | case SENSOR_CUSTOM_REG1: |
| 445 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 446 | |
| 447 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 448 | "cam_v_custom1")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 449 | CAM_DBG(CAM_SENSOR, |
| 450 | "i:%d j:%d cam_vcustom1", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 451 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 452 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 453 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 454 | soc_info->rgltr_min_volt[j], |
| 455 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 456 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 457 | soc_info->rgltr_min_volt[j] = |
| 458 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 459 | power_setting[i].config_val; |
| 460 | } |
| 461 | break; |
| 462 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 463 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 464 | } |
| 465 | if (j == num_vreg) |
| 466 | power_setting[i].seq_val = INVALID_VREG; |
| 467 | break; |
| 468 | case SENSOR_CUSTOM_REG2: |
| 469 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 470 | |
| 471 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 472 | "cam_v_custom2")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 473 | CAM_DBG(CAM_SENSOR, |
| 474 | "i:%d j:%d cam_vcustom2", i, j); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 475 | power_setting[i].seq_val = j; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 476 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 477 | if (VALIDATE_VOLTAGE( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 478 | soc_info->rgltr_min_volt[j], |
| 479 | soc_info->rgltr_max_volt[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 480 | power_setting[i].config_val)) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 481 | soc_info->rgltr_min_volt[j] = |
| 482 | soc_info->rgltr_max_volt[j] = |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 483 | power_setting[i].config_val; |
| 484 | } |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | if (j == num_vreg) |
| 489 | power_setting[i].seq_val = INVALID_VREG; |
| 490 | break; |
| 491 | |
| 492 | default: { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 493 | CAM_ERR(CAM_SENSOR, "invalid seq_val %d", |
| 494 | power_setting[i].seq_val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 495 | break; |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | return rc; |
| 501 | } |
| 502 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 503 | int cam_sensor_util_request_gpio_table( |
| 504 | struct cam_hw_soc_info *soc_info, int gpio_en) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 505 | { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 506 | int rc = 0, i = 0; |
| 507 | uint8_t size = 0; |
| 508 | struct cam_soc_gpio_data *gpio_conf = |
| 509 | soc_info->gpio_data; |
| 510 | struct gpio *gpio_tbl = gpio_conf->cam_gpio_req_tbl; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 511 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 512 | size = gpio_conf->cam_gpio_req_tbl_size; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 513 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 514 | if (gpio_conf->cam_gpio_common_tbl_size <= 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 515 | CAM_INFO(CAM_SENSOR, "No GPIO entry"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 519 | if (!gpio_tbl || !size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 520 | CAM_ERR(CAM_SENSOR, "invalid gpio_tbl %pK / size %d", |
| 521 | gpio_tbl, size); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 522 | return -EINVAL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 525 | for (i = 0; i < size; i++) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 526 | CAM_DBG(CAM_SENSOR, "i: %d, gpio %d dir %ld", i, |
| 527 | gpio_tbl[i].gpio, gpio_tbl[i].flags); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | if (gpio_en) { |
| 531 | for (i = 0; i < size; i++) { |
| 532 | rc = gpio_request_one(gpio_tbl[i].gpio, |
| 533 | gpio_tbl[i].flags, gpio_tbl[i].label); |
| 534 | if (rc) { |
| 535 | /* |
| 536 | * After GPIO request fails, contine to |
| 537 | * apply new gpios, outout a error message |
| 538 | * for driver bringup debug |
| 539 | */ |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 540 | CAM_ERR(CAM_SENSOR, "gpio %d:%s request fails", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 541 | gpio_tbl[i].gpio, gpio_tbl[i].label); |
| 542 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 543 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 544 | } else { |
| 545 | gpio_free_array(gpio_tbl, size); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 548 | return rc; |
| 549 | } |
| 550 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 551 | |
| 552 | int cam_sensor_util_init_gpio_pin_tbl( |
| 553 | struct cam_hw_soc_info *soc_info, |
| 554 | struct msm_camera_gpio_num_info **pgpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 555 | { |
| 556 | int rc = 0, val = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 557 | uint32_t gpio_array_size; |
| 558 | struct platform_device *pdev = NULL; |
| 559 | struct device_node *of_node = NULL; |
| 560 | struct cam_soc_gpio_data *gconf = NULL; |
| 561 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 562 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 563 | pdev = soc_info->pdev; |
| 564 | of_node = pdev->dev.of_node; |
| 565 | |
| 566 | gconf = soc_info->gpio_data; |
| 567 | if (!gconf) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 568 | CAM_ERR(CAM_SENSOR, "No gpio_common_table is found"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 569 | return -EINVAL; |
| 570 | } |
| 571 | |
| 572 | if (!gconf->cam_gpio_common_tbl) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 573 | CAM_ERR(CAM_SENSOR, "gpio_common_table is not initialized"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 574 | return -EINVAL; |
| 575 | } |
| 576 | |
| 577 | gpio_array_size = gconf->cam_gpio_common_tbl_size; |
| 578 | |
| 579 | if (!gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 580 | CAM_ERR(CAM_SENSOR, "invalid size of gpio table"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 581 | return -EINVAL; |
| 582 | } |
| 583 | |
| 584 | *pgpio_num_info = kzalloc(sizeof(struct msm_camera_gpio_num_info), |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 585 | GFP_KERNEL); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 586 | if (!*pgpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 587 | return -ENOMEM; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 588 | gpio_num_info = *pgpio_num_info; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 589 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 590 | rc = of_property_read_u32(of_node, "gpio-vana", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 591 | if (rc != -EINVAL) { |
| 592 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 593 | CAM_ERR(CAM_SENSOR, "read gpio-vana failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 594 | goto free_gpio_info; |
| 595 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 596 | CAM_ERR(CAM_SENSOR, "gpio-vana invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 597 | rc = -EINVAL; |
| 598 | goto free_gpio_info; |
| 599 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 600 | gpio_num_info->gpio_num[SENSOR_VANA] = |
| 601 | gconf->cam_gpio_common_tbl[val].gpio; |
| 602 | gpio_num_info->valid[SENSOR_VANA] = 1; |
| 603 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 604 | CAM_DBG(CAM_SENSOR, "%s:%d gpio-vana %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 605 | gpio_num_info->gpio_num[SENSOR_VANA]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 608 | rc = of_property_read_u32(of_node, "gpio-vio", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 609 | if (rc != -EINVAL) { |
| 610 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 611 | CAM_ERR(CAM_SENSOR, "read gpio-vio failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 612 | goto free_gpio_info; |
| 613 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 614 | CAM_ERR(CAM_SENSOR, "gpio-vio invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 615 | goto free_gpio_info; |
| 616 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 617 | gpio_num_info->gpio_num[SENSOR_VIO] = |
| 618 | gconf->cam_gpio_common_tbl[val].gpio; |
| 619 | gpio_num_info->valid[SENSOR_VIO] = 1; |
| 620 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 621 | CAM_DBG(CAM_SENSOR, "gpio-vio %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 622 | gpio_num_info->gpio_num[SENSOR_VIO]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 625 | rc = of_property_read_u32(of_node, "gpio-vaf", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 626 | if (rc != -EINVAL) { |
| 627 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 628 | CAM_ERR(CAM_SENSOR, "read gpio-vaf failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 629 | goto free_gpio_info; |
| 630 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 631 | CAM_ERR(CAM_SENSOR, "gpio-vaf invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 632 | rc = -EINVAL; |
| 633 | goto free_gpio_info; |
| 634 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 635 | gpio_num_info->gpio_num[SENSOR_VAF] = |
| 636 | gconf->cam_gpio_common_tbl[val].gpio; |
| 637 | gpio_num_info->valid[SENSOR_VAF] = 1; |
| 638 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 639 | CAM_DBG(CAM_SENSOR, "gpio-vaf %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 640 | gpio_num_info->gpio_num[SENSOR_VAF]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 643 | rc = of_property_read_u32(of_node, "gpio-vdig", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 644 | if (rc != -EINVAL) { |
| 645 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 646 | CAM_ERR(CAM_SENSOR, "read gpio-vdig failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 647 | goto free_gpio_info; |
| 648 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 649 | CAM_ERR(CAM_SENSOR, "gpio-vdig invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 650 | rc = -EINVAL; |
| 651 | goto free_gpio_info; |
| 652 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 653 | gpio_num_info->gpio_num[SENSOR_VDIG] = |
| 654 | gconf->cam_gpio_common_tbl[val].gpio; |
| 655 | gpio_num_info->valid[SENSOR_VDIG] = 1; |
| 656 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 657 | CAM_DBG(CAM_SENSOR, "gpio-vdig %d", |
| 658 | gpio_num_info->gpio_num[SENSOR_VDIG]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 661 | rc = of_property_read_u32(of_node, "gpio-reset", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 662 | if (rc != -EINVAL) { |
| 663 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 664 | CAM_ERR(CAM_SENSOR, "read gpio-reset failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 665 | goto free_gpio_info; |
| 666 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 667 | CAM_ERR(CAM_SENSOR, "gpio-reset invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 668 | rc = -EINVAL; |
| 669 | goto free_gpio_info; |
| 670 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 671 | gpio_num_info->gpio_num[SENSOR_RESET] = |
| 672 | gconf->cam_gpio_common_tbl[val].gpio; |
| 673 | gpio_num_info->valid[SENSOR_RESET] = 1; |
| 674 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 675 | CAM_DBG(CAM_SENSOR, "gpio-reset %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 676 | gpio_num_info->gpio_num[SENSOR_RESET]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 679 | rc = of_property_read_u32(of_node, "gpio-standby", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 680 | if (rc != -EINVAL) { |
| 681 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 682 | CAM_ERR(CAM_SENSOR, |
| 683 | "read gpio-standby failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 684 | goto free_gpio_info; |
| 685 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 686 | CAM_ERR(CAM_SENSOR, "gpio-standby invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 687 | rc = -EINVAL; |
| 688 | goto free_gpio_info; |
| 689 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 690 | gpio_num_info->gpio_num[SENSOR_STANDBY] = |
| 691 | gconf->cam_gpio_common_tbl[val].gpio; |
| 692 | gpio_num_info->valid[SENSOR_STANDBY] = 1; |
| 693 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 694 | CAM_DBG(CAM_SENSOR, "gpio-standby %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 695 | gpio_num_info->gpio_num[SENSOR_STANDBY]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 698 | rc = of_property_read_u32(of_node, "gpio-af-pwdm", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 699 | if (rc != -EINVAL) { |
| 700 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 701 | CAM_ERR(CAM_SENSOR, |
| 702 | "read gpio-af-pwdm failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 703 | goto free_gpio_info; |
| 704 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 705 | CAM_ERR(CAM_SENSOR, "gpio-af-pwdm invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 706 | rc = -EINVAL; |
| 707 | goto free_gpio_info; |
| 708 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 709 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM] = |
| 710 | gconf->cam_gpio_common_tbl[val].gpio; |
| 711 | gpio_num_info->valid[SENSOR_VAF_PWDM] = 1; |
| 712 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 713 | CAM_DBG(CAM_SENSOR, "gpio-af-pwdm %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 714 | gpio_num_info->gpio_num[SENSOR_VAF_PWDM]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 717 | rc = of_property_read_u32(of_node, "gpio-custom1", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 718 | if (rc != -EINVAL) { |
| 719 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 720 | CAM_ERR(CAM_SENSOR, |
| 721 | "read gpio-custom1 failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 722 | goto free_gpio_info; |
| 723 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 724 | CAM_ERR(CAM_SENSOR, "gpio-custom1 invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 725 | rc = -EINVAL; |
| 726 | goto free_gpio_info; |
| 727 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 728 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1] = |
| 729 | gconf->cam_gpio_common_tbl[val].gpio; |
| 730 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO1] = 1; |
| 731 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 732 | CAM_DBG(CAM_SENSOR, "gpio-custom1 %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 733 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 736 | rc = of_property_read_u32(of_node, "gpio-custom2", &val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 737 | if (rc != -EINVAL) { |
| 738 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 739 | CAM_ERR(CAM_SENSOR, |
| 740 | "read gpio-custom2 failed rc %d", rc); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 741 | goto free_gpio_info; |
| 742 | } else if (val >= gpio_array_size) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 743 | CAM_ERR(CAM_SENSOR, "gpio-custom2 invalid %d", val); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 744 | rc = -EINVAL; |
| 745 | goto free_gpio_info; |
| 746 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 747 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2] = |
| 748 | gconf->cam_gpio_common_tbl[val].gpio; |
| 749 | gpio_num_info->valid[SENSOR_CUSTOM_GPIO2] = 1; |
| 750 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 751 | CAM_DBG(CAM_SENSOR, "gpio-custom2 %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 752 | gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2]); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 753 | } else { |
| 754 | rc = 0; |
| 755 | } |
| 756 | |
| 757 | return rc; |
| 758 | |
| 759 | free_gpio_info: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 760 | kfree(gpio_num_info); |
| 761 | gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 762 | return rc; |
| 763 | } |
| 764 | |
| 765 | int msm_camera_pinctrl_init( |
| 766 | struct msm_pinctrl_info *sensor_pctrl, struct device *dev) { |
| 767 | |
| 768 | sensor_pctrl->pinctrl = devm_pinctrl_get(dev); |
| 769 | if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 770 | CAM_ERR(CAM_SENSOR, "Getting pinctrl handle failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 771 | return -EINVAL; |
| 772 | } |
| 773 | sensor_pctrl->gpio_state_active = |
| 774 | pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 775 | CAM_SENSOR_PINCTRL_STATE_DEFAULT); |
| 776 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_active)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 777 | CAM_ERR(CAM_SENSOR, |
| 778 | "Failed to get the active state pinctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 779 | return -EINVAL; |
| 780 | } |
| 781 | sensor_pctrl->gpio_state_suspend |
| 782 | = pinctrl_lookup_state(sensor_pctrl->pinctrl, |
| 783 | CAM_SENSOR_PINCTRL_STATE_SLEEP); |
| 784 | if (IS_ERR_OR_NULL(sensor_pctrl->gpio_state_suspend)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 785 | CAM_ERR(CAM_SENSOR, |
| 786 | "Failed to get the suspend state pinctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 787 | return -EINVAL; |
| 788 | } |
| 789 | return 0; |
| 790 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 791 | int msm_cam_sensor_handle_reg_gpio(int seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 792 | struct msm_camera_gpio_num_info *gpio_num_info, int val) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 793 | { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 794 | int gpio_offset = -1; |
| 795 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 796 | if (!gpio_num_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 797 | CAM_ERR(CAM_SENSOR, "Input Parameters are not proper"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 798 | return -EINVAL; |
| 799 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 800 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 801 | 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] | 802 | |
| 803 | gpio_offset = seq_type; |
| 804 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 805 | if (gpio_num_info->valid[gpio_offset] == 1) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 806 | CAM_DBG(CAM_SENSOR, "VALID GPIO offset: %d, seqtype: %d", |
| 807 | gpio_offset, seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 808 | gpio_set_value_cansleep( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 809 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 810 | [gpio_offset], val); |
| 811 | } |
| 812 | |
| 813 | return 0; |
| 814 | } |
| 815 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 816 | int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl, |
| 817 | struct cam_hw_soc_info *soc_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 818 | { |
| 819 | 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] | 820 | int32_t vreg_idx = -1; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 821 | struct cam_sensor_power_setting *power_setting = NULL; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 822 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 823 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 824 | CAM_DBG(CAM_SENSOR, "Enter"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 825 | if (!ctrl) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 826 | CAM_ERR(CAM_SENSOR, "Invalid ctrl handle"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 827 | return -EINVAL; |
| 828 | } |
| 829 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 830 | gpio_num_info = ctrl->gpio_num_info; |
| 831 | num_vreg = soc_info->num_rgltr; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 832 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 833 | if ((num_vreg == 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 834 | CAM_ERR(CAM_SENSOR, "Regulators are not initialized"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 835 | return -EINVAL; |
| 836 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 837 | |
| 838 | ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev); |
| 839 | if (ret < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 840 | CAM_ERR(CAM_SENSOR, "Initialization of pinctrl failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 841 | ctrl->cam_pinctrl_status = 0; |
| 842 | } else { |
| 843 | ctrl->cam_pinctrl_status = 1; |
| 844 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 845 | |
| 846 | rc = cam_sensor_util_request_gpio_table(soc_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 847 | if (rc < 0) |
| 848 | no_gpio = rc; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 849 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 850 | if (ctrl->cam_pinctrl_status) { |
| 851 | ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl, |
| 852 | ctrl->pinctrl_info.gpio_state_active); |
| 853 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 854 | CAM_ERR(CAM_SENSOR, "cannot set pin to active state"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | for (index = 0; index < ctrl->power_setting_size; index++) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 858 | CAM_DBG(CAM_SENSOR, "index: %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 859 | power_setting = &ctrl->power_setting[index]; |
| 860 | |
| 861 | switch (power_setting->seq_type) { |
| 862 | case SENSOR_MCLK: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 863 | if (power_setting->seq_val >= soc_info->num_clk) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 864 | CAM_ERR(CAM_SENSOR, "clk index %d >= max %u", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 865 | power_setting->seq_val, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 866 | soc_info->num_clk); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 867 | goto power_up_failed; |
| 868 | } |
| 869 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 870 | if (!strcmp(soc_info->rgltr_name[j], |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 871 | "cam_clk")) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 872 | CAM_DBG(CAM_SENSOR, |
| 873 | "Enable cam_clk: %d", j); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 874 | |
| 875 | soc_info->rgltr[j] = |
| 876 | regulator_get( |
| 877 | &soc_info->pdev->dev, |
| 878 | soc_info->rgltr_name[j]); |
| 879 | |
| 880 | if (IS_ERR_OR_NULL( |
| 881 | soc_info->rgltr[j])) { |
| 882 | rc = PTR_ERR( |
| 883 | soc_info->rgltr[j]); |
| 884 | rc = rc ? rc : -EINVAL; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 885 | CAM_ERR(CAM_SENSOR, |
| 886 | "vreg %s %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 887 | soc_info->rgltr_name[j], |
| 888 | rc); |
| 889 | soc_info->rgltr[j] = NULL; |
| 890 | } |
| 891 | |
| 892 | rc = cam_soc_util_regulator_enable( |
| 893 | soc_info->rgltr[j], |
| 894 | soc_info->rgltr_name[j], |
| 895 | soc_info->rgltr_min_volt[j], |
| 896 | soc_info->rgltr_max_volt[j], |
| 897 | soc_info->rgltr_op_mode[j], |
| 898 | soc_info->rgltr_delay[j]); |
| 899 | |
| 900 | power_setting->data[0] = |
| 901 | soc_info->rgltr[j]; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | if (power_setting->config_val) |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 905 | soc_info->clk_rate[0][power_setting->seq_val] = |
| 906 | power_setting->config_val; |
| 907 | |
| 908 | for (j = 0; j < soc_info->num_clk; j++) { |
| 909 | rc = cam_soc_util_clk_enable(soc_info->clk[j], |
| 910 | soc_info->clk_name[j], |
| 911 | soc_info->clk_rate[0][j]); |
| 912 | if (rc) |
| 913 | break; |
| 914 | } |
| 915 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 916 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 917 | CAM_ERR(CAM_SENSOR, "clk enable failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 918 | goto power_up_failed; |
| 919 | } |
| 920 | break; |
| 921 | case SENSOR_RESET: |
| 922 | case SENSOR_STANDBY: |
| 923 | case SENSOR_CUSTOM_GPIO1: |
| 924 | case SENSOR_CUSTOM_GPIO2: |
| 925 | if (no_gpio) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 926 | CAM_ERR(CAM_SENSOR, "request gpio failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 927 | return no_gpio; |
| 928 | } |
| 929 | if (power_setting->seq_val >= CAM_VREG_MAX || |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 930 | !gpio_num_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 931 | CAM_ERR(CAM_SENSOR, "gpio index %d >= max %d", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 932 | power_setting->seq_val, |
| 933 | CAM_VREG_MAX); |
| 934 | goto power_up_failed; |
| 935 | } |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 936 | CAM_DBG(CAM_SENSOR, "gpio set val %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 937 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 938 | [power_setting->seq_val]); |
| 939 | |
| 940 | rc = msm_cam_sensor_handle_reg_gpio( |
| 941 | power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 942 | gpio_num_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 943 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 944 | CAM_ERR(CAM_SENSOR, |
| 945 | "Error in handling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 946 | goto power_up_failed; |
| 947 | } |
| 948 | break; |
| 949 | case SENSOR_VANA: |
| 950 | case SENSOR_VDIG: |
| 951 | case SENSOR_VIO: |
| 952 | case SENSOR_VAF: |
| 953 | case SENSOR_VAF_PWDM: |
| 954 | case SENSOR_CUSTOM_REG1: |
| 955 | case SENSOR_CUSTOM_REG2: |
| 956 | if (power_setting->seq_val == INVALID_VREG) |
| 957 | break; |
| 958 | |
| 959 | if (power_setting->seq_val >= CAM_VREG_MAX) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 960 | CAM_ERR(CAM_SENSOR, "vreg index %d >= max %d", |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 961 | power_setting->seq_val, |
| 962 | CAM_VREG_MAX); |
| 963 | goto power_up_failed; |
| 964 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 965 | if (power_setting->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 966 | CAM_DBG(CAM_SENSOR, "Enable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 967 | vreg_idx = power_setting->seq_val; |
| 968 | |
| 969 | soc_info->rgltr[vreg_idx] = |
| 970 | regulator_get(&soc_info->pdev->dev, |
| 971 | soc_info->rgltr_name[vreg_idx]); |
| 972 | if (IS_ERR_OR_NULL( |
| 973 | soc_info->rgltr[vreg_idx])) { |
| 974 | rc = PTR_ERR(soc_info->rgltr[vreg_idx]); |
| 975 | rc = rc ? rc : -EINVAL; |
| 976 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 977 | CAM_ERR(CAM_SENSOR, "%s get failed %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 978 | soc_info->rgltr_name[vreg_idx], |
| 979 | rc); |
| 980 | |
| 981 | soc_info->rgltr[vreg_idx] = NULL; |
| 982 | } |
| 983 | |
| 984 | rc = cam_soc_util_regulator_enable( |
| 985 | soc_info->rgltr[vreg_idx], |
| 986 | soc_info->rgltr_name[vreg_idx], |
| 987 | soc_info->rgltr_min_volt[vreg_idx], |
| 988 | soc_info->rgltr_max_volt[vreg_idx], |
| 989 | soc_info->rgltr_op_mode[vreg_idx], |
| 990 | soc_info->rgltr_delay[vreg_idx]); |
| 991 | |
| 992 | power_setting->data[0] = |
| 993 | soc_info->rgltr[vreg_idx]; |
| 994 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 995 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 996 | CAM_ERR(CAM_SENSOR, "usr_idx:%d dts_idx:%d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 997 | power_setting->seq_val, num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 998 | |
| 999 | rc = msm_cam_sensor_handle_reg_gpio( |
| 1000 | power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1001 | gpio_num_info, 1); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1002 | if (rc < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1003 | CAM_ERR(CAM_SENSOR, |
| 1004 | "Error in handling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1005 | goto power_up_failed; |
| 1006 | } |
| 1007 | break; |
| 1008 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1009 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1010 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1011 | break; |
| 1012 | } |
| 1013 | if (power_setting->delay > 20) |
| 1014 | msleep(power_setting->delay); |
| 1015 | else if (power_setting->delay) |
| 1016 | usleep_range(power_setting->delay * 1000, |
| 1017 | (power_setting->delay * 1000) + 1000); |
| 1018 | } |
| 1019 | |
| 1020 | return 0; |
| 1021 | power_up_failed: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1022 | CAM_ERR(CAM_SENSOR, "failed"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1023 | for (index--; index >= 0; index--) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1024 | CAM_DBG(CAM_SENSOR, "index %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1025 | power_setting = &ctrl->power_setting[index]; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1026 | CAM_DBG(CAM_SENSOR, "type %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1027 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1028 | switch (power_setting->seq_type) { |
| 1029 | case SENSOR_RESET: |
| 1030 | case SENSOR_STANDBY: |
| 1031 | case SENSOR_CUSTOM_GPIO1: |
| 1032 | case SENSOR_CUSTOM_GPIO2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1033 | if (!gpio_num_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1034 | continue; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1035 | if (!gpio_num_info->valid |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1036 | [power_setting->seq_val]) |
| 1037 | continue; |
| 1038 | gpio_set_value_cansleep( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1039 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1040 | [power_setting->seq_val], GPIOF_OUT_INIT_LOW); |
| 1041 | break; |
| 1042 | case SENSOR_VANA: |
| 1043 | case SENSOR_VDIG: |
| 1044 | case SENSOR_VIO: |
| 1045 | case SENSOR_VAF: |
| 1046 | case SENSOR_VAF_PWDM: |
| 1047 | case SENSOR_CUSTOM_REG1: |
| 1048 | case SENSOR_CUSTOM_REG2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1049 | if (power_setting->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1050 | CAM_DBG(CAM_SENSOR, "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1051 | vreg_idx = power_setting->seq_val; |
| 1052 | |
| 1053 | rc = cam_soc_util_regulator_disable( |
| 1054 | soc_info->rgltr[vreg_idx], |
| 1055 | soc_info->rgltr_name[vreg_idx], |
| 1056 | soc_info->rgltr_min_volt[vreg_idx], |
| 1057 | soc_info->rgltr_max_volt[vreg_idx], |
| 1058 | soc_info->rgltr_op_mode[vreg_idx], |
| 1059 | soc_info->rgltr_delay[vreg_idx]); |
| 1060 | |
| 1061 | power_setting->data[0] = |
| 1062 | soc_info->rgltr[vreg_idx]; |
| 1063 | |
| 1064 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1065 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1066 | CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d", |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1067 | power_setting->seq_val, num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1068 | |
| 1069 | msm_cam_sensor_handle_reg_gpio(power_setting->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1070 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 1071 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1072 | break; |
| 1073 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1074 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1075 | power_setting->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1076 | break; |
| 1077 | } |
| 1078 | if (power_setting->delay > 20) { |
| 1079 | msleep(power_setting->delay); |
| 1080 | } else if (power_setting->delay) { |
| 1081 | usleep_range(power_setting->delay * 1000, |
| 1082 | (power_setting->delay * 1000) + 1000); |
| 1083 | } |
| 1084 | } |
| 1085 | if (ctrl->cam_pinctrl_status) { |
| 1086 | ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl, |
| 1087 | ctrl->pinctrl_info.gpio_state_suspend); |
| 1088 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1089 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1090 | devm_pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 1091 | } |
| 1092 | ctrl->cam_pinctrl_status = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1093 | |
| 1094 | cam_sensor_util_request_gpio_table(soc_info, 0); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1095 | |
| 1096 | return rc; |
| 1097 | } |
| 1098 | |
| 1099 | static struct cam_sensor_power_setting* |
| 1100 | msm_camera_get_power_settings(struct cam_sensor_power_ctrl_t *ctrl, |
| 1101 | enum msm_camera_power_seq_type seq_type, |
| 1102 | uint16_t seq_val) |
| 1103 | { |
| 1104 | struct cam_sensor_power_setting *power_setting, *ps = NULL; |
| 1105 | int idx; |
| 1106 | |
| 1107 | for (idx = 0; idx < ctrl->power_setting_size; idx++) { |
| 1108 | power_setting = &ctrl->power_setting[idx]; |
| 1109 | if (power_setting->seq_type == seq_type && |
| 1110 | power_setting->seq_val == seq_val) { |
| 1111 | ps = power_setting; |
| 1112 | return ps; |
| 1113 | } |
| 1114 | |
| 1115 | } |
| 1116 | |
| 1117 | return ps; |
| 1118 | } |
| 1119 | |
| 1120 | 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] | 1121 | struct cam_hw_soc_info *soc_info, int32_t index) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1122 | { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1123 | int32_t num_vreg = 0, j = 0, rc = 0, idx = 0; |
| 1124 | struct cam_sensor_power_setting *ps = NULL; |
| 1125 | struct cam_sensor_power_setting *pd = NULL; |
| 1126 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1127 | num_vreg = soc_info->num_rgltr; |
| 1128 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1129 | pd = &ctrl->power_down_setting[index]; |
| 1130 | |
| 1131 | for (j = 0; j < num_vreg; j++) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1132 | if (!strcmp(soc_info->rgltr_name[j], "cam_clk")) { |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1133 | |
| 1134 | ps = NULL; |
| 1135 | for (idx = 0; idx < |
| 1136 | ctrl->power_setting_size; idx++) { |
| 1137 | if (ctrl->power_setting[idx]. |
| 1138 | seq_type == pd->seq_type) { |
| 1139 | ps = &ctrl->power_setting[idx]; |
| 1140 | break; |
| 1141 | } |
| 1142 | } |
| 1143 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1144 | if (ps != NULL) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1145 | CAM_DBG(CAM_SENSOR, "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1146 | |
| 1147 | rc = cam_soc_util_regulator_disable( |
| 1148 | soc_info->rgltr[j], |
| 1149 | soc_info->rgltr_name[j], |
| 1150 | soc_info->rgltr_min_volt[j], |
| 1151 | soc_info->rgltr_max_volt[j], |
| 1152 | soc_info->rgltr_op_mode[j], |
| 1153 | soc_info->rgltr_delay[j]); |
| 1154 | |
| 1155 | ps->data[0] = |
| 1156 | soc_info->rgltr[j]; |
| 1157 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | return rc; |
| 1162 | } |
| 1163 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1164 | int msm_camera_power_down(struct cam_sensor_power_ctrl_t *ctrl, |
| 1165 | struct cam_hw_soc_info *soc_info) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1166 | { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1167 | int index = 0, ret = 0, num_vreg = 0, i; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1168 | struct cam_sensor_power_setting *pd = NULL; |
| 1169 | struct cam_sensor_power_setting *ps; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1170 | struct msm_camera_gpio_num_info *gpio_num_info = NULL; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1171 | |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1172 | CAM_DBG(CAM_SENSOR, "Enter"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1173 | if (!ctrl || !soc_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1174 | CAM_ERR(CAM_SENSOR, "failed ctrl %pK", ctrl); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1175 | return -EINVAL; |
| 1176 | } |
| 1177 | |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1178 | gpio_num_info = ctrl->gpio_num_info; |
| 1179 | num_vreg = soc_info->num_rgltr; |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1180 | |
| 1181 | for (index = 0; index < ctrl->power_down_setting_size; index++) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1182 | CAM_DBG(CAM_SENSOR, "index %d", index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1183 | pd = &ctrl->power_down_setting[index]; |
| 1184 | ps = NULL; |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1185 | CAM_DBG(CAM_SENSOR, "type %d", pd->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1186 | switch (pd->seq_type) { |
| 1187 | case SENSOR_MCLK: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1188 | ret = cam_config_mclk_reg(ctrl, soc_info, index); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1189 | if (ret < 0) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1190 | CAM_ERR(CAM_SENSOR, |
| 1191 | "config clk reg failed rc: %d", ret); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1192 | return ret; |
| 1193 | } |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1194 | //cam_soc_util_clk_disable_default(soc_info); |
| 1195 | for (i = soc_info->num_clk - 1; i >= 0; i--) { |
| 1196 | cam_soc_util_clk_disable(soc_info->clk[i], |
| 1197 | soc_info->clk_name[i]); |
| 1198 | } |
| 1199 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1200 | break; |
| 1201 | case SENSOR_RESET: |
| 1202 | case SENSOR_STANDBY: |
| 1203 | case SENSOR_CUSTOM_GPIO1: |
| 1204 | case SENSOR_CUSTOM_GPIO2: |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1205 | |
| 1206 | if (!gpio_num_info->valid[pd->seq_val]) |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1207 | continue; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1208 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1209 | gpio_set_value_cansleep( |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1210 | gpio_num_info->gpio_num |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1211 | [pd->seq_val], |
| 1212 | (int) pd->config_val); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1213 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1214 | break; |
| 1215 | case SENSOR_VANA: |
| 1216 | case SENSOR_VDIG: |
| 1217 | case SENSOR_VIO: |
| 1218 | case SENSOR_VAF: |
| 1219 | case SENSOR_VAF_PWDM: |
| 1220 | case SENSOR_CUSTOM_REG1: |
| 1221 | case SENSOR_CUSTOM_REG2: |
| 1222 | if (pd->seq_val == INVALID_VREG) |
| 1223 | break; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1224 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1225 | ps = msm_camera_get_power_settings( |
| 1226 | ctrl, pd->seq_type, |
| 1227 | pd->seq_val); |
| 1228 | if (ps) { |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1229 | if (pd->seq_val < num_vreg) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1230 | CAM_DBG(CAM_SENSOR, |
| 1231 | "Disable Regulator"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1232 | ret = cam_soc_util_regulator_disable( |
| 1233 | soc_info->rgltr[ps->seq_val], |
| 1234 | soc_info->rgltr_name[ps->seq_val], |
| 1235 | soc_info->rgltr_min_volt[ps->seq_val], |
| 1236 | soc_info->rgltr_max_volt[ps->seq_val], |
| 1237 | soc_info->rgltr_op_mode[ps->seq_val], |
| 1238 | soc_info->rgltr_delay[ps->seq_val]); |
| 1239 | |
| 1240 | ps->data[0] = |
| 1241 | soc_info->rgltr[ps->seq_val]; |
| 1242 | } |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1243 | else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1244 | CAM_ERR(CAM_SENSOR, |
| 1245 | "seq_val:%d > num_vreg: %d", |
| 1246 | pd->seq_val, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1247 | num_vreg); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1248 | } else |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1249 | CAM_ERR(CAM_SENSOR, |
| 1250 | "error in power up/down seq"); |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1251 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1252 | ret = msm_cam_sensor_handle_reg_gpio(pd->seq_type, |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1253 | gpio_num_info, GPIOF_OUT_INIT_LOW); |
| 1254 | |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1255 | if (ret < 0) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1256 | CAM_ERR(CAM_SENSOR, |
| 1257 | "Error disabling VREG GPIO"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1258 | break; |
| 1259 | default: |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1260 | CAM_ERR(CAM_SENSOR, "error power seq type %d", |
| 1261 | pd->seq_type); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1262 | break; |
| 1263 | } |
| 1264 | if (pd->delay > 20) |
| 1265 | msleep(pd->delay); |
| 1266 | else if (pd->delay) |
| 1267 | usleep_range(pd->delay * 1000, |
| 1268 | (pd->delay * 1000) + 1000); |
| 1269 | } |
| 1270 | |
| 1271 | if (ctrl->cam_pinctrl_status) { |
| 1272 | ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl, |
| 1273 | ctrl->pinctrl_info.gpio_state_suspend); |
| 1274 | if (ret) |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame^] | 1275 | CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state"); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1276 | devm_pinctrl_put(ctrl->pinctrl_info.pinctrl); |
| 1277 | } |
| 1278 | |
| 1279 | ctrl->cam_pinctrl_status = 0; |
Alok Pandey | 01b1b35 | 2017-06-25 20:38:54 +0530 | [diff] [blame] | 1280 | |
| 1281 | cam_sensor_util_request_gpio_table(soc_info, 0); |
Viswanadha Raju Thotakura | 426ec66 | 2017-03-15 17:00:29 -0700 | [diff] [blame] | 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |