| /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 and |
| * only version 2 as published by the Free Software Foundation. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| */ |
| |
| #include <linux/of.h> |
| #include <linux/of_gpio.h> |
| #include <cam_sensor_cmn_header.h> |
| #include <cam_sensor_util.h> |
| #include <cam_sensor_io.h> |
| #include <cam_req_mgr_util.h> |
| |
| #include "cam_ois_soc.h" |
| #include "cam_debug_util.h" |
| |
| /** |
| * @e_ctrl: ctrl structure |
| * |
| * Parses ois dt |
| */ |
| static int cam_ois_get_dt_data(struct cam_ois_ctrl_t *o_ctrl) |
| { |
| int rc = 0; |
| struct cam_hw_soc_info *soc_info = &o_ctrl->soc_info; |
| struct cam_ois_soc_private *soc_private = |
| (struct cam_ois_soc_private *)o_ctrl->soc_info.soc_private; |
| struct cam_sensor_power_ctrl_t *power_info = &soc_private->power_info; |
| struct device_node *of_node = NULL; |
| |
| of_node = soc_info->dev->of_node; |
| |
| if (!of_node) { |
| CAM_ERR(CAM_OIS, "of_node is NULL, device type %d", |
| o_ctrl->ois_device_type); |
| return -EINVAL; |
| } |
| rc = cam_soc_util_get_dt_properties(soc_info); |
| if (rc < 0) { |
| CAM_ERR(CAM_OIS, "cam_soc_util_get_dt_properties rc %d", |
| rc); |
| return rc; |
| } |
| |
| if (!soc_info->gpio_data) { |
| CAM_INFO(CAM_OIS, "No GPIO found"); |
| return 0; |
| } |
| |
| if (!soc_info->gpio_data->cam_gpio_common_tbl_size) { |
| CAM_INFO(CAM_OIS, "No GPIO found"); |
| return -EINVAL; |
| } |
| |
| rc = cam_sensor_util_init_gpio_pin_tbl(soc_info, |
| &power_info->gpio_num_info); |
| if ((rc < 0) || (!power_info->gpio_num_info)) { |
| CAM_ERR(CAM_OIS, "No/Error OIS GPIOs"); |
| return -EINVAL; |
| } |
| |
| return rc; |
| } |
| /** |
| * @o_ctrl: ctrl structure |
| * |
| * This function is called from cam_ois_platform/i2c_driver_probe, it parses |
| * the ois dt node. |
| */ |
| int cam_ois_driver_soc_init(struct cam_ois_ctrl_t *o_ctrl) |
| { |
| int rc = 0; |
| struct cam_hw_soc_info *soc_info = &o_ctrl->soc_info; |
| struct device_node *of_node = NULL; |
| |
| if (!soc_info->dev) { |
| CAM_ERR(CAM_OIS, "soc_info is not initialized"); |
| return -EINVAL; |
| } |
| |
| of_node = soc_info->dev->of_node; |
| if (!of_node) { |
| CAM_ERR(CAM_OIS, "dev.of_node NULL"); |
| return -EINVAL; |
| } |
| |
| rc = of_property_read_u32(of_node, "cell-index", |
| &o_ctrl->subdev_id); |
| if (rc < 0) { |
| CAM_ERR(CAM_OIS, "failed rc %d", rc); |
| return rc; |
| } |
| |
| if (o_ctrl->ois_device_type == MSM_CAMERA_PLATFORM_DEVICE) { |
| rc = of_property_read_u32(of_node, "cci-master", |
| &o_ctrl->cci_i2c_master); |
| if (rc < 0) { |
| CAM_DBG(CAM_OIS, "failed rc %d", rc); |
| return rc; |
| } |
| } |
| |
| rc = cam_ois_get_dt_data(o_ctrl); |
| if (rc < 0) |
| CAM_DBG(CAM_OIS, "failed: ois get dt data rc %d", rc); |
| |
| return rc; |
| } |