bitbang: remove superfluous switch between jtag and swd
[openocd.git] / src / jtag / drivers / bcm2835gpio.c
index 38ef163fab53fdf0da378491bce801769b89d1a2..f547d93a4c49036f302af0753ffd609e52fea076 100644 (file)
@@ -51,7 +51,6 @@ static volatile uint32_t *pio_base;
 
 static bb_value_t bcm2835gpio_read(void);
 static int bcm2835gpio_write(int tck, int tms, int tdi);
-static int bcm2835gpio_reset(int trst, int srst);
 
 static int bcm2835_swdio_read(void);
 static void bcm2835_swdio_drive(bool is_output);
@@ -62,7 +61,6 @@ static int bcm2835gpio_quit(void);
 static struct bitbang_interface bcm2835gpio_bitbang = {
        .read = bcm2835gpio_read,
        .write = bcm2835gpio_write,
-       .reset = bcm2835gpio_reset,
        .swdio_read = bcm2835_swdio_read,
        .swdio_drive = bcm2835_swdio_drive,
        .blink = NULL
@@ -199,7 +197,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionums)
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       command_print(CMD_CTX,
+       command_print(CMD,
                        "BCM2835 GPIO config: tck = %d, tms = %d, tdi = %d, tdo = %d",
                        tck_gpio, tms_gpio, tdi_gpio, tdo_gpio);
 
@@ -211,7 +209,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tck)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: tck = %d", tck_gpio);
+       command_print(CMD, "BCM2835 GPIO config: tck = %d", tck_gpio);
        return ERROR_OK;
 }
 
@@ -220,7 +218,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tms)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: tms = %d", tms_gpio);
+       command_print(CMD, "BCM2835 GPIO config: tms = %d", tms_gpio);
        return ERROR_OK;
 }
 
@@ -229,7 +227,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdo)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: tdo = %d", tdo_gpio);
+       command_print(CMD, "BCM2835 GPIO config: tdo = %d", tdo_gpio);
        return ERROR_OK;
 }
 
@@ -238,7 +236,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdi)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: tdi = %d", tdi_gpio);
+       command_print(CMD, "BCM2835 GPIO config: tdi = %d", tdi_gpio);
        return ERROR_OK;
 }
 
@@ -247,7 +245,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_srst)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: srst = %d", srst_gpio);
+       command_print(CMD, "BCM2835 GPIO config: srst = %d", srst_gpio);
        return ERROR_OK;
 }
 
@@ -256,7 +254,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_trst)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio);
 
-       command_print(CMD_CTX, "BCM2835 GPIO config: trst = %d", trst_gpio);
+       command_print(CMD, "BCM2835 GPIO config: trst = %d", trst_gpio);
        return ERROR_OK;
 }
 
@@ -269,7 +267,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionums)
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       command_print(CMD_CTX,
+       command_print(CMD,
                        "BCM2835 GPIO nums: swclk = %d, swdio = %d",
                        swclk_gpio, swdio_gpio);
 
@@ -281,7 +279,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swclk)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio);
 
-       command_print(CMD_CTX, "BCM2835 num: swclk = %d", swclk_gpio);
+       command_print(CMD, "BCM2835 num: swclk = %d", swclk_gpio);
        return ERROR_OK;
 }
 
@@ -290,7 +288,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swdio)
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio);
 
-       command_print(CMD_CTX, "BCM2835 num: swdio = %d", swdio_gpio);
+       command_print(CMD, "BCM2835 num: swdio = %d", swdio_gpio);
        return ERROR_OK;
 }
 
@@ -300,6 +298,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs)
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], speed_coeff);
                COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset);
        }
+
+       command_print(CMD, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d",
+                                 speed_coeff, speed_offset);
        return ERROR_OK;
 }
 
@@ -307,6 +308,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_peripheral_base)
 {
        if (CMD_ARGC == 1)
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bcm2835_peri_base);
+
+       command_print(CMD, "BCM2835 GPIO: peripheral_base = 0x%08x",
+                                 bcm2835_peri_base);
        return ERROR_OK;
 }
 
