rk3026: i2s add several attempts to double confirm i2s frac effect
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk3188 / board-rk3188-icatch7002-camera.c
1 #ifdef CONFIG_VIDEO_RK29
2 #include <plat/rk_camera.h>
3 #include "../../../drivers/spi/rk29_spim.h"
4 #include <linux/spi/spi.h>
5 #include <linux/dma-mapping.h>
6 #include <linux/interrupt.h>
7 #include <linux/highmem.h>
8 #include <linux/delay.h>
9 #include <linux/slab.h>
10 #include <linux/platform_device.h>
11 #include <linux/clk.h>
12 #include <linux/cpufreq.h>
13 #include <mach/gpio.h>
14 #include <mach/irqs.h>
15 #include <linux/miscdevice.h>
16 #include <asm/dma.h>
17 #include <linux/preempt.h>
18 #include <mach/board.h>
19 #include <linux/miscdevice.h>
20
21 struct spi_device* g_icatch_spi_dev = NULL;
22
23
24 static struct rk29xx_spi_chip spi_icatch = {
25         //.poll_mode = 1,
26         .enable_dma = 0,
27 };
28 //user must define this struct according to hardware config     
29 static struct spi_board_info board_spi_icatch_devices[] = {     
30         {
31                 .modalias  = "spi_icatch",
32                 .bus_num = 0,   //0 or 1
33                 .max_speed_hz  = 24*1000*1000,
34                 .chip_select   = 0, 
35                 .mode = SPI_MODE_0,
36                 .controller_data = &spi_icatch,
37         },      
38         
39 };
40
41
42 static int __devinit spi_icatch_probe(struct spi_device *spi)
43 {       
44         struct spi_test_data *spi_test_data;
45         int ret = 0;
46         
47         spi->bits_per_word = 8;
48         spi->mode = SPI_MODE_0;
49         ret = spi_setup(spi);
50         if (ret < 0){
51                 dev_err(spi, "ERR: fail to setup spi\n");
52                 return -1;
53         }       
54
55         g_icatch_spi_dev = spi;
56
57         printk("%s:bus_num=%d,ok\n",__func__,spi->master->bus_num);
58
59         return ret;
60
61 }
62
63
64 static struct spi_driver spi_icatch_driver = {
65         .driver = {
66                 .name           = "spi_icatch",
67                 .bus            = &spi_bus_type,
68                 .owner          = THIS_MODULE,
69         },
70
71         .probe          = spi_icatch_probe,
72 };
73
74 static struct miscdevice spi_test_icatch = {
75         .minor = MISC_DYNAMIC_MINOR,
76         .name = "spi_misc_icatch",
77 };
78
79 static int __init spi_icatch_init(void)
80 {       
81         spi_register_board_info(board_spi_icatch_devices, ARRAY_SIZE(board_spi_icatch_devices));
82         
83         misc_register(&spi_test_icatch);
84         return spi_register_driver(&spi_icatch_driver);
85 }
86
87 static void __exit spi_icatch_exit(void)
88 {
89         
90         misc_deregister(&spi_test_icatch);
91         return spi_unregister_driver(&spi_icatch_driver);
92 }
93
94 module_init(spi_icatch_init);
95 module_exit(spi_icatch_exit);
96
97 /* Notes:
98
99 Simple camera device registration:
100
101        new_camera_device(sensor_name,\       // sensor name, it is equal to CONFIG_SENSOR_X
102                           face,\              // sensor face information, it can be back or front
103                           pwdn_io,\           // power down gpio configuration, it is equal to CONFIG_SENSOR_POWERDN_PIN_XX
104                           flash_attach,\      // sensor is attach flash or not
105                           mir,\               // sensor image mirror and flip control information
106                           i2c_chl,\           // i2c channel which the sensor attached in hardware, it is equal to CONFIG_SENSOR_IIC_ADAPTER_ID_X
107                           cif_chl)  \         // cif channel which the sensor attached in hardware, it is equal to CONFIG_SENSOR_CIF_INDEX_X
108
109 Comprehensive camera device registration:
110
111       new_camera_device_ex(sensor_name,\
112                              face,\
113                              ori,\            // sensor orientation, it is equal to CONFIG_SENSOR_ORIENTATION_X
114                              pwr_io,\         // sensor power gpio configuration, it is equal to CONFIG_SENSOR_POWER_PIN_XX
115                              pwr_active,\     // sensor power active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
116                              rst_io,\         // sensor reset gpio configuration, it is equal to CONFIG_SENSOR_RESET_PIN_XX
117                              rst_active,\     // sensor reset active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
118                              pwdn_io,\
119                              pwdn_active,\    // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
120                              flash_attach,\
121                              res,\            // sensor resolution, this is real resolution or resoltuion after interpolate
122                              mir,\
123                              i2c_chl,\
124                              i2c_spd,\        // i2c speed , 100000 = 100KHz
125                              i2c_addr,\       // the i2c slave device address for sensor
126                              cif_chl,\
127                              mclk)\           // sensor input clock rate, 24 or 48
128                           
129 */
130 static struct rkcamera_platform_data new_camera[] = {
131   new_camera_device_ex(RK29_CAM_ISP_ICATCH7002_OV5693,
132                          back,
133                          180,            // sensor orientation, it is equal to CONFIG_SENSOR_ORIENTATION_X
134                          INVALID_VALUE,         // sensor power gpio configuration, it is equal to CONFIG_SENSOR_POWER_PIN_XX
135                          INVALID_VALUE,     // sensor power active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
136                          RK30_PIN0_PC1,         // sensor reset gpio configuration, it is equal to CONFIG_SENSOR_RESET_PIN_XX
137                          0x0,     // sensor reset active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
138                          RK30_PIN0_PC0,
139                          0x1,    // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
140                          INVALID_VALUE,
141                          CONS(RK29_CAM_ISP_ICATCH7002_OV5693,_FULL_RESOLUTION),            // sensor resolution, this is real resolution or resoltuion after interpolate
142                          0,
143                          3,
144                          300000,        // i2c speed , 100000 = 100KHz
145                          CONS(RK29_CAM_ISP_ICATCH7002_OV5693,_I2C_ADDR),       // the i2c slave device address for sensor
146                          0,
147                          24),           // sensor input clock rate, 24 or 48
148         new_camera_device_ex(RK29_CAM_ISP_ICATCH7002_MI1040, //RK29_CAM_ISP_ICATCH7002_MI1040,
149                          front,
150                          360,            // sensor orientation, it is equal to CONFIG_SENSOR_ORIENTATION_X
151                          INVALID_VALUE,         // sensor power gpio configuration, it is equal to CONFIG_SENSOR_POWER_PIN_XX
152                          INVALID_VALUE,     // sensor power active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
153                          RK30_PIN0_PC1,         // sensor reset gpio configuration, it is equal to CONFIG_SENSOR_RESET_PIN_XX
154                          0x0,     // sensor reset active level, is equal to CONFIG_SENSOR_RESETACTIVE_LEVEL_X
155                          RK30_PIN0_PC0,
156                          0x1,    // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
157                          INVALID_VALUE,
158                          CONS(RK29_CAM_ISP_ICATCH7002_MI1040,_FULL_RESOLUTION),            // sensor resolution, this is real resolution or resoltuion after interpolate
159                          0,
160                          3,
161                          300000,        // i2c speed , 100000 = 100KHz
162                          CONS(RK29_CAM_ISP_ICATCH7002_MI1040,_I2C_ADDR),       // the i2c slave device address for sensor
163                          0,
164                          24),           // sensor input clock rate, 24 or 48
165         new_camera_device_end  
166 };
167 #endif  //#ifdef CONFIG_VIDEO_RK29
168 /*---------------- Camera Sensor Configuration Macro End------------------------*/
169 #include "../../../drivers/media/video/rk30_camera.c"
170 /*---------------- Camera Sensor Macro Define End  ---------*/
171
172 #define PMEM_CAM_SIZE PMEM_CAM_NECESSARY
173 /*****************************************************************************************
174  * camera  devices
175  * author: ddl@rock-chips.com
176  *****************************************************************************************/
177 #ifdef CONFIG_VIDEO_RK29
178 #define CONFIG_SENSOR_POWER_IOCTL_USR      1 //define this refer to your board layout
179 #define CONFIG_SENSOR_RESET_IOCTL_USR      1
180 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR          0
181 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
182
183 static void rk_cif_power(struct rk29camera_gpio_res *res,int on)
184 {
185         struct regulator *ldo_18,*ldo_28;
186     int camera_reset = res->gpio_reset;
187     int camera_pwrdn = res->gpio_powerdown;
188
189           
190         ldo_28 = regulator_get(NULL, "ricoh_ldo8");     // vcc28_cif
191         ldo_18 = regulator_get(NULL, "ricoh_ldo5");     // vcc18_cif
192         if (ldo_28 == NULL || IS_ERR(ldo_28) || ldo_18 == NULL || IS_ERR(ldo_18)){
193                 printk("get cif ldo failed!\n");
194                 return;
195         }
196         if(on == 0){
197                 while(regulator_is_enabled(ldo_28)>0)   
198                         regulator_disable(ldo_28);
199                 regulator_put(ldo_28);
200
201                 while(regulator_is_enabled(ldo_18)>0)
202                         regulator_disable(ldo_18);
203
204                 iomux_set(GPIO1_A4);
205                 iomux_set(GPIO1_A5) ;
206                 iomux_set(GPIO1_A6);
207                 iomux_set(GPIO1_A7);
208                 iomux_set(GPIO3_B6);
209                 iomux_set(GPIO3_B7);
210                 iomux_set(GPIO0_C0);
211                 gpio_set_value(RK30_PIN1_PA4,0);
212                 gpio_set_value(RK30_PIN1_PA5,0);
213                 gpio_set_value(RK30_PIN1_PA6,0);        // for clk 24M
214                 gpio_set_value(RK30_PIN1_PA7,0);
215                 gpio_set_value(RK30_PIN3_PB6,0);
216                 gpio_set_value(RK30_PIN3_PB7,0);
217                 gpio_set_value(RK30_PIN0_PC0,0);
218
219                 printk("%s off ldo5 vcc18_cif=%dmV end\n", __func__, regulator_get_voltage(ldo_18));
220                 regulator_put(ldo_18);
221                 
222         }
223         else{
224         // reset must be low
225         if (camera_reset != INVALID_GPIO) 
226                 gpio_set_value(camera_reset, 0);
227         printk("%s ResetPin=%d ..PinLevel = %x\n",res->dev_name,camera_reset,0);
228         //pwdn musb be low
229         if (camera_pwrdn != INVALID_GPIO) 
230                 gpio_set_value(camera_pwrdn, 0);
231         printk("%s PwrdnPin=%d ..PinLevel = %x\n",res->dev_name,camera_pwrdn,0);
232         
233                 gpio_set_value(RK30_PIN1_PA6,1);        //Vincent_Liu@asus.com for clk 24M
234
235
236                 regulator_set_voltage(ldo_18, 1800000, 1800000);
237                 regulator_enable(ldo_18);
238                 printk("%s set ldo5 vcc18_cif=%dmV end\n", __func__, regulator_get_voltage(ldo_18));
239                 regulator_put(ldo_18);
240
241                 regulator_set_voltage(ldo_28, 2800000, 2800000);
242                 regulator_enable(ldo_28);
243                 //printk("%s set ldo7 vcc28_cif=%dmV end\n", __func__, regulator_get_voltage(ldo_28));
244                 regulator_put(ldo_28);
245
246         }
247 }
248
249 #if CONFIG_SENSOR_RESET_IOCTL_USR
250 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
251 {
252         //#error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
253                 
254     int camera_reset = res->gpio_reset;
255     int camera_ioflag = res->gpio_flag;
256     int camera_io_init = res->gpio_init;  
257     int ret = 0;
258     
259     if (camera_reset != INVALID_GPIO) {
260                 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
261                         if (on) {
262                         gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
263                         printk("%s ResetPin=%d ..PinLevel = %x\n",res->dev_name,camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
264                                 mdelay(6);
265                         } else {
266                                 gpio_set_value(camera_reset,(((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
267                         printk("%s ResetPin= %d..PinLevel = %x\n",res->dev_name, camera_reset, (((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
268                 mdelay(6);
269                         iomux_set(SPI0_CLK);
270                         iomux_set(SPI0_RXD);
271                         iomux_set(SPI0_TXD);
272                         iomux_set(SPI0_CS0);
273                         iomux_set(I2C3_SDA);
274                         iomux_set(I2C3_SCL);
275                 mdelay(6);
276                 }
277                 } else {
278                         ret = RK29_CAM_EIO_REQUESTFAIL;
279                         printk("%s ResetPin=%d request failed!", res->dev_name,camera_reset);
280                 }
281     } else {
282                 ret = RK29_CAM_EIO_INVALID;
283     }
284     return ret;
285
286 }
287 #endif
288
289 #if CONFIG_SENSOR_POWER_IOCTL_USR
290 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
291 {
292         //#error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
293         rk_cif_power(res,on);
294         return 0;
295 }
296 #endif
297
298 #if CONFIG_SENSOR_FLASH_IOCTL_USR
299 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
300 {
301         #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
302 }
303 #endif
304
305 static struct rk29camera_platform_ioctl_cb      sensor_ioctl_cb = {
306         #if CONFIG_SENSOR_POWER_IOCTL_USR
307         .sensor_power_cb = sensor_power_usr_cb,
308         #else
309         .sensor_power_cb = NULL,
310         #endif
311
312         #if CONFIG_SENSOR_RESET_IOCTL_USR
313         .sensor_reset_cb = sensor_reset_usr_cb,
314         #else
315         .sensor_reset_cb = NULL,
316         #endif
317
318         #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
319         .sensor_powerdown_cb = sensor_powerdown_usr_cb,
320         #else
321         .sensor_powerdown_cb = NULL,
322         #endif
323
324         #if CONFIG_SENSOR_FLASH_IOCTL_USR
325         .sensor_flash_cb = sensor_flash_usr_cb,
326         #else
327         .sensor_flash_cb = NULL,
328         #endif
329 };
330 static rk_sensor_user_init_data_s rk_init_data_sensor[RK_CAM_NUM] ;
331 #include "../../../drivers/media/video/rk30_camera.c"
332
333 #endif /* CONFIG_VIDEO_RK29 */