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>
17 #include <linux/preempt.h>
18 #include <mach/board.h>
19 #include <linux/miscdevice.h>
21 struct spi_device* g_icatch_spi_dev = NULL;
24 static struct rk29xx_spi_chip spi_icatch = {
28 //user must define this struct according to hardware config
29 static struct spi_board_info board_spi_icatch_devices[] = {
31 .modalias = "spi_icatch",
32 .bus_num = 0, //0 or 1
33 .max_speed_hz = 24*1000*1000,
36 .controller_data = &spi_icatch,
42 static int __devinit spi_icatch_probe(struct spi_device *spi)
44 struct spi_test_data *spi_test_data;
47 spi->bits_per_word = 8;
48 spi->mode = SPI_MODE_0;
51 dev_err(spi, "ERR: fail to setup spi\n");
55 g_icatch_spi_dev = spi;
57 printk("%s:bus_num=%d,ok\n",__func__,spi->master->bus_num);
64 static struct spi_driver spi_icatch_driver = {
71 .probe = spi_icatch_probe,
74 static struct miscdevice spi_test_icatch = {
75 .minor = MISC_DYNAMIC_MINOR,
76 .name = "spi_misc_icatch",
79 static int __init spi_icatch_init(void)
81 spi_register_board_info(board_spi_icatch_devices, ARRAY_SIZE(board_spi_icatch_devices));
83 misc_register(&spi_test_icatch);
84 return spi_register_driver(&spi_icatch_driver);
87 static void __exit spi_icatch_exit(void)
90 misc_deregister(&spi_test_icatch);
91 return spi_unregister_driver(&spi_icatch_driver);
94 module_init(spi_icatch_init);
95 module_exit(spi_icatch_exit);
99 Simple camera device registration:
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
109 Comprehensive camera device registration:
111 new_camera_device_ex(sensor_name,\
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
119 pwdn_active,\ // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
121 res,\ // sensor resolution, this is real resolution or resoltuion after interpolate
124 i2c_spd,\ // i2c speed , 100000 = 100KHz
125 i2c_addr,\ // the i2c slave device address for sensor
127 mclk)\ // sensor input clock rate, 24 or 48
130 static struct rkcamera_platform_data new_camera[] = {
131 new_camera_device_ex(RK29_CAM_ISP_ICATCH7002_OV5693,
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
139 0x1, // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
141 CONS(RK29_CAM_ISP_ICATCH7002_OV5693,_FULL_RESOLUTION), // sensor resolution, this is real resolution or resoltuion after interpolate
144 300000, // i2c speed , 100000 = 100KHz
145 CONS(RK29_CAM_ISP_ICATCH7002_OV5693,_I2C_ADDR), // the i2c slave device address for sensor
147 24), // sensor input clock rate, 24 or 48
148 new_camera_device_ex(RK29_CAM_ISP_ICATCH7002_MI1040, //RK29_CAM_ISP_ICATCH7002_MI1040,
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
156 0x1, // sensor power down active level, is equal to CONFIG_SENSOR_POWERDNACTIVE_LEVEL_X
158 CONS(RK29_CAM_ISP_ICATCH7002_MI1040,_FULL_RESOLUTION), // sensor resolution, this is real resolution or resoltuion after interpolate
161 300000, // i2c speed , 100000 = 100KHz
162 CONS(RK29_CAM_ISP_ICATCH7002_MI1040,_I2C_ADDR), // the i2c slave device address for sensor
164 24), // sensor input clock rate, 24 or 48
165 new_camera_device_end
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 ---------*/
172 #define PMEM_CAM_SIZE PMEM_CAM_NECESSARY
173 /*****************************************************************************************
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
183 static void rk_cif_power(struct rk29camera_gpio_res *res,int on)
185 struct regulator *ldo_18,*ldo_28;
186 int camera_reset = res->gpio_reset;
187 int camera_pwrdn = res->gpio_powerdown;
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");
197 while(regulator_is_enabled(ldo_28)>0)
198 regulator_disable(ldo_28);
199 regulator_put(ldo_28);
201 while(regulator_is_enabled(ldo_18)>0)
202 regulator_disable(ldo_18);
205 iomux_set(GPIO1_A5) ;
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);
219 printk("%s off ldo5 vcc18_cif=%dmV end\n", __func__, regulator_get_voltage(ldo_18));
220 regulator_put(ldo_18);
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);
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);
233 gpio_set_value(RK30_PIN1_PA6,1); //Vincent_Liu@asus.com for clk 24M
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);
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);
249 #if CONFIG_SENSOR_RESET_IOCTL_USR
250 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
252 //#error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
254 int camera_reset = res->gpio_reset;
255 int camera_ioflag = res->gpio_flag;
256 int camera_io_init = res->gpio_init;
259 if (camera_reset != INVALID_GPIO) {
260 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
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));
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));
278 ret = RK29_CAM_EIO_REQUESTFAIL;
279 printk("%s ResetPin=%d request failed!", res->dev_name,camera_reset);
282 ret = RK29_CAM_EIO_INVALID;
289 #if CONFIG_SENSOR_POWER_IOCTL_USR
290 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
292 //#error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
293 rk_cif_power(res,on);
298 #if CONFIG_SENSOR_FLASH_IOCTL_USR
299 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
301 #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
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,
309 .sensor_power_cb = NULL,
312 #if CONFIG_SENSOR_RESET_IOCTL_USR
313 .sensor_reset_cb = sensor_reset_usr_cb,
315 .sensor_reset_cb = NULL,
318 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
319 .sensor_powerdown_cb = sensor_powerdown_usr_cb,
321 .sensor_powerdown_cb = NULL,
324 #if CONFIG_SENSOR_FLASH_IOCTL_USR
325 .sensor_flash_cb = sensor_flash_usr_cb,
327 .sensor_flash_cb = NULL,
330 static rk_sensor_user_init_data_s rk_init_data_sensor[RK_CAM_NUM] ;
331 #include "../../../drivers/media/video/rk30_camera.c"
333 #endif /* CONFIG_VIDEO_RK29 */