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

Go to the source code of this file.

Data Structures

struct  imx_gpio_regs
 

Macros

#define IMX_GPIO_BASE   0x0209c000
 
#define IMX_GPIO_REGS_COUNT   8
 
#define IMX_GPIO_SIZE   0x00004000
 

Functions

struct imx_gpio_regs __attribute__ ((aligned(IMX_GPIO_SIZE)))
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_srst)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_tck)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_tdi)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_tdo)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_tms)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionum_trst)
 
 COMMAND_HANDLER (imx_gpio_handle_jtag_gpionums)
 
 COMMAND_HANDLER (imx_gpio_handle_peripheral_base)
 
 COMMAND_HANDLER (imx_gpio_handle_speed_coeffs)
 
 COMMAND_HANDLER (imx_gpio_handle_swd_gpionum_swclk)
 
 COMMAND_HANDLER (imx_gpio_handle_swd_gpionum_swdio)
 
 COMMAND_HANDLER (imx_gpio_handle_swd_gpionums)
 
static void gpio_clear (int g)
 
static bool gpio_level (int g)
 
static bool gpio_mode_get (int g)
 
static void gpio_mode_input_set (int g)
 
static void gpio_mode_output_set (int g)
 
static void gpio_mode_set (int g, int m)
 
static void gpio_set (int g)
 
static int imx_gpio_init (void)
 
static bool imx_gpio_jtag_mode_possible (void)
 
static int imx_gpio_khz (int khz, int *jtag_speed)
 
static int imx_gpio_quit (void)
 
static bb_value_t imx_gpio_read (void)
 
static int imx_gpio_reset (int trst, int srst)
 
static int imx_gpio_speed (int speed)
 
static int imx_gpio_speed_div (int speed, int *khz)
 
static bool imx_gpio_swd_mode_possible (void)
 
static int imx_gpio_swd_write (int swclk, int swdio)
 
static void imx_gpio_swdio_drive (bool is_output)
 
static int imx_gpio_swdio_read (void)
 
static int imx_gpio_write (int tck, int tms, int tdi)
 
static int is_gpio_valid (int gpio)
 

Variables

static int dev_mem_fd
 
uint32_t dr
 
uint32_t edge_sel
 
uint32_t gdir
 
uint32_t icr1
 
uint32_t icr2
 
uint32_t imr
 
struct adapter_driver imx_gpio_adapter_driver
 
static struct bitbang_interface imx_gpio_bitbang
 
static const struct command_registration imx_gpio_command_handlers []
 
static struct jtag_interface imx_gpio_interface
 
static uint32_t imx_gpio_peri_base = IMX_GPIO_BASE
 
static const char *const imx_gpio_transports [] = { "jtag", "swd", NULL }
 
uint32_t isr
 
static unsigned int jtag_delay
 
static volatile struct imx_gpio_regspio_base
 
uint32_t psr
 
static int speed_coeff = 50000
 
static int speed_offset = 100
 
static int srst_gpio = -1
 
static int srst_gpio_mode
 
static int swclk_gpio = -1
 
static int swclk_gpio_mode
 
static int swdio_gpio = -1
 
static int swdio_gpio_mode
 
static int tck_gpio = -1
 
static int tck_gpio_mode
 
static int tdi_gpio = -1
 
static int tdi_gpio_mode
 
static int tdo_gpio = -1
 
static int tdo_gpio_mode
 
static int tms_gpio = -1
 
static int tms_gpio_mode
 
static int trst_gpio = -1
 
static int trst_gpio_mode
 

Macro Definition Documentation

◆ IMX_GPIO_BASE

#define IMX_GPIO_BASE   0x0209c000

Definition at line 19 of file imx_gpio.c.

◆ IMX_GPIO_REGS_COUNT

#define IMX_GPIO_REGS_COUNT   8

Definition at line 21 of file imx_gpio.c.

◆ IMX_GPIO_SIZE

#define IMX_GPIO_SIZE   0x00004000

Definition at line 20 of file imx_gpio.c.

Function Documentation

◆ __attribute__()

struct imx_gpio_regs __attribute__ ( (aligned(IMX_GPIO_SIZE))  )

◆ COMMAND_HANDLER() [1/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_srst  )

