25
25
#include <linux/usb/ch9.h>
26
26
#include <linux/usb/gadget.h>
27
27
#include <linux/of.h>
28
- #include <linux/of_gpio .h>
28
+ #include <linux/gpio/consumer .h>
29
29
#include <linux/platform_data/atmel.h>
30
30
#include <linux/regmap.h>
31
31
#include <linux/mfd/syscon.h>
@@ -1510,7 +1510,6 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1510
1510
1511
1511
static void at91_vbus_update (struct at91_udc * udc , unsigned value )
1512
1512
{
1513
- value ^= udc -> board .vbus_active_low ;
1514
1513
if (value != udc -> vbus )
1515
1514
at91_vbus_session (& udc -> gadget , value );
1516
1515
}
@@ -1521,7 +1520,7 @@ static irqreturn_t at91_vbus_irq(int irq, void *_udc)
1521
1520
1522
1521
/* vbus needs at least brief debouncing */
1523
1522
udelay (10 );
1524
- at91_vbus_update (udc , gpio_get_value (udc -> board .vbus_pin ));
1523
+ at91_vbus_update (udc , gpiod_get_value (udc -> board .vbus_pin ));
1525
1524
1526
1525
return IRQ_HANDLED ;
1527
1526
}
@@ -1531,7 +1530,7 @@ static void at91_vbus_timer_work(struct work_struct *work)
1531
1530
struct at91_udc * udc = container_of (work , struct at91_udc ,
1532
1531
vbus_timer_work );
1533
1532
1534
- at91_vbus_update (udc , gpio_get_value_cansleep (udc -> board .vbus_pin ));
1533
+ at91_vbus_update (udc , gpiod_get_value_cansleep (udc -> board .vbus_pin ));
1535
1534
1536
1535
if (!timer_pending (& udc -> vbus_timer ))
1537
1536
mod_timer (& udc -> vbus_timer , jiffies + VBUS_POLL_TIMEOUT );
@@ -1595,7 +1594,6 @@ static void at91udc_shutdown(struct platform_device *dev)
1595
1594
static int at91rm9200_udc_init (struct at91_udc * udc )
1596
1595
{
1597
1596
struct at91_ep * ep ;
1598
- int ret ;
1599
1597
int i ;
1600
1598
1601
1599
for (i = 0 ; i < NUM_ENDPOINTS ; i ++ ) {
@@ -1615,32 +1613,23 @@ static int at91rm9200_udc_init(struct at91_udc *udc)
1615
1613
}
1616
1614
}
1617
1615
1618
- if (!gpio_is_valid ( udc -> board .pullup_pin ) ) {
1616
+ if (!udc -> board .pullup_pin ) {
1619
1617
DBG ("no D+ pullup?\n" );
1620
1618
return - ENODEV ;
1621
1619
}
1622
1620
1623
- ret = devm_gpio_request (& udc -> pdev -> dev , udc -> board .pullup_pin ,
1624
- "udc_pullup" );
1625
- if (ret ) {
1626
- DBG ("D+ pullup is busy\n" );
1627
- return ret ;
1628
- }
1629
-
1630
- gpio_direction_output (udc -> board .pullup_pin ,
1631
- udc -> board .pullup_active_low );
1621
+ gpiod_direction_output (udc -> board .pullup_pin ,
1622
+ gpiod_is_active_low (udc -> board .pullup_pin ));
1632
1623
1633
1624
return 0 ;
1634
1625
}
1635
1626
1636
1627
static void at91rm9200_udc_pullup (struct at91_udc * udc , int is_on )
1637
1628
{
1638
- int active = !udc -> board .pullup_active_low ;
1639
-
1640
1629
if (is_on )
1641
- gpio_set_value (udc -> board .pullup_pin , active );
1630
+ gpiod_set_value (udc -> board .pullup_pin , 1 );
1642
1631
else
1643
- gpio_set_value (udc -> board .pullup_pin , ! active );
1632
+ gpiod_set_value (udc -> board .pullup_pin , 0 );
1644
1633
}
1645
1634
1646
1635
static const struct at91_udc_caps at91rm9200_udc_caps = {
@@ -1783,20 +1772,20 @@ static void at91udc_of_init(struct at91_udc *udc, struct device_node *np)
1783
1772
{
1784
1773
struct at91_udc_data * board = & udc -> board ;
1785
1774
const struct of_device_id * match ;
1786
- enum of_gpio_flags flags ;
1787
1775
u32 val ;
1788
1776
1789
1777
if (of_property_read_u32 (np , "atmel,vbus-polled" , & val ) == 0 )
1790
1778
board -> vbus_polled = 1 ;
1791
1779
1792
- board -> vbus_pin = of_get_named_gpio_flags (np , "atmel,vbus-gpio" , 0 ,
1793
- & flags );
1794
- board -> vbus_active_low = (flags & OF_GPIO_ACTIVE_LOW ) ? 1 : 0 ;
1780
+ board -> vbus_pin = gpiod_get_from_of_node (np , "atmel,vbus-gpio" , 0 ,
1781
+ GPIOD_IN , "udc_vbus" );
1782
+ if (IS_ERR (board -> vbus_pin ))
1783
+ board -> vbus_pin = NULL ;
1795
1784
1796
- board -> pullup_pin = of_get_named_gpio_flags (np , "atmel,pullup-gpio" , 0 ,
1797
- & flags );
1798
-
1799
- board -> pullup_active_low = ( flags & OF_GPIO_ACTIVE_LOW ) ? 1 : 0 ;
1785
+ board -> pullup_pin = gpiod_get_from_of_node (np , "atmel,pullup-gpio" , 0 ,
1786
+ GPIOD_ASIS , "udc_pullup" );
1787
+ if ( IS_ERR ( board -> pullup_pin ))
1788
+ board -> pullup_pin = NULL ;
1800
1789
1801
1790
match = of_match_node (at91_udc_dt_ids , np );
1802
1791
if (match )
@@ -1886,22 +1875,14 @@ static int at91udc_probe(struct platform_device *pdev)
1886
1875
goto err_unprepare_iclk ;
1887
1876
}
1888
1877
1889
- if (gpio_is_valid (udc -> board .vbus_pin )) {
1890
- retval = devm_gpio_request (dev , udc -> board .vbus_pin ,
1891
- "udc_vbus" );
1892
- if (retval ) {
1893
- DBG ("request vbus pin failed\n" );
1894
- goto err_unprepare_iclk ;
1895
- }
1896
-
1897
- gpio_direction_input (udc -> board .vbus_pin );
1878
+ if (udc -> board .vbus_pin ) {
1879
+ gpiod_direction_input (udc -> board .vbus_pin );
1898
1880
1899
1881
/*
1900
1882
* Get the initial state of VBUS - we cannot expect
1901
1883
* a pending interrupt.
1902
1884
*/
1903
- udc -> vbus = gpio_get_value_cansleep (udc -> board .vbus_pin ) ^
1904
- udc -> board .vbus_active_low ;
1885
+ udc -> vbus = gpiod_get_value_cansleep (udc -> board .vbus_pin );
1905
1886
1906
1887
if (udc -> board .vbus_polled ) {
1907
1888
INIT_WORK (& udc -> vbus_timer_work , at91_vbus_timer_work );
@@ -1910,7 +1891,7 @@ static int at91udc_probe(struct platform_device *pdev)
1910
1891
jiffies + VBUS_POLL_TIMEOUT );
1911
1892
} else {
1912
1893
retval = devm_request_irq (dev ,
1913
- gpio_to_irq (udc -> board .vbus_pin ),
1894
+ gpiod_to_irq (udc -> board .vbus_pin ),
1914
1895
at91_vbus_irq , 0 , driver_name , udc );
1915
1896
if (retval ) {
1916
1897
DBG ("request vbus irq %d failed\n" ,
@@ -1988,8 +1969,8 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
1988
1969
enable_irq_wake (udc -> udp_irq );
1989
1970
1990
1971
udc -> active_suspend = wake ;
1991
- if (gpio_is_valid ( udc -> board .vbus_pin ) && !udc -> board .vbus_polled && wake )
1992
- enable_irq_wake (udc -> board .vbus_pin );
1972
+ if (udc -> board .vbus_pin && !udc -> board .vbus_polled && wake )
1973
+ enable_irq_wake (gpiod_to_irq ( udc -> board .vbus_pin ) );
1993
1974
return 0 ;
1994
1975
}
1995
1976
@@ -1998,9 +1979,9 @@ static int at91udc_resume(struct platform_device *pdev)
1998
1979
struct at91_udc * udc = platform_get_drvdata (pdev );
1999
1980
unsigned long flags ;
2000
1981
2001
- if (gpio_is_valid ( udc -> board .vbus_pin ) && !udc -> board .vbus_polled &&
1982
+ if (udc -> board .vbus_pin && !udc -> board .vbus_polled &&
2002
1983
udc -> active_suspend )
2003
- disable_irq_wake (udc -> board .vbus_pin );
1984
+ disable_irq_wake (gpiod_to_irq ( udc -> board .vbus_pin ) );
2004
1985
2005
1986
/* maybe reconnect to host; if so, clocks on */
2006
1987
if (udc -> active_suspend )
0 commit comments