Skip to content

Commit d19d2de

Browse files
981213brgl
authored andcommitted
gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
Some gpio controllers ignores pin value writing when that pin is configured as input mode. As a result, bgpio_dir_out should set pin to output before configuring pin values or gpio pin values can't be set up properly. Introduce two variants of bgpio_dir_out: bgpio_dir_out_val_first and bgpio_dir_out_dir_first, and assign direction_output according to a new flag: BGPIOF_NO_SET_ON_INPUT. Signed-off-by: Chuanhong Guo <gch981213@gmail.com> Tested-by: René van Dorst <opensource@vdorst.com> Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
1 parent d1ee7e1 commit d19d2de

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎drivers/gpio/gpio-mmio.c‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,10 @@ static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
389389
return GPIO_LINE_DIRECTION_IN;
390390
}
391391

392-
static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
392+
static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
393393
{
394394
unsigned long flags;
395395

396-
gc->set(gc, gpio, val);
397-
398396
spin_lock_irqsave(&gc->bgpio_lock, flags);
399397

400398
gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
@@ -405,7 +403,21 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
405403
gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
406404

407405
spin_unlock_irqrestore(&gc->bgpio_lock, flags);
406+
}
408407

408+
static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio,
409+
int val)
410+
{
411+
bgpio_dir_out(gc, gpio, val);
412+
gc->set(gc, gpio, val);
413+
return 0;
414+
}
415+
416+
static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
417+
int val)
418+
{
419+
gc->set(gc, gpio, val);
420+
bgpio_dir_out(gc, gpio, val);
409421
return 0;
410422
}
411423

@@ -538,7 +550,10 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
538550
if (dirout || dirin) {
539551
gc->reg_dir_out = dirout;
540552
gc->reg_dir_in = dirin;
541-
gc->direction_output = bgpio_dir_out;
553+
if (flags & BGPIOF_NO_SET_ON_INPUT)
554+
gc->direction_output = bgpio_dir_out_dir_first;
555+
else
556+
gc->direction_output = bgpio_dir_out_val_first;
542557
gc->direction_input = bgpio_dir_in;
543558
gc->get_direction = bgpio_get_dir;
544559
} else {

‎include/linux/gpio/driver.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
572572
#define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
573573
#define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
574574
#define BGPIOF_NO_OUTPUT BIT(5) /* only input */
575+
#define BGPIOF_NO_SET_ON_INPUT BIT(6)
575576

576577
int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
577578
irq_hw_number_t hwirq);

0 commit comments

Comments
 (0)