This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8202

-- gerrit

commit 537735347b061298209e727a7e9688b057533bb4
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Sun Apr 7 17:18:40 2024 +0200

    jtag: linuxgpiod: wrap gpiod_request_config from libgpiod v2
    
    Reorganize the code of helper_get_line() for label err_out.
    Define and use dummy functions from v2 for v1:
    - gpiod_request_config_new(),
    - gpiod_request_config_free(),
    - gpiod_request_config_set_consumer().
    
    Change-Id: Ide7cd8459941a5a863c425a2b5abf1fb4a075874
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/jtag/drivers/linuxgpiod.c b/src/jtag/drivers/linuxgpiod.c
index 156e9cb2f5..f0ff9b03e3 100644
--- a/src/jtag/drivers/linuxgpiod.c
+++ b/src/jtag/drivers/linuxgpiod.c
@@ -19,6 +19,35 @@
 #include <transport/transport.h>
 #include "bitbang.h"
 
+/*
+ * In case of libgpiod v1, use as much as possible API from v2 plus
+ * the dummy wrappers below.
+ */
+#if HAVE_LIBGPIOD_V1
+
+#define gpiod_request_config            gpiod_line_request_config
+
+static struct gpiod_request_config *gpiod_request_config_new(void)
+{
+       static struct gpiod_request_config my;
+
+       my = (struct gpiod_request_config) { NULL };
+
+       return &my;
+}
+
+static void gpiod_request_config_free(struct gpiod_request_config *config)
+{
+}
+
+static void gpiod_request_config_set_consumer(struct gpiod_request_config 
*config,
+       const char *consumer)
+{
+       config->consumer = consumer;
+}
+
+#endif /* HAVE_LIBGPIOD_V1 */
+
 static struct gpiod_chip *gpiod_chip[ADAPTER_GPIO_IDX_NUM] = {};
 static struct gpiod_line *gpiod_line[ADAPTER_GPIO_IDX_NUM] = {};
 
@@ -296,6 +325,15 @@ static int helper_get_line(enum adapter_gpio_config_index 
idx)
                return ERROR_JTAG_INIT_FAILED;
        }
 
+       struct gpiod_request_config *req_cfg = gpiod_request_config_new();
+       if (!req_cfg) {
+               LOG_ERROR("Cannot configure LinuxGPIOD line for %s", 
adapter_gpio_get_name(idx));
+               retval = ERROR_JTAG_INIT_FAILED;
+               goto err_out;
+       }
+
+       gpiod_request_config_set_consumer(req_cfg, "OpenOCD");
+
        switch (adapter_gpio_config[idx].init_state) {
        case ADAPTER_GPIO_INIT_STATE_INPUT:
                dir = GPIOD_LINE_REQUEST_DIRECTION_INPUT;
@@ -348,19 +386,22 @@ static int helper_get_line(enum adapter_gpio_config_index 
idx)
        if (adapter_gpio_config[idx].active_low)
                flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
 
-       struct gpiod_line_request_config config = {
-               .consumer = "OpenOCD",
-               .request_type = dir,
-               .flags = flags,
-       };
+       req_cfg->request_type = dir;
+       req_cfg->flags = flags;
 
-       retval = gpiod_line_request(gpiod_line[idx], &config, val);
+       retval = gpiod_line_request(gpiod_line[idx], req_cfg, val);
        if (retval < 0) {
                LOG_ERROR("Error requesting gpio line %s", 
adapter_gpio_get_name(idx));
-               return ERROR_JTAG_INIT_FAILED;
+               retval = ERROR_JTAG_INIT_FAILED;
+               goto err_out;
        }
 
-       return ERROR_OK;
+       retval = ERROR_OK;
+
+err_out:
+       gpiod_request_config_free(req_cfg);
+
+       return retval;
 }
 
 static int linuxgpiod_init(void)

-- 

Reply via email to