summaryrefslogtreecommitdiffstats
path: root/bsp/meta-rcar/meta-rcar-gen3-adas/recipes-kernel/linux/linux-renesas/0393-media-soc_camera-dummy-add-mbus-controls-ids.patch
blob: 7f72578da03d23111e815e0c5c3054ed28fe7199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
From e0b7cbaad7f2cea64239929ac96af234027bd19f Mon Sep 17 00:00:00 2001
From: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
Date: Mon, 17 Jun 2019 23:19:20 +0300
Subject: [PATCH] media: soc_camera: dummy: add mbus, controls, ids

This add different media buses, controls, otp ids and
module params

Signed-off-by: Vladimir Barinov <vladimir.barinov@cogentembedded.com>
---
 drivers/media/i2c/soc_camera/dummy.c | 216 +++++++++++++++++++++++++++++++----
 1 file changed, 195 insertions(+), 21 deletions(-)

diff --git a/drivers/media/i2c/soc_camera/dummy.c b/drivers/media/i2c/soc_camera/dummy.c
index a38d7c4..d213fff 100644
--- a/drivers/media/i2c/soc_camera/dummy.c
+++ b/drivers/media/i2c/soc_camera/dummy.c
@@ -20,17 +20,30 @@
 #include <media/v4l2-common.h>
 #include <media/v4l2-ctrls.h>
 
-#define MEDIA_BUS_FORMAT MEDIA_BUS_FMT_YUYV8_2X8
-
 struct dummy_priv {
 	struct v4l2_subdev		sd;
 	struct v4l2_ctrl_handler	hdl;
 	struct media_pad		pad;
 	struct v4l2_rect		rect;
+	u8				id[6];
 	int				max_width;
 	int				max_height;
+	const char *			media_bus_format;
+	int				mbus_format;
 };
 
