Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #include <linux/videodev2.h> |
2 | #include <linux/i2c.h> | |
3 | #include <linux/platform_device.h> | |
4 | #include <linux/delay.h> | |
5 | #include <linux/cdev.h> | |
6 | #include <linux/uaccess.h> | |
7 | #include <linux/fs.h> | |
8 | #include <asm/atomic.h> | |
9 | #include <linux/xlog.h> | |
10 | ||
11 | #include "kd_camera_hw.h" | |
12 | ||
13 | #include "kd_imgsensor.h" | |
14 | #include "kd_imgsensor_define.h" | |
15 | #include "kd_camera_feature.h" | |
16 | ||
17 | /****************************************************************************** | |
18 | * Debug configuration | |
19 | ******************************************************************************/ | |
20 | #define PFX "[kd_camera_hw]" | |
21 | #define PK_DBG_NONE(fmt, arg...) do {} while (0) | |
22 | #define PK_DBG_FUNC(fmt, arg...) xlog_printk(ANDROID_LOG_INFO, PFX , fmt, ##arg) | |
23 | ||
24 | #define DEBUG_CAMERA_HW_K | |
25 | #ifdef DEBUG_CAMERA_HW_K | |
26 | #define PK_DBG PK_DBG_FUNC | |
27 | #define PK_ERR(fmt, arg...) xlog_printk(ANDROID_LOG_ERR, PFX , fmt, ##arg) | |
28 | #define PK_XLOG_INFO(fmt, args...) \ | |
29 | do { \ | |
30 | xlog_printk(ANDROID_LOG_INFO, PFX , fmt, ##arg); \ | |
31 | } while(0) | |
32 | #else | |
33 | #define PK_DBG(a,...) | |
34 | #define PK_ERR(a,...) | |
35 | #define PK_XLOG_INFO(fmt, args...) | |
36 | #endif | |
37 | ||
38 | ||
39 | ||
40 | int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSensorName, BOOL On, char* mode_name) | |
41 | { | |
42 | #if !defined (MTK_ALPS_BOX_SUPPORT) | |
43 | ||
44 | u32 pinSetIdx = 0;//default main sensor | |
45 | ||
46 | #define IDX_PS_CMRST 0 | |
47 | #define IDX_PS_CMPDN 4 | |
48 | ||
49 | #define IDX_PS_MODE 1 | |
50 | #define IDX_PS_ON 2 | |
51 | #define IDX_PS_OFF 3 | |
52 | ||
53 | ||
54 | u32 pinSet[2][8] = { | |
55 | //for main sensor | |
56 | {GPIO_CAMERA_CMRST_PIN, | |
57 | GPIO_CAMERA_CMRST_PIN_M_GPIO, /* mode */ | |
58 | GPIO_OUT_ONE, /* ON state */ | |
59 | GPIO_OUT_ZERO, /* OFF state */ | |
60 | GPIO_CAMERA_CMPDN_PIN, | |
61 | GPIO_CAMERA_CMPDN_PIN_M_GPIO, | |
62 | GPIO_OUT_ONE, | |
63 | GPIO_OUT_ZERO, | |
64 | }, | |
65 | //for sub sensor | |
66 | {GPIO_CAMERA_CMRST1_PIN, | |
67 | GPIO_CAMERA_CMRST1_PIN_M_GPIO, | |
68 | GPIO_OUT_ONE, | |
69 | GPIO_OUT_ZERO, | |
70 | GPIO_CAMERA_CMPDN1_PIN, | |
71 | GPIO_CAMERA_CMPDN1_PIN_M_GPIO, | |
72 | GPIO_OUT_ONE, | |
73 | GPIO_OUT_ZERO, | |
74 | }, | |
75 | }; | |
76 | ||
77 | if (DUAL_CAMERA_MAIN_SENSOR == SensorIdx){ | |
78 | pinSetIdx = 0; | |
79 | } | |
80 | else if (DUAL_CAMERA_SUB_SENSOR == SensorIdx) { | |
81 | pinSetIdx = 1; | |
82 | } | |
83 | ||
84 | //power ON | |
4b9e9796 S |
85 | if (On) { |
86 | ||
6fa3eb70 S |
87 | PK_DBG("kdCISModulePowerOn -on:currSensorName=%s;\n",currSensorName); |
88 | PK_DBG("kdCISModulePowerOn -on:pinSetIdx=%d\n",pinSetIdx); | |
4b9e9796 S |
89 | |
90 | if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)||0 == strcmp(SENSOR_DRVNAME_OV56702ND_MIPI_RAW,currSensorName))){ | |
91 | ||
92 | if (pinSetIdx == 0){ | |
93 | //PDN pin | |
94 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
95 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
96 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ZERO)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
97 | ||
98 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name)) | |
99 | { | |
100 | PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n"); | |
101 | } | |
102 | ||
103 | mdelay(10); | |
104 | ||
105 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");} | |
106 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
107 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_OUT_ONE)){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
108 | ||
109 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name)) | |
110 | { | |
111 | PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
112 | } | |
113 | ||
114 | mdelay(10); | |
115 | ||
116 | ||
117 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1200,mode_name)) | |
118 | { | |
119 | PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
120 | } | |
121 | mdelay(10); | |
122 | ||
123 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ONE)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
124 | ||
125 | } | |
126 | }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW ,currSensorName))) { | |
127 | ||
128 | if (pinSetIdx == 1){ | |
129 | { | |
130 | //PDN pin | |
131 | // if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");} | |
132 | // if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
133 | // if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
134 | // mdelay(10); | |
135 | // if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
136 | // mdelay(5); | |
137 | ||
138 | //RST pin | |
139 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
140 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
141 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
142 | mdelay(10); | |
143 | } | |
144 | ||
145 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name)) | |
146 | { | |
147 | PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n"); | |
148 | goto _kdCISModulePowerOn_exit_; | |
149 | } | |
150 | ||
151 | msleep(10); | |
152 | ||
153 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name)) | |
154 | { | |
155 | PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n"); | |
156 | goto _kdCISModulePowerOn_exit_; | |
157 | } | |
158 | ||
159 | //if(TRUE != hwPowerOn(PMIC_APP_MAIN_CAMERA_POWER_D, VOL_1500,mode_name)) | |
160 | // { | |
161 | // PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
162 | // goto _kdCISModulePowerOn_exit_; | |
163 | // } | |
164 | ||
165 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
166 | ||
167 | // wait power to be stable | |
168 | mdelay(10); | |
169 | } | |
170 | ||
171 | }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2355_MIPI_RAW ,currSensorName))) { | |
172 | ||
173 | if (pinSetIdx == 1){ | |
174 | //PDN pin | |
175 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");} | |
176 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
177 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
178 | ||
179 | //RST pin | |
180 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
181 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
182 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
183 | mdelay(10); | |
184 | ||
185 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name)) | |
186 | { | |
187 | PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n"); | |
188 | goto _kdCISModulePowerOn_exit_; | |
189 | } | |
190 | ||
191 | ||
192 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1800,mode_name)) | |
193 | { | |
194 | PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
195 | goto _kdCISModulePowerOn_exit_; | |
196 | } | |
197 | ||
198 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name)) | |
199 | { | |
200 | PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n"); | |
201 | goto _kdCISModulePowerOn_exit_; | |
202 | } | |
203 | ||
204 | ||
205 | mdelay(5); | |
206 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
207 | ||
208 | mdelay(5); | |
209 | ||
210 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST], pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
211 | ||
212 | // wait power to be stable | |
213 | mdelay(10); | |
214 | ||
215 | } | |
216 | ||
217 | } | |
218 | ||
219 | ||
220 | }else {//power OFF | |
221 | ||
222 | if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)||0 == strcmp(SENSOR_DRVNAME_OV56702ND_MIPI_RAW,currSensorName))){ | |
223 | ||
224 | if (pinSetIdx == 0){ | |
225 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
226 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
227 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor | |
228 | ||
229 | mdelay(5); | |
230 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D, mode_name)) { | |
231 | PK_DBG("[CAMERA SENSOR] Fail to OFF d digital power\n"); | |
232 | } | |
233 | mdelay(5); | |
234 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name)) | |
235 | { | |
236 | PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n"); | |
237 | } | |
238 | ||
239 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");} | |
240 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
241 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module | |
242 | mdelay(5); | |
243 | ||
244 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) { | |
245 | PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n"); | |
246 | } | |
247 | } | |
248 | ||
249 | ||
250 | } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW,currSensorName))){ | |
251 | ||
252 | if (pinSetIdx == 1){ | |
253 | if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) { | |
254 | ||
255 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
256 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
257 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor | |
258 | ||
259 | } | |
260 | ||
261 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) { | |
262 | PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n"); | |
263 | } | |
264 | mdelay(5); | |
265 | ||
266 | ||
267 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name)) | |
268 | { | |
269 | PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n"); | |
270 | } | |
271 | } | |
272 | } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2355_MIPI_RAW,currSensorName))){ | |
273 | ||
274 | if (pinSetIdx == 1){ | |
275 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");} | |
276 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
277 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN], pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
278 | ||
279 | mdelay(5); | |
280 | ||
281 | if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) { | |
282 | ||
283 | if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");} | |
284 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
285 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor | |
286 | ||
287 | } | |
288 | ||
289 | mdelay(5); | |
290 | ||
291 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) { | |
292 | PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n"); | |
293 | } | |
294 | ||
295 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D,mode_name)) | |
296 | { | |
297 | PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n"); | |
298 | } | |
299 | ||
300 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name)) | |
301 | { | |
302 | PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n"); | |
303 | } | |
304 | } | |
305 | } | |
306 | ||
307 | ||
308 | }// | |
309 | ||
6fa3eb70 S |
310 | #endif /* end of defined MTK_ALPS_BOX_SUPPORT */ |
311 | ||
312 | return 0; | |
313 | ||
314 | _kdCISModulePowerOn_exit_: | |
315 | return -EIO; | |
316 | } | |
317 | ||
318 | EXPORT_SYMBOL(kdCISModulePowerOn); | |
319 | ||
320 | ||
321 | //!-- | |
322 | // | |
323 | ||
324 | ||
325 | ||
326 |