Skip to content

Commit

Permalink
gpio: Use new GPIO_LINE_DIRECTION
Browse files Browse the repository at this point in the history
It's hard for occasional GPIO code reader/writer to know if values 0/1
equal to IN or OUT. Use defined GPIO_LINE_DIRECTION_IN and
GPIO_LINE_DIRECTION_OUT to help them out.

NOTE - for gpio-amd-fch and gpio-bd9571mwv:
This commit also changes the return value for direction get to equal 1
for direction INPUT. Prior this commit these drivers might have
returned some other positive value but 1 for INPUT.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Acked-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Matti Vaittinen authored and Linus Walleij committed Nov 7, 2019
1 parent 9208b1e commit e42615e
Show file tree
Hide file tree
Showing 60 changed files with 211 additions and 102 deletions.
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-104-dio-48e.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ static int dio48e_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
const unsigned port = offset / 8;
const unsigned mask = BIT(offset % 8);

return !!(dio48egpio->io_state[port] & mask);
if (dio48egpio->io_state[port] & mask)
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-104-idi-48.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct idi_48_gpio {

static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{
return 1;
return GPIO_LINE_DIRECTION_IN;
}

static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-104-idio-16.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ struct idio_16_gpio {
static int idio_16_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
{
if (offset > 15)
return 1;
return GPIO_LINE_DIRECTION_IN;

return 0;
return GPIO_LINE_DIRECTION_OUT;
}

static int idio_16_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-74xx-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ static int mmio_74xx_get_direction(struct gpio_chip *gc, unsigned offset)
{
struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc);

return !(priv->flags & MMIO_74XX_DIR_OUT);
if (priv->flags & MMIO_74XX_DIR_OUT)
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-amd-fch.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int amd_fch_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio)
ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_DIRECTION);
spin_unlock_irqrestore(&priv->lock, flags);

return ret;
return ret ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
}

static void amd_fch_gpio_set(struct gpio_chip *gc,
Expand Down
7 changes: 3 additions & 4 deletions drivers/gpio/gpio-aspeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,18 @@ static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
u32 val;

if (!have_input(gpio, offset))
return 0;
return GPIO_LINE_DIRECTION_OUT;

if (!have_output(gpio, offset))
return 1;
return GPIO_LINE_DIRECTION_IN;

spin_lock_irqsave(&gpio->lock, flags);

val = ioread32(bank_reg(gpio, bank, reg_dir)) & GPIO_BIT(offset);

spin_unlock_irqrestore(&gpio->lock, flags);

return !val;

return val ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
}

static inline int irqd_to_aspeed_gpio_data(struct irq_data *d,
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/gpio-bcm-kona.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static int bcm_kona_gpio_get_dir(struct gpio_chip *chip, unsigned gpio)
u32 val;

val = readl(reg_base + GPIO_CONTROL(gpio)) & GPIO_GPCTR0_IOTR_MASK;
return !!val;
return val ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
}

static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
Expand All @@ -144,7 +144,7 @@ static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
raw_spin_lock_irqsave(&kona_gpio->lock, flags);

/* this function only applies to output pin */
if (bcm_kona_gpio_get_dir(chip, gpio) == 1)
if (bcm_kona_gpio_get_dir(chip, gpio) == GPIO_LINE_DIRECTION_IN)
goto out;

reg_offset = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id);
Expand All @@ -170,7 +170,7 @@ static int bcm_kona_gpio_get(struct gpio_chip *chip, unsigned gpio)
reg_base = kona_gpio->reg_base;
raw_spin_lock_irqsave(&kona_gpio->lock, flags);

if (bcm_kona_gpio_get_dir(chip, gpio) == 1)
if (bcm_kona_gpio_get_dir(chip, gpio) == GPIO_LINE_DIRECTION_IN)
reg_offset = GPIO_IN_STATUS(bank_id);
else
reg_offset = GPIO_OUT_STATUS(bank_id);
Expand Down
8 changes: 5 additions & 3 deletions drivers/gpio/gpio-bd70528.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
dev_err(bdgpio->chip.dev, "Could not read gpio direction\n");
return ret;
}
if (val & BD70528_GPIO_OUT_EN_MASK)
return GPIO_LINE_DIRECTION_OUT;

