1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de>
4 * Copyright (c) 2018 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
7 #ifndef OPENOCD_JTAG_ADAPTER_H
8 #define OPENOCD_JTAG_ADAPTER_H
14 /** Supported output drive modes for adaptor GPIO */
15 enum adapter_gpio_drive_mode
{
16 ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL
,
17 ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN
,
18 ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE
,
21 /** Supported GPIO directions */
22 enum adapter_gpio_direction
{
23 ADAPTER_GPIO_DIRECTION_INPUT
,
24 ADAPTER_GPIO_DIRECTION_OUTPUT
,
25 ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL
,
28 /** Supported initial states for GPIO */
29 enum adapter_gpio_init_state
{
30 ADAPTER_GPIO_INIT_STATE_INACTIVE
, /* Should be zero so it is the default state */
31 ADAPTER_GPIO_INIT_STATE_ACTIVE
,
32 ADAPTER_GPIO_INIT_STATE_INPUT
,
35 /** Supported pull directions for GPIO */
36 enum adapter_gpio_pull
{
37 ADAPTER_GPIO_PULL_NONE
,
39 ADAPTER_GPIO_PULL_DOWN
,
43 enum adapter_gpio_config_index
{
48 ADAPTER_GPIO_IDX_TRST
,
49 ADAPTER_GPIO_IDX_SWDIO
,
50 ADAPTER_GPIO_IDX_SWDIO_DIR
,
51 ADAPTER_GPIO_IDX_SWCLK
,
52 ADAPTER_GPIO_IDX_SRST
,
54 ADAPTER_GPIO_IDX_NUM
, /* must be the last item */
57 /** Configuration options for a single GPIO */
58 struct adapter_gpio_config
{
61 enum adapter_gpio_drive_mode drive
; /* For outputs only */
62 enum adapter_gpio_init_state init_state
;
64 enum adapter_gpio_pull pull
;
67 struct command_context
;
69 /** Register the adapter's commands */
70 int adapter_register_commands(struct command_context
*ctx
);
72 /** Initialize debug adapter upon startup. */
73 int adapter_init(struct command_context
*cmd_ctx
);
75 /** Shutdown the debug adapter upon program exit. */
76 int adapter_quit(void);
78 /** @returns true if adapter has been initialized */
79 bool is_adapter_initialized(void);
81 /** @returns USB location string set with command 'adapter usb location' */
82 const char *adapter_usb_get_location(void);
84 /** @returns true if USB location string is "<dev_bus>-<port_path[0]>[.<port_path[1]>[...]]" */
85 bool adapter_usb_location_equal(uint8_t dev_bus
, uint8_t *port_path
, size_t path_len
);
87 /** @returns The current adapter speed setting. */
88 int adapter_get_speed(int *speed
);
91 * Given a @a speed setting, use the interface @c speed_div callback to
93 * @param speed The speed setting to convert back to readable kHz.
94 * @returns ERROR_OK if the interface has not been initialized or on success;
95 * otherwise, the error code produced by the @c speed_div callback.
97 int adapter_get_speed_readable(int *speed
);
99 /** Attempt to configure the adapter for the specified kHz. */
100 int adapter_config_khz(unsigned int khz
);
103 * Attempt to enable RTCK/RCLK. If that fails, fallback to the
104 * specified frequency.
106 int adapter_config_rclk(unsigned int fallback_speed_khz
);
108 /** Retrieves the clock speed of the adapter in kHz. */
109 unsigned int adapter_get_speed_khz(void);
111 /** Retrieves the serial number set with command 'adapter serial' */
112 const char *adapter_get_required_serial(void);
115 * Retrieves gpio name
117 const char *adapter_gpio_get_name(enum adapter_gpio_config_index idx
);
120 * Retrieves gpio configuration set with command "adapter gpio <signal_name>"
122 const struct adapter_gpio_config
*adapter_gpio_get_config(void);
124 #endif /* OPENOCD_JTAG_ADAPTER_H */