2 * Generic Platform Camera Driver
4 * Copyright (C) 2008 Magnus Damm
5 * Based on mt9m001 driver,
6 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/platform_device.h>
18 #include <linux/videodev2.h>
19 #include <media/v4l2-common.h>
20 #include <media/soc_camera.h>
22 struct soc_camera_platform_info {
25 unsigned long format_depth;
26 struct v4l2_pix_format format;
27 unsigned long bus_param;
28 int (*set_capture)(struct soc_camera_platform_info *info, int enable);
31 struct soc_camera_platform_priv {
32 struct soc_camera_platform_info *info;
33 struct soc_camera_device icd;
34 struct soc_camera_data_format format;
37 static struct soc_camera_platform_info *
38 soc_camera_platform_get_info(struct soc_camera_device *icd)
40 struct soc_camera_platform_priv *priv;
41 priv = container_of(icd, struct soc_camera_platform_priv, icd);
45 static int soc_camera_platform_init(struct soc_camera_device *icd)
50 static int soc_camera_platform_release(struct soc_camera_device *icd)
55 static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
57 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
58 return p->set_capture(p, 1);
61 static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
63 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
64 return p->set_capture(p, 0);
67 static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
74 soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
76 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
80 static int soc_camera_platform_set_fmt_cap(struct soc_camera_device *icd,
81 __u32 pixfmt, struct v4l2_rect *rect)
86 static int soc_camera_platform_try_fmt_cap(struct soc_camera_device *icd,
87 struct v4l2_format *f)
89 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
91 f->fmt.pix.width = p->format.width;
92 f->fmt.pix.height = p->format.height;
96 static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
98 struct soc_camera_platform_priv *priv;
99 priv = container_of(icd, struct soc_camera_platform_priv, icd);
101 priv->format.name = priv->info->format_name;
102 priv->format.depth = priv->info->format_depth;
103 priv->format.fourcc = priv->info->format.pixelformat;
104 priv->format.colorspace = priv->info->format.colorspace;
106 icd->formats = &priv->format;
107 icd->num_formats = 1;
109 return soc_camera_video_start(icd);
112 static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
114 soc_camera_video_stop(icd);
117 static struct soc_camera_ops soc_camera_platform_ops = {
118 .owner = THIS_MODULE,
119 .probe = soc_camera_platform_video_probe,
120 .remove = soc_camera_platform_video_remove,
121 .init = soc_camera_platform_init,
122 .release = soc_camera_platform_release,
123 .start_capture = soc_camera_platform_start_capture,
124 .stop_capture = soc_camera_platform_stop_capture,
125 .set_fmt_cap = soc_camera_platform_set_fmt_cap,
126 .try_fmt_cap = soc_camera_platform_try_fmt_cap,
127 .set_bus_param = soc_camera_platform_set_bus_param,
128 .query_bus_param = soc_camera_platform_query_bus_param,
131 static int soc_camera_platform_probe(struct platform_device *pdev)
133 struct soc_camera_platform_priv *priv;
134 struct soc_camera_platform_info *p;
135 struct soc_camera_device *icd;
138 p = pdev->dev.platform_data;
142 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
147 platform_set_drvdata(pdev, priv);
150 icd->ops = &soc_camera_platform_ops;
151 icd->control = &pdev->dev;
153 icd->width_max = priv->info->format.width;
155 icd->height_max = priv->info->format.height;
157 icd->iface = priv->info->iface;
159 ret = soc_camera_device_register(icd);
166 static int soc_camera_platform_remove(struct platform_device *pdev)
168 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
170 soc_camera_device_unregister(&priv->icd);
175 static struct platform_driver soc_camera_platform_driver = {
177 .name = "soc_camera_platform",
179 .probe = soc_camera_platform_probe,
180 .remove = soc_camera_platform_remove,
183 static int __init soc_camera_platform_module_init(void)
185 return platform_driver_register(&soc_camera_platform_driver);
188 static void __exit soc_camera_platform_module_exit(void)
190 return platform_driver_unregister(&soc_camera_platform_driver);
193 module_init(soc_camera_platform_module_init);
194 module_exit(soc_camera_platform_module_exit);
196 MODULE_DESCRIPTION("SoC Camera Platform driver");
197 MODULE_AUTHOR("Magnus Damm");
198 MODULE_LICENSE("GPL v2");