perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / media / platform / soc_camera / soc_camera_platform.c
blob6745a6e3f464d57f5c0104570988fa05c79fada0
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Generic Platform Camera Driver
5 * Copyright (C) 2008 Magnus Damm
6 * Based on mt9m001 driver,
7 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
8 */
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/delay.h>
14 #include <linux/platform_device.h>
15 #include <linux/videodev2.h>
16 #include <media/v4l2-subdev.h>
17 #include <media/soc_camera.h>
18 #include <linux/platform_data/media/soc_camera_platform.h>
20 struct soc_camera_platform_priv {
21 struct v4l2_subdev subdev;
24 static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
26 struct v4l2_subdev *subdev = platform_get_drvdata(pdev);
27 return container_of(subdev, struct soc_camera_platform_priv, subdev);
30 static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
32 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
33 return p->set_capture(p, enable);
36 static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
37 struct v4l2_subdev_pad_config *cfg,
38 struct v4l2_subdev_format *format)
40 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
41 struct v4l2_mbus_framefmt *mf = &format->format;
43 mf->width = p->format.width;
44 mf->height = p->format.height;
45 mf->code = p->format.code;
46 mf->colorspace = p->format.colorspace;
47 mf->field = p->format.field;
49 return 0;
52 static int soc_camera_platform_s_power(struct v4l2_subdev *sd, int on)
54 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
56 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, NULL, on);
59 static const struct v4l2_subdev_core_ops platform_subdev_core_ops = {
60 .s_power = soc_camera_platform_s_power,
63 static int soc_camera_platform_enum_mbus_code(struct v4l2_subdev *sd,
64 struct v4l2_subdev_pad_config *cfg,
65 struct v4l2_subdev_mbus_code_enum *code)
67 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
69 if (code->pad || code->index)
70 return -EINVAL;
72 code->code = p->format.code;
73 return 0;
76 static int soc_camera_platform_get_selection(struct v4l2_subdev *sd,
77 struct v4l2_subdev_pad_config *cfg,
78 struct v4l2_subdev_selection *sel)
80 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
82 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
83 return -EINVAL;
85 switch (sel->target) {
86 case V4L2_SEL_TGT_CROP_BOUNDS:
87 case V4L2_SEL_TGT_CROP_DEFAULT:
88 case V4L2_SEL_TGT_CROP:
89 sel->r.left = 0;
90 sel->r.top = 0;
91 sel->r.width = p->format.width;
92 sel->r.height = p->format.height;
93 return 0;
94 default:
95 return -EINVAL;
99 static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
100 struct v4l2_mbus_config *cfg)
102 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
104 cfg->flags = p->mbus_param;
105 cfg->type = p->mbus_type;
107 return 0;
110 static const struct v4l2_subdev_video_ops platform_subdev_video_ops = {
111 .s_stream = soc_camera_platform_s_stream,
112 .g_mbus_config = soc_camera_platform_g_mbus_config,
115 static const struct v4l2_subdev_pad_ops platform_subdev_pad_ops = {
116 .enum_mbus_code = soc_camera_platform_enum_mbus_code,
117 .get_selection = soc_camera_platform_get_selection,
118 .get_fmt = soc_camera_platform_fill_fmt,
119 .set_fmt = soc_camera_platform_fill_fmt,
122 static const struct v4l2_subdev_ops platform_subdev_ops = {
123 .core = &platform_subdev_core_ops,
124 .video = &platform_subdev_video_ops,
125 .pad = &platform_subdev_pad_ops,
128 static int soc_camera_platform_probe(struct platform_device *pdev)
130 struct soc_camera_host *ici;
131 struct soc_camera_platform_priv *priv;
132 struct soc_camera_platform_info *p = pdev->dev.platform_data;
133 struct soc_camera_device *icd;
135 if (!p)
136 return -EINVAL;
138 if (!p->icd) {
139 dev_err(&pdev->dev,
140 "Platform has not set soc_camera_device pointer!\n");
141 return -EINVAL;
144 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
145 if (!priv)
146 return -ENOMEM;
148 icd = p->icd;
150 /* soc-camera convention: control's drvdata points to the subdev */
151 platform_set_drvdata(pdev, &priv->subdev);
152 /* Set the control device reference */
153 icd->control = &pdev->dev;
155 ici = to_soc_camera_host(icd->parent);
157 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
158 v4l2_set_subdevdata(&priv->subdev, p);
159 strlcpy(priv->subdev.name, dev_name(&pdev->dev),
160 sizeof(priv->subdev.name));
162 return v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
165 static int soc_camera_platform_remove(struct platform_device *pdev)
167 struct soc_camera_platform_priv *priv = get_priv(pdev);
168 struct soc_camera_platform_info *p = v4l2_get_subdevdata(&priv->subdev);
170 p->icd->control = NULL;
171 v4l2_device_unregister_subdev(&priv->subdev);
172 return 0;
175 static struct platform_driver soc_camera_platform_driver = {
176 .driver = {
177 .name = "soc_camera_platform",
179 .probe = soc_camera_platform_probe,
180 .remove = soc_camera_platform_remove,
183 module_platform_driver(soc_camera_platform_driver);
185 MODULE_DESCRIPTION("SoC Camera Platform driver");
186 MODULE_AUTHOR("Magnus Damm");
187 MODULE_LICENSE("GPL v2");
188 MODULE_ALIAS("platform:soc_camera_platform");