@@ -2555,6 +2555,14 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
25552555 * rely on gpio_request() having been called beforehand.
25562556 */
25572557
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+
25582566/**
25592567 * gpiod_direction_input - set the GPIO direction to input
25602568 * @desc: GPIO to set to input
@@ -2602,20 +2610,19 @@ int gpiod_direction_input(struct gpio_desc *desc)
26022610 if (status == 0 )
26032611 clear_bit (FLAG_IS_OUT , & desc -> flags );
26042612
2613+ if (test_bit (FLAG_PULL_UP , & desc -> flags ))
2614+ gpio_set_config (chip , gpio_chip_hwgpio (desc ),
2615+ PIN_CONFIG_BIAS_PULL_UP );
2616+ else if (test_bit (FLAG_PULL_DOWN , & desc -> flags ))
2617+ gpio_set_config (chip , gpio_chip_hwgpio (desc ),
2618+ PIN_CONFIG_BIAS_PULL_DOWN );
2619+
26052620 trace_gpio_direction (desc_to_gpio (desc ), 1 , status );
26062621
26072622 return status ;
26082623}
26092624EXPORT_SYMBOL_GPL (gpiod_direction_input );
26102625
2611- static int gpio_set_drive_single_ended (struct gpio_chip * gc , unsigned offset ,
2612- enum pin_config_param mode )
2613- {
2614- unsigned long config = { PIN_CONF_PACKED (mode , 0 ) };
2615-
2616- return gc -> set_config ? gc -> set_config (gc , offset , config ) : - ENOTSUPP ;
2617- }
2618-
26192626static int gpiod_direction_output_raw_commit (struct gpio_desc * desc , int value )
26202627{
26212628 struct gpio_chip * gc = desc -> gdev -> chip ;
@@ -2712,25 +2719,25 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
27122719 gc = desc -> gdev -> chip ;
27132720 if (test_bit (FLAG_OPEN_DRAIN , & desc -> flags )) {
27142721 /* First see if we can enable open drain in hardware */
2715- ret = gpio_set_drive_single_ended (gc , gpio_chip_hwgpio (desc ),
2716- PIN_CONFIG_DRIVE_OPEN_DRAIN );
2722+ ret = gpio_set_config (gc , gpio_chip_hwgpio (desc ),
2723+ PIN_CONFIG_DRIVE_OPEN_DRAIN );
27172724 if (!ret )
27182725 goto set_output_value ;
27192726 /* Emulate open drain by not actively driving the line high */
27202727 if (value )
27212728 return gpiod_direction_input (desc );
27222729 }
27232730 else if (test_bit (FLAG_OPEN_SOURCE , & desc -> flags )) {
2724- ret = gpio_set_drive_single_ended (gc , gpio_chip_hwgpio (desc ),
2725- PIN_CONFIG_DRIVE_OPEN_SOURCE );
2731+ ret = gpio_set_config (gc , gpio_chip_hwgpio (desc ),
2732+ PIN_CONFIG_DRIVE_OPEN_SOURCE );
27262733 if (!ret )
27272734 goto set_output_value ;
27282735 /* Emulate open source by not actively driving the line low */
27292736 if (!value )
27302737 return gpiod_direction_input (desc );
27312738 } else {
2732- gpio_set_drive_single_ended (gc , gpio_chip_hwgpio (desc ),
2733- PIN_CONFIG_DRIVE_PUSH_PULL );
2739+ gpio_set_config (gc , gpio_chip_hwgpio (desc ),
2740+ PIN_CONFIG_DRIVE_PUSH_PULL );
27342741 }
27352742
27362743set_output_value :
@@ -2762,7 +2769,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
27622769 }
27632770
27642771 config = pinconf_to_config_packed (PIN_CONFIG_INPUT_DEBOUNCE , debounce );
2765- return chip -> set_config (chip , gpio_chip_hwgpio (desc ), config );
2772+ return gpio_set_config (chip , gpio_chip_hwgpio (desc ), config );
27662773}
27672774EXPORT_SYMBOL_GPL (gpiod_set_debounce );
27682775
@@ -2799,7 +2806,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
27992806 packed = pinconf_to_config_packed (PIN_CONFIG_PERSIST_STATE ,
28002807 !transitory );
28012808 gpio = gpio_chip_hwgpio (desc );
2802- rc = chip -> set_config (chip , gpio , packed );
2809+ rc = gpio_set_config (chip , gpio , packed );
28032810 if (rc == - ENOTSUPP ) {
28042811 dev_dbg (& desc -> gdev -> dev , "Persistence not supported for GPIO %d\n" ,
28052812 gpio );
@@ -4087,6 +4094,17 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
40874094 if (lflags & GPIO_OPEN_SOURCE )
40884095 set_bit (FLAG_OPEN_SOURCE , & desc -> flags );
40894096
4097+ if ((lflags & GPIO_PULL_UP ) && (lflags & GPIO_PULL_DOWN )) {
4098+ gpiod_err (desc ,
4099+ "both pull-up and pull-down enabled, invalid configuration\n" );
4100+ return - EINVAL ;
4101+ }
4102+
4103+ if (lflags & GPIO_PULL_UP )
4104+ set_bit (FLAG_PULL_UP , & desc -> flags );
4105+ else if (lflags & GPIO_PULL_DOWN )
4106+ set_bit (FLAG_PULL_DOWN , & desc -> flags );
4107+
40904108 status = gpiod_set_transitory (desc , (lflags & GPIO_TRANSITORY ));
40914109 if (status < 0 )
40924110 return status ;
0 commit comments