OpenOCD
linuxgpiod.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Bitbang driver for Linux GPIO descriptors through libgpiod
4  * Copyright (C) 2020 Antonio Borneo <borneo.antonio@gmail.com>
5  *
6  * Largely based on sysfsgpio driver
7  * Copyright (C) 2012 by Creative Product Design, marc @ cpdesign.com.au
8  * Copyright (C) 2014 by Jean-Christian de Rivaz <jc@eclis.ch>
9  * Copyright (C) 2014 by Paul Fertser <fercerpav@gmail.com>
10  */
11 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <gpiod.h>
17 #include <jtag/adapter.h>
18 #include <jtag/interface.h>
19 #include <transport/transport.h>
20 #include "bitbang.h"
21 #include "linuxgpiod.h"
22 
23 /*
24  * In case of libgpiod v1, use as much as possible API from v2 plus
25  * the dummy wrappers below.
26  */
27 #ifdef HAVE_LIBGPIOD_V1
28 
29 #define GPIOD_LINE_DIRECTION_INPUT GPIOD_LINE_REQUEST_DIRECTION_INPUT
30 #define GPIOD_LINE_DIRECTION_OUTPUT GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
31 
32 #define GPIOD_LINE_VALUE_INACTIVE 0
33 #define GPIOD_LINE_VALUE_ACTIVE 1
34 
35 #define GPIOD_LINE_DRIVE_PUSH_PULL 0
36 #define GPIOD_LINE_DRIVE_OPEN_DRAIN GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN
37 #define GPIOD_LINE_DRIVE_OPEN_SOURCE GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE
38 
39 #define GPIOD_LINE_BIAS_DISABLED GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE
40 #define GPIOD_LINE_BIAS_PULL_UP GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
41 #define GPIOD_LINE_BIAS_PULL_DOWN GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
42 
43 struct gpiod_line_settings {
44  int direction;
45  int value;
46  int drive;
47  int bias;
48  int active_low;
49 };
50 
51 static struct gpiod_line_settings *gpiod_line_settings_new(void)
52 {
53  struct gpiod_line_settings *rv;
54 
55  rv = calloc(sizeof(struct gpiod_line_settings), 1);
56  if (!rv) {
57  LOG_ERROR("No memory for gpiod line settings");
58  return NULL;
59  }
60 
61  return rv;
62 }
63 
64 static void gpiod_line_settings_free(struct gpiod_line_settings *settings)
65 {
66  free(settings);
67 }
68 
69 static int gpiod_line_settings_set_direction(struct gpiod_line_settings *settings,
70  int direction)
71 {
72  settings->direction = direction;
73 
74  return 0;
75 }
76 
77 static int gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings,
78  int value)
79 {
80  settings->value = value;
81 
82  return 0;
83 }
84 
85 static int gpiod_line_settings_set_drive(struct gpiod_line_settings *settings, int drive)
86 {
87  settings->drive = drive;
88 
89  return 0;
90 }
91 
92 static void gpiod_line_settings_set_active_low(struct gpiod_line_settings *settings,
93  bool active_low)
94 {
95  if (active_low)
96  settings->active_low = GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
97 }
98 
99 #ifdef HAVE_LIBGPIOD1_FLAGS_BIAS
100 
101 static int gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, int bias)
102 {
103  settings->bias = bias;
104 
105  return 0;
106 }
107 
108 #else /* HAVE_LIBGPIOD1_FLAGS_BIAS */
109 
110 static int gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, int bias)
111 {
112  if (bias == GPIOD_LINE_BIAS_DISABLED)
113  return 0;
114 
115  LOG_WARNING("linuxgpiod: ignoring request for pull-%s: not supported by libgpiod v%s",
116  (bias == GPIOD_LINE_BIAS_PULL_UP) ? "up" : "down",
117  gpiod_version_string());
118 
119  return 0;
120 }
121 
122 #endif /* HAVE_LIBGPIOD1_FLAGS_BIAS */
123 
124 struct gpiod_line_config {
125  unsigned int gpio_num;
126  struct gpiod_line_settings *line_settings;
127 };
128 
129 static struct gpiod_line_config *gpiod_line_config_new(void)
130 {
131  struct gpiod_line_config *rv;
132 
133  rv = calloc(sizeof(struct gpiod_line_config), 1);
134  if (!rv) {
135  LOG_ERROR("No memory for gpiod line config");
136  return NULL;
137  }
138 
139  return rv;
140 }
141 
142 static void gpiod_line_config_free(struct gpiod_line_config *config)
143 {
144  free(config);
145 }
146 
147 static int gpiod_line_config_add_line_settings(struct gpiod_line_config *config,
148  const unsigned int *offsets, size_t num_offsets, struct gpiod_line_settings *settings)
149 {
150  assert(num_offsets == 1);
151 
152  config->gpio_num = *offsets;
153  config->line_settings = settings;
154 
155  return 0;
156 }
157 
158 struct gpiod_request_config {
159  const char *consumer;
160 };
161 
162 static struct gpiod_request_config *gpiod_request_config_new(void)
163 {
164  struct gpiod_request_config *rv;
165 
166  rv = calloc(sizeof(struct gpiod_request_config), 1);
167  if (!rv) {
168  LOG_ERROR("No memory for gpiod request config");
169  return NULL;
170  }
171 
172  return rv;
173 }
174 
175 static void gpiod_request_config_free(struct gpiod_request_config *config)
176 {
177  free(config);
178 }
179 
180 static void gpiod_request_config_set_consumer(struct gpiod_request_config *config,
181  const char *consumer)
182 {
183  config->consumer = consumer;
184 }
185 
186 struct gpiod_line_request {
187  struct gpiod_line *gpio_line;
188  struct gpiod_chip *chip;
189  struct gpiod_request_config *req_cfg;
190  struct gpiod_line_config *line_cfg;
191 };
192 
193 static void gpiod_line_request_release(struct gpiod_line_request *request);
194 
195 static struct gpiod_line_request *gpiod_chip_request_lines(struct gpiod_chip *chip,
196  struct gpiod_request_config *req_cfg, struct gpiod_line_config *line_cfg)
197 {
198  struct gpiod_line_request *line_req;
199  int rv, flags = 0;
200 
201  assert(req_cfg);
202 
203  line_req = calloc(sizeof(struct gpiod_line_request), 1);
204  if (!line_req) {
205  LOG_ERROR("No memory for gpiod line request");
206  return NULL;
207  }
208 
209  line_req->gpio_line = gpiod_chip_get_line(chip, line_cfg->gpio_num);
210  if (!line_req->gpio_line) {
211  free(line_req);
212  return NULL;
213  }
214 
215  /* remember stuff in case we need to reconfigure later */
216  line_req->chip = chip;
217  line_req->req_cfg = gpiod_request_config_new();
218  *line_req->req_cfg = *req_cfg;
219  line_req->line_cfg = line_cfg;
220 
221  flags |= line_cfg->line_settings->drive;
222  flags |= line_cfg->line_settings->bias;
223  flags |= line_cfg->line_settings->active_low;
224 
225  struct gpiod_line_request_config config = {
226  .consumer = line_req->req_cfg->consumer,
227  .request_type = line_cfg->line_settings->direction,
228  .flags = flags,
229  };
230 
231  rv = gpiod_line_request(line_req->gpio_line, &config, line_cfg->line_settings->value);
232  if (rv < 0) {
233  gpiod_line_request_release(line_req);
234  return NULL;
235  }
236 
237  return line_req;
238 }
239 
240 static int gpiod_line_request_get_value(struct gpiod_line_request *request,
241  __attribute__((unused)) unsigned int offset)
242 {
243  return gpiod_line_get_value(request->gpio_line);
244 }
245 
246 static int gpiod_line_request_set_value(struct gpiod_line_request *request,
247  __attribute__((unused)) unsigned int offset, int value)
248 {
249  return gpiod_line_set_value(request->gpio_line, value);
250 }
251 
252 static void gpiod_line_request_release(struct gpiod_line_request *request)
253 {
254  gpiod_request_config_free(request->req_cfg);
255  gpiod_line_release(request->gpio_line);
256  free(request);
257 }
258 
259 static int gpiod_line_request_reconfigure_lines(struct gpiod_line_request *request,
260  struct gpiod_line_config *line_cfg)
261 {
262  int rv, flags = 0;
263 
264  /* in libgpiod v1 we have to release the line and re-aquire it */
265  gpiod_line_release(request->gpio_line);
266  request->gpio_line = gpiod_chip_get_line(request->chip, request->line_cfg->gpio_num);
267  if (!request->gpio_line)
268  return -1;
269 
270  flags |= line_cfg->line_settings->drive;
271  flags |= line_cfg->line_settings->bias;
272  flags |= line_cfg->line_settings->active_low;
273 
274  struct gpiod_line_request_config config = {
275  .consumer = request->req_cfg->consumer,
276  .request_type = line_cfg->line_settings->direction,
277  .flags = flags,
278  };
279 
280  rv = gpiod_line_request(request->gpio_line, &config, line_cfg->line_settings->value);
281  if (rv < 0)
282  return -1;
283 
284  /* remember updated line_cfg */
285  request->line_cfg = line_cfg;
286  return 0;
287 }
288 
289 #endif /* HAVE_LIBGPIOD_V1 */
290 
294 static struct gpiod_line_request *gpiod_line_req[ADAPTER_GPIO_IDX_NUM] = {};
295 
296 static int last_swclk;
297 static int last_swdio;
298 static bool last_stored;
299 static bool swdio_input;
300 
301 /* Helper to get/set a single line */
303 {
304  return gpiod_line_request_get_value(gpiod_line_req[idx],
305  adapter_gpio_get_config()[idx].gpio_num);
306 }
307 
309 {
310  return gpiod_line_request_set_value(gpiod_line_req[idx],
311  adapter_gpio_get_config()[idx].gpio_num,
312  value);
313 }
314 
315 /*
316  * Helper function to determine if gpio config is valid
317  *
318  * Assume here that there will be less than 10000 gpios per gpiochip, and less
319  * than 1000 gpiochips.
320  */
322 {
324  return adapter_gpio_config[idx].chip_num < 1000
325  && adapter_gpio_config[idx].gpio_num < 10000;
326 }
327 
328 /* Bitbang interface read of TDO */
329 static enum bb_value linuxgpiod_read(void)
330 {
331  int retval;
332 
334  if (retval < 0) {
335  LOG_WARNING("reading tdo failed");
336  return 0;
337  }
338 
339  return retval ? BB_HIGH : BB_LOW;
340 }
341 
342 /*
343  * Bitbang interface write of TCK, TMS, TDI
344  *
345  * Seeing as this is the only function where the outputs are changed,
346  * we can cache the old value to avoid needlessly writing it.
347  */
348 static int linuxgpiod_write(int tck, int tms, int tdi)
349 {
350  static int last_tck;
351  static int last_tms;
352  static int last_tdi;
353 
354  static int first_time;
355 
356  int retval;
357 
358  if (!first_time) {
359  last_tck = !tck;
360  last_tms = !tms;
361  last_tdi = !tdi;
362  first_time = 1;
363  }
364 
365  if (tdi != last_tdi) {
367  if (retval < 0)
368  LOG_WARNING("writing tdi failed");
369  }
370 
371  if (tms != last_tms) {
373  if (retval < 0)
374  LOG_WARNING("writing tms failed");
375  }
376 
377  /* write clk last */
378  if (tck != last_tck) {
380  if (retval < 0)
381  LOG_WARNING("writing tck failed");
382  }
383 
384  last_tdi = tdi;
385  last_tms = tms;
386  last_tck = tck;
387 
388  return ERROR_OK;
389 }
390 
391 static int linuxgpiod_swdio_read(void)
392 {
393  int retval;
394 
396  if (retval < 0) {
397  LOG_WARNING("Fail read swdio");
398  return 0;
399  }
400 
401  return retval;
402 }
403 
404 static void linuxgpiod_swdio_drive(bool is_output)
405 {
406  int retval;
408 
409  if (is_output) {
412  if (retval < 0)
413  LOG_WARNING("Failed to set swdio_dir=1");
414  }
415 
416  retval = gpiod_line_settings_set_direction(gpiod_line_settings[ADAPTER_GPIO_IDX_SWDIO],
417  GPIOD_LINE_DIRECTION_OUTPUT);
418  if (retval < 0)
419  LOG_WARNING("Failed to set new direction of swdio");
420 
421  retval = gpiod_line_settings_set_output_value(gpiod_line_settings[ADAPTER_GPIO_IDX_SWDIO],
422  GPIOD_LINE_VALUE_ACTIVE);
423  if (retval < 0)
424  LOG_WARNING("Failed to set output value of swdio");
425 
426  retval = gpiod_line_config_add_line_settings(gpiod_line_config[ADAPTER_GPIO_IDX_SWDIO],
429  if (retval < 0)
430  LOG_WARNING("Failed to apply output configuration to swdio");
431 
432  retval = gpiod_line_request_reconfigure_lines(gpiod_line_req[ADAPTER_GPIO_IDX_SWDIO],
434  if (retval < 0)
435  LOG_WARNING("Failed to switch swdio to output");
436  } else {
437  retval = gpiod_line_settings_set_direction(gpiod_line_settings[ADAPTER_GPIO_IDX_SWDIO],
438  GPIOD_LINE_DIRECTION_INPUT);
439  if (retval < 0)
440  LOG_WARNING("Failed to switch swdio to output");
441 
442  retval = gpiod_line_config_add_line_settings(gpiod_line_config[ADAPTER_GPIO_IDX_SWDIO],
445  if (retval < 0)
446  LOG_WARNING("Failed to apply input configuration to swdio");
447 
448  retval = gpiod_line_request_reconfigure_lines(gpiod_line_req[ADAPTER_GPIO_IDX_SWDIO],
450  if (retval < 0)
451  LOG_WARNING("Failed to switch swdio to input");
452 
455  if (retval < 0)
456  LOG_WARNING("Failed to set swdio_dir=0");
457  }
458  }
459 
460  last_stored = false;
461  swdio_input = !is_output;
462 }
463 
464 static int linuxgpiod_swd_write(int swclk, int swdio)
465 {
466  int retval;
467 
468  if (!swdio_input) {
469  if (!last_stored || swdio != last_swdio) {
471  if (retval < 0)
472  LOG_WARNING("Fail set swdio");
473  }
474  }
475 
476  /* write swclk last */
477  if (!last_stored || swclk != last_swclk) {
479  if (retval < 0)
480  LOG_WARNING("Fail set swclk");
481  }
482 
483  last_swdio = swdio;
484  last_swclk = swclk;
485  last_stored = true;
486 
487  return ERROR_OK;
488 }
489 
490 static int linuxgpiod_blink(bool on)
491 {
492  int retval;
493 
495  return ERROR_OK;
496 
498  if (retval < 0)
499  LOG_WARNING("Fail set led");
500  return retval;
501 }
502 
503 static const struct bitbang_interface linuxgpiod_bitbang = {
505  .write = linuxgpiod_write,
506  .swdio_read = linuxgpiod_swdio_read,
507  .swdio_drive = linuxgpiod_swdio_drive,
508  .swd_write = linuxgpiod_swd_write,
509  .blink = linuxgpiod_blink,
510 };
511 
512 /*
513  * Bitbang interface to manipulate reset lines SRST and TRST
514  *
515  * (1) assert or (0) deassert reset lines
516  */
517 int linuxgpiod_reset(int trst, int srst)
518 {
519  int retval1 = 0, retval2 = 0;
520 
521  LOG_DEBUG("linuxgpiod_reset");
522 
523  /*
524  * active low behavior handled by "adaptor gpio" command and
525  * GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW flag when requesting the line.
526  */
529  if (retval1 < 0)
530  LOG_WARNING("set srst value failed");
531  }
532 
535  if (retval2 < 0)
536  LOG_WARNING("set trst value failed");
537  }
538 
539  return ((retval1 < 0) || (retval2 < 0)) ? ERROR_FAIL : ERROR_OK;
540 }
541 
543 {
545  return false;
547  return false;
549  return false;
551  return false;
552  return true;
553 }
554 
556 {
558  return false;
560  return false;
561  return true;
562 }
563 
564 static inline void helper_release(enum adapter_gpio_config_index idx)
565 {
566  if (gpiod_line_req[idx]) {
567  gpiod_line_request_release(gpiod_line_req[idx]);
568  gpiod_line_req[idx] = NULL;
569  }
570  if (gpiod_line_config[idx]) {
571  gpiod_line_config_free(gpiod_line_config[idx]);
572  gpiod_line_config[idx] = NULL;
573  }
574  if (gpiod_line_settings[idx]) {
575  gpiod_line_settings_free(gpiod_line_settings[idx]);
576  gpiod_line_settings[idx] = NULL;
577  }
578  if (gpiod_chip[idx]) {
579  gpiod_chip_close(gpiod_chip[idx]);
580  gpiod_chip[idx] = NULL;
581  }
582 }
583 
585 {
586  LOG_DEBUG("linuxgpiod_quit");
587  for (int i = 0; i < ADAPTER_GPIO_IDX_NUM; ++i)
588  helper_release(i);
589 
590  return ERROR_OK;
591 }
592 
594 {
595  struct gpiod_request_config *req_cfg = NULL;
596  char chip_path[24];
597  int rv = 0;
599 
600  if (!is_gpio_config_valid(idx))
601  return ERROR_OK;
602 
603  snprintf(chip_path, sizeof(chip_path), "/dev/gpiochip%u", adapter_gpio_config[idx].chip_num);
604  gpiod_chip[idx] = gpiod_chip_open(chip_path);
605 
606  if (!gpiod_chip[idx]) {
607  LOG_ERROR("Cannot open LinuxGPIOD chip %d for %s", adapter_gpio_config[idx].chip_num,
608  adapter_gpio_get_name(idx));
609  return ERROR_JTAG_INIT_FAILED;
610  }
611 
612  gpiod_line_settings[idx] = gpiod_line_settings_new();
613  gpiod_line_config[idx] = gpiod_line_config_new();
614  req_cfg = gpiod_request_config_new();
615 
616  if (!gpiod_line_settings[idx] || !gpiod_line_config[idx] || !req_cfg) {
617  LOG_ERROR("Cannot configure LinuxGPIOD line for %s", adapter_gpio_get_name(idx));
618  gpiod_request_config_free(req_cfg);
619  return ERROR_JTAG_INIT_FAILED;
620  }
621 
622  gpiod_request_config_set_consumer(req_cfg, "OpenOCD");
623 
624  switch (adapter_gpio_config[idx].init_state) {
626  rv = gpiod_line_settings_set_direction(gpiod_line_settings[idx], GPIOD_LINE_DIRECTION_INPUT);
627  break;
629  rv = gpiod_line_settings_set_direction(gpiod_line_settings[idx], GPIOD_LINE_DIRECTION_OUTPUT);
630  rv |= gpiod_line_settings_set_output_value(gpiod_line_settings[idx], GPIOD_LINE_VALUE_INACTIVE);
631  break;
633  rv = gpiod_line_settings_set_direction(gpiod_line_settings[idx], GPIOD_LINE_DIRECTION_OUTPUT);
634  rv |= gpiod_line_settings_set_output_value(gpiod_line_settings[idx], GPIOD_LINE_VALUE_ACTIVE);
635  break;
636  }
637  if (rv < 0) {
638  LOG_ERROR("Error while configuring LinuxGPIOD line init state for %s", adapter_gpio_get_name(idx));
639  gpiod_request_config_free(req_cfg);
640  return ERROR_JTAG_INIT_FAILED;
641  }
642 
643  switch (adapter_gpio_config[idx].drive) {
645  rv = gpiod_line_settings_set_drive(gpiod_line_settings[idx], GPIOD_LINE_DRIVE_PUSH_PULL);
646  break;
648  rv = gpiod_line_settings_set_drive(gpiod_line_settings[idx], GPIOD_LINE_DRIVE_OPEN_DRAIN);
649  break;
651  rv = gpiod_line_settings_set_drive(gpiod_line_settings[idx], GPIOD_LINE_DRIVE_OPEN_SOURCE);
652  break;
653  }
654  if (rv < 0) {
655  LOG_ERROR("Error while configuring LinuxGPIOD line driving for %s", adapter_gpio_get_name(idx));
656  gpiod_request_config_free(req_cfg);
657  return ERROR_JTAG_INIT_FAILED;
658  }
659 
660  switch (adapter_gpio_config[idx].pull) {
662  rv = gpiod_line_settings_set_bias(gpiod_line_settings[idx], GPIOD_LINE_BIAS_DISABLED);
663  break;
665  rv = gpiod_line_settings_set_bias(gpiod_line_settings[idx], GPIOD_LINE_BIAS_PULL_UP);
666  break;
668  rv = gpiod_line_settings_set_bias(gpiod_line_settings[idx], GPIOD_LINE_BIAS_PULL_DOWN);
669  break;
670  }
671  if (rv < 0) {
672  LOG_ERROR("Error while configuring LinuxGPIOD line biasing for %s", adapter_gpio_get_name(idx));
673  gpiod_request_config_free(req_cfg);
674  return ERROR_JTAG_INIT_FAILED;
675  }
676 
677  gpiod_line_settings_set_active_low(gpiod_line_settings[idx], adapter_gpio_config[idx].active_low);
678 
679  rv = gpiod_line_config_add_line_settings(gpiod_line_config[idx],
680  &adapter_gpio_config[idx].gpio_num, 1,
681  gpiod_line_settings[idx]);
682  if (rv < 0) {
683  LOG_ERROR("Error configuring gpio line %s", adapter_gpio_get_name(idx));
684  gpiod_request_config_free(req_cfg);
685  return ERROR_JTAG_INIT_FAILED;
686  }
687 
688  gpiod_line_req[idx] = gpiod_chip_request_lines(gpiod_chip[idx], req_cfg, gpiod_line_config[idx]);
689 
690  gpiod_request_config_free(req_cfg);
691 
692  if (!gpiod_line_req[idx]) {
693  LOG_ERROR("Error requesting gpio line %s", adapter_gpio_get_name(idx));
694  return ERROR_JTAG_INIT_FAILED;
695  }
696 
697  return ERROR_OK;
698 }
699 
700 static int linuxgpiod_init(void)
701 {
702  LOG_INFO("Linux GPIOD JTAG/SWD bitbang driver");
703 
706 
707  /*
708  * Configure JTAG/SWD signals. Default directions and initial states are handled
709  * by adapter.c and "adapter gpio" command.
710  */
711 
712  /* Initialize SRST first to avoid signal conflict in
713  * connect_assert_srst mode */
715  goto out_error;
716 
717  if (transport_is_jtag()) {
719  LOG_ERROR("Require tck, tms, tdi and tdo gpios for JTAG mode");
720  goto out_error;
721  }
722 
728  goto out_error;
729  }
730 
731  if (transport_is_swd()) {
732  int retval1, retval2;
734  LOG_ERROR("Require swclk and swdio gpio for SWD mode");
735  goto out_error;
736  }
737 
738  /*
739  * swdio and its buffer should be initialized in the order that prevents
740  * two outputs from being connected together. This will occur if the
741  * swdio GPIO is configured as an output while the external buffer is
742  * configured to send the swdio signal from the target to the GPIO.
743  */
747  } else {
750  }
751  if (retval1 != ERROR_OK || retval2 != ERROR_OK)
752  goto out_error;
753 
755  goto out_error;
756  }
757 
759  goto out_error;
760 
761  return ERROR_OK;
762 
763 out_error:
764  linuxgpiod_quit();
765 
766  return ERROR_JTAG_INIT_FAILED;
767 }
768 
769 static struct jtag_interface linuxgpiod_interface = {
771  .execute_queue = bitbang_execute_queue,
772 };
773 
775  .name = "linuxgpiod",
776  .transport_ids = TRANSPORT_SWD | TRANSPORT_JTAG,
777  .transport_preferred_id = TRANSPORT_SWD,
778 
779  .init = linuxgpiod_init,
780  .quit = linuxgpiod_quit,
781  .reset = linuxgpiod_reset,
782 
783  .jtag_ops = &linuxgpiod_interface,
784  .swd_ops = &bitbang_swd,
785 };
const struct adapter_gpio_config * adapter_gpio_get_config(void)
Retrieves gpio configuration set with command "adapter gpio <signal_name>".
Definition: adapter.c:1349
const char * adapter_gpio_get_name(enum adapter_gpio_config_index idx)
Retrieves gpio name.
Definition: adapter.c:1343
@ 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_UP
Definition: adapter.h:47
@ ADAPTER_GPIO_PULL_DOWN
Definition: adapter.h:48
@ 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:954
static int last_tms
Definition: arm-jtag-ew.c:522
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:293
const struct swd_driver bitbang_swd
Definition: bitbang.c:596
bb_value
Definition: bitbang.h:17
@ BB_LOW
Definition: bitbang.h:18
@ BB_HIGH
Definition: bitbang.h:19
static uint16_t direction
Definition: ftdi.c:157
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:199
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1823
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
static bool last_stored
Definition: linuxgpiod.c:298
static int linuxgpiod_blink(bool on)
Definition: linuxgpiod.c:490
struct adapter_driver linuxgpiod_adapter_driver
Definition: linuxgpiod.c:774
static void helper_release(enum adapter_gpio_config_index idx)
Definition: linuxgpiod.c:564
static int last_swclk
Definition: linuxgpiod.c:296
int linuxgpiod_reset(int trst, int srst)
Definition: linuxgpiod.c:517
static bool linuxgpiod_jtag_mode_possible(void)
Definition: linuxgpiod.c:542
static bool is_gpio_config_valid(enum adapter_gpio_config_index idx)
Definition: linuxgpiod.c:321
int linuxgpiod_helper_get_line(enum adapter_gpio_config_index idx)
Definition: linuxgpiod.c:593
int linuxgpiod_quit(void)
Definition: linuxgpiod.c:584
static const struct bitbang_interface linuxgpiod_bitbang
Definition: linuxgpiod.c:503
static int linuxgpiod_line_set_value(enum adapter_gpio_config_index idx, int value)
Definition: linuxgpiod.c:308
static struct gpiod_line_settings * gpiod_line_settings[ADAPTER_GPIO_IDX_NUM]
Definition: linuxgpiod.c:292
static int linuxgpiod_line_get_value(enum adapter_gpio_config_index idx)
Definition: linuxgpiod.c:302
static struct jtag_interface linuxgpiod_interface
Definition: linuxgpiod.c:769
static int linuxgpiod_swdio_read(void)
Definition: linuxgpiod.c:391
static struct gpiod_line_request * gpiod_line_req[ADAPTER_GPIO_IDX_NUM]
Definition: linuxgpiod.c:294
static enum bb_value linuxgpiod_read(void)
Definition: linuxgpiod.c:329
static void linuxgpiod_swdio_drive(bool is_output)
Definition: linuxgpiod.c:404
static int linuxgpiod_write(int tck, int tms, int tdi)
Definition: linuxgpiod.c:348
static int last_swdio
Definition: linuxgpiod.c:297
static bool swdio_input
Definition: linuxgpiod.c:299
static struct gpiod_chip * gpiod_chip[ADAPTER_GPIO_IDX_NUM]
Definition: linuxgpiod.c:291
static struct gpiod_line_config * gpiod_line_config[ADAPTER_GPIO_IDX_NUM]
Definition: linuxgpiod.c:293
static int linuxgpiod_swd_write(int swclk, int swdio)
Definition: linuxgpiod.c:464
static int linuxgpiod_init(void)
Definition: linuxgpiod.c:700
static bool linuxgpiod_swd_mode_possible(void)
Definition: linuxgpiod.c:555
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_INFO(expr ...)
Definition: log.h:141
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
struct qn908x_flash_bank __attribute__
Definition: armv8.c:1059
Represents a driver for a debugging interface.
Definition: interface.h:219
const char *const name
The name of the interface driver.
Definition: interface.h:221
Configuration options for a single GPIO.
Definition: adapter.h:68
unsigned int gpio_num
Definition: adapter.h:69
unsigned int chip_num
Definition: adapter.h:70
enum adapter_gpio_pull pull
Definition: adapter.h:75
enum adapter_gpio_init_state init_state
Definition: adapter.h:72
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
Represents a driver for a debugging interface.
Definition: interface.h:194
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:198
#define TRANSPORT_SWD
Definition: transport.h:20
#define TRANSPORT_JTAG
Definition: transport.h:19
#define NULL
Definition: usb.h:16
uint8_t offset[4]
Definition: vdebug.c:9