From: Michael S. <mi...@sc...> - 2024-08-26 12:05:18
|
Hi, here is a patch to use the kernel's LED trigger system instead of direct GPIO access for the activity LED. This makes it possible to use an existing LED that is not attached to the GPIB HAT, and a single LED can be used for multiple functions. To convert the HAT LED to a kernel LED: echo "dtoverlay=gpio-led,gpio=4,trigger=heartbeat,label=hat_led" >>/boot/firmware/config.txt load GPIB driver module echo "gpib" >/sys/class/leds/hat_led/trigger cu Michael >From 33923fc9e9176bbbb7a3d237d3f9f22b719cfc85 Mon Sep 17 00:00:00 2001 From: root <root@gpib-rp2> Date: Sun, 18 Aug 2024 21:20:41 +0200 Subject: [PATCH] use LED trigger for GPIB activity LED instead of direct GPIO access --- .../drivers/gpib/gpio/gpib_bitbang.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/linux-gpib-kernel/drivers/gpib/gpio/gpib_bitbang.c b/linux-gpib-kernel/drivers/gpib/gpio/gpib_bitbang.c index a393bb45..46c8ea5c 100644 --- a/linux-gpib-kernel/drivers/gpib/gpio/gpib_bitbang.c +++ b/linux-gpib-kernel/drivers/gpib/gpio/gpib_bitbang.c @@ -97,6 +97,7 @@ #include <linux/gpio/machine.h> #include <linux/gpio.h> #include <linux/irq.h> +#include <linux/leds.h> static int sn7516x_used=1, sn7516x; module_param(sn7516x_used,int,0660); @@ -163,11 +164,12 @@ typedef enum { */ #define GPIB_PINS 16 -#define SN7516X_PINS 4 +#define SN7516X_PINS 3 #define NUM_PINS (GPIB_PINS + SN7516X_PINS) -#define ACT_LED_ON if (ACT_LED != NULL) gpiod_direction_output(ACT_LED, 1) -#define ACT_LED_OFF if (ACT_LED != NULL) gpiod_direction_output(ACT_LED, 0) +DEFINE_LED_TRIGGER(ledtrig_gpib); +#define ACT_LED_ON do {led_trigger_event(ledtrig_gpib, LED_FULL);} while(0) +#define ACT_LED_OFF do {led_trigger_event(ledtrig_gpib, LED_OFF);} while(0) struct gpio_desc * all_descriptors[GPIB_PINS+SN7516X_PINS]; @@ -192,7 +194,6 @@ struct gpio_desc * all_descriptors[GPIB_PINS+SN7516X_PINS]; #define PE all_descriptors[16] #define DC all_descriptors[17] #define TE all_descriptors[18] -#define ACT_LED all_descriptors[19] /* YOGA dapter uses a global enable for the buffer chips, re-using the TE pin */ #define YOGA_ENABLE TE @@ -218,8 +219,7 @@ int gpios_vector[] = { PE_pin_nr, DC_pin_nr, - TE_pin_nr, - ACT_LED_pin_nr + TE_pin_nr }; /* Lookup table for general GPIOs */ @@ -1197,6 +1197,8 @@ static int allocate_gpios(gpib_board_t *board) { retval = -1; } if (lookup_table) gpiod_remove_lookup_table(lookup_table); + // Initialize LED trigger + led_trigger_register_simple("gpib", &ledtrig_gpib); return retval; } @@ -1207,6 +1209,8 @@ static void bb_detach(gpib_board_t *board) dbg_printk(2, "Enter with data %p\n", board->private_data); if (board->private_data == NULL) return; + led_trigger_unregister_simple(ledtrig_gpib); + bb_free_irq(board, &priv->irq_DAV, NAME "_DAV"); bb_free_irq(board, &priv->irq_NRFD, NAME "_NRFD"); bb_free_irq(board, &priv->irq_NDAC, NAME "_NDAC"); @@ -1266,7 +1270,6 @@ static int bb_attach(gpib_board_t *board, const gpib_board_config_t *config) gpios_vector[&(D06) - &(all_descriptors[0])] = YOGA_D06_pin_nr; gpios_vector[&(PE) - &(all_descriptors[0])] = -1; gpios_vector[&(DC) - &(all_descriptors[0])] = -1; - gpios_vector[&(ACT_LED) - &(all_descriptors[0])] = -1; } else { dbg_printk (0, "Unrecognized pin mapping.\n"); goto bb_attach_fail; -- 2.39.2 |