]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/media/video/soc_camera_platform.c
V4L/DVB (12515): soc-camera: use struct v4l2_rect in struct soc_camera_device
[mirror_ubuntu-artful-kernel.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-subdev.h>
20 #include <media/soc_camera.h>
21 #include <media/soc_camera_platform.h>
22
23 struct soc_camera_platform_priv {
24 struct v4l2_subdev subdev;
25 struct soc_camera_data_format format;
26 };
27
28 static struct soc_camera_platform_info *
29 soc_camera_platform_get_info(struct soc_camera_device *icd)
30 {
31 struct platform_device *pdev = to_platform_device(dev_get_drvdata(&icd->dev));
32 return pdev->dev.platform_data;
33 }
34
35 static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
36 {
37 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
38 return p->set_capture(p, enable);
39 }
40
41 static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
42 unsigned long flags)
43 {
44 return 0;
45 }
46
47 static unsigned long
48 soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
49 {
50 struct soc_camera_platform_info *p = soc_camera_platform_get_info(icd);
51 return p->bus_param;
52 }
53
54 static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
55 struct v4l2_rect *rect)
56 {
57 return 0;
58 }
59
60 static int soc_camera_platform_try_fmt(struct v4l2_subdev *sd,
61 struct v4l2_format *f)
62 {
63 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
64 struct v4l2_pix_format *pix = &f->fmt.pix;
65
66 pix->width = p->format.width;
67 pix->height = p->format.height;
68 return 0;
69 }
70
71 static void soc_camera_platform_video_probe(struct soc_camera_device *icd,
72 struct platform_device *pdev)
73 {
74 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
75 struct soc_camera_platform_info *p = pdev->dev.platform_data;
76
77 priv->format.name = p->format_name;
78 priv->format.depth = p->format_depth;
79 priv->format.fourcc = p->format.pixelformat;
80 priv->format.colorspace = p->format.colorspace;
81
82 icd->formats = &priv->format;
83 icd->num_formats = 1;
84 }
85
86 static struct v4l2_subdev_core_ops platform_subdev_core_ops;
87
88 static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
89 .s_stream = soc_camera_platform_s_stream,
90 .try_fmt = soc_camera_platform_try_fmt,
91 };
92
93 static struct v4l2_subdev_ops platform_subdev_ops = {
94 .core = &platform_subdev_core_ops,
95 .video = &platform_subdev_video_ops,
96 };
97
98 static struct soc_camera_ops soc_camera_platform_ops = {
99 .set_crop = soc_camera_platform_set_crop,
100 .set_bus_param = soc_camera_platform_set_bus_param,
101 .query_bus_param = soc_camera_platform_query_bus_param,
102 };
103
104 static int soc_camera_platform_probe(struct platform_device *pdev)
105 {
106 struct soc_camera_host *ici;
107 struct soc_camera_platform_priv *priv;
108 struct soc_camera_platform_info *p = pdev->dev.platform_data;
109 struct soc_camera_device *icd;
110 int ret;
111
112 if (!p)
113 return -EINVAL;
114
115 if (!p->dev) {
116 dev_err(&pdev->dev,
117 "Platform has not set soc_camera_device pointer!\n");
118 return -EINVAL;
119 }
120
121 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
122 if (!priv)
123 return -ENOMEM;
124
125 icd = to_soc_camera_dev(p->dev);
126
127 platform_set_drvdata(pdev, priv);
128 dev_set_drvdata(&icd->dev, &pdev->dev);
129
130 icd->width_min = 0;
131 icd->rect_max.width = p->format.width;
132 icd->height_min = 0;
133 icd->rect_max.height = p->format.height;
134 icd->y_skip_top = 0;
135 icd->ops = &soc_camera_platform_ops;
136
137 ici = to_soc_camera_host(icd->dev.parent);
138
139 soc_camera_platform_video_probe(icd, pdev);
140
141 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
142 v4l2_set_subdevdata(&priv->subdev, p);
143 priv->subdev.grp_id = (__u32)icd;
144 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE);
145
146 ret = v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
147 if (ret)
148 goto evdrs;
149
150 return ret;
151
152 evdrs:
153 icd->ops = NULL;
154 platform_set_drvdata(pdev, NULL);
155 kfree(priv);
156 return ret;
157 }
158
159 static int soc_camera_platform_remove(struct platform_device *pdev)
160 {
161 struct soc_camera_platform_priv *priv = platform_get_drvdata(pdev);
162 struct soc_camera_platform_info *p = pdev->dev.platform_data;
163 struct soc_camera_device *icd = to_soc_camera_dev(p->dev);
164
165 v4l2_device_unregister_subdev(&priv->subdev);
166 icd->ops = NULL;
167 platform_set_drvdata(pdev, NULL);
168 kfree(priv);
169 return 0;
170 }
171
172 static struct platform_driver soc_camera_platform_driver = {
173 .driver = {
174 .name = "soc_camera_platform",
175 .owner = THIS_MODULE,
176 },
177 .probe = soc_camera_platform_probe,
178 .remove = soc_camera_platform_remove,
179 };
180
181 static int __init soc_camera_platform_module_init(void)
182 {
183 return platform_driver_register(&soc_camera_platform_driver);
184 }
185
186 static void __exit soc_camera_platform_module_exit(void)
187 {
188 platform_driver_unregister(&soc_camera_platform_driver);
189 }
190
191 module_init(soc_camera_platform_module_init);
192 module_exit(soc_camera_platform_module_exit);
193
194 MODULE_DESCRIPTION("SoC Camera Platform driver");
195 MODULE_AUTHOR("Magnus Damm");
196 MODULE_LICENSE("GPL v2");
197 MODULE_ALIAS("platform:soc_camera_platform");