Commit 93876132 authored by Komal Shah's avatar Komal Shah Committed by Tony Lindgren

Attached patch uses the platform driver structure and introduced probe

and remove function from init and cleanup. It builds for H2, but unable
to test as not having H2 board access.
Signed-off-by: default avatarKomal Shah <komal_shah802003@yahoo.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent 7508d984
......@@ -914,9 +914,9 @@ camera_core_open(struct inode *inode, struct file *file)
}
#ifdef CONFIG_PM
static int camera_core_suspend(struct device *dev, pm_message_t state)
static int camera_core_suspend(struct platform_device *pdev, pm_message_t state)
{
struct camera_device *cam = dev_get_drvdata(dev);
struct camera_device *cam = platform_get_drvdata(pdev);
int ret = 0;
spin_lock(&cam->img_lock);
......@@ -925,12 +925,13 @@ static int camera_core_suspend(struct device *dev, pm_message_t state)
}
cam->cam_sensor->power_off(cam->sensor_data);
spin_unlock(&cam->img_lock);
return ret;
}
static int camera_core_resume(struct device *dev)
static int camera_core_resume(struct platform_device *pdev)
{
struct camera_device *cam = dev_get_drvdata(dev);
struct camera_device *cam = platform_get_drvdata(pdev);
int ret = 0;
spin_lock(&cam->img_lock);
......@@ -963,79 +964,17 @@ static struct file_operations camera_core_fops =
.release = camera_core_release,
};
static struct device_driver camera_core_driver = {
.name = CAM_NAME,
.bus = &platform_bus_type,
.probe = NULL,
.remove = NULL,
#ifdef CONFIG_PM
.suspend = camera_core_suspend,
.resume = camera_core_resume,
#endif
.shutdown = NULL,
};
static struct platform_device camera_core_device = {
.name = CAM_NAME,
.dev = {
.release = NULL,
},
.id = 0,
};
void
camera_core_cleanup(void)
{
struct camera_device *cam = camera_dev;
struct video_device *vfd;
if (!cam)
return;
vfd = cam->vfd;
if (vfd) {
if (vfd->minor == -1) {
/* The device never got registered, so release the
** video_device struct directly
*/
video_device_release(vfd);
} else {
/* The unregister function will release the video_device
** struct as well as unregistering it.
*/
video_unregister_device(vfd);
driver_unregister(&camera_core_driver);
platform_device_unregister(&camera_core_device);
}
cam->vfd = NULL;
}
if (cam->overlay_base) {
dma_free_coherent(NULL, cam->overlay_size,
(void *)cam->overlay_base,
cam->overlay_base_phys);
cam->overlay_base = 0;
}
cam->overlay_base_phys = 0;
cam->cam_sensor->cleanup(cam->sensor_data);
cam->cam_hardware->cleanup(cam->hardware_data);
kfree(cam);
camera_dev = NULL;
return;
}
int __init
camera_core_init(void)
static int __init camera_core_probe(struct platform_device *pdev)
{
struct camera_device *cam;
struct video_device *vfd;
int status;
cam = kzalloc(sizeof(struct camera_device), GFP_KERNEL);
if (!cam) {
printk(KERN_ERR CAM_NAME ": could not allocate memory\n");
goto init_error;
status = -ENOMEM;
goto err0;
}
/* Save the pointer to camera device in a global variable */
......@@ -1046,7 +985,8 @@ camera_core_init(void)
if (!vfd) {
printk(KERN_ERR CAM_NAME
": could not allocate video device struct\n");
goto init_error;
status = -ENOMEM;
goto err1;
}
vfd->release = video_device_release;
......@@ -1077,7 +1017,8 @@ camera_core_init(void)
if (!cam->overlay_base) {
printk(KERN_ERR CAM_NAME
": cannot allocate overlay framebuffer\n");
goto init_error;
status = -ENOMEM;
goto err2;
}
}
memset((void*)cam->overlay_base, 0, cam->overlay_size);
......@@ -1092,7 +1033,8 @@ camera_core_init(void)
cam->hardware_data = cam->cam_hardware->init();
if (!cam->hardware_data) {
printk(KERN_ERR CAM_NAME ": cannot initialize interface hardware\n");
goto init_error;
status = -ENODEV;
goto err3;
}
/* initialize the spinlock used to serialize access to the image
......@@ -1116,7 +1058,8 @@ camera_core_init(void)
if (!cam->sensor_data) {
cam->cam_hardware->disable(cam->hardware_data);
printk(KERN_ERR CAM_NAME ": cannot initialize sensor\n");
goto init_error;
status = -ENODEV;
goto err4;
}
printk(KERN_INFO CAM_NAME ": %s interface with %s sensor\n",
......@@ -1142,34 +1085,115 @@ camera_core_init(void)
/* Disable the Camera after detection */
cam->cam_hardware->disable(cam->hardware_data);
dev_set_drvdata(&camera_core_device.dev, (void *)cam);
if (platform_device_register(&camera_core_device) < 0) {
printk(KERN_ERR CAM_NAME
": could not register platform_device\n");
goto init_error;
}
platform_set_drvdata(pdev, cam);
if (driver_register(&camera_core_driver) < 0) {
printk(KERN_ERR CAM_NAME
": could not register driver\n");
platform_device_unregister(&camera_core_device);
goto init_error;
}
if (video_register_device(vfd, VFL_TYPE_GRABBER, video_nr) < 0) {
printk(KERN_ERR CAM_NAME
": could not register Video for Linux device\n");
platform_device_unregister(&camera_core_device);
driver_unregister(&camera_core_driver);
goto init_error;
status = -ENODEV;
goto err5;
}
printk(KERN_INFO CAM_NAME
": registered device video%d [v4l2]\n", vfd->minor);
return 0;
init_error:
camera_core_cleanup();
return -ENODEV;
err5:
cam->cam_sensor->cleanup(cam->sensor_data);
err4:
cam->cam_hardware->cleanup(cam->hardware_data);
err3:
dma_free_coherent(NULL, cam->overlay_size,
(void *)cam->overlay_base,
cam->overlay_base_phys);
cam->overlay_base = 0;
err2:
video_device_release(vfd);
err1:
kfree(cam);
camera_dev = NULL;
err0:
return status;
}
static int camera_core_remove(struct platform_device *pdev)
{
struct camera_device *cam = platform_get_drvdata(pdev);
struct video_device *vfd;
vfd = cam->vfd;
if (vfd) {
if (vfd->minor == -1) {
/* The device never got registered, so release the
** video_device struct directly
*/
video_device_release(vfd);
} else {
/* The unregister function will release the video_device
** struct as well as unregistering it.
*/
video_unregister_device(vfd);
}
cam->vfd = NULL;
}
if (cam->overlay_base) {
dma_free_coherent(NULL, cam->overlay_size,
(void *)cam->overlay_base,
cam->overlay_base_phys);
cam->overlay_base = 0;
}
cam->overlay_base_phys = 0;
cam->cam_sensor->cleanup(cam->sensor_data);
cam->cam_hardware->cleanup(cam->hardware_data);
kfree(cam);
camera_dev = NULL;
return 0;
}
static struct platform_driver camera_core_driver = {
.driver = {
.name = CAM_NAME,
.owner = THIS_MODULE,
},
.probe = camera_core_probe,
.remove = camera_core_remove,
#ifdef CONFIG_PM
.suspend = camera_core_suspend,
.resume = camera_core_resume,
#endif
};
static struct platform_device camera_core_device = {
.name = CAM_NAME,
.dev = {
.release = NULL,
},
.id = 0,
};
void __exit
camera_core_cleanup(void)
{
platform_driver_unregister(&camera_core_driver);
platform_device_unregister(&camera_core_device);
return;
}
static char banner[] __initdata = KERN_INFO "OMAP Camera driver initialzing\n";
int __init
camera_core_init(void)
{
printk(banner);
platform_device_register(&camera_core_device);
platform_driver_register(&camera_core_driver);
return 0;
}
MODULE_AUTHOR("Texas Instruments.");
......@@ -1185,4 +1209,3 @@ MODULE_PARM_DESC(capture_mem,
module_init(camera_core_init);
module_exit(camera_core_cleanup);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment