OpenOCD
am335xgpio.c File Reference
Include dependency graph for am335xgpio.c:

Go to the source code of this file.

Macros

#define AM335XGPIO_CLEAR_REG_BITS(chip_num, offset, bit_mask)    (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) &= ~(bit_mask))
 
#define AM335XGPIO_GPIO0_HW_ADDR   0x44E07000
 
#define AM335XGPIO_GPIO1_HW_ADDR   0x4804C000
 
#define AM335XGPIO_GPIO2_HW_ADDR   0x481AC000
 
#define AM335XGPIO_GPIO3_HW_ADDR   0x481AE000
 
#define AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET   (0x190 / 4)
 
#define AM335XGPIO_GPIO_DATAIN_OFFSET   (0x138 / 4)
 
#define AM335XGPIO_GPIO_DATAOUT_OFFSET   (0x13C / 4) /* DATAOUT register uses 0 for output, 1 for input */
 
#define AM335XGPIO_GPIO_OE_OFFSET   (0x134 / 4)
 
#define AM335XGPIO_GPIO_SETDATAOUT_OFFSET   (0x194 / 4)
 
#define AM335XGPIO_NUM_GPIO_CHIPS   4
 
#define AM335XGPIO_NUM_GPIO_PER_CHIP   32
 
#define AM335XGPIO_READ_REG(chip_num, offset)    (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)))
 
#define AM335XGPIO_SET_HIGH(gpio_config)    AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_SETDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))
 
#define AM335XGPIO_SET_INPUT(gpio_config)    AM335XGPIO_SET_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))
 
#define AM335XGPIO_SET_LOW(gpio_config)    AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))
 
#define AM335XGPIO_SET_OUTPUT(gpio_config)    AM335XGPIO_CLEAR_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))
 
#define AM335XGPIO_SET_REG_BITS(chip_num, offset, bit_mask)    (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) |= (bit_mask))
 
#define AM335XGPIO_WRITE_REG(chip_num, offset, value)    (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) = (value))
 

Enumerations

enum  amx335gpio_initial_gpio_mode { AM335XGPIO_GPIO_MODE_INPUT , AM335XGPIO_GPIO_MODE_OUTPUT_LOW , AM335XGPIO_GPIO_MODE_OUTPUT_HIGH }
 

Functions

static int am335xgpio_blink (int on)
 
static int am335xgpio_init (void)
 
static bool am335xgpio_jtag_mode_possible (void)
 
static int am335xgpio_khz (int khz, int *jtag_speed)
 
static void am335xgpio_munmap (void)
 
static int am335xgpio_quit (void)
 
static bb_value_t am335xgpio_read (void)
 
static int am335xgpio_reset (int trst, int srst)
 
static int am335xgpio_speed (int speed)
 
static int am335xgpio_speed_div (int speed, int *khz)
 
static bool am335xgpio_swd_mode_possible (void)
 
static int am335xgpio_swd_write (int swclk, int swdio)
 
static void am335xgpio_swdio_drive (bool is_output)
 
static int am335xgpio_swdio_read (void)
 
static int am335xgpio_write (int tck, int tms, int tdi)
 
 COMMAND_HANDLER (am335xgpio_handle_speed_coeffs)
 
static enum amx335gpio_initial_gpio_mode get_gpio_mode (const struct adapter_gpio_config *gpio_config)
 
static const char * get_gpio_mode_name (enum amx335gpio_initial_gpio_mode gpio_mode)
 
static int get_gpio_value (const struct adapter_gpio_config *gpio_config)
 
static void initialize_gpio (enum adapter_gpio_config_index idx)
 
static bool is_gpio_config_valid (const struct adapter_gpio_config *gpio_config)
 
static void restore_gpio (enum adapter_gpio_config_index idx)
 
static void set_gpio_value (const struct adapter_gpio_config *gpio_config, int value)
 

Variables

static const struct adapter_gpio_configadapter_gpio_config
 
struct adapter_driver am335xgpio_adapter_driver
 
static struct bitbang_interface am335xgpio_bitbang
 
static const struct command_registration am335xgpio_command_handlers []
 
static const uint32_t am335xgpio_gpio_chip_hw_addr [AM335XGPIO_NUM_GPIO_CHIPS]
 
static volatile uint32_t * am335xgpio_gpio_chip_mmap_addr [AM335XGPIO_NUM_GPIO_CHIPS]
 
static struct jtag_interface am335xgpio_interface
 
static const struct command_registration am335xgpio_subcommand_handlers []
 
static const char *const am335xgpio_transports [] = { "jtag", "swd", NULL }
 
static int dev_mem_fd
 
