@@ -1352,14 +1352,6 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
1352
1352
spin_lock_irqsave (& gpio_lock , flags );
1353
1353
}
1354
1354
done :
1355
- if (status < 0 ) {
1356
- /* Clear flags that might have been set by the caller before
1357
- * requesting the GPIO.
1358
- */
1359
- clear_bit (FLAG_ACTIVE_LOW , & desc -> flags );
1360
- clear_bit (FLAG_OPEN_DRAIN , & desc -> flags );
1361
- clear_bit (FLAG_OPEN_SOURCE , & desc -> flags );
1362
- }
1363
1355
spin_unlock_irqrestore (& gpio_lock , flags );
1364
1356
return status ;
1365
1357
}
@@ -2587,39 +2579,31 @@ struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
2587
2579
}
2588
2580
EXPORT_SYMBOL_GPL (gpiod_get_optional );
2589
2581
2590
- /**
2591
- * gpiod_parse_flags - helper function to parse GPIO lookup flags
2592
- * @desc: gpio to be setup
2593
- * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
2594
- * of_get_gpio_hog()
2595
- *
2596
- * Set the GPIO descriptor flags based on the given GPIO lookup flags.
2597
- */
2598
- static void gpiod_parse_flags (struct gpio_desc * desc , unsigned long lflags )
2599
- {
2600
- if (lflags & GPIO_ACTIVE_LOW )
2601
- set_bit (FLAG_ACTIVE_LOW , & desc -> flags );
2602
- if (lflags & GPIO_OPEN_DRAIN )
2603
- set_bit (FLAG_OPEN_DRAIN , & desc -> flags );
2604
- if (lflags & GPIO_OPEN_SOURCE )
2605
- set_bit (FLAG_OPEN_SOURCE , & desc -> flags );
2606
- }
2607
2582
2608
2583
/**
2609
2584
* gpiod_configure_flags - helper function to configure a given GPIO
2610
2585
* @desc: gpio whose value will be assigned
2611
2586
* @con_id: function within the GPIO consumer
2587
+ * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
2588
+ * of_get_gpio_hog()
2612
2589
* @dflags: gpiod_flags - optional GPIO initialization flags
2613
2590
*
2614
2591
* Return 0 on success, -ENOENT if no GPIO has been assigned to the
2615
2592
* requested function and/or index, or another IS_ERR() code if an error
2616
2593
* occurred while trying to acquire the GPIO.
2617
2594
*/
2618
2595
static int gpiod_configure_flags (struct gpio_desc * desc , const char * con_id ,
2619
- enum gpiod_flags dflags )
2596
+ unsigned long lflags , enum gpiod_flags dflags )
2620
2597
{
2621
2598
int status ;
2622
2599
2600
+ if (lflags & GPIO_ACTIVE_LOW )
2601
+ set_bit (FLAG_ACTIVE_LOW , & desc -> flags );
2602
+ if (lflags & GPIO_OPEN_DRAIN )
2603
+ set_bit (FLAG_OPEN_DRAIN , & desc -> flags );
2604
+ if (lflags & GPIO_OPEN_SOURCE )
2605
+ set_bit (FLAG_OPEN_SOURCE , & desc -> flags );
2606
+
2623
2607
/* No particular flag request, return here... */
2624
2608
if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET )) {
2625
2609
pr_debug ("no flags found for %s\n" , con_id );
@@ -2686,13 +2670,11 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2686
2670
return desc ;
2687
2671
}
2688
2672
2689
- gpiod_parse_flags (desc , lookupflags );
2690
-
2691
2673
status = gpiod_request (desc , con_id );
2692
2674
if (status < 0 )
2693
2675
return ERR_PTR (status );
2694
2676
2695
- status = gpiod_configure_flags (desc , con_id , flags );
2677
+ status = gpiod_configure_flags (desc , con_id , lookupflags , flags );
2696
2678
if (status < 0 ) {
2697
2679
dev_dbg (dev , "setup of GPIO %s failed\n" , con_id );
2698
2680
gpiod_put (desc );
@@ -2748,6 +2730,10 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
2748
2730
if (IS_ERR (desc ))
2749
2731
return desc ;
2750
2732
2733
+ ret = gpiod_request (desc , NULL );
2734
+ if (ret )
2735
+ return ERR_PTR (ret );
2736
+
2751
2737
if (active_low )
2752
2738
set_bit (FLAG_ACTIVE_LOW , & desc -> flags );
2753
2739
@@ -2758,10 +2744,6 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
2758
2744
set_bit (FLAG_OPEN_SOURCE , & desc -> flags );
2759
2745
}
2760
2746
2761
- ret = gpiod_request (desc , NULL );
2762
- if (ret )
2763
- return ERR_PTR (ret );
2764
-
2765
2747
return desc ;
2766
2748
}
2767
2749
EXPORT_SYMBOL_GPL (fwnode_get_named_gpiod );
@@ -2814,8 +2796,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
2814
2796
chip = gpiod_to_chip (desc );
2815
2797
hwnum = gpio_chip_hwgpio (desc );
2816
2798
2817
- gpiod_parse_flags (desc , lflags );
2818
-
2819
2799
local_desc = gpiochip_request_own_desc (chip , hwnum , name );
2820
2800
if (IS_ERR (local_desc )) {
2821
2801
status = PTR_ERR (local_desc );
@@ -2824,7 +2804,7 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
2824
2804
return status ;
2825
2805
}
2826
2806
2827
- status = gpiod_configure_flags (desc , name , dflags );
2807
+ status = gpiod_configure_flags (desc , name , lflags , dflags );
2828
2808
if (status < 0 ) {
2829
2809
pr_err ("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n" ,
2830
2810
name , chip -> label , hwnum , status );
0 commit comments