[git:edid-decode/master] edid-decode: minor modifications to README and emscripten path

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: edid-decode: minor modifications to README and emscripten path
Author:  Hans Verkuil 
Date:Fri May 10 11:40:32 2024 +0200

Use 'build' and 'build-wasm' as the build directories (i.e. no
underscore prefix). This makes it consistent with the v4l-utils
project.

Drop the path from the default emscripten toolchain in wasm-crossfile.txt,
i.e. by default it is assumed to be in the user's PATH.

Signed-off-by: Hans Verkuil 

 .gitignore|  1 +
 README| 17 -
 emscripten/wasm-crossfile.txt | 10 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

---

diff --git a/.gitignore b/.gitignore
index a4ab473135af..c83b5ba66671 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ edid-decode
 emscripten/*.o
 emscripten/edid-decode.wasm
 emscripten/edid-decode.js
+install-wasm
diff --git a/README b/README
index bf4e66870503..0a1154213f80 100644
--- a/README
+++ b/README
@@ -6,9 +6,9 @@ To build this do:
 
 git clone git://linuxtv.org/edid-decode.git
 cd edid-decode
-meson setup _build
-meson compile -C _build
-meson install -C _build
+meson setup build
+meson compile -C build
+meson install -C build
 
 Patches and bug reports can be sent to the linux-me...@vger.kernel.org
 mailinglist (see https://www.linuxtv.org/lists.php). Please make sure
@@ -49,16 +49,15 @@ This is updated regularly with the latest edid-decode. It 
uses emscripten
 and the html file is maintained in the emscripten directory of edid-decode.
 To build it, set the project up using the provided crossfile:
 
-   meson setup _build-wasm \
-   --cross-file ./emscripten/wasm-crossfile.txt \
-   --prefix=$(pwd)/_install-wasm
-   meson install _build-wasm
+   meson setup build-wasm --cross-file ./emscripten/wasm-crossfile.txt 
--prefix=$(pwd)/install-wasm
+   meson install -C build-wasm
# serve the files using a local webserver
-   cd _install-wasm/bin
+   cd install-wasm/bin
python3 -m http.server
 
 This assumes that emscripten is installed, of course. The location of the
-toolchain can be adjusted in emscripten/wasm-crossfile.txt.
+toolchain can be adjusted in emscripten/wasm-crossfile.txt. Currently
+it assumes that the emscripten tools are in your $PATH.
 See also https://emscripten.org/docs/getting_started/Tutorial.html and
 https://mesonbuild.com/Cross-compilation.html.
 
diff --git a/emscripten/wasm-crossfile.txt b/emscripten/wasm-crossfile.txt
index a41f46ca2ede..ef0d9d8f196b 100644
--- a/emscripten/wasm-crossfile.txt
+++ b/emscripten/wasm-crossfile.txt
@@ -1,8 +1,8 @@
 [binaries]
-c = '/usr/lib/emscripten/emcc'
-cpp = '/usr/lib/emscripten/em++'
-ar = '/usr/lib/emscripten/emar'
-strip = '/usr/lib/emscripten/emstrip'
+c = 'emcc'
+cpp = 'em++'
+ar = 'emar'
+strip = 'emstrip'
 
 [built-in options]
 default_library = 'static'
@@ -11,4 +11,4 @@ default_library = 'static'
 system = 'emscripten'
 cpu_family = 'wasm32'
 cpu = 'wasm32'
-endian = 'little'
\ No newline at end of file
+endian = 'little'


[git:edid-decode/master] edid-decode: build: add support for building with meson

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: edid-decode: build: add support for building with meson
Author:  Sebastian Wick 
Date:Tue Apr 2 22:13:47 2024 +0200

This also removes the old Makefile based build-system.

The immediate reason for adding support for meson is that this allows us
to include edid-decode as a subproject in libdisplay-info.

v3:
 * Declare a meson variable for the executable to make it possible to
   get it via subproject.get_variable()
v2:
 * Remove the make build-system
 * Adjust the README on how to build/install with meson
 * Fix installing for the wasm-build

Signed-off-by: Sebastian Wick 
Signed-off-by: Hans Verkuil 

 Makefile  | 50 -
 README| 28 +++
 emscripten/wasm-crossfile.txt | 14 ++
 meson.build   | 65 +++
 4 files changed, 96 insertions(+), 61 deletions(-)

---

diff --git a/Makefile b/Makefile
deleted file mode 100644
index 375fedb8fe25..
diff --git a/README b/README
index 4c2b7fe87a2e..bf4e66870503 100644
--- a/README
+++ b/README
@@ -6,8 +6,9 @@ To build this do:
 
 git clone git://linuxtv.org/edid-decode.git
 cd edid-decode
-make
-make install
+meson setup _build
+meson compile -C _build
+meson install -C _build
 
 Patches and bug reports can be sent to the linux-me...@vger.kernel.org
 mailinglist (see https://www.linuxtv.org/lists.php). Please make sure
@@ -46,15 +47,20 @@ https://hverkuil.home.xs4all.nl/edid-decode/edid-decode.html
 
 This is updated regularly with the latest edid-decode. It uses emscripten
 and the html file is maintained in the emscripten directory of edid-decode.
-To build edid-decode.js/wasm run 'make edid-decode.js'. This assumes
-that emscripten is installed, of course.
-
-You can use the konqueror browser to run it locally:
-
-   konqueror emscripten/edid-decode.html
-
-For other browsers you need to serve the files using a local webserver.
-See also https://emscripten.org/docs/getting_started/Tutorial.html
+To build it, set the project up using the provided crossfile:
+
+   meson setup _build-wasm \
+   --cross-file ./emscripten/wasm-crossfile.txt \
+   --prefix=$(pwd)/_install-wasm
+   meson install _build-wasm
+   # serve the files using a local webserver
+   cd _install-wasm/bin
+   python3 -m http.server
+
+This assumes that emscripten is installed, of course. The location of the
+toolchain can be adjusted in emscripten/wasm-crossfile.txt.
+See also https://emscripten.org/docs/getting_started/Tutorial.html and
+https://mesonbuild.com/Cross-compilation.html.
 
 You can find a very large collection of EDIDs here:
 https://github.com/linuxhw/EDID
diff --git a/emscripten/wasm-crossfile.txt b/emscripten/wasm-crossfile.txt
new file mode 100644
index ..a41f46ca2ede
--- /dev/null
+++ b/emscripten/wasm-crossfile.txt
@@ -0,0 +1,14 @@
+[binaries]
+c = '/usr/lib/emscripten/emcc'
+cpp = '/usr/lib/emscripten/em++'
+ar = '/usr/lib/emscripten/emar'
+strip = '/usr/lib/emscripten/emstrip'
+
+[built-in options]
+default_library = 'static'
+
+[host_machine]
+system = 'emscripten'
+cpu_family = 'wasm32'
+cpu = 'wasm32'
+endian = 'little'
\ No newline at end of file
diff --git a/meson.build b/meson.build
new file mode 100644
index ..ca5765276bc5
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,65 @@
+project(
+   'edid-decode',
+   'cpp',
+)
+
+edid_decode_args = [
+   '-Wno-missing-field-initializers',
+   '-Wno-unused-parameter',
+   '-Wimplicit-fallthrough',
+]
+edid_decode_link_args = []
+
+git = find_program('git', native: true, required: false)
+if git.found()
+   git_commit = run_command(
+   [git, 'rev-parse', '--short=12', 'HEAD'],
+   check: false,
+   )
+   git_date = run_command(
+   [git, 'show', '--quiet', '--date=format-local:%F %T', 
'--format=%cd'],
+   env: {'TZ': 'UTC'},
+   check: false,
+   )
+
+   if git_commit.returncode() == 0
+   edid_decode_args += ['-DSHA=' + git_commit.stdout().strip()]
+   endif
+   if git_date.returncode() == 0
+   edid_decode_args += ['-DDATE=' + git_date.stdout().strip()]
+   endif
+endif
+
+if target_machine.system() == 'emscripten'
+   edid_decode_link_args += [
+   '-sEXPORTED_FUNCTIONS=_parse_edid',
+   '-sEXPORTED_RUNTIME_METHODS=ccall,cwrap'
+   ]
+
+   fs = import('fs')
+   foreach filename : ['edid-decode.html', 'edid-decode.ico']
+   fs.copyfile(
+   'emscripten' / filename,
+   install: true,
+   install_dir: 'bin',
+   )
+   endforeach
+endif
+
+edid_decode = executable(
+   'edid-decode',
+   'calc-gtf-cvt.cpp',
+   'calc-ovt.cpp

[git:media_stage/master] media: ov2740: Ensure proper reset sequence on probe()

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2740: Ensure proper reset sequence on probe()
Author:  Hans de Goede 
Date:Mon May 6 15:24:38 2024 +0200

Before this commit on probe() the driver would do:

reset=1// from probe() calling gpiod_get(GPIOD_OUT_HIGH)
reset=0// from resume()
msleep(20) // from resume()

So if reset was 0 before getting the GPIO the reset line would only be
driven high for a very short time and sometimes there would be errors
reading the id register afterwards.

Add a msleep(20) after getting the reset line to ensure the sensor is
properly reset:

reset=1// from probe() calling gpiod_get(GPIOD_OUT_HIGH)
msleep(20) // from probe()
reset=0// from resume()
msleep(20) // from resume()

Signed-off-by: Hans de Goede 
Tested-by: Stanislaw Gruszka 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2740.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 57906df7be4e..c48dbcde9877 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -1333,9 +1333,16 @@ static int ov2740_probe(struct i2c_client *client)
return dev_err_probe(dev, ret, "failed to check HW 
configuration\n");
 
ov2740->reset_gpio = devm_gpiod_get_optional(dev, "reset", 
GPIOD_OUT_HIGH);
-   if (IS_ERR(ov2740->reset_gpio))
+   if (IS_ERR(ov2740->reset_gpio)) {
return dev_err_probe(dev, PTR_ERR(ov2740->reset_gpio),
 "failed to get reset GPIO\n");
+   } else if (ov2740->reset_gpio) {
+   /*
+* Ensure reset is asserted for at least 20 ms before
+* ov2740_resume() deasserts it.
+*/
+   msleep(20);
+   }
 
ov2740->clk = devm_clk_get_optional(dev, "clk");
if (IS_ERR(ov2740->clk))


[git:media_stage/master] media: intel/ipu6: Don't print user-triggerable errors to kernel log

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: Don't print user-triggerable errors to kernel log
Author:  Sakari Ailus 
Date:Thu May 2 18:21:30 2024 +0300

Use dev_dbg() for printing messages on user-triggerable conditions that
have no relation to driver or hardware issues.

