demo: Fix timeout command usage
[glsdk/util-scripts.git] / debug / vip_diagnostic.sh
1 #!/bin/bash
2 #Author:- Nikhil Devshatwar
3 #This script is used for debugging issues with VIP and LVDS cameras.
4 #This can be used for linux based capture as well as infoadas use cases.
5 #For any queries, contact http://e2e.ti.com/support/omap/f/885
8 resolve_port()
9 {
10         if [ $port = "vin1a" ]; then
11                 inst=0x48970000
12                 slice=0x5500
13                 i2cbus=11
14                 desAddr=0x60
15                 crossbar=VIP1_IRQ_1
16                 echo "VIP 1 Slice 0 Port A <--> LVDS cam1"
17         elif [ $port = "vin2a" ]; then
18                 inst=0x48970000
19                 slice=0x5a00
20                 i2cbus=12
21                 desAddr=0x64
22                 crossbar=VIP1_IRQ_2
23                 echo "VIP 1 Slice 1 Port A <--> LVDS cam2"
24         elif [ $port = "vin3a" ]; then
25                 inst=0x48990000
26                 slice=0x5500
27                 i2cbus=13
28                 desAddr=0x68
29                 crossbar=VIP2_IRQ_1
30                 echo "VIP 2 Slice 0 Port A <--> LVDS cam3"
31         elif [ $port = "vin4b" ]; then
32                 inst=0x48990000
33                 slice=0x5a00
34                 i2cbus=15
35                 desAddr=0x61
36                 crossbar=VIP2_IRQ_2
37                 echo "VIP 2 Slice 1 Port B <--> LVDS cam5"
38         elif [ $port = "vin5a" ]; then
39                 inst=0x489b0000
40                 slice=0x5500
41                 i2cbus=14
42                 desAddr=0x6c
43                 crossbar=VIP3_IRQ_1
44                 echo "VIP 3 Slice 0 Port A <--> LVDS cam4"
45         elif [ $port = "vin6a" ]; then
46                 inst=0x489b0000
47                 slice=0x5a00
48                 i2cbus=16
49                 desAddr=0x69
50                 crossbar=VIP3_IRQ_2
51                 echo "VIP 3 Slice 1 Port A <--> LVDS cam6"
52         else
53                 echo "Unsupported port $port"
54                 exit 1
55         fi
56 }
58 resolve_board()
59 {
60         basebus=1
61 }
63 parser_reg()
64 {
65         addr=`printf "0x%08x" $(( $inst + $slice + $2 ))`
66         omapconf $1 $addr $3 2>/dev/null
67 }
69 vpdma_dumpdesc()
70 {
71         echo
72         echo "VPDMA descriptor dump"
73         listAddr=`printf "0x%x" $(( $inst + 0xd004 ))`
74         startAddr=0x`omapconf read $listAddr 2>/dev/null`
75         endAddr=`printf "0x%x" $(( $startAddr + 0x40 ))`
76         omapconf dump $startAddr $endAddr 2>/dev/null
78         #Print the data type
79         w0Addr=`printf "0x%x" $(( $startAddr + 0x0 ))`
80         word0=`omapconf read $w0Addr 2>/dev/null`
81         dtype=`printf "0x%x" $(( 0x$word0 >> 26 & 0x3f))`
82         echo "VPDMA data type:- $dtype"
84         #Print the channel number
85         w4Addr=`printf "0x%x" $(( $startAddr + 0xc ))`
86         word4=`omapconf read $w4Addr 2>/dev/null`
87         chan=`printf "%d" $(( 0x$word4 >> 16 & 0xff))`
88         echo "VPDMA channel number used:- $chan" 
90         #Print write descriptor
91         echo
92         echo "VPDMA write descriptor dump"
93         w5Addr=`printf "0x%x" $(( $startAddr + 0x10 ))`
94         word4=0x`omapconf read $w5Addr 2>/dev/null`
95         wrst=`printf "0x%x" $(( $word4 & ~0x7))`
96         wrend=`printf "0x%x" $(( $wrst + 0x20 ))`
97         omapconf dump $wrst $wrend 2>/dev/null
99         #Print size written
100         fraddr=`printf "0x%x" $(( $wrst + 0x10 ))`
101         frval=0x`omapconf read $fraddr 2>/dev/null`
102         width=`printf "%d" $(( $frval >> 16 ))`
103         height=`printf "%d" $(( $frval & 0xff ))`
104         echo "Frame size written:- $width x $height"
107 ovcam() {
108 #ovcam [read | write] <i2cbus> <chip> <16bit addr> [<val>]
109         addrlow=`printf "0x%02x" $(($4 & 0xff))`
110         addrhigh=`printf "0x%02x" $(($4 >> 8))`
111         i2cset -f -y $2 $3 $addrhigh $addrlow
112         if [ $1 = "read" ]; then
113                 i2cget -f -y $2 $3
114         elif [ $1 = "write" ]; then
115                 i2cset -f -y $2 $3 $5
116         fi
119 getIRQcnt() {
120 #Make sure that gicirq is set correctly
121         cat /proc/interrupts | grep "$gicirq" | awk '-F ' '{ print $2 }'
124 crossbar_dump() {
125         echo
126         echo "Crossbar mapping:-"
127         mpumap=`omapconf dump crossbar 2>/dev/null | grep $crossbar`
128         echo $mpumap
129         echo
130         mpuirq=`echo $mpumap | cut -d ' ' -f2`
131         srcirq=`echo $mpumap | cut -d ' ' -f6`
132         gicirq=`printf "GIC %d" $(( $mpuirq + 32 ))`
133         echo "Crossbar source $srcirq $crossbar mapped to MPU $gicirq"
134         cat /proc/interrupts | grep "$gicirq"
135         echo
136         echo "Interrupt count:- `getIRQcnt`"
139 testE()
141         printf "=> %50s" "$1"
142         if [ $2 = $3 ]; then
143                 echo -e "\t\tPASS"
144         else
145                 echo -e "\t\t\tFAIL"
146         fi
149 testNE()
151         printf "=> %50s" "$1"
152         if [ $2 != $3 ]; then
153                 echo -e "\t\tPASS"
154         else
155                 echo -e "\t\t\tFAIL"
156         fi
159 echo
160 echo
161 echo "=====================VIP diagnostic script==================="
162 echo  "Basic tests to debug capture issues quickly"
163 echo
165 #set -x
166 port="vin1a"
167 #Parse the cmd line args
168 if [ $# -gt 0 ]; then
169         port=$1
170         shift
171 fi
173 resolve_port
174 resolve_board
176 testE "Check if the DE-SERIALIZER is accessible"        `i2cget -f -y $basebus $desAddr 0x0`    "0xc0"
177 testE "Check if the SERIALIZER is connected"            `i2cget -f -y $basebus $desAddr 0x1c`   "0x03"
178 testE "Check if the SERIALIZER is accessible"           `i2cget -f -y $i2cbus 0x58 0x0`         "0xb0"
179 testE "Check if the CAMERA clock is present"            `i2cget -f -y $i2cbus 0x58 0x0c`        "0x15"
180 testE "Check if the CAMERA is accessible"               `ovcam read $i2cbus 0x30 0x300b`        "0x35"
181 testNE "Check if the parser is configured"              `parser_reg read 0x04`                  "00000000"
182 testNE "Check if the port is detecting the frame size"  `parser_reg read 0x30`                  "00000000"
184 vpdma_dumpdesc
186 crossbar_dump
188 echo
189 echo "=============================END============================="
190 #TODO: Check pinmux registers, check gpio data
191 #TODO: Check board muxes
192 #TODO: Calculate FPS
193 #TODO: Check if the sensor-cfg works for start/stop - connect/disconnect
194 #TODO: Check low FPS capture
195 #TODO: Check multi instance capture
197 echo "If all of these tests PASS and still there is a problem, go home :)"
198 echo
199 echo