Skip to content

Commit 4a555f2

Browse files
bala-gunasundargregkh
authored andcommitted
usb: gadget: at91_udc: Convert to GPIO descriptors
Replace the legacy GPIO APIs with gpio descriptor consumer interface. Remove all gpio inversion(active low) flags as it is already handled by the gpiod_set_value() and gpiod_get_value() functions. Reviewed-by: Dan Sneddon <[email protected]> Signed-off-by: Balamanikandan Gunasundar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 16d4275 commit 4a555f2

File tree

2 files changed

+27
-48
lines changed

2 files changed

+27
-48
lines changed

drivers/usb/gadget/udc/at91_udc.c

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <linux/usb/ch9.h>
2626
#include <linux/usb/gadget.h>
2727
#include <linux/of.h>
28-
#include <linux/of_gpio.h>
28+
#include <linux/gpio/consumer.h>
2929
#include <linux/platform_data/atmel.h>
3030
#include <linux/regmap.h>
3131
#include <linux/mfd/syscon.h>
@@ -1510,7 +1510,6 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
15101510

15111511
static void at91_vbus_update(struct at91_udc *udc, unsigned value)
15121512
{
1513-
value ^= udc->board.vbus_active_low;
15141513
if (value != udc->vbus)
15151514
at91_vbus_session(&udc->gadget, value);
15161515
}
@@ -1521,7 +1520,7 @@ static irqreturn_t at91_vbus_irq(int irq, void *_udc)
15211520

15221521
/* vbus needs at least brief debouncing */
15231522
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));
15251524

15261525
return IRQ_HANDLED;
15271526
}
@@ -1531,7 +1530,7 @@ static void at91_vbus_timer_work(struct work_struct *work)
15311530
struct at91_udc *udc = container_of(work, struct at91_udc,
15321531
vbus_timer_work);
15331532

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));
15351534

15361535
if (!timer_pending(&udc->vbus_timer))
15371536
mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT);
@@ -1595,7 +1594,6 @@ static void at91udc_shutdown(struct platform_device *dev)
15951594
static int at91rm9200_udc_init(struct at91_udc *udc)
15961595
{
15971596
struct at91_ep *ep;
1598-
int ret;
15991597
int i;
16001598

16011599
for (i = 0; i < NUM_ENDPOINTS; i++) {
@@ -1615,32 +1613,23 @@ static int at91rm9200_udc_init(struct at91_udc *udc)
16151613
}
16161614
}
16171615

1618-
if (!gpio_is_valid(udc->board.pullup_pin)) {
1616+
if (!udc->board.pullup_pin) {
16191617
DBG("no D+ pullup?\n");
16201618
return -ENODEV;
16211619
}
16221620

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));
16321623

16331624
return 0;
16341625
}
16351626

16361627
static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)
16371628
{
1638-
int active = !udc->board.pullup_active_low;
1639-
16401629
if (is_on)
1641-
gpio_set_value(udc->board.pullup_pin, active);
1630+
gpiod_set_value(udc->board.pullup_pin, 1);
16421631
else
1643-
gpio_set_value(udc->board.pullup_pin, !active);
1632+
gpiod_set_value(udc->board.pullup_pin, 0);
16441633
}
16451634

16461635
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)
17831772
{
17841773
struct at91_udc_data *board = &udc->board;
17851774
const struct of_device_id *match;
1786-
enum of_gpio_flags flags;
17871775
u32 val;
17881776

17891777
if (of_property_read_u32(np, "atmel,vbus-polled", &val) == 0)
17901778
board->vbus_polled = 1;
17911779

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;
17951784

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;
18001789

18011790
match = of_match_node(at91_udc_dt_ids, np);
18021791
if (match)
@@ -1886,22 +1875,14 @@ static int at91udc_probe(struct platform_device *pdev)
18861875
goto err_unprepare_iclk;
18871876
}
18881877

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);
18981880

18991881
/*
19001882
* Get the initial state of VBUS - we cannot expect
19011883
* a pending interrupt.
19021884
*/
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);
19051886

19061887
if (udc->board.vbus_polled) {
19071888
INIT_WORK(&udc->vbus_timer_work, at91_vbus_timer_work);
@@ -1910,7 +1891,7 @@ static int at91udc_probe(struct platform_device *pdev)
19101891
jiffies + VBUS_POLL_TIMEOUT);
19111892
} else {
19121893
retval = devm_request_irq(dev,
1913-
gpio_to_irq(udc->board.vbus_pin),
1894+
gpiod_to_irq(udc->board.vbus_pin),
19141895
at91_vbus_irq, 0, driver_name, udc);
19151896
if (retval) {
19161897
DBG("request vbus irq %d failed\n",
@@ -1988,8 +1969,8 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
19881969
enable_irq_wake(udc->udp_irq);
19891970

19901971
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));
19931974
return 0;
19941975
}
19951976

@@ -1998,9 +1979,9 @@ static int at91udc_resume(struct platform_device *pdev)
19981979
struct at91_udc *udc = platform_get_drvdata(pdev);
19991980
unsigned long flags;
20001981

2001-
if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled &&
1982+
if (udc->board.vbus_pin && !udc->board.vbus_polled &&
20021983
udc->active_suspend)
2003-
disable_irq_wake(udc->board.vbus_pin);
1984+
disable_irq_wake(gpiod_to_irq(udc->board.vbus_pin));
20041985

20051986
/* maybe reconnect to host; if so, clocks on */
20061987
if (udc->active_suspend)

drivers/usb/gadget/udc/at91_udc.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ struct at91_udc_caps {
109109
};
110110

111111
struct at91_udc_data {
112-
int vbus_pin; /* high == host powering us */
113-
u8 vbus_active_low; /* vbus polarity */
114-
u8 vbus_polled; /* Use polling, not interrupt */
115-
int pullup_pin; /* active == D+ pulled up */
116-
u8 pullup_active_low; /* true == pullup_pin is active low */
112+
struct gpio_desc *vbus_pin; /* high == host powering us */
113+
u8 vbus_polled; /* Use polling, not interrupt */
114+
struct gpio_desc *pullup_pin; /* active == D+ pulled up */
117115
};
118116

119117
/*

0 commit comments

Comments
 (0)