drivers/bcm2835gpio: Migrate to adapter gpio commands

Use the new "adapter gpio" commands to configure the GPIOs used by the
bcm2835gpio driver. The driver supports only 1 chip (gpiochip0).

The reset function now honours the srst_open_drain and trst_open_drain
options.

Signed-off-by: Steve Marple <stevemarple@googlemail.com>
Change-Id: I5b6c68b16362000cf5141a83394549d2bf3af108
Reviewed-on: https://review.openocd.org/c/openocd/+/7123
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Steve Marple
2022-06-25 23:45:18 +01:00
committed by Antonio Borneo
parent e643a494d4
commit 0dd969d83b
7 changed files with 460 additions and 457 deletions

View File

@@ -3292,66 +3292,12 @@ able to coexist nicely with both sysfs bitbanging and various
peripherals' kernel drivers. The driver restores the previous
configuration on exit.
GPIO numbers >= 32 can't be used for performance reasons.
GPIO numbers >= 32 can't be used for performance reasons. GPIO configuration is
handled by the generic command @ref{adapter gpio, @command{adapter gpio}}.
See @file{interface/raspberrypi-native.cfg} for a sample config and
pinout.
@deffn {Config Command} {bcm2835gpio jtag_nums} @var{tck} @var{tms} @var{tdi} @var{tdo}
Set JTAG transport GPIO numbers for TCK, TMS, TDI, and TDO (in that order).
Must be specified to enable JTAG transport. These pins can also be specified
individually.
@end deffn
@deffn {Config Command} {bcm2835gpio tck_num} @var{tck}
Set TCK GPIO number. Must be specified to enable JTAG transport. Can also be
specified using the configuration command @command{bcm2835gpio jtag_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio tms_num} @var{tms}
Set TMS GPIO number. Must be specified to enable JTAG transport. Can also be
specified using the configuration command @command{bcm2835gpio jtag_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio tdo_num} @var{tdo}
Set TDO GPIO number. Must be specified to enable JTAG transport. Can also be
specified using the configuration command @command{bcm2835gpio jtag_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio tdi_num} @var{tdi}
Set TDI GPIO number. Must be specified to enable JTAG transport. Can also be
specified using the configuration command @command{bcm2835gpio jtag_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio swd_nums} @var{swclk} @var{swdio}
Set SWD transport GPIO numbers for SWCLK and SWDIO (in that order). Must be
specified to enable SWD transport. These pins can also be specified individually.
@end deffn
@deffn {Config Command} {bcm2835gpio swclk_num} @var{swclk}
Set SWCLK GPIO number. Must be specified to enable SWD transport. Can also be
specified using the configuration command @command{bcm2835gpio swd_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio swdio_num} @var{swdio}
Set SWDIO GPIO number. Must be specified to enable SWD transport. Can also be
specified using the configuration command @command{bcm2835gpio swd_nums}.
@end deffn
@deffn {Config Command} {bcm2835gpio swdio_dir_num} @var{swdio} @var{dir}
Set SWDIO direction control pin GPIO number. If specified, this pin can be used
to control the direction of an external buffer on the SWDIO pin (set=output
mode, clear=input mode). If not specified, this feature is disabled.
@end deffn
@deffn {Config Command} {bcm2835gpio srst_num} @var{srst}
Set SRST GPIO number. Must be specified to enable SRST.
@end deffn
@deffn {Config Command} {bcm2835gpio trst_num} @var{trst}
Set TRST GPIO number. Must be specified to enable TRST.
@end deffn
@deffn {Config Command} {bcm2835gpio speed_coeffs} @var{speed_coeff} @var{speed_offset}
Set SPEED_COEFF and SPEED_OFFSET for delay calculations. If unspecified,
speed_coeff defaults to 113714, and speed_offset defaults to 28.

File diff suppressed because it is too large Load Diff

View File

