23 #define BCM2835_GPIO_BASE (bcm2835_peri_base + 0x200000)
25 #define BCM2835_PADS_GPIO_0_27 (bcm2835_peri_base + 0x100000)
26 #define BCM2835_PADS_GPIO_0_27_OFFSET (0x2c / 4)
29 #define BCM2835_GPIO_MODE_INPUT 0
30 #define BCM2835_GPIO_MODE_OUTPUT 1
33 #define MODE_GPIO(g) (*(pio_base+((g)/10))>>(((g)%10)*3) & 7)
34 #define INP_GPIO(g) do { *(pio_base+((g)/10)) &= ~(7<<(((g)%10)*3)); } while (0)
35 #define SET_MODE_GPIO(g, m) do { \
37 *(pio_base+((g)/10)) |= ((m)<<(((g)%10)*3)); } while (0)
38 #define OUT_GPIO(g) SET_MODE_GPIO(g, BCM2835_GPIO_MODE_OUTPUT)
40 #define GPIO_SET (*(pio_base+7))
41 #define GPIO_CLR (*(pio_base+10))
42 #define GPIO_LEV (*(pio_base+13))
45 static volatile uint32_t *
pio_base = MAP_FAILED;
80 value = value ^ (gpio_config->
active_low ? 1 : 0);
81 switch (gpio_config->
drive) {
133 LOG_DEBUG(
"saved GPIO mode for %s (GPIO %d %d): %d",
138 LOG_WARNING(
"BCM2835 GPIO does not support pull-up or pull-down settings (signal %s)",
163 uint32_t value = (
GPIO_LEV >> shift) & 1;
233 LOG_DEBUG(
"BCM2835 GPIO: bcm2835gpio_reset(%d, %d), trst_gpio: %d %d, srst_gpio: %d %d",
257 uint32_t value = (
GPIO_LEV >> shift) & 1;
264 LOG_DEBUG(
"BCM2835 GPIO: RCLK not supported");
309 .
name =
"speed_coeffs",
310 .handler = &bcm2835gpio_handle_speed_coeffs,
312 .help =
"SPEED_COEFF and SPEED_OFFSET for delay calculations.",
313 .usage =
"[SPEED_COEFF SPEED_OFFSET]",
316 .name =
"peripheral_base",
317 .handler = &bcm2835gpio_handle_peripheral_base,
319 .help =
"peripheral base to access GPIOs (RPi1 0x20000000, RPi2 0x3F000000).",
328 .
name =
"bcm2835gpio",
330 .help =
"perform bcm2835gpio management",
362 munmap((
void *)
pio_base, sysconf(_SC_PAGE_SIZE));
367 munmap((
void *)
pads_base, sysconf(_SC_PAGE_SIZE));
391 LOG_INFO(
"BCM2835 GPIO JTAG/SWD bitbang driver");
397 LOG_ERROR(
"Require tck, tms, tdi and tdo gpios for JTAG mode");
402 LOG_ERROR(
"Require swclk and swdio gpio for SWD mode");
406 dev_mem_fd = open(
"/dev/gpiomem", O_RDWR | O_SYNC);
408 LOG_DEBUG(
"Cannot open /dev/gpiomem, fallback to /dev/mem");
409 dev_mem_fd = open(
"/dev/mem", O_RDWR | O_SYNC);
416 pio_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
425 pads_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
471 LOG_DEBUG(
"BCM2835 GPIO using fast mode for SWD write");
474 LOG_DEBUG(
"BCM2835 GPIO using generic mode for SWD write");
525 .
name =
"bcm2835gpio",
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
@ ADAPTER_GPIO_INIT_STATE_ACTIVE
@ ADAPTER_GPIO_INIT_STATE_INPUT
@ ADAPTER_GPIO_INIT_STATE_INACTIVE
adapter_gpio_config_index
Adapter GPIO.
@ ADAPTER_GPIO_IDX_SWDIO_DIR
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN
@ ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL
bool transport_is_swd(void)
Returns true if the current debug session is using SWD as its transport.
static bool bcm2835gpio_jtag_mode_possible(void)
static void bcm2835gpio_munmap(void)
#define BCM2835_GPIO_BASE
static const struct command_registration bcm2835gpio_command_handlers[]
static volatile uint32_t * pads_base
static bool bcm2835gpio_swd_mode_possible(void)
static void restore_gpio(enum adapter_gpio_config_index idx)
static bool is_gpio_config_valid(enum adapter_gpio_config_index idx)
static int bcm2835gpio_swd_write_generic(int swclk, int swdio)
static void bcm2835_gpio_synchronize(void)
static void bcm2835_swdio_drive(bool is_output)
#define BCM2835_PADS_GPIO_0_27
static int bcm2835gpio_blink(int on)
static struct bitbang_interface bcm2835gpio_bitbang
static int bcm2835gpio_init(void)
static bb_value_t bcm2835gpio_read(void)
static int bcm2835gpio_write(int tck, int tms, int tdi)
#define SET_MODE_GPIO(g, m)
static const char *const bcm2835_transports[]
struct adapter_driver bcm2835gpio_adapter_driver
static int bcm2835gpio_khz(int khz, int *jtag_speed)
static unsigned int jtag_delay
static const struct command_registration bcm2835gpio_subcommand_handlers[]
static int bcm2835_swdio_read(void)
COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs)
static const struct adapter_gpio_config * adapter_gpio_config
static void set_gpio_value(const struct adapter_gpio_config *gpio_config, int value)
static int bcm2835gpio_reset(int trst, int srst)
#define BCM2835_GPIO_MODE_OUTPUT
static uint32_t initial_drive_strength_etc
static volatile uint32_t * pio_base
static struct jtag_interface bcm2835gpio_interface
uint32_t bcm2835_peri_base
static void initialize_gpio(enum adapter_gpio_config_index idx)
static int bcm2835gpio_quit(void)
static int bcm2835gpio_speed_div(int speed, int *khz)
static int bcm2835gpio_speed(int speed)
static int bcm2835gpio_swd_write_fast(int swclk, int swdio)
#define BCM2835_PADS_GPIO_0_27_OFFSET
int bitbang_execute_queue(void)
const struct swd_driver bitbang_swd
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define DEBUG_CAP_TMS_SEQ
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
#define ERROR_JTAG_INIT_FAILED
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Configuration options for a single GPIO.
enum adapter_gpio_drive_mode drive
Low level callbacks (for bitbang).
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
bb_value_t(* read)(void)
Sample TDO and return the value.
const char * usage
a string listing the options and arguments, required or optional
unsigned int output_level
Represents a driver for a debugging interface.
unsigned supported
Bit vector listing capabilities exposed by this driver.