2008-07-17 10:02:08 +08:00
|
|
|
/*
|
|
|
|
* Generic Platform Camera Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Magnus Damm
|
|
|
|
* Based on mt9m001 driver,
|
|
|
|
* Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/videodev2.h>
|
|
|
|
#include <media/v4l2-common.h>
|
|
|
|
#include <media/soc_camera.h>
|
2008-10-17 06:49:27 +08:00
|
|
|
#include <media/soc_camera_platform.h>
|
2008-07-17 10:02:08 +08:00
|
|
|
|
|
|
|
struct soc_camera_platform_priv {
|
|
|
|
struct soc_camera_data_format format;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct soc_camera_platform_info *
|
|
|
|
soc_camera_platform_get_info(struct soc_camera_device *icd)
|
|
|
|
{
|
2009-08-25 22:28:22 +08:00
|
|
|
struct platform_device *pdev = to_platform_device(dev_get_drvdata(&icd->dev));
|
|
|
|
return pdev->dev.platform_data;
|
2008-07-17 10:02:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_init(struct soc_camera_device *icd)
|
|
|
|
{
|
2009-08-25 22:28:22 +08:00
|
|
|
struct soc_camera_link *icl = to_soc_camera_link(icd);
|
2008-10-17 06:49:27 +08:00
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
if (icl->power)
|
|
|
|
icl->power(dev_get_drvdata(&icd->dev), 1);
|
2008-10-17 06:49:27 +08:00
|
|
|
|
2008-07-17 10:02:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_release(struct soc_camera_device *icd)
|
|
|
|
{
|
2009-08-25 22:28:22 +08:00
|
|
|
struct soc_camera_link *icl = to_soc_camera_link(icd);
|
2008-10-17 06:49:27 +08:00
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
if (icl->power)
|
|
|
|
icl->power(dev_get_drvdata(&icd->dev), 0);
|
2008-10-17 06:49:27 +08:00
|
|
|
|
2008-07-17 10:02:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
|
|
|
|
{
|
|
|
|
struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
|
|
|
|
return p->set_capture(p, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
|
|
|
|
{
|
|
|
|
struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
|
|
|
|
return p->set_capture(p, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
|
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
|
|
|
|
{
|
|
|
|
struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
|
|
|
|
return p->bus_param;
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:08:20 +08:00
|
|
|
static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
|
|
|
|
struct v4l2_rect *rect)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:45:21 +08:00
|
|
|
static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
|
2009-03-13 17:08:20 +08:00
|
|
|
struct v4l2_format *f)
|
2008-07-17 10:02:08 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:45:21 +08:00
|
|
|
static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
|
|
|
|
struct v4l2_format *f)
|
2008-07-17 10:02:08 +08:00
|
|
|
{
|
|
|
|
struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
|
2008-12-18 22:51:55 +08:00
|
|
|
struct v4l2_pix_format *pix = &f->fmt.pix;
|
2008-07-17 10:02:08 +08:00
|
|
|
|
2008-12-18 22:51:55 +08:00
|
|
|
pix->width = p->format.width;
|
|
|
|
pix->height = p->format.height;
|
2008-07-17 10:02:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
static int soc_camera_platform_video_probe(struct soc_camera_device *icd,
|
|
|
|
struct platform_device *pdev)
|
2008-07-17 10:02:08 +08:00
|
|
|
{
|
2009-08-25 22:28:22 +08:00
|
|
|
struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
struct soc_camera_platform_info *p = pdev->dev.platform_data;
|
|
|
|
int ret;
|
2008-07-17 10:02:08 +08:00
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
priv->format.name = p->format_name;
|
|
|
|
priv->format.depth = p->format_depth;
|
|
|
|
priv->format.fourcc = p->format.pixelformat;
|
|
|
|
priv->format.colorspace = p->format.colorspace;
|
2008-07-17 10:02:08 +08:00
|
|
|
|
|
|
|
icd->formats = &priv->format;
|
|
|
|
icd->num_formats = 1;
|
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
/* ..._video_start() does dev_set_drvdata(&icd->dev, &pdev->dev) */
|
|
|
|
ret = soc_camera_video_start(icd, &pdev->dev);
|
2008-07-17 10:02:08 +08:00
|
|
|
soc_camera_video_stop(icd);
|
2009-08-25 22:28:22 +08:00
|
|
|
return ret;
|
2008-07-17 10:02:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct soc_camera_ops soc_camera_platform_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.init = soc_camera_platform_init,
|
|
|
|
.release = soc_camera_platform_release,
|
|
|
|
.start_capture = soc_camera_platform_start_capture,
|
|
|
|
.stop_capture = soc_camera_platform_stop_capture,
|
2009-03-13 17:08:20 +08:00
|
|
|
.set_crop = soc_camera_platform_set_crop,
|
2008-12-01 20:45:21 +08:00
|
|
|
.set_fmt = soc_camera_platform_set_fmt,
|
|
|
|
.try_fmt = soc_camera_platform_try_fmt,
|
2008-07-17 10:02:08 +08:00
|
|
|
.set_bus_param = soc_camera_platform_set_bus_param,
|
|
|
|
.query_bus_param = soc_camera_platform_query_bus_param,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int soc_camera_platform_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct soc_camera_platform_priv *priv;
|
2009-08-25 22:28:22 +08:00
|
|
|
struct soc_camera_platform_info *p = pdev->dev.platform_data;
|
2008-07-17 10:02:08 +08:00
|
|
|
struct soc_camera_device *icd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
icd = to_soc_camera_dev(p->dev);
|
|
|
|
if (!icd)
|
|
|
|
goto enoicd;
|
|
|
|
|
2008-07-17 10:02:08 +08:00
|
|
|
icd->ops = &soc_camera_platform_ops;
|
2009-08-25 22:28:22 +08:00
|
|
|
dev_set_drvdata(&icd->dev, &pdev->dev);
|
2008-07-17 10:02:08 +08:00
|
|
|
icd->width_min = 0;
|
2009-08-25 22:28:22 +08:00
|
|
|
icd->width_max = p->format.width;
|
2008-07-17 10:02:08 +08:00
|
|
|
icd->height_min = 0;
|
2009-08-25 22:28:22 +08:00
|
|
|
icd->height_max = p->format.height;
|
2008-07-17 10:02:08 +08:00
|
|
|
icd->y_skip_top = 0;
|
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
ret = soc_camera_platform_video_probe(icd, pdev);
|
|
|
|
if (ret) {
|
|
|
|
icd->ops = NULL;
|
2008-07-17 10:02:08 +08:00
|
|
|
kfree(priv);
|
2009-08-25 22:28:22 +08:00
|
|
|
}
|
2008-07-17 10:02:08 +08:00
|
|
|
|
|
|
|
return ret;
|
2009-08-25 22:28:22 +08:00
|
|
|
|
|
|
|
enoicd:
|
|
|
|
kfree(priv);
|
|
|
|
return -EINVAL;
|
2008-07-17 10:02:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int soc_camera_platform_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
|
2009-08-25 22:28:22 +08:00
|
|
|
struct soc_camera_platform_info *p = pdev->dev.platform_data;
|
|
|
|
struct soc_camera_device *icd = to_soc_camera_dev(p->dev);
|
2008-07-17 10:02:08 +08:00
|
|
|
|
2009-08-25 22:28:22 +08:00
|
|
|
icd->ops = NULL;
|
2008-07-17 10:02:08 +08:00
|
|
|
kfree(priv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver soc_camera_platform_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "soc_camera_platform",
|
|
|
|
},
|
|
|
|
.probe = soc_camera_platform_probe,
|
|
|
|
.remove = soc_camera_platform_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init soc_camera_platform_module_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&soc_camera_platform_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit soc_camera_platform_module_exit(void)
|
|
|
|
{
|
2008-08-02 06:48:51 +08:00
|
|
|
platform_driver_unregister(&soc_camera_platform_driver);
|
2008-07-17 10:02:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(soc_camera_platform_module_init);
|
|
|
|
module_exit(soc_camera_platform_module_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SoC Camera Platform driver");
|
|
|
|
MODULE_AUTHOR("Magnus Damm");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2009-08-25 22:28:22 +08:00
|
|
|
MODULE_ALIAS("platform:soc_camera_platform");
|