23 #define AM335XGPIO_NUM_GPIO_PER_CHIP 32
24 #define AM335XGPIO_NUM_GPIO_CHIPS 4
25 #define AM335XGPIO_GPIO0_HW_ADDR 0x44E07000
26 #define AM335XGPIO_GPIO1_HW_ADDR 0x4804C000
27 #define AM335XGPIO_GPIO2_HW_ADDR 0x481AC000
28 #define AM335XGPIO_GPIO3_HW_ADDR 0x481AE000
34 #define AM335XGPIO_GPIO_OE_OFFSET (0x134 / 4)
35 #define AM335XGPIO_GPIO_DATAIN_OFFSET (0x138 / 4)
36 #define AM335XGPIO_GPIO_DATAOUT_OFFSET (0x13C / 4)
37 #define AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET (0x190 / 4)
38 #define AM335XGPIO_GPIO_SETDATAOUT_OFFSET (0x194 / 4)
40 #define AM335XGPIO_READ_REG(chip_num, offset) \
41 (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)))
43 #define AM335XGPIO_WRITE_REG(chip_num, offset, value) \
44 (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) = (value))
46 #define AM335XGPIO_SET_REG_BITS(chip_num, offset, bit_mask) \
47 (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) |= (bit_mask))
49 #define AM335XGPIO_CLEAR_REG_BITS(chip_num, offset, bit_mask) \
50 (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) &= ~(bit_mask))
52 #define AM335XGPIO_SET_INPUT(gpio_config) \
53 AM335XGPIO_SET_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))
54 #define AM335XGPIO_SET_OUTPUT(gpio_config) \
55 AM335XGPIO_CLEAR_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))
56 #define AM335XGPIO_SET_HIGH(gpio_config) \
57 AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_SETDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))
58 #define AM335XGPIO_SET_LOW(gpio_config) \
59 AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))
97 unsigned int shift = gpio_config->
gpio_num;
99 value = (value >> shift) & 1;
100 return value ^ (gpio_config->
active_low ? 1 : 0);
105 value = value ^ (gpio_config->
active_low ? 1 : 0);
106 switch (gpio_config->
drive) {
152 return "output (low)";
154 return "output (high)";
165 LOG_DEBUG(
"saved GPIO mode for %s (GPIO %d %d): %s",
170 LOG_WARNING(
"am335xgpio does not support pull-up or pull-down settings (signal %s)",
251 LOG_DEBUG(
"am335xgpio_reset(%d, %d), trst_gpio: %d %d, srst_gpio: %d %d",
324 command_print(
CMD,
"AM335x GPIO config: speed_coeffs = %d, speed_offset = %d",
331 .
name =
"speed_coeffs",
332 .handler = am335xgpio_handle_speed_coeffs,
334 .help =
"SPEED_COEFF and SPEED_OFFSET for delay calculations.",
335 .usage =
"[SPEED_COEFF SPEED_OFFSET]",
342 .
name =
"am335xgpio",
344 .help =
"perform am335xgpio management",
384 LOG_ERROR(
"Cannot unmap GPIO memory for chip %d: %s", i, strerror(errno));
389 LOG_INFO(
"AM335x GPIO JTAG/SWD bitbang driver");
395 LOG_ERROR(
"Require tck, tms, tdi and tdo gpios for JTAG mode");
400 LOG_ERROR(
"Require swclk and swdio gpio for SWD mode");
404 dev_mem_fd = open(
"/dev/gpiomem", O_RDWR | O_SYNC);
406 LOG_DEBUG(
"Cannot open /dev/gpiomem, fallback to /dev/mem");
407 dev_mem_fd = open(
"/dev/mem", O_RDWR | O_SYNC);
494 .
name =
"am335xgpio",
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 int am335xgpio_swdio_read(void)
static int am335xgpio_quit(void)
static const struct command_registration am335xgpio_command_handlers[]
static const char * get_gpio_mode_name(enum amx335gpio_initial_gpio_mode gpio_mode)
#define AM335XGPIO_SET_OUTPUT(gpio_config)
static int am335xgpio_write(int tck, int tms, int tdi)
#define AM335XGPIO_SET_HIGH(gpio_config)
#define AM335XGPIO_NUM_GPIO_PER_CHIP
static void restore_gpio(enum adapter_gpio_config_index idx)
static void am335xgpio_munmap(void)
static int am335xgpio_speed_div(int speed, int *khz)
#define AM335XGPIO_GPIO_DATAOUT_OFFSET
static bool am335xgpio_swd_mode_possible(void)
#define AM335XGPIO_GPIO3_HW_ADDR
static int am335xgpio_init(void)
#define AM335XGPIO_GPIO2_HW_ADDR
#define AM335XGPIO_GPIO_OE_OFFSET
static const uint32_t am335xgpio_gpio_chip_hw_addr[AM335XGPIO_NUM_GPIO_CHIPS]
static int am335xgpio_speed(int speed)
#define AM335XGPIO_SET_INPUT(gpio_config)
static volatile uint32_t * am335xgpio_gpio_chip_mmap_addr[AM335XGPIO_NUM_GPIO_CHIPS]
static unsigned int jtag_delay
#define AM335XGPIO_READ_REG(chip_num, offset)
static int am335xgpio_khz(int khz, int *jtag_speed)
static struct jtag_interface am335xgpio_interface
struct adapter_driver am335xgpio_adapter_driver
static const struct command_registration am335xgpio_subcommand_handlers[]
amx335gpio_initial_gpio_mode
@ AM335XGPIO_GPIO_MODE_OUTPUT_LOW
@ AM335XGPIO_GPIO_MODE_OUTPUT_HIGH
@ AM335XGPIO_GPIO_MODE_INPUT
#define AM335XGPIO_NUM_GPIO_CHIPS
static const struct adapter_gpio_config * adapter_gpio_config
static int am335xgpio_swd_write(int swclk, int swdio)
COMMAND_HANDLER(am335xgpio_handle_speed_coeffs)
static void set_gpio_value(const struct adapter_gpio_config *gpio_config, int value)
#define AM335XGPIO_SET_LOW(gpio_config)
static bool is_gpio_config_valid(const struct adapter_gpio_config *gpio_config)
#define AM335XGPIO_GPIO0_HW_ADDR
static int am335xgpio_blink(int on)
static const char *const am335xgpio_transports[]
static enum amx335gpio_initial_gpio_mode get_gpio_mode(const struct adapter_gpio_config *gpio_config)
#define AM335XGPIO_GPIO_DATAIN_OFFSET
static void am335xgpio_swdio_drive(bool is_output)
static int get_gpio_value(const struct adapter_gpio_config *gpio_config)
static enum amx335gpio_initial_gpio_mode initial_gpio_mode[ADAPTER_GPIO_IDX_NUM]
static void initialize_gpio(enum adapter_gpio_config_index idx)
#define AM335XGPIO_GPIO1_HW_ADDR
static struct bitbang_interface am335xgpio_bitbang
static bool am335xgpio_jtag_mode_possible(void)
static bb_value_t am335xgpio_read(void)
static int am335xgpio_reset(int trst, int srst)
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_pull pull
enum adapter_gpio_init_state init_state
enum adapter_gpio_drive_mode drive
Low level callbacks (for bitbang).
bb_value_t(* 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 supported
Bit vector listing capabilities exposed by this driver.