Fixes: 3c1dfb5a69cf ("media: intel/ipu6: input system video nodes and buffer 
queues")
Signed-off-by: Sakari Ailus 
Reviewed-by: Bingbu Cao 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys-queue.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
index 11cd2c977abe..40a8ebfcfce2 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
@@ -34,7 +34,7 @@ static int queue_setup(struct vb2_queue *q, unsigned int 
*num_buffers,
if (!*num_planes) {
sizes[0] = size;
} else if (sizes[0] < size) {
-   dev_err(dev, "%s: queue setup: size %u < %u\n",
+   dev_dbg(dev, "%s: queue setup: size %u < %u\n",
av->vdev.name, sizes[0], size);
return -EINVAL;
}
@@ -359,7 +359,7 @@ static void buf_queue(struct vb2_buffer *vb)
 */
ret = buffer_list_get(stream, );
if (ret < 0) {
-   dev_warn(dev, "No buffers available\n");
+   dev_dbg(dev, "No buffers available\n");
goto out;
}
 
@@ -426,7 +426,7 @@ static int ipu6_isys_link_fmt_validate(struct 
ipu6_isys_queue *aq)
 
if (format.width != ipu6_isys_get_frame_width(av) ||
format.height != ipu6_isys_get_frame_height(av)) {
-   dev_err(dev, "wrong width or height %ux%u (%ux%u expected)\n",
+   dev_dbg(dev, "wrong width or height %ux%u (%ux%u expected)\n",
ipu6_isys_get_frame_width(av),
ipu6_isys_get_frame_height(av), format.width,
format.height);
@@ -521,13 +521,13 @@ static int start_streaming(struct vb2_queue *q, unsigned 
int count)
 
ret = ipu6_isys_setup_video(av, _entity, _queues);
if (ret < 0) {
-   dev_err(dev, "failed to setup video\n");
+   dev_dbg(dev, "failed to setup video\n");
goto out_return_buffers;
}
 
ret = ipu6_isys_link_fmt_validate(aq);
if (ret) {
-   dev_err(dev,
+   dev_dbg(dev,
"%s: link format validation failed (%d)\n",
av->vdev.name, ret);
goto out_pipeline_stop;


[git:media_stage/master] Revert "media: v4l2-ctrls: show all owned controls in log_status"

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: Revert "media: v4l2-ctrls: show all owned controls in log_status"
Author:  Hans Verkuil 
Date:Fri May 10 09:11:46 2024 +0200

This reverts commit 9801b5b28c6929139d6fc8d739cc67bb2739.

This patch introduced a potential deadlock scenario:

[Wed May  8 10:02:06 2024]  Possible unsafe locking scenario:

[Wed May  8 10:02:06 2024]CPU0CPU1
[Wed May  8 10:02:06 2024]
[Wed May  8 10:02:06 2024]   lock(vivid_ctrls:1620:(hdl_vid_cap)->_lock);
[Wed May  8 10:02:06 2024]
lock(vivid_ctrls:1608:(hdl_user_vid)->_lock);
[Wed May  8 10:02:06 2024]
lock(vivid_ctrls:1620:(hdl_vid_cap)->_lock);
[Wed May  8 10:02:06 2024]   lock(vivid_ctrls:1608:(hdl_user_vid)->_lock);

For now just revert.

Fixes: 9801b5b28c69 ("media: v4l2-ctrls: show all owned controls in log_status")
Cc: sta...@vger.kernel.org
Signed-off-by: Hans Verkuil 
Reviewed-by: Laurent Pinchart 

 drivers/media/v4l2-core/v4l2-ctrls-core.c | 18 +-
 1 file changed, 5 insertions(+), 13 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c 
b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index c59dd691f79f..eeab6a5eb7ba 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2507,8 +2507,7 @@ int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
 EXPORT_SYMBOL(v4l2_ctrl_handler_setup);
 
 /* Log the control name and value */
-static void log_ctrl(const struct v4l2_ctrl_handler *hdl,
-struct v4l2_ctrl *ctrl,
+static void log_ctrl(const struct v4l2_ctrl *ctrl,
 const char *prefix, const char *colon)
 {
if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
@@ -2518,11 +2517,7 @@ static void log_ctrl(const struct v4l2_ctrl_handler *hdl,
 
pr_info("%s%s%s: ", prefix, colon, ctrl->name);
 
-   if (ctrl->handler != hdl)
-   v4l2_ctrl_lock(ctrl);
ctrl->type_ops->log(ctrl);
-   if (ctrl->handler != hdl)
-   v4l2_ctrl_unlock(ctrl);
 
if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
   V4L2_CTRL_FLAG_GRABBED |
@@ -2541,7 +2536,7 @@ static void log_ctrl(const struct v4l2_ctrl_handler *hdl,
 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
  const char *prefix)
 {
-   struct v4l2_ctrl_ref *ref;
+   struct v4l2_ctrl *ctrl;
const char *colon = "";
int len;
 
@@ -2553,12 +2548,9 @@ void v4l2_ctrl_handler_log_status(struct 
v4l2_ctrl_handler *hdl,
if (len && prefix[len - 1] != ' ')
colon = ": ";
mutex_lock(hdl->lock);
-   list_for_each_entry(ref, >ctrl_refs, node) {
-   if (ref->from_other_dev ||
-   (ref->ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
-   continue;
-   log_ctrl(hdl, ref->ctrl, prefix, colon);
-   }
+   list_for_each_entry(ctrl, >ctrls, node)
+   if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
+   log_ctrl(ctrl, prefix, colon);
mutex_unlock(hdl->lock);
 }
 EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);


[git:media_stage/master] Merge tag 'media-fixes-unicam-20240510' of https://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux into media_stage

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: Merge tag 'media-fixes-unicam-20240510' of 
https://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux into media_stage
Author:  Hans Verkuil 
Date:Fri May 10 09:53:11 2024 +0200

bcm2835-unicam fixes for v6.10

Signed-off-by: Hans Verkuil 
From: Laurent Pinchart 
Link: 
https://patchwork.linuxtv.org/project/linux-media/patch/20240509222123.ga21...@pendragon.ideasonboard.com/

---



[git:v4l-utils/master] v4l-utils: test-media: add dmesg -n info before modprobes

2024-05-10 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l-utils: test-media: add dmesg -n info before modprobes
Author:  Hans Verkuil 
Date:Fri May 10 09:42:13 2024 +0200

Sometimes the modprobe vivid fails, but because dmesg is set to
the 'notice' level it is not clear why it fails since the usual
kernel info messages are filtered out.

Switch to dmesg -n info before each modprobe so we can actually
see what is going on.

Signed-off-by: Hans Verkuil 

 contrib/test/test-media | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=649f37341d935bc73c3f7854a7c67e98fe55a60e
diff --git a/contrib/test/test-media b/contrib/test/test-media
index 18a4f8864529..5895cf0422dd 100755
--- a/contrib/test/test-media
+++ b/contrib/test/test-media
@@ -193,16 +193,17 @@ fi
 
 if [ $unload -eq 1 ]; then
test-media-unload.pl
-   dmesg -n notice
 fi
 
 if [ $kmemleak -eq 1 ]; then
echo clear >/sys/kernel/debug/kmemleak
 fi
 
+dmesg -n info
 rmmod vivid 2&>/dev/null
 modprobe vivid n_devs=3 multiplanar=1,2,2 cache_hints=1,0,0 #allocators=0,1,1
 sleep $modprobe_time
+dmesg -n notice
 
 tmp=`mktemp`
 
@@ -247,11 +248,12 @@ if [ $vivid -eq 1 -a $setup -eq 0 ]; then
 fi
 
 if [ $visl -eq 1 -a $setup -eq 0 ]; then
-   dmesg -n notice
echo
echo loading visl module | tee /dev/kmsg
+   dmesg -n info
modprobe visl
sleep $modprobe_time
+   dmesg -n notice
echo
echo visl compliance tests | tee /dev/kmsg
echo
@@ -296,8 +298,10 @@ if [ $visl -eq 1 -a $setup -eq 0 ]; then
echo
fi
 
+   dmesg -n info
modprobe visl
sleep $modprobe_time
+   dmesg -n notice
 
$v4l2_ctl -z platform:visl --all
 
@@ -402,8 +406,10 @@ if [ $vivid -eq 1 -a $setup -eq 0 ]; then
echo
fi
 
+   dmesg -n info
modprobe vivid n_devs=3 multiplanar=1,2,2 cache_hints=1,0,0 
#allocators=0,1,1
sleep $modprobe_time
+   dmesg -n notice
 
$v4l2_ctl -z platform:vivid-002 -d vivid-002-vid-cap -i3 -v 
width=3840,height=2160,pixelformat=NV24
$v4l2_ctl -z platform:vivid-002 -d vivid-002-vid-out -o1 -x 
width=3840,height=2160,pixelformat=NM16
@@ -423,6 +429,7 @@ fi
 
 if [ $vim2m -eq 1 ]; then
rmmod vim2m 2&>/dev/null
+   dmesg -n info
modprobe vim2m
sleep $modprobe_time
dmesg -n notice
@@ -499,6 +506,7 @@ fi
 
 if [ $vimc -eq 1 ]; then
rmmod vimc 2&>/dev/null
+   dmesg -n info
modprobe vimc
sleep $modprobe_time
dmesg -n notice
@@ -603,6 +611,7 @@ if [ $vicodec -eq 1 ]; then
fi
 
rmmod vicodec 2&>/dev/null
+   dmesg -n info
modprobe vicodec
sleep $modprobe_time
dmesg -n notice
@@ -777,6 +786,7 @@ fi
 
 if [ $vidtv -eq 1 ]; then
rmmod dvb_vidtv_bridge dvb_vidtv_tuner dvb_vidtv_demod 2&>/dev/null
+   dmesg -n info
modprobe vidtv
sleep $modprobe_time
dmesg -n notice


[git:v4l-utils/master] v4l2-compliance: do not warn for unexpected vivid_ro_ctrl values

2024-05-08 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-compliance: do not warn for unexpected vivid_ro_ctrl values
Author:  Hans Verkuil 
Date:Wed May 8 08:59:46 2024 +0200

The vivid driver does not produce reliable sequence counters,
the first sequence counter may be > 0, and there are gaps in the
counters when there shouldn't be.

Until this is fixed (work in progress) replace the warning when
an unexpected vivid_ro_ctrl value is seen by an info message.

Once vivid is fixed this can be reworked.

Signed-off-by: Hans Verkuil 

 utils/v4l2-compliance/v4l2-compliance.h | 10 ++
 utils/v4l2-compliance/v4l2-test-buffers.cpp | 10 --
 2 files changed, 18 insertions(+), 2 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=7d7c5d2973f0891c5289dcd33fb8e6a84ac9c91e
diff --git a/utils/v4l2-compliance/v4l2-compliance.h 
b/utils/v4l2-compliance/v4l2-compliance.h
index b6e342f31ce3..3517bd07a452 100644
--- a/utils/v4l2-compliance/v4l2-compliance.h
+++ b/utils/v4l2-compliance/v4l2-compliance.h
@@ -226,6 +226,16 @@ private:
printf("\t\tinfo: " fmt, ##args);   \
} while (0)
 
+#define info_once(fmt, args...)\
+   do {\
+   static bool show;   \
+   \
+   if (!show) {\
+   show = true;\
+   info(fmt, ##args);  \
+   }   \
+   } while (0)
+
 #define warn(fmt, args...) \
do {\
warnings++; \
diff --git a/utils/v4l2-compliance/v4l2-test-buffers.cpp 
b/utils/v4l2-compliance/v4l2-test-buffers.cpp
index 1db6f4e9e66c..fbd68d8dbb4e 100644
--- a/utils/v4l2-compliance/v4l2-test-buffers.cpp
+++ b/utils/v4l2-compliance/v4l2-test-buffers.cpp
@@ -2690,9 +2690,12 @@ int testRequests(struct node *node, bool test_streaming)
// (sequence number & 0xff).
vivid_ro_ctrls.request_fd = buf_req_fds[i];
fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, 
_ro_ctrls));
+   // FIXME: due to unreliable sequence counters from 
vivid this
+   // test fails regularly. For now replace the 
'warn_once' by
+   // 'info_once' until vivid is fixed.
if (node->is_video && !node->can_output &&
vivid_ro_ctrl.value != (int)i)
-   warn_once("vivid_ro_ctrl.value (%d) != i 
(%u)\n",
+   info_once("vivid_ro_ctrl.value (%d) != i 
(%u)\n",
  vivid_ro_ctrl.value, i);
 
// Check that the dynamic control array is set as
@@ -2768,9 +2771,12 @@ int testRequests(struct node *node, bool test_streaming)
// For vivid check the final read-only value,
vivid_ro_ctrls.which = 0;
fail_on_test(doioctl(node, VIDIOC_G_EXT_CTRLS, 
_ro_ctrls));
+   // FIXME: due to unreliable sequence counters from 
vivid this
+   // test fails regularly. For now replace the 'warn' by 
'info'
+   // until vivid is fixed.
if (node->is_video && !node->can_output &&
vivid_ro_ctrl.value != (int)(num_bufs - 1))
-   warn("vivid_ro_ctrl.value (%d) != num_bufs - 1 
(%d)\n",
+   info("vivid_ro_ctrl.value (%d) != num_bufs - 1 
(%d)\n",
 vivid_ro_ctrl.value, num_bufs - 1);
 
// the final dynamic array value,


[git:media_stage/master] media: uvcvideo: Refactor iterators

2024-05-04 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: uvcvideo: Refactor iterators
Author:  Ricardo Ribalda 
Date:Mon Apr 29 15:04:42 2024 +

Avoid using the iterators after the list_for_each() constructs.
This patch should be a NOP, but makes cocci, happier:

drivers/media/usb/uvc/uvc_ctrl.c:1861:44-50: ERROR: invalid reference to the 
index variable of the iterator on line 1850
drivers/media/usb/uvc/uvc_ctrl.c:2195:17-23: ERROR: invalid reference to the 
index variable of the iterator on line 2179

Reviewed-by: Sergey Senozhatsky 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/usb/uvc/uvc_ctrl.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

---

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index f8ae14b8b426..4b685f883e4d 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1850,16 +1850,18 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int 
rollback,
list_for_each_entry(entity, >entities, chain) {
ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback,
 _ctrl);
-   if (ret < 0)
+   if (ret < 0) {
+   if (ctrls)
+   ctrls->error_idx =
+   uvc_ctrl_find_ctrl_idx(entity, ctrls,
+  err_ctrl);
goto done;
+   }
}
 
if (!rollback)
uvc_ctrl_send_events(handle, ctrls->controls, ctrls->count);
 done:
-   if (ret < 0 && ctrls)
-   ctrls->error_idx = uvc_ctrl_find_ctrl_idx(entity, ctrls,
- err_ctrl);
mutex_unlock(>ctrl_mutex);
return ret;
 }
@@ -2165,7 +2167,7 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
 int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
struct uvc_xu_control_query *xqry)
 {
-   struct uvc_entity *entity;
+   struct uvc_entity *entity, *iter;
struct uvc_control *ctrl;
unsigned int i;
bool found;
@@ -2175,16 +2177,16 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
int ret;
 
/* Find the extension unit. */
-   found = false;
-   list_for_each_entry(entity, >entities, chain) {
-   if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
-   entity->id == xqry->unit) {
-   found = true;
+   entity = NULL;
+   list_for_each_entry(iter, >entities, chain) {
+   if (UVC_ENTITY_TYPE(iter) == UVC_VC_EXTENSION_UNIT &&
+   iter->id == xqry->unit) {
+   entity = iter;
break;
}
}
 
-   if (!found) {
+   if (!entity) {
uvc_dbg(chain->dev, CONTROL, "Extension unit %u not found\n",
xqry->unit);
return -ENOENT;


[git:media_stage/master] media: cec.h: Fix kerneldoc

2024-05-04 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: cec.h: Fix kerneldoc
Author:  Ricardo Ribalda 
Date:Fri May 3 11:33:20 2024 +

is_claiming_log_addrs documentation was missing.

fix this kernel-doc warning:
include/media/cec.h:296: warning: Function parameter or struct member 
'is_claiming_log_addrs' not described in 'cec_adapter'

Signed-off-by: Ricardo Ribalda 
Reviewed-by: Hans Verkuil 
Signed-off-by: Hans Verkuil 

 include/media/cec.h | 1 +
 1 file changed, 1 insertion(+)

---

diff --git a/include/media/cec.h b/include/media/cec.h
index d3abe84c9c9e..d131514032f2 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -187,6 +187,7 @@ struct cec_adap_ops {
  * in order to transmit or receive CEC messages. This is usually a HW
  * limitation.
  * @is_enabled:the CEC adapter is enabled
+ * @is_claiming_log_addrs:  true if cec_claim_log_addrs() is running
  * @is_configuring:the CEC adapter is configuring (i.e. claiming LAs)
  * @must_reconfigure:  while configuring, the PA changed, so reclaim LAs
  * @is_configured: the CEC adapter is configured (i.e. has claimed LAs)


[git:media_stage/master] media: v4l: async: refactor v4l2_async_create_ancillary_links

2024-05-04 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: async: refactor v4l2_async_create_ancillary_links
Author:  Ricardo Ribalda 
Date:Mon Apr 15 19:34:26 2024 +

Return 0 without checking IS_ERR or PTR_ERR if CONFIG_MEDIA_CONTROLLER
is not enabled.

This makes cocci happier:

drivers/media/v4l2-core/v4l2-async.c:331:23-30: ERROR: PTR_ERR applied after 
initialization to constant on line 319

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-async.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-async.c 
b/drivers/media/v4l2-core/v4l2-async.c
index 3a22da443a22..222f01665f7c 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -316,9 +316,8 @@ v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier 
*notifier);
 static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
 struct v4l2_subdev *sd)
 {
-   struct media_link *link = NULL;
-
 #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
+   struct media_link *link;
 
if (sd->entity.function != MEDIA_ENT_F_LENS &&
sd->entity.function != MEDIA_ENT_F_FLASH)
@@ -326,9 +325,10 @@ static int v4l2_async_create_ancillary_links(struct 
v4l2_async_notifier *n,
 
link = media_create_ancillary_link(>sd->entity, >entity);
 
-#endif
-
return IS_ERR(link) ? PTR_ERR(link) : 0;
+#else
+   return 0;
+#endif
 }
 
 static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,


[git:v4l-utils/master] sync-with-kernel.sh: add v4l2-dv-timings.h

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: sync-with-kernel.sh: add v4l2-dv-timings.h
Author:  Hans Verkuil 
Date:Mon Apr 29 15:40:09 2024 +0200

The v4l2-dv-timings.h header was never copied from the kernel
source to the local include/linux directory. Add it.

Signed-off-by: Hans Verkuil 

 include/linux/v4l2-dv-timings.h | 970 
 sync-with-kernel.sh |   2 +
 2 files changed, 972 insertions(+)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=dd049328e5282f478ba543a50dcb14618782abbb
diff --git a/include/linux/v4l2-dv-timings.h b/include/linux/v4l2-dv-timings.h
new file mode 100644
index ..ef0128c7369c
--- /dev/null
+++ b/include/linux/v4l2-dv-timings.h
@@ -0,0 +1,970 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * V4L2 DV timings header.
+ *
+ * Copyright (C) 2012-2016  Hans Verkuil 
+ */
+
+#ifndef _V4L2_DV_TIMINGS_H
+#define _V4L2_DV_TIMINGS_H
+
+#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6))
+/* Sadly gcc versions older than 4.6 have a bug in how they initialize
+   anonymous unions where they require additional curly brackets.
+   This violates the C1x standard. This workaround adds the curly brackets
+   if needed. */
+#define V4L2_INIT_BT_TIMINGS(_width, args...) \
+   { .bt = { _width , ## args } }
+#else
+#define V4L2_INIT_BT_TIMINGS(_width, args...) \
+   .bt = { _width , ## args }
+#endif
+
+/* CEA-861-F timings (i.e. standard HDTV timings) */
+
+#define V4L2_DV_BT_CEA_640X480P59_94 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(640, 480, 0, 0, \
+   25175000, 16, 96, 48, 10, 2, 33, 0, 0, 0, \
+   V4L2_DV_BT_STD_DMT | V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_HAS_CEA861_VIC, { 0, 0 }, 1) \
+}
+
+/* Note: these are the nominal timings, for HDMI links this format is typically
+ * double-clocked to meet the minimum pixelclock requirements.  */
+#define V4L2_DV_BT_CEA_720X480I59_94 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 480, 1, 0, \
+   1350, 19, 62, 57, 4, 3, 15, 4, 3, 16, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_HALF_LINE | V4L2_DV_FL_IS_CE_VIDEO | \
+   V4L2_DV_FL_HAS_PICTURE_ASPECT | V4L2_DV_FL_HAS_CEA861_VIC, \
+   { 4, 3 }, 6) \
+}
+
+#define V4L2_DV_BT_CEA_720X480P59_94 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 480, 0, 0, \
+   2700, 16, 62, 60, 9, 6, 30, 0, 0, 0, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_IS_CE_VIDEO | V4L2_DV_FL_HAS_PICTURE_ASPECT | \
+   V4L2_DV_FL_HAS_CEA861_VIC, { 4, 3 }, 2) \
+}
+
+/* Note: these are the nominal timings, for HDMI links this format is typically
+ * double-clocked to meet the minimum pixelclock requirements.  */
+#define V4L2_DV_BT_CEA_720X576I50 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 576, 1, 0, \
+   1350, 12, 63, 69, 2, 3, 19, 2, 3, 20, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_HALF_LINE | V4L2_DV_FL_IS_CE_VIDEO | \
+   V4L2_DV_FL_HAS_PICTURE_ASPECT | V4L2_DV_FL_HAS_CEA861_VIC, \
+   { 4, 3 }, 21) \
+}
+
+#define V4L2_DV_BT_CEA_720X576P50 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(720, 576, 0, 0, \
+   2700, 12, 64, 68, 5, 5, 39, 0, 0, 0, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_IS_CE_VIDEO | V4L2_DV_FL_HAS_PICTURE_ASPECT | \
+   V4L2_DV_FL_HAS_CEA861_VIC, { 4, 3 }, 17) \
+}
+
+#define V4L2_DV_BT_CEA_1280X720P24 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(1280, 720, 0, \
+   V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \
+   5940, 1760, 40, 220, 5, 5, 20, 0, 0, 0, \
+   V4L2_DV_BT_STD_DMT | V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_HAS_CEA861_VIC, { 0, 0 
}, 60) \
+}
+
+#define V4L2_DV_BT_CEA_1280X720P25 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(1280, 720, 0, \
+   V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \
+   7425, 2420, 40, 220, 5, 5, 20, 0, 0, 0, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_IS_CE_VIDEO | V4L2_DV_FL_HAS_CEA861_VIC, { 0, 0 }, 
61) \
+}
+
+#define V4L2_DV_BT_CEA_1280X720P30 { \
+   .type = V4L2_DV_BT_656_1120, \
+   V4L2_INIT_BT_TIMINGS(1280, 720, 0, \
+   V4L2_DV_HSYNC_POS_POL | V4L2_DV_VSYNC_POS_POL, \
+   7425, 1760, 40, 220, 5, 5, 20, 0, 0, 0, \
+   V4L2_DV_BT_STD_CEA861, \
+   V4L2_DV_FL_CAN_REDUCE_FPS | V4L2_DV_FL_IS_CE_VIDEO | \
+   V4L2_DV_FL_HAS_CEA861_VIC

[git:media_stage/master] media: v4l: subdev: Copy argument back to user also for S_ROUTING

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: subdev: Copy argument back to user also for S_ROUTING
Author:  Sakari Ailus 
Date:Thu Aug 31 14:40:29 2023 +0300

As the user needs to know what went wrong for S_ROUTING, copy array
arguments back to the user.

Signed-off-by: Sakari Ailus 
Reviewed-by: Julien Massot 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-ioctl.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 5e928e2a2beb..0260acef97d2 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -3461,11 +3461,14 @@ video_usercopy(struct file *file, unsigned int 
orig_cmd, unsigned long arg,
 * FIXME: subdev IOCTLS are partially handled here and partially in
 * v4l2-subdev.c and the 'always_copy' flag can only be set for IOCTLS
 * defined here as part of the 'v4l2_ioctls' array. As
-* VIDIOC_SUBDEV_G_ROUTING needs to return results to applications even
-* in case of failure, but it is not defined here as part of the
+* VIDIOC_SUBDEV_[GS]_ROUTING needs to return results to applications
+* even in case of failure, but it is not defined here as part of the
 * 'v4l2_ioctls' array, insert an ad-hoc check to address that.
 */
-   if (err < 0 && !always_copy && cmd != VIDIOC_SUBDEV_G_ROUTING)
+   if (cmd == VIDIOC_SUBDEV_G_ROUTING || cmd == VIDIOC_SUBDEV_S_ROUTING)
+   always_copy = true;
+
+   if (err < 0 && !always_copy)
goto out;
 
if (has_array_args) {


[git:media_stage/master] media: uapi: Add generic serial metadata mbus formats

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: uapi: Add generic serial metadata mbus formats
Author:  Sakari Ailus 
Date:Tue Apr 25 16:50:25 2023 +0300

Add generic serial metadata mbus formats. These formats describe data
width and packing but not the content itself. The reason for specifying
such formats is that the formats as such are fairly device specific but
they are still handled by CSI-2 receiver drivers that should not be aware
of device specific formats. What makes generic metadata formats possible
is that these formats are parsed by software only, after capturing the
data to system memory.

Also add a definition for "Data Unit" to cover what is essentially a pixel
but is not image data.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/glossary.rst |   7 +
 .../userspace-api/media/v4l/subdev-formats.rst | 254 +
 include/uapi/linux/media-bus-format.h  |   9 +
 3 files changed, 270 insertions(+)

---

diff --git a/Documentation/userspace-api/media/glossary.rst 
b/Documentation/userspace-api/media/glossary.rst
index 5759f4c78398..55a9c37130ba 100644
--- a/Documentation/userspace-api/media/glossary.rst
+++ b/Documentation/userspace-api/media/glossary.rst
@@ -25,6 +25,13 @@ Glossary
 
See :ref:`cec`.
 
+Data Unit
+
+   Unit of data transported by a bus. On parallel buses, the data unit
+   consists of one or more related samples while on serial buses the data
+   unit is logical. If the data unit is image data, it may also be called a
+   pixel.
+
 Device Driver
Part of the Linux Kernel that implements support for a hardware
component.
diff --git a/Documentation/userspace-api/media/v4l/subdev-formats.rst 
b/Documentation/userspace-api/media/v4l/subdev-formats.rst
index eb3cd20b0cf2..c2cebf61d528 100644
--- a/Documentation/userspace-api/media/v4l/subdev-formats.rst
+++ b/Documentation/userspace-api/media/v4l/subdev-formats.rst
@@ -8306,3 +8306,257 @@ The following table lists the existing metadata formats.
both sides of the link and the bus format is a fixed
metadata format that is not configurable from userspace.
Width and height will be set to 0 for this format.
+
+Generic Serial Metadata Formats
+^^^
+
+Generic serial metadata formats are used on serial buses where the actual data
+content is more or less device specific but the data is transmitted and 
received
+by multiple devices that do not process the data in any way, simply writing
+it to system memory for processing in software at the end of the pipeline.
+
+"b" in an array cell signifies a byte of data, followed by the number of the 
bit
+and finally the bit number in subscript. "x" indicates a padding bit.
+
+.. _media-bus-format-generic-meta:
+
+.. cssclass: longtable
+
+.. flat-table:: Generic Serial Metadata Formats
+:header-rows:  2
+:stub-columns: 0
+
+* - Identifier
+  - Code
+  -
+  - :cspan:`23` Data organization within bus :term:`Data Unit`
+* -
+  -
+  - Bit
+  - 23
+  - 22
+  - 21
+  - 20
+  - 19
+  - 18
+  - 17
+  - 16
+  - 15
+  - 14
+  - 13
+  - 12
+  - 11
+  - 10
+  - 9
+  - 8
+  - 7
+  - 6
+  - 5
+  - 4
+  - 3
+  - 2
+  - 1
+  - 0
+* .. _MEDIA-BUS-FMT-META-8:
+
+  - MEDIA_BUS_FMT_META_8
+  - 0x8001
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - b0\ :sub:`7`
+  - b0\ :sub:`6`
+  - b0\ :sub:`5`
+  - b0\ :sub:`4`
+  - b0\ :sub:`3`
+  - b0\ :sub:`2`
+  - b0\ :sub:`1`
+  - b0\ :sub:`0`
+* .. _MEDIA-BUS-FMT-META-10:
+
+  - MEDIA_BUS_FMT_META_10
+  - 0x8002
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - b0\ :sub:`7`
+  - b0\ :sub:`6`
+  - b0\ :sub:`5`
+  - b0\ :sub:`4`
+  - b0\ :sub:`3`
+  - b0\ :sub:`2`
+  - b0\ :sub:`1`
+  - b0\ :sub:`0`
+  - x
+  - x
+* .. _MEDIA-BUS-FMT-META-12:
+
+  - MEDIA_BUS_FMT_META_12
+  - 0x8003
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - b0\ :sub:`7`
+  - b0\ :sub:`6`
+  - b0\ :sub:`5`
+  - b0\ :sub:`4`
+  - b0\ :sub:`3`
+  - b0\ :sub:`2`
+  - b0\ :sub:`1`
+  - b0\ :sub:`0`
+  - x
+  - x
+  - x
+  - x
+* .. _MEDIA-BUS-FMT-META-14:
+
+  - MEDIA_BUS_FMT_META_14
+  - 0x8004
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - b0\ :sub:`7`
+  - b0\ :sub:`6`
+  - b0\

[git:media_stage/master] media: v4l2-subdev: Clearly document that the crop API won't be extended

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l2-subdev: Clearly document that the crop API won't be 
extended
Author:  Laurent Pinchart 
Date:Tue Apr 2 02:37:25 2024 +0300

The V4L2 subdev crop API has been marked as obsolete, deprecated by the
selection API. Despite this, it has recently been extended with streams
support. In hindsight this was a mistake. Make sure it doesn't happen
again by clearly documenting that no new extensions will be accepted.

Suggested-by: Hans Verkuil 
Signed-off-by: Laurent Pinchart 
Acked-by: Sakari Ailus 
Reviewed-by: Tomi Valkeinen 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst | 6 +++---
 include/uapi/linux/v4l2-subdev.h   | 4 
 2 files changed, 7 insertions(+), 3 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst 
b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst
index 92d933631fda..88a748103a71 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst
@@ -37,9 +37,9 @@ Description
 
 .. note::
 
-This is an :ref:`obsolete` interface and may be removed
-in the future. It is superseded by
-:ref:`the selection API `.
+This is an :ref:`obsolete` interface and may be removed in the future. It 
is
+superseded by :ref:`the selection API `. No new
+extensions to the :c:type:`v4l2_subdev_crop` structure will be accepted.
 
 To retrieve the current crop rectangle applications set the ``pad``
 field of a struct :c:type:`v4l2_subdev_crop` to the
diff --git a/include/uapi/linux/v4l2-subdev.h b/include/uapi/linux/v4l2-subdev.h
index 7048c51581c6..81a24bd38003 100644
--- a/include/uapi/linux/v4l2-subdev.h
+++ b/include/uapi/linux/v4l2-subdev.h
@@ -50,6 +50,10 @@ struct v4l2_subdev_format {
  * @rect: pad crop rectangle boundaries
  * @stream: stream number, defined in subdev routing
  * @reserved: drivers and applications must zero this array
+ *
+ * The subdev crop API is an obsolete interface and may be removed in the
+ * future. It is superseded by the selection API. No new extensions to this
+ * structure will be accepted.
  */
 struct v4l2_subdev_crop {
__u32 which;


[git:media_stage/master] media: Documentation: Add "stream" into glossary

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: Documentation: Add "stream" into glossary
Author:  Sakari Ailus 
Date:Wed Oct 11 21:33:19 2023 +0300

Add term "stream" to the glossary of the Media subsystem documentation.

Signed-off-by: Sakari Ailus 
Reviewed-by: Tomi Valkeinen 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/glossary.rst | 5 +
 1 file changed, 5 insertions(+)

---

diff --git a/Documentation/userspace-api/media/glossary.rst 
b/Documentation/userspace-api/media/glossary.rst
index 96a360edbf3b..5759f4c78398 100644
--- a/Documentation/userspace-api/media/glossary.rst
+++ b/Documentation/userspace-api/media/glossary.rst
@@ -173,6 +173,11 @@ Glossary
An integrated circuit that integrates all components of a computer
or other electronic systems.
 
+Stream
+   A distinct flow of data (image data or metadata) from an initial source
+   to a final sink. The initial source may be e.g. an image sensor and the
+   final sink e.g. a memory buffer.
+
 V4L2 API
**V4L2 userspace API**
 


[git:media_stage/master] media: v4l: subdev: Add a function to lock two sub-device states, use it

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: subdev: Add a function to lock two sub-device states, use 
it
Author:  Sakari Ailus 
Date:Wed Sep 6 10:56:14 2023 +0300

Add two new functions, v4l2_subdev_lock_states() and
v4l2_subdev_unclock_states(), to acquire and release the state of two
sub-devices. They differ from calling v4l2_subdev_{un,}lock_state() so
that if the two states share the same lock, the lock is acquired only
once.

Also use the new functions in v4l2_subdev_link_validate().

Signed-off-by: Sakari Ailus 
Reviewed-by: Julien Massot 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-subdev.c | 12 ---
 include/media/v4l2-subdev.h   | 40 +++
 2 files changed, 44 insertions(+), 8 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 2d67ec54569a..779583447eac 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1437,17 +1437,13 @@ int v4l2_subdev_link_validate(struct media_link *link)
 
states_locked = sink_state && source_state;
 
-   if (states_locked) {
-   v4l2_subdev_lock_state(sink_state);
-   v4l2_subdev_lock_state(source_state);
-   }
+   if (states_locked)
+   v4l2_subdev_lock_states(sink_state, source_state);
 
ret = v4l2_subdev_link_validate_locked(link, states_locked);
 
-   if (states_locked) {
-   v4l2_subdev_unlock_state(sink_state);
-   v4l2_subdev_unlock_state(source_state);
-   }
+   if (states_locked)
+   v4l2_subdev_unlock_states(sink_state, source_state);
 
return ret;
 }
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 1af16b16f0bf..e22c50ce7e05 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1724,6 +1724,46 @@ static inline void v4l2_subdev_unlock_state(struct 
v4l2_subdev_state *state)
mutex_unlock(state->lock);
 }
 
+/**
+ * v4l2_subdev_lock_states - Lock two sub-device states
+ * @state1: One subdevice state
+ * @state2: The other subdevice state
+ *
+ * Locks the state of two sub-devices.
+ *
+ * The states must be unlocked with v4l2_subdev_unlock_states() after use.
+ *
+ * This differs from calling v4l2_subdev_lock_state() on both states so that if
+ * the states share the same lock, the lock is acquired only once (so no
+ * deadlock occurs). The caller is responsible for ensuring the locks will
+ * always be acquired in the same order.
+ */
+static inline void v4l2_subdev_lock_states(struct v4l2_subdev_state *state1,
+  struct v4l2_subdev_state *state2)
+{
+   mutex_lock(state1->lock);
+   if (state1->lock != state2->lock)
+   mutex_lock(state2->lock);
+}
+
+/**
+ * v4l2_subdev_unlock_states() - Unlock two sub-device states
+ * @state1: One subdevice state
+ * @state2: The other subdevice state
+ *
+ * Unlocks the state of two sub-devices.
+ *
+ * This differs from calling v4l2_subdev_unlock_state() on both states so that
+ * if the states share the same lock, the lock is released only once.
+ */
+static inline void v4l2_subdev_unlock_states(struct v4l2_subdev_state *state1,
+struct v4l2_subdev_state *state2)
+{
+   mutex_unlock(state1->lock);
+   if (state1->lock != state2->lock)
+   mutex_unlock(state2->lock);
+}
+
 /**
  * v4l2_subdev_get_unlocked_active_state() - Checks that the active subdev 
state
  *  is unlocked and returns it


[git:media_stage/master] media: Documentation: Additional streams generally don't harm capture

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: Documentation: Additional streams generally don't harm capture
Author:  Sakari Ailus 
Date:Thu Sep 21 14:51:30 2023 +0300

Having extra streams on the source end of the link that cannot be captured
by the sink sub-device generally are not an issue, at least not on CSI-2
bus. Still document that there may be hardware-specific limitations. For
example on parallel bus this might not work on all cases.

Signed-off-by: Sakari Ailus 
Reviewed-by: Tomi Valkeinen 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/v4l/dev-subdev.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/dev-subdev.rst 
b/Documentation/userspace-api/media/v4l/dev-subdev.rst
index f375b820ab68..b76e02e54512 100644
--- a/Documentation/userspace-api/media/v4l/dev-subdev.rst
+++ b/Documentation/userspace-api/media/v4l/dev-subdev.rst
@@ -529,9 +529,9 @@ the its sink pad and allows to route them individually to 
one of its source
 pads.
 
 Subdevice drivers that support multiplexed streams are compatible with
-non-multiplexed subdev drivers, but, of course, require a routing configuration
-where the link between those two types of drivers contains only a single
-stream.
+non-multiplexed subdev drivers. However, if the driver at the sink end of a 
link
+does not support streams, then only stream 0 of source end may be captured.
+There may be additional limitations specific to the sink device.
 
 Understanding streams
 ^


[git:media_stage/master] media: uapi: v4l: Add generic 8-bit metadata format definitions

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: uapi: v4l: Add generic 8-bit metadata format definitions
Author:  Sakari Ailus 
Date:Wed Apr 26 13:28:48 2023 +0300

Generic 8-bit metadata formats define the in-memory data layout but not
the format of the data itself. The reasoning for having such formats is to
allow CSI-2 receiver drivers to receive and DMA drivers to write the data
to memory without knowing a large number of device-specific formats.

These formats may be used only in conjunction with a Media Controller
pipeline where the internal pad of the source sub-device defines the
specific format of the data (using an mbus code).

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 .../userspace-api/media/v4l/dev-subdev.rst |   2 +
 .../userspace-api/media/v4l/meta-formats.rst   |   3 +-
 .../userspace-api/media/v4l/metafmt-generic.rst| 340 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |   7 +
 include/uapi/linux/videodev2.h |   8 +
 5 files changed, 359 insertions(+), 1 deletion(-)

---

diff --git a/Documentation/userspace-api/media/v4l/dev-subdev.rst 
b/Documentation/userspace-api/media/v4l/dev-subdev.rst
index 43988516acdd..f375b820ab68 100644
--- a/Documentation/userspace-api/media/v4l/dev-subdev.rst
+++ b/Documentation/userspace-api/media/v4l/dev-subdev.rst
@@ -506,6 +506,8 @@ source pads.
 
 subdev-formats
 
+.. _subdev-routing:
+
 Streams, multiplexed media pads and internal routing
 
 
diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst 
b/Documentation/userspace-api/media/v4l/meta-formats.rst
index 0bb61fc5bc00..c23aac823d2c 100644
--- a/Documentation/userspace-api/media/v4l/meta-formats.rst
+++ b/Documentation/userspace-api/media/v4l/meta-formats.rst
@@ -13,9 +13,10 @@ These formats are used for the :ref:`metadata` interface 
only.
 :maxdepth: 1
 
 metafmt-d4xx
+metafmt-generic
 metafmt-intel-ipu3
 metafmt-rkisp1
 metafmt-uvc
+metafmt-vivid
 metafmt-vsp1-hgo
 metafmt-vsp1-hgt
-metafmt-vivid
diff --git a/Documentation/userspace-api/media/v4l/metafmt-generic.rst 
b/Documentation/userspace-api/media/v4l/metafmt-generic.rst
new file mode 100644
index ..78ab56b21682
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/metafmt-generic.rst
@@ -0,0 +1,340 @@
+.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later
+
+
+V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MC1A'), 
V4L2_META_FMT_GENERIC_CSI2_12 ('MC1C'), V4L2_META_FMT_GENERIC_CSI2_14 ('MC1E'), 
V4L2_META_FMT_GENERIC_CSI2_16 ('MC1G'), V4L2_META_FMT_GENERIC_CSI2_20 ('MC1K'), 
V4L2_META_FMT_GENERIC_CSI2_24 ('MC1O')
+
+
+
+Generic line-based metadata formats
+
+
+Description
+===
+
+These generic line-based metadata formats define the memory layout of the data
+without defining the format or meaning of the metadata itself.
+
+.. _v4l2-meta-fmt-generic-8:
+
+V4L2_META_FMT_GENERIC_8
+---
+
+The V4L2_META_FMT_GENERIC_8 format is a plain 8-bit metadata format. This 
format
+is used on CSI-2 for 8 bits per :term:`Data Unit`.
+
+Additionally it is used for 16 bits per Data Unit when two bytes of metadata 
are
+packed into one 16-bit Data Unit. Otherwise the 16 bits per pixel dataformat is
+:ref:`V4L2_META_FMT_GENERIC_CSI2_16 `.
+
+**Byte Order Of V4L2_META_FMT_GENERIC_8.**
+Each cell is one byte. "M" denotes a byte of metadata.
+
+.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|
+
+.. flat-table:: Sample 4x2 Metadata Frame
+:header-rows:  0
+:stub-columns: 0
+:widths: 12 8 8 8 8
+
+* - start + 0:
+  - M\ :sub:`00`
+  - M\ :sub:`10`
+  - M\ :sub:`20`
+  - M\ :sub:`30`
+* - start + 4:
+  - M\ :sub:`01`
+  - M\ :sub:`11`
+  - M\ :sub:`21`
+  - M\ :sub:`31`
+
+.. _v4l2-meta-fmt-generic-csi2-10:
+
+V4L2_META_FMT_GENERIC_CSI2_10
+-
+
+V4L2_META_FMT_GENERIC_CSI2_10 contains 8-bit generic metadata packed in 10-bit
+Data Units, with one padding byte after every four bytes of metadata. This
+format is typically used by CSI-2 receivers with a source that transmits
+MEDIA_BUS_FMT_META_10 and the CSI-2 receiver writes the received data to memory
+as-is.
+
+T

[git:media_stage/master] media: v4l: Set line based metadata flag in V4L2 core

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: Set line based metadata flag in V4L2 core
Author:  Sakari Ailus 
Date:Tue Apr 23 10:39:47 2024 +0300

Set (and unset) the V4L2_FMT_FLAG_META_LINE_BASED flag in struct
v4l2_fmtdesc based on the format after returning the driver callback for
enumerating formats. This way the drivers don't need to care about the
flag.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-ioctl.c | 16 
 include/uapi/linux/videodev2.h   |  4 
 2 files changed, 20 insertions(+)

---

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 2cfc9106857a..5e928e2a2beb 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1538,6 +1538,22 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
}
}
 
+   if (fmt->type == V4L2_BUF_TYPE_META_CAPTURE) {
+   switch (fmt->pixelformat) {
+   case V4L2_META_FMT_GENERIC_8:
+   case V4L2_META_FMT_GENERIC_CSI2_10:
+   case V4L2_META_FMT_GENERIC_CSI2_12:
+   case V4L2_META_FMT_GENERIC_CSI2_14:
+   case V4L2_META_FMT_GENERIC_CSI2_16:
+   case V4L2_META_FMT_GENERIC_CSI2_20:
+   case V4L2_META_FMT_GENERIC_CSI2_24:
+   fmt->flags |= V4L2_FMT_FLAG_META_LINE_BASED;
+   break;
+   default:
+   fmt->flags &= ~V4L2_FMT_FLAG_META_LINE_BASED;
+   }
+   }
+
if (descr)
WARN_ON(strscpy(fmt->description, descr, sz) < 0);
fmt->flags |= flags;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 647ce3419bd8..d944db7ae1ed 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -839,6 +839,10 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 3A Parameters */
 #define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A Statistics */
 
+/*
+ * Line-based metadata formats. Remember to update v4l_fill_fmtdesc() when
+ * adding new ones!
+ */
 #define V4L2_META_FMT_GENERIC_8v4l2_fourcc('M', 'E', 'T', '8') 
/* Generic 8-bit metadata */
 #define V4L2_META_FMT_GENERIC_CSI2_10  v4l2_fourcc('M', 'C', '1', 'A') /* 
10-bit CSI-2 packed 8-bit metadata */
 #define V4L2_META_FMT_GENERIC_CSI2_12  v4l2_fourcc('M', 'C', '1', 'C') /* 
12-bit CSI-2 packed 8-bit metadata */


[git:media_stage/master] media: uapi: Document which mbus format fields are valid for metadata

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: uapi: Document which mbus format fields are valid for metadata
Author:  Sakari Ailus 
Date:Tue Aug 1 16:15:36 2023 +0300

Now that metadata mbus formats have been added, it is necessary to define
which fields in struct v4l2_mbus_format are applicable to them (not many).

Signed-off-by: Sakari Ailus 
Reviewed-by: Tomi Valkeinen 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 .../userspace-api/media/v4l/subdev-formats.rst | 15 ---
 include/uapi/linux/v4l2-mediabus.h | 18 --
 2 files changed, 20 insertions(+), 13 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/subdev-formats.rst 
b/Documentation/userspace-api/media/v4l/subdev-formats.rst
index c2cebf61d528..d2a6cd2e1eb2 100644
--- a/Documentation/userspace-api/media/v4l/subdev-formats.rst
+++ b/Documentation/userspace-api/media/v4l/subdev-formats.rst
@@ -33,7 +33,7 @@ Media Bus Formats
 * - __u32
   - ``field``
   - Field order, from enum :c:type:`v4l2_field`. See
-   :ref:`field-order` for details.
+   :ref:`field-order` for details. Zero for metadata mbus codes.
 * - __u32
   - ``colorspace``
   - Image colorspace, from enum :c:type:`v4l2_colorspace`.
@@ -45,7 +45,7 @@ Media Bus Formats
conversion is supported by setting the flag
V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE in the corresponding struct
:c:type:`v4l2_subdev_mbus_code_enum` during enumeration.
-   See :ref:`v4l2-subdev-mbus-code-flags`.
+   See :ref:`v4l2-subdev-mbus-code-flags`. Zero for metadata mbus codes.
 * - union {
   - (anonymous)
 * - __u16
@@ -61,7 +61,7 @@ Media Bus Formats
that ycbcr_enc conversion is supported by setting the flag
V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC in the corresponding struct
:c:type:`v4l2_subdev_mbus_code_enum` during enumeration.
-   See :ref:`v4l2-subdev-mbus-code-flags`.
+   See :ref:`v4l2-subdev-mbus-code-flags`. Zero for metadata mbus codes.
 * - __u16
   - ``hsv_enc``
   - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`.
@@ -75,7 +75,7 @@ Media Bus Formats
that hsv_enc conversion is supported by setting the flag
V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC in the corresponding struct
:c:type:`v4l2_subdev_mbus_code_enum` during enumeration.
-   See :ref:`v4l2-subdev-mbus-code-flags`
+   See :ref:`v4l2-subdev-mbus-code-flags`. Zero for metadata mbus codes.
 * - }
   -
 * - __u16
@@ -90,8 +90,8 @@ Media Bus Formats
The driver indicates that quantization conversion is supported by
setting the flag V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION in the
corresponding struct :c:type:`v4l2_subdev_mbus_code_enum`
-   during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`.
-
+   during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`. Zero for
+   metadata mbus codes.
 * - __u16
   - ``xfer_func``
   - Transfer function, from enum :c:type:`v4l2_xfer_func`.
@@ -104,7 +104,8 @@ Media Bus Formats
The driver indicates that the transfer function conversion is supported 
by
setting the flag V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC in the
corresponding struct :c:type:`v4l2_subdev_mbus_code_enum`
-   during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`.
+   during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`. Zero for
+   metadata mbus codes.
 * - __u16
   - ``flags``
   - flags See:  :ref:v4l2-mbus-framefmt-flags
diff --git a/include/uapi/linux/v4l2-mediabus.h 
b/include/uapi/linux/v4l2-mediabus.h
index 6b07b73473b5..946520bc49f1 100644
--- a/include/uapi/linux/v4l2-mediabus.h
+++ b/include/uapi/linux/v4l2-mediabus.h
@@ -19,12 +19,18 @@
  * @width: image width
  * @height:image height
  * @code:  data format code (from enum v4l2_mbus_pixelcode)
- * @field: used interlacing type (from enum v4l2_field)
- * @colorspace:colorspace of the data (from enum v4l2_colorspace)
- * @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding)
- * @hsv_enc:   HSV encoding of the data (from enum v4l2_hsv_encoding)
- * @quantization: quantization of the data (from enum v4l2_quantization)
- * @xfer_func:  transfer function of the data (from enum v4l2_xfer_func)
+ * @field: used interlacing type (from enum v4l2_field), zero for metadata
+ * mbus codes
+ * @colorspace:colorspace of the data (from enum v4l2_colorspace), 
zero on
+ * metadata mbus codes
+ * @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding), zero
+ * for metadata mbus codes
+ * @hsv_enc:   HSV encoding of the data (from enum v4l2_hsv_encoding), zero for
+ * metadata mbus codes
+ * @quantization: quantization of the data (from enum v4l2_quantization), zero

[git:media_stage/master] media: v4l: Support line-based metadata capture

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: Support line-based metadata capture
Author:  Sakari Ailus 
Date:Tue Feb 21 19:37:29 2023 +0200

Many camera sensors, among other devices, transmit embedded data and image
data for each CSI-2 frame. This embedded data typically contains register
configuration of the sensor that has been used to capture the image data
of the same frame.

The embedded data is received by the CSI-2 receiver and has the same
properties as the image data, including that it is line based: it has
width, height and bytesperline (stride).

Add these fields to struct v4l2_meta_format and document them.

Also add V4L2_FMT_FLAG_META_LINE_BASED to tell a given format is
line-based i.e. these fields of struct v4l2_meta_format are valid for it.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/v4l/dev-meta.rst  | 21 +
 .../userspace-api/media/v4l/vidioc-enum-fmt.rst |  7 +++
 .../userspace-api/media/videodev2.h.rst.exceptions  |  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c|  5 +++--
 include/uapi/linux/videodev2.h  | 10 ++
 5 files changed, 42 insertions(+), 2 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/dev-meta.rst 
b/Documentation/userspace-api/media/v4l/dev-meta.rst
index 0e7e1ee1471a..5eee9ab60395 100644
--- a/Documentation/userspace-api/media/v4l/dev-meta.rst
+++ b/Documentation/userspace-api/media/v4l/dev-meta.rst
@@ -47,6 +47,12 @@ member of the ``fmt`` union as needed per the desired 
operation. Both drivers
 and applications must set the remainder of the :c:type:`v4l2_format` structure
 to 0.
 
+Devices that capture metadata by line have the struct v4l2_fmtdesc
+``V4L2_FMT_FLAG_META_LINE_BASED`` flag set for :c:func:`VIDIOC_ENUM_FMT`. Such
+devices can typically also :ref:`capture image data `. This primarily
+involves devices that receive the data from a different devices such as a 
camera
+sensor.
+
 .. c:type:: v4l2_meta_format
 
 .. tabularcolumns:: |p{1.4cm}|p{2.4cm}|p{13.5cm}|
@@ -65,3 +71,18 @@ to 0.
   - ``buffersize``
   - Maximum buffer size in bytes required for data. The value is set by the
 driver.
+* - __u32
+  - ``width``
+  - Width of a line of metadata in Data Units. Valid when
+   :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is set,
+   otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`.
+* - __u32
+  - ``height``
+  - Number of rows of metadata. Valid when :c:type`v4l2_fmtdesc` flag
+   ``V4L2_FMT_FLAG_META_LINE_BASED`` is set, otherwise zero. See
+   :c:func:`VIDIOC_ENUM_FMT`.
+* - __u32
+  - ``bytesperline``
+  - Offset in bytes between the beginning of two consecutive lines. Valid
+   when :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is
+   set, otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`.
diff --git a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst 
b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
index 000c154b0f98..3adb3d205531 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst
@@ -227,6 +227,13 @@ the ``mbus_code`` field is handled differently:
The application can ask to configure the quantization of the capture
device when calling the :ref:`VIDIOC_S_FMT ` ioctl with
:ref:`V4L2_PIX_FMT_FLAG_SET_CSC ` set.
+* - ``V4L2_FMT_FLAG_META_LINE_BASED``
+  - 0x0200
+  - The metadata format is line-based. In this case the ``width``,
+   ``height`` and ``bytesperline`` fields of :c:type:`v4l2_meta_format` are
+   valid. The buffer consists of ``height`` lines, each having ``width``
+   Data Units of data and the offset (in bytes) between the beginning of
+   each two consecutive lines is ``bytesperline``.
 
 Return Value
 
diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions 
b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
index 3e58aac4ef0b..bdc628e8c1d6 100644
--- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions
@@ -215,6 +215,7 @@ replace define V4L2_FMT_FLAG_CSC_XFER_FUNC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_YCBCR_ENC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_HSV_ENC fmtdesc-flags
 replace define V4L2_FMT_FLAG_CSC_QUANTIZATION fmtdesc-flags
+replace define V4L2_FMT_FLAG_META_LINE_BASED fmtdesc-flags
 
 # V4L2 timecode types
 replace define V4L2_TC_TYPE_24FPS timecode-type
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index ae2dca7f2817..2cfc9106857a 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -343,8 +343,9 @@ static void

[git:media_stage/master] media: Documentation: Document S_ROUTING behaviour

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: Documentation: Document S_ROUTING behaviour
Author:  Sakari Ailus 
Date:Thu Sep 21 12:12:49 2023 +0300

Document S_ROUTING behaviour for different devices.

Generally in devices that produce streams the streams are static and some
can be enabled and disabled, whereas in devices that just transport them
or write them to memory, more configurability is allowed. Document this.

Signed-off-by: Sakari Ailus 
Reviewed-by: Julien Massot 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 .../userspace-api/media/v4l/dev-subdev.rst | 23 ++
 1 file changed, 23 insertions(+)

---

diff --git a/Documentation/userspace-api/media/v4l/dev-subdev.rst 
b/Documentation/userspace-api/media/v4l/dev-subdev.rst
index b76e02e54512..0f9eda3187f3 100644
--- a/Documentation/userspace-api/media/v4l/dev-subdev.rst
+++ b/Documentation/userspace-api/media/v4l/dev-subdev.rst
@@ -572,6 +572,29 @@ Any configurations of a stream within a pad, such as 
format or selections,
 are independent of similar configurations on other streams. This is
 subject to change in the future.
 
+Device types and routing setup
+^^
+
+Different kinds of sub-devices have differing behaviour for route activation,
+depending on the hardware. In all cases, however, only routes that have the
+``V4L2_SUBDEV_STREAM_FL_ACTIVE`` flag set are active.
+
+Devices generating the streams may allow enabling and disabling some of the
+routes or have a fixed routing configuration. If the routes can be disabled, 
not
+declaring the routes (or declaring them without
+``VIDIOC_SUBDEV_STREAM_FL_ACTIVE`` flag set) in ``VIDIOC_SUBDEV_S_ROUTING`` 
will
+disable the routes. ``VIDIOC_SUBDEV_S_ROUTING`` will still return such routes
+back to the user in the routes array, with the ``V4L2_SUBDEV_STREAM_FL_ACTIVE``
+flag unset.
+
+Devices transporting the streams almost always have more configurability with
+respect to routing. Typically any route between the sub-device's sink and 
source
+pads is possible, and multiple routes (usually up to certain limited number) 
may
+be active simultaneously. For such devices, no routes are created by the driver
+and user-created routes are fully replaced when ``VIDIOC_SUBDEV_S_ROUTING`` is
+called on the sub-device. Such newly created routes have the device's default
+configuration for format and selection rectangles.
+
 Configuring streams
 ^^^
 


[git:v4l-utils/master] utils: media-ctl: Support changed routing API

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: utils: media-ctl: Support changed routing API
Author:  Sakari Ailus 
Date:Wed Apr 24 18:22:25 2024 +0300

Set len_routes of struct v4l2_subdev_routing. ENOSPC error code is no
longer used, i.e. having room for fewer routes than exist in the
configuration is not considered an error anymore.

Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 utils/media-ctl/libv4l2subdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=41c51ada5c966fbf6b8c6e58282e5c2c1cf1a0bb
diff --git a/utils/media-ctl/libv4l2subdev.c b/utils/media-ctl/libv4l2subdev.c
index c614f4a2e0fd..e0df686e01c7 100644
--- a/utils/media-ctl/libv4l2subdev.c
+++ b/utils/media-ctl/libv4l2subdev.c
@@ -258,7 +258,7 @@ int v4l2_subdev_get_routing(struct media_entity *entity,
}
 
ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_ROUTING, );
-   if (ret == -1 && errno != ENOSPC)
+   if (ret == -1)
return -errno;
 
if (!routing.num_routes) {
@@ -272,6 +272,7 @@ int v4l2_subdev_get_routing(struct media_entity *entity,
return -ENOMEM;
 
routing.routes = (uintptr_t)r;
+   routing.len_routes = routing.num_routes;
ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_ROUTING, );
if (ret) {
free(r);
@@ -292,6 +293,7 @@ int v4l2_subdev_set_routing(struct media_entity *entity,
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
.routes = (uintptr_t)routes,
.num_routes = num_routes,
+   .len_routes = num_routes,
};
int ret;
 


[git:v4l-utils/master] v4l2-info: support V4L2_FMT_FLAG_META_LINE_BASED

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-info: support V4L2_FMT_FLAG_META_LINE_BASED
Author:  Hans Verkuil 
Date:Mon Apr 29 15:07:28 2024 +0200

Detect if this flag is set and report it.

Signed-off-by: Hans Verkuil 

 utils/common/v4l2-info.cpp | 1 +
 1 file changed, 1 insertion(+)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=d333ba126430b96aa3f6a0378d8d7da329149cbd
diff --git a/utils/common/v4l2-info.cpp b/utils/common/v4l2-info.cpp
index 72731bad8016..cfd242aacb12 100644
--- a/utils/common/v4l2-info.cpp
+++ b/utils/common/v4l2-info.cpp
@@ -381,6 +381,7 @@ static constexpr flag_def fmtdesc_ ## enc_type ## _def[] = 
{\
{ V4L2_FMT_FLAG_CSC_YCBCR_ENC, "csc-"#enc_type },   
\
{ V4L2_FMT_FLAG_CSC_QUANTIZATION, "csc-quantization" }, 
\
{ V4L2_FMT_FLAG_CSC_XFER_FUNC, "csc-xfer-func" },   
\
+   { V4L2_FMT_FLAG_META_LINE_BASED, "meta-line-based" },   
\
{ 0, NULL } 
\
 };
 


[git:v4l-utils/master] sync-with-kernel.sh: filter V4L2_META_FMT_GENERIC_ defines

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: sync-with-kernel.sh: filter V4L2_META_FMT_GENERIC_ defines
Author:  Hans Verkuil 
Date:Mon Apr 29 15:04:37 2024 +0200

These meta formats are not yet enabled (under #ifdef __KERNEL__),
so drop these for now.

Signed-off-by: Hans Verkuil 

 sync-with-kernel.sh | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=1cb86d3a502eb5456405eae9ecafa3b8154bc588
diff --git a/sync-with-kernel.sh b/sync-with-kernel.sh
index a11545dd8d0d..a882006d4023 100755
--- a/sync-with-kernel.sh
+++ b/sync-with-kernel.sh
@@ -53,7 +53,10 @@ patch -d ${TOPSRCDIR} --no-backup-if-mismatch -p1 
<${TOPSRCDIR}/utils/common/v4l
 cp -a ${KERNEL_DIR}/drivers/media/test-drivers/vicodec/codec-fwht.[ch] 
${TOPSRCDIR}/utils/common/
 cp -a ${KERNEL_DIR}/drivers/media/test-drivers/vicodec/codec-v4l2-fwht.[ch] 
${TOPSRCDIR}/utils/common/
 patch -d ${TOPSRCDIR} --no-backup-if-mismatch -p1 
<${TOPSRCDIR}/utils/common/codec-fwht.patch
-grep V4L2_.*_FMT.*descr ${KERNEL_DIR}/drivers/media/v4l2-core/v4l2-ioctl.c | 
perl -pe 's/.*V4L2_(.*)_FMT/\tcase V4L2_\1_FMT/; s/:.*descr = /: return /; 
s/;.*/;/;' >${TOPSRCDIR}/utils/common/v4l2-pix-formats.h
+
+# Remove the ' | grep -v V4L2_META_FMT_GENERIC_' part once these meta formats
+# are enabled in videodev2.h. Currently these are under #ifdef __KERNEL__.
+grep V4L2_.*_FMT.*descr ${KERNEL_DIR}/drivers/media/v4l2-core/v4l2-ioctl.c | 
grep -v V4L2_META_FMT_GENERIC_ | perl -pe 's/.*V4L2_(.*)_FMT/\tcase 
V4L2_\1_FMT/; s/:.*descr = /: return /; s/;.*/;/;' 
>${TOPSRCDIR}/utils/common/v4l2-pix-formats.h
 
 function keytable {
SRCDIR=${TOPSRCDIR}/utils/keytable


[git:v4l-utils/master] v4l-utils: sync-with-kernel

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l-utils: sync-with-kernel
Author:  Hans Verkuil 
Date:Mon Apr 29 15:05:39 2024 +0200

Update v4l-utils to the latest kernel headers.

Signed-off-by: Hans Verkuil 

 contrib/freebsd/include/linux/videodev2.h | 15 ++-
 contrib/test/ioctl_32.h   |  4 ++--
 contrib/test/ioctl_64.h   |  4 ++--
 include/linux/dvb/frontend.h  |  2 +-
 include/linux/media-bus-format.h  |  9 +
 include/linux/v4l2-mediabus.h | 18 --
 include/linux/v4l2-subdev.h   | 14 +++---
 include/linux/videodev2.h | 15 ++-
 lib/include/libdvbv5/dvb-frontend.h   |  2 +-
 utils/common/v4l2-pix-formats.h   |  2 ++
 utils/v4l2-tracer/retrace-gen.cpp | 14 +-
 utils/v4l2-tracer/trace-gen.cpp   |  5 -
 utils/v4l2-tracer/v4l2-tracer-info-gen.h  |  3 +++
 13 files changed, 88 insertions(+), 19 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=e0b148ecb1bb810763de47bac3ab29e3c6e20cce
diff --git a/contrib/freebsd/include/linux/videodev2.h 
b/contrib/freebsd/include/linux/videodev2.h
index 4815944b0b8c..74c2e9c234b3 100644
--- a/contrib/freebsd/include/linux/videodev2.h
+++ b/contrib/freebsd/include/linux/videodev2.h
@@ -606,6 +606,8 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
Greyscale bit-packed */
 #define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  Greyscale, 
MIPI RAW10 packed */
 #define V4L2_PIX_FMT_IPU3_Y10  v4l2_fourcc('i', 'p', '3', 'y') /* IPU3 
packed 10-bit greyscale */
+#define V4L2_PIX_FMT_Y12Pv4l2_fourcc('Y', '1', '2', 'P') /* 12  Greyscale, 
MIPI RAW12 packed */
+#define V4L2_PIX_FMT_Y14Pv4l2_fourcc('Y', '1', '4', 'P') /* 14  Greyscale, 
MIPI RAW14 packed */
 
 /* Palette formats */
 #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
palette */
@@ -846,6 +848,7 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 3A Parameters */
 #define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A Statistics */
 
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
@@ -876,6 +879,7 @@ struct v4l2_fmtdesc {
 #define V4L2_FMT_FLAG_CSC_YCBCR_ENC0x0080
 #define V4L2_FMT_FLAG_CSC_HSV_ENC  V4L2_FMT_FLAG_CSC_YCBCR_ENC
 #define V4L2_FMT_FLAG_CSC_QUANTIZATION 0x0100
+#define V4L2_FMT_FLAG_META_LINE_BASED  0x0200
 
/* Frame Size and frame rate enumeration */
 /*
@@ -1824,7 +1828,7 @@ struct v4l2_ext_control {
struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll_info;
struct v4l2_ctrl_hdr10_mastering_display 
*p_hdr10_mastering_display;
void *ptr;
-   };
+   } __attribute__ ((packed));
 } __attribute__ ((packed));
 
 struct v4l2_ext_controls {
@@ -2394,10 +2398,19 @@ struct v4l2_sdr_format {
  * struct v4l2_meta_format - metadata format definition
  * @dataformat:little endian four character code (fourcc)
  * @buffersize:maximum size in bytes required for data
+ * @width: number of data units of data per line (valid for line
+ * based formats only, see format documentation)
+ * @height:number of lines of data per buffer (valid for line based
+ * formats only)
+ * @bytesperline:  offset between the beginnings of two adjacent lines in
+ * bytes (valid for line based formats only)
  */
 struct v4l2_meta_format {
uint32_tdataformat;
uint32_tbuffersize;
+   uint32_twidth;
+   uint32_theight;
+   uint32_tbytesperline;
 } __attribute__ ((packed));
 
 /**
diff --git a/contrib/test/ioctl_32.h b/contrib/test/ioctl_32.h
index 97f58676fce1..42997b76cf8d 100644
--- a/contrib/test/ioctl_32.h
+++ b/contrib/test/ioctl_32.h
@@ -103,7 +103,7 @@
 #define CMD32_VIDIOC_SUBDEV_G_EDID 0xc0245628
 #define CMD32_VIDIOC_SUBDEV_G_FMT 0xc0585604
 #define CMD32_VIDIOC_SUBDEV_G_FRAME_INTERVAL 0xc0305615
-#define CMD32_VIDIOC_SUBDEV_G_ROUTING 0xc0285626
+#define CMD32_VIDIOC_SUBDEV_G_ROUTING 0xc0405626
 #define CMD32_VIDIOC_SUBDEV_G_SELECTION 0xc040563d
 #define CMD32_VIDIOC_SUBDEV_G_STD 0x80085617
 #define CMD32_VIDIOC_SUBDEV_QUERYCAP 0x80405600
@@ -115,7 +115,7 @@
 #define CMD32_VIDIOC_SUBDEV_S_EDID 0xc0245629
 #define CMD32_VIDIOC_SUBDEV_S_FMT 0xc0585605
 #define CMD32_VIDIOC_SUBDEV_S_FRAME_INTERVAL 0xc0305616
-#define

[git:v4l-utils/master] v4l2-compliance: Add tests for V4L2_FMT_FLAG_META_LINE_BASED flag

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-compliance: Add tests for V4L2_FMT_FLAG_META_LINE_BASED flag
Author:  Laurent Pinchart 
Date:Wed Apr 24 18:22:27 2024 +0300

The metadata API supports a new flag, V4L2_FMT_FLAG_META_LINE_BASED. It
can be set for metadata formats only, and is the only flag that can be
set for metadata formats. When set, the width, height and bytesperline
fields must not be zero. Add corresponding tests.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 utils/v4l2-compliance/v4l2-test-formats.cpp | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=de8f9eeab55ff7e6b181f468a40282028aad89dd
diff --git a/utils/v4l2-compliance/v4l2-test-formats.cpp 
b/utils/v4l2-compliance/v4l2-test-formats.cpp
index 423567fe573b..5507e45ef3dd 100644
--- a/utils/v4l2-compliance/v4l2-test-formats.cpp
+++ b/utils/v4l2-compliance/v4l2-test-formats.cpp
@@ -281,12 +281,23 @@ static int testEnumFormatsType(struct node *node, 
unsigned type)
  V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL |
  V4L2_FMT_FLAG_CSC_COLORSPACE |
  V4L2_FMT_FLAG_CSC_YCBCR_ENC | 
V4L2_FMT_FLAG_CSC_HSV_ENC |
- V4L2_FMT_FLAG_CSC_QUANTIZATION | 
V4L2_FMT_FLAG_CSC_XFER_FUNC))
+ V4L2_FMT_FLAG_CSC_QUANTIZATION | 
V4L2_FMT_FLAG_CSC_XFER_FUNC |
+ V4L2_FMT_FLAG_META_LINE_BASED))
return fail("unknown flag %08x returned\n", 
fmtdesc.flags);
if (!(fmtdesc.flags & V4L2_FMT_FLAG_COMPRESSED))
fail_on_test(fmtdesc.flags & 
(V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM |
  
V4L2_FMT_FLAG_DYN_RESOLUTION |
  
V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL));
+
+   // Checks for metadata formats.
+   // The META_LINE_BASED flag can be set for metadata formats 
only.
+   if (type == V4L2_BUF_TYPE_META_OUTPUT || type == 
V4L2_BUF_TYPE_META_CAPTURE)
+   fail_on_test(fmtdesc.flags & 
~V4L2_FMT_FLAG_META_LINE_BASED);
+   // Only the META_LINE_BASED flag is valid for metadata formats.
+   if (fmtdesc.flags & V4L2_FMT_FLAG_META_LINE_BASED)
+   fail_on_test(type != V4L2_BUF_TYPE_META_OUTPUT &&
+type != V4L2_BUF_TYPE_META_CAPTURE);
+
ret = testEnumFrameSizes(node, fmtdesc.pixelformat);
if (ret)
fail_on_test(node->codec_mask & STATEFUL_ENCODER);
@@ -590,6 +601,10 @@ static int testFormatsType(struct node *node, int ret,  
unsigned type, struct v4
return fail("dataformat %08x (%s) for buftype %d not 
reported by ENUM_FMT\n",
meta.dataformat, 
fcc2s(meta.dataformat).c_str(), type);
fail_on_test(meta.buffersize == 0);
+   if (map.at(meta.dataformat) & V4L2_FMT_FLAG_META_LINE_BASED) {
+   fail_on_test(!meta.width || !meta.height);
+   fail_on_test(!meta.bytesperline);
+   }
break;
case V4L2_BUF_TYPE_PRIVATE:
break;


[git:v4l-utils/master] v4l2-compliance: Support the changed routing API

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-compliance: Support the changed routing API
Author:  Laurent Pinchart 
Date:Wed Apr 24 18:22:26 2024 +0300

Set len_routes of struct v4l2_subdev_routing. ENOSPC error code is no
longer used, i.e. having room for fewer routes than exist in the
configuration is not considered an error anymore.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 utils/v4l2-compliance/v4l2-compliance.cpp   | 12 +++-
 utils/v4l2-compliance/v4l2-test-subdevs.cpp | 19 +++
 2 files changed, 18 insertions(+), 13 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=4b9446901cfd38247f936866994d39efde0f7c82
diff --git a/utils/v4l2-compliance/v4l2-compliance.cpp 
b/utils/v4l2-compliance/v4l2-compliance.cpp
index fd7e7d76e214..144f961842c6 100644
--- a/utils/v4l2-compliance/v4l2-compliance.cpp
+++ b/utils/v4l2-compliance/v4l2-compliance.cpp
@@ -1272,15 +1272,17 @@ void testNode(struct node , struct node 
_m2m_cap, struct node _
 
for (unsigned which = V4L2_SUBDEV_FORMAT_TRY;
which <= V4L2_SUBDEV_FORMAT_ACTIVE; which++) {
+   struct v4l2_subdev_routing  = 
sd_routing[which];
 
-   sd_routing[which].which = which;
-   sd_routing[which].routes = 
(uintptr_t)sd_routes[which];
-   sd_routing[which].num_routes = NUM_ROUTES_MAX;
+   routing.which = which;
+   routing.routes = (uintptr_t)sd_routes[which];
+   routing.len_routes = NUM_ROUTES_MAX;
+   routing.num_routes = 0;
 
-   ret = doioctl(, VIDIOC_SUBDEV_G_ROUTING, 
_routing[which]);
+   ret = doioctl(, VIDIOC_SUBDEV_G_ROUTING, 
);
if (ret) {
fail("VIDIOC_SUBDEV_G_ROUTING: failed 
to get routing\n");
-   sd_routing[which].num_routes = 0;
+   routing.num_routes = 0;
}
}
}
diff --git a/utils/v4l2-compliance/v4l2-test-subdevs.cpp 
b/utils/v4l2-compliance/v4l2-test-subdevs.cpp
index da304a8caa8a..41eaf77112f0 100644
--- a/utils/v4l2-compliance/v4l2-test-subdevs.cpp
+++ b/utils/v4l2-compliance/v4l2-test-subdevs.cpp
@@ -587,17 +587,15 @@ int testSubDevRouting(struct node *node, unsigned which)
 
routing.which = which;
routing.routes = (uintptr_t)
+   routing.len_routes = 0;
routing.num_routes = 0;
memset(routing.reserved, 0xff, sizeof(routing.reserved));
 
-   /*
-* First test that G_ROUTING either returns success, or ENOSPC and
-* updates num_routes.
-*/
+   /* First test that G_ROUTING returns success even when len_routes is 0. 
*/
 
ret = doioctl(node, VIDIOC_SUBDEV_G_ROUTING, );
-   fail_on_test(ret && ret != ENOSPC);
-   fail_on_test(ret == ENOSPC && routing.num_routes == 0);
+   fail_on_test(ret);
+   fail_on_test(routing.num_routes > NUM_ROUTES_MAX);
fail_on_test(check_0(routing.reserved, sizeof(routing.reserved)));
 
if (!routing.num_routes)
@@ -609,7 +607,8 @@ int testSubDevRouting(struct node *node, unsigned which)
 */
 
uint32_t num_routes = routing.num_routes;
-   routing.num_routes = num_routes + 1;
+   routing.len_routes = NUM_ROUTES_MAX;
+   routing.num_routes = 0;
fail_on_test(doioctl(node, VIDIOC_SUBDEV_G_ROUTING, ));
fail_on_test(routing.num_routes != num_routes);
 
@@ -633,10 +632,14 @@ int testSubDevRouting(struct node *node, unsigned which)
}
}
 
-   /* Set the same routes back, which should always succeed. */
+   /*
+* Set the same routes back, which should always succeed and report the
+* same number of routes.
+*/
 
memset(routing.reserved, 0xff, sizeof(routing.reserved));
fail_on_test(doioctl(node, VIDIOC_SUBDEV_S_ROUTING, ));
+   fail_on_test(routing.num_routes != num_routes);
fail_on_test(check_0(routing.reserved, sizeof(routing.reserved)));
 
/* Test setting invalid pads */


[git:media_stage/master] media: v4l: subdev: Add trivial set_routing support

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: subdev: Add trivial set_routing support
Author:  Sakari Ailus 
Date:Thu Aug 31 15:40:07 2023 +0300

Add trivial S_ROUTING IOCTL support for drivers where routing is static.
Essentially this means returning the same information G_ROUTING call would
have done.

Signed-off-by: Sakari Ailus 
Co-developed-by: Laurent Pinchart 
Signed-off-by: Laurent Pinchart 
Reviewed-by: Julien Massot 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-subdev.c | 14 ++
 1 file changed, 14 insertions(+)

---

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 3d1ed8ab5229..8470d6eda9a3 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1013,6 +1013,20 @@ static long subdev_do_ioctl(struct file *file, unsigned 
int cmd, void *arg,
return -EINVAL;
}
 
+   /*
+* If the driver doesn't support setting routing, just return
+* the routing table.
+*/
+   if (!v4l2_subdev_has_op(sd, pad, set_routing)) {
+   memcpy((struct v4l2_subdev_route 
*)(uintptr_t)routing->routes,
+  state->routing.routes,
+  min(state->routing.num_routes, 
routing->len_routes) *
+  sizeof(*state->routing.routes));
+   routing->num_routes = state->routing.num_routes;
+
+   return 0;
+   }
+
krouting.num_routes = routing->num_routes;
krouting.len_routes = routing->len_routes;
krouting.routes = routes;


[git:media_stage/master] media: v4l: Add V4L2-PIX-FMT-Y12P format

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: Add V4L2-PIX-FMT-Y12P format
Author:  Jean-Michel Hautbois 
Date:Wed Apr 24 18:35:37 2024 +0300

This is a packed grey-scale image format with a depth of 12 bits per
pixel. Two consecutive pixels are packed into 3 bytes. The first 2 bytes
contain the 8 high order bits of the pixels, and the 3rd byte contains
the 4 least significants bits of each pixel, in the same order.

Add the entry in userspace API, and document it.

Signed-off-by: Jean-Michel Hautbois 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst | 11 +++
 drivers/media/v4l2-core/v4l2-ioctl.c  |  1 +
 include/uapi/linux/videodev2.h|  1 +
 3 files changed, 13 insertions(+)

---

diff --git a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst 
b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
index cf8e4dfbfbd4..a650ceda7cdb 100644
--- a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
+++ b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
@@ -114,6 +114,17 @@ are often referred to as greyscale formats.
   - ...
   - ...
 
+* .. _V4L2-PIX-FMT-Y12P:
+
+  - ``V4L2_PIX_FMT_Y12P``
+  - 'Y12P'
+
+  - Y'\ :sub:`0`\ [11:4]
+  - Y'\ :sub:`1`\ [11:4]
+  - Y'\ :sub:`1`\ [3:0] Y'\ :sub:`0`\ [3:0]
+  - ...
+  - ...
+
 * .. _V4L2-PIX-FMT-Y14:
 
   - ``V4L2_PIX_FMT_Y14``
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index aab671fae45b..94fe2a1d13cd 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1321,6 +1321,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; 
break;
case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 
Packed)"; break;
+   case V4L2_PIX_FMT_Y12P: descr = "12-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index d944db7ae1ed..760fb8ed7f69 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -599,6 +599,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
Greyscale bit-packed */
 #define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  Greyscale, 
MIPI RAW10 packed */
 #define V4L2_PIX_FMT_IPU3_Y10  v4l2_fourcc('i', 'p', '3', 'y') /* IPU3 
packed 10-bit greyscale */
+#define V4L2_PIX_FMT_Y12Pv4l2_fourcc('Y', '1', '2', 'P') /* 12  Greyscale, 
MIPI RAW12 packed */
 
 /* Palette formats */
 #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
palette */


[git:media_stage/master] media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
Author:  Sakari Ailus 
Date:Thu Aug 31 14:56:28 2023 +0300

The len_routes field is used to tell the size of the routes array in
struct v4l2_subdev_routing. This way the number of routes returned from
S_ROUTING IOCTL may be larger than the number of routes provided, in case
there are more routes returned by the driver.

Note that this uAPI is still disabled in the code, so this change can
safely be done. Anyone who manually patched the code to enable this uAPI
must update their code.

The patch also increases the number of reserved fields in struct
v4l2_subdev_routing.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 .../media/v4l/vidioc-subdev-g-routing.rst  | 46 +++---
 drivers/media/v4l2-core/v4l2-ioctl.c   |  4 +-
 drivers/media/v4l2-core/v4l2-subdev.c  | 12 +++---
 include/media/v4l2-subdev.h|  2 +
 include/uapi/linux/v4l2-subdev.h   | 10 +++--
 5 files changed, 49 insertions(+), 25 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst 
b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
index 26b5004bfe6d..cbd9370006b6 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
@@ -43,23 +43,38 @@ The routing configuration determines the flows of data 
inside an entity.
 Drivers report their current routing tables using the
 ``VIDIOC_SUBDEV_G_ROUTING`` ioctl and application may enable or disable routes
 with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and
-setting or clearing flags of the  ``flags`` field of a
-struct :c:type:`v4l2_subdev_route`.
+setting or clearing flags of the ``flags`` field of a struct
+:c:type:`v4l2_subdev_route`.
 
-All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is 
called. This
-means that the userspace must reconfigure all streams after calling the ioctl
-with e.g. ``VIDIOC_SUBDEV_S_FMT``.
+All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called.
+This means that the userspace must reconfigure all stream formats and 
selections
+after calling the ioctl with e.g. ``VIDIOC_SUBDEV_S_FMT``.
 
 Only subdevices which have both sink and source pads can support routing.
 
-When inspecting routes through ``VIDIOC_SUBDEV_G_ROUTING`` and the application
-provided ``num_routes`` is not big enough to contain all the available routes
-the subdevice exposes, drivers return the ENOSPC error code and adjust the
-value of the ``num_routes`` field. Application should then reserve enough 
memory
-for all the route entries and call ``VIDIOC_SUBDEV_G_ROUTING`` again.
-
-On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the
-``num_routes`` field to reflect the actual number of routes returned.
+The ``len_routes`` field indicates the number of routes that can fit in the
+``routes`` array allocated by userspace. It is set by applications for both
+ioctls to indicate how many routes the kernel can return, and is never modified
+by the kernel.
+
+The ``num_routes`` field indicates the number of routes in the routing
+table. For ``VIDIOC_SUBDEV_S_ROUTING``, it is set by userspace to the number of
+routes that the application stored in the ``routes`` array. For both ioctls, it
+is returned by the kernel and indicates how many routes are stored in the
+subdevice routing table. This may be smaller or larger than the value of
+``num_routes`` set by the application for ``VIDIOC_SUBDEV_S_ROUTING``, as
+drivers may adjust the requested routing table.
+
+The kernel can return a ``num_routes`` value larger than ``len_routes`` from
+both ioctls. This indicates thare are more routes in the routing table than 
fits
+the ``routes`` array. In this case, the ``routes`` array is filled by the 
kernel
+with the first ``len_routes`` entries of the subdevice routing table. This is
+not considered to be an error, and the ioctl call succeeds. If the applications
+wants to retrieve the missing routes, it can issue a new
+``VIDIOC_SUBDEV_G_ROUTING`` call with a large enough ``routes`` array.
+
+``VIDIOC_SUBDEV_S_ROUTING`` may return more routes than the user provided in
+``num_routes`` field due to e.g. hardware properties.
 
 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
 
@@ -74,6 +89,9 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver 
updates the
   - ``which``
   - Routing table to be accessed, from enum
 :ref:`v4l2_subdev_format_whence `.
+* - __u32
+  - ``len_routes``
+  - The length of the array (as in memory reserved for the array)
 * - struct :c:type:`v4l2_subdev_route`
   - ``routes[]``
   - Array of struct :c:type

[git:media_stage/master] media: v4l: Add V4L2-PIX-FMT-Y14P format

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: Add V4L2-PIX-FMT-Y14P format
Author:  Jean-Michel Hautbois 
Date:Wed Apr 24 18:35:38 2024 +0300

This is a packed grey-scale image format with a depth of 14 bits per
pixel. Every four consecutive samples are packed into seven bytes. Each
of the first four bytes contain the eight high order bits of the pixels,
and the three following bytes contains the six least significants bits
of each pixel, in the same order.

As the other formats only needed 5 bytes before, append two bytes in the
documentation array.

Signed-off-by: Jean-Michel Hautbois 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 .../userspace-api/media/v4l/pixfmt-yuv-luma.rst| 37 ++
 drivers/media/v4l2-core/v4l2-ioctl.c   |  1 +
 include/uapi/linux/videodev2.h |  1 +
 3 files changed, 39 insertions(+)

---

diff --git a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst 
b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
index a650ceda7cdb..b3c5779521d8 100644
--- a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
+++ b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst
@@ -36,6 +36,8 @@ are often referred to as greyscale formats.
   - Byte 2
   - Byte 3
   - Byte 4
+  - Byte 5
+  - Byte 6
 
 * .. _V4L2-PIX-FMT-GREY:
 
@@ -47,6 +49,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-IPU3-Y10:
 
@@ -58,6 +62,8 @@ are often referred to as greyscale formats.
   - Y'\ :sub:`2`\ [3:0] Y'\ :sub:`1`\ [9:6]
   - Y'\ :sub:`3`\ [1:0] Y'\ :sub:`2`\ [9:4]
   - Y'\ :sub:`3`\ [9:2]
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y10:
 
@@ -69,6 +75,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y10BPACK:
 
@@ -80,6 +88,8 @@ are often referred to as greyscale formats.
   - Y'\ :sub:`1`\ [3:0] Y'\ :sub:`2`\ [9:6]
   - Y'\ :sub:`2`\ [5:0] Y'\ :sub:`3`\ [9:8]
   - Y'\ :sub:`3`\ [7:0]
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y10P:
 
@@ -91,6 +101,8 @@ are often referred to as greyscale formats.
   - Y'\ :sub:`2`\ [9:2]
   - Y'\ :sub:`3`\ [9:2]
   - Y'\ :sub:`3`\ [1:0] Y'\ :sub:`2`\ [1:0] Y'\ :sub:`1`\ [1:0] Y'\ 
:sub:`0`\ [1:0]
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y12:
 
@@ -102,6 +114,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y012:
 
@@ -113,6 +127,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y12P:
 
@@ -124,6 +140,8 @@ are often referred to as greyscale formats.
   - Y'\ :sub:`1`\ [3:0] Y'\ :sub:`0`\ [3:0]
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y14:
 
@@ -135,6 +153,21 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
+
+* .. _V4L2-PIX-FMT-Y14P:
+
+  - ``V4L2_PIX_FMT_Y14P``
+  - 'Y14P'
+
+  - Y'\ :sub:`0`\ [13:6]
+  - Y'\ :sub:`1`\ [13:6]
+  - Y'\ :sub:`2`\ [13:6]
+  - Y'\ :sub:`3`\ [13:6]
+  - Y'\ :sub:`1`\ [1:0] Y'\ :sub:`0`\ [5:0]
+  - Y'\ :sub:`2`\ [3:0] Y'\ :sub:`1`\ [5:2]
+  - Y'\ :sub:`3`\ [5:0] Y'\ :sub:`2`\ [5:4]
 
 * .. _V4L2-PIX-FMT-Y16:
 
@@ -146,6 +179,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 * .. _V4L2-PIX-FMT-Y16-BE:
 
@@ -157,6 +192,8 @@ are often referred to as greyscale formats.
   - ...
   - ...
   - ...
+  - ...
+  - ...
 
 .. raw:: latex
 
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 94fe2a1d13cd..4c76d17b4629 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1322,6 +1322,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 
Packed)"; break;
case V4L2_PIX_FMT_Y12P: descr = "12-bit Greyscale (MIPI 
Packed)"; break;
+   case V4L2_PIX_FMT_Y14P: descr = "14-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videod

[git:media_stage/master] media: v4l: subdev: Return routes set using S_ROUTING

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: subdev: Return routes set using S_ROUTING
Author:  Sakari Ailus 
Date:Wed Sep 6 13:51:04 2023 +0300

Return the routes set using S_ROUTING back to the user. Also reflect this
in documentation.

Signed-off-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst  |  7 ++-
 drivers/media/v4l2-core/v4l2-subdev.c| 12 +++-
 2 files changed, 13 insertions(+), 6 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst 
b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
index cbd9370006b6..1cf795480602 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst
@@ -44,7 +44,8 @@ Drivers report their current routing tables using the
 ``VIDIOC_SUBDEV_G_ROUTING`` ioctl and application may enable or disable routes
 with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and
 setting or clearing flags of the ``flags`` field of a struct
-:c:type:`v4l2_subdev_route`.
+:c:type:`v4l2_subdev_route`. Similarly to ``VIDIOC_SUBDEV_G_ROUTING``, also
+``VIDIOC_SUBDEV_S_ROUTING`` returns the routes back to the user.
 
 All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called.
 This means that the userspace must reconfigure all stream formats and 
selections
@@ -153,10 +154,6 @@ On success 0 is returned, on error -1 and the ``errno`` 
variable is set
 appropriately. The generic error codes are described at the
 :ref:`Generic Error Codes ` chapter.
 
-ENOSPC
-   The application provided ``num_routes`` is not big enough to contain
-   all the available routes the subdevice exposes.
-
 EINVAL
The sink or source pad identifiers reference a non-existing pad or reference
pads of different types (ie. the sink_pad identifiers refers to a source
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index b565f202df67..3d1ed8ab5229 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1017,8 +1017,18 @@ static long subdev_do_ioctl(struct file *file, unsigned 
int cmd, void *arg,
krouting.len_routes = routing->len_routes;
krouting.routes = routes;
 
-   return v4l2_subdev_call(sd, pad, set_routing, state,
+   rval = v4l2_subdev_call(sd, pad, set_routing, state,
routing->which, );
+   if (rval < 0)
+   return rval;
+
+   memcpy((struct v4l2_subdev_route *)(uintptr_t)routing->routes,
+  state->routing.routes,
+  min(state->routing.num_routes, routing->len_routes) *
+  sizeof(*state->routing.routes));
+   routing->num_routes = state->routing.num_routes;
+
+   return 0;
}
 
case VIDIOC_SUBDEV_G_CLIENT_CAP: {


[git:media_stage/master] dt-bindings: media: Add bindings for bcm2835-unicam

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: dt-bindings: media: Add bindings for bcm2835-unicam
Author:  Dave Stevenson 
Date:Wed Apr 24 18:35:39 2024 +0300

Introduce the dt-bindings documentation for bcm2835 CCP2/CSI2 Unicam
camera interface.

Signed-off-by: Dave Stevenson 
Co-developed-by: Naushir Patuck 
Signed-off-by: Naushir Patuck 
Co-developed-by: Jean-Michel Hautbois 
Signed-off-by: Jean-Michel Hautbois 
Reviewed-by: Laurent Pinchart 
Reviewed-by: Rob Herring 
Signed-off-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 .../bindings/media/brcm,bcm2835-unicam.yaml| 127 +
 MAINTAINERS|   6 +
 2 files changed, 133 insertions(+)

---

diff --git a/Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml 
b/Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml
new file mode 100644
index ..5fb5d60f069a
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/brcm,bcm2835-unicam.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Broadcom BCM283x Camera Interface (Unicam)
+
+maintainers:
+  - Raspberry Pi Kernel Maintenance 
+
+description: |-
+  The Unicam block on BCM283x SoCs is the receiver for either
+  CSI-2 or CCP2 data from image sensors or similar devices.
+
+  The main platform using this SoC is the Raspberry Pi family of boards.  On
+  the Pi the VideoCore firmware can also control this hardware block, and
+  driving it from two different processors will cause issues.  To avoid this,
+  the firmware checks the device tree configuration during boot. If it finds
+  device tree nodes whose name starts with 'csi' then it will stop the firmware
+  accessing the block, and it can then safely be used via the device tree
+  binding.
+
+properties:
+  compatible:
+const: brcm,bcm2835-unicam
+
+  reg:
+items:
+  - description: Unicam block.
+  - description: Clock Manager Image (CMI) block.
+
+  reg-names:
+items:
+  - const: unicam
+  - const: cmi
+
+  interrupts:
+maxItems: 1
+
+  clocks:
+items:
+  - description: Clock to drive the LP state machine of Unicam.
+  - description: Clock for the VPU (core clock).
+
+  clock-names:
+items:
+  - const: lp
+  - const: vpu
+
+  power-domains:
+items:
+  - description: Unicam power domain
+
+  brcm,num-data-lanes:
+$ref: /schemas/types.yaml#/definitions/uint32
+enum: [ 2, 4 ]
+description: |
+  Number of CSI-2 data lanes supported by this Unicam instance. The number
+  of data lanes actively used is specified with the data-lanes endpoint
+  property.
+
+  port:
+$ref: /schemas/graph.yaml#/$defs/port-base
+unevaluatedProperties: false
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+additionalProperties: false
+
+properties:
+  bus-type:
+enum: [ 3, 4 ]
+
+  clock-noncontinuous: true
+  data-lanes: true
+  remote-endpoint: true
+
+required:
+  - bus-type
+  - data-lanes
+  - remote-endpoint
+
+required:
+  - endpoint
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - brcm,num-data-lanes
+  - port
+
+additionalProperties: False
+
+examples:
+  - |
+#include 
+#include 
+#include 
+#include 
+
+csi1: csi@7e801000 {
+compatible = "brcm,bcm2835-unicam";
+reg = <0x7e801000 0x800>,
+  <0x7e802004 0x4>;
+reg-names = "unicam", "cmi";
+interrupts = ;
+clocks = < BCM2835_CLOCK_CAM1>,
+ <_clocks 4>;
+clock-names = "lp", "vpu";
+power-domains = < RPI_POWER_DOMAIN_UNICAM1>;
+brcm,num-data-lanes = <2>;
+port {
+csi1_ep: endpoint {
+remote-endpoint = <_0>;
+bus-type = ;
+data-lanes = <1 2>;
+};
+};
+};
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 7c121493f43d..91420f602eb9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4034,6 +4034,12 @@ N:   bcm113*
 N: bcm216*
 N: kona
 
+BROADCOM BCM2835 CAMERA DRIVERS
+M: Raspberry Pi Kernel Maintenance 
+L: linux-me...@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml
+
 BROADCOM BCM47XX MIPS ARCHITECTURE
 M: Hauke Mehrtens 
 M: Rafał Miłecki 


[git:media_stage/master] media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: bcm2835-unicam: Add support for CCP2/CSI2 camera interface
Author:  Dave Stevenson 
Date:Wed Apr 24 18:35:40 2024 +0300

Add a driver for the Unicam camera receiver block on BCM283x processors.
It is represented as two video device nodes: unicam-image and
unicam-embedded which are connected to an internal subdev (named
unicam-subdev) in order to manage streams routing.

Signed-off-by: Dave Stevenson 
Co-developed-by: Naushir Patuck 
Signed-off-by: Naushir Patuck 
Co-developed-by: Jean-Michel Hautbois 
Signed-off-by: Jean-Michel Hautbois 
Co-developed-by: Laurent Pinchart 
Signed-off-by: Laurent Pinchart 
[Sakari Ailus: Squash fixes by Laurent.]
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 MAINTAINERS|1 +
 drivers/media/platform/Kconfig |1 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/broadcom/Kconfig|   23 +
 drivers/media/platform/broadcom/Makefile   |3 +
 .../media/platform/broadcom/bcm2835-unicam-regs.h  |  246 ++
 drivers/media/platform/broadcom/bcm2835-unicam.c   | 2744 
 7 files changed, 3019 insertions(+)

---

diff --git a/MAINTAINERS b/MAINTAINERS
index 91420f602eb9..037d065fb8bb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4039,6 +4039,7 @@ M:Raspberry Pi Kernel Maintenance 

 L: linux-me...@vger.kernel.org
 S: Maintained
 F: Documentation/devicetree/bindings/media/brcm,bcm2835-unicam.yaml
+F: drivers/media/platform/bcm2835/
 
 BROADCOM BCM47XX MIPS ARCHITECTURE
 M: Hauke Mehrtens 
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 91e54215de3a..2d79bfc68c15 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -67,6 +67,7 @@ source "drivers/media/platform/amlogic/Kconfig"
 source "drivers/media/platform/amphion/Kconfig"
 source "drivers/media/platform/aspeed/Kconfig"
 source "drivers/media/platform/atmel/Kconfig"
+source "drivers/media/platform/broadcom/Kconfig"
 source "drivers/media/platform/cadence/Kconfig"
 source "drivers/media/platform/chips-media/Kconfig"
 source "drivers/media/platform/intel/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 3296ec1ebe16..da17301f7439 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -10,6 +10,7 @@ obj-y += amlogic/
 obj-y += amphion/
 obj-y += aspeed/
 obj-y += atmel/
+obj-y += broadcom/
 obj-y += cadence/
 obj-y += chips-media/
 obj-y += intel/
diff --git a/drivers/media/platform/broadcom/Kconfig 
b/drivers/media/platform/broadcom/Kconfig
new file mode 100644
index ..cc2c9afcc948
--- /dev/null
+++ b/drivers/media/platform/broadcom/Kconfig
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config VIDEO_BCM2835_UNICAM
+   tristate "Broadcom BCM283x/BCM271x Unicam video capture driver"
+   depends on ARCH_BCM2835 || COMPILE_TEST
+   depends on PM
+   depends on VIDEO_DEV
+   select MEDIA_CONTROLLER
+   select V4L2_FWNODE
+   select VIDEO_V4L2_SUBDEV_API
+   select VIDEOBUF2_DMA_CONTIG
+   help
+ Say Y here to enable support for the BCM283x/BCM271x CSI-2 receiver.
+ This is a V4L2 driver that controls the CSI-2 receiver directly,
+ independently from the VC4 firmware.
+
+ This driver is mutually exclusive with the use of bcm2835-camera. The
+ firmware will disable all access to the peripheral from within the
+ firmware if it finds a DT node using it, and bcm2835-camera will
+ therefore fail to probe.
+
+ To compile this driver as a module, choose M here. The module will be
+ called bcm2835-unicam.
diff --git a/drivers/media/platform/broadcom/Makefile 
b/drivers/media/platform/broadcom/Makefile
new file mode 100644
index ..03d2045aba2e
--- /dev/null
+++ b/drivers/media/platform/broadcom/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_VIDEO_BCM2835_UNICAM) += bcm2835-unicam.o
diff --git a/drivers/media/platform/broadcom/bcm2835-unicam-regs.h 
b/drivers/media/platform/broadcom/bcm2835-unicam-regs.h
new file mode 100644
index ..fce6fa92707c
--- /dev/null
+++ b/drivers/media/platform/broadcom/bcm2835-unicam-regs.h
@@ -0,0 +1,246 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/*
+ * Copyright (C) 2017-2020 Raspberry Pi Trading.
+ * Dave Stevenson 
+ */
+
+#ifndef VC4_REGS_UNICAM_H
+#define VC4_REGS_UNICAM_H
+
+#include 
+
+/*
+ * The following values are taken from files found within the code drop
+ * made by Broadcom for the BCM21553 Graphics Driver, predominantly in
+ * brcm_usrlib/dag/vmcsx/vcinclude/hardware_vc4.h.
+ * They have been modified to b

[git:media_stage/master] media: ivsc: csi: Use IPU bridge

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ivsc: csi: Use IPU bridge
Author:  Sakari Ailus 
Date:Tue Feb 13 11:44:09 2024 +0200

Use IPU bridge to instantiate software nodes for IPU6 related devices. If
the IPU6 device is probed before the MEI CSI device is created, neither
will probe unless there are further devices probed successfully which
triggers re-probe of both IPU6 and MEI CSI.

This patch ensures the necessary software nodes are in place when the MEI
CSI driver is probed.

Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ivsc/mei_csi.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/pci/intel/ivsc/mei_csi.c 
b/drivers/media/pci/intel/ivsc/mei_csi.c
index 55e0c60c420c..89b582a221ab 100644
--- a/drivers/media/pci/intel/ivsc/mei_csi.c
+++ b/drivers/media/pci/intel/ivsc/mei_csi.c
@@ -19,12 +19,15 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -661,11 +664,23 @@ static int mei_csi_probe(struct mei_cl_device *cldev,
 const struct mei_cl_device_id *id)
 {
struct device *dev = >dev;
+   struct pci_dev *ipu;
struct mei_csi *csi;
+   unsigned int i;
int ret;
 
-   if (!dev_fwnode(dev))
-   return -EPROBE_DEFER;
+   for (i = 0, ipu = NULL; !ipu && ipu6_pci_tbl[i].vendor; i++)
+   ipu = pci_get_device(ipu6_pci_tbl[i].vendor,
+ipu6_pci_tbl[i].device, NULL);
+
+   if (!ipu)
+   return -ENODEV;
+
+   ret = ipu_bridge_init(>dev, ipu_bridge_parse_ssdb);
+   if (ret < 0)
+   return ret;
+   if (WARN_ON(!dev_fwnode(dev)))
+   return -ENXIO;
 
csi = devm_kzalloc(dev, sizeof(struct mei_csi), GFP_KERNEL);
if (!csi)
@@ -784,6 +799,7 @@ static struct mei_cl_driver mei_csi_driver = {
 
 module_mei_cl_driver(mei_csi_driver);
 
+MODULE_IMPORT_NS(INTEL_IPU_BRIDGE);
 MODULE_AUTHOR("Wentong Wu ");
 MODULE_AUTHOR("Zhifeng Wang ");
 MODULE_DESCRIPTION("Device driver for IVSC CSI");


[git:media_stage/master] media: ipu6: Add PCI device table header

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ipu6: Add PCI device table header
Author:  Sakari Ailus 
Date:Tue Feb 13 11:00:28 2024 +0200

Add a header for the PCI device table of all IPU6 devices. This will be
used by the IPU bridge as well so place the table in a header.

Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 include/media/ipu6-pci-table.h | 28 
 1 file changed, 28 insertions(+)

---

diff --git a/include/media/ipu6-pci-table.h b/include/media/ipu6-pci-table.h
new file mode 100644
index ..0899d9d2f978
--- /dev/null
+++ b/include/media/ipu6-pci-table.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2024 Intel Corporation
+ */
+
+#ifndef __IPU6_PCI_TBL_H__
+#define __IPU6_PCI_TBL_H__
+
+#include 
+
+#define PCI_DEVICE_ID_INTEL_IPU6   0x9a19
+#define PCI_DEVICE_ID_INTEL_IPU6SE 0x4e19
+#define PCI_DEVICE_ID_INTEL_IPU6EP_ADLP0x465d
+#define PCI_DEVICE_ID_INTEL_IPU6EP_ADLN0x462e
+#define PCI_DEVICE_ID_INTEL_IPU6EP_RPLP0xa75d
+#define PCI_DEVICE_ID_INTEL_IPU6EP_MTL 0x7d19
+
+static const struct pci_device_id ipu6_pci_tbl[] = {
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6) },
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6SE) },
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_ADLP) },
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_ADLN) },
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_RPLP) },
+   { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_MTL) },
+   { }
+};
+
+#endif /* __IPU6_PCI_TBL_H__ */


[git:media_stage/master] media: intel/ipu6: add Intel IPU6 PCI device driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add Intel IPU6 PCI device driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:53 2024 +0800

Intel Image Processing Unit 6th Gen includes input and processing systems
but the hardware presents itself as a single PCI device in system.

The IPU6 PCI device driver basically does PCI configurations and loads the
firmware binary, initialises IPU virtual bus and sets up platform specific
variants to support multiple IPU6 devices in single device driver.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h | 179 +
 drivers/media/pci/intel/ipu6/ipu6.c   | 922 ++
 drivers/media/pci/intel/ipu6/ipu6.h   | 342 
 3 files changed, 1443 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h 
b/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
new file mode 100644
index ..b883385adb44
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
@@ -0,0 +1,179 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2018 - 2024 Intel Corporation */
+
+#ifndef IPU6_PLATFORM_REGS_H
+#define IPU6_PLATFORM_REGS_H
+
+#include 
+
+/*
+ * IPU6 uses uniform address within IPU6, therefore all subsystem registers
+ * locates in one single space starts from 0 but in different sctions with
+ * different addresses, the subsystem offsets are defined to 0 as the
+ * register definition will have the address offset to 0.
+ */
+#define IPU6_UNIFIED_OFFSET0
+
+#define IPU6_ISYS_IOMMU0_OFFSET0x2e
+#define IPU6_ISYS_IOMMU1_OFFSET0x2e0500
+#define IPU6_ISYS_IOMMUI_OFFSET0x2e0a00
+
+#define IPU6_PSYS_IOMMU0_OFFSET0x1b
+#define IPU6_PSYS_IOMMU1_OFFSET0x1b0700
+#define IPU6_PSYS_IOMMU1R_OFFSET   0x1b0e00
+#define IPU6_PSYS_IOMMUI_OFFSET0x1b1500
+
+/* the offset from IOMMU base register */
+#define IPU6_MMU_L1_STREAM_ID_REG_OFFSET   0x0c
+#define IPU6_MMU_L2_STREAM_ID_REG_OFFSET   0x4c
+#define IPU6_PSYS_MMU1W_L2_STREAM_ID_REG_OFFSET0x8c
+
+#define IPU6_MMU_INFO_OFFSET   0x8
+
+#define IPU6_ISYS_SPC_OFFSET   0x21
+
+#define IPU6SE_PSYS_SPC_OFFSET 0x11
+#define IPU6_PSYS_SPC_OFFSET   0x118000
+
+#define IPU6_ISYS_DMEM_OFFSET  0x20
+#define IPU6_PSYS_DMEM_OFFSET  0x10
+
+#define IPU6_REG_ISYS_UNISPART_IRQ_EDGE0x27c000
+#define IPU6_REG_ISYS_UNISPART_IRQ_MASK0x27c004
+#define IPU6_REG_ISYS_UNISPART_IRQ_STATUS  0x27c008
+#define IPU6_REG_ISYS_UNISPART_IRQ_CLEAR   0x27c00c
+#define IPU6_REG_ISYS_UNISPART_IRQ_ENABLE  0x27c010
+#define IPU6_REG_ISYS_UNISPART_IRQ_LEVEL_NOT_PULSE 0x27c014
+#define IPU6_REG_ISYS_UNISPART_SW_IRQ_REG  0x27c414
+#define IPU6_REG_ISYS_UNISPART_SW_IRQ_MUX_REG  0x27c418
+#define IPU6_ISYS_UNISPART_IRQ_CSI0BIT(2)
+#define IPU6_ISYS_UNISPART_IRQ_CSI1BIT(3)
+#define IPU6_ISYS_UNISPART_IRQ_SW  BIT(22)
+
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_EDGE 0x2b0200
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_MASK 0x2b0204
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_STATUS   0x2b0208
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_CLEAR0x2b020c
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_ENABLE   0x2b0210
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_LEVEL_NOT_PULSE  0x2b0214
+
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_EDGE0x2d2100
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_MASK0x2d2104
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_STATUS  0x2d2108
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_CLEAR   0x2d210c
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_ENABLE  0x2d2110
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_LEVEL_NOT_PULSE 0x2d2114
+
+/* CDC Burst collector thresholds for isys - 3 FIFOs i = 0..2 */
+#define IPU6_REG_ISYS_CDC_THRESHOLD(i) (0x27c400 + ((i) * 4))
+
+#define IPU6_CSI_IRQ_NUM_PER_PIPE  4
+#define IPU6SE_ISYS_CSI_PORT_NUM   4
+#define IPU6_ISYS_CSI_PORT_NUM 8
+
+#define IPU6_ISYS_CSI_PORT_IRQ(irq_num)BIT(irq_num)
+
+/* PKG DIR OFFSET in IMR in secure mode */
+#define IPU6_PKG_DIR_IMR_OFFSET0x40
+
+#define IPU6_ISYS_REG_SPC_STATUS_CTRL  0x0
+
+#define IPU6_ISYS_SPC_STATUS_START BIT(1)
+#define IPU6_ISYS_SPC_STATUS_RUN   BIT(3)
+#define IPU6_ISYS_SPC_STATUS_READY BIT(5)
+#define IPU6_ISYS_SPC_STATUS_CTRL_ICACHE_INVALIDATEBIT(12)
+#define IPU6_ISYS_SPC_STATUS_ICACHE_PREFETCH   BIT(13

[git:media_stage/master] media: intel/ipu6: add IPU auxiliary devices

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add IPU auxiliary devices
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:54 2024 +0800

Even though the IPU input system and processing system are in a single PCI
device, each system has its own power sequence. Powering up the processing
system depends on first powering up the input system.

Besides, both the input and processing systems have their own MMU hardware
for IPU DMA address mapping.

Register the IS/PS devices on auxiliary bus and attach power domain to
implement the power sequence dependency.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-bus.c | 165 
 drivers/media/pci/intel/ipu6/ipu6-bus.h |  58 +++
 2 files changed, 223 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-bus.c 
b/drivers/media/pci/intel/ipu6/ipu6-bus.c
new file mode 100644
index ..149ec098cdbf
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-bus.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-buttress.h"
+#include "ipu6-dma.h"
+
+static int bus_pm_runtime_suspend(struct device *dev)
+{
+   struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+   int ret;
+
+   ret = pm_generic_runtime_suspend(dev);
+   if (ret)
+   return ret;
+
+   ret = ipu6_buttress_power(dev, adev->ctrl, false);
+   if (!ret)
+   return 0;
+
+   dev_err(dev, "power down failed!\n");
+
+   /* Powering down failed, attempt to resume device now */
+   ret = pm_generic_runtime_resume(dev);
+   if (!ret)
+   return -EBUSY;
+
+   return -EIO;
+}
+
+static int bus_pm_runtime_resume(struct device *dev)
+{
+   struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+   int ret;
+
+   ret = ipu6_buttress_power(dev, adev->ctrl, true);
+   if (ret)
+   return ret;
+
+   ret = pm_generic_runtime_resume(dev);
+   if (ret)
+   goto out_err;
+
+   return 0;
+
+out_err:
+   ipu6_buttress_power(dev, adev->ctrl, false);
+
+   return -EBUSY;
+}
+
+static struct dev_pm_domain ipu6_bus_pm_domain = {
+   .ops = {
+   .runtime_suspend = bus_pm_runtime_suspend,
+   .runtime_resume = bus_pm_runtime_resume,
+   },
+};
+
+static DEFINE_MUTEX(ipu6_bus_mutex);
+
+static void ipu6_bus_release(struct device *dev)
+{
+   struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+
+   kfree(adev->pdata);
+   kfree(adev);
+}
+
+struct ipu6_bus_device *
+ipu6_bus_initialize_device(struct pci_dev *pdev, struct device *parent,
+  void *pdata, struct ipu6_buttress_ctrl *ctrl,
+  char *name)
+{
+   struct auxiliary_device *auxdev;
+   struct ipu6_bus_device *adev;
+   struct ipu6_device *isp = pci_get_drvdata(pdev);
+   int ret;
+
+   adev = kzalloc(sizeof(*adev), GFP_KERNEL);
+   if (!adev)
+   return ERR_PTR(-ENOMEM);
+
+   adev->dma_mask = DMA_BIT_MASK(isp->secure_mode ? IPU6_MMU_ADDR_BITS :
+ IPU6_MMU_ADDR_BITS_NON_SECURE);
+   adev->isp = isp;
+   adev->ctrl = ctrl;
+   adev->pdata = pdata;
+   auxdev = >auxdev;
+   auxdev->name = name;
+   auxdev->id = (pci_domain_nr(pdev->bus) << 16) |
+ PCI_DEVID(pdev->bus->number, pdev->devfn);
+
+   auxdev->dev.parent = parent;
+   auxdev->dev.release = ipu6_bus_release;
+   auxdev->dev.dma_ops = _dma_ops;
+   auxdev->dev.dma_mask = >dma_mask;
+   auxdev->dev.dma_parms = pdev->dev.dma_parms;
+   auxdev->dev.coherent_dma_mask = adev->dma_mask;
+
+   ret = auxiliary_device_init(auxdev);
+   if (ret < 0) {
+   dev_err(>pdev->dev, "auxiliary device init failed (%d)\n",
+   ret);
+   kfree(adev);
+   return ERR_PTR(ret);
+   }
+
+   dev_pm_domain_set(>dev, _bus_pm_domain);
+
+   pm_runtime_forbid(>auxdev.dev);
+   pm_runtime_enable(>auxdev.dev);
+
+   return adev;
+}
+
+int ipu6_bus_add_device(struct ipu6_bus_device *adev)
+{
+   struct auxiliary_device *auxdev = >auxdev;
+   int ret;
+
+   ret = auxiliary_device_add(auxdev);
+   if (ret) {
+   auxiliary_device_uninit(auxdev);
+   return ret;
+   }
+
+   mutex_lock(_bus_mutex);
+   list_add(>list, >isp->devices);
+

[git:media_stage/master] media: intel/ipu6: add IPU6 buttress interface driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add IPU6 buttress interface driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:55 2024 +0800

The IPU6 buttress is the interface between IPU device (input system and
processing system) with rest of the SoC. It contains overall IPU hardware
control registers, these control registers are used as the interfaces with
the Intel Converged Security Engine and Punit to do firmware
authentication and power management.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-buttress.c   | 912 +
 drivers/media/pci/intel/ipu6/ipu6-buttress.h   |  92 +++
 .../pci/intel/ipu6/ipu6-platform-buttress-regs.h   | 226 +
 3 files changed, 1230 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-buttress.c 
b/drivers/media/pci/intel/ipu6/ipu6-buttress.c
new file mode 100644
index ..dbcf1aa87872
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-buttress.c
@@ -0,0 +1,912 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-buttress.h"
+#include "ipu6-platform-buttress-regs.h"
+
+#define BOOTLOADER_STATUS_OFFSET   0x15c
+
+#define BOOTLOADER_MAGIC_KEY   0xb00710ad
+
+#define ENTRY  BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE1
+#define EXIT   BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE2
+#define QUERY  BUTTRESS_IU2CSECSR_IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE
+
+#define BUTTRESS_TSC_SYNC_RESET_TRIAL_MAX  10
+
+#define BUTTRESS_POWER_TIMEOUT_US  (200 * USEC_PER_MSEC)
+
+#define BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US   (5 * USEC_PER_SEC)
+#define BUTTRESS_CSE_AUTHENTICATE_TIMEOUT_US   (10 * USEC_PER_SEC)
+#define BUTTRESS_CSE_FWRESET_TIMEOUT_US(100 * USEC_PER_MSEC)
+
+#define BUTTRESS_IPC_TX_TIMEOUT_MS MSEC_PER_SEC
+#define BUTTRESS_IPC_RX_TIMEOUT_MS MSEC_PER_SEC
+#define BUTTRESS_IPC_VALIDITY_TIMEOUT_US   (1 * USEC_PER_SEC)
+#define BUTTRESS_TSC_SYNC_TIMEOUT_US   (5 * USEC_PER_MSEC)
+
+#define BUTTRESS_IPC_RESET_RETRY   2000
+#define BUTTRESS_CSE_IPC_RESET_RETRY   4
+#define BUTTRESS_IPC_CMD_SEND_RETRY1
+
+#define BUTTRESS_MAX_CONSECUTIVE_IRQS  100
+
+static const u32 ipu6_adev_irq_mask[2] = {
+   BUTTRESS_ISR_IS_IRQ,
+   BUTTRESS_ISR_PS_IRQ
+};
+
+int ipu6_buttress_ipc_reset(struct ipu6_device *isp,
+   struct ipu6_buttress_ipc *ipc)
+{
+   unsigned int retries = BUTTRESS_IPC_RESET_RETRY;
+   struct ipu6_buttress *b = >buttress;
+   u32 val = 0, csr_in_clr;
+
+   if (!isp->secure_mode) {
+   dev_dbg(>pdev->dev, "Skip IPC reset for non-secure mode");
+   return 0;
+   }
+
+   mutex_lock(>ipc_mutex);
+
+   /* Clear-by-1 CSR (all bits), corresponding internal states. */
+   val = readl(isp->base + ipc->csr_in);
+   writel(val, isp->base + ipc->csr_in);
+
+   /* Set peer CSR bit IPC_PEER_COMP_ACTIONS_RST_PHASE1 */
+   writel(ENTRY, isp->base + ipc->csr_out);
+   /*
+* Clear-by-1 all CSR bits EXCEPT following
+* bits:
+* A. IPC_PEER_COMP_ACTIONS_RST_PHASE1.
+* B. IPC_PEER_COMP_ACTIONS_RST_PHASE2.
+* C. Possibly custom bits, depending on
+* their role.
+*/
+   csr_in_clr = BUTTRESS_IU2CSECSR_IPC_PEER_DEASSERTED_REG_VALID_REQ |
+   BUTTRESS_IU2CSECSR_IPC_PEER_ACKED_REG_VALID |
+   BUTTRESS_IU2CSECSR_IPC_PEER_ASSERTED_REG_VALID_REQ | QUERY;
+
+   do {
+   usleep_range(400, 500);
+   val = readl(isp->base + ipc->csr_in);
+   switch (val) {
+   case ENTRY | EXIT:
+   case ENTRY | EXIT | QUERY:
+   /*
+* 1) Clear-by-1 CSR bits
+* (IPC_PEER_COMP_ACTIONS_RST_PHASE1,
+* IPC_PEER_COMP_ACTIONS_RST_PHASE2).
+* 2) Set peer CSR bit
+* IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE.
+*/
+   writel(ENTRY | EXIT, isp->base + ipc->csr_in);
+   writel(QUERY, isp->base + ipc->csr_out);
+   break;
+   case ENTRY:
+   case ENTRY | QUERY:
+   /*
+* 1) Clear-by-1 CSR bits
+* (IPC_PEER_COMP_ACTIONS_RST_PHASE1,
+

[git:media_stage/master] media: intel/ipu6: add syscom interfaces between firmware and driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add syscom interfaces between firmware and driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:58 2024 +0800

Syscom is an inter-process(or) communication mechanism between an IPU and
host. Syscom uses message queues for message exchange between IPU and
host. Each message queue has its consumer and producer, host queue
messages to firmware as the producer and then firmware to dequeue the
messages as consumer and vice versa. IPU and host use shared registers or
memory to reside the read and write indices which are updated by consumer
and producer.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 413 +
 drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 
 2 files changed, 460 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-com.c 
b/drivers/media/pci/intel/ipu6/ipu6-fw-com.c
new file mode 100644
index ..0b33fe9e703d
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-com.c
@@ -0,0 +1,413 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-fw-com.h"
+
+/*
+ * FWCOM layer is a shared resource between FW and driver. It consist
+ * of token queues to both send and receive directions. Queue is simply
+ * an array of structures with read and write indexes to the queue.
+ * There are 1...n queues to both directions. Queues locates in
+ * system RAM and are mapped to ISP MMU so that both CPU and ISP can
+ * see the same buffer. Indexes are located in ISP DMEM so that FW code
+ * can poll those with very low latency and cost. CPU access to indexes is
+ * more costly but that happens only at message sending time and
+ * interrupt triggered message handling. CPU doesn't need to poll indexes.
+ * wr_reg / rd_reg are offsets to those dmem location. They are not
+ * the indexes itself.
+ */
+
+/* Shared structure between driver and FW - do not modify */
+struct ipu6_fw_sys_queue {
+   u64 host_address;
+   u32 vied_address;
+   u32 size;
+   u32 token_size;
+   u32 wr_reg; /* reg number in subsystem's regmem */
+   u32 rd_reg;
+   u32 _align;
+} __packed;
+
+struct ipu6_fw_sys_queue_res {
+   u64 host_address;
+   u32 vied_address;
+   u32 reg;
+} __packed;
+
+enum syscom_state {
+   /* Program load or explicit host setting should init to this */
+   SYSCOM_STATE_UNINIT = 0x57a7e000,
+   /* SP Syscom sets this when it is ready for use */
+   SYSCOM_STATE_READY = 0x57a7e001,
+   /* SP Syscom sets this when no more syscom accesses will happen */
+   SYSCOM_STATE_INACTIVE = 0x57a7e002,
+};
+
+enum syscom_cmd {
+   /* Program load or explicit host setting should init to this */
+   SYSCOM_COMMAND_UNINIT = 0x57a7f000,
+   /* Host Syscom requests syscom to become inactive */
+   SYSCOM_COMMAND_INACTIVE = 0x57a7f001,
+};
+
+/* firmware config: data that sent from the host to SP via DDR */
+/* Cell copies data into a context */
+
+struct ipu6_fw_syscom_config {
+   u32 firmware_address;
+
+   u32 num_input_queues;
+   u32 num_output_queues;
+
+   /* ISP pointers to an array of ipu6_fw_sys_queue structures */
+   u32 input_queue;
+   u32 output_queue;
+
+   /* ISYS / PSYS private data */
+   u32 specific_addr;
+   u32 specific_size;
+};
+
+struct ipu6_fw_com_context {
+   struct ipu6_bus_device *adev;
+   void __iomem *dmem_addr;
+   int (*cell_ready)(struct ipu6_bus_device *adev);
+   void (*cell_start)(struct ipu6_bus_device *adev);
+
+   void *dma_buffer;
+   dma_addr_t dma_addr;
+   unsigned int dma_size;
+   unsigned long attrs;
+
+   struct ipu6_fw_sys_queue *input_queue;  /* array of host to SP queues */
+   struct ipu6_fw_sys_queue *output_queue; /* array of SP to host */
+
+   u32 config_vied_addr;
+
+   unsigned int buttress_boot_offset;
+   void __iomem *base_addr;
+};
+
+#define FW_COM_WR_REG 0
+#define FW_COM_RD_REG 4
+
+#define REGMEM_OFFSET 0
+#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
+
+enum regmem_id {
+   /* pass pkg_dir address to SPC in non-secure mode */
+   PKG_DIR_ADDR_REG = 0,
+   /* Tunit CFG blob for secure - provided by host.*/
+   TUNIT_CFG_DWR_REG = 1,
+   /* syscom commands - modified by the host */
+   SYSCOM_COMMAND_REG = 2,
+   /* Store interrupt status - updated by SP */
+   SYSCOM_IRQ_REG = 3,
+   /* first syscom queue pointer register */
+   SYSCOM_QPR_BASE_REG = 4
+};
+
+#define BUTTRESS_FW_BOOT_PARAMS_0 0x4000
+#define BUTTRESS_FW_BOOT_PARAM_REG(base, offset, id)   \
+   ((base) + BUTTRESS_FW_BOOT_PARAMS_0 + (

[git:media_stage/master] media: intel/ipu6: input system ABI between firmware and driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: input system ABI between firmware and driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:59 2024 +0800

Implement the input system firmware ABIs in the ISYS driver, including
stream configuration, control command, capture request and response.

Signed-off-by: Bingbu Cao 
Co-developed-by: Sakari Ailus 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c | 487 +++
 drivers/media/pci/intel/ipu6/ipu6-fw-isys.h | 596 
 2 files changed, 1083 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c 
b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
new file mode 100644
index ..62ed92ff1d30
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
@@ -0,0 +1,487 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-fw-com.h"
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+static const char send_msg_types[N_IPU6_FW_ISYS_SEND_TYPE][32] = {
+   "STREAM_OPEN",
+   "STREAM_START",
+   "STREAM_START_AND_CAPTURE",
+   "STREAM_CAPTURE",
+   "STREAM_STOP",
+   "STREAM_FLUSH",
+   "STREAM_CLOSE"
+};
+
+static int handle_proxy_response(struct ipu6_isys *isys, unsigned int req_id)
+{
+   struct device *dev = >adev->auxdev.dev;
+   struct ipu6_fw_isys_proxy_resp_info_abi *resp;
+   int ret;
+
+   resp = ipu6_recv_get_token(isys->fwcom, IPU6_BASE_PROXY_RECV_QUEUES);
+   if (!resp)
+   return 1;
+
+   dev_dbg(dev, "Proxy response: id %u, error %u, details %u\n",
+   resp->request_id, resp->error_info.error,
+   resp->error_info.error_details);
+
+   ret = req_id == resp->request_id ? 0 : -EIO;
+
+   ipu6_recv_put_token(isys->fwcom, IPU6_BASE_PROXY_RECV_QUEUES);
+
+   return ret;
+}
+
+int ipu6_fw_isys_send_proxy_token(struct ipu6_isys *isys,
+ unsigned int req_id,
+ unsigned int index,
+ unsigned int offset, u32 value)
+{
+   struct ipu6_fw_com_context *ctx = isys->fwcom;
+   struct device *dev = >adev->auxdev.dev;
+   struct ipu6_fw_proxy_send_queue_token *token;
+   unsigned int timeout = 1000;
+   int ret;
+
+   dev_dbg(dev,
+   "proxy send: req_id 0x%x, index %d, offset 0x%x, value 0x%x\n",
+   req_id, index, offset, value);
+
+   token = ipu6_send_get_token(ctx, IPU6_BASE_PROXY_SEND_QUEUES);
+   if (!token)
+   return -EBUSY;
+
+   token->request_id = req_id;
+   token->region_index = index;
+   token->offset = offset;
+   token->value = value;
+   ipu6_send_put_token(ctx, IPU6_BASE_PROXY_SEND_QUEUES);
+
+   do {
+   usleep_range(100, 110);
+   ret = handle_proxy_response(isys, req_id);
+   if (!ret)
+   break;
+   if (ret == -EIO) {
+   dev_err(dev, "Proxy respond with unexpected id\n");
+   break;
+   }
+   timeout--;
+   } while (ret && timeout);
+
+   if (!timeout)
+   dev_err(dev, "Proxy response timed out\n");
+
+   return ret;
+}
+
+int ipu6_fw_isys_complex_cmd(struct ipu6_isys *isys,
+const unsigned int stream_handle,
+void *cpu_mapped_buf,
+dma_addr_t dma_mapped_buf,
+size_t size, u16 send_type)
+{
+   struct ipu6_fw_com_context *ctx = isys->fwcom;
+   struct device *dev = >adev->auxdev.dev;
+   struct ipu6_fw_send_queue_token *token;
+
+   if (send_type >= N_IPU6_FW_ISYS_SEND_TYPE)
+   return -EINVAL;
+
+   dev_dbg(dev, "send_token: %s\n", send_msg_types[send_type]);
+
+   /*
+* Time to flush cache in case we have some payload. Not all messages
+* have that
+*/
+   if (cpu_mapped_buf)
+   clflush_cache_range(cpu_mapped_buf, size);
+
+   token = ipu6_send_get_token(ctx,
+   stream_handle + IPU6_BASE_MSG_SEND_QUEUES);
+   if (!token)
+   return -EBUSY;
+
+   token->payload = dma_mapped_buf;
+   token->buf_handle = (unsigned long)cpu_mapped_buf;
+   token->send_type = send_type;
+
+   ipu6_send_put_token(ctx, stream_handle + I

[git:media_stage/master] media: intel/ipu6: CPD parsing for get firmware components

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: CPD parsing for get firmware components
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:56 2024 +0800

For IPU6, firmware is generated and released as signed Code Partition
Directory (CPD) format file which is aligned with the SPI flash code
partition definition. The CPD format includes CPD header, manifest,
metadata and module data. The driver parses them according to the CPD
layout to acquire each component.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-cpd.c | 362 
 drivers/media/pci/intel/ipu6/ipu6-cpd.h | 105 +
 2 files changed, 467 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-cpd.c 
b/drivers/media/pci/intel/ipu6/ipu6-cpd.c
new file mode 100644
index ..715b21ab4b8e
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-cpd.c
@@ -0,0 +1,362 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-cpd.h"
+
+/* 15 entries + header*/
+#define MAX_PKG_DIR_ENT_CNT16
+/* 2 qword per entry/header */
+#define PKG_DIR_ENT_LEN2
+/* PKG_DIR size in bytes */
+#define PKG_DIR_SIZE   ((MAX_PKG_DIR_ENT_CNT) *\
+(PKG_DIR_ENT_LEN) * sizeof(u64))
+/* _IUPKDR_ */
+#define PKG_DIR_HDR_MARK   0x5f4955504b44525fULL
+
+/* $CPD */
+#define CPD_HDR_MARK   0x44504324
+
+#define MAX_MANIFEST_SIZE  (SZ_2K * sizeof(u32))
+#define MAX_METADATA_SIZE  SZ_64K
+
+#define MAX_COMPONENT_ID   127
+#define MAX_COMPONENT_VERSION  0x
+
+#define MANIFEST_IDX   0
+#define METADATA_IDX   1
+#define MODULEDATA_IDX 2
+/*
+ * PKG_DIR Entry (type == id)
+ * 63:5655  54:48   47:32   31:24   23:0
+ * Rsvd RsvdTypeVersion RsvdSize
+ */
+#define PKG_DIR_SIZE_MASK  GENMASK(23, 0)
+#define PKG_DIR_VERSION_MASK   GENMASK(47, 32)
+#define PKG_DIR_TYPE_MASK  GENMASK(54, 48)
+
+static inline const struct ipu6_cpd_ent *ipu6_cpd_get_entry(const void *cpd,
+   u8 idx)
+{
+   const struct ipu6_cpd_hdr *cpd_hdr = cpd;
+   const struct ipu6_cpd_ent *ent;
+
+   ent = (const struct ipu6_cpd_ent *)((const u8 *)cpd + cpd_hdr->hdr_len);
+   return ent + idx;
+}
+
+#define ipu6_cpd_get_manifest(cpd) ipu6_cpd_get_entry(cpd, MANIFEST_IDX)
+#define ipu6_cpd_get_metadata(cpd) ipu6_cpd_get_entry(cpd, METADATA_IDX)
+#define ipu6_cpd_get_moduledata(cpd) ipu6_cpd_get_entry(cpd, MODULEDATA_IDX)
+
+static const struct ipu6_cpd_metadata_cmpnt_hdr *
+ipu6_cpd_metadata_get_cmpnt(struct ipu6_device *isp, const void *metadata,
+   unsigned int metadata_size, u8 idx)
+{
+   size_t extn_size = sizeof(struct ipu6_cpd_metadata_extn);
+   size_t cmpnt_count = metadata_size - extn_size;
+
+   cmpnt_count = div_u64(cmpnt_count, isp->cpd_metadata_cmpnt_size);
+
+   if (idx > MAX_COMPONENT_ID || idx >= cmpnt_count) {
+   dev_err(>pdev->dev, "Component index out of range (%d)\n",
+   idx);
+   return ERR_PTR(-EINVAL);
+   }
+
+   return metadata + extn_size + idx * isp->cpd_metadata_cmpnt_size;
+}
+
+static u32 ipu6_cpd_metadata_cmpnt_version(struct ipu6_device *isp,
+  const void *metadata,
+  unsigned int metadata_size, u8 idx)
+{
+   const struct ipu6_cpd_metadata_cmpnt_hdr *cmpnt;
+
+   cmpnt = ipu6_cpd_metadata_get_cmpnt(isp, metadata, metadata_size, idx);
+   if (IS_ERR(cmpnt))
+   return PTR_ERR(cmpnt);
+
+   return cmpnt->ver;
+}
+
+static int ipu6_cpd_metadata_get_cmpnt_id(struct ipu6_device *isp,
+ const void *metadata,
+ unsigned int metadata_size, u8 idx)
+{
+   const struct ipu6_cpd_metadata_cmpnt_hdr *cmpnt;
+
+   cmpnt = ipu6_cpd_metadata_get_cmpnt(isp, metadata, metadata_size, idx);
+   if (IS_ERR(cmpnt))
+   return PTR_ERR(cmpnt);
+
+   return cmpnt->id;
+}
+
+static int ipu6_cpd_parse_module_data(struct ipu6_device *isp,
+ const void *module_data,
+ unsigned int module_data_size,
+ dma_addr_t dma_addr_module_data,
+ u64 *pkg_dir, const void *metadata,
+ unsigned int metadata_size)
+{
+   co

[git:media_stage/master] media: intel/ipu6: add the main input system driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add the main input system driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:02 2024 +0800

The main input system driver does basic ISYS hardware setup, IRQ handling
and sets up device nodes.

Signed-off-by: Bingbu Cao 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys.c | 1368 ++
 drivers/media/pci/intel/ipu6/ipu6-isys.h |  206 +
 drivers/media/pci/intel/ipu6/ipu6.c  |   35 +-
 3 files changed, 1578 insertions(+), 31 deletions(-)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys.c
new file mode 100644
index ..d3918e26f631
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys.c
@@ -0,0 +1,1368 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-cpd.h"
+#include "ipu6-isys.h"
+#include "ipu6-isys-csi2.h"
+#include "ipu6-mmu.h"
+#include "ipu6-platform-buttress-regs.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+#define IPU6_BUTTRESS_FABIC_CONTROL0x68
+#define GDA_ENABLE_IWAKE_INDEX 2
+#define GDA_IWAKE_THRESHOLD_INDEX  1
+#define GDA_IRQ_CRITICAL_THRESHOLD_INDEX   0
+#define GDA_MEMOPEN_THRESHOLD_INDEX3
+#define DEFAULT_DID_RATIO  90
+#define DEFAULT_IWAKE_THRESHOLD0x42
+#define DEFAULT_MEM_OPEN_TIME  10
+#define ONE_THOUSAND_MICROSECOND   1000
+/* One page is 2KB, 8 x 16 x 16 = 2048B = 2KB */
+#define ISF_DMA_TOP_GDA_PROFERTY_PAGE_SIZE 0x800
+
+/* LTR & DID value are 10 bit at most */
+#define LTR_DID_VAL_MAX1023
+#define LTR_DEFAULT_VALUE  0x70503c19
+#define FILL_TIME_DEFAULT_VALUE0xfff0783c
+#define LTR_DID_PKGC_2R20
+#define LTR_SCALE_DEFAULT  5
+#define LTR_SCALE_1024NS   2
+#define DID_SCALE_1US  2
+#define DID_SCALE_32US 3
+#define REG_PKGC_PMON_CFG  0xb00
+
+#define VAL_PKGC_PMON_CFG_RESET0x38
+#define VAL_PKGC_PMON_CFG_START0x7
+
+#define IS_PIXEL_BUFFER_PAGES  0x80
+/*
+ * when iwake mode is disabled, the critical threshold is statically set
+ * to 75% of the IS pixel buffer, criticalThreshold = (128 * 3) / 4
+ */
+#define CRITICAL_THRESHOLD_IWAKE_DISABLE   (IS_PIXEL_BUFFER_PAGES * 3 / 4)
+
+union fabric_ctrl {
+   struct {
+   u16 ltr_val   : 10;
+   u16 ltr_scale : 3;
+   u16 reserved  : 3;
+   u16 did_val   : 10;
+   u16 did_scale : 3;
+   u16 reserved2 : 1;
+   u16 keep_power_in_D0   : 1;
+   u16 keep_power_override : 1;
+   } bits;
+   u32 value;
+};
+
+enum ltr_did_type {
+   LTR_IWAKE_ON,
+   LTR_IWAKE_OFF,
+   LTR_ISYS_ON,
+   LTR_ISYS_OFF,
+   LTR_ENHANNCE_IWAKE,
+   LTR_TYPE_MAX
+};
+
+#define ISYS_PM_QOS_VALUE  300
+
+static int isys_isr_one(struct ipu6_bus_device *adev);
+
+static int
+isys_complete_ext_device_registration(struct ipu6_isys *isys,
+ struct v4l2_subdev *sd,
+ struct ipu6_isys_csi2_config *csi2)
+{
+   struct device *dev = >adev->auxdev.dev;
+   unsigned int i;
+   int ret;
+
+   for (i = 0; i < sd->entity.num_pads; i++) {
+   if (sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE)
+   break;
+   }
+
+   if (i == sd->entity.num_pads) {
+   dev_warn(dev, "no src pad in external entity\n");
+   ret = -ENOENT;
+   goto unregister_subdev;
+   }
+
+   ret = media_create_pad_link(>entity, i,
+   >csi2[csi2->port].asd.sd.entity,
+   0, MEDIA_LNK_FL_ENABLED |
+  MEDIA_LNK_FL_IMMUTABLE);
+   if (ret) {
+   dev_warn(dev, "can't create link\n");
+   goto unregister_subdev;
+   }
+
+   isys->csi2[csi2->port].nlanes = csi2->nlanes;
+
+   return 0;
+
+unregister_subd

[git:media_stage/master] media: intel/ipu6: add IPU6 DMA mapping API and MMU table

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add IPU6 DMA mapping API and MMU table
Author:  Bingbu Cao 
Date:Wed Jan 31 17:50:57 2024 +0800

The Intel IPU6 has internal microcontrollers (scalar processor, SP) which
are used to execute the firmware. The SPs can access IPU internal memory
and system DRAM mapped to its an internal 32-bit virtual address space.

This patch adds a driver for the IPU MMU and a DMA mapping implementation
using the internal MMU. The system IOMMU may be used besides the IPU MMU.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-dma.c | 502 +++
 drivers/media/pci/intel/ipu6/ipu6-dma.h |  19 +
 drivers/media/pci/intel/ipu6/ipu6-mmu.c | 845 
 drivers/media/pci/intel/ipu6/ipu6-mmu.h |  73 +++
 4 files changed, 1439 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c 
b/drivers/media/pci/intel/ipu6/ipu6-dma.c
new file mode 100644
index ..92530a1cc90f
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -0,0 +1,502 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-dma.h"
+#include "ipu6-mmu.h"
+
+struct vm_info {
+   struct list_head list;
+   struct page **pages;
+   dma_addr_t ipu6_iova;
+   void *vaddr;
+   unsigned long size;
+};
+
+static struct vm_info *get_vm_info(struct ipu6_mmu *mmu, dma_addr_t iova)
+{
+   struct vm_info *info, *save;
+
+   list_for_each_entry_safe(info, save, >vma_list, list) {
+   if (iova >= info->ipu6_iova &&
+   iova < (info->ipu6_iova + info->size))
+   return info;
+   }
+
+   return NULL;
+}
+
+static void __dma_clear_buffer(struct page *page, size_t size,
+  unsigned long attrs)
+{
+   void *ptr;
+
+   if (!page)
+   return;
+   /*
+* Ensure that the allocated pages are zeroed, and that any data
+* lurking in the kernel direct-mapped region is invalidated.
+*/
+   ptr = page_address(page);
+   memset(ptr, 0, size);
+   if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+   clflush_cache_range(ptr, size);
+}
+
+static struct page **__dma_alloc_buffer(struct device *dev, size_t size,
+   gfp_t gfp, unsigned long attrs)
+{
+   int count = PHYS_PFN(size);
+   int array_size = count * sizeof(struct page *);
+   struct page **pages;
+   int i = 0;
+
+   pages = kvzalloc(array_size, GFP_KERNEL);
+   if (!pages)
+   return NULL;
+
+   gfp |= __GFP_NOWARN;
+
+   while (count) {
+   int j, order = __fls(count);
+
+   pages[i] = alloc_pages(gfp, order);
+   while (!pages[i] && order)
+   pages[i] = alloc_pages(gfp, --order);
+   if (!pages[i])
+   goto error;
+
+   if (order) {
+   split_page(pages[i], order);
+   j = 1 << order;
+   while (j--)
+   pages[i + j] = pages[i] + j;
+   }
+
+   __dma_clear_buffer(pages[i], PAGE_SIZE << order, attrs);
+   i += 1 << order;
+   count -= 1 << order;
+   }
+
+   return pages;
+error:
+   while (i--)
+   if (pages[i])
+   __free_pages(pages[i], 0);
+   kvfree(pages);
+   return NULL;
+}
+
+static void __dma_free_buffer(struct device *dev, struct page **pages,
+ size_t size, unsigned long attrs)
+{
+   int count = PHYS_PFN(size);
+   unsigned int i;
+
+   for (i = 0; i < count && pages[i]; i++) {
+   __dma_clear_buffer(pages[i], PAGE_SIZE, attrs);
+   __free_pages(pages[i], 0);
+   }
+
+   kvfree(pages);
+}
+
+static void ipu6_dma_sync_single_for_cpu(struct device *dev,
+dma_addr_t dma_handle,
+size_t size,
+enum dma_data_direction dir)
+{
+   void *vaddr;
+   u32 offset;
+   struct vm_info *info;
+   struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+
+   info = get_vm_info(mmu, dma_handle);
+   if (WARN_ON(!info))
+   return;
+
+   offset = dma_handle - info->ipu6_iova;
+   if (WARN_ON(size > (info->size - offset)))
+   return;
+
+   vaddr = 

[git:media_stage/master] media: intel/ipu6: add the CSI2 DPHY implementation

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add the CSI2 DPHY implementation
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:01 2024 +0800

IPU6 CSI-2 D-PHY hardware varies on different platforms, current IPU6 has
three D-PHY hardware instances which are used on Tigerlake, Alder lake,
Meteor lake and Jasper lake. MCD D-PHY is included in Tigerlake and Alder
lake, DWC D-PHY is included in Meteor lake.

Each PHY has its own register interface, the input system driver calls the
appropriate D-PHY callbacks for the hardware set in isys_probe().

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c | 536 +
 drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c | 242 
 drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c | 720 +++
 3 files changed, 1498 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
new file mode 100644
index ..1715275e6776
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
@@ -0,0 +1,536 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+
+#define IPU6_DWC_DPHY_BASE(i)  (0x238038 + 0x34 * (i))
+#define IPU6_DWC_DPHY_RSTZ 0x00
+#define IPU6_DWC_DPHY_SHUTDOWNZ0x04
+#define IPU6_DWC_DPHY_HSFREQRANGE  0x08
+#define IPU6_DWC_DPHY_CFGCLKFREQRANGE  0x0c
+#define IPU6_DWC_DPHY_TEST_IFC_ACCESS_MODE 0x10
+#define IPU6_DWC_DPHY_TEST_IFC_REQ 0x14
+#define IPU6_DWC_DPHY_TEST_IFC_REQ_COMPLETION  0x18
+#define IPU6_DWC_DPHY_DFT_CTRL00x28
+#define IPU6_DWC_DPHY_DFT_CTRL10x2c
+#define IPU6_DWC_DPHY_DFT_CTRL20x30
+
+/*
+ * test IFC request definition:
+ * - req: 0 for read, 1 for write
+ * - 12 bits address
+ * - 8bits data (will ignore for read)
+ * --2416--4-0
+ * --|-data-|-addr-|-req-|
+ */
+#define IFC_REQ(req, addr, data) (FIELD_PREP(GENMASK(23, 16), data) | \
+ FIELD_PREP(GENMASK(15, 4), addr) | \
+ FIELD_PREP(GENMASK(1, 0), req))
+
+#define TEST_IFC_REQ_READ  0
+#define TEST_IFC_REQ_WRITE 1
+#define TEST_IFC_REQ_RESET 2
+
+#define TEST_IFC_ACCESS_MODE_FSM   0
+#define TEST_IFC_ACCESS_MODE_IFC_CTL   1
+
+enum phy_fsm_state {
+   PHY_FSM_STATE_POWERON = 0,
+   PHY_FSM_STATE_BGPON = 1,
+   PHY_FSM_STATE_CAL_TYPE = 2,
+   PHY_FSM_STATE_BURNIN_CAL = 3,
+   PHY_FSM_STATE_TERMCAL = 4,
+   PHY_FSM_STATE_OFFSETCAL = 5,
+   PHY_FSM_STATE_OFFSET_LANE = 6,
+   PHY_FSM_STATE_IDLE = 7,
+   PHY_FSM_STATE_ULP = 8,
+   PHY_FSM_STATE_DDLTUNNING = 9,
+   PHY_FSM_STATE_SKEW_BACKWARD = 10,
+   PHY_FSM_STATE_INVALID,
+};
+
+static void dwc_dphy_write(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+  u32 data)
+{
+   struct device *dev = >adev->auxdev.dev;
+   void __iomem *isys_base = isys->pdata->base;
+   void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+
+   dev_dbg(dev, "write: reg 0x%lx = data 0x%x", base + addr - isys_base,
+   data);
+   writel(data, base + addr);
+}
+
+static u32 dwc_dphy_read(struct ipu6_isys *isys, u32 phy_id, u32 addr)
+{
+   struct device *dev = >adev->auxdev.dev;
+   void __iomem *isys_base = isys->pdata->base;
+   void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+   u32 data;
+
+   data = readl(base + addr);
+   dev_dbg(dev, "read: reg 0x%lx = data 0x%x", base + addr - isys_base,
+   data);
+
+   return data;
+}
+
+static void dwc_dphy_write_mask(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+   u32 data, u8 shift, u8 width)
+{
+   u32 temp;
+   u32 mask;
+
+   mask = (1 << width) - 1;
+   temp = dwc_dphy_read(isys, phy_id, addr);
+   temp &= ~(mask << shift);
+   temp |= (data & mask) << shift;
+   dwc_dphy_write(isys, phy_id, addr, temp);
+}
+
+static u32 __maybe_unused dwc_dphy_read_mask(struct ipu6_isys *isys, u32 
phy_id,
+u32 addr, u8 shift,  u8 width)
+{
+   u32 val;
+
+   val = dwc_dphy_read(isys, phy_id, addr) >> shift;
+   return val & ((1 << width) - 1);
+}
+
+#define DWC_DPHY_TIMEOUT (5 * USEC_PER_SEC)
+static int dwc_dphy_ifc_read(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+u32 *val)
+{
+   str

[git:media_stage/master] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:00 2024 +0800

Input system CSI2 receiver is exposed as a v4l2 sub-device. Each CSI2
sub-device represent one single CSI2 hardware port which be linked with
external sub-device such camera sensor by linked with ISYS CSI2's sink
pad. The CSI2 source pad is linked to the sink pad of video capture device.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c  | 658 +
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h  |  82 +++
 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c| 398 +
 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h|  59 ++
 .../pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h   | 172 ++
 5 files changed, 1369 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
new file mode 100644
index ..e8d93aa7fc6d
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -0,0 +1,658 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-isys.h"
+#include "ipu6-isys-csi2.h"
+#include "ipu6-isys-subdev.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+
+static const u32 csi2_supported_codes[] = {
+   MEDIA_BUS_FMT_RGB565_1X16,
+   MEDIA_BUS_FMT_RGB888_1X24,
+   MEDIA_BUS_FMT_UYVY8_1X16,
+   MEDIA_BUS_FMT_YUYV8_1X16,
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   MEDIA_BUS_FMT_SGBRG10_1X10,
+   MEDIA_BUS_FMT_SGRBG10_1X10,
+   MEDIA_BUS_FMT_SRGGB10_1X10,
+   MEDIA_BUS_FMT_SBGGR12_1X12,
+   MEDIA_BUS_FMT_SGBRG12_1X12,
+   MEDIA_BUS_FMT_SGRBG12_1X12,
+   MEDIA_BUS_FMT_SRGGB12_1X12,
+   MEDIA_BUS_FMT_SBGGR8_1X8,
+   MEDIA_BUS_FMT_SGBRG8_1X8,
+   MEDIA_BUS_FMT_SGRBG8_1X8,
+   MEDIA_BUS_FMT_SRGGB8_1X8,
+   0
+};
+
+/*
+ * Strings corresponding to CSI-2 receiver errors are here.
+ * Corresponding macros are defined in the header file.
+ */
+static const struct ipu6_csi2_error dphy_rx_errors[] = {
+   { "Single packet header error corrected", true },
+   { "Multiple packet header errors detected", true },
+   { "Payload checksum (CRC) error", true },
+   { "Transfer FIFO overflow", false },
+   { "Reserved short packet data type detected", true },
+   { "Reserved long packet data type detected", true },
+   { "Incomplete long packet detected", false },
+   { "Frame sync error", false },
+   { "Line sync error", false },
+   { "DPHY recoverable synchronization error", true },
+   { "DPHY fatal error", false },
+   { "DPHY elastic FIFO overflow", false },
+   { "Inter-frame short packet discarded", true },
+   { "Inter-frame long packet discarded", true },
+   { "MIPI pktgen overflow", false },
+   { "MIPI pktgen data loss", false },
+   { "FIFO overflow", false },
+   { "Lane deskew", false },
+   { "SOT sync error", false },
+   { "HSIDLE detected", false }
+};
+
+s64 ipu6_isys_csi2_get_link_freq(struct ipu6_isys_csi2 *csi2)
+{
+   struct media_pad *src_pad;
+   struct v4l2_subdev *ext_sd;
+   struct device *dev;
+
+   if (!csi2)
+   return -EINVAL;
+
+   dev = >isys->adev->auxdev.dev;
+   src_pad = media_entity_remote_source_pad_unique(>asd.sd.entity);
+   if (IS_ERR(src_pad)) {
+   dev_err(dev, "can't get source pad of %s (%ld)\n",
+   csi2->asd.sd.name, PTR_ERR(src_pad));
+   return PTR_ERR(src_pad);
+   }
+
+   ext_sd = media_entity_to_v4l2_subdev(src_pad->entity);
+   if (WARN(!ext_sd, "Failed to get subdev for %s\n", csi2->asd.sd.name))
+   return -ENODEV;
+
+   return v4l2_get_link_freq(ext_sd->ctrl_handler, 0, 0);
+}
+
+static int csi2_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
+   struct v4l2_event_subscription *sub)
+{
+   struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(sd);
+   struct ipu6_isys_csi2 *csi2 = to_ipu6_isys_csi2(asd);
+   struct device *dev = >isys->adev->auxdev.dev;
+
+   dev_dbg(dev, "csi2 subscribe event(type %u id %u)\n",
+   sub->type, sub->id);
+
+   switch (sub->type) {
+   case V4L2_

[git:media_stage/master] media: intel/ipu6: input system video nodes and buffer queues

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: input system video nodes and buffer queues
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:03 2024 +0800

Register V4L2 video device and setup the VB2 queues to support video
capture. Video streaming callback will trigger the input system driver to
construct a input system stream configuration for firmware based on data
type and stream ID and then queue buffers to firmware to do capture.

Signed-off-by: Bingbu Cao 
Co-developed-by: Sakari Ailus 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys-queue.c |  809 +++
 drivers/media/pci/intel/ipu6/ipu6-isys-queue.h |   78 ++
 drivers/media/pci/intel/ipu6/ipu6-isys-video.c | 1249 
 drivers/media/pci/intel/ipu6/ipu6-isys-video.h |  132 +++
 4 files changed, 2268 insertions(+)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
new file mode 100644
index ..be37c0ba9711
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
@@ -0,0 +1,809 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013--2024 Intel Corporation
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu6-bus.h"
+#include "ipu6-fw-isys.h"
+#include "ipu6-isys.h"
+#include "ipu6-isys-video.h"
+
+static int queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
+  unsigned int *num_planes, unsigned int sizes[],
+  struct device *alloc_devs[])
+{
+   struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(q);
+   struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+   struct device *dev = >isys->adev->auxdev.dev;
+   u32 size = av->pix_fmt.sizeimage;
+
+   /* num_planes == 0: we're being called through VIDIOC_REQBUFS */
+   if (!*num_planes) {
+   sizes[0] = size;
+   } else if (sizes[0] < size) {
+   dev_err(dev, "%s: queue setup: size %u < %u\n",
+   av->vdev.name, sizes[0], size);
+   return -EINVAL;
+   }
+
+   *num_planes = 1;
+
+   return 0;
+}
+
+static int ipu6_isys_buf_prepare(struct vb2_buffer *vb)
+{
+   struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+   struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+   struct device *dev = >isys->adev->auxdev.dev;
+
+   dev_dbg(dev, "buffer: %s: configured size %u, buffer size %lu\n",
+   av->vdev.name, av->pix_fmt.sizeimage,
+   vb2_plane_size(vb, 0));
+
+   if (av->pix_fmt.sizeimage > vb2_plane_size(vb, 0))
+   return -EINVAL;
+
+   vb2_set_plane_payload(vb, 0, av->pix_fmt.bytesperline *
+ av->pix_fmt.height);
+   vb->planes[0].data_offset = 0;
+
+   return 0;
+}
+
+/*
+ * Queue a buffer list back to incoming or active queues. The buffers
+ * are removed from the buffer list.
+ */
+void ipu6_isys_buffer_list_queue(struct ipu6_isys_buffer_list *bl,
+unsigned long op_flags,
+enum vb2_buffer_state state)
+{
+   struct ipu6_isys_buffer *ib, *ib_safe;
+   unsigned long flags;
+   bool first = true;
+
+   if (!bl)
+   return;
+
+   WARN_ON_ONCE(!bl->nbufs);
+   WARN_ON_ONCE(op_flags & IPU6_ISYS_BUFFER_LIST_FL_ACTIVE &&
+op_flags & IPU6_ISYS_BUFFER_LIST_FL_INCOMING);
+
+   list_for_each_entry_safe(ib, ib_safe, >head, head) {
+   struct ipu6_isys_video *av;
+   struct vb2_buffer *vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+   struct ipu6_isys_queue *aq =
+   vb2_queue_to_isys_queue(vb->vb2_queue);
+   struct device *dev;
+
+   av = ipu6_isys_queue_to_video(aq);
+   dev = >isys->adev->auxdev.dev;
+   spin_lock_irqsave(>lock, flags);
+   list_del(>head);
+   if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_ACTIVE)
+   list_add(>head, >active);
+   else if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_INCOMING)
+   list_add_tail(>head, >incoming);
+   spin_unlock_irqrestore(>lock, flags);
+
+   if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_SET_STATE)
+   vb2_buffer_done(vb, state);
+
+   if (first) {
+   dev_dbg(dev,
+   "queue buf list %p flags %lx, s %d, %d bufs\n",
+   bl, op_flags, state, bl->nb

[git:media_stage/master] media: MAINTAINERS: add maintainers for Intel IPU6 input system driver

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: MAINTAINERS: add maintainers for Intel IPU6 input system driver
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:05 2024 +0800

Update MAINTAINERS file for Intel IPU6 input system driver.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

---

diff --git a/MAINTAINERS b/MAINTAINERS
index 037d065fb8bb..5a178aaf21b3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11005,6 +11005,16 @@ F: Documentation/admin-guide/media/ipu3_rcb.svg
 F: Documentation/userspace-api/media/v4l/metafmt-intel-ipu3.rst
 F: drivers/staging/media/ipu3/
 
+INTEL IPU6 INPUT SYSTEM DRIVER
+M: Sakari Ailus 
+M: Bingbu Cao 
+R: Tianshu Qiu 
+L: linux-me...@vger.kernel.org
+S: Maintained
+T: git git://linuxtv.org/media_tree.git
+F: Documentation/admin-guide/media/ipu6-isys.rst
+F: drivers/media/pci/intel/ipu6/
+
 INTEL ISHTP ECLITE DRIVER
 M: Sumesh K Naduvalath 
 L: platform-driver-...@vger.kernel.org


[git:media_stage/master] media: intel/ipu6: support line-based metadata capture support

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: support line-based metadata capture support
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:05 2024 +0800

Some camera sensor can output the embedded data in specific data type.
This patch adds the support for metadata capture in IPU6 ISYS driver.

Signed-off-by: Hongju Wang 
Signed-off-by: Bingbu Cao 
Co-developed-by: Sakari Ailus 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c   |   5 +
 drivers/media/pci/intel/ipu6/ipu6-isys-queue.c  |  45 ++--
 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c |   5 +
 drivers/media/pci/intel/ipu6/ipu6-isys-video.c  | 335 ++--
 drivers/media/pci/intel/ipu6/ipu6-isys-video.h  |  11 +-
 drivers/media/pci/intel/ipu6/ipu6-isys.c|   1 -
 6 files changed, 296 insertions(+), 106 deletions(-)

---

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index e8d93aa7fc6d..b9ce4324996d 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -42,6 +42,11 @@ static const u32 csi2_supported_codes[] = {
MEDIA_BUS_FMT_SGBRG8_1X8,
MEDIA_BUS_FMT_SGRBG8_1X8,
MEDIA_BUS_FMT_SRGGB8_1X8,
+   MEDIA_BUS_FMT_META_8,
+   MEDIA_BUS_FMT_META_10,
+   MEDIA_BUS_FMT_META_12,
+   MEDIA_BUS_FMT_META_16,
+   MEDIA_BUS_FMT_META_24,
0
 };
 
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c 
b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
index be37c0ba9711..11cd2c977abe 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
@@ -28,7 +28,7 @@ static int queue_setup(struct vb2_queue *q, unsigned int 
*num_buffers,
struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(q);
struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
struct device *dev = >isys->adev->auxdev.dev;
-   u32 size = av->pix_fmt.sizeimage;
+   u32 size = ipu6_isys_get_data_size(av);
 
/* num_planes == 0: we're being called through VIDIOC_REQBUFS */
if (!*num_planes) {
@@ -49,17 +49,17 @@ static int ipu6_isys_buf_prepare(struct vb2_buffer *vb)
struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
struct device *dev = >isys->adev->auxdev.dev;
+   u32 bytesperline = ipu6_isys_get_bytes_per_line(av);
+   u32 height = ipu6_isys_get_frame_height(av);
+   u32 size = ipu6_isys_get_data_size(av);
 
dev_dbg(dev, "buffer: %s: configured size %u, buffer size %lu\n",
-   av->vdev.name, av->pix_fmt.sizeimage,
-   vb2_plane_size(vb, 0));
+   av->vdev.name, size, vb2_plane_size(vb, 0));
 
-   if (av->pix_fmt.sizeimage > vb2_plane_size(vb, 0))
+   if (size > vb2_plane_size(vb, 0))
return -EINVAL;
 
-   vb2_set_plane_payload(vb, 0, av->pix_fmt.bytesperline *
- av->pix_fmt.height);
-   vb->planes[0].data_offset = 0;
+   vb2_set_plane_payload(vb, 0, bytesperline * height);
 
return 0;
 }
@@ -328,15 +328,12 @@ static void buf_queue(struct vb2_buffer *vb)
struct isys_fw_msgs *msg;
unsigned long flags;
dma_addr_t dma;
-   unsigned int i;
int ret;
 
dev_dbg(dev, "queue buffer %u for %s\n", vb->index, av->vdev.name);
 
-   for (i = 0; i < vb->num_planes; i++) {
-   dma = vb2_dma_contig_plane_dma_addr(vb, i);
-   dev_dbg(dev, "iova: plane %u iova %pad\n", i, );
-   }
+   dma = vb2_dma_contig_plane_dma_addr(vb, 0);
+   dev_dbg(dev, "iova: iova %pad\n", );
 
spin_lock_irqsave(>lock, flags);
list_add(>head, >incoming);
@@ -409,7 +406,7 @@ static int ipu6_isys_link_fmt_validate(struct 
ipu6_isys_queue *aq)
struct media_pad *remote_pad =
media_pad_remote_pad_first(av->vdev.entity.pads);
struct v4l2_subdev *sd;
-   u32 r_stream;
+   u32 r_stream, code;
int ret;
 
if (!remote_pad)
@@ -427,17 +424,19 @@ static int ipu6_isys_link_fmt_validate(struct 
ipu6_isys_queue *aq)
return ret;
}
 
-   if (format.width != av->pix_fmt.width ||
-   format.height != av->pix_fmt.height) {
-   dev_dbg(dev, "wrong width or height %ux%u (%ux%u expected)\n",
-   av->pix_fmt.width, av->pix_fmt.height,
-   format.width, format.height);
+   if (format.width != ipu6_isys_get_frame_width(av) ||
+   format.height != ipu6_isys_get_frame_height(av)) {
+   dev_err(dev, "wrong width or 

[git:media_stage/master] media: intel/ipu6: add Kconfig and Makefile

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: intel/ipu6: add Kconfig and Makefile
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:04 2024 +0800

Add Kconfig and Makefile for the IPU6 driver.

Signed-off-by: Bingbu Cao 
Signed-off-by: Andreas Helbech Kleist 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/intel/Kconfig   |  1 +
 drivers/media/pci/intel/Makefile  |  1 +
 drivers/media/pci/intel/ipu6/Kconfig  | 18 ++
 drivers/media/pci/intel/ipu6/Makefile | 23 +++
 4 files changed, 43 insertions(+)

---

diff --git a/drivers/media/pci/intel/Kconfig b/drivers/media/pci/intel/Kconfig
index ee4684159d3d..04cb3d253486 100644
--- a/drivers/media/pci/intel/Kconfig
+++ b/drivers/media/pci/intel/Kconfig
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 source "drivers/media/pci/intel/ipu3/Kconfig"
+source "drivers/media/pci/intel/ipu6/Kconfig"
 source "drivers/media/pci/intel/ivsc/Kconfig"
 
 config IPU_BRIDGE
diff --git a/drivers/media/pci/intel/Makefile b/drivers/media/pci/intel/Makefile
index f199a97e1d78..3a2cc6567159 100644
--- a/drivers/media/pci/intel/Makefile
+++ b/drivers/media/pci/intel/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_IPU_BRIDGE) += ipu-bridge.o
 obj-y  += ipu3/
 obj-y  += ivsc/
+obj-$(CONFIG_VIDEO_INTEL_IPU6) += ipu6/
diff --git a/drivers/media/pci/intel/ipu6/Kconfig 
b/drivers/media/pci/intel/ipu6/Kconfig
new file mode 100644
index ..154343080c82
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/Kconfig
@@ -0,0 +1,18 @@
+config VIDEO_INTEL_IPU6
+   tristate "Intel IPU6 driver"
+   depends on ACPI || COMPILE_TEST
+   depends on VIDEO_DEV
+   depends on X86 && X86_64 && HAS_DMA
+   select DMA_OPS
+   select IOMMU_IOVA
+   select VIDEO_V4L2_SUBDEV_API
+   select MEDIA_CONTROLLER
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_FWNODE
+   select IPU_BRIDGE
+   help
+ This is the 6th Gen Intel Image Processing Unit, found in Intel SoCs
+ and used for capturing images and video from camera sensors.
+
+ To compile this driver, say Y here! It contains 2 modules -
+ intel_ipu6 and intel_ipu6_isys.
diff --git a/drivers/media/pci/intel/ipu6/Makefile 
b/drivers/media/pci/intel/ipu6/Makefile
new file mode 100644
index ..a821b0a1567f
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/Makefile
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+intel-ipu6-y   := ipu6.o \
+   ipu6-bus.o \
+   ipu6-dma.o \
+   ipu6-mmu.o \
+   ipu6-buttress.o \
+   ipu6-cpd.o \
+   ipu6-fw-com.o
+
+obj-$(CONFIG_VIDEO_INTEL_IPU6) += intel-ipu6.o
+
+intel-ipu6-isys-y  := ipu6-isys.o \
+   ipu6-isys-csi2.o \
+   ipu6-fw-isys.o \
+   ipu6-isys-video.o \
+   ipu6-isys-queue.o \
+   ipu6-isys-subdev.o \
+   ipu6-isys-mcd-phy.o \
+   ipu6-isys-jsl-phy.o \
+   ipu6-isys-dwc-phy.o
+
+obj-$(CONFIG_VIDEO_INTEL_IPU6) += intel-ipu6-isys.o


[git:media_stage/master] media: Documentation: add Intel IPU6 ISYS driver admin-guide doc

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: Documentation: add Intel IPU6 ISYS driver admin-guide doc
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:06 2024 +0800

This document mainly describe the functionality of IPU6 and IPU6 isys
driver, and gives an example that how user can do imaging capture with
tools.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/admin-guide/media/ipu6-isys.rst  | 161 ++
 .../admin-guide/media/ipu6_isys_graph.svg  | 548 +
 Documentation/admin-guide/media/v4l-drivers.rst|   1 +
 3 files changed, 710 insertions(+)

---

diff --git a/Documentation/admin-guide/media/ipu6-isys.rst 
b/Documentation/admin-guide/media/ipu6-isys.rst
new file mode 100644
index ..0721e920b5e6
--- /dev/null
+++ b/Documentation/admin-guide/media/ipu6-isys.rst
@@ -0,0 +1,161 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. include:: 
+
+
+Intel Image Processing Unit 6 (IPU6) Input System driver
+
+
+Copyright |copy| 2023--2024 Intel Corporation
+
+Introduction
+
+
+This file documents the Intel IPU6 (6th generation Image Processing Unit)
+Input System (MIPI CSI2 receiver) drivers located under
+drivers/media/pci/intel/ipu6.
+
+The Intel IPU6 can be found in certain Intel SoCs but not in all SKUs:
+
+* Tiger Lake
+* Jasper Lake
+* Alder Lake
+* Raptor Lake
+* Meteor Lake
+
+Intel IPU6 is made up of two components - Input System (ISYS) and Processing
+System (PSYS).
+
+The Input System mainly works as MIPI CSI-2 receiver which receives and
+processes the image data from the sensors and outputs the frames to memory.
+
+There are 2 driver modules - intel-ipu6 and intel-ipu6-isys. intel-ipu6 is an
+IPU6 common driver which does PCI configuration, firmware loading and parsing,
+firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
+configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
+sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
+to the IPU6 ISYS through V4L2 sub-device sensor drivers.
+
+.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
+ information about the IPU6 hardware.
+
+Input system driver
+===
+
+The Input System driver mainly configures CSI-2 D-PHY, constructs the firmware
+stream configuration, sends commands to firmware, gets response from hardware
+and firmware and then returns buffers to user.  The ISYS is represented as
+several V4L2 sub-devices as well as video nodes.
+
+.. kernel-figure::  ipu6_isys_graph.svg
+   :alt: ipu6 isys media graph with multiple streams support
+
+   IPU6 ISYS media graph with multiple streams support
+
+The graph has been produced using the following command:
+
+.. code-block:: none
+
+   fdp -Gsplines=true -Tsvg < dot > dot.svg
+
+Capturing frames with IPU6 ISYS
+---
+
+IPU6 ISYS is used to capture frames from the camera sensors connected to the
+CSI2 ports. The supported input formats of ISYS are listed in table below:
+
+.. tabularcolumns:: |p{0.8cm}|p{4.0cm}|p{4.0cm}|
+
+.. flat-table::
+:header-rows: 1
+
+* - IPU6 ISYS supported input formats
+
+* - RGB565, RGB888
+
+* - UYVY8, YUYV8
+
+* - RAW8, RAW10, RAW12
+
+.. _ipu6_isys_capture_examples:
+
+Examples
+
+
+Here is an example of IPU6 ISYS raw capture on Dell XPS 9315 laptop. On this
+machine, ov01a10 sensor is connected to IPU ISYS CSI-2 port 2, which can
+generate images at sBGGR10 with resolution 1280x800.
+
+Using the media controller APIs, we can configure ov01a10 sensor by
+media-ctl [#f1]_ and yavta [#f2]_ to transmit frames to IPU6 ISYS.
+
+.. code-block:: none
+
+# Example 1 capture frame from ov01a10 camera sensor
+# This example assumes /dev/media0 as the IPU ISYS media device
+export MDEV=/dev/media0
+
+# Establish the link for the media devices using media-ctl
+media-ctl -d $MDEV -l "\"ov01a10 3-0036\":0 -> \"Intel IPU6 CSI2 2\":0[1]"
+
+# Set the format for the media devices
+media-ctl -d $MDEV -V "ov01a10:0 [fmt:SBGGR10/1280x800]"
+media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:0 [fmt:SBGGR10/1280x800]"
+media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:1 [fmt:SBGGR10/1280x800]"
+
+Once the media pipeline is configured, desired sensor specific settings
+(such as exposure and gain settings) can be set, using the yavta tool.
+
+e.g
+
+.. code-block:: none
+
+# and that ov01a10 sensor is connected to i2c bus 3 with address 0x36
+export SDEV=$(media-ctl -d $MDEV -e "ov01a10 3-0036")
+
+yavta -w 0x009e0903 400 $SDEV
+yavta -w 0x009e0913 1000 $SDEV
+yavta -w 0x009e0911 2000 $SDEV
+
+Once the desired sensor settin

[git:media_stage/master] media: Documentation: add documentation of Intel IPU6 driver and hardware overview

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: Documentation: add documentation of Intel IPU6 driver and 
hardware overview
Author:  Bingbu Cao 
Date:Wed Jan 31 17:51:07 2024 +0800

Add a documentation for an overview of IPU6 hardware and describe the main
the components of IPU6 driver.

Signed-off-by: Bingbu Cao 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/driver-api/media/drivers/index.rst |   1 +
 Documentation/driver-api/media/drivers/ipu6.rst  | 205 +++
 2 files changed, 206 insertions(+)

---

diff --git a/Documentation/driver-api/media/drivers/index.rst 
b/Documentation/driver-api/media/drivers/index.rst
index c4123a16b5f9..7f6f3dcd5c90 100644
--- a/Documentation/driver-api/media/drivers/index.rst
+++ b/Documentation/driver-api/media/drivers/index.rst
@@ -26,6 +26,7 @@ Video4Linux (V4L) drivers
vimc-devel
zoran
ccs/ccs
+   ipu6
 
 
 Digital TV drivers
diff --git a/Documentation/driver-api/media/drivers/ipu6.rst 
b/Documentation/driver-api/media/drivers/ipu6.rst
new file mode 100644
index ..6e1dd19b36fb
--- /dev/null
+++ b/Documentation/driver-api/media/drivers/ipu6.rst
@@ -0,0 +1,205 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==
+Intel IPU6 Driver
+==
+
+Author: Bingbu Cao 
+
+Overview
+=
+
+Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
+Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
+Meteor Lake. IPU6 consists of two major systems: Input System (ISYS) and
+Processing System (PSYS). IPU6 are visible on the PCI bus as a single device, 
it
+can be found by ``lspci``:
+
+``:00:05.0 Multimedia controller: Intel Corporation Device  (rev xx)``
+
+IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is
+visible for driver.
+
+Buttress
+=
+
+The IPU6 is connecting to the system fabric with Buttress which is enabling 
host
+driver to control the IPU6, it also allows IPU6 access the system memory to
+store and load frame pixel streams and any other metadata.
+
+Buttress mainly manages several system functionalities: power management,
+interrupt handling, firmware authentication and global timer sync.
+
+ISYS and PSYS Power flow
+
+
+IPU6 driver initialize the ISYS and PSYS power up or down request by setting 
the
+Buttress frequency control register for ISYS and PSYS
+(``IPU6_BUTTRESS_REG_IS_FREQ_CTL`` and ``IPU6_BUTTRESS_REG_PS_FREQ_CTL``) in
+function:
+
+.. c:function:: int ipu6_buttress_power(...)
+
+Buttress forwards the request to Punit, after Punit execute the power up flow,
+Buttress indicates driver that ISYS or PSYS is powered up by updating the power
+status registers.
+
+.. Note:: ISYS power up needs take place prior to PSYS power up, ISYS power 
down
+ needs take place after PSYS power down due to hardware limitation.
+
+Interrupt
+-
+
+IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered 
when
+ISYS, PSYS, Buttress event or error happen, driver can get the interrupt cause
+by reading the interrupt status register ``BUTTRESS_REG_ISR_STATUS``, driver
+clears the irq status and then calls specific ISYS or PSYS irq handler.
+
+.. c:function:: irqreturn_t ipu6_buttress_isr(int irq, ...)
+
+Security and firmware authentication
+-
+
+To address the IPU6 firmware security concerns, the IPU6 firmware needs to
+undergo an authentication process before it is allowed to executed on the IPU6
+internal processors. The IPU6 driver will work with Converged Security Engine
+(CSE) to complete authentication process. The CSE is responsible of
+authenticating the IPU6 firmware. The authenticated firmware binary is copied
+into an isolated memory region. Firmware authentication process is implemented
+by CSE following an IPC handshake with the IPU6 driver. There are some Buttress
+registers used by the CSE and the IPU6 driver to communicate with each other 
via
+IPC.
+
+.. c:function:: int ipu6_buttress_authenticate(...)
+
+Global timer sync
+-
+
+The IPU6 driver initiates a Hammock Harbor synchronization flow each time it
+starts camera operation. The IPU6 will synchronizes an internal counter in the
+Buttress with a copy of the SoC time, this counter maintains the up-to-date 
time
+until camera operation is stopped. The IPU6 driver can use this time counter to
+calibrate the timestamp based on the timestamp in response event from firmware.
+
+.. c:function:: int ipu6_buttress_start_tsc_sync(...)
+
+DMA and MMU
+
+
+The IPU6 has its own scalar processor where the firmware run at and an internal
+32-bit virtual address space. The IPU6 has MMU address translation hardware to
+allow that scalar processors to access the internal memory and external system
+memory through IPU6 virtual address. The address

[git:media_stage/master] media: uapi: v4l: Don't expose generic metadata formats to userspace

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: uapi: v4l: Don't expose generic metadata formats to userspace
Author:  Laurent Pinchart 
Date:Fri Apr 26 18:33:19 2024 +0300

The generic metadata pixel formats (V4L2_META_FMT_GENERIC_*) are meant
to be used in conjunction with device-specific media bus codes. Those
codes are work in progress and not available in the upstream kernel yet.
To make sure the generic metadata pixel formats won't be used by
userspace until we have the full infrastructure in place, keep their
definition private to the kernel for now.

Signed-off-by: Laurent Pinchart 
Signed-off-by: Hans Verkuil 

 include/uapi/linux/videodev2.h | 2 ++
 1 file changed, 2 insertions(+)

---

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 2f9762842313..fe6b67e83751 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -841,6 +841,7 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_RK_ISP1_PARAMS   v4l2_fourcc('R', 'K', '1', 'P') /* 
Rockchip ISP1 3A Parameters */
 #define V4L2_META_FMT_RK_ISP1_STAT_3A  v4l2_fourcc('R', 'K', '1', 'S') /* 
Rockchip ISP1 3A Statistics */
 
+#ifdef __KERNEL__
 /*
  * Line-based metadata formats. Remember to update v4l_fill_fmtdesc() when
  * adding new ones!
@@ -852,6 +853,7 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_GENERIC_CSI2_16  v4l2_fourcc('M', 'C', '1', 'G') /* 
16-bit CSI-2 packed 8-bit metadata */
 #define V4L2_META_FMT_GENERIC_CSI2_20  v4l2_fourcc('M', 'C', '1', 'K') /* 
20-bit CSI-2 packed 8-bit metadata */
 #define V4L2_META_FMT_GENERIC_CSI2_24  v4l2_fourcc('M', 'C', '1', 'O') /* 
24-bit CSI-2 packed 8-bit metadata */
+#endif
 
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe


[git:v4l-utils/master] cec-ctl: exit after reporting all cec devices with --list-devices

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: cec-ctl: exit after reporting all cec devices with --list-devices
Author:  Hans Verkuil 
Date:Mon Apr 29 08:55:23 2024 +0200

If the --list-devices option is used, then just exit after listing all
devices. Do not continue and report the driver info of /dev/cec0, that's
unexpected.

Signed-off-by: Hans Verkuil 

 utils/cec-ctl/cec-ctl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=6cea55784db171c184896c1b6390d97d9ccd0a15
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index 1a5f874e939e..8848a49d9b4c 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -2692,7 +2692,7 @@ int main(int argc, char **argv)
}
}
list_devices();
-   break;
+   return 0;
 
case OptTestStandbyWakeupCycle: {
static constexpr const char *arg_names[] = {


[git:v4l-utils/master] v4l2-ctl: --list-devices --verbose will list current input/output

2024-04-29 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-ctl: --list-devices --verbose will list current input/output
Author:  Hans Verkuil 
Date:Mon Apr 29 08:57:22 2024 +0200

It can be handy to see what the current input or output name is of
a given v4l2 device: that often gives useful information to determine
which device to use. So if --verbose is added to --list-devices, then
it will report that information in parenthesis after the device name.

Signed-off-by: Hans Verkuil 

 utils/v4l2-ctl/v4l2-ctl-common.cpp | 34 ++
 utils/v4l2-ctl/v4l2-ctl.cpp|  4 ++--
 utils/v4l2-ctl/v4l2-ctl.h  |  4 ++--
 3 files changed, 30 insertions(+), 12 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=0f80c102cf9bad691fac3263d7020d4ba159c78d
diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp 
b/utils/v4l2-ctl/v4l2-ctl-common.cpp
index 0370708b7482..1f9cd0fb6d98 100644
--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
@@ -286,6 +286,7 @@ static void list_devices()
int fd = open(file.c_str(), O_RDWR);
std::string bus_info;
std::string card;
+   std::string extra;
 
if (fd < 0)
continue;
@@ -305,8 +306,23 @@ static void list_devices()
card = mdi.driver;
}
} else {
+   unsigned idx;
+
bus_info = reinterpret_cast(vcap.bus_info);
card = reinterpret_cast(vcap.card);
+   if (!ioctl(fd, VIDIOC_G_INPUT, )) {
+   struct v4l2_input in = {
+   .index = idx
+   };
+   if (!ioctl(fd, VIDIOC_ENUMINPUT, ))
+   extra = std::string(" (input: ") + 
(const char *)in.name + ")";
+   } else if (!ioctl(fd, VIDIOC_G_OUTPUT, )) {
+   struct v4l2_output out = {
+   .index = idx
+   };
+   if (!ioctl(fd, VIDIOC_ENUMOUTPUT, ))
+   extra = std::string(" (output: ") + 
(const char *)out.name + ")";
+   }
}
close(fd);
if (err)
@@ -316,6 +332,8 @@ static void list_devices()
cards[bus_info] += "\t" + file;
if (!(links[file].empty()))
cards[bus_info] += " <- " + links[file];
+   if (verbose)
+   cards[bus_info] += extra;
cards[bus_info] += "\n";
}
for (const auto  : cards) {
@@ -1037,7 +1055,7 @@ static bool parse_next_subopt(char **subs, char **value)
return true;
 }
 
-void common_cmd(const std::string _bus_info, int ch, char *optarg)
+void common_cmd(int ch, char *optarg)
 {
char *value, *subs;
 
@@ -1084,12 +1102,6 @@ void common_cmd(const std::string _bus_info, int 
ch, char *optarg)
case OptSetPriority:
prio = static_cast(strtoul(optarg, nullptr, 
0));
break;
-   case OptListDevices:
-   if (media_bus_info.empty())
-   list_devices();
-   else
-   list_media_devices(media_bus_info);
-   break;
}
 }
 
@@ -1356,8 +1368,14 @@ void common_get(cv4l_fd &_fd)
}
 }
 
-void common_list(cv4l_fd )
+void common_list(const std::string _bus_info, cv4l_fd )
 {
+   if (options[OptListDevices]) {
+   if (media_bus_info.empty())
+   list_devices();
+   else
+   list_media_devices(media_bus_info);
+   }
if (options[OptListCtrls] || options[OptListCtrlsMenus]) {
list_controls(fd.g_fd(), options[OptListCtrlsMenus]);
}
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index eb172654add5..a64fa514b6e0 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -1276,7 +1276,7 @@ int main(int argc, char **argv)
common_usage();
return 1;
default:
-   common_cmd(media_bus_info, ch, optarg);
+   common_cmd(ch, optarg);
tuner_cmd(ch, optarg);
io_cmd(ch, optarg);
stds_cmd(ch, optarg);
@@ -1510,7 +1510,7 @@ int main(int argc, char **argv)
 
/* List options */
 
-   common_list(c_fd);
+   common_list(media_bus_info, c_fd);
io_li

[git:media_stage/master] media: mediatek: vcodec: fix possible unbalanced PM counter

2024-04-27 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: mediatek: vcodec: fix possible unbalanced PM counter
Author:  Eugen Hristev 
Date:Thu Dec 28 13:32:40 2023 +0200

It is possible that mtk_vcodec_enc_pw_on fails, and in that scenario
the PM counter is not incremented, and subsequent call to
mtk_vcodec_enc_pw_off decrements the counter, leading to a PM imbalance.
Fix by bailing out of venc_if_encode in the case when mtk_vcodec_enc_pw_on
fails.

Fixes: 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder 
Driver")
Signed-off-by: Eugen Hristev 
Reviewed-by: AngeloGioacchino Del Regno 

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Sebastian Fricke 
Signed-off-by: Hans Verkuil 

 drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c | 4 +++-
 drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h | 2 +-
 drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c   | 5 -
 3 files changed, 8 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c 
b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
index a22b7dfc656e..1a2b14a3e219 100644
--- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
+++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
@@ -58,13 +58,15 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev 
*mtkdev)
return 0;
 }
 
-void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm)
+int mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm)
 {
int ret;
 
ret = pm_runtime_resume_and_get(pm->dev);
if (ret)
dev_err(pm->dev, "pm_runtime_resume_and_get fail: %d", ret);
+
+   return ret;
 }
 
 void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm)
diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h 
b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
index 157ea08ba9e3..2e28f25e36cc 100644
--- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
+++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
@@ -10,7 +10,7 @@
 #include "mtk_vcodec_enc_drv.h"
 
 int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *dev);
-void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm);
+int mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c 
b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
index c402a686f3cb..e83747b8d69a 100644
--- a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
+++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
@@ -64,7 +64,9 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
ctx->dev->curr_ctx = ctx;
spin_unlock_irqrestore(>dev->irqlock, flags);
 
-   mtk_vcodec_enc_pw_on(>dev->pm);
+   ret = mtk_vcodec_enc_pw_on(>dev->pm);
+   if (ret)
+   goto venc_if_encode_pw_on_err;
mtk_vcodec_enc_clock_on(>dev->pm);
ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf,
  bs_buf, result);
@@ -75,6 +77,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
ctx->dev->curr_ctx = NULL;
spin_unlock_irqrestore(>dev->irqlock, flags);
 
+venc_if_encode_pw_on_err:
mtk_venc_unlock(ctx);
return ret;
 }


[git:media_stage/master] media: cec: return -ENODEV instead of -ENXIO if unregistered

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: cec: return -ENODEV instead of -ENXIO if unregistered
Author:  Hans Verkuil 
Date:Fri Feb 23 10:08:47 2024 +0100

If the CEC device is unregistered, then an attempt to open
the device node should result in an -ENODEV error instead of
-ENXIO.

Document this as well in cec-func-open.rst.

This is consistent with the error code returned by other
file operations such as ioctl.

Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/cec/cec-func-open.rst | 4 ++--
 drivers/media/cec/core/cec-core.c   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

---

diff --git a/Documentation/userspace-api/media/cec/cec-func-open.rst 
b/Documentation/userspace-api/media/cec/cec-func-open.rst
index d86563a34b9e..125c8ac6680b 100644
--- a/Documentation/userspace-api/media/cec/cec-func-open.rst
+++ b/Documentation/userspace-api/media/cec/cec-func-open.rst
@@ -70,5 +70,5 @@ include:
 ``ENOMEM``
 Insufficient kernel memory was available.
 
-``ENXIO``
-No device corresponding to this device special file exists.
+``ENODEV``
+Device not found or was removed.
diff --git a/drivers/media/cec/core/cec-core.c 
b/drivers/media/cec/core/cec-core.c
index 5a54db839e5d..6f940df0230c 100644
--- a/drivers/media/cec/core/cec-core.c
+++ b/drivers/media/cec/core/cec-core.c
@@ -62,12 +62,12 @@ int cec_get_device(struct cec_devnode *devnode)
 */
mutex_lock(>lock);
/*
-* return ENXIO if the cec device has been removed
+* return ENODEV if the cec device has been removed
 * already or if it is not registered anymore.
 */
if (!devnode->registered) {
mutex_unlock(>lock);
-   return -ENXIO;
+   return -ENODEV;
}
/* and increase the device refcount */
get_device(>dev);


[git:media_stage/master] media: v4l2-core: hold videodev_lock until dev reg, finishes

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l2-core: hold videodev_lock until dev reg, finishes
Author:  Hans Verkuil 
Date:Fri Feb 23 09:45:36 2024 +0100

After the new V4L2 device node was registered, some additional
initialization was done before the device node was marked as
'registered'. During the time between creating the device node
and marking it as 'registered' it was possible to open the
device node, which would return -ENODEV since the 'registered'
flag was not yet set.

Hold the videodev_lock mutex from just before the device node
is registered until the 'registered' flag is set. Since v4l2_open
will take the same lock, it will wait until this registration
process is finished. This resolves this race condition.

Signed-off-by: Hans Verkuil 
Reviewed-by: Sakari Ailus 
Cc:   # for vi4.18 and up

 drivers/media/v4l2-core/v4l2-dev.c | 3 +++
 1 file changed, 3 insertions(+)

---

diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
b/drivers/media/v4l2-core/v4l2-dev.c
index e39e9742fdb5..be2ba7ca5de2 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -1039,8 +1039,10 @@ int __video_register_device(struct video_device *vdev,
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
vdev->dev.parent = vdev->dev_parent;
dev_set_name(>dev, "%s%d", name_base, vdev->num);
+   mutex_lock(_lock);
ret = device_register(>dev);
if (ret < 0) {
+   mutex_unlock(_lock);
pr_err("%s: device_register failed\n", __func__);
goto cleanup;
}
@@ -1060,6 +1062,7 @@ int __video_register_device(struct video_device *vdev,
 
/* Part 6: Activate this minor. The char device can now be used. */
set_bit(V4L2_FL_REGISTERED, >flags);
+   mutex_unlock(_lock);
 
return 0;
 


[git:media_stage/master] media: dt-bindings: nxp,imx8-jpeg: Add clocks entries

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dt-bindings: nxp,imx8-jpeg: Add clocks entries
Author:  Fabio Estevam 
Date:Mon Apr 8 15:06:53 2024 +0300

The JPEG decoder/encoder present in iMX8QXP and iMX8QM SoCs need
the PER and IPG clocks to be functional, so add the clock entries.

This also fixes the following schema warning:

imx8qm-apalis-eval.dtb: jpegdec@5840: 'assigned-clock-rates', 
'assigned-clocks', 'clock-names', 'clocks' do not match any of the regexes: 
'pinctrl-[0-9]+'
from schema $id: http://devicetree.org/schemas/media/nxp,imx8-jpeg.yaml#

Signed-off-by: Fabio Estevam 
Signed-off-by: Mirela Rabulea 
Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Hans Verkuil 

 Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml | 11 +++
 1 file changed, 11 insertions(+)

---

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
index 3d9d1db37040..2be30c5fdc83 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml
@@ -31,6 +31,11 @@ properties:
   reg:
 maxItems: 1
 
+  clocks:
+items:
+  - description: AXI DMA engine clock for fetching JPEG bitstream from 
memory (per)
+  - description: IP bus clock for register access (ipg)
+
   interrupts:
 description: |
   There are 4 slots available in the IP, which the driver may use
@@ -49,6 +54,7 @@ properties:
 required:
   - compatible
   - reg
+  - clocks
   - interrupts
   - power-domains
 
@@ -56,12 +62,15 @@ additionalProperties: false
 
 examples:
   - |
+#include 
 #include 
 #include 
 
 jpegdec: jpegdec@5840 {
 compatible = "nxp,imx8qxp-jpgdec";
 reg = <0x5840 0x0005 >;
+clocks = <_jpeg_dec_lpcg IMX_LPCG_CLK_0>,
+ <_jpeg_dec_lpcg IMX_LPCG_CLK_4>;
 interrupts = ,
  ,
  ,
@@ -76,6 +85,8 @@ examples:
 jpegenc: jpegenc@5845 {
 compatible = "nxp,imx8qm-jpgenc", "nxp,imx8qxp-jpgenc";
 reg = <0x5845 0x0005 >;
+clocks = <_jpeg_enc_lpcg IMX_LPCG_CLK_0>,
+ <_jpeg__lpcg IMX_LPCG_CLK_4>;
 interrupts = ,
  ,
  ,


[git:media_stage/master] media: stk1160: fix bounds checking in stk1160_copy_video()

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: stk1160: fix bounds checking in stk1160_copy_video()
Author:  Dan Carpenter 
Date:Mon Apr 22 12:32:44 2024 +0300

The subtract in this condition is reversed.  The ->length is the length
of the buffer.  The ->bytesused is how many bytes we have copied thus
far.  When the condition is reversed that means the result of the
subtraction is always negative but since it's unsigned then the result
is a very high positive value.  That means the overflow check is never
true.

Additionally, the ->bytesused doesn't actually work for this purpose
because we're not writing to "buf->mem + buf->bytesused".  Instead, the
math to calculate the destination where we are writing is a bit
involved.  You calculate the number of full lines already written,
multiply by two, skip a line if necessary so that we start on an odd
numbered line, and add the offset into the line.

To fix this buffer overflow, just take the actual destination where we
are writing, if the offset is already out of bounds print an error and
return.  Otherwise, write up to buf->length bytes.

Fixes: 9cb2173e6ea8 ("[media] media: Add stk1160 new driver (easycap 
replacement)")
Signed-off-by: Dan Carpenter 
Reviewed-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/usb/stk1160/stk1160-video.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/usb/stk1160/stk1160-video.c 
b/drivers/media/usb/stk1160/stk1160-video.c
index 366f0e4a5dc0..e79c45db60ab 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -99,7 +99,7 @@ void stk1160_buffer_done(struct stk1160 *dev)
 static inline
 void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
 {
-   int linesdone, lineoff, lencopy;
+   int linesdone, lineoff, lencopy, offset;
int bytesperline = dev->width * 2;
struct stk1160_buffer *buf = dev->isoc_ctl.buf;
u8 *dst = buf->mem;
@@ -139,8 +139,13 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int 
len)
 * Check if we have enough space left in the buffer.
 * In that case, we force loop exit after copy.
 */
-   if (lencopy > buf->bytesused - buf->length) {
-   lencopy = buf->bytesused - buf->length;
+   offset = dst - (u8 *)buf->mem;
+   if (offset > buf->length) {
+   dev_warn_ratelimited(dev->dev, "out of bounds offset\n");
+   return;
+   }
+   if (lencopy > buf->length - offset) {
+   lencopy = buf->length - offset;
remain = lencopy;
}
 
@@ -182,8 +187,13 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int 
len)
 * Check if we have enough space left in the buffer.
 * In that case, we force loop exit after copy.
 */
-   if (lencopy > buf->bytesused - buf->length) {
-   lencopy = buf->bytesused - buf->length;
+   offset = dst - (u8 *)buf->mem;
+   if (offset > buf->length) {
+   dev_warn_ratelimited(dev->dev, "offset out of 
bounds\n");
+   return;
+   }
+   if (lencopy > buf->length - offset) {
+   lencopy = buf->length - offset;
remain = lencopy;
}
 


[git:media_stage/master] doc: media: v4l/func-open.rst: ENXIO should be ENODEV

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: doc: media: v4l/func-open.rst: ENXIO should be ENODEV
Author:  Hans Verkuil 
Date:Fri Feb 23 10:15:20 2024 +0100

The error that V4L2 returns when an attempt is made to open an
unregisted device node is ENODEV, no ENXIO. Update the documentation.

Signed-off-by: Hans Verkuil 

 Documentation/userspace-api/media/v4l/func-open.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

---

diff --git a/Documentation/userspace-api/media/v4l/func-open.rst 
b/Documentation/userspace-api/media/v4l/func-open.rst
index ba23ff1e45dd..be3808cbf876 100644
--- a/Documentation/userspace-api/media/v4l/func-open.rst
+++ b/Documentation/userspace-api/media/v4l/func-open.rst
@@ -65,8 +65,8 @@ EBUSY
 The driver does not support multiple opens and the device is already
 in use.
 
-ENXIO
-No device corresponding to this device special file exists.
+ENODEV
+Device not found or was removed.
 
 ENOMEM
 Not enough kernel memory was available to complete the request.


[git:media_stage/master] media: videobuf2: improve max_num_buffers sanity checks

2024-04-25 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: videobuf2: improve max_num_buffers sanity checks
Author:  Hans Verkuil 
Date:Mon Mar 18 15:29:33 2024 +0100

Ensure that drivers set max_num_buffers to a value >= 32.
For now there is no reason for drivers to request a lower
limit and doing so might potentially cause userspace issues.
Note that the old check of > MAX_BUFFER_INDEX was pointless
since q->max_num_buffers was already limited to MAX_BUFFER_INDEX
or less.

Also add a sanity check in __vb2_init_fileio(), returning
-ENOSPC if a driver returns more than 32 buffers from
VIDIOC_REQBUFS with count = q->min_reqbufs_allocation.

The vb2_fileio_data struct only supports up to 32 buffers,
so we need a check there.

Signed-off-by: Hans Verkuil 

 drivers/media/common/videobuf2/videobuf2-core.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c 
b/drivers/media/common/videobuf2/videobuf2-core.c
index 0b2b48e1b2df..358f1fe42975 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -2584,7 +2584,7 @@ int vb2_core_queue_init(struct vb2_queue *q)
WARN_ON(!q->ops->buf_queue))
return -EINVAL;
 
-   if (WARN_ON(q->max_num_buffers > MAX_BUFFER_INDEX) ||
+   if (WARN_ON(q->max_num_buffers < VB2_MAX_FRAME) ||
WARN_ON(q->min_queued_buffers > q->max_num_buffers))
return -EINVAL;
 
@@ -2855,6 +2855,12 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
ret = vb2_core_reqbufs(q, fileio->memory, 0, >count);
if (ret)
goto err_kfree;
+   /* vb2_fileio_data supports max VB2_MAX_FRAME buffers */
+   if (fileio->count > VB2_MAX_FRAME) {
+   dprintk(q, 1, "fileio: more than VB2_MAX_FRAME buffers 
requested\n");
+   ret = -ENOSPC;
+   goto err_reqbufs;
+   }
 
/*
 * Userspace can never add or delete buffers later, so there


[git:media_stage/master] Merge tag 'tags/media-next-uvc-20240419' of git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git into media_stage

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: Merge tag 'tags/media-next-uvc-20240419' of 
git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git into 
media_stage
Author:  Hans Verkuil 
Date:Mon Apr 22 13:32:03 2024 +0200

uvcvideo fixes:

Ricardo Ribalda (3):
  media: uvcvideo: Add quirk for Logitech Rally Bar
  media: uvcvideo: Fix power line control for Shine-Optics Camera
  media: uvcvideo: Disable autosuspend for Insta360 Link

Signed-off-by: Hans Verkuil 
From: Laurent Pinchart 
Link: 
https://patchwork.linuxtv.org/project/linux-media/patch/20240419125149.ga2...@pendragon.ideasonboard.com/

---



[git:media_stage/master] media: imx335: Describe CCI struct member

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Describe CCI struct member
Author:  Umang Jain 
Date:Mon Apr 22 16:12:47 2024 +0530

Add description for 'struct regmap *cci' member of struct imx335.

This will fix the following compile-time warning:
warning: Function parameter or struct member 'cci' not described in 'imx335'

Signed-off-by: Umang Jain 
Reviewed-by: Kieran Bingham 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/imx335.c | 1 +
 1 file changed, 1 insertion(+)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index c43e57455704..990d74214cc2 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -176,6 +176,7 @@ struct imx335_mode {
  * @pad: Media pad. Only one pad supported
  * @reset_gpio: Sensor reset gpio
  * @supplies: Regulator supplies to handle power control
+ * @cci: CCI register map
  * @inclk: Sensor input clock
  * @ctrl_handler: V4L2 control handler
  * @link_freq_ctrl: Pointer to link frequency control


[git:media_stage/master] media: mc: mark the media devnode as registered from the, start

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: mc: mark the media devnode as registered from the, start
Author:  Hans Verkuil 
Date:Fri Feb 23 09:46:19 2024 +0100

First the media device node was created, and if successful it was
marked as 'registered'. This leaves a small race condition where
an application can open the device node and get an error back
because the 'registered' flag was not yet set.

Change the order: first set the 'registered' flag, then actually
register the media device node. If that fails, then clear the flag.

Signed-off-by: Hans Verkuil 
Acked-by: Sakari Ailus 
Reviewed-by: Laurent Pinchart 
Fixes: cf4b9211b568 ("[media] media: Media device node support")
Cc: sta...@vger.kernel.org
Signed-off-by: Sakari Ailus 

 drivers/media/mc/mc-devnode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c
index 7f67825c8757..318e267e798e 100644
--- a/drivers/media/mc/mc-devnode.c
+++ b/drivers/media/mc/mc-devnode.c
@@ -245,15 +245,14 @@ int __must_check media_devnode_register(struct 
media_device *mdev,
kobject_set_name(>cdev.kobj, "media%d", devnode->minor);
 
/* Part 3: Add the media and char device */
+   set_bit(MEDIA_FLAG_REGISTERED, >flags);
ret = cdev_device_add(>cdev, >dev);
if (ret < 0) {
+   clear_bit(MEDIA_FLAG_REGISTERED, >flags);
pr_err("%s: cdev_device_add failed\n", __func__);
goto cdev_add_error;
}
 
-   /* Part 4: Activate this minor. The char device can now be used. */
-   set_bit(MEDIA_FLAG_REGISTERED, >flags);
-
return 0;
 
 cdev_add_error:


[git:media_stage/master] media: v4l: Don't turn on privacy LED if streamon fails

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l: Don't turn on privacy LED if streamon fails
Author:  Sakari Ailus 
Date:Wed Apr 10 12:58:44 2024 +0300

Turn on the privacy LED only if streamon succeeds. This can be done after
enabling streaming on the sensor.

Fixes: b6e10ff6c23d ("media: v4l2-core: Make the v4l2-core code enable/disable 
the privacy LED if present")
Signed-off-by: Sakari Ailus 
Reviewed-by: Hans de Goede 
Reviewed-by: Tomi Valkeinen 
Reviewed-by: Umang Jain 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-subdev.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

---

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 0f590c9dc6ca..2d67ec54569a 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -442,15 +442,6 @@ static int call_s_stream(struct v4l2_subdev *sd, int 
enable)
if (WARN_ON(!!sd->enabled_streams == !!enable))
return 0;
 
-#if IS_REACHABLE(CONFIG_LEDS_CLASS)
-   if (!IS_ERR_OR_NULL(sd->privacy_led)) {
-   if (enable)
-   led_set_brightness(sd->privacy_led,
-  sd->privacy_led->max_brightness);
-   else
-   led_set_brightness(sd->privacy_led, 0);
-   }
-#endif
ret = sd->ops->video->s_stream(sd, enable);
 
if (!enable && ret < 0) {
@@ -458,9 +449,20 @@ static int call_s_stream(struct v4l2_subdev *sd, int 
enable)
ret = 0;
}
 
-   if (!ret)
+   if (!ret) {
sd->enabled_streams = enable ? BIT(0) : 0;
 
+#if IS_REACHABLE(CONFIG_LEDS_CLASS)
+   if (!IS_ERR_OR_NULL(sd->privacy_led)) {
+   if (enable)
+   led_set_brightness(sd->privacy_led,
+  
sd->privacy_led->max_brightness);
+   else
+   led_set_brightness(sd->privacy_led, 0);
+   }
+#endif
+   }
+
return ret;
 }
 


[git:media_stage/master] media: cadence: csi2rx: configure DPHY before starting source stream

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: cadence: csi2rx: configure DPHY before starting source stream
Author:  Pratyush Yadav 
Date:Fri Feb 23 13:53:01 2024 +0530

When the source device is operating above 1.5 Gbps per lane, it needs to
send the Skew Calibration Sequence before sending any HS data. If the
DPHY is initialized after the source stream is started, then it might
miss the sequence and not be able to receive data properly. Move the
start of source subdev to the end of the sequence to make sure
everything is ready to receive data before the source starts streaming.

Signed-off-by: Pratyush Yadav 
Fixes: 3295cf1241d3 ("media: cadence: Add support for external dphy")
Tested-by: Julien Massot 
Tested-by: Changhuang Liang 
Reviewed-by: Julien Massot 
Reviewed-by: Changhuang Liang 
Signed-off-by: Jai Luthra 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/platform/cadence/cdns-csi2rx.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

---

diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
b/drivers/media/platform/cadence/cdns-csi2rx.c
index 2d7b0508cc9a..6f7d27a48eff 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -239,10 +239,6 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 
writel(reg, csi2rx->base + CSI2RX_STATIC_CFG_REG);
 
-   ret = v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, true);
-   if (ret)
-   goto err_disable_pclk;
-
/* Enable DPHY clk and data lanes. */
if (csi2rx->dphy) {
reg = CSI2RX_DPHY_CL_EN | CSI2RX_DPHY_CL_RST;
@@ -252,6 +248,13 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
}
 
writel(reg, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG);
+
+   ret = csi2rx_configure_ext_dphy(csi2rx);
+   if (ret) {
+   dev_err(csi2rx->dev,
+   "Failed to configure external DPHY: %d\n", ret);
+   goto err_disable_pclk;
+   }
}
 
/*
@@ -291,14 +294,9 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 
reset_control_deassert(csi2rx->sys_rst);
 
-   if (csi2rx->dphy) {
-   ret = csi2rx_configure_ext_dphy(csi2rx);
-   if (ret) {
-   dev_err(csi2rx->dev,
-   "Failed to configure external DPHY: %d\n", ret);
-   goto err_disable_sysclk;
-   }
-   }
+   ret = v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, true);
+   if (ret)
+   goto err_disable_sysclk;
 
clk_disable_unprepare(csi2rx->p_clk);
 
@@ -312,6 +310,10 @@ err_disable_pixclk:
clk_disable_unprepare(csi2rx->pixel_clk[i - 1]);
}
 
+   if (csi2rx->dphy) {
+   writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG);
+   phy_power_off(csi2rx->dphy);
+   }
 err_disable_pclk:
clk_disable_unprepare(csi2rx->p_clk);
 


[git:media_stage/master] media: ti: j721e-csi2rx: Fix races while restarting DMA

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ti: j721e-csi2rx: Fix races while restarting DMA
Author:  Jai Luthra 
Date:Fri Feb 23 13:53:02 2024 +0530

After the frame is submitted to DMA, it may happen that the submitted
list is not updated soon enough, and the DMA callback is triggered
before that.

This can lead to kernel crashes, so move everything in a single
lock/unlock section to prevent such races.

Fixes: b4a3d877dc92 ("media: ti: Add CSI2RX support for J721E")
Signed-off-by: Jai Luthra 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c 
b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
index 6da83d0cffaa..22442fce7607 100644
--- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
+++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
@@ -786,15 +786,14 @@ static void ti_csi2rx_buffer_queue(struct vb2_buffer *vb)
dev_warn(csi->dev,
 "Failed to drain DMA. Next frame might be 
bogus\n");
 
+   spin_lock_irqsave(>lock, flags);
ret = ti_csi2rx_start_dma(csi, buf);
if (ret) {
-   dev_err(csi->dev, "Failed to start DMA: %d\n", ret);
-   spin_lock_irqsave(>lock, flags);
vb2_buffer_done(>vb.vb2_buf, VB2_BUF_STATE_ERROR);
dma->state = TI_CSI2RX_DMA_IDLE;
spin_unlock_irqrestore(>lock, flags);
+   dev_err(csi->dev, "Failed to start DMA: %d\n", ret);
} else {
-   spin_lock_irqsave(>lock, flags);
list_add_tail(>list, >submitted);
spin_unlock_irqrestore(>lock, flags);
}


[git:media_stage/master] media: dt-bindings: sony,imx290: Allow props from video-interface-devices

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dt-bindings: sony,imx290: Allow props from 
video-interface-devices
Author:  Alexander Stein 
Date:Fri Mar 1 09:40:07 2024 +0100

Allow properties from video-interface-devices. This aligns the bindings
to sony,imx415.yaml. Changes inspired by commit e2e73ed46c395 ("media:
dt-bindings: sony,imx415: Allow props from video-interface-devices")

Signed-off-by: Alexander Stein 
Reviewed-by: Laurent Pinchart 
Acked-by: Conor Dooley 
Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

---

diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml 
b/Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml
index a531badc16c9..bf05ca48601a 100644
--- a/Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/sony,imx290.yaml
@@ -23,6 +23,9 @@ description: |-
   is treated the same as this as it was the original compatible string.
   imx290llr is the mono version of the sensor.
 
+allOf:
+  - $ref: /schemas/media/video-interface-devices.yaml#
+
 properties:
   compatible:
 oneOf:
@@ -101,7 +104,7 @@ required:
   - vdddo-supply
   - port
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   - |


[git:media_stage/master] media: dt-bindings: i2c: use absolute path to other schema

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dt-bindings: i2c: use absolute path to other schema
Author:  Alexander Stein 
Date:Fri Mar 1 09:40:08 2024 +0100

Absolute path to other DT schema is preferred over relative one.

Signed-off-by: Alexander Stein 
Acked-by: Krzysztof Kozlowski 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 Documentation/devicetree/bindings/media/i2c/galaxycore,gc0308.yaml | 2 +-
 Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml | 2 +-
 Documentation/devicetree/bindings/media/i2c/sony,imx214.yaml   | 2 +-
 Documentation/devicetree/bindings/media/i2c/sony,imx415.yaml   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

---

diff --git a/Documentation/devicetree/bindings/media/i2c/galaxycore,gc0308.yaml 
b/Documentation/devicetree/bindings/media/i2c/galaxycore,gc0308.yaml
index f81e7daed67b..2bf1a81feaf4 100644
--- a/Documentation/devicetree/bindings/media/i2c/galaxycore,gc0308.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/galaxycore,gc0308.yaml
@@ -15,7 +15,7 @@ description: |
   They include an ISP capable of auto exposure and auto white balance.
 
 allOf:
-  - $ref: ../video-interface-devices.yaml#
+  - $ref: /schemas/media/video-interface-devices.yaml#
 
 properties:
   compatible:
diff --git a/Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml 
b/Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml
index 1726ecca4c77..9eac588de0bc 100644
--- a/Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/galaxycore,gc2145.yaml
@@ -19,7 +19,7 @@ description:
   either through a parallel interface or through MIPI CSI-2.
 
 allOf:
-  - $ref: ../video-interface-devices.yaml#
+  - $ref: /schemas/media/video-interface-devices.yaml#
 
 properties:
   compatible:
diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx214.yaml 
b/Documentation/devicetree/bindings/media/i2c/sony,imx214.yaml
index 60903da84e1f..0162eec8ca99 100644
--- a/Documentation/devicetree/bindings/media/i2c/sony,imx214.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/sony,imx214.yaml
@@ -16,7 +16,7 @@ description: |
   maximum throughput of 1.2Gbps/lane.
 
 allOf:
-  - $ref: ../video-interface-devices.yaml#
+  - $ref: /schemas/media/video-interface-devices.yaml#
 
 properties:
   compatible:
diff --git a/Documentation/devicetree/bindings/media/i2c/sony,imx415.yaml 
b/Documentation/devicetree/bindings/media/i2c/sony,imx415.yaml
index 9a00dab2e8a3..34962c5c7006 100644
--- a/Documentation/devicetree/bindings/media/i2c/sony,imx415.yaml
+++ b/Documentation/devicetree/bindings/media/i2c/sony,imx415.yaml
@@ -18,7 +18,7 @@ description: |-
   available via CSI-2 serial data output (two or four lanes).
 
 allOf:
-  - $ref: ../video-interface-devices.yaml#
+  - $ref: /schemas/media/video-interface-devices.yaml#
 
 properties:
   compatible:


[git:media_stage/master] media: staging: ipu3-imgu: Update firmware path

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: staging: ipu3-imgu: Update firmware path
Author:  Sakari Ailus 
Date:Thu Apr 11 09:54:04 2024 +0300

Use the current firmware path in linux-firmware repository. Check the
older paths still in order to avoid causing issues to the users.

Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/staging/media/ipu3/ipu3-css-fw.c | 4 +++-
 drivers/staging/media/ipu3/ipu3-css-fw.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

---

diff --git a/drivers/staging/media/ipu3/ipu3-css-fw.c 
b/drivers/staging/media/ipu3/ipu3-css-fw.c
index 2b659b0ccca1..37482b626c3c 100644
--- a/drivers/staging/media/ipu3/ipu3-css-fw.c
+++ b/drivers/staging/media/ipu3/ipu3-css-fw.c
@@ -117,7 +117,9 @@ int imgu_css_fw_init(struct imgu_css *css)
unsigned int i, j, binary_nr;
int r;
 
-   r = request_firmware(>fw, IMGU_FW_NAME_20161208, css->dev);
+   r = request_firmware(>fw, IMGU_FW_NAME_IPU_20161208, css->dev);
+   if (r == -ENOENT)
+   r = request_firmware(>fw, IMGU_FW_NAME_20161208, css->dev);
if (r == -ENOENT)
r = request_firmware(>fw, IMGU_FW_NAME, css->dev);
if (r)
diff --git a/drivers/staging/media/ipu3/ipu3-css-fw.h 
b/drivers/staging/media/ipu3/ipu3-css-fw.h
index f9403da75785..c956aa21df25 100644
--- a/drivers/staging/media/ipu3/ipu3-css-fw.h
+++ b/drivers/staging/media/ipu3/ipu3-css-fw.h
@@ -9,6 +9,8 @@
 #define IMGU_FW_NAME   "intel/ipu3-fw.bin"
 #define IMGU_FW_NAME_20161208  \
"intel/irci_irci_ecr-master_20161208_0213_20170112_1500.bin"
+#define IMGU_FW_NAME_IPU_20161208  \
+   "intel/ipu/irci_irci_ecr-master_20161208_0213_20170112_1500.bin"
 
 typedef u32 imgu_fw_ptr;
 


[git:media_stage/master] media: imx335: Parse fwnode properties

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Parse fwnode properties
Author:  Kieran Bingham 
Date:Sun Apr 14 19:36:17 2024 +0530

Call the V4L2 fwnode device parser to handle controls that are
standardised by the framework.

Signed-off-by: Kieran Bingham 
Signed-off-by: Umang Jain 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/imx335.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index fbf6bf662028..f6e42bef12a7 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -1227,10 +1227,16 @@ static int imx335_init_controls(struct imx335 *imx335)
 {
struct v4l2_ctrl_handler *ctrl_hdlr = >ctrl_handler;
const struct imx335_mode *mode = imx335->cur_mode;
+   struct v4l2_fwnode_device_properties props;
u32 lpfr;
int ret;
 
-   ret = v4l2_ctrl_handler_init(ctrl_hdlr, 7);
+   ret = v4l2_fwnode_device_parse(imx335->dev, );
+   if (ret)
+   return ret;
+
+   /* v4l2_fwnode_device_properties can add two more controls */
+   ret = v4l2_ctrl_handler_init(ctrl_hdlr, 9);
if (ret)
return ret;
 
@@ -1295,6 +1301,8 @@ static int imx335_init_controls(struct imx335 *imx335)
if (imx335->hblank_ctrl)
imx335->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
+   v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, _ctrl_ops, );
+
if (ctrl_hdlr->error) {
dev_err(imx335->dev, "control init failed: %d\n",
ctrl_hdlr->error);


[git:media_stage/master] media: imx335: Use V4L2 CCI for accessing sensor registers

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Use V4L2 CCI for accessing sensor registers
Author:  Umang Jain 
Date:Sun Apr 14 19:36:18 2024 +0530

Use the new comon CCI register access helpers to replace the private
register access helpers in the imx335 driver.

Select V4L2_CCI_I2C Kconfig option which the imx335 driver now
depends on.

Signed-off-by: Umang Jain 
Reviewed-by: Kieran Bingham 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/Kconfig  |   1 +
 drivers/media/i2c/imx335.c | 595 -
 2 files changed, 266 insertions(+), 330 deletions(-)

---

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 56f276b920ab..8d248b9c9562 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -195,6 +195,7 @@ config VIDEO_IMX334
 config VIDEO_IMX335
tristate "Sony IMX335 sensor support"
depends on OF_GPIO
+   select V4L2_CCI_I2C
help
  This is a Video4Linux2 sensor driver for the Sony
  IMX335 camera.
diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index f6e42bef12a7..18b481edd4e4 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -11,62 +11,108 @@
 #include 
 #include 
 #include 
+#include 
 
+#include 
 #include 
 #include 
 #include 
 
 /* Streaming Mode */
-#define IMX335_REG_MODE_SELECT 0x3000
-#define IMX335_MODE_STANDBY0x01
-#define IMX335_MODE_STREAMING  0x00
+#define IMX335_REG_MODE_SELECT CCI_REG8(0x3000)
+#define IMX335_MODE_STANDBY0x01
+#define IMX335_MODE_STREAMING  0x00
 
-/* Data Lanes */
-#define IMX335_LANEMODE0x3a01
-#define IMX335_2LANE   1
-#define IMX335_4LANE   3
+/* Group hold register */
+#define IMX335_REG_HOLDCCI_REG8(0x3001)
+
+#define IMX335_REG_MASTER_MODE CCI_REG8(0x3002)
+#define IMX335_REG_BCWAIT_TIME CCI_REG8(0x300c)
+#define IMX335_REG_CPWAIT_TIME CCI_REG8(0x300d)
+#define IMX335_REG_WINMODE CCI_REG8(0x3018)
+#define IMX335_REG_HTRIMMING_START CCI_REG16_LE(0x302c)
+#define IMX335_REG_HNUMCCI_REG8(0x302e)
 
 /* Lines per frame */
-#define IMX335_REG_LPFR0x3030
+#define IMX335_REG_VMAXCCI_REG24_LE(0x3030)
 
-/* Chip ID */
-#define IMX335_REG_ID  0x3912
-#define IMX335_ID  0x00
+#define IMX335_REG_OPB_SIZE_V  CCI_REG8(0x304c)
+#define IMX335_REG_ADBIT   CCI_REG8(0x3050)
+#define IMX335_REG_Y_OUT_SIZE  CCI_REG16_LE(0x3056)
+
+#define IMX335_REG_SHUTTER CCI_REG24_LE(0x3058)
+#define IMX335_EXPOSURE_MIN1
+#define IMX335_EXPOSURE_OFFSET 9
+#define IMX335_EXPOSURE_STEP   1
+#define IMX335_EXPOSURE_DEFAULT0x0648
 
-/* Exposure control */
-#define IMX335_REG_SHUTTER 0x3058
-#define IMX335_EXPOSURE_MIN1
-#define IMX335_EXPOSURE_OFFSET 9
-#define IMX335_EXPOSURE_STEP   1
-#define IMX335_EXPOSURE_DEFAULT0x0648
+#define IMX335_REG_AREA3_ST_ADR_1  CCI_REG16_LE(0x3074)
+#define IMX335_REG_AREA3_WIDTH_1   CCI_REG16_LE(0x3076)
 
 /* Analog gain control */
-#define IMX335_REG_AGAIN   0x30e8
-#define IMX335_AGAIN_MIN   0
-#define IMX335_AGAIN_MAX   240
-#define IMX335_AGAIN_STEP  1
-#define IMX335_AGAIN_DEFAULT   0
+#define IMX335_REG_AGAIN   CCI_REG8(0x30e8)
+#define IMX335_AGAIN_MIN   0
+#define IMX335_AGAIN_MAX   240
+#define IMX335_AGAIN_STEP  1
+#define IMX335_AGAIN_DEFAULT   0
 
-/* Group hold register */
-#define IMX335_REG_HOLD0x3001
+#define IMX335_REG_TPG_TESTCLKEN   CCI_REG8(0x3148)
+
+#define IMX335_REG_INCLKSEL1   CCI_REG16_LE(0x314c)
+#define IMX335_REG_INCLKSEL2   CCI_REG8(0x315a)
+#define IMX335_REG_INCLKSEL3   CCI_REG8(0x3168)
+#define IMX335_REG_INCLKSEL4   CCI_REG8(0x316a)
+
+#define IMX335_REG_MDBIT   CCI_REG8(0x319d)
+#define IMX335_REG_SYSMODE CCI_REG8(0x319e)
+
+#define IMX335_REG_XVS_XHS_DRV CCI_REG8(0x31a1)
 
 /* Test pattern generator */
-#define IMX335_REG_TPG 0x329e
-#define IMX335_TPG_ALL_000 0
-#define IMX335_TPG_ALL_FFF 1
-#define IMX335_TPG_ALL_555 2
-#define IMX335_TPG_ALL_AAA 3
-#define IMX335_TPG_TOG_555_AAA 4
-#define IMX335_TPG_TOG_AAA_555 5
-#define IMX335_TPG_TOG_000_555 6
-#define IMX335_TPG_TOG_555_000 7
-#define IMX335_TPG_TOG_000_FFF 8
-#define IMX335_TPG_TOG_FFF_000 9
-#define IMX335_TPG_H_COLOR_BARS 10
-#define IMX335_TPG_V_COLOR_BARS 11
+#define IMX335_REG_TPG_DIG_CLP_MODECCI_REG8(0x3280)
+#define IMX335_REG_TPG_EN_DUOUTCCI_REG8(0x329c)
+#define IMX335_REG_TPG CCI_REG8(0x329e)
+#define IMX335_TPG_ALL_000 0
+#define IMX335_T

[git:media_stage/master] media: imx335: Use integer values for size registers

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Use integer values for size registers
Author:  Umang Jain 
Date:Sun Apr 14 19:36:19 2024 +0530

Consider integer values for registers that are related to various
sizes in the register map. This helps in improving the overall
readability.

No functional changes intended in this patch.

Signed-off-by: Umang Jain 
Reviewed-by: Tommaso Merciai 
Reviewed-by: Kieran Bingham 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/imx335.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index 18b481edd4e4..d07c7de5d22d 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -255,12 +255,12 @@ static const struct cci_reg_sequence 
mode_2592x1940_regs[] = {
{ IMX335_REG_MODE_SELECT, IMX335_MODE_STANDBY },
{ IMX335_REG_MASTER_MODE, 0x00 },
{ IMX335_REG_WINMODE, 0x04 },
-   { IMX335_REG_HTRIMMING_START, 0x0180 },
-   { IMX335_REG_HNUM, 0x0a20 },
-   { IMX335_REG_Y_OUT_SIZE, 0x0794 },
-   { IMX335_REG_AREA3_ST_ADR_1, 0x00b0 },
-   { IMX335_REG_AREA3_WIDTH_1, 0x0f58 },
-   { IMX335_REG_OPB_SIZE_V, 0x00 },
+   { IMX335_REG_HTRIMMING_START, 384 },
+   { IMX335_REG_HNUM, 2592 },
+   { IMX335_REG_Y_OUT_SIZE, 1940 },
+   { IMX335_REG_AREA3_ST_ADR_1, 176 },
+   { IMX335_REG_AREA3_WIDTH_1, 3928 },
+   { IMX335_REG_OPB_SIZE_V, 0 },
{ IMX335_REG_XVS_XHS_DRV, 0x00 },
{ CCI_REG8(0x3288), 0x21 },
{ CCI_REG8(0x328a), 0x02 },


[git:media_stage/master] media: imx335: Limit analogue gain value

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Limit analogue gain value
Author:  Umang Jain 
Date:Sun Apr 14 19:36:21 2024 +0530

The sensor gain (both analog and digital) are controlled by a
single gain value where:
- 0dB to 30dB correspond to analog gain
- 30.3dB to 72dB correspond to digital gain
  (with 0.3dB step)

Hence, limit the analogue gain value to 100.
For digital gain, support can be added later if needed.

Signed-off-by: Umang Jain 
Reviewed-by: Kieran Bingham 
Reviewed-by: Tommaso Merciai 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/imx335.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index b206d17a57bc..c43e57455704 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -49,10 +49,10 @@
 #define IMX335_REG_AREA3_ST_ADR_1  CCI_REG16_LE(0x3074)
 #define IMX335_REG_AREA3_WIDTH_1   CCI_REG16_LE(0x3076)
 
-/* Analog gain control */
-#define IMX335_REG_AGAIN   CCI_REG8(0x30e8)
+/* Analog and Digital gain control */
+#define IMX335_REG_GAINCCI_REG8(0x30e8)
 #define IMX335_AGAIN_MIN   0
-#define IMX335_AGAIN_MAX   240
+#define IMX335_AGAIN_MAX   100
 #define IMX335_AGAIN_STEP  1
 #define IMX335_AGAIN_DEFAULT   0
 
@@ -479,7 +479,7 @@ static int imx335_update_exp_gain(struct imx335 *imx335, 
u32 exposure, u32 gain)
cci_write(imx335->cci, IMX335_REG_HOLD, 1, );
cci_write(imx335->cci, IMX335_REG_VMAX, lpfr, );
cci_write(imx335->cci, IMX335_REG_SHUTTER, shutter, );
-   cci_write(imx335->cci, IMX335_REG_AGAIN, gain, );
+   cci_write(imx335->cci, IMX335_REG_GAIN, gain, );
/*
 * Unconditionally attempt to release the hold, but track the
 * error if the unhold itself fails.
@@ -1183,6 +1183,14 @@ static int imx335_init_controls(struct imx335 *imx335)
 IMX335_EXPOSURE_STEP,
 IMX335_EXPOSURE_DEFAULT);
 
+   /*
+* The sensor has an analog gain and a digital gain, both controlled
+* through a single gain value, expressed in 0.3dB increments. Values
+* from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values
+* up to 72.0dB (240) add further digital gain. Limit the range to
+* analog gain only, support for digital gain can be added separately
+* if needed.
+*/
imx335->again_ctrl = v4l2_ctrl_new_std(ctrl_hdlr,
   _ctrl_ops,
   V4L2_CID_ANALOGUE_GAIN,


[git:media_stage/master] media: v4l2-ctrls: Return handler error in creating new fwnode properties

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: v4l2-ctrls: Return handler error in creating new fwnode 
properties
Author:  Sakari Ailus 
Date:Fri Apr 12 15:56:49 2024 +0300

If the control handler is in an error state, return that error immediately
in v4l2_ctrl_new_fwnode_properties(). Effectively the change here is that
the same error code (handler's error) is returned in all cases instead of
possibly returning -EINVAL.

Signed-off-by: Sakari Ailus 
Reviewed-by: Umang Jain 
Signed-off-by: Hans Verkuil 

 drivers/media/v4l2-core/v4l2-ctrls-core.c | 3 +++
 1 file changed, 3 insertions(+)

---

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c 
b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 9a09a981e1d9..c59dd691f79f 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2567,6 +2567,9 @@ int v4l2_ctrl_new_fwnode_properties(struct 
v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ctrl_ops,
const struct v4l2_fwnode_device_properties 
*p)
 {
+   if (hdl->error)
+   return hdl->error;
+
if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) {
u32 orientation_ctrl;
 


[git:media_stage/master] media: ov2680: Do not fail if data-lanes property is absent

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Do not fail if data-lanes property is absent
Author:  Fabio Estevam 
Date:Sun Apr 14 18:09:06 2024 -0300

Since commit 63b0cd30b78e ("media: ov2680: Add bus-cfg / endpoint
property verification") the ov2680 driver no longer probes when the
'data-lanes' property is absent.

The OV2680 sensor has only one data lane, so there is no need for
describing it the devicetree.

Remove the unnecessary data-lanes property check.

Suggested-by: Sakari Ailus 
Fixes: 63b0cd30b78e ("media: ov2680: Add bus-cfg / endpoint property 
verification")
Signed-off-by: Fabio Estevam 
Reviewed-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 7 ---
 1 file changed, 7 deletions(-)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index a857763c7984..4577a8977c85 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -1116,13 +1116,6 @@ static int ov2680_parse_dt(struct ov2680_dev *sensor)
sensor->pixel_rate = sensor->link_freq[0] * 2;
do_div(sensor->pixel_rate, 10);
 
-   /* Verify bus cfg */
-   if (bus_cfg.bus.mipi_csi2.num_data_lanes != 1) {
-   ret = dev_err_probe(dev, -EINVAL,
-   "only a 1-lane CSI2 config is supported");
-   goto out_free_bus_cfg;
-   }
-
if (!bus_cfg.nr_of_link_frequencies) {
dev_warn(dev, "Consider passing 'link-frequencies' in DT\n");
goto skip_link_freq_validation;


[git:media_stage/master] media: ov2680: Stop sending more data then requested

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Stop sending more data then requested
Author:  Hans de Goede 
Date:Mon Apr 15 15:03:14 2024 +0200

There is no reason to send OV2680_END_MARGIN extra columns on top of
the mode width and the same for sending extra lines over the mode height.

This sending of extra lines/columns was inherited from the atomisp
ov2680 driver, it is unclear why this was done and this complicates
adding V4L2_CID_VBLANK support, so remove it.

Reviewed-by: Kieran Bingham 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 4577a8977c85..ad140d9d4c2e 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -86,9 +86,6 @@
 #define OV2680_PIXELS_PER_LINE 1704
 #define OV2680_LINES_PER_FRAME 1294
 
-/* If possible send 16 extra rows / lines to the ISP as padding */
-#define OV2680_END_MARGIN  16
-
 /* Max exposure time is VTS - 8 */
 #define OV2680_INTEGRATION_TIME_MARGIN 8
 
@@ -359,11 +356,9 @@ static void ov2680_calc_mode(struct ov2680_dev *sensor)
sensor->mode.v_start = (sensor->mode.crop.top +
(sensor->mode.crop.height - height) / 2) & ~1;
sensor->mode.h_end =
-   min(sensor->mode.h_start + width + OV2680_END_MARGIN - 1,
-   OV2680_NATIVE_WIDTH - 1);
+   min(sensor->mode.h_start + width - 1, OV2680_NATIVE_WIDTH - 1);
sensor->mode.v_end =
-   min(sensor->mode.v_start + height + OV2680_END_MARGIN - 1,
-   OV2680_NATIVE_HEIGHT - 1);
+   min(sensor->mode.v_start + height - 1, OV2680_NATIVE_HEIGHT - 
1);
sensor->mode.h_output_size = orig_width;
sensor->mode.v_output_size = orig_height;
sensor->mode.hts = OV2680_PIXELS_PER_LINE;


[git:media_stage/master] media: imx335: Support 2 or 4 lane operation modes

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Support 2 or 4 lane operation modes
Author:  Kieran Bingham 
Date:Sun Apr 14 19:36:16 2024 +0530

The IMX335 can support both 2 and 4 lane configurations.
Extend the driver to configure the lane mode accordingly.
Update the pixel rate depending on the number of lanes in use.

Signed-off-by: Kieran Bingham 
Signed-off-by: Umang Jain 
Reviewed-by: Tommaso Merciai 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 
[hverkuil: fixup missing : in @lane_mode kerneldoc line]

 drivers/media/i2c/imx335.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index dab6d080bc4c..fbf6bf662028 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -21,6 +21,11 @@
 #define IMX335_MODE_STANDBY0x01
 #define IMX335_MODE_STREAMING  0x00
 
+/* Data Lanes */
+#define IMX335_LANEMODE0x3a01
+#define IMX335_2LANE   1
+#define IMX335_4LANE   3
+
 /* Lines per frame */
 #define IMX335_REG_LPFR0x3030
 
@@ -147,6 +152,7 @@ struct imx335_mode {
  * @exp_ctrl: Pointer to exposure control
  * @again_ctrl: Pointer to analog gain control
  * @vblank: Vertical blanking in lines
+ * @lane_mode: Mode for number of connected data lanes
  * @cur_mode: Pointer to current selected sensor mode
  * @mutex: Mutex for serializing sensor controls
  * @link_freq_bitmap: Menu bitmap for link_freq_ctrl
@@ -171,6 +177,7 @@ struct imx335 {
struct v4l2_ctrl *again_ctrl;
};
u32 vblank;
+   u32 lane_mode;
const struct imx335_mode *cur_mode;
struct mutex mutex;
unsigned long link_freq_bitmap;
@@ -936,6 +943,11 @@ static int imx335_start_streaming(struct imx335 *imx335)
return ret;
}
 
+   /* Configure lanes */
+   ret = imx335_write_reg(imx335, IMX335_LANEMODE, 1, imx335->lane_mode);
+   if (ret)
+   return ret;
+
/* Setup handler will write actual exposure and gain */
ret =  __v4l2_ctrl_handler_setup(imx335->sd.ctrl_handler);
if (ret) {
@@ -1096,7 +1108,14 @@ static int imx335_parse_hw_config(struct imx335 *imx335)
if (ret)
return ret;
 
-   if (bus_cfg.bus.mipi_csi2.num_data_lanes != IMX335_NUM_DATA_LANES) {
+   switch (bus_cfg.bus.mipi_csi2.num_data_lanes) {
+   case 2:
+   imx335->lane_mode = IMX335_2LANE;
+   break;
+   case 4:
+   imx335->lane_mode = IMX335_4LANE;
+   break;
+   default:
dev_err(imx335->dev,
"number of CSI2 data lanes %d is not supported\n",
bus_cfg.bus.mipi_csi2.num_data_lanes);


[git:media_stage/master] media: ov2680: Add vblank control

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Add vblank control
Author:  Hans de Goede 
Date:Mon Apr 15 15:03:16 2024 +0200

Add vblank control to allow changing the framerate /
higher exposure values.

Reviewed-by: Kieran Bingham 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 56 --
 1 file changed, 49 insertions(+), 7 deletions(-)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index ad04e7d5f1f4..5847122dc01b 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -75,6 +75,8 @@
 #define OV2680_ACTIVE_START_TOP8
 #define OV2680_MIN_CROP_WIDTH  2
 #define OV2680_MIN_CROP_HEIGHT 2
+#define OV2680_MIN_VBLANK  4
+#define OV2680_MAX_VBLANK  0x
 
 /* Fixed pre-div of 1/2 */
 #define OV2680_PLL_PREDIV0 2
@@ -84,7 +86,7 @@
 
 /* 66MHz pixel clock: 66MHz / 1704 * 1294 = 30fps */
 #define OV2680_PIXELS_PER_LINE 1704
-#define OV2680_LINES_PER_FRAME 1294
+#define OV2680_LINES_PER_FRAME_30FPS   1294
 
 /* Max exposure time is VTS - 8 */
 #define OV2680_INTEGRATION_TIME_MARGIN 8
@@ -127,6 +129,7 @@ struct ov2680_ctrls {
struct v4l2_ctrl *test_pattern;
struct v4l2_ctrl *link_freq;
struct v4l2_ctrl *pixel_rate;
+   struct v4l2_ctrl *vblank;
 };
 
 struct ov2680_mode {
@@ -394,8 +397,7 @@ static int ov2680_set_mode(struct ov2680_dev *sensor)
  sensor->mode.v_output_size, );
cci_write(sensor->regmap, OV2680_REG_TIMING_HTS,
  OV2680_PIXELS_PER_LINE, );
-   cci_write(sensor->regmap, OV2680_REG_TIMING_VTS,
- OV2680_LINES_PER_FRAME, );
+   /* VTS gets set by the vblank ctrl */
cci_write(sensor->regmap, OV2680_REG_ISP_X_WIN, 0, );
cci_write(sensor->regmap, OV2680_REG_ISP_Y_WIN, 0, );
cci_write(sensor->regmap, OV2680_REG_X_INC, inc, );
@@ -469,6 +471,15 @@ static int ov2680_exposure_set(struct ov2680_dev *sensor, 
u32 exp)
 NULL);
 }
 
+static int ov2680_exposure_update_range(struct ov2680_dev *sensor)
+{
+   int exp_max = sensor->mode.fmt.height + sensor->ctrls.vblank->val -
+ OV2680_INTEGRATION_TIME_MARGIN;
+
+   return __v4l2_ctrl_modify_range(sensor->ctrls.exposure, 0, exp_max,
+   1, exp_max);
+}
+
 static int ov2680_stream_enable(struct ov2680_dev *sensor)
 {
int ret;
@@ -635,7 +646,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *try_fmt;
const struct v4l2_rect *crop;
unsigned int width, height;
-   int ret = 0;
+   int def, max, ret = 0;
 
crop = __ov2680_get_pad_crop(sensor, sd_state, format->pad,
 format->which);
@@ -664,6 +675,21 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
sensor->mode.fmt = format->format;
ov2680_calc_mode(sensor);
 
+   /* vblank range is height dependent adjust and reset to default */
+   max = OV2680_MAX_VBLANK - height;
+   def = OV2680_LINES_PER_FRAME_30FPS - height;
+   ret = __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV2680_MIN_VBLANK,
+  max, 1, def);
+   if (ret)
+   goto unlock;
+
+   ret = __v4l2_ctrl_s_ctrl(sensor->ctrls.vblank, def);
+   if (ret)
+   goto unlock;
+
+   /* exposure range depends on vts which may have changed */
+   ret = ov2680_exposure_update_range(sensor);
+
 unlock:
mutex_unlock(>lock);
 
@@ -833,6 +859,13 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)
struct ov2680_dev *sensor = to_ov2680_dev(sd);
int ret;
 
+   /* Update exposure range on vblank changes */
+   if (ctrl->id == V4L2_CID_VBLANK) {
+   ret = ov2680_exposure_update_range(sensor);
+   if (ret)
+   return ret;
+   }
+
/* Only apply changes to the controls if the device is powered up */
if (!pm_runtime_get_if_in_use(sensor->sd.dev)) {
ov2680_set_bayer_order(sensor, >mode.fmt);
@@ -855,6 +888,10 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_TEST_PATTERN:
ret = ov2680_test_pattern_set(sensor, ctrl->val);
break;
+   case V4L2_CID_VBLANK:
+   ret = cci_write(sensor->regmap, OV2680_REG_TIMING_VTS,
+   sensor->mode.fmt.height + ctrl->val, NULL);
+   break;
default:
ret = -EINVAL;
break;
@@ -913,8 +950,7 @@ static int ov2680_v4l2_reg

[git:media_stage/master] media: ov2680: Add camera orientation and sensor rotation controls

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Add camera orientation and sensor rotation controls
Author:  Hans de Goede 
Date:Mon Apr 15 15:03:18 2024 +0200

Add camera orientation and sensor rotation controls using
the v4l2_fwnode_device_parse() and v4l2_ctrl_new_fwnode_properties()
helpers.

Reviewed-by: Kieran Bingham 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 7 +++
 1 file changed, 7 insertions(+)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 03df910f7564..3ae0ea58668d 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -957,6 +957,7 @@ static int ov2680_v4l2_register(struct ov2680_dev *sensor)
const struct v4l2_ctrl_ops *ops = _ctrl_ops;
struct ov2680_ctrls *ctrls = >ctrls;
struct v4l2_ctrl_handler *hdl = >handler;
+   struct v4l2_fwnode_device_properties props;
int def, max, ret = 0;
 
v4l2_i2c_subdev_init(>sd, client, _subdev_ops);
@@ -1004,6 +1005,12 @@ static int ov2680_v4l2_register(struct ov2680_dev 
*sensor)
ctrls->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK,
  def, def, 1, def);
 
+   ret = v4l2_fwnode_device_parse(sensor->dev, );
+   if (ret)
+   goto cleanup_entity;
+
+   v4l2_ctrl_new_fwnode_properties(hdl, ops, );
+
if (hdl->error) {
ret = hdl->error;
goto cleanup_entity;


[git:media_stage/master] media: ov2680: Add hblank control

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Add hblank control
Author:  Hans de Goede 
Date:Mon Apr 15 15:03:17 2024 +0200

Add hblank control so that the sensor has all the mandatory
controls for libcamera.

Reviewed-by: Kieran Bingham 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 12 
 1 file changed, 12 insertions(+)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 5847122dc01b..03df910f7564 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -130,6 +130,7 @@ struct ov2680_ctrls {
struct v4l2_ctrl *link_freq;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *vblank;
+   struct v4l2_ctrl *hblank;
 };
 
 struct ov2680_mode {
@@ -689,6 +690,12 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
 
/* exposure range depends on vts which may have changed */
ret = ov2680_exposure_update_range(sensor);
+   if (ret)
+   goto unlock;
+
+   /* adjust hblank value for new width */
+   def = OV2680_PIXELS_PER_LINE - width;
+   ret = __v4l2_ctrl_modify_range(sensor->ctrls.hblank, def, def, 1, def);
 
 unlock:
mutex_unlock(>lock);
@@ -993,6 +1000,10 @@ static int ov2680_v4l2_register(struct ov2680_dev *sensor)
ctrls->vblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VBLANK,
  OV2680_MIN_VBLANK, max, 1, def);
 
+   def = OV2680_PIXELS_PER_LINE - OV2680_DEFAULT_WIDTH;
+   ctrls->hblank = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HBLANK,
+ def, def, 1, def);
+
if (hdl->error) {
ret = hdl->error;
goto cleanup_entity;
@@ -1001,6 +1012,7 @@ static int ov2680_v4l2_register(struct ov2680_dev *sensor)
ctrls->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
ctrls->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+   ctrls->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
sensor->sd.ctrl_handler = hdl;
 


[git:media_stage/master] media: ov2680: Drop hts, vts ov2680_mode struct members

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Drop hts, vts ov2680_mode struct members
Author:  Hans de Goede 
Date:Mon Apr 15 15:03:15 2024 +0200

The hts, vts ov2680_mode struct members always contain
OV2680_PIXELS_PER_LINE resp. OV2680_LINES_PER_FRAME,
drop them and simply use these values directly.

Reviewed-by: Kieran Bingham 
Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/ov2680.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index ad140d9d4c2e..ad04e7d5f1f4 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -140,8 +140,6 @@ struct ov2680_mode {
u16 v_end;
u16 h_output_size;
u16 v_output_size;
-   u16 hts;
-   u16 vts;
 };
 
 struct ov2680_dev {
@@ -361,8 +359,6 @@ static void ov2680_calc_mode(struct ov2680_dev *sensor)
min(sensor->mode.v_start + height - 1, OV2680_NATIVE_HEIGHT - 
1);
sensor->mode.h_output_size = orig_width;
sensor->mode.v_output_size = orig_height;
-   sensor->mode.hts = OV2680_PIXELS_PER_LINE;
-   sensor->mode.vts = OV2680_LINES_PER_FRAME;
 }
 
 static int ov2680_set_mode(struct ov2680_dev *sensor)
@@ -397,9 +393,9 @@ static int ov2680_set_mode(struct ov2680_dev *sensor)
cci_write(sensor->regmap, OV2680_REG_VERTICAL_OUTPUT_SIZE,
  sensor->mode.v_output_size, );
cci_write(sensor->regmap, OV2680_REG_TIMING_HTS,
- sensor->mode.hts, );
+ OV2680_PIXELS_PER_LINE, );
cci_write(sensor->regmap, OV2680_REG_TIMING_VTS,
- sensor->mode.vts, );
+ OV2680_LINES_PER_FRAME, );
cci_write(sensor->regmap, OV2680_REG_ISP_X_WIN, 0, );
cci_write(sensor->regmap, OV2680_REG_ISP_Y_WIN, 0, );
cci_write(sensor->regmap, OV2680_REG_X_INC, inc, );


[git:media_stage/master] media: imx335: Fix active area height discrepency

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: imx335: Fix active area height discrepency
Author:  Umang Jain 
Date:Sun Apr 14 19:36:20 2024 +0530

The imx335 reports a recommended pixel area of - 2592x1944.
The driver supported mode however limits it to height=1940.

Fix the height discrepency by correctly the value of height
(with updates to vblank and mode registers).

The IMX335_REG_HTRIMMING should also be corrected to the start
offset(i.e. 48) instead of chosing a abritrary crop start of 384.

Signed-off-by: Umang Jain 
Reviewed-by: Kieran Bingham 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/imx335.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

---

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index d07c7de5d22d..b206d17a57bc 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -255,9 +255,9 @@ static const struct cci_reg_sequence mode_2592x1940_regs[] 
= {
{ IMX335_REG_MODE_SELECT, IMX335_MODE_STANDBY },
{ IMX335_REG_MASTER_MODE, 0x00 },
{ IMX335_REG_WINMODE, 0x04 },
-   { IMX335_REG_HTRIMMING_START, 384 },
+   { IMX335_REG_HTRIMMING_START, 48 },
{ IMX335_REG_HNUM, 2592 },
-   { IMX335_REG_Y_OUT_SIZE, 1940 },
+   { IMX335_REG_Y_OUT_SIZE, 1944 },
{ IMX335_REG_AREA3_ST_ADR_1, 176 },
{ IMX335_REG_AREA3_WIDTH_1, 3928 },
{ IMX335_REG_OPB_SIZE_V, 0 },
@@ -408,10 +408,10 @@ static const u32 imx335_mbus_codes[] = {
 /* Supported sensor mode configurations */
 static const struct imx335_mode supported_mode = {
.width = 2592,
-   .height = 1940,
+   .height = 1944,
.hblank = 342,
-   .vblank = 2560,
-   .vblank_min = 2560,
+   .vblank = 2556,
+   .vblank_min = 2556,
.vblank_max = 133060,
.pclk = 39600,
.reg_list = {


[git:media_stage/master] media: hi556: Add support for reset GPIO

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: hi556: Add support for reset GPIO
Author:  Hans de Goede 
Date:Mon Apr 15 15:10:36 2024 +0200

On some ACPI platforms, such as Chromebooks the ACPI methods to
change the power-state (_PS0 and _PS3) fully take care of powering
on/off the sensor.

On other ACPI platforms, such as e.g. various HP models with IPU6 +
hi556 sensor, the sensor driver must control the reset GPIO itself.

Add support for having the driver control an optional reset GPIO.

Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/hi556.c | 45 -
 1 file changed, 44 insertions(+), 1 deletion(-)

---

diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
index c54cd49e56a1..e084f7888e29 100644
--- a/drivers/media/i2c/hi556.c
+++ b/drivers/media/i2c/hi556.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -633,6 +634,9 @@ struct hi556 {
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *exposure;
 
+   /* GPIOs, clocks, etc. */
+   struct gpio_desc *reset_gpio;
+
/* Current mode */
const struct hi556_mode *cur_mode;
 
@@ -1276,6 +1280,25 @@ static void hi556_remove(struct i2c_client *client)
mutex_destroy(>mutex);
 }
 
+static int hi556_suspend(struct device *dev)
+{
+   struct v4l2_subdev *sd = dev_get_drvdata(dev);
+   struct hi556 *hi556 = to_hi556(sd);
+
+   gpiod_set_value_cansleep(hi556->reset_gpio, 1);
+   return 0;
+}
+
+static int hi556_resume(struct device *dev)
+{
+   struct v4l2_subdev *sd = dev_get_drvdata(dev);
+   struct hi556 *hi556 = to_hi556(sd);
+
+   gpiod_set_value_cansleep(hi556->reset_gpio, 0);
+   usleep_range(5000, 5500);
+   return 0;
+}
+
 static int hi556_probe(struct i2c_client *client)
 {
struct hi556 *hi556;
@@ -1295,12 +1318,24 @@ static int hi556_probe(struct i2c_client *client)
 
v4l2_i2c_subdev_init(>sd, client, _subdev_ops);
 
+   hi556->reset_gpio = devm_gpiod_get_optional(>dev, "reset",
+   GPIOD_OUT_HIGH);
+   if (IS_ERR(hi556->reset_gpio))
+   return dev_err_probe(>dev, PTR_ERR(hi556->reset_gpio),
+"failed to get reset GPIO\n");
+
full_power = acpi_dev_state_d0(>dev);
if (full_power) {
+   /* Ensure non ACPI managed resources are enabled */
+   ret = hi556_resume(>dev);
+   if (ret)
+   return dev_err_probe(>dev, ret,
+"failed to power on sensor\n");
+
ret = hi556_identify_module(hi556);
if (ret) {
dev_err(>dev, "failed to find sensor: %d", ret);
-   return ret;
+   goto probe_error_power_off;
}
}
 
@@ -1345,9 +1380,16 @@ probe_error_v4l2_ctrl_handler_free:
v4l2_ctrl_handler_free(hi556->sd.ctrl_handler);
mutex_destroy(>mutex);
 
+probe_error_power_off:
+   if (full_power)
+   hi556_suspend(>dev);
+
return ret;
 }
 
+static DEFINE_RUNTIME_DEV_PM_OPS(hi556_pm_ops, hi556_suspend, hi556_resume,
+NULL);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id hi556_acpi_ids[] = {
{"INT3537"},
@@ -1361,6 +1403,7 @@ static struct i2c_driver hi556_i2c_driver = {
.driver = {
.name = "hi556",
.acpi_match_table = ACPI_PTR(hi556_acpi_ids),
+   .pm = pm_sleep_ptr(_pm_ops),
},
.probe = hi556_probe,
.remove = hi556_remove,


[git:media_stage/master] media: hi556: Add support for avdd regulator

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: hi556: Add support for avdd regulator
Author:  Hans de Goede 
Date:Mon Apr 15 15:10:38 2024 +0200

On some ACPI platforms, such as Chromebooks the ACPI methods to
change the power-state (_PS0 and _PS3) fully take care of powering
on/off the sensor.

On other ACPI platforms, such as e.g. various HP models with IPU6 +
hi556 sensor, the sensor driver must control the avdd regulator itself.

Add support for having the driver control the sensor's avdd regulator.
Note this relies on the regulator-core providing a dummy regulator
(which it does by default) on platforms where Linux is not aware of
the avdd regulator.

Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/hi556.c | 24 
 1 file changed, 24 insertions(+)

---

diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
index 235caadf02dc..b440f386f062 100644
--- a/drivers/media/i2c/hi556.c
+++ b/drivers/media/i2c/hi556.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -638,6 +639,7 @@ struct hi556 {
/* GPIOs, clocks, etc. */
struct gpio_desc *reset_gpio;
struct clk *clk;
+   struct regulator *avdd;
 
/* Current mode */
const struct hi556_mode *cur_mode;
@@ -1286,8 +1288,17 @@ static int hi556_suspend(struct device *dev)
 {
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct hi556 *hi556 = to_hi556(sd);
+   int ret;
 
gpiod_set_value_cansleep(hi556->reset_gpio, 1);
+
+   ret = regulator_disable(hi556->avdd);
+   if (ret) {
+   dev_err(dev, "failed to disable avdd: %d\n", ret);
+   gpiod_set_value_cansleep(hi556->reset_gpio, 0);
+   return ret;
+   }
+
clk_disable_unprepare(hi556->clk);
return 0;
 }
@@ -1302,6 +1313,13 @@ static int hi556_resume(struct device *dev)
if (ret)
return ret;
 
+   ret = regulator_enable(hi556->avdd);
+   if (ret) {
+   dev_err(dev, "failed to enable avdd: %d\n", ret);
+   clk_disable_unprepare(hi556->clk);
+   return ret;
+   }
+
gpiod_set_value_cansleep(hi556->reset_gpio, 0);
usleep_range(5000, 5500);
return 0;
@@ -1337,6 +1355,12 @@ static int hi556_probe(struct i2c_client *client)
return dev_err_probe(>dev, PTR_ERR(hi556->clk),
 "failed to get clock\n");
 
+   /* The regulator core will provide a "dummy" regulator if necessary */
+   hi556->avdd = devm_regulator_get(>dev, "avdd");
+   if (IS_ERR(hi556->avdd))
+   return dev_err_probe(>dev, PTR_ERR(hi556->avdd),
+"failed to get avdd regulator\n");
+
full_power = acpi_dev_state_d0(>dev);
if (full_power) {
/* Ensure non ACPI managed resources are enabled */


[git:media_stage/master] media: hi556: Add support for external clock

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: hi556: Add support for external clock
Author:  Hans de Goede 
Date:Mon Apr 15 15:10:37 2024 +0200

On some ACPI platforms, such as Chromebooks the ACPI methods to
change the power-state (_PS0 and _PS3) fully take care of powering
on/off the sensor.

On other ACPI platforms, such as e.g. various HP models with IPU6 +
hi556 sensor, the sensor driver must control the sensor's clock itself.

Add support for having the driver control an optional clock.

Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/hi556.c | 13 +
 1 file changed, 13 insertions(+)

---

diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
index e084f7888e29..235caadf02dc 100644
--- a/drivers/media/i2c/hi556.c
+++ b/drivers/media/i2c/hi556.c
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -636,6 +637,7 @@ struct hi556 {
 
/* GPIOs, clocks, etc. */
struct gpio_desc *reset_gpio;
+   struct clk *clk;
 
/* Current mode */
const struct hi556_mode *cur_mode;
@@ -1286,6 +1288,7 @@ static int hi556_suspend(struct device *dev)
struct hi556 *hi556 = to_hi556(sd);
 
gpiod_set_value_cansleep(hi556->reset_gpio, 1);
+   clk_disable_unprepare(hi556->clk);
return 0;
 }
 
@@ -1293,6 +1296,11 @@ static int hi556_resume(struct device *dev)
 {
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct hi556 *hi556 = to_hi556(sd);
+   int ret;
+
+   ret = clk_prepare_enable(hi556->clk);
+   if (ret)
+   return ret;
 
gpiod_set_value_cansleep(hi556->reset_gpio, 0);
usleep_range(5000, 5500);
@@ -1324,6 +1332,11 @@ static int hi556_probe(struct i2c_client *client)
return dev_err_probe(>dev, PTR_ERR(hi556->reset_gpio),
 "failed to get reset GPIO\n");
 
+   hi556->clk = devm_clk_get_optional(>dev, "clk");
+   if (IS_ERR(hi556->clk))
+   return dev_err_probe(>dev, PTR_ERR(hi556->clk),
+"failed to get clock\n");
+
full_power = acpi_dev_state_d0(>dev);
if (full_power) {
/* Ensure non ACPI managed resources are enabled */


[git:media_stage/master] media: hi556: Return -EPROBE_DEFER if no endpoint is found

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: hi556: Return -EPROBE_DEFER if no endpoint is found
Author:  Hans de Goede 
Date:Mon Apr 15 15:10:35 2024 +0200

With ipu bridge, endpoints may only be created when ipu bridge has
initialised. This may happen after the sensor driver has first probed.

Signed-off-by: Hans de Goede 
Signed-off-by: Sakari Ailus 
Signed-off-by: Hans Verkuil 

 drivers/media/i2c/hi556.c | 23 ---
 1 file changed, 12 insertions(+), 11 deletions(-)

---

diff --git a/drivers/media/i2c/hi556.c b/drivers/media/i2c/hi556.c
index 38c77d515786..c54cd49e56a1 100644
--- a/drivers/media/i2c/hi556.c
+++ b/drivers/media/i2c/hi556.c
@@ -1206,8 +1206,18 @@ static int hi556_check_hwcfg(struct device *dev)
int ret = 0;
unsigned int i, j;
 
-   if (!fwnode)
-   return -ENXIO;
+   /*
+* Sometimes the fwnode graph is initialized by the bridge driver,
+* wait for this.
+*/
+   ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
+   if (!ep)
+   return -EPROBE_DEFER;
+
+   ret = v4l2_fwnode_endpoint_alloc_parse(ep, _cfg);
+   fwnode_handle_put(ep);
+   if (ret)
+   return ret;
 
ret = fwnode_property_read_u32(fwnode, "clock-frequency", );
if (ret) {
@@ -1220,15 +1230,6 @@ static int hi556_check_hwcfg(struct device *dev)
return -EINVAL;
}
 
-   ep = fwnode_graph_get_next_endpoint(fwnode, NULL);
-   if (!ep)
-   return -ENXIO;
-
-   ret = v4l2_fwnode_endpoint_alloc_parse(ep, _cfg);
-   fwnode_handle_put(ep);
-   if (ret)
-   return ret;
-
if (bus_cfg.bus.mipi_csi2.num_data_lanes != 2) {
dev_err(dev, "number of CSI2 data lanes %d is not supported",
bus_cfg.bus.mipi_csi2.num_data_lanes);


[git:media_stage/master] Merge tag 'tags/media-next-imx-20240419' of git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git into media_stage

2024-04-22 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: Merge tag 'tags/media-next-imx-20240419' of 
git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git into 
media_stage
Author:  Hans Verkuil 
Date:Mon Apr 22 10:44:31 2024 +0200

NXP media drivers improvements.

Signed-off-by: Hans Verkuil 
From: Laurent Pinchart 
Link: 
https://patchwork.linuxtv.org/project/linux-media/patch/20240419103822.ga6...@pendragon.ideasonboard.com/

---



[git:media_stage/master] media: c8sectpfe: Do not depend on DEBUG_FS

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: c8sectpfe: Do not depend on DEBUG_FS
Author:  Ricardo Ribalda 
Date:Thu Apr 11 12:14:03 2024 +

Make dependency on DEBUG_FS conditional, that way we are not forced to
enable DEBUG_FS if we can to use this driver.

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/platform/st/sti/c8sectpfe/Kconfig | 1 -
 drivers/media/platform/st/sti/c8sectpfe/Makefile| 7 +--
 drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-debugfs.h | 5 +
 3 files changed, 10 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/platform/st/sti/c8sectpfe/Kconfig 
b/drivers/media/platform/st/sti/c8sectpfe/Kconfig
index 702b910509c9..01c33d9c9ec3 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/Kconfig
+++ b/drivers/media/platform/st/sti/c8sectpfe/Kconfig
@@ -5,7 +5,6 @@ config DVB_C8SECTPFE
depends on PINCTRL && DVB_CORE && I2C
depends on ARCH_STI || ARCH_MULTIPLATFORM || COMPILE_TEST
select FW_LOADER
-   select DEBUG_FS
select DVB_LNBP21 if MEDIA_SUBDRV_AUTOSELECT
select DVB_STV090x if MEDIA_SUBDRV_AUTOSELECT
select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/platform/st/sti/c8sectpfe/Makefile 
b/drivers/media/platform/st/sti/c8sectpfe/Makefile
index aedfc725cc19..99425137ee0a 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/Makefile
+++ b/drivers/media/platform/st/sti/c8sectpfe/Makefile
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
-c8sectpfe-y += c8sectpfe-core.o c8sectpfe-common.o c8sectpfe-dvb.o \
-   c8sectpfe-debugfs.o
+c8sectpfe-y += c8sectpfe-core.o c8sectpfe-common.o c8sectpfe-dvb.o
+
+ifneq ($(CONFIG_DEBUG_FS),)
+c8sectpfe-y += c8sectpfe-debugfs.o
+endif
 
 obj-$(CONFIG_DVB_C8SECTPFE) += c8sectpfe.o
 
diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-debugfs.h 
b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-debugfs.h
index d2c35fb32d7e..8e1bfd860524 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-debugfs.h
+++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-debugfs.h
@@ -12,7 +12,12 @@
 
 #include "c8sectpfe-core.h"
 
+#if defined(CONFIG_DEBUG_FS)
 void c8sectpfe_debugfs_init(struct c8sectpfei *);
 void c8sectpfe_debugfs_exit(struct c8sectpfei *);
+#else
+static inline void c8sectpfe_debugfs_init(struct c8sectpfei *) {};
+static inline void c8sectpfe_debugfs_exit(struct c8sectpfei *) {};
+#endif
 
 #endif /* __C8SECTPFE_DEBUG_H */


[git:media_stage/master] media: dvb: as102-fe: Fix as10x_register_addr packing

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dvb: as102-fe: Fix as10x_register_addr packing
Author:  Ricardo Ribalda 
Date:Wed Apr 10 12:24:37 2024 +

This structure is embedded in multiple other structures that are packed,
which conflicts with it being aligned.

drivers/media/usb/as102/as10x_cmd.h:379:30: warning: field reg_addr within 
'struct as10x_dump_memory::(unnamed at 
drivers/media/usb/as102/as10x_cmd.h:373:2)' is less aligned than 'struct 
as10x_register_addr' and is usually due to 'struct as10x_dump_memory::(unnamed 
at drivers/media/usb/as102/as10x_cmd.h:373:2)' being packed, which can lead to 
unaligned accesses [-Wunaligned-access]

Mark it as being packed.

Marking the inner struct as 'packed' does not change the layout, since the
whole struct is already packed, it just silences the clang warning. See
also this llvm discussion:

https://github.com/llvm/llvm-project/issues/55520

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/dvb-frontends/as102_fe_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/drivers/media/dvb-frontends/as102_fe_types.h 
b/drivers/media/dvb-frontends/as102_fe_types.h
index 297f9520ebf9..8a4e392c8896 100644
--- a/drivers/media/dvb-frontends/as102_fe_types.h
+++ b/drivers/media/dvb-frontends/as102_fe_types.h
@@ -174,6 +174,6 @@ struct as10x_register_addr {
uint32_t addr;
/* register mode access */
uint8_t mode;
-};
+} __packed;
 
 #endif


[git:media_stage/master] media: solo6x10: Use pcim functions

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: solo6x10: Use pcim functions
Author:  Ricardo Ribalda 
Date:Thu Apr 11 21:17:50 2024 +

Instead of handling manually the release of the memory regions let devm
do that for us.

Makes smatch happy:
drivers/media/pci/solo6x10/solo6x10-core.c:631 solo_pci_probe() warn: 'pdev' 
from pci_request_regions() not released on lines: 631.

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/solo6x10/solo6x10-core.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

---

diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c 
b/drivers/media/pci/solo6x10/solo6x10-core.c
index 6d87fbb0ee04..abf30b7609e1 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -145,10 +145,8 @@ static void free_solo_dev(struct solo_dev *solo_dev)
/* Now cleanup the PCI device */
solo_irq_off(solo_dev, ~0);
free_irq(pdev->irq, solo_dev);
-   pci_iounmap(pdev, solo_dev->reg_base);
}
 
-   pci_release_regions(pdev);
pci_disable_device(pdev);
v4l2_device_unregister(_dev->v4l2_dev);
pci_set_drvdata(pdev, NULL);
@@ -480,15 +478,10 @@ static int solo_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
pci_write_config_byte(pdev, 0x40, 0x00);
pci_write_config_byte(pdev, 0x41, 0x00);
 
-   ret = pci_request_regions(pdev, SOLO6X10_NAME);
+   ret = pcim_iomap_regions(pdev, BIT(0), SOLO6X10_NAME);
if (ret)
goto fail_probe;
-
-   solo_dev->reg_base = pci_ioremap_bar(pdev, 0);
-   if (solo_dev->reg_base == NULL) {
-   ret = -ENOMEM;
-   goto fail_probe;
-   }
+   solo_dev->reg_base = pcim_iomap_table(pdev)[0];
 
chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
SOLO_CHIP_ID_MASK;


[git:media_stage/master] media: solo6x10: Use devm functions

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: solo6x10: Use devm functions
Author:  Ricardo Ribalda 
Date:Thu Apr 11 21:17:51 2024 +

Let devm handle the life cycle of the irq request.

Makes smatch happier:

drivers/media/pci/solo6x10/solo6x10-core.c:631 solo_pci_probe() warn: 'pdev' 
from pci_request_regions() not released on lines: 631.

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/solo6x10/solo6x10-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c 
b/drivers/media/pci/solo6x10/solo6x10-core.c
index abf30b7609e1..1a9e2bccc413 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -144,7 +144,6 @@ static void free_solo_dev(struct solo_dev *solo_dev)
 
/* Now cleanup the PCI device */
solo_irq_off(solo_dev, ~0);
-   free_irq(pdev->irq, solo_dev);
}
 
pci_disable_device(pdev);
@@ -544,8 +543,8 @@ static int solo_pci_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
/* PLL locking time of 1ms */
mdelay(1);
 
-   ret = request_irq(pdev->irq, solo_isr, IRQF_SHARED, SOLO6X10_NAME,
- solo_dev);
+   ret = devm_request_irq(>dev, pdev->irq, solo_isr, IRQF_SHARED,
+  SOLO6X10_NAME, solo_dev);
if (ret)
goto fail_probe;
 


[git:media_stage/master] media: videodev2: Fix v4l2_ext_control packing.

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: videodev2: Fix v4l2_ext_control packing.
Author:  Ricardo Ribalda 
Date:Wed Apr 10 12:24:39 2024 +

The structure is packed, which requires that all its fields need to be
also packed.

./include/uapi/linux/videodev2.h:1810:2: warning: field  within 'struct 
v4l2_ext_control' is less aligned than 'union v4l2_ext_control::(anonymous at 
./include/uapi/linux/videodev2.h:1810:2)' and is usually due to 'struct 
v4l2_ext_control' being packed, which can lead to unaligned accesses 
[-Wunaligned-access]

Explicitly set the inner union as packed.

Marking the inner union as 'packed' does not change the layout, since the
whole struct is already packed, it just silences the clang warning. See
also this llvm discussion:

https://github.com/llvm/llvm-project/issues/55520

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 include/uapi/linux/videodev2.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 2663213b76a4..bf12860d570a 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1842,7 +1842,7 @@ struct v4l2_ext_control {
struct v4l2_ctrl_hdr10_cll_info __user *p_hdr10_cll_info;
struct v4l2_ctrl_hdr10_mastering_display __user 
*p_hdr10_mastering_display;
void __user *ptr;
-   };
+   } __attribute__ ((packed));
 } __attribute__ ((packed));
 
 struct v4l2_ext_controls {


[git:media_stage/master] media: saa7134: Use devm_request_irq

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: saa7134: Use devm_request_irq
Author:  Ricardo Ribalda 
Date:Thu Apr 11 21:17:52 2024 +

The handled version of request_irq let us remove the free_irq and makes
smatch happier:

drivers/media/pci/saa7134/saa7134-alsa.c:1186 alsa_card_saa7134_create() warn: 
'dev->pci->irq' from request_irq() not released on lines: 1186

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/pci/saa7134/saa7134-alsa.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

---

diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c 
b/drivers/media/pci/saa7134/saa7134-alsa.c
index d3cde05a6eba..dd2236c5c4a1 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1096,9 +1096,6 @@ static void snd_saa7134_free(struct snd_card * card)
if (chip->dev->dmasound.priv_data == NULL)
return;
 
-   if (chip->irq >= 0)
-   free_irq(chip->irq, >dev->dmasound);
-
chip->dev->dmasound.priv_data = NULL;
 
 }
@@ -1147,10 +1144,8 @@ static int alsa_card_saa7134_create(struct saa7134_dev 
*dev, int devnum)
chip->iobase = pci_resource_start(dev->pci, 0);
 
 
-   err = request_irq(dev->pci->irq, saa7134_alsa_irq,
-   IRQF_SHARED, dev->name,
-   (void*) >dmasound);
-
+   err = devm_request_irq(>pci->dev, dev->pci->irq, saa7134_alsa_irq,
+  IRQF_SHARED, dev->name, >dmasound);
if (err < 0) {
pr_err("%s: can't get IRQ %d for ALSA\n",
dev->name, dev->pci->irq);


[git:media_stage/master] media: dvb: Fix dtvs_stats packing.

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dvb: Fix dtvs_stats packing.
Author:  Ricardo Ribalda 
Date:Wed Apr 10 12:24:38 2024 +

The structure is packed, which requires that all its fields need to be
also packed.

./include/uapi/linux/dvb/frontend.h:854:2: warning: field  within 'struct 
dtv_stats' is less aligned than 'union dtv_stats::(anonymous at 
./include/uapi/linux/dvb/frontend.h:854:2)' and is usually due to 'struct 
dtv_stats' being packed, which can lead to unaligned accesses 
[-Wunaligned-access]

Explicitly set the inner union as packed.

Marking the inner union as 'packed' does not change the layout, since the
whole struct is already packed, it just silences the clang warning. See
also this llvm discussion:

https://github.com/llvm/llvm-project/issues/55520

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 include/uapi/linux/dvb/frontend.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

---

diff --git a/include/uapi/linux/dvb/frontend.h 
b/include/uapi/linux/dvb/frontend.h
index 7e0983b987c2..8d38c6befda8 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -854,7 +854,7 @@ struct dtv_stats {
union {
__u64 uvalue;   /* for counters and relative scales */
__s64 svalue;   /* for 0.001 dB measures */
-   };
+   }  __attribute__ ((packed));
 } __attribute__ ((packed));
 
 


[git:media_stage/master] media: tunner: xc5000: Refactor firmware load

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: tunner: xc5000: Refactor firmware load
Author:  Ricardo Ribalda 
Date:Thu Apr 11 21:17:54 2024 +

Make sure the firmware is released when we leave
xc_load_fw_and_init_tuner()

This change makes smatch happy:
drivers/media/tuners/xc5000.c:1213 xc_load_fw_and_init_tuner() warn: 'fw' from 
request_firmware() not released on lines: 1213.

Cc: Shuah Khan 
Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/tuners/xc5000.c | 39 +--
 1 file changed, 17 insertions(+), 22 deletions(-)

---

diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index 2182e5b7b606..30aa4ee958bd 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -58,7 +58,7 @@ struct xc5000_priv {
struct dvb_frontend *fe;
struct delayed_work timer_sleep;
 
-   const struct firmware   *firmware;
+   bool inited;
 };
 
 /* Misc Defines */
@@ -1110,23 +1110,19 @@ static int xc_load_fw_and_init_tuner(struct 
dvb_frontend *fe, int force)
if (!force && xc5000_is_firmware_loaded(fe) == 0)
return 0;
 
-   if (!priv->firmware) {
-   ret = request_firmware(, desired_fw->name,
-   priv->i2c_props.adap->dev.parent);
-   if (ret) {
-   pr_err("xc5000: Upload failed. rc %d\n", ret);
-   return ret;
-   }
-   dprintk(1, "firmware read %zu bytes.\n", fw->size);
+   ret = request_firmware(, desired_fw->name,
+  priv->i2c_props.adap->dev.parent);
+   if (ret) {
+   pr_err("xc5000: Upload failed. rc %d\n", ret);
+   return ret;
+   }
+   dprintk(1, "firmware read %zu bytes.\n", fw->size);
 
-   if (fw->size != desired_fw->size) {
-   pr_err("xc5000: Firmware file with incorrect size\n");
-   release_firmware(fw);
-   return -EINVAL;
-   }
-   priv->firmware = fw;
-   } else
-   fw = priv->firmware;
+   if (fw->size != desired_fw->size) {
+   pr_err("xc5000: Firmware file with incorrect size\n");
+   release_firmware(fw);
+   return -EINVAL;
+   }
 
/* Try up to 5 times to load firmware */
for (i = 0; i < 5; i++) {
@@ -1204,6 +1200,7 @@ static int xc_load_fw_and_init_tuner(struct dvb_frontend 
*fe, int force)
}
 
 err:
+   release_firmware(fw);
if (!ret)
printk(KERN_INFO "xc5000: Firmware %s loaded and running.\n",
   desired_fw->name);
@@ -1274,7 +1271,7 @@ static int xc5000_resume(struct dvb_frontend *fe)
 
/* suspended before firmware is loaded.
   Avoid firmware load in resume path. */
-   if (!priv->firmware)
+   if (!priv->inited)
return 0;
 
return xc5000_set_params(fe);
@@ -1293,6 +1290,8 @@ static int xc5000_init(struct dvb_frontend *fe)
if (debug)
xc_debug_dump(priv);
 
+   priv->inited = true;
+
return 0;
 }
 
@@ -1306,10 +1305,6 @@ static void xc5000_release(struct dvb_frontend *fe)
 
if (priv) {
cancel_delayed_work(>timer_sleep);
-   if (priv->firmware) {
-   release_firmware(priv->firmware);
-   priv->firmware = NULL;
-   }
hybrid_tuner_release_state(priv);
}
 


[git:media_stage/master] media: dvb-usb: dib0700_devices: Add missing release_firmware()

2024-04-16 Thread Hans Verkuil
This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: dvb-usb: dib0700_devices: Add missing release_firmware()
Author:  Ricardo Ribalda 
Date:Thu Apr 11 21:17:56 2024 +

Add missing release_firmware on the error paths.

drivers/media/usb/dvb-usb/dib0700_devices.c:2415 stk9090m_frontend_attach() 
warn: 'state->frontend_firmware' from request_firmware() not released on lines: 
2415.
drivers/media/usb/dvb-usb/dib0700_devices.c:2497 nim9090md_frontend_attach() 
warn: 'state->frontend_firmware' from request_firmware() not released on lines: 
2489,2497.

Signed-off-by: Ricardo Ribalda 
Signed-off-by: Hans Verkuil 

 drivers/media/usb/dvb-usb/dib0700_devices.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 3af594134a6d..6ddc20513393 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -2412,7 +2412,12 @@ static int stk9090m_frontend_attach(struct 
dvb_usb_adapter *adap)
 
adap->fe_adap[0].fe = dvb_attach(dib9000_attach, >dev->i2c_adap, 
0x80, _config);
 
-   return adap->fe_adap[0].fe == NULL ?  -ENODEV : 0;
+   if (!adap->fe_adap[0].fe) {
+   release_firmware(state->frontend_firmware);
+   return -ENODEV;
+   }
+
+   return 0;
 }
 
 static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
@@ -2485,8 +2490,10 @@ static int nim9090md_frontend_attach(struct 
dvb_usb_adapter *adap)
dib9000_i2c_enumeration(>dev->i2c_adap, 1, 0x20, 0x80);
adap->fe_adap[0].fe = dvb_attach(dib9000_attach, >dev->i2c_adap, 
0x80, _config[0]);
 
-   if (adap->fe_adap[0].fe == NULL)
+   if (!adap->fe_adap[0].fe) {
+   release_firmware(state->frontend_firmware);
return -ENODEV;
+   }
 
i2c = dib9000_get_i2c_master(adap->fe_adap[0].fe, 
DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);
@@ -2494,7 +2501,12 @@ static int nim9090md_frontend_attach(struct 
dvb_usb_adapter *adap)
fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, _config[1]);
dib9000_set_slave_frontend(adap->fe_adap[0].fe, fe_slave);
 
-   return fe_slave == NULL ?  -ENODEV : 0;
+   if (!fe_slave) {
+   release_firmware(state->frontend_firmware);
+   return -ENODEV;
+   }
+
+   return 0;
 }
 
 static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)


  1   2   3   4   5   6   7   8   9   10   >