|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +read_aura_reg () { |
| 4 | + a=$(/usr/sbin/i2cget -y -f 10 0x68 "$1") |
| 5 | + echo "$a" |
| 6 | +} |
| 7 | + |
| 8 | +turn_aura_page () { |
| 9 | + /usr/sbin/i2cset -y -f 10 0x68 0xff "$1" |
| 10 | +} |
| 11 | + |
| 12 | +write_aura_reg() { |
| 13 | + /usr/sbin/i2cset -y -f 10 0x68 "$1" "$2" |
| 14 | +} |
| 15 | + |
| 16 | +dump_aura_page () { |
| 17 | + turn_aura_page "$1" |
| 18 | + for ((num=1; num <= "$2"; num++)) |
| 19 | + do |
| 20 | + hex=$(printf '0x%x' "$a") |
| 21 | + read_val=$(read_aura_reg "$hex") |
| 22 | + echo "$1" : "$hex" : "$read_val" |
| 23 | + done |
| 24 | +} |
| 25 | +dump_aura_all_page() { |
| 26 | + echo Page 0x0 |
| 27 | + dump_aura_page 0x0 235 |
| 28 | + echo Page 0x1 |
| 29 | + dump_aura_page 0x1 47 |
| 30 | + echo Page 0x2 |
| 31 | + dump_aura_page 0x2 79 |
| 32 | + echo Page 0x3 |
| 33 | + dump_aura_page 0x3 111 |
| 34 | + echo Page 0x4 |
| 35 | + dump_aura_page 0x4 111 |
| 36 | + echo Page 0x6 |
| 37 | + dump_aura_page 0x6 239 |
| 38 | + echo Page 0x7 |
| 39 | + dump_aura_page 0x7 239 |
| 40 | + echo Page 0x0a |
| 41 | + dump_aura_page 0x0a 238 |
| 42 | + echo Page 0x1a |
| 43 | + dump_aura_page 0x1a 99 |
| 44 | + echo Page 0x0b |
| 45 | + dump_aura_page 0x0b 238 |
| 46 | + echo Page 0x1b |
| 47 | + dump_aura_page 0x1b 99 |
| 48 | + echo Page 0x0c |
| 49 | + dump_aura_page 0x0c 238 |
| 50 | + echo Page 0x1c |
| 51 | + dump_aura_page 0x1c 99 |
| 52 | + echo Page 0x0d |
| 53 | + dump_aura_page 0x0d 238 |
| 54 | + echo Page 0x1d |
| 55 | + dump_aura_page 0x1d 99 |
| 56 | +} |
| 57 | + |
| 58 | +#DCO Config |
| 59 | +config_aura_dco () { |
| 60 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 61 | + /usr/sbin/i2cset -y -f 10 0x68 0x17 0x0a |
| 62 | + /usr/sbin/i2cset -y -f 10 0x68 0x42 0x00 |
| 63 | + /usr/sbin/i2cset -y -f 10 0x68 0x57 0x42 |
| 64 | + /usr/sbin/i2cset -y -f 10 0x68 0x0f 0x00 |
| 65 | + /usr/sbin/i2cset -y -f 10 0x68 0x0f 0x01 |
| 66 | + /usr/sbin/i2cset -y -f 10 0x68 0x0f 0x00 |
| 67 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 68 | + /usr/sbin/i2cset -y -f 10 0x68 0x0f 0x10 |
| 69 | + /usr/sbin/i2cset -y -f 10 0x68 0x0f 0x40 |
| 70 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 71 | + /usr/sbin/i2cset -y -f 10 0x68 0xbd 0xc3 |
| 72 | + /usr/sbin/i2cset -y -f 10 0x68 0xd1 0xb0 |
| 73 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x1a |
| 74 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 75 | + /usr/sbin/i2cget -y -f 10 0x68 0x57 |
| 76 | + /usr/sbin/i2cset -y -f 10 0x68 0x57 0x42 |
| 77 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 78 | + /usr/sbin/i2cset -y -f 10 0x68 0x51 0x00 |
| 79 | + /usr/sbin/i2cset -y -f 10 0x68 0x52 0x48 |
| 80 | + /usr/sbin/i2cset -y -f 10 0x68 0x53 0x55 |
| 81 | + /usr/sbin/i2cset -y -f 10 0x68 0x54 0x55 |
| 82 | + /usr/sbin/i2cset -y -f 10 0x68 0x55 0x35 |
| 83 | + /usr/sbin/i2cset -y -f 10 0x68 0x56 0x00 |
| 84 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0b |
| 85 | + /usr/sbin/i2cget -y -f 10 0x68 0x57 |
| 86 | + /usr/sbin/i2cset -y -f 10 0x68 0x57 0x01 |
| 87 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0c |
| 88 | + /usr/sbin/i2cget -y -f 10 0x68 0x57 |
| 89 | + /usr/sbin/i2cset -y -f 10 0x68 0x57 0x01 |
| 90 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0d |
| 91 | + /usr/sbin/i2cget -y -f 10 0x68 0x57 |
| 92 | + /usr/sbin/i2cset -y -f 10 0x68 0x57 0x01 |
| 93 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x00 |
| 94 | +} |
| 95 | + |
| 96 | +# Increase Freq |
| 97 | +increase_aura_freq() { |
| 98 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xae |
| 99 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xee |
| 100 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xae |
| 101 | +} |
| 102 | + |
| 103 | +# Decrease Freq |
| 104 | +decrease_aura_freq () { |
| 105 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xae |
| 106 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xbe |
| 107 | + /usr/sbin/i2cset -y -f 10 0x68 0x64 0xae |
| 108 | +} |
| 109 | + |
| 110 | +check_permanent_fix () { |
| 111 | + echo "0" |
| 112 | +} |
| 113 | + |
| 114 | +check_volatile_fix() { |
| 115 | + # Enable Debug Mode |
| 116 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x0a |
| 117 | + /usr/sbin/i2cset -y -f 10 0x68 0xbd 0xc3 |
| 118 | + /usr/sbin/i2cset -y -f 10 0x68 0xb3 0x57 |
| 119 | + |
| 120 | + # Read Divider |
| 121 | + reg_read=$(read_aura_reg 0xd0) |
| 122 | + reg_read=$(read_aura_reg 0xb5) |
| 123 | + driver="${reg_read}" |
| 124 | + reg_read=$(read_aura_reg 0xb6) |
| 125 | + driver="${driver} ${reg_read}" |
| 126 | + reg_read=$(read_aura_reg 0xb7) |
| 127 | + driver="${driver} ${reg_read}" |
| 128 | + reg_read=$(read_aura_reg 0xb8) |
| 129 | + driver="${driver} ${reg_read}" |
| 130 | + reg_read=$(read_aura_reg 0xb9) |
| 131 | + driver="${driver} ${reg_read}" |
| 132 | + reg_read=$(read_aura_reg 0xba) |
| 133 | + driver="${driver} ${reg_read}" |
| 134 | + reg_read=$(read_aura_reg 0xbb) |
| 135 | + driver="${driver} ${reg_read}" |
| 136 | + reg_read=$(read_aura_reg 0xbc) |
| 137 | + driver="${driver} ${reg_read}" |
| 138 | + |
| 139 | + # Read Denominator |
| 140 | + /usr/sbin/i2cset -y -f 10 0x68 0xb3 0x56 |
| 141 | + reg_read=$(read_aura_reg 0xd0) |
| 142 | + reg_read=$(read_aura_reg 0xb5) |
| 143 | + denominator="${reg_read}" |
| 144 | + reg_read=$(read_aura_reg 0xb6) |
| 145 | + denominator="${denominator} ${reg_read}" |
| 146 | + reg_read=$(read_aura_reg 0xb7) |
| 147 | + denominator="${denominator} ${reg_read}" |
| 148 | + reg_read=$(read_aura_reg 0xb8) |
| 149 | + denominator="${denominator} ${reg_read}" |
| 150 | + reg_read=$(read_aura_reg 0xb9) |
| 151 | + denominator="${denominator} ${reg_read}" |
| 152 | + reg_read=$(read_aura_reg 0xba) |
| 153 | + denominator="${denominator} ${reg_read}" |
| 154 | + reg_read=$(read_aura_reg 0xbb) |
| 155 | + denominator="${denominator} ${reg_read}" |
| 156 | + |
| 157 | + # Disable Debug Mode |
| 158 | + /usr/sbin/i2cset -y -f 10 0x68 0xbd 0x00 |
| 159 | + # Return values: |
| 160 | + # 0: Needs fix, |
| 161 | + # 1: Already fixed, |
| 162 | + # Anything Else: Unknown state |
| 163 | + if [ "$driver" == "0x00 0x00 0x55 0x55 0x55 0x15 0x34 0x00" ]; then |
| 164 | + echo "0" |
| 165 | + elif [ "$driver" == "0x00 0x20 0xaa 0xaa 0x2a 0x16 0x34 0x00" ]; then |
| 166 | + echo "1" |
| 167 | + else |
| 168 | + echo "$driver" |
| 169 | + fi |
| 170 | +} |
| 171 | + |
| 172 | +check_if_aura() { |
| 173 | + a=$(i2cdetect -y 10|grep -c 68) |
| 174 | + if [ "$a" == "1" ]; then |
| 175 | + echo "1" |
| 176 | + else |
| 177 | + echo "0" |
| 178 | + fi |
| 179 | +} |
| 180 | + |
| 181 | +improve_aura_pll() { |
| 182 | + aura_found=$(check_if_aura) |
| 183 | + if [ "$aura_found" == "1" ]; then |
| 184 | + echo "Aura Crystal found. Moving on" |
| 185 | + else |
| 186 | + echo "Aura chip not found. Exiting..." |
| 187 | + exit 0 |
| 188 | + fi |
| 189 | + perma_fix=$(check_permanent_fix) |
| 190 | + if [ "$perma_fix" == "1" ]; then |
| 191 | + echo "Permanent Aura Fix Applied. No need to apply volatile fix." |
| 192 | + exit |
| 193 | + else |
| 194 | + echo "No Permanent Aura Fix Found" |
| 195 | + fi |
| 196 | + retry="3" |
| 197 | + while [ "$retry" != "0" ]; do |
| 198 | + retry=$(("$retry" - 1)) |
| 199 | + echo "Retry left : $retry" |
| 200 | + vola_fix=$(check_volatile_fix) |
| 201 | + if [ "$vola_fix" == "1" ]; then |
| 202 | + echo "Volatile Aura Fix Applied. No need to apply volatile fix." |
| 203 | + echo "AURA_FIX_SUCCESS" |
| 204 | + exit |
| 205 | + elif [ "$vola_fix" == "0" ]; then |
| 206 | + echo "No Volatile Aura Fix Found" |
| 207 | + else |
| 208 | + echo "Aura is in bad state. Trying soft reset of Aura." |
| 209 | + /usr/sbin/i2cset -y -f 10 0x68 0xff 0x00 |
| 210 | + /usr/sbin/i2cset -y -f 10 0x68 0xfe 0x01 |
| 211 | + /usr/sbin/i2cset -y -f 10 0x68 0xfe 0x00 |
| 212 | + echo "Sleeping for 10 seconds for PLL on Aura to lock" |
| 213 | + sleep 10 |
| 214 | + fi |
| 215 | + echo "Applying Auro Volatile Fix..." |
| 216 | + echo "Configuring Aura DCO" |
| 217 | + config_aura_dco |
| 218 | + echo "Increasing Aura all PLL freq : Execution 1 or 4" |
| 219 | + increase_aura_freq |
| 220 | + echo "Increasing Aura all PLL freq : Execution 2 or 4" |
| 221 | + increase_aura_freq |
| 222 | + echo "Increasing Aura all PLL freq : Execution 3 or 4" |
| 223 | + increase_aura_freq |
| 224 | + echo "Increasing Aura all PLL freq : Execution 4 or 4" |
| 225 | + increase_aura_freq |
| 226 | + vola_fix=$(check_volatile_fix) |
| 227 | + if [ "$vola_fix" == "1" ]; then |
| 228 | + echo "AURA_FIX_SUCCESS" |
| 229 | + exit |
| 230 | + else |
| 231 | + echo "Unexpected driver value after programming : $vola_fix" |
| 232 | + fi |
| 233 | + done |
| 234 | + echo "AURA_FIX_FAILURE" |
| 235 | + exit 1 |
| 236 | +} |
| 237 | + |
| 238 | +# Main Entry. Run the script to improve Aura Pll |
| 239 | +if [ "$1" == "check" ]; then |
| 240 | + if [ "$(check_if_aura)" != "1" ]; then |
| 241 | + echo "UNSUPPORTED_HW_AURA_CRYSTAL_NOT_FOUND" |
| 242 | + exit 1 |
| 243 | + fi |
| 244 | + status=$(check_volatile_fix) |
| 245 | + if [ "$status" == "1" ]; then |
| 246 | + echo "FIX_APPLIED" |
| 247 | + exit 0 |
| 248 | + elif [ "$status" == "0" ]; then |
| 249 | + echo "FIX_NOT_APPLIED" |
| 250 | + exit 1 |
| 251 | + else |
| 252 | + echo "UNKNOWN_STATE" |
| 253 | + exit 1 |
| 254 | + fi |
| 255 | +else |
| 256 | + improve_aura_pll |
| 257 | +fi |
0 commit comments