Commit 422cde25 authored by Boris Brezillon's avatar Boris Brezillon Committed by Nicolas Ferre

usb: gadget: at91_udc: Simplify probe and remove functions

Make use of devm_ functions to simplify probe and remove code.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarNicolas Ferre <nicolas.ferre@atmel.com>
parent 9f00fc1d
...@@ -1710,15 +1710,6 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1710,15 +1710,6 @@ static int at91udc_probe(struct platform_device *pdev)
int retval; int retval;
struct resource *res; struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENXIO;
if (!request_mem_region(res->start, resource_size(res), driver_name)) {
DBG("someone's using UDC memory\n");
return -EBUSY;
}
/* init software state */ /* init software state */
udc = &controller; udc = &controller;
udc->gadget.dev.parent = dev; udc->gadget.dev.parent = dev;
...@@ -1731,13 +1722,13 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1731,13 +1722,13 @@ static int at91udc_probe(struct platform_device *pdev)
if (cpu_is_at91rm9200()) { if (cpu_is_at91rm9200()) {
if (!gpio_is_valid(udc->board.pullup_pin)) { if (!gpio_is_valid(udc->board.pullup_pin)) {
DBG("no D+ pullup?\n"); DBG("no D+ pullup?\n");
retval = -ENODEV; return -ENODEV;
goto fail0;
} }
retval = gpio_request(udc->board.pullup_pin, "udc_pullup"); retval = devm_gpio_request(dev, udc->board.pullup_pin,
"udc_pullup");
if (retval) { if (retval) {
DBG("D+ pullup is busy\n"); DBG("D+ pullup is busy\n");
goto fail0; return retval;
} }
gpio_direction_output(udc->board.pullup_pin, gpio_direction_output(udc->board.pullup_pin,
udc->board.pullup_active_low); udc->board.pullup_active_low);
...@@ -1756,32 +1747,32 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1756,32 +1747,32 @@ static int at91udc_probe(struct platform_device *pdev)
udc->ep[3].maxpacket = 64; udc->ep[3].maxpacket = 64;
} }
udc->udp_baseaddr = ioremap(res->start, resource_size(res)); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!udc->udp_baseaddr) { udc->udp_baseaddr = devm_ioremap_resource(dev, res);
retval = -ENOMEM; if (IS_ERR(udc->udp_baseaddr))
goto fail0a; return PTR_ERR(udc->udp_baseaddr);
}
udc_reinit(udc); udc_reinit(udc);
/* get interface and function clocks */ /* get interface and function clocks */
udc->iclk = clk_get(dev, "pclk"); udc->iclk = devm_clk_get(dev, "pclk");
udc->fclk = clk_get(dev, "hclk"); if (IS_ERR(udc->iclk))
if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { return PTR_ERR(udc->iclk);
DBG("clocks missing\n");
retval = -ENODEV; udc->fclk = devm_clk_get(dev, "hclk");
goto fail1; if (IS_ERR(udc->fclk))
} return PTR_ERR(udc->fclk);
/* don't do anything until we have both gadget driver and VBUS */ /* don't do anything until we have both gadget driver and VBUS */
clk_set_rate(udc->fclk, 48000000); clk_set_rate(udc->fclk, 48000000);
retval = clk_prepare(udc->fclk); retval = clk_prepare(udc->fclk);
if (retval) if (retval)
goto fail1; return retval;
retval = clk_prepare_enable(udc->iclk); retval = clk_prepare_enable(udc->iclk);
if (retval) if (retval)
goto fail1b; goto err_unprepare_fclk;
at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff); at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff);
/* Clear all pending interrupts - UDP may be used by bootloader. */ /* Clear all pending interrupts - UDP may be used by bootloader. */
...@@ -1790,18 +1781,21 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1790,18 +1781,21 @@ static int at91udc_probe(struct platform_device *pdev)
/* request UDC and maybe VBUS irqs */ /* request UDC and maybe VBUS irqs */
udc->udp_irq = platform_get_irq(pdev, 0); udc->udp_irq = platform_get_irq(pdev, 0);
retval = request_irq(udc->udp_irq, at91_udc_irq, retval = devm_request_irq(dev, udc->udp_irq, at91_udc_irq, 0,
0, driver_name, udc); driver_name, udc);
if (retval < 0) { if (retval) {
DBG("request irq %d failed\n", udc->udp_irq); DBG("request irq %d failed\n", udc->udp_irq);
goto fail1c; goto err_unprepare_iclk;
} }
if (gpio_is_valid(udc->board.vbus_pin)) { if (gpio_is_valid(udc->board.vbus_pin)) {
retval = gpio_request(udc->board.vbus_pin, "udc_vbus"); retval = devm_gpio_request(dev, udc->board.vbus_pin,
if (retval < 0) { "udc_vbus");
if (retval) {
DBG("request vbus pin failed\n"); DBG("request vbus pin failed\n");
goto fail2; goto err_unprepare_iclk;
} }
gpio_direction_input(udc->board.vbus_pin); gpio_direction_input(udc->board.vbus_pin);
/* /*
...@@ -1818,12 +1812,13 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1818,12 +1812,13 @@ static int at91udc_probe(struct platform_device *pdev)
mod_timer(&udc->vbus_timer, mod_timer(&udc->vbus_timer,
jiffies + VBUS_POLL_TIMEOUT); jiffies + VBUS_POLL_TIMEOUT);
} else { } else {
if (request_irq(gpio_to_irq(udc->board.vbus_pin), retval = devm_request_irq(dev,
at91_vbus_irq, 0, driver_name, udc)) { gpio_to_irq(udc->board.vbus_pin),
at91_vbus_irq, 0, driver_name, udc);
if (retval) {
DBG("request vbus irq %d failed\n", DBG("request vbus irq %d failed\n",
udc->board.vbus_pin); udc->board.vbus_pin);
retval = -EBUSY; goto err_unprepare_iclk;
goto fail3;
} }
} }
} else { } else {
...@@ -1832,44 +1827,27 @@ static int at91udc_probe(struct platform_device *pdev) ...@@ -1832,44 +1827,27 @@ static int at91udc_probe(struct platform_device *pdev)
} }
retval = usb_add_gadget_udc(dev, &udc->gadget); retval = usb_add_gadget_udc(dev, &udc->gadget);
if (retval) if (retval)
goto fail4; goto err_unprepare_iclk;
dev_set_drvdata(dev, udc); dev_set_drvdata(dev, udc);
device_init_wakeup(dev, 1); device_init_wakeup(dev, 1);
create_debug_file(udc); create_debug_file(udc);
INFO("%s version %s\n", driver_name, DRIVER_VERSION); INFO("%s version %s\n", driver_name, DRIVER_VERSION);
return 0; return 0;
fail4:
if (gpio_is_valid(udc->board.vbus_pin) && !udc->board.vbus_polled) err_unprepare_iclk:
free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
fail3:
if (gpio_is_valid(udc->board.vbus_pin))
gpio_free(udc->board.vbus_pin);
fail2:
free_irq(udc->udp_irq, udc);
fail1c:
clk_unprepare(udc->iclk); clk_unprepare(udc->iclk);
fail1b: err_unprepare_fclk:
clk_unprepare(udc->fclk); clk_unprepare(udc->fclk);
fail1:
if (!IS_ERR(udc->fclk))
clk_put(udc->fclk);
if (!IS_ERR(udc->iclk))
clk_put(udc->iclk);
iounmap(udc->udp_baseaddr);
fail0a:
if (cpu_is_at91rm9200())
gpio_free(udc->board.pullup_pin);
fail0:
release_mem_region(res->start, resource_size(res));
DBG("%s probe failed, %d\n", driver_name, retval); DBG("%s probe failed, %d\n", driver_name, retval);
return retval; return retval;
} }
static int __exit at91udc_remove(struct platform_device *pdev) static int __exit at91udc_remove(struct platform_device *pdev)
{ {
struct at91_udc *udc = platform_get_drvdata(pdev); struct at91_udc *udc = platform_get_drvdata(pdev);
struct resource *res;
unsigned long flags; unsigned long flags;
DBG("remove\n"); DBG("remove\n");
...@@ -1884,25 +1862,9 @@ static int __exit at91udc_remove(struct platform_device *pdev) ...@@ -1884,25 +1862,9 @@ static int __exit at91udc_remove(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 0); device_init_wakeup(&pdev->dev, 0);
remove_debug_file(udc); remove_debug_file(udc);
if (gpio_is_valid(udc->board.vbus_pin)) {
free_irq(gpio_to_irq(udc->board.vbus_pin), udc);
gpio_free(udc->board.vbus_pin);
}
free_irq(udc->udp_irq, udc);
iounmap(udc->udp_baseaddr);
if (cpu_is_at91rm9200())
gpio_free(udc->board.pullup_pin);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
clk_unprepare(udc->fclk); clk_unprepare(udc->fclk);
clk_unprepare(udc->iclk); clk_unprepare(udc->iclk);
clk_put(udc->iclk);
clk_put(udc->fclk);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment