浏览代码

usb: gadget: at91_udc: add usb_clk for transition to common clk framework

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 adds support for usb clock retrieval and configuration, and is
backward compatible with the current at91 clk implementation (if usb clk
is not found, it does not configure/enable it).

Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Boris BREZILLON 12 年之前
父节点
当前提交
c0aefc75ce
共有 2 个文件被更改,包括 16 次插入3 次删除
  1. 15 2
      drivers/usb/gadget/at91_udc.c
  2. 1 1
      drivers/usb/gadget/at91_udc.h

+ 15 - 2
drivers/usb/gadget/at91_udc.c

@@ -870,6 +870,11 @@ static void clk_on(struct at91_udc *udc)
 	if (udc->clocked)
 	if (udc->clocked)
 		return;
 		return;
 	udc->clocked = 1;
 	udc->clocked = 1;
+
+	if (IS_ENABLED(CONFIG_COMMON_CLK)) {
+		clk_set_rate(udc->uclk, 48000000);
+		clk_prepare_enable(udc->uclk);
+	}
 	clk_prepare_enable(udc->iclk);
 	clk_prepare_enable(udc->iclk);
 	clk_prepare_enable(udc->fclk);
 	clk_prepare_enable(udc->fclk);
 }
 }
@@ -882,6 +887,8 @@ static void clk_off(struct at91_udc *udc)
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
 	clk_disable_unprepare(udc->fclk);
 	clk_disable_unprepare(udc->fclk);
 	clk_disable_unprepare(udc->iclk);
 	clk_disable_unprepare(udc->iclk);
+	if (IS_ENABLED(CONFIG_COMMON_CLK))
+		clk_disable_unprepare(udc->uclk);
 }
 }
 
 
 /*
 /*
@@ -1774,10 +1781,12 @@ static int at91udc_probe(struct platform_device *pdev)
 	/* get interface and function clocks */
 	/* get interface and function clocks */
 	udc->iclk = clk_get(dev, "udc_clk");
 	udc->iclk = clk_get(dev, "udc_clk");
 	udc->fclk = clk_get(dev, "udpck");
 	udc->fclk = clk_get(dev, "udpck");
-	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
+	if (IS_ENABLED(CONFIG_COMMON_CLK))
+		udc->uclk = clk_get(dev, "usb_clk");
+	if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
+	    (IS_ENABLED(CONFIG_COMMON_CLK) && IS_ERR(udc->uclk))) {
 		DBG("clocks missing\n");
 		DBG("clocks missing\n");
 		retval = -ENODEV;
 		retval = -ENODEV;
-		/* NOTE: we "know" here that refcounts on these are NOPs */
 		goto fail1;
 		goto fail1;
 	}
 	}
 
 
@@ -1851,6 +1860,8 @@ fail3:
 fail2:
 fail2:
 	free_irq(udc->udp_irq, udc);
 	free_irq(udc->udp_irq, udc);
 fail1:
 fail1:
+	if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk))
+		clk_put(udc->uclk);
 	if (!IS_ERR(udc->fclk))
 	if (!IS_ERR(udc->fclk))
 		clk_put(udc->fclk);
 		clk_put(udc->fclk);
 	if (!IS_ERR(udc->iclk))
 	if (!IS_ERR(udc->iclk))
@@ -1898,6 +1909,8 @@ static int __exit at91udc_remove(struct platform_device *pdev)
 
 
 	clk_put(udc->iclk);
 	clk_put(udc->iclk);
 	clk_put(udc->fclk);
 	clk_put(udc->fclk);
+	if (IS_ENABLED(CONFIG_COMMON_CLK))
+		clk_put(udc->uclk);
 
 
 	return 0;
 	return 0;
 }
 }

+ 1 - 1
drivers/usb/gadget/at91_udc.h

@@ -126,7 +126,7 @@ struct at91_udc {
 	unsigned			active_suspend:1;
 	unsigned			active_suspend:1;
 	u8				addr;
 	u8				addr;
 	struct at91_udc_data		board;
 	struct at91_udc_data		board;
-	struct clk			*iclk, *fclk;
+	struct clk			*iclk, *fclk, *uclk;
 	struct platform_device		*pdev;
 	struct platform_device		*pdev;
 	struct proc_dir_entry		*pde;
 	struct proc_dir_entry		*pde;
 	void __iomem			*udp_baseaddr;
 	void __iomem			*udp_baseaddr;