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 int exynos4_usb_phy1_init(struct platform_device
*pdev
)
32 struct clk
*xusbxti_clk
;
37 atomic_inc(&host_usage
);
39 otg_clk
= clk_get(&pdev
->dev
, "otg");
40 if (IS_ERR(otg_clk
)) {
41 dev_err(&pdev
->dev
, "Failed to get otg clock\n");
42 return PTR_ERR(otg_clk
);
45 err
= clk_enable(otg_clk
);
51 if (exynos4_usb_host_phy_is_on())
54 writel(readl(S5P_USBHOST_PHY_CONTROL
) | S5P_USBHOST_PHY_ENABLE
,
55 S5P_USBHOST_PHY_CONTROL
);
57 /* set clock frequency for PLL */
58 phyclk
= readl(EXYNOS4_PHYCLK
) & ~CLKSEL_MASK
;
60 xusbxti_clk
= clk_get(&pdev
->dev
, "xusbxti");
61 if (xusbxti_clk
&& !IS_ERR(xusbxti_clk
)) {
62 switch (clk_get_rate(xusbxti_clk
)) {
71 /* default reference clock */
77 writel(phyclk
, EXYNOS4_PHYCLK
);
79 /* floating prevention logic: disable */
80 writel((readl(EXYNOS4_PHY1CON
) | FPENABLEN
), EXYNOS4_PHY1CON
);
82 /* set to normal HSIC 0 and 1 of PHY1 */
83 writel((readl(EXYNOS4_PHYPWR
) & ~PHY1_HSIC_NORMAL_MASK
),
86 /* set to normal standard USB of PHY1 */
87 writel((readl(EXYNOS4_PHYPWR
) & ~PHY1_STD_NORMAL_MASK
), EXYNOS4_PHYPWR
);
89 /* reset all ports of both PHY and Link */
90 rstcon
= readl(EXYNOS4_RSTCON
) | HOST_LINK_PORT_SWRST_MASK
|
92 writel(rstcon
, EXYNOS4_RSTCON
);
95 rstcon
&= ~(HOST_LINK_PORT_SWRST_MASK
| PHY1_SWRST_MASK
);
96 writel(rstcon
, EXYNOS4_RSTCON
);
105 static int exynos4_usb_phy1_exit(struct platform_device
*pdev
)
110 if (atomic_dec_return(&host_usage
) > 0)
113 otg_clk
= clk_get(&pdev
->dev
, "otg");
114 if (IS_ERR(otg_clk
)) {
115 dev_err(&pdev
->dev
, "Failed to get otg clock\n");
116 return PTR_ERR(otg_clk
);
119 err
= clk_enable(otg_clk
);
125 writel((readl(EXYNOS4_PHYPWR
) | PHY1_STD_ANALOG_POWERDOWN
),
128 writel(readl(S5P_USBHOST_PHY_CONTROL
) & ~S5P_USBHOST_PHY_ENABLE
,
129 S5P_USBHOST_PHY_CONTROL
);
131 clk_disable(otg_clk
);
137 int s5p_usb_phy_init(struct platform_device
*pdev
, int type
)
139 if (type
== S5P_USB_PHY_HOST
)
140 return exynos4_usb_phy1_init(pdev
);
145 int s5p_usb_phy_exit(struct platform_device
*pdev
, int type
)
147 if (type
== S5P_USB_PHY_HOST
)
148 return exynos4_usb_phy1_exit(pdev
);