return !(val & BD70528_GPIO_OUT_EN_MASK);
return GPIO_LINE_DIRECTION_IN;
}

static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
Expand Down Expand Up @@ -166,9 +168,9 @@ static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset)
* locking would make no sense.
*/
ret = bd70528_get_direction(chip, offset);
if (ret == 0)
if (ret == GPIO_LINE_DIRECTION_OUT)
ret = bd70528_gpio_get_o(bdgpio, offset);
else if (ret == 1)
else if (ret == GPIO_LINE_DIRECTION_IN)
ret = bd70528_gpio_get_i(bdgpio, offset);
else
dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n");
Expand Down
4 changes: 3 additions & 1 deletion drivers/gpio/gpio-bd9571mwv.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, &val);
if (ret < 0)
return ret;
if (val & BIT(offset))
return GPIO_LINE_DIRECTION_IN;

return val & BIT(offset);
return GPIO_LINE_DIRECTION_OUT;
}

static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip,
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/gpio-dln2.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
struct dln2_gpio *dln2 = gpiochip_get_data(chip);

if (test_bit(offset, dln2->output_enabled))
return 0;
return GPIO_LINE_DIRECTION_OUT;

return 1;
return GPIO_LINE_DIRECTION_IN;
}

static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
Expand All @@ -214,7 +214,7 @@ static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
if (dir < 0)
return dir;

if (dir == 1)
if (dir == GPIO_LINE_DIRECTION_IN)
return dln2_gpio_pin_get_in_val(dln2, offset);

return dln2_gpio_pin_get_out_val(dln2, offset);
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-exar.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO;
unsigned int bit = (offset + exar_gpio->first_pin) % 8;

return !!(exar_get(chip, addr) & BIT(bit));
if (exar_get(chip, addr) & BIT(bit))
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-f7188x.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset)

superio_exit(sio->addr);

return !(dir & 1 << offset);
if (dir & 1 << offset)
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-gpio-mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ static int gpiomm_gpio_get_direction(struct gpio_chip *chip,
const unsigned int port = offset / 8;
const unsigned int mask = BIT(offset % 8);

return !!(gpiommgpio->io_state[port] & mask);
if (gpiommgpio->io_state[port] & mask)
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int gpiomm_gpio_direction_input(struct gpio_chip *chip,
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-htc-egpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ static int egpio_get_direction(struct gpio_chip *chip, unsigned offset)

egpio = gpiochip_get_data(chip);

return !test_bit(offset, &egpio->is_out);
if (test_bit(offset, &egpio->is_out))
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static void egpio_write_cache(struct egpio_info *ei)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-ich.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ static bool ichx_gpio_check_available(struct gpio_chip *gpio, unsigned nr)

static int ichx_gpio_get_direction(struct gpio_chip *gpio, unsigned nr)
{
return ichx_read_bit(GPIO_IO_SEL, nr);
if (ichx_read_bit(GPIO_IO_SEL, nr))
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-kempld.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ static int kempld_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;

return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset);
if (kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset))
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static int kempld_gpio_pincount(struct kempld_device_data *pld)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-lp873x.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int lp873x_gpio_get_direction(struct gpio_chip *chip,
unsigned int offset)
{
/* This device is output only */
return 0;
return GPIO_LINE_DIRECTION_OUT;
}

static int lp873x_gpio_direction_input(struct gpio_chip *chip,
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-lp87565.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ static int lp87565_gpio_get_direction(struct gpio_chip *chip,
if (ret < 0)
return ret;

return !(val & BIT(offset));
if (val & BIT(offset))
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static int lp87565_gpio_direction_input(struct gpio_chip *chip,
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-madera.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ static int madera_gpio_get_direction(struct gpio_chip *chip,
if (ret < 0)
return ret;

return !!(val & MADERA_GP1_DIR_MASK);
if (val & MADERA_GP1_DIR_MASK)
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int madera_gpio_direction_in(struct gpio_chip *chip, unsigned int offset)
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-max3191x.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ DECLARE_CRC8_TABLE(max3191x_crc8);

static int max3191x_get_direction(struct gpio_chip *gpio, unsigned int offset)
{
return 1; /* always in */
return GPIO_LINE_DIRECTION_IN; /* always in */
}

static int max3191x_direction_input(struct gpio_chip *gpio, unsigned int offset)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-merrifield.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ static int mrfld_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
{
void __iomem *gpdr = gpio_reg(chip, offset, GPDR);

return !(readl(gpdr) & BIT(offset % 32));
if (readl(gpdr) & BIT(offset % 32))
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static int mrfld_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
Expand Down
21 changes: 15 additions & 6 deletions drivers/gpio/gpio-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,24 @@ static int bgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
{
/* Return 0 if output, 1 if input */
if (gc->bgpio_dir_unreadable)
return !(gc->bgpio_dir & bgpio_line2mask(gc, gpio));
if (gc->reg_dir_out)
return !(gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio));
if (gc->bgpio_dir_unreadable) {
if (gc->bgpio_dir & bgpio_line2mask(gc, gpio))
return GPIO_LINE_DIRECTION_OUT;
return GPIO_LINE_DIRECTION_IN;
}

if (gc->reg_dir_out) {
if (gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio))
return GPIO_LINE_DIRECTION_OUT;
return GPIO_LINE_DIRECTION_IN;
}

if (gc->reg_dir_in)
return !!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio));
if (!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio)))
return GPIO_LINE_DIRECTION_OUT;

/* This should not happen */
return 1;
return GPIO_LINE_DIRECTION_IN;
}