static enum amx335gpio_initial_gpio_mode initial_gpio_mode [ADAPTER_GPIO_IDX_NUM]
 
static unsigned int jtag_delay
 
static int speed_coeff = 600000
 
static int speed_offset = 575
 

Macro Definition Documentation

◆ AM335XGPIO_CLEAR_REG_BITS

#define AM335XGPIO_CLEAR_REG_BITS (   chip_num,
  offset,
  bit_mask 
)     (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) &= ~(bit_mask))

Definition at line 49 of file am335xgpio.c.

◆ AM335XGPIO_GPIO0_HW_ADDR

#define AM335XGPIO_GPIO0_HW_ADDR   0x44E07000

Definition at line 25 of file am335xgpio.c.

◆ AM335XGPIO_GPIO1_HW_ADDR

#define AM335XGPIO_GPIO1_HW_ADDR   0x4804C000

Definition at line 26 of file am335xgpio.c.

◆ AM335XGPIO_GPIO2_HW_ADDR

#define AM335XGPIO_GPIO2_HW_ADDR   0x481AC000

Definition at line 27 of file am335xgpio.c.

◆ AM335XGPIO_GPIO3_HW_ADDR

#define AM335XGPIO_GPIO3_HW_ADDR   0x481AE000

Definition at line 28 of file am335xgpio.c.

◆ AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET

#define AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET   (0x190 / 4)

Definition at line 37 of file am335xgpio.c.

◆ AM335XGPIO_GPIO_DATAIN_OFFSET

#define AM335XGPIO_GPIO_DATAIN_OFFSET   (0x138 / 4)

Definition at line 35 of file am335xgpio.c.

◆ AM335XGPIO_GPIO_DATAOUT_OFFSET

#define AM335XGPIO_GPIO_DATAOUT_OFFSET   (0x13C / 4) /* DATAOUT register uses 0 for output, 1 for input */

Definition at line 36 of file am335xgpio.c.

◆ AM335XGPIO_GPIO_OE_OFFSET

#define AM335XGPIO_GPIO_OE_OFFSET   (0x134 / 4)

Definition at line 34 of file am335xgpio.c.

◆ AM335XGPIO_GPIO_SETDATAOUT_OFFSET

#define AM335XGPIO_GPIO_SETDATAOUT_OFFSET   (0x194 / 4)

Definition at line 38 of file am335xgpio.c.

◆ AM335XGPIO_NUM_GPIO_CHIPS

#define AM335XGPIO_NUM_GPIO_CHIPS   4

Definition at line 24 of file am335xgpio.c.

◆ AM335XGPIO_NUM_GPIO_PER_CHIP

#define AM335XGPIO_NUM_GPIO_PER_CHIP   32

Definition at line 23 of file am335xgpio.c.

◆ AM335XGPIO_READ_REG

#define AM335XGPIO_READ_REG (   chip_num,
  offset 
)     (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)))

Definition at line 40 of file am335xgpio.c.

◆ AM335XGPIO_SET_HIGH

#define AM335XGPIO_SET_HIGH (   gpio_config)     AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_SETDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))

Definition at line 56 of file am335xgpio.c.

◆ AM335XGPIO_SET_INPUT

#define AM335XGPIO_SET_INPUT (   gpio_config)     AM335XGPIO_SET_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))

Definition at line 52 of file am335xgpio.c.

◆ AM335XGPIO_SET_LOW

#define AM335XGPIO_SET_LOW (   gpio_config)     AM335XGPIO_WRITE_REG((gpio_config)->chip_num, AM335XGPIO_GPIO_CLEARDATAOUT_OFFSET, BIT((gpio_config)->gpio_num))

Definition at line 58 of file am335xgpio.c.

◆ AM335XGPIO_SET_OUTPUT

#define AM335XGPIO_SET_OUTPUT (   gpio_config)     AM335XGPIO_CLEAR_REG_BITS((gpio_config)->chip_num, AM335XGPIO_GPIO_OE_OFFSET, BIT((gpio_config)->gpio_num))

Definition at line 54 of file am335xgpio.c.

◆ AM335XGPIO_SET_REG_BITS

#define AM335XGPIO_SET_REG_BITS (   chip_num,
  offset,
  bit_mask 
)     (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) |= (bit_mask))

Definition at line 46 of file am335xgpio.c.

◆ AM335XGPIO_WRITE_REG

#define AM335XGPIO_WRITE_REG (   chip_num,
  offset,
  value 
)     (*(am335xgpio_gpio_chip_mmap_addr[(chip_num)] + (offset)) = (value))

Definition at line 43 of file am335xgpio.c.

Enumeration Type Documentation

◆ amx335gpio_initial_gpio_mode

