[media] v4l2: replace enum_mbus_fmt by enum_mbus_code
[deliverable/linux.git] / drivers / media / platform / soc_camera / 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};
26
08590b96 27static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
326c9862 28{
08590b96
GL
29 struct v4l2_subdev *subdev = platform_get_drvdata(pdev);
30 return container_of(subdev, struct soc_camera_platform_priv, subdev);
31}
32
979ea1dd 33static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
326c9862 34{
979ea1dd
GL
35 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
36 return p->set_capture(p, enable);
326c9862
MD
37}
38
e7d403f5
KM
39static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
40 struct v4l2_mbus_framefmt *mf)
326c9862 41{
979ea1dd 42 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
326c9862 43
760697be
GL
44 mf->width = p->format.width;
45 mf->height = p->format.height;
46 mf->code = p->format.code;
47 mf->colorspace = p->format.colorspace;
e7d403f5 48 mf->field = p->format.field;
760697be 49
326c9862
MD
50 return 0;
51}
52
4ec10bac
LP
53static int soc_camera_platform_s_power(struct v4l2_subdev *sd, int on)
54{
55 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
56
9aea470b 57 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, NULL, on);
4ec10bac
LP
58}
59
60static struct v4l2_subdev_core_ops platform_subdev_core_ops = {
61 .s_power = soc_camera_platform_s_power,
62};
760697be 63
ebcff5fc
HV
64static int soc_camera_platform_enum_mbus_code(struct v4l2_subdev *sd,
65 struct v4l2_subdev_pad_config *cfg,
66 struct v4l2_subdev_mbus_code_enum *code)
326c9862 67{
760697be 68 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
326c9862 69
ebcff5fc 70 if (code->pad || code->index)
760697be 71 return -EINVAL;
326c9862 72
ebcff5fc 73 code->code = p->format.code;
760697be 74 return 0;
326c9862
MD
75}
76
e7d403f5
KM
77static int soc_camera_platform_g_crop(struct v4l2_subdev *sd,
78 struct v4l2_crop *a)
79{
80 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
81
82 a->c.left = 0;
83 a->c.top = 0;
84 a->c.width = p->format.width;
85 a->c.height = p->format.height;
86 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
87
88 return 0;
89}
90
91static int soc_camera_platform_cropcap(struct v4l2_subdev *sd,
92 struct v4l2_cropcap *a)
93{
94 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
95
96 a->bounds.left = 0;
97 a->bounds.top = 0;
98 a->bounds.width = p->format.width;
99 a->bounds.height = p->format.height;
100 a->defrect = a->bounds;
101 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
102 a->pixelaspect.numerator = 1;
103 a->pixelaspect.denominator = 1;
104
105 return 0;
106}
107
84c760a5
GL
108static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
109 struct v4l2_mbus_config *cfg)
110{
111 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
112
113 cfg->flags = p->mbus_param;
114 cfg->type = p->mbus_type;
115
116 return 0;
117}
118
979ea1dd
GL
119static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
120 .s_stream = soc_camera_platform_s_stream,
e7d403f5
KM
121 .cropcap = soc_camera_platform_cropcap,
122 .g_crop = soc_camera_platform_g_crop,
123 .try_mbus_fmt = soc_camera_platform_fill_fmt,
124 .g_mbus_fmt = soc_camera_platform_fill_fmt,
125 .s_mbus_fmt = soc_camera_platform_fill_fmt,
84c760a5 126 .g_mbus_config = soc_camera_platform_g_mbus_config,
979ea1dd
GL
127};
128
ebcff5fc
HV
129static const struct v4l2_subdev_pad_ops platform_subdev_pad_ops = {
130 .enum_mbus_code = soc_camera_platform_enum_mbus_code,
131};
132
979ea1dd
GL
133static struct v4l2_subdev_ops platform_subdev_ops = {
134 .core = &platform_subdev_core_ops,
135 .video = &platform_subdev_video_ops,
ebcff5fc 136 .pad = &platform_subdev_pad_ops,
979ea1dd
GL
137};
138
326c9862
MD
139static int soc_camera_platform_probe(struct platform_device *pdev)
140{
979ea1dd 141 struct soc_camera_host *ici;
326c9862 142 struct soc_camera_platform_priv *priv;
40e2e092 143 struct soc_camera_platform_info *p = pdev->dev.platform_data;
326c9862 144 struct soc_camera_device *icd;
326c9862 145
326c9862
MD
146 if (!p)
147 return -EINVAL;
148
7dfff953 149 if (!p->icd) {
979ea1dd
GL
150 dev_err(&pdev->dev,
151 "Platform has not set soc_camera_device pointer!\n");
152 return -EINVAL;
153 }
154
70e176a5 155 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
326c9862
MD
156 if (!priv)
157 return -ENOMEM;
158
7dfff953 159 icd = p->icd;
40e2e092 160
08590b96
GL
161 /* soc-camera convention: control's drvdata points to the subdev */
162 platform_set_drvdata(pdev, &priv->subdev);
163 /* Set the control device reference */
7dfff953 164 icd->control = &pdev->dev;
979ea1dd 165
7dfff953 166 ici = to_soc_camera_host(icd->parent);
979ea1dd 167
979ea1dd
GL
168 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
169 v4l2_set_subdevdata(&priv->subdev, p);
979ea1dd
GL
170 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE);
171
f253f184 172 return v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
326c9862
MD
173}
174
175static int soc_camera_platform_remove(struct platform_device *pdev)
176{
08590b96 177 struct soc_camera_platform_priv *priv = get_priv(pdev);
fff96b66 178 struct soc_camera_platform_info *p = v4l2_get_subdevdata(&priv->subdev);
326c9862 179
fff96b66 180 p->icd->control = NULL;
979ea1dd 181 v4l2_device_unregister_subdev(&priv->subdev);
326c9862
MD
182 return 0;
183}
184
185static struct platform_driver soc_camera_platform_driver = {
992bc797 186 .driver = {
326c9862
MD
187 .name = "soc_camera_platform",
188 },
189 .probe = soc_camera_platform_probe,
190 .remove = soc_camera_platform_remove,
191};
192
1d6629b1 193module_platform_driver(soc_camera_platform_driver);
326c9862
MD
194
195MODULE_DESCRIPTION("SoC Camera Platform driver");
196MODULE_AUTHOR("Magnus Damm");
197MODULE_LICENSE("GPL v2");
40e2e092 198MODULE_ALIAS("platform:soc_camera_platform");
This page took 0.671892 seconds and 5 git commands to generate.