platform/kernel/linux-starfive.git
21 months agomedia: mediatek: vcodec/venc: return 0 instead of 'ret'.
Hans Verkuil [Thu, 26 Jan 2023 12:59:16 +0000 (13:59 +0100)]
media: mediatek: vcodec/venc: return 0 instead of 'ret'.

Since 'ret' is known to be 0, just return '0'. This fixes a smatch warning:

venc_h264_if.c:568 h264_encode_frame() warn: missing error code? 'ret'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
Cc: Yunfei Dong <yunfei.dong@mediatek.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: mediatek: mdp3: replace return by goto for proper unwind
Hans Verkuil [Thu, 26 Jan 2023 12:56:20 +0000 (13:56 +0100)]
media: mediatek: mdp3: replace return by goto for proper unwind

An error was returned at one point without going through the
goto label for proper unwinding.

This fixes a smatch warning:

mtk-mdp3-comp.c:1005 mdp_comp_config() warn: missing unwind goto?

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Moudy Ho <moudy.ho@mediatek.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dvb-frontends: drx39xyj: replace return with goto for proper unwind
Hans Verkuil [Thu, 26 Jan 2023 12:37:23 +0000 (13:37 +0100)]
media: dvb-frontends: drx39xyj: replace return with goto for proper unwind

In three places there was a return instead of a goto to the unwind
code.

This fixes three smatch warnings:

drxj.c:9542 ctrl_get_qam_sig_quality() warn: missing unwind goto?
drxj.c:10919 ctrl_set_standard() warn: missing unwind goto?
drxj.c:11466 drxj_open() warn: missing unwind goto?

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: marvell: change return to goto for proper unwind
Hans Verkuil [Thu, 26 Jan 2023 12:33:10 +0000 (13:33 +0100)]
media: marvell: change return to goto for proper unwind

The probe function used 'goto out' everywhere, except in one
place where it returned an error. That too should be a 'goto out'.

This fixes a smatch warning:

mmp-driver.c:257 mmpcam_probe() warn: missing unwind goto?

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dvb-frontends: cxd2880: return 0 instead of 'ret'.
Hans Verkuil [Thu, 26 Jan 2023 12:29:11 +0000 (13:29 +0100)]
media: dvb-frontends: cxd2880: return 0 instead of 'ret'.

Since 'ret' is known to be 0, just return '0'. This fixes 10 smatch warnings:

cxd2880_tnrdmd_dvbt.c:836 cxd2880_tnrdmd_dvbt_check_demod_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt.c:841 cxd2880_tnrdmd_dvbt_check_demod_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt.c:896 cxd2880_tnrdmd_dvbt_check_ts_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt.c:901 cxd2880_tnrdmd_dvbt_check_ts_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt.c:904 cxd2880_tnrdmd_dvbt_check_ts_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt2.c:1027 cxd2880_tnrdmd_dvbt2_check_demod_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt2.c:1032 cxd2880_tnrdmd_dvbt2_check_demod_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt2.c:1087 cxd2880_tnrdmd_dvbt2_check_ts_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt2.c:1092 cxd2880_tnrdmd_dvbt2_check_ts_lock() warn: missing error code? 'ret'
cxd2880_tnrdmd_dvbt2.c:1095 cxd2880_tnrdmd_dvbt2_check_ts_lock() warn: missing error code? 'ret'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Yasunari Takiguchi <Yasunari.Takiguchi@sony.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: usb: dvb-usb-v2: af9015.c: return 0 instead of 'ret'.
Hans Verkuil [Thu, 26 Jan 2023 12:26:19 +0000 (13:26 +0100)]
media: usb: dvb-usb-v2: af9015.c: return 0 instead of 'ret'.

Since 'ret' is known to be 0, just return '0'. This fixes two smatch warnings:

af9015.c:1168 af9015_rc_query() warn: missing error code? 'ret'
af9015.c:1177 af9015_rc_query() warn: missing error code? 'ret'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dvb-frontends: cxd2880: return 0 instead of 'ret'.
Hans Verkuil [Thu, 26 Jan 2023 12:20:36 +0000 (13:20 +0100)]
media: dvb-frontends: cxd2880: return 0 instead of 'ret'.

Since 'ret' is known to be 0, just return '0'. This fixes two smatch warnings:

cxd2880_tnrdmd.c:2165 cxd2880_tnrdmd_check_internal_cpu_status() warn: missing error code? 'ret'
cxd2880_tnrdmd.c:2169 cxd2880_tnrdmd_check_internal_cpu_status() warn: missing error code? 'ret'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Yasunari Takiguchi <Yasunari.Takiguchi@sony.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: i2c: s5c73m3: return 0 instead of 'ret'.
Hans Verkuil [Thu, 26 Jan 2023 12:18:18 +0000 (13:18 +0100)]
media: i2c: s5c73m3: return 0 instead of 'ret'.

Since 'ret' is known to be 0, just return '0'. This fixes a smatch warning:

s5c73m3-core.c:439 __s5c73m3_s_stream() warn: missing error code? 'ret'

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: davinci/vpif.c: drop unnecessary cast
Hans Verkuil [Thu, 26 Jan 2023 12:16:40 +0000 (13:16 +0100)]
media: davinci/vpif.c: drop unnecessary cast

DEFINE_RES_IRQ_NAMED already casts to (struct resource), so no
need to do it again.

This fixes a sparse warning:

vpif.c:483:20: warning: cast to non-scalar

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: visl: make visl_qops static
Hans Verkuil [Thu, 26 Jan 2023 11:58:32 +0000 (12:58 +0100)]
media: visl: make visl_qops static

This struct can be static. This fixes a sparse warning:

visl-video.c:690:22: warning: symbol 'visl_qops' was not declared. Should it be static?

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: pci: sh_css: Inline single invocation of macro STATS_ENABLED()
Brent Pappas [Fri, 20 Jan 2023 17:14:08 +0000 (18:14 +0100)]
media: atomisp: pci: sh_css: Inline single invocation of macro STATS_ENABLED()

Inline the single invocation of the macro STATS_ENABLED().
The macro abstraction is not necessary because the logic behind it is only
used once.

Link: https://lore.kernel.org/r/20230120171408.16099-1-bpappas@pappasbrent.com
Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: pci: hive_isp_css_common: host: vmem: Replace SUBWORD macros with...
Brent Pappas [Fri, 20 Jan 2023 18:26:25 +0000 (19:26 +0100)]
media: atomisp: pci: hive_isp_css_common: host: vmem: Replace SUBWORD macros with functions

Replace the macros SUBWORD() and INV_SUBWORD() with functions to comply
with Linux coding style standards.

Link: https://lore.kernel.org/r/20230120182625.23227-1-bpappas@pappasbrent.com
Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: pci: Replace bytes macros with functions
Brent Pappas [Wed, 18 Jan 2023 16:07:39 +0000 (17:07 +0100)]
media: atomisp: pci: Replace bytes macros with functions

Replace the function-like macros FPNTBL_BYTES(), SCTBL_BYTES(), and
MORPH_PLANE_BYTES() with functions to comply with Linux coding style
standards.
Replace multiplication with calls to array_size() and array3_size()
to prevent accidental arithmetic overflow.

Link: https://lore.kernel.org/r/20230118160739.26059-1-bpappas@pappasbrent.com
Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2722: Power on sensor from set_fmt() callback
Hans de Goede [Sat, 3 Dec 2022 20:16:25 +0000 (21:16 +0100)]
media: atomisp: ov2722: Power on sensor from set_fmt() callback

Depending on which order userspace makes various v4l2 calls, the sensor
might still be powered down when set_fmt is called.

What should really happen here is delay the writing of the mode-related
registers till streaming is started, but for now use the same quick fix
as the atomisp_ov2680 / atomisp_gc0310 code and call power_up() from
set_fmt() in combination with keeping track of the power-state to avoid
doing the power-up sequence twice.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2722: Don't take the input_lock for try_fmt calls.
Hans de Goede [Sat, 3 Dec 2022 19:44:00 +0000 (20:44 +0100)]
media: atomisp: ov2722: Don't take the input_lock for try_fmt calls.

