Viswanadha Raju Thotakura | 525e2d1 | 2017-02-26 16:12:38 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <cam_sensor_cmn_header.h> |
| 15 | #include "cam_actuator_core.h" |
| 16 | #include <cam_sensor_util.h> |
| 17 | |
| 18 | int32_t cam_actuator_slaveInfo_pkt_parser(struct cam_actuator_ctrl_t *a_ctrl, |
| 19 | uint32_t *cmd_buf) |
| 20 | { |
| 21 | int32_t rc = 0; |
| 22 | struct cam_cmd_i2c_info *i2c_info; |
| 23 | |
| 24 | if (!a_ctrl || !cmd_buf) { |
| 25 | pr_err("%s:%d Invalid Args\n", __func__, __LINE__); |
| 26 | return -EINVAL; |
| 27 | } |
| 28 | |
| 29 | i2c_info = (struct cam_cmd_i2c_info *)cmd_buf; |
| 30 | a_ctrl->io_master_info.cci_client->i2c_freq_mode = |
| 31 | i2c_info->i2c_freq_mode; |
| 32 | a_ctrl->io_master_info.cci_client->sid = |
| 33 | i2c_info->slave_addr >> 1; |
| 34 | CDBG("%s:%d Slave addr: 0x%x Freq Mode: %d\n", __func__, |
| 35 | __LINE__, i2c_info->slave_addr, i2c_info->i2c_freq_mode); |
| 36 | |
| 37 | return rc; |
| 38 | } |
| 39 | |
| 40 | int32_t cam_actuator_apply_settings(struct cam_actuator_ctrl_t *a_ctrl, |
| 41 | struct i2c_settings_array *i2c_set) |
| 42 | { |
| 43 | struct i2c_settings_list *i2c_list; |
| 44 | int32_t rc = 0; |
| 45 | uint32_t i, size; |
| 46 | |
| 47 | if (a_ctrl == NULL || i2c_set == NULL) { |
| 48 | pr_err("%s:%d Invalid Args\n", __func__, __LINE__); |
| 49 | return -EINVAL; |
| 50 | } |
| 51 | |
| 52 | if (i2c_set->is_settings_valid != 1) { |
| 53 | pr_err("%s: %d :Error: Invalid settings\n", |
| 54 | __func__, __LINE__); |
| 55 | return -EINVAL; |
| 56 | } |
| 57 | |
| 58 | list_for_each_entry(i2c_list, |
| 59 | &(i2c_set->list_head), list) { |
| 60 | if (i2c_list->op_code == CAM_SENSOR_I2C_WRITE_RANDOM) { |
| 61 | rc = camera_io_dev_write(&(a_ctrl->io_master_info), |
| 62 | &(i2c_list->i2c_settings)); |
| 63 | if (rc < 0) { |
| 64 | pr_err("%s: %d :Error: Failed in Applying i2c write settings\n", |
| 65 | __func__, __LINE__); |
| 66 | return rc; |
| 67 | } |
| 68 | } else if (i2c_list->op_code == CAM_SENSOR_I2C_POLL) { |
| 69 | size = i2c_list->i2c_settings.size; |
| 70 | for (i = 0; i < size; i++) { |
| 71 | rc = camera_io_dev_poll( |
| 72 | &(a_ctrl->io_master_info), |
| 73 | i2c_list->i2c_settings. |
| 74 | reg_setting[i].reg_addr, |
| 75 | i2c_list->i2c_settings. |
| 76 | reg_setting[i].reg_data, |
| 77 | i2c_list->i2c_settings. |
| 78 | reg_setting[i].data_mask, |
| 79 | i2c_list->i2c_settings.addr_type, |
| 80 | i2c_list->i2c_settings.data_type, |
| 81 | i2c_list->i2c_settings. |
| 82 | reg_setting[i].delay); |
| 83 | if (rc < 0) { |
| 84 | pr_err("%s: %d :Error: Failed in Applying i2c poll settings\n", |
| 85 | __func__, __LINE__); |
| 86 | return rc; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return rc; |
| 93 | } |
| 94 | |
| 95 | int32_t cam_actuator_apply_request(struct cam_req_mgr_apply_request *apply) |
| 96 | { |
| 97 | int32_t rc = 0, request_id, del_req_id; |
| 98 | struct cam_actuator_ctrl_t *a_ctrl = NULL; |
| 99 | |
| 100 | if (!apply) { |
| 101 | pr_err("%s:%d :Error: Invalid Input Args\n", |
| 102 | __func__, __LINE__); |
| 103 | return -EINVAL; |
| 104 | } |
| 105 | |
| 106 | a_ctrl = (struct cam_actuator_ctrl_t *) |
| 107 | cam_get_device_priv(apply->dev_hdl); |
| 108 | if (!a_ctrl) { |
| 109 | pr_err("%s: %d :Error: Device data is NULL\n", |
| 110 | __func__, __LINE__); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | request_id = apply->request_id % MAX_PER_FRAME_ARRAY; |
| 114 | CDBG("%s:%d Request Id: %lld\n", |
| 115 | __func__, __LINE__, apply->request_id); |
| 116 | |
| 117 | if ((apply->request_id == |
| 118 | a_ctrl->i2c_data.per_frame[request_id].request_id) && |
| 119 | (a_ctrl->i2c_data.per_frame[request_id].is_settings_valid) |
| 120 | == 1) { |
| 121 | rc = cam_actuator_apply_settings(a_ctrl, |
| 122 | &a_ctrl->i2c_data.per_frame[request_id]); |
| 123 | if (rc < 0) { |
| 124 | pr_err("%s:%d Failed in applying the request: %lld\n", |
| 125 | __func__, __LINE__, apply->request_id); |
| 126 | return rc; |
| 127 | } |
| 128 | } |
| 129 | del_req_id = (request_id + |
| 130 | MAX_PER_FRAME_ARRAY - MAX_SYSTEM_PIPELINE_DELAY) % |
| 131 | MAX_PER_FRAME_ARRAY; |
| 132 | |
| 133 | if (apply->request_id > |
| 134 | a_ctrl->i2c_data.per_frame[del_req_id].request_id) { |
| 135 | a_ctrl->i2c_data.per_frame[del_req_id].request_id = 0; |
| 136 | rc = delete_request(&a_ctrl->i2c_data.per_frame[del_req_id]); |
| 137 | if (rc < 0) { |
| 138 | pr_err("%s: %d :Error: Fail deleting the req: %d err: %d\n", |
| 139 | __func__, __LINE__, del_req_id, rc); |
| 140 | return rc; |
| 141 | } |
| 142 | } else { |
| 143 | CDBG("%s:%d No Valid Req to clean Up\n", __func__, __LINE__); |
| 144 | } |
| 145 | |
| 146 | return rc; |
| 147 | } |
| 148 | |
| 149 | int32_t cam_actuator_establish_link( |
| 150 | struct cam_req_mgr_core_dev_link_setup *link) |
| 151 | { |
| 152 | struct cam_actuator_ctrl_t *a_ctrl = NULL; |
| 153 | |
| 154 | if (!link) { |
| 155 | pr_err("%s:%d Invalid Args\n", __func__, __LINE__); |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | |
| 159 | a_ctrl = (struct cam_actuator_ctrl_t *) |
| 160 | cam_get_device_priv(link->dev_hdl); |
| 161 | if (!a_ctrl) { |
| 162 | pr_err("%s:%d :Error: Device data is NULL\n", |
| 163 | __func__, __LINE__); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | if (link->link_enable) { |
| 167 | a_ctrl->bridge_intf.link_hdl = link->link_hdl; |
| 168 | a_ctrl->bridge_intf.crm_cb = link->crm_cb; |
| 169 | } else { |
| 170 | a_ctrl->bridge_intf.link_hdl = -1; |
| 171 | a_ctrl->bridge_intf.crm_cb = NULL; |
| 172 | } |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | int32_t cam_actuator_publish_dev_info(struct cam_req_mgr_device_info *info) |
| 178 | { |
| 179 | if (!info) { |
| 180 | pr_err("%s:%d Invalid Args\n", __func__, __LINE__); |
| 181 | return -EINVAL; |
| 182 | } |
| 183 | |
| 184 | info->dev_id = CAM_REQ_MGR_DEVICE_ACTUATOR; |
| 185 | strlcpy(info->name, CAM_ACTUATOR_NAME, sizeof(info->name)); |
| 186 | info->p_delay = 0; |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | int32_t cam_actuator_i2c_pkt_parse(struct cam_actuator_ctrl_t *a_ctrl, |
| 192 | void *arg) |
| 193 | { |
| 194 | int32_t rc = 0; |
| 195 | uint64_t generic_ptr; |
| 196 | struct cam_control *ioctl_ctrl = NULL; |
| 197 | struct cam_packet *csl_packet = NULL; |
| 198 | struct cam_config_dev_cmd config; |
| 199 | struct i2c_data_settings *i2c_data = NULL; |
| 200 | struct i2c_settings_array *i2c_reg_settings = NULL; |
| 201 | struct cam_cmd_buf_desc *cmd_desc = NULL; |
| 202 | size_t len_of_buff = 0; |
| 203 | uint32_t *offset = NULL, *cmd_buf; |
| 204 | struct cam_req_mgr_add_request add_req; |
| 205 | |
| 206 | if (!a_ctrl || !arg) { |
| 207 | pr_err("%s:%d :Error: Invalid Args\n", |
| 208 | __func__, __LINE__); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
| 212 | ioctl_ctrl = (struct cam_control *)arg; |
| 213 | if (copy_from_user(&config, (void __user *) ioctl_ctrl->handle, |
| 214 | sizeof(config))) |
| 215 | return -EFAULT; |
| 216 | rc = cam_mem_get_cpu_buf(config.packet_handle, |
| 217 | (uint64_t *)&generic_ptr, &len_of_buff); |
| 218 | if (rc < 0) { |
| 219 | pr_err("%s:%d :Error: error in converting command Handle %d\n", |
| 220 | __func__, __LINE__, rc); |
| 221 | return rc; |
| 222 | } |
| 223 | |
| 224 | if (config.offset > len_of_buff) { |
| 225 | pr_err("%s: %d offset is out of bounds: offset: %lld len: %zu\n", |
| 226 | __func__, __LINE__, config.offset, len_of_buff); |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
| 230 | csl_packet = (struct cam_packet *)(generic_ptr + |
| 231 | config.offset); |
| 232 | CDBG("%s:%d Pkt opcode: %d\n", |
| 233 | __func__, __LINE__, csl_packet->header.op_code); |
| 234 | |
| 235 | if ((csl_packet->header.op_code & 0xFFFFFF) == |
| 236 | CAM_ACTUATOR_PACKET_OPCODE_INIT) { |
| 237 | i2c_data = &(a_ctrl->i2c_data); |
| 238 | i2c_reg_settings = &i2c_data->init_settings; |
| 239 | |
| 240 | offset = (uint32_t *)&csl_packet->payload; |
| 241 | offset += (csl_packet->cmd_buf_offset / sizeof(uint32_t)); |
| 242 | cmd_desc = (struct cam_cmd_buf_desc *)(offset); |
| 243 | |
| 244 | if (csl_packet->num_cmd_buf != 2) { |
| 245 | pr_err("%s:: %d :Error: cmd Buffers in Init : %d\n", |
| 246 | __func__, __LINE__, csl_packet->num_cmd_buf); |
| 247 | return -EINVAL; |
| 248 | } |
| 249 | |
| 250 | rc = cam_mem_get_cpu_buf(cmd_desc[0].mem_handle, |
| 251 | (uint64_t *)&generic_ptr, &len_of_buff); |
| 252 | if (rc < 0) { |
| 253 | pr_err("%s:%d Failed to get cpu buf\n", |
| 254 | __func__, __LINE__); |
| 255 | return rc; |
| 256 | } |
| 257 | cmd_buf = (uint32_t *)generic_ptr; |
| 258 | cmd_buf += cmd_desc->offset / sizeof(uint32_t); |
| 259 | rc = cam_actuator_slaveInfo_pkt_parser(a_ctrl, cmd_buf); |
| 260 | if (rc < 0) { |
| 261 | pr_err("%s:%d Failed in parsing the pkt\n", |
| 262 | __func__, __LINE__); |
| 263 | return rc; |
| 264 | } |
| 265 | cmd_buf += (sizeof(struct cam_cmd_i2c_info)/sizeof(uint32_t)); |
| 266 | i2c_data->init_settings.request_id = 0; |
| 267 | i2c_reg_settings->is_settings_valid = 1; |
| 268 | rc = cam_sensor_i2c_pkt_parser(i2c_reg_settings, |
| 269 | &cmd_desc[1], 1); |
| 270 | if (rc < 0) { |
| 271 | pr_err("%s:%d :Error: actuator pkt parsing failed: %d\n", |
| 272 | __func__, __LINE__, rc); |
| 273 | return rc; |
| 274 | } |
| 275 | } else if ((csl_packet->header.op_code & 0xFFFFFF) == |
| 276 | CAM_ACTUATOR_PACKET_AUTO_MOVE_LENS) { |
| 277 | a_ctrl->act_apply_state = |
| 278 | ACT_APPLY_SETTINGS_NOW; |
| 279 | |
| 280 | i2c_data = &(a_ctrl->i2c_data); |
| 281 | i2c_reg_settings = &i2c_data->init_settings; |
| 282 | |
| 283 | i2c_data->init_settings.request_id = |
| 284 | csl_packet->header.request_id; |
| 285 | i2c_reg_settings->is_settings_valid = 1; |
| 286 | offset = (uint32_t *)&csl_packet->payload; |
| 287 | offset += csl_packet->cmd_buf_offset / sizeof(uint32_t); |
| 288 | cmd_desc = (struct cam_cmd_buf_desc *)(offset); |
| 289 | rc = cam_sensor_i2c_pkt_parser(i2c_reg_settings, |
| 290 | cmd_desc, 1); |
| 291 | if (rc < 0) { |
| 292 | pr_err("%s:%d :Error: actuator pkt parsing failed: %d\n", |
| 293 | __func__, __LINE__, rc); |
| 294 | return rc; |
| 295 | } |
| 296 | } else if ((csl_packet->header.op_code & 0xFFFFFF) == |
| 297 | CAM_ACTUATOR_PACKET_MANUAL_MOVE_LENS) { |
| 298 | i2c_data = &(a_ctrl->i2c_data); |
| 299 | i2c_reg_settings = |
| 300 | &i2c_data->per_frame |
| 301 | [csl_packet->header.request_id % MAX_PER_FRAME_ARRAY]; |
| 302 | |
| 303 | i2c_data->init_settings.request_id = |
| 304 | csl_packet->header.request_id; |
| 305 | i2c_reg_settings->is_settings_valid = 1; |
| 306 | offset = (uint32_t *)&csl_packet->payload; |
| 307 | offset += csl_packet->cmd_buf_offset / sizeof(uint32_t); |
| 308 | cmd_desc = (struct cam_cmd_buf_desc *)(offset); |
| 309 | rc = cam_sensor_i2c_pkt_parser(i2c_reg_settings, |
| 310 | cmd_desc, 1); |
| 311 | if (rc < 0) { |
| 312 | pr_err("%s:%d :Error: actuator pkt parsing failed: %d\n", |
| 313 | __func__, __LINE__, rc); |
| 314 | return rc; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | if ((csl_packet->header.op_code & 0xFFFFFF) != |
| 319 | CAM_ACTUATOR_PACKET_OPCODE_INIT) { |
| 320 | add_req.link_hdl = a_ctrl->bridge_intf.link_hdl; |
| 321 | add_req.req_id = csl_packet->header.request_id; |
| 322 | add_req.dev_hdl = a_ctrl->bridge_intf.device_hdl; |
| 323 | if (a_ctrl->bridge_intf.crm_cb && |
| 324 | a_ctrl->bridge_intf.crm_cb->add_req) |
| 325 | a_ctrl->bridge_intf.crm_cb->add_req(&add_req); |
| 326 | CDBG("%s: %d Req Id: %lld added to Bridge\n", |
| 327 | __func__, __LINE__, add_req.req_id); |
| 328 | } |
| 329 | |
| 330 | return rc; |
| 331 | } |
| 332 | |
| 333 | static int32_t cam_actuator_vreg_control(struct cam_actuator_ctrl_t *a_ctrl, |
| 334 | int config) |
| 335 | { |
| 336 | int rc = 0, i, cnt; |
| 337 | struct cam_actuator_vreg *vreg_cfg; |
| 338 | |
| 339 | vreg_cfg = &a_ctrl->vreg_cfg; |
| 340 | cnt = vreg_cfg->num_vreg; |
| 341 | if (!cnt) |
| 342 | return 0; |
| 343 | |
| 344 | if (cnt >= MSM_ACTUATOR_MAX_VREGS) { |
| 345 | pr_err("%s:%d Regulators more than supported %d\n", |
| 346 | __func__, __LINE__, cnt); |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | for (i = 0; i < cnt; i++) { |
| 351 | if (a_ctrl->io_master_info.master_type == |
| 352 | CCI_MASTER) { |
| 353 | rc = msm_camera_config_single_vreg( |
| 354 | &(a_ctrl->v4l2_dev_str.pdev->dev), |
| 355 | &vreg_cfg->cam_vreg[i], |
| 356 | (struct regulator **)&vreg_cfg->data[i], |
| 357 | config); |
| 358 | } else if (a_ctrl->io_master_info.master_type == |
| 359 | I2C_MASTER) { |
| 360 | rc = msm_camera_config_single_vreg( |
| 361 | &(a_ctrl->io_master_info.client->dev), |
| 362 | &vreg_cfg->cam_vreg[i], |
| 363 | (struct regulator **)&vreg_cfg->data[i], |
| 364 | config); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return rc; |
| 369 | } |
| 370 | |
| 371 | static int32_t cam_actuator_power_up(struct cam_actuator_ctrl_t *a_ctrl) |
| 372 | { |
| 373 | int rc = 0; |
| 374 | |
| 375 | rc = cam_actuator_vreg_control(a_ctrl, 1); |
| 376 | if (rc < 0) { |
| 377 | pr_err("%s:%d Actuator Reg Failed %d\n", |
| 378 | __func__, __LINE__, rc); |
| 379 | return rc; |
| 380 | } |
| 381 | |
| 382 | if (a_ctrl->gconf && |
| 383 | a_ctrl->gconf->gpio_num_info && |
| 384 | a_ctrl->gconf->gpio_num_info->valid[SENSOR_VAF] == 1) { |
| 385 | rc = msm_camera_request_gpio_table( |
| 386 | a_ctrl->gconf->cam_gpio_req_tbl, |
| 387 | a_ctrl->gconf->cam_gpio_req_tbl_size, 1); |
| 388 | if (rc < 0) { |
| 389 | pr_err("%s:%d :Error: Failed in req gpio: %d\n", |
| 390 | __func__, __LINE__, rc); |
| 391 | return rc; |
| 392 | } |
| 393 | if (a_ctrl->cam_pinctrl_status) { |
| 394 | rc = pinctrl_select_state( |
| 395 | a_ctrl->pinctrl_info.pinctrl, |
| 396 | a_ctrl->pinctrl_info.gpio_state_active); |
| 397 | if (rc < 0) |
| 398 | pr_err("%s:%d :Error: cannot set pin to active state: %d", |
| 399 | __func__, __LINE__, rc); |
| 400 | } |
| 401 | |
| 402 | gpio_set_value_cansleep( |
| 403 | a_ctrl->gconf->gpio_num_info->gpio_num[SENSOR_VAF], |
| 404 | 1); |
| 405 | } |
| 406 | |
| 407 | /* VREG needs some delay to power up */ |
| 408 | usleep_range(2000, 2050); |
| 409 | |
| 410 | return rc; |
| 411 | } |
| 412 | |
| 413 | static int32_t cam_actuator_power_down(struct cam_actuator_ctrl_t *a_ctrl) |
| 414 | { |
| 415 | int32_t rc = 0; |
| 416 | |
| 417 | rc = cam_actuator_vreg_control(a_ctrl, 0); |
| 418 | if (rc < 0) { |
| 419 | pr_err("%s failed %d\n", __func__, __LINE__); |
| 420 | return rc; |
| 421 | } |
| 422 | |
| 423 | if (a_ctrl->gconf && |
| 424 | a_ctrl->gconf->gpio_num_info && |
| 425 | a_ctrl->gconf->gpio_num_info-> |
| 426 | valid[SENSOR_VAF] == 1) { |
| 427 | |
| 428 | gpio_set_value_cansleep( |
| 429 | a_ctrl->gconf->gpio_num_info-> |
| 430 | gpio_num[SENSOR_VAF], |
| 431 | GPIOF_OUT_INIT_LOW); |
| 432 | |
| 433 | if (a_ctrl->cam_pinctrl_status) { |
| 434 | rc = pinctrl_select_state( |
| 435 | a_ctrl->pinctrl_info.pinctrl, |
| 436 | a_ctrl->pinctrl_info. |
| 437 | gpio_state_suspend); |
| 438 | if (rc < 0) |
| 439 | pr_err("%s:%d cannot set pin to suspend state: %d", |
| 440 | __func__, __LINE__, rc); |
| 441 | |
| 442 | devm_pinctrl_put( |
| 443 | a_ctrl->pinctrl_info.pinctrl); |
| 444 | } |
| 445 | a_ctrl->cam_pinctrl_status = 0; |
| 446 | rc = msm_camera_request_gpio_table( |
| 447 | a_ctrl->gconf->cam_gpio_req_tbl, |
| 448 | a_ctrl->gconf->cam_gpio_req_tbl_size, |
| 449 | 0); |
| 450 | if (rc < 0) |
| 451 | pr_err("%s:%d Failed in selecting state: %d\n", |
| 452 | __func__, __LINE__, rc); |
| 453 | } |
| 454 | |
| 455 | return rc; |
| 456 | } |
| 457 | |
| 458 | int32_t cam_actuator_driver_cmd(struct cam_actuator_ctrl_t *a_ctrl, |
| 459 | void *arg) |
| 460 | { |
| 461 | int rc = 0; |
| 462 | struct cam_control *cmd = (struct cam_control *)arg; |
| 463 | |
| 464 | if (!a_ctrl || !cmd) { |
| 465 | pr_err("%s: %d :Error: Invalid Args\n", |
| 466 | __func__, __LINE__); |
| 467 | return -EINVAL; |
| 468 | } |
| 469 | |
| 470 | pr_debug("%s:%d Opcode to Actuator: %d\n", |
| 471 | __func__, __LINE__, cmd->op_code); |
| 472 | |
| 473 | mutex_lock(&(a_ctrl->actuator_mutex)); |
| 474 | switch (cmd->op_code) { |
| 475 | case CAM_ACQUIRE_DEV: { |
| 476 | struct cam_sensor_acquire_dev actuator_acq_dev; |
| 477 | struct cam_create_dev_hdl bridge_params; |
| 478 | |
| 479 | if (a_ctrl->bridge_intf.device_hdl != -1) { |
| 480 | pr_err("%s:%d Device is already acquired\n", |
| 481 | __func__, __LINE__); |
| 482 | rc = -EINVAL; |
| 483 | goto release_mutex; |
| 484 | } |
| 485 | rc = copy_from_user(&actuator_acq_dev, |
| 486 | (void __user *) cmd->handle, |
| 487 | sizeof(actuator_acq_dev)); |
| 488 | if (rc < 0) { |
| 489 | pr_err("%s:%d :Error: Failed Copying from user\n", |
| 490 | __func__, __LINE__); |
| 491 | goto release_mutex; |
| 492 | } |
| 493 | |
| 494 | bridge_params.session_hdl = actuator_acq_dev.session_handle; |
| 495 | bridge_params.ops = &a_ctrl->bridge_intf.ops; |
| 496 | bridge_params.v4l2_sub_dev_flag = 0; |
| 497 | bridge_params.media_entity_flag = 0; |
| 498 | bridge_params.priv = a_ctrl; |
| 499 | |
| 500 | actuator_acq_dev.device_handle = |
| 501 | cam_create_device_hdl(&bridge_params); |
| 502 | a_ctrl->bridge_intf.device_hdl = actuator_acq_dev.device_handle; |
| 503 | a_ctrl->bridge_intf.session_hdl = |
| 504 | actuator_acq_dev.session_handle; |
| 505 | |
| 506 | CDBG("%s:%d Device Handle: %d\n", |
| 507 | __func__, __LINE__, actuator_acq_dev.device_handle); |
| 508 | if (copy_to_user((void __user *) cmd->handle, &actuator_acq_dev, |
| 509 | sizeof(struct cam_sensor_acquire_dev))) { |
| 510 | pr_err("%s:%d :Error: Failed Copy to User\n", |
| 511 | __func__, __LINE__); |
| 512 | rc = -EFAULT; |
| 513 | goto release_mutex; |
| 514 | } |
| 515 | |
| 516 | } |
| 517 | break; |
| 518 | case CAM_RELEASE_DEV: { |
| 519 | if (a_ctrl->bridge_intf.device_hdl == -1) { |
| 520 | pr_err("%s:%d :Error: link hdl: %d device hdl: %d\n", |
| 521 | __func__, __LINE__, |
| 522 | a_ctrl->bridge_intf.device_hdl, |
| 523 | a_ctrl->bridge_intf.link_hdl); |
| 524 | rc = -EINVAL; |
| 525 | goto release_mutex; |
| 526 | } |
| 527 | rc = cam_destroy_device_hdl(a_ctrl->bridge_intf.device_hdl); |
| 528 | if (rc < 0) |
| 529 | pr_err("%s:%d :Error: destroying the device hdl\n", |
| 530 | __func__, __LINE__); |
| 531 | a_ctrl->bridge_intf.device_hdl = -1; |
| 532 | a_ctrl->bridge_intf.link_hdl = -1; |
| 533 | a_ctrl->bridge_intf.session_hdl = -1; |
| 534 | } |
| 535 | break; |
| 536 | case CAM_QUERY_CAP: { |
| 537 | struct cam_actuator_query_cap actuator_cap; |
| 538 | |
| 539 | actuator_cap.slot_info = a_ctrl->id; |
| 540 | if (copy_to_user((void __user *) cmd->handle, &actuator_cap, |
| 541 | sizeof(struct cam_actuator_query_cap))) { |
| 542 | pr_err("%s:%d :Error: Failed Copy to User\n", |
| 543 | __func__, __LINE__); |
| 544 | rc = -EFAULT; |
| 545 | goto release_mutex; |
| 546 | } |
| 547 | } |
| 548 | break; |
| 549 | case CAM_START_DEV: { |
| 550 | rc = cam_actuator_power_up(a_ctrl); |
| 551 | if (rc < 0) { |
| 552 | pr_err("%s: %d :Error: Actuator Power up failed\n", |
| 553 | __func__, __LINE__); |
| 554 | goto release_mutex; |
| 555 | } |
| 556 | rc = camera_io_init(&a_ctrl->io_master_info); |
| 557 | if (rc < 0) { |
| 558 | pr_err("%s:%d :Error: cci_init failed\n", |
| 559 | __func__, __LINE__); |
| 560 | cam_actuator_power_down(a_ctrl); |
| 561 | } |
| 562 | |
| 563 | rc = cam_actuator_apply_settings(a_ctrl, |
| 564 | &a_ctrl->i2c_data.init_settings); |
| 565 | if (rc < 0) |
| 566 | pr_err("%s: %d :Error: Cannot apply Init settings\n", |
| 567 | __func__, __LINE__); |
| 568 | |
| 569 | /* Delete the request even if the apply is failed */ |
| 570 | rc = delete_request(&a_ctrl->i2c_data.init_settings); |
| 571 | if (rc < 0) { |
| 572 | pr_err("%s:%d Fail in deleting the Init settings\n", |
| 573 | __func__, __LINE__); |
| 574 | rc = -EINVAL; |
| 575 | goto release_mutex; |
| 576 | } |
| 577 | } |
| 578 | break; |
| 579 | case CAM_STOP_DEV: { |
| 580 | rc = camera_io_release(&a_ctrl->io_master_info); |
| 581 | if (rc < 0) |
| 582 | pr_err("%s:%d :Error: Failed in releasing CCI\n", |
| 583 | __func__, __LINE__); |
| 584 | rc = cam_actuator_power_down(a_ctrl); |
| 585 | if (rc < 0) { |
| 586 | pr_err("%s:%d :Error: Actuator Power down failed\n", |
| 587 | __func__, __LINE__); |
| 588 | goto release_mutex; |
| 589 | } |
| 590 | } |
| 591 | break; |
| 592 | case CAM_CONFIG_DEV: { |
| 593 | a_ctrl->act_apply_state = |
| 594 | ACT_APPLY_SETTINGS_LATER; |
| 595 | rc = cam_actuator_i2c_pkt_parse(a_ctrl, arg); |
| 596 | if (rc < 0) { |
| 597 | pr_err("%s:%d :Error: Failed in actuator Parsing\n", |
| 598 | __func__, __LINE__); |
| 599 | } |
| 600 | |
| 601 | if (a_ctrl->act_apply_state == |
| 602 | ACT_APPLY_SETTINGS_NOW) { |
| 603 | rc = cam_actuator_apply_settings(a_ctrl, |
| 604 | &a_ctrl->i2c_data.init_settings); |
| 605 | if (rc < 0) |
| 606 | pr_err("%s:%d :Error: Cannot apply Update settings\n", |
| 607 | __func__, __LINE__); |
| 608 | |
| 609 | /* Delete the request even if the apply is failed */ |
| 610 | rc = delete_request(&a_ctrl->i2c_data.init_settings); |
| 611 | if (rc < 0) { |
| 612 | pr_err("%s: %d :Error: Failed in Deleting the Init Pkt: %d\n", |
| 613 | __func__, __LINE__, rc); |
| 614 | goto release_mutex; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | break; |
Lakshmi Narayana Kalavala | c2fac45 | 2017-06-12 12:38:07 -0700 | [diff] [blame^] | 619 | case CAM_SD_SHUTDOWN: |
| 620 | break; |
Viswanadha Raju Thotakura | 525e2d1 | 2017-02-26 16:12:38 -0800 | [diff] [blame] | 621 | default: |
| 622 | pr_err("%s:%d Invalid Opcode %d\n", |
| 623 | __func__, __LINE__, cmd->op_code); |
| 624 | } |
| 625 | |
| 626 | release_mutex: |
| 627 | mutex_unlock(&(a_ctrl->actuator_mutex)); |
| 628 | |
| 629 | return rc; |
| 630 | } |