| 1 | #!/bin/sh |
| 2 | |
| 3 | MEDIA_CTL=media-ctl |
| 4 | V4L2_CTL=v4l2-ctl |
| 5 | GST=gst-launch-1.0 |
| 6 | |
| 7 | out() { |
| 8 | echo "$@" |
| 9 | } |
| 10 | |
| 11 | dbg() { |
| 12 | [ -n "$DEBUG" ] && { echo "$@" 1>&2; } |
| 13 | } |
| 14 | |
| 15 | err() { |
| 16 | local ret=$1 |
| 17 | |
| 18 | shift |
| 19 | |
| 20 | [ -n "$FORCE" ] && { |
| 21 | out "# Error: $@" |
| 22 | } || { |
| 23 | echo "Error: $@" 1>&2 |
| 24 | exit $ret |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | # link 2 entities together |
| 29 | # $1 pad1 |
| 30 | # $2 pad2 |
| 31 | # $3 flags |
| 32 | lnk() { |
| 33 | out $MEDIA_CTL -l \""$1 -> $2$3"\" |
| 34 | } |
| 35 | |
| 36 | # format pad |
| 37 | fmt() { |
| 38 | out $MEDIA_CTL --set-v4l2 "\"$1\"" |
| 39 | } |
| 40 | |
| 41 | # mode0: sensor -> mux -> csi -> /dev/videoN |
| 42 | # raw capture |
| 43 | mode0() { |
| 44 | EP="ipu${IPU}_csi${CSI}" |
| 45 | EPP=2 |
| 46 | [ $SOC = imx6q ] && p=1 || p=4 |
| 47 | |
| 48 | out "# setup links" |
| 49 | lnk "'$SENSOR':0" "'ipu${IPU}_csi${CSI}_mux':$p" "[1]" |
| 50 | lnk "'ipu${IPU}_csi${CSI}_mux':$((p+1))" "'$EP':0" "[1]" |
| 51 | lnk "'$EP':$EPP" "'$EP capture':0" "[1]" |
| 52 | |
| 53 | out "# configure pads" |
| 54 | case "$SENS" in |
| 55 | adv7180) |
| 56 | fmt "'$SENSOR':0 [fmt:UYVY2X8/$res field:alternate]" |
| 57 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:UYVY2X8/$res]" |
| 58 | # rec709 config at CSI pad 0 |
| 59 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 60 | # CSI src pad output is frame height |
| 61 | h=$((h*2)) |
| 62 | res=${w}x${h} |
| 63 | fmt "'$EP':$EPP [fmt:AYUV32/$res]" |
| 64 | # Error: gstreamer: Device does not support progressive interlacing |
| 65 | ;; |
| 66 | tda1997x) |
| 67 | fmt "'$SENSOR':0 [fmt:$fmt field:$field]" |
| 68 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:$fmt field:$field]" |
| 69 | # rec709 config at CSI pad 0 |
| 70 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 71 | fmt "'$EP':$EPP [fmt:AYUV32/$res]" |
| 72 | out "$MEDIA_CTL --get-v4l2 '\"$EP\":$EPP'" |
| 73 | ;; |
| 74 | esac |
| 75 | } |
| 76 | |
| 77 | # mode1: sensor -> mux -> csi -> ic_prp -> ic_prpenc -> /dev/videoN |
| 78 | # IC enc CSC/Scale/interweave |
| 79 | mode1() { |
| 80 | EP="ipu${IPU}_ic_prpenc" |
| 81 | EPP=1 |
| 82 | [ $SOC = imx6q ] && p=1 || p=4 |
| 83 | |
| 84 | out "# setup links" |
| 85 | lnk "'$SENSOR':0" "'ipu${IPU}_csi${CSI}_mux':$p" "[1]" |
| 86 | lnk "'ipu${IPU}_csi${CSI}_mux':$((p+1))" "'ipu${IPU}_csi${CSI}':0" "[1]" |
| 87 | lnk "'ipu${IPU}_csi${CSI}':1" "'ipu${IPU}_ic_prp':0" "[1]" |
| 88 | lnk "'ipu${IPU}_ic_prp':1" "'$EP':0" "[1]" |
| 89 | lnk "'$EP':1" "'$EP capture':0" "[1]" |
| 90 | |
| 91 | out "# configure pads" |
| 92 | case "$SENS" in |
| 93 | adv7180) |
| 94 | fmt "'$SENSOR':0 [fmt:UYVY2X8/$res field:alternate]" |
| 95 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:UYVY2X8/$res]" |
| 96 | # rec709 config at CSI pad 0 |
| 97 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 98 | # CSI src pad output is frame height |
| 99 | h=$((h*2)) |
| 100 | res=${w}x${h} |
| 101 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 102 | fmt "'ipu${IPU}_ic_prp':1 [fmt:AYUV32/$res]" |
| 103 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 104 | # Error: gstreamer: Device does not support progressive interlacing |
| 105 | ;; |
| 106 | tda1997x) |
| 107 | [ "$fcc" = "UYVY8_1X16" ] && { |
| 108 | err 1 "Invalid mode: 16bit capture (passthrough) can't go through IC" |
| 109 | } |
| 110 | fmt "'$SENSOR':0 [fmt:$fmt field:$field]" |
| 111 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:$fmt field:$field]" |
| 112 | [ "$w" -ge 1024 -o "$h" -ge 1024 ] && { |
| 113 | # downscale CSI resolution |
| 114 | res="$((w/2))x$((h/2))" |
| 115 | dbg "Adjusting resolution from ${w}x${h} to $res" |
| 116 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 117 | #fmt "'ipu${IPU}_csi${CSI}':0 [crop:(0,0)/$res]" |
| 118 | #fmt "'ipu${IPU}_csi${CSI}':0 [compose:(0,0)/$res]" |
| 119 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 120 | fmt "'ipu${IPU}_ic_prp':1 [fmt:AYUV32/$res]" |
| 121 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 122 | } || { |
| 123 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 124 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 125 | fmt "'ipu${IPU}_ic_prp':1 [fmt:AYUV32/$res]" |
| 126 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 127 | out "$MEDIA_CTL --get-v4l2 '\"$EP\":1'" |
| 128 | } |
| 129 | ;; |
| 130 | esac |
| 131 | } |
| 132 | |
| 133 | # mode2: sensor -> mux -> csi -> ic_prp -> ic_prpvf -> /dev/videoN |
| 134 | # IC vf CSC/Scale/interweave (same as mode1 but using vf instead of enc) |
| 135 | mode2() { |
| 136 | EP="ipu${IPU}_ic_prpvf" |
| 137 | EPP=1 |
| 138 | [ $SOC = imx6q ] && p=1 || p=4 |
| 139 | |
| 140 | out "# setup links" |
| 141 | lnk "'$SENSOR':0" "'ipu${IPU}_csi${CSI}_mux':$p" "[1]" |
| 142 | lnk "'ipu${IPU}_csi${CSI}_mux':$((p+1))" "'ipu${IPU}_csi${CSI}':0" "[1]" |
| 143 | lnk "'ipu${IPU}_csi${CSI}':1" "'ipu${IPU}_ic_prp':0" "[1]" |
| 144 | lnk "'ipu${IPU}_ic_prp':2" "'$EP':0" "[1]" |
| 145 | lnk "'$EP':1" "'$EP capture':0" "[1]" |
| 146 | |
| 147 | out "# configure pads" |
| 148 | case "$SENS" in |
| 149 | adv7180) |
| 150 | fmt "'$SENSOR':0 [fmt:UYVY2X8/$res field:alternate]" |
| 151 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:UYVY2X8/$res]" |
| 152 | # rec709 config at CSI pad 0 |
| 153 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 154 | # CSI src pad output is frame height |
| 155 | h=$((h*2)) |
| 156 | res=${w}x${h} |
| 157 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 158 | fmt "'ipu${IPU}_ic_prp':2 [fmt:AYUV32/$res]" |
| 159 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 160 | # Error: gstreamer: Device does not support progressive interlacing |
| 161 | ;; |
| 162 | tda1997x) |
| 163 | [ "$fcc" = "UYVY8_1X16" ] && { |
| 164 | err 1 "Invalid mode: 16bit capture (passthrough) can't go through IC" |
| 165 | } |
| 166 | fmt "'$SENSOR':0 [fmt:$fmt field:$field]" |
| 167 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:$fmt field:$field]" |
| 168 | # rec709 config at CSI pad 0 |
| 169 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 170 | [ "$w" -ge 1024 -o "$h" -ge 1024 ] && { |
| 171 | # downscale CSI resolution |
| 172 | res="$((w/2))x$((h/2))" |
| 173 | dbg "Adjusting resolution from ${w}x${h} to $res" |
| 174 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 175 | #fmt "'ipu${IPU}_csi${CSI}':0 [crop:(0,0)/$res]" |
| 176 | #fmt "'ipu${IPU}_csi${CSI}':0 [compose:(0,0)/$res]" |
| 177 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 178 | fmt "'ipu${IPU}_ic_prp':2 [fmt:AYUV32/$res]" |
| 179 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 180 | } || { |
| 181 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 182 | fmt "'ipu${IPU}_ic_prp':2 [fmt:AYUV32/$res]" |
| 183 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 184 | out "$MEDIA_CTL --get-v4l2 '\"$EP\":1'" |
| 185 | } |
| 186 | ;; |
| 187 | esac |
| 188 | } |
| 189 | |
| 190 | # mode3: sensor -> mux -> csi -> vdic -> ic_prp -> ic_prpvf -> /dev/videoN |
| 191 | # IC vf CSC/Scale/interweave with motion compensated de-interlace |
| 192 | mode3() { |
| 193 | EP="ipu${IPU}_ic_prpvf" |
| 194 | EPP=1 |
| 195 | [ $SOC = imx6q ] && p=1 || p=4 |
| 196 | |
| 197 | [ "$fld" = "progressive" ] && { |
| 198 | err 1 "Invalid mode: VDIC does not accept progressive video" |
| 199 | } |
| 200 | |
| 201 | out "# setup links" |
| 202 | lnk "'$SENSOR':0" "'ipu${IPU}_csi${CSI}_mux':$p" "[1]" |
| 203 | lnk "'ipu${IPU}_csi${CSI}_mux':$((p+1))" "'ipu${IPU}_csi${CSI}':0" "[1]" |
| 204 | lnk "'ipu${IPU}_csi${CSI}':1" "'ipu${IPU}_vdic':0" "[1]" |
| 205 | lnk "'ipu${IPU}_vdic':2" "'ipu${IPU}_ic_prp':0" "[1]" |
| 206 | lnk "'ipu${IPU}_ic_prp':2" "'$EP':0" "[1]" |
| 207 | lnk "'$EP':1" "'$EP capture':0" "[1]" |
| 208 | |
| 209 | out "# configure pads" |
| 210 | case "$SENS" in |
| 211 | adv7180) |
| 212 | fmt "'$SENSOR':0 [fmt:UYVY2X8/$res field:alternate]" |
| 213 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:UYVY2X8/$res]" |
| 214 | # rec709 config at CSI pad 0 |
| 215 | fmt "'ipu${IPU}_csi${CSI}':0 [fmt:$fmt field:$field colorspace:rec709 ycbcr:709]" |
| 216 | # CSI src pad output is frame height |
| 217 | h=$((h*2)) |
| 218 | res=${w}x${h} |
| 219 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 220 | fmt "'ipu${IPU}_vdic':2 [fmt:AYUV32/$res field:none]" |
| 221 | fmt "'ipu${IPU}_ic_prp':2 [fmt:AYUV32/$res field:none]" |
| 222 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 223 | ;; |
| 224 | tda1997x) |
| 225 | fmt "'$SENSOR':0 [fmt:$fmt field:$field]" |
| 226 | fmt "'ipu${IPU}_csi${CSI}_mux':$((p+1)) [fmt:$fmt field:$field]" |
| 227 | fmt "'ipu${IPU}_csi${CSI}':1 [fmt:AYUV32/$res]" |
| 228 | fmt "'ipu${IPU}_vdic':2 [fmt:AYUV32/$res]" |
| 229 | fmt "'ipu${IPU}_ic_prp':2 [fmt:AYUV32/$res]" |
| 230 | fmt "'$EP':1 [fmt:AYUV32/$res]" |
| 231 | ;; |
| 232 | esac |
| 233 | } |
| 234 | |
| 235 | # return entity/pad format (all or specific field) |
| 236 | # $1 entity |
| 237 | # $2 optional parameter (fmt|fcc|res|int|field|colorspace) |
| 238 | # (will return entire fmt if empty) |
| 239 | get_format_param() { |
| 240 | local sensor="$1" |
| 241 | local param="$2" |
| 242 | local fmt name val int res fcc |
| 243 | |
| 244 | # v4l-utils 1.16.1: [fmt:UYVY8_1X16/1280x720 field:none colorspace:rec709] |
| 245 | fmt=$($MEDIA_CTL --get-v4l2 "$sensor" | sed -n 's/.*\[\(.*\)\]/\1/p') |
| 246 | dbg "get_format_param: $sensor [$fmt]" |
| 247 | [ -z "$param" ] && { |
| 248 | echo $fmt |
| 249 | return |
| 250 | } |
| 251 | for i in $fmt; do |
| 252 | name=$(echo "$i" | sed -n 's/\(.*\):.*/\1/p') |
| 253 | val=$(echo "$i" | sed -n 's/.*:\(.*\)/\1/p') |
| 254 | [ "$param" = "$name" ] && { |
| 255 | echo $val |
| 256 | return |
| 257 | } |
| 258 | [ "$name" = "fmt" ] && { |
| 259 | fcc=$(echo "$val" | awk -F '/' '{print $1}') |
| 260 | res=$(echo "$val" | awk -F '/' '{print $2}') |
| 261 | int=$(echo "$val" | awk -F '@' '{print $2}') |
| 262 | [ -n "$int" ] && { |
| 263 | res=$(echo "$res" | awk -F '@' '{print $1}') |
| 264 | } |
| 265 | case "$param" in |
| 266 | fcc) echo "$fcc"; return;; |
| 267 | res) echo "$res"; return;; |
| 268 | int) echo "$int"; return;; |
| 269 | esac |
| 270 | } |
| 271 | done |
| 272 | } |
| 273 | |
| 274 | # obtain entity/pad format |
| 275 | # TODO: replace with get_format_param usage |
| 276 | get_sensor_format() { |
| 277 | local sensor="$1" |
| 278 | local subdev="$($MEDIA_CTL -e "$sensor")" |
| 279 | |
| 280 | dbg "get_sensor_format: sensor='$sensor' subdev=$subdev" |
| 281 | # Get framerate and std (sets the following vars): |
| 282 | # std=NTSC|PAL |
| 283 | # framerate=29.9 |
| 284 | # w=720 |
| 285 | # h=480|576 |
| 286 | # fld="seq-bt" |
| 287 | # res=${w}x${h} |
| 288 | # pixelclock=calculated |
| 289 | case "$sensor" in |
| 290 | # for SD encoders: |
| 291 | # TODO: get-detected-standard not detecting switch between PAL/NTSC |
| 292 | # use 'v4l2-ctl --get-detected-standard' (VIDIOC_QUERYSTD) to get |
| 293 | # received std. |
| 294 | # use 'v4l2-ctl --get-standard' (VIDIOC_G_STD) to get selected std |
| 295 | # use 'v4l2-ctl --set-standard' (VIDIOC_S_STD) to set selected std |
| 296 | adv7180*) |
| 297 | csc=YUV |
| 298 | #fmt="$($V4L2_CTL --device $subdev --get-standard)" |
| 299 | # TODO: 'Video standard = 0x00000000' means no signal |
| 300 | #[ $? -ne 0 ] && { err 2 "v4l-utils 1.16 required for subdev support"; } |
| 301 | fmt=$STD |
| 302 | case $fmt in |
| 303 | *NTSC*) |
| 304 | std=NTSC |
| 305 | framerate=29.9 |
| 306 | w=720 |
| 307 | h=480 |
| 308 | fld="seq-bt" |
| 309 | res=${w}x${h} |
| 310 | pixelclock=$((w*h*2*30)) |
| 311 | ;; |
| 312 | *PAL*) |
| 313 | std=PAL |
| 314 | framerate=24.9 |
| 315 | w=720 |
| 316 | h=576 |
| 317 | fld="seq-tb" |
| 318 | res=${w}x${h} |
| 319 | pixelclock=$((w*h*2*30)) |
| 320 | ;; |
| 321 | *) err 2 "unknown standard or no input: $fmt";; |
| 322 | esac |
| 323 | out "# sensor standard" |
| 324 | #out $V4L2_CTL --device $subdev --get-detected-standard \# $std |
| 325 | out $V4L2_CTL --device $subdev --set-standard $std > /dev/null |
| 326 | out $V4L2_CTL --device $subdev --get-detected-standard # display std |
| 327 | ;; |
| 328 | # for DV encoders: |
| 329 | # use 'v4l2-ctl --get-dv-timings' detailed timing data |
| 330 | tda1997*) |
| 331 | fmt="$($V4L2_CTL --device $subdev --get-dv-timings)" |
| 332 | pixelclock="$(echo "$fmt" | sed -n 's/.*Pixelclock: \(.*\) Hz.*/\1/p')" |
| 333 | framerate="$(echo "$fmt" | sed -n 's/.*(\(.*\) frames.*/\1/p')" |
| 334 | fld="$(echo "$fmt" | sed -n 's/.*Frame format: \(.*\)/\1/p')" |
| 335 | out "# get framerate" |
| 336 | out $V4L2_CTL --device $subdev --get-dv-timings \# $res $fld $framerate |
| 337 | ;; |
| 338 | esac |
| 339 | dbg "fmt=$fmt" |
| 340 | dbg "std=$std" |
| 341 | dbg "res=$res" |
| 342 | dbg "fld=$fld" |
| 343 | dbg "framerate=$framerate" |
| 344 | dbg "pixelclock=$pixelclock" |
| 345 | |
| 346 | # media-ctl --get-v4l2 will return fcc/res/field/colorspace |
| 347 | fmt=$($MEDIA_CTL --get-v4l2 "'$sensor':0" | sed -n 's/.*\[\(.*\)\]/\1/p') |
| 348 | SENS_FMT=$fmt |
| 349 | #out "# sensor format" |
| 350 | #out $MEDIA_CTL --get-v4l2 \'\"$sensor\":0\' \# $SENS_FMT |
| 351 | for i in $fmt; do |
| 352 | name=$(echo "$i" | sed -n 's/\(.*\):.*/\1/p') |
| 353 | val=$(echo "$i" | sed -n 's/.*:\(.*\)/\1/p') |
| 354 | eval $name="$val" |
| 355 | [ "$name" = "fmt" ] && { |
| 356 | fcc=$(echo "$val" | awk -F '/' '{print $1}') |
| 357 | res=$(echo "$val" | awk -F '/' '{print $2}') |
| 358 | int=$(echo "$val" | awk -F '@' '{print $2}') |
| 359 | [ -n "$int" ] && { |
| 360 | res=$(echo "$res" | awk -F '@' '{print $1}') |
| 361 | } |
| 362 | w=$(echo "$res" | awk -F 'x' '{print $1}') |
| 363 | h=$(echo "$res" | awk -F 'x' '{print $2}') |
| 364 | } |
| 365 | |
| 366 | [ "$name" = "field" ] && { |
| 367 | [ "$val" = "none" ] && { |
| 368 | src=${h}p |
| 369 | } || { |
| 370 | src=${h}i |
| 371 | } |
| 372 | } |
| 373 | [ "$name" = "colorspace" ] && { |
| 374 | case "$val" in |
| 375 | rec709) csc=YUV;; |
| 376 | srgb) csc=RGB;; |
| 377 | esac |
| 378 | } |
| 379 | #dbg "$name=$val" |
| 380 | done |
| 381 | |
| 382 | dbg " fld:$field" |
| 383 | dbg " fmt:$fmt" |
| 384 | dbg " fcc:$fcc" |
| 385 | dbg " res:$res (width=$w height=$h)" |
| 386 | dbg " int:$int" |
| 387 | dbg " csc:$colorspace" |
| 388 | } |
| 389 | |
| 390 | adv7180_setup() { |
| 391 | # parse sensor format into vars |
| 392 | get_sensor_format "$SENSOR" |
| 393 | } |
| 394 | |
| 395 | # set and detect current HDMI input source, break it down to its components |
| 396 | # (such as pixel format, resolution, field, and colorspace) and assign |
| 397 | # them to variables for later use |
| 398 | tda1997x_setup() { |
| 399 | # set output format to detected input format |
| 400 | out "# set sensor output pad to sensor source format" |
| 401 | $V4L2_CTL -d $SUBDEV --set-dv-bt-timings=query > /dev/null |
| 402 | out $V4L2_CTL -d $SUBDEV --set-dv-bt-timings=query |
| 403 | |
| 404 | # parse sensor format into vars |
| 405 | get_sensor_format "$SENSOR" |
| 406 | } |
| 407 | |
| 408 | # Get SOC and BOARD from dt unless passed in |
| 409 | SOC=${SOC:-$(sed -n 's/gw,\(imx6.*\)-.*/\1/p' /proc/device-tree/compatible)} |
| 410 | BOARD=${BOARD:-$(sed -n 's/gw,imx6.*-\(gw.*\)gw,ventana.*/\1/p' /proc/device-tree/compatible)} |
| 411 | SENSOR=${1:-adv7180} |
| 412 | STD=${2:-NTSC} |
| 413 | |
| 414 | dbg "BOARD=$BOARD" |
| 415 | dbg "SOC=$SOC" |
| 416 | dbg "SENSOR=$SENSOR" |
| 417 | |
| 418 | # if IPUCSI not provided, determine it from BOARD/SOC/SENSOR |
| 419 | [ -z "${IPU}" -o -z "${CSI}" ] && { |
| 420 | dbg "Determining IPU and CSI for ${SOC}-${BOARD}-${SENSOR}..." |
| 421 | case "${SOC}-${BOARD}-${SENSOR}" in |
| 422 | imx6q-gw54xx-adv7180|\ |
| 423 | imx6q-gw53xx-adv7180|\ |
| 424 | imx6q-gw52xx-adv7180) |
| 425 | IPU=2 |
| 426 | CSI=1 |
| 427 | ;; |
| 428 | imx6dl-gw52xx-adv7180|\ |
| 429 | imx6dl-gw53xx-adv7180) |
| 430 | IPU=1 |
| 431 | CSI=1 |
| 432 | ;; |
| 433 | imx6q-gw51xx-adv7180|\ |
| 434 | imx6q-gw553x-adv7180|\ |
| 435 | imx6dl-gw51xx-adv7180|\ |
| 436 | imx6dl-gw553x-adv7180|\ |
| 437 | imx6dl-gw551x-tda1997x|\ |
| 438 | imx6q-gw551x-tda1997x|\ |
| 439 | imx6q-gw54xx-tda1997x) |
| 440 | IPU=1 |
| 441 | CSI=0 |
| 442 | ;; |
| 443 | *) |
| 444 | err 1 "Unrecognized board/soc/sensor: '${SOC}-${BOARD}-${SENSOR}'" |
| 445 | ;; |
| 446 | esac |
| 447 | case "${SENSOR}" in |
| 448 | adv7180) |
| 449 | SENS=$SENSOR |
| 450 | SENSOR="adv7180 2-0020" |
| 451 | # use VDIC pipeline for Analog CVBS capture |
| 452 | MODE=${MODE:-3} |
| 453 | ;; |
| 454 | tda1997x) |
| 455 | SENS=$SENSOR |
| 456 | SENSOR="tda19971 2-0048" |
| 457 | # use RAW pipeline for Digital HDMI capture |
| 458 | MODE=${MODE:-0} |
| 459 | ;; |
| 460 | esac |
| 461 | } |
| 462 | SUBDEV=$($MEDIA_CTL -e "$SENSOR") |
| 463 | dbg "SUBDEV=$SUBDEV" |
| 464 | |
| 465 | # create graphs (txt/dot/png) in $DIR if exists |
| 466 | [ -n "$DIR" -a -d "$DIR" ] && { |
| 467 | $MEDIA_CTL --reset |
| 468 | $MEDIA_CTL --print-topology > ${DIR}/${SOC}-${BOARD}-media.txt |
| 469 | $MEDIA_CTL --print-dot > ${DIR}/${SOC}-${BOARD}-media.dot |
| 470 | [ -x /usr/bin/dot ] && /usr/bin/dot -Tpng \ |
| 471 | ${DIR}/${SOC}-${BOARD}-media.dot \ |
| 472 | > ${DIR}/${SOC}-${BOARD}-media.png |
| 473 | } |
| 474 | |
| 475 | # Mode: |
| 476 | # There are multiple basic IMX6 pipelines which we will specify by a mode var: |
| 477 | # 0: sensor -> mux -> csi -> /dev/videoN |
| 478 | # 1: sensor -> mux -> csi -> ic_prp -> ic_prpenc -> /dev/videoN |
| 479 | # 2: sensor -> mux -> csi -> ic_prp -> ic_prpvf -> /dev/videoN |
| 480 | # 3: sensor -> mux -> csi -> vdic -> ic_prp -> ic_prpvf -> /dev/videoN |
| 481 | MODE=${MODE:-0} |
| 482 | case $MODE in |
| 483 | 0) MODE_DESC="sensor->mux->csi";; |
| 484 | 1) MODE_DESC="sensor->mux->csi->ic_prp->ic_prpenc";; |
| 485 | 2) MODE_DESC="sensor->mux->csi->ic_prp->ic_prpvf";; |
| 486 | 3) MODE_DESC="sensor->mux->csi->vdic->ic_prp->ic_prpvf";; |
| 487 | *) err 1 "invalid MODE:$MODE";; |
| 488 | esac |
| 489 | |
| 490 | dbg "IPUCSI=ipu${IPU}_csi${CSI} MODE$MODE:$MODE_DESC" |
| 491 | |
| 492 | out "#!/bin/sh" |
| 493 | out "" |
| 494 | out "# ${SOC}-${BOARD} ${SENS} IPU${IPU}_CSI${CSI} MODE$MODE:$MODE_DESC" |
| 495 | out "" |
| 496 | |
| 497 | # perform any sensor specific setup |
| 498 | ${SENS}_setup |
| 499 | |
| 500 | out "" |
| 501 | out "#" |
| 502 | out "# ${SOC}-${BOARD} IPU${IPU}_CSI${CSI} ${SENS} $fcc ${src}@${framerate}Hz $csc MODE${MODE}:$MODE_DESC $(uname -r)" |
| 503 | out "#" |
| 504 | out "# reset all links" |
| 505 | out "$MEDIA_CTL --reset" |
| 506 | |
| 507 | # setup links, formats, and EP (endpoint entity) |
| 508 | mode${MODE} |
| 509 | dbg "EP=$EP" |
| 510 | # set v4l2 capture device |
| 511 | DEVICE=$($MEDIA_CTL -e "$EP capture") |
| 512 | out "# devices" |
| 513 | [ "$SENS" = "adv7180" -a "$MODE" -ne "3" ] && { |
| 514 | out "# configure video device" |
| 515 | out $V4L2_CTL --device $DEVICE --set-fmt-video=field=interlaced_bt |
| 516 | } |
| 517 | |
| 518 | ENCODER=/dev/$(for i in $(ls -d /sys/class/video4linux/video*); do [ "coda-encoder" = "$(cat $i/name)" ] && basename $i; done) |
| 519 | DECODER=/dev/$(for i in $(ls -d /sys/class/video4linux/video*); do [ "coda-decoder" = "$(cat $i/name)" ] && basename $i; done) |
| 520 | MEM2MEM=/dev/$(for i in $(ls -d /sys/class/video4linux/video*); do [ "ipu_ic_pp mem2mem" = "$(cat $i/name)" ] && basename $i; done) |
| 521 | GST_CONVERT=$(gst-inspect-1.0 | grep -e "v4l2.*convert*" | sed -e 's/.*:\s*\(v4l2.*convert\):.*/\1/') |
| 522 | |
| 523 | out "echo DEVICE=$DEVICE" |
| 524 | out "echo ENCODER=$ENCODER" |
| 525 | out "echo DECODER=$DECODER" |
| 526 | out "echo MEM2MEM=$MEM2MEM" |
| 527 | out "echo GST_CONVERT=$GST_CONVERT" |
| 528 | out "export DEVICE=$DEVICE # capture" |
| 529 | out "export ENCODER=$ENCODER # encode" |
| 530 | out "export DECODER=$DECODER # decode" |
| 531 | out "export MEM2MEM=$MEM2MEM # converter" |
| 532 | out "export GST_CONVERT=$GST_CONVERT # GST converter" |
| 533 | |