Enumerator
AM335XGPIO_GPIO_MODE_INPUT 
AM335XGPIO_GPIO_MODE_OUTPUT_LOW 
AM335XGPIO_GPIO_MODE_OUTPUT_HIGH 

Definition at line 61 of file am335xgpio.c.

Function Documentation

◆ am335xgpio_blink()

static int am335xgpio_blink ( int  on)
static

Definition at line 276 of file am335xgpio.c.

◆ am335xgpio_init()

◆ am335xgpio_jtag_mode_possible()

static bool am335xgpio_jtag_mode_possible ( void  )
static

◆ am335xgpio_khz()

static int am335xgpio_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 293 of file am335xgpio.c.

References ERROR_FAIL, ERROR_OK, LOG_DEBUG, speed_coeff, and speed_offset.

◆ am335xgpio_munmap()

static void am335xgpio_munmap ( void  )
static

Definition at line 380 of file am335xgpio.c.

References am335xgpio_gpio_chip_mmap_addr, AM335XGPIO_NUM_GPIO_CHIPS, and LOG_ERROR.

Referenced by am335xgpio_init().

◆ am335xgpio_quit()

static int am335xgpio_quit ( void  )
static

Definition at line 462 of file am335xgpio.c.

◆ am335xgpio_read()

static bb_value_t am335xgpio_read ( void  )
static

Definition at line 210 of file am335xgpio.c.

References ADAPTER_GPIO_IDX_TDO, BB_HIGH, BB_LOW, and get_gpio_value().

◆ am335xgpio_reset()

static int am335xgpio_reset ( int  trst,
int  srst 
)
static

◆ am335xgpio_speed()

static int am335xgpio_speed ( int  speed)
static

Definition at line 311 of file am335xgpio.c.

References ERROR_OK, and jtag_delay.

◆ am335xgpio_speed_div()

static int am335xgpio_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 305 of file am335xgpio.c.

References ERROR_OK, speed_coeff, and speed_offset.

◆ am335xgpio_swd_mode_possible()

static bool am335xgpio_swd_mode_possible ( void  )
static

Definition at line 371 of file am335xgpio.c.

References ADAPTER_GPIO_IDX_SWCLK, ADAPTER_GPIO_IDX_SWDIO, and is_gpio_config_valid().

Referenced by am335xgpio_init().

◆ am335xgpio_swd_write()

static int am335xgpio_swd_write ( int  swclk,
int  swdio 
)
static

◆ am335xgpio_swdio_drive()

static void am335xgpio_swdio_drive ( bool  is_output)
static

◆ am335xgpio_swdio_read()

static int am335xgpio_swdio_read ( void  )
static

Definition at line 271 of file am335xgpio.c.

References ADAPTER_GPIO_IDX_SWDIO, and get_gpio_value().

◆ am335xgpio_write()

static int am335xgpio_write ( int  tck,
int  tms,
int  tdi 
)
static

◆ COMMAND_HANDLER()

COMMAND_HANDLER ( am335xgpio_handle_speed_coeffs  )

Definition at line 317 of file am335xgpio.c.

◆ get_gpio_mode()

◆ get_gpio_mode_name()

static const char* get_gpio_mode_name ( enum amx335gpio_initial_gpio_mode  gpio_mode)
static

◆ get_gpio_value()

static int get_gpio_value ( const struct adapter_gpio_config gpio_config)
static

◆ initialize_gpio()

◆ is_gpio_config_valid()

◆ restore_gpio()

◆ set_gpio_value()

static void set_gpio_value ( const struct adapter_gpio_config gpio_config,
int  value 
)
static

Variable Documentation

◆ adapter_gpio_config

Definition at line 85 of file am335xgpio.c.

◆ am335xgpio_adapter_driver

struct adapter_driver am335xgpio_adapter_driver
Initial value:
= {
.name = "am335xgpio",
.transports = am335xgpio_transports,
.init = am335xgpio_init,
.quit = am335xgpio_quit,
.reset = am335xgpio_reset,
.speed = am335xgpio_speed,
.speed_div = am335xgpio_speed_div,
.jtag_ops = &am335xgpio_interface,
.swd_ops = &bitbang_swd,
}
static int am335xgpio_quit(void)
Definition: am335xgpio.c:462
static const struct command_registration am335xgpio_command_handlers[]
Definition: am335xgpio.c:340
static int am335xgpio_speed_div(int speed, int *khz)
Definition: am335xgpio.c:305
static int am335xgpio_init(void)
Definition: am335xgpio.c:387
static int am335xgpio_speed(int speed)
Definition: am335xgpio.c:311
static int am335xgpio_khz(int khz, int *jtag_speed)
Definition: am335xgpio.c:293
static struct jtag_interface am335xgpio_interface
Definition: am335xgpio.c:353
static const char *const am335xgpio_transports[]
Definition: am335xgpio.c:351
static int am335xgpio_reset(int trst, int srst)
Definition: am335xgpio.c:239
const struct swd_driver bitbang_swd
Definition: bitbang.c:569

