Skip to content

Commit 01be377

Browse files
committed
Merge tag 'media/v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media fixes from Mauro Carvalho Chehab: "Some fixes for some platform drivers (rockchip, atmel, omap, daVinci, tegra-cec, coda and rcar). Also includes a fix on one of the V4L2 uAPI doc, explaining a border case" * tag 'media/v5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: media: rockchip/vpu: Fix/re-order probe-error/remove path media: rockchip/vpu: Initialize mdev->bus_info media: rockchip/vpu: Get vdev from the file arg in vidioc_querycap() media: rockchip/vpu: Add missing dont_use_autosuspend() calls media: rockchip/vpu: Do not request id 0 for our video device media: tegra-cec: fix cec_notifier_parse_hdmi_phandle return check media: davinci/vpbe: array underflow in vpbe_enum_outputs() media: field-order.rst: clarify FIELD_ANY and FIELD_NONE media: staging/imx: add media device to capture register media: rcar-csi2: Propagate the FLD signal for NTSC and PAL media: rcar-csi2: restart CSI-2 link if error is detected media: omap_vout: potential buffer overflow in vidioc_dqbuf() media: coda: fix unset field and fail on invalid field in buf_prepare media: atmel: atmel-isc: fix asd memory allocation media: atmel: atmel-isc: fix INIT_WORK misplacement media: atmel: atmel-isc: limit incoming pixels per frame
2 parents 11b1177 + fc8670d commit 01be377

File tree

16 files changed

+172
-42
lines changed

16 files changed

+172
-42
lines changed

Documentation/media/uapi/v4l/field-order.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,20 @@ enum v4l2_field
7575

7676
* - ``V4L2_FIELD_ANY``
7777
- 0
78-
- Applications request this field order when any one of the
79-
``V4L2_FIELD_NONE``, ``V4L2_FIELD_TOP``, ``V4L2_FIELD_BOTTOM``, or
80-
``V4L2_FIELD_INTERLACED`` formats is acceptable. Drivers choose
81-
depending on hardware capabilities or e. g. the requested image
82-
size, and return the actual field order. Drivers must never return
83-
``V4L2_FIELD_ANY``. If multiple field orders are possible the
78+
- Applications request this field order when any field format
79+
is acceptable. Drivers choose depending on hardware capabilities or
80+
e.g. the requested image size, and return the actual field order.
81+
Drivers must never return ``V4L2_FIELD_ANY``.
82+
If multiple field orders are possible the
8483
driver must choose one of the possible field orders during
8584
:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
8685
:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct
8786
:c:type:`v4l2_buffer` ``field`` can never be
8887
``V4L2_FIELD_ANY``.
8988
* - ``V4L2_FIELD_NONE``
9089
- 1
91-
- Images are in progressive format, not interlaced. The driver may
92-
also indicate this order when it cannot distinguish between
93-
``V4L2_FIELD_TOP`` and ``V4L2_FIELD_BOTTOM``.
90+
- Images are in progressive (frame-based) format, not interlaced
91+
(field-based).
9492
* - ``V4L2_FIELD_TOP``
9593
- 2
9694
- Images consist of the top (aka odd) field only.

drivers/media/platform/atmel/atmel-isc-regs.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@
3737
#define ISC_PFG_CFG0_BPS_TWELVE (0x0 << 28)
3838
#define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28)
3939

40+
#define ISC_PFE_CFG0_COLEN BIT(12)
41+
#define ISC_PFE_CFG0_ROWEN BIT(13)
42+
43+
/* ISC Parallel Front End Configuration 1 Register */
44+
#define ISC_PFE_CFG1 0x00000010
45+
46+
#define ISC_PFE_CFG1_COLMIN(v) ((v))
47+
#define ISC_PFE_CFG1_COLMIN_MASK GENMASK(15, 0)
48+
#define ISC_PFE_CFG1_COLMAX(v) ((v) << 16)
49+
#define ISC_PFE_CFG1_COLMAX_MASK GENMASK(31, 16)
50+
51+
/* ISC Parallel Front End Configuration 2 Register */
52+
#define ISC_PFE_CFG2 0x00000014
53+
54+
#define ISC_PFE_CFG2_ROWMIN(v) ((v))
55+
#define ISC_PFE_CFG2_ROWMIN_MASK GENMASK(15, 0)
56+
#define ISC_PFE_CFG2_ROWMAX(v) ((v) << 16)
57+
#define ISC_PFE_CFG2_ROWMAX_MASK GENMASK(31, 16)
58+
4059
/* ISC Clock Enable Register */
4160
#define ISC_CLKEN 0x00000018
4261

