Mounika Reddy Tangirala | 38448ac | 2018-02-08 15:08:11 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 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 | #define pr_fmt(fmt) "%s:%d " fmt, __func__, __LINE__ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include "msm_sd.h" |
| 17 | #include "msm_actuator.h" |
| 18 | #include "msm_cci.h" |
| 19 | |
| 20 | DEFINE_MSM_MUTEX(msm_actuator_mutex); |
| 21 | |
| 22 | #undef CDBG |
| 23 | #ifdef MSM_ACTUATOR_DEBUG |
| 24 | #define CDBG(fmt, args...) pr_err(fmt, ##args) |
| 25 | #else |
| 26 | #define CDBG(fmt, args...) pr_debug(fmt, ##args) |
| 27 | #endif |
| 28 | |
| 29 | #define PARK_LENS_LONG_STEP 7 |
| 30 | #define PARK_LENS_MID_STEP 5 |
| 31 | #define PARK_LENS_SMALL_STEP 3 |
| 32 | #define MAX_QVALUE 4096 |
| 33 | |
frankcheng | 049cc9e | 2020-05-09 20:59:58 +0800 | [diff] [blame^] | 34 | extern int nActuatorAK7374; |
| 35 | extern int nActuatorDW9800; |
| 36 | |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 37 | static struct v4l2_file_operations msm_actuator_v4l2_subdev_fops; |
| 38 | static int32_t msm_actuator_power_up(struct msm_actuator_ctrl_t *a_ctrl); |
| 39 | static int32_t msm_actuator_power_down(struct msm_actuator_ctrl_t *a_ctrl); |
| 40 | |
| 41 | static struct msm_actuator msm_vcm_actuator_table; |
| 42 | static struct msm_actuator msm_piezo_actuator_table; |
| 43 | static struct msm_actuator msm_hvcm_actuator_table; |
| 44 | static struct msm_actuator msm_bivcm_actuator_table; |
| 45 | |
| 46 | static struct i2c_driver msm_actuator_i2c_driver; |
| 47 | static struct msm_actuator *actuators[] = { |
| 48 | &msm_vcm_actuator_table, |
| 49 | &msm_piezo_actuator_table, |
| 50 | &msm_hvcm_actuator_table, |
| 51 | &msm_bivcm_actuator_table, |
| 52 | }; |
| 53 | |
| 54 | static int32_t msm_actuator_piezo_set_default_focus( |
| 55 | struct msm_actuator_ctrl_t *a_ctrl, |
| 56 | struct msm_actuator_move_params_t *move_params) |
| 57 | { |
| 58 | int32_t rc = 0; |
| 59 | struct msm_camera_i2c_reg_setting reg_setting; |
| 60 | |
| 61 | CDBG("Enter\n"); |
| 62 | |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 63 | if (a_ctrl->i2c_reg_tbl == NULL) { |
| 64 | pr_err("failed. i2c reg table is NULL"); |
| 65 | return -EFAULT; |
| 66 | } |
| 67 | |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 68 | if (a_ctrl->curr_step_pos != 0) { |
| 69 | a_ctrl->i2c_tbl_index = 0; |
| 70 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 71 | a_ctrl->initial_code, 0, 0); |
| 72 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 73 | a_ctrl->initial_code, 0, 0); |
| 74 | reg_setting.reg_setting = a_ctrl->i2c_reg_tbl; |
| 75 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 76 | reg_setting.size = a_ctrl->i2c_tbl_index; |
| 77 | rc = a_ctrl->i2c_client.i2c_func_tbl-> |
| 78 | i2c_write_table_w_microdelay( |
| 79 | &a_ctrl->i2c_client, ®_setting); |
| 80 | if (rc < 0) { |
| 81 | pr_err("%s: i2c write error:%d\n", |
| 82 | __func__, rc); |
| 83 | return rc; |
| 84 | } |
| 85 | a_ctrl->i2c_tbl_index = 0; |
| 86 | a_ctrl->curr_step_pos = 0; |
| 87 | } |
| 88 | CDBG("Exit\n"); |
| 89 | return rc; |
| 90 | } |
| 91 | |
| 92 | static void msm_actuator_parse_i2c_params(struct msm_actuator_ctrl_t *a_ctrl, |
| 93 | int16_t next_lens_position, uint32_t hw_params, uint16_t delay) |
| 94 | { |
| 95 | struct msm_actuator_reg_params_t *write_arr = NULL; |
| 96 | uint32_t hw_dword = hw_params; |
| 97 | uint16_t i2c_byte1 = 0, i2c_byte2 = 0; |
| 98 | uint16_t value = 0; |
| 99 | uint32_t size = 0, i = 0; |
| 100 | struct msm_camera_i2c_reg_array *i2c_tbl = NULL; |
| 101 | |
| 102 | CDBG("Enter\n"); |
| 103 | |
| 104 | if (a_ctrl == NULL) { |
| 105 | pr_err("failed. actuator ctrl is NULL"); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (a_ctrl->i2c_reg_tbl == NULL) { |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 110 | pr_err("failed. i2c reg table is NULL"); |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | |
| 114 | size = a_ctrl->reg_tbl_size; |
| 115 | write_arr = a_ctrl->reg_tbl; |
| 116 | i2c_tbl = a_ctrl->i2c_reg_tbl; |
| 117 | |
| 118 | for (i = 0; i < size; i++) { |
| 119 | if (write_arr[i].reg_write_type == MSM_ACTUATOR_WRITE_DAC) { |
| 120 | value = (next_lens_position << |
| 121 | write_arr[i].data_shift) | |
| 122 | ((hw_dword & write_arr[i].hw_mask) >> |
| 123 | write_arr[i].hw_shift); |
frankcheng | 049cc9e | 2020-05-09 20:59:58 +0800 | [diff] [blame^] | 124 | //[Camera] Modify for IMX363 module AF Person Liu 20190509 S |
| 125 | //[Camera] Modify for IMX363 module AF Frank Cheng 20191225 S |
| 126 | //[Camera] Modify for S5KGM1SP module AF Frank Cheng 20200427 S |
| 127 | /* |
| 128 | pr_err("%s:%d nActuatorAK7374: %d\n", |
| 129 | __func__, __LINE__, |
| 130 | nActuatorAK7374); |
| 131 | pr_err("%s:%d nActuatorDW9800: %d\n", |
| 132 | __func__, __LINE__, |
| 133 | nActuatorDW9800); |
| 134 | */ |
| 135 | if(nActuatorAK7374 == 0 && nActuatorDW9800 == 0)value = abs(1023-value); |
| 136 | //[Camera] Modify for S5KGM1SP module AF Frank Cheng 20200427 E |
| 137 | //[Camera] Modify for IMX363 module AF Frank Cheng 20191225 E |
| 138 | //[Camera] Modify for IMX363 module AF Person Liu 20190509 E |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 139 | if (write_arr[i].reg_addr != 0xFFFF) { |
| 140 | i2c_byte1 = write_arr[i].reg_addr; |
| 141 | i2c_byte2 = value; |
| 142 | if (size != (i+1)) { |
| 143 | i2c_byte2 = value & 0xFF; |
| 144 | CDBG("byte1:0x%x, byte2:0x%x\n", |
| 145 | i2c_byte1, i2c_byte2); |
| 146 | if (a_ctrl->i2c_tbl_index > |
| 147 | a_ctrl->total_steps) { |
| 148 | pr_err("failed:i2c table index out of bound\n"); |
| 149 | break; |
| 150 | } |
| 151 | i2c_tbl[a_ctrl->i2c_tbl_index]. |
| 152 | reg_addr = i2c_byte1; |
| 153 | i2c_tbl[a_ctrl->i2c_tbl_index]. |
| 154 | reg_data = i2c_byte2; |
| 155 | i2c_tbl[a_ctrl->i2c_tbl_index]. |
| 156 | delay = 0; |
| 157 | a_ctrl->i2c_tbl_index++; |
| 158 | i++; |
| 159 | i2c_byte1 = write_arr[i].reg_addr; |
| 160 | i2c_byte2 = (value & 0xFF00) >> 8; |
| 161 | } |
| 162 | } else { |
| 163 | i2c_byte1 = (value & 0xFF00) >> 8; |
| 164 | i2c_byte2 = value & 0xFF; |
| 165 | } |
| 166 | } else { |
| 167 | i2c_byte1 = write_arr[i].reg_addr; |
| 168 | i2c_byte2 = (hw_dword & write_arr[i].hw_mask) >> |
| 169 | write_arr[i].hw_shift; |
| 170 | } |
| 171 | if (a_ctrl->i2c_tbl_index > a_ctrl->total_steps) { |
| 172 | pr_err("failed: i2c table index out of bound\n"); |
| 173 | break; |
| 174 | } |
| 175 | CDBG("i2c_byte1:0x%x, i2c_byte2:0x%x\n", i2c_byte1, i2c_byte2); |
| 176 | i2c_tbl[a_ctrl->i2c_tbl_index].reg_addr = i2c_byte1; |
| 177 | i2c_tbl[a_ctrl->i2c_tbl_index].reg_data = i2c_byte2; |
| 178 | i2c_tbl[a_ctrl->i2c_tbl_index].delay = delay; |
| 179 | a_ctrl->i2c_tbl_index++; |
| 180 | } |
| 181 | CDBG("Exit\n"); |
| 182 | } |
| 183 | |
| 184 | static int msm_actuator_bivcm_handle_i2c_ops( |
| 185 | struct msm_actuator_ctrl_t *a_ctrl, |
| 186 | int16_t next_lens_position, uint32_t hw_params, uint16_t delay) |
| 187 | { |
| 188 | struct msm_actuator_reg_params_t *write_arr = a_ctrl->reg_tbl; |
| 189 | uint32_t hw_dword = hw_params; |
| 190 | uint16_t i2c_byte1 = 0, i2c_byte2 = 0; |
| 191 | uint16_t value = 0, reg_data = 0; |
| 192 | uint32_t size = a_ctrl->reg_tbl_size, i = 0; |
| 193 | int32_t rc = 0; |
| 194 | struct msm_camera_i2c_reg_array i2c_tbl; |
| 195 | struct msm_camera_i2c_reg_setting reg_setting; |
| 196 | enum msm_camera_i2c_reg_addr_type save_addr_type = |
| 197 | a_ctrl->i2c_client.addr_type; |
| 198 | |
| 199 | for (i = 0; i < size; i++) { |
| 200 | reg_setting.size = 1; |
| 201 | switch (write_arr[i].reg_write_type) { |
| 202 | case MSM_ACTUATOR_WRITE_DAC: |
| 203 | value = (next_lens_position << |
| 204 | write_arr[i].data_shift) | |
| 205 | ((hw_dword & write_arr[i].hw_mask) >> |
| 206 | write_arr[i].hw_shift); |
| 207 | if (write_arr[i].reg_addr != 0xFFFF) { |
| 208 | i2c_byte1 = write_arr[i].reg_addr; |
| 209 | i2c_byte2 = value; |
| 210 | } else { |
| 211 | i2c_byte1 = (value & 0xFF00) >> 8; |
| 212 | i2c_byte2 = value & 0xFF; |
| 213 | } |
| 214 | i2c_tbl.reg_addr = i2c_byte1; |
| 215 | i2c_tbl.reg_data = i2c_byte2; |
| 216 | i2c_tbl.delay = delay; |
| 217 | a_ctrl->i2c_tbl_index++; |
| 218 | |
| 219 | reg_setting.reg_setting = &i2c_tbl; |
| 220 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 221 | rc = a_ctrl->i2c_client. |
| 222 | i2c_func_tbl->i2c_write_table_w_microdelay( |
| 223 | &a_ctrl->i2c_client, ®_setting); |
| 224 | if (rc < 0) { |
| 225 | pr_err("i2c write error:%d\n", rc); |
| 226 | return rc; |
| 227 | } |
| 228 | break; |
| 229 | case MSM_ACTUATOR_WRITE: |
| 230 | i2c_tbl.reg_data = write_arr[i].reg_data; |
| 231 | i2c_tbl.reg_addr = write_arr[i].reg_addr; |
| 232 | i2c_tbl.delay = write_arr[i].delay; |
| 233 | reg_setting.reg_setting = &i2c_tbl; |
| 234 | reg_setting.data_type = write_arr[i].data_type; |
| 235 | switch (write_arr[i].addr_type) { |
| 236 | case MSM_ACTUATOR_BYTE_ADDR: |
| 237 | a_ctrl->i2c_client.addr_type = |
| 238 | MSM_CAMERA_I2C_BYTE_ADDR; |
| 239 | break; |
| 240 | case MSM_ACTUATOR_WORD_ADDR: |
| 241 | a_ctrl->i2c_client.addr_type = |
| 242 | MSM_CAMERA_I2C_WORD_ADDR; |
| 243 | break; |
| 244 | default: |
| 245 | pr_err("Unsupport addr type: %d\n", |
| 246 | write_arr[i].addr_type); |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | rc = a_ctrl->i2c_client. |
| 251 | i2c_func_tbl->i2c_write_table_w_microdelay( |
| 252 | &a_ctrl->i2c_client, ®_setting); |
| 253 | if (rc < 0) { |
| 254 | pr_err("i2c write error:%d\n", rc); |
| 255 | return rc; |
| 256 | } |
| 257 | break; |
| 258 | case MSM_ACTUATOR_WRITE_DIR_REG: |
| 259 | i2c_tbl.reg_data = hw_dword & 0xFFFF; |
| 260 | i2c_tbl.reg_addr = write_arr[i].reg_addr; |
| 261 | i2c_tbl.delay = write_arr[i].delay; |
| 262 | reg_setting.reg_setting = &i2c_tbl; |
| 263 | reg_setting.data_type = write_arr[i].data_type; |
| 264 | switch (write_arr[i].addr_type) { |
| 265 | case MSM_ACTUATOR_BYTE_ADDR: |
| 266 | a_ctrl->i2c_client.addr_type = |
| 267 | MSM_CAMERA_I2C_BYTE_ADDR; |
| 268 | break; |
| 269 | case MSM_ACTUATOR_WORD_ADDR: |
| 270 | a_ctrl->i2c_client.addr_type = |
| 271 | MSM_CAMERA_I2C_WORD_ADDR; |
| 272 | break; |
| 273 | default: |
| 274 | pr_err("Unsupport addr type: %d\n", |
| 275 | write_arr[i].addr_type); |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | rc = a_ctrl->i2c_client. |
| 280 | i2c_func_tbl->i2c_write_table_w_microdelay( |
| 281 | &a_ctrl->i2c_client, ®_setting); |
| 282 | if (rc < 0) { |
| 283 | pr_err("i2c write error:%d\n", rc); |
| 284 | return rc; |
| 285 | } |
| 286 | break; |
| 287 | case MSM_ACTUATOR_POLL: |
| 288 | switch (write_arr[i].addr_type) { |
| 289 | case MSM_ACTUATOR_BYTE_ADDR: |
| 290 | a_ctrl->i2c_client.addr_type = |
| 291 | MSM_CAMERA_I2C_BYTE_ADDR; |
| 292 | break; |
| 293 | case MSM_ACTUATOR_WORD_ADDR: |
| 294 | a_ctrl->i2c_client.addr_type = |
| 295 | MSM_CAMERA_I2C_WORD_ADDR; |
| 296 | break; |
| 297 | default: |
| 298 | pr_err("Unsupport addr type: %d\n", |
| 299 | write_arr[i].addr_type); |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_poll( |
| 304 | &a_ctrl->i2c_client, |
| 305 | write_arr[i].reg_addr, |
| 306 | write_arr[i].reg_data, |
| 307 | write_arr[i].data_type, |
| 308 | write_arr[i].delay); |
| 309 | if (rc < 0) { |
| 310 | pr_err("i2c poll error:%d\n", rc); |
| 311 | return rc; |
| 312 | } |
| 313 | break; |
| 314 | case MSM_ACTUATOR_READ_WRITE: |
| 315 | i2c_tbl.reg_addr = write_arr[i].reg_addr; |
| 316 | i2c_tbl.delay = write_arr[i].delay; |
| 317 | reg_setting.reg_setting = &i2c_tbl; |
| 318 | reg_setting.data_type = write_arr[i].data_type; |
| 319 | |
| 320 | switch (write_arr[i].addr_type) { |
| 321 | case MSM_ACTUATOR_BYTE_ADDR: |
| 322 | a_ctrl->i2c_client.addr_type = |
| 323 | MSM_CAMERA_I2C_BYTE_ADDR; |
| 324 | break; |
| 325 | case MSM_ACTUATOR_WORD_ADDR: |
| 326 | a_ctrl->i2c_client.addr_type = |
| 327 | MSM_CAMERA_I2C_WORD_ADDR; |
| 328 | break; |
| 329 | default: |
| 330 | pr_err("Unsupport addr type: %d\n", |
| 331 | write_arr[i].addr_type); |
| 332 | break; |
| 333 | } |
| 334 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_read( |
| 335 | &a_ctrl->i2c_client, |
| 336 | write_arr[i].reg_addr, |
| 337 | ®_data, |
| 338 | write_arr[i].data_type); |
| 339 | if (rc < 0) { |
| 340 | pr_err("i2c poll error:%d\n", rc); |
| 341 | return rc; |
| 342 | } |
| 343 | |
| 344 | i2c_tbl.reg_addr = write_arr[i].reg_data; |
| 345 | i2c_tbl.reg_data = reg_data; |
| 346 | i2c_tbl.delay = write_arr[i].delay; |
| 347 | reg_setting.reg_setting = &i2c_tbl; |
| 348 | reg_setting.data_type = write_arr[i].data_type; |
| 349 | |
| 350 | rc = a_ctrl->i2c_client. |
| 351 | i2c_func_tbl->i2c_write_table_w_microdelay( |
| 352 | &a_ctrl->i2c_client, ®_setting); |
| 353 | if (rc < 0) { |
| 354 | pr_err("i2c write error:%d\n", rc); |
| 355 | return rc; |
| 356 | } |
| 357 | break; |
| 358 | case MSM_ACTUATOR_WRITE_HW_DAMP: |
| 359 | i2c_tbl.reg_addr = write_arr[i].reg_addr; |
| 360 | i2c_tbl.reg_data = (hw_dword & write_arr[i].hw_mask) >> |
| 361 | write_arr[i].hw_shift; |
| 362 | i2c_tbl.delay = 0; |
| 363 | reg_setting.reg_setting = &i2c_tbl; |
| 364 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 365 | |
| 366 | rc = a_ctrl->i2c_client. |
| 367 | i2c_func_tbl->i2c_write_table_w_microdelay( |
| 368 | &a_ctrl->i2c_client, ®_setting); |
| 369 | if (rc < 0) { |
| 370 | pr_err("i2c write error:%d\n", rc); |
| 371 | return rc; |
| 372 | } |
| 373 | break; |
| 374 | default: |
| 375 | pr_err("%s:%d Invalid selection\n", |
| 376 | __func__, __LINE__); |
| 377 | return -EINVAL; |
| 378 | } |
| 379 | a_ctrl->i2c_client.addr_type = save_addr_type; |
| 380 | } |
| 381 | CDBG("Exit\n"); |
| 382 | return rc; |
| 383 | } |
| 384 | |
| 385 | static int32_t msm_actuator_init_focus(struct msm_actuator_ctrl_t *a_ctrl, |
| 386 | uint16_t size, struct reg_settings_t *settings) |
| 387 | { |
| 388 | int32_t rc = -EFAULT; |
| 389 | int32_t i = 0; |
| 390 | enum msm_camera_i2c_reg_addr_type save_addr_type; |
| 391 | |
| 392 | CDBG("Enter\n"); |
| 393 | |
| 394 | save_addr_type = a_ctrl->i2c_client.addr_type; |
| 395 | for (i = 0; i < size; i++) { |
| 396 | |
| 397 | switch (settings[i].addr_type) { |
| 398 | case MSM_CAMERA_I2C_BYTE_ADDR: |
| 399 | a_ctrl->i2c_client.addr_type = MSM_CAMERA_I2C_BYTE_ADDR; |
| 400 | break; |
| 401 | case MSM_CAMERA_I2C_WORD_ADDR: |
| 402 | a_ctrl->i2c_client.addr_type = MSM_CAMERA_I2C_WORD_ADDR; |
| 403 | break; |
| 404 | default: |
| 405 | pr_err("Unsupport addr type: %d\n", |
| 406 | settings[i].addr_type); |
| 407 | break; |
| 408 | } |
| 409 | |
| 410 | switch (settings[i].i2c_operation) { |
| 411 | case MSM_ACT_WRITE: |
| 412 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_write( |
| 413 | &a_ctrl->i2c_client, |
| 414 | settings[i].reg_addr, |
| 415 | settings[i].reg_data, |
| 416 | settings[i].data_type); |
| 417 | if (settings[i].delay > 20) |
| 418 | msleep(settings[i].delay); |
| 419 | else if (settings[i].delay != 0) |
| 420 | usleep_range(settings[i].delay * 1000, |
| 421 | (settings[i].delay * 1000) + 1000); |
| 422 | break; |
| 423 | case MSM_ACT_POLL: |
| 424 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_poll( |
| 425 | &a_ctrl->i2c_client, |
| 426 | settings[i].reg_addr, |
| 427 | settings[i].reg_data, |
| 428 | settings[i].data_type, |
| 429 | settings[i].delay); |
| 430 | break; |
| 431 | default: |
| 432 | pr_err("Unsupport i2c_operation: %d\n", |
| 433 | settings[i].i2c_operation); |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | if (rc < 0) { |
| 438 | pr_err("%s:%d fail addr = 0X%X, data = 0X%X, dt = %d", |
| 439 | __func__, __LINE__, settings[i].reg_addr, |
| 440 | settings[i].reg_data, settings[i].data_type); |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | a_ctrl->curr_step_pos = 0; |
| 446 | /* |
| 447 | * Recover register addr_type after the init |
| 448 | * settings are written. |
| 449 | */ |
| 450 | a_ctrl->i2c_client.addr_type = save_addr_type; |
| 451 | CDBG("Exit\n"); |
| 452 | return rc; |
| 453 | } |
| 454 | |
| 455 | static void msm_actuator_write_focus( |
| 456 | struct msm_actuator_ctrl_t *a_ctrl, |
| 457 | uint16_t curr_lens_pos, |
| 458 | struct damping_params_t *damping_params, |
| 459 | int8_t sign_direction, |
| 460 | int16_t code_boundary) |
| 461 | { |
| 462 | int16_t next_lens_pos = 0; |
| 463 | uint16_t damping_code_step = 0; |
| 464 | uint16_t wait_time = 0; |
| 465 | |
| 466 | CDBG("Enter\n"); |
| 467 | |
| 468 | damping_code_step = damping_params->damping_step; |
| 469 | wait_time = damping_params->damping_delay; |
| 470 | |
| 471 | /* Write code based on damping_code_step in a loop */ |
| 472 | for (next_lens_pos = |
| 473 | curr_lens_pos + (sign_direction * damping_code_step); |
| 474 | (sign_direction * next_lens_pos) <= |
| 475 | (sign_direction * code_boundary); |
| 476 | next_lens_pos = |
| 477 | (next_lens_pos + |
| 478 | (sign_direction * damping_code_step))) { |
| 479 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 480 | next_lens_pos, damping_params->hw_params, wait_time); |
| 481 | curr_lens_pos = next_lens_pos; |
| 482 | } |
| 483 | |
| 484 | if (curr_lens_pos != code_boundary) { |
| 485 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 486 | code_boundary, damping_params->hw_params, wait_time); |
| 487 | } |
| 488 | CDBG("Exit\n"); |
| 489 | } |
| 490 | |
| 491 | static int msm_actuator_bivcm_write_focus( |
| 492 | struct msm_actuator_ctrl_t *a_ctrl, |
| 493 | uint16_t curr_lens_pos, |
| 494 | struct damping_params_t *damping_params, |
| 495 | int8_t sign_direction, |
| 496 | int16_t code_boundary) |
| 497 | { |
| 498 | int16_t next_lens_pos = 0; |
| 499 | uint16_t damping_code_step = 0; |
| 500 | uint16_t wait_time = 0; |
| 501 | int32_t rc = 0; |
| 502 | |
| 503 | CDBG("Enter\n"); |
| 504 | |
| 505 | damping_code_step = damping_params->damping_step; |
| 506 | wait_time = damping_params->damping_delay; |
| 507 | |
| 508 | /* Write code based on damping_code_step in a loop */ |
| 509 | for (next_lens_pos = |
| 510 | curr_lens_pos + (sign_direction * damping_code_step); |
| 511 | (sign_direction * next_lens_pos) <= |
| 512 | (sign_direction * code_boundary); |
| 513 | next_lens_pos = |
| 514 | (next_lens_pos + |
| 515 | (sign_direction * damping_code_step))) { |
| 516 | rc = msm_actuator_bivcm_handle_i2c_ops(a_ctrl, |
| 517 | next_lens_pos, damping_params->hw_params, wait_time); |
| 518 | if (rc < 0) { |
| 519 | pr_err("%s:%d msm_actuator_bivcm_handle_i2c_ops failed\n", |
| 520 | __func__, __LINE__); |
| 521 | return rc; |
| 522 | } |
| 523 | curr_lens_pos = next_lens_pos; |
| 524 | } |
| 525 | |
| 526 | if (curr_lens_pos != code_boundary) { |
| 527 | rc = msm_actuator_bivcm_handle_i2c_ops(a_ctrl, |
| 528 | code_boundary, damping_params->hw_params, wait_time); |
| 529 | if (rc < 0) { |
| 530 | pr_err("%s:%d msm_actuator_bivcm_handle_i2c_ops failed\n", |
| 531 | __func__, __LINE__); |
| 532 | return rc; |
| 533 | } |
| 534 | } |
| 535 | CDBG("Exit\n"); |
| 536 | return rc; |
| 537 | } |
| 538 | |
| 539 | static int32_t msm_actuator_piezo_move_focus( |
| 540 | struct msm_actuator_ctrl_t *a_ctrl, |
| 541 | struct msm_actuator_move_params_t *move_params) |
| 542 | { |
| 543 | int32_t dest_step_position = move_params->dest_step_pos; |
| 544 | struct damping_params_t ringing_params_kernel; |
| 545 | int32_t rc = 0; |
| 546 | int32_t num_steps = move_params->num_steps; |
| 547 | struct msm_camera_i2c_reg_setting reg_setting; |
| 548 | |
| 549 | CDBG("Enter\n"); |
| 550 | |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 551 | if (a_ctrl->i2c_reg_tbl == NULL) { |
| 552 | pr_err("failed. i2c reg table is NULL"); |
| 553 | return -EFAULT; |
| 554 | } |
| 555 | |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 556 | if (copy_from_user(&ringing_params_kernel, |
| 557 | &(move_params->ringing_params[0]), |
| 558 | sizeof(struct damping_params_t))) { |
| 559 | pr_err("copy_from_user failed\n"); |
| 560 | return -EFAULT; |
| 561 | } |
| 562 | |
| 563 | if (num_steps <= 0 || num_steps > MAX_NUMBER_OF_STEPS) { |
| 564 | pr_err("num_steps out of range = %d\n", |
| 565 | num_steps); |
| 566 | return -EFAULT; |
| 567 | } |
| 568 | |
| 569 | if (dest_step_position > a_ctrl->total_steps) { |
| 570 | pr_err("Step pos greater than total steps = %d\n", |
| 571 | dest_step_position); |
| 572 | return -EFAULT; |
| 573 | } |
| 574 | |
| 575 | a_ctrl->i2c_tbl_index = 0; |
| 576 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 577 | (num_steps * |
| 578 | a_ctrl->region_params[0].code_per_step), |
| 579 | ringing_params_kernel.hw_params, 0); |
| 580 | |
| 581 | reg_setting.reg_setting = a_ctrl->i2c_reg_tbl; |
| 582 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 583 | reg_setting.size = a_ctrl->i2c_tbl_index; |
| 584 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_write_table_w_microdelay( |
| 585 | &a_ctrl->i2c_client, ®_setting); |
| 586 | if (rc < 0) { |
| 587 | pr_err("i2c write error:%d\n", rc); |
| 588 | return rc; |
| 589 | } |
| 590 | a_ctrl->i2c_tbl_index = 0; |
| 591 | a_ctrl->curr_step_pos = dest_step_position; |
| 592 | CDBG("Exit\n"); |
| 593 | return rc; |
| 594 | } |
| 595 | |
| 596 | static int32_t msm_actuator_move_focus( |
| 597 | struct msm_actuator_ctrl_t *a_ctrl, |
| 598 | struct msm_actuator_move_params_t *move_params) |
| 599 | { |
| 600 | int32_t rc = 0; |
| 601 | struct damping_params_t *ringing_params_kernel = NULL; |
| 602 | int8_t sign_dir = move_params->sign_dir; |
| 603 | uint16_t step_boundary = 0; |
| 604 | uint16_t target_step_pos = 0; |
| 605 | uint16_t target_lens_pos = 0; |
| 606 | int16_t dest_step_pos = move_params->dest_step_pos; |
| 607 | uint16_t curr_lens_pos = 0; |
| 608 | int dir = move_params->dir; |
| 609 | int32_t num_steps = move_params->num_steps; |
| 610 | struct msm_camera_i2c_reg_setting reg_setting; |
| 611 | |
| 612 | CDBG("called, dir %d, num_steps %d\n", dir, num_steps); |
| 613 | |
| 614 | if ((dest_step_pos == a_ctrl->curr_step_pos) || |
| 615 | ((dest_step_pos <= a_ctrl->total_steps) && |
| 616 | (a_ctrl->step_position_table[dest_step_pos] == |
| 617 | a_ctrl->step_position_table[a_ctrl->curr_step_pos]))) |
| 618 | return rc; |
| 619 | |
| 620 | if ((sign_dir > MSM_ACTUATOR_MOVE_SIGNED_NEAR) || |
| 621 | (sign_dir < MSM_ACTUATOR_MOVE_SIGNED_FAR)) { |
| 622 | pr_err("Invalid sign_dir = %d\n", sign_dir); |
| 623 | return -EFAULT; |
| 624 | } |
| 625 | if ((dir > MOVE_FAR) || (dir < MOVE_NEAR)) { |
| 626 | pr_err("Invalid direction = %d\n", dir); |
| 627 | return -EFAULT; |
| 628 | } |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 629 | if (a_ctrl->i2c_reg_tbl == NULL) { |
| 630 | pr_err("failed. i2c reg table is NULL"); |
| 631 | return -EFAULT; |
| 632 | } |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 633 | if (dest_step_pos > a_ctrl->total_steps) { |
| 634 | pr_err("Step pos greater than total steps = %d\n", |
| 635 | dest_step_pos); |
| 636 | return -EFAULT; |
| 637 | } |
| 638 | if ((a_ctrl->region_size <= 0) || |
| 639 | (a_ctrl->region_size > MAX_ACTUATOR_REGION) || |
| 640 | (!move_params->ringing_params)) { |
| 641 | pr_err("Invalid-region size = %d, ringing_params = %pK\n", |
| 642 | a_ctrl->region_size, move_params->ringing_params); |
| 643 | return -EFAULT; |
| 644 | } |
| 645 | /*Allocate memory for damping parameters of all regions*/ |
| 646 | ringing_params_kernel = kmalloc( |
| 647 | sizeof(struct damping_params_t)*(a_ctrl->region_size), |
| 648 | GFP_KERNEL); |
| 649 | if (!ringing_params_kernel) { |
| 650 | pr_err("kmalloc for damping parameters failed\n"); |
| 651 | return -EFAULT; |
| 652 | } |
| 653 | if (copy_from_user(ringing_params_kernel, |
| 654 | &(move_params->ringing_params[0]), |
| 655 | (sizeof(struct damping_params_t))*(a_ctrl->region_size))) { |
| 656 | pr_err("copy_from_user failed\n"); |
| 657 | /*Free the allocated memory for damping parameters*/ |
| 658 | kfree(ringing_params_kernel); |
| 659 | return -EFAULT; |
| 660 | } |
| 661 | curr_lens_pos = a_ctrl->step_position_table[a_ctrl->curr_step_pos]; |
| 662 | a_ctrl->i2c_tbl_index = 0; |
| 663 | CDBG("curr_step_pos =%d dest_step_pos =%d curr_lens_pos=%d\n", |
| 664 | a_ctrl->curr_step_pos, dest_step_pos, curr_lens_pos); |
| 665 | |
| 666 | while (a_ctrl->curr_step_pos != dest_step_pos) { |
| 667 | step_boundary = |
| 668 | a_ctrl->region_params[a_ctrl->curr_region_index]. |
| 669 | step_bound[dir]; |
| 670 | if ((dest_step_pos * sign_dir) <= |
| 671 | (step_boundary * sign_dir)) { |
| 672 | |
| 673 | target_step_pos = dest_step_pos; |
| 674 | target_lens_pos = |
| 675 | a_ctrl->step_position_table[target_step_pos]; |
| 676 | a_ctrl->func_tbl->actuator_write_focus(a_ctrl, |
| 677 | curr_lens_pos, |
| 678 | &ringing_params_kernel |
| 679 | [a_ctrl->curr_region_index], |
| 680 | sign_dir, |
| 681 | target_lens_pos); |
| 682 | curr_lens_pos = target_lens_pos; |
| 683 | |
| 684 | } else { |
| 685 | target_step_pos = step_boundary; |
| 686 | target_lens_pos = |
| 687 | a_ctrl->step_position_table[target_step_pos]; |
| 688 | a_ctrl->func_tbl->actuator_write_focus(a_ctrl, |
| 689 | curr_lens_pos, |
| 690 | &ringing_params_kernel |
| 691 | [a_ctrl->curr_region_index], |
| 692 | sign_dir, |
| 693 | target_lens_pos); |
| 694 | curr_lens_pos = target_lens_pos; |
| 695 | |
| 696 | a_ctrl->curr_region_index += sign_dir; |
| 697 | } |
| 698 | a_ctrl->curr_step_pos = target_step_pos; |
| 699 | } |
| 700 | /*Free the memory allocated for damping parameters*/ |
| 701 | kfree(ringing_params_kernel); |
| 702 | |
| 703 | move_params->curr_lens_pos = curr_lens_pos; |
| 704 | reg_setting.reg_setting = a_ctrl->i2c_reg_tbl; |
| 705 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 706 | reg_setting.size = a_ctrl->i2c_tbl_index; |
| 707 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_write_table_w_microdelay( |
| 708 | &a_ctrl->i2c_client, ®_setting); |
| 709 | if (rc < 0) { |
| 710 | pr_err("i2c write error:%d\n", rc); |
| 711 | return rc; |
| 712 | } |
| 713 | a_ctrl->i2c_tbl_index = 0; |
| 714 | CDBG("Exit\n"); |
| 715 | |
| 716 | return rc; |
| 717 | } |
| 718 | |
| 719 | static int32_t msm_actuator_bivcm_move_focus( |
| 720 | struct msm_actuator_ctrl_t *a_ctrl, |
| 721 | struct msm_actuator_move_params_t *move_params) |
| 722 | { |
| 723 | int32_t rc = 0; |
| 724 | struct damping_params_t *ringing_params_kernel = NULL; |
| 725 | int8_t sign_dir = move_params->sign_dir; |
| 726 | uint16_t step_boundary = 0; |
| 727 | uint16_t target_step_pos = 0; |
| 728 | uint16_t target_lens_pos = 0; |
| 729 | int16_t dest_step_pos = move_params->dest_step_pos; |
| 730 | uint16_t curr_lens_pos = 0; |
| 731 | int dir = move_params->dir; |
| 732 | int32_t num_steps = move_params->num_steps; |
| 733 | |
| 734 | if (a_ctrl->step_position_table == NULL) { |
| 735 | pr_err("Step Position Table is NULL"); |
| 736 | return -EFAULT; |
| 737 | } |
| 738 | |
| 739 | CDBG("called, dir %d, num_steps %d\n", dir, num_steps); |
| 740 | |
| 741 | if (dest_step_pos == a_ctrl->curr_step_pos) |
| 742 | return rc; |
| 743 | |
| 744 | if ((sign_dir > MSM_ACTUATOR_MOVE_SIGNED_NEAR) || |
| 745 | (sign_dir < MSM_ACTUATOR_MOVE_SIGNED_FAR)) { |
| 746 | pr_err("Invalid sign_dir = %d\n", sign_dir); |
| 747 | return -EFAULT; |
| 748 | } |
| 749 | if ((dir > MOVE_FAR) || (dir < MOVE_NEAR)) { |
| 750 | pr_err("Invalid direction = %d\n", dir); |
| 751 | return -EFAULT; |
| 752 | } |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 753 | if (a_ctrl->i2c_reg_tbl == NULL) { |
| 754 | pr_err("failed. i2c reg table is NULL"); |
| 755 | return -EFAULT; |
| 756 | } |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 757 | if (dest_step_pos > a_ctrl->total_steps) { |
| 758 | pr_err("Step pos greater than total steps = %d\n", |
| 759 | dest_step_pos); |
| 760 | return -EFAULT; |
| 761 | } |
| 762 | if ((a_ctrl->region_size <= 0) || |
| 763 | (a_ctrl->region_size > MAX_ACTUATOR_REGION) || |
| 764 | (!move_params->ringing_params)) { |
| 765 | pr_err("Invalid-region size = %d, ringing_params = %pK\n", |
| 766 | a_ctrl->region_size, move_params->ringing_params); |
| 767 | return -EFAULT; |
| 768 | } |
| 769 | /*Allocate memory for damping parameters of all regions*/ |
| 770 | ringing_params_kernel = kmalloc( |
| 771 | sizeof(struct damping_params_t)*(a_ctrl->region_size), |
| 772 | GFP_KERNEL); |
| 773 | if (!ringing_params_kernel) { |
| 774 | pr_err("kmalloc for damping parameters failed\n"); |
| 775 | return -EFAULT; |
| 776 | } |
| 777 | if (copy_from_user(ringing_params_kernel, |
| 778 | &(move_params->ringing_params[0]), |
| 779 | (sizeof(struct damping_params_t))*(a_ctrl->region_size))) { |
| 780 | pr_err("copy_from_user failed\n"); |
| 781 | /*Free the allocated memory for damping parameters*/ |
| 782 | kfree(ringing_params_kernel); |
| 783 | return -EFAULT; |
| 784 | } |
| 785 | curr_lens_pos = a_ctrl->step_position_table[a_ctrl->curr_step_pos]; |
| 786 | a_ctrl->i2c_tbl_index = 0; |
| 787 | CDBG("curr_step_pos =%d dest_step_pos =%d curr_lens_pos=%d\n", |
| 788 | a_ctrl->curr_step_pos, dest_step_pos, curr_lens_pos); |
| 789 | |
| 790 | while (a_ctrl->curr_step_pos != dest_step_pos) { |
| 791 | step_boundary = |
| 792 | a_ctrl->region_params[a_ctrl->curr_region_index]. |
| 793 | step_bound[dir]; |
| 794 | if ((dest_step_pos * sign_dir) <= |
| 795 | (step_boundary * sign_dir)) { |
| 796 | |
| 797 | target_step_pos = dest_step_pos; |
| 798 | target_lens_pos = |
| 799 | a_ctrl->step_position_table[target_step_pos]; |
| 800 | rc = msm_actuator_bivcm_write_focus(a_ctrl, |
| 801 | curr_lens_pos, |
| 802 | &ringing_params_kernel |
| 803 | [a_ctrl->curr_region_index], |
| 804 | sign_dir, |
| 805 | target_lens_pos); |
| 806 | if (rc < 0) { |
| 807 | kfree(ringing_params_kernel); |
| 808 | return rc; |
| 809 | } |
| 810 | curr_lens_pos = target_lens_pos; |
| 811 | } else { |
| 812 | target_step_pos = step_boundary; |
| 813 | target_lens_pos = |
| 814 | a_ctrl->step_position_table[target_step_pos]; |
| 815 | rc = msm_actuator_bivcm_write_focus(a_ctrl, |
| 816 | curr_lens_pos, |
| 817 | &ringing_params_kernel |
| 818 | [a_ctrl->curr_region_index], |
| 819 | sign_dir, |
| 820 | target_lens_pos); |
| 821 | if (rc < 0) { |
| 822 | kfree(ringing_params_kernel); |
| 823 | return rc; |
| 824 | } |
| 825 | curr_lens_pos = target_lens_pos; |
| 826 | |
| 827 | a_ctrl->curr_region_index += sign_dir; |
| 828 | } |
| 829 | a_ctrl->curr_step_pos = target_step_pos; |
| 830 | } |
| 831 | /*Free the memory allocated for damping parameters*/ |
| 832 | kfree(ringing_params_kernel); |
| 833 | |
| 834 | move_params->curr_lens_pos = curr_lens_pos; |
| 835 | a_ctrl->i2c_tbl_index = 0; |
| 836 | CDBG("Exit\n"); |
| 837 | return rc; |
| 838 | } |
| 839 | |
| 840 | static int32_t msm_actuator_park_lens(struct msm_actuator_ctrl_t *a_ctrl) |
| 841 | { |
| 842 | int32_t rc = 0; |
| 843 | uint16_t next_lens_pos = 0; |
| 844 | struct msm_camera_i2c_reg_setting reg_setting; |
| 845 | |
| 846 | a_ctrl->i2c_tbl_index = 0; |
| 847 | if ((a_ctrl->curr_step_pos > a_ctrl->total_steps) || |
| 848 | (!a_ctrl->park_lens.max_step) || |
| 849 | (!a_ctrl->step_position_table) || |
| 850 | (!a_ctrl->i2c_reg_tbl) || |
| 851 | (!a_ctrl->func_tbl) || |
| 852 | (!a_ctrl->func_tbl->actuator_parse_i2c_params)) { |
| 853 | pr_err("%s:%d Failed to park lens.\n", |
| 854 | __func__, __LINE__); |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | if (a_ctrl->park_lens.max_step > a_ctrl->max_code_size) |
| 859 | a_ctrl->park_lens.max_step = a_ctrl->max_code_size; |
| 860 | |
| 861 | next_lens_pos = a_ctrl->step_position_table[a_ctrl->curr_step_pos]; |
| 862 | while (next_lens_pos) { |
| 863 | /* conditions which help to reduce park lens time */ |
| 864 | if (next_lens_pos > (a_ctrl->park_lens.max_step * |
| 865 | PARK_LENS_LONG_STEP)) { |
| 866 | next_lens_pos = next_lens_pos - |
| 867 | (a_ctrl->park_lens.max_step * |
| 868 | PARK_LENS_LONG_STEP); |
| 869 | } else if (next_lens_pos > (a_ctrl->park_lens.max_step * |
| 870 | PARK_LENS_MID_STEP)) { |
| 871 | next_lens_pos = next_lens_pos - |
| 872 | (a_ctrl->park_lens.max_step * |
| 873 | PARK_LENS_MID_STEP); |
| 874 | } else if (next_lens_pos > (a_ctrl->park_lens.max_step * |
| 875 | PARK_LENS_SMALL_STEP)) { |
| 876 | next_lens_pos = next_lens_pos - |
| 877 | (a_ctrl->park_lens.max_step * |
| 878 | PARK_LENS_SMALL_STEP); |
| 879 | } else { |
| 880 | next_lens_pos = (next_lens_pos > |
| 881 | a_ctrl->park_lens.max_step) ? |
| 882 | (next_lens_pos - a_ctrl->park_lens. |
| 883 | max_step) : 0; |
| 884 | } |
| 885 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 886 | next_lens_pos, a_ctrl->park_lens.hw_params, |
| 887 | a_ctrl->park_lens.damping_delay); |
| 888 | |
| 889 | reg_setting.reg_setting = a_ctrl->i2c_reg_tbl; |
| 890 | reg_setting.size = a_ctrl->i2c_tbl_index; |
| 891 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 892 | |
| 893 | rc = a_ctrl->i2c_client.i2c_func_tbl-> |
| 894 | i2c_write_table_w_microdelay( |
| 895 | &a_ctrl->i2c_client, ®_setting); |
| 896 | if (rc < 0) { |
| 897 | pr_err("%s Failed I2C write Line %d\n", |
| 898 | __func__, __LINE__); |
| 899 | return rc; |
| 900 | } |
| 901 | a_ctrl->i2c_tbl_index = 0; |
| 902 | /* Use typical damping time delay to avoid tick sound */ |
| 903 | usleep_range(10000, 12000); |
| 904 | } |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | static int32_t msm_actuator_bivcm_init_step_table( |
| 910 | struct msm_actuator_ctrl_t *a_ctrl, |
| 911 | struct msm_actuator_set_info_t *set_info) |
| 912 | { |
| 913 | int16_t code_per_step = 0; |
| 914 | int16_t cur_code = 0; |
| 915 | uint16_t step_index = 0, region_index = 0; |
| 916 | uint16_t step_boundary = 0; |
| 917 | uint32_t max_code_size = 1; |
| 918 | uint16_t data_size = set_info->actuator_params.data_size; |
| 919 | uint16_t mask = 0, i = 0; |
| 920 | uint32_t qvalue = 0; |
| 921 | |
| 922 | CDBG("Enter\n"); |
| 923 | |
| 924 | for (; data_size > 0; data_size--) { |
| 925 | max_code_size *= 2; |
| 926 | mask |= (1 << i++); |
| 927 | } |
| 928 | |
| 929 | a_ctrl->max_code_size = max_code_size; |
| 930 | kfree(a_ctrl->step_position_table); |
| 931 | a_ctrl->step_position_table = NULL; |
| 932 | |
| 933 | if (set_info->af_tuning_params.total_steps |
| 934 | > MAX_ACTUATOR_AF_TOTAL_STEPS) { |
| 935 | pr_err("Max actuator totalsteps exceeded = %d\n", |
| 936 | set_info->af_tuning_params.total_steps); |
| 937 | return -EFAULT; |
| 938 | } |
| 939 | /* Fill step position table */ |
| 940 | a_ctrl->step_position_table = |
| 941 | kmalloc(sizeof(uint16_t) * |
| 942 | (set_info->af_tuning_params.total_steps + 1), GFP_KERNEL); |
| 943 | |
| 944 | if (a_ctrl->step_position_table == NULL) |
| 945 | return -ENOMEM; |
| 946 | |
| 947 | cur_code = set_info->af_tuning_params.initial_code; |
| 948 | a_ctrl->step_position_table[step_index++] = cur_code; |
| 949 | for (region_index = 0; |
| 950 | region_index < a_ctrl->region_size; |
| 951 | region_index++) { |
| 952 | code_per_step = |
| 953 | a_ctrl->region_params[region_index].code_per_step; |
| 954 | step_boundary = |
| 955 | a_ctrl->region_params[region_index]. |
| 956 | step_bound[MOVE_NEAR]; |
| 957 | if (step_boundary > |
| 958 | set_info->af_tuning_params.total_steps) { |
| 959 | pr_err("invalid step_boundary = %d, max_val = %d", |
| 960 | step_boundary, |
| 961 | set_info->af_tuning_params.total_steps); |
| 962 | kfree(a_ctrl->step_position_table); |
| 963 | a_ctrl->step_position_table = NULL; |
| 964 | return -EINVAL; |
| 965 | } |
| 966 | qvalue = a_ctrl->region_params[region_index].qvalue; |
| 967 | for (; step_index <= step_boundary; |
| 968 | step_index++) { |
| 969 | if (qvalue > 1 && qvalue <= MAX_QVALUE) |
| 970 | cur_code = step_index * code_per_step / qvalue; |
| 971 | else |
| 972 | cur_code = step_index * code_per_step; |
| 973 | cur_code = (set_info->af_tuning_params.initial_code + |
| 974 | cur_code) & mask; |
| 975 | if (cur_code < max_code_size) |
| 976 | a_ctrl->step_position_table[step_index] = |
| 977 | cur_code; |
| 978 | else { |
| 979 | for (; step_index < |
| 980 | set_info->af_tuning_params.total_steps; |
| 981 | step_index++) |
| 982 | a_ctrl-> |
| 983 | step_position_table[ |
| 984 | step_index] = |
| 985 | max_code_size; |
| 986 | } |
| 987 | CDBG("step_position_table[%d] = %d\n", step_index, |
| 988 | a_ctrl->step_position_table[step_index]); |
| 989 | } |
| 990 | } |
| 991 | CDBG("Exit\n"); |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | static int32_t msm_actuator_init_step_table(struct msm_actuator_ctrl_t *a_ctrl, |
| 996 | struct msm_actuator_set_info_t *set_info) |
| 997 | { |
| 998 | int16_t code_per_step = 0; |
| 999 | uint32_t qvalue = 0; |
| 1000 | int16_t cur_code = 0; |
| 1001 | uint16_t step_index = 0, region_index = 0; |
| 1002 | uint16_t step_boundary = 0; |
| 1003 | uint32_t max_code_size = 1; |
| 1004 | uint16_t data_size = set_info->actuator_params.data_size; |
| 1005 | |
| 1006 | CDBG("Enter\n"); |
| 1007 | |
| 1008 | /* validate the actuator state */ |
| 1009 | if (a_ctrl->actuator_state != ACT_OPS_ACTIVE) { |
| 1010 | pr_err("%s:%d invalid actuator_state %d\n" |
| 1011 | , __func__, __LINE__, a_ctrl->actuator_state); |
| 1012 | return -EINVAL; |
| 1013 | } |
| 1014 | for (; data_size > 0; data_size--) |
| 1015 | max_code_size *= 2; |
| 1016 | |
| 1017 | a_ctrl->max_code_size = max_code_size; |
| 1018 | |
| 1019 | /* free the step_position_table to allocate a new one */ |
| 1020 | kfree(a_ctrl->step_position_table); |
| 1021 | a_ctrl->step_position_table = NULL; |
| 1022 | |
| 1023 | if (set_info->af_tuning_params.total_steps |
| 1024 | > MAX_ACTUATOR_AF_TOTAL_STEPS) { |
| 1025 | pr_err("Max actuator totalsteps exceeded = %d\n", |
| 1026 | set_info->af_tuning_params.total_steps); |
| 1027 | return -EFAULT; |
| 1028 | } |
| 1029 | /* Fill step position table */ |
| 1030 | a_ctrl->step_position_table = |
| 1031 | kmalloc(sizeof(uint16_t) * |
| 1032 | (set_info->af_tuning_params.total_steps + 1), GFP_KERNEL); |
| 1033 | |
| 1034 | if (a_ctrl->step_position_table == NULL) |
| 1035 | return -ENOMEM; |
| 1036 | |
| 1037 | cur_code = set_info->af_tuning_params.initial_code; |
| 1038 | a_ctrl->step_position_table[step_index++] = cur_code; |
| 1039 | for (region_index = 0; |
| 1040 | region_index < a_ctrl->region_size; |
| 1041 | region_index++) { |
| 1042 | code_per_step = |
| 1043 | a_ctrl->region_params[region_index].code_per_step; |
| 1044 | qvalue = |
| 1045 | a_ctrl->region_params[region_index].qvalue; |
| 1046 | step_boundary = |
| 1047 | a_ctrl->region_params[region_index]. |
| 1048 | step_bound[MOVE_NEAR]; |
| 1049 | if (step_boundary > |
| 1050 | set_info->af_tuning_params.total_steps) { |
| 1051 | pr_err("invalid step_boundary = %d, max_val = %d", |
| 1052 | step_boundary, |
| 1053 | set_info->af_tuning_params.total_steps); |
| 1054 | kfree(a_ctrl->step_position_table); |
| 1055 | a_ctrl->step_position_table = NULL; |
| 1056 | return -EINVAL; |
| 1057 | } |
| 1058 | for (; step_index <= step_boundary; |
| 1059 | step_index++) { |
| 1060 | if (qvalue > 1 && qvalue <= MAX_QVALUE) |
| 1061 | cur_code = step_index * code_per_step / qvalue; |
| 1062 | else |
| 1063 | cur_code = step_index * code_per_step; |
| 1064 | cur_code += set_info->af_tuning_params.initial_code; |
| 1065 | if (cur_code < max_code_size) |
| 1066 | a_ctrl->step_position_table[step_index] = |
| 1067 | cur_code; |
| 1068 | else { |
| 1069 | for (; step_index < |
| 1070 | set_info->af_tuning_params.total_steps; |
| 1071 | step_index++) |
| 1072 | a_ctrl-> |
| 1073 | step_position_table[ |
| 1074 | step_index] = |
| 1075 | max_code_size; |
| 1076 | } |
| 1077 | CDBG("step_position_table[%d] = %d\n", step_index, |
| 1078 | a_ctrl->step_position_table[step_index]); |
| 1079 | } |
| 1080 | } |
| 1081 | CDBG("Exit\n"); |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
| 1085 | static int32_t msm_actuator_set_default_focus( |
| 1086 | struct msm_actuator_ctrl_t *a_ctrl, |
| 1087 | struct msm_actuator_move_params_t *move_params) |
| 1088 | { |
| 1089 | int32_t rc = 0; |
| 1090 | |
| 1091 | CDBG("Enter\n"); |
| 1092 | |
| 1093 | if (a_ctrl->curr_step_pos != 0) |
| 1094 | rc = a_ctrl->func_tbl->actuator_move_focus(a_ctrl, move_params); |
| 1095 | CDBG("Exit\n"); |
| 1096 | return rc; |
| 1097 | } |
| 1098 | |
| 1099 | static int32_t msm_actuator_vreg_control(struct msm_actuator_ctrl_t *a_ctrl, |
| 1100 | int config) |
| 1101 | { |
| 1102 | int rc = 0, i, cnt; |
| 1103 | struct msm_actuator_vreg *vreg_cfg; |
| 1104 | |
| 1105 | vreg_cfg = &a_ctrl->vreg_cfg; |
| 1106 | cnt = vreg_cfg->num_vreg; |
| 1107 | if (!cnt) |
| 1108 | return 0; |
| 1109 | |
| 1110 | if (cnt >= MSM_ACTUATOR_MAX_VREGS) { |
| 1111 | pr_err("%s failed %d cnt %d\n", __func__, __LINE__, cnt); |
| 1112 | return -EINVAL; |
| 1113 | } |
| 1114 | |
| 1115 | for (i = 0; i < cnt; i++) { |
| 1116 | if (a_ctrl->act_device_type == MSM_CAMERA_PLATFORM_DEVICE) { |
| 1117 | rc = msm_camera_config_single_vreg(&(a_ctrl->pdev->dev), |
| 1118 | &vreg_cfg->cam_vreg[i], |
| 1119 | (struct regulator **)&vreg_cfg->data[i], |
| 1120 | config); |
| 1121 | } else if (a_ctrl->act_device_type == |
| 1122 | MSM_CAMERA_I2C_DEVICE) { |
| 1123 | rc = msm_camera_config_single_vreg( |
| 1124 | &(a_ctrl->i2c_client.client->dev), |
| 1125 | &vreg_cfg->cam_vreg[i], |
| 1126 | (struct regulator **)&vreg_cfg->data[i], |
| 1127 | config); |
| 1128 | } |
| 1129 | } |
| 1130 | return rc; |
| 1131 | } |
| 1132 | |
| 1133 | static int32_t msm_actuator_power_down(struct msm_actuator_ctrl_t *a_ctrl) |
| 1134 | { |
| 1135 | int32_t rc = 0; |
| 1136 | enum msm_sensor_power_seq_gpio_t gpio; |
| 1137 | |
| 1138 | CDBG("Enter\n"); |
| 1139 | if (a_ctrl->actuator_state != ACT_DISABLE_STATE) { |
| 1140 | |
| 1141 | if (a_ctrl->func_tbl && a_ctrl->func_tbl->actuator_park_lens) { |
| 1142 | rc = a_ctrl->func_tbl->actuator_park_lens(a_ctrl); |
| 1143 | if (rc < 0) |
| 1144 | pr_err("%s:%d Lens park failed.\n", |
| 1145 | __func__, __LINE__); |
| 1146 | } |
| 1147 | |
| 1148 | rc = msm_actuator_vreg_control(a_ctrl, 0); |
| 1149 | if (rc < 0) { |
| 1150 | pr_err("%s failed %d\n", __func__, __LINE__); |
| 1151 | return rc; |
| 1152 | } |
| 1153 | |
| 1154 | for (gpio = SENSOR_GPIO_AF_PWDM; |
| 1155 | gpio < SENSOR_GPIO_MAX; gpio++) { |
| 1156 | if (a_ctrl->gconf && |
| 1157 | a_ctrl->gconf->gpio_num_info && |
| 1158 | a_ctrl->gconf->gpio_num_info-> |
| 1159 | valid[gpio] == 1) { |
| 1160 | |
| 1161 | gpio_set_value_cansleep( |
| 1162 | a_ctrl->gconf->gpio_num_info-> |
| 1163 | gpio_num[gpio], |
| 1164 | GPIOF_OUT_INIT_LOW); |
| 1165 | |
| 1166 | if (a_ctrl->cam_pinctrl_status) { |
| 1167 | rc = pinctrl_select_state( |
| 1168 | a_ctrl->pinctrl_info.pinctrl, |
| 1169 | a_ctrl->pinctrl_info. |
| 1170 | gpio_state_suspend); |
| 1171 | if (rc < 0) |
| 1172 | pr_err("ERR:%s:%d cannot set pin to suspend state: %d", |
| 1173 | __func__, __LINE__, rc); |
| 1174 | |
| 1175 | devm_pinctrl_put( |
| 1176 | a_ctrl->pinctrl_info.pinctrl); |
| 1177 | } |
| 1178 | a_ctrl->cam_pinctrl_status = 0; |
| 1179 | rc = msm_camera_request_gpio_table( |
| 1180 | a_ctrl->gconf->cam_gpio_req_tbl, |
| 1181 | a_ctrl->gconf->cam_gpio_req_tbl_size, |
| 1182 | 0); |
| 1183 | if (rc < 0) |
| 1184 | pr_err("ERR:%s:Failed in selecting state in actuator power down: %d\n", |
| 1185 | __func__, rc); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | kfree(a_ctrl->step_position_table); |
| 1190 | a_ctrl->step_position_table = NULL; |
| 1191 | kfree(a_ctrl->i2c_reg_tbl); |
| 1192 | a_ctrl->i2c_reg_tbl = NULL; |
| 1193 | a_ctrl->i2c_tbl_index = 0; |
| 1194 | a_ctrl->actuator_state = ACT_OPS_INACTIVE; |
| 1195 | } |
| 1196 | CDBG("Exit\n"); |
| 1197 | return rc; |
| 1198 | } |
| 1199 | |
| 1200 | static int32_t msm_actuator_set_position( |
| 1201 | struct msm_actuator_ctrl_t *a_ctrl, |
| 1202 | struct msm_actuator_set_position_t *set_pos) |
| 1203 | { |
| 1204 | int32_t rc = 0; |
| 1205 | int32_t index; |
| 1206 | uint16_t next_lens_position; |
| 1207 | uint16_t delay; |
| 1208 | uint32_t hw_params = 0; |
| 1209 | struct msm_camera_i2c_reg_setting reg_setting; |
| 1210 | |
| 1211 | CDBG("%s Enter %d\n", __func__, __LINE__); |
| 1212 | if (set_pos->number_of_steps <= 0 || |
| 1213 | set_pos->number_of_steps > MAX_NUMBER_OF_STEPS) { |
| 1214 | pr_err("num_steps out of range = %d\n", |
| 1215 | set_pos->number_of_steps); |
| 1216 | return -EFAULT; |
| 1217 | } |
| 1218 | |
| 1219 | if (!a_ctrl || !a_ctrl->func_tbl || |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 1220 | !a_ctrl->func_tbl->actuator_parse_i2c_params || |
| 1221 | !a_ctrl->i2c_reg_tbl) { |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1222 | pr_err("failed. NULL actuator pointers."); |
| 1223 | return -EFAULT; |
| 1224 | } |
| 1225 | |
| 1226 | if (a_ctrl->actuator_state != ACT_OPS_ACTIVE) { |
| 1227 | pr_err("failed. Invalid actuator state."); |
| 1228 | return -EFAULT; |
| 1229 | } |
| 1230 | |
| 1231 | a_ctrl->i2c_tbl_index = 0; |
| 1232 | hw_params = set_pos->hw_params; |
| 1233 | for (index = 0; index < set_pos->number_of_steps; index++) { |
| 1234 | next_lens_position = set_pos->pos[index]; |
| 1235 | delay = set_pos->delay[index]; |
| 1236 | a_ctrl->func_tbl->actuator_parse_i2c_params(a_ctrl, |
| 1237 | next_lens_position, hw_params, delay); |
| 1238 | |
| 1239 | reg_setting.reg_setting = a_ctrl->i2c_reg_tbl; |
| 1240 | reg_setting.size = a_ctrl->i2c_tbl_index; |
| 1241 | reg_setting.data_type = a_ctrl->i2c_data_type; |
| 1242 | |
| 1243 | rc = a_ctrl->i2c_client.i2c_func_tbl-> |
| 1244 | i2c_write_table_w_microdelay( |
| 1245 | &a_ctrl->i2c_client, ®_setting); |
| 1246 | if (rc < 0) { |
| 1247 | pr_err("%s Failed I2C write Line %d\n", |
| 1248 | __func__, __LINE__); |
| 1249 | return rc; |
| 1250 | } |
| 1251 | a_ctrl->i2c_tbl_index = 0; |
| 1252 | } |
| 1253 | CDBG("%s exit %d\n", __func__, __LINE__); |
| 1254 | return rc; |
| 1255 | } |
| 1256 | |
| 1257 | static int32_t msm_actuator_bivcm_set_position( |
| 1258 | struct msm_actuator_ctrl_t *a_ctrl, |
| 1259 | struct msm_actuator_set_position_t *set_pos) |
| 1260 | { |
| 1261 | int32_t rc = 0; |
| 1262 | int32_t index; |
| 1263 | uint16_t next_lens_position; |
| 1264 | uint16_t delay; |
| 1265 | uint32_t hw_params = 0; |
| 1266 | |
| 1267 | CDBG("%s Enter %d\n", __func__, __LINE__); |
| 1268 | if (set_pos->number_of_steps <= 0 || |
| 1269 | set_pos->number_of_steps > MAX_NUMBER_OF_STEPS) { |
| 1270 | pr_err("num_steps out of range = %d\n", |
| 1271 | set_pos->number_of_steps); |
| 1272 | return -EFAULT; |
| 1273 | } |
| 1274 | |
| 1275 | if (!a_ctrl) { |
| 1276 | pr_err("failed. NULL actuator pointers."); |
| 1277 | return -EFAULT; |
| 1278 | } |
| 1279 | |
| 1280 | if (a_ctrl->actuator_state != ACT_OPS_ACTIVE) { |
| 1281 | pr_err("failed. Invalid actuator state."); |
| 1282 | return -EFAULT; |
| 1283 | } |
| 1284 | |
| 1285 | a_ctrl->i2c_tbl_index = 0; |
| 1286 | hw_params = set_pos->hw_params; |
| 1287 | for (index = 0; index < set_pos->number_of_steps; index++) { |
| 1288 | next_lens_position = set_pos->pos[index]; |
| 1289 | delay = set_pos->delay[index]; |
| 1290 | rc = msm_actuator_bivcm_handle_i2c_ops(a_ctrl, |
| 1291 | next_lens_position, hw_params, delay); |
| 1292 | a_ctrl->i2c_tbl_index = 0; |
| 1293 | } |
| 1294 | CDBG("%s exit %d\n", __func__, __LINE__); |
| 1295 | return rc; |
| 1296 | } |
| 1297 | |
| 1298 | static int32_t msm_actuator_set_param(struct msm_actuator_ctrl_t *a_ctrl, |
| 1299 | struct msm_actuator_set_info_t *set_info) { |
| 1300 | struct reg_settings_t *init_settings = NULL; |
| 1301 | int32_t rc = -EFAULT; |
| 1302 | uint16_t i = 0; |
| 1303 | struct msm_camera_cci_client *cci_client = NULL; |
| 1304 | |
| 1305 | CDBG("Enter\n"); |
| 1306 | |
| 1307 | for (i = 0; i < ARRAY_SIZE(actuators); i++) { |
| 1308 | if (set_info->actuator_params.act_type == |
| 1309 | actuators[i]->act_type) { |
| 1310 | a_ctrl->func_tbl = &actuators[i]->func_tbl; |
| 1311 | rc = 0; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | if (rc < 0) { |
| 1316 | pr_err("Actuator function table not found\n"); |
| 1317 | return rc; |
| 1318 | } |
| 1319 | if (set_info->af_tuning_params.total_steps |
| 1320 | > MAX_ACTUATOR_AF_TOTAL_STEPS) { |
| 1321 | pr_err("Max actuator totalsteps exceeded = %d\n", |
| 1322 | set_info->af_tuning_params.total_steps); |
| 1323 | return -EFAULT; |
| 1324 | } |
| 1325 | if (set_info->af_tuning_params.region_size |
| 1326 | > MAX_ACTUATOR_REGION) { |
| 1327 | pr_err("MAX_ACTUATOR_REGION is exceeded.\n"); |
| 1328 | return -EFAULT; |
| 1329 | } |
| 1330 | |
| 1331 | a_ctrl->region_size = set_info->af_tuning_params.region_size; |
| 1332 | a_ctrl->pwd_step = set_info->af_tuning_params.pwd_step; |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1333 | |
| 1334 | if (copy_from_user(&a_ctrl->region_params, |
| 1335 | (void __user *)set_info->af_tuning_params.region_params, |
| 1336 | a_ctrl->region_size * sizeof(struct region_params_t))) { |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1337 | pr_err("Error copying region_params\n"); |
| 1338 | return -EFAULT; |
| 1339 | } |
| 1340 | if (a_ctrl->act_device_type == MSM_CAMERA_PLATFORM_DEVICE) { |
| 1341 | cci_client = a_ctrl->i2c_client.cci_client; |
| 1342 | cci_client->sid = |
| 1343 | set_info->actuator_params.i2c_addr >> 1; |
| 1344 | cci_client->retries = 3; |
| 1345 | cci_client->id_map = 0; |
| 1346 | cci_client->cci_i2c_master = a_ctrl->cci_master; |
| 1347 | cci_client->i2c_freq_mode = |
| 1348 | set_info->actuator_params.i2c_freq_mode; |
| 1349 | } else { |
| 1350 | a_ctrl->i2c_client.client->addr = |
| 1351 | set_info->actuator_params.i2c_addr; |
| 1352 | } |
| 1353 | |
| 1354 | a_ctrl->i2c_data_type = set_info->actuator_params.i2c_data_type; |
| 1355 | a_ctrl->i2c_client.addr_type = set_info->actuator_params.i2c_addr_type; |
| 1356 | if (set_info->actuator_params.reg_tbl_size <= |
| 1357 | MAX_ACTUATOR_REG_TBL_SIZE) { |
| 1358 | a_ctrl->reg_tbl_size = set_info->actuator_params.reg_tbl_size; |
| 1359 | } else { |
| 1360 | a_ctrl->reg_tbl_size = 0; |
| 1361 | pr_err("MAX_ACTUATOR_REG_TBL_SIZE is exceeded.\n"); |
| 1362 | return -EFAULT; |
| 1363 | } |
| 1364 | |
| 1365 | if ((a_ctrl->actuator_state == ACT_OPS_ACTIVE) && |
| 1366 | (a_ctrl->i2c_reg_tbl != NULL)) { |
| 1367 | kfree(a_ctrl->i2c_reg_tbl); |
| 1368 | } |
| 1369 | a_ctrl->i2c_reg_tbl = NULL; |
| 1370 | a_ctrl->i2c_reg_tbl = |
| 1371 | kmalloc(sizeof(struct msm_camera_i2c_reg_array) * |
| 1372 | (set_info->af_tuning_params.total_steps + 1), GFP_KERNEL); |
| 1373 | if (!a_ctrl->i2c_reg_tbl) { |
| 1374 | pr_err("kmalloc fail\n"); |
| 1375 | return -ENOMEM; |
| 1376 | } |
| 1377 | |
VijayaKumar T M | d91809f | 2018-03-09 16:06:26 +0530 | [diff] [blame] | 1378 | a_ctrl->total_steps = set_info->af_tuning_params.total_steps; |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1379 | if (copy_from_user(&a_ctrl->reg_tbl, |
| 1380 | (void __user *)set_info->actuator_params.reg_tbl_params, |
| 1381 | a_ctrl->reg_tbl_size * |
| 1382 | sizeof(struct msm_actuator_reg_params_t))) { |
| 1383 | kfree(a_ctrl->i2c_reg_tbl); |
| 1384 | a_ctrl->i2c_reg_tbl = NULL; |
| 1385 | return -EFAULT; |
| 1386 | } |
| 1387 | |
| 1388 | if (set_info->actuator_params.init_setting_size && |
| 1389 | set_info->actuator_params.init_setting_size |
| 1390 | <= MAX_ACTUATOR_INIT_SET) { |
| 1391 | if (a_ctrl->func_tbl->actuator_init_focus) { |
| 1392 | init_settings = kmalloc(sizeof(struct reg_settings_t) * |
| 1393 | (set_info->actuator_params.init_setting_size), |
| 1394 | GFP_KERNEL); |
| 1395 | if (init_settings == NULL) { |
| 1396 | kfree(a_ctrl->i2c_reg_tbl); |
| 1397 | a_ctrl->i2c_reg_tbl = NULL; |
| 1398 | pr_err("Error allocating memory for init_settings\n"); |
| 1399 | return -EFAULT; |
| 1400 | } |
| 1401 | if (copy_from_user(init_settings, |
| 1402 | (void __user *) |
| 1403 | set_info->actuator_params.init_settings, |
| 1404 | set_info->actuator_params.init_setting_size * |
| 1405 | sizeof(struct reg_settings_t))) { |
| 1406 | kfree(init_settings); |
| 1407 | kfree(a_ctrl->i2c_reg_tbl); |
| 1408 | a_ctrl->i2c_reg_tbl = NULL; |
| 1409 | pr_err("Error copying init_settings\n"); |
| 1410 | return -EFAULT; |
| 1411 | } |
| 1412 | rc = a_ctrl->func_tbl->actuator_init_focus(a_ctrl, |
| 1413 | set_info->actuator_params.init_setting_size, |
| 1414 | init_settings); |
| 1415 | kfree(init_settings); |
| 1416 | if (rc < 0) { |
| 1417 | kfree(a_ctrl->i2c_reg_tbl); |
| 1418 | a_ctrl->i2c_reg_tbl = NULL; |
| 1419 | pr_err("Error actuator_init_focus\n"); |
| 1420 | return -EFAULT; |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | /* Park lens data */ |
| 1426 | a_ctrl->park_lens = set_info->actuator_params.park_lens; |
| 1427 | a_ctrl->initial_code = set_info->af_tuning_params.initial_code; |
| 1428 | if (a_ctrl->func_tbl->actuator_init_step_table) |
| 1429 | rc = a_ctrl->func_tbl-> |
| 1430 | actuator_init_step_table(a_ctrl, set_info); |
| 1431 | |
| 1432 | a_ctrl->curr_step_pos = 0; |
| 1433 | a_ctrl->curr_region_index = 0; |
| 1434 | CDBG("Exit\n"); |
| 1435 | |
| 1436 | return rc; |
| 1437 | } |
| 1438 | |
| 1439 | static int msm_actuator_init(struct msm_actuator_ctrl_t *a_ctrl) |
| 1440 | { |
| 1441 | int rc = 0; |
| 1442 | |
| 1443 | CDBG("Enter\n"); |
| 1444 | if (!a_ctrl) { |
| 1445 | pr_err("failed\n"); |
| 1446 | return -EINVAL; |
| 1447 | } |
| 1448 | if (a_ctrl->act_device_type == MSM_CAMERA_PLATFORM_DEVICE) { |
| 1449 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_util( |
| 1450 | &a_ctrl->i2c_client, MSM_CCI_INIT); |
| 1451 | if (rc < 0) |
| 1452 | pr_err("cci_init failed\n"); |
| 1453 | } |
| 1454 | a_ctrl->actuator_state = ACT_OPS_ACTIVE; |
| 1455 | CDBG("Exit\n"); |
| 1456 | return rc; |
| 1457 | } |
| 1458 | |
| 1459 | static int32_t msm_actuator_config(struct msm_actuator_ctrl_t *a_ctrl, |
| 1460 | void *argp) |
| 1461 | { |
| 1462 | struct msm_actuator_cfg_data *cdata = |
| 1463 | (struct msm_actuator_cfg_data *)argp; |
| 1464 | int32_t rc = -EINVAL; |
| 1465 | |
| 1466 | mutex_lock(a_ctrl->actuator_mutex); |
| 1467 | CDBG("Enter\n"); |
| 1468 | CDBG("%s type %d\n", __func__, cdata->cfgtype); |
| 1469 | |
| 1470 | if (cdata->cfgtype != CFG_ACTUATOR_INIT && |
| 1471 | cdata->cfgtype != CFG_ACTUATOR_POWERUP && |
| 1472 | a_ctrl->actuator_state == ACT_DISABLE_STATE) { |
| 1473 | pr_err("actuator disabled %d\n", rc); |
| 1474 | mutex_unlock(a_ctrl->actuator_mutex); |
| 1475 | return rc; |
| 1476 | } |
| 1477 | |
| 1478 | switch (cdata->cfgtype) { |
| 1479 | case CFG_ACTUATOR_INIT: |
| 1480 | rc = msm_actuator_init(a_ctrl); |
| 1481 | if (rc < 0) |
| 1482 | pr_err("msm_actuator_init failed %d\n", rc); |
| 1483 | break; |
| 1484 | case CFG_GET_ACTUATOR_INFO: |
| 1485 | cdata->is_af_supported = 1; |
| 1486 | cdata->cfg.cam_name = a_ctrl->cam_name; |
| 1487 | rc = 0; |
| 1488 | break; |
| 1489 | |
| 1490 | case CFG_SET_ACTUATOR_INFO: |
| 1491 | rc = msm_actuator_set_param(a_ctrl, &cdata->cfg.set_info); |
| 1492 | if (rc < 0) |
| 1493 | pr_err("init table failed %d\n", rc); |
| 1494 | break; |
| 1495 | |
| 1496 | case CFG_SET_DEFAULT_FOCUS: |
| 1497 | if (a_ctrl->func_tbl && |
| 1498 | a_ctrl->func_tbl->actuator_set_default_focus) |
| 1499 | rc = a_ctrl->func_tbl->actuator_set_default_focus( |
| 1500 | a_ctrl, &cdata->cfg.move); |
| 1501 | if (rc < 0) |
| 1502 | pr_err("move focus failed %d\n", rc); |
| 1503 | break; |
| 1504 | |
| 1505 | case CFG_MOVE_FOCUS: |
| 1506 | if (a_ctrl->func_tbl && |
| 1507 | a_ctrl->func_tbl->actuator_move_focus) |
| 1508 | rc = a_ctrl->func_tbl->actuator_move_focus(a_ctrl, |
| 1509 | &cdata->cfg.move); |
| 1510 | if (rc < 0) |
| 1511 | pr_err("move focus failed %d\n", rc); |
| 1512 | break; |
| 1513 | case CFG_ACTUATOR_POWERDOWN: |
| 1514 | rc = msm_actuator_power_down(a_ctrl); |
| 1515 | if (rc < 0) |
| 1516 | pr_err("msm_actuator_power_down failed %d\n", rc); |
| 1517 | break; |
| 1518 | |
| 1519 | case CFG_SET_POSITION: |
| 1520 | if (a_ctrl->func_tbl && |
| 1521 | a_ctrl->func_tbl->actuator_set_position) |
| 1522 | rc = a_ctrl->func_tbl->actuator_set_position(a_ctrl, |
| 1523 | &cdata->cfg.setpos); |
| 1524 | if (rc < 0) |
| 1525 | pr_err("actuator_set_position failed %d\n", rc); |
| 1526 | break; |
| 1527 | |
| 1528 | case CFG_ACTUATOR_POWERUP: |
| 1529 | rc = msm_actuator_power_up(a_ctrl); |
| 1530 | if (rc < 0) |
| 1531 | pr_err("Failed actuator power up%d\n", rc); |
| 1532 | break; |
| 1533 | |
| 1534 | default: |
| 1535 | break; |
| 1536 | } |
| 1537 | mutex_unlock(a_ctrl->actuator_mutex); |
| 1538 | CDBG("Exit\n"); |
| 1539 | return rc; |
| 1540 | } |
| 1541 | |
| 1542 | static int32_t msm_actuator_get_subdev_id(struct msm_actuator_ctrl_t *a_ctrl, |
| 1543 | void *arg) |
| 1544 | { |
| 1545 | uint32_t *subdev_id = (uint32_t *)arg; |
| 1546 | |
| 1547 | CDBG("Enter\n"); |
| 1548 | if (!subdev_id) { |
| 1549 | pr_err("failed\n"); |
| 1550 | return -EINVAL; |
| 1551 | } |
| 1552 | if (a_ctrl->act_device_type == MSM_CAMERA_PLATFORM_DEVICE) |
| 1553 | *subdev_id = a_ctrl->pdev->id; |
| 1554 | else |
| 1555 | *subdev_id = a_ctrl->subdev_id; |
| 1556 | |
| 1557 | CDBG("subdev_id %d\n", *subdev_id); |
| 1558 | CDBG("Exit\n"); |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | static struct msm_camera_i2c_fn_t msm_sensor_cci_func_tbl = { |
| 1563 | .i2c_read = msm_camera_cci_i2c_read, |
| 1564 | .i2c_read_seq = msm_camera_cci_i2c_read_seq, |
| 1565 | .i2c_write = msm_camera_cci_i2c_write, |
| 1566 | .i2c_write_table = msm_camera_cci_i2c_write_table, |
| 1567 | .i2c_write_seq_table = msm_camera_cci_i2c_write_seq_table, |
| 1568 | .i2c_write_table_w_microdelay = |
| 1569 | msm_camera_cci_i2c_write_table_w_microdelay, |
| 1570 | .i2c_util = msm_sensor_cci_i2c_util, |
| 1571 | .i2c_poll = msm_camera_cci_i2c_poll, |
| 1572 | }; |
| 1573 | |
| 1574 | static struct msm_camera_i2c_fn_t msm_sensor_qup_func_tbl = { |
| 1575 | .i2c_read = msm_camera_qup_i2c_read, |
| 1576 | .i2c_read_seq = msm_camera_qup_i2c_read_seq, |
| 1577 | .i2c_write = msm_camera_qup_i2c_write, |
| 1578 | .i2c_write_table = msm_camera_qup_i2c_write_table, |
| 1579 | .i2c_write_seq_table = msm_camera_qup_i2c_write_seq_table, |
| 1580 | .i2c_write_table_w_microdelay = |
| 1581 | msm_camera_qup_i2c_write_table_w_microdelay, |
| 1582 | .i2c_poll = msm_camera_qup_i2c_poll, |
| 1583 | }; |
| 1584 | |
| 1585 | static int msm_actuator_close(struct v4l2_subdev *sd, |
| 1586 | struct v4l2_subdev_fh *fh) { |
| 1587 | int rc = 0; |
| 1588 | struct msm_actuator_ctrl_t *a_ctrl = v4l2_get_subdevdata(sd); |
| 1589 | |
| 1590 | CDBG("Enter\n"); |
| 1591 | if (!a_ctrl) { |
| 1592 | pr_err("failed\n"); |
| 1593 | return -EINVAL; |
| 1594 | } |
| 1595 | mutex_lock(a_ctrl->actuator_mutex); |
| 1596 | if (a_ctrl->act_device_type == MSM_CAMERA_PLATFORM_DEVICE && |
| 1597 | a_ctrl->actuator_state != ACT_DISABLE_STATE) { |
| 1598 | rc = a_ctrl->i2c_client.i2c_func_tbl->i2c_util( |
| 1599 | &a_ctrl->i2c_client, MSM_CCI_RELEASE); |
| 1600 | if (rc < 0) |
| 1601 | pr_err("cci_init failed\n"); |
| 1602 | } |
| 1603 | kfree(a_ctrl->i2c_reg_tbl); |
| 1604 | a_ctrl->i2c_reg_tbl = NULL; |
Mounika Reddy Tangirala | 38448ac | 2018-02-08 15:08:11 +0530 | [diff] [blame] | 1605 | if (a_ctrl->actuator_state == ACT_OPS_ACTIVE) { |
| 1606 | rc = msm_actuator_power_down(a_ctrl); |
| 1607 | if (rc < 0) { |
| 1608 | pr_err("%s:%d Actuator Power down failed\n", |
| 1609 | __func__, __LINE__); |
| 1610 | } |
| 1611 | } |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1612 | a_ctrl->actuator_state = ACT_DISABLE_STATE; |
| 1613 | mutex_unlock(a_ctrl->actuator_mutex); |
| 1614 | CDBG("Exit\n"); |
| 1615 | return rc; |
| 1616 | } |
| 1617 | |
| 1618 | static const struct v4l2_subdev_internal_ops msm_actuator_internal_ops = { |
| 1619 | .close = msm_actuator_close, |
| 1620 | }; |
| 1621 | |
| 1622 | static long msm_actuator_subdev_ioctl(struct v4l2_subdev *sd, |
| 1623 | unsigned int cmd, void *arg) |
| 1624 | { |
| 1625 | int rc; |
| 1626 | struct msm_actuator_ctrl_t *a_ctrl = v4l2_get_subdevdata(sd); |
| 1627 | void *argp = (void *)arg; |
| 1628 | |
| 1629 | CDBG("Enter\n"); |
| 1630 | CDBG("%s:%d a_ctrl %pK argp %pK\n", __func__, __LINE__, a_ctrl, argp); |
| 1631 | switch (cmd) { |
| 1632 | case VIDIOC_MSM_SENSOR_GET_SUBDEV_ID: |
| 1633 | return msm_actuator_get_subdev_id(a_ctrl, argp); |
| 1634 | case VIDIOC_MSM_ACTUATOR_CFG: |
| 1635 | return msm_actuator_config(a_ctrl, argp); |
| 1636 | case MSM_SD_NOTIFY_FREEZE: |
| 1637 | return 0; |
| 1638 | case MSM_SD_UNNOTIFY_FREEZE: |
| 1639 | return 0; |
| 1640 | case MSM_SD_SHUTDOWN: |
| 1641 | if (!a_ctrl->i2c_client.i2c_func_tbl) { |
| 1642 | pr_err("a_ctrl->i2c_client.i2c_func_tbl NULL\n"); |
| 1643 | return -EINVAL; |
| 1644 | } |
| 1645 | mutex_lock(a_ctrl->actuator_mutex); |
| 1646 | rc = msm_actuator_power_down(a_ctrl); |
| 1647 | if (rc < 0) { |
| 1648 | pr_err("%s:%d Actuator Power down failed\n", |
| 1649 | __func__, __LINE__); |
| 1650 | } |
| 1651 | mutex_unlock(a_ctrl->actuator_mutex); |
| 1652 | return msm_actuator_close(sd, NULL); |
| 1653 | default: |
| 1654 | return -ENOIOCTLCMD; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | #ifdef CONFIG_COMPAT |
| 1659 | static long msm_actuator_subdev_do_ioctl( |
| 1660 | struct file *file, unsigned int cmd, void *arg) |
| 1661 | { |
| 1662 | struct video_device *vdev = video_devdata(file); |
| 1663 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
| 1664 | struct msm_actuator_cfg_data32 *u32 = |
| 1665 | (struct msm_actuator_cfg_data32 *)arg; |
| 1666 | struct msm_actuator_cfg_data actuator_data; |
| 1667 | void *parg = arg; |
| 1668 | long rc; |
| 1669 | |
| 1670 | switch (cmd) { |
| 1671 | case VIDIOC_MSM_ACTUATOR_CFG32: |
| 1672 | cmd = VIDIOC_MSM_ACTUATOR_CFG; |
| 1673 | switch (u32->cfgtype) { |
| 1674 | case CFG_SET_ACTUATOR_INFO: |
| 1675 | actuator_data.cfgtype = u32->cfgtype; |
| 1676 | actuator_data.is_af_supported = u32->is_af_supported; |
| 1677 | actuator_data.cfg.set_info.actuator_params.act_type = |
| 1678 | u32->cfg.set_info.actuator_params.act_type; |
| 1679 | |
| 1680 | actuator_data.cfg.set_info.actuator_params |
| 1681 | .reg_tbl_size = |
| 1682 | u32->cfg.set_info.actuator_params.reg_tbl_size; |
| 1683 | |
| 1684 | actuator_data.cfg.set_info.actuator_params.data_size = |
| 1685 | u32->cfg.set_info.actuator_params.data_size; |
| 1686 | |
| 1687 | actuator_data.cfg.set_info.actuator_params |
| 1688 | .init_setting_size = |
| 1689 | u32->cfg.set_info.actuator_params |
| 1690 | .init_setting_size; |
| 1691 | |
| 1692 | actuator_data.cfg.set_info.actuator_params.i2c_addr = |
| 1693 | u32->cfg.set_info.actuator_params.i2c_addr; |
| 1694 | |
| 1695 | actuator_data.cfg.set_info.actuator_params. |
| 1696 | i2c_freq_mode = |
| 1697 | u32->cfg.set_info.actuator_params.i2c_freq_mode; |
| 1698 | |
| 1699 | actuator_data.cfg.set_info.actuator_params |
| 1700 | .i2c_addr_type = |
| 1701 | u32->cfg.set_info.actuator_params.i2c_addr_type; |
| 1702 | |
| 1703 | actuator_data.cfg.set_info.actuator_params |
| 1704 | .i2c_data_type = |
| 1705 | u32->cfg.set_info.actuator_params.i2c_data_type; |
| 1706 | |
| 1707 | actuator_data.cfg.set_info.actuator_params |
| 1708 | .reg_tbl_params = |
| 1709 | compat_ptr( |
| 1710 | u32->cfg.set_info.actuator_params |
| 1711 | .reg_tbl_params); |
| 1712 | |
| 1713 | actuator_data.cfg.set_info.actuator_params |
| 1714 | .init_settings = |
| 1715 | compat_ptr( |
| 1716 | u32->cfg.set_info.actuator_params |
| 1717 | .init_settings); |
| 1718 | |
| 1719 | actuator_data.cfg.set_info.af_tuning_params |
| 1720 | .initial_code = |
| 1721 | u32->cfg.set_info.af_tuning_params.initial_code; |
| 1722 | |
| 1723 | actuator_data.cfg.set_info.af_tuning_params.pwd_step = |
| 1724 | u32->cfg.set_info.af_tuning_params.pwd_step; |
| 1725 | |
| 1726 | actuator_data.cfg.set_info.af_tuning_params |
| 1727 | .region_size = |
| 1728 | u32->cfg.set_info.af_tuning_params.region_size; |
| 1729 | |
| 1730 | actuator_data.cfg.set_info.af_tuning_params |
| 1731 | .total_steps = |
| 1732 | u32->cfg.set_info.af_tuning_params.total_steps; |
| 1733 | |
| 1734 | actuator_data.cfg.set_info.af_tuning_params |
| 1735 | .region_params = compat_ptr( |
| 1736 | u32->cfg.set_info.af_tuning_params |
| 1737 | .region_params); |
| 1738 | |
| 1739 | actuator_data.cfg.set_info.actuator_params.park_lens = |
| 1740 | u32->cfg.set_info.actuator_params.park_lens; |
| 1741 | |
| 1742 | parg = &actuator_data; |
| 1743 | break; |
| 1744 | case CFG_SET_DEFAULT_FOCUS: |
| 1745 | case CFG_MOVE_FOCUS: |
| 1746 | actuator_data.cfgtype = u32->cfgtype; |
| 1747 | actuator_data.is_af_supported = u32->is_af_supported; |
| 1748 | actuator_data.cfg.move.dir = u32->cfg.move.dir; |
| 1749 | |
| 1750 | actuator_data.cfg.move.sign_dir = |
| 1751 | u32->cfg.move.sign_dir; |
| 1752 | |
| 1753 | actuator_data.cfg.move.dest_step_pos = |
| 1754 | u32->cfg.move.dest_step_pos; |
| 1755 | |
| 1756 | actuator_data.cfg.move.num_steps = |
| 1757 | u32->cfg.move.num_steps; |
| 1758 | |
| 1759 | actuator_data.cfg.move.curr_lens_pos = |
| 1760 | u32->cfg.move.curr_lens_pos; |
| 1761 | |
| 1762 | actuator_data.cfg.move.ringing_params = |
| 1763 | compat_ptr(u32->cfg.move.ringing_params); |
| 1764 | parg = &actuator_data; |
| 1765 | break; |
| 1766 | case CFG_SET_POSITION: |
| 1767 | actuator_data.cfgtype = u32->cfgtype; |
| 1768 | actuator_data.is_af_supported = u32->is_af_supported; |
| 1769 | memcpy(&actuator_data.cfg.setpos, &(u32->cfg.setpos), |
| 1770 | sizeof(struct msm_actuator_set_position_t)); |
| 1771 | break; |
| 1772 | default: |
| 1773 | actuator_data.cfgtype = u32->cfgtype; |
| 1774 | parg = &actuator_data; |
| 1775 | break; |
| 1776 | } |
| 1777 | break; |
| 1778 | case VIDIOC_MSM_ACTUATOR_CFG: |
| 1779 | pr_err("%s: invalid cmd 0x%x received\n", __func__, cmd); |
| 1780 | return -EINVAL; |
| 1781 | } |
| 1782 | |
| 1783 | rc = msm_actuator_subdev_ioctl(sd, cmd, parg); |
| 1784 | |
| 1785 | switch (cmd) { |
| 1786 | |
| 1787 | case VIDIOC_MSM_ACTUATOR_CFG: |
| 1788 | |
| 1789 | switch (u32->cfgtype) { |
| 1790 | |
| 1791 | case CFG_SET_DEFAULT_FOCUS: |
| 1792 | case CFG_MOVE_FOCUS: |
| 1793 | u32->cfg.move.curr_lens_pos = |
| 1794 | actuator_data.cfg.move.curr_lens_pos; |
| 1795 | break; |
| 1796 | default: |
| 1797 | break; |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | return rc; |
| 1802 | } |
| 1803 | |
| 1804 | static long msm_actuator_subdev_fops_ioctl(struct file *file, unsigned int cmd, |
| 1805 | unsigned long arg) |
| 1806 | { |
| 1807 | return video_usercopy(file, cmd, arg, msm_actuator_subdev_do_ioctl); |
| 1808 | } |
| 1809 | #endif |
| 1810 | |
| 1811 | static int32_t msm_actuator_power_up(struct msm_actuator_ctrl_t *a_ctrl) |
| 1812 | { |
| 1813 | int rc = 0; |
| 1814 | enum msm_sensor_power_seq_gpio_t gpio; |
| 1815 | |
| 1816 | CDBG("%s called\n", __func__); |
| 1817 | |
| 1818 | rc = msm_actuator_vreg_control(a_ctrl, 1); |
| 1819 | if (rc < 0) { |
| 1820 | pr_err("%s failed %d\n", __func__, __LINE__); |
| 1821 | return rc; |
| 1822 | } |
| 1823 | |
| 1824 | for (gpio = SENSOR_GPIO_AF_PWDM; gpio < SENSOR_GPIO_MAX; gpio++) { |
| 1825 | if (a_ctrl->gconf && |
| 1826 | a_ctrl->gconf->gpio_num_info && |
| 1827 | a_ctrl->gconf->gpio_num_info->valid[gpio] == 1) { |
| 1828 | rc = msm_camera_request_gpio_table( |
| 1829 | a_ctrl->gconf->cam_gpio_req_tbl, |
| 1830 | a_ctrl->gconf->cam_gpio_req_tbl_size, 1); |
| 1831 | if (rc < 0) { |
| 1832 | pr_err("ERR:%s:Failed in selecting state for actuator: %d\n", |
| 1833 | __func__, rc); |
| 1834 | return rc; |
| 1835 | } |
| 1836 | if (a_ctrl->cam_pinctrl_status) { |
| 1837 | rc = pinctrl_select_state( |
| 1838 | a_ctrl->pinctrl_info.pinctrl, |
| 1839 | a_ctrl->pinctrl_info.gpio_state_active); |
| 1840 | if (rc < 0) |
| 1841 | pr_err("ERR:%s:%d cannot set pin to active state: %d", |
| 1842 | __func__, __LINE__, rc); |
| 1843 | } |
| 1844 | |
| 1845 | gpio_set_value_cansleep( |
| 1846 | a_ctrl->gconf->gpio_num_info->gpio_num[gpio], |
| 1847 | 1); |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | /* VREG needs some delay to power up */ |
| 1852 | usleep_range(2000, 3000); |
| 1853 | a_ctrl->actuator_state = ACT_ENABLE_STATE; |
| 1854 | |
| 1855 | CDBG("Exit\n"); |
| 1856 | return rc; |
| 1857 | } |
| 1858 | |
| 1859 | static struct v4l2_subdev_core_ops msm_actuator_subdev_core_ops = { |
| 1860 | .ioctl = msm_actuator_subdev_ioctl, |
| 1861 | }; |
| 1862 | |
| 1863 | static struct v4l2_subdev_ops msm_actuator_subdev_ops = { |
| 1864 | .core = &msm_actuator_subdev_core_ops, |
| 1865 | }; |
| 1866 | |
| 1867 | static const struct i2c_device_id msm_actuator_i2c_id[] = { |
| 1868 | {"qcom,actuator", (kernel_ulong_t)NULL}, |
| 1869 | { } |
| 1870 | }; |
| 1871 | |
| 1872 | static int32_t msm_actuator_i2c_probe(struct i2c_client *client, |
| 1873 | const struct i2c_device_id *id) |
| 1874 | { |
| 1875 | int rc = 0; |
| 1876 | struct msm_actuator_ctrl_t *act_ctrl_t = NULL; |
| 1877 | struct msm_actuator_vreg *vreg_cfg = NULL; |
| 1878 | |
| 1879 | CDBG("Enter\n"); |
| 1880 | |
| 1881 | if (client == NULL) { |
| 1882 | pr_err("msm_actuator_i2c_probe: client is null\n"); |
| 1883 | return -EINVAL; |
| 1884 | } |
| 1885 | |
| 1886 | act_ctrl_t = kzalloc(sizeof(struct msm_actuator_ctrl_t), |
| 1887 | GFP_KERNEL); |
| 1888 | if (!act_ctrl_t) |
| 1889 | return -ENOMEM; |
| 1890 | |
| 1891 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 1892 | pr_err("i2c_check_functionality failed\n"); |
| 1893 | goto probe_failure; |
| 1894 | } |
| 1895 | |
| 1896 | CDBG("client = 0x%pK\n", client); |
| 1897 | |
| 1898 | rc = of_property_read_u32(client->dev.of_node, "cell-index", |
| 1899 | &act_ctrl_t->subdev_id); |
| 1900 | CDBG("cell-index %d, rc %d\n", act_ctrl_t->subdev_id, rc); |
| 1901 | if (rc < 0) { |
| 1902 | pr_err("failed rc %d\n", rc); |
| 1903 | goto probe_failure; |
| 1904 | } |
| 1905 | |
| 1906 | if (of_find_property(client->dev.of_node, |
| 1907 | "qcom,cam-vreg-name", NULL)) { |
| 1908 | vreg_cfg = &act_ctrl_t->vreg_cfg; |
| 1909 | rc = msm_camera_get_dt_vreg_data(client->dev.of_node, |
| 1910 | &vreg_cfg->cam_vreg, &vreg_cfg->num_vreg); |
| 1911 | if (rc < 0) { |
| 1912 | pr_err("failed rc %d\n", rc); |
| 1913 | goto probe_failure; |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | act_ctrl_t->i2c_driver = &msm_actuator_i2c_driver; |
| 1918 | act_ctrl_t->i2c_client.client = client; |
| 1919 | act_ctrl_t->curr_step_pos = 0, |
| 1920 | act_ctrl_t->curr_region_index = 0, |
| 1921 | /* Set device type as I2C */ |
| 1922 | act_ctrl_t->act_device_type = MSM_CAMERA_I2C_DEVICE; |
| 1923 | act_ctrl_t->i2c_client.i2c_func_tbl = &msm_sensor_qup_func_tbl; |
| 1924 | act_ctrl_t->act_v4l2_subdev_ops = &msm_actuator_subdev_ops; |
| 1925 | act_ctrl_t->actuator_mutex = &msm_actuator_mutex; |
| 1926 | act_ctrl_t->cam_name = act_ctrl_t->subdev_id; |
| 1927 | CDBG("act_ctrl_t->cam_name: %d", act_ctrl_t->cam_name); |
| 1928 | /* Assign name for sub device */ |
| 1929 | snprintf(act_ctrl_t->msm_sd.sd.name, sizeof(act_ctrl_t->msm_sd.sd.name), |
| 1930 | "%s", act_ctrl_t->i2c_driver->driver.name); |
| 1931 | |
| 1932 | /* Initialize sub device */ |
| 1933 | v4l2_i2c_subdev_init(&act_ctrl_t->msm_sd.sd, |
| 1934 | act_ctrl_t->i2c_client.client, |
| 1935 | act_ctrl_t->act_v4l2_subdev_ops); |
| 1936 | v4l2_set_subdevdata(&act_ctrl_t->msm_sd.sd, act_ctrl_t); |
| 1937 | act_ctrl_t->msm_sd.sd.internal_ops = &msm_actuator_internal_ops; |
| 1938 | act_ctrl_t->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
| 1939 | media_entity_pads_init(&act_ctrl_t->msm_sd.sd.entity, 0, NULL); |
Trishansh Bhardwaj | 586ba08 | 2018-02-24 15:02:44 +0530 | [diff] [blame] | 1940 | act_ctrl_t->msm_sd.sd.entity.function = MSM_CAMERA_SUBDEV_ACTUATOR; |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 1941 | act_ctrl_t->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0x2; |
| 1942 | msm_sd_register(&act_ctrl_t->msm_sd); |
| 1943 | msm_cam_copy_v4l2_subdev_fops(&msm_actuator_v4l2_subdev_fops); |
| 1944 | #ifdef CONFIG_COMPAT |
| 1945 | msm_actuator_v4l2_subdev_fops.compat_ioctl32 = |
| 1946 | msm_actuator_subdev_fops_ioctl; |
| 1947 | #endif |
| 1948 | act_ctrl_t->msm_sd.sd.devnode->fops = |
| 1949 | &msm_actuator_v4l2_subdev_fops; |
| 1950 | act_ctrl_t->actuator_state = ACT_DISABLE_STATE; |
| 1951 | pr_info("msm_actuator_i2c_probe: succeeded\n"); |
| 1952 | CDBG("Exit\n"); |
| 1953 | |
| 1954 | return 0; |
| 1955 | |
| 1956 | probe_failure: |
| 1957 | kfree(act_ctrl_t); |
| 1958 | return rc; |
| 1959 | } |
| 1960 | |
| 1961 | static int32_t msm_actuator_platform_probe(struct platform_device *pdev) |
| 1962 | { |
| 1963 | int32_t rc = 0; |
| 1964 | struct msm_camera_cci_client *cci_client = NULL; |
| 1965 | struct msm_actuator_ctrl_t *msm_actuator_t = NULL; |
| 1966 | struct msm_actuator_vreg *vreg_cfg; |
| 1967 | |
| 1968 | CDBG("Enter\n"); |
| 1969 | |
| 1970 | if (!pdev->dev.of_node) { |
| 1971 | pr_err("of_node NULL\n"); |
| 1972 | return -EINVAL; |
| 1973 | } |
| 1974 | |
| 1975 | msm_actuator_t = kzalloc(sizeof(struct msm_actuator_ctrl_t), |
| 1976 | GFP_KERNEL); |
| 1977 | if (!msm_actuator_t) |
| 1978 | return -ENOMEM; |
| 1979 | rc = of_property_read_u32((&pdev->dev)->of_node, "cell-index", |
| 1980 | &pdev->id); |
| 1981 | CDBG("cell-index %d, rc %d\n", pdev->id, rc); |
| 1982 | if (rc < 0) { |
| 1983 | kfree(msm_actuator_t); |
| 1984 | pr_err("failed rc %d\n", rc); |
| 1985 | return rc; |
| 1986 | } |
| 1987 | |
| 1988 | rc = of_property_read_u32((&pdev->dev)->of_node, "qcom,cci-master", |
| 1989 | &msm_actuator_t->cci_master); |
| 1990 | CDBG("qcom,cci-master %d, rc %d\n", msm_actuator_t->cci_master, rc); |
| 1991 | if (rc < 0 || msm_actuator_t->cci_master >= MASTER_MAX) { |
| 1992 | kfree(msm_actuator_t); |
| 1993 | pr_err("failed rc %d\n", rc); |
| 1994 | return rc; |
| 1995 | } |
| 1996 | |
| 1997 | if (of_find_property((&pdev->dev)->of_node, |
| 1998 | "qcom,cam-vreg-name", NULL)) { |
| 1999 | vreg_cfg = &msm_actuator_t->vreg_cfg; |
| 2000 | rc = msm_camera_get_dt_vreg_data((&pdev->dev)->of_node, |
| 2001 | &vreg_cfg->cam_vreg, &vreg_cfg->num_vreg); |
| 2002 | if (rc < 0) { |
| 2003 | kfree(msm_actuator_t); |
| 2004 | pr_err("failed rc %d\n", rc); |
| 2005 | return rc; |
| 2006 | } |
| 2007 | } |
| 2008 | rc = msm_sensor_driver_get_gpio_data(&(msm_actuator_t->gconf), |
| 2009 | (&pdev->dev)->of_node); |
| 2010 | if (rc <= 0) { |
| 2011 | pr_err("%s: No/Error Actuator GPIOs\n", __func__); |
| 2012 | } else { |
| 2013 | msm_actuator_t->cam_pinctrl_status = 1; |
| 2014 | rc = msm_camera_pinctrl_init( |
| 2015 | &(msm_actuator_t->pinctrl_info), &(pdev->dev)); |
| 2016 | if (rc < 0) { |
| 2017 | pr_err("ERR:%s: Error in reading actuator pinctrl\n", |
| 2018 | __func__); |
| 2019 | msm_actuator_t->cam_pinctrl_status = 0; |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | msm_actuator_t->act_v4l2_subdev_ops = &msm_actuator_subdev_ops; |
| 2024 | msm_actuator_t->actuator_mutex = &msm_actuator_mutex; |
| 2025 | msm_actuator_t->cam_name = pdev->id; |
| 2026 | |
| 2027 | /* Set platform device handle */ |
| 2028 | msm_actuator_t->pdev = pdev; |
| 2029 | /* Set device type as platform device */ |
| 2030 | msm_actuator_t->act_device_type = MSM_CAMERA_PLATFORM_DEVICE; |
| 2031 | msm_actuator_t->i2c_client.i2c_func_tbl = &msm_sensor_cci_func_tbl; |
| 2032 | msm_actuator_t->i2c_client.cci_client = kzalloc(sizeof( |
| 2033 | struct msm_camera_cci_client), GFP_KERNEL); |
| 2034 | if (!msm_actuator_t->i2c_client.cci_client) { |
| 2035 | kfree(msm_actuator_t->vreg_cfg.cam_vreg); |
| 2036 | kfree(msm_actuator_t); |
| 2037 | pr_err("failed no memory\n"); |
| 2038 | return -ENOMEM; |
| 2039 | } |
| 2040 | |
| 2041 | cci_client = msm_actuator_t->i2c_client.cci_client; |
| 2042 | cci_client->cci_subdev = msm_cci_get_subdev(); |
| 2043 | cci_client->cci_i2c_master = msm_actuator_t->cci_master; |
| 2044 | v4l2_subdev_init(&msm_actuator_t->msm_sd.sd, |
| 2045 | msm_actuator_t->act_v4l2_subdev_ops); |
| 2046 | v4l2_set_subdevdata(&msm_actuator_t->msm_sd.sd, msm_actuator_t); |
| 2047 | msm_actuator_t->msm_sd.sd.internal_ops = &msm_actuator_internal_ops; |
| 2048 | msm_actuator_t->msm_sd.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
| 2049 | snprintf(msm_actuator_t->msm_sd.sd.name, |
| 2050 | ARRAY_SIZE(msm_actuator_t->msm_sd.sd.name), "msm_actuator"); |
| 2051 | media_entity_pads_init(&msm_actuator_t->msm_sd.sd.entity, 0, NULL); |
Trishansh Bhardwaj | 586ba08 | 2018-02-24 15:02:44 +0530 | [diff] [blame] | 2052 | msm_actuator_t->msm_sd.sd.entity.function = MSM_CAMERA_SUBDEV_ACTUATOR; |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 2053 | msm_actuator_t->msm_sd.close_seq = MSM_SD_CLOSE_2ND_CATEGORY | 0x2; |
| 2054 | msm_sd_register(&msm_actuator_t->msm_sd); |
| 2055 | msm_actuator_t->actuator_state = ACT_DISABLE_STATE; |
| 2056 | msm_cam_copy_v4l2_subdev_fops(&msm_actuator_v4l2_subdev_fops); |
| 2057 | #ifdef CONFIG_COMPAT |
| 2058 | msm_actuator_v4l2_subdev_fops.compat_ioctl32 = |
| 2059 | msm_actuator_subdev_fops_ioctl; |
| 2060 | #endif |
| 2061 | msm_actuator_t->msm_sd.sd.devnode->fops = |
| 2062 | &msm_actuator_v4l2_subdev_fops; |
| 2063 | |
| 2064 | CDBG("Exit\n"); |
| 2065 | return rc; |
| 2066 | } |
| 2067 | |
| 2068 | static const struct of_device_id msm_actuator_i2c_dt_match[] = { |
| 2069 | {.compatible = "qcom,actuator"}, |
| 2070 | {} |
| 2071 | }; |
| 2072 | |
| 2073 | MODULE_DEVICE_TABLE(of, msm_actuator_i2c_dt_match); |
| 2074 | |
| 2075 | static struct i2c_driver msm_actuator_i2c_driver = { |
| 2076 | .id_table = msm_actuator_i2c_id, |
| 2077 | .probe = msm_actuator_i2c_probe, |
| 2078 | .remove = __exit_p(msm_actuator_i2c_remove), |
| 2079 | .driver = { |
| 2080 | .name = "qcom,actuator", |
| 2081 | .owner = THIS_MODULE, |
| 2082 | .of_match_table = msm_actuator_i2c_dt_match, |
| 2083 | }, |
| 2084 | }; |
| 2085 | |
| 2086 | static const struct of_device_id msm_actuator_dt_match[] = { |
| 2087 | {.compatible = "qcom,actuator", .data = NULL}, |
| 2088 | {} |
| 2089 | }; |
| 2090 | |
| 2091 | MODULE_DEVICE_TABLE(of, msm_actuator_dt_match); |
| 2092 | |
| 2093 | static struct platform_driver msm_actuator_platform_driver = { |
| 2094 | .probe = msm_actuator_platform_probe, |
| 2095 | .driver = { |
| 2096 | .name = "qcom,actuator", |
| 2097 | .owner = THIS_MODULE, |
| 2098 | .of_match_table = msm_actuator_dt_match, |
| 2099 | }, |
| 2100 | }; |
| 2101 | |
| 2102 | static int __init msm_actuator_init_module(void) |
| 2103 | { |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 2104 | CDBG("Enter\n"); |
Sundara Vinayagam | 16b4b35 | 2018-05-15 17:13:10 +0530 | [diff] [blame] | 2105 | platform_driver_register(&msm_actuator_platform_driver); |
Pratap Nirujogi | 6e75991 | 2018-01-17 17:51:17 +0530 | [diff] [blame] | 2106 | return i2c_add_driver(&msm_actuator_i2c_driver); |
| 2107 | } |
| 2108 | |
| 2109 | static struct msm_actuator msm_vcm_actuator_table = { |
| 2110 | .act_type = ACTUATOR_VCM, |
| 2111 | .func_tbl = { |
| 2112 | .actuator_init_step_table = msm_actuator_init_step_table, |
| 2113 | .actuator_move_focus = msm_actuator_move_focus, |
| 2114 | .actuator_write_focus = msm_actuator_write_focus, |
| 2115 | .actuator_set_default_focus = msm_actuator_set_default_focus, |
| 2116 | .actuator_init_focus = msm_actuator_init_focus, |
| 2117 | .actuator_parse_i2c_params = msm_actuator_parse_i2c_params, |
| 2118 | .actuator_set_position = msm_actuator_set_position, |
| 2119 | .actuator_park_lens = msm_actuator_park_lens, |
| 2120 | }, |
| 2121 | }; |
| 2122 | |
| 2123 | static struct msm_actuator msm_piezo_actuator_table = { |
| 2124 | .act_type = ACTUATOR_PIEZO, |
| 2125 | .func_tbl = { |
| 2126 | .actuator_init_step_table = NULL, |
| 2127 | .actuator_move_focus = msm_actuator_piezo_move_focus, |
| 2128 | .actuator_write_focus = NULL, |
| 2129 | .actuator_set_default_focus = |
| 2130 | msm_actuator_piezo_set_default_focus, |
| 2131 | .actuator_init_focus = msm_actuator_init_focus, |
| 2132 | .actuator_parse_i2c_params = msm_actuator_parse_i2c_params, |
| 2133 | .actuator_park_lens = NULL, |
| 2134 | }, |
| 2135 | }; |
| 2136 | |
| 2137 | static struct msm_actuator msm_hvcm_actuator_table = { |
| 2138 | .act_type = ACTUATOR_HVCM, |
| 2139 | .func_tbl = { |
| 2140 | .actuator_init_step_table = msm_actuator_init_step_table, |
| 2141 | .actuator_move_focus = msm_actuator_move_focus, |
| 2142 | .actuator_write_focus = msm_actuator_write_focus, |
| 2143 | .actuator_set_default_focus = msm_actuator_set_default_focus, |
| 2144 | .actuator_init_focus = msm_actuator_init_focus, |
| 2145 | .actuator_parse_i2c_params = msm_actuator_parse_i2c_params, |
| 2146 | .actuator_set_position = msm_actuator_set_position, |
| 2147 | .actuator_park_lens = msm_actuator_park_lens, |
| 2148 | }, |
| 2149 | }; |
| 2150 | |
| 2151 | static struct msm_actuator msm_bivcm_actuator_table = { |
| 2152 | .act_type = ACTUATOR_BIVCM, |
| 2153 | .func_tbl = { |
| 2154 | .actuator_init_step_table = msm_actuator_bivcm_init_step_table, |
| 2155 | .actuator_move_focus = msm_actuator_bivcm_move_focus, |
| 2156 | .actuator_write_focus = NULL, |
| 2157 | .actuator_set_default_focus = msm_actuator_set_default_focus, |
| 2158 | .actuator_init_focus = msm_actuator_init_focus, |
| 2159 | .actuator_parse_i2c_params = NULL, |
| 2160 | .actuator_set_position = msm_actuator_bivcm_set_position, |
| 2161 | .actuator_park_lens = NULL, |
| 2162 | }, |
| 2163 | }; |
| 2164 | |
| 2165 | module_init(msm_actuator_init_module); |
| 2166 | MODULE_DESCRIPTION("MSM ACTUATOR"); |
| 2167 | MODULE_LICENSE("GPL v2"); |