platform/kernel/linux-rpi.git
2 years agomedia: ov7251: add missing disable functions on error in ov7251_set_power_on()
Yang Yingliang [Wed, 22 Jun 2022 04:42:43 +0000 (05:42 +0100)]
media: ov7251: add missing disable functions on error in ov7251_set_power_on()

Add the missing gpiod_set_value_cansleep() and clk_disable_unprepare()
before return from ov7251_set_power_on() in the error handling case.

Fixes: 9e1d3012cc10 ("media: i2c: Remove .s_power() from ov7251")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: sunxi: Depend on GENERIC_PHY_MIPI_DPHY
Sakari Ailus [Wed, 13 Jul 2022 15:18:08 +0000 (16:18 +0100)]
media: sunxi: Depend on GENERIC_PHY_MIPI_DPHY

The sun6i-mipi-csi2 and sun6i-a83t-mipi-csi2 drivers depend on the generic
MIPI D-PHY support. Select it. This fixes a linking problem when either of
these drivers is enabled and GENERIC_PHY_MIPI_DPHY is disabled.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: v4l2: Sanitize colorspace values in the framework
Laurent Pinchart [Thu, 17 Mar 2022 12:37:12 +0000 (12:37 +0000)]
media: v4l2: Sanitize colorspace values in the framework

Extend the format sanitization code in the framework to handle invalid
values for the colorspace-related fields.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: v4l2: Make colorspace validity checks more future-proof
Laurent Pinchart [Thu, 17 Mar 2022 12:37:12 +0000 (12:37 +0000)]
media: v4l2: Make colorspace validity checks more future-proof

The helper functions that test validity of colorspace-related fields
use the last value of the corresponding enums. This isn't very
future-proof, as there's a high chance someone adding a new value may
forget to update the helpers. Add new "LAST" entries to the enumerations
to improve this, and keep them private to the kernel.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vivid: Add support for the new YUVA and YUVX formats
Laurent Pinchart [Mon, 7 Mar 2022 17:01:38 +0000 (17:01 +0000)]
media: vivid: Add support for the new YUVA and YUVX formats

Extend vivid to support the newly added YUVA and YUVX pixel formats
through the TPG.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: v4l2-tpg: Add support for the new YUVA and YUVX formats
Laurent Pinchart [Mon, 7 Mar 2022 16:33:44 +0000 (16:33 +0000)]
media: v4l2-tpg: Add support for the new YUVA and YUVX formats

Extend the TPG to support generating the newly added YUVA and YUVX pixel
formats.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: v4l: Add packed YUV 4:4:4 YUVA and YUVX pixel formats
Laurent Pinchart [Mon, 7 Mar 2022 16:32:00 +0000 (16:32 +0000)]
media: v4l: Add packed YUV 4:4:4 YUVA and YUVX pixel formats

The new YUVA and YUVX are permutations of the existing AYUV and XYUV
formats. They are use by the NXP i.MX8 ISI hardware.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: Make encoder capability fields fit requirements
Chen-Yu Tsai [Fri, 8 Jul 2022 10:44:51 +0000 (11:44 +0100)]
media: mediatek: vcodec: Make encoder capability fields fit requirements

This partially reverts commit fd9f8050e355d7fd1e126cd207b06c96cde7f783,
and changes things so that the capability string fields of the encoder
conform to their requirements.

The driver name field should contain the actual driver name, not some
otherwise unused string macro from the driver. To make this clear,
copy the name from the driver's name field.

