[PATCH v2 27/42] usb: gadget: at91_udc: add usb_clk for transition to common clk framework
From: Boris BREZILLON
Date: Wed Jul 17 2013 - 11:49:47 EST
The AT91 PMC (Power Management Controller) provides an USB clock used by
USB Full Speed host (ohci) and USB Full Speed device (udc).
The usb drivers (ohci and udc) must configure this clock to 48Mhz.
This configuration was formely done in mach-at91/clock.c, but this
implementation will be removed when moving to common clk framework.
This patch add support for usb clock retrieval and configuration.
Signed-off-by: Boris BREZILLON <b.brezillon@xxxxxxxxxxx>
---
drivers/usb/gadget/at91_udc.c | 31 ++++++++++++++++++++++++++-----
drivers/usb/gadget/at91_udc.h | 2 +-
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index fce8e4e..05aac04 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -870,6 +870,8 @@ static void clk_on(struct at91_udc *udc)
if (udc->clocked)
return;
udc->clocked = 1;
+ clk_set_rate(udc->uclk, 48000000);
+ clk_prepare_enable(udc->uclk);
clk_prepare_enable(udc->iclk);
clk_prepare_enable(udc->fclk);
}
@@ -882,6 +884,7 @@ static void clk_off(struct at91_udc *udc)
udc->gadget.speed = USB_SPEED_UNKNOWN;
clk_disable_unprepare(udc->fclk);
clk_disable_unprepare(udc->iclk);
+ clk_disable_unprepare(udc->uclk);
}
/*
@@ -1773,18 +1776,28 @@ static int at91udc_probe(struct platform_device *pdev)
/* get interface and function clocks */
udc->iclk = clk_get(dev, "udc_clk");
- udc->fclk = clk_get(dev, "udpck");
- if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
- DBG("clocks missing\n");
+ if (IS_ERR(udc->iclk)) {
+ DBG("interface clock missing\n");
retval = -ENODEV;
- /* NOTE: we "know" here that refcounts on these are NOPs */
goto fail1;
}
+ udc->fclk = clk_get(dev, "udpck");
+ if (IS_ERR(udc->fclk)) {
+ DBG("function clock missing\n");
+ retval = -ENODEV;
+ goto fail1a;
+ }
+ udc->uclk = clk_get(dev, "usb_clk");
+ if (IS_ERR(udc->uclk)) {
+ DBG("usb clock missing\n");
+ retval = -ENODEV;
+ goto fail1b;
+ }
/* don't do anything until we have both gadget driver and VBUS */
retval = clk_prepare_enable(udc->iclk);
if (retval)
- goto fail1;
+ goto fail1c;
at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff);
/* Clear all pending interrupts - UDP may be used by bootloader. */
@@ -1850,6 +1863,13 @@ fail3:
gpio_free(udc->board.vbus_pin);
fail2:
free_irq(udc->udp_irq, udc);
+
+fail1c:
+ clk_put(udc->uclk);
+fail1b:
+ clk_put(udc->fclk);
+fail1a:
+ clk_put(udc->iclk);
fail1:
iounmap(udc->udp_baseaddr);
fail0a:
@@ -1894,6 +1914,7 @@ static int __exit at91udc_remove(struct platform_device *pdev)
clk_put(udc->iclk);
clk_put(udc->fclk);
+ clk_put(udc->uclk);
return 0;
}
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index e647d1c..0175246 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -126,7 +126,7 @@ struct at91_udc {
unsigned active_suspend:1;
u8 addr;
struct at91_udc_data board;
- struct clk *iclk, *fclk;
+ struct clk *iclk, *fclk, *uclk;
struct platform_device *pdev;
struct proc_dir_entry *pde;
void __iomem *udp_baseaddr;
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/