forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/staging/media/imx/imx-ic-prp.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * V4L2 Capture IC Preprocess Subdev for Freescale i.MX5/6 SOC
34 *
....@@ -6,11 +7,6 @@
67 * for resizing, colorspace conversion, and rotation.
78 *
89 * Copyright (c) 2012-2017 Mentor Graphics Inc.
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
1410 */
1511 #include <linux/delay.h>
1612 #include <linux/interrupt.h>
....@@ -30,8 +26,8 @@
3026 /*
3127 * Min/Max supported width and heights.
3228 */
33
-#define MIN_W 176
34
-#define MIN_H 144
29
+#define MIN_W 32
30
+#define MIN_H 32
3531 #define MAX_W 4096
3632 #define MAX_H 4096
3733 #define W_ALIGN 4 /* multiple of 16 pixels */
....@@ -39,15 +35,11 @@
3935 #define S_ALIGN 1 /* multiple of 2 */
4036
4137 struct prp_priv {
42
- struct imx_media_dev *md;
4338 struct imx_ic_priv *ic_priv;
4439 struct media_pad pad[PRP_NUM_PADS];
4540
4641 /* lock to protect all members below */
4742 struct mutex lock;
48
-
49
- /* IPU units we require */
50
- struct ipu_soc *ipu;
5143
5244 struct v4l2_subdev *src_sd;
5345 struct v4l2_subdev *sink_sd_prpenc;
....@@ -66,7 +58,7 @@
6658 {
6759 struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
6860
69
- return ic_priv->prp_priv;
61
+ return ic_priv->task_priv;
7062 }
7163
7264 static int prp_start(struct prp_priv *priv)
....@@ -74,12 +66,10 @@
7466 struct imx_ic_priv *ic_priv = priv->ic_priv;
7567 bool src_is_vdic;
7668
77
- priv->ipu = priv->md->ipu[ic_priv->ipu_id];
78
-
7969 /* set IC to receive from CSI or VDI depending on source */
80
- src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_VDIC);
70
+ src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC);
8171
82
- ipu_set_ic_src_mux(priv->ipu, priv->csi_id, src_is_vdic);
72
+ ipu_set_ic_src_mux(ic_priv->ipu, priv->csi_id, src_is_vdic);
8373
8474 return 0;
8575 }
....@@ -116,8 +106,8 @@
116106
117107 switch (code->pad) {
118108 case PRP_SINK_PAD:
119
- ret = imx_media_enum_ipu_format(&code->code, code->index,
120
- CS_SEL_ANY);
109
+ ret = imx_media_enum_ipu_formats(&code->code, code->index,
110
+ PIXFMT_SEL_YUV_RGB);
121111 break;
122112 case PRP_SRC_PAD_PRPENC:
123113 case PRP_SRC_PAD_PRPVF:
....@@ -190,15 +180,17 @@
190180 MIN_H, MAX_H, H_ALIGN, S_ALIGN);
191181
192182 cc = imx_media_find_ipu_format(sdformat->format.code,
193
- CS_SEL_ANY);
183
+ PIXFMT_SEL_YUV_RGB);
194184 if (!cc) {
195
- imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY);
196
- cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
185
+ imx_media_enum_ipu_formats(&code, 0,
186
+ PIXFMT_SEL_YUV_RGB);
187
+ cc = imx_media_find_ipu_format(code,
188
+ PIXFMT_SEL_YUV_RGB);
197189 sdformat->format.code = cc->codes[0];
198190 }
199191
200
- imx_media_fill_default_mbus_fields(&sdformat->format, infmt,
201
- true);
192
+ if (sdformat->format.field == V4L2_FIELD_ANY)
193
+ sdformat->format.field = V4L2_FIELD_NONE;
202194 break;
203195 case PRP_SRC_PAD_PRPENC:
204196 case PRP_SRC_PAD_PRPVF:
....@@ -206,6 +198,8 @@
206198 sdformat->format = *infmt;
207199 break;
208200 }
201
+
202
+ imx_media_try_colorimetry(&sdformat->format, true);
209203
210204 fmt = __prp_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
211205 *fmt = sdformat->format;
....@@ -220,12 +214,12 @@
220214 {
221215 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
222216 struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
223
- struct prp_priv *priv = ic_priv->prp_priv;
217
+ struct prp_priv *priv = ic_priv->task_priv;
224218 struct v4l2_subdev *remote_sd;
225219 int ret = 0;
226220
227
- dev_dbg(ic_priv->dev, "link setup %s -> %s", remote->entity->name,
228
- local->entity->name);
221
+ dev_dbg(ic_priv->ipu_dev, "%s: link setup %s -> %s",
222
+ ic_priv->sd.name, remote->entity->name, local->entity->name);
229223
230224 remote_sd = media_entity_to_v4l2_subdev(remote->entity);
231225
....@@ -237,8 +231,8 @@
237231 ret = -EBUSY;
238232 goto out;
239233 }
240
- if (priv->sink_sd_prpenc && (remote_sd->grp_id &
241
- IMX_MEDIA_GRP_ID_VDIC)) {
234
+ if (priv->sink_sd_prpenc &&
235
+ (remote_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC)) {
242236 ret = -EINVAL;
243237 goto out;
244238 }
....@@ -259,7 +253,7 @@
259253 goto out;
260254 }
261255 if (priv->src_sd && (priv->src_sd->grp_id &
262
- IMX_MEDIA_GRP_ID_VDIC)) {
256
+ IMX_MEDIA_GRP_ID_IPU_VDIC)) {
263257 ret = -EINVAL;
264258 goto out;
265259 }
....@@ -299,7 +293,7 @@
299293 struct v4l2_subdev_format *sink_fmt)
300294 {
301295 struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
302
- struct prp_priv *priv = ic_priv->prp_priv;
296
+ struct prp_priv *priv = ic_priv->task_priv;
303297 struct v4l2_subdev *csi;
304298 int ret;
305299
....@@ -308,14 +302,14 @@
308302 if (ret)
309303 return ret;
310304
311
- csi = imx_media_find_upstream_subdev(priv->md, &ic_priv->sd.entity,
312
- IMX_MEDIA_GRP_ID_CSI);
305
+ csi = imx_media_pipeline_subdev(&ic_priv->sd.entity,
306
+ IMX_MEDIA_GRP_ID_IPU_CSI, true);
313307 if (IS_ERR(csi))
314308 csi = NULL;
315309
316310 mutex_lock(&priv->lock);
317311
318
- if (priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_VDIC) {
312
+ if (priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC) {
319313 /*
320314 * the ->PRPENC link cannot be enabled if the source
321315 * is the VDIC
....@@ -334,10 +328,10 @@
334328
335329 if (csi) {
336330 switch (csi->grp_id) {
337
- case IMX_MEDIA_GRP_ID_CSI0:
331
+ case IMX_MEDIA_GRP_ID_IPU_CSI0:
338332 priv->csi_id = 0;
339333 break;
340
- case IMX_MEDIA_GRP_ID_CSI1:
334
+ case IMX_MEDIA_GRP_ID_IPU_CSI1:
341335 priv->csi_id = 1;
342336 break;
343337 default:
....@@ -355,7 +349,7 @@
355349 static int prp_s_stream(struct v4l2_subdev *sd, int enable)
356350 {
357351 struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
358
- struct prp_priv *priv = ic_priv->prp_priv;
352
+ struct prp_priv *priv = ic_priv->task_priv;
359353 int ret = 0;
360354
361355 mutex_lock(&priv->lock);
....@@ -372,7 +366,8 @@
372366 if (priv->stream_count != !enable)
373367 goto update_count;
374368
375
- dev_dbg(ic_priv->dev, "stream %s\n", enable ? "ON" : "OFF");
369
+ dev_dbg(ic_priv->ipu_dev, "%s: stream %s\n", sd->name,
370
+ enable ? "ON" : "OFF");
376371
377372 if (enable)
378373 ret = prp_start(priv);
....@@ -422,43 +417,33 @@
422417 if (fi->pad >= PRP_NUM_PADS)
423418 return -EINVAL;
424419
425
- /* No limits on frame interval */
426420 mutex_lock(&priv->lock);
427
- priv->frame_interval = fi->interval;
421
+
422
+ /* No limits on valid frame intervals */
423
+ if (fi->interval.numerator == 0 || fi->interval.denominator == 0)
424
+ fi->interval = priv->frame_interval;
425
+ else
426
+ priv->frame_interval = fi->interval;
427
+
428428 mutex_unlock(&priv->lock);
429429
430430 return 0;
431431 }
432432
433
-/*
434
- * retrieve our pads parsed from the OF graph by the media device
435
- */
436433 static int prp_registered(struct v4l2_subdev *sd)
437434 {
438435 struct prp_priv *priv = sd_to_priv(sd);
439
- int i, ret;
440436 u32 code;
441
-
442
- /* get media device */
443
- priv->md = dev_get_drvdata(sd->v4l2_dev->dev);
444
-
445
- for (i = 0; i < PRP_NUM_PADS; i++) {
446
- priv->pad[i].flags = (i == PRP_SINK_PAD) ?
447
- MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
448
- }
449437
450438 /* init default frame interval */
451439 priv->frame_interval.numerator = 1;
452440 priv->frame_interval.denominator = 30;
453441
454442 /* set a default mbus format */
455
- imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV);
456
- ret = imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
457
- V4L2_FIELD_NONE, NULL);
458
- if (ret)
459
- return ret;
443
+ imx_media_enum_ipu_formats(&code, 0, PIXFMT_SEL_YUV);
460444
461
- return media_entity_pads_init(&sd->entity, PRP_NUM_PADS, priv->pad);
445
+ return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
446
+ V4L2_FIELD_NONE, NULL);
462447 }
463448
464449 static const struct v4l2_subdev_pad_ops prp_pad_ops = {
....@@ -492,21 +477,27 @@
492477 static int prp_init(struct imx_ic_priv *ic_priv)
493478 {
494479 struct prp_priv *priv;
480
+ int i;
495481
496
- priv = devm_kzalloc(ic_priv->dev, sizeof(*priv), GFP_KERNEL);
482
+ priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL);
497483 if (!priv)
498484 return -ENOMEM;
499485
500486 mutex_init(&priv->lock);
501
- ic_priv->prp_priv = priv;
487
+ ic_priv->task_priv = priv;
502488 priv->ic_priv = ic_priv;
503489
504
- return 0;
490
+ for (i = 0; i < PRP_NUM_PADS; i++)
491
+ priv->pad[i].flags = (i == PRP_SINK_PAD) ?
492
+ MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
493
+
494
+ return media_entity_pads_init(&ic_priv->sd.entity, PRP_NUM_PADS,
495
+ priv->pad);
505496 }
506497
507498 static void prp_remove(struct imx_ic_priv *ic_priv)
508499 {
509
- struct prp_priv *priv = ic_priv->prp_priv;
500
+ struct prp_priv *priv = ic_priv->task_priv;
510501
511502 mutex_destroy(&priv->lock);
512503 }