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

Merge branch 'ib-pca953x-config' into devel

+127 -18
+12
Documentation/devicetree/bindings/gpio/gpio.txt
··· 67 67 https://en.wikipedia.org/wiki/Open_collector 68 68 - Bit 3: 0 means the output should be maintained during sleep/low-power mode 69 69 1 means the output state can be lost during sleep/low-power mode 70 + - Bit 4: 0 means no pull-up resistor should be enabled 71 + 1 means a pull-up resistor should be enabled 72 + This setting only applies to hardware with a simple on/off 73 + control for pull-up configuration. If the hardware has more 74 + elaborate pull-up configuration, it should be represented 75 + using a pin control binding. 76 + - Bit 5: 0 means no pull-down resistor should be enabled 77 + 1 means a pull-down resistor should be enabled 78 + This setting only applies to hardware with a simple on/off 79 + control for pull-down configuration. If the hardware has more 80 + elaborate pull-down configuration, it should be represented 81 + using a pin control binding. 70 82 71 83 1.1) GPIO specifier best practices 72 84 ----------------------------------
+64 -2
drivers/gpio/gpio-pca953x.c
··· 179 179 #define PCA957x_BANK_OUTPUT BIT(5) 180 180 181 181 #define PCAL9xxx_BANK_IN_LATCH BIT(8 + 2) 182 + #define PCAL9xxx_BANK_PULL_EN BIT(8 + 3) 183 + #define PCAL9xxx_BANK_PULL_SEL BIT(8 + 4) 182 184 #define PCAL9xxx_BANK_IRQ_MASK BIT(8 + 5) 183 185 #define PCAL9xxx_BANK_IRQ_STAT BIT(8 + 6) 184 186 ··· 202 200 * - Extended set, above 0x40, often chip specific. 203 201 * - PCAL6524/PCAL9555A with custom PCAL IRQ handling: 204 202 * Input latch register 0x40 + 2 * bank_size RW 203 + * Pull-up/pull-down enable reg 0x40 + 3 * bank_size RW 204 + * Pull-up/pull-down select reg 0x40 + 4 * bank_size RW 205 205 * Interrupt mask register 0x40 + 5 * bank_size RW 206 206 * Interrupt status register 0x40 + 6 * bank_size R 207 207 * ··· 252 248 } 253 249 254 250 if (chip->driver_data & PCA_PCAL) { 255 - bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK | 251 + bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | 252 + PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK | 256 253 PCAL9xxx_BANK_IRQ_STAT; 257 254 } 258 255 ··· 274 269 } 275 270 276 271 if (chip->driver_data & PCA_PCAL) 277 - bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_IRQ_MASK; 272 + bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | 273 + PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK; 278 274 279 275 return pca953x_check_register(chip, reg, bank); 280 276 } ··· 480 474 mutex_unlock(&chip->i2c_lock); 481 475 } 482 476 477 + static int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip, 478 + unsigned int offset, 479 + unsigned long config) 480 + { 481 + u8 pull_en_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_EN, offset, 482 + true, false); 483 + u8 pull_sel_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_SEL, offset, 484 + true, false); 485 + u8 bit = BIT(offset % BANK_SZ); 486 + int ret; 487 + 488 + /* 489 + * pull-up/pull-down configuration requires PCAL extended 490 + * registers 491 + */ 492 + if (!(chip->driver_data & PCA_PCAL)) 493 + return -ENOTSUPP; 494 + 495 + mutex_lock(&chip->i2c_lock); 496 + 497 + /* Disable pull-up/pull-down */ 498 + ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0); 499 + if (ret) 500 + goto exit; 501 + 502 + /* Configure pull-up/pull-down */ 503 + if (config == PIN_CONFIG_BIAS_PULL_UP) 504 + ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit); 505 + else if (config == PIN_CONFIG_BIAS_PULL_DOWN) 506 + ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0); 507 + if (ret) 508 + goto exit; 509 + 510 + /* Enable pull-up/pull-down */ 511 + ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit); 512 + 513 + exit: 514 + mutex_unlock(&chip->i2c_lock); 515 + return ret; 516 + } 517 + 518 + static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 519 + unsigned long config) 520 + { 521 + struct pca953x_chip *chip = gpiochip_get_data(gc); 522 + 523 + switch (config) { 524 + case PIN_CONFIG_BIAS_PULL_UP: 525 + case PIN_CONFIG_BIAS_PULL_DOWN: 526 + return pca953x_gpio_set_pull_up_down(chip, offset, config); 527 + default: 528 + return -ENOTSUPP; 529 + } 530 + } 531 + 483 532 static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) 484 533 { 485 534 struct gpio_chip *gc; ··· 547 486 gc->set = pca953x_gpio_set_value; 548 487 gc->get_direction = pca953x_gpio_get_direction; 549 488 gc->set_multiple = pca953x_gpio_set_multiple; 489 + gc->set_config = pca953x_gpio_set_config; 550 490 gc->can_sleep = true; 551 491 552 492 gc->base = chip->gpio_start;
+5
drivers/gpio/gpiolib-of.c
··· 345 345 if (of_flags & OF_GPIO_TRANSITORY) 346 346 *flags |= GPIO_TRANSITORY; 347 347 348 + if (of_flags & OF_GPIO_PULL_UP) 349 + *flags |= GPIO_PULL_UP; 350 + if (of_flags & OF_GPIO_PULL_DOWN) 351 + *flags |= GPIO_PULL_DOWN; 352 + 348 353 return desc; 349 354 } 350 355
+34 -16
drivers/gpio/gpiolib.c
··· 2555 2555 * rely on gpio_request() having been called beforehand. 2556 2556 */ 2557 2557 2558 + static int gpio_set_config(struct gpio_chip *gc, unsigned offset, 2559 + enum pin_config_param mode) 2560 + { 2561 + unsigned long config = { PIN_CONF_PACKED(mode, 0) }; 2562 + 2563 + return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; 2564 + } 2565 + 2558 2566 /** 2559 2567 * gpiod_direction_input - set the GPIO direction to input 2560 2568 * @desc: GPIO to set to input ··· 2610 2602 if (status == 0) 2611 2603 clear_bit(FLAG_IS_OUT, &desc->flags); 2612 2604 2605 + if (test_bit(FLAG_PULL_UP, &desc->flags)) 2606 + gpio_set_config(chip, gpio_chip_hwgpio(desc), 2607 + PIN_CONFIG_BIAS_PULL_UP); 2608 + else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) 2609 + gpio_set_config(chip, gpio_chip_hwgpio(desc), 2610 + PIN_CONFIG_BIAS_PULL_DOWN); 2611 + 2613 2612 trace_gpio_direction(desc_to_gpio(desc), 1, status); 2614 2613 2615 2614 return status; 2616 2615 } 2617 2616 EXPORT_SYMBOL_GPL(gpiod_direction_input); 2618 - 2619 - static int gpio_set_drive_single_ended(struct gpio_chip *gc, unsigned offset, 2620 - enum pin_config_param mode) 2621 - { 2622 - unsigned long config = { PIN_CONF_PACKED(mode, 0) }; 2623 - 2624 - return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; 2625 - } 2626 2617 2627 2618 static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value) 2628 2619 { ··· 2719 2712 gc = desc->gdev->chip; 2720 2713 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) { 2721 2714 /* First see if we can enable open drain in hardware */ 2722 - ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), 2723 - PIN_CONFIG_DRIVE_OPEN_DRAIN); 2715 + ret = gpio_set_config(gc, gpio_chip_hwgpio(desc), 2716 + PIN_CONFIG_DRIVE_OPEN_DRAIN); 2724 2717 if (!ret) 2725 2718 goto set_output_value; 2726 2719 /* Emulate open drain by not actively driving the line high */ ··· 2728 2721 return gpiod_direction_input(desc); 2729 2722 } 2730 2723 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) { 2731 - ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), 2732 - PIN_CONFIG_DRIVE_OPEN_SOURCE); 2724 + ret = gpio_set_config(gc, gpio_chip_hwgpio(desc), 2725 + PIN_CONFIG_DRIVE_OPEN_SOURCE); 2733 2726 if (!ret) 2734 2727 goto set_output_value; 2735 2728 /* Emulate open source by not actively driving the line low */ 2736 2729 if (!value) 2737 2730 return gpiod_direction_input(desc); 2738 2731 } else { 2739 - gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc), 2740 - PIN_CONFIG_DRIVE_PUSH_PULL); 2732 + gpio_set_config(gc, gpio_chip_hwgpio(desc), 2733 + PIN_CONFIG_DRIVE_PUSH_PULL); 2741 2734 } 2742 2735 2743 2736 set_output_value: ··· 2769 2762 } 2770 2763 2771 2764 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce); 2772 - return chip->set_config(chip, gpio_chip_hwgpio(desc), config); 2765 + return gpio_set_config(chip, gpio_chip_hwgpio(desc), config); 2773 2766 } 2774 2767 EXPORT_SYMBOL_GPL(gpiod_set_debounce); 2775 2768 ··· 2806 2799 packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE, 2807 2800 !transitory); 2808 2801 gpio = gpio_chip_hwgpio(desc); 2809 - rc = chip->set_config(chip, gpio, packed); 2802 + rc = gpio_set_config(chip, gpio, packed); 2810 2803 if (rc == -ENOTSUPP) { 2811 2804 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n", 2812 2805 gpio); ··· 4093 4086 4094 4087 if (lflags & GPIO_OPEN_SOURCE) 4095 4088 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 4089 + 4090 + if ((lflags & GPIO_PULL_UP) && (lflags & GPIO_PULL_DOWN)) { 4091 + gpiod_err(desc, 4092 + "both pull-up and pull-down enabled, invalid configuration\n"); 4093 + return -EINVAL; 4094 + } 4095 + 4096 + if (lflags & GPIO_PULL_UP) 4097 + set_bit(FLAG_PULL_UP, &desc->flags); 4098 + else if (lflags & GPIO_PULL_DOWN) 4099 + set_bit(FLAG_PULL_DOWN, &desc->flags); 4096 4100 4097 4101 status = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY)); 4098 4102 if (status < 0)
+2
drivers/gpio/gpiolib.h
··· 219 219 #define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */ 220 220 #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ 221 221 #define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */ 222 + #define FLAG_PULL_UP 13 /* GPIO has pull up enabled */ 223 + #define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */ 222 224 223 225 /* Connection label */ 224 226 const char *label;
+6
include/dt-bindings/gpio/gpio.h
··· 33 33 #define GPIO_PERSISTENT 0 34 34 #define GPIO_TRANSITORY 8 35 35 36 + /* Bit 4 express pull up */ 37 + #define GPIO_PULL_UP 16 38 + 39 + /* Bit 5 express pull down */ 40 + #define GPIO_PULL_DOWN 32 41 + 36 42 #endif
+2
include/linux/gpio/machine.h
··· 12 12 GPIO_OPEN_SOURCE = (1 << 2), 13 13 GPIO_PERSISTENT = (0 << 3), 14 14 GPIO_TRANSITORY = (1 << 3), 15 + GPIO_PULL_UP = (1 << 4), 16 + GPIO_PULL_DOWN = (1 << 5), 15 17 }; 16 18 17 19 /**
+2
include/linux/of_gpio.h
··· 28 28 OF_GPIO_SINGLE_ENDED = 0x2, 29 29 OF_GPIO_OPEN_DRAIN = 0x4, 30 30 OF_GPIO_TRANSITORY = 0x8, 31 + OF_GPIO_PULL_UP = 0x10, 32 + OF_GPIO_PULL_DOWN = 0x20, 31 33 }; 32 34 33 35 #ifdef CONFIG_OF_GPIO