1 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Copyright (C) 2011 by Karl Kurbjun
5 # Copyright (C) 2009 by David Brownell
8 # Utilities for TI ICEpick-C/D used in most TI SoCs
9 # Details about the ICEPick are available in the the TRM for each SoC
10 # and http://processors.wiki.ti.com/index.php/ICEPICK
16 # define ICEPick instructions
22 return $constant($key)
25 # Instruction to connect to the icepick module
26 proc icepick_c_connect {jrc} {
28 # Send CONNECT instruction in IR state
29 irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
31 # Send write and connect key
32 drscan $jrc 8 0x89 -endstate DRPAUSE
35 # Instruction to disconnect to the icepick module
36 proc icepick_c_disconnect {jrc} {
38 # Send CONNECT instruction in IR state
39 irscan $jrc [CONST IR_CONNECT] -endstate IRPAUSE
41 # Send write and connect key
42 drscan $jrc 8 0x86 -endstate DRPAUSE
47 # this function is for sending router commands
49 # jrc: TAP name for the ICEpick
50 # rw: read/write (0 for read, 1 for write)
51 # block: icepick or DAP
52 # register: which register to read/write
53 # payload: value to read/write
54 # this function is for sending router commands
56 proc icepick_c_router {jrc rw block register payload} {
59 [expr { ( ($rw & 0x1) << 31) | ( ($block & 0x7) << 28) | \
60 ( ($register & 0xF) << 24) | ( $payload & 0xFFFFFF ) } ]
62 # echo "\tNew router value:\t0x[format %x $new_dr_value]"
65 irscan $jrc [CONST IR_ROUTER] -endstate IRPAUSE
67 # ROUTER instructions are 32 bits wide
68 set old_dr_value 0x[drscan $jrc 32 $new_dr_value -endstate DRPAUSE]
69 # echo "\tOld router value:\t0x[format %x $old_dr_value]"
72 # Configure the icepick control register
73 proc icepick_c_setup {jrc} {
75 # send a router write, block is 0, register is 1, value is 0x2100
76 icepick_c_router $jrc 1 0x0 0x1 0x001000
79 # jrc == TAP name for the ICEpick
80 # port == a port number, 0..15 for debug tap, 16..31 for test tap
81 proc icepick_c_tapenable {jrc port} {
83 if { ($port >= 0) && ($port < 16) } {
87 } elseif { $port < 32 } {
89 set tap [expr {$port - 16}]
92 echo "ERROR: Invalid ICEPick C port number: $port"
96 # First CONNECT to the ICEPick
97 # echo "Connecting to ICEPick"
98 icepick_c_connect $jrc
100 # echo "Configuring the ICEpick"
103 # NOTE: it's important not to enter RUN/IDLE state until
104 # done sending these instructions and data to the ICEpick.
105 # And never to enter RESET, which will disable the TAPs.
107 # first enable power and clock for TAP
108 icepick_c_router $jrc 1 $block $tap 0x110048
110 # TRM states that the register should be read back here, skipped for now
112 # enable debug "default" mode
113 icepick_c_router $jrc 1 $block $tap 0x112048
115 # TRM states that debug enable and debug mode should be read back and
116 # confirmed - skipped for now
118 # Finally select the tap
119 icepick_c_router $jrc 1 $block $tap 0x112148
121 # Enter the bypass state
122 irscan $jrc [CONST IR_BYPASS] -endstate RUN/IDLE
126 # jrc == TAP name for the ICEpick
127 # coreid== core id number 0..15 (not same as port number!)
128 proc icepick_d_set_core_control {jrc coreid value } {
129 icepick_c_router $jrc 1 0x6 $coreid $value
132 # jrc == TAP name for the ICEpick
133 # port == a port number, 0..15
134 # Follow the sequence described in
135 # http://processors.wiki.ti.com/images/f/f6/Router_Scan_Sequence-ICEpick-D.pdf
136 proc icepick_d_tapenable {jrc port coreid { value 0x2008 } } {
138 # First CONNECT to the ICEPick
139 icepick_c_connect $jrc
143 icepick_c_router $jrc 1 0x2 $port 0x2108
145 # Set icepick core control for $coreid
146 icepick_d_set_core_control $jrc $coreid $value
148 # Enter the bypass state
149 irscan $jrc [CONST IF_BYPASS] -endstate RUN/IDLE
153 # This function uses the ICEPick to send a warm system reset
154 proc icepick_c_wreset {jrc} {
156 # send a router write, block is 0, register is 1, value is 0x2100
157 icepick_c_router $jrc 1 0x0 0x1 0x002101