@@ -316,74 +320,84 @@ static const struct command_registration bcm2835gpio_command_handlers[] = {
                .handler = &bcm2835gpio_handle_jtag_gpionums,
                .mode = COMMAND_CONFIG,
                .help = "gpio numbers for tck, tms, tdi, tdo. (in that order)",
-               .usage = "(tck tms tdi tdo)* ",
+               .usage = "[tck tms tdi tdo]",
        },
        {
                .name = "bcm2835gpio_tck_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_tck,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for tck.",
+               .usage = "[tck]",
        },
        {
                .name = "bcm2835gpio_tms_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_tms,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for tms.",
+               .usage = "[tms]",
        },
        {
                .name = "bcm2835gpio_tdo_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_tdo,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for tdo.",
+               .usage = "[tdo]",
        },
        {
                .name = "bcm2835gpio_tdi_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_tdi,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for tdi.",
+               .usage = "[tdi]",
        },
        {
                .name = "bcm2835gpio_swd_nums",
                .handler = &bcm2835gpio_handle_swd_gpionums,
                .mode = COMMAND_CONFIG,
                .help = "gpio numbers for swclk, swdio. (in that order)",
-               .usage = "(swclk swdio)* ",
+               .usage = "[swclk swdio]",
        },
        {
                .name = "bcm2835gpio_swclk_num",
                .handler = &bcm2835gpio_handle_swd_gpionum_swclk,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for swclk.",
+               .usage = "[swclk]",
        },
        {
                .name = "bcm2835gpio_swdio_num",
                .handler = &bcm2835gpio_handle_swd_gpionum_swdio,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for swdio.",
+               .usage = "[swdio]",
        },
        {
                .name = "bcm2835gpio_srst_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_srst,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for srst.",
+               .usage = "[srst]",
        },
        {
                .name = "bcm2835gpio_trst_num",
                .handler = &bcm2835gpio_handle_jtag_gpionum_trst,
                .mode = COMMAND_CONFIG,
                .help = "gpio number for trst.",
+               .usage = "[trst]",
        },
        {
                .name = "bcm2835gpio_speed_coeffs",
                .handler = &bcm2835gpio_handle_speed_coeffs,
                .mode = COMMAND_CONFIG,
                .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.",
+               .usage = "[SPEED_COEFF SPEED_OFFSET]",
        },
        {
                .name = "bcm2835gpio_peripheral_base",
                .handler = &bcm2835gpio_handle_peripheral_base,
                .mode = COMMAND_CONFIG,
                .help = "peripheral base to access GPIOs (RPi1 0x20000000, RPi2 0x3F000000).",
+               .usage = "[base]",
        },
 
        COMMAND_REGISTRATION_DONE
@@ -391,18 +405,25 @@ static const struct command_registration bcm2835gpio_command_handlers[] = {
 
 static const char * const bcm2835_transports[] = { "jtag", "swd", NULL };
 
-struct jtag_interface bcm2835gpio_interface = {
-       .name = "bcm2835gpio",
+static struct jtag_interface bcm2835gpio_interface = {
        .supported = DEBUG_CAP_TMS_SEQ,
        .execute_queue = bitbang_execute_queue,
+};
+
+struct adapter_driver bcm2835gpio_adapter_driver = {
+       .name = "bcm2835gpio",
        .transports = bcm2835_transports,
-       .swd = &bitbang_swd,
-       .speed = bcm2835gpio_speed,
-       .khz = bcm2835gpio_khz,
-       .speed_div = bcm2835gpio_speed_div,
        .commands = bcm2835gpio_command_handlers,
+
        .init = bcm2835gpio_init,
        .quit = bcm2835gpio_quit,
+       .reset = bcm2835gpio_reset,
+       .speed = bcm2835gpio_speed,
+       .khz = bcm2835gpio_khz,
+       .speed_div = bcm2835gpio_speed_div,
+
+       .jtag_ops = &bcm2835gpio_interface,
+       .swd_ops = &bitbang_swd,
 };
 
 static bool bcm2835gpio_jtag_mode_possible(void)
@@ -445,7 +466,11 @@ static int bcm2835gpio_init(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
+       dev_mem_fd = open("/dev/gpiomem", O_RDWR | O_SYNC);
+       if (dev_mem_fd < 0) {
+               LOG_DEBUG("Cannot open /dev/gpiomem, fallback to /dev/mem");
+               dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
+       }
        if (dev_mem_fd < 0) {
                perror("open");
                return ERROR_JTAG_INIT_FAILED;
@@ -510,7 +535,6 @@ static int bcm2835gpio_init(void)
 
        if (swd_mode) {
                bcm2835gpio_bitbang.write = bcm2835gpio_swd_write;
-               bitbang_switch_to_swd();
        }
 
        return ERROR_OK;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)