On ov2722_set_fmt() calls with format->which == V4L2_SUBDEV_FORMAT_TRY,
ov2722_set_fmt() does not talk to the sensor, so there is no need to
lock the dev->input_lock mutex in this case.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2722: Fix GPIO1 polarity
Hans de Goede [Sat, 3 Dec 2022 15:44:21 +0000 (16:44 +0100)]
media: atomisp: ov2722: Fix GPIO1 polarity

The comment claims the PWDN pin is active when pulled down in other words,
it is /power-down so it needs to be driven high to get the sensor
powered-up (not powered down) and flag is 1 when powering-up the sensor
so the ! is wrong, drop it.

This also matches with the schematics which I have which shows GPIO1 also
enables a 3.3v line to the sensor-module which controls the privacy-LED
and indeed before this patch the privacy LED was inverted from what it
should be (and the sensor did not work).

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2722: Call atomisp_gmin_remove_subdev() on probe failure
Hans de Goede [Sat, 3 Dec 2022 15:48:07 +0000 (16:48 +0100)]
media: atomisp: ov2722: Call atomisp_gmin_remove_subdev() on probe failure

Call atomisp_gmin_remove_subdev() on probe failure to properly free
the GPIOs and other resources acquired by the gmin_camera_platform_data()
call earlier.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Switch over to ACPI powermanagement
Hans de Goede [Sun, 15 Jan 2023 21:03:19 +0000 (22:03 +0100)]
media: atomisp: ov2680: Switch over to ACPI powermanagement

The DSDT of all Windows BYT / CHT devices which I have seen has proper
ACPI powermagement for the clk and regulators used by the sensors.

So there is no need for the whole custom atomisp_gmin custom code to
disable the ACPI pm and directly poke at the PMIC for this.

Replace all the atomisp_gmin usage with using the new
atomisp_register_sensor_no_gmin() / atomisp_unregister_subdev()
helpers which allow registering a sensor with the atomisp code
without using any of the atomisp_gmin power-management code.

Note eventually these calls should be replaced by the standard
v4l2_async_register_subdev_sensor() mechanism.

But this first requires a bunch of work to the atomisp main code
to make it set the necessary fwnodes up, similar to how
drivers/media/pci/intel/ipu3/cio2-bridge.c does this.

This has been tested on:
-Trekstor Surftab duo W1 10.1, CHT, AXP288 PMIC, 2x ov2680 sensor
-Asus T101HA, CHT, TI PMIC, 1x ov2680 sensor
-MPMAN Converter 9, BYT, AXP288 PMIC, ov2680 back, gc0310 front sensor

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Use devm_kzalloc() for sensor data struct
Hans de Goede [Sun, 15 Jan 2023 13:05:38 +0000 (14:05 +0100)]
media: atomisp: ov2680: Use devm_kzalloc() for sensor data struct

Use devm_kzalloc() to allocate the sensor data struct. It is always free-ed
as the last step of probe-error-exit or remove, so it can be devm-managed.

This will make unwinding things easier when support is added to the ov2680
code to use standard GPIO APIs instead of the custom atomisp_gmin code.

This also allows dropping the out_free label and use direct return
on errors.

This may seem like a functional change since the out_free label also
did a v4l2_device_unregister_subdev() but at the 2 changed returns
the device is not registered yet, so that always is a no-op and can
be dropped.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Add dev local variable to probe()
Hans de Goede [Sun, 29 Jan 2023 19:30:40 +0000 (20:30 +0100)]
media: atomisp: ov2680: Add dev local variable to probe()

Add a dev local variable to probe(), to allow shortening
&client->dev in various places, including further patches
in this series.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: s/dev/sensor/
Hans de Goede [Sun, 15 Jan 2023 12:56:20 +0000 (13:56 +0100)]
media: atomisp: ov2680: s/dev/sensor/

Using dev as name for variables pointing to struct ov2680_device is a bit
unfortunate choice.

All the recently added / rewritten code is already using sensor for this,
replace the remaining usages of "struct ov2680_device *dev" with
"struct ov2680_device *sensor".

Note the power_up()/power_down() related functions are not changed as
these will be removed in one of the next patches.

No functional changes.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Add runtime-pm support
Hans de Goede [Sat, 14 Jan 2023 14:19:18 +0000 (15:19 +0100)]
media: atomisp: ov2680: Add runtime-pm support

Add runtime-pm support. This is a preparation patch for letting
ACPI deal with the regulators and clocks instead of the DIY code
in atomisp_gmin_platform.c.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Delay power-on till streaming is started
Hans de Goede [Fri, 13 Jan 2023 20:49:20 +0000 (21:49 +0100)]
media: atomisp: ov2680: Delay power-on till streaming is started

Move the setting of the mode to stream on, this also allows
delaying power-on till streaming is started.

And drop the deprecated s_power callback since this now no long
is necessary.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Cleanup includes
Hans de Goede [Sat, 14 Jan 2023 12:14:56 +0000 (13:14 +0100)]
media: atomisp: ov2680: Cleanup includes

Remove unused includes and sort the remaining ones alphabetically.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Consistently indent define values
Hans de Goede [Sat, 14 Jan 2023 13:01:49 +0000 (14:01 +0100)]
media: atomisp: ov2680: Consistently indent define values

Use the same indentation level for all #define values.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Drop MAX_FMTS define
Hans de Goede [Fri, 13 Jan 2023 15:51:54 +0000 (16:51 +0100)]
media: atomisp: ov2680: Drop MAX_FMTS define

The ov2680 only supports a single format, there is no need to
use a define for this.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Remove unused data-types and defines from ov2680.h
Hans de Goede [Fri, 13 Jan 2023 15:51:01 +0000 (16:51 +0100)]
media: atomisp: ov2680: Remove unused data-types and defines from ov2680.h

Remove a bunch of unused data-types and defines from ov2680.h.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Fix frame_size list
Hans de Goede [Fri, 13 Jan 2023 15:55:10 +0000 (16:55 +0100)]
media: atomisp: ov2680: Fix frame_size list

3 fixes for the framesize list:

1. Drop modes < 640x480, these are made by significant cropping,
   leading to such a small remainig field-of-view that they are
   not really usable

2. 1616x1082 is presumably intended to be 1600x1080 + 16 pixels
   padding in both dimensions, but the height is wrong.
   Change this to 1616x1096.

3. The 800x600 mode is missing the 16 pixels padding and
   720x592 is missing 16 pixels padding in its width and
   the 720x576 base mode is a mode with non square pixels,
   while the sensor has square pixels.
   Replace both with 768x576 + 16 pixels padding -> 784x592

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Drop struct ov2680_resolution / ov2680_res_preview
Hans de Goede [Fri, 13 Jan 2023 15:46:40 +0000 (16:46 +0100)]
media: atomisp: ov2680: Drop struct ov2680_resolution / ov2680_res_preview

Drop struct ov2680_resolution and the ov2680_res_preview[] array,
this is now only used in ov2680_enum_frame_size() and only
the width + height are used there.

Replace this with a new struct v4l2_frmsize_discrete ov2680_frame_sizes[]
array.

No functional changes.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Drop v4l2_find_nearest_size() call from set_fmt()
Hans de Goede [Fri, 13 Jan 2023 15:01:40 +0000 (16:01 +0100)]
media: atomisp: ov2680: Drop v4l2_find_nearest_size() call from set_fmt()

Since we now calculate timings baded on the desired width and height,
any width and height are valid as long as they don't exceed the sensor's
dimensions.

Drop the v4l2_find_nearest_size() call and instead clamp the requested
width and height.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Fix ov2680_enum_frame_interval()
Hans de Goede [Fri, 13 Jan 2023 14:40:58 +0000 (15:40 +0100)]
media: atomisp: ov2680: Fix ov2680_enum_frame_interval()

Fix and simplify ov2680_enum_frame_interval(), the index is not
an index into ov2680_res_preview[], so using N_PREVIEW is wrong.

Instead it is an index indexing the different framerates for
the resolution specified in fie->width, fie->height.

