Skip to content

Commit dcd062a

Browse files
XBurstbebarino
authored andcommitted
clk: JZ4780: Add functions for enable and disable USB PHY.
Add new functions to "jz4780_otg_phy_ops" to enable or disable the USB PHY in the JZ4780 SoC. Tested-by: 周正 (Zhou Zheng) <[email protected]> Signed-off-by: 周琰杰 (Zhou Yanjie) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 82df5b7 commit dcd062a

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

drivers/clk/ingenic/jz4780-cgu.c

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright (c) 2013-2015 Imagination Technologies
66
* Author: Paul Burton <[email protected]>
7+
* Copyright (c) 2020 周琰杰 (Zhou Yanjie) <[email protected]>
78
*/
89

910
#include <linux/clk-provider.h>
@@ -59,6 +60,7 @@
5960
#define USBPCR_VBUSVLDEXT BIT(24)
6061
#define USBPCR_VBUSVLDEXTSEL BIT(23)
6162
#define USBPCR_POR BIT(22)
63+
#define USBPCR_SIDDQ BIT(21)
6264
#define USBPCR_OTG_DISABLE BIT(20)
6365
#define USBPCR_COMPDISTUNE_MASK (0x7 << 17)
6466
#define USBPCR_OTGTUNE_MASK (0x7 << 14)
@@ -100,32 +102,6 @@
100102

101103
static struct ingenic_cgu *cgu;
102104

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-
129105
static unsigned long jz4780_otg_phy_recalc_rate(struct clk_hw *hw,
130106
unsigned long parent_rate)
131107
{
@@ -149,7 +125,6 @@ static unsigned long jz4780_otg_phy_recalc_rate(struct clk_hw *hw,
149125
return 19200000;
150126
}
151127

152-
BUG();
153128
return parent_rate;
154129
}
155130

@@ -206,13 +181,43 @@ static int jz4780_otg_phy_set_rate(struct clk_hw *hw, unsigned long req_rate,
206181
return 0;
207182
}
208183

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;
212198

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 = {
213214
.recalc_rate = jz4780_otg_phy_recalc_rate,
214215
.round_rate = jz4780_otg_phy_round_rate,
215216
.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,
216221
};
217222

218223
static int jz4780_core1_enable(struct clk_hw *hw)

0 commit comments

Comments
 (0)