static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
Expand Down
11 changes: 3 additions & 8 deletions drivers/gpio/gpio-mockup.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@

#define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__)

enum {
GPIO_MOCKUP_DIR_IN = 0,
GPIO_MOCKUP_DIR_OUT = 1,
};

/*
* struct gpio_pin_status - structure describing a GPIO status
* @dir: Configures direction of gpio as "in" or "out", 0=in, 1=out
* @dir: Configures direction of gpio as "in" or "out"
* @value: Configures status of the gpio as 0(low) or 1(high)
*/
struct gpio_mockup_line_status {
Expand Down Expand Up @@ -152,7 +147,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc,
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);

mutex_lock(&chip->lock);
chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT;
chip->lines[offset].dir = GPIO_LINE_DIRECTION_OUT;
__gpio_mockup_set(chip, offset, value);
mutex_unlock(&chip->lock);

Expand All @@ -164,7 +159,7 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset)
struct gpio_mockup_chip *chip = gpiochip_get_data(gc);

mutex_lock(&chip->lock);
chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN;
chip->lines[offset].dir = GPIO_LINE_DIRECTION_IN;
mutex_unlock(&chip->lock);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/gpio-moxtet.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ static int moxtet_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)

/* All lines are hard wired to be either input or output, not both. */
if (chip->desc->in_mask & BIT(offset))
return 1;
return GPIO_LINE_DIRECTION_IN;
else if (chip->desc->out_mask & BIT(offset))
return 0;
return GPIO_LINE_DIRECTION_OUT;
else
return -EINVAL;
}
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ static int mvebu_gpio_get_direction(struct gpio_chip *chip, unsigned int pin)

regmap_read(mvchip->regs, GPIO_IO_CONF_OFF + mvchip->offset, &u);

return !!(u & BIT(pin));
if (u & BIT(pin))
return GPIO_LINE_DIRECTION_IN;

return GPIO_LINE_DIRECTION_OUT;
}

static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned int pin)
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/gpio-mxs.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ static int mxs_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
u32 dir;

dir = readl(port->base + PINCTRL_DOE(port));
return !(dir & mask);
if (dir & mask)
return GPIO_LINE_DIRECTION_OUT;

return GPIO_LINE_DIRECTION_IN;
}

static const struct platform_device_id mxs_gpio_ids[] = {
Expand Down
Loading

0 comments on commit e42615e

Please sign in to comment.