Definition at line 257 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and srst_gpio.

◆ COMMAND_HANDLER() [2/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_tck  )

Definition at line 221 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and tck_gpio.

◆ COMMAND_HANDLER() [3/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_tdi  )

Definition at line 248 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and tdi_gpio.

◆ COMMAND_HANDLER() [4/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_tdo  )

Definition at line 239 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and tdo_gpio.

◆ COMMAND_HANDLER() [5/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_tms  )

Definition at line 230 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and tms_gpio.

◆ COMMAND_HANDLER() [6/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionum_trst  )

Definition at line 266 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and trst_gpio.

◆ COMMAND_HANDLER() [7/12]

COMMAND_HANDLER ( imx_gpio_handle_jtag_gpionums  )

◆ COMMAND_HANDLER() [8/12]

COMMAND_HANDLER ( imx_gpio_handle_peripheral_base  )

◆ COMMAND_HANDLER() [9/12]

COMMAND_HANDLER ( imx_gpio_handle_speed_coeffs  )

◆ COMMAND_HANDLER() [10/12]

COMMAND_HANDLER ( imx_gpio_handle_swd_gpionum_swclk  )

Definition at line 291 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and swclk_gpio.

◆ COMMAND_HANDLER() [11/12]

COMMAND_HANDLER ( imx_gpio_handle_swd_gpionum_swdio  )

Definition at line 300 of file imx_gpio.c.

References CMD, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, command_print(), ERROR_OK, and swdio_gpio.

◆ COMMAND_HANDLER() [12/12]

COMMAND_HANDLER ( imx_gpio_handle_swd_gpionums  )

◆ gpio_clear()

static void gpio_clear ( int  g)
inlinestatic

Definition at line 65 of file imx_gpio.c.

References imx_gpio_regs::dr, and pio_base.

Referenced by imx_gpio_init(), imx_gpio_reset(), imx_gpio_swd_write(), and imx_gpio_write().

◆ gpio_level()

static bool gpio_level ( int  g)
inlinestatic

Definition at line 70 of file imx_gpio.c.

References imx_gpio_regs::dr, and pio_base.

Referenced by imx_gpio_read(), and imx_gpio_swdio_read().

◆ gpio_mode_get()

static bool gpio_mode_get ( int  g)
inlinestatic

Definition at line 40 of file imx_gpio.c.

References imx_gpio_regs::gdir, and pio_base.

Referenced by imx_gpio_init().

◆ gpio_mode_input_set()

static void gpio_mode_input_set ( int  g)
inlinestatic

Definition at line 45 of file imx_gpio.c.

References imx_gpio_regs::gdir, and pio_base.

Referenced by gpio_mode_set(), imx_gpio_init(), and imx_gpio_swdio_drive().

◆ gpio_mode_output_set()

static void gpio_mode_output_set ( int  g)
inlinestatic

Definition at line 50 of file imx_gpio.c.

References imx_gpio_regs::gdir, and pio_base.

Referenced by gpio_mode_set(), imx_gpio_init(), and imx_gpio_swdio_drive().

◆ gpio_mode_set()

static void gpio_mode_set ( int  g,
int  m 
)
inlinestatic

Definition at line 55 of file imx_gpio.c.

References gpio_mode_input_set(), and gpio_mode_output_set().

Referenced by imx_gpio_quit().

◆ gpio_set()

static void gpio_set ( int  g)
inlinestatic

Definition at line 60 of file imx_gpio.c.

References imx_gpio_regs::dr, and pio_base.

Referenced by imx_gpio_init(), imx_gpio_reset(), imx_gpio_swd_write(), and imx_gpio_write().

◆ imx_gpio_init()

◆ imx_gpio_jtag_mode_possible()

static bool imx_gpio_jtag_mode_possible ( void  )
static

Definition at line 443 of file imx_gpio.c.

References is_gpio_valid(), tck_gpio, tdi_gpio, tdo_gpio, and tms_gpio.

Referenced by imx_gpio_init().

◆ imx_gpio_khz()

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

Definition at line 174 of file imx_gpio.c.

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

◆ imx_gpio_quit()

◆ imx_gpio_read()

static bb_value_t imx_gpio_read ( void  )
static

Definition at line 121 of file imx_gpio.c.

References BB_HIGH, BB_LOW, gpio_level(), and tdo_gpio.

◆ imx_gpio_reset()

static int imx_gpio_reset ( int  trst,
int  srst 
)
static

Definition at line 150 of file imx_gpio.c.

References ERROR_OK, gpio_clear(), gpio_set(), srst_gpio, and trst_gpio.

◆ imx_gpio_speed()

static int imx_gpio_speed ( int  speed)
static

Definition at line 192 of file imx_gpio.c.

References ERROR_OK, and jtag_delay.

◆ imx_gpio_speed_div()

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

Definition at line 186 of file imx_gpio.c.

References ERROR_OK, speed_coeff, and speed_offset.

◆ imx_gpio_swd_mode_possible()

static bool imx_gpio_swd_mode_possible ( void  )
static

Definition at line 456 of file imx_gpio.c.

References is_gpio_valid(), swclk_gpio, and swdio_gpio.

Referenced by imx_gpio_init().

◆ imx_gpio_swd_write()

static int imx_gpio_swd_write ( int  swclk,
int  swdio 
)
static

Definition at line 138 of file imx_gpio.c.

References ERROR_OK, gpio_clear(), gpio_set(), jtag_delay, swclk_gpio, and swdio_gpio.

◆ imx_gpio_swdio_drive()

static void imx_gpio_swdio_drive ( bool  is_output)
static

Definition at line 161 of file imx_gpio.c.

References gpio_mode_input_set(), gpio_mode_output_set(), and swdio_gpio.

◆ imx_gpio_swdio_read()

static int imx_gpio_swdio_read ( void  )
static

Definition at line 169 of file imx_gpio.c.

References gpio_level(), and swdio_gpio.

◆ imx_gpio_write()

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

Definition at line 126 of file imx_gpio.c.

References ERROR_OK, gpio_clear(), gpio_set(), jtag_delay, tck_gpio, tdi_gpio, and tms_gpio.

◆ is_gpio_valid()

static int is_gpio_valid ( int  gpio)
static

Definition at line 198 of file imx_gpio.c.

References IMX_GPIO_REGS_COUNT.

Referenced by imx_gpio_jtag_mode_possible(), and imx_gpio_swd_mode_possible().

Variable Documentation

◆ dev_mem_fd

int dev_mem_fd
static

Definition at line 36 of file imx_gpio.c.

Referenced by imx_gpio_init().

◆ dr

uint32_t dr

Definition at line 0 of file imx_gpio.c.

◆ edge_sel

uint32_t edge_sel

Definition at line 7 of file imx_gpio.c.

◆ gdir

uint32_t gdir

Definition at line 1 of file imx_gpio.c.

◆ icr1

uint32_t icr1

Definition at line 3 of file imx_gpio.c.

◆ icr2

uint32_t icr2

Definition at line 4 of file imx_gpio.c.

◆ imr

uint32_t imr

Definition at line 5 of file imx_gpio.c.

◆ imx_gpio_adapter_driver

struct adapter_driver imx_gpio_adapter_driver
Initial value:
= {
.name = "imx_gpio",
.transports = imx_gpio_transports,
.init = imx_gpio_init,
.quit = imx_gpio_quit,
.reset = imx_gpio_reset,
.speed = imx_gpio_speed,
.khz = imx_gpio_khz,
.speed_div = imx_gpio_speed_div,
.jtag_ops = &imx_gpio_interface,
.swd_ops = &bitbang_swd,
}
const struct swd_driver bitbang_swd
Definition: bitbang.c:617
static int imx_gpio_speed(int speed)
Definition: imx_gpio.c:192
static int imx_gpio_khz(int khz, int *jtag_speed)
Definition: imx_gpio.c:174
static const char *const imx_gpio_transports[]
Definition: imx_gpio.c:420
static struct jtag_interface imx_gpio_interface
Definition: imx_gpio.c:422
static int imx_gpio_speed_div(int speed, int *khz)
Definition: imx_gpio.c:186
static int imx_gpio_quit(void)
Definition: imx_gpio.c:548
static int imx_gpio_init(void)
Definition: imx_gpio.c:465
static const struct command_registration imx_gpio_command_handlers[]
Definition: imx_gpio.c:331
static int imx_gpio_reset(int trst, int srst)
Definition: imx_gpio.c:150

