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