Since the ov2680 code only supports a single fixed 30 fps,
index must always be 0 and we don't need to check the other
fie input values.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Drop unused res member from struct ov2680_device
Hans de Goede [Sun, 8 Jan 2023 15:22:42 +0000 (16:22 +0100)]
media: atomisp: ov2680: Drop unused res member from struct ov2680_device

The res member of struct ov2680_device isn't read anywhere anymore,
drop it.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Use defines for fps, lines-per-frame and skip-frames
Hans de Goede [Sun, 8 Jan 2023 14:06:26 +0000 (15:06 +0100)]
media: atomisp: ov2680: Use defines for fps, lines-per-frame and skip-frames

The fps, lines-per-frame and skip-frames values are the same for all
resolutions, use defines for these.

The ov2680_res_preview[] incorrectly sets fps to 60 for some low-res
modes, this is incorrect with the current fixed (resolution independent)
lines-per-frame value.

Note this not drop the now no longer used fps, lines-per-frame and
skip-frames struct ov2680_resolution members. The entire struct is going
away in the next patches so that would just cause unnecessary changes.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Make setting the modes algorithm based
Hans de Goede [Sun, 1 Jan 2023 17:08:42 +0000 (18:08 +0100)]
media: atomisp: ov2680: Make setting the modes algorithm based

Instead of using a long fixed register settings list for each resolution,
calculate the register settings based on the requested width + height.

This will allow future enhancements like adding hblank and vblank controls
and adding selection support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Fix window settings and enable window for all resolutions
Hans de Goede [Mon, 2 Jan 2023 21:02:04 +0000 (22:02 +0100)]
media: atomisp: ov2680: Fix window settings and enable window for all resolutions

By default the ov2680 automatically sets the window to match the outputsize
and automatically adjusts it to keep the bayer pattern stable when enabling
hflip/vflip.

This does not work for the 1616x1216 mode because there is no room to
adjust the window there. To make flipping work in the 1616 wide modes the
register lists for those modes set bit 0 of 0x5708 (manual_win_en) to 1 and
ov2680_set_bayer_order() updates the bayer-order on the pad to match.

But ov2680_set_bayer_order() is always called, so when enabling flipping
on modes with a width of less then 1616 now results in the wrong bayer
order being reported on the pad since the sensor is auto-adjusting
the window in this case.

Specify the correct (== output-size) window-size in all resolutions
register-list and always set the manual_win_en bit, so that the bayer order
is changed on hflip/vflip enable on all resolutions.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Add test pattern control
Hans de Goede [Tue, 3 Jan 2023 20:32:52 +0000 (21:32 +0100)]
media: atomisp: ov2680: Add test pattern control

Add a test pattern control. This is a 1:1 copy of the test pattern
control in the main drivers/media/i2c/ov2680.c driver.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Add exposure and gain controls
Hans de Goede [Fri, 30 Dec 2022 18:37:42 +0000 (19:37 +0100)]
media: atomisp: ov2680: Add exposure and gain controls

Add exposure and gain controls. This allows controlling
the exposure and gain through standard v4l2 IOCTLs.

Note the register defines for the exposure and gain registers
are renamed to match the datasheet.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Drop custom ATOMISP_IOC_S_EXPOSURE support
Hans de Goede [Sun, 4 Dec 2022 16:24:34 +0000 (17:24 +0100)]
media: atomisp: ov2680: Drop custom ATOMISP_IOC_S_EXPOSURE support

Exposure and gain control should use standard v4l2 controls,
not a custom ioctl.

The next patch in this series will re-add support as standard controls,
this is split into 2 patches for easier reviewing.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Rework flip ctrls
Hans de Goede [Tue, 3 Jan 2023 18:53:28 +0000 (19:53 +0100)]
media: atomisp: ov2680: Rework flip ctrls

Rework the flip ctrls to be more like those of mainline (non staging)
drivers.

This is modelled after the main ov2680 and ov5693 drivers. This also
introduces __ov2680_get_pad_format() to make the ov2680 code more compliant
with the mainline v4l2-subdev APIs.

Note the OV2680_FLIP_REG and OV2680_MIRROR_REG defines are renamed to
OV2680_REG_FORMAT1 and OV2680_REG_FORMAT2 to match the datasheet.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: ov2680: Use the new ov_16bit_addr_reg_helpers.h
Hans de Goede [Sun, 4 Dec 2022 16:21:02 +0000 (17:21 +0100)]
media: atomisp: ov2680: Use the new ov_16bit_addr_reg_helpers.h

Use the new ov_16bit_addr_reg_helpers.h instead of duplicating
the ovxxxx sensor I2C register access helpers found in many different
sensor drivers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: core: add ov_16bit_addr_reg_helpers.h
Hans de Goede [Sun, 4 Dec 2022 15:48:49 +0000 (16:48 +0100)]
media: core: add ov_16bit_addr_reg_helpers.h

The following drivers under drivers/media/i2c: ov08x40.c, ov13858.c,
ov13b10.c, ov2680.c, ov2685.c, ov2740.c, ov4689.c, ov5670.c,
ov5675.c, ov5695.c, ov8856.c, ov9282.c and ov9734.c,

as well as various "atomisp" sensor drivers in drivers/staging, *all*
use register access helpers with the following function prototypes:

int ovxxxx_read_reg(struct ovxxxx_dev *sensor, u16 reg,
                    unsigned int len, u32 *val);

int ovxxxx_write_reg(struct ovxxxx_dev *sensor, u16 reg,
                     unsigned int len, u32 val);

To read/write registers on Omnivision OVxxxx image sensors wich expect
a 16 bit register address in big-endian format and which have 1-3 byte
wide registers, in big-endian format (for the higher width registers).

Add a new ov_16bit_addr_reg_helpers.h header file with static inline
versions of these register access helpers, so that this code duplication
can be removed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Properly initialize function field of media-entity links
Hans de Goede [Sun, 29 Jan 2023 21:01:20 +0000 (22:01 +0100)]
media: atomisp: Properly initialize function field of media-entity links

Don't use MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN to initialize the function field
of various media-entity links.

This fixes the following warnings showing up in dmesg:

 atomisp-isp2 0000:00:03.0: Entity type for entity ATOM ISP CSI2-port0 was not initialized!
 atomisp-isp2 0000:00:03.0: Entity type for entity ATOM ISP CSI2-port1 was not initialized!
 atomisp-isp2 0000:00:03.0: Entity type for entity ATOM ISP CSI2-port2 was not initialized!
 atomisp-isp2 0000:00:03.0: Entity type for entity tpg_subdev was not initialized!
 atomisp-isp2 0000:00:03.0: Entity type for entity ATOMISP_SUBDEV_0 was not initialized!
 atomisp-isp2 0000:00:03.0: Entity type for entity ATOMISP_SUBDEV_1 was not initialized!

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove csi2_link_setup()
Hans de Goede [Sun, 29 Jan 2023 20:49:10 +0000 (21:49 +0100)]
media: atomisp: Remove csi2_link_setup()

Looking at csi2_link_setup(), this function can never work,
it does a switch-case like this:

 switch (local->index | is_media_entity_v4l2_subdev(remote->entity))

with cases like this:

 case ATOMISP_SUBDEV_PAD_SOURCE | MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN

where ATOMISP_SUBDEV_PAD_SOURCE matches an index (0-1) and
MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN is 0x00020000, but
is_media_entity_v4l2_subdev(remote->entity) does not return
MEDIA_ENT_F_* values, it return a bool, so 0 or 1 which means
that non of the cases can ever match the input value.

Looking at the rest of the function all it ever does (if it
would actually hit one of the cases) is set the atomisp_mipi_csi2_device
struct's output member.

And checking the rest of the atomisp code that member is never
read. Also userspace does not actually setup media-controller
links when using the atomisp /dev/video$ nodes since all the links
are fixed. So csi2_link_setup() never runs.

Remove the unnecessary and broken csi2_link_setup() function
and also remove the unused atomisp_mipi_csi2_device struct's
output member.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove isp_subdev_link_setup()
Hans de Goede [Sun, 22 Jan 2023 19:59:23 +0000 (20:59 +0100)]
media: atomisp: Remove isp_subdev_link_setup()

