···6767 https://en.wikipedia.org/wiki/Open_collector6868- Bit 3: 0 means the output should be maintained during sleep/low-power mode6969 1 means the output state can be lost during sleep/low-power mode7070+- Bit 4: 0 means no pull-up resistor should be enabled7171+ 1 means a pull-up resistor should be enabled7272+ This setting only applies to hardware with a simple on/off7373+ control for pull-up configuration. If the hardware has more7474+ elaborate pull-up configuration, it should be represented7575+ using a pin control binding.7676+- Bit 5: 0 means no pull-down resistor should be enabled7777+ 1 means a pull-down resistor should be enabled7878+ This setting only applies to hardware with a simple on/off7979+ control for pull-down configuration. If the hardware has more8080+ elaborate pull-down configuration, it should be represented8181+ using a pin control binding.708271831.1) GPIO specifier best practices7284----------------------------------
···345345 if (of_flags & OF_GPIO_TRANSITORY)346346 *flags |= GPIO_TRANSITORY;347347348348+ if (of_flags & OF_GPIO_PULL_UP)349349+ *flags |= GPIO_PULL_UP;350350+ if (of_flags & OF_GPIO_PULL_DOWN)351351+ *flags |= GPIO_PULL_DOWN;352352+348353 return desc;349354}350355
+34-16
drivers/gpio/gpiolib.c
···25552555 * rely on gpio_request() having been called beforehand.25562556 */2557255725582558+static int gpio_set_config(struct gpio_chip *gc, unsigned offset,25592559+ enum pin_config_param mode)25602560+{25612561+ unsigned long config = { PIN_CONF_PACKED(mode, 0) };25622562+25632563+ return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;25642564+}25652565+25582566/**25592567 * gpiod_direction_input - set the GPIO direction to input25602568 * @desc: GPIO to set to input···26102602 if (status == 0)26112603 clear_bit(FLAG_IS_OUT, &desc->flags);2612260426052605+ if (test_bit(FLAG_PULL_UP, &desc->flags))26062606+ gpio_set_config(chip, gpio_chip_hwgpio(desc),26072607+ PIN_CONFIG_BIAS_PULL_UP);26082608+ else if (test_bit(FLAG_PULL_DOWN, &desc->flags))26092609+ gpio_set_config(chip, gpio_chip_hwgpio(desc),26102610+ PIN_CONFIG_BIAS_PULL_DOWN);26112611+26132612 trace_gpio_direction(desc_to_gpio(desc), 1, status);2614261326152614 return status;26162615}26172616EXPORT_SYMBOL_GPL(gpiod_direction_input);26182618-26192619-static int gpio_set_drive_single_ended(struct gpio_chip *gc, unsigned offset,26202620- enum pin_config_param mode)26212621-{26222622- unsigned long config = { PIN_CONF_PACKED(mode, 0) };26232623-26242624- return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;26252625-}2626261726272618static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)26282619{···27192712 gc = desc->gdev->chip;27202713 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) {27212714 /* First see if we can enable open drain in hardware */27222722- ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),27232723- PIN_CONFIG_DRIVE_OPEN_DRAIN);27152715+ ret = gpio_set_config(gc, gpio_chip_hwgpio(desc),27162716+ PIN_CONFIG_DRIVE_OPEN_DRAIN);27242717 if (!ret)27252718 goto set_output_value;27262719 /* Emulate open drain by not actively driving the line high */···27282721 return gpiod_direction_input(desc);27292722 }27302723 else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {27312731- ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),27322732- PIN_CONFIG_DRIVE_OPEN_SOURCE);27242724+ ret = gpio_set_config(gc, gpio_chip_hwgpio(desc),27252725+ PIN_CONFIG_DRIVE_OPEN_SOURCE);27332726 if (!ret)27342727 goto set_output_value;27352728 /* Emulate open source by not actively driving the line low */27362729 if (!value)27372730 return gpiod_direction_input(desc);27382731 } else {27392739- gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),27402740- PIN_CONFIG_DRIVE_PUSH_PULL);27322732+ gpio_set_config(gc, gpio_chip_hwgpio(desc),27332733+ PIN_CONFIG_DRIVE_PUSH_PULL);27412734 }2742273527432736set_output_value:···27692762 }2770276327712764 config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);27722772- return chip->set_config(chip, gpio_chip_hwgpio(desc), config);27652765+ return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);27732766}27742767EXPORT_SYMBOL_GPL(gpiod_set_debounce);27752768···28062799 packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,28072800 !transitory);28082801 gpio = gpio_chip_hwgpio(desc);28092809- rc = chip->set_config(chip, gpio, packed);28022802+ rc = gpio_set_config(chip, gpio, packed);28102803 if (rc == -ENOTSUPP) {28112804 dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",28122805 gpio);···4093408640944087 if (lflags & GPIO_OPEN_SOURCE)40954088 set_bit(FLAG_OPEN_SOURCE, &desc->flags);40894089+40904090+ if ((lflags & GPIO_PULL_UP) && (lflags & GPIO_PULL_DOWN)) {40914091+ gpiod_err(desc,40924092+ "both pull-up and pull-down enabled, invalid configuration\n");40934093+ return -EINVAL;40944094+ }40954095+40964096+ if (lflags & GPIO_PULL_UP)40974097+ set_bit(FLAG_PULL_UP, &desc->flags);40984098+ else if (lflags & GPIO_PULL_DOWN)40994099+ set_bit(FLAG_PULL_DOWN, &desc->flags);4096410040974101 status = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY));40984102 if (status < 0)
+2
drivers/gpio/gpiolib.h
···219219#define FLAG_IRQ_IS_ENABLED 10 /* GPIO is connected to an enabled IRQ */220220#define FLAG_IS_HOGGED 11 /* GPIO is hogged */221221#define FLAG_TRANSITORY 12 /* GPIO may lose value in sleep or reset */222222+#define FLAG_PULL_UP 13 /* GPIO has pull up enabled */223223+#define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */222224223225 /* Connection label */224226 const char *label;
+6
include/dt-bindings/gpio/gpio.h
···3333#define GPIO_PERSISTENT 03434#define GPIO_TRANSITORY 835353636+/* Bit 4 express pull up */3737+#define GPIO_PULL_UP 163838+3939+/* Bit 5 express pull down */4040+#define GPIO_PULL_DOWN 324141+3642#endif