]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/media/video/soc_camera_platform.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[linux-2.6-omap-h63xx.git] / drivers / media / video / soc_camera_platform.c
1 /*
2  * Generic Platform Camera Driver
3  *
4  * Copyright (C) 2008 Magnus Damm
5  * Based on mt9m001 driver,
6  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7  *
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.
11  */
12
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>
22
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;
27 };
28
29 static struct soc_camera_platform_info *
30 soc_camera_platform_get_info(struct soc_camera_device *icd)
31 {
32         struct soc_camera_platform_priv *priv;
33         priv = container_of(icd, struct soc_camera_platform_priv, icd);
34         return priv->info;
35 }
36
37 static int soc_camera_platform_init(struct soc_camera_device *icd)
38 {
39         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
40
41         if (p->power)
42                 p->power(1);
43
44         return 0;
45 }
46
47 static int soc_camera_platform_release(struct soc_camera_device *icd)
48 {
49         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
50
51         if (p->power)
52                 p->power(0);
53
54         return 0;
55 }
56
57 static int soc_camera_platform_start_capture(struct soc_camera_device *icd)
58 {
59         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
60         return p->set_capture(p, 1);
61 }
62
63 static int soc_camera_platform_stop_capture(struct soc_camera_device *icd)
64 {
65         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
66         return p->set_capture(p, 0);
67 }
68
69 static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
70                                              unsigned long flags)
71 {
72         return 0;
73 }
74
75 static unsigned long
76 soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
77 {
78         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
79         return p->bus_param;
80 }
81
82 static int soc_camera_platform_set_fmt_cap(struct soc_camera_device *icd,
83                                            __u32 pixfmt, struct v4l2_rect *rect)
84 {
85         return 0;
86 }
87
88 static int soc_camera_platform_try_fmt_cap(struct soc_camera_device *icd,
89                                            struct v4l2_format *f)
90 {
91         struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
92
93         f->fmt.pix.width = p->format.width;
94         f->fmt.pix.height = p->format.height;
95         return 0;
96 }
97
98 static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
99 {
100         struct soc_camera_platform_priv *priv;
101         priv = container_of(icd, struct soc_camera_platform_priv, icd);
102
103         priv->format.name = priv->info->format_name;
104         priv->format.depth = priv->info->format_depth;
105         priv->format.fourcc = priv->info->format.pixelformat;
106         priv->format.colorspace = priv->info->format.colorspace;
107
108         icd->formats = &priv->format;
109         icd->num_formats = 1;
110
111         return soc_camera_video_start(icd);
112 }
113
114 static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
115 {
116         soc_camera_video_stop(icd);
117 }
118
119 static struct soc_camera_ops soc_camera_platform_ops = {
120         .owner                  = THIS_MODULE,
121         .probe                  = soc_camera_platform_video_probe,
122         .remove                 = soc_camera_platform_video_remove,
123         .init                   = soc_camera_platform_init,
124         .release                = soc_camera_platform_release,
125         .start_capture          = soc_camera_platform_start_capture,
126         .stop_capture           = soc_camera_platform_stop_capture,
127         .set_fmt_cap            = soc_camera_platform_set_fmt_cap,
128         .try_fmt_cap            = soc_camera_platform_try_fmt_cap,
129         .set_bus_param          = soc_camera_platform_set_bus_param,
130         .query_bus_param        = soc_camera_platform_query_bus_param,
131 };
132
133 static int soc_camera_platform_probe(struct platform_device *pdev)
134 {
135         struct soc_camera_platform_priv *priv;
136         struct soc_camera_platform_info *p;
137         struct soc_camera_device *icd;
138         int ret;
139
140         p = pdev->dev.platform_data;
141         if (!p)
142                 return -EINVAL;
143
144         priv = kzalloc(sizeof(*priv), GFP_KERNEL);
145         if (!priv)
146                 return -ENOMEM;
147
148         priv->info = p;
149         platform_set_drvdata(pdev, priv);
150
151         icd = &priv->icd;
152         icd->ops        = &soc_camera_platform_ops;
153         icd->control    = &pdev->dev;
154         icd->width_min  = 0;
155         icd->width_max  = priv->info->format.width;
156         icd->height_min = 0;
157         icd->height_max = priv->info->format.height;
158         icd->y_skip_top = 0;
159         icd->iface      = priv->info->iface;
160
161         ret = soc_camera_device_register(icd);
162         if (ret)
163                 kfree(priv);
164
165         return ret;
166 }
167
168 static int soc_camera_platform_remove(struct platform_device *pdev)
169 {
170         struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
171
172         soc_camera_device_unregister(&priv->icd);
173         kfree(priv);
174         return 0;
175 }
176
177 static struct platform_driver soc_camera_platform_driver = {
178         .driver         = {
179                 .name   = "soc_camera_platform",
180         },
181         .probe          = soc_camera_platform_probe,
182         .remove         = soc_camera_platform_remove,
183 };
184
185 static int __init soc_camera_platform_module_init(void)
186 {
187         return platform_driver_register(&soc_camera_platform_driver);
188 }
189
190 static void __exit soc_camera_platform_module_exit(void)
191 {
192         platform_driver_unregister(&soc_camera_platform_driver);
193 }
194
195 module_init(soc_camera_platform_module_init);
196 module_exit(soc_camera_platform_module_exit);
197
198 MODULE_DESCRIPTION("SoC Camera Platform driver");
199 MODULE_AUTHOR("Magnus Damm");
200 MODULE_LICENSE("GPL v2");