Looking at isp_subdev_link_setup(), this function can never work,
it does a switch-case like this:

 switch (local->index | is_media_entity_v4l2_subdev(remote->entity))

with cases like this:

 case ATOMISP_SUBDEV_PAD_SINK | MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN

where ATOMISP_SUBDEV_PAD_SINK matches an index (0-4) and
MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN is 0x00020000, but
is_media_entity_v4l2_subdev(remote->entity) does not return
MEDIA_ENT_F_* values, it return a bool, so 0 or 1 which means
that non of the cases can ever match the input value.

Looking at the rest of the function all it ever does (if it
would actually hit one of the cases) is set the atomisp_sub_device
struct's input member.

And checking the rest of the atomisp code that member is never
read. Also userspace does not actually setup media-controller
links when using the atomisp /dev/video$ nodes since all the links
are fixed. So isp_subdev_link_setup() never runs.

Remove the unnecessary and broken isp_subdev_link_setup() function
and also remove the unused atomisp_sub_device struct's input member.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Put sensor ACPI devices in D3 before disable ACPI power-resources
Hans de Goede [Sun, 22 Jan 2023 19:48:13 +0000 (20:48 +0100)]
media: atomisp: Put sensor ACPI devices in D3 before disable ACPI power-resources

The device core will call ACPI to turn the device (i2c_client) for a sensor
on / put it in D0 before calling its probe() method.

This takes a reference on all of the ACPI power-resources belonging to
the device. Since the atomisp_gmin_platform code disables ACPI
power-resource management and does its own pm, this reference never gets
released.

This is a problem for ACPI power-resources which are shared with other
devices since those now never get turned off again (nor back on again).

Explicitly put the device in D3 before disabling the ACPI power-resource
management.

Note that atomisp_register_i2c_module() runs near the end of the sensor
driver's probe() function, after the driver is done with probing the hw.
So the power-resouces (the same resources as directly controlled by
the atomisp platform code) getting turned off (a second time, as they are
already off) is not a problem.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Stop overriding padding w/h to 12 on BYT
Hans de Goede [Sun, 22 Jan 2023 15:47:26 +0000 (16:47 +0100)]
media: atomisp: Stop overriding padding w/h to 12 on BYT

atomisp_set_fmt() first does:

v4l2_fill_mbus_format(&vformat.format, ...);
        vformat.format.height += padding_h;
        vformat.format.width += padding_w;

        ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, pad,
                               set_fmt, NULL, &vformat);
        if (ret)
                return ret;

f->fmt.pix.width = vformat.format.width - padding_w;
f->fmt.pix.height = vformat.format.height - padding_h;

this happens with the original padding w/h = 16 values and then later
on it calls:

                ret = atomisp_set_fmt_to_snr(vdev, &s_fmt,
                                             f->fmt.pix.pixelformat, padding_w,
                                             padding_h, dvs_env_w, dvs_env_h);

Which repeats the above structure. If at that point padding w/h are
changed to 12 then it will now request a different output-size of
the sensor driver.

The sensor drivers so far have actually been ignoring this since they use
v4l2_find_nearest_size() on a fixed resolution list and the nearest
resolution will be the one from the earlier calls where padding w/h
was 16.

But there really is no reason for sensor drivers to use a fixed
resolution list. They make lower resolutions using cropping so they
can make any resolution as long as width/height are even numbers.

Dropping the fixed-resolution list limit from sensors on BYT results
in trying to start streaming failing because the resolution set to
the sensor now no longer matches with the resolution used during
the initial part of the configuration done by atomisp_set_fmt().

Drop the BYT specific overriding of the padding_w/h to 12, so that
the padding in the first and second s_fmt calls made to the sensor
matches, to fix stream start failing when the fixed resolution list
is dropped.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Drop ffmt local var from atomisp_set_fmt()
Hans de Goede [Sun, 22 Jan 2023 15:51:57 +0000 (16:51 +0100)]
media: atomisp: Drop ffmt local var from atomisp_set_fmt()

ffmt is a local variable pointing to a substruct of another local
variable which really just makes the code harder to read / follow,
so drop it.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Add atomisp_register_sensor_no_gmin() helper
Hans de Goede [Sun, 15 Jan 2023 21:09:57 +0000 (22:09 +0100)]
media: atomisp: Add atomisp_register_sensor_no_gmin() helper

The DSDT of all Windows BYT / CHT devices which I have seen has proper
ACPI powermagement for the clk and regulators used by the sensors.

So there is no need for the whole custom atomisp_gmin custom code to
disable the ACPI pm and directly poke at the PMIC for this.

Add new atomisp_register_sensor_no_gmin() + atomisp_unregister_subdev()
helpers which allow registering a sensor with the atomisp code without
using any of the atomisp_gmin power-management code.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove atomisp_gmin_find_subdev()
Hans de Goede [Sat, 14 Jan 2023 18:10:39 +0000 (19:10 +0100)]
media: atomisp: Remove atomisp_gmin_find_subdev()

atomisp_gmin_find_subdev() can be used to lookup a subdev
given its i2c-adapter + i2c-client-address.

But the only caller of it reads this from the intel_v4l2_subdev_table
struct and that same struct already contains a pointer to the v4l2_subdev.

So this function is not necessary, drop it and modify its only caller
to directly take the subdev from the intel_v4l2_subdev_table struct.

Also drop struct intel_v4l2_subdev_i2c_board_info since that now no
longer is used.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Allow sensor drivers without a s_power callback
Hans de Goede [Fri, 13 Jan 2023 17:06:06 +0000 (18:06 +0100)]
media: atomisp: Allow sensor drivers without a s_power callback

The s_power callback for v4l2-subdevs has been deprecated, allow sensor
drivers without a s_power callback to work by ignoring the -ENOIOCTLCMD
return value.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Do not turn off sensor when the atomisp-sub-dev does not own it
Hans de Goede [Fri, 30 Dec 2022 18:17:13 +0000 (19:17 +0100)]
media: atomisp: Do not turn off sensor when the atomisp-sub-dev does not own it

The atomisp driver creates 8 /dev/video# device nodes. 4 nodes (preview /
video / viewfinder / capture) for each of 2 possible streams aka
atomisp-sub-device-s (asd-s).

Both streams start with asd->input_curr set to 0 (to the first sensor),
opening + releasing a file-handle on one of the nodes of an asd,
while streaming from the other asd causes the sensor to get turned off,
leading to the stream failing.

The atomisp-code already tracks which asd "owns" a specific sensor,
use this to only turn the sensor off if it is owned by the asd.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove unnecessary memset(foo, 0, sizeof(foo)) calls
Hans de Goede [Wed, 28 Dec 2022 21:56:03 +0000 (22:56 +0100)]
media: atomisp: Remove unnecessary memset(foo, 0, sizeof(foo)) calls

The memory for all of struct atomisp_video_pipe is kzalloc()-ed in
atomisp_subdev_init() so there is no need to memset parts of
struct atomisp_video_pipe to 0.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Drop atomisp_init_pipe()
Hans de Goede [Wed, 28 Dec 2022 21:48:15 +0000 (22:48 +0100)]
media: atomisp: Drop atomisp_init_pipe()

atomisp_init_pipe() does 3 things:

1. Init a bunch of list-heads / locks
2. Init the vb_queue for the videodev (aka pipe)
3. zero the per-frame parameters related variables of the pipe

1. and 2. really should not be done at file-open time, but once at probe.
Currently the code is getting away with doing this on every videodev-open
because only 1 open is allowed at a time.

1. is already done at probe time by atomisp_init_subdev_pipe(), move 2. to
atomisp_init_subdev_pipe() so that it is also done once at probe.

As for 3. The per-frame parameters can only be set from a qbuf ioctl,
which can only happen after a reqbufs ioctl and atomisp_buf_cleanup
already zeros the per-frame parameters when the buffers are released,
so 3. is not necessary at all.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove deferred firmware loading support
Hans de Goede [Wed, 28 Dec 2022 19:14:00 +0000 (20:14 +0100)]
media: atomisp: Remove deferred firmware loading support

