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> 127a01c190SPaul Cercueil #include <linux/syscore_ops.h> 137a01c190SPaul Cercueil #include <dt-bindings/clock/jz4770-cgu.h> 147a01c190SPaul Cercueil #include "cgu.h" 157a01c190SPaul Cercueil 167a01c190SPaul Cercueil /* 177a01c190SPaul Cercueil * CPM registers offset address definition 187a01c190SPaul Cercueil */ 197a01c190SPaul Cercueil #define CGU_REG_CPCCR 0x00 207a01c190SPaul Cercueil #define CGU_REG_LCR 0x04 217a01c190SPaul Cercueil #define CGU_REG_CPPCR0 0x10 227a01c190SPaul Cercueil #define CGU_REG_CLKGR0 0x20 237a01c190SPaul Cercueil #define CGU_REG_OPCR 0x24 247a01c190SPaul Cercueil #define CGU_REG_CLKGR1 0x28 257a01c190SPaul Cercueil #define CGU_REG_CPPCR1 0x30 267a01c190SPaul Cercueil #define CGU_REG_USBPCR1 0x48 277a01c190SPaul Cercueil #define CGU_REG_USBCDR 0x50 287a01c190SPaul Cercueil #define CGU_REG_I2SCDR 0x60 297a01c190SPaul Cercueil #define CGU_REG_LPCDR 0x64 307a01c190SPaul Cercueil #define CGU_REG_MSC0CDR 0x68 317a01c190SPaul Cercueil #define CGU_REG_UHCCDR 0x6c 327a01c190SPaul Cercueil #define CGU_REG_SSICDR 0x74 337a01c190SPaul Cercueil #define CGU_REG_CIMCDR 0x7c 347a01c190SPaul Cercueil #define CGU_REG_GPSCDR 0x80 357a01c190SPaul Cercueil #define CGU_REG_PCMCDR 0x84 367a01c190SPaul Cercueil #define CGU_REG_GPUCDR 0x88 377a01c190SPaul Cercueil #define CGU_REG_MSC1CDR 0xA4 387a01c190SPaul Cercueil #define CGU_REG_MSC2CDR 0xA8 397a01c190SPaul Cercueil #define CGU_REG_BCHCDR 0xAC 407a01c190SPaul Cercueil 417a01c190SPaul Cercueil /* bits within the LCR register */ 427a01c190SPaul Cercueil #define LCR_LPM BIT(0) /* Low Power Mode */ 437a01c190SPaul Cercueil 447a01c190SPaul Cercueil /* bits within the OPCR register */ 457a01c190SPaul Cercueil #define OPCR_SPENDH BIT(5) /* UHC PHY suspend */ 467a01c190SPaul Cercueil 477a01c190SPaul Cercueil /* bits within the USBPCR1 register */ 487a01c190SPaul Cercueil #define USBPCR1_UHC_POWER BIT(5) /* UHC PHY power down */ 497a01c190SPaul Cercueil 507a01c190SPaul Cercueil static struct ingenic_cgu *cgu; 517a01c190SPaul Cercueil 527a01c190SPaul Cercueil static int jz4770_uhc_phy_enable(struct clk_hw *hw) 537a01c190SPaul Cercueil { 547a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR; 557a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1; 567a01c190SPaul Cercueil 577a01c190SPaul Cercueil writel(readl(reg_opcr) & ~OPCR_SPENDH, reg_opcr); 587a01c190SPaul Cercueil writel(readl(reg_usbpcr1) | USBPCR1_UHC_POWER, reg_usbpcr1); 597a01c190SPaul Cercueil return 0; 607a01c190SPaul Cercueil } 617a01c190SPaul Cercueil 627a01c190SPaul Cercueil static void jz4770_uhc_phy_disable(struct clk_hw *hw) 637a01c190SPaul Cercueil { 647a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR; 657a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1; 667a01c190SPaul Cercueil 677a01c190SPaul Cercueil writel(readl(reg_usbpcr1) & ~USBPCR1_UHC_POWER, reg_usbpcr1); 687a01c190SPaul Cercueil writel(readl(reg_opcr) | OPCR_SPENDH, reg_opcr); 697a01c190SPaul Cercueil } 707a01c190SPaul Cercueil 717a01c190SPaul Cercueil static int jz4770_uhc_phy_is_enabled(struct clk_hw *hw) 727a01c190SPaul Cercueil { 737a01c190SPaul Cercueil void __iomem *reg_opcr = cgu->base + CGU_REG_OPCR; 747a01c190SPaul Cercueil void __iomem *reg_usbpcr1 = cgu->base + CGU_REG_USBPCR1; 757a01c190SPaul Cercueil 767a01c190SPaul Cercueil return !(readl(reg_opcr) & OPCR_SPENDH) && 777a01c190SPaul Cercueil (readl(reg_usbpcr1) & USBPCR1_UHC_POWER); 787a01c190SPaul Cercueil } 797a01c190SPaul Cercueil 807a01c190SPaul Cercueil static const struct clk_ops jz4770_uhc_phy_ops = { 817a01c190SPaul Cercueil .enable = jz4770_uhc_phy_enable, 827a01c190SPaul Cercueil .disable = jz4770_uhc_phy_disable, 837a01c190SPaul Cercueil .is_enabled = jz4770_uhc_phy_is_enabled, 847a01c190SPaul Cercueil }; 857a01c190SPaul Cercueil 867a01c190SPaul Cercueil static const s8 pll_od_encoding[8] = { 877a01c190SPaul Cercueil 0x0, 0x1, -1, 0x2, -1, -1, -1, 0x3, 887a01c190SPaul Cercueil }; 897a01c190SPaul Cercueil 90*44b06a76SPaul Cercueil static const u8 jz4770_cgu_cpccr_div_table[] = { 91*44b06a76SPaul Cercueil 1, 2, 3, 4, 6, 8, 12, 92*44b06a76SPaul Cercueil }; 93*44b06a76SPaul Cercueil 947a01c190SPaul Cercueil static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = { 957a01c190SPaul Cercueil 967a01c190SPaul Cercueil /* External clocks */ 977a01c190SPaul Cercueil 987a01c190SPaul Cercueil [JZ4770_CLK_EXT] = { "ext", CGU_CLK_EXT }, 997a01c190SPaul Cercueil [JZ4770_CLK_OSC32K] = { "osc32k", CGU_CLK_EXT }, 1007a01c190SPaul Cercueil 1017a01c190SPaul Cercueil /* PLLs */ 1027a01c190SPaul Cercueil 1037a01c190SPaul Cercueil [JZ4770_CLK_PLL0] = { 1047a01c190SPaul Cercueil "pll0", CGU_CLK_PLL, 1057a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT }, 1067a01c190SPaul Cercueil .pll = { 1077a01c190SPaul Cercueil .reg = CGU_REG_CPPCR0, 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, 1187a01c190SPaul Cercueil .bypass_bit = 9, 1197a01c190SPaul Cercueil .enable_bit = 8, 1207a01c190SPaul Cercueil .stable_bit = 10, 1217a01c190SPaul Cercueil }, 1227a01c190SPaul Cercueil }, 1237a01c190SPaul Cercueil 1247a01c190SPaul Cercueil [JZ4770_CLK_PLL1] = { 1257a01c190SPaul Cercueil /* TODO: PLL1 can depend on PLL0 */ 1267a01c190SPaul Cercueil "pll1", CGU_CLK_PLL, 1277a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT }, 1287a01c190SPaul Cercueil .pll = { 1297a01c190SPaul Cercueil .reg = CGU_REG_CPPCR1, 1307a01c190SPaul Cercueil .m_shift = 24, 1317a01c190SPaul Cercueil .m_bits = 7, 1327a01c190SPaul Cercueil .m_offset = 1, 1337a01c190SPaul Cercueil .n_shift = 18, 1347a01c190SPaul Cercueil .n_bits = 5, 1357a01c190SPaul Cercueil .n_offset = 1, 1367a01c190SPaul Cercueil .od_shift = 16, 1377a01c190SPaul Cercueil .od_bits = 2, 1387a01c190SPaul Cercueil .od_max = 8, 1397a01c190SPaul Cercueil .od_encoding = pll_od_encoding, 1407a01c190SPaul Cercueil .enable_bit = 7, 1417a01c190SPaul Cercueil .stable_bit = 6, 1427a01c190SPaul Cercueil .no_bypass_bit = true, 1437a01c190SPaul Cercueil }, 1447a01c190SPaul Cercueil }, 1457a01c190SPaul Cercueil 1467a01c190SPaul Cercueil /* Main clocks */ 1477a01c190SPaul Cercueil 1487a01c190SPaul Cercueil [JZ4770_CLK_CCLK] = { 1497a01c190SPaul Cercueil "cclk", CGU_CLK_DIV, 1507a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 151*44b06a76SPaul Cercueil .div = { 152*44b06a76SPaul Cercueil CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1, 153*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 154*44b06a76SPaul Cercueil }, 1557a01c190SPaul Cercueil }, 1567a01c190SPaul Cercueil [JZ4770_CLK_H0CLK] = { 1577a01c190SPaul Cercueil "h0clk", CGU_CLK_DIV, 1587a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 159*44b06a76SPaul Cercueil .div = { 160*44b06a76SPaul Cercueil CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1, 161*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 162*44b06a76SPaul Cercueil }, 1637a01c190SPaul Cercueil }, 1647a01c190SPaul Cercueil [JZ4770_CLK_H1CLK] = { 1657a01c190SPaul Cercueil "h1clk", CGU_CLK_DIV | CGU_CLK_GATE, 1667a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 167*44b06a76SPaul Cercueil .div = { 168*44b06a76SPaul Cercueil CGU_REG_CPCCR, 24, 1, 4, 22, -1, -1, 169*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 170*44b06a76SPaul Cercueil }, 171a6523b6fSPaul Cercueil .gate = { CGU_REG_CLKGR1, 7 }, 1727a01c190SPaul Cercueil }, 1737a01c190SPaul Cercueil [JZ4770_CLK_H2CLK] = { 1747a01c190SPaul Cercueil "h2clk", CGU_CLK_DIV, 1757a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 176*44b06a76SPaul Cercueil .div = { 177*44b06a76SPaul Cercueil CGU_REG_CPCCR, 16, 1, 4, 22, -1, -1, 178*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 179*44b06a76SPaul Cercueil }, 1807a01c190SPaul Cercueil }, 1817a01c190SPaul Cercueil [JZ4770_CLK_C1CLK] = { 18245ba63a2SPaul Cercueil "c1clk", CGU_CLK_DIV | CGU_CLK_GATE, 1837a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 184*44b06a76SPaul Cercueil .div = { 185*44b06a76SPaul Cercueil CGU_REG_CPCCR, 12, 1, 4, 22, -1, -1, 186*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 187*44b06a76SPaul Cercueil }, 18845ba63a2SPaul Cercueil .gate = { CGU_REG_OPCR, 31, true }, // disable CCLK stop on idle 1897a01c190SPaul Cercueil }, 1907a01c190SPaul Cercueil [JZ4770_CLK_PCLK] = { 1917a01c190SPaul Cercueil "pclk", CGU_CLK_DIV, 1927a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, }, 193*44b06a76SPaul Cercueil .div = { 194*44b06a76SPaul Cercueil CGU_REG_CPCCR, 8, 1, 4, 22, -1, -1, 195*44b06a76SPaul Cercueil jz4770_cgu_cpccr_div_table, 196*44b06a76SPaul Cercueil }, 1977a01c190SPaul Cercueil }, 1987a01c190SPaul Cercueil 1997a01c190SPaul Cercueil /* Those divided clocks can connect to PLL0 or PLL1 */ 2007a01c190SPaul Cercueil 2017a01c190SPaul Cercueil [JZ4770_CLK_MMC0_MUX] = { 2027a01c190SPaul Cercueil "mmc0_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2037a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2047a01c190SPaul Cercueil .mux = { CGU_REG_MSC0CDR, 30, 1 }, 2057a01c190SPaul Cercueil .div = { CGU_REG_MSC0CDR, 0, 1, 7, -1, -1, 31 }, 2067a01c190SPaul Cercueil .gate = { CGU_REG_MSC0CDR, 31 }, 2077a01c190SPaul Cercueil }, 2087a01c190SPaul Cercueil [JZ4770_CLK_MMC1_MUX] = { 2097a01c190SPaul Cercueil "mmc1_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2107a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2117a01c190SPaul Cercueil .mux = { CGU_REG_MSC1CDR, 30, 1 }, 2127a01c190SPaul Cercueil .div = { CGU_REG_MSC1CDR, 0, 1, 7, -1, -1, 31 }, 2137a01c190SPaul Cercueil .gate = { CGU_REG_MSC1CDR, 31 }, 2147a01c190SPaul Cercueil }, 2157a01c190SPaul Cercueil [JZ4770_CLK_MMC2_MUX] = { 2167a01c190SPaul Cercueil "mmc2_mux", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2177a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2187a01c190SPaul Cercueil .mux = { CGU_REG_MSC2CDR, 30, 1 }, 2197a01c190SPaul Cercueil .div = { CGU_REG_MSC2CDR, 0, 1, 7, -1, -1, 31 }, 2207a01c190SPaul Cercueil .gate = { CGU_REG_MSC2CDR, 31 }, 2217a01c190SPaul Cercueil }, 2227a01c190SPaul Cercueil [JZ4770_CLK_CIM] = { 2237a01c190SPaul Cercueil "cim", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2247a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2257a01c190SPaul Cercueil .mux = { CGU_REG_CIMCDR, 31, 1 }, 2267a01c190SPaul Cercueil .div = { CGU_REG_CIMCDR, 0, 1, 8, -1, -1, -1 }, 2277a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 26 }, 2287a01c190SPaul Cercueil }, 2297a01c190SPaul Cercueil [JZ4770_CLK_UHC] = { 2307a01c190SPaul Cercueil "uhc", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2317a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2327a01c190SPaul Cercueil .mux = { CGU_REG_UHCCDR, 29, 1 }, 2337a01c190SPaul Cercueil .div = { CGU_REG_UHCCDR, 0, 1, 4, -1, -1, -1 }, 2347a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 24 }, 2357a01c190SPaul Cercueil }, 2367a01c190SPaul Cercueil [JZ4770_CLK_GPU] = { 2377a01c190SPaul Cercueil "gpu", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2387a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, -1 }, 2397a01c190SPaul Cercueil .mux = { CGU_REG_GPUCDR, 31, 1 }, 2407a01c190SPaul Cercueil .div = { CGU_REG_GPUCDR, 0, 1, 3, -1, -1, -1 }, 2417a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 9 }, 2427a01c190SPaul Cercueil }, 2437a01c190SPaul Cercueil [JZ4770_CLK_BCH] = { 2447a01c190SPaul Cercueil "bch", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2457a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2467a01c190SPaul Cercueil .mux = { CGU_REG_BCHCDR, 31, 1 }, 2477a01c190SPaul Cercueil .div = { CGU_REG_BCHCDR, 0, 1, 3, -1, -1, -1 }, 2487a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 1 }, 2497a01c190SPaul Cercueil }, 2507a01c190SPaul Cercueil [JZ4770_CLK_LPCLK_MUX] = { 2517a01c190SPaul Cercueil "lpclk", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2527a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2537a01c190SPaul Cercueil .mux = { CGU_REG_LPCDR, 29, 1 }, 2547a01c190SPaul Cercueil .div = { CGU_REG_LPCDR, 0, 1, 11, -1, -1, -1 }, 2557a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 28 }, 2567a01c190SPaul Cercueil }, 2577a01c190SPaul Cercueil [JZ4770_CLK_GPS] = { 2587a01c190SPaul Cercueil "gps", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2597a01c190SPaul Cercueil .parents = { JZ4770_CLK_PLL0, JZ4770_CLK_PLL1, }, 2607a01c190SPaul Cercueil .mux = { CGU_REG_GPSCDR, 31, 1 }, 2617a01c190SPaul Cercueil .div = { CGU_REG_GPSCDR, 0, 1, 4, -1, -1, -1 }, 2627a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 22 }, 2637a01c190SPaul Cercueil }, 2647a01c190SPaul Cercueil 2657a01c190SPaul Cercueil /* Those divided clocks can connect to EXT, PLL0 or PLL1 */ 2667a01c190SPaul Cercueil 2677a01c190SPaul Cercueil [JZ4770_CLK_SSI_MUX] = { 2687a01c190SPaul Cercueil "ssi_mux", CGU_CLK_DIV | CGU_CLK_MUX, 2697a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1, 2707a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 }, 2717a01c190SPaul Cercueil .mux = { CGU_REG_SSICDR, 30, 2 }, 2727a01c190SPaul Cercueil .div = { CGU_REG_SSICDR, 0, 1, 6, -1, -1, -1 }, 2737a01c190SPaul Cercueil }, 2747a01c190SPaul Cercueil [JZ4770_CLK_PCM_MUX] = { 2757a01c190SPaul Cercueil "pcm_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_PCMCDR, 30, 2 }, 2797a01c190SPaul Cercueil .div = { CGU_REG_PCMCDR, 0, 1, 9, -1, -1, -1 }, 2807a01c190SPaul Cercueil }, 2817a01c190SPaul Cercueil [JZ4770_CLK_I2S] = { 2827a01c190SPaul Cercueil "i2s", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2837a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1, 2847a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 }, 2857a01c190SPaul Cercueil .mux = { CGU_REG_I2SCDR, 30, 2 }, 2867a01c190SPaul Cercueil .div = { CGU_REG_I2SCDR, 0, 1, 9, -1, -1, -1 }, 2877a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 13 }, 2887a01c190SPaul Cercueil }, 2897a01c190SPaul Cercueil [JZ4770_CLK_OTG] = { 2907a01c190SPaul Cercueil "usb", CGU_CLK_DIV | CGU_CLK_GATE | CGU_CLK_MUX, 2917a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, -1, 2927a01c190SPaul Cercueil JZ4770_CLK_PLL0, JZ4770_CLK_PLL1 }, 2937a01c190SPaul Cercueil .mux = { CGU_REG_USBCDR, 30, 2 }, 2947a01c190SPaul Cercueil .div = { CGU_REG_USBCDR, 0, 1, 8, -1, -1, -1 }, 2957a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 2 }, 2967a01c190SPaul Cercueil }, 2977a01c190SPaul Cercueil 2987a01c190SPaul Cercueil /* Gate-only clocks */ 2997a01c190SPaul Cercueil 3007a01c190SPaul Cercueil [JZ4770_CLK_SSI0] = { 3017a01c190SPaul Cercueil "ssi0", CGU_CLK_GATE, 3027a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, }, 3037a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 4 }, 3047a01c190SPaul Cercueil }, 3057a01c190SPaul Cercueil [JZ4770_CLK_SSI1] = { 3067a01c190SPaul Cercueil "ssi1", CGU_CLK_GATE, 3077a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, }, 3087a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 19 }, 3097a01c190SPaul Cercueil }, 3107a01c190SPaul Cercueil [JZ4770_CLK_SSI2] = { 3117a01c190SPaul Cercueil "ssi2", CGU_CLK_GATE, 3127a01c190SPaul Cercueil .parents = { JZ4770_CLK_SSI_MUX, }, 3137a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 20 }, 3147a01c190SPaul Cercueil }, 3157a01c190SPaul Cercueil [JZ4770_CLK_PCM0] = { 3167a01c190SPaul Cercueil "pcm0", CGU_CLK_GATE, 3177a01c190SPaul Cercueil .parents = { JZ4770_CLK_PCM_MUX, }, 3187a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 8 }, 3197a01c190SPaul Cercueil }, 3207a01c190SPaul Cercueil [JZ4770_CLK_PCM1] = { 3217a01c190SPaul Cercueil "pcm1", CGU_CLK_GATE, 3227a01c190SPaul Cercueil .parents = { JZ4770_CLK_PCM_MUX, }, 3237a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 10 }, 3247a01c190SPaul Cercueil }, 3257a01c190SPaul Cercueil [JZ4770_CLK_DMA] = { 3267a01c190SPaul Cercueil "dma", CGU_CLK_GATE, 3277a01c190SPaul Cercueil .parents = { JZ4770_CLK_H2CLK, }, 3287a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 21 }, 3297a01c190SPaul Cercueil }, 3307a01c190SPaul Cercueil [JZ4770_CLK_I2C0] = { 3317a01c190SPaul Cercueil "i2c0", CGU_CLK_GATE, 3327a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3337a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 5 }, 3347a01c190SPaul Cercueil }, 3357a01c190SPaul Cercueil [JZ4770_CLK_I2C1] = { 3367a01c190SPaul Cercueil "i2c1", CGU_CLK_GATE, 3377a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3387a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 6 }, 3397a01c190SPaul Cercueil }, 3407a01c190SPaul Cercueil [JZ4770_CLK_I2C2] = { 3417a01c190SPaul Cercueil "i2c2", CGU_CLK_GATE, 3427a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3437a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 15 }, 3447a01c190SPaul Cercueil }, 3457a01c190SPaul Cercueil [JZ4770_CLK_UART0] = { 3467a01c190SPaul Cercueil "uart0", CGU_CLK_GATE, 3477a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3487a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 15 }, 3497a01c190SPaul Cercueil }, 3507a01c190SPaul Cercueil [JZ4770_CLK_UART1] = { 3517a01c190SPaul Cercueil "uart1", CGU_CLK_GATE, 3527a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3537a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 16 }, 3547a01c190SPaul Cercueil }, 3557a01c190SPaul Cercueil [JZ4770_CLK_UART2] = { 3567a01c190SPaul Cercueil "uart2", CGU_CLK_GATE, 3577a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3587a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 17 }, 3597a01c190SPaul Cercueil }, 3607a01c190SPaul Cercueil [JZ4770_CLK_UART3] = { 3617a01c190SPaul Cercueil "uart3", CGU_CLK_GATE, 3627a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3637a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 18 }, 3647a01c190SPaul Cercueil }, 3657a01c190SPaul Cercueil [JZ4770_CLK_IPU] = { 3667a01c190SPaul Cercueil "ipu", CGU_CLK_GATE, 3677a01c190SPaul Cercueil .parents = { JZ4770_CLK_H0CLK, }, 3687a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 29 }, 3697a01c190SPaul Cercueil }, 3707a01c190SPaul Cercueil [JZ4770_CLK_ADC] = { 3717a01c190SPaul Cercueil "adc", CGU_CLK_GATE, 3727a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3737a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 14 }, 3747a01c190SPaul Cercueil }, 3757a01c190SPaul Cercueil [JZ4770_CLK_AIC] = { 3767a01c190SPaul Cercueil "aic", CGU_CLK_GATE, 3777a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT, }, 3787a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 8 }, 3797a01c190SPaul Cercueil }, 3807a01c190SPaul Cercueil [JZ4770_CLK_AUX] = { 3817a01c190SPaul Cercueil "aux", CGU_CLK_GATE, 3827a01c190SPaul Cercueil .parents = { JZ4770_CLK_C1CLK, }, 3837a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR1, 14 }, 3847a01c190SPaul Cercueil }, 3857a01c190SPaul Cercueil [JZ4770_CLK_VPU] = { 3867a01c190SPaul Cercueil "vpu", CGU_CLK_GATE, 3877a01c190SPaul Cercueil .parents = { JZ4770_CLK_H1CLK, }, 3886ee3d385SPaul Cercueil .gate = { CGU_REG_LCR, 30, false, 150 }, 3897a01c190SPaul Cercueil }, 3907a01c190SPaul Cercueil [JZ4770_CLK_MMC0] = { 3917a01c190SPaul Cercueil "mmc0", CGU_CLK_GATE, 3927a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC0_MUX, }, 3937a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 3 }, 3947a01c190SPaul Cercueil }, 3957a01c190SPaul Cercueil [JZ4770_CLK_MMC1] = { 3967a01c190SPaul Cercueil "mmc1", CGU_CLK_GATE, 3977a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC1_MUX, }, 3987a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 11 }, 3997a01c190SPaul Cercueil }, 4007a01c190SPaul Cercueil [JZ4770_CLK_MMC2] = { 4017a01c190SPaul Cercueil "mmc2", CGU_CLK_GATE, 4027a01c190SPaul Cercueil .parents = { JZ4770_CLK_MMC2_MUX, }, 4037a01c190SPaul Cercueil .gate = { CGU_REG_CLKGR0, 12 }, 4047a01c190SPaul Cercueil }, 40511b689a3SPaul Cercueil [JZ4770_CLK_OTG_PHY] = { 40611b689a3SPaul Cercueil "usb_phy", CGU_CLK_GATE, 40711b689a3SPaul Cercueil .parents = { JZ4770_CLK_OTG }, 40811b689a3SPaul Cercueil .gate = { CGU_REG_OPCR, 7, true, 50 }, 40911b689a3SPaul Cercueil }, 4107a01c190SPaul Cercueil 4117a01c190SPaul Cercueil /* Custom clocks */ 4127a01c190SPaul Cercueil 4137a01c190SPaul Cercueil [JZ4770_CLK_UHC_PHY] = { 4147a01c190SPaul Cercueil "uhc_phy", CGU_CLK_CUSTOM, 4157a01c190SPaul Cercueil .parents = { JZ4770_CLK_UHC, -1, -1, -1 }, 4167a01c190SPaul Cercueil .custom = { &jz4770_uhc_phy_ops }, 4177a01c190SPaul Cercueil }, 4187a01c190SPaul Cercueil 4197a01c190SPaul Cercueil [JZ4770_CLK_EXT512] = { 4207a01c190SPaul Cercueil "ext/512", CGU_CLK_FIXDIV, 4217a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT }, 4227a01c190SPaul Cercueil .fixdiv = { 512 }, 4237a01c190SPaul Cercueil }, 4247a01c190SPaul Cercueil 4257a01c190SPaul Cercueil [JZ4770_CLK_RTC] = { 4267a01c190SPaul Cercueil "rtc", CGU_CLK_MUX, 4277a01c190SPaul Cercueil .parents = { JZ4770_CLK_EXT512, JZ4770_CLK_OSC32K, }, 4287a01c190SPaul Cercueil .mux = { CGU_REG_OPCR, 2, 1}, 4297a01c190SPaul Cercueil }, 4307a01c190SPaul Cercueil }; 4317a01c190SPaul Cercueil 4327a01c190SPaul Cercueil #if IS_ENABLED(CONFIG_PM_SLEEP) 4337a01c190SPaul Cercueil static int jz4770_cgu_pm_suspend(void) 4347a01c190SPaul Cercueil { 4357a01c190SPaul Cercueil u32 val; 4367a01c190SPaul Cercueil 4377a01c190SPaul Cercueil val = readl(cgu->base + CGU_REG_LCR); 4387a01c190SPaul Cercueil writel(val | LCR_LPM, cgu->base + CGU_REG_LCR); 4397a01c190SPaul Cercueil return 0; 4407a01c190SPaul Cercueil } 4417a01c190SPaul Cercueil 4427a01c190SPaul Cercueil static void jz4770_cgu_pm_resume(void) 4437a01c190SPaul Cercueil { 4447a01c190SPaul Cercueil u32 val; 4457a01c190SPaul Cercueil 4467a01c190SPaul Cercueil val = readl(cgu->base + CGU_REG_LCR); 4477a01c190SPaul Cercueil writel(val & ~LCR_LPM, cgu->base + CGU_REG_LCR); 4487a01c190SPaul Cercueil } 4497a01c190SPaul Cercueil 4507a01c190SPaul Cercueil static struct syscore_ops jz4770_cgu_pm_ops = { 4517a01c190SPaul Cercueil .suspend = jz4770_cgu_pm_suspend, 4527a01c190SPaul Cercueil .resume = jz4770_cgu_pm_resume, 4537a01c190SPaul Cercueil }; 4547a01c190SPaul Cercueil #endif /* CONFIG_PM_SLEEP */ 4557a01c190SPaul Cercueil 4567a01c190SPaul Cercueil static void __init jz4770_cgu_init(struct device_node *np) 4577a01c190SPaul Cercueil { 4587a01c190SPaul Cercueil int retval; 4597a01c190SPaul Cercueil 4607a01c190SPaul Cercueil cgu = ingenic_cgu_new(jz4770_cgu_clocks, 4617a01c190SPaul Cercueil ARRAY_SIZE(jz4770_cgu_clocks), np); 4627a01c190SPaul Cercueil if (!cgu) 4637a01c190SPaul Cercueil pr_err("%s: failed to initialise CGU\n", __func__); 4647a01c190SPaul Cercueil 4657a01c190SPaul Cercueil retval = ingenic_cgu_register_clocks(cgu); 4667a01c190SPaul Cercueil if (retval) 4677a01c190SPaul Cercueil pr_err("%s: failed to register CGU Clocks\n", __func__); 4687a01c190SPaul Cercueil 4697a01c190SPaul Cercueil #if IS_ENABLED(CONFIG_PM_SLEEP) 4707a01c190SPaul Cercueil register_syscore_ops(&jz4770_cgu_pm_ops); 4717a01c190SPaul Cercueil #endif 4727a01c190SPaul Cercueil } 4737a01c190SPaul Cercueil 4747a01c190SPaul Cercueil /* We only probe via devicetree, no need for a platform driver */ 4757a01c190SPaul Cercueil CLK_OF_DECLARE(jz4770_cgu, "ingenic,jz4770-cgu", jz4770_cgu_init); 476