OpenOCD
bcm2835gpio.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2013 by Paul Fertser, fercerpav@gmail.com *
5  * *
6  * Copyright (C) 2012 by Creative Product Design, marc @ cpdesign.com.au *
7  * Based on at91rm9200.c (c) Anders Larsen *
8  * and RPi GPIO examples by Gert van Loo & Dom *
9  ***************************************************************************/
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include <jtag/adapter.h>
16 #include <jtag/interface.h>
17 #include <transport/transport.h>
18 #include "bitbang.h"
19 
20 #include <sys/mman.h>
21 
22 static char *bcm2835_peri_mem_dev;
23 static off_t bcm2835_peri_base = 0x20000000;
24 #define BCM2835_GPIO_BASE (bcm2835_peri_base + 0x200000) /* GPIO controller */
25 
26 #define BCM2835_PADS_GPIO_0_27 (bcm2835_peri_base + 0x100000)
27 #define BCM2835_PADS_GPIO_0_27_OFFSET (0x2c / 4)
28 
29 /* See "GPIO Function Select Registers (GPFSELn)" in "Broadcom BCM2835 ARM Peripherals" datasheet. */
30 #define BCM2835_GPIO_MODE_INPUT 0
31 #define BCM2835_GPIO_MODE_OUTPUT 1
32 
33 /* GPIO setup macros */
34 #define BCM2835_GPIO_REG_READ(offset) \
35  (*(pio_base + (offset)))
36 
37 #define BCM2835_GPIO_REG_WRITE(offset, value) \
38  (*(pio_base + (offset)) = (value))
39 
40 #define BCM2835_GPIO_SET_REG_BITS(offset, bit_mask) \
41  (*(pio_base + (offset)) |= (bit_mask))
42 
43 #define BCM2835_GPIO_CLEAR_REG_BITS(offset, bit_mask) \
44  (*(pio_base + (offset)) &= ~(bit_mask))
45 
46 #define BCM2835_GPIO_MODE_ADDR(gpio_pin_num) (pio_base + ((gpio_pin_num) / 10))
47 #define BCM2835_GPIO_SET_ADDR(gpio_pin_num) (pio_base + 7 + ((gpio_pin_num) / 32))
48 #define BCM2835_GPIO_CLR_ADDR(gpio_pin_num) (pio_base + 10 + ((gpio_pin_num) / 32))
49 #define BCM2835_GPIO_LEVEL_ADDR(gpio_pin_num) (pio_base + 13 + ((gpio_pin_num) / 32))
50 
51 static int dev_mem_fd;
52 static volatile uint32_t *pio_base = MAP_FAILED;
53 static volatile uint32_t *pads_base = MAP_FAILED;
54 
55 /* Transition delay coefficients */
56 static int speed_coeff = 113714;
57 static int speed_offset = 28;
58 static unsigned int jtag_delay;
59 
61 static struct initial_gpio_state {
62  unsigned int mode;
66 
67 static struct {
68  volatile uint32_t *swdio_clr_set_addr[2];
69  uint32_t swdio_mask;
70  volatile uint32_t *swdio_read_level_addr;
73  volatile uint32_t *swdio_mode_addr;
76  volatile uint32_t *swclk_clr_set_addr[2];
77  uint32_t swclk_mask;
78  volatile uint32_t *tdi_clr_set_addr[2];
79  uint32_t tdi_mask;
80  volatile uint32_t *tms_clr_set_addr[2];
81  uint32_t tms_mask;
82  volatile uint32_t *tck_clr_set_addr[2];
83  uint32_t tck_mask;
84  volatile uint32_t *tdo_read_level_addr;
88 
89 /* GPFSEL[0,5], read the function select bits of specified GPIO pin number */
90 static inline unsigned int bcm2835_get_mode(unsigned int gpio_pin_num)
91 {
92  return (BCM2835_GPIO_REG_READ((gpio_pin_num / 10)) >> ((gpio_pin_num % 10) * 3) & 7);
93 }
94 
95 /* GPLEV[13,14], current level of the pin */
96 static inline bool bcm2835_get_level(unsigned int gpio_pin_num)
97 {
98  return ((BCM2835_GPIO_REG_READ((13 + (gpio_pin_num / 32))) >> (gpio_pin_num % 32)) & 1);
99 }
100 
101 /* set GPIO pin as input */
102 static inline void bcm2835_set_input(unsigned int gpio_pin_num)
103 {
104  BCM2835_GPIO_CLEAR_REG_BITS((gpio_pin_num / 10), (7 << ((gpio_pin_num % 10) * 3)));
105 }
106 
107 /* clear the mode bits first, then set as necessary */
108 static inline void bcm2835_set_mode(unsigned int gpio_pin_num, unsigned char mode)
109 {
110  bcm2835_set_input(gpio_pin_num);
111  BCM2835_GPIO_SET_REG_BITS((gpio_pin_num / 10), (mode << ((gpio_pin_num % 10) * 3)));
112 }
113 
114 /* set GPIO pin as output */
115 static inline void bcm2835_set_output(unsigned int gpio_pin_num)
116 {
118 }
119 
120 /* GPSET[7,8], sets bits which are 1, ignores bits which are 0 */
121 static inline void bcm2835_gpio_set(unsigned int gpio_pin_num)
122 {
123  BCM2835_GPIO_REG_WRITE((7 + (gpio_pin_num / 32)), (1 << (gpio_pin_num % 32)));
124 }
125 
126 /* GPCLR[10,11], clears bits which are 1, ignores bits which are 0 */
127 static inline void bcm2835_gpio_clear(unsigned int gpio_pin_num)
128 {
129  BCM2835_GPIO_REG_WRITE((10 + (gpio_pin_num / 32)), (1 << (gpio_pin_num % 32)));
130 }
131 
132 static inline const char *bcm2835_get_mem_dev(void)
133 {
135  return bcm2835_peri_mem_dev;
136 
137  return "/dev/gpiomem";
138 }
139 
140 static inline void bcm2835_gpio_synchronize(void)
141 {
142  /* Ensure that previous writes to GPIO registers are flushed out of
143  * the inner shareable domain to prevent pipelined writes to the
144  * same address being merged.
145  */
146  __sync_synchronize();
147 }
148 
149 static inline void bcm2835_delay(void)
150 {
151  for (unsigned int i = 0; i < jtag_delay; i++)
152  asm volatile ("");
153 }
154 
156 {
157  /* Only chip 0 is supported, accept unset value (-1) too */
158  return adapter_gpio_config[idx].gpio_num <= 53;
159 }
160 
161 static void set_gpio_value(const struct adapter_gpio_config *gpio_config, int value)
162 {
163  value = value ^ (gpio_config->active_low ? 1 : 0);
164  switch (gpio_config->drive) {
166  if (value)
167  bcm2835_gpio_set(gpio_config->gpio_num);
168  else
169  bcm2835_gpio_clear(gpio_config->gpio_num);
170  /* For performance reasons assume the GPIO is already set as an output
171  * and therefore the call can be omitted here.
172  */
173  break;
175  if (value) {
176  bcm2835_set_input(gpio_config->gpio_num);
177  } else {
178  bcm2835_gpio_clear(gpio_config->gpio_num);
179  bcm2835_set_output(gpio_config->gpio_num);
180  }
181  break;
183  if (value) {
184  bcm2835_gpio_set(gpio_config->gpio_num);
185  bcm2835_set_output(gpio_config->gpio_num);
186  } else {
187  bcm2835_set_input(gpio_config->gpio_num);
188  }
189  break;
190  }
192 }
193 
195 {
196  if (is_gpio_config_valid(idx)) {
199  if (initial_gpio_state[idx].output_level)
200  bcm2835_gpio_set(adapter_gpio_config[idx].gpio_num);
201  else
203  }
204  }
206 }
207 
209 {
210  if (!is_gpio_config_valid(idx))
211  return;
212 
215  LOG_DEBUG("saved GPIO mode for %s (GPIO %d %d): %d",
216  adapter_gpio_get_name(idx), adapter_gpio_config[idx].chip_num, adapter_gpio_config[idx].gpio_num,
217  initial_gpio_state[idx].mode);
218 
219  if (adapter_gpio_config[idx].pull != ADAPTER_GPIO_PULL_NONE) {
220  LOG_WARNING("BCM2835 GPIO does not support pull-up or pull-down settings (signal %s)",
221  adapter_gpio_get_name(idx));
222  }
223 
224  switch (adapter_gpio_config[idx].init_state) {
227  break;
230  break;
232  bcm2835_set_input(adapter_gpio_config[idx].gpio_num);
233  break;
234  }
235 
236  /* Direction for non push-pull is already set by set_gpio_value() */
241 }
242 
243 static enum bb_value bcm2835gpio_read(void)
244 {
245  bool value = ((*gpio_control.tdo_read_level_addr >> gpio_control.tdo_level_shift_bits) & 1);
246  return (value ^ gpio_control.tdo_active_low) ? BB_HIGH : BB_LOW;
247 }
248 
249 static int bcm2835gpio_write(int tck, int tms, int tdi)
250 {
251  *gpio_control.tdi_clr_set_addr[tdi] = gpio_control.tdi_mask;
252  *gpio_control.tms_clr_set_addr[tms] = gpio_control.tms_mask;
253  *gpio_control.tck_clr_set_addr[tck] = gpio_control.tck_mask; /* Write clock last */
254 
256 
257  bcm2835_delay();
258 
259  return ERROR_OK;
260 }
261 
262 /* Requires push-pull drive mode for swclk and swdio */
263 static int bcm2835gpio_swd_write_fast(int swclk, int swdio)
264 {
265  *gpio_control.swdio_clr_set_addr[swdio] = gpio_control.swdio_mask;
266  *gpio_control.swclk_clr_set_addr[swclk] = gpio_control.swclk_mask; /* Write clock last */
267 
269 
270  bcm2835_delay();
271 
272  return ERROR_OK;
273 }
274 
275 /* Generic mode that works for open-drain/open-source drive modes, but slower */
276 static int bcm2835gpio_swd_write_generic(int swclk, int swdio)
277 {
279  set_gpio_value(&adapter_gpio_config[ADAPTER_GPIO_IDX_SWCLK], swclk); /* Write clock last */
280 
281  bcm2835_delay();
282 
283  return ERROR_OK;
284 }
285 
286 /* (1) assert or (0) deassert reset lines */
287 static int bcm2835gpio_reset(int trst, int srst)
288 {
289  /* As the "adapter reset_config" command keeps the srst and trst gpio drive
290  * mode settings in sync we can use our standard set_gpio_value() function
291  * that honours drive mode and active low.
292  */
295 
298 
299  LOG_DEBUG("trst %d gpio: %d %d, srst %d gpio: %d %d",
300  trst,
303  srst,
306  return ERROR_OK;
307 }
308 
309 static void bcm2835_swdio_drive(bool is_output)
310 {
311  if (is_output) {
314  /* per bcm2835_set_output, clear mode bits then set the pin to output */
315  *gpio_control.swdio_mode_addr = (gpio_control.swdio_mode_output_mask |
316  (*gpio_control.swdio_mode_addr & gpio_control.swdio_mode_input_mask));
317  } else {
318  *gpio_control.swdio_mode_addr &= gpio_control.swdio_mode_input_mask;
321  }
323 }
324 
325 static int bcm2835_swdio_read(void)
326 {
327  bool value = ((*gpio_control.swdio_read_level_addr >> gpio_control.swdio_level_shift_bits) & 1);
328  return (int)(value ^ gpio_control.swdio_active_low);
329 }
330 
331 static int bcm2835gpio_khz(int khz, int *jtag_speed)
332 {
333  if (!khz) {
334  LOG_DEBUG("BCM2835 GPIO: RCLK not supported");
335  return ERROR_FAIL;
336  }
337  *jtag_speed = DIV_ROUND_UP(speed_coeff, khz) - speed_offset;
338  LOG_DEBUG("jtag_delay %d", *jtag_speed);
339  if (*jtag_speed < 0)
340  *jtag_speed = 0;
341  return ERROR_OK;
342 }
343 
344 static int bcm2835gpio_speed_div(int speed, int *khz)
345 {
346  int divisor = speed + speed_offset;
347  /* divide with roundig to the closest */
348  *khz = (speed_coeff + divisor / 2) / divisor;
349  return ERROR_OK;
350 }
351 
352 static int bcm2835gpio_speed(int speed)
353 {
354  jtag_delay = speed;
355  return ERROR_OK;
356 }
357 
358 COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs)
359 {
360  if (CMD_ARGC == 2) {
363  }
364 
365  command_print(CMD, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d",
367  return ERROR_OK;
368 }
369 
370 COMMAND_HANDLER(bcm2835gpio_handle_peripheral_mem_dev)
371 {
372  if (CMD_ARGC == 1) {
373  free(bcm2835_peri_mem_dev);
374  bcm2835_peri_mem_dev = strdup(CMD_ARGV[0]);
375  }
376 
377  command_print(CMD, "BCM2835 GPIO: peripheral_mem_dev = %s",
379  return ERROR_OK;
380 }
381 
382 COMMAND_HANDLER(bcm2835gpio_handle_peripheral_base)
383 {
384  uint64_t tmp_base;
385  if (CMD_ARGC == 1) {
386  COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], tmp_base);
387  bcm2835_peri_base = (off_t)tmp_base;
388  }
389 
390  tmp_base = bcm2835_peri_base;
391  command_print(CMD, "BCM2835 GPIO: peripheral_base = 0x%08" PRIx64,
392  tmp_base);
393  return ERROR_OK;
394 }
395 
397  {
398  .name = "speed_coeffs",
399  .handler = &bcm2835gpio_handle_speed_coeffs,
400  .mode = COMMAND_CONFIG,
401  .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.",
402  .usage = "[SPEED_COEFF SPEED_OFFSET]",
403  },
404  {
405  .name = "peripheral_mem_dev",
406  .handler = &bcm2835gpio_handle_peripheral_mem_dev,
407  .mode = COMMAND_CONFIG,
408  .help = "device to map memory mapped GPIOs from.",
409  .usage = "[device]",
410  },
411  {
412  .name = "peripheral_base",
413  .handler = &bcm2835gpio_handle_peripheral_base,
414  .mode = COMMAND_CONFIG,
415  .help = "peripheral base to access GPIOs, not needed with /dev/gpiomem.",
416  .usage = "[base]",
417  },
418 
420 };
421 
422 static const struct command_registration bcm2835gpio_command_handlers[] = {
423  {
424  .name = "bcm2835gpio",
425  .mode = COMMAND_ANY,
426  .help = "perform bcm2835gpio management",
428  .usage = "",
429  },
431 };
432 
434 {
436  return false;
438  return false;
440  return false;
442  return false;
443  return true;
444 }
445 
447 {
449  return false;
451  return false;
452  return true;
453 }
454 
455 static void bcm2835gpio_munmap(void)
456 {
457  if (pio_base != MAP_FAILED) {
458  munmap((void *)pio_base, sysconf(_SC_PAGE_SIZE));
459  pio_base = MAP_FAILED;
460  }
461 
462  if (pads_base != MAP_FAILED) {
463  munmap((void *)pads_base, sysconf(_SC_PAGE_SIZE));
464  pads_base = MAP_FAILED;
465  }
466 }
467 
468 static int bcm2835gpio_blink(bool on)
469 {
472 
473  return ERROR_OK;
474 }
475 
478  .write = bcm2835gpio_write,
479  .swdio_read = bcm2835_swdio_read,
480  .swdio_drive = bcm2835_swdio_drive,
481  .swd_write = bcm2835gpio_swd_write_generic,
482  .blink = bcm2835gpio_blink,
483 };
484 
487  .write = bcm2835gpio_write,
488  .swdio_read = bcm2835_swdio_read,
489  .swdio_drive = bcm2835_swdio_drive,
490  .swd_write = bcm2835gpio_swd_write_fast,
491  .blink = bcm2835gpio_blink,
492 };
493 
494 static int bcm2835gpio_init(void)
495 {
496  LOG_INFO("BCM2835 GPIO JTAG/SWD bitbang driver");
497 
499 
501  LOG_ERROR("Require tck, tms, tdi and tdo gpios for JTAG mode");
502  return ERROR_JTAG_INIT_FAILED;
503  }
504 
506  LOG_ERROR("Require swclk and swdio gpio for SWD mode");
507  return ERROR_JTAG_INIT_FAILED;
508  }
509 
510  bool is_gpiomem = strcmp(bcm2835_get_mem_dev(), "/dev/gpiomem") == 0;
511  bool pad_mapping_possible = !is_gpiomem;
512 
513  dev_mem_fd = open(bcm2835_get_mem_dev(), O_RDWR | O_SYNC);
514  if (dev_mem_fd < 0) {
515  LOG_ERROR("open %s: %s", bcm2835_get_mem_dev(), strerror(errno));
516  /* TODO: add /dev/mem specific doc and refer to it
517  * if (!is_gpiomem && (errno == EACCES || errno == EPERM))
518  * LOG_INFO("Consult the user's guide chapter 4.? how to set permissions and capabilities");
519  */
520  return ERROR_JTAG_INIT_FAILED;
521  }
522 
523  pio_base = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
524  MAP_SHARED, dev_mem_fd, BCM2835_GPIO_BASE);
525 
526  if (pio_base == MAP_FAILED) {
527  LOG_ERROR("mmap: %s", strerror(errno));
528  close(dev_mem_fd);
529  return ERROR_JTAG_INIT_FAILED;
530  }
531 
532  /* TODO: move pads config to a separate utility */
533  if (pad_mapping_possible) {
534  pads_base = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
535  MAP_SHARED, dev_mem_fd, BCM2835_PADS_GPIO_0_27);
536 
537  if (pads_base == MAP_FAILED) {
538  LOG_ERROR("mmap pads: %s", strerror(errno));
539  LOG_WARNING("Continuing with unchanged GPIO pad settings (drive strength and slew rate)");
540  }
541  } else {
542  pads_base = MAP_FAILED;
543  }
544 
545  close(dev_mem_fd);
546 
547  if (pads_base != MAP_FAILED) {
548  /* set 4mA drive strength, slew rate limited, hysteresis on */
550 LOG_INFO("initial pads conf %08x", pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
551  pads_base[BCM2835_PADS_GPIO_0_27_OFFSET] = 0x5a000008 + 1;
552 LOG_INFO("pads conf set to %08x", pads_base[BCM2835_PADS_GPIO_0_27_OFFSET]);
553  }
554 
555  /* Configure JTAG/SWD signals. Default directions and initial states are handled
556  * by adapter.c and "adapter gpio" command.
557  */
558  if (transport_is_jtag()) {
564 
565  /* flip the addresses used when pins are active low */
566  unsigned char idx = adapter_gpio_config[ADAPTER_GPIO_IDX_TMS].active_low ? 1 : 0;
570 
575 
580 
582  gpio_control.tdo_level_shift_bits = (adapter_gpio_config[ADAPTER_GPIO_IDX_TDO].gpio_num % 32);
584  }
585 
586  const struct bitbang_interface *bcm2835gpio_bitbang = &bcm2835gpio_bitbang_swd_write_generic;
587 
588  if (transport_is_swd()) {
589  /* swdio and its buffer should be initialized in the order that prevents
590  * two outputs from being connected together. This will occur if the
591  * swdio GPIO of the AM335x is configured as an output while its
592  * external buffer is configured to send the swdio signal from the
593  * target to the AM335x.
594  */
598  } else {
601  }
602 
604 
607  /* flip the addresses used when pins are active low */
608  unsigned char idx = adapter_gpio_config[ADAPTER_GPIO_IDX_SWDIO].active_low ? 1 : 0;
609  gpio_control.swdio_clr_set_addr[idx] =
611  gpio_control.swdio_clr_set_addr[!idx] =
614  gpio_control.swdio_read_level_addr =
616  gpio_control.swdio_level_shift_bits = (adapter_gpio_config[ADAPTER_GPIO_IDX_SWDIO].gpio_num % 32);
619  gpio_control.swdio_mode_input_mask =
621  gpio_control.swdio_mode_output_mask =
623 
625  gpio_control.swclk_clr_set_addr[idx] =
627  gpio_control.swclk_clr_set_addr[!idx] =
630 
631  LOG_DEBUG("BCM2835 GPIO using fast mode for SWD write");
632  bcm2835gpio_bitbang = &bcm2835gpio_bitbang_swd_write_fast;
633  } else {
634  LOG_DEBUG("BCM2835 GPIO using generic mode for SWD write");
635  assert(bcm2835gpio_bitbang == &bcm2835gpio_bitbang_swd_write_generic);
636  }
637  }
638 
641 
642  bitbang_interface = bcm2835gpio_bitbang;
643 
644  return ERROR_OK;
645 }
646 
647 static int bcm2835gpio_quit(void)
648 {
649  if (transport_is_jtag()) {
655  }
656 
657  if (transport_is_swd()) {
658  /* Restore swdio/swdio_dir to their initial modes, even if that means
659  * connecting two outputs. Begin by making swdio an input so that the
660  * current and final states of swdio and swdio_dir do not have to be
661  * considered to calculate the safe restoration order.
662  */
667  }
668 
671 
672  if (pads_base != MAP_FAILED) {
673  /* Restore drive strength. MSB is password ("5A") */
675  }
677  free(bcm2835_peri_mem_dev);
678 
679  return ERROR_OK;
680 }
681 
682 
683 static struct jtag_interface bcm2835gpio_interface = {
685  .execute_queue = bitbang_execute_queue,
686 };
688  .name = "bcm2835gpio",
689  .transport_ids = TRANSPORT_JTAG | TRANSPORT_SWD,
690  .transport_preferred_id = TRANSPORT_JTAG,
691  .commands = bcm2835gpio_command_handlers,
692 
693  .init = bcm2835gpio_init,
694  .quit = bcm2835gpio_quit,
695  .reset = bcm2835gpio_reset,
696  .speed = bcm2835gpio_speed,
697  .khz = bcm2835gpio_khz,
698  .speed_div = bcm2835gpio_speed_div,
699 
700  .jtag_ops = &bcm2835gpio_interface,
701  .swd_ops = &bitbang_swd,
702 };
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
Definition: adapter.c:1263
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
Definition: adapter.c:1257
@ ADAPTER_GPIO_INIT_STATE_ACTIVE
Definition: adapter.h:32
@ ADAPTER_GPIO_INIT_STATE_INPUT
Definition: adapter.h:33
@ ADAPTER_GPIO_INIT_STATE_INACTIVE
Definition: adapter.h:31
adapter_gpio_config_index
Adapter GPIO.
Definition: adapter.h:52
@ ADAPTER_GPIO_IDX_LED
Definition: adapter.h:62
@ ADAPTER_GPIO_IDX_NUM
Definition: adapter.h:64
@ ADAPTER_GPIO_IDX_SWCLK
Definition: adapter.h:60
@ ADAPTER_GPIO_IDX_SWDIO_DIR
Definition: adapter.h:59
@ ADAPTER_GPIO_IDX_SRST
Definition: adapter.h:61
@ ADAPTER_GPIO_IDX_TRST
Definition: adapter.h:57
@ ADAPTER_GPIO_IDX_TDI
Definition: adapter.h:54
@ ADAPTER_GPIO_IDX_TMS
Definition: adapter.h:55
@ ADAPTER_GPIO_IDX_TCK
Definition: adapter.h:56
@ ADAPTER_GPIO_IDX_TDO
Definition: adapter.h:53
@ ADAPTER_GPIO_IDX_SWDIO
Definition: adapter.h:58
@ ADAPTER_GPIO_PULL_NONE
Definition: adapter.h:46
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE
Definition: adapter.h:19
@ ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN
Definition: adapter.h:18
@ ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL
Definition: adapter.h:17
bool transport_is_swd(void)
Returns true if the current debug session is using SWD as its transport.
Definition: adi_v5_swd.c:773
enum arm_mode mode
Definition: armv4_5.c:281
static char * bcm2835_peri_mem_dev
Definition: bcm2835gpio.c:22
static void bcm2835_set_output(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:115
static bool bcm2835gpio_jtag_mode_possible(void)
Definition: bcm2835gpio.c:433
uint32_t tdo_level_shift_bits
Definition: bcm2835gpio.c:85
volatile uint32_t * swdio_read_level_addr
Definition: bcm2835gpio.c:70
static void bcm2835gpio_munmap(void)
Definition: bcm2835gpio.c:455
static bool bcm2835_get_level(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:96
#define BCM2835_GPIO_BASE
Definition: bcm2835gpio.c:24
static void bcm2835_set_input(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:102
static const struct command_registration bcm2835gpio_command_handlers[]
Definition: bcm2835gpio.c:422
volatile uint32_t * swdio_mode_addr
Definition: bcm2835gpio.c:73
static const struct bitbang_interface bcm2835gpio_bitbang_swd_write_generic
Definition: bcm2835gpio.c:476
volatile uint32_t * tms_clr_set_addr[2]
Definition: bcm2835gpio.c:80
static void bcm2835_gpio_set(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:121
static volatile uint32_t * pads_base
Definition: bcm2835gpio.c:53
#define BCM2835_GPIO_CLR_ADDR(gpio_pin_num)
Definition: bcm2835gpio.c:48
static bool bcm2835gpio_swd_mode_possible(void)
Definition: bcm2835gpio.c:446
static void restore_gpio(enum adapter_gpio_config_index idx)
Definition: bcm2835gpio.c:194
volatile uint32_t * swclk_clr_set_addr[2]
Definition: bcm2835gpio.c:76
volatile uint32_t * swdio_clr_set_addr[2]
Definition: bcm2835gpio.c:68
static bool is_gpio_config_valid(enum adapter_gpio_config_index idx)
Definition: bcm2835gpio.c:155
static int bcm2835gpio_swd_write_generic(int swclk, int swdio)
Definition: bcm2835gpio.c:276
static void bcm2835_gpio_clear(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:127
static void bcm2835_gpio_synchronize(void)
Definition: bcm2835gpio.c:140
static void bcm2835_delay(void)
Definition: bcm2835gpio.c:149
uint32_t swdio_mode_input_mask
Definition: bcm2835gpio.c:74
static void bcm2835_swdio_drive(bool is_output)
Definition: bcm2835gpio.c:309
volatile uint32_t * tdi_clr_set_addr[2]
Definition: bcm2835gpio.c:78
#define BCM2835_PADS_GPIO_0_27
Definition: bcm2835gpio.c:26
uint32_t tck_mask
Definition: bcm2835gpio.c:83
static int bcm2835gpio_init(void)
Definition: bcm2835gpio.c:494
bool tdo_active_low
Definition: bcm2835gpio.c:86
static int bcm2835gpio_write(int tck, int tms, int tdi)
Definition: bcm2835gpio.c:249
static enum bb_value bcm2835gpio_read(void)
Definition: bcm2835gpio.c:243
struct adapter_driver bcm2835gpio_adapter_driver
Definition: bcm2835gpio.c:687
static off_t bcm2835_peri_base
Definition: bcm2835gpio.c:23
static int bcm2835gpio_khz(int khz, int *jtag_speed)
Definition: bcm2835gpio.c:331
static unsigned int jtag_delay
Definition: bcm2835gpio.c:58
static const struct bitbang_interface bcm2835gpio_bitbang_swd_write_fast
Definition: bcm2835gpio.c:485
static const struct command_registration bcm2835gpio_subcommand_handlers[]
Definition: bcm2835gpio.c:396
#define BCM2835_GPIO_REG_WRITE(offset, value)
Definition: bcm2835gpio.c:37
#define BCM2835_GPIO_SET_ADDR(gpio_pin_num)
Definition: bcm2835gpio.c:47
static int dev_mem_fd
Definition: bcm2835gpio.c:51
static int bcm2835_swdio_read(void)
Definition: bcm2835gpio.c:325
uint32_t swdio_mask
Definition: bcm2835gpio.c:69
COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs)
Definition: bcm2835gpio.c:358
static int speed_coeff
Definition: bcm2835gpio.c:56
static unsigned int bcm2835_get_mode(unsigned int gpio_pin_num)
Definition: bcm2835gpio.c:90
static const struct adapter_gpio_config * adapter_gpio_config
Definition: bcm2835gpio.c:60
static void bcm2835_set_mode(unsigned int gpio_pin_num, unsigned char mode)
Definition: bcm2835gpio.c:108
#define BCM2835_GPIO_LEVEL_ADDR(gpio_pin_num)
Definition: bcm2835gpio.c:49
#define BCM2835_GPIO_SET_REG_BITS(offset, bit_mask)
Definition: bcm2835gpio.c:40
static struct @17 gpio_control
static void set_gpio_value(const struct adapter_gpio_config *gpio_config, int value)
Definition: bcm2835gpio.c:161
volatile uint32_t * tdo_read_level_addr
Definition: bcm2835gpio.c:84
static int bcm2835gpio_reset(int trst, int srst)
Definition: bcm2835gpio.c:287
#define BCM2835_GPIO_MODE_OUTPUT
Definition: bcm2835gpio.c:31
#define BCM2835_GPIO_REG_READ(offset)
Definition: bcm2835gpio.c:34
static uint32_t initial_drive_strength_etc
Definition: bcm2835gpio.c:65
uint32_t swdio_mode_output_mask
Definition: bcm2835gpio.c:75
#define BCM2835_GPIO_CLEAR_REG_BITS(offset, bit_mask)
Definition: bcm2835gpio.c:43
static int speed_offset
Definition: bcm2835gpio.c:57
uint32_t swdio_level_shift_bits
Definition: bcm2835gpio.c:71
bool swdio_active_low
Definition: bcm2835gpio.c:72
uint32_t tms_mask
Definition: bcm2835gpio.c:81
static volatile uint32_t * pio_base
Definition: bcm2835gpio.c:52
static struct jtag_interface bcm2835gpio_interface
Definition: bcm2835gpio.c:683
static const char * bcm2835_get_mem_dev(void)
Definition: bcm2835gpio.c:132
static void initialize_gpio(enum adapter_gpio_config_index idx)
Definition: bcm2835gpio.c:208
#define BCM2835_GPIO_MODE_ADDR(gpio_pin_num)
Definition: bcm2835gpio.c:46
uint32_t swclk_mask
Definition: bcm2835gpio.c:77
uint32_t tdi_mask
Definition: bcm2835gpio.c:79
static int bcm2835gpio_quit(void)
Definition: bcm2835gpio.c:647
static int bcm2835gpio_blink(bool on)
Definition: bcm2835gpio.c:468
static int bcm2835gpio_speed_div(int speed, int *khz)
Definition: bcm2835gpio.c:344
volatile uint32_t * tck_clr_set_addr[2]
Definition: bcm2835gpio.c:82
static int bcm2835gpio_speed(int speed)
Definition: bcm2835gpio.c:352
static int bcm2835gpio_swd_write_fast(int swclk, int swdio)
Definition: bcm2835gpio.c:263
#define BCM2835_PADS_GPIO_0_27_OFFSET
Definition: bcm2835gpio.c:27
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:293
const struct swd_driver bitbang_swd
Definition: bitbang.c:614
bb_value
Definition: bitbang.h:17
@ BB_LOW
Definition: bitbang.h:18
@ BB_HIGH
Definition: bitbang.h:19
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:371
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#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...
Definition: command.h:440
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:188
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1840
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
#define LOG_WARNING(expr ...)
Definition: log.h:131
#define ERROR_FAIL
Definition: log.h:175
#define LOG_ERROR(expr ...)
Definition: log.h:134
#define LOG_INFO(expr ...)
Definition: log.h:128
#define LOG_DEBUG(expr ...)
Definition: log.h:111
#define ERROR_OK
Definition: log.h:169
Represents a driver for a debugging interface.
Definition: interface.h:208
const char *const name
The name of the interface driver.
Definition: interface.h:210
Configuration options for a single GPIO.
Definition: adapter.h:68
unsigned int gpio_num
Definition: adapter.h:69
enum adapter_gpio_drive_mode drive
Definition: adapter.h:71
Low level callbacks (for bitbang).
Definition: bitbang.h:30
enum bb_value(* read)(void)
Sample TDO and return the value.
Definition: bitbang.h:32
const char * name
Definition: command.h:234
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:239
unsigned int mode
Definition: bcm2835gpio.c:62
Represents a driver for a debugging interface.
Definition: interface.h:183
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:187
#define TRANSPORT_SWD
Definition: transport.h:20
#define TRANSPORT_JTAG
Definition: transport.h:19
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
#define NULL
Definition: usb.h:16