Make atomisp behave like any other drivers and have it load the firmware
at probe time (as it was already doing by default).

The deferred firmware loading support needlessly complicates the
v4l2_file_operations.open callback (atomisp_open()), getting in
the way of allowing multiple opens like a normal v4l2 device would.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove no longer used binning info from sensor resolution info
Hans de Goede [Mon, 12 Dec 2022 21:42:11 +0000 (22:42 +0100)]
media: atomisp: Remove no longer used binning info from sensor resolution info

Remove the no longer used bin_factor_x, bin_factor_y and bin_mode members
from the resolution info inside various atomisp camera sensor drivers.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove V4L2_CID_BIN_FACTOR_HORZ/_VERT
Hans de Goede [Mon, 12 Dec 2022 21:32:22 +0000 (22:32 +0100)]
media: atomisp: Remove V4L2_CID_BIN_FACTOR_HORZ/_VERT

The bin-factor-x and bin-factor-y ctrls are only used internally to
get a single value to pass to atomisp_css_input_set_binning_factor(),
which is supposed to tune the lens-shading correction for the binning
factor. But all sensor drivers return either 0 or 1 for this,
with 0 meaning unset and 1 meaning no-binning. Even though some modes
do actually do binning ...

Also note that the removed atomisp_get_sensor_bin_factor() would fall
back to 0 if either the x and y factor differ or if the ctrls are not
implemented (not all sensor drivers implement them).

Simply always pass 0 to atomisp_css_input_set_binning_factor().

This is part of a patch-series which tries to remove atomisp specific /
custom code from the sensor drivers, with as end goal to make the atomisp
drivers regular camera sensor drivers.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove custom ATOMISP_IOC_G_SENSOR_MODE_DATA ioctl
Hans de Goede [Mon, 12 Dec 2022 21:19:07 +0000 (22:19 +0100)]
media: atomisp: Remove custom ATOMISP_IOC_G_SENSOR_MODE_DATA ioctl

This ioctl returns a number of fixed sensor parameters +
a number of mode-specific parameters.

With libcamera these fixed parameters are instead stored in a table
with sensor-name to parameters mappings (camera_sensor_properties.cpp);
and the variable parameters can be derived from the set fmt.

So this custom ioctl is not necessary; and it currently has no users.

Remove the ioctl and all the sensor drivers xxxx_get_intg_factor()
helpers which return this info.

This is part of a patch-series which tries to remove atomisp specific /
custom code from the sensor drivers, with as end goal to make the atomisp
drivers regular camera sensor drivers.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove custom ATOMISP_IOC_ISP_MAKERNOTE ioctl
Hans de Goede [Sun, 11 Dec 2022 23:21:54 +0000 (00:21 +0100)]
media: atomisp: Remove custom ATOMISP_IOC_ISP_MAKERNOTE ioctl

This ioctl simply returns a couple of fixed sensor parameters.

With libcamera these fixed parameters are instead stored in a table
with sensor-name to parameters mappings (camera_sensor_properties.cpp),
so this custom ioctl is not necessary; and it currently has no users.

Remove the ioctl and also remove the custom v4l2-ctrls underpinning
the ioctl.

This is part of a patch-series which tries to remove atomisp specific /
custom code from the sensor drivers, with as end goal to make the atomisp
drivers regular camera sensor drivers.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove useless msleep(10) before power-on on BYT
Hans de Goede [Sun, 15 Jan 2023 14:37:41 +0000 (15:37 +0100)]
media: atomisp: Remove useless msleep(10) before power-on on BYT

On BYT on poweron/runtime-resume the code is doing:

1. Do nothing
2. msleep(10)
3. Start actual poweron sequence

Since the runtime resume can happen at any moment, waiting 10ms
after it does not really make any sense.

According to both the comment and to:
https://github.com/intel/ProductionKernelQuilts/blob/master/uefi/cht-m1stable/patches/cam-0341-atomisp-WA-sleep-10ms-when-power-up-ISP-on-byt.patch

Which is the patch which originally added this this was added
as a workaround for a single test failing on a single model
tablet/laptop. So lets just drop this.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove non working doorbell check from punit_ddr_dvfs_enable()
Hans de Goede [Sun, 15 Jan 2023 14:27:39 +0000 (15:27 +0100)]
media: atomisp: Remove non working doorbell check from punit_ddr_dvfs_enable()

punit_ddr_dvfs_enable() is only used on CHT devices and there dmesg
gets filled with: "DDR DVFS, door bell is not cleared within 3ms"
messages, so clearly the doorbell checking is not working.

This check was added by:
https://github.com/intel/ProductionKernelQuilts/blob/master/uefi/cht-m1stable/patches/cam-0340-atomisp-add-door-bell-for-ddr-dvfs-on-cht.patch

Which commit message says: "PUNIT interface added to check Req_ACK
of freq status". This suggests that the doorbell mechanism may only
be available with certain PUNIT fw versions and it seems that
many CHT devices do not have this fw version; that or the doorbell
mechanism is not working for other reasons.

Revert cam-0340-atomisp-add-door-bell-for-ddr-dvfs-on-cht.patch,
replacing the doorbell check with a msleep(20) this fixes dmesg
getting filled with error messages.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Silence "isys dma store at addr, val" debug messages
Hans de Goede [Sat, 26 Nov 2022 22:08:25 +0000 (23:08 +0100)]
media: atomisp: Silence "isys dma store at addr, val" debug messages

These are clearly debug messages, printing these all the time is not
useful.

Silence these by simply removing them altogether.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Move power-management over to a custom pm-domain
Hans de Goede [Sat, 26 Nov 2022 22:02:49 +0000 (23:02 +0100)]
media: atomisp: Move power-management over to a custom pm-domain

The atomisp does not use standard PCI power-management through the
PCI config space. Instead this driver directly tells the P-Unit to
disable the ISP over the IOSF. The standard PCI subsystem pm_ops will
try to access the config space before (resume) / after (suspend) this
driver has turned the ISP on / off, resulting in the following errors:

 Unable to change power state from D0 to D3hot, device inaccessible
 Unable to change power state from D3cold to D0, device inaccessible

Getting logged into dmesg a whole bunch of time during boot as well as
every time the camera is used.

To avoid these errors use a custom pm_domain instead of standard driver
pm-callbacks so that all the PCI subsys suspend / resume handling is
skipped and call pci_save_state() / pci_restore_state() ourselves.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Remove atomisp_sw_contex struct
Hans de Goede [Mon, 21 Nov 2022 14:06:09 +0000 (15:06 +0100)]
media: atomisp: Remove atomisp_sw_contex struct

Remove the atomisp_sw_contex struct, it has only 1 member: running_freq,
instead store running_freq directly.

While at it also change running_freq from an int to an unsigned int,
all values stored in it are unsigned and it is compared to the also
unsigned new_freq variable.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Fix regulator registers on BYT devices with CRC PMIC
Hans de Goede [Thu, 1 Dec 2022 21:59:40 +0000 (22:59 +0100)]
media: atomisp: Fix regulator registers on BYT devices with CRC PMIC

The Crystal Cove PMIC used on some BYT/CHT devices has different revisions
when paired with Bay Trail (BYT) vs Cherry Trail (CHT) SoCs.

The current hardcoded values are only valid for CHT devices, change
the code so that it uses the correct register values on both BYT and CHT.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Check buffer index is in range inside atomisp_qbuf_wrapper()
Hans de Goede [Wed, 28 Dec 2022 19:31:43 +0000 (20:31 +0100)]
media: atomisp: Check buffer index is in range inside atomisp_qbuf_wrapper()

Check buffer index is in range inside atomisp_qbuf_wrapper() before
using it do index pipe->frame_request_config_id[].

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Fix WARN() when the vb2 start_streaming callback fails
Hans de Goede [Sat, 21 Jan 2023 15:54:03 +0000 (16:54 +0100)]
media: atomisp: Fix WARN() when the vb2 start_streaming callback fails

