4
4
*
5
5
* Copyright (c) 2013-2015 Imagination Technologies
6
6
* Author: Paul Burton <[email protected] >
7
+ * Copyright (c) 2020 周琰杰 (Zhou Yanjie) <[email protected] >
7
8
*/
8
9
9
10
#include <linux/clk-provider.h>
59
60
#define USBPCR_VBUSVLDEXT BIT(24)
60
61
#define USBPCR_VBUSVLDEXTSEL BIT(23)
61
62
#define USBPCR_POR BIT(22)
63
+ #define USBPCR_SIDDQ BIT(21)
62
64
#define USBPCR_OTG_DISABLE BIT(20)
63
65
#define USBPCR_COMPDISTUNE_MASK (0x7 << 17)
64
66
#define USBPCR_OTGTUNE_MASK (0x7 << 14)
100
102
101
103
static struct ingenic_cgu * cgu ;
102
104
103
- static u8 jz4780_otg_phy_get_parent (struct clk_hw * hw )
104
- {
105
- /* we only use CLKCORE, revisit if that ever changes */
106
- return 0 ;
107
- }
108
-
109
- static int jz4780_otg_phy_set_parent (struct clk_hw * hw , u8 idx )
110
- {
111
- unsigned long flags ;
112
- u32 usbpcr1 ;
113
-
114
- if (idx > 0 )
115
- return - EINVAL ;
116
-
117
- spin_lock_irqsave (& cgu -> lock , flags );
118
-
119
- usbpcr1 = readl (cgu -> base + CGU_REG_USBPCR1 );
120
- usbpcr1 &= ~USBPCR1_REFCLKSEL_MASK ;
121
- /* we only use CLKCORE */
122
- usbpcr1 |= USBPCR1_REFCLKSEL_CORE ;
123
- writel (usbpcr1 , cgu -> base + CGU_REG_USBPCR1 );
124
-
125
- spin_unlock_irqrestore (& cgu -> lock , flags );
126
- return 0 ;
127
- }
128
-
129
105
static unsigned long jz4780_otg_phy_recalc_rate (struct clk_hw * hw ,
130
106
unsigned long parent_rate )
131
107
{
@@ -149,7 +125,6 @@ static unsigned long jz4780_otg_phy_recalc_rate(struct clk_hw *hw,
149
125
return 19200000 ;
150
126
}
151
127
152
- BUG ();
153
128
return parent_rate ;
154
129
}
155
130
@@ -206,13 +181,43 @@ static int jz4780_otg_phy_set_rate(struct clk_hw *hw, unsigned long req_rate,
206
181
return 0 ;
207
182
}
208
183
209
- static const struct clk_ops jz4780_otg_phy_ops = {
210
- .get_parent = jz4780_otg_phy_get_parent ,
211
- .set_parent = jz4780_otg_phy_set_parent ,
184
+ static int jz4780_otg_phy_enable (struct clk_hw * hw )
185
+ {
186
+ void __iomem * reg_opcr = cgu -> base + CGU_REG_OPCR ;
187
+ void __iomem * reg_usbpcr = cgu -> base + CGU_REG_USBPCR ;
188
+
189
+ writel (readl (reg_opcr ) | OPCR_SPENDN0 , reg_opcr );
190
+ writel (readl (reg_usbpcr ) & ~USBPCR_OTG_DISABLE & ~USBPCR_SIDDQ , reg_usbpcr );
191
+ return 0 ;
192
+ }
193
+
194
+ static void jz4780_otg_phy_disable (struct clk_hw * hw )
195
+ {
196
+ void __iomem * reg_opcr = cgu -> base + CGU_REG_OPCR ;
197
+ void __iomem * reg_usbpcr = cgu -> base + CGU_REG_USBPCR ;
212
198
199
+ writel (readl (reg_opcr ) & ~OPCR_SPENDN0 , reg_opcr );
200
+ writel (readl (reg_usbpcr ) | USBPCR_OTG_DISABLE | USBPCR_SIDDQ , reg_usbpcr );
201
+ }
202
+
203
+ static int jz4780_otg_phy_is_enabled (struct clk_hw * hw )
204
+ {
205
+ void __iomem * reg_opcr = cgu -> base + CGU_REG_OPCR ;
206
+ void __iomem * reg_usbpcr = cgu -> base + CGU_REG_USBPCR ;
207
+
208
+ return (readl (reg_opcr ) & OPCR_SPENDN0 ) &&
209
+ !(readl (reg_usbpcr ) & USBPCR_SIDDQ ) &&
210
+ !(readl (reg_usbpcr ) & USBPCR_OTG_DISABLE );
211
+ }
212
+
213
+ static const struct clk_ops jz4780_otg_phy_ops = {
213
214
.recalc_rate = jz4780_otg_phy_recalc_rate ,
214
215
.round_rate = jz4780_otg_phy_round_rate ,
215
216
.set_rate = jz4780_otg_phy_set_rate ,
217
+
218
+ .enable = jz4780_otg_phy_enable ,
219
+ .disable = jz4780_otg_phy_disable ,
220
+ .is_enabled = jz4780_otg_phy_is_enabled ,
216
221
};
217
222
218
223
static int jz4780_core1_enable (struct clk_hw * hw )
0 commit comments