mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
gpio: Use new GPIO_LINE_DIRECTION
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>
This commit is contained in:
committed by
Linus Walleij
parent
9208b1e77d
commit
e42615ec23
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -487,10 +487,10 @@ 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);
|
||||
|
||||
@@ -498,8 +498,7 @@ static int aspeed_gpio_get_direction(struct gpio_chip *gc, unsigned int 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,
|
||||
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user