The videobuf2-core expects buffers to be put back in the queued state
when the vb2 start_streaming callback fails. But the atomisp
atomisp_flush_video_pipe() would unconditionally return them to the core
in an error state.

This triggers the following warning in the videobuf2-core:

drivers/media/common/videobuf2/videobuf2-core.c:1652:
/*
 * If done_list is not empty, then start_streaming() didn't call
 * vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or
 * STATE_DONE.
 */
WARN_ON(!list_empty(&q->done_list));

Fix this by adding a state argument to atomisp_flush_video_pipe() and use
VB2_BUF_STATE_QUEUED as state when atomisp_start_streaming() fails.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Only set default_run_mode on first open of a stream/asd
Hans de Goede [Wed, 28 Dec 2022 22:11:47 +0000 (23:11 +0100)]
media: atomisp: Only set default_run_mode on first open of a stream/asd

Calling v4l2_ctrl_s_ctrl(asd->run_mode, pipe->default_run_mode) when
the stream is already active (through another /dev/video# node) causes
the stream to stop.

Move the call to set the default run-mode so that it is only done
on the first open of one of the 4 /dev/video# nodes of one of
the 2 streams (atomisp-sub-devices / asd-s).

Fixes: 2c45e343c581 ("media: atomisp: set per-device's default mode")
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: Propagate set_fmt() errors in queue_setup()
Hans de Goede [Thu, 22 Dec 2022 22:00:48 +0000 (23:00 +0100)]
media: atomisp: Propagate set_fmt() errors in queue_setup()

If set_fmt() fails make queue_setup() actually return the error instead of
returning 0.

This fixes the following oops on set_fmt() failures:

[ 1060.378662] ------------[ cut here ]------------
[ 1060.378805] WARNING: CPU: 0 PID: 2080 at drivers/media/common/videobuf2/videobuf2-core.c:840 vb2_core_reqbufs+0x3f7/0x430 [videobuf2_common]
...
[ 1060.381414] RIP: 0010:vb2_core_reqbufs+0x3f7/0x430 [videobuf2_common]
...
[ 1060.382066]  vb2_ioctl_reqbufs+0x9d/0xe0 [videobuf2_v4l2]
[ 1060.382181]  __video_do_ioctl+0x18e/0x3c0 [videodev]

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: use vb2_start_streaming_called()
Hans Verkuil [Thu, 8 Dec 2022 08:12:00 +0000 (09:12 +0100)]
media: atomisp: use vb2_start_streaming_called()

Don't touch q->start_streaming_called directly, use the
vb2_start_streaming_called() function instead.

Link: https://lore.kernel.org/r/bc6c24ec-72ea-64a1-9061-311cc7339827@xs4all.nl
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: atomisp: fix videobuf2 Kconfig depenendency
Arnd Bergmann [Wed, 4 Jan 2023 08:21:36 +0000 (09:21 +0100)]
media: atomisp: fix videobuf2 Kconfig depenendency

The recent conversion missed the Kconfig bit, so it can now
end up in a link error on randconfig builds:

ld.lld: error: undefined symbol: vb2_vmalloc_memops
>>> referenced by atomisp_fops.c
>>>               drivers/staging/media/atomisp/pci/atomisp_fops.o:(atomisp_open) in archive vmlinux.a

Link: https://lore.kernel.org/r/20230104082212.3770415-1-arnd@kernel.org
Fixes: cb48ae89be3b ("media: atomisp: Convert to videobuf2")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: rc: Fix use-after-free bugs caused by ene_tx_irqsim()
Duoming Zhou [Tue, 24 Jan 2023 07:55:33 +0000 (08:55 +0100)]
media: rc: Fix use-after-free bugs caused by ene_tx_irqsim()

When the ene device is detaching, function ene_remove() will
be called. But there is no function to cancel tx_sim_timer
in ene_remove(), the timer handler ene_tx_irqsim() could race
with ene_remove(). As a result, the UAF bugs could happen,
the process is shown below.

    (cleanup routine)          |        (timer routine)
                               | mod_timer(&dev->tx_sim_timer, ..)
ene_remove()                   | (wait a time)
                               | ene_tx_irqsim()
                               |   dev->hw_lock //USE
                               |   ene_tx_sample(dev) //USE

Fix by adding del_timer_sync(&dev->tx_sim_timer) in ene_remove(),
The tx_sim_timer could stop before ene device is deallocated.

What's more, The rc_unregister_device() and del_timer_sync()
should be called first in ene_remove() and the deallocated
functions such as free_irq(), release_region() and so on
should be called behind them. Because the rc_unregister_device()
is well synchronized. Otherwise, race conditions may happen. The
situations that may lead to race conditions are shown below.

Firstly, the rx receiver is disabled with ene_rx_disable()
before rc_unregister_device() in ene_remove(), which means it
can be enabled again if a process opens /dev/lirc0 between
ene_rx_disable() and rc_unregister_device().

Secondly, the irqaction descriptor is freed by free_irq()
before the rc device is unregistered, which means irqaction
descriptor may be accessed again after it is deallocated.

Thirdly, the timer can call ene_tx_sample() that can write
to the io ports, which means the io ports could be accessed
again after they are deallocated by release_region().

Therefore, the rc_unregister_device() and del_timer_sync()
should be called first in ene_remove().

Suggested by: Sean Young <sean@mess.org>

Fixes: 9ea53b74df9c ("V4L/DVB: STAGING: remove lirc_ene0100 driver")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: rc: gpio-ir-recv: add remove function
Li Jun [Wed, 11 Jan 2023 09:39:21 +0000 (10:39 +0100)]
media: rc: gpio-ir-recv: add remove function

In case runtime PM is enabled, do runtime PM clean up to remove
cpu latency qos request, otherwise driver removal may have below
kernel dump:

[   19.463299] Unable to handle kernel NULL pointer dereference at
virtual address 0000000000000048
[   19.472161] Mem abort info:
[   19.474985]   ESR = 0x0000000096000004
[   19.478754]   EC = 0x25: DABT (current EL), IL = 32 bits
[   19.484081]   SET = 0, FnV = 0
[   19.487149]   EA = 0, S1PTW = 0
[   19.490361]   FSC = 0x04: level 0 translation fault
[   19.495256] Data abort info:
[   19.498149]   ISV = 0, ISS = 0x00000004
[   19.501997]   CM = 0, WnR = 0
[   19.504977] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000049f81000
[   19.511432] [0000000000000048] pgd=0000000000000000,
p4d=0000000000000000
[   19.518245] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
[   19.524520] Modules linked in: gpio_ir_recv(+) rc_core [last
unloaded: rc_core]
[   19.531845] CPU: 0 PID: 445 Comm: insmod Not tainted
6.2.0-rc1-00028-g2c397a46d47c #72
[   19.531854] Hardware name: FSL i.MX8MM EVK board (DT)
[   19.531859] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS
BTYPE=--)
[   19.551777] pc : cpu_latency_qos_remove_request+0x20/0x110
[   19.557277] lr : gpio_ir_recv_runtime_suspend+0x18/0x30
[gpio_ir_recv]
[   19.557294] sp : ffff800008ce3740
[   19.557297] x29: ffff800008ce3740 x28: 0000000000000000 x27:
ffff800008ce3d50
[   19.574270] x26: ffffc7e3e9cea100 x25: 00000000000f4240 x24:
ffffc7e3f9ef0e30
[   19.574284] x23: 0000000000000000 x22: ffff0061803820f4 x21:
0000000000000008
[   19.574296] x20: ffffc7e3fa75df30 x19: 0000000000000020 x18:
ffffffffffffffff
[   19.588570] x17: 0000000000000000 x16: ffffc7e3f9efab70 x15:
ffffffffffffffff
[   19.595712] x14: ffff800008ce37b8 x13: ffff800008ce37aa x12:
0000000000000001
[   19.602853] x11: 0000000000000001 x10: ffffcbe3ec0dff87 x9 :
0000000000000008
[   19.609991] x8 : 0101010101010101 x7 : 0000000000000000 x6 :
000000000f0bfe9f
[   19.624261] x5 : 00ffffffffffffff x4 : 0025ab8e00000000 x3 :
ffff006180382010
[   19.631405] x2 : ffffc7e3e9ce8030 x1 : ffffc7e3fc3eb810 x0 :
0000000000000020
[   19.638548] Call trace:
[   19.640995]  cpu_latency_qos_remove_request+0x20/0x110
[   19.646142]  gpio_ir_recv_runtime_suspend+0x18/0x30 [gpio_ir_recv]
[   19.652339]  pm_generic_runtime_suspend+0x2c/0x44
[   19.657055]  __rpm_callback+0x48/0x1dc
[   19.660807]  rpm_callback+0x6c/0x80
[   19.664301]  rpm_suspend+0x10c/0x640
[   19.667880]  rpm_idle+0x250/0x2d0
[   19.671198]  update_autosuspend+0x38/0xe0
[   19.675213]  pm_runtime_set_autosuspend_delay+0x40/0x60
[   19.680442]  gpio_ir_recv_probe+0x1b4/0x21c [gpio_ir_recv]
[   19.685941]  platform_probe+0x68/0xc0
[   19.689610]  really_probe+0xc0/0x3dc
[   19.693189]  __driver_probe_device+0x7c/0x190
[   19.697550]  driver_probe_device+0x3c/0x110
[   19.701739]  __driver_attach+0xf4/0x200
[   19.705578]  bus_for_each_dev+0x70/0xd0
[   19.709417]  driver_attach+0x24/0x30
[   19.712998]  bus_add_driver+0x17c/0x240
[   19.716834]  driver_register+0x78/0x130
[   19.720676]  __platform_driver_register+0x28/0x34
[   19.725386]  gpio_ir_recv_driver_init+0x20/0x1000 [gpio_ir_recv]
[   19.731404]  do_one_initcall+0x44/0x2ac
[   19.735243]  do_init_module+0x48/0x1d0
[   19.739003]  load_module+0x19fc/0x2034
[   19.742759]  __do_sys_finit_module+0xac/0x12c
[   19.747124]  __arm64_sys_finit_module+0x20/0x30
[   19.751664]  invoke_syscall+0x48/0x114
[   19.755420]  el0_svc_common.constprop.0+0xcc/0xec
[   19.760132]  do_el0_svc+0x38/0xb0
[   19.763456]  el0_svc+0x2c/0x84
[   19.766516]  el0t_64_sync_handler+0xf4/0x120
[   19.770789]  el0t_64_sync+0x190/0x194
[   19.774460] Code: 910003fd a90153f3 aa0003f3 91204021 (f9401400)
[   19.780556] ---[ end trace 0000000000000000 ]---

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dt-bindings: st,stih-cec: convert to DT schema
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:15 +0000 (11:31 +0100)]
media: dt-bindings: st,stih-cec: convert to DT schema

