static struct platform_driver rk_camera_driver =
{
.driver = {
.name = RK29_CAM_DRV_NAME,
},
.probe = rk_camera_probe,
.remove = __devexit_p(rk_camera_remove),
};
static int rk_camera_init_async(void *unused)
{
platform_driver_register(&rk_camera_driver);
return 0;
}
static int __devinit rk_camera_init(void)
{
kthread_run(rk_camera_init_async, NULL, "rk_camera_init");
return 0;
}
static void __exit rk_camera_exit(void)
{
platform_driver_unregister(&rk_camera_driver);
}
device_initcall_sync(rk_camera_init);
module_exit(rk_camera_exit);
static int rk_camera_probe(struct platform_device *pdev)
{
struct rk_camera_dev *pcdev;
…..
pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
…..
pcdev->soc_host.drv_name = RK29_CAM_DRV_NAME;
pcdev->soc_host.ops = &rk_soc_camera_host_ops;
pcdev->soc_host.priv = pcdev;
pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
pcdev->soc_host.nr = pdev->id;
err = soc_camera_host_register(&pcdev->soc_host); //系统需事先注册了"soc-camera-pdrv”设备,才会执行成功
if (err) {
RKCAMERA_TR("%s(%d): soc_camera_host_register failed\n",__FUNCTION__,__LINE__);
goto exit_free_irq;
}
…..
}
#define new_camera_device_ex(sensor_name,\
face,\
ori,\
pwr_io,\
pwr_active,\
rst_io,\
rst_active,\
pwdn_io,\
pwdn_active,\
flash_attach,\
res,\
mir,\
i2c_chl,\
i2c_spd,\
i2c_addr,\
cif_chl,\
mclk)\
{\
.dev = {\
.i2c_cam_info = {\
I2C_BOARD_INFO(STR(sensor_name), i2c_addr>>1),\
},\
.link_info = {\
.bus_id= RK29_CAM_PLATFORM_DEV_ID+cif_chl,\
.i2c_adapter_id = i2c_chl,\
.module_name = STR(sensor_name),\
},\
.device_info = {\
.name = "soc-camera-pdrv",\
.dev = {\
.init_name = STR(CONS(_CONS(sensor_name,_),face)),\
},\
},\
},\
.io = {\
.gpio_power = pwr_io,\
.gpio_reset = rst_io,\
.gpio_powerdown = pwdn_io,\
.gpio_af = INVALID_GPIO,\
.gpio_flash = INVALID_GPIO,\
.gpio_flag = ((pwr_active&0x01)<<RK29_CAM_POWERACTIVE_BITPOS)|((rst_active&0x01)<<RK29_CAM_RESETACTIVE_BITPOS)|((pwdn_active&0x01)<<RK29_CAM_POWERDNACTIVE_BITPOS),\
},\
.orientation = ori,\
.resolution = res,\
.mirror = mir,\
.i2c_rate = i2c_spd,\
.flash = flash_attach,\
.pwdn_info = ((pwdn_active&0x10)|0x01),\
.powerup_sequence = CONS(sensor_name,_PWRSEQ),\
.mclk_rate = mclk,\
}
static struct rkcamera_platform_data new_camera[] = {
new_camera_device_ex(RK29_CAM_SENSOR_ADV7180,
back,
0,
INVALID_VALUE,
INVALID_VALUE,
INVALID_VALUE,
INVALID_VALUE,
RK30_PIN1_PB5,
GPIO_LOW,
0,
0,
0,
3,
100000,
0x42,
0,
24),
new_camera_device_end
};
int rk_sensor_register(void)
{
int i;
i = 0;
while (strstr(new_camera[i].dev.device_info.dev.init_name,"end")==NULL) {
…..
new_camera[i].dev.link_info.board_info =&new_camera[i].dev.i2c_cam_info;
new_camera[i].dev.device_info.id = i+6;
new_camera[i].dev.device_info.dev.platform_data = &new_camera[i].dev.link_info;
…..
platform_device_register(&new_camera[i].dev.device_info);
}
return 0;
}
static struct rk29camera_platform_data rk_camera_platform_data = {
.io_init = rk_sensor_io_init,
.io_deinit = rk_sensor_io_deinit,
.iomux = rk_sensor_iomux,
.sensor_ioctrl = rk_sensor_ioctrl,
.sensor_register = rk_sensor_register,
...
.register_dev_new = new_camera,
}
/*platform_device : */
#if RK_SUPPORT_CIF0
struct platform_device rk_device_camera_host_0 = {
.name = RK29_CAM_DRV_NAME,
.id = RK_CAM_PLATFORM_DEV_ID_0, /* This is used to put cameras on this interface */
.num_resources = ARRAY_SIZE(rk_camera_resource_host_0),
.resource = rk_camera_resource_host_0,
.dev = {
.dma_mask = &rockchip_device_camera_dmamask,
.coherent_dma_mask = 0xffffffffUL,
.platform_data = &rk_camera_platform_data,
}
};
#endif
static int rk_register_camera_devices(void)
{
…..
new_camera = rk_camera_platform_data.register_dev_new;
…..
#if RK_SUPPORT_CIF0
if (host_registered_0) {
platform_device_register(&rk_device_camera_host_0);
}
#endif
if (rk_camera_platform_data.sensor_register)
(rk_camera_platform_data.sensor_register)();
…..
}
module_init(rk_register_camera_devices);