static int32_t msm_led_get_dt_data(struct device_node *of_node, struct msm_led_flash_ctrl_t *fctrl) { int32_t rc = 0, i = 0; struct msm_camera_gpio_conf *gconf = NULL; struct device_node *flash_src_node = NULL; struct msm_camera_sensor_board_info *flashdata = NULL; uint32_t count = 0; uint16_t *gpio_array = NULL; uint16_t gpio_array_size = 0; uint32_t id_info[3]; CDBG("called\n"); if (!of_node) { pr_err("of_node NULL\n"); return -EINVAL; } fctrl->flashdata = kzalloc(sizeof( struct msm_camera_sensor_board_info), GFP_KERNEL); if (!fctrl->flashdata) { pr_err("%s failed %d\n", __func__, __LINE__); return -ENOMEM; } flashdata = fctrl->flashdata; flashdata->sensor_init_params = kzalloc(sizeof( struct msm_sensor_init_params), GFP_KERNEL); if (!flashdata->sensor_init_params) { pr_err("%s failed %d\n", __func__, __LINE__); return -ENOMEM; } rc = of_property_read_u32(of_node, "cell-index", &fctrl->subdev_id); if (rc < 0) { pr_err("failed\n"); return -EINVAL; } CDBG("subdev id %d\n", fctrl->subdev_id); rc = of_property_read_string(of_node, "qcom,flash-name", &flashdata->sensor_name); CDBG("%s qcom,flash-name %s, rc %d\n", __func__, flashdata->sensor_name, rc); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR1; } if (of_get_property(of_node, "qcom,flash-source", &count)) { count /= sizeof(uint32_t); CDBG("count %d\n", count); if (count > MAX_LED_TRIGGERS) { pr_err("failed\n"); return -EINVAL; } for (i = 0; i < count; i++) { flash_src_node = of_parse_phandle(of_node, "qcom,flash-source", i); if (!flash_src_node) { pr_err("flash_src_node NULL\n"); continue; } rc = of_property_read_string(flash_src_node, "linux,default-trigger", &fctrl->led_trigger_name[i]); if (rc < 0) { pr_err("failed\n"); of_node_put(flash_src_node); continue; } CDBG("default trigger %s\n", fctrl->led_trigger_name[i]); rc = of_property_read_u32(flash_src_node, "qcom,max-current", &fctrl->op_current[i]); if (rc < 0) { pr_err("failed rc %d\n", rc); of_node_put(flash_src_node); continue; } of_node_put(flash_src_node); CDBG("max_current[%d] %d\n", i, fctrl->op_current[i]); led_trigger_register_simple( fctrl->led_trigger_name[i], &fctrl->led_trigger[i]); } } else { flashdata->gpio_conf = kzalloc(sizeof(struct msm_camera_gpio_conf), GFP_KERNEL); if (!flashdata->gpio_conf) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; return rc; } gconf = flashdata->gpio_conf; gpio_array_size = of_gpio_count(of_node); CDBG("%s gpio count %d\n", __func__, gpio_array_size); if (gpio_array_size) { gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size, GFP_KERNEL); if (!gpio_array) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; goto ERROR4; } for (i = 0; i < gpio_array_size; i++) { gpio_array[i] = of_get_gpio(of_node, i); CDBG("%s gpio_array[%d] = %d\n", __func__, i, gpio_array[i]); } rc = msm_sensor_get_dt_gpio_req_tbl(of_node, gconf, gpio_array, gpio_array_size); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR4; } rc = msm_sensor_get_dt_gpio_set_tbl(of_node, gconf, gpio_array, gpio_array_size); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR5; } rc = msm_flash_init_gpio_pin_tbl(of_node, gconf, gpio_array, gpio_array_size); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR6; } } flashdata->slave_info = kzalloc(sizeof(struct msm_camera_slave_info), GFP_KERNEL); if (!flashdata->slave_info) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; goto ERROR8; } rc = of_property_read_u32_array(of_node, "qcom,slave-id", id_info, 3); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR9; } fctrl->flashdata->slave_info->sensor_slave_addr = id_info[0]; fctrl->flashdata->slave_info->sensor_id_reg_addr = id_info[1]; fctrl->flashdata->slave_info->sensor_id = id_info[2]; kfree(gpio_array); return rc; ERROR9: kfree(fctrl->flashdata->slave_info); ERROR8: kfree(fctrl->flashdata->gpio_conf->gpio_num_info); ERROR6: kfree(gconf->cam_gpio_set_tbl); ERROR5: kfree(gconf->cam_gpio_req_tbl); ERROR4: kfree(gconf); ERROR1: kfree(fctrl->flashdata); kfree(gpio_array); } return rc; }
static int32_t msm_led_get_dt_data(struct device_node *of_node, struct msm_led_flash_ctrl_t *fctrl) { int32_t rc = 0, i = 0; struct msm_camera_gpio_conf *gconf = NULL; struct device_node *flash_src_node = NULL; struct msm_camera_sensor_board_info *flashdata = NULL; uint32_t count = 0; uint16_t *gpio_array = NULL; uint16_t gpio_array_size = 0; uint32_t id_info[3]; CDBG("called\n"); if (!of_node) { pr_err("of_node NULL\n"); return -EINVAL; } fctrl->flashdata = kzalloc(sizeof( struct msm_camera_sensor_board_info), GFP_KERNEL); if (!fctrl->flashdata) { pr_err("%s failed %d\n", __func__, __LINE__); return -ENOMEM; } flashdata = fctrl->flashdata; flashdata->sensor_init_params = kzalloc(sizeof( struct msm_sensor_init_params), GFP_KERNEL); if (!flashdata->sensor_init_params) { pr_err("%s failed %d\n", __func__, __LINE__); return -ENOMEM; } rc = of_property_read_u32(of_node, "cell-index", &fctrl->subdev_id); if (rc < 0) { pr_err("failed\n"); return -EINVAL; } CDBG("subdev id %d\n", fctrl->subdev_id); rc = of_property_read_string(of_node, "qcom,flash-name", &flashdata->sensor_name); CDBG("%s qcom,flash-name %s, rc %d\n", __func__, flashdata->sensor_name, rc); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR1; } rc = of_property_read_u32(of_node, "qcom,cci-master", &fctrl->cci_i2c_master); CDBG("%s qcom,cci-master %d, rc %d\n", __func__, fctrl->cci_i2c_master, rc); if (rc < 0) { /* Set default master 0 */ fctrl->cci_i2c_master = MASTER_0; rc = 0; } if (of_get_property(of_node, "qcom,flash-source", &count)) { count /= sizeof(uint32_t); CDBG("count %d\n", count); if (count > MAX_LED_TRIGGERS) { pr_err("failed\n"); return -EINVAL; } for (i = 0; i < count; i++) { flash_src_node = of_parse_phandle(of_node, "qcom,flash-source", i); if (!flash_src_node) { pr_err("flash_src_node NULL\n"); continue; } rc = of_property_read_string(flash_src_node, "linux,default-trigger", &fctrl->flash_trigger_name[i]); if (rc < 0) { pr_err("failed\n"); of_node_put(flash_src_node); continue; } CDBG("default trigger %s\n", fctrl->flash_trigger_name[i]); rc = of_property_read_u32(flash_src_node, "qcom,max-current", &fctrl->flash_op_current[i]); if (rc < 0) { pr_err("failed rc %d\n", rc); of_node_put(flash_src_node); continue; } of_node_put(flash_src_node); CDBG("max_current[%d] %d\n", i, fctrl->flash_op_current[i]); led_trigger_register_simple( fctrl->flash_trigger_name[i], &fctrl->flash_trigger[i]); } } else { /*Handle LED Flash Ctrl by GPIO*/ flashdata->gpio_conf = kzalloc(sizeof(struct msm_camera_gpio_conf), GFP_KERNEL); if (!flashdata->gpio_conf) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; return rc; } gconf = flashdata->gpio_conf; gpio_array_size = of_gpio_count(of_node); CDBG("%s gpio count %d\n", __func__, gpio_array_size); if (gpio_array_size) { gpio_array = kzalloc(sizeof(uint16_t) * gpio_array_size, GFP_KERNEL); if (!gpio_array) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; goto ERROR4; } for (i = 0; i < gpio_array_size; i++) { gpio_array[i] = of_get_gpio(of_node, i); CDBG("%s gpio_array[%d] = %d\n", __func__, i, gpio_array[i]); } rc = msm_sensor_get_dt_gpio_req_tbl(of_node, gconf, gpio_array, gpio_array_size); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR4; } rc = msm_sensor_get_dt_gpio_set_tbl(of_node, gconf, gpio_array, gpio_array_size); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR5; } rc = msm_flash_init_gpio_pin_tbl(of_node, gconf, gpio_array, gpio_array_size, fctrl); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR6; } } flashdata->slave_info = kzalloc(sizeof(struct msm_camera_slave_info), GFP_KERNEL); if (!flashdata->slave_info) { pr_err("%s failed %d\n", __func__, __LINE__); rc = -ENOMEM; goto ERROR8; } rc = of_property_read_u32_array(of_node, "qcom,slave-id", id_info, 3); if (rc < 0) { pr_err("%s failed %d\n", __func__, __LINE__); goto ERROR9; } /* Fix me - Currently for I2c framework is looking for 7-bit device node entry in dts. But the camera led framework for i2c slaves is looking for 8 bit address.So added a shift. Need to fix this.*/ if (fctrl->flash_device_type == MSM_CAMERA_I2C_DEVICE) { fctrl->flashdata->slave_info->sensor_slave_addr = id_info[0] << 1; } else { fctrl->flashdata->slave_info->sensor_slave_addr = id_info[0]; } fctrl->flashdata->slave_info->sensor_id_reg_addr = id_info[1]; fctrl->flashdata->slave_info->sensor_id = id_info[2]; kfree(gpio_array); return rc; ERROR9: kfree(fctrl->flashdata->slave_info); ERROR8: kfree(fctrl->flashdata->gpio_conf->gpio_num_info); ERROR6: kfree(gconf->cam_gpio_set_tbl); ERROR5: kfree(gconf->cam_gpio_req_tbl); ERROR4: kfree(gconf); ERROR1: kfree(fctrl->flashdata); kfree(gpio_array); } return rc; }