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 | |
85 | if (On) { | |
86 | ||
87 | PK_DBG("kdCISModulePowerOn -on:currSensorName=%s;\n",currSensorName); | |
88 | PK_DBG("kdCISModulePowerOn -on:pinSetIdx=%d\n",pinSetIdx); | |
89 | ||
90 | if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName))){ | |
91 | ||
92 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name)) | |
93 | { | |
94 | PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n"); | |
95 | } | |
96 | ||
97 | mdelay(10); | |
98 | ||
99 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1800,mode_name)) | |
100 | { | |
101 | PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
102 | } | |
103 | mdelay(10); | |
104 | ||
105 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name)) | |
106 | { | |
107 | PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
108 | } | |
109 | mdelay(10); | |
110 | ||
111 | ||
112 | PK_DBG("SENSOR_DRVNAME_OV5670_MIPI_RAW power!! \n"); | |
113 | 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");} | |
114 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
115 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ZERO)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
116 | mdelay(10); | |
117 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_OUT_ONE)){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} | |
118 | mdelay(1); | |
119 | ||
120 | //PDN pin | |
121 | 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");} | |
122 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
123 | if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_OUT_ONE)){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} | |
124 | }else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_RAW ,currSensorName))) { | |
125 | ||
126 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800, mode_name)) | |
127 | { | |
128 | PK_DBG("[CAMERA SENSOR] Fail to enable IO power\n"); | |
129 | goto _kdCISModulePowerOn_exit_; | |
130 | } | |
131 | { | |
132 | //PDN pin | |
133 | 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");} | |
134 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN], GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
135 | 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");} | |
136 | mdelay(10); | |
137 | 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");} | |
138 | mdelay(5); | |
139 | ||
140 | //RST pin | |
141 | 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");} | |
142 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST], GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
143 | 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");} | |
144 | mdelay(10); | |
145 | 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");} | |
146 | mdelay(5); | |
147 | } | |
148 | ||
149 | msleep(20); | |
150 | ||
151 | if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800, mode_name)) | |
152 | { | |
153 | PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n"); | |
154 | goto _kdCISModulePowerOn_exit_; | |
155 | } | |
156 | ||
157 | //if(TRUE != hwPowerOn(PMIC_APP_MAIN_CAMERA_POWER_D, VOL_1500,mode_name)) | |
158 | // { | |
159 | // PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n"); | |
160 | // goto _kdCISModulePowerOn_exit_; | |
161 | // } | |
162 | ||
163 | ||
164 | // wait power to be stable | |
165 | mdelay(25); | |
166 | ||
167 | } | |
168 | }else {//power OFF | |
169 | ||
170 | //PK_DBG("[OFF]sensorIdx:%d \n",SensorIdx); | |
171 | if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) { | |
172 | 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");} | |
173 | 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");} | |
174 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");} | |
175 | if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");} | |
176 | 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 | |
177 | 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 | |
178 | } | |
179 | ||
180 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) { | |
181 | PK_DBG("[CAMERA SENSOR] Fail to OFF a power\n"); | |
182 | } | |
183 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A2,mode_name)){ | |
184 | PK_DBG("[CAMERA SENSOR] Fail to OFF a2 power\n"); | |
185 | } | |
186 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D, mode_name)) { | |
187 | PK_DBG("[CAMERA SENSOR] Fail to OFF d digital power\n"); | |
188 | } | |
189 | if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2,mode_name)) | |
190 | { | |
191 | PK_DBG("[CAMERA SENSOR] Fail to OFF d2 digital power\n"); | |
192 | } | |
193 | }// | |
194 | ||
195 | #endif /* end of defined MTK_ALPS_BOX_SUPPORT */ | |
196 | ||
197 | return 0; | |
198 | ||
199 | _kdCISModulePowerOn_exit_: | |
200 | return -EIO; | |
201 | } | |
202 | ||
203 | EXPORT_SYMBOL(kdCISModulePowerOn); | |
204 | ||
205 | ||
206 | //!-- | |
207 | // | |
208 | ||
209 | ||
210 | ||
211 |