drivers/linuxgpiod: add led
Bitbang interface allows having a LED on one of the GPIO. Let also linuxgpiod driver to specify and use the LED connection. Change-Id: Id3d8772ee1808b92354fd073ba3947bacd8253ef Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5770 Tested-by: jenkins
This commit is contained in:
parent
d62b3c51df
commit
9b32a06dad
|
@ -27,6 +27,7 @@ static int trst_gpio = -1;
|
||||||
static int srst_gpio = -1;
|
static int srst_gpio = -1;
|
||||||
static int swclk_gpio = -1;
|
static int swclk_gpio = -1;
|
||||||
static int swdio_gpio = -1;
|
static int swdio_gpio = -1;
|
||||||
|
static int led_gpio = -1;
|
||||||
static int gpiochip = -1;
|
static int gpiochip = -1;
|
||||||
|
|
||||||
static struct gpiod_chip *gpiod_chip;
|
static struct gpiod_chip *gpiod_chip;
|
||||||
|
@ -38,6 +39,7 @@ static struct gpiod_line *gpiod_trst;
|
||||||
static struct gpiod_line *gpiod_swclk;
|
static struct gpiod_line *gpiod_swclk;
|
||||||
static struct gpiod_line *gpiod_swdio;
|
static struct gpiod_line *gpiod_swdio;
|
||||||
static struct gpiod_line *gpiod_srst;
|
static struct gpiod_line *gpiod_srst;
|
||||||
|
static struct gpiod_line *gpiod_led;
|
||||||
|
|
||||||
static int last_swclk;
|
static int last_swclk;
|
||||||
static int last_swdio;
|
static int last_swdio;
|
||||||
|
@ -171,13 +173,26 @@ static int linuxgpiod_swd_write(int swclk, int swdio)
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int linuxgpiod_blink(int on)
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if (!gpiod_led)
|
||||||
|
return ERROR_OK;
|
||||||
|
|
||||||
|
retval = gpiod_line_set_value(gpiod_led, on);
|
||||||
|
if (retval < 0)
|
||||||
|
LOG_WARNING("Fail set led");
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
static struct bitbang_interface linuxgpiod_bitbang = {
|
static struct bitbang_interface linuxgpiod_bitbang = {
|
||||||
.read = linuxgpiod_read,
|
.read = linuxgpiod_read,
|
||||||
.write = linuxgpiod_write,
|
.write = linuxgpiod_write,
|
||||||
.swdio_read = linuxgpiod_swdio_read,
|
.swdio_read = linuxgpiod_swdio_read,
|
||||||
.swdio_drive = linuxgpiod_swdio_drive,
|
.swdio_drive = linuxgpiod_swdio_drive,
|
||||||
.swd_write = linuxgpiod_swd_write,
|
.swd_write = linuxgpiod_swd_write,
|
||||||
.blink = NULL,
|
.blink = linuxgpiod_blink,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -248,6 +263,7 @@ static inline void helper_release(struct gpiod_line *line)
|
||||||
|
|
||||||
static int linuxgpiod_quit(void)
|
static int linuxgpiod_quit(void)
|
||||||
{
|
{
|
||||||
|
helper_release(gpiod_led);
|
||||||
helper_release(gpiod_srst);
|
helper_release(gpiod_srst);
|
||||||
helper_release(gpiod_swdio);
|
helper_release(gpiod_swdio);
|
||||||
helper_release(gpiod_swclk);
|
helper_release(gpiod_swclk);
|
||||||
|
@ -370,6 +386,12 @@ static int linuxgpiod_init(void)
|
||||||
goto out_error;
|
goto out_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_gpio_valid(led_gpio)) {
|
||||||
|
gpiod_led = helper_get_output_line("led", led_gpio, 0);
|
||||||
|
if (gpiod_led == NULL)
|
||||||
|
goto out_error;
|
||||||
|
}
|
||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
|
||||||
out_error:
|
out_error:
|
||||||
|
@ -484,6 +506,15 @@ COMMAND_HANDLER(linuxgpiod_handle_swd_gpionum_swdio)
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
COMMAND_HANDLER(linuxgpiod_handle_gpionum_led)
|
||||||
|
{
|
||||||
|
if (CMD_ARGC == 1)
|
||||||
|
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], led_gpio);
|
||||||
|
|
||||||
|
command_print(CMD, "LinuxGPIOD num: led = %d", led_gpio);
|
||||||
|
return ERROR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
COMMAND_HANDLER(linuxgpiod_handle_gpiochip)
|
COMMAND_HANDLER(linuxgpiod_handle_gpiochip)
|
||||||
{
|
{
|
||||||
if (CMD_ARGC == 1)
|
if (CMD_ARGC == 1)
|
||||||
|
@ -564,6 +595,13 @@ static const struct command_registration linuxgpiod_command_handlers[] = {
|
||||||
.help = "gpio number for swdio.",
|
.help = "gpio number for swdio.",
|
||||||
.usage = "swdio",
|
.usage = "swdio",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "linuxgpiod_led_num",
|
||||||
|
.handler = linuxgpiod_handle_gpionum_led,
|
||||||
|
.mode = COMMAND_CONFIG,
|
||||||
|
.help = "gpio number for LED.",
|
||||||
|
.usage = "led",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "linuxgpiod_gpiochip",
|
.name = "linuxgpiod_gpiochip",
|
||||||
.handler = linuxgpiod_handle_gpiochip,
|
.handler = linuxgpiod_handle_gpiochip,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# | TMS/SWDIO | J3.4 (PA3) | 3 |
|
# | TMS/SWDIO | J3.4 (PA3) | 3 |
|
||||||
# | TDI | J3.5 (PA4) | 4 |
|
# | TDI | J3.5 (PA4) | 4 |
|
||||||
# | nTRST | J3.6 (PA5) | 5 |
|
# | nTRST | J3.6 (PA5) | 5 |
|
||||||
|
# | LED | J3.7 (PA6) | 6 |
|
||||||
# | GND | J3.12 (GND) | |
|
# | GND | J3.12 (GND) | |
|
||||||
# +-----------+-------------+-------------+
|
# +-----------+-------------+-------------+
|
||||||
|
|
||||||
|
@ -21,5 +22,6 @@ linuxgpiod_jtag_nums 2 3 4 1
|
||||||
linuxgpiod_trst_num 5
|
linuxgpiod_trst_num 5
|
||||||
linuxgpiod_swd_nums 2 3
|
linuxgpiod_swd_nums 2 3
|
||||||
linuxgpiod_srst_num 0
|
linuxgpiod_srst_num 0
|
||||||
|
linuxgpiod_led_num 6
|
||||||
|
|
||||||
reset_config trst_and_srst separate srst_push_pull
|
reset_config trst_and_srst separate srst_push_pull
|
||||||
|
|
Loading…
Reference in New Issue