2 * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 4210 support
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * Author: Kamil Debski <k.debski@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/delay.h>
14 #include <linux/phy/phy.h>
15 #include <linux/regmap.h>
16 #include "phy-samsung-usb2.h"
18 /* Exynos USB PHY registers */
20 /* PHY power control */
21 #define EXYNOS_4210_UPHYPWR 0x0
23 #define EXYNOS_4210_UPHYPWR_PHY0_SUSPEND BIT(0)
24 #define EXYNOS_4210_UPHYPWR_PHY0_PWR BIT(3)
25 #define EXYNOS_4210_UPHYPWR_PHY0_OTG_PWR BIT(4)
26 #define EXYNOS_4210_UPHYPWR_PHY0_SLEEP BIT(5)
27 #define EXYNOS_4210_UPHYPWR_PHY0 ( \
28 EXYNOS_4210_UPHYPWR_PHY0_SUSPEND | \
29 EXYNOS_4210_UPHYPWR_PHY0_PWR | \
30 EXYNOS_4210_UPHYPWR_PHY0_OTG_PWR | \
31 EXYNOS_4210_UPHYPWR_PHY0_SLEEP)
33 #define EXYNOS_4210_UPHYPWR_PHY1_SUSPEND BIT(6)
34 #define EXYNOS_4210_UPHYPWR_PHY1_PWR BIT(7)
35 #define EXYNOS_4210_UPHYPWR_PHY1_SLEEP BIT(8)
36 #define EXYNOS_4210_UPHYPWR_PHY1 ( \
37 EXYNOS_4210_UPHYPWR_PHY1_SUSPEND | \
38 EXYNOS_4210_UPHYPWR_PHY1_PWR | \
39 EXYNOS_4210_UPHYPWR_PHY1_SLEEP)
41 #define EXYNOS_4210_UPHYPWR_HSIC0_SUSPEND BIT(9)
42 #define EXYNOS_4210_UPHYPWR_HSIC0_SLEEP BIT(10)
43 #define EXYNOS_4210_UPHYPWR_HSIC0 ( \
44 EXYNOS_4210_UPHYPWR_HSIC0_SUSPEND | \
45 EXYNOS_4210_UPHYPWR_HSIC0_SLEEP)
47 #define EXYNOS_4210_UPHYPWR_HSIC1_SUSPEND BIT(11)
48 #define EXYNOS_4210_UPHYPWR_HSIC1_SLEEP BIT(12)
49 #define EXYNOS_4210_UPHYPWR_HSIC1 ( \
50 EXYNOS_4210_UPHYPWR_HSIC1_SUSPEND | \
51 EXYNOS_4210_UPHYPWR_HSIC1_SLEEP)
53 /* PHY clock control */
54 #define EXYNOS_4210_UPHYCLK 0x4
56 #define EXYNOS_4210_UPHYCLK_PHYFSEL_MASK (0x3 << 0)
57 #define EXYNOS_4210_UPHYCLK_PHYFSEL_OFFSET 0
58 #define EXYNOS_4210_UPHYCLK_PHYFSEL_48MHZ (0x0 << 0)
59 #define EXYNOS_4210_UPHYCLK_PHYFSEL_24MHZ (0x3 << 0)
60 #define EXYNOS_4210_UPHYCLK_PHYFSEL_12MHZ (0x2 << 0)
62 #define EXYNOS_4210_UPHYCLK_PHY0_ID_PULLUP BIT(2)
63 #define EXYNOS_4210_UPHYCLK_PHY0_COMMON_ON BIT(4)
64 #define EXYNOS_4210_UPHYCLK_PHY1_COMMON_ON BIT(7)
66 /* PHY reset control */
67 #define EXYNOS_4210_UPHYRST 0x8
69 #define EXYNOS_4210_URSTCON_PHY0 BIT(0)
70 #define EXYNOS_4210_URSTCON_OTG_HLINK BIT(1)
71 #define EXYNOS_4210_URSTCON_OTG_PHYLINK BIT(2)
72 #define EXYNOS_4210_URSTCON_PHY1_ALL BIT(3)
73 #define EXYNOS_4210_URSTCON_PHY1_P0 BIT(4)
74 #define EXYNOS_4210_URSTCON_PHY1_P1P2 BIT(5)
75 #define EXYNOS_4210_URSTCON_HOST_LINK_ALL BIT(6)
76 #define EXYNOS_4210_URSTCON_HOST_LINK_P0 BIT(7)
77 #define EXYNOS_4210_URSTCON_HOST_LINK_P1 BIT(8)
78 #define EXYNOS_4210_URSTCON_HOST_LINK_P2 BIT(9)
80 /* Isolation, configured in the power management unit */
81 #define EXYNOS_4210_USB_ISOL_DEVICE_OFFSET 0x704
82 #define EXYNOS_4210_USB_ISOL_DEVICE BIT(0)
83 #define EXYNOS_4210_USB_ISOL_HOST_OFFSET 0x708
84 #define EXYNOS_4210_USB_ISOL_HOST BIT(0)
86 /* USBYPHY1 Floating prevention */
87 #define EXYNOS_4210_UPHY1CON 0x34
88 #define EXYNOS_4210_UPHY1CON_FLOAT_PREVENTION 0x1
90 /* Mode switching SUB Device <-> Host */
91 #define EXYNOS_4210_MODE_SWITCH_OFFSET 0x21c
92 #define EXYNOS_4210_MODE_SWITCH_MASK 1
93 #define EXYNOS_4210_MODE_SWITCH_DEVICE 0
94 #define EXYNOS_4210_MODE_SWITCH_HOST 1
96 enum exynos4210_phy_id
{
105 * exynos4210_rate_to_clk() converts the supplied clock rate to the value that
106 * can be written to the phy register.
108 static int exynos4210_rate_to_clk(unsigned long rate
, u32
*reg
)
112 *reg
= EXYNOS_4210_UPHYCLK_PHYFSEL_12MHZ
;
115 *reg
= EXYNOS_4210_UPHYCLK_PHYFSEL_24MHZ
;
118 *reg
= EXYNOS_4210_UPHYCLK_PHYFSEL_48MHZ
;
127 static void exynos4210_isol(struct samsung_usb2_phy_instance
*inst
, bool on
)
129 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
133 switch (inst
->cfg
->id
) {
134 case EXYNOS4210_DEVICE
:
135 offset
= EXYNOS_4210_USB_ISOL_DEVICE_OFFSET
;
136 mask
= EXYNOS_4210_USB_ISOL_DEVICE
;
138 case EXYNOS4210_HOST
:
139 offset
= EXYNOS_4210_USB_ISOL_HOST_OFFSET
;
140 mask
= EXYNOS_4210_USB_ISOL_HOST
;
146 regmap_update_bits(drv
->reg_pmu
, offset
, mask
, on
? 0 : mask
);
149 static void exynos4210_phy_pwr(struct samsung_usb2_phy_instance
*inst
, bool on
)
151 struct samsung_usb2_phy_driver
*drv
= inst
->drv
;
158 switch (inst
->cfg
->id
) {
159 case EXYNOS4210_DEVICE
:
160 phypwr
= EXYNOS_4210_UPHYPWR_PHY0
;
161 rstbits
= EXYNOS_4210_URSTCON_PHY0
;
163 case EXYNOS4210_HOST
:
164 phypwr
= EXYNOS_4210_UPHYPWR_PHY1
;
165 rstbits
= EXYNOS_4210_URSTCON_PHY1_ALL
|
166 EXYNOS_4210_URSTCON_PHY1_P0
|
167 EXYNOS_4210_URSTCON_PHY1_P1P2
|
168 EXYNOS_4210_URSTCON_HOST_LINK_ALL
|
169 EXYNOS_4210_URSTCON_HOST_LINK_P0
;
170 writel(on
, drv
->reg_phy
+ EXYNOS_4210_UPHY1CON
);
172 case EXYNOS4210_HSIC0
:
173 phypwr
= EXYNOS_4210_UPHYPWR_HSIC0
;
174 rstbits
= EXYNOS_4210_URSTCON_PHY1_P1P2
|
175 EXYNOS_4210_URSTCON_HOST_LINK_P1
;
177 case EXYNOS4210_HSIC1
:
178 phypwr
= EXYNOS_4210_UPHYPWR_HSIC1
;
179 rstbits
= EXYNOS_4210_URSTCON_PHY1_P1P2
|
180 EXYNOS_4210_URSTCON_HOST_LINK_P2
;
185 clk
= readl(drv
->reg_phy
+ EXYNOS_4210_UPHYCLK
);
186 clk
&= ~EXYNOS_4210_UPHYCLK_PHYFSEL_MASK
;
187 clk
|= drv
->ref_reg_val
<< EXYNOS_4210_UPHYCLK_PHYFSEL_OFFSET
;
188 writel(clk
, drv
->reg_phy
+ EXYNOS_4210_UPHYCLK
);
190 pwr
= readl(drv
->reg_phy
+ EXYNOS_4210_UPHYPWR
);
192 writel(pwr
, drv
->reg_phy
+ EXYNOS_4210_UPHYPWR
);
194 rst
= readl(drv
->reg_phy
+ EXYNOS_4210_UPHYRST
);
196 writel(rst
, drv
->reg_phy
+ EXYNOS_4210_UPHYRST
);
199 writel(rst
, drv
->reg_phy
+ EXYNOS_4210_UPHYRST
);
200 /* The following delay is necessary for the reset sequence to be
204 pwr
= readl(drv
->reg_phy
+ EXYNOS_4210_UPHYPWR
);
206 writel(pwr
, drv
->reg_phy
+ EXYNOS_4210_UPHYPWR
);
210 static int exynos4210_power_on(struct samsung_usb2_phy_instance
*inst
)
212 /* Order of initialisation is important - first power then isolation */
213 exynos4210_phy_pwr(inst
, 1);
214 exynos4210_isol(inst
, 0);
219 static int exynos4210_power_off(struct samsung_usb2_phy_instance
*inst
)
221 exynos4210_isol(inst
, 1);
222 exynos4210_phy_pwr(inst
, 0);
228 static const struct samsung_usb2_common_phy exynos4210_phys
[] = {
231 .id
= EXYNOS4210_DEVICE
,
232 .power_on
= exynos4210_power_on
,
233 .power_off
= exynos4210_power_off
,
237 .id
= EXYNOS4210_HOST
,
238 .power_on
= exynos4210_power_on
,
239 .power_off
= exynos4210_power_off
,
243 .id
= EXYNOS4210_HSIC0
,
244 .power_on
= exynos4210_power_on
,
245 .power_off
= exynos4210_power_off
,
249 .id
= EXYNOS4210_HSIC1
,
250 .power_on
= exynos4210_power_on
,
251 .power_off
= exynos4210_power_off
,
255 const struct samsung_usb2_phy_config exynos4210_usb2_phy_config
= {
256 .has_mode_switch
= 0,
257 .num_phys
= EXYNOS4210_NUM_PHYS
,
258 .phys
= exynos4210_phys
,
259 .rate_to_clk
= exynos4210_rate_to_clk
,