Merge branch 'linux-next' of git://git.infradead.org/ubifs-2.6
[deliverable/linux.git] / drivers / media / video / soc_camera_platform.c
CommitLineData
326c9862
MD
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>
50c616fd 21#include <media/soc_camera_platform.h>
326c9862
MD
22
23struct 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
29static struct soc_camera_platform_info *
30soc_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
37static int soc_camera_platform_init(struct soc_camera_device *icd)
38{
50c616fd
GL
39 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
40
41 if (p->power)
42 p->power(1);
43
326c9862
MD
44 return 0;
45}
46
47static int soc_camera_platform_release(struct soc_camera_device *icd)
48{
50c616fd
GL
49 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
50
51 if (p->power)
52 p->power(0);
53
326c9862
MD
54 return 0;
55}
56
57static 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
63static 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
69static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
70 unsigned long flags)
71{
72 return 0;
73}
74
75static unsigned long
76soc_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
d8fac217
GL
82static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
83 __u32 pixfmt, struct v4l2_rect *rect)
326c9862
MD
84{
85 return 0;
86}
87
d8fac217
GL
88static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
89 struct v4l2_format *f)
326c9862
MD
90{
91 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
64f5905e 92 struct v4l2_pix_format *pix = &f->fmt.pix;
326c9862 93
64f5905e
GL
94 pix->width = p->format.width;
95 pix->height = p->format.height;
326c9862
MD
96 return 0;
97}
98
99static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
100{
101 struct soc_camera_platform_priv *priv;
102 priv = container_of(icd, struct soc_camera_platform_priv, icd);
103
104 priv->format.name = priv->info->format_name;
105 priv->format.depth = priv->info->format_depth;
106 priv->format.fourcc = priv->info->format.pixelformat;
107 priv->format.colorspace = priv->info->format.colorspace;
108
109 icd->formats = &priv->format;
110 icd->num_formats = 1;
111
112 return soc_camera_video_start(icd);
113}
114
115static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
116{
117 soc_camera_video_stop(icd);
118}
119
120static struct soc_camera_ops soc_camera_platform_ops = {
121 .owner = THIS_MODULE,
122 .probe = soc_camera_platform_video_probe,
123 .remove = soc_camera_platform_video_remove,
124 .init = soc_camera_platform_init,
125 .release = soc_camera_platform_release,
126 .start_capture = soc_camera_platform_start_capture,
127 .stop_capture = soc_camera_platform_stop_capture,
d8fac217
GL
128 .set_fmt = soc_camera_platform_set_fmt,
129 .try_fmt = soc_camera_platform_try_fmt,
326c9862
MD
130 .set_bus_param = soc_camera_platform_set_bus_param,
131 .query_bus_param = soc_camera_platform_query_bus_param,
132};
133
134static int soc_camera_platform_probe(struct platform_device *pdev)
135{
136 struct soc_camera_platform_priv *priv;
137 struct soc_camera_platform_info *p;
138 struct soc_camera_device *icd;
139 int ret;
140
141 p = pdev->dev.platform_data;
142 if (!p)
143 return -EINVAL;
144
145 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
146 if (!priv)
147 return -ENOMEM;
148
149 priv->info = p;
150 platform_set_drvdata(pdev, priv);
151
152 icd = &priv->icd;
153 icd->ops = &soc_camera_platform_ops;
154 icd->control = &pdev->dev;
155 icd->width_min = 0;
156 icd->width_max = priv->info->format.width;
157 icd->height_min = 0;
158 icd->height_max = priv->info->format.height;
159 icd->y_skip_top = 0;
160 icd->iface = priv->info->iface;
161
162 ret = soc_camera_device_register(icd);
163 if (ret)
164 kfree(priv);
165
166 return ret;
167}
168
169static int soc_camera_platform_remove(struct platform_device *pdev)
170{
171 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
172
173 soc_camera_device_unregister(&priv->icd);
174 kfree(priv);
175 return 0;
176}
177
178static struct platform_driver soc_camera_platform_driver = {
179 .driver = {
180 .name = "soc_camera_platform",
181 },
182 .probe = soc_camera_platform_probe,
183 .remove = soc_camera_platform_remove,
184};
185
186static int __init soc_camera_platform_module_init(void)
187{
188 return platform_driver_register(&soc_camera_platform_driver);
189}
190
191static void __exit soc_camera_platform_module_exit(void)
192{
01c1e4ca 193 platform_driver_unregister(&soc_camera_platform_driver);
326c9862
MD
194}
195
196module_init(soc_camera_platform_module_init);
197module_exit(soc_camera_platform_module_exit);
198
199MODULE_DESCRIPTION("SoC Camera Platform driver");
200MODULE_AUTHOR("Magnus Damm");
201MODULE_LICENSE("GPL v2");
This page took 0.091743 seconds and 5 git commands to generate.