Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -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 "cam_sensor_io.h" |
| 14 | #include "cam_sensor_i2c.h" |
| 15 | |
| 16 | int32_t camera_io_dev_poll(struct camera_io_master *io_master_info, |
| 17 | uint32_t addr, uint16_t data, uint32_t data_mask, |
| 18 | enum camera_sensor_i2c_type data_type, |
| 19 | enum camera_sensor_i2c_type addr_type, |
| 20 | uint32_t delay_ms) |
| 21 | { |
| 22 | int16_t mask = data_mask & 0xFF; |
| 23 | |
| 24 | if (!io_master_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 25 | CAM_ERR(CAM_SENSOR, "Invalid Args"); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 26 | return -EINVAL; |
| 27 | } |
| 28 | |
| 29 | if (io_master_info->master_type == CCI_MASTER) { |
| 30 | return cam_cci_i2c_poll(io_master_info->cci_client, |
| 31 | addr, data, mask, data_type, addr_type, delay_ms); |
Jigarkumar Zala | a431ad6 | 2017-04-27 12:44:36 -0700 | [diff] [blame] | 32 | } else if (io_master_info->master_type == I2C_MASTER) { |
| 33 | return cam_qup_i2c_poll(io_master_info->client, |
| 34 | addr, data, data_mask, addr_type, data_type, |
| 35 | delay_ms); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 36 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 37 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 38 | io_master_info->master_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 39 | return -EINVAL; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | int32_t camera_io_dev_read(struct camera_io_master *io_master_info, |
| 44 | uint32_t addr, uint32_t *data, |
Jigarkumar Zala | 2bb8164 | 2017-06-05 15:10:01 -0700 | [diff] [blame] | 45 | enum camera_sensor_i2c_type addr_type, |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 46 | enum camera_sensor_i2c_type data_type) |
| 47 | { |
| 48 | if (!io_master_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 49 | CAM_ERR(CAM_SENSOR, "Invalid Args"); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 50 | return -EINVAL; |
| 51 | } |
| 52 | |
| 53 | if (io_master_info->master_type == CCI_MASTER) { |
| 54 | return cam_cci_i2c_read(io_master_info->cci_client, |
Jigarkumar Zala | 2bb8164 | 2017-06-05 15:10:01 -0700 | [diff] [blame] | 55 | addr, data, addr_type, data_type); |
Jigarkumar Zala | a431ad6 | 2017-04-27 12:44:36 -0700 | [diff] [blame] | 56 | } else if (io_master_info->master_type == I2C_MASTER) { |
| 57 | return cam_qup_i2c_read(io_master_info->client, |
| 58 | addr, data, addr_type, data_type); |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 59 | } else if (io_master_info->master_type == SPI_MASTER) { |
| 60 | return cam_spi_read(io_master_info, |
Jigarkumar Zala | 80a1140 | 2017-09-05 16:14:59 -0700 | [diff] [blame] | 61 | addr, data, addr_type, data_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 62 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 63 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 64 | io_master_info->master_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 65 | return -EINVAL; |
| 66 | } |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int32_t camera_io_dev_read_seq(struct camera_io_master *io_master_info, |
| 71 | uint32_t addr, uint8_t *data, |
| 72 | enum camera_sensor_i2c_type addr_type, int32_t num_bytes) |
| 73 | { |
| 74 | if (io_master_info->master_type == CCI_MASTER) { |
| 75 | return cam_camera_cci_i2c_read_seq(io_master_info->cci_client, |
| 76 | addr, data, addr_type, num_bytes); |
| 77 | } else if (io_master_info->master_type == I2C_MASTER) { |
| 78 | return cam_qup_i2c_read_seq(io_master_info->client, |
| 79 | addr, data, addr_type, num_bytes); |
| 80 | } else if (io_master_info->master_type == SPI_MASTER) { |
Jigarkumar Zala | 80a1140 | 2017-09-05 16:14:59 -0700 | [diff] [blame] | 81 | return cam_spi_read_seq(io_master_info, |
| 82 | addr, data, addr_type, num_bytes); |
Vivek Veenam | 2ad8de1 | 2017-04-04 18:56:22 +0530 | [diff] [blame] | 83 | } else { |
| 84 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 85 | io_master_info->master_type); |
| 86 | return -EINVAL; |
| 87 | } |
| 88 | return 0; |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | int32_t camera_io_dev_write(struct camera_io_master *io_master_info, |
| 92 | struct cam_sensor_i2c_reg_setting *write_setting) |
| 93 | { |
| 94 | if (!write_setting || !io_master_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 95 | CAM_ERR(CAM_SENSOR, |
| 96 | "Input parameters not valid ws: %pK ioinfo: %pK", |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 97 | write_setting, io_master_info); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
| 101 | if (io_master_info->master_type == CCI_MASTER) { |
| 102 | return cam_cci_i2c_write_table(io_master_info, |
| 103 | write_setting); |
Jigarkumar Zala | a431ad6 | 2017-04-27 12:44:36 -0700 | [diff] [blame] | 104 | } else if (io_master_info->master_type == I2C_MASTER) { |
| 105 | return cam_qup_i2c_write_table(io_master_info, |
| 106 | write_setting); |
Jigarkumar Zala | ae15233 | 2017-07-18 17:21:48 -0700 | [diff] [blame] | 107 | } else if (io_master_info->master_type == SPI_MASTER) { |
| 108 | return cam_spi_write_table(io_master_info, |
| 109 | write_setting); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 110 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 111 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 112 | io_master_info->master_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 113 | return -EINVAL; |
| 114 | } |
| 115 | } |
| 116 | |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 117 | int32_t camera_io_dev_write_continuous(struct camera_io_master *io_master_info, |
| 118 | struct cam_sensor_i2c_reg_setting *write_setting, |
| 119 | uint8_t cam_sensor_i2c_write_flag) |
| 120 | { |
| 121 | if (!write_setting || !io_master_info) { |
| 122 | CAM_ERR(CAM_SENSOR, |
| 123 | "Input parameters not valid ws: %pK ioinfo: %pK", |
| 124 | write_setting, io_master_info); |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | |
| 128 | if (io_master_info->master_type == CCI_MASTER) { |
| 129 | return cam_cci_i2c_write_continuous_table(io_master_info, |
| 130 | write_setting, cam_sensor_i2c_write_flag); |
| 131 | } else if (io_master_info->master_type == I2C_MASTER) { |
Jigarkumar Zala | 75fd425 | 2017-11-14 12:44:58 -0800 | [diff] [blame] | 132 | return cam_qup_i2c_write_continuous_table(io_master_info, |
| 133 | write_setting, cam_sensor_i2c_write_flag); |
Karthik Anantha Ram | 0fb02a3 | 2017-08-23 11:52:50 -0700 | [diff] [blame] | 134 | } else if (io_master_info->master_type == SPI_MASTER) { |
| 135 | return cam_spi_write_table(io_master_info, |
| 136 | write_setting); |
| 137 | } else { |
| 138 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 139 | io_master_info->master_type); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | } |
| 143 | |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 144 | int32_t camera_io_init(struct camera_io_master *io_master_info) |
| 145 | { |
| 146 | if (!io_master_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 147 | CAM_ERR(CAM_SENSOR, "Invalid Args"); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 148 | return -EINVAL; |
| 149 | } |
| 150 | |
| 151 | if (io_master_info->master_type == CCI_MASTER) { |
| 152 | io_master_info->cci_client->cci_subdev = |
| 153 | cam_cci_get_subdev(); |
| 154 | return cam_sensor_cci_i2c_util(io_master_info->cci_client, |
| 155 | MSM_CCI_INIT); |
Jigarkumar Zala | 80a1140 | 2017-09-05 16:14:59 -0700 | [diff] [blame] | 156 | } else if ((io_master_info->master_type == I2C_MASTER) || |
| 157 | (io_master_info->master_type == SPI_MASTER)) { |
| 158 | return 0; |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 159 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 160 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 161 | io_master_info->master_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 162 | return -EINVAL; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | int32_t camera_io_release(struct camera_io_master *io_master_info) |
| 167 | { |
| 168 | if (!io_master_info) { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 169 | CAM_ERR(CAM_SENSOR, "Invalid Args"); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 170 | return -EINVAL; |
| 171 | } |
| 172 | |
| 173 | if (io_master_info->master_type == CCI_MASTER) { |
| 174 | return cam_sensor_cci_i2c_util(io_master_info->cci_client, |
| 175 | MSM_CCI_RELEASE); |
Karthik Anantha Ram | b1d35b3 | 2017-10-02 14:00:36 -0700 | [diff] [blame] | 176 | } else if ((io_master_info->master_type == I2C_MASTER) || |
| 177 | (io_master_info->master_type == SPI_MASTER)) { |
| 178 | return 0; |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 179 | } else { |
Jigarkumar Zala | cbb5a38 | 2017-07-17 19:06:42 -0700 | [diff] [blame] | 180 | CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d", |
| 181 | io_master_info->master_type); |
Viswanadha Raju Thotakura | b7ac375 | 2017-02-27 15:00:51 -0800 | [diff] [blame] | 182 | return -EINVAL; |
| 183 | } |
| 184 | } |