Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Matti Vaittinen and committed by
Linus Walleij
e42615ec 9208b1e7

+211 -102
+4 -1
drivers/gpio/gpio-104-dio-48e.c
··· 59 59 const unsigned port = offset / 8; 60 60 const unsigned mask = BIT(offset % 8); 61 61 62 - return !!(dio48egpio->io_state[port] & mask); 62 + if (dio48egpio->io_state[port] & mask) 63 + return GPIO_LINE_DIRECTION_IN; 64 + 65 + return GPIO_LINE_DIRECTION_OUT; 63 66 } 64 67 65 68 static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+1 -1
drivers/gpio/gpio-104-idi-48.c
··· 53 53 54 54 static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 55 55 { 56 - return 1; 56 + return GPIO_LINE_DIRECTION_IN; 57 57 } 58 58 59 59 static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+2 -2
drivers/gpio/gpio-104-idio-16.c
··· 51 51 static int idio_16_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 52 52 { 53 53 if (offset > 15) 54 - return 1; 54 + return GPIO_LINE_DIRECTION_IN; 55 55 56 - return 0; 56 + return GPIO_LINE_DIRECTION_OUT; 57 57 } 58 58 59 59 static int idio_16_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+4 -1
drivers/gpio/gpio-74xx-mmio.c
··· 77 77 { 78 78 struct mmio_74xx_gpio_priv *priv = gpiochip_get_data(gc); 79 79 80 - return !(priv->flags & MMIO_74XX_DIR_OUT); 80 + if (priv->flags & MMIO_74XX_DIR_OUT) 81 + return GPIO_LINE_DIRECTION_OUT; 82 + 83 + return GPIO_LINE_DIRECTION_IN; 81 84 } 82 85 83 86 static int mmio_74xx_dir_in(struct gpio_chip *gc, unsigned int gpio)
+1 -1
drivers/gpio/gpio-amd-fch.c
··· 92 92 ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_DIRECTION); 93 93 spin_unlock_irqrestore(&priv->lock, flags); 94 94 95 - return ret; 95 + return ret ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT; 96 96 } 97 97 98 98 static void amd_fch_gpio_set(struct gpio_chip *gc,
+3 -4
drivers/gpio/gpio-aspeed.c
··· 487 487 u32 val; 488 488 489 489 if (!have_input(gpio, offset)) 490 - return 0; 490 + return GPIO_LINE_DIRECTION_OUT; 491 491 492 492 if (!have_output(gpio, offset)) 493 - return 1; 493 + return GPIO_LINE_DIRECTION_IN; 494 494 495 495 spin_lock_irqsave(&gpio->lock, flags); 496 496 ··· 498 498 499 499 spin_unlock_irqrestore(&gpio->lock, flags); 500 500 501 - return !val; 502 - 501 + return val ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; 503 502 } 504 503 505 504 static inline int irqd_to_aspeed_gpio_data(struct irq_data *d,
+3 -3
drivers/gpio/gpio-bcm-kona.c
··· 127 127 u32 val; 128 128 129 129 val = readl(reg_base + GPIO_CONTROL(gpio)) & GPIO_GPCTR0_IOTR_MASK; 130 - return !!val; 130 + return val ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT; 131 131 } 132 132 133 133 static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) ··· 144 144 raw_spin_lock_irqsave(&kona_gpio->lock, flags); 145 145 146 146 /* this function only applies to output pin */ 147 - if (bcm_kona_gpio_get_dir(chip, gpio) == 1) 147 + if (bcm_kona_gpio_get_dir(chip, gpio) == GPIO_LINE_DIRECTION_IN) 148 148 goto out; 149 149 150 150 reg_offset = value ? GPIO_OUT_SET(bank_id) : GPIO_OUT_CLEAR(bank_id); ··· 170 170 reg_base = kona_gpio->reg_base; 171 171 raw_spin_lock_irqsave(&kona_gpio->lock, flags); 172 172 173 - if (bcm_kona_gpio_get_dir(chip, gpio) == 1) 173 + if (bcm_kona_gpio_get_dir(chip, gpio) == GPIO_LINE_DIRECTION_IN) 174 174 reg_offset = GPIO_IN_STATUS(bank_id); 175 175 else 176 176 reg_offset = GPIO_OUT_STATUS(bank_id);
+5 -3
drivers/gpio/gpio-bd70528.c
··· 54 54 dev_err(bdgpio->chip.dev, "Could not read gpio direction\n"); 55 55 return ret; 56 56 } 57 + if (val & BD70528_GPIO_OUT_EN_MASK) 58 + return GPIO_LINE_DIRECTION_OUT; 57 59 58 - return !(val & BD70528_GPIO_OUT_EN_MASK); 60 + return GPIO_LINE_DIRECTION_IN; 59 61 } 60 62 61 63 static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset, ··· 168 166 * locking would make no sense. 169 167 */ 170 168 ret = bd70528_get_direction(chip, offset); 171 - if (ret == 0) 169 + if (ret == GPIO_LINE_DIRECTION_OUT) 172 170 ret = bd70528_gpio_get_o(bdgpio, offset); 173 - else if (ret == 1) 171 + else if (ret == GPIO_LINE_DIRECTION_IN) 174 172 ret = bd70528_gpio_get_i(bdgpio, offset); 175 173 else 176 174 dev_err(bdgpio->chip.dev, "failed to read GPIO direction\n");
+3 -1
drivers/gpio/gpio-bd9571mwv.c
··· 37 37 ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, &val); 38 38 if (ret < 0) 39 39 return ret; 40 + if (val & BIT(offset)) 41 + return GPIO_LINE_DIRECTION_IN; 40 42 41 - return val & BIT(offset); 43 + return GPIO_LINE_DIRECTION_OUT; 42 44 } 43 45 44 46 static int bd9571mwv_gpio_direction_input(struct gpio_chip *chip,
+3 -3
drivers/gpio/gpio-dln2.c
··· 200 200 struct dln2_gpio *dln2 = gpiochip_get_data(chip); 201 201 202 202 if (test_bit(offset, dln2->output_enabled)) 203 - return 0; 203 + return GPIO_LINE_DIRECTION_OUT; 204 204 205 - return 1; 205 + return GPIO_LINE_DIRECTION_IN; 206 206 } 207 207 208 208 static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset) ··· 214 214 if (dir < 0) 215 215 return dir; 216 216 217 - if (dir == 1) 217 + if (dir == GPIO_LINE_DIRECTION_IN) 218 218 return dln2_gpio_pin_get_in_val(dln2, offset); 219 219 220 220 return dln2_gpio_pin_get_out_val(dln2, offset);
+4 -1
drivers/gpio/gpio-exar.c
··· 77 77 EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; 78 78 unsigned int bit = (offset + exar_gpio->first_pin) % 8; 79 79 80 - return !!(exar_get(chip, addr) & BIT(bit)); 80 + if (exar_get(chip, addr) & BIT(bit)) 81 + return GPIO_LINE_DIRECTION_IN; 82 + 83 + return GPIO_LINE_DIRECTION_OUT; 81 84 } 82 85 83 86 static int exar_get_value(struct gpio_chip *chip, unsigned int offset)
+4 -1
drivers/gpio/gpio-f7188x.c
··· 250 250 251 251 superio_exit(sio->addr); 252 252 253 - return !(dir & 1 << offset); 253 + if (dir & 1 << offset) 254 + return GPIO_LINE_DIRECTION_OUT; 255 + 256 + return GPIO_LINE_DIRECTION_IN; 254 257 } 255 258 256 259 static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
+4 -1
drivers/gpio/gpio-gpio-mm.c
··· 52 52 const unsigned int port = offset / 8; 53 53 const unsigned int mask = BIT(offset % 8); 54 54 55 - return !!(gpiommgpio->io_state[port] & mask); 55 + if (gpiommgpio->io_state[port] & mask) 56 + return GPIO_LINE_DIRECTION_IN; 57 + 58 + return GPIO_LINE_DIRECTION_OUT; 56 59 } 57 60 58 61 static int gpiomm_gpio_direction_input(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-htc-egpio.c
··· 220 220 221 221 egpio = gpiochip_get_data(chip); 222 222 223 - return !test_bit(offset, &egpio->is_out); 223 + if (test_bit(offset, &egpio->is_out)) 224 + return GPIO_LINE_DIRECTION_OUT; 225 + 226 + return GPIO_LINE_DIRECTION_IN; 224 227 } 225 228 226 229 static void egpio_write_cache(struct egpio_info *ei)
+4 -1
drivers/gpio/gpio-ich.c
··· 159 159 160 160 static int ichx_gpio_get_direction(struct gpio_chip *gpio, unsigned nr) 161 161 { 162 - return ichx_read_bit(GPIO_IO_SEL, nr); 162 + if (ichx_read_bit(GPIO_IO_SEL, nr)) 163 + return GPIO_LINE_DIRECTION_IN; 164 + 165 + return GPIO_LINE_DIRECTION_OUT; 163 166 } 164 167 165 168 static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
+4 -1
drivers/gpio/gpio-kempld.c
··· 104 104 struct kempld_gpio_data *gpio = gpiochip_get_data(chip); 105 105 struct kempld_device_data *pld = gpio->pld; 106 106 107 - return !kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset); 107 + if (kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset)) 108 + return GPIO_LINE_DIRECTION_OUT; 109 + 110 + return GPIO_LINE_DIRECTION_IN; 108 111 } 109 112 110 113 static int kempld_gpio_pincount(struct kempld_device_data *pld)
+1 -1
drivers/gpio/gpio-lp873x.c
··· 33 33 unsigned int offset) 34 34 { 35 35 /* This device is output only */ 36 - return 0; 36 + return GPIO_LINE_DIRECTION_OUT; 37 37 } 38 38 39 39 static int lp873x_gpio_direction_input(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-lp87565.c
··· 57 57 if (ret < 0) 58 58 return ret; 59 59 60 - return !(val & BIT(offset)); 60 + if (val & BIT(offset)) 61 + return GPIO_LINE_DIRECTION_OUT; 62 + 63 + return GPIO_LINE_DIRECTION_IN; 61 64 } 62 65 63 66 static int lp87565_gpio_direction_input(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-madera.c
··· 34 34 if (ret < 0) 35 35 return ret; 36 36 37 - return !!(val & MADERA_GP1_DIR_MASK); 37 + if (val & MADERA_GP1_DIR_MASK) 38 + return GPIO_LINE_DIRECTION_IN; 39 + 40 + return GPIO_LINE_DIRECTION_OUT; 38 41 } 39 42 40 43 static int madera_gpio_direction_in(struct gpio_chip *chip, unsigned int offset)
+1 -1
drivers/gpio/gpio-max3191x.c
··· 94 94 95 95 static int max3191x_get_direction(struct gpio_chip *gpio, unsigned int offset) 96 96 { 97 - return 1; /* always in */ 97 + return GPIO_LINE_DIRECTION_IN; /* always in */ 98 98 } 99 99 100 100 static int max3191x_direction_input(struct gpio_chip *gpio, unsigned int offset)
+4 -1
drivers/gpio/gpio-merrifield.c
··· 162 162 { 163 163 void __iomem *gpdr = gpio_reg(chip, offset, GPDR); 164 164 165 - return !(readl(gpdr) & BIT(offset % 32)); 165 + if (readl(gpdr) & BIT(offset % 32)) 166 + return GPIO_LINE_DIRECTION_OUT; 167 + 168 + return GPIO_LINE_DIRECTION_IN; 166 169 } 167 170 168 171 static int mrfld_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
+15 -6
drivers/gpio/gpio-mmio.c
··· 370 370 static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio) 371 371 { 372 372 /* Return 0 if output, 1 if input */ 373 - if (gc->bgpio_dir_unreadable) 374 - return !(gc->bgpio_dir & bgpio_line2mask(gc, gpio)); 375 - if (gc->reg_dir_out) 376 - return !(gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio)); 373 + if (gc->bgpio_dir_unreadable) { 374 + if (gc->bgpio_dir & bgpio_line2mask(gc, gpio)) 375 + return GPIO_LINE_DIRECTION_OUT; 376 + return GPIO_LINE_DIRECTION_IN; 377 + } 378 + 379 + if (gc->reg_dir_out) { 380 + if (gc->read_reg(gc->reg_dir_out) & bgpio_line2mask(gc, gpio)) 381 + return GPIO_LINE_DIRECTION_OUT; 382 + return GPIO_LINE_DIRECTION_IN; 383 + } 384 + 377 385 if (gc->reg_dir_in) 378 - return !!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio)); 386 + if (!(gc->read_reg(gc->reg_dir_in) & bgpio_line2mask(gc, gpio))) 387 + return GPIO_LINE_DIRECTION_OUT; 379 388 380 389 /* This should not happen */ 381 - return 1; 390 + return GPIO_LINE_DIRECTION_IN; 382 391 } 383 392 384 393 static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+3 -8
drivers/gpio/gpio-mockup.c
··· 34 34 35 35 #define gpio_mockup_err(...) pr_err(GPIO_MOCKUP_NAME ": " __VA_ARGS__) 36 36 37 - enum { 38 - GPIO_MOCKUP_DIR_IN = 0, 39 - GPIO_MOCKUP_DIR_OUT = 1, 40 - }; 41 - 42 37 /* 43 38 * struct gpio_pin_status - structure describing a GPIO status 44 - * @dir: Configures direction of gpio as "in" or "out", 0=in, 1=out 39 + * @dir: Configures direction of gpio as "in" or "out" 45 40 * @value: Configures status of the gpio as 0(low) or 1(high) 46 41 */ 47 42 struct gpio_mockup_line_status { ··· 147 152 struct gpio_mockup_chip *chip = gpiochip_get_data(gc); 148 153 149 154 mutex_lock(&chip->lock); 150 - chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; 155 + chip->lines[offset].dir = GPIO_LINE_DIRECTION_OUT; 151 156 __gpio_mockup_set(chip, offset, value); 152 157 mutex_unlock(&chip->lock); 153 158 ··· 159 164 struct gpio_mockup_chip *chip = gpiochip_get_data(gc); 160 165 161 166 mutex_lock(&chip->lock); 162 - chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN; 167 + chip->lines[offset].dir = GPIO_LINE_DIRECTION_IN; 163 168 mutex_unlock(&chip->lock); 164 169 165 170 return 0;
+2 -2
drivers/gpio/gpio-moxtet.c
··· 78 78 79 79 /* All lines are hard wired to be either input or output, not both. */ 80 80 if (chip->desc->in_mask & BIT(offset)) 81 - return 1; 81 + return GPIO_LINE_DIRECTION_IN; 82 82 else if (chip->desc->out_mask & BIT(offset)) 83 - return 0; 83 + return GPIO_LINE_DIRECTION_OUT; 84 84 else 85 85 return -EINVAL; 86 86 }
+4 -1
drivers/gpio/gpio-mvebu.c
··· 384 384 385 385 regmap_read(mvchip->regs, GPIO_IO_CONF_OFF + mvchip->offset, &u); 386 386 387 - return !!(u & BIT(pin)); 387 + if (u & BIT(pin)) 388 + return GPIO_LINE_DIRECTION_IN; 389 + 390 + return GPIO_LINE_DIRECTION_OUT; 388 391 } 389 392 390 393 static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned int pin)
+4 -1
drivers/gpio/gpio-mxs.c
··· 248 248 u32 dir; 249 249 250 250 dir = readl(port->base + PINCTRL_DOE(port)); 251 - return !(dir & mask); 251 + if (dir & mask) 252 + return GPIO_LINE_DIRECTION_OUT; 253 + 254 + return GPIO_LINE_DIRECTION_IN; 252 255 } 253 256 254 257 static const struct platform_device_id mxs_gpio_ids[] = {
+4 -2
drivers/gpio/gpio-omap.c
··· 805 805 { 806 806 struct gpio_bank *bank = gpiochip_get_data(chip); 807 807 808 - return !!(readl_relaxed(bank->base + bank->regs->direction) & 809 - BIT(offset)); 808 + if (readl_relaxed(bank->base + bank->regs->direction) & BIT(offset)) 809 + return GPIO_LINE_DIRECTION_IN; 810 + 811 + return GPIO_LINE_DIRECTION_OUT; 810 812 } 811 813 812 814 static int omap_gpio_input(struct gpio_chip *chip, unsigned offset)
+4 -1
drivers/gpio/gpio-pca953x.c
··· 449 449 if (ret < 0) 450 450 return ret; 451 451 452 - return !!(reg_val & bit); 452 + if (reg_val & bit) 453 + return GPIO_LINE_DIRECTION_IN; 454 + 455 + return GPIO_LINE_DIRECTION_OUT; 453 456 } 454 457 455 458 static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
+2 -2
drivers/gpio/gpio-pci-idio-16.c
··· 61 61 unsigned int offset) 62 62 { 63 63 if (offset > 15) 64 - return 1; 64 + return GPIO_LINE_DIRECTION_IN; 65 65 66 - return 0; 66 + return GPIO_LINE_DIRECTION_OUT; 67 67 } 68 68 69 69 static int idio_16_gpio_direction_input(struct gpio_chip *chip,
+6 -3
drivers/gpio/gpio-pcie-idio-24.c
··· 104 104 105 105 /* FET Outputs */ 106 106 if (offset < 24) 107 - return 0; 107 + return GPIO_LINE_DIRECTION_OUT; 108 108 109 109 /* Isolated Inputs */ 110 110 if (offset < 48) 111 - return 1; 111 + return GPIO_LINE_DIRECTION_IN; 112 112 113 113 /* TTL/CMOS I/O */ 114 114 /* OUT MODE = 1 when TTL/CMOS Output Mode is set */ 115 - return !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask); 115 + if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask) 116 + return GPIO_LINE_DIRECTION_OUT; 117 + 118 + return GPIO_LINE_DIRECTION_IN; 116 119 } 117 120 118 121 static int idio_24_gpio_direction_input(struct gpio_chip *chip,
+1 -1
drivers/gpio/gpio-pisosr.c
··· 65 65 unsigned offset) 66 66 { 67 67 /* This device always input */ 68 - return 1; 68 + return GPIO_LINE_DIRECTION_IN; 69 69 } 70 70 71 71 static int pisosr_gpio_direction_input(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-pl061.c
··· 63 63 { 64 64 struct pl061 *pl061 = gpiochip_get_data(gc); 65 65 66 - return !(readb(pl061->base + GPIODIR) & BIT(offset)); 66 + if (readb(pl061->base + GPIODIR) & BIT(offset)) 67 + return GPIO_LINE_DIRECTION_OUT; 68 + 69 + return GPIO_LINE_DIRECTION_IN; 67 70 } 68 71 69 72 static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
+4 -1
drivers/gpio/gpio-raspberrypi-exp.c
··· 147 147 get.gpio); 148 148 return ret ? ret : -EIO; 149 149 } 150 - return !get.direction; 150 + if (get.direction) 151 + return GPIO_LINE_DIRECTION_OUT; 152 + 153 + return GPIO_LINE_DIRECTION_IN; 151 154 } 152 155 153 156 static int rpi_exp_gpio_get(struct gpio_chip *gc, unsigned int off)
+4 -1
drivers/gpio/gpio-rcar.c
··· 279 279 { 280 280 struct gpio_rcar_priv *p = gpiochip_get_data(chip); 281 281 282 - return !(gpio_rcar_read(p, INOUTSEL) & BIT(offset)); 282 + if (gpio_rcar_read(p, INOUTSEL) & BIT(offset)) 283 + return GPIO_LINE_DIRECTION_OUT; 284 + 285 + return GPIO_LINE_DIRECTION_IN; 283 286 } 284 287 285 288 static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
+2 -1
drivers/gpio/gpio-reg.c
··· 26 26 { 27 27 struct gpio_reg *r = to_gpio_reg(gc); 28 28 29 - return r->direction & BIT(offset) ? 1 : 0; 29 + return r->direction & BIT(offset) ? GPIO_LINE_DIRECTION_IN : 30 + GPIO_LINE_DIRECTION_OUT; 30 31 } 31 32 32 33 static int gpio_reg_direction_output(struct gpio_chip *gc, unsigned offset,
+4 -1
drivers/gpio/gpio-sa1100.c
··· 53 53 { 54 54 void __iomem *gpdr = sa1100_gpio_chip(chip)->membase + R_GPDR; 55 55 56 - return !(readl_relaxed(gpdr) & BIT(offset)); 56 + if (readl_relaxed(gpdr) & BIT(offset)) 57 + return GPIO_LINE_DIRECTION_OUT; 58 + 59 + return GPIO_LINE_DIRECTION_IN; 57 60 } 58 61 59 62 static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset)
+4 -3
drivers/gpio/gpio-sama5d2-piobu.c
··· 119 119 if (ret < 0) 120 120 return ret; 121 121 122 - return (ret == PIOBU_IN) ? 1 : 0; 122 + return (ret == PIOBU_IN) ? GPIO_LINE_DIRECTION_IN : 123 + GPIO_LINE_DIRECTION_OUT; 123 124 } 124 125 125 126 /** ··· 155 154 /* if pin is input, read value from PDS else read from SOD */ 156 155 int ret = sama5d2_piobu_get_direction(chip, pin); 157 156 158 - if (ret == 1) 157 + if (ret == GPIO_LINE_DIRECTION_IN) 159 158 ret = sama5d2_piobu_read_value(chip, pin, PIOBU_PDS); 160 - else if (!ret) 159 + else if (ret == GPIO_LINE_DIRECTION_OUT) 161 160 ret = sama5d2_piobu_read_value(chip, pin, PIOBU_SOD); 162 161 163 162 if (ret < 0)
+4 -1
drivers/gpio/gpio-sch.c
··· 127 127 { 128 128 struct sch_gpio *sch = gpiochip_get_data(gc); 129 129 130 - return sch_gpio_reg_get(sch, gpio_num, GIO); 130 + if (sch_gpio_reg_get(sch, gpio_num, GIO)) 131 + return GPIO_LINE_DIRECTION_IN; 132 + 133 + return GPIO_LINE_DIRECTION_OUT; 131 134 } 132 135 133 136 static const struct gpio_chip sch_gpio_chip = {
+4 -1
drivers/gpio/gpio-sch311x.c
··· 228 228 data = inb(block->runtime_reg + block->config_regs[offset]); 229 229 spin_unlock(&block->lock); 230 230 231 - return !!(data & SCH311X_GPIO_CONF_DIR); 231 + if (data & SCH311X_GPIO_CONF_DIR) 232 + return GPIO_LINE_DIRECTION_IN; 233 + 234 + return GPIO_LINE_DIRECTION_OUT; 232 235 } 233 236 234 237 static int sch311x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
+2 -2
drivers/gpio/gpio-siox.c
··· 203 203 static int gpio_siox_get_direction(struct gpio_chip *chip, unsigned int offset) 204 204 { 205 205 if (offset < 12) 206 - return 1; /* input */ 206 + return GPIO_LINE_DIRECTION_IN; 207 207 else 208 - return 0; /* output */ 208 + return GPIO_LINE_DIRECTION_OUT; 209 209 } 210 210 211 211 static int gpio_siox_probe(struct siox_device *sdevice)
+4 -1
drivers/gpio/gpio-stmpe.c
··· 84 84 if (ret < 0) 85 85 return ret; 86 86 87 - return !(ret & mask); 87 + if (ret & mask) 88 + return GPIO_LINE_DIRECTION_OUT; 89 + 90 + return GPIO_LINE_DIRECTION_IN; 88 91 } 89 92 90 93 static int stmpe_gpio_direction_output(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-tc3589x.c
··· 97 97 if (ret < 0) 98 98 return ret; 99 99 100 - return !(ret & BIT(pos)); 100 + if (ret & BIT(pos)) 101 + return GPIO_LINE_DIRECTION_OUT; 102 + 103 + return GPIO_LINE_DIRECTION_IN; 101 104 } 102 105 103 106 static int tc3589x_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+4 -1
drivers/gpio/gpio-tegra.c
··· 215 215 216 216 oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset)); 217 217 218 - return !(oe & pin_mask); 218 + if (oe & pin_mask) 219 + return GPIO_LINE_DIRECTION_OUT; 220 + 221 + return GPIO_LINE_DIRECTION_IN; 219 222 } 220 223 221 224 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
+2 -2
drivers/gpio/gpio-tegra186.c
··· 111 111 112 112 value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG); 113 113 if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT) 114 - return 0; 114 + return GPIO_LINE_DIRECTION_OUT; 115 115 116 - return 1; 116 + return GPIO_LINE_DIRECTION_IN; 117 117 } 118 118 119 119 static int tegra186_gpio_direction_input(struct gpio_chip *chip,
+4 -1
drivers/gpio/gpio-thunderx.c
··· 169 169 170 170 bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line)); 171 171 172 - return !(bit_cfg & GPIO_BIT_CFG_TX_OE); 172 + if (bit_cfg & GPIO_BIT_CFG_TX_OE) 173 + return GPIO_LINE_DIRECTION_OUT; 174 + 175 + return GPIO_LINE_DIRECTION_IN; 173 176 } 174 177 175 178 static int thunderx_gpio_set_config(struct gpio_chip *chip,
+1 -1
drivers/gpio/gpio-tpic2810.c
··· 39 39 unsigned offset) 40 40 { 41 41 /* This device always output */ 42 - return 0; 42 + return GPIO_LINE_DIRECTION_OUT; 43 43 } 44 44 45 45 static int tpic2810_direction_input(struct gpio_chip *chip,
+1 -1
drivers/gpio/gpio-tps65086.c
··· 21 21 unsigned offset) 22 22 { 23 23 /* This device is output only */ 24 - return 0; 24 + return GPIO_LINE_DIRECTION_OUT; 25 25 } 26 26 27 27 static int tps65086_gpio_direction_input(struct gpio_chip *chip,
+2 -2
drivers/gpio/gpio-tps65912.c
··· 32 32 return ret; 33 33 34 34 if (val & GPIO_CFG_MASK) 35 - return 0; 35 + return GPIO_LINE_DIRECTION_OUT; 36 36 else 37 - return 1; 37 + return GPIO_LINE_DIRECTION_IN; 38 38 } 39 39 40 40 static int tps65912_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
+3 -3
drivers/gpio/gpio-tps68470.c
··· 47 47 return !!(val & BIT(offset)); 48 48 } 49 49 50 - /* Return 0 if output, 1 if input */ 51 50 static int tps68470_gpio_get_direction(struct gpio_chip *gc, 52 51 unsigned int offset) 53 52 { ··· 56 57 57 58 /* rest are always outputs */ 58 59 if (offset >= TPS68470_N_REGULAR_GPIO) 59 - return 0; 60 + return GPIO_LINE_DIRECTION_OUT; 60 61 61 62 ret = regmap_read(regmap, TPS68470_GPIO_CTL_REG_A(offset), &val); 62 63 if (ret) { ··· 66 67 } 67 68 68 69 val &= TPS68470_GPIO_MODE_MASK; 69 - return val >= TPS68470_GPIO_MODE_OUT_CMOS ? 0 : 1; 70 + return val >= TPS68470_GPIO_MODE_OUT_CMOS ? GPIO_LINE_DIRECTION_OUT : 71 + GPIO_LINE_DIRECTION_IN; 70 72 } 71 73 72 74 static void tps68470_gpio_set(struct gpio_chip *gc, unsigned int offset,
+4 -1
drivers/gpio/gpio-tqmx86.c
··· 101 101 static int tqmx86_gpio_get_direction(struct gpio_chip *chip, 102 102 unsigned int offset) 103 103 { 104 - return !!(TQMX86_DIR_INPUT_MASK & BIT(offset)); 104 + if (TQMX86_DIR_INPUT_MASK & BIT(offset)) 105 + return GPIO_LINE_DIRECTION_IN; 106 + 107 + return GPIO_LINE_DIRECTION_OUT; 105 108 } 106 109 107 110 static void tqmx86_gpio_irq_mask(struct irq_data *data)
+4 -1
drivers/gpio/gpio-ts4900.c
··· 44 44 45 45 regmap_read(priv->regmap, offset, &reg); 46 46 47 - return !(reg & TS4900_GPIO_OE); 47 + if (reg & TS4900_GPIO_OE) 48 + return GPIO_LINE_DIRECTION_OUT; 49 + 50 + return GPIO_LINE_DIRECTION_IN; 48 51 } 49 52 50 53 static int ts4900_gpio_direction_input(struct gpio_chip *chip,
+5 -5
drivers/gpio/gpio-twl4030.c
··· 165 165 if (ret < 0) 166 166 return ret; 167 167 168 - /* 1 = output, but gpiolib semantics are inverse so invert */ 169 - ret = !(ret & d_msk); 168 + if (ret & d_msk) 169 + return GPIO_LINE_DIRECTION_OUT; 170 170 171 - return ret; 171 + return GPIO_LINE_DIRECTION_IN; 172 172 } 173 173 174 174 static int twl4030_set_gpio_dataout(int gpio, int enable) ··· 380 380 { 381 381 struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 382 382 /* 383 - * Default 0 = output 383 + * Default GPIO_LINE_DIRECTION_OUT 384 384 * LED GPIOs >= TWL4030_GPIO_MAX are always output 385 385 */ 386 - int ret = 0; 386 + int ret = GPIO_LINE_DIRECTION_OUT; 387 387 388 388 mutex_lock(&priv->mutex); 389 389 if (offset < TWL4030_GPIO_MAX) {
+1 -2
drivers/gpio/gpio-twl6040.c
··· 34 34 35 35 static int twl6040gpo_get_direction(struct gpio_chip *chip, unsigned offset) 36 36 { 37 - /* This means "out" */ 38 - return 0; 37 + return GPIO_LINE_DIRECTION_OUT; 39 38 } 40 39 41 40 static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset,
+4 -1
drivers/gpio/gpio-uniphier.c
··· 113 113 static int uniphier_gpio_get_direction(struct gpio_chip *chip, 114 114 unsigned int offset) 115 115 { 116 - return uniphier_gpio_offset_read(chip, offset, UNIPHIER_GPIO_PORT_DIR); 116 + if (uniphier_gpio_offset_read(chip, offset, UNIPHIER_GPIO_PORT_DIR)) 117 + return GPIO_LINE_DIRECTION_IN; 118 + 119 + return GPIO_LINE_DIRECTION_OUT; 117 120 } 118 121 119 122 static int uniphier_gpio_direction_input(struct gpio_chip *chip,
+5 -2
drivers/gpio/gpio-wcove.c
··· 170 170 int ret, reg = to_reg(gpio, CTRL_OUT); 171 171 172 172 if (reg < 0) 173 - return 0; 173 + return GPIO_LINE_DIRECTION_OUT; 174 174 175 175 ret = regmap_read(wg->regmap, reg, &val); 176 176 if (ret) 177 177 return ret; 178 178 179 - return !(val & CTLO_DIR_OUT); 179 + if (val & CTLO_DIR_OUT) 180 + return GPIO_LINE_DIRECTION_OUT; 181 + 182 + return GPIO_LINE_DIRECTION_IN; 180 183 } 181 184 182 185 static int wcove_gpio_get(struct gpio_chip *chip, unsigned int gpio)
+4 -1
drivers/gpio/gpio-ws16c48.c
··· 56 56 const unsigned port = offset / 8; 57 57 const unsigned mask = BIT(offset % 8); 58 58 59 - return !!(ws16c48gpio->io_state[port] & mask); 59 + if (ws16c48gpio->io_state[port] & mask) 60 + return GPIO_LINE_DIRECTION_IN; 61 + 62 + return GPIO_LINE_DIRECTION_OUT; 60 63 } 61 64 62 65 static int ws16c48_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+4 -1
drivers/gpio/gpio-xgene.c
··· 80 80 bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); 81 81 bit_offset = GPIO_BIT_OFFSET(offset); 82 82 83 - return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset)); 83 + if (ioread32(chip->base + bank_offset) & BIT(bit_offset)) 84 + return GPIO_LINE_DIRECTION_IN; 85 + 86 + return GPIO_LINE_DIRECTION_OUT; 84 87 } 85 88 86 89 static int xgene_gpio_dir_in(struct gpio_chip *gc, unsigned int offset)
+4 -1
drivers/gpio/gpio-xra1403.c
··· 83 83 if (ret) 84 84 return ret; 85 85 86 - return !!(val & BIT(offset % 8)); 86 + if (val & BIT(offset % 8)) 87 + return GPIO_LINE_DIRECTION_IN; 88 + 89 + return GPIO_LINE_DIRECTION_OUT; 87 90 } 88 91 89 92 static int xra1403_get(struct gpio_chip *chip, unsigned int offset)
+2 -2
drivers/gpio/gpio-xtensa.c
··· 72 72 73 73 static int xtensa_impwire_get_direction(struct gpio_chip *gc, unsigned offset) 74 74 { 75 - return 1; /* input only */ 75 + return GPIO_LINE_DIRECTION_IN; /* input only */ 76 76 } 77 77 78 78 static int xtensa_impwire_get_value(struct gpio_chip *gc, unsigned offset) ··· 95 95 96 96 static int xtensa_expstate_get_direction(struct gpio_chip *gc, unsigned offset) 97 97 { 98 - return 0; /* output only */ 98 + return GPIO_LINE_DIRECTION_OUT; /* output only */ 99 99 } 100 100 101 101 static int xtensa_expstate_get_value(struct gpio_chip *gc, unsigned offset)
+5 -2
drivers/gpio/gpio-zynq.c
··· 360 360 * 361 361 * This function returns the direction of the specified GPIO. 362 362 * 363 - * Return: 0 for output, 1 for input 363 + * Return: GPIO_LINE_DIRECTION_OUT or GPIO_LINE_DIRECTION_IN 364 364 */ 365 365 static int zynq_gpio_get_direction(struct gpio_chip *chip, unsigned int pin) 366 366 { ··· 372 372 373 373 reg = readl_relaxed(gpio->base_addr + ZYNQ_GPIO_DIRM_OFFSET(bank_num)); 374 374 375 - return !(reg & BIT(bank_pin_num)); 375 + if (reg & BIT(bank_pin_num)) 376 + return GPIO_LINE_DIRECTION_OUT; 377 + 378 + return GPIO_LINE_DIRECTION_IN; 376 379 } 377 380 378 381 /**