V4L/DVB (12529): soc-camera: switch to s_crop v4l2-subdev video operation
[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>
979ea1dd 19#include <media/v4l2-subdev.h>
326c9862 20#include <media/soc_camera.h>
50c616fd 21#include <media/soc_camera_platform.h>
326c9862
MD
22
23struct soc_camera_platform_priv {
979ea1dd 24 struct v4l2_subdev subdev;
326c9862
MD
25 struct soc_camera_data_format format;
26};
27
08590b96 28static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
326c9862 29{
08590b96
GL
30 struct v4l2_subdev *subdev = platform_get_drvdata(pdev);
31 return container_of(subdev, struct soc_camera_platform_priv, subdev);
32}
33
34static struct soc_camera_platform_info *get_info(struct soc_camera_device *icd)
35{
36 struct platform_device *pdev = to_platform_device(to_soc_camera_control(icd));
40e2e092 37 return pdev->dev.platform_data;
326c9862
MD
38}
39
979ea1dd 40static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
326c9862 41{
979ea1dd
GL
42 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
43 return p->set_capture(p, enable);
326c9862
MD
44}
45
46static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
47 unsigned long flags)
48{
49 return 0;
50}
51
52static unsigned long
53soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
54{
08590b96 55 struct soc_camera_platform_info *p = get_info(icd);
326c9862
MD
56 return p->bus_param;
57}
58
979ea1dd 59static int soc_camera_platform_try_fmt(struct v4l2_subdev *sd,
09e231b3 60 struct v4l2_format *f)
326c9862 61{
979ea1dd 62 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
64f5905e 63 struct v4l2_pix_format *pix = &f->fmt.pix;
326c9862 64
64f5905e
GL
65 pix->width = p->format.width;
66 pix->height = p->format.height;
326c9862
MD
67 return 0;
68}
69
979ea1dd
GL
70static void soc_camera_platform_video_probe(struct soc_camera_device *icd,
71 struct platform_device *pdev)
326c9862 72{
08590b96 73 struct soc_camera_platform_priv *priv = get_priv(pdev);
40e2e092 74 struct soc_camera_platform_info *p = pdev->dev.platform_data;
326c9862 75
40e2e092
GL
76 priv->format.name = p->format_name;
77 priv->format.depth = p->format_depth;
78 priv->format.fourcc = p->format.pixelformat;
79 priv->format.colorspace = p->format.colorspace;
326c9862
MD
80
81 icd->formats = &priv->format;
82 icd->num_formats = 1;
326c9862
MD
83}
84
979ea1dd
GL
85static struct v4l2_subdev_core_ops platform_subdev_core_ops;
86
87static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
88 .s_stream = soc_camera_platform_s_stream,
89 .try_fmt = soc_camera_platform_try_fmt,
90};
91
92static struct v4l2_subdev_ops platform_subdev_ops = {
93 .core = &platform_subdev_core_ops,
94 .video = &platform_subdev_video_ops,
95};
96
326c9862 97static struct soc_camera_ops soc_camera_platform_ops = {
326c9862
MD
98 .set_bus_param = soc_camera_platform_set_bus_param,
99 .query_bus_param = soc_camera_platform_query_bus_param,
100};
101
102static int soc_camera_platform_probe(struct platform_device *pdev)
103{
979ea1dd 104 struct soc_camera_host *ici;
326c9862 105 struct soc_camera_platform_priv *priv;
40e2e092 106 struct soc_camera_platform_info *p = pdev->dev.platform_data;
326c9862
MD
107 struct soc_camera_device *icd;
108 int ret;
109
326c9862
MD
110 if (!p)
111 return -EINVAL;
112
979ea1dd
GL
113 if (!p->dev) {
114 dev_err(&pdev->dev,
115 "Platform has not set soc_camera_device pointer!\n");
116 return -EINVAL;
117 }
118
326c9862
MD
119 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
120 if (!priv)
121 return -ENOMEM;
122
40e2e092 123 icd = to_soc_camera_dev(p->dev);
40e2e092 124
08590b96
GL
125 /* soc-camera convention: control's drvdata points to the subdev */
126 platform_set_drvdata(pdev, &priv->subdev);
127 /* Set the control device reference */
40e2e092 128 dev_set_drvdata(&icd->dev, &pdev->dev);
979ea1dd 129
a0705b07
GL
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;
326c9862 136
979ea1dd
GL
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;
326c9862
MD
149
150 return ret;
40e2e092 151
979ea1dd
GL
152evdrs:
153 icd->ops = NULL;
154 platform_set_drvdata(pdev, NULL);
40e2e092 155 kfree(priv);
979ea1dd 156 return ret;
326c9862
MD
157}
158
159static int soc_camera_platform_remove(struct platform_device *pdev)
160{
08590b96 161 struct soc_camera_platform_priv *priv = get_priv(pdev);
40e2e092
GL
162 struct soc_camera_platform_info *p = pdev->dev.platform_data;
163 struct soc_camera_device *icd = to_soc_camera_dev(p->dev);
326c9862 164
979ea1dd 165 v4l2_device_unregister_subdev(&priv->subdev);
40e2e092 166 icd->ops = NULL;
979ea1dd 167 platform_set_drvdata(pdev, NULL);
326c9862
MD
168 kfree(priv);
169 return 0;
170}
171
172static struct platform_driver soc_camera_platform_driver = {
173 .driver = {
174 .name = "soc_camera_platform",
979ea1dd 175 .owner = THIS_MODULE,
326c9862
MD
176 },
177 .probe = soc_camera_platform_probe,
178 .remove = soc_camera_platform_remove,
179};
180
181static int __init soc_camera_platform_module_init(void)
182{
183 return platform_driver_register(&soc_camera_platform_driver);
184}
185
186static void __exit soc_camera_platform_module_exit(void)
187{
01c1e4ca 188 platform_driver_unregister(&soc_camera_platform_driver);
326c9862
MD
189}
190
191module_init(soc_camera_platform_module_init);
192module_exit(soc_camera_platform_module_exit);
193
194MODULE_DESCRIPTION("SoC Camera Platform driver");
195MODULE_AUTHOR("Magnus Damm");
196MODULE_LICENSE("GPL v2");
40e2e092 197MODULE_ALIAS("platform:soc_camera_platform");
This page took 0.173978 seconds and 5 git commands to generate.