The card name for the video encoder previously held a static platform
name that was fixed to match MT8173. This obviously doesn't make sense
for newer chips. Since commit fd9f8050e355 ("media: mediatek: vcodec:
Change encoder v4l2 capability value"), this field was changed to hold
the driver's name, or "mtk-vcodec-dec". This doesn't make much sense
either, since this still doesn't reflect what chip this is.

Instead, fill in the card name with "MTxxxx video encoder" with the
proper chip number.

Since commit f2d8b6917f3b ("media: v4l: ioctl: Set bus_info in
v4l_querycap()"), the V4L2 core provides a default value for the
bus_info field for platform and PCI devices. This value will match
the default value for media devices added by commit cef699749f37
("media: mc: Set bus_info in media_device_init()"). These defaults
are stable and device-specific.

Drop the custom capability bus_info from the mtk-vcodec encoder
driver, and use the defaults.

As this patch removes the last usage of MTK_VCODEC_DRV_NAME, remove
the macro as well.

Fixes: fd9f8050e355 ("media: mediatek: vcodec: Change encoder v4l2 capability value")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: Make decoder capability fields fit requirements
Chen-Yu Tsai [Fri, 8 Jul 2022 10:44:50 +0000 (11:44 +0100)]
media: mediatek: vcodec: Make decoder capability fields fit requirements

This partially reverts commit a8a7a278c56ad3b4ddd4db9a960e0537d032b0b3,
and changes things so that the capability string fields of the decoder
conform to their requirements.

This recent change caused ChromeOS's decoder to no longer function. This
is due to ChromeOS using the driver name field to match the video device
with its accompanying media device. After the change, they no longer
matched.

The driver name field should contain the actual driver name, not some
otherwise unused string macro from the driver. To make this clear,
copy the name from the driver's name field.

The card name for the video decoder previously held a static platform
name that was fixed to match MT8173. This obviously doesn't make sense
for newer chips. Since commit a8a7a278c56a ("media: mediatek: vcodec:
Change decoder v4l2 capability value"), this field was changed to hold
the driver's name, or "mtk-vcodec-dec". This doesn't make much sense
either, since this still doesn't reflect what chip this is.

Instead, fill in the card name with "MTxxxx video decoder" with the
proper chip number.

Since commit f2d8b6917f3b ("media: v4l: ioctl: Set bus_info in
v4l_querycap()"), the V4L2 core provides a default value for the
bus_info field for platform and PCI devices. This value will match
the default value for media devices added by commit cef699749f37
("media: mc: Set bus_info in media_device_init()"). These defaults
are stable and device-specific.

Drop the custom capability bus_info from the mtk-vcodec decoder
driver, and use the defaults. This also fixes the long standing
issue where the media device used for the stateless decoder didn't
have its bus_info set, and would never match its accompanying video
device.

Fixes: a8a7a278c56a ("media: mediatek: vcodec: Change decoder v4l2 capability value")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: lirc: ensure lirc device receives repeats
Marko Mäkelä [Fri, 8 Jul 2022 08:44:59 +0000 (09:44 +0100)]
media: lirc: ensure lirc device receives repeats

Pressing a button on a remote control unit will typically lead to
messages being sent several times per second until the button is released.

Some remote control units indicate long key presses by sending
special "repeat" messages, for which the protocol driver calls
rc_repeat(). Other units repeat the same message over and over,
which will be handled by calling rc_keydown().

The function rc_keydown() never set the LIRC "repeat" flag to distinguish
repeated messages that were sent due to a long keypress, and messages
sent due to repeated short keypresses. While a user-space program may
implement special logic to distinguish long keypresses, it is much simpler
to be able to rely on the flag.

Commit de142c32410649e64d44928505ffad2176a96a9e ("media: lirc: implement
reading scancode") would never set the LIRC_SCANCODE_FLAG_REPEAT flag.
Commit b66218fddfd29f315a103db811152ab0c95fb054
("media: lirc: ensure lirc device receives nec repeats") fixed it up for
rc_repeat() but not rc_keydown().

Signed-off-by: Marko Mäkelä <marko.makela@iki.fi>
Co-developed-by: Sean Young <sean@mess.org>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: ati-remote: remove private err() macro
Oliver Neukum [Wed, 6 Jul 2022 07:44:59 +0000 (08:44 +0100)]
media: ati-remote: remove private err() macro

Drivers should use dev_err()

Signed-off-by: Oliver Neukum <oneukum@suse.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: igorplugusb: use correct size pass to igorplugusb_probe()
Yang Yingliang [Tue, 28 Jun 2022 06:54:53 +0000 (07:54 +0100)]
media: igorplugusb: use correct size pass to igorplugusb_probe()

After 'buf_in' change to pointer, the sizeof() is not correct buffer
size, it should be MAX_PACKET.

Fixes: b3f820b905c9 ("media: igorplugusb: respect DMA coherency")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vimc: documentation for lens
Yunke Cao [Wed, 29 Jun 2022 02:06:30 +0000 (03:06 +0100)]
media: vimc: documentation for lens

Add documentation for vimc-lens.
Add a lens into the vimc topology graph.

Signed-off-by: Yunke Cao <yunkec@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vimc: use data link entities enum to index the ent_config array
Daniel Oakley [Thu, 16 Jun 2022 10:07:47 +0000 (11:07 +0100)]
media: vimc: use data link entities enum to index the ent_config array

Future additions to the ent_config[] could break the association between
the index of the struct vimc_ent_config entries in the ent_config[] array,
and the index defined by the enum proposed in the previous patch. Using
designated initializers solves this by linking the 2 together clearly in
code and prevents the array not reflecting the enum. There is no
functional change intended.

Suggested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Daniel Oakley <daniel.oakley@ideasonboard.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vimc: enumerate data link entities for clarity
Daniel Oakley [Thu, 16 Jun 2022 10:07:46 +0000 (11:07 +0100)]
media: vimc: enumerate data link entities for clarity

The data_links array was hard to read and understand. By implementing
enumerated vimc data link entities, clarity has been improved when
defining data_links. This therefore should help new programmers to
understand the codebase better. There is no functional change intended.

Suggested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Daniel Oakley <daniel.oakley@ideasonboard.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vimc: expand the names of vimc entity types
Daniel Oakley [Thu, 16 Jun 2022 10:07:45 +0000 (11:07 +0100)]
media: vimc: expand the names of vimc entity types

When introducing the lens controller, it became apparent that the vimc
entity type names were hard to understand, e.g. vimc_len_type refers to the
lens. The names of the vimc entity types have been expanded to make the
code easier to understand. There is no functional change intended.

Suggested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Daniel Oakley <daniel.oakley@ideasonboard.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: vimc: add ancillary lens
Yunke Cao [Tue, 28 Jun 2022 00:53:52 +0000 (01:53 +0100)]
media: vimc: add ancillary lens

Add lens to vimc driver and link them with sensors using ancillary links.
Provides an example of ancillary link usage.The lens supports
FOCUS_ABSOLUTE control.

Test example: With default vimc topology
> media-ctl -p
Media controller API version 5.18.0
...
- entity 28: Lens A (0 pad, 0 link)
             type V4L2 subdev subtype Lens flags 0
             device node name /dev/v4l-subdev6
- entity 29: Lens B (0 pad, 0 link)
             type V4L2 subdev subtype Lens flags 0
             device node name /dev/v4l-subdev7
> v4l2-ctl -d /dev/v4l-subdev7 -C focus_absolute
focus_absolute: 0

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Yunke Cao <yunkec@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: v4l: async: Also match secondary fwnode endpoints
Sakari Ailus [Tue, 5 Jul 2022 17:40:54 +0000 (18:40 +0100)]
media: v4l: async: Also match secondary fwnode endpoints

For camera sensor devices the firmware information of which comes from
non-DT (or some ACPI variants), the kernel makes the information visible
to the drivers in a form similar to DT. This takes place through device's
secondary fwnodes, in which case also the secondary fwnode needs to be
heterogenously (endpoint vs. device) matched.

Fixes: 1f391df44607 ("media: v4l2-async: Use endpoints in __v4l2_async_nf_add_fwnode_remote()")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: amphion: only insert the first sequence startcode for vc1l format
Ming Qian [Fri, 8 Jul 2022 08:56:50 +0000 (09:56 +0100)]
media: amphion: only insert the first sequence startcode for vc1l format

For format V4L2_PIX_FMT_VC1_ANNEX_L,
the amphion vpu requires driver to help insert some custom startcode
before sequence and frame.
but only the first sequence startcode is needed,
the extra startcode will cause decoding error.
So after seek, we don't need to insert the sequence startcode.

In other words, for V4L2_PIX_FMT_VC1_ANNEX_L,
the vpu doesn't support dynamic resolution change.

Fixes: 145e936380edb ("media: amphion: implement malone decoder rpc interface")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: amphion: sync buffer status with firmware during abort
Ming Qian [Fri, 1 Jul 2022 05:50:04 +0000 (06:50 +0100)]
media: amphion: sync buffer status with firmware during abort

1. prevent to allocate buffer to firmware during abort
2. release buffer when clear the slots

Fixes: 6de8d628df6ef ("media: amphion: add v4l2 m2m vpu decoder stateful driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: hantro: Fix RK3399 H.264 format advertising
Ezequiel Garcia [Wed, 29 Jun 2022 19:56:23 +0000 (20:56 +0100)]
media: hantro: Fix RK3399 H.264 format advertising

Commit 1f82f2df523cb ("media: hantro: Enable H.264 on Rockchip VDPU2")
enabled H.264 on some SoCs with VDPU2 cores. This had the side-effect
of exposing H.264 coded format as supported on RK3399.

Fix this and clarify how the codec is explicitly disabled on RK3399 on
this driver.

Fixes: 1f82f2df523cb ("media: hantro: Enable H.264 on Rockchip VDPU2")
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tested-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: docs: Remove extraneous \endgroup from P010 table
Akira Yokosawa [Wed, 29 Jun 2022 13:01:17 +0000 (14:01 +0100)]
media: docs: Remove extraneous \endgroup from P010 table

The \endgroup command at the bottom of a table added in commit
5374d8fb75f3 ("media: Add P010 video format") doesn't have a
corresponding \begingroup command preceding it.

This imbalance causes an build error in "make pdfdocs".

Fix the issue by removing it.

Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Fixes: 5374d8fb75f3 ("media: Add P010 video format")
Cc: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Cc: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: dt-bindings: media: samsung,s5pv210-jpeg: convert to dtschema
Krzysztof Kozlowski [Wed, 29 Jun 2022 12:08:03 +0000 (13:08 +0100)]
media: dt-bindings: media: samsung,s5pv210-jpeg: convert to dtschema

Convert the Samsung SoC JPEG codec bindings to DT schema.

The original bindings were quite old and incomplete, so change during
conversion:
1. Add typical (already used) properties like iommus and power domains.
2. Document samsung,exynos4212-jpeg compatible (already used in DTS and
   driver).
3. List clocks per each variant.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: amphion: defer setting last_buffer_dequeued until resolution changes are processed
Ming Qian [Tue, 28 Jun 2022 05:21:12 +0000 (06:21 +0100)]
media: amphion: defer setting last_buffer_dequeued until resolution changes are processed

Don't set last_buffer_dequeued during dynamic resolution change,
otherwise it may be cleared in handling resolution change,
as streamoff may be called in dynamic resolution change.

Normally, this does not happen.
But we encounter a special testcase,
User issue V4L2_DEC_CMD_STOP after enqueue one buffer
that only contains codec config header, but not any frame data.
So VPU report the parsed resolution, then report the eos event.

So driver should notify user to handle resolution change first,
after it's handled, set the last_buffer_dequeued.
then the user can exit decoding normally.

Otherwise the user may be stalled.

Fixes: 6de8d628df6ef ("media: amphion: add v4l2 m2m vpu decoder stateful driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: Initialize decoder parameters for each instance
Chen-Yu Tsai [Mon, 4 Jul 2022 08:49:30 +0000 (09:49 +0100)]
media: mediatek: vcodec: Initialize decoder parameters for each instance

The decoder parameters are stored in each instance's context data. This
needs to be initialized per-instance, but a previous fix incorrectly
changed it to only be initialized for the first opened instance. This
resulted in subsequent instances not correctly signaling the requirement
for the Requests API.

Fix this by calling the initializing function outside of the
v4l2_fh_is_singular() conditional block.

Fixes: faddaa735c20 ("media: mediatek: vcodec: Initialize decoder parameters after getting dec_capability")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Yunfei Dong <yunfei.dong@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Embed framesize inside mtk_video_fmt
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:38 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Embed framesize inside mtk_video_fmt

Right now the decoder maintains two separate lists for supported pixel
formats and frame sizes. Getting the supported frame sizes for the
current set format is a bit convoluted, requiring a search through
the separate frame size list. The frame sizes are used to clamp and
align requested resolutions.

Instead, the frame size structure could be embedded inside the pixel
format structure. Getting one also gets the other. And since the
the driver already keeps pointers to the current set format, getting
the frame sizes becomes straightforward.

Do just that. Move v4l2_frmsize_stepwise inside mtk_video_fmt, and get
rid of mtk_codec_framesizes.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Drop max_{width,height} from mtk_vcodec_ctx
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:37 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Drop max_{width,height} from mtk_vcodec_ctx

This partially reverts commit b018be06f3c7 ("media: mediatek: vcodec:
Read max resolution from dec_capability").

After the previous patches:

  - media: mediatek: vcodec: decoder: Fix 4K frame size enumeration
  - media: mediatek: vcodec: decoder: Skip alignment for default resolution
  - media: mediatek: vcodec: decoder: Fix resolution clamping in TRY_FMT

the max_{width,height} fields in |struct mtk_vcodec_ctx| no longer have
any real users. Remove them.

Fixes: b018be06f3c7 ("media: mediatek: vcodec: Read max resolution from dec_capability")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Fix resolution clamping in TRY_FMT
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:36 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Fix resolution clamping in TRY_FMT

In commit b018be06f3c7 ("media: mediatek: vcodec: Read max resolution
from dec_capability"), TRY_FMT clamps the resolution to the maximum
that was previously set either by default 1080p or the limit set by a
previous S_FMT call. This does not make sense when doing TRY_FMT for
the output side, which may have different capabilities.

Instead, for the output side, find the maximum resolution based on the
pixel format requested. For the capture side, find the maximum
resolution based on the currently set output format.

The maximum resolution is found from the list of per-format frame
sizes, so the patch "media: mediatek: vcodec: dec: Fix 4K frame size
enumeration" is needed.

Fixes: b018be06f3c7 ("media: mediatek: vcodec: Read max resolution from dec_capability")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Skip alignment for default resolution
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:35 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Skip alignment for default resolution

The default resolution of 64x64 is already aligned, according to the
call to v4l_bound_align_image() in mtk_vcodec_dec_set_default_params().

Drop the redundant v4l_bound_align_image() call. This also removes one
usage of ctx->max_{width,height}.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Fix 4K frame size enumeration
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:34 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Fix 4K frame size enumeration

This partially reverts commit b018be06f3c7 ("media: mediatek: vcodec:
Read max resolution from dec_capability"). In this commit, the maximum
resolution ended up being a function of both the firmware capability and
the current set format.

However, frame size enumeration for output (coded) formats should not
depend on the format set, but should return supported resolutions for
the format requested by userspace.

Fix this so that the driver returns the supported resolutions correctly,
even if the instance only has default settings, or if the output format
is currently set to VP8F, which does not support 4K.

This adds an copy of special casing for !VP8 and 4K support. The other
existing copy will be removed when .max_{width,height} are removed from
|struct mtk_vcodec_ctx| in a subsequent patch.

Fixes: b018be06f3c7 ("media: mediatek: vcodec: Read max resolution from dec_capability")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mediatek: vcodec: decoder: Const-ify stepwise_fhd
Chen-Yu Tsai [Wed, 6 Jul 2022 08:21:33 +0000 (09:21 +0100)]
media: mediatek: vcodec: decoder: Const-ify stepwise_fhd

stepwise_fhd is the reference framesize variable, and should not be
altered. Make it constant.

Fixes: ("76250b48de79 media: mediatek: vcodec: Getting supported decoder format types")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop usage of shared helpers
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop usage of shared helpers

None of the shared helpers are used anymore. Make this official by
dropping inclusion of imx-media.h.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop V4L2 events support
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop V4L2 events support

The only event that the driver allows subscribing to,
V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR, is never generated. Drop events
support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats()
Laurent Pinchart [Tue, 10 May 2022 09:47:34 +0000 (10:47 +0100)]
media: staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats()

Inline the imx7_csi_enum_pixel_formats() function in its only caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation
Laurent Pinchart [Tue, 10 May 2022 09:47:34 +0000 (10:47 +0100)]
media: staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation

The driver won't accept unsupported pixel formats, there's thus no need
to validate it in imx7_csi_pad_link_validate().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support
Laurent Pinchart [Tue, 10 May 2022 09:47:34 +0000 (10:47 +0100)]
media: staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support

The device supports 14-bit greyscale formats the same way it supports
14-bit Bayer formats.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Fix list of supported formats
Laurent Pinchart [Tue, 10 May 2022 09:47:34 +0000 (10:47 +0100)]
media: staging: media: imx: imx7-media-csi: Fix list of supported formats

The list of supported formats comes from helpers shared with the i.MX6
IPUv3 and is incorrect in multiple regards:

- 10-, 12- and 14-bit Bayer formats are stored in memory as SBGGR10,
  SBGGR12 and SBGGR14 respectively (plus components permutations), not
  SBGGR16. Same thing for greyscale formats.
- 16-bit RAW formats are not supported by the hardware.

Fix the supported formats table.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Simplify default format in try_fmt
Laurent Pinchart [Tue, 10 May 2022 09:47:34 +0000 (10:47 +0100)]
media: staging: media: imx: imx7-media-csi: Simplify default format in try_fmt

When trying a format on the video node, if the requested pixel format
isn't supported, fallback to the default with a simpler logic.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()

Inline the imx7_csi_init_mbus_fmt() function in its only caller. This
allows simplifying the code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields

The imx7_csi_pixfmt cycles field is never used nor set, the bayer field
is never used, and the planar field is never set. Drop them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors

All the format lookup functions are called with a ANY selector, drop
selector support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt

When trying a format on the subdev sink pad, if the requested media bus
code isn't supported, fallback to the default with a simpler logic.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Define macro for default mbus code
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Define macro for default mbus code

Define a macro for the default media bus code and use it through the
driver to replace a hardcoded value and a dynamic query from the
pixel_formats table.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Make default formats consistent
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Make default formats consistent

Use the same default image width and height for both the CSI subdev and
the video node to achieve a consistent default through the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats

A large number of formats defined in the pixel_formats array are not
supported, as shown by the switch-case check in
imx7_csi_pad_link_validate(). Drop them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop IPU-only formats
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop IPU-only formats

The formats specific to the IPUv3 are not supported by the CSI bridge.
Drop them, along with the related code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorim...
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorimetry()

The imx7_csi_try_colorimetry() function supports the unrelated image
converter hardware as it originates from shared helpers. Drop that.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv...
Laurent Pinchart [Tue, 10 May 2022 02:06:45 +0000 (03:06 +0100)]
media: staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv field

Replace the enum ipu_color_space cs field in struct imx7_csi_pixfmt with
a bool yuv field. This decouples the driver from the unrelated IPUv3
headers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Import format helpers
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Import format helpers

To prepare for code refactoring, copy the format helpers used by this
driver from imx-media-utils.c. Rename structures and functions to avoid
name clashes, no functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop error message on alloc failure
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Drop error message on alloc failure

The kernel memory allocators already complain loudly to the log when
allocation fails. There's no need for an additional message.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Decouple from shared macros
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Decouple from shared macros

Decouple from the IMX7_CSI_VIDEO_DEF_PIX_WIDTH,
IMX7_CSI_VIDEO_DEF_PIX_HEIGHT and IMX_MEDIA_EOF_TIMEOUT macros defined
in shared helpers by duplicating them in the imx7-media-csi driver, with
a rename to avoid name clashes. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf

Decouple from the imx_media_dma_buf structure defined in shared helpers
by duplicating it in the imx7-media-csi driver, along with the two small
alloc and free functions. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Store imx7_csi in drv data
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Store imx7_csi in drv data

Replace the subdev pointer stored in platform drv data with the imx7_csi
pointer. Drop a now redundant dev_set_drvdata() call.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi

Now that the driver doesn't use any helper that relies on the
imx_media_video_dev structure anymore, merge its fields directly in the
imx7_csi structure. Update all the users accordingly, and drop the list
field that isn't used by the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer

Decouple from the imx_media_buffer structure defined in shared helpers
by duplicating it in the imx7-media-csi driver. No functional change
intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi

Now that the driver doesn't use any helper that relies on the
imx_media_dev structure anymore, merge the three fields of the
imx_media_dev structure directly in the imx7_csi structure. Update all
the users accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Inline pipeline start/stop
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Inline pipeline start/stop

The imx7_csi_media_pipeline_set_stream() function has separate branches
for the start and stop paths, surrounded by mutex lock/unlock. That is
very little shared code, inline the locking and corresponding branch in
each of the two callers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Avoid unnecessary casts
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Avoid unnecessary casts

Simplify the imx7_csi_media_pipeline_set_stream() function by passing it
the imx7_csi pointer, which avoids going from subdev to entity and back
to subdev.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream()
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream()

To prepare for code refactoring, copy the
imx_media_pipeline_set_stream() helper used by this driver from
imx-media-utils.c. Rename the function to avoid name clashes, no
functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()
Laurent Pinchart [Tue, 10 May 2022 00:37:01 +0000 (01:37 +0100)]
media: staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()

Inline the imx_media_pipeline_pad() helper, dropping all the code unused
by the imx7-media-csi driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Don't initialize unused fields
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Don't initialize unused fields

The imx_media_dev structure contains three fields that are not used by
this driver or any helper code that it calls. Don't initialize them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call
Laurent Pinchart [Tue, 10 May 2022 00:25:26 +0000 (01:25 +0100)]
media: staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call

There's no need to call imx_media_add_video_device() anymore, as the
video devices list it manages is only used by the control inheritance
mechanism in the helpers, which this driver doesn't use.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi

There's no need anymore to allocate the imx_media_dev structure
separately from imx7_csi. Embed it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper

To prepare for code refactoring, copy the imx_media_dev_init() helper
used by this driver from imx-media-dev-common.c. Rename the function to
avoid name clashes, and leave the v4l2_device notify handler out as it
only serves to implement control inheritance, which this driver doesn't
use. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Don't set subdev group id
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Don't set subdev group id

The subdev group id isn't used by any of the remaining helpers used by
this driver, don't set it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Ensure consistent function prefix
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Ensure consistent function prefix

Rename all the functions and macros imported from imx-media-capture.c
with a consistent imx7_csi_video_ prefix. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi

Merge the capture_priv fields in the imx7_csi structure as there's no
more need to have two separate structures. Update all the users
accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure

The struct imx7_csi fields are in a random order, reorganize them
logically to prepare for adding new fields.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop unused controls support
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Drop unused controls support

Drop the unused control handler from the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop legacy video device support
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Drop legacy video device support

Drop all the code related to the unused (by this driver) legacy video
device support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Import video device helpers
Laurent Pinchart [Mon, 9 May 2022 22:32:33 +0000 (23:32 +0100)]
media: staging: media: imx: imx7-media-csi: Import video device helpers

To prepare for code refactoring, copy the video device helper code used
by this driver verbatim from imx-media-capture. Rename some functions to
avoid name clashes, and leave the legacy ioctls out as they're not used
by the imx7-media-csi driver. No functional change included.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi
Paul Elder [Fri, 6 May 2022 11:36:58 +0000 (12:36 +0100)]
media: staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi

imx_media_of_add_csi() from imx-media-of.c validates that the fwnode for
the CSI bridge is enabled, and adds the fwnode to the async notifier of
the imxmd. The former is redundant, as if the CSI bridge driver probes,
clearly it is enabled in the DT. The latter is not needed as the imxmd
notifier isn't used anymore. The call is thus not needed and can be
dropped. This removes the dependency of imx7-media-csi.c on
imx-media-of.c.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Move format init to probe time
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Move format init to probe time

There's no need to wait until the subdev is registered to initialize the
active pad formats. Do so at probe time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop unused frame_interval
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Drop unused frame_interval

The frame_interval field of the imx7_csi structure is set but never
used. Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Don't populate vdev lists
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Don't populate vdev lists

The imx_media_dev framework maintains a per-pad list of connected video
devices, created once all subdevs have been bound. This is used for two
purposes, updating V4L2 control inheritance when links change, and
relaying subdev events to video nodes. None of these are used by the
imx7-media-csi driver as it implements the MC-centric approach. Drop
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Move misc init out of probe()
Paul Elder [Thu, 5 May 2022 12:48:33 +0000 (13:48 +0100)]
media: staging: media: imx: imx7-media-csi: Move misc init out of probe()

There is a chunk of miscellaneous initializations related to the CSI
subdev and media pads directly in the probe function. Move them into the
imx7_csi_media_init() function to clean up the probe function.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop the imx_media notifier
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Drop the imx_media notifier

The V4L2 async notifier embedded in the imx_media_dev structure is
triggered when the CSI bridge subdev is registered. We don't need an
async notifier for this, as we can call the .complete() handler directly
from the CSI bridge subdev .registered() handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Drop duplicate link creation
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Drop duplicate link creation

The imx_media_create_csi2_links() creates a media controller link
between the CSI-2 receiver and the next entity in the pipeline, which
can be either a video mux (handled by the video-mux driver) or the CSI
bridge itself. This isn't needed, as the link is already created either
by the video-mux driver or by the imx7-media-csi driver itself (in
imx7_csi_notify_bound()).

Drop imx_media_create_csi2_links(), which allows dropping the CSI bridge
subdev grp_id.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Import notifier helpers
Laurent Pinchart [Sun, 6 Feb 2022 05:13:53 +0000 (05:13 +0000)]
media: staging: media: imx: imx7-media-csi: Import notifier helpers

To prepare for code refactoring, copy the V4L2 async notifier helper
code used by this driver verbatim from imx-media-dev-common.c. Rename
some functions to avoid name clashes. No functional change included.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
Laurent Pinchart [Sat, 5 Feb 2022 04:16:36 +0000 (04:16 +0000)]
media: staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()

Prepare for the decoupling of the imx7-media-csi driver from the
IPUv3-based drivers by moving the imx_media_dev handling from probe()
function to separate functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: imx: imx7-media-csi: Initialize locks early on
Laurent Pinchart [Sat, 5 Feb 2022 04:16:36 +0000 (04:16 +0000)]
media: staging: media: imx: imx7-media-csi: Initialize locks early on

Group all the direct initialization of imx7_csi fields at the beginning
of the imx7_csi_probe() function instead of spreading them around.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: renesas: rcar_drif: Drop of_match_ptr()
Laurent Pinchart [Wed, 25 May 2022 09:16:04 +0000 (10:16 +0100)]
media: renesas: rcar_drif: Drop of_match_ptr()

The device_driver structure's of_match_table field exists
unconditionally, so there's no need for of_match_ptr(). This fixes a
compiler warning when test-compiling on non-OF platforms:

drivers/media/platform/renesas/rcar_drif.c:1470:34: warning: unused variable 'rcar_drif_of_table' [-Wunused-const-variable]
static const struct of_device_id rcar_drif_of_table[] = {
                                 ^

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: xilinx: Drop unexpected word 'with' in comments
Jiang Jian [Thu, 23 Jun 2022 12:29:48 +0000 (13:29 +0100)]
media: xilinx: Drop unexpected word 'with' in comments

There is an unexpected word 'with' in the comments that need to be
dropped.

Signed-off-by: Jiang Jian <jiangjian@cdjrlc.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mt9p031: Move open subdev op init code into init_cfg
Marek Vasut [Sat, 18 Jun 2022 23:54:43 +0000 (00:54 +0100)]
media: mt9p031: Move open subdev op init code into init_cfg

The .open subdev op is not always called soon enough to initialize
the default crop settings. Move all this initialization into .init_cfg
op instead.

Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: mt9p031: Add MT9P006 compatible
Marek Vasut [Sat, 18 Jun 2022 22:22:55 +0000 (23:22 +0100)]
media: mt9p031: Add MT9P006 compatible

Add compatible for MT9P006 sensor, which is older variant of MT9P031
and compatible with this driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: dt-bindings: mt9p031: Add MT9P006 compatible string
Marek Vasut [Sat, 18 Jun 2022 22:22:54 +0000 (23:22 +0100)]
media: dt-bindings: mt9p031: Add MT9P006 compatible string

Add compatible for MT9P006 sensor, which is older variant of MT9P031
and compatible with this driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging/media/atomisp/pci/atomisp: Fix typo in string
Li zeming [Mon, 4 Jul 2022 02:28:07 +0000 (03:28 +0100)]
media: staging/media/atomisp/pci/atomisp: Fix typo in string

Remove the repeated ',' from string

Link: https://lore.kernel.org/linux-media/20220704022807.3215-1-zeming@nfschina.com
Signed-off-by: Li zeming <zeming@nfschina.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp: clean up for-loop, remove redundant assignment to variable i
Colin Ian King [Tue, 28 Jun 2022 15:24:51 +0000 (16:24 +0100)]
media: atomisp: clean up for-loop, remove redundant assignment to variable i

There is a for-loop that initializes variable i but does not use it; the
assignment is redundant and can be removed. The proceeding assignment to
pointer fw can also be moved into the for-loop to clean up the code.

Link: https://lore.kernel.org/linux-media/20220628152451.184416-1-colin.i.king@gmail.com
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media/atomisp: use max() impl
Karthik Alapati [Wed, 22 Jun 2022 16:39:00 +0000 (17:39 +0100)]
media: staging: media/atomisp: use max() impl

fix a coccinelle warning by replacing opencoded max()
implementation with max()

WARNING opportunity for max()

Link: https://lore.kernel.org/linux-media/YrNFpF2qvTxpZP8e@karthik-strix-linux.karthek.com
Signed-off-by: Karthik Alapati <mail@karthek.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp: Fix typo in comments
Jiang Jian [Wed, 22 Jun 2022 14:34:42 +0000 (15:34 +0100)]
media: atomisp: Fix typo in comments

Remove the repeated word 'and' from comments

file: drivers/staging/media/atomisp/pci/hive_isp_css_include/host/debug_public.h
line: 28

* The buffer has a remote and and a local store

changed to:

* The buffer has a remote and a local store

Link: https://lore.kernel.org/linux-media/20220622143442.16942-1-jiangjian@cdjrlc.com
Signed-off-by: Jiang Jian <jiangjian@cdjrlc.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp_gmin_platform: stop abusing efivar API
Ard Biesheuvel [Mon, 20 Jun 2022 10:08:19 +0000 (11:08 +0100)]
media: atomisp_gmin_platform: stop abusing efivar API

As the code comment already suggests, using the efivar API in this way
is not how it is intended, and so let's switch to the right one, which
is simply to call efi.get_variable() directly after checking whether or
not the GetVariable() runtime service is supported.

Link: https://lore.kernel.org/linux-media/20220620100819.1682995-1-ardb@kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp: fix -Wdangling-pointer warning
Hans de Goede [Sun, 12 Jun 2022 16:05:56 +0000 (17:05 +0100)]
media: atomisp: fix -Wdangling-pointer warning

ia_css_rmgr_acq_vbuf() uses a local on stack
"struct ia_css_rmgr_vbuf_handle v" variable.

When this path using this is hit, either the rmgr_pop_handle() call
will make *handle point to another vbuf-handle, or because
v.count == 0, ia_css_rmgr_refcount_retain_vbuf() will alloc a new
vbuf-handle and make *handle point to it.

So on leaving the function *handle will never point to the on stack
vbuf-handle, but gcc does not know this and emits the following:

drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c: In function ‘ia_css_rmgr_acq_vbuf’:
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:276:33: warning: storing the address of local variable ‘h’ in ‘*handle’ [-Wdangling-pointer=]
  276 |                         *handle = &h;
      |                         ~~~~~~~~^~~~
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:257:40: note: ‘h’ declared here
  257 |         struct ia_css_rmgr_vbuf_handle h;
      |                                        ^
drivers/staging/media/atomisp/pci/runtime/rmgr/src/rmgr_vbuf.c:257:40: note: ‘handle’ declared here

Rework the code using a new_handle helper to suppress this
false-postive compiler warning.

Link: https://lore.kernel.org/linux-media/20220612160556.108264-4-hdegoede@redhat.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp: fix uninitialized stack mem usage in ia_css_rmgr_acq_vbuf()
Hans de Goede [Sun, 12 Jun 2022 16:05:55 +0000 (17:05 +0100)]
media: atomisp: fix uninitialized stack mem usage in ia_css_rmgr_acq_vbuf()

When ia_css_rmgr_acq_vbuf() enters the code path where it uses the local
"struct ia_css_rmgr_vbuf_handle v" on the stack it relies on v.count==0
so that ia_css_rmgr_refcount_retain_vbuf allocates a new handle.

Explicitly set v.count to 0 rather then it being whatever was on the stack.

Link: https://lore.kernel.org/linux-media/20220612160556.108264-3-hdegoede@redhat.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp: revert "don't pass a pointer to a local variable"
Hans de Goede [Sun, 12 Jun 2022 16:05:54 +0000 (17:05 +0100)]
media: atomisp: revert "don't pass a pointer to a local variable"

The gcc is warning about returning a pointer to a local variable
is a false positive.

The type of handle is "struct ia_css_rmgr_vbuf_handle **" and
"h.vptr" is left to NULL, so the "if ((*handle)->vptr == 0x0)"
check always succeeds when the "*handle = &h;" statement which
gcc warns about executes. Leading to this statement being executed:

rmgr_pop_handle(pool, handle);

If that succeeds,  then *handle has been set to point to one of
the pre-allocated array of handles, so it no longer points to h.

If that fails the following statement will be executed:

/* Note that handle will change to an internally maintained one */
ia_css_rmgr_refcount_retain_vbuf(handle);

Which allocated a new handle from the array of pre-allocated handles
and then makes *handle point to this. So the address of h is actually
never returned.

The fix for the false-postive compiler warning actually breaks the code,
the new:

**handle = h;

is part of a "if (pool->copy_on_write) { ... }" which means that the
handle where *handle points to should be treated read-only, IOW
**handle must never be set, instead *handle must be set to point to
a new handle (with a copy of the contents of the old handle).

The old code correctly did this and the new fixed code gets this wrong.

Note there is another patch in this series, which fixes the warning
in another way.

Link: https://lore.kernel.org/linux-media/20220612160556.108264-2-hdegoede@redhat.com
Fixes: fa1451374ebf ("media: atomisp: don't pass a pointer to a local variable")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: atomisp-mt9m114: Fix pointer dereferenced before checking
Haowen Bai [Mon, 30 May 2022 07:58:01 +0000 (08:58 +0100)]
media: atomisp-mt9m114: Fix pointer dereferenced before checking

The info->data is dereferencing before null checking, so move
it after checking.

Link: https://lore.kernel.org/linux-media/1653897481-25681-1-git-send-email-baihaowen@meizu.com
Signed-off-by: Haowen Bai <baihaowen@meizu.com>
Reviewed-by: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: [PATCH] pci: atomisp_cmd: fix three missing checks on list iterator
Xiaomeng Tong [Thu, 14 Apr 2022 04:14:15 +0000 (05:14 +0100)]
media: [PATCH] pci: atomisp_cmd: fix three missing checks on list iterator

The three bugs are here:
__func__, s3a_buf->s3a_data->exp_id);
__func__, md_buf->metadata->exp_id);
__func__, dis_buf->dis_data->exp_id);

The list iterator 's3a_buf/md_buf/dis_buf' will point to a bogus
position containing HEAD if the list is empty or no element is found.
This case must be checked before any use of the iterator, otherwise
it will lead to a invalid memory access.

To fix this bug, add an check. Use a new variable '*_iter' as the
list iterator, while use the old variable '*_buf' as a dedicated
pointer to point to the found element.

Link: https://lore.kernel.org/linux-media/20220414041415.3342-1-xiam0nd.tong@gmail.com
Cc: stable@vger.kernel.org
Fixes: ad85094b293e4 ("Revert "media: staging: atomisp: Remove driver"")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: atomisp: Use kmap_local_page() in hmm_store()
Fabio M. De Francesco [Wed, 13 Apr 2022 22:55:31 +0000 (23:55 +0100)]
media: staging: media: atomisp: Use kmap_local_page() in hmm_store()

The use of kmap() is being deprecated in favor of kmap_local_page()
where it is feasible. The same is true for kmap_atomic().

In file pci/hmm/hmm.c, function hmm_store() test if we are in atomic
context and, if so, it calls kmap_atomic(), if not, it calls kmap().

First of all, in_atomic() shouldn't be used in drivers. This macro
cannot always detect atomic context; in particular, it cannot know
about held spinlocks in non-preemptible kernels.

Notwithstanding what it is said above, this code doesn't need to care
whether or not it is executing in atomic context. It can simply use
kmap_local_page() / kunmap_local() that can instead do the mapping /
unmapping regardless of the context.

With kmap_local_page(), the mapping is per thread, CPU local and not
globally visible. Therefore, hmm_store()() is a function where the use
of kmap_local_page() in place of both kmap() and kmap_atomic() is
correctly suited.

Convert the calls of kmap() / kunmap() and kmap_atomic() /
kunmap_atomic() to kmap_local_page() / kunmap_local() and drop the
unnecessary tests which test if the code is in atomic context.

Link: https://lore.kernel.org/linux-media/20220413225531.9425-1-fmdefrancesco@gmail.com
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: atomisp: Use kmap_local_page() in hmm_set()
Fabio M. De Francesco [Wed, 13 Apr 2022 21:22:10 +0000 (22:22 +0100)]
media: staging: media: atomisp: Use kmap_local_page() in hmm_set()

The use of kmap() is being deprecated in favor of kmap_local_page()
where it is feasible. In file pci/hmm/hmm.c, function hmm_set() calls
kmap() / kunmap() where kmap_local_page() can instead do the mapping.

With kmap_local_page(), the mapping is per thread, CPU local and not
globally visible. Therefore, hmm_set()() is a function where the use
of kmap_local_page() in place of kmap() is correctly suited.

Convert the calls of kmap() / kunmap() to kmap_local_page() /
kunmap_local().

Link: https://lore.kernel.org/linux-media/20220413212210.18494-1-fmdefrancesco@gmail.com
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: media: atomisp: Convert kmap() to kmap_local_page()
Fabio M. De Francesco [Fri, 8 Apr 2022 22:31:29 +0000 (23:31 +0100)]
media: staging: media: atomisp: Convert kmap() to kmap_local_page()

The use of kmap() is being deprecated in favor of kmap_local_page() where
it is feasible. With kmap_local_page(), the mapping is per thread, CPU
local and not globally visible.

load_and_flush_by_kmap() is a function where the use of kmap_local_page()
in place of kmap() is correctly suited.

Convert load_and_flush_by_kmap() from kmap() to kmap_local_page().

Link: https://lore.kernel.org/linux-media/20220408223129.3844-1-fmdefrancesco@gmail.com
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2 years agomedia: staging: atomisp: rework reading the id and revision values
Tom Rix [Sat, 26 Mar 2022 19:18:53 +0000 (19:18 +0000)]
media: staging: atomisp: rework reading the id and revision values

Clang static analysis reports this representative issue
atomisp-ov2722.c:920:3: warning: 3rd function call
  argument is an uninitialized value
  dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

high and low are only set when ov2722_read_reg() is successful.
Reporting the high value when there is an error is not
meaningful.  The later read for low is not checked.  high
and low are or-ed together and checked against a non zero
value.

Remove the unneeded error reporting for high.  Initialize
high and low to 0 and use the id check to determine if
the reads were successful

The later read for revision is not checked.  If it
fails the old high value will be used and the revision
will be misreported.

Since the revision is only reported and not checked or
stored it is not necessary to return if the read with
successful.  This makes the ret variable unnecessary
so remove it.

Link: https://lore.kernel.org/linux-media/20220326191853.2914552-1-trix@redhat.com
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>