.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * V4L2 Capture IC Preprocess Subdev for Freescale i.MX5/6 SOC |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * for resizing, colorspace conversion, and rotation. |
---|
7 | 8 | * |
---|
8 | 9 | * 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. |
---|
14 | 10 | */ |
---|
15 | 11 | #include <linux/delay.h> |
---|
16 | 12 | #include <linux/interrupt.h> |
---|
.. | .. |
---|
30 | 26 | /* |
---|
31 | 27 | * Min/Max supported width and heights. |
---|
32 | 28 | */ |
---|
33 | | -#define MIN_W 176 |
---|
34 | | -#define MIN_H 144 |
---|
| 29 | +#define MIN_W 32 |
---|
| 30 | +#define MIN_H 32 |
---|
35 | 31 | #define MAX_W 4096 |
---|
36 | 32 | #define MAX_H 4096 |
---|
37 | 33 | #define W_ALIGN 4 /* multiple of 16 pixels */ |
---|
.. | .. |
---|
39 | 35 | #define S_ALIGN 1 /* multiple of 2 */ |
---|
40 | 36 | |
---|
41 | 37 | struct prp_priv { |
---|
42 | | - struct imx_media_dev *md; |
---|
43 | 38 | struct imx_ic_priv *ic_priv; |
---|
44 | 39 | struct media_pad pad[PRP_NUM_PADS]; |
---|
45 | 40 | |
---|
46 | 41 | /* lock to protect all members below */ |
---|
47 | 42 | struct mutex lock; |
---|
48 | | - |
---|
49 | | - /* IPU units we require */ |
---|
50 | | - struct ipu_soc *ipu; |
---|
51 | 43 | |
---|
52 | 44 | struct v4l2_subdev *src_sd; |
---|
53 | 45 | struct v4l2_subdev *sink_sd_prpenc; |
---|
.. | .. |
---|
66 | 58 | { |
---|
67 | 59 | struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd); |
---|
68 | 60 | |
---|
69 | | - return ic_priv->prp_priv; |
---|
| 61 | + return ic_priv->task_priv; |
---|
70 | 62 | } |
---|
71 | 63 | |
---|
72 | 64 | static int prp_start(struct prp_priv *priv) |
---|
.. | .. |
---|
74 | 66 | struct imx_ic_priv *ic_priv = priv->ic_priv; |
---|
75 | 67 | bool src_is_vdic; |
---|
76 | 68 | |
---|
77 | | - priv->ipu = priv->md->ipu[ic_priv->ipu_id]; |
---|
78 | | - |
---|
79 | 69 | /* 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); |
---|
81 | 71 | |
---|
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); |
---|
83 | 73 | |
---|
84 | 74 | return 0; |
---|
85 | 75 | } |
---|
.. | .. |
---|
116 | 106 | |
---|
117 | 107 | switch (code->pad) { |
---|
118 | 108 | 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); |
---|
121 | 111 | break; |
---|
122 | 112 | case PRP_SRC_PAD_PRPENC: |
---|
123 | 113 | case PRP_SRC_PAD_PRPVF: |
---|
.. | .. |
---|
190 | 180 | MIN_H, MAX_H, H_ALIGN, S_ALIGN); |
---|
191 | 181 | |
---|
192 | 182 | cc = imx_media_find_ipu_format(sdformat->format.code, |
---|
193 | | - CS_SEL_ANY); |
---|
| 183 | + PIXFMT_SEL_YUV_RGB); |
---|
194 | 184 | 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); |
---|
197 | 189 | sdformat->format.code = cc->codes[0]; |
---|
198 | 190 | } |
---|
199 | 191 | |
---|
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; |
---|
202 | 194 | break; |
---|
203 | 195 | case PRP_SRC_PAD_PRPENC: |
---|
204 | 196 | case PRP_SRC_PAD_PRPVF: |
---|
.. | .. |
---|
206 | 198 | sdformat->format = *infmt; |
---|
207 | 199 | break; |
---|
208 | 200 | } |
---|
| 201 | + |
---|
| 202 | + imx_media_try_colorimetry(&sdformat->format, true); |
---|
209 | 203 | |
---|
210 | 204 | fmt = __prp_get_fmt(priv, cfg, sdformat->pad, sdformat->which); |
---|
211 | 205 | *fmt = sdformat->format; |
---|
.. | .. |
---|
220 | 214 | { |
---|
221 | 215 | struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); |
---|
222 | 216 | 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; |
---|
224 | 218 | struct v4l2_subdev *remote_sd; |
---|
225 | 219 | int ret = 0; |
---|
226 | 220 | |
---|
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); |
---|
229 | 223 | |
---|
230 | 224 | remote_sd = media_entity_to_v4l2_subdev(remote->entity); |
---|
231 | 225 | |
---|
.. | .. |
---|
237 | 231 | ret = -EBUSY; |
---|
238 | 232 | goto out; |
---|
239 | 233 | } |
---|
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)) { |
---|
242 | 236 | ret = -EINVAL; |
---|
243 | 237 | goto out; |
---|
244 | 238 | } |
---|
.. | .. |
---|
259 | 253 | goto out; |
---|
260 | 254 | } |
---|
261 | 255 | if (priv->src_sd && (priv->src_sd->grp_id & |
---|
262 | | - IMX_MEDIA_GRP_ID_VDIC)) { |
---|
| 256 | + IMX_MEDIA_GRP_ID_IPU_VDIC)) { |
---|
263 | 257 | ret = -EINVAL; |
---|
264 | 258 | goto out; |
---|
265 | 259 | } |
---|
.. | .. |
---|
299 | 293 | struct v4l2_subdev_format *sink_fmt) |
---|
300 | 294 | { |
---|
301 | 295 | 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; |
---|
303 | 297 | struct v4l2_subdev *csi; |
---|
304 | 298 | int ret; |
---|
305 | 299 | |
---|
.. | .. |
---|
308 | 302 | if (ret) |
---|
309 | 303 | return ret; |
---|
310 | 304 | |
---|
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); |
---|
313 | 307 | if (IS_ERR(csi)) |
---|
314 | 308 | csi = NULL; |
---|
315 | 309 | |
---|
316 | 310 | mutex_lock(&priv->lock); |
---|
317 | 311 | |
---|
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) { |
---|
319 | 313 | /* |
---|
320 | 314 | * the ->PRPENC link cannot be enabled if the source |
---|
321 | 315 | * is the VDIC |
---|
.. | .. |
---|
334 | 328 | |
---|
335 | 329 | if (csi) { |
---|
336 | 330 | switch (csi->grp_id) { |
---|
337 | | - case IMX_MEDIA_GRP_ID_CSI0: |
---|
| 331 | + case IMX_MEDIA_GRP_ID_IPU_CSI0: |
---|
338 | 332 | priv->csi_id = 0; |
---|
339 | 333 | break; |
---|
340 | | - case IMX_MEDIA_GRP_ID_CSI1: |
---|
| 334 | + case IMX_MEDIA_GRP_ID_IPU_CSI1: |
---|
341 | 335 | priv->csi_id = 1; |
---|
342 | 336 | break; |
---|
343 | 337 | default: |
---|
.. | .. |
---|
355 | 349 | static int prp_s_stream(struct v4l2_subdev *sd, int enable) |
---|
356 | 350 | { |
---|
357 | 351 | 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; |
---|
359 | 353 | int ret = 0; |
---|
360 | 354 | |
---|
361 | 355 | mutex_lock(&priv->lock); |
---|
.. | .. |
---|
372 | 366 | if (priv->stream_count != !enable) |
---|
373 | 367 | goto update_count; |
---|
374 | 368 | |
---|
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"); |
---|
376 | 371 | |
---|
377 | 372 | if (enable) |
---|
378 | 373 | ret = prp_start(priv); |
---|
.. | .. |
---|
422 | 417 | if (fi->pad >= PRP_NUM_PADS) |
---|
423 | 418 | return -EINVAL; |
---|
424 | 419 | |
---|
425 | | - /* No limits on frame interval */ |
---|
426 | 420 | 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 | + |
---|
428 | 428 | mutex_unlock(&priv->lock); |
---|
429 | 429 | |
---|
430 | 430 | return 0; |
---|
431 | 431 | } |
---|
432 | 432 | |
---|
433 | | -/* |
---|
434 | | - * retrieve our pads parsed from the OF graph by the media device |
---|
435 | | - */ |
---|
436 | 433 | static int prp_registered(struct v4l2_subdev *sd) |
---|
437 | 434 | { |
---|
438 | 435 | struct prp_priv *priv = sd_to_priv(sd); |
---|
439 | | - int i, ret; |
---|
440 | 436 | 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 | | - } |
---|
449 | 437 | |
---|
450 | 438 | /* init default frame interval */ |
---|
451 | 439 | priv->frame_interval.numerator = 1; |
---|
452 | 440 | priv->frame_interval.denominator = 30; |
---|
453 | 441 | |
---|
454 | 442 | /* 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); |
---|
460 | 444 | |
---|
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); |
---|
462 | 447 | } |
---|
463 | 448 | |
---|
464 | 449 | static const struct v4l2_subdev_pad_ops prp_pad_ops = { |
---|
.. | .. |
---|
492 | 477 | static int prp_init(struct imx_ic_priv *ic_priv) |
---|
493 | 478 | { |
---|
494 | 479 | struct prp_priv *priv; |
---|
| 480 | + int i; |
---|
495 | 481 | |
---|
496 | | - priv = devm_kzalloc(ic_priv->dev, sizeof(*priv), GFP_KERNEL); |
---|
| 482 | + priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL); |
---|
497 | 483 | if (!priv) |
---|
498 | 484 | return -ENOMEM; |
---|
499 | 485 | |
---|
500 | 486 | mutex_init(&priv->lock); |
---|
501 | | - ic_priv->prp_priv = priv; |
---|
| 487 | + ic_priv->task_priv = priv; |
---|
502 | 488 | priv->ic_priv = ic_priv; |
---|
503 | 489 | |
---|
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); |
---|
505 | 496 | } |
---|
506 | 497 | |
---|
507 | 498 | static void prp_remove(struct imx_ic_priv *ic_priv) |
---|
508 | 499 | { |
---|
509 | | - struct prp_priv *priv = ic_priv->prp_priv; |
---|
| 500 | + struct prp_priv *priv = ic_priv->task_priv; |
---|
510 | 501 | |
---|
511 | 502 | mutex_destroy(&priv->lock); |
---|
512 | 503 | } |
---|