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>
19
20
20
21
/* CGU register offsets */
21
22
#define CGU_REG_CLOCKCONTROL 0x00
22
- #define CGU_REG_LCR 0x04
23
- #define CGU_REG_APLL 0x10
24
- #define CGU_REG_MPLL 0x14
25
- #define CGU_REG_EPLL 0x18
26
- #define CGU_REG_VPLL 0x1c
27
- #define CGU_REG_CLKGR0 0x20
28
- #define CGU_REG_OPCR 0x24
29
- #define CGU_REG_CLKGR1 0x28
30
- #define CGU_REG_DDRCDR 0x2c
31
- #define CGU_REG_VPUCDR 0x30
32
- #define CGU_REG_USBPCR 0x3c
33
- #define CGU_REG_USBRDT 0x40
34
- #define CGU_REG_USBVBFIL 0x44
35
- #define CGU_REG_USBPCR1 0x48
36
- #define CGU_REG_LP0CDR 0x54
37
- #define CGU_REG_I2SCDR 0x60
38
- #define CGU_REG_LP1CDR 0x64
39
- #define CGU_REG_MSC0CDR 0x68
40
- #define CGU_REG_UHCCDR 0x6c
41
- #define CGU_REG_SSICDR 0x74
42
- #define CGU_REG_CIMCDR 0x7c
43
- #define CGU_REG_PCMCDR 0x84
44
- #define CGU_REG_GPUCDR 0x88
45
- #define CGU_REG_HDMICDR 0x8c
46
- #define CGU_REG_MSC1CDR 0xa4
47
- #define CGU_REG_MSC2CDR 0xa8
48
- #define CGU_REG_BCHCDR 0xac
49
- #define CGU_REG_CLOCKSTATUS 0xd4
23
+ #define CGU_REG_LCR 0x04
24
+ #define CGU_REG_APLL 0x10
25
+ #define CGU_REG_MPLL 0x14
26
+ #define CGU_REG_EPLL 0x18
27
+ #define CGU_REG_VPLL 0x1c
28
+ #define CGU_REG_CLKGR0 0x20
29
+ #define CGU_REG_OPCR 0x24
30
+ #define CGU_REG_CLKGR1 0x28
31
+ #define CGU_REG_DDRCDR 0x2c
32
+ #define CGU_REG_VPUCDR 0x30
33
+ #define CGU_REG_USBPCR 0x3c
34
+ #define CGU_REG_USBRDT 0x40
35
+ #define CGU_REG_USBVBFIL 0x44
36
+ #define CGU_REG_USBPCR1 0x48
37
+ #define CGU_REG_LP0CDR 0x54
38
+ #define CGU_REG_I2SCDR 0x60
39
+ #define CGU_REG_LP1CDR 0x64
40
+ #define CGU_REG_MSC0CDR 0x68
41
+ #define CGU_REG_UHCCDR 0x6c
42
+ #define CGU_REG_SSICDR 0x74
43
+ #define CGU_REG_CIMCDR 0x7c
44
+ #define CGU_REG_PCMCDR 0x84
45
+ #define CGU_REG_GPUCDR 0x88
46
+ #define CGU_REG_HDMICDR 0x8c
47
+ #define CGU_REG_MSC1CDR 0xa4
48
+ #define CGU_REG_MSC2CDR 0xa8
49
+ #define CGU_REG_BCHCDR 0xac
50
+ #define CGU_REG_CLOCKSTATUS 0xd4
50
51
51
52
/* bits within the OPCR register */
52
- #define OPCR_SPENDN0 BIT(7)
53
- #define OPCR_SPENDN1 BIT(6)
53
+ #define OPCR_SPENDN0 BIT(7)
54
+ #define OPCR_SPENDN1 BIT(6)
54
55
55
56
/* bits within the USBPCR register */
56
- #define USBPCR_USB_MODE BIT(31)
57
+ #define USBPCR_USB_MODE BIT(31)
57
58
#define USBPCR_IDPULLUP_MASK (0x3 << 28)
58
- #define USBPCR_COMMONONN BIT(25)
59
- #define USBPCR_VBUSVLDEXT BIT(24)
59
+ #define USBPCR_COMMONONN BIT(25)
60
+ #define USBPCR_VBUSVLDEXT BIT(24)
60
61
#define USBPCR_VBUSVLDEXTSEL BIT(23)
61
- #define USBPCR_POR BIT(22)
62
- #define USBPCR_OTG_DISABLE BIT(20)
62
+ #define USBPCR_POR BIT(22)
63
+ #define USBPCR_SIDDQ BIT(21)
64
+ #define USBPCR_OTG_DISABLE BIT(20)
63
65
#define USBPCR_COMPDISTUNE_MASK (0x7 << 17)
64
- #define USBPCR_OTGTUNE_MASK (0x7 << 14)
66
+ #define USBPCR_OTGTUNE_MASK (0x7 << 14)
65
67
#define USBPCR_SQRXTUNE_MASK (0x7 << 11)
66
68
#define USBPCR_TXFSLSTUNE_MASK (0xf << 7)
67
69
#define USBPCR_TXPREEMPHTUNE BIT(6)
78
80
#define USBPCR1_REFCLKDIV_48 (0x2 << USBPCR1_REFCLKDIV_SHIFT)
79
81
#define USBPCR1_REFCLKDIV_24 (0x1 << USBPCR1_REFCLKDIV_SHIFT)
80
82
#define USBPCR1_REFCLKDIV_12 (0x0 << USBPCR1_REFCLKDIV_SHIFT)
81
- #define USBPCR1_USB_SEL BIT(28)
82
- #define USBPCR1_WORD_IF0 BIT(19)
83
- #define USBPCR1_WORD_IF1 BIT(18)
83
+ #define USBPCR1_USB_SEL BIT(28)
84
+ #define USBPCR1_WORD_IF0 BIT(19)
85
+ #define USBPCR1_WORD_IF1 BIT(18)
84
86
85
87
/* bits within the USBRDT register */
86
- #define USBRDT_VBFIL_LD_EN BIT(25)
87
- #define USBRDT_USBRDT_MASK 0x7fffff
88
+ #define USBRDT_VBFIL_LD_EN BIT(25)
89
+ #define USBRDT_USBRDT_MASK 0x7fffff
88
90
89
91
/* bits within the USBVBFIL register */
90
92
#define USBVBFIL_IDDIGFIL_SHIFT 16
91
93
#define USBVBFIL_IDDIGFIL_MASK (0xffff << USBVBFIL_IDDIGFIL_SHIFT)
92
94
#define USBVBFIL_USBVBFIL_MASK (0xffff)
93
95
94
96
/* bits within the LCR register */
95
- #define LCR_PD_SCPU BIT(31)
96
- #define LCR_SCPUS BIT(27)
97
+ #define LCR_PD_SCPU BIT(31)
98
+ #define LCR_SCPUS BIT(27)
97
99
98
100
/* bits within the CLKGR1 register */
99
- #define CLKGR1_CORE1 BIT(15)
101
+ #define CLKGR1_CORE1 BIT(15)
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
+ }
212
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 ;
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 )
@@ -516,6 +521,18 @@ static const struct ingenic_cgu_clk_info jz4780_cgu_clocks[] = {
516
521
.gate = { CGU_REG_CLKGR0 , 1 },
517
522
},
518
523
524
+ [JZ4780_CLK_EXCLK_DIV512 ] = {
525
+ "exclk_div512" , CGU_CLK_FIXDIV ,
526
+ .parents = { JZ4780_CLK_EXCLK },
527
+ .fixdiv = { 512 },
528
+ },
529
+
530
+ [JZ4780_CLK_RTC ] = {
531
+ "rtc_ercs" , CGU_CLK_MUX | CGU_CLK_GATE ,
532
+ .parents = { JZ4780_CLK_EXCLK_DIV512 , JZ4780_CLK_RTCLK },
533
+ .mux = { CGU_REG_OPCR , 2 , 1 },
534
+ },
535
+
519
536
/* Gate-only clocks */
520
537
521
538
[JZ4780_CLK_NEMC ] = {
0 commit comments