@@ -455,70 +455,140 @@ proc vsllink_usb_interface args {
eval vsllink usb_interface $args
}
lappend _telnet_autocomplete_skip bcm2835_gpio_helper
proc bcm2835_gpio_helper {sig_name args} {
set caller [lindex [info level -1] 0]
echo "DEPRECATED! use 'adapter gpio $sig_name' not '$caller'"
switch [llength $args] {
0 {}
1 {eval adapter gpio $sig_name $args -chip 0}
2 {eval adapter gpio $sig_name [lindex $args 1] -chip [lindex $args 0]}
default {return -code 1 -level 1 "$caller: syntax error"}
}
eval adapter gpio $sig_name
}
lappend _telnet_autocomplete_skip bcm2835gpio_jtag_nums
proc bcm2835gpio_jtag_nums args {
echo "DEPRECATED! use 'bcm2835gpio jtag_nums' not 'bcm2835gpio_jtag_nums'"
eval bcm2835gpio jtag_nums $args
proc bcm2835gpio_jtag_nums {tck_num tms_num tdi_num tdo_num} {
echo "DEPRECATED! use 'adapter gpio tck; adapter gpio tms; adapter gpio tdi; adapter gpio tdo' not 'bcm2835gpio_jtag_nums'"
eval adapter gpio tck $tck_num -chip 0
eval adapter gpio tms $tms_num -chip 0
eval adapter gpio tdi $tdi_num -chip 0
eval adapter gpio tdo $tdo_num -chip 0
}
lappend _telnet_autocomplete_skip bcm2835gpio_tck_num
proc bcm2835gpio_tck_num args {
echo "DEPRECATED! use 'bcm2835gpio tck_num' not 'bcm2835gpio_tck_num'"
eval bcm2835gpio tck_num $args
eval bcm2835_gpio_helper tck $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_tms_num
proc bcm2835gpio_tms_num args {
echo "DEPRECATED! use 'bcm2835gpio tms_num' not 'bcm2835gpio_tms_num'"
eval bcm2835gpio tms_num $args
eval bcm2835_gpio_helper tms $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_tdo_num
proc bcm2835gpio_tdo_num args {
echo "DEPRECATED! use 'bcm2835gpio tdo_num' not 'bcm2835gpio_tdo_num'"
eval bcm2835gpio tdo_num $args
eval bcm2835_gpio_helper tdo $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_tdi_num
proc bcm2835gpio_tdi_num args {
echo "DEPRECATED! use 'bcm2835gpio tdi_num' not 'bcm2835gpio_tdi_num'"
eval bcm2835gpio tdi_num $args
eval bcm2835_gpio_helper tdi $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_swd_nums
proc bcm2835gpio_swd_nums args {
echo "DEPRECATED! use 'bcm2835gpio swd_nums' not 'bcm2835gpio_swd_nums'"
eval bcm2835gpio swd_nums $args
proc bcm2835gpio_swd_nums {swclk_num swdio_num} {
echo "DEPRECATED! use 'adapter gpio swclk; adapter gpio swdio' not 'bcm2835gpio_swd_nums'"
eval adapter gpio swclk $swclk_num -chip 0
eval adapter gpio swdio $swdio_num -chip 0
}
lappend _telnet_autocomplete_skip bcm2835gpio_swclk_num
proc bcm2835gpio_swclk_num args {
echo "DEPRECATED! use 'bcm2835gpio swclk_num' not 'bcm2835gpio_swclk_num'"
eval bcm2835gpio swclk_num $args
eval bcm2835_gpio_helper swclk $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_swdio_num
proc bcm2835gpio_swdio_num args {
echo "DEPRECATED! use 'bcm2835gpio swdio_num' not 'bcm2835gpio_swdio_num'"
eval bcm2835gpio swdio_num $args
eval bcm2835_gpio_helper swdio $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_swdio_dir_num
proc bcm2835gpio_swdio_dir_num args {
echo "DEPRECATED! use 'bcm2835gpio swdio_dir_num' not 'bcm2835gpio_swdio_dir_num'"
eval bcm2835gpio swdio_dir_num $args
eval bcm2835_gpio_helper swdio_dir $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_srst_num
proc bcm2835gpio_srst_num args {
echo "DEPRECATED! use 'bcm2835gpio srst_num' not 'bcm2835gpio_srst_num'"
eval bcm2835gpio srst_num $args
eval bcm2835_gpio_helper srst $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_trst_num
proc bcm2835gpio_trst_num args {
echo "DEPRECATED! use 'bcm2835gpio trst_num' not 'bcm2835gpio_trst_num'"
eval bcm2835gpio trst_num $args
eval bcm2835_gpio_helper trst $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio jtag_nums"
proc "bcm2835gpio jtag_nums" {tck_num tms_num tdi_num tdo_num} {
echo "DEPRECATED! use 'adapter gpio tck; adapter gpio tms; adapter gpio tdi; adapter gpio tdo' not 'bcm2835gpio jtag_nums'"
eval adapter gpio tck $tck_num -chip 0
eval adapter gpio tms $tms_num -chip 0
eval adapter gpio tdi $tdi_num -chip 0
eval adapter gpio tdo $tdo_num -chip 0
}
lappend _telnet_autocomplete_skip "bcm2835gpio tck_num"
proc "bcm2835gpio tck_num" args {
eval bcm2835_gpio_helper tck $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio tms_num"
proc "bcm2835gpio tms_num" args {
eval bcm2835_gpio_helper tms $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio tdo_num"
proc "bcm2835gpio tdo_num" args {
eval bcm2835_gpio_helper tdo $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio tdi_num"
proc "bcm2835gpio tdi_num" args {
eval bcm2835_gpio_helper tdi $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio swd_nums"
proc "bcm2835gpio swd_nums" {swclk_num swdio_num} {
echo "DEPRECATED! use 'adapter gpio swclk; adapter gpio swdio' not 'bcm2835gpio swd_nums'"
eval adapter gpio swclk $swclk_num -chip 0
eval adapter gpio swdio $swdio_num -chip 0
}
lappend _telnet_autocomplete_skip "bcm2835gpio swclk_num"
proc "bcm2835gpio swclk_num" args {
eval bcm2835_gpio_helper swclk $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio swdio_num"
proc "bcm2835gpio swdio_num" args {
eval bcm2835_gpio_helper swdio $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio swdio_dir_num"
proc "bcm2835gpio swdio_dir_num" args {
eval bcm2835_gpio_helper swdio_dir $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio srst_num"
proc "bcm2835gpio srst_num" args {
eval bcm2835_gpio_helper srst $args
}
lappend _telnet_autocomplete_skip "bcm2835gpio trst_num"
proc "bcm2835gpio trst_num" args {
eval bcm2835_gpio_helper trst $args
}
lappend _telnet_autocomplete_skip bcm2835gpio_speed_coeffs

View File

@@ -7,31 +7,35 @@
adapter driver bcm2835gpio
bcm2835gpio_peripheral_base 0x3F000000
bcm2835gpio peripheral_base 0x3F000000
# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
# These depend on system clock, calibrated for stock 700MHz
# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET
bcm2835gpio_speed_coeffs 146203 36
bcm2835gpio speed_coeffs 146203 36
# Each of the JTAG lines need a gpio number set: tck tms tdi tdo
# Header pin numbers: 23 22 19 21
bcm2835gpio_jtag_nums 11 25 10 9
adapter gpio tck -chip 0 11
adapter gpio tms -chip 0 25
adapter gpio tdi -chip 0 10
adapter gpio tdo -chip 0 9
# Each of the SWD lines need a gpio number set: swclk swdio
# Header pin numbers: 23 22
bcm2835gpio_swd_nums 11 25
adapter gpio swclk -chip 0 11
adapter gpio swdio -chip 0 25
# Direction pin for SWDIO level shifting buffer
bcm2835gpio_swdio_dir_num 6
adapter gpio swdio_dir -chip 0 6
# If you define trst or srst, use appropriate reset_config
# Header pin numbers: TRST - 26, SRST - 18
bcm2835gpio_trst_num 7
adapter gpio trst -chip 0 7
#reset_config trst_only
bcm2835gpio_srst_num 24
adapter gpio srst -chip 0 24
#reset_config srst_only
# or if you have both connected

View File

@@ -21,19 +21,23 @@ bcm2835gpio speed_coeffs 113714 28
# Each of the JTAG lines need a gpio number set: tck tms tdi tdo
# Header pin numbers: 23 22 19 21
bcm2835gpio jtag_nums 11 25 10 9
adapter gpio tck -chip 0 11
adapter gpio tms -chip 0 25
adapter gpio tdi -chip 0 10
adapter gpio tdo -chip 0 9
# Each of the SWD lines need a gpio number set: swclk swdio
# Header pin numbers: 23 22
bcm2835gpio swd_nums 11 25
adapter gpio swclk -chip 0 11
adapter gpio swdio -chip 0 25
# If you define trst or srst, use appropriate reset_config
# Header pin numbers: TRST - 26, SRST - 18
# bcm2835gpio trst_num 7
# adapter gpio trst -chip 0 7
# reset_config trst_only
# bcm2835gpio srst_num 24
# adapter gpio srst -chip 0 24
# reset_config srst_only srst_push_pull
# or if you have both connected,

View File

@@ -21,19 +21,23 @@ bcm2835gpio speed_coeffs 146203 36
# Each of the JTAG lines need a gpio number set: tck tms tdi tdo
# Header pin numbers: 23 22 19 21
bcm2835gpio jtag_nums 11 25 10 9
adapter gpio tck -chip 0 11
adapter gpio tms -chip 0 25
adapter gpio tdi -chip 0 10
adapter gpio tdo -chip 0 9
# Each of the SWD lines need a gpio number set: swclk swdio
# Header pin numbers: 23 22
bcm2835gpio swd_nums 11 25
adapter gpio swclk -chip 0 11
adapter gpio swdio -chip 0 25
# If you define trst or srst, use appropriate reset_config
# Header pin numbers: TRST - 26, SRST - 18
# bcm2835gpio trst_num 7
# adapter gpio trst -chip 0 7
# reset_config trst_only
# bcm2835gpio srst_num 24
# adapter gpio srst -chip 0 24
# reset_config srst_only srst_push_pull
# or if you have both connected,

View File

@@ -0,0 +1,105 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# OpenOCD script to test that the deprecated "bcm2835gpio *" and "bcm2835gpio_*"
# commands produce the expected results. Run this command as:
# openocd -f <path>/test-bcm2835gpio-deprecated-commands.cfg
# Raise an error if the "actual" value does not match the "expected" value. Trim
# whitespace (including newlines) from strings before comparing.
proc expected_value {expected actual} {
if {[string trim $expected] ne [string trim $actual]} {
error [puts "ERROR: '${actual}' != '${expected}'"]
}
}
set supported_signals {tdo tdi tms tck trst swdio swdio_dir swclk srst}
adapter speed 100
adapter driver bcm2835gpio
puts "Driver is '[adapter name]'"
expected_value "bcm2835gpio" [adapter name]
echo [adapter gpio]
#####################################
# Test the "bcm2835gpio *" commands
# Change the GPIO chip for all signals. Don't check directly here, do so when
# each signal command is tested.
# bcm2835gpio gpiochip 0
bcm2835gpio jtag_nums 1 2 3 4
expected_value "adapter gpio tck (output): num 1, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tck]
expected_value "adapter gpio tms (output): num 2, chip 0, active-high, push-pull, pull-none, init-state active" [eval adapter gpio tms]
expected_value "adapter gpio tdi (output): num 3, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tdi]
expected_value "adapter gpio tdo (input): num 4, chip 0, active-high, pull-none, init-state input" [eval adapter gpio tdo]
bcm2835gpio tck_num 5
expected_value "adapter gpio tck (output): num 5, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tck]
bcm2835gpio tms_num 6
expected_value "adapter gpio tms (output): num 6, chip 0, active-high, push-pull, pull-none, init-state active" [eval adapter gpio tms]
bcm2835gpio tdi_num 7
expected_value "adapter gpio tdi (output): num 7, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tdi]
bcm2835gpio tdo_num 8
expected_value "adapter gpio tdo (input): num 8, chip 0, active-high, pull-none, init-state input" [eval adapter gpio tdo]
bcm2835gpio swd_nums 9 10
expected_value "adapter gpio swclk (output): num 9, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swclk]
expected_value "adapter gpio swdio (bidirectional): num 10, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swdio]
bcm2835gpio swclk_num 11
expected_value "adapter gpio swclk (output): num 11, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swclk]
bcm2835gpio swdio_num 12
expected_value "adapter gpio swdio (bidirectional): num 12, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swdio]
bcm2835gpio swdio_dir_num 13
expected_value "adapter gpio swdio_dir (output): num 13, chip 0, active-high, push-pull, pull-none" [eval adapter gpio swdio_dir]
bcm2835gpio srst_num 14
expected_value "adapter gpio srst (output): num 14, chip 0, active-low, pull-none, init-state inactive" [eval adapter gpio srst]
bcm2835gpio trst_num 15
expected_value "adapter gpio trst (output): num 15, chip 0, active-low, pull-none, init-state inactive" [eval adapter gpio trst]
#####################################
# Test the old bcm2835gpio_* commands
# Reset the GPIO chip for all signals. Don't check directly here, do so when
# each signal command is tested.
foreach sig_name $supported_signals {
eval adapter gpio $sig_name -chip -1
}
bcm2835gpio_jtag_nums 17 18 19 20
expected_value "adapter gpio tck (output): num 17, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tck]
expected_value "adapter gpio tms (output): num 18, chip 0, active-high, push-pull, pull-none, init-state active" [eval adapter gpio tms]
expected_value "adapter gpio tdi (output): num 19, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tdi]
expected_value "adapter gpio tdo (input): num 20, chip 0, active-high, pull-none, init-state input" [eval adapter gpio tdo]
bcm2835gpio_tck_num 21
expected_value "adapter gpio tck (output): num 21, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tck]
bcm2835gpio_tms_num 22
expected_value "adapter gpio tms (output): num 22, chip 0, active-high, push-pull, pull-none, init-state active" [eval adapter gpio tms]
bcm2835gpio_tdi_num 23
expected_value "adapter gpio tdi (output): num 23, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio tdi]
bcm2835gpio_tdo_num 24
expected_value "adapter gpio tdo (input): num 24, chip 0, active-high, pull-none, init-state input" [eval adapter gpio tdo]
bcm2835gpio_swd_nums 25 26
expected_value "adapter gpio swclk (output): num 25, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swclk]
expected_value "adapter gpio swdio (bidirectional): num 26, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swdio]
bcm2835gpio_swclk_num 27
expected_value "adapter gpio swclk (output): num 27, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swclk]
bcm2835gpio_swdio_num 28
expected_value "adapter gpio swdio (bidirectional): num 28, chip 0, active-high, push-pull, pull-none, init-state inactive" [eval adapter gpio swdio]
puts "SUCCESS"