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>
21 #include <media/soc_camera_platform.h>
23 struct soc_camera_platform_priv {
24 struct soc_camera_platform_info *info;
25 struct soc_camera_device icd;
26 struct soc_camera_data_format format;
29 static struct soc_camera_platform_info *
30 soc_camera_platform_get_info(struct soc_camera_device *icd)
32 struct soc_camera_platform_priv *priv;
33 priv = container_of(icd, struct soc_camera_platform_priv, icd);
37 static int soc_camera_platform_init(struct soc_camera_device *icd)
39 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
47 static int soc_camera_platform_release(struct soc_camera_device *icd)
49 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
57 static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
59 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
60 return p->set_capture(p, 1);
63 static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
65 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
66 return p->set_capture(p, 0);
69 static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
76 soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
78 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
82 static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
83 struct v4l2_rect *rect)
88 static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
89 struct v4l2_format *f)
94 static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
95 struct v4l2_format *f)
97 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
98 struct v4l2_pix_format *pix = &f->fmt.pix;
100 pix->width = p->format.width;
101 pix->height = p->format.height;
105 static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
107 struct soc_camera_platform_priv *priv;
108 priv = container_of(icd, struct soc_camera_platform_priv, icd);
110 priv->format.name = priv->info->format_name;
111 priv->format.depth = priv->info->format_depth;
112 priv->format.fourcc = priv->info->format.pixelformat;
113 priv->format.colorspace = priv->info->format.colorspace;
115 icd->formats = &priv->format;
116 icd->num_formats = 1;
118 return soc_camera_video_start(icd);
121 static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
123 soc_camera_video_stop(icd);
126 static struct soc_camera_ops soc_camera_platform_ops = {
127 .owner = THIS_MODULE,
128 .probe = soc_camera_platform_video_probe,
129 .remove = soc_camera_platform_video_remove,
130 .init = soc_camera_platform_init,
131 .release = soc_camera_platform_release,
132 .start_capture = soc_camera_platform_start_capture,
133 .stop_capture = soc_camera_platform_stop_capture,
134 .set_crop = soc_camera_platform_set_crop,
135 .set_fmt = soc_camera_platform_set_fmt,
136 .try_fmt = soc_camera_platform_try_fmt,
137 .set_bus_param = soc_camera_platform_set_bus_param,
138 .query_bus_param = soc_camera_platform_query_bus_param,
141 static int soc_camera_platform_probe(struct platform_device *pdev)
143 struct soc_camera_platform_priv *priv;
144 struct soc_camera_platform_info *p;
145 struct soc_camera_device *icd;
148 p = pdev->dev.platform_data;
152 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
157 platform_set_drvdata(pdev, priv);
160 icd->ops = &soc_camera_platform_ops;
161 icd->control = &pdev->dev;
163 icd->width_max = priv->info->format.width;
165 icd->height_max = priv->info->format.height;
167 icd->iface = priv->info->iface;
169 ret = soc_camera_device_register(icd);
176 static int soc_camera_platform_remove(struct platform_device *pdev)
178 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
180 soc_camera_device_unregister(&priv->icd);
185 static struct platform_driver soc_camera_platform_driver = {
187 .name = "soc_camera_platform",
189 .probe = soc_camera_platform_probe,
190 .remove = soc_camera_platform_remove,
193 static int __init soc_camera_platform_module_init(void)
195 return platform_driver_register(&soc_camera_platform_driver);
198 static void __exit soc_camera_platform_module_exit(void)
200 platform_driver_unregister(&soc_camera_platform_driver);
203 module_init(soc_camera_platform_module_init);
204 module_exit(soc_camera_platform_module_exit);
206 MODULE_DESCRIPTION("SoC Camera Platform driver");
207 MODULE_AUTHOR("Magnus Damm");
208 MODULE_LICENSE("GPL v2");