blob: d69ff4779be637aa5874fec9755c675547cc9217 [file] [log] [blame]
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -08001/* 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
16int32_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 Zalacbb5a382017-07-17 19:06:42 -070025 CAM_ERR(CAM_SENSOR, "Invalid Args");
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080026 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 Zalaa431ad62017-04-27 12:44:36 -070032 } 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 Thotakurab7ac3752017-02-27 15:00:51 -080036 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -070037 CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d",
38 io_master_info->master_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080039 return -EINVAL;
40 }
41}
42
43int32_t camera_io_dev_read(struct camera_io_master *io_master_info,
44 uint32_t addr, uint32_t *data,
Jigarkumar Zala2bb81642017-06-05 15:10:01 -070045 enum camera_sensor_i2c_type addr_type,
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080046 enum camera_sensor_i2c_type data_type)
47{
48 if (!io_master_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -070049 CAM_ERR(CAM_SENSOR, "Invalid Args");
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080050 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 Zala2bb81642017-06-05 15:10:01 -070055 addr, data, addr_type, data_type);
Jigarkumar Zalaa431ad62017-04-27 12:44:36 -070056 } 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 Veenam2ad8de12017-04-04 18:56:22 +053059 } else if (io_master_info->master_type == SPI_MASTER) {
60 return cam_spi_read(io_master_info,
Jigarkumar Zala80a11402017-09-05 16:14:59 -070061 addr, data, addr_type, data_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080062 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -070063 CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d",
64 io_master_info->master_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080065 return -EINVAL;
66 }
Vivek Veenam2ad8de12017-04-04 18:56:22 +053067 return 0;
68}
69
70int32_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 Zala80a11402017-09-05 16:14:59 -070081 return cam_spi_read_seq(io_master_info,
82 addr, data, addr_type, num_bytes);
Vivek Veenam2ad8de12017-04-04 18:56:22 +053083 } 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 Thotakurab7ac3752017-02-27 15:00:51 -080089}
90
91int32_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 Zalacbb5a382017-07-17 19:06:42 -070095 CAM_ERR(CAM_SENSOR,
96 "Input parameters not valid ws: %pK ioinfo: %pK",
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -080097 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 Zalaa431ad62017-04-27 12:44:36 -0700104 } else if (io_master_info->master_type == I2C_MASTER) {
105 return cam_qup_i2c_write_table(io_master_info,
106 write_setting);
Jigarkumar Zalaae152332017-07-18 17:21:48 -0700107 } else if (io_master_info->master_type == SPI_MASTER) {
108 return cam_spi_write_table(io_master_info,
109 write_setting);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800110 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700111 CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d",
112 io_master_info->master_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800113 return -EINVAL;
114 }
115}
116
Karthik Anantha Ram0fb02a32017-08-23 11:52:50 -0700117int32_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 Zala75fd4252017-11-14 12:44:58 -0800132 return cam_qup_i2c_write_continuous_table(io_master_info,
133 write_setting, cam_sensor_i2c_write_flag);
Karthik Anantha Ram0fb02a32017-08-23 11:52:50 -0700134 } 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 Thotakurab7ac3752017-02-27 15:00:51 -0800144int32_t camera_io_init(struct camera_io_master *io_master_info)
145{
146 if (!io_master_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700147 CAM_ERR(CAM_SENSOR, "Invalid Args");
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800148 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 Zala80a11402017-09-05 16:14:59 -0700156 } else if ((io_master_info->master_type == I2C_MASTER) ||
157 (io_master_info->master_type == SPI_MASTER)) {
158 return 0;
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800159 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700160 CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d",
161 io_master_info->master_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800162 return -EINVAL;
163 }
164}
165
166int32_t camera_io_release(struct camera_io_master *io_master_info)
167{
168 if (!io_master_info) {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700169 CAM_ERR(CAM_SENSOR, "Invalid Args");
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800170 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 Ramb1d35b32017-10-02 14:00:36 -0700176 } else if ((io_master_info->master_type == I2C_MASTER) ||
177 (io_master_info->master_type == SPI_MASTER)) {
178 return 0;
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800179 } else {
Jigarkumar Zalacbb5a382017-07-17 19:06:42 -0700180 CAM_ERR(CAM_SENSOR, "Invalid Comm. Master:%d",
181 io_master_info->master_type);
Viswanadha Raju Thotakurab7ac3752017-02-27 15:00:51 -0800182 return -EINVAL;
183 }
184}