* [PATCH 1/8] staging: gpib: Fix request_system_control in gpio
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 2/8] staging: gpib: Fix setting controller-in-charge Dave Penkler
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
The implementation of the bb_request_system_control function
confused setting controller-in-charge with becoming system-controller.
Remove setting controller-in-charge and add initialization of the
control lines for the system-controller role.
Fixes: 4cd654f84769 ("staging: gpib: Add gpio bitbang GPIB driver")
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index 9670522fe36e..29aab72c1f0f 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -889,9 +889,13 @@ static int bb_request_system_control(struct gpib_board *board, int request_contr
if (!request_control)
return -EINVAL;
- set_bit(CIC_NUM, &board->status);
- // drive DAV & EOI false, enable NRFD & NDAC irqs
- SET_DIR_WRITE(board->private_data);
+ gpiod_direction_output(REN, 1); /* user space must enable REN if needed */
+ gpiod_direction_output(IFC, 1); /* user space must toggle IFC if needed */
+ if (sn7516x)
+ gpiod_direction_output(DC, 0); /* enable ATN as output on SN75161/2 */
+
+ gpiod_direction_input(SRQ);
+
return 0;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/8] staging: gpib: Fix setting controller-in-charge
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
2025-04-18 17:34 ` [PATCH 1/8] staging: gpib: Fix request_system_control in gpio Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 3/8] staging: gpib: Enable SRQ irq on request_system_control Dave Penkler
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
The gpio board can only act as system controller.
By the IEEE488.1 standard a system controller becomes
controller-in-charge when it asserts the interface-clear control
line.
Remove the setting of controller-in-charge from bb_take_control
and move it to bb_interface_clear.
Fixes: 4cd654f84769 ("staging: gpib: Add gpio bitbang GPIB driver")
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index 29aab72c1f0f..a92c4eda99a0 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -872,7 +872,6 @@ static int bb_take_control(struct gpib_board *board, int synchronous)
{
dbg_printk(2, "%d\n", synchronous);
set_atn(board, 1);
- set_bit(CIC_NUM, &board->status);
return 0;
}
@@ -908,6 +907,7 @@ static void bb_interface_clear(struct gpib_board *board, int assert)
gpiod_direction_output(IFC, 0);
priv->talker_state = talker_idle;
priv->listener_state = listener_idle;
+ set_bit(CIC_NUM, &board->status);
} else {
gpiod_direction_output(IFC, 1);
}
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/8] staging: gpib: Enable SRQ irq on request_system_control
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
2025-04-18 17:34 ` [PATCH 1/8] staging: gpib: Fix request_system_control in gpio Dave Penkler
2025-04-18 17:34 ` [PATCH 2/8] staging: gpib: Fix setting controller-in-charge Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 4/8] staging: gpib: Remove dependency on LED subsystem Dave Penkler
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
The SRQ irq was being enabled on attach but the board is not
set up to handle it until it becomes system controller.
Move the enabling of the SRQ irq to bb_request_system_control.
Fixes: 4cd654f84769 ("staging: gpib: Add gpio bitbang GPIB driver")
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index a92c4eda99a0..ac9ecb6e0aad 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -884,6 +884,8 @@ static int bb_go_to_standby(struct gpib_board *board)
static int bb_request_system_control(struct gpib_board *board, int request_control)
{
+ struct bb_priv *priv = board->private_data;
+
dbg_printk(2, "%d\n", request_control);
if (!request_control)
return -EINVAL;
@@ -895,6 +897,8 @@ static int bb_request_system_control(struct gpib_board *board, int request_contr
gpiod_direction_input(SRQ);
+ ENABLE_IRQ(priv->irq_SRQ, IRQ_TYPE_EDGE_FALLING);
+
return 0;
}
@@ -1299,8 +1303,6 @@ static int bb_attach(struct gpib_board *board, const struct gpib_board_config *c
IRQF_TRIGGER_NONE))
goto bb_attach_fail_r;
- ENABLE_IRQ(priv->irq_SRQ, IRQ_TYPE_EDGE_FALLING);
-
dbg_printk(0, "attached board %d\n", board->minor);
goto bb_attach_out;
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/8] staging: gpib: Remove dependency on LED subsystem
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
` (2 preceding siblings ...)
2025-04-18 17:34 ` [PATCH 3/8] staging: gpib: Enable SRQ irq on request_system_control Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 5/8] staging: gpib: Remove atn_asserted global variable Dave Penkler
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
The yoga pin map is compatible with the others so that its led
can be used as the activity led. Using the LED subsytem required
adding a dtoverlay to the boot config as well as setting up the
activity led via sysfs. To simplify the setup we remove the
dependency on the LED subsystem and use the on board led as for
the other pin maps.
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index ac9ecb6e0aad..caa8361da696 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -66,7 +66,6 @@
#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);
@@ -136,19 +135,14 @@ enum lines_t {
#define SN7516X_PINS 4
#define NUM_PINS (GPIB_PINS + SN7516X_PINS)
-DEFINE_LED_TRIGGER(ledtrig_gpib);
-#define ACT_LED_ON do { \
+#define ACT_LED_ON do { \
if (ACT_LED) \
- gpiod_direction_output(ACT_LED, 1); \
- else \
- led_trigger_event(ledtrig_gpib, LED_FULL); } \
- while (0)
-#define ACT_LED_OFF do { \
+ gpiod_direction_output(ACT_LED, 1); \
+ } while (0)
+#define ACT_LED_OFF do { \
if (ACT_LED) \
- gpiod_direction_output(ACT_LED, 0); \
- else \
- led_trigger_event(ledtrig_gpib, LED_OFF); } \
- while (0)
+ gpiod_direction_output(ACT_LED, 0); \
+ } while (0)
static struct gpio_desc *all_descriptors[GPIB_PINS + SN7516X_PINS];
@@ -1180,8 +1174,6 @@ static int allocate_gpios(struct gpib_board *board)
}
if (lookup_table)
gpiod_remove_lookup_table(lookup_table);
- // Initialize LED trigger
- led_trigger_register_simple("gpib", &ledtrig_gpib);
return retval;
}
@@ -1193,8 +1185,6 @@ static void bb_detach(struct gpib_board *board)
if (!board->private_data)
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");
@@ -1254,7 +1244,6 @@ static int bb_attach(struct gpib_board *board, const struct gpib_board_config *c
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 {
dev_err(board->gpib_dev, "Unrecognized pin map %s\n", pin_map);
goto bb_attach_fail;
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/8] staging: gpib: Remove atn_asserted global variable
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
` (3 preceding siblings ...)
2025-04-18 17:34 ` [PATCH 4/8] staging: gpib: Remove dependency on LED subsystem Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 6/8] staging: gpib: Change error code for no listener Dave Penkler
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
atn_asserted was introduced to deal with an issue where certain models
of the Raspberry Pi would lose interrupts under heavy load. Using
a combination of edge and level interrupts the problem was resolved
so the work-around is no longer needed.
This patch removes the work-around.
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index caa8361da696..1d650cb57cd2 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -306,7 +306,6 @@ struct bb_priv {
int dav_seq;
long all_irqs;
int dav_idle;
- int atn_asserted;
enum talker_function_state talker_state;
enum listener_function_state listener_state;
@@ -614,7 +613,8 @@ static irqreturn_t bb_NRFD_interrupt(int irq, void *arg)
goto nrfd_exit;
}
- if (priv->atn_asserted && priv->w_cnt >= priv->length) { // test for end of transfer
+ if (priv->w_cnt >= priv->length) { // test for missed NDAC end of transfer
+ dev_err(board->gpib_dev, "Unexpected NRFD exit\n");
priv->write_done = 1;
priv->w_busy = 0;
wake_up_interruptible(&board->wait);
@@ -686,14 +686,14 @@ static irqreturn_t bb_NDAC_interrupt(int irq, void *arg)
dbg_printk(3, "accepted %zu\n", priv->w_cnt - 1);
- if (!priv->atn_asserted && priv->w_cnt >= priv->length) { // test for end of transfer
+ gpiod_set_value(DAV, 1); // Data not available
+ priv->dav_tx = 1;
+ priv->phase = 510;
+
+ if (priv->w_cnt >= priv->length) { // test for end of transfer
priv->write_done = 1;
priv->w_busy = 0;
wake_up_interruptible(&board->wait);
- } else {
- gpiod_set_value(DAV, 1); // Data not available
- priv->dav_tx = 1;
- priv->phase = 510;
}
ndac_exit:
@@ -850,6 +850,7 @@ static void set_atn(struct gpib_board *board, int atn_asserted)
priv->listener_state = listener_addressed;
if (priv->talker_state == talker_active)
priv->talker_state = talker_addressed;
+ SET_DIR_WRITE(priv); // need to be able to read bus NRFD/NDAC
} else {
if (priv->listener_state == listener_addressed) {
priv->listener_state = listener_active;
@@ -859,7 +860,6 @@ static void set_atn(struct gpib_board *board, int atn_asserted)
priv->talker_state = talker_active;
}
gpiod_direction_output(_ATN, !atn_asserted);
- priv->atn_asserted = atn_asserted;
}
static int bb_take_control(struct gpib_board *board, int synchronous)
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 6/8] staging: gpib: Change error code for no listener
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
` (4 preceding siblings ...)
2025-04-18 17:34 ` [PATCH 5/8] staging: gpib: Remove atn_asserted global variable Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 7/8] staging: gpib: Cleanup allocate_gpios code Dave Penkler
2025-04-18 17:34 ` [PATCH 8/8] staging: gpib: Set control lines in attach Dave Penkler
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
When doing a write a test is made to see whether there are any
listeners. The code was returning ENODEV which is incorrect.
The user library translates ENOTCONN to a user level no listener
error code.
Change the error code to ENOTCONN.
Fixes: 4cd654f84769 ("staging: gpib: Add gpio bitbang GPIB driver")
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index 1d650cb57cd2..86b98eb1ce69 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -516,7 +516,7 @@ static int bb_write(struct gpib_board *board, u8 *buffer, size_t length,
gpiod_get_value(NRFD), gpiod_get_value(NDAC));
if (gpiod_get_value(NRFD) && gpiod_get_value(NDAC)) { /* check for listener */
- retval = -ENODEV;
+ retval = -ENOTCONN;
goto write_end;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 7/8] staging: gpib: Cleanup allocate_gpios code
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
` (5 preceding siblings ...)
2025-04-18 17:34 ` [PATCH 6/8] staging: gpib: Change error code for no listener Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
2025-04-18 17:34 ` [PATCH 8/8] staging: gpib: Set control lines in attach Dave Penkler
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
The function was using unnecessary variables error and retval.
Simplify the code by testing for failure first and remove the
redundant variables.
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 39 +++++++++++-------------
1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index 86b98eb1ce69..5c134cfb6d61 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -1123,8 +1123,7 @@ static void release_gpios(void)
static int allocate_gpios(struct gpib_board *board)
{
- int j, retval = 0;
- bool error = false;
+ int j;
int table_index = 0;
char name[256];
struct gpio_desc *desc;
@@ -1135,8 +1134,8 @@ static int allocate_gpios(struct gpib_board *board)
return -ENOENT;
}
- lookup_table = lookup_tables[0];
- lookup_table->dev_id = dev_name(board->gpib_dev);
+ lookup_table = lookup_tables[table_index];
+ lookup_table->dev_id = dev_name(board->gpib_dev);
gpiod_add_lookup_table(lookup_table);
dbg_printk(1, "Allocating gpios using table index %d\n", table_index);
@@ -1153,28 +1152,26 @@ static int allocate_gpios(struct gpib_board *board)
gpiod_remove_lookup_table(lookup_table);
table_index++;
lookup_table = lookup_tables[table_index];
- if (lookup_table) {
- dbg_printk(1, "Allocation failed, now using table_index %d\n",
- table_index);
- lookup_table->dev_id = dev_name(board->gpib_dev);
- gpiod_add_lookup_table(lookup_table);
- goto try_again;
+ if (!lookup_table) {
+ dev_err(board->gpib_dev, "Unable to obtain gpio descriptor for pin %d error %ld\n",
+ gpios_vector[j], PTR_ERR(desc));
+ goto alloc_gpios_fail;
}
- dev_err(board->gpib_dev, "Unable to obtain gpio descriptor for pin %d error %ld\n",
- gpios_vector[j], PTR_ERR(desc));
- error = true;
- break;
+ dbg_printk(1, "Allocation failed, now using table_index %d\n", table_index);
+ lookup_table->dev_id = dev_name(board->gpib_dev);
+ gpiod_add_lookup_table(lookup_table);
+ goto try_again;
}
all_descriptors[j] = desc;
}
- if (error) { /* undo what already done */
- release_gpios();
- retval = -1;
- }
- if (lookup_table)
- gpiod_remove_lookup_table(lookup_table);
- return retval;
+ gpiod_remove_lookup_table(lookup_table);
+
+ return 0;
+
+alloc_gpios_fail:
+ release_gpios();
+ return -1;
}
static void bb_detach(struct gpib_board *board)
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 8/8] staging: gpib: Set control lines in attach
2025-04-18 17:34 [PATCH 0/8] staging: gpib: Fixes and cleanup for gpio driver Dave Penkler
` (6 preceding siblings ...)
2025-04-18 17:34 ` [PATCH 7/8] staging: gpib: Cleanup allocate_gpios code Dave Penkler
@ 2025-04-18 17:34 ` Dave Penkler
7 siblings, 0 replies; 9+ messages in thread
From: Dave Penkler @ 2025-04-18 17:34 UTC (permalink / raw)
To: gregkh, linux-staging, linux-kernel; +Cc: marcello.carla, Dave Penkler
When the driver is attached the state of the main control lines
is not defined and can lead to hangs. Set the control lines to
a known state (logic false).
Fixes: 4cd654f84769 ("staging: gpib: Add gpio bitbang GPIB driver")
Tested-by: Dave Penkler <dpenkler@gmail.com>
Signed-off-by: Dave Penkler <dpenkler@gmail.com>
---
drivers/staging/gpib/gpio/gpib_bitbang.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/staging/gpib/gpio/gpib_bitbang.c b/drivers/staging/gpib/gpio/gpib_bitbang.c
index 5c134cfb6d61..625fef24a0bf 100644
--- a/drivers/staging/gpib/gpio/gpib_bitbang.c
+++ b/drivers/staging/gpib/gpio/gpib_bitbang.c
@@ -1262,6 +1262,10 @@ static int bb_attach(struct gpib_board *board, const struct gpib_board_config *c
gpiod_direction_output(TE, 1);
gpiod_direction_output(PE, 1);
}
+/* Set main control lines to a known state */
+ gpiod_direction_output(IFC, 1);
+ gpiod_direction_output(REN, 1);
+ gpiod_direction_output(_ATN, 1);
if (strcmp(PINMAP_2, pin_map) == 0) { /* YOGA: enable level shifters */
gpiod_direction_output(YOGA_ENABLE, 1);
--
2.49.0
^ permalink raw reply related [flat|nested] 9+ messages in thread