drivers/media/platform/atmel/atmel-isc.c

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,40 @@ static void isc_start_dma(struct isc_device *isc)
721721
u32 sizeimage = isc->fmt.fmt.pix.sizeimage;
722722
u32 dctrl_dview;
723723
dma_addr_t addr0;
724+
u32 h, w;
725+
726+
h = isc->fmt.fmt.pix.height;
727+
w = isc->fmt.fmt.pix.width;
728+
729+
/*
730+
* In case the sensor is not RAW, it will output a pixel (12-16 bits)
731+
* with two samples on the ISC Data bus (which is 8-12)
732+
* ISC will count each sample, so, we need to multiply these values
733+
* by two, to get the real number of samples for the required pixels.
734+
*/
735+
if (!ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) {
736+
h <<= 1;
737+
w <<= 1;
738+
}
739+
740+
/*
741+
* We limit the column/row count that the ISC will output according
742+
* to the configured resolution that we want.
743+
* This will avoid the situation where the sensor is misconfigured,
744+
* sending more data, and the ISC will just take it and DMA to memory,
745+
* causing corruption.
746+
*/
747+
regmap_write(regmap, ISC_PFE_CFG1,
748+
(ISC_PFE_CFG1_COLMIN(0) & ISC_PFE_CFG1_COLMIN_MASK) |
749+
(ISC_PFE_CFG1_COLMAX(w - 1) & ISC_PFE_CFG1_COLMAX_MASK));
750+
751+
regmap_write(regmap, ISC_PFE_CFG2,
752+
(ISC_PFE_CFG2_ROWMIN(0) & ISC_PFE_CFG2_ROWMIN_MASK) |
753+
(ISC_PFE_CFG2_ROWMAX(h - 1) & ISC_PFE_CFG2_ROWMAX_MASK));
754+
755+
regmap_update_bits(regmap, ISC_PFE_CFG0,
756+
ISC_PFE_CFG0_COLEN | ISC_PFE_CFG0_ROWEN,
757+
ISC_PFE_CFG0_COLEN | ISC_PFE_CFG0_ROWEN);
724758

725759
addr0 = vb2_dma_contig_plane_dma_addr(&isc->cur_frm->vb.vb2_buf, 0);
726760
regmap_write(regmap, ISC_DAD0, addr0);
@@ -1965,6 +1999,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)
19651999
struct vb2_queue *q = &isc->vb2_vidq;
19662000
int ret;
19672001

2002+
INIT_WORK(&isc->awb_work, isc_awb_work);
2003+
19682004
ret = v4l2_device_register_subdev_nodes(&isc->v4l2_dev);
19692005
if (ret < 0) {
19702006
v4l2_err(&isc->v4l2_dev, "Failed to register subdev nodes\n");
@@ -2018,8 +2054,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier)
20182054
return ret;
20192055
}
20202056

2021-
INIT_WORK(&isc->awb_work, isc_awb_work);
2022-
20232057
/* Register video device */
20242058
strscpy(vdev->name, ATMEL_ISC_NAME, sizeof(vdev->name));
20252059
vdev->release = video_device_release_empty;
@@ -2135,8 +2169,11 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc)
21352169
break;
21362170
}
21372171

2138-
subdev_entity->asd = devm_kzalloc(dev,
2139-
sizeof(*subdev_entity->asd), GFP_KERNEL);
2172+
/* asd will be freed by the subsystem once it's added to the
2173+
* notifier list
2174+
*/
2175+
subdev_entity->asd = kzalloc(sizeof(*subdev_entity->asd),
2176+
GFP_KERNEL);
21402177
if (!subdev_entity->asd) {
21412178
of_node_put(rem);
21422179
ret = -ENOMEM;
@@ -2284,6 +2321,7 @@ static int atmel_isc_probe(struct platform_device *pdev)
22842321
subdev_entity->asd);
22852322
if (ret) {
22862323
fwnode_handle_put(subdev_entity->asd->match.fwnode);
2324+
kfree(subdev_entity->asd);
22872325
goto cleanup_subdev;
22882326
}
22892327

