17a01c190SPaul Cercueil // SPDX-License-Identifier: GPL-2.0
27a01c190SPaul Cercueil /*
37a01c190SPaul Cercueil * JZ4770 SoC CGU driver
47a01c190SPaul Cercueil * Copyright 2018, Paul Cercueil <paul@crapouillou.net>
57a01c190SPaul Cercueil */
67a01c190SPaul Cercueil
77a01c190SPaul Cercueil #include <linux/bitops.h>
87a01c190SPaul Cercueil #include <linux/clk-provider.h>
97a01c190SPaul Cercueil #include <linux/delay.h>
1062e59c4eSStephen Boyd #include <linux/io.h>
117a01c190SPaul Cercueil #include <linux/of.h>
129d9cc58aS周琰杰 (Zhou Yanjie)
13c4a11bf4SPaul Cercueil #include <dt-bindings/clock/ingenic,jz4770-cgu.h>
149d9cc58aS周琰杰 (Zhou Yanjie)
157a01c190SPaul Cercueil #include "cgu.h"
162ee93e3cSPaul Cercueil #include "pm.h"
177a01c190SPaul Cercueil
187a01c190SPaul Cercueil /*
197a01c190SPaul Cercueil * CPM registers offset address definition
207a01c190SPaul Cercueil */
217a01c190SPaul Cercueil #define CGU_REG_CPCCR 0x00
227a01c190SPaul Cercueil #define CGU_REG_LCR 0x04
237a01c190SPaul Cercueil #define CGU_REG_CPPCR0 0x10
247a01c190SPaul Cercueil #define CGU_REG_CLKGR0 0x20
257a01c190SPaul Cercueil #define CGU_REG_OPCR 0x24
267a01c190SPaul Cercueil #define CGU_REG_CLKGR1 0x28
277a01c190SPaul Cercueil #define CGU_REG_CPPCR1 0x30
287a01c190SPaul Cercueil #define CGU_REG_USBPCR1 0x48
297a01c190SPaul Cercueil #define CGU_REG_USBCDR 0x50
307a01c190SPaul Cercueil #define CGU_REG_I2SCDR 0x60
317a01c190SPaul Cercueil #define CGU_REG_LPCDR 0x64
327a01c190SPaul Cercueil #define CGU_REG_MSC0CDR 0x68
337a01c190SPaul Cercueil #define CGU_REG_UHCCDR 0x6c
347a01c190SPaul Cercueil #define CGU_REG_SSICDR 0x74
357a01c190SPaul Cercueil #define CGU_REG_CIMCDR 0x7c
367a01c190SPaul Cercueil #define CGU_REG_GPSCDR 0x80
377a01c190SPaul Cercueil #define CGU_REG_PCMCDR 0x84
387a01c190SPaul Cercueil #define CGU_REG_GPUCDR 0x88
397a01c190SPaul Cercueil #define CGU_REG_MSC1CDR 0xA4
407a01c190SPaul Cercueil #define CGU_REG_MSC2CDR 0xA8
417a01c190SPaul Cercueil #define CGU_REG_BCHCDR 0xAC
427a01c190SPaul Cercueil
437a01c190SPaul Cercueil /* bits within the OPCR register */
447a01c190SPaul Cercueil #define OPCR_SPENDH BIT(5) /* UHC PHY suspend */
457a01c190SPaul Cercueil
467a01c190SPaul Cercueil /* bits within the USBPCR1 register */
477a01c190SPaul Cercueil #define USBPCR1_UHC_POWER BIT(5) /* UHC PHY power down */
487a01c190SPaul Cercueil
497a01c190SPaul Cercueil static struct ingenic_cgu *cgu;
507a01c190SPaul Cercueil
jz4770_uhc_phy_enable(struct clk_hw * hw)517a01c190SPaul Cercueil static int jz4770_uhc_phy_enable(struct clk_hw *hw)
527a01c190SPaul Cercueil {
537a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR;
547a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1;
557a01c190SPaul Cercueil
567a01c190SPaul Cercueil writel(readl(reg_opcr) & ~OPCR_SPENDH, reg_opcr);
577a01c190SPaul Cercueil writel(readl(reg_usbpcr1) | USBPCR1_UHC_POWER, reg_usbpcr1);
587a01c190SPaul Cercueil return 0;
597a01c190SPaul Cercueil }
607a01c190SPaul Cercueil
jz4770_uhc_phy_disable(struct clk_hw * hw)617a01c190SPaul Cercueil static void jz4770_uhc_phy_disable(struct clk_hw *hw)
627a01c190SPaul Cercueil {
637a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR;
647a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1;
657a01c190SPaul Cercueil
667a01c190SPaul Cercueil writel(readl(reg_usbpcr1) & ~USBPCR1_UHC_POWER, reg_usbpcr1);
677a01c190SPaul Cercueil writel(readl(reg_opcr) | OPCR_SPENDH, reg_opcr);
687a01c190SPaul Cercueil }
697a01c190SPaul Cercueil
jz4770_uhc_phy_is_enabled(struct clk_hw * hw)707a01c190SPaul Cercueil static int jz4770_uhc_phy_is_enabled(struct clk_hw *hw)
717a01c190SPaul Cercueil {
727a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR;
737a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1;
747a01c190SPaul Cercueil
757a01c190SPaul Cercueil return !(readl(reg_opcr) & OPCR_SPENDH) &&
767a01c190SPaul Cercueil (readl(reg_usbpcr1) & USBPCR1_UHC_POWER);
777a01c190SPaul Cercueil }
787a01c190SPaul Cercueil
797a01c190SPaul Cercueil static const struct clk_ops jz4770_uhc_phy_ops = {
807a01c190SPaul Cercueil .enable = jz4770_uhc_phy_enable,
817a01c190SPaul Cercueil .disable = jz4770_uhc_phy_disable,
827a01c190SPaul Cercueil .is_enabled = jz4770_uhc_phy_is_enabled,
837a01c190SPaul Cercueil };
847a01c190SPaul Cercueil
857a01c190SPaul Cercueil static const s8 pll_od_encoding[8] = {
867a01c190SPaul Cercueil 0x0, 0x1, -1, 0x2, -1, -1, -1, 0x3,
877a01c190SPaul Cercueil };
887a01c190SPaul Cercueil
8944b06a76SPaul Cercueil static const u8 jz4770_cgu_cpccr_div_table[] = {
9044b06a76SPaul Cercueil 1, 2, 3, 4, 6, 8, 12,
9144b06a76SPaul Cercueil };
9244b06a76SPaul Cercueil
937a01c190SPaul Cercueil static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = {
947a01c190SPaul Cercueil
957a01c190SPaul Cercueil /* External clocks */
967a01c190SPaul Cercueil
977a01c190SPaul Cercueil [JZ4770_CLK_EXT] = { "ext", CGU_CLK_EXT },
987a01c190SPaul Cercueil [JZ4770_CLK_OSC32K] = { "osc32k", CGU_CLK_EXT },
997a01c190SPaul Cercueil
1007a01c190SPaul Cercueil /* PLLs */
1017a01c190SPaul Cercueil
1027a01c190SPaul Cercueil [JZ4770_CLK_PLL0] = {
1037a01c190SPaul Cercueil "pll0", CGU_CLK_PLL,
1047a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT },
1057a01c190SPaul Cercueil .pll = {
1067a01c190SPaul Cercueil .reg = CGU_REG_CPPCR0,
1079d9cc58aS周琰杰 (Zhou Yanjie) .rate_multiplier = 1,
1087a01c190SPaul Cercueil .m_shift = 24,
1097a01c190SPaul Cercueil .m_bits = 7,
1107a01c190SPaul Cercueil .m_offset = 1,
1117a01c190SPaul Cercueil .n_shift = 18,
1127a01c190SPaul Cercueil .n_bits = 5,
1137a01c190SPaul Cercueil .n_offset = 1,
1147a01c190SPaul Cercueil .od_shift = 16,
1157a01c190SPaul Cercueil .od_bits = 2,
1167a01c190SPaul Cercueil .od_max = 8,
1177a01c190SPaul Cercueil .od_encoding = pll_od_encoding,
1189d9cc58aS周琰杰 (Zhou Yanjie) .bypass_reg = CGU_REG_CPPCR0,
1197a01c190SPaul Cercueil .bypass_bit = 9,
1207a01c190SPaul Cercueil .enable_bit = 8,
1217a01c190SPaul Cercueil .stable_bit = 10,
1227a01c190SPaul Cercueil },
1237a01c190SPaul Cercueil },
1247a01c190SPaul Cercueil
1257a01c190SPaul Cercueil [JZ4770_CLK_PLL1] = {
1267a01c190SPaul Cercueil /* TODO: PLL1 can depend on PLL0 */
1277a01c190SPaul Cercueil "pll1", CGU_CLK_PLL,
1287a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT },
1297a01c190SPaul Cercueil .pll = {
1307a01c190SPaul Cercueil .reg = CGU_REG_CPPCR1,
1319d9cc58aS周琰杰 (Zhou Yanjie) .rate_multiplier = 1,
1327a01c190SPaul Cercueil .m_shift = 24,
1337a01c190SPaul Cercueil .m_bits = 7,
1347a01c190SPaul Cercueil .m_offset = 1,
1357a01c190SPaul Cercueil .n_shift = 18,
1367a01c190SPaul Cercueil .n_bits = 5,
1377a01c190SPaul Cercueil .n_offset = 1,
1387a01c190SPaul Cercueil .od_shift = 16,
1397a01c190SPaul Cercueil .od_bits = 2,
1407a01c190SPaul Cercueil .od_max = 8,
1417a01c190SPaul Cercueil .od_encoding = pll_od_encoding,
142037f1ffdSPaul Cercueil .bypass_bit = -1,
1437a01c190SPaul Cercueil .enable_bit = 7,
1447a01c190SPaul Cercueil .stable_bit = 6,
1457a01c190SPaul Cercueil },
1467a01c190SPaul Cercueil },
1477a01c190SPaul Cercueil
1487a01c190SPaul Cercueil /* Main clocks */
1497a01c190SPaul Cercueil
1507a01c190SPaul Cercueil [JZ4770_CLK_CCLK] = {
1517a01c190SPaul Cercueil "cclk", CGU_CLK_DIV,
152*ca54d06fSAidan MacDonald /*
153*ca54d06fSAidan MacDonald * Disabling the CPU clock or any parent clocks will hang the
154*ca54d06fSAidan MacDonald * system; mark it critical.
155*ca54d06fSAidan MacDonald */
156*ca54d06fSAidan MacDonald .flags = CLK_IS_CRITICAL,
1577a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
15844b06a76SPaul Cercueil .div = {
159249592bfSPaul Cercueil CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1, 0,
16044b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
16144b06a76SPaul Cercueil },
1627a01c190SPaul Cercueil },
1637a01c190SPaul Cercueil [JZ4770_CLK_H0CLK] = {
1647a01c190SPaul Cercueil "h0clk", CGU_CLK_DIV,
1657a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
16644b06a76SPaul Cercueil .div = {
167249592bfSPaul Cercueil CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1, 0,
16844b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
16944b06a76SPaul Cercueil },
1707a01c190SPaul Cercueil },
1717a01c190SPaul Cercueil [JZ4770_CLK_H1CLK] = {
1727a01c190SPaul Cercueil "h1clk", CGU_CLK_DIV | CGU_CLK_GATE,
1737a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
17444b06a76SPaul Cercueil .div = {
175249592bfSPaul Cercueil CGU_REG_CPCCR, 24, 1, 4, 22, -1, -1, 0,
17644b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
17744b06a76SPaul Cercueil },
178a6523b6fSPaul Cercueil .gate = { CGU_REG_CLKGR1, 7 },
1797a01c190SPaul Cercueil },
1807a01c190SPaul Cercueil [JZ4770_CLK_H2CLK] = {
1817a01c190SPaul Cercueil "h2clk", CGU_CLK_DIV,
1827a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
18344b06a76SPaul Cercueil .div = {
184249592bfSPaul Cercueil CGU_REG_CPCCR, 16, 1, 4, 22, -1, -1, 0,
18544b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
18644b06a76SPaul Cercueil },
1877a01c190SPaul Cercueil },
1887a01c190SPaul Cercueil [JZ4770_CLK_C1CLK] = {
18945ba63a2SPaul Cercueil "c1clk", CGU_CLK_DIV | CGU_CLK_GATE,
1907a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
19144b06a76SPaul Cercueil .div = {
192249592bfSPaul Cercueil CGU_REG_CPCCR, 12, 1, 4, 22, -1, -1, 0,
19344b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
19444b06a76SPaul Cercueil },
19545ba63a2SPaul Cercueil .gate = { CGU_REG_OPCR, 31, true }, // disable CCLK stop on idle
1967a01c190SPaul Cercueil },
1977a01c190SPaul Cercueil [JZ4770_CLK_PCLK] = {
1987a01c190SPaul Cercueil "pclk", CGU_CLK_DIV,
1997a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, },
20044b06a76SPaul Cercueil .div = {
201249592bfSPaul Cercueil CGU_REG_CPCCR, 8, 1, 4, 22, -1, -1, 0,
20244b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table,
20344b06a76SPaul Cercueil },
2047a01c190SPaul Cercueil },
2057a01c190SPaul Cercueil
2067a01c190SPaul Cercueil /* Those divided clocks can connect to PLL0 or PLL1 */
2077a01c190SPaul Cercueil
2087a01c190SPaul Cercueil [JZ4770_CLK_MMC0_MUX] = {
2097a01c190SPaul Cercueil "mmc0_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2107a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2117a01c190SPaul Cercueil .mux = { CGU_REG_MSC0CDR, 30, 1 },
2127a01c190SPaul Cercueil .div = { CGU_REG_MSC0CDR, 0, 1, 7, -1, -1, 31 },
2137a01c190SPaul Cercueil .gate = { CGU_REG_MSC0CDR, 31 },
2147a01c190SPaul Cercueil },
2157a01c190SPaul Cercueil [JZ4770_CLK_MMC1_MUX] = {
2167a01c190SPaul Cercueil "mmc1_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2177a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2187a01c190SPaul Cercueil .mux = { CGU_REG_MSC1CDR, 30, 1 },
2197a01c190SPaul Cercueil .div = { CGU_REG_MSC1CDR, 0, 1, 7, -1, -1, 31 },
2207a01c190SPaul Cercueil .gate = { CGU_REG_MSC1CDR, 31 },
2217a01c190SPaul Cercueil },
2227a01c190SPaul Cercueil [JZ4770_CLK_MMC2_MUX] = {
2237a01c190SPaul Cercueil "mmc2_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2247a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2257a01c190SPaul Cercueil .mux = { CGU_REG_MSC2CDR, 30, 1 },
2267a01c190SPaul Cercueil .div = { CGU_REG_MSC2CDR, 0, 1, 7, -1, -1, 31 },
2277a01c190SPaul Cercueil .gate = { CGU_REG_MSC2CDR, 31 },
2287a01c190SPaul Cercueil },
2297a01c190SPaul Cercueil [JZ4770_CLK_CIM] = {
2307a01c190SPaul Cercueil "cim", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2317a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2327a01c190SPaul Cercueil .mux = { CGU_REG_CIMCDR, 31, 1 },
2337a01c190SPaul Cercueil .div = { CGU_REG_CIMCDR, 0, 1, 8, -1, -1, -1 },
2347a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 26 },
2357a01c190SPaul Cercueil },
2367a01c190SPaul Cercueil [JZ4770_CLK_UHC] = {
2377a01c190SPaul Cercueil "uhc", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2387a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2397a01c190SPaul Cercueil .mux = { CGU_REG_UHCCDR, 29, 1 },
2407a01c190SPaul Cercueil .div = { CGU_REG_UHCCDR, 0, 1, 4, -1, -1, -1 },
2417a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 24 },
2427a01c190SPaul Cercueil },
2437a01c190SPaul Cercueil [JZ4770_CLK_GPU] = {
2447a01c190SPaul Cercueil "gpu", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2457a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, -1 },
2467a01c190SPaul Cercueil .mux = { CGU_REG_GPUCDR, 31, 1 },
2477a01c190SPaul Cercueil .div = { CGU_REG_GPUCDR, 0, 1, 3, -1, -1, -1 },
2487a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 9 },
2497a01c190SPaul Cercueil },
2507a01c190SPaul Cercueil [JZ4770_CLK_BCH] = {
2517a01c190SPaul Cercueil "bch", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2527a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2537a01c190SPaul Cercueil .mux = { CGU_REG_BCHCDR, 31, 1 },
2547a01c190SPaul Cercueil .div = { CGU_REG_BCHCDR, 0, 1, 3, -1, -1, -1 },
2557a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 1 },
2567a01c190SPaul Cercueil },
2577a01c190SPaul Cercueil [JZ4770_CLK_LPCLK_MUX] = {
2587a01c190SPaul Cercueil "lpclk", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2597a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2607a01c190SPaul Cercueil .mux = { CGU_REG_LPCDR, 29, 1 },
2617a01c190SPaul Cercueil .div = { CGU_REG_LPCDR, 0, 1, 11, -1, -1, -1 },
2627a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 28 },
2637a01c190SPaul Cercueil },
2647a01c190SPaul Cercueil [JZ4770_CLK_GPS] = {
2657a01c190SPaul Cercueil "gps", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2667a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, },
2677a01c190SPaul Cercueil .mux = { CGU_REG_GPSCDR, 31, 1 },
2687a01c190SPaul Cercueil .div = { CGU_REG_GPSCDR, 0, 1, 4, -1, -1, -1 },
2697a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 22 },
2707a01c190SPaul Cercueil },
2717a01c190SPaul Cercueil
2727a01c190SPaul Cercueil /* Those divided clocks can connect to EXT, PLL0 or PLL1 */
2737a01c190SPaul Cercueil
2747a01c190SPaul Cercueil [JZ4770_CLK_SSI_MUX] = {
2757a01c190SPaul Cercueil "ssi_mux", CGU_CLK_DIV | CGU_CLK_MUX,
2767a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1,
2777a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 },
2787a01c190SPaul Cercueil .mux = { CGU_REG_SSICDR, 30, 2 },
2797a01c190SPaul Cercueil .div = { CGU_REG_SSICDR, 0, 1, 6, -1, -1, -1 },
2807a01c190SPaul Cercueil },
2817a01c190SPaul Cercueil [JZ4770_CLK_PCM_MUX] = {
2827a01c190SPaul Cercueil "pcm_mux", CGU_CLK_DIV | CGU_CLK_MUX,
2837a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1,
2847a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 },
2857a01c190SPaul Cercueil .mux = { CGU_REG_PCMCDR, 30, 2 },
2867a01c190SPaul Cercueil .div = { CGU_REG_PCMCDR, 0, 1, 9, -1, -1, -1 },
2877a01c190SPaul Cercueil },
2887a01c190SPaul Cercueil [JZ4770_CLK_I2S] = {
2897a01c190SPaul Cercueil "i2s", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2907a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1,
2917a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 },
2927a01c190SPaul Cercueil .mux = { CGU_REG_I2SCDR, 30, 2 },
2937a01c190SPaul Cercueil .div = { CGU_REG_I2SCDR, 0, 1, 9, -1, -1, -1 },
2947a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 13 },
2957a01c190SPaul Cercueil },
2967a01c190SPaul Cercueil [JZ4770_CLK_OTG] = {
2977a01c190SPaul Cercueil "usb", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX,
2987a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1,
2997a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 },
3007a01c190SPaul Cercueil .mux = { CGU_REG_USBCDR, 30, 2 },
3017a01c190SPaul Cercueil .div = { CGU_REG_USBCDR, 0, 1, 8, -1, -1, -1 },
3027a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 2 },
3037a01c190SPaul Cercueil },
3047a01c190SPaul Cercueil
3057a01c190SPaul Cercueil /* Gate-only clocks */
3067a01c190SPaul Cercueil
3077a01c190SPaul Cercueil [JZ4770_CLK_SSI0] = {
3087a01c190SPaul Cercueil "ssi0", CGU_CLK_GATE,
3097a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, },
3107a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 4 },
3117a01c190SPaul Cercueil },
3127a01c190SPaul Cercueil [JZ4770_CLK_SSI1] = {
3137a01c190SPaul Cercueil "ssi1", CGU_CLK_GATE,
3147a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, },
3157a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 19 },
3167a01c190SPaul Cercueil },
3177a01c190SPaul Cercueil [JZ4770_CLK_SSI2] = {
3187a01c190SPaul Cercueil "ssi2", CGU_CLK_GATE,
3197a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, },
3207a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 20 },
3217a01c190SPaul Cercueil },
3227a01c190SPaul Cercueil [JZ4770_CLK_PCM0] = {
3237a01c190SPaul Cercueil "pcm0", CGU_CLK_GATE,
3247a01c190SPaul Cercueil .parents = { JZ4770_CLK_PCM_MUX, },
3257a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 8 },
3267a01c190SPaul Cercueil },
3277a01c190SPaul Cercueil [JZ4770_CLK_PCM1] = {
3287a01c190SPaul Cercueil "pcm1", CGU_CLK_GATE,
3297a01c190SPaul Cercueil .parents = { JZ4770_CLK_PCM_MUX, },
3307a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 10 },
3317a01c190SPaul Cercueil },
3327a01c190SPaul Cercueil [JZ4770_CLK_DMA] = {
3337a01c190SPaul Cercueil "dma", CGU_CLK_GATE,
3347a01c190SPaul Cercueil .parents = { JZ4770_CLK_H2CLK, },
3357a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 21 },
3367a01c190SPaul Cercueil },
337b5bc83bbSPaul Cercueil [JZ4770_CLK_BDMA] = {
338b5bc83bbSPaul Cercueil "bdma", CGU_CLK_GATE,
339b5bc83bbSPaul Cercueil .parents = { JZ4770_CLK_H2CLK, },
340b5bc83bbSPaul Cercueil .gate = { CGU_REG_CLKGR1, 0 },
341b5bc83bbSPaul Cercueil },
3427a01c190SPaul Cercueil [JZ4770_CLK_I2C0] = {
3437a01c190SPaul Cercueil "i2c0", CGU_CLK_GATE,
3447a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3457a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 5 },
3467a01c190SPaul Cercueil },
3477a01c190SPaul Cercueil [JZ4770_CLK_I2C1] = {
3487a01c190SPaul Cercueil "i2c1", CGU_CLK_GATE,
3497a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3507a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 6 },
3517a01c190SPaul Cercueil },
3527a01c190SPaul Cercueil [JZ4770_CLK_I2C2] = {
3537a01c190SPaul Cercueil "i2c2", CGU_CLK_GATE,
3547a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3557a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 15 },
3567a01c190SPaul Cercueil },
3577a01c190SPaul Cercueil [JZ4770_CLK_UART0] = {
3587a01c190SPaul Cercueil "uart0", CGU_CLK_GATE,
3597a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3607a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 15 },
3617a01c190SPaul Cercueil },
3627a01c190SPaul Cercueil [JZ4770_CLK_UART1] = {
3637a01c190SPaul Cercueil "uart1", CGU_CLK_GATE,
3647a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3657a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 16 },
3667a01c190SPaul Cercueil },
3677a01c190SPaul Cercueil [JZ4770_CLK_UART2] = {
3687a01c190SPaul Cercueil "uart2", CGU_CLK_GATE,
3697a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3707a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 17 },
3717a01c190SPaul Cercueil },
3727a01c190SPaul Cercueil [JZ4770_CLK_UART3] = {
3737a01c190SPaul Cercueil "uart3", CGU_CLK_GATE,
3747a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3757a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 18 },
3767a01c190SPaul Cercueil },
3777a01c190SPaul Cercueil [JZ4770_CLK_IPU] = {
3787a01c190SPaul Cercueil "ipu", CGU_CLK_GATE,
3797a01c190SPaul Cercueil .parents = { JZ4770_CLK_H0CLK, },
3807a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 29 },
3817a01c190SPaul Cercueil },
3827a01c190SPaul Cercueil [JZ4770_CLK_ADC] = {
3837a01c190SPaul Cercueil "adc", CGU_CLK_GATE,
3847a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3857a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 14 },
3867a01c190SPaul Cercueil },
3877a01c190SPaul Cercueil [JZ4770_CLK_AIC] = {
3887a01c190SPaul Cercueil "aic", CGU_CLK_GATE,
3897a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, },
3907a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 8 },
3917a01c190SPaul Cercueil },
3927a01c190SPaul Cercueil [JZ4770_CLK_AUX] = {
3937a01c190SPaul Cercueil "aux", CGU_CLK_GATE,
3947a01c190SPaul Cercueil .parents = { JZ4770_CLK_C1CLK, },
3957a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 14 },
3967a01c190SPaul Cercueil },
3977a01c190SPaul Cercueil [JZ4770_CLK_VPU] = {
3987a01c190SPaul Cercueil "vpu", CGU_CLK_GATE,
3997a01c190SPaul Cercueil .parents = { JZ4770_CLK_H1CLK, },
4006ee3d385SPaul Cercueil .gate = { CGU_REG_LCR, 30, false, 150 },
4017a01c190SPaul Cercueil },
4027a01c190SPaul Cercueil [JZ4770_CLK_MMC0] = {
4037a01c190SPaul Cercueil "mmc0", CGU_CLK_GATE,
4047a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC0_MUX, },
4057a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 3 },
4067a01c190SPaul Cercueil },
4077a01c190SPaul Cercueil [JZ4770_CLK_MMC1] = {
4087a01c190SPaul Cercueil "mmc1", CGU_CLK_GATE,
4097a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC1_MUX, },
4107a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 11 },
4117a01c190SPaul Cercueil },
4127a01c190SPaul Cercueil [JZ4770_CLK_MMC2] = {
4137a01c190SPaul Cercueil "mmc2", CGU_CLK_GATE,
4147a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC2_MUX, },
4157a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 12 },
4167a01c190SPaul Cercueil },
41711b689a3SPaul Cercueil [JZ4770_CLK_OTG_PHY] = {
41811b689a3SPaul Cercueil "usb_phy", CGU_CLK_GATE,
41911b689a3SPaul Cercueil .parents = { JZ4770_CLK_OTG },
42011b689a3SPaul Cercueil .gate = { CGU_REG_OPCR, 7, true, 50 },
42111b689a3SPaul Cercueil },
4227a01c190SPaul Cercueil
4237a01c190SPaul Cercueil /* Custom clocks */
4247a01c190SPaul Cercueil
4257a01c190SPaul Cercueil [JZ4770_CLK_UHC_PHY] = {
4267a01c190SPaul Cercueil "uhc_phy", CGU_CLK_CUSTOM,
4277a01c190SPaul Cercueil .parents = { JZ4770_CLK_UHC, -1, -1, -1 },
4287a01c190SPaul Cercueil .custom = { &jz4770_uhc_phy_ops },
4297a01c190SPaul Cercueil },
4307a01c190SPaul Cercueil
4317a01c190SPaul Cercueil [JZ4770_CLK_EXT512] = {
4327a01c190SPaul Cercueil "ext/512", CGU_CLK_FIXDIV,
4337a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT },
4347a01c190SPaul Cercueil .fixdiv = { 512 },
4357a01c190SPaul Cercueil },
4367a01c190SPaul Cercueil
4377a01c190SPaul Cercueil [JZ4770_CLK_RTC] = {
4387a01c190SPaul Cercueil "rtc", CGU_CLK_MUX,
4397a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT512, JZ4770_CLK_OSC32K, },
4407a01c190SPaul Cercueil .mux = { CGU_REG_OPCR, 2, 1},
4417a01c190SPaul Cercueil },
4427a01c190SPaul Cercueil };
4437a01c190SPaul Cercueil
jz4770_cgu_init(struct device_node * np)4447a01c190SPaul Cercueil static void __init jz4770_cgu_init(struct device_node *np)
4457a01c190SPaul Cercueil {
4467a01c190SPaul Cercueil int retval;
4477a01c190SPaul Cercueil
4487a01c190SPaul Cercueil cgu = ingenic_cgu_new(jz4770_cgu_clocks,
4497a01c190SPaul Cercueil ARRAY_SIZE(jz4770_cgu_clocks), np);
450c067b46dSPaul Cercueil if (!cgu) {
4517a01c190SPaul Cercueil pr_err("%s: failed to initialise CGU\n", __func__);
452c067b46dSPaul Cercueil return;
453c067b46dSPaul Cercueil }
4547a01c190SPaul Cercueil
4557a01c190SPaul Cercueil retval = ingenic_cgu_register_clocks(cgu);
4567a01c190SPaul Cercueil if (retval)
4577a01c190SPaul Cercueil pr_err("%s: failed to register CGU Clocks\n", __func__);
4587a01c190SPaul Cercueil
4592ee93e3cSPaul Cercueil ingenic_cgu_register_syscore_ops(cgu);
4607a01c190SPaul Cercueil }
4617a01c190SPaul Cercueil
4627a01c190SPaul Cercueil /* We only probe via devicetree, no need for a platform driver */
46303d570e1SPaul Cercueil CLK_OF_DECLARE_DRIVER(jz4770_cgu, "ingenic,jz4770-cgu", jz4770_cgu_init);
464