Definition at line 462 of file am335xgpio.c.

◆ am335xgpio_bitbang

struct bitbang_interface am335xgpio_bitbang
static
Initial value:
= {
.read = am335xgpio_read,
.write = am335xgpio_write,
.swdio_read = am335xgpio_swdio_read,
.swdio_drive = am335xgpio_swdio_drive,
.swd_write = am335xgpio_swd_write,
}
static int am335xgpio_swdio_read(void)
Definition: am335xgpio.c:271
static int am335xgpio_write(int tck, int tms, int tdi)
Definition: am335xgpio.c:215
static int am335xgpio_swd_write(int swclk, int swdio)
Definition: am335xgpio.c:227
static int am335xgpio_blink(int on)
Definition: am335xgpio.c:276
static void am335xgpio_swdio_drive(bool is_output)
Definition: am335xgpio.c:258
static bb_value_t am335xgpio_read(void)
Definition: am335xgpio.c:210

Definition at line 276 of file am335xgpio.c.

Referenced by am335xgpio_init().

◆ am335xgpio_command_handlers

const struct command_registration am335xgpio_command_handlers[]
static
Initial value:
= {
{
.name = "am335xgpio",
.mode = COMMAND_ANY,
.help = "perform am335xgpio management",
.usage = "",
},
}
static const struct command_registration am335xgpio_subcommand_handlers[]
Definition: am335xgpio.c:329
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235

Definition at line 317 of file am335xgpio.c.

◆ am335xgpio_gpio_chip_hw_addr

const uint32_t am335xgpio_gpio_chip_hw_addr[AM335XGPIO_NUM_GPIO_CHIPS]
static
Initial value:
= {
}
#define AM335XGPIO_GPIO3_HW_ADDR
Definition: am335xgpio.c:28
#define AM335XGPIO_GPIO2_HW_ADDR
Definition: am335xgpio.c:27
#define AM335XGPIO_GPIO0_HW_ADDR
Definition: am335xgpio.c:25
#define AM335XGPIO_GPIO1_HW_ADDR
Definition: am335xgpio.c:26

Definition at line 67 of file am335xgpio.c.

Referenced by am335xgpio_init().

◆ am335xgpio_gpio_chip_mmap_addr

volatile uint32_t* am335xgpio_gpio_chip_mmap_addr[AM335XGPIO_NUM_GPIO_CHIPS]
static

Definition at line 75 of file am335xgpio.c.

Referenced by am335xgpio_init(), and am335xgpio_munmap().

◆ am335xgpio_interface

struct jtag_interface am335xgpio_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
}
int bitbang_execute_queue(void)
Definition: bitbang.c:281
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189

Definition at line 351 of file am335xgpio.c.

◆ am335xgpio_subcommand_handlers

const struct command_registration am335xgpio_subcommand_handlers[]
static
Initial value:
= {
{
.name = "speed_coeffs",
.handler = am335xgpio_handle_speed_coeffs,
.mode = COMMAND_CONFIG,
.help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.",
.usage = "[SPEED_COEFF SPEED_OFFSET]",
},
}
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 317 of file am335xgpio.c.

◆ am335xgpio_transports

const char* const am335xgpio_transports[] = { "jtag", "swd", NULL }
static

Definition at line 351 of file am335xgpio.c.

◆ dev_mem_fd

int dev_mem_fd
static

Definition at line 77 of file am335xgpio.c.

Referenced by am335xgpio_init().

◆ initial_gpio_mode

enum amx335gpio_initial_gpio_mode initial_gpio_mode[ADAPTER_GPIO_IDX_NUM]
static

Definition at line 77 of file am335xgpio.c.

Referenced by initialize_gpio(), and restore_gpio().

◆ jtag_delay

unsigned int jtag_delay
static

Definition at line 83 of file am335xgpio.c.

Referenced by am335xgpio_speed(), am335xgpio_swd_write(), and am335xgpio_write().

◆ speed_coeff

int speed_coeff = 600000
static

Definition at line 81 of file am335xgpio.c.

Referenced by am335xgpio_khz(), and am335xgpio_speed_div().

◆ speed_offset

int speed_offset = 575
static

Definition at line 82 of file am335xgpio.c.

Referenced by am335xgpio_khz(), and am335xgpio_speed_div().