Convert ST STIH4xx HDMI CEC bindings to DT schema.

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>
21 months agomedia: dt-bindings: nvidia,tegra114-cec: convert to DT schema
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:14 +0000 (11:31 +0100)]
media: dt-bindings: nvidia,tegra114-cec: convert to DT schema

Convert NVIDIA Tegra HDMI CEC bindings to DT schema.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Acked-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dt-bindings: cec-gpio: convert to DT schema
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:13 +0000 (11:31 +0100)]
media: dt-bindings: cec-gpio: convert to DT schema

Convert HDMI CEC GPIO bindings to DT schema.

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>
21 months agomedia: dt-bindings: samsung,s5p-cec: convert to DT schema
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:12 +0000 (11:31 +0100)]
media: dt-bindings: samsung,s5p-cec: convert to DT schema

Convert Samsung S5P HDMI CEC adapter bindings to DT schema.

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>
21 months agomedia: dt-bindings: chrontel,ch7322: reference common CEC properties
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:11 +0000 (11:31 +0100)]
media: dt-bindings: chrontel,ch7322: reference common CEC properties

Reference common HDMI CEC adapter properties to simplify the binding and
have only one place of definition for common properties.  The common CEC
binding expects also node name to be 'cec'.

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>
21 months agomedia: dt-bindings: amlogic,meson-gx-ao-cec: reference common CEC properties
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:10 +0000 (11:31 +0100)]
media: dt-bindings: amlogic,meson-gx-ao-cec: reference common CEC properties

Reference common HDMI CEC adapter properties to simplify the binding and
have only one place of definition for common properties.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Neil Armstrong <neil.armstrong@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>
21 months agomedia: dt-bindings: cec: convert common CEC properties to DT schema
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:09 +0000 (11:31 +0100)]
media: dt-bindings: cec: convert common CEC properties to DT schema

Convert common HDMI CEC adapter bindings to DT schema.

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>
21 months agomedia: dt-bindings: st,stm32-cec: move to cec subfolder
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:08 +0000 (11:31 +0100)]
media: dt-bindings: st,stm32-cec: move to cec subfolder

Move st,stm32-cec.yaml bindings to cec subfolder and drop unneeded
"bindings" in the title.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: dt-bindings: amlogic,meson-gx-ao-cec: move to cec subfolder
Krzysztof Kozlowski [Thu, 8 Dec 2022 10:31:07 +0000 (11:31 +0100)]
media: dt-bindings: amlogic,meson-gx-ao-cec: move to cec subfolder

Move amlogic,meson-gx-ao-cec.yaml bindings to cec subfolder and drop
unneeded quotes.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Neil Armstrong <neil.armstrong@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: drivers/media/v4l2-core/v4l2-h264 : add detection of null pointers
Dong Chuanjian [Tue, 27 Dec 2022 02:36:25 +0000 (03:36 +0100)]
media: drivers/media/v4l2-core/v4l2-h264 : add detection of null pointers

When the pointer variable is judged to be null, null is returned
directly.

[hverkuil: fix two checkpatch warnings]

Signed-off-by: Dong Chuanjian <chuanjian@nfschina.com>
Acked-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Fixes: d3f756ad629b ("media: v4l2: Trace calculated p/b0/b1 initial reflist")
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: hantro: Use core-generated bus_info value
Chen-Yu Tsai [Mon, 26 Dec 2022 05:26:06 +0000 (06:26 +0100)]
media: hantro: Use core-generated bus_info value

The Hantro driver uses a hardcoded value for the bus_info field in the
media device and |struct v4l2_capability|. This worked well when there
was just one device. However with the iMX.8 series we are now seeing
two Hantro blocks on the same chip. The static bus_info is no longer
sufficient for differentiating devices.

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 static bus_info values from the hantro driver and use the
defaults.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: mediatek: vcodec: Using pm_runtime_put instead of pm_runtime_put_sync
Yunfei Dong [Sat, 14 Jan 2023 09:41:12 +0000 (10:41 +0100)]
media: mediatek: vcodec: Using pm_runtime_put instead of pm_runtime_put_sync

pm_runtime_put will set RPM_ASYNC flag then queue an idle-notification
request again, won't return error immediately until current request is
scheduled.

But pm_runtime_put_sync run the ->runtime_idle() callback directly, return
error immediately no matter whether current request is scheduled.

Signed-off-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>
21 months agomedia: amphion: correct the unspecified color space
Ming Qian [Fri, 13 Jan 2023 05:25:51 +0000 (06:25 +0100)]
media: amphion: correct the unspecified color space

in the E.2.1 of Rec. ITU-T H.264 (06/2019),
0 of colour primaries is reserved, and 2 is unspecified.
driver can map V4L2_COLORSPACE_LAST to 0,
and map V4L2_COLORSPACE_DEFAULT to 2.

v4l2_xfer_func and v4l2_ycbcr_encoding are similar case.

Fixes: 3cd084519c6f ("media: amphion: add vpu v4l2 m2m support")
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>
21 months agomedia: imx-jpeg: Apply clk_bulk api instead of operating specific clk
Ming Qian [Thu, 12 Jan 2023 09:47:02 +0000 (10:47 +0100)]
media: imx-jpeg: Apply clk_bulk api instead of operating specific clk

using the api of clk_bulk can simplify the code.
and the clock of the jpeg codec may be changed,
the clk_bulk api can be compatible with the future change.

