10 #include <linux/export.h>
16 #include <lantiq_soc.h>
22 #define CGU_IFCCR 0x0018
23 #define CGU_IFCCR_VR9 0x0024
25 #define CGU_SYS 0x0010
27 #define CGU_PCICR 0x0034
28 #define CGU_PCICR_VR9 0x0038
32 #define PMU_PWDCR 0x1C
34 #define PMU_PWDSR 0x20
36 #define PMU_PWDCR1 0x24
38 #define PMU_PWDSR1 0x28
40 #define PWDCR(x) ((x) ? (PMU_PWDCR1) : (PMU_PWDCR))
42 #define PWDSR(x) ((x) ? (PMU_PWDSR1) : (PMU_PWDSR))
45 #define PMU_USB0_P BIT(0)
46 #define PMU_PCI BIT(4)
47 #define PMU_DMA BIT(5)
48 #define PMU_USB0 BIT(6)
49 #define PMU_ASC0 BIT(7)
50 #define PMU_EPHY BIT(7)
51 #define PMU_SPI BIT(8)
52 #define PMU_DFE BIT(9)
53 #define PMU_EBU BIT(10)
54 #define PMU_STP BIT(11)
55 #define PMU_GPT BIT(12)
56 #define PMU_AHBS BIT(13)
57 #define PMU_FPI BIT(14)
58 #define PMU_AHBM BIT(15)
59 #define PMU_ASC1 BIT(17)
60 #define PMU_PPE_QSB BIT(18)
61 #define PMU_PPE_SLL01 BIT(19)
62 #define PMU_PPE_TC BIT(21)
63 #define PMU_PPE_EMA BIT(22)
64 #define PMU_PPE_DPLUM BIT(23)
65 #define PMU_PPE_DPLUS BIT(24)
66 #define PMU_USB1_P BIT(26)
67 #define PMU_USB1 BIT(27)
68 #define PMU_SWITCH BIT(28)
69 #define PMU_PPE_TOP BIT(29)
70 #define PMU_GPHY BIT(30)
71 #define PMU_PCIE_CLK BIT(31)
73 #define PMU1_PCIE_PHY BIT(0)
74 #define PMU1_PCIE_CTL BIT(1)
75 #define PMU1_PCIE_PDI BIT(4)
76 #define PMU1_PCIE_MSI BIT(5)
78 #define pmu_w32(x, y) ltq_w32((x), pmu_membase + (y))
79 #define pmu_r32(x) ltq_r32(pmu_membase + (x))
81 static void __iomem *pmu_membase;
97 panic(
"activating PMU module failed!");
109 static int cgu_enable(
struct clk *
clk)
111 ltq_cgu_w32(ltq_cgu_r32(ifccr) | clk->
bits, ifccr);
116 static void cgu_disable(
struct clk *clk)
118 ltq_cgu_w32(ltq_cgu_r32(ifccr) & ~clk->
bits, ifccr);
122 static int pmu_enable(
struct clk *clk)
131 panic(
"activating PMU module failed!\n");
137 static void pmu_disable(
struct clk *clk)
144 static int pci_enable(
struct clk *clk)
146 unsigned int val = ltq_cgu_r32(ifccr);
162 ltq_cgu_w32(val, ifccr);
168 static int pci_ext_enable(
struct clk *clk)
170 ltq_cgu_w32(ltq_cgu_r32(ifccr) & ~(1 << 16), ifccr);
171 ltq_cgu_w32((1 << 30), pcicr);
176 static void pci_ext_disable(
struct clk *clk)
178 ltq_cgu_w32(ltq_cgu_r32(ifccr) | (1 << 16), ifccr);
179 ltq_cgu_w32((1 << 31) | (1 << 30), pcicr);
183 static int clkout_enable(
struct clk *clk)
188 for (i = 0; i < 4; i++) {
190 int shift = 14 - (2 * clk->
module);
192 unsigned int val = ltq_cgu_r32(ifccr);
194 val &= ~(3 << shift);
197 ltq_cgu_w32(val, ifccr);
205 static void clkdev_add_pmu(
const char *
dev,
const char *
con,
208 struct clk *clk = kzalloc(
sizeof(
struct clk),
GFP_KERNEL);
210 clk->
cl.dev_id =
dev;
211 clk->
cl.con_id =
con;
221 static void clkdev_add_cgu(
const char *dev,
const char *con,
224 struct clk *clk = kzalloc(
sizeof(
struct clk),
GFP_KERNEL);
226 clk->
cl.dev_id =
dev;
227 clk->
cl.con_id =
con;
238 static void clkdev_add_pci(
void)
240 struct clk *clk = kzalloc(
sizeof(
struct clk),
GFP_KERNEL);
244 clk->
cl.dev_id =
"17000000.pci";
248 clk->
rates = valid_pci_rates;
256 clk_ext->
cl.dev_id =
"17000000.pci";
257 clk_ext->
cl.con_id =
"external";
259 clk_ext->
enable = pci_ext_enable;
260 clk_ext->
disable = pci_ext_disable;
265 static unsigned long valid_clkout_rates[4][5] = {
272 static void clkdev_add_clkout(
void)
276 for (i = 0; i < 4; i++) {
280 name = kzalloc(
sizeof(
"clkout0"),
GFP_KERNEL);
283 clk = kzalloc(
sizeof(
struct clk),
GFP_KERNEL);
284 clk->
cl.dev_id =
"1f103000.cgu";
288 clk->
rates = valid_clkout_rates[
i];
289 clk->
enable = clkout_enable;
298 struct resource res_pmu, res_cgu, res_ebu;
307 if (!np_pmu || !np_cgu || !np_ebu)
308 panic(
"Failed to load core nodess from devicetree");
313 panic(
"Failed to get core resources");
316 res_pmu.
name) < 0) ||
318 res_cgu.
name) < 0) ||
321 pr_err(
"Failed to request core reources");
325 resource_size(&res_cgu));
327 resource_size(&res_ebu));
329 panic(
"Failed to remap core resources");
349 clkdev_add_pmu(
"1e180000.etop",
NULL, 0, PMU_PPE);
358 if (ltq_cgu_r32(
CGU_SYS) & (1 << 5))
362 clkdev_add_cgu(
"1e180000.etop",
"ephycgu",
CGU_EPHY),
363 clkdev_add_pmu(
"1e180000.etop",
"ephy", 0,
PMU_EPHY);
368 clkdev_add_pmu(
"1d900000.pcie",
"bus", 0,
PMU_PCIE_CLK);
376 clkdev_add_pmu(
"1e180000.etop",
"switch", 0,
PMU_SWITCH);