drivers/media/platform/coda/coda-common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,10 +1515,20 @@ static int coda_queue_setup(struct vb2_queue *vq,
15151515

15161516
static int coda_buf_prepare(struct vb2_buffer *vb)
15171517
{
1518+
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
15181519
struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
15191520
struct coda_q_data *q_data;
15201521

15211522
q_data = get_q_data(ctx, vb->vb2_queue->type);
1523+
if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
1524+
if (vbuf->field == V4L2_FIELD_ANY)
1525+
vbuf->field = V4L2_FIELD_NONE;
1526+
if (vbuf->field != V4L2_FIELD_NONE) {
1527+
v4l2_warn(&ctx->dev->v4l2_dev,
1528+
"%s field isn't supported\n", __func__);
1529+
return -EINVAL;
1530+
}
1531+
}
15221532

15231533
if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
15241534
v4l2_warn(&ctx->dev->v4l2_dev,

drivers/media/platform/davinci/vpbe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int vpbe_enum_outputs(struct vpbe_device *vpbe_dev,
104104
struct v4l2_output *output)
105105
{
106106
struct vpbe_config *cfg = vpbe_dev->cfg;
107-
int temp_index = output->index;
107+
unsigned int temp_index = output->index;
108108

109109
if (temp_index >= cfg->num_outputs)
110110
return -EINVAL;

drivers/media/platform/omap/omap_vout.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,23 +1527,20 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
15271527
unsigned long size;
15281528
struct videobuf_buffer *vb;
15291529

1530-
vb = q->bufs[b->index];
1531-
15321530
if (!vout->streaming)
15331531
return -EINVAL;
15341532

1535-
if (file->f_flags & O_NONBLOCK)
1536-
/* Call videobuf_dqbuf for non blocking mode */
1537-
ret = videobuf_dqbuf(q, (struct v4l2_buffer *)b, 1);
1538-
else
1539-
/* Call videobuf_dqbuf for blocking mode */
1540-
ret = videobuf_dqbuf(q, (struct v4l2_buffer *)b, 0);
1533+
ret = videobuf_dqbuf(q, b, !!(file->f_flags & O_NONBLOCK));
1534+
if (ret)
1535+
return ret;
1536+
1537+
vb = q->bufs[b->index];
15411538

15421539
addr = (unsigned long) vout->buf_phy_addr[vb->i];
15431540
size = (unsigned long) vb->size;
15441541
dma_unmap_single(vout->vid_dev->v4l2_dev.dev, addr,
15451542
size, DMA_TO_DEVICE);
1546-
return ret;
1543+
return 0;
15471544
}
15481545

15491546
static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)

drivers/media/platform/rcar-vin/rcar-csi2.c

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct rcar_csi2;
6868
/* Field Detection Control */
6969
#define FLD_REG 0x1c
7070
#define FLD_FLD_NUM(n) (((n) & 0xff) << 16)
71+
#define FLD_DET_SEL(n) (((n) & 0x3) << 4)
7172
#define FLD_FLD_EN4 BIT(3)
7273
#define FLD_FLD_EN3 BIT(2)
7374
#define FLD_FLD_EN2 BIT(1)
@@ -84,6 +85,9 @@ struct rcar_csi2;
8485

8586
/* Interrupt Enable */
8687
#define INTEN_REG 0x30
88+
#define INTEN_INT_AFIFO_OF BIT(27)
89+
#define INTEN_INT_ERRSOTHS BIT(4)
90+
#define INTEN_INT_ERRSOTSYNCHS BIT(3)
8791

8892
/* Interrupt Source Mask */
8993
#define INTCLOSE_REG 0x34
@@ -475,7 +479,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp)
475479
static int rcsi2_start_receiver(struct rcar_csi2 *priv)
476480
{
477481
const struct rcar_csi2_format *format;
478-
u32 phycnt, vcdt = 0, vcdt2 = 0;
482+
u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
479483
unsigned int i;
480484
int mbps, ret;
481485

@@ -507,13 +511,27 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
507511
vcdt2 |= vcdt_part << ((i % 2) * 16);
508512
}
509513

514+
if (priv->mf.field == V4L2_FIELD_ALTERNATE) {
515+
fld = FLD_DET_SEL(1) | FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2
516+
| FLD_FLD_EN;
517+
518+
if (priv->mf.height == 240)
519+
fld |= FLD_FLD_NUM(0);
520+
else
521+
fld |= FLD_FLD_NUM(1);
522+
}
523+
510524
phycnt = PHYCNT_ENABLECLK;
511525
phycnt |= (1 << priv->lanes) - 1;
512526

513527
mbps = rcsi2_calc_mbps(priv, format->bpp);
514528
if (mbps < 0)
515529
return mbps;
516530

531+
/* Enable interrupts. */
532+
rcsi2_write(priv, INTEN_REG, INTEN_INT_AFIFO_OF | INTEN_INT_ERRSOTHS
533+
| INTEN_INT_ERRSOTSYNCHS);
534+
517535
/* Init */
518536
rcsi2_write(priv, TREF_REG, TREF_TREF);
519537
rcsi2_write(priv, PHTC_REG, 0);
@@ -549,8 +567,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
549567
rcsi2_write(priv, PHYCNT_REG, phycnt);
550568
rcsi2_write(priv, LINKCNT_REG, LINKCNT_MONITOR_EN |
551569
LINKCNT_REG_MONI_PACT_EN | LINKCNT_ICLK_NONSTOP);
552-
rcsi2_write(priv, FLD_REG, FLD_FLD_NUM(2) | FLD_FLD_EN4 |
553-
FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN);
570+
rcsi2_write(priv, FLD_REG, fld);
554571
rcsi2_write(priv, PHYCNT_REG, phycnt | PHYCNT_SHUTDOWNZ);
555572
rcsi2_write(priv, PHYCNT_REG, phycnt | PHYCNT_SHUTDOWNZ | PHYCNT_RSTZ);
556573

