blob: 9ba5cbf3fb9275cb2d2656c64c4511b57117c607 [file] [log] [blame]
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001/* 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 Thotakura426ec662017-03-15 17:00:29 -070015
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 Thotakura426ec662017-03-15 17:00:29 -070022static 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
50int32_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 Zalacbb5a382017-07-17 19:06:42 -070056 CAM_ERR(CAM_SENSOR, "FATAL:: Invalid argument");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -070057 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
72int32_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 Zalacbb5a382017-07-17 19:06:42 -070085 CAM_ERR(CAM_SENSOR, "Invalid list ptr");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -070086 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 Zalacbb5a382017-07-17 19:06:42 -0700107 CAM_ERR(CAM_SENSOR, "Delay Rxed Before any buffer: %d", offset);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700108 return -EINVAL;
109 }
110
111 return rc;
112}
113
114int32_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 Zalacbb5a382017-07-17 19:06:42 -0700128 CAM_ERR(CAM_SENSOR, "Failed in allocating mem for list");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700129 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
154int32_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 Zalacbb5a382017-07-17 19:06:42 -0700167 CAM_ERR(CAM_SENSOR, "Failed in allocating i2c_list");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700168 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 */
209int 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 Zalacbb5a382017-07-17 19:06:42 -0700229 CAM_DBG(CAM_SENSOR, "Total cmd Buf in Bytes: %d",
230 cmd_desc[i].length);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700231
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 Zalacbb5a382017-07-17 19:06:42 -0700239 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 Thotakura426ec662017-03-15 17:00:29 -0700242 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 Zalacbb5a382017-07-17 19:06:42 -0700261 CAM_ERR(CAM_SENSOR,
262 "Failed in random read %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700263 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 Zalacbb5a382017-07-17 19:06:42 -0700282 CAM_ERR(CAM_SENSOR,
283 "delay hdl failed: %d",
284 rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700285 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 Zalacbb5a382017-07-17 19:06:42 -0700294 CAM_ERR(CAM_SENSOR,
295 "Random read fail: %d",
296 rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700297 return rc;
298 }
299 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700300 CAM_ERR(CAM_SENSOR,
301 "Wrong Wait Command: %d",
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700302 generic_op_code);
303 return -EINVAL;
304 }
305 break;
306 }
307 default:
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700308 CAM_ERR(CAM_SENSOR, "Invalid Command Type:%d",
309 cmm_hdr->cmd_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700310 return -EINVAL;
311 }
312 }
313 i2c_reg_settings->is_settings_valid = 1;
314 }
315
316 return rc;
317}
318
Alok Pandey01b1b352017-06-25 20:38:54 +0530319int32_t msm_camera_fill_vreg_params(
320 struct cam_hw_soc_info *soc_info,
321 struct cam_sensor_power_setting *power_setting,
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700322 uint16_t power_setting_size)
323{
324 int32_t rc = 0, j = 0, i = 0;
Alok Pandey01b1b352017-06-25 20:38:54 +0530325 uint32_t num_vreg;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700326
327 /* Validate input parameters */
Alok Pandey01b1b352017-06-25 20:38:54 +0530328 if (!soc_info || !power_setting) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700329 CAM_ERR(CAM_SENSOR, "failed: soc_info %pK power_setting %pK",
330 soc_info, power_setting);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700331 return -EINVAL;
332 }
333
Alok Pandey01b1b352017-06-25 20:38:54 +0530334 num_vreg = soc_info->num_rgltr;
335
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700336 if (num_vreg <= 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700337 CAM_ERR(CAM_SENSOR, "failed: num_vreg %d", num_vreg);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700338 return -EINVAL;
339 }
340
Alok Pandey01b1b352017-06-25 20:38:54 +0530341
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700342 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 Pandey01b1b352017-06-25 20:38:54 +0530346 if (!strcmp(soc_info->rgltr_name[j],
347 "cam_vdig")) {
348
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700349 CAM_DBG(CAM_SENSOR,
350 "i: %d j: %d cam_vdig", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700351 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530352
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700353 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530354 soc_info->rgltr_min_volt[j],
355 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700356 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530357 soc_info->rgltr_min_volt[j] =
358 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700359 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 Pandey01b1b352017-06-25 20:38:54 +0530370
371 if (!strcmp(soc_info->rgltr_name[j],
372 "cam_vio")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700373 CAM_DBG(CAM_SENSOR,
374 "i: %d j: %d cam_vio", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700375 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530376
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700377 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530378 soc_info->rgltr_min_volt[j],
379 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700380 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530381 soc_info->rgltr_min_volt[j] =
382 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700383 power_setting[i].config_val;
384 }
385 break;
386 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530387
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700388 }
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 Pandey01b1b352017-06-25 20:38:54 +0530395
396 if (!strcmp(soc_info->rgltr_name[j],
397 "cam_vana")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700398 CAM_DBG(CAM_SENSOR,
399 "i: %d j: %d cam_vana", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700400 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530401
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700402 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530403 soc_info->rgltr_min_volt[j],
404 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700405 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530406 soc_info->rgltr_min_volt[j] =
407 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700408 power_setting[i].config_val;
409 }
410 break;
411 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530412
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700413 }
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 Pandey01b1b352017-06-25 20:38:54 +0530420
421 if (!strcmp(soc_info->rgltr_name[j],
422 "cam_vaf")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700423 CAM_DBG(CAM_SENSOR,
424 "i: %d j: %d cam_vaf", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700425 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530426
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700427 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530428 soc_info->rgltr_min_volt[j],
429 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700430 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530431 soc_info->rgltr_min_volt[j] =
432 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700433 power_setting[i].config_val;
434 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530435
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700436 break;
437 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530438
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700439 }
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 Pandey01b1b352017-06-25 20:38:54 +0530446
447 if (!strcmp(soc_info->rgltr_name[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700448 "cam_v_custom1")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700449 CAM_DBG(CAM_SENSOR,
450 "i:%d j:%d cam_vcustom1", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700451 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530452
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700453 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530454 soc_info->rgltr_min_volt[j],
455 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700456 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530457 soc_info->rgltr_min_volt[j] =
458 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700459 power_setting[i].config_val;
460 }
461 break;
462 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530463
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700464 }
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 Pandey01b1b352017-06-25 20:38:54 +0530470
471 if (!strcmp(soc_info->rgltr_name[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700472 "cam_v_custom2")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700473 CAM_DBG(CAM_SENSOR,
474 "i:%d j:%d cam_vcustom2", i, j);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700475 power_setting[i].seq_val = j;
Alok Pandey01b1b352017-06-25 20:38:54 +0530476
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700477 if (VALIDATE_VOLTAGE(
Alok Pandey01b1b352017-06-25 20:38:54 +0530478 soc_info->rgltr_min_volt[j],
479 soc_info->rgltr_max_volt[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700480 power_setting[i].config_val)) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530481 soc_info->rgltr_min_volt[j] =
482 soc_info->rgltr_max_volt[j] =
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700483 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 Zalacbb5a382017-07-17 19:06:42 -0700493 CAM_ERR(CAM_SENSOR, "invalid seq_val %d",
494 power_setting[i].seq_val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700495 break;
496 }
497 }
498 }
499
500 return rc;
501}
502
Alok Pandey01b1b352017-06-25 20:38:54 +0530503int cam_sensor_util_request_gpio_table(
504 struct cam_hw_soc_info *soc_info, int gpio_en)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700505{
Alok Pandey01b1b352017-06-25 20:38:54 +0530506 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 Thotakura426ec662017-03-15 17:00:29 -0700511
Alok Pandey01b1b352017-06-25 20:38:54 +0530512 size = gpio_conf->cam_gpio_req_tbl_size;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700513
Alok Pandey01b1b352017-06-25 20:38:54 +0530514 if (gpio_conf->cam_gpio_common_tbl_size <= 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700515 CAM_INFO(CAM_SENSOR, "No GPIO entry");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700516 return 0;
517 }
518
Alok Pandey01b1b352017-06-25 20:38:54 +0530519 if (!gpio_tbl || !size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700520 CAM_ERR(CAM_SENSOR, "invalid gpio_tbl %pK / size %d",
521 gpio_tbl, size);
Alok Pandey01b1b352017-06-25 20:38:54 +0530522 return -EINVAL;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700523 }
524
Alok Pandey01b1b352017-06-25 20:38:54 +0530525 for (i = 0; i < size; i++) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700526 CAM_DBG(CAM_SENSOR, "i: %d, gpio %d dir %ld", i,
527 gpio_tbl[i].gpio, gpio_tbl[i].flags);
Alok Pandey01b1b352017-06-25 20:38:54 +0530528 }
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 Zalacbb5a382017-07-17 19:06:42 -0700540 CAM_ERR(CAM_SENSOR, "gpio %d:%s request fails",
Alok Pandey01b1b352017-06-25 20:38:54 +0530541 gpio_tbl[i].gpio, gpio_tbl[i].label);
542 }
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700543 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530544 } else {
545 gpio_free_array(gpio_tbl, size);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700546 }
547
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700548 return rc;
549}
550
Alok Pandey01b1b352017-06-25 20:38:54 +0530551
552int 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 Thotakura426ec662017-03-15 17:00:29 -0700555{
556 int rc = 0, val = 0;
Alok Pandey01b1b352017-06-25 20:38:54 +0530557 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 Thotakura426ec662017-03-15 17:00:29 -0700562
Alok Pandey01b1b352017-06-25 20:38:54 +0530563 pdev = soc_info->pdev;
564 of_node = pdev->dev.of_node;
565
566 gconf = soc_info->gpio_data;
567 if (!gconf) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700568 CAM_ERR(CAM_SENSOR, "No gpio_common_table is found");
Alok Pandey01b1b352017-06-25 20:38:54 +0530569 return -EINVAL;
570 }
571
572 if (!gconf->cam_gpio_common_tbl) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700573 CAM_ERR(CAM_SENSOR, "gpio_common_table is not initialized");
Alok Pandey01b1b352017-06-25 20:38:54 +0530574 return -EINVAL;
575 }
576
577 gpio_array_size = gconf->cam_gpio_common_tbl_size;
578
579 if (!gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700580 CAM_ERR(CAM_SENSOR, "invalid size of gpio table");
Alok Pandey01b1b352017-06-25 20:38:54 +0530581 return -EINVAL;
582 }
583
584 *pgpio_num_info = kzalloc(sizeof(struct msm_camera_gpio_num_info),
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700585 GFP_KERNEL);
Alok Pandey01b1b352017-06-25 20:38:54 +0530586 if (!*pgpio_num_info)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700587 return -ENOMEM;
Alok Pandey01b1b352017-06-25 20:38:54 +0530588 gpio_num_info = *pgpio_num_info;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700589
Alok Pandey01b1b352017-06-25 20:38:54 +0530590 rc = of_property_read_u32(of_node, "gpio-vana", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700591 if (rc != -EINVAL) {
592 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700593 CAM_ERR(CAM_SENSOR, "read gpio-vana failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700594 goto free_gpio_info;
595 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700596 CAM_ERR(CAM_SENSOR, "gpio-vana invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700597 rc = -EINVAL;
598 goto free_gpio_info;
599 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530600 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 Zalacbb5a382017-07-17 19:06:42 -0700604 CAM_DBG(CAM_SENSOR, "%s:%d gpio-vana %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530605 gpio_num_info->gpio_num[SENSOR_VANA]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700606 }
607
Alok Pandey01b1b352017-06-25 20:38:54 +0530608 rc = of_property_read_u32(of_node, "gpio-vio", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700609 if (rc != -EINVAL) {
610 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700611 CAM_ERR(CAM_SENSOR, "read gpio-vio failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700612 goto free_gpio_info;
613 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700614 CAM_ERR(CAM_SENSOR, "gpio-vio invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700615 goto free_gpio_info;
616 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530617 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 Zalacbb5a382017-07-17 19:06:42 -0700621 CAM_DBG(CAM_SENSOR, "gpio-vio %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530622 gpio_num_info->gpio_num[SENSOR_VIO]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700623 }
624
Alok Pandey01b1b352017-06-25 20:38:54 +0530625 rc = of_property_read_u32(of_node, "gpio-vaf", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700626 if (rc != -EINVAL) {
627 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700628 CAM_ERR(CAM_SENSOR, "read gpio-vaf failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700629 goto free_gpio_info;
630 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700631 CAM_ERR(CAM_SENSOR, "gpio-vaf invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700632 rc = -EINVAL;
633 goto free_gpio_info;
634 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530635 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 Zalacbb5a382017-07-17 19:06:42 -0700639 CAM_DBG(CAM_SENSOR, "gpio-vaf %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530640 gpio_num_info->gpio_num[SENSOR_VAF]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700641 }
642
Alok Pandey01b1b352017-06-25 20:38:54 +0530643 rc = of_property_read_u32(of_node, "gpio-vdig", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700644 if (rc != -EINVAL) {
645 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700646 CAM_ERR(CAM_SENSOR, "read gpio-vdig failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700647 goto free_gpio_info;
648 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700649 CAM_ERR(CAM_SENSOR, "gpio-vdig invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700650 rc = -EINVAL;
651 goto free_gpio_info;
652 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530653 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 Zalacbb5a382017-07-17 19:06:42 -0700657 CAM_DBG(CAM_SENSOR, "gpio-vdig %d",
658 gpio_num_info->gpio_num[SENSOR_VDIG]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700659 }
660
Alok Pandey01b1b352017-06-25 20:38:54 +0530661 rc = of_property_read_u32(of_node, "gpio-reset", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700662 if (rc != -EINVAL) {
663 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700664 CAM_ERR(CAM_SENSOR, "read gpio-reset failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700665 goto free_gpio_info;
666 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700667 CAM_ERR(CAM_SENSOR, "gpio-reset invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700668 rc = -EINVAL;
669 goto free_gpio_info;
670 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530671 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 Zalacbb5a382017-07-17 19:06:42 -0700675 CAM_DBG(CAM_SENSOR, "gpio-reset %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530676 gpio_num_info->gpio_num[SENSOR_RESET]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700677 }
678
Alok Pandey01b1b352017-06-25 20:38:54 +0530679 rc = of_property_read_u32(of_node, "gpio-standby", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700680 if (rc != -EINVAL) {
681 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700682 CAM_ERR(CAM_SENSOR,
683 "read gpio-standby failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700684 goto free_gpio_info;
685 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700686 CAM_ERR(CAM_SENSOR, "gpio-standby invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700687 rc = -EINVAL;
688 goto free_gpio_info;
689 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530690 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 Zalacbb5a382017-07-17 19:06:42 -0700694 CAM_DBG(CAM_SENSOR, "gpio-standby %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530695 gpio_num_info->gpio_num[SENSOR_STANDBY]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700696 }
697
Alok Pandey01b1b352017-06-25 20:38:54 +0530698 rc = of_property_read_u32(of_node, "gpio-af-pwdm", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700699 if (rc != -EINVAL) {
700 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700701 CAM_ERR(CAM_SENSOR,
702 "read gpio-af-pwdm failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700703 goto free_gpio_info;
704 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700705 CAM_ERR(CAM_SENSOR, "gpio-af-pwdm invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700706 rc = -EINVAL;
707 goto free_gpio_info;
708 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530709 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 Zalacbb5a382017-07-17 19:06:42 -0700713 CAM_DBG(CAM_SENSOR, "gpio-af-pwdm %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530714 gpio_num_info->gpio_num[SENSOR_VAF_PWDM]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700715 }
716
Alok Pandey01b1b352017-06-25 20:38:54 +0530717 rc = of_property_read_u32(of_node, "gpio-custom1", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700718 if (rc != -EINVAL) {
719 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700720 CAM_ERR(CAM_SENSOR,
721 "read gpio-custom1 failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700722 goto free_gpio_info;
723 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700724 CAM_ERR(CAM_SENSOR, "gpio-custom1 invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700725 rc = -EINVAL;
726 goto free_gpio_info;
727 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530728 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 Zalacbb5a382017-07-17 19:06:42 -0700732 CAM_DBG(CAM_SENSOR, "gpio-custom1 %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530733 gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO1]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700734 }
735
Alok Pandey01b1b352017-06-25 20:38:54 +0530736 rc = of_property_read_u32(of_node, "gpio-custom2", &val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700737 if (rc != -EINVAL) {
738 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700739 CAM_ERR(CAM_SENSOR,
740 "read gpio-custom2 failed rc %d", rc);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700741 goto free_gpio_info;
742 } else if (val >= gpio_array_size) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700743 CAM_ERR(CAM_SENSOR, "gpio-custom2 invalid %d", val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700744 rc = -EINVAL;
745 goto free_gpio_info;
746 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530747 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 Zalacbb5a382017-07-17 19:06:42 -0700751 CAM_DBG(CAM_SENSOR, "gpio-custom2 %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530752 gpio_num_info->gpio_num[SENSOR_CUSTOM_GPIO2]);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700753 } else {
754 rc = 0;
755 }
756
757 return rc;
758
759free_gpio_info:
Alok Pandey01b1b352017-06-25 20:38:54 +0530760 kfree(gpio_num_info);
761 gpio_num_info = NULL;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700762 return rc;
763}
764
765int 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 Zalacbb5a382017-07-17 19:06:42 -0700770 CAM_ERR(CAM_SENSOR, "Getting pinctrl handle failed");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700771 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 Zalacbb5a382017-07-17 19:06:42 -0700777 CAM_ERR(CAM_SENSOR,
778 "Failed to get the active state pinctrl handle");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700779 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 Zalacbb5a382017-07-17 19:06:42 -0700785 CAM_ERR(CAM_SENSOR,
786 "Failed to get the suspend state pinctrl handle");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700787 return -EINVAL;
788 }
789 return 0;
790}
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700791int msm_cam_sensor_handle_reg_gpio(int seq_type,
Alok Pandey01b1b352017-06-25 20:38:54 +0530792 struct msm_camera_gpio_num_info *gpio_num_info, int val)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700793{
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700794 int gpio_offset = -1;
795
Alok Pandey01b1b352017-06-25 20:38:54 +0530796 if (!gpio_num_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700797 CAM_ERR(CAM_SENSOR, "Input Parameters are not proper");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700798 return -EINVAL;
799 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530800
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700801 CAM_DBG(CAM_SENSOR, "Seq type: %d, config: %d", seq_type, val);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700802
803 gpio_offset = seq_type;
804
Alok Pandey01b1b352017-06-25 20:38:54 +0530805 if (gpio_num_info->valid[gpio_offset] == 1) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700806 CAM_DBG(CAM_SENSOR, "VALID GPIO offset: %d, seqtype: %d",
807 gpio_offset, seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700808 gpio_set_value_cansleep(
Alok Pandey01b1b352017-06-25 20:38:54 +0530809 gpio_num_info->gpio_num
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700810 [gpio_offset], val);
811 }
812
813 return 0;
814}
815
Alok Pandey01b1b352017-06-25 20:38:54 +0530816int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl,
817 struct cam_hw_soc_info *soc_info)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700818{
819 int rc = 0, index = 0, no_gpio = 0, ret = 0, num_vreg, j = 0;
Alok Pandey01b1b352017-06-25 20:38:54 +0530820 int32_t vreg_idx = -1;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700821 struct cam_sensor_power_setting *power_setting = NULL;
Alok Pandey01b1b352017-06-25 20:38:54 +0530822 struct msm_camera_gpio_num_info *gpio_num_info = NULL;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700823
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700824 CAM_DBG(CAM_SENSOR, "Enter");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700825 if (!ctrl) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700826 CAM_ERR(CAM_SENSOR, "Invalid ctrl handle");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700827 return -EINVAL;
828 }
829
Alok Pandey01b1b352017-06-25 20:38:54 +0530830 gpio_num_info = ctrl->gpio_num_info;
831 num_vreg = soc_info->num_rgltr;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700832
Alok Pandey01b1b352017-06-25 20:38:54 +0530833 if ((num_vreg == 0) || (num_vreg > CAM_SOC_MAX_REGULATOR)) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700834 CAM_ERR(CAM_SENSOR, "Regulators are not initialized");
Alok Pandey01b1b352017-06-25 20:38:54 +0530835 return -EINVAL;
836 }
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700837
838 ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev);
839 if (ret < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700840 CAM_ERR(CAM_SENSOR, "Initialization of pinctrl failed");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700841 ctrl->cam_pinctrl_status = 0;
842 } else {
843 ctrl->cam_pinctrl_status = 1;
844 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530845
846 rc = cam_sensor_util_request_gpio_table(soc_info, 1);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700847 if (rc < 0)
848 no_gpio = rc;
Alok Pandey01b1b352017-06-25 20:38:54 +0530849
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700850 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 Zalacbb5a382017-07-17 19:06:42 -0700854 CAM_ERR(CAM_SENSOR, "cannot set pin to active state");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700855 }
856
857 for (index = 0; index < ctrl->power_setting_size; index++) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700858 CAM_DBG(CAM_SENSOR, "index: %d", index);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700859 power_setting = &ctrl->power_setting[index];
860
861 switch (power_setting->seq_type) {
862 case SENSOR_MCLK:
Alok Pandey01b1b352017-06-25 20:38:54 +0530863 if (power_setting->seq_val >= soc_info->num_clk) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700864 CAM_ERR(CAM_SENSOR, "clk index %d >= max %u",
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700865 power_setting->seq_val,
Alok Pandey01b1b352017-06-25 20:38:54 +0530866 soc_info->num_clk);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700867 goto power_up_failed;
868 }
869 for (j = 0; j < num_vreg; j++) {
Alok Pandey01b1b352017-06-25 20:38:54 +0530870 if (!strcmp(soc_info->rgltr_name[j],
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700871 "cam_clk")) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700872 CAM_DBG(CAM_SENSOR,
873 "Enable cam_clk: %d", j);
Alok Pandey01b1b352017-06-25 20:38:54 +0530874
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 Zalacbb5a382017-07-17 19:06:42 -0700885 CAM_ERR(CAM_SENSOR,
886 "vreg %s %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530887 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 Thotakura426ec662017-03-15 17:00:29 -0700902 }
903 }
904 if (power_setting->config_val)
Alok Pandey01b1b352017-06-25 20:38:54 +0530905 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 Thotakura426ec662017-03-15 17:00:29 -0700916 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700917 CAM_ERR(CAM_SENSOR, "clk enable failed");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700918 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 Zalacbb5a382017-07-17 19:06:42 -0700926 CAM_ERR(CAM_SENSOR, "request gpio failed");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700927 return no_gpio;
928 }
929 if (power_setting->seq_val >= CAM_VREG_MAX ||
Alok Pandey01b1b352017-06-25 20:38:54 +0530930 !gpio_num_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700931 CAM_ERR(CAM_SENSOR, "gpio index %d >= max %d",
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700932 power_setting->seq_val,
933 CAM_VREG_MAX);
934 goto power_up_failed;
935 }
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700936 CAM_DBG(CAM_SENSOR, "gpio set val %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530937 gpio_num_info->gpio_num
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700938 [power_setting->seq_val]);
939
940 rc = msm_cam_sensor_handle_reg_gpio(
941 power_setting->seq_type,
Alok Pandey01b1b352017-06-25 20:38:54 +0530942 gpio_num_info, 1);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700943 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700944 CAM_ERR(CAM_SENSOR,
945 "Error in handling VREG GPIO");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700946 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 Zalacbb5a382017-07-17 19:06:42 -0700960 CAM_ERR(CAM_SENSOR, "vreg index %d >= max %d",
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700961 power_setting->seq_val,
962 CAM_VREG_MAX);
963 goto power_up_failed;
964 }
Alok Pandey01b1b352017-06-25 20:38:54 +0530965 if (power_setting->seq_val < num_vreg) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700966 CAM_DBG(CAM_SENSOR, "Enable Regulator");
Alok Pandey01b1b352017-06-25 20:38:54 +0530967 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 Zalacbb5a382017-07-17 19:06:42 -0700977 CAM_ERR(CAM_SENSOR, "%s get failed %d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530978 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 Thotakura426ec662017-03-15 17:00:29 -0700995 else
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700996 CAM_ERR(CAM_SENSOR, "usr_idx:%d dts_idx:%d",
Alok Pandey01b1b352017-06-25 20:38:54 +0530997 power_setting->seq_val, num_vreg);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -0700998
999 rc = msm_cam_sensor_handle_reg_gpio(
1000 power_setting->seq_type,
Alok Pandey01b1b352017-06-25 20:38:54 +05301001 gpio_num_info, 1);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001002 if (rc < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001003 CAM_ERR(CAM_SENSOR,
1004 "Error in handling VREG GPIO");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001005 goto power_up_failed;
1006 }
1007 break;
1008 default:
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001009 CAM_ERR(CAM_SENSOR, "error power seq type %d",
1010 power_setting->seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001011 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;
1021power_up_failed:
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001022 CAM_ERR(CAM_SENSOR, "failed");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001023 for (index--; index >= 0; index--) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001024 CAM_DBG(CAM_SENSOR, "index %d", index);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001025 power_setting = &ctrl->power_setting[index];
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001026 CAM_DBG(CAM_SENSOR, "type %d",
Alok Pandey01b1b352017-06-25 20:38:54 +05301027 power_setting->seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001028 switch (power_setting->seq_type) {
1029 case SENSOR_RESET:
1030 case SENSOR_STANDBY:
1031 case SENSOR_CUSTOM_GPIO1:
1032 case SENSOR_CUSTOM_GPIO2:
Alok Pandey01b1b352017-06-25 20:38:54 +05301033 if (!gpio_num_info)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001034 continue;
Alok Pandey01b1b352017-06-25 20:38:54 +05301035 if (!gpio_num_info->valid
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001036 [power_setting->seq_val])
1037 continue;
1038 gpio_set_value_cansleep(
Alok Pandey01b1b352017-06-25 20:38:54 +05301039 gpio_num_info->gpio_num
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001040 [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 Pandey01b1b352017-06-25 20:38:54 +05301049 if (power_setting->seq_val < num_vreg) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001050 CAM_DBG(CAM_SENSOR, "Disable Regulator");
Alok Pandey01b1b352017-06-25 20:38:54 +05301051 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 Thotakura426ec662017-03-15 17:00:29 -07001065 else
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001066 CAM_ERR(CAM_SENSOR, "seq_val:%d > num_vreg: %d",
Alok Pandey01b1b352017-06-25 20:38:54 +05301067 power_setting->seq_val, num_vreg);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001068
1069 msm_cam_sensor_handle_reg_gpio(power_setting->seq_type,
Alok Pandey01b1b352017-06-25 20:38:54 +05301070 gpio_num_info, GPIOF_OUT_INIT_LOW);
1071
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001072 break;
1073 default:
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001074 CAM_ERR(CAM_SENSOR, "error power seq type %d",
1075 power_setting->seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001076 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 Zalacbb5a382017-07-17 19:06:42 -07001089 CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001090 devm_pinctrl_put(ctrl->pinctrl_info.pinctrl);
1091 }
1092 ctrl->cam_pinctrl_status = 0;
Alok Pandey01b1b352017-06-25 20:38:54 +05301093
1094 cam_sensor_util_request_gpio_table(soc_info, 0);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001095
1096 return rc;
1097}
1098
1099static struct cam_sensor_power_setting*
1100msm_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
1120static int cam_config_mclk_reg(struct cam_sensor_power_ctrl_t *ctrl,
Alok Pandey01b1b352017-06-25 20:38:54 +05301121 struct cam_hw_soc_info *soc_info, int32_t index)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001122{
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001123 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 Pandey01b1b352017-06-25 20:38:54 +05301127 num_vreg = soc_info->num_rgltr;
1128
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001129 pd = &ctrl->power_down_setting[index];
1130
1131 for (j = 0; j < num_vreg; j++) {
Alok Pandey01b1b352017-06-25 20:38:54 +05301132 if (!strcmp(soc_info->rgltr_name[j], "cam_clk")) {
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001133
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 Pandey01b1b352017-06-25 20:38:54 +05301144 if (ps != NULL) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001145 CAM_DBG(CAM_SENSOR, "Disable Regulator");
Alok Pandey01b1b352017-06-25 20:38:54 +05301146
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 Thotakura426ec662017-03-15 17:00:29 -07001158 }
1159 }
1160
1161 return rc;
1162}
1163
Alok Pandey01b1b352017-06-25 20:38:54 +05301164int msm_camera_power_down(struct cam_sensor_power_ctrl_t *ctrl,
1165 struct cam_hw_soc_info *soc_info)
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001166{
Alok Pandey01b1b352017-06-25 20:38:54 +05301167 int index = 0, ret = 0, num_vreg = 0, i;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001168 struct cam_sensor_power_setting *pd = NULL;
1169 struct cam_sensor_power_setting *ps;
Alok Pandey01b1b352017-06-25 20:38:54 +05301170 struct msm_camera_gpio_num_info *gpio_num_info = NULL;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001171
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001172 CAM_DBG(CAM_SENSOR, "Enter");
Alok Pandey01b1b352017-06-25 20:38:54 +05301173 if (!ctrl || !soc_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001174 CAM_ERR(CAM_SENSOR, "failed ctrl %pK", ctrl);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001175 return -EINVAL;
1176 }
1177
Alok Pandey01b1b352017-06-25 20:38:54 +05301178 gpio_num_info = ctrl->gpio_num_info;
1179 num_vreg = soc_info->num_rgltr;
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001180
1181 for (index = 0; index < ctrl->power_down_setting_size; index++) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001182 CAM_DBG(CAM_SENSOR, "index %d", index);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001183 pd = &ctrl->power_down_setting[index];
1184 ps = NULL;
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001185 CAM_DBG(CAM_SENSOR, "type %d", pd->seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001186 switch (pd->seq_type) {
1187 case SENSOR_MCLK:
Alok Pandey01b1b352017-06-25 20:38:54 +05301188 ret = cam_config_mclk_reg(ctrl, soc_info, index);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001189 if (ret < 0) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001190 CAM_ERR(CAM_SENSOR,
1191 "config clk reg failed rc: %d", ret);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001192 return ret;
1193 }
Alok Pandey01b1b352017-06-25 20:38:54 +05301194 //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 Thotakura426ec662017-03-15 17:00:29 -07001200 break;
1201 case SENSOR_RESET:
1202 case SENSOR_STANDBY:
1203 case SENSOR_CUSTOM_GPIO1:
1204 case SENSOR_CUSTOM_GPIO2:
Alok Pandey01b1b352017-06-25 20:38:54 +05301205
1206 if (!gpio_num_info->valid[pd->seq_val])
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001207 continue;
Alok Pandey01b1b352017-06-25 20:38:54 +05301208
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001209 gpio_set_value_cansleep(
Alok Pandey01b1b352017-06-25 20:38:54 +05301210 gpio_num_info->gpio_num
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001211 [pd->seq_val],
1212 (int) pd->config_val);
Alok Pandey01b1b352017-06-25 20:38:54 +05301213
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001214 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 Pandey01b1b352017-06-25 20:38:54 +05301224
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001225 ps = msm_camera_get_power_settings(
1226 ctrl, pd->seq_type,
1227 pd->seq_val);
1228 if (ps) {
Alok Pandey01b1b352017-06-25 20:38:54 +05301229 if (pd->seq_val < num_vreg) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001230 CAM_DBG(CAM_SENSOR,
1231 "Disable Regulator");
Alok Pandey01b1b352017-06-25 20:38:54 +05301232 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 Thotakura426ec662017-03-15 17:00:29 -07001243 else
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001244 CAM_ERR(CAM_SENSOR,
1245 "seq_val:%d > num_vreg: %d",
1246 pd->seq_val,
Alok Pandey01b1b352017-06-25 20:38:54 +05301247 num_vreg);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001248 } else
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001249 CAM_ERR(CAM_SENSOR,
1250 "error in power up/down seq");
Alok Pandey01b1b352017-06-25 20:38:54 +05301251
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001252 ret = msm_cam_sensor_handle_reg_gpio(pd->seq_type,
Alok Pandey01b1b352017-06-25 20:38:54 +05301253 gpio_num_info, GPIOF_OUT_INIT_LOW);
1254
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001255 if (ret < 0)
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001256 CAM_ERR(CAM_SENSOR,
1257 "Error disabling VREG GPIO");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001258 break;
1259 default:
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -07001260 CAM_ERR(CAM_SENSOR, "error power seq type %d",
1261 pd->seq_type);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001262 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 Zalacbb5a382017-07-17 19:06:42 -07001275 CAM_ERR(CAM_SENSOR, "cannot set pin to suspend state");
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001276 devm_pinctrl_put(ctrl->pinctrl_info.pinctrl);
1277 }
1278
1279 ctrl->cam_pinctrl_status = 0;
Alok Pandey01b1b352017-06-25 20:38:54 +05301280
1281 cam_sensor_util_request_gpio_table(soc_info, 0);
Viswanadha Raju Thotakura426ec662017-03-15 17:00:29 -07001282
1283 return 0;
1284}
1285