blob: c48676356ab7d503a4fc32257fccfe67d8a73ffa [file] [log] [blame]
Magnus Damm326c9862008-07-16 23:02:08 -03001/*
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>
Guennadi Liakhovetski50c616f2008-10-16 19:49:27 -030021#include <media/soc_camera_platform.h>
Magnus Damm326c9862008-07-16 23:02:08 -030022
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{
Guennadi Liakhovetski50c616f2008-10-16 19:49:27 -030039 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
40
41 if (p->power)
42 p->power(1);
43
Magnus Damm326c9862008-07-16 23:02:08 -030044 return 0;
45}
46
47static int soc_camera_platform_release(struct soc_camera_device *icd)
48{
Guennadi Liakhovetski50c616f2008-10-16 19:49:27 -030049 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
50
51 if (p->power)
52 p->power(0);
53
Magnus Damm326c9862008-07-16 23:02:08 -030054 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
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -030082static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
83 struct v4l2_rect *rect)
84{
85 return 0;
86}
87
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -030088static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -030089 struct v4l2_format *f)
Magnus Damm326c9862008-07-16 23:02:08 -030090{
91 return 0;
92}
93
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -030094static int soc_camera_platform_try_fmt(struct soc_camera_device *icd,
95 struct v4l2_format *f)
Magnus Damm326c9862008-07-16 23:02:08 -030096{
97 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
Guennadi Liakhovetski64f59052008-12-18 11:51:55 -030098 struct v4l2_pix_format *pix = &f->fmt.pix;
Magnus Damm326c9862008-07-16 23:02:08 -030099
Guennadi Liakhovetski64f59052008-12-18 11:51:55 -0300100 pix->width = p->format.width;
101 pix->height = p->format.height;
Magnus Damm326c9862008-07-16 23:02:08 -0300102 return 0;
103}
104
105static int soc_camera_platform_video_probe(struct soc_camera_device *icd)
106{
107 struct soc_camera_platform_priv *priv;
108 priv = container_of(icd, struct soc_camera_platform_priv, icd);
109
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;
114
115 icd->formats = &priv->format;
116 icd->num_formats = 1;
117
118 return soc_camera_video_start(icd);
119}
120
121static void soc_camera_platform_video_remove(struct soc_camera_device *icd)
122{
123 soc_camera_video_stop(icd);
124}
125
126static 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,
Guennadi Liakhovetski09e231b2009-03-13 06:08:20 -0300134 .set_crop = soc_camera_platform_set_crop,
Guennadi Liakhovetskid8fac212008-12-01 09:45:21 -0300135 .set_fmt = soc_camera_platform_set_fmt,
136 .try_fmt = soc_camera_platform_try_fmt,
Magnus Damm326c9862008-07-16 23:02:08 -0300137 .set_bus_param = soc_camera_platform_set_bus_param,
138 .query_bus_param = soc_camera_platform_query_bus_param,
139};
140
141static int soc_camera_platform_probe(struct platform_device *pdev)
142{
143 struct soc_camera_platform_priv *priv;
144 struct soc_camera_platform_info *p;
145 struct soc_camera_device *icd;
146 int ret;
147
148 p = pdev->dev.platform_data;
149 if (!p)
150 return -EINVAL;
151
152 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
153 if (!priv)
154 return -ENOMEM;
155
156 priv->info = p;
157 platform_set_drvdata(pdev, priv);
158
159 icd = &priv->icd;
160 icd->ops = &soc_camera_platform_ops;
161 icd->control = &pdev->dev;
162 icd->width_min = 0;
163 icd->width_max = priv->info->format.width;
164 icd->height_min = 0;
165 icd->height_max = priv->info->format.height;
166 icd->y_skip_top = 0;
167 icd->iface = priv->info->iface;
168
169 ret = soc_camera_device_register(icd);
170 if (ret)
171 kfree(priv);
172
173 return ret;
174}
175
176static int soc_camera_platform_remove(struct platform_device *pdev)
177{
178 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
179
180 soc_camera_device_unregister(&priv->icd);
181 kfree(priv);
182 return 0;
183}
184
185static struct platform_driver soc_camera_platform_driver = {
186 .driver = {
187 .name = "soc_camera_platform",
188 },
189 .probe = soc_camera_platform_probe,
190 .remove = soc_camera_platform_remove,
191};
192
193static int __init soc_camera_platform_module_init(void)
194{
195 return platform_driver_register(&soc_camera_platform_driver);
196}
197
198static void __exit soc_camera_platform_module_exit(void)
199{
Paul Mundt01c1e4c2008-08-01 19:48:51 -0300200 platform_driver_unregister(&soc_camera_platform_driver);
Magnus Damm326c9862008-07-16 23:02:08 -0300201}
202
203module_init(soc_camera_platform_module_init);
204module_exit(soc_camera_platform_module_exit);
205
206MODULE_DESCRIPTION("SoC Camera Platform driver");
207MODULE_AUTHOR("Magnus Damm");
208MODULE_LICENSE("GPL v2");