+static int width = 1920;
+module_param(width, int, 0644);
+MODULE_PARM_DESC(width, " width (default: 1920)");
+
+static int height = 1080;
+module_param(height, int, 0644);
+MODULE_PARM_DESC(height, " height (default: 1080)");
+
+static char *mbus = "yuyv";
+module_param(mbus, charp, 0644);
+MODULE_PARM_DESC(mbus, " MEDIA_BUS_FORMAT (default: YUYV)");
+
 static inline struct dummy_priv *to_dummy(const struct i2c_client *client)
 {
 	return container_of(i2c_get_clientdata(client), struct dummy_priv, sd);
@@ -59,7 +72,7 @@ static int dummy_get_fmt(struct v4l2_subdev *sd,
 
 	mf->width = priv->rect.width;
 	mf->height = priv->rect.height;
-	mf->code = MEDIA_BUS_FORMAT;
+	mf->code = priv->mbus_format;
 	mf->colorspace = V4L2_COLORSPACE_SMPTE170M;
 	mf->field = V4L2_FIELD_NONE;
 
@@ -71,8 +84,10 @@ static int dummy_set_fmt(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_format *format)
 {
 	struct v4l2_mbus_framefmt *mf = &format->format;
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct dummy_priv *priv = to_dummy(client);
 
-	mf->code = MEDIA_BUS_FORMAT;
+	mf->code = priv->mbus_format;
 	mf->colorspace = V4L2_COLORSPACE_SMPTE170M;
 	mf->field = V4L2_FIELD_NONE;
 
@@ -86,10 +101,28 @@ static int dummy_enum_mbus_code(struct v4l2_subdev *sd,
 				struct v4l2_subdev_pad_config *cfg,
 				struct v4l2_subdev_mbus_code_enum *code)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct dummy_priv *priv = to_dummy(client);
+
 	if (code->pad || code->index > 0)
 		return -EINVAL;
 
-	code->code = MEDIA_BUS_FORMAT;
+	code->code = priv->mbus_format;
+
+	return 0;
+}
+
+static int dummy_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct dummy_priv *priv = to_dummy(client);
+
+	memcpy(edid->edid, priv->id, 6);
+
+	edid->edid[6] = 0xff;
+	edid->edid[7] = client->addr;
+	edid->edid[8] = 'D' >> 8;
+	edid->edid[9] = 'Y' & 0xff;
 
 	return 0;
 }
@@ -164,9 +197,50 @@ static int dummy_g_mbus_config(struct v4l2_subdev *sd,
 	return 0;
 }
 
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int dummy_g_register(struct v4l2_subdev *sd,
+			    struct v4l2_dbg_register *reg)
+{
+	reg->val = 0;
+	reg->size = sizeof(u16);
+
+	return 0;
+}
+
+static int dummy_s_register(struct v4l2_subdev *sd,
+			    const struct v4l2_dbg_register *reg)
+{
+	return 0;
+}
+#endif
+
+static struct v4l2_subdev_core_ops dummy_core_ops = {
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	.g_register = dummy_g_register,
+	.s_register = dummy_s_register,
+#endif
+};
+
 static int dummy_s_ctrl(struct v4l2_ctrl *ctrl)
 {
-	return -EINVAL;
+	switch (ctrl->id) {
+	case V4L2_CID_BRIGHTNESS:
+	case V4L2_CID_CONTRAST:
+	case V4L2_CID_SATURATION:
+	case V4L2_CID_HUE:
+	case V4L2_CID_GAMMA:
+	case V4L2_CID_SHARPNESS:
+	case V4L2_CID_AUTOGAIN:
+	case V4L2_CID_GAIN:
+	case V4L2_CID_ANALOGUE_GAIN:
+	case V4L2_CID_EXPOSURE:
+	case V4L2_CID_HFLIP:
+	case V4L2_CID_VFLIP:
+	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+		break;
+	}
+
+	return 0;
 }
 
 static const struct v4l2_ctrl_ops dummy_ctrl_ops = {
@@ -179,6 +253,7 @@ static struct v4l2_subdev_video_ops dummy_video_ops = {
 };
 
 static const struct v4l2_subdev_pad_ops dummy_subdev_pad_ops = {
+	.get_edid	= dummy_get_edid,
 	.enum_mbus_code	= dummy_enum_mbus_code,
 	.get_selection	= dummy_get_selection,
 	.set_selection	= dummy_set_selection,
@@ -187,38 +262,107 @@ static const struct v4l2_subdev_pad_ops dummy_subdev_pad_ops = {
 };
 
 static struct v4l2_subdev_ops dummy_subdev_ops = {
+	.core	= &dummy_core_ops,
 	.video	= &dummy_video_ops,
 	.pad	= &dummy_subdev_pad_ops,
 };
 
+static void dummy_otp_id_read(struct i2c_client *client)
+{
+	struct dummy_priv *priv = to_dummy(client);
+
+	/* dummy camera id */
+	priv->id[0] = 'd';
+	priv->id[1] = 'u';
+	priv->id[2] = 'm';
+	priv->id[3] = 'm';
+	priv->id[4] = 'y';
+	priv->id[5] = '.';
+}
+
+static ssize_t dummy_otp_id_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(to_i2c_client(dev));
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct dummy_priv *priv = to_dummy(client);
+
+	dummy_otp_id_read(client);
+
+	return snprintf(buf, 32, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+			priv->id[0], priv->id[1], priv->id[2], priv->id[3], priv->id[4], priv->id[5]);
+}
+
+static DEVICE_ATTR(otp_id_dummy, S_IRUGO, dummy_otp_id_show, NULL);
+
 static int dummy_initialize(struct i2c_client *client)
 {
 	struct dummy_priv *priv = to_dummy(client);
 
-	dev_info(&client->dev, "Dummy sensor res %dx%d\n", priv->max_width, priv->max_height);
+	if (strcmp(priv->media_bus_format, "yuyv") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_YUYV8_2X8;
+	else if (strcmp(priv->media_bus_format, "uyvy") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_UYVY8_2X8;
+	else if (strcmp(priv->media_bus_format, "grey") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_Y8_1X8;
+	else if (strcmp(priv->media_bus_format, "rggb8") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SRGGB8_1X8;
+	else if (strcmp(priv->media_bus_format, "bggr8") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SBGGR8_1X8;
+	else if (strcmp(priv->media_bus_format, "grbg8") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SGRBG8_1X8;
+	else if (strcmp(priv->media_bus_format, "rggb12") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SRGGB12_1X12;
+	else if (strcmp(priv->media_bus_format, "bggr12") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SBGGR12_1X12;
+	else if (strcmp(priv->media_bus_format, "grbg12") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SGRBG12_1X12;
+	else if (strcmp(priv->media_bus_format, "rggb14") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SRGGB14_1X14;
+	else if (strcmp(priv->media_bus_format, "bggr14") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SBGGR14_1X14;
+	else if (strcmp(priv->media_bus_format, "grbg14") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SGRBG14_1X14;
+	else if (strcmp(priv->media_bus_format, "rggb16") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SRGGB16_1X16;
+	else if (strcmp(priv->media_bus_format, "bggr16") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SBGGR16_1X16;
+	else if (strcmp(priv->media_bus_format, "grbg16") == 0)
+		priv->mbus_format = MEDIA_BUS_FMT_SGRBG16_1X16;
+	else {
+		v4l_err(client, "failed to parse mbus format (%s)\n", priv->media_bus_format);
+		return -EINVAL;
+	}
+
+	/* Read OTP IDs */
+	dummy_otp_id_read(client);
+
+	dev_info(&client->dev, "Dummy camera sensor, res %dx%d, mbus %s, OTP_ID %02x:%02x:%02x:%02x:%02x:%02x\n",
+		 priv->max_width, priv->max_height, priv->media_bus_format, priv->id[0], priv->id[1], priv->id[2], priv->id[3], priv->id[4], priv->id[5]);
 
 	return 0;
 }
 
 static int dummy_parse_dt(struct device_node *np, struct dummy_priv *priv)
 {
-	struct i2c_client *client = v4l2_get_subdevdata(&priv->sd);
-	int err;
+	if (of_property_read_u32(np, "dummy,width", &priv->max_width))
+		priv->max_width = width;
 
-	err = of_property_read_u32(np, "dummy,width", &priv->max_width);
-	if (err) {
-		dev_err(&client->dev, "dummy,width must be defined\n");
-		goto out;
-	}
+	if (of_property_read_u32(np, "dummy,height", &priv->max_height))
+		priv->max_height = height;
 
-	err = of_property_read_u32(np, "dummy,height", &priv->max_height);
-	if (err) {
-		dev_err(&client->dev, "dummy,height must be defined\n");
-		goto out;
-	}
+	if (of_property_read_string(np, "dummy,mbus", &priv->media_bus_format))
+		priv->media_bus_format = mbus;
 
-out:
-	return err;
+	/* module params override dts */
+	if (strcmp(mbus, "yuyv"))
+		priv->media_bus_format = mbus;
+	if (width != 1920)
+		priv->max_width = width;
+	if (height != 1080)
+		priv->max_height = height;
+
+	return 0;
 }
 
 static int dummy_probe(struct i2c_client *client,
@@ -235,6 +379,30 @@ static int dummy_probe(struct i2c_client *client,
 	priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
 
 	v4l2_ctrl_handler_init(&priv->hdl, 4);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_BRIGHTNESS, 0, 16, 1, 7);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_CONTRAST, 0, 16, 1, 7);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_SATURATION, 0, 7, 1, 2);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_HUE, 0, 23, 1, 12);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_GAMMA, -128, 128, 1, 0);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_SHARPNESS, 0, 10, 1, 3);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_AUTOGAIN, 0, 1, 1, 0);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_GAIN, 1, 0x7ff, 1, 0x200);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_ANALOGUE_GAIN, 1, 0xe, 1, 0xa);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_EXPOSURE, 1, 0x600, 1, 0x144);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_HFLIP, 0, 1, 1, 0);
+	v4l2_ctrl_new_std(&priv->hdl, &dummy_ctrl_ops,
+			  V4L2_CID_VFLIP, 0, 1, 1, 0);
 	priv->sd.ctrl_handler = &priv->hdl;
 
 	ret = priv->hdl.error;
@@ -266,6 +434,11 @@ static int dummy_probe(struct i2c_client *client,
 	if (ret)
 		goto cleanup;
 
+	if (device_create_file(&client->dev, &dev_attr_otp_id_dummy) != 0) {
+		dev_err(&client->dev, "sysfs otp_id entry creation failed\n");
+		goto cleanup;
+	}
+
 	return 0;
 
 cleanup:
@@ -281,6 +454,7 @@ static int dummy_remove(struct i2c_client *client)
 {
 	struct dummy_priv *priv = i2c_get_clientdata(client);
 
+	device_remove_file(&client->dev, &dev_attr_otp_id_dummy);
 	v4l2_async_unregister_subdev(&priv->sd);
 	media_entity_cleanup(&priv->sd.entity);
 	v4l2_ctrl_handler_free(&priv->hdl);
-- 
2.7.4