diff options
author | Magnus Damm <magnus.damm@gmail.com> | 2008-07-16 22:02:08 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-20 06:25:49 -0400 |
commit | 326c986207cb2065b9819107caa31efd2bbc48db (patch) | |
tree | c6cdd453904da5e0184d3c19e6967f8043e46426 /drivers/media | |
parent | 0d3244d6439c8c31d2a29efd587c7aca9042c8aa (diff) |
V4L/DVB (8343): soc_camera_platform: Add SoC Camera Platform driver
This patch adds a simple platform camera device. Useful for testing
cameras with SoC camera host drivers. Only one single pixel format
and resolution combination is supported.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/Kconfig | 6 | ||||
-rw-r--r-- | drivers/media/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/video/soc_camera_platform.c | 198 |
3 files changed, 205 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index fdeaff257caf..1199a1a2e6f5 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
@@ -961,6 +961,12 @@ config MT9V022_PCA9536_SWITCH | |||
961 | Select this if your MT9V022 camera uses a PCA9536 I2C GPIO | 961 | Select this if your MT9V022 camera uses a PCA9536 I2C GPIO |
962 | extender to switch between 8 and 10 bit datawidth modes | 962 | extender to switch between 8 and 10 bit datawidth modes |
963 | 963 | ||
964 | config SOC_CAMERA_PLATFORM | ||
965 | tristate "platform camera support" | ||
966 | depends on SOC_CAMERA | ||
967 | help | ||
968 | This is a generic SoC camera platform driver, useful for testing | ||
969 | |||
964 | config VIDEO_PXA27x | 970 | config VIDEO_PXA27x |
965 | tristate "PXA27x Quick Capture Interface driver" | 971 | tristate "PXA27x Quick Capture Interface driver" |
966 | depends on VIDEO_DEV && PXA27x | 972 | depends on VIDEO_DEV && PXA27x |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 6dd51b01ef90..45d5db5abb1e 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -137,6 +137,7 @@ obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o | |||
137 | obj-$(CONFIG_SOC_CAMERA) += soc_camera.o | 137 | obj-$(CONFIG_SOC_CAMERA) += soc_camera.o |
138 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o | 138 | obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o |
139 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o | 139 | obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o |
140 | obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o | ||
140 | 141 | ||
141 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ | 142 | obj-$(CONFIG_VIDEO_AU0828) += au0828/ |
142 | 143 | ||
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c new file mode 100644 index 000000000000..eefb0327ebb6 --- /dev/null +++ b/drivers/media/video/soc_camera_platform.c | |||
@@ -0,0 +1,198 @@ | |||
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 | |||
22 | struct soc_camera_platform_info { | ||
23 | int iface; | ||
24 | char *format_name; | ||
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); | ||
29 | }; | ||
30 | |||
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; | ||
35 | }; | ||
36 | |||
37 | static struct soc_camera_platform_info * | ||
38 | soc_camera_platform_get_info(struct soc_camera_device *icd) | ||
39 | { | ||
40 | struct soc_camera_platform_priv *priv; | ||
41 | priv = container_of(icd, struct soc_camera_platform_priv, icd); | ||
42 | return priv->info; | ||
43 | } | ||
44 | |||
45 | static int soc_camera_platform_init(struct soc_camera_device *icd) | ||
46 | { | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static int soc_camera_platform_release(struct soc_camera_device *icd) | ||
51 | { | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static int soc_camera_platform_start_capture(struct soc_camera_device *icd) | ||
56 | { | ||
57 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); | ||
58 | return p->set_capture(p, 1); | ||
59 | } | ||
60 | |||
61 | static int soc_camera_platform_stop_capture(struct soc_camera_device *icd) | ||
62 | { | ||
63 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); | ||
64 | return p->set_capture(p, 0); | ||
65 | } | ||
66 | |||
67 | static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd, | ||
68 | unsigned long flags) | ||
69 | { | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static unsigned long | ||
74 | soc_camera_platform_query_bus_param(struct soc_camera_device *icd) | ||
75 | { | ||
76 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); | ||
77 | return p->bus_param; | ||
78 | } | ||
79 | |||
80 | static int soc_camera_platform_set_fmt_cap(struct soc_camera_device *icd, | ||
81 | __u32 pixfmt, struct v4l2_rect *rect) | ||
82 | { | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static int soc_camera_platform_try_fmt_cap(struct soc_camera_device *icd, | ||
87 | struct v4l2_format *f) | ||
88 | { | ||
89 | struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd); | ||
90 | |||
91 | f->fmt.pix.width = p->format.width; | ||
92 | f->fmt.pix.height = p->format.height; | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | static int soc_camera_platform_video_probe(struct soc_camera_device *icd) | ||
97 | { | ||
98 | struct soc_camera_platform_priv *priv; | ||
99 | priv = container_of(icd, struct soc_camera_platform_priv, icd); | ||
100 | |||
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; | ||
105 | |||
106 | icd->formats = &priv->format; | ||
107 | icd->num_formats = 1; | ||
108 | |||
109 | return soc_camera_video_start(icd); | ||
110 | } | ||
111 | |||
112 | static void soc_camera_platform_video_remove(struct soc_camera_device *icd) | ||
113 | { | ||
114 | soc_camera_video_stop(icd); | ||
115 | } | ||
116 | |||
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, | ||
129 | }; | ||
130 | |||
131 | static int soc_camera_platform_probe(struct platform_device *pdev) | ||
132 | { | ||
133 | struct soc_camera_platform_priv *priv; | ||
134 | struct soc_camera_platform_info *p; | ||
135 | struct soc_camera_device *icd; | ||
136 | int ret; | ||
137 | |||
138 | p = pdev->dev.platform_data; | ||
139 | if (!p) | ||
140 | return -EINVAL; | ||
141 | |||
142 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
143 | if (!priv) | ||
144 | return -ENOMEM; | ||
145 | |||
146 | priv->info = p; | ||
147 | platform_set_drvdata(pdev, priv); | ||
148 | |||
149 | icd = &priv->icd; | ||
150 | icd->ops = &soc_camera_platform_ops; | ||
151 | icd->control = &pdev->dev; | ||
152 | icd->width_min = 0; | ||
153 | icd->width_max = priv->info->format.width; | ||
154 | icd->height_min = 0; | ||
155 | icd->height_max = priv->info->format.height; | ||
156 | icd->y_skip_top = 0; | ||
157 | icd->iface = priv->info->iface; | ||
158 | |||
159 | ret = soc_camera_device_register(icd); | ||
160 | if (ret) | ||
161 | kfree(priv); | ||
162 | |||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | static int soc_camera_platform_remove(struct platform_device *pdev) | ||
167 | { | ||
168 | struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev); | ||
169 | |||
170 | soc_camera_device_unregister(&priv->icd); | ||
171 | kfree(priv); | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static struct platform_driver soc_camera_platform_driver = { | ||
176 | .driver = { | ||
177 | .name = "soc_camera_platform", | ||
178 | }, | ||
179 | .probe = soc_camera_platform_probe, | ||
180 | .remove = soc_camera_platform_remove, | ||
181 | }; | ||
182 | |||
183 | static int __init soc_camera_platform_module_init(void) | ||
184 | { | ||
185 | return platform_driver_register(&soc_camera_platform_driver); | ||
186 | } | ||
187 | |||
188 | static void __exit soc_camera_platform_module_exit(void) | ||
189 | { | ||
190 | return platform_driver_unregister(&soc_camera_platform_driver); | ||
191 | } | ||
192 | |||
193 | module_init(soc_camera_platform_module_init); | ||
194 | module_exit(soc_camera_platform_module_exit); | ||
195 | |||
196 | MODULE_DESCRIPTION("SoC Camera Platform driver"); | ||
197 | MODULE_AUTHOR("Magnus Damm"); | ||
198 | MODULE_LICENSE("GPL v2"); | ||