@@ -675,6 +692,43 @@ static const struct v4l2_subdev_ops rcar_csi2_subdev_ops = {
675692
.pad = &rcar_csi2_pad_ops,
676693
};
677694

695+
static irqreturn_t rcsi2_irq(int irq, void *data)
696+
{
697+
struct rcar_csi2 *priv = data;
698+
u32 status, err_status;
699+
700+
status = rcsi2_read(priv, INTSTATE_REG);
701+
err_status = rcsi2_read(priv, INTERRSTATE_REG);
702+
703+
if (!status)
704+
return IRQ_HANDLED;
705+
706+
rcsi2_write(priv, INTSTATE_REG, status);
707+
708+
if (!err_status)
709+
return IRQ_HANDLED;
710+
711+
rcsi2_write(priv, INTERRSTATE_REG, err_status);
712+
713+
dev_info(priv->dev, "Transfer error, restarting CSI-2 receiver\n");
714+
715+
return IRQ_WAKE_THREAD;
716+
}
717+
718+
static irqreturn_t rcsi2_irq_thread(int irq, void *data)
719+
{
720+
struct rcar_csi2 *priv = data;
721+
722+
mutex_lock(&priv->lock);
723+
rcsi2_stop(priv);
724+
usleep_range(1000, 2000);
725+
if (rcsi2_start(priv))
726+
dev_warn(priv->dev, "Failed to restart CSI-2 receiver\n");
727+
mutex_unlock(&priv->lock);
728+
729+
return IRQ_HANDLED;
730+
}
731+
678732
/* -----------------------------------------------------------------------------
679733
* Async handling and registration of subdevices and links.
680734
*/
@@ -947,7 +1001,7 @@ static int rcsi2_probe_resources(struct rcar_csi2 *priv,
9471001
struct platform_device *pdev)
9481002
{
9491003
struct resource *res;
950-
int irq;
1004+
int irq, ret;
9511005

9521006
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
9531007
priv->base = devm_ioremap_resource(&pdev->dev, res);
@@ -958,6 +1012,12 @@ static int rcsi2_probe_resources(struct rcar_csi2 *priv,
9581012
if (irq < 0)
9591013
return irq;
9601014

1015+
ret = devm_request_threaded_irq(&pdev->dev, irq, rcsi2_irq,
1016+
rcsi2_irq_thread, IRQF_SHARED,
1017+
KBUILD_MODNAME, priv);
1018+
if (ret)
1019+
return ret;
1020+
9611021
priv->rstc = devm_reset_control_get(&pdev->dev, NULL);
9621022
if (IS_ERR(priv->rstc))
9631023
return PTR_ERR(priv->rstc);

drivers/media/platform/tegra-cec/tegra_cec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ static int tegra_cec_probe(struct platform_device *pdev)
334334

335335
hdmi_dev = cec_notifier_parse_hdmi_phandle(&pdev->dev);
336336

337-
if (!hdmi_dev)
338-
return -ENODEV;
337+
if (IS_ERR(hdmi_dev))
338+
return PTR_ERR(hdmi_dev);
339339

340340
cec = devm_kzalloc(&pdev->dev, sizeof(struct tegra_cec), GFP_KERNEL);
341341

drivers/staging/media/imx/imx-ic-prpencvf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ static int prp_registered(struct v4l2_subdev *sd)
12661266
if (ret)
12671267
return ret;
12681268

1269-
ret = imx_media_capture_device_register(priv->vdev);
1269+
ret = imx_media_capture_device_register(priv->md, priv->vdev);
12701270
if (ret)
12711271
return ret;
12721272

drivers/staging/media/imx/imx-media-capture.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ void imx_media_capture_device_error(struct imx_media_video_dev *vdev)
701701
}
702702
EXPORT_SYMBOL_GPL(imx_media_capture_device_error);
703703

704-
int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
704+
int imx_media_capture_device_register(struct imx_media_dev *md,
705+
struct imx_media_video_dev *vdev)
705706
{
706707
struct capture_priv *priv = to_capture_priv(vdev);
707708
struct v4l2_subdev *sd = priv->src_sd;
@@ -710,8 +711,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
710711
struct v4l2_subdev_format fmt_src;
711712
int ret;
712713

713-
/* get media device */
714-
priv->md = dev_get_drvdata(sd->v4l2_dev->dev);
714+
priv->md = md;
715715

716716
vfd->v4l2_dev = sd->v4l2_dev;
717717

0 commit comments

Comments
 (0)