24 #define BCM2835_GPIO_BASE (bcm2835_peri_base + 0x200000)
26 #define BCM2835_PADS_GPIO_0_27 (bcm2835_peri_base + 0x100000)
27 #define BCM2835_PADS_GPIO_0_27_OFFSET (0x2c / 4)
30 #define BCM2835_GPIO_MODE_INPUT 0
31 #define BCM2835_GPIO_MODE_OUTPUT 1
34 #define BCM2835_GPIO_REG_READ(offset) \
35 (*(pio_base + (offset)))
37 #define BCM2835_GPIO_REG_WRITE(offset, value) \
38 (*(pio_base + (offset)) = (value))
40 #define BCM2835_GPIO_SET_REG_BITS(offset, bit_mask) \
41 (*(pio_base + (offset)) |= (bit_mask))
43 #define BCM2835_GPIO_CLEAR_REG_BITS(offset, bit_mask) \
44 (*(pio_base + (offset)) &= ~(bit_mask))
46 #define BCM2835_GPIO_MODE_ADDR(gpio_pin_num) (pio_base + ((gpio_pin_num) / 10))
47 #define BCM2835_GPIO_SET_ADDR(gpio_pin_num) (pio_base + 7 + ((gpio_pin_num) / 32))
48 #define BCM2835_GPIO_CLR_ADDR(gpio_pin_num) (pio_base + 10 + ((gpio_pin_num) / 32))
49 #define BCM2835_GPIO_LEVEL_ADDR(gpio_pin_num) (pio_base + 13 + ((gpio_pin_num) / 32))
52 static volatile uint32_t *
pio_base = MAP_FAILED;
137 return "/dev/gpiomem";
146 __sync_synchronize();
163 value = value ^ (gpio_config->
active_low ? 1 : 0);
164 switch (gpio_config->
drive) {
215 LOG_DEBUG(
"saved GPIO mode for %s (GPIO %d %d): %d",
220 LOG_WARNING(
"BCM2835 GPIO does not support pull-up or pull-down settings (signal %s)",
299 LOG_DEBUG(
"trst %d gpio: %d %d, srst %d gpio: %d %d",
334 LOG_DEBUG(
"BCM2835 GPIO: RCLK not supported");
398 .
name =
"speed_coeffs",
399 .handler = &bcm2835gpio_handle_speed_coeffs,
401 .help =
"SPEED_COEFF and SPEED_OFFSET for delay calculations.",
402 .usage =
"[SPEED_COEFF SPEED_OFFSET]",
405 .name =
"peripheral_mem_dev",
406 .handler = &bcm2835gpio_handle_peripheral_mem_dev,
408 .help =
"device to map memory mapped GPIOs from.",
412 .name =
"peripheral_base",
413 .handler = &bcm2835gpio_handle_peripheral_base,
415 .help =
"peripheral base to access GPIOs, not needed with /dev/gpiomem.",
424 .
name =
"bcm2835gpio",
426 .help =
"perform bcm2835gpio management",
458 munmap((
void *)
pio_base, sysconf(_SC_PAGE_SIZE));
463 munmap((
void *)
pads_base, sysconf(_SC_PAGE_SIZE));
496 LOG_INFO(
"BCM2835 GPIO JTAG/SWD bitbang driver");
501 LOG_ERROR(
"Require tck, tms, tdi and tdo gpios for JTAG mode");
506 LOG_ERROR(
"Require swclk and swdio gpio for SWD mode");
511 bool pad_mapping_possible = !is_gpiomem;
523 pio_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
533 if (pad_mapping_possible) {
534 pads_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
538 LOG_ERROR(
"mmap pads: %s", strerror(errno));
539 LOG_WARNING(
"Continuing with unchanged GPIO pad settings (drive strength and slew rate)");
631 LOG_DEBUG(
"BCM2835 GPIO using fast mode for SWD write");
634 LOG_DEBUG(
"BCM2835 GPIO using generic mode for SWD write");
688 .
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 char * bcm2835_peri_mem_dev
static void bcm2835_set_output(unsigned int gpio_pin_num)
static bool bcm2835gpio_jtag_mode_possible(void)
uint32_t tdo_level_shift_bits
volatile uint32_t * swdio_read_level_addr
static void bcm2835gpio_munmap(void)
static bool bcm2835_get_level(unsigned int gpio_pin_num)
#define BCM2835_GPIO_BASE
static void bcm2835_set_input(unsigned int gpio_pin_num)
static const struct command_registration bcm2835gpio_command_handlers[]
volatile uint32_t * swdio_mode_addr
static const struct bitbang_interface bcm2835gpio_bitbang_swd_write_generic
volatile uint32_t * tms_clr_set_addr[2]
static void bcm2835_gpio_set(unsigned int gpio_pin_num)
static volatile uint32_t * pads_base
#define BCM2835_GPIO_CLR_ADDR(gpio_pin_num)
static bool bcm2835gpio_swd_mode_possible(void)
static void restore_gpio(enum adapter_gpio_config_index idx)
volatile uint32_t * swclk_clr_set_addr[2]
volatile uint32_t * swdio_clr_set_addr[2]
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_clear(unsigned int gpio_pin_num)
static void bcm2835_gpio_synchronize(void)
static void bcm2835_delay(void)
uint32_t swdio_mode_input_mask
static void bcm2835_swdio_drive(bool is_output)
volatile uint32_t * tdi_clr_set_addr[2]
#define BCM2835_PADS_GPIO_0_27
static int bcm2835gpio_init(void)
static int bcm2835gpio_write(int tck, int tms, int tdi)
static enum bb_value bcm2835gpio_read(void)
struct adapter_driver bcm2835gpio_adapter_driver
static off_t bcm2835_peri_base
static int bcm2835gpio_khz(int khz, int *jtag_speed)
static unsigned int jtag_delay
static const struct bitbang_interface bcm2835gpio_bitbang_swd_write_fast
static const struct command_registration bcm2835gpio_subcommand_handlers[]
#define BCM2835_GPIO_REG_WRITE(offset, value)
#define BCM2835_GPIO_SET_ADDR(gpio_pin_num)
static int bcm2835_swdio_read(void)
COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs)
static unsigned int bcm2835_get_mode(unsigned int gpio_pin_num)
static const struct adapter_gpio_config * adapter_gpio_config
static void bcm2835_set_mode(unsigned int gpio_pin_num, unsigned char mode)
#define BCM2835_GPIO_LEVEL_ADDR(gpio_pin_num)
#define BCM2835_GPIO_SET_REG_BITS(offset, bit_mask)
static struct @17 gpio_control
static void set_gpio_value(const struct adapter_gpio_config *gpio_config, int value)
volatile uint32_t * tdo_read_level_addr
static int bcm2835gpio_reset(int trst, int srst)
#define BCM2835_GPIO_MODE_OUTPUT
#define BCM2835_GPIO_REG_READ(offset)
static uint32_t initial_drive_strength_etc
uint32_t swdio_mode_output_mask
#define BCM2835_GPIO_CLEAR_REG_BITS(offset, bit_mask)
uint32_t swdio_level_shift_bits
static volatile uint32_t * pio_base
static struct jtag_interface bcm2835gpio_interface
static const char * bcm2835_get_mem_dev(void)
static void initialize_gpio(enum adapter_gpio_config_index idx)
#define BCM2835_GPIO_MODE_ADDR(gpio_pin_num)
static int bcm2835gpio_quit(void)
static int bcm2835gpio_blink(bool on)
static int bcm2835gpio_speed_div(int speed, int *khz)
volatile uint32_t * tck_clr_set_addr[2]
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(struct jtag_command *cmd_queue)
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).
enum bb_value(* read)(void)
Sample TDO and return the value.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.