@@ -1582,38 +1582,43 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
1582
1582
* gpiod_get - obtain a GPIO for a given GPIO function
1583
1583
* @dev: GPIO consumer, can be NULL for system-global GPIOs
1584
1584
* @con_id: function within the GPIO consumer
1585
+ * @flags: optional GPIO initialization flags
1585
1586
*
1586
1587
* Return the GPIO descriptor corresponding to the function con_id of device
1587
1588
* dev, -ENOENT if no GPIO has been assigned to the requested function, or
1588
1589
* another IS_ERR() code if an error occured while trying to acquire the GPIO.
1589
1590
*/
1590
- struct gpio_desc * __must_check gpiod_get (struct device * dev , const char * con_id )
1591
+ struct gpio_desc * __must_check __gpiod_get (struct device * dev , const char * con_id ,
1592
+ enum gpiod_flags flags )
1591
1593
{
1592
- return gpiod_get_index (dev , con_id , 0 );
1594
+ return gpiod_get_index (dev , con_id , 0 , flags );
1593
1595
}
1594
- EXPORT_SYMBOL_GPL (gpiod_get );
1596
+ EXPORT_SYMBOL_GPL (__gpiod_get );
1595
1597
1596
1598
/**
1597
1599
* gpiod_get_optional - obtain an optional GPIO for a given GPIO function
1598
1600
* @dev: GPIO consumer, can be NULL for system-global GPIOs
1599
1601
* @con_id: function within the GPIO consumer
1602
+ * @flags: optional GPIO initialization flags
1600
1603
*
1601
1604
* This is equivalent to gpiod_get(), except that when no GPIO was assigned to
1602
1605
* the requested function it will return NULL. This is convenient for drivers
1603
1606
* that need to handle optional GPIOs.
1604
1607
*/
1605
- struct gpio_desc * __must_check gpiod_get_optional (struct device * dev ,
1606
- const char * con_id )
1608
+ struct gpio_desc * __must_check __gpiod_get_optional (struct device * dev ,
1609
+ const char * con_id ,
1610
+ enum gpiod_flags flags )
1607
1611
{
1608
- return gpiod_get_index_optional (dev , con_id , 0 );
1612
+ return gpiod_get_index_optional (dev , con_id , 0 , flags );
1609
1613
}
1610
- EXPORT_SYMBOL_GPL (gpiod_get_optional );
1614
+ EXPORT_SYMBOL_GPL (__gpiod_get_optional );
1611
1615
1612
1616
/**
1613
1617
* gpiod_get_index - obtain a GPIO from a multi-index GPIO function
1614
1618
* @dev: GPIO consumer, can be NULL for system-global GPIOs
1615
1619
* @con_id: function within the GPIO consumer
1616
1620
* @idx: index of the GPIO to obtain in the consumer
1621
+ * @flags: optional GPIO initialization flags
1617
1622
*
1618
1623
* This variant of gpiod_get() allows to access GPIOs other than the first
1619
1624
* defined one for functions that define several GPIOs.
@@ -1622,23 +1627,24 @@ EXPORT_SYMBOL_GPL(gpiod_get_optional);
1622
1627
* requested function and/or index, or another IS_ERR() code if an error
1623
1628
* occured while trying to acquire the GPIO.
1624
1629
*/
1625
- struct gpio_desc * __must_check gpiod_get_index (struct device * dev ,
1630
+ struct gpio_desc * __must_check __gpiod_get_index (struct device * dev ,
1626
1631
const char * con_id ,
1627
- unsigned int idx )
1632
+ unsigned int idx ,
1633
+ enum gpiod_flags flags )
1628
1634
{
1629
1635
struct gpio_desc * desc = NULL ;
1630
1636
int status ;
1631
- enum gpio_lookup_flags flags = 0 ;
1637
+ enum gpio_lookup_flags lookupflags = 0 ;
1632
1638
1633
1639
dev_dbg (dev , "GPIO lookup for consumer %s\n" , con_id );
1634
1640
1635
1641
/* Using device tree? */
1636
1642
if (IS_ENABLED (CONFIG_OF ) && dev && dev -> of_node ) {
1637
1643
dev_dbg (dev , "using device tree for GPIO lookup\n" );
1638
- desc = of_find_gpio (dev , con_id , idx , & flags );
1644
+ desc = of_find_gpio (dev , con_id , idx , & lookupflags );
1639
1645
} else if (IS_ENABLED (CONFIG_ACPI ) && dev && ACPI_HANDLE (dev )) {
1640
1646
dev_dbg (dev , "using ACPI for GPIO lookup\n" );
1641
- desc = acpi_find_gpio (dev , con_id , idx , & flags );
1647
+ desc = acpi_find_gpio (dev , con_id , idx , & lookupflags );
1642
1648
}
1643
1649
1644
1650
/*
@@ -1647,7 +1653,7 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
1647
1653
*/
1648
1654
if (!desc || desc == ERR_PTR (- ENOENT )) {
1649
1655
dev_dbg (dev , "using lookup tables for GPIO lookup" );
1650
- desc = gpiod_find (dev , con_id , idx , & flags );
1656
+ desc = gpiod_find (dev , con_id , idx , & lookupflags );
1651
1657
}
1652
1658
1653
1659
if (IS_ERR (desc )) {
@@ -1660,43 +1666,62 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
1660
1666
if (status < 0 )
1661
1667
return ERR_PTR (status );
1662
1668
1663
- if (flags & GPIO_ACTIVE_LOW )
1669
+ if (lookupflags & GPIO_ACTIVE_LOW )
1664
1670
set_bit (FLAG_ACTIVE_LOW , & desc -> flags );
1665
- if (flags & GPIO_OPEN_DRAIN )
1671
+ if (lookupflags & GPIO_OPEN_DRAIN )
1666
1672
set_bit (FLAG_OPEN_DRAIN , & desc -> flags );
1667
- if (flags & GPIO_OPEN_SOURCE )
1673
+ if (lookupflags & GPIO_OPEN_SOURCE )
1668
1674
set_bit (FLAG_OPEN_SOURCE , & desc -> flags );
1669
1675
1676
+ /* No particular flag request, return here... */
1677
+ if (flags & GPIOD_FLAGS_BIT_DIR_SET )
1678
+ return desc ;
1679
+
1680
+ /* Process flags */
1681
+ if (flags & GPIOD_FLAGS_BIT_DIR_OUT )
1682
+ status = gpiod_direction_output (desc ,
1683
+ flags & GPIOD_FLAGS_BIT_DIR_VAL );
1684
+ else
1685
+ status = gpiod_direction_input (desc );
1686
+
1687
+ if (status < 0 ) {
1688
+ dev_dbg (dev , "setup of GPIO %s failed\n" , con_id );
1689
+ gpiod_put (desc );
1690
+ return ERR_PTR (status );
1691
+ }
1692
+
1670
1693
return desc ;
1671
1694
}
1672
- EXPORT_SYMBOL_GPL (gpiod_get_index );
1695
+ EXPORT_SYMBOL_GPL (__gpiod_get_index );
1673
1696
1674
1697
/**
1675
1698
* gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
1676
1699
* function
1677
1700
* @dev: GPIO consumer, can be NULL for system-global GPIOs
1678
1701
* @con_id: function within the GPIO consumer
1679
1702
* @index: index of the GPIO to obtain in the consumer
1703
+ * @flags: optional GPIO initialization flags
1680
1704
*
1681
1705
* This is equivalent to gpiod_get_index(), except that when no GPIO with the
1682
1706
* specified index was assigned to the requested function it will return NULL.
1683
1707
* This is convenient for drivers that need to handle optional GPIOs.
1684
1708
*/
1685
- struct gpio_desc * __must_check gpiod_get_index_optional (struct device * dev ,
1709
+ struct gpio_desc * __must_check __gpiod_get_index_optional (struct device * dev ,
1686
1710
const char * con_id ,
1687
- unsigned int index )
1711
+ unsigned int index ,
1712
+ enum gpiod_flags flags )
1688
1713
{
1689
1714
struct gpio_desc * desc ;
1690
1715
1691
- desc = gpiod_get_index (dev , con_id , index );
1716
+ desc = gpiod_get_index (dev , con_id , index , flags );
1692
1717
if (IS_ERR (desc )) {
1693
1718
if (PTR_ERR (desc ) == - ENOENT )
1694
1719
return NULL ;
1695
1720
}
1696
1721
1697
1722
return desc ;
1698
1723
}
1699
- EXPORT_SYMBOL_GPL (gpiod_get_index_optional );
1724
+ EXPORT_SYMBOL_GPL (__gpiod_get_index_optional );
1700
1725
1701
1726
/**
1702
1727
* gpiod_put - dispose of a GPIO descriptor
0 commit comments