PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / media / platform / soc_camera / soc_camera_platform.c
blobceaddfb85e492f6551a4c12fab5565c3f5f28e33
1 /*
2 * Generic Platform Camera Driver
4 * Copyright (C) 2008 Magnus Damm
5 * Based on mt9m001 driver,
6 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
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.
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>
23 struct soc_camera_platform_priv {
24 struct v4l2_subdev subdev;
27 static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
29 struct v4l2_subdev *subdev = platform_get_drvdata(pdev);
30 return container_of(subdev, struct soc_camera_platform_priv, subdev);
33 static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
35 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
36 return p->set_capture(p, enable);
39 static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
40 struct v4l2_mbus_framefmt *mf)
42 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
44 mf->width = p->format.width;
45 mf->height = p->format.height;
46 mf->code = p->format.code;
47 mf->colorspace = p->format.colorspace;
48 mf->field = p->format.field;
50 return 0;
53 static int soc_camera_platform_s_power(struct v4l2_subdev *sd, int on)
55 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
57 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, NULL, on);
60 static struct v4l2_subdev_core_ops platform_subdev_core_ops = {
61 .s_power = soc_camera_platform_s_power,
64 static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
65 enum v4l2_mbus_pixelcode *code)
67 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
69 if (index)
70 return -EINVAL;
72 *code = p->format.code;
73 return 0;
76 static int soc_camera_platform_g_crop(struct v4l2_subdev *sd,
77 struct v4l2_crop *a)
79 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
81 a->c.left = 0;
82 a->c.top = 0;
83 a->c.width = p->format.width;
84 a->c.height = p->format.height;
85 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
87 return 0;
90 static int soc_camera_platform_cropcap(struct v4l2_subdev *sd,
91 struct v4l2_cropcap *a)
93 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
95 a->bounds.left = 0;
96 a->bounds.top = 0;
97 a->bounds.width = p->format.width;
98 a->bounds.height = p->format.height;
99 a->defrect = a->bounds;
100 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 a->pixelaspect.numerator = 1;
102 a->pixelaspect.denominator = 1;
104 return 0;
107 static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
108 struct v4l2_mbus_config *cfg)
110 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
112 cfg->flags = p->mbus_param;
113 cfg->type = p->mbus_type;
115 return 0;
118 static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
119 .s_stream = soc_camera_platform_s_stream,
120 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
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,
126 .g_mbus_config = soc_camera_platform_g_mbus_config,
129 static struct v4l2_subdev_ops platform_subdev_ops = {
130 .core = &platform_subdev_core_ops,
131 .video = &platform_subdev_video_ops,
134 static int soc_camera_platform_probe(struct platform_device *pdev)
136 struct soc_camera_host *ici;
137 struct soc_camera_platform_priv *priv;
138 struct soc_camera_platform_info *p = pdev->dev.platform_data;
139 struct soc_camera_device *icd;
141 if (!p)
142 return -EINVAL;
144 if (!p->icd) {
145 dev_err(&pdev->dev,
146 "Platform has not set soc_camera_device pointer!\n");
147 return -EINVAL;
150 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
151 if (!priv)
152 return -ENOMEM;
154 icd = p->icd;
156 /* soc-camera convention: control's drvdata points to the subdev */
157 platform_set_drvdata(pdev, &priv->subdev);
158 /* Set the control device reference */
159 icd->control = &pdev->dev;
161 ici = to_soc_camera_host(icd->parent);
163 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
164 v4l2_set_subdevdata(&priv->subdev, p);
165 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE);
167 return v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
170 static int soc_camera_platform_remove(struct platform_device *pdev)
172 struct soc_camera_platform_priv *priv = get_priv(pdev);
173 struct soc_camera_platform_info *p = v4l2_get_subdevdata(&priv->subdev);
175 p->icd->control = NULL;
176 v4l2_device_unregister_subdev(&priv->subdev);
177 return 0;
180 static struct platform_driver soc_camera_platform_driver = {
181 .driver = {
182 .name = "soc_camera_platform",
183 .owner = THIS_MODULE,
185 .probe = soc_camera_platform_probe,
186 .remove = soc_camera_platform_remove,
189 module_platform_driver(soc_camera_platform_driver);
191 MODULE_DESCRIPTION("SoC Camera Platform driver");
192 MODULE_AUTHOR("Magnus Damm");
193 MODULE_LICENSE("GPL v2");
194 MODULE_ALIAS("platform:soc_camera_platform");