From a5877e03072c9578cd97a84f4db1106f24a588a9 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 1 Mar 2022 22:35:16 +0200 Subject: utils: rkisp1: Support optional CSI-2 receiver subdev The media graph may include a CSI-2 receiver entity between the sensor and the ISP for platforms that have a CSI-2 receiver external to the ISP. Support this by configuring the pipeline accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- utils/rkisp1/rkisp1-capture.sh | 56 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'utils/rkisp1') diff --git a/utils/rkisp1/rkisp1-capture.sh b/utils/rkisp1/rkisp1-capture.sh index 2549779d..c5f859f2 100755 --- a/utils/rkisp1/rkisp1-capture.sh +++ b/utils/rkisp1/rkisp1-capture.sh @@ -14,6 +14,37 @@ # - raw2rgbpnm (from git://git.retiisi.org.uk/~sailus/raw2rgbpnm.git) # - yavta (from git://git.ideasonboard.org/yavta.git) +# Return the entity connected to a given pad +# $1: The pad, expressed as "entity":index +mc_remote_entity() { + local entity="${1%:*}" + local pad="${1#*:}" + + ${mediactl} -p | awk ' +/^- entity / { + in_entity=0 +} + +/^- entity [0-9]+: '"${entity}"' / { + in_entity=1 +} + +/^[ \t]+pad/ { + in_pad=0 +} + +/^[ \t]+pad'"${pad}"': / { + in_pad=1 +} + +/^[ \t]+(<-|->) "[^"]+"/ { + if (in_entity && in_pad) { + print gensub(/^[^"]+"([^"]+)":([0-9]+).*$/, "\\1", "g") + exit + } +}' +} + # Locate the sensor entity find_sensor() { local bus @@ -28,6 +59,17 @@ find_sensor() { echo "$sensor_name $bus" } +# Locate the CSI-2 receiver +find_csi2_rx() { + local sensor_name=$1 + local csi2_rx + + csi2_rx=$(mc_remote_entity "$sensor_name:0") + if [ "$csi2_rx" != rkisp1_isp ] ; then + echo "$csi2_rx" + fi +} + # Locate the media device find_media_device() { local mdev @@ -63,15 +105,27 @@ configure_pipeline() { local format="fmt:$sensor_mbus_code/$sensor_size" local capture_mbus_code=$1 local capture_size=$2 + local csi2_rx echo "Configuring pipeline for $sensor in $format" + csi2_rx=$(find_csi2_rx "$sensor") + $mediactl -r - $mediactl -l "'$sensor':0 -> 'rkisp1_isp':0 [1]" + if [ -n "$csi2_rx" ] ; then + $mediactl -l "'$sensor':0 -> '$csi2_rx':0 [1]" + $mediactl -l "'$csi2_rx':1 -> 'rkisp1_isp':0 [1]" + else + $mediactl -l "'$sensor':0 -> 'rkisp1_isp':0 [1]" + fi $mediactl -l "'rkisp1_isp':2 -> 'rkisp1_resizer_mainpath':0 [1]" $mediactl -V "\"$sensor\":0 [$format]" + if [ -n "$csi2_rx" ] ; then + $mediactl -V "'$csi2_rx':0 [$format]" + $mediactl -V "'$csi2_rx':1 [$format]" + fi $mediactl -V "'rkisp1_isp':0 [$format crop:(0,0)/$sensor_size]" $mediactl -V "'rkisp1_isp':2 [fmt:$capture_mbus_code/$sensor_size crop:(0,0)/$sensor_size]" $mediactl -V "'rkisp1_resizer_mainpath':0 [fmt:$capture_mbus_code/$sensor_size crop:(0,0)/$sensor_size]" -- cgit v1.2.1