Definition at line 420 of file imx_gpio.c.

◆ imx_gpio_bitbang

struct bitbang_interface imx_gpio_bitbang
static
Initial value:
= {
.read = imx_gpio_read,
.write = imx_gpio_write,
.swdio_read = imx_gpio_swdio_read,
.swdio_drive = imx_gpio_swdio_drive,
.swd_write = imx_gpio_swd_write,
.blink = NULL
}
static int imx_gpio_write(int tck, int tms, int tdi)
Definition: imx_gpio.c:126
static void imx_gpio_swdio_drive(bool is_output)
Definition: imx_gpio.c:161
static int imx_gpio_swd_write(int swclk, int swdio)
Definition: imx_gpio.c:138
static int imx_gpio_swdio_read(void)
Definition: imx_gpio.c:169
static bb_value_t imx_gpio_read(void)
Definition: imx_gpio.c:121
#define NULL
Definition: usb.h:16

Definition at line 83 of file imx_gpio.c.

Referenced by imx_gpio_init().

◆ imx_gpio_command_handlers

const struct command_registration imx_gpio_command_handlers[]
static

Definition at line 321 of file imx_gpio.c.

◆ imx_gpio_interface

struct jtag_interface imx_gpio_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
}
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:296
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:187

Definition at line 420 of file imx_gpio.c.

◆ imx_gpio_peri_base

uint32_t imx_gpio_peri_base = IMX_GPIO_BASE
static

Definition at line 23 of file imx_gpio.c.

Referenced by COMMAND_HANDLER(), and imx_gpio_init().

◆ imx_gpio_transports

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

Definition at line 420 of file imx_gpio.c.

◆ isr

uint32_t isr

Definition at line 6 of file imx_gpio.c.

◆ jtag_delay

unsigned int jtag_delay
static

Definition at line 119 of file imx_gpio.c.

Referenced by imx_gpio_speed(), imx_gpio_swd_write(), and imx_gpio_write().

◆ pio_base

volatile struct imx_gpio_regs* pio_base
static

◆ psr

uint32_t psr

Definition at line 2 of file imx_gpio.c.

◆ speed_coeff

int speed_coeff = 50000
static

Definition at line 117 of file imx_gpio.c.

Referenced by COMMAND_HANDLER(), imx_gpio_khz(), and imx_gpio_speed_div().

◆ speed_offset

int speed_offset = 100
static

Definition at line 118 of file imx_gpio.c.

Referenced by COMMAND_HANDLER(), imx_gpio_khz(), and imx_gpio_speed_div().

◆ srst_gpio

int srst_gpio = -1
static

Definition at line 105 of file imx_gpio.c.

Referenced by COMMAND_HANDLER(), imx_gpio_init(), imx_gpio_quit(), and imx_gpio_reset().

◆ srst_gpio_mode

int srst_gpio_mode
static

Definition at line 106 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ swclk_gpio

int swclk_gpio = -1
static

◆ swclk_gpio_mode

int swclk_gpio_mode
static

Definition at line 108 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ swdio_gpio

◆ swdio_gpio_mode

int swdio_gpio_mode
static

Definition at line 110 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ tck_gpio

int tck_gpio = -1
static

◆ tck_gpio_mode

int tck_gpio_mode
static

Definition at line 96 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ tdi_gpio

int tdi_gpio = -1
static

◆ tdi_gpio_mode

int tdi_gpio_mode
static

Definition at line 100 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ tdo_gpio

int tdo_gpio = -1
static

◆ tdo_gpio_mode

int tdo_gpio_mode
static

Definition at line 102 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ tms_gpio

int tms_gpio = -1
static

◆ tms_gpio_mode

int tms_gpio_mode
static

Definition at line 98 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().

◆ trst_gpio

int trst_gpio = -1
static

Definition at line 103 of file imx_gpio.c.

Referenced by COMMAND_HANDLER(), imx_gpio_init(), imx_gpio_quit(), and imx_gpio_reset().

◆ trst_gpio_mode

int trst_gpio_mode
static

Definition at line 104 of file imx_gpio.c.

Referenced by imx_gpio_init(), and imx_gpio_quit().