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 MODE_GPIO(g) (*(pio_base+((g)/10))>>(((g)%10)*3) & 7)
35 #define INP_GPIO(g) do { *(pio_base+((g)/10)) &= ~(7<<(((g)%10)*3)); } while (0)
36 #define SET_MODE_GPIO(g, m) do { \
38 *(pio_base+((g)/10)) |= ((m)<<(((g)%10)*3)); } while (0)
39 #define OUT_GPIO(g) SET_MODE_GPIO(g, BCM2835_GPIO_MODE_OUTPUT)
41 #define GPIO_SET (*(pio_base+7))
42 #define GPIO_CLR (*(pio_base+10))
43 #define GPIO_LEV (*(pio_base+13))
46 static volatile uint32_t *
pio_base = MAP_FAILED;
66 return "/dev/gpiomem";
92 value = value ^ (gpio_config->
active_low ? 1 : 0);
93 switch (gpio_config->
drive) {
145 LOG_DEBUG(
"saved GPIO mode for %s (GPIO %d %d): %d",
150 LOG_WARNING(
"BCM2835 GPIO does not support pull-up or pull-down settings (signal %s)",
176 uint32_t value = (
GPIO_LEV >> shift) & 1;
243 LOG_DEBUG(
"trst %d gpio: %d %d, srst %d gpio: %d %d",
270 uint32_t value = (
GPIO_LEV >> shift) & 1;
277 LOG_DEBUG(
"BCM2835 GPIO: RCLK not supported");
341 .
name =
"speed_coeffs",
342 .handler = &bcm2835gpio_handle_speed_coeffs,
344 .help =
"SPEED_COEFF and SPEED_OFFSET for delay calculations.",
345 .usage =
"[SPEED_COEFF SPEED_OFFSET]",
348 .name =
"peripheral_mem_dev",
349 .handler = &bcm2835gpio_handle_peripheral_mem_dev,
351 .help =
"device to map memory mapped GPIOs from.",
355 .name =
"peripheral_base",
356 .handler = &bcm2835gpio_handle_peripheral_base,
358 .help =
"peripheral base to access GPIOs, not needed with /dev/gpiomem.",
367 .
name =
"bcm2835gpio",
369 .help =
"perform bcm2835gpio management",
401 munmap((
void *)
pio_base, sysconf(_SC_PAGE_SIZE));
406 munmap((
void *)
pads_base, sysconf(_SC_PAGE_SIZE));
430 LOG_INFO(
"BCM2835 GPIO JTAG/SWD bitbang driver");
436 LOG_ERROR(
"Require tck, tms, tdi and tdo gpios for JTAG mode");
441 LOG_ERROR(
"Require swclk and swdio gpio for SWD mode");
446 bool pad_mapping_possible = !is_gpiomem;
458 pio_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
468 if (pad_mapping_possible) {
469 pads_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
473 LOG_ERROR(
"mmap pads: %s", strerror(errno));
474 LOG_WARNING(
"Continuing with unchanged GPIO pad settings (drive strength and slew rate)");
520 LOG_DEBUG(
"BCM2835 GPIO using fast mode for SWD write");
523 LOG_DEBUG(
"BCM2835 GPIO using generic mode for SWD write");
577 .
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 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_delay(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 off_t bcm2835_peri_base
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
static const char * bcm2835_get_mem_dev(void)
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(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).
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.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.