2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
3 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
12 #include <linux/clk.h>
13 #include <linux/delay.h>
14 #include <linux/err.h>
16 #include <linux/platform_device.h>
17 #include <mach/regs-pmu.h>
18 #include <mach/regs-usb-phy.h>
20 #include <plat/usb-phy.h>
22 static atomic_t host_usage;
24 static int exynos4_usb_host_phy_is_on(void)
26 return (readl(EXYNOS4_PHYPWR) & PHY1_STD_ANALOG_POWERDOWN) ? 0 : 1;
29 static void exynos4210_usb_phy_clkset(struct platform_device *pdev)
31 struct clk *xusbxti_clk;
34 /* set clock frequency for PLL */
35 phyclk = readl(EXYNOS4_PHYCLK) & ~CLKSEL_MASK;
37 xusbxti_clk = clk_get(&pdev->dev, "xusbxti");
38 if (xusbxti_clk && !IS_ERR(xusbxti_clk)) {
39 switch (clk_get_rate(xusbxti_clk)) {
48 /* default reference clock */
54 writel(phyclk, EXYNOS4_PHYCLK);
57 static int exynos4210_usb_phy0_init(struct platform_device *pdev)
61 writel(readl(S5P_USBDEVICE_PHY_CONTROL) | S5P_USBDEVICE_PHY_ENABLE,
62 S5P_USBDEVICE_PHY_CONTROL);
64 exynos4210_usb_phy_clkset(pdev);
66 /* set to normal PHY0 */
67 writel((readl(EXYNOS4_PHYPWR) & ~PHY0_NORMAL_MASK), EXYNOS4_PHYPWR);
69 /* reset PHY0 and Link */
70 rstcon = readl(EXYNOS4_RSTCON) | PHY0_SWRST_MASK;
71 writel(rstcon, EXYNOS4_RSTCON);
74 rstcon &= ~PHY0_SWRST_MASK;
75 writel(rstcon, EXYNOS4_RSTCON);
80 static int exynos4210_usb_phy0_exit(struct platform_device *pdev)
82 writel((readl(EXYNOS4_PHYPWR) | PHY0_ANALOG_POWERDOWN |
83 PHY0_OTG_DISABLE), EXYNOS4_PHYPWR);
85 writel(readl(S5P_USBDEVICE_PHY_CONTROL) & ~S5P_USBDEVICE_PHY_ENABLE,
86 S5P_USBDEVICE_PHY_CONTROL);
91 static int exynos4210_usb_phy1_init(struct platform_device *pdev)
97 atomic_inc(&host_usage);
99 otg_clk = clk_get(&pdev->dev, "otg");
100 if (IS_ERR(otg_clk)) {
101 dev_err(&pdev->dev, "Failed to get otg clock\n");
102 return PTR_ERR(otg_clk);
105 err = clk_enable(otg_clk);
111 if (exynos4_usb_host_phy_is_on())
114 writel(readl(S5P_USBHOST_PHY_CONTROL) | S5P_USBHOST_PHY_ENABLE,
115 S5P_USBHOST_PHY_CONTROL);
117 exynos4210_usb_phy_clkset(pdev);
119 /* floating prevention logic: disable */
120 writel((readl(EXYNOS4_PHY1CON) | FPENABLEN), EXYNOS4_PHY1CON);
122 /* set to normal HSIC 0 and 1 of PHY1 */
123 writel((readl(EXYNOS4_PHYPWR) & ~PHY1_HSIC_NORMAL_MASK),
126 /* set to normal standard USB of PHY1 */
127 writel((readl(EXYNOS4_PHYPWR) & ~PHY1_STD_NORMAL_MASK), EXYNOS4_PHYPWR);
129 /* reset all ports of both PHY and Link */
130 rstcon = readl(EXYNOS4_RSTCON) | HOST_LINK_PORT_SWRST_MASK |
132 writel(rstcon, EXYNOS4_RSTCON);
135 rstcon &= ~(HOST_LINK_PORT_SWRST_MASK | PHY1_SWRST_MASK);
136 writel(rstcon, EXYNOS4_RSTCON);
139 clk_disable(otg_clk);
145 static int exynos4210_usb_phy1_exit(struct platform_device *pdev)
150 if (atomic_dec_return(&host_usage) > 0)
153 otg_clk = clk_get(&pdev->dev, "otg");
154 if (IS_ERR(otg_clk)) {
155 dev_err(&pdev->dev, "Failed to get otg clock\n");
156 return PTR_ERR(otg_clk);
159 err = clk_enable(otg_clk);
165 writel((readl(EXYNOS4_PHYPWR) | PHY1_STD_ANALOG_POWERDOWN),
168 writel(readl(S5P_USBHOST_PHY_CONTROL) & ~S5P_USBHOST_PHY_ENABLE,
169 S5P_USBHOST_PHY_CONTROL);
171 clk_disable(otg_clk);
177 int s5p_usb_phy_init(struct platform_device *pdev, int type)
179 if (type == S5P_USB_PHY_DEVICE)
180 return exynos4210_usb_phy0_init(pdev);
181 else if (type == S5P_USB_PHY_HOST)
182 return exynos4210_usb_phy1_init(pdev);
187 int s5p_usb_phy_exit(struct platform_device *pdev, int type)
189 if (type == S5P_USB_PHY_DEVICE)
190 return exynos4210_usb_phy0_exit(pdev);
191 else if (type == S5P_USB_PHY_HOST)
192 return exynos4210_usb_phy1_exit(pdev);