Fixes: 4c2e5156d9fa ("media: imx-jpeg: Add pm-runtime support for imx-jpeg")
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>
21 months agomedia: sun4i-csi: Fix 'Unbalanced pm_runtime_enable!'
Oleg Verych [Sat, 7 Jan 2023 08:37:49 +0000 (09:37 +0100)]
media: sun4i-csi: Fix 'Unbalanced pm_runtime_enable!'

When removing the module, balance PM runtime enable with
the corresponding disable call.

Signed-off-by: Oleg Verych <olecom@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: rkisp1: make a few const arrays static
Colin Ian King [Thu, 5 Jan 2023 18:44:03 +0000 (19:44 +0100)]
media: rkisp1: make a few const arrays static

Don't populate the const arrays on the stack, instead make them
static. Also makes the object code smaller.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: vidtv: make const array DURATION static
Colin Ian King [Thu, 5 Jan 2023 18:33:14 +0000 (19:33 +0100)]
media: vidtv: make const array DURATION static

Don't populate the read-only const array DURATION on the stack but
instead make it static. Also makes the object code a little smaller.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: staging: media: imx: change imx_media_fim_set_stream() to return void
Deepak R Varma [Tue, 3 Jan 2023 17:38:20 +0000 (18:38 +0100)]
media: staging: media: imx: change imx_media_fim_set_stream() to return void

At present, the function imx_media_fim_set_stream() always returns 0.
So, convert it to be a function returning void instead. Issue identified
using the returnvar.cocci Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <drv@mailo.com>
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: hantro: Fix JPEG encoder ENUM_FRMSIZE on RK3399
Nicolas Dufresne [Fri, 23 Dec 2022 18:16:47 +0000 (19:16 +0100)]
media: hantro: Fix JPEG encoder ENUM_FRMSIZE on RK3399

Since 79c987de8b354, enumerating framesize on format set with "MODE_NONE"
(any raw formats) is reporting an invalid frmsize.

  Size: Stepwise 0x0 - 0x0 with step 0/0

Before this change, the driver would return EINVAL, which is also invalid
but worked in GStreamer. The original intent was not to implement it, hence
the -ENOTTY return in this change. While drivers should implement
ENUM_FRMSIZE for all formats and queues, this change is limited in scope to
fix the regression.

This fixes taking picture in Gnome Cheese software, or any software using
GSteamer to encode JPEG with hardware acceleration.

Fixes: 79c987de8b35 ("media: hantro: Use post processor scaling capacities")
Reported-by: Robert Mader <robert.mader@collabora.com>
Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tested-by: Robert Mader <robert.mader@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: radio/wl128x: remove unnecessary (void*) conversions
Zhou jie [Fri, 23 Dec 2022 09:08:58 +0000 (10:08 +0100)]
media: radio/wl128x: remove unnecessary (void*) conversions

The void * type pointer does not need to be cast.

Signed-off-by: Zhou jie <zhoujie@nfschina.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: v4l2-jpeg: ignore the unknown APP14 marker
Ming Qian [Fri, 16 Dec 2022 09:08:44 +0000 (10:08 +0100)]
media: v4l2-jpeg: ignore the unknown APP14 marker

The legal identifier of APP14 is "Adobe\0",
but sometimes it may be
"This is an unknown APP marker . Compliant decoders must ignore it."
In this case, just ignore it.
It won't affect the decode result.

Fixes: b8035f7988a8 ("media: Add parsing for APP14 data segment in jpeg helpers")
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>
21 months agomedia: v4l2-jpeg: correct the skip count in jpeg_parse_app14_data
Ming Qian [Fri, 16 Dec 2022 08:30:33 +0000 (09:30 +0100)]
media: v4l2-jpeg: correct the skip count in jpeg_parse_app14_data

The curr pointer has advanced 14 bytes in jpeg_parse_app14_data.
1. jpeg_get_word_be(stream), it goes forward 2 bytes.
2. jpeg_skip(stream, 11), it goes forward 11 bytes.
3. jpeg_get_byte(stream), it goes forward 1 bytes.

so the remain bytes of this segment should be (lp - 2 - 11 - 1),
but not (lp - 2 - 11).

if driver skip 1 extra bytes, the following parsing may go wrong.

Fixes: b8035f7988a8 ("media: Add parsing for APP14 data segment in jpeg helpers")
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>
21 months agomedia: platform: mtk-mdp3: fix Kconfig dependencies
Arnd Bergmann [Thu, 15 Dec 2022 16:40:08 +0000 (17:40 +0100)]
media: platform: mtk-mdp3: fix Kconfig dependencies

The new mdp3 driver uses 'select' to force-enable a couple of drivers
it depends on. This is error-prone and likely to cause dependency
loops as well as warnings like:

WARNING: unmet direct dependencies detected for VIDEO_MEDIATEK_VPU
  Depends on [n]: MEDIA_SUPPORT [=m] && MEDIA_PLATFORM_SUPPORT [=y] && MEDIA_PLATFORM_DRIVERS [=y] && V4L_MEM2MEM_DRIVERS [=n] && VIDEO_DEV [=m] && (ARCH_MEDIATEK [=y] || COMPILE_TEST [=y])
  Selected by [m]:
  - VIDEO_MEDIATEK_MDP3 [=m] && MEDIA_SUPPORT [=m] && MEDIA_PLATFORM_SUPPORT [=y] && MEDIA_PLATFORM_DRIVERS [=y] && (MTK_IOMMU [=m] || COMPILE_TEST [=y]) && VIDEO_DEV [=m] && (ARCH_MEDIATEK [=y] || COMPILE_TEST [=y]) && HAS_DMA [=y] && REMOTEPROC [=y]

This specific warning was already addressed in a previous patch,
but there are similar unnecessary 'select' statements, so turn those
into 'depends on'. This also means the dependency on ARCH_MEDIATEK
is redundant and can be dropped.

Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
Fixes: 9195a860ef0a ("media: platform: mtk-mdp3: remove unused VIDEO_MEDIATEK_VPU config")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-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>
21 months agomedia: camss: csiphy-3ph: avoid undefined behavior
Arnd Bergmann [Thu, 15 Dec 2022 16:28:46 +0000 (17:28 +0100)]
media: camss: csiphy-3ph: avoid undefined behavior

Marking a case of the switch statement as unreachable means the
compiler treats it as undefined behavior, which is then caught by
an objtool warning:

drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.o: warning: objtool: csiphy_lanes_enable() falls through to next function csiphy_lanes_disable()

Instead of simply continuing execution at a random place of the
driver, print a warning and return from to the caller, which
makes it possible to understand what happens and avoids the
warning.

Fixes: 53655d2a0ff2 ("media: camss: csiphy-3ph: add support for SM8250 CSI DPHY")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Robert Foss <robert.foss@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: chips-media/imx-vdoa: Drop empty platform remove function
Uwe Kleine-König [Tue, 13 Dec 2022 15:35:53 +0000 (16:35 +0100)]
media: chips-media/imx-vdoa: Drop empty platform remove function

A remove callback just returning 0 is equivalent to no remove callback
at all. So drop the useless function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: ti/davinci: vpbe_venc: Drop empty platform remove function
Uwe Kleine-König [Tue, 13 Dec 2022 15:35:51 +0000 (16:35 +0100)]
media: ti/davinci: vpbe_venc: Drop empty platform remove function

A remove callback just returning 0 is equivalent to no remove callback
at all. So drop the useless function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Lad Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: ti/davinci: vpbe_osd: Drop empty platform remove function
Uwe Kleine-König [Tue, 13 Dec 2022 15:35:50 +0000 (16:35 +0100)]
media: ti/davinci: vpbe_osd: Drop empty platform remove function

A remove callback just returning 0 is equivalent to no remove callback
at all. So drop the useless function.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Lad Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
21 months agomedia: go7007: don't modify q->streaming
Hans Verkuil [Thu, 8 Dec 2022 07:52:06 +0000 (08:52 +0100)]
media: go7007: don't modify q->streaming

The streaming state is maintained by the vb2 core, so drivers
must never change it themselves.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>