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) ({ \
35 typeof(_g) g = (_g); \
36 *(pio_base + (g / 10)) >> ((g % 10) * 3) & 7; \
39 #define INP_GPIO(_g) do { \
40 typeof(_g) g1 = (_g); \
41 *(pio_base + (g1 / 10)) &= ~(7 << ((g1 % 10) * 3)); \
44 #define SET_MODE_GPIO(_g, m) do { \
45 typeof(_g) g = (_g); \
48 *(pio_base + (g / 10)) |= ((m) << ((g % 10) * 3)); \
51 #define OUT_GPIO(g) SET_MODE_GPIO(g, BCM2835_GPIO_MODE_OUTPUT)
53 #define GPIO_SET (*(pio_base + 7))
54 #define GPIO_CLR (*(pio_base + 10))
55 #define GPIO_LEV (*(pio_base + 13))
58 static volatile uint32_t *
pio_base = MAP_FAILED;
78 return "/dev/gpiomem";
104 value = value ^ (gpio_config->
active_low ? 1 : 0);
105 switch (gpio_config->
drive) {
157 LOG_DEBUG(
"saved GPIO mode for %s (GPIO %d %d): %d",
162 LOG_WARNING(
"BCM2835 GPIO does not support pull-up or pull-down settings (signal %s)",
188 uint32_t value = (
GPIO_LEV >> shift) & 1;
254 LOG_DEBUG(
"trst %d gpio: %d %d, srst %d gpio: %d %d",
281 uint32_t value = (
GPIO_LEV >> shift) & 1;
288 LOG_DEBUG(
"BCM2835 GPIO: RCLK not supported");
352 .
name =
"speed_coeffs",
353 .handler = &bcm2835gpio_handle_speed_coeffs,
355 .help =
"SPEED_COEFF and SPEED_OFFSET for delay calculations.",
356 .usage =
"[SPEED_COEFF SPEED_OFFSET]",
359 .name =
"peripheral_mem_dev",
360 .handler = &bcm2835gpio_handle_peripheral_mem_dev,
362 .help =
"device to map memory mapped GPIOs from.",
366 .name =
"peripheral_base",
367 .handler = &bcm2835gpio_handle_peripheral_base,
369 .help =
"peripheral base to access GPIOs, not needed with /dev/gpiomem.",
378 .
name =
"bcm2835gpio",
380 .help =
"perform bcm2835gpio management",
412 munmap((
void *)
pio_base, sysconf(_SC_PAGE_SIZE));
417 munmap((
void *)
pads_base, sysconf(_SC_PAGE_SIZE));
441 LOG_INFO(
"BCM2835 GPIO JTAG/SWD bitbang driver");
447 LOG_ERROR(
"Require tck, tms, tdi and tdo gpios for JTAG mode");
452 LOG_ERROR(
"Require swclk and swdio gpio for SWD mode");
457 bool pad_mapping_possible = !is_gpiomem;
469 pio_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
479 if (pad_mapping_possible) {
480 pads_base = mmap(
NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
484 LOG_ERROR(
"mmap pads: %s", strerror(errno));
485 LOG_WARNING(
"Continuing with unchanged GPIO pad settings (drive strength and slew rate)");
531 LOG_DEBUG(
"BCM2835 GPIO using fast mode for SWD write");
534 LOG_DEBUG(
"BCM2835 GPIO using generic mode for SWD write");
588 .
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 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)
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
#define SET_MODE_GPIO(_g, m)
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_blink(bool on)
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 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.