18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Hisilicon Hi3620 clock driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2012-2013 Hisilicon Limited.
68c2ecf20Sopenharmony_ci * Copyright (c) 2012-2013 Linaro Limited.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Author: Haojian Zhuang <haojian.zhuang@linaro.org>
98c2ecf20Sopenharmony_ci *	   Xin Li <li.xin@linaro.org>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/kernel.h>
138c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
148c2ecf20Sopenharmony_ci#include <linux/io.h>
158c2ecf20Sopenharmony_ci#include <linux/of.h>
168c2ecf20Sopenharmony_ci#include <linux/of_address.h>
178c2ecf20Sopenharmony_ci#include <linux/of_device.h>
188c2ecf20Sopenharmony_ci#include <linux/slab.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <dt-bindings/clock/hi3620-clock.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "clk.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* clock parent list */
258c2ecf20Sopenharmony_cistatic const char *const timer0_mux_p[] __initconst = { "osc32k", "timerclk01", };
268c2ecf20Sopenharmony_cistatic const char *const timer1_mux_p[] __initconst = { "osc32k", "timerclk01", };
278c2ecf20Sopenharmony_cistatic const char *const timer2_mux_p[] __initconst = { "osc32k", "timerclk23", };
288c2ecf20Sopenharmony_cistatic const char *const timer3_mux_p[] __initconst = { "osc32k", "timerclk23", };
298c2ecf20Sopenharmony_cistatic const char *const timer4_mux_p[] __initconst = { "osc32k", "timerclk45", };
308c2ecf20Sopenharmony_cistatic const char *const timer5_mux_p[] __initconst = { "osc32k", "timerclk45", };
318c2ecf20Sopenharmony_cistatic const char *const timer6_mux_p[] __initconst = { "osc32k", "timerclk67", };
328c2ecf20Sopenharmony_cistatic const char *const timer7_mux_p[] __initconst = { "osc32k", "timerclk67", };
338c2ecf20Sopenharmony_cistatic const char *const timer8_mux_p[] __initconst = { "osc32k", "timerclk89", };
348c2ecf20Sopenharmony_cistatic const char *const timer9_mux_p[] __initconst = { "osc32k", "timerclk89", };
358c2ecf20Sopenharmony_cistatic const char *const uart0_mux_p[] __initconst = { "osc26m", "pclk", };
368c2ecf20Sopenharmony_cistatic const char *const uart1_mux_p[] __initconst = { "osc26m", "pclk", };
378c2ecf20Sopenharmony_cistatic const char *const uart2_mux_p[] __initconst = { "osc26m", "pclk", };
388c2ecf20Sopenharmony_cistatic const char *const uart3_mux_p[] __initconst = { "osc26m", "pclk", };
398c2ecf20Sopenharmony_cistatic const char *const uart4_mux_p[] __initconst = { "osc26m", "pclk", };
408c2ecf20Sopenharmony_cistatic const char *const spi0_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", };
418c2ecf20Sopenharmony_cistatic const char *const spi1_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", };
428c2ecf20Sopenharmony_cistatic const char *const spi2_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", };
438c2ecf20Sopenharmony_ci/* share axi parent */
448c2ecf20Sopenharmony_cistatic const char *const saxi_mux_p[] __initconst = { "armpll3", "armpll2", };
458c2ecf20Sopenharmony_cistatic const char *const pwm0_mux_p[] __initconst = { "osc32k", "osc26m", };
468c2ecf20Sopenharmony_cistatic const char *const pwm1_mux_p[] __initconst = { "osc32k", "osc26m", };
478c2ecf20Sopenharmony_cistatic const char *const sd_mux_p[] __initconst = { "armpll2", "armpll3", };
488c2ecf20Sopenharmony_cistatic const char *const mmc1_mux_p[] __initconst = { "armpll2", "armpll3", };
498c2ecf20Sopenharmony_cistatic const char *const mmc1_mux2_p[] __initconst = { "osc26m", "mmc1_div", };
508c2ecf20Sopenharmony_cistatic const char *const g2d_mux_p[] __initconst = { "armpll2", "armpll3", };
518c2ecf20Sopenharmony_cistatic const char *const venc_mux_p[] __initconst = { "armpll2", "armpll3", };
528c2ecf20Sopenharmony_cistatic const char *const vdec_mux_p[] __initconst = { "armpll2", "armpll3", };
538c2ecf20Sopenharmony_cistatic const char *const vpp_mux_p[] __initconst = { "armpll2", "armpll3", };
548c2ecf20Sopenharmony_cistatic const char *const edc0_mux_p[] __initconst = { "armpll2", "armpll3", };
558c2ecf20Sopenharmony_cistatic const char *const ldi0_mux_p[] __initconst = { "armpll2", "armpll4",
568c2ecf20Sopenharmony_ci					     "armpll3", "armpll5", };
578c2ecf20Sopenharmony_cistatic const char *const edc1_mux_p[] __initconst = { "armpll2", "armpll3", };
588c2ecf20Sopenharmony_cistatic const char *const ldi1_mux_p[] __initconst = { "armpll2", "armpll4",
598c2ecf20Sopenharmony_ci					     "armpll3", "armpll5", };
608c2ecf20Sopenharmony_cistatic const char *const rclk_hsic_p[] __initconst = { "armpll3", "armpll2", };
618c2ecf20Sopenharmony_cistatic const char *const mmc2_mux_p[] __initconst = { "armpll2", "armpll3", };
628c2ecf20Sopenharmony_cistatic const char *const mmc3_mux_p[] __initconst = { "armpll2", "armpll3", };
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* fixed rate clocks */
668c2ecf20Sopenharmony_cistatic struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] __initdata = {
678c2ecf20Sopenharmony_ci	{ HI3620_OSC32K,   "osc32k",   NULL, 0, 32768, },
688c2ecf20Sopenharmony_ci	{ HI3620_OSC26M,   "osc26m",   NULL, 0, 26000000, },
698c2ecf20Sopenharmony_ci	{ HI3620_PCLK,     "pclk",     NULL, 0, 26000000, },
708c2ecf20Sopenharmony_ci	{ HI3620_PLL_ARM0, "armpll0",  NULL, 0, 1600000000, },
718c2ecf20Sopenharmony_ci	{ HI3620_PLL_ARM1, "armpll1",  NULL, 0, 1600000000, },
728c2ecf20Sopenharmony_ci	{ HI3620_PLL_PERI, "armpll2",  NULL, 0, 1440000000, },
738c2ecf20Sopenharmony_ci	{ HI3620_PLL_USB,  "armpll3",  NULL, 0, 1440000000, },
748c2ecf20Sopenharmony_ci	{ HI3620_PLL_HDMI, "armpll4",  NULL, 0, 1188000000, },
758c2ecf20Sopenharmony_ci	{ HI3620_PLL_GPU,  "armpll5",  NULL, 0, 1300000000, },
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* fixed factor clocks */
798c2ecf20Sopenharmony_cistatic struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] __initdata = {
808c2ecf20Sopenharmony_ci	{ HI3620_RCLK_TCXO,   "rclk_tcxo",   "osc26m",   1, 4,  0, },
818c2ecf20Sopenharmony_ci	{ HI3620_RCLK_CFGAXI, "rclk_cfgaxi", "armpll2",  1, 30, 0, },
828c2ecf20Sopenharmony_ci	{ HI3620_RCLK_PICO,   "rclk_pico",   "hsic_div", 1, 40, 0, },
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic struct hisi_mux_clock hi3620_mux_clks[] __initdata = {
868c2ecf20Sopenharmony_ci	{ HI3620_TIMER0_MUX, "timer0_mux", timer0_mux_p, ARRAY_SIZE(timer0_mux_p), CLK_SET_RATE_PARENT, 0,     15, 2, 0,                   },
878c2ecf20Sopenharmony_ci	{ HI3620_TIMER1_MUX, "timer1_mux", timer1_mux_p, ARRAY_SIZE(timer1_mux_p), CLK_SET_RATE_PARENT, 0,     17, 2, 0,                   },
888c2ecf20Sopenharmony_ci	{ HI3620_TIMER2_MUX, "timer2_mux", timer2_mux_p, ARRAY_SIZE(timer2_mux_p), CLK_SET_RATE_PARENT, 0,     19, 2, 0,                   },
898c2ecf20Sopenharmony_ci	{ HI3620_TIMER3_MUX, "timer3_mux", timer3_mux_p, ARRAY_SIZE(timer3_mux_p), CLK_SET_RATE_PARENT, 0,     21, 2, 0,                   },
908c2ecf20Sopenharmony_ci	{ HI3620_TIMER4_MUX, "timer4_mux", timer4_mux_p, ARRAY_SIZE(timer4_mux_p), CLK_SET_RATE_PARENT, 0x18,  0,  2, 0,                   },
918c2ecf20Sopenharmony_ci	{ HI3620_TIMER5_MUX, "timer5_mux", timer5_mux_p, ARRAY_SIZE(timer5_mux_p), CLK_SET_RATE_PARENT, 0x18,  2,  2, 0,                   },
928c2ecf20Sopenharmony_ci	{ HI3620_TIMER6_MUX, "timer6_mux", timer6_mux_p, ARRAY_SIZE(timer6_mux_p), CLK_SET_RATE_PARENT, 0x18,  4,  2, 0,                   },
938c2ecf20Sopenharmony_ci	{ HI3620_TIMER7_MUX, "timer7_mux", timer7_mux_p, ARRAY_SIZE(timer7_mux_p), CLK_SET_RATE_PARENT, 0x18,  6,  2, 0,                   },
948c2ecf20Sopenharmony_ci	{ HI3620_TIMER8_MUX, "timer8_mux", timer8_mux_p, ARRAY_SIZE(timer8_mux_p), CLK_SET_RATE_PARENT, 0x18,  8,  2, 0,                   },
958c2ecf20Sopenharmony_ci	{ HI3620_TIMER9_MUX, "timer9_mux", timer9_mux_p, ARRAY_SIZE(timer9_mux_p), CLK_SET_RATE_PARENT, 0x18,  10, 2, 0,                   },
968c2ecf20Sopenharmony_ci	{ HI3620_UART0_MUX,  "uart0_mux",  uart0_mux_p,  ARRAY_SIZE(uart0_mux_p),  CLK_SET_RATE_PARENT, 0x100, 7,  1, CLK_MUX_HIWORD_MASK, },
978c2ecf20Sopenharmony_ci	{ HI3620_UART1_MUX,  "uart1_mux",  uart1_mux_p,  ARRAY_SIZE(uart1_mux_p),  CLK_SET_RATE_PARENT, 0x100, 8,  1, CLK_MUX_HIWORD_MASK, },
988c2ecf20Sopenharmony_ci	{ HI3620_UART2_MUX,  "uart2_mux",  uart2_mux_p,  ARRAY_SIZE(uart2_mux_p),  CLK_SET_RATE_PARENT, 0x100, 9,  1, CLK_MUX_HIWORD_MASK, },
998c2ecf20Sopenharmony_ci	{ HI3620_UART3_MUX,  "uart3_mux",  uart3_mux_p,  ARRAY_SIZE(uart3_mux_p),  CLK_SET_RATE_PARENT, 0x100, 10, 1, CLK_MUX_HIWORD_MASK, },
1008c2ecf20Sopenharmony_ci	{ HI3620_UART4_MUX,  "uart4_mux",  uart4_mux_p,  ARRAY_SIZE(uart4_mux_p),  CLK_SET_RATE_PARENT, 0x100, 11, 1, CLK_MUX_HIWORD_MASK, },
1018c2ecf20Sopenharmony_ci	{ HI3620_SPI0_MUX,   "spi0_mux",   spi0_mux_p,   ARRAY_SIZE(spi0_mux_p),   CLK_SET_RATE_PARENT, 0x100, 12, 1, CLK_MUX_HIWORD_MASK, },
1028c2ecf20Sopenharmony_ci	{ HI3620_SPI1_MUX,   "spi1_mux",   spi1_mux_p,   ARRAY_SIZE(spi1_mux_p),   CLK_SET_RATE_PARENT, 0x100, 13, 1, CLK_MUX_HIWORD_MASK, },
1038c2ecf20Sopenharmony_ci	{ HI3620_SPI2_MUX,   "spi2_mux",   spi2_mux_p,   ARRAY_SIZE(spi2_mux_p),   CLK_SET_RATE_PARENT, 0x100, 14, 1, CLK_MUX_HIWORD_MASK, },
1048c2ecf20Sopenharmony_ci	{ HI3620_SAXI_MUX,   "saxi_mux",   saxi_mux_p,   ARRAY_SIZE(saxi_mux_p),   CLK_SET_RATE_PARENT, 0x100, 15, 1, CLK_MUX_HIWORD_MASK, },
1058c2ecf20Sopenharmony_ci	{ HI3620_PWM0_MUX,   "pwm0_mux",   pwm0_mux_p,   ARRAY_SIZE(pwm0_mux_p),   CLK_SET_RATE_PARENT, 0x104, 10, 1, CLK_MUX_HIWORD_MASK, },
1068c2ecf20Sopenharmony_ci	{ HI3620_PWM1_MUX,   "pwm1_mux",   pwm1_mux_p,   ARRAY_SIZE(pwm1_mux_p),   CLK_SET_RATE_PARENT, 0x104, 11, 1, CLK_MUX_HIWORD_MASK, },
1078c2ecf20Sopenharmony_ci	{ HI3620_SD_MUX,     "sd_mux",     sd_mux_p,     ARRAY_SIZE(sd_mux_p),     CLK_SET_RATE_PARENT, 0x108, 4,  1, CLK_MUX_HIWORD_MASK, },
1088c2ecf20Sopenharmony_ci	{ HI3620_MMC1_MUX,   "mmc1_mux",   mmc1_mux_p,   ARRAY_SIZE(mmc1_mux_p),   CLK_SET_RATE_PARENT, 0x108, 9,  1, CLK_MUX_HIWORD_MASK, },
1098c2ecf20Sopenharmony_ci	{ HI3620_MMC1_MUX2,  "mmc1_mux2",  mmc1_mux2_p,  ARRAY_SIZE(mmc1_mux2_p),  CLK_SET_RATE_PARENT, 0x108, 10, 1, CLK_MUX_HIWORD_MASK, },
1108c2ecf20Sopenharmony_ci	{ HI3620_G2D_MUX,    "g2d_mux",    g2d_mux_p,    ARRAY_SIZE(g2d_mux_p),    CLK_SET_RATE_PARENT, 0x10c, 5,  1, CLK_MUX_HIWORD_MASK, },
1118c2ecf20Sopenharmony_ci	{ HI3620_VENC_MUX,   "venc_mux",   venc_mux_p,   ARRAY_SIZE(venc_mux_p),   CLK_SET_RATE_PARENT, 0x10c, 11, 1, CLK_MUX_HIWORD_MASK, },
1128c2ecf20Sopenharmony_ci	{ HI3620_VDEC_MUX,   "vdec_mux",   vdec_mux_p,   ARRAY_SIZE(vdec_mux_p),   CLK_SET_RATE_PARENT, 0x110, 5,  1, CLK_MUX_HIWORD_MASK, },
1138c2ecf20Sopenharmony_ci	{ HI3620_VPP_MUX,    "vpp_mux",    vpp_mux_p,    ARRAY_SIZE(vpp_mux_p),    CLK_SET_RATE_PARENT, 0x110, 11, 1, CLK_MUX_HIWORD_MASK, },
1148c2ecf20Sopenharmony_ci	{ HI3620_EDC0_MUX,   "edc0_mux",   edc0_mux_p,   ARRAY_SIZE(edc0_mux_p),   CLK_SET_RATE_PARENT, 0x114, 6,  1, CLK_MUX_HIWORD_MASK, },
1158c2ecf20Sopenharmony_ci	{ HI3620_LDI0_MUX,   "ldi0_mux",   ldi0_mux_p,   ARRAY_SIZE(ldi0_mux_p),   CLK_SET_RATE_PARENT, 0x114, 13, 2, CLK_MUX_HIWORD_MASK, },
1168c2ecf20Sopenharmony_ci	{ HI3620_EDC1_MUX,   "edc1_mux",   edc1_mux_p,   ARRAY_SIZE(edc1_mux_p),   CLK_SET_RATE_PARENT, 0x118, 6,  1, CLK_MUX_HIWORD_MASK, },
1178c2ecf20Sopenharmony_ci	{ HI3620_LDI1_MUX,   "ldi1_mux",   ldi1_mux_p,   ARRAY_SIZE(ldi1_mux_p),   CLK_SET_RATE_PARENT, 0x118, 14, 2, CLK_MUX_HIWORD_MASK, },
1188c2ecf20Sopenharmony_ci	{ HI3620_RCLK_HSIC,  "rclk_hsic",  rclk_hsic_p,  ARRAY_SIZE(rclk_hsic_p),  CLK_SET_RATE_PARENT, 0x130, 2,  1, CLK_MUX_HIWORD_MASK, },
1198c2ecf20Sopenharmony_ci	{ HI3620_MMC2_MUX,   "mmc2_mux",   mmc2_mux_p,   ARRAY_SIZE(mmc2_mux_p),   CLK_SET_RATE_PARENT, 0x140, 4,  1, CLK_MUX_HIWORD_MASK, },
1208c2ecf20Sopenharmony_ci	{ HI3620_MMC3_MUX,   "mmc3_mux",   mmc3_mux_p,   ARRAY_SIZE(mmc3_mux_p),   CLK_SET_RATE_PARENT, 0x140, 9,  1, CLK_MUX_HIWORD_MASK, },
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic struct hisi_divider_clock hi3620_div_clks[] __initdata = {
1248c2ecf20Sopenharmony_ci	{ HI3620_SHAREAXI_DIV, "saxi_div",   "saxi_mux",  0, 0x100, 0, 5, CLK_DIVIDER_HIWORD_MASK, NULL, },
1258c2ecf20Sopenharmony_ci	{ HI3620_CFGAXI_DIV,   "cfgaxi_div", "saxi_div",  0, 0x100, 5, 2, CLK_DIVIDER_HIWORD_MASK, NULL, },
1268c2ecf20Sopenharmony_ci	{ HI3620_SD_DIV,       "sd_div",     "sd_mux",	  0, 0x108, 0, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
1278c2ecf20Sopenharmony_ci	{ HI3620_MMC1_DIV,     "mmc1_div",   "mmc1_mux",  0, 0x108, 5, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
1288c2ecf20Sopenharmony_ci	{ HI3620_HSIC_DIV,     "hsic_div",   "rclk_hsic", 0, 0x130, 0, 2, CLK_DIVIDER_HIWORD_MASK, NULL, },
1298c2ecf20Sopenharmony_ci	{ HI3620_MMC2_DIV,     "mmc2_div",   "mmc2_mux",  0, 0x140, 0, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
1308c2ecf20Sopenharmony_ci	{ HI3620_MMC3_DIV,     "mmc3_div",   "mmc3_mux",  0, 0x140, 5, 4, CLK_DIVIDER_HIWORD_MASK, NULL, },
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = {
1348c2ecf20Sopenharmony_ci	{ HI3620_TIMERCLK01,   "timerclk01",   "timer_rclk01", CLK_SET_RATE_PARENT, 0x20, 0, 0, },
1358c2ecf20Sopenharmony_ci	{ HI3620_TIMER_RCLK01, "timer_rclk01", "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x20, 1, 0, },
1368c2ecf20Sopenharmony_ci	{ HI3620_TIMERCLK23,   "timerclk23",   "timer_rclk23", CLK_SET_RATE_PARENT, 0x20, 2, 0, },
1378c2ecf20Sopenharmony_ci	{ HI3620_TIMER_RCLK23, "timer_rclk23", "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x20, 3, 0, },
1388c2ecf20Sopenharmony_ci	{ HI3620_RTCCLK,       "rtcclk",       "pclk",         CLK_SET_RATE_PARENT, 0x20, 5, 0, },
1398c2ecf20Sopenharmony_ci	{ HI3620_KPC_CLK,      "kpc_clk",      "pclk",         CLK_SET_RATE_PARENT, 0x20, 6, 0, },
1408c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK0,     "gpioclk0",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 8, 0, },
1418c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK1,     "gpioclk1",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 9, 0, },
1428c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK2,     "gpioclk2",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 10, 0, },
1438c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK3,     "gpioclk3",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 11, 0, },
1448c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK4,     "gpioclk4",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 12, 0, },
1458c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK5,     "gpioclk5",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 13, 0, },
1468c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK6,     "gpioclk6",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 14, 0, },
1478c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK7,     "gpioclk7",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 15, 0, },
1488c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK8,     "gpioclk8",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 16, 0, },
1498c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK9,     "gpioclk9",     "pclk",         CLK_SET_RATE_PARENT, 0x20, 17, 0, },
1508c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK10,    "gpioclk10",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 18, 0, },
1518c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK11,    "gpioclk11",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 19, 0, },
1528c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK12,    "gpioclk12",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 20, 0, },
1538c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK13,    "gpioclk13",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 21, 0, },
1548c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK14,    "gpioclk14",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 22, 0, },
1558c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK15,    "gpioclk15",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 23, 0, },
1568c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK16,    "gpioclk16",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 24, 0, },
1578c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK17,    "gpioclk17",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 25, 0, },
1588c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK18,    "gpioclk18",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 26, 0, },
1598c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK19,    "gpioclk19",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 27, 0, },
1608c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK20,    "gpioclk20",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 28, 0, },
1618c2ecf20Sopenharmony_ci	{ HI3620_GPIOCLK21,    "gpioclk21",    "pclk",         CLK_SET_RATE_PARENT, 0x20, 29, 0, },
1628c2ecf20Sopenharmony_ci	{ HI3620_DPHY0_CLK,    "dphy0_clk",    "osc26m",       CLK_SET_RATE_PARENT, 0x30, 15, 0, },
1638c2ecf20Sopenharmony_ci	{ HI3620_DPHY1_CLK,    "dphy1_clk",    "osc26m",       CLK_SET_RATE_PARENT, 0x30, 16, 0, },
1648c2ecf20Sopenharmony_ci	{ HI3620_DPHY2_CLK,    "dphy2_clk",    "osc26m",       CLK_SET_RATE_PARENT, 0x30, 17, 0, },
1658c2ecf20Sopenharmony_ci	{ HI3620_USBPHY_CLK,   "usbphy_clk",   "rclk_pico",    CLK_SET_RATE_PARENT, 0x30, 24, 0, },
1668c2ecf20Sopenharmony_ci	{ HI3620_ACP_CLK,      "acp_clk",      "rclk_cfgaxi",  CLK_SET_RATE_PARENT, 0x30, 28, 0, },
1678c2ecf20Sopenharmony_ci	{ HI3620_TIMERCLK45,   "timerclk45",   "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x40, 3, 0, },
1688c2ecf20Sopenharmony_ci	{ HI3620_TIMERCLK67,   "timerclk67",   "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x40, 4, 0, },
1698c2ecf20Sopenharmony_ci	{ HI3620_TIMERCLK89,   "timerclk89",   "rclk_tcxo",    CLK_SET_RATE_PARENT, 0x40, 5, 0, },
1708c2ecf20Sopenharmony_ci	{ HI3620_PWMCLK0,      "pwmclk0",      "pwm0_mux",     CLK_SET_RATE_PARENT, 0x40, 7, 0, },
1718c2ecf20Sopenharmony_ci	{ HI3620_PWMCLK1,      "pwmclk1",      "pwm1_mux",     CLK_SET_RATE_PARENT, 0x40, 8, 0, },
1728c2ecf20Sopenharmony_ci	{ HI3620_UARTCLK0,     "uartclk0",     "uart0_mux",    CLK_SET_RATE_PARENT, 0x40, 16, 0, },
1738c2ecf20Sopenharmony_ci	{ HI3620_UARTCLK1,     "uartclk1",     "uart1_mux",    CLK_SET_RATE_PARENT, 0x40, 17, 0, },
1748c2ecf20Sopenharmony_ci	{ HI3620_UARTCLK2,     "uartclk2",     "uart2_mux",    CLK_SET_RATE_PARENT, 0x40, 18, 0, },
1758c2ecf20Sopenharmony_ci	{ HI3620_UARTCLK3,     "uartclk3",     "uart3_mux",    CLK_SET_RATE_PARENT, 0x40, 19, 0, },
1768c2ecf20Sopenharmony_ci	{ HI3620_UARTCLK4,     "uartclk4",     "uart4_mux",    CLK_SET_RATE_PARENT, 0x40, 20, 0, },
1778c2ecf20Sopenharmony_ci	{ HI3620_SPICLK0,      "spiclk0",      "spi0_mux",     CLK_SET_RATE_PARENT, 0x40, 21, 0, },
1788c2ecf20Sopenharmony_ci	{ HI3620_SPICLK1,      "spiclk1",      "spi1_mux",     CLK_SET_RATE_PARENT, 0x40, 22, 0, },
1798c2ecf20Sopenharmony_ci	{ HI3620_SPICLK2,      "spiclk2",      "spi2_mux",     CLK_SET_RATE_PARENT, 0x40, 23, 0, },
1808c2ecf20Sopenharmony_ci	{ HI3620_I2CCLK0,      "i2cclk0",      "pclk",         CLK_SET_RATE_PARENT, 0x40, 24, 0, },
1818c2ecf20Sopenharmony_ci	{ HI3620_I2CCLK1,      "i2cclk1",      "pclk",         CLK_SET_RATE_PARENT, 0x40, 25, 0, },
1828c2ecf20Sopenharmony_ci	{ HI3620_SCI_CLK,      "sci_clk",      "osc26m",       CLK_SET_RATE_PARENT, 0x40, 26, 0, },
1838c2ecf20Sopenharmony_ci	{ HI3620_I2CCLK2,      "i2cclk2",      "pclk",         CLK_SET_RATE_PARENT, 0x40, 28, 0, },
1848c2ecf20Sopenharmony_ci	{ HI3620_I2CCLK3,      "i2cclk3",      "pclk",         CLK_SET_RATE_PARENT, 0x40, 29, 0, },
1858c2ecf20Sopenharmony_ci	{ HI3620_DDRC_PER_CLK, "ddrc_per_clk", "rclk_cfgaxi",  CLK_SET_RATE_PARENT, 0x50, 9, 0, },
1868c2ecf20Sopenharmony_ci	{ HI3620_DMAC_CLK,     "dmac_clk",     "rclk_cfgaxi",  CLK_SET_RATE_PARENT, 0x50, 10, 0, },
1878c2ecf20Sopenharmony_ci	{ HI3620_USB2DVC_CLK,  "usb2dvc_clk",  "rclk_cfgaxi",  CLK_SET_RATE_PARENT, 0x50, 17, 0, },
1888c2ecf20Sopenharmony_ci	{ HI3620_SD_CLK,       "sd_clk",       "sd_div",       CLK_SET_RATE_PARENT, 0x50, 20, 0, },
1898c2ecf20Sopenharmony_ci	{ HI3620_MMC_CLK1,     "mmc_clk1",     "mmc1_mux2",    CLK_SET_RATE_PARENT, 0x50, 21, 0, },
1908c2ecf20Sopenharmony_ci	{ HI3620_MMC_CLK2,     "mmc_clk2",     "mmc2_div",     CLK_SET_RATE_PARENT, 0x50, 22, 0, },
1918c2ecf20Sopenharmony_ci	{ HI3620_MMC_CLK3,     "mmc_clk3",     "mmc3_div",     CLK_SET_RATE_PARENT, 0x50, 23, 0, },
1928c2ecf20Sopenharmony_ci	{ HI3620_MCU_CLK,      "mcu_clk",      "acp_clk",      CLK_SET_RATE_PARENT, 0x50, 24, 0, },
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistatic void __init hi3620_clk_init(struct device_node *np)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	clk_data = hisi_clk_init(np, HI3620_NR_CLKS);
2008c2ecf20Sopenharmony_ci	if (!clk_data)
2018c2ecf20Sopenharmony_ci		return;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	hisi_clk_register_fixed_rate(hi3620_fixed_rate_clks,
2048c2ecf20Sopenharmony_ci				     ARRAY_SIZE(hi3620_fixed_rate_clks),
2058c2ecf20Sopenharmony_ci				     clk_data);
2068c2ecf20Sopenharmony_ci	hisi_clk_register_fixed_factor(hi3620_fixed_factor_clks,
2078c2ecf20Sopenharmony_ci				       ARRAY_SIZE(hi3620_fixed_factor_clks),
2088c2ecf20Sopenharmony_ci				       clk_data);
2098c2ecf20Sopenharmony_ci	hisi_clk_register_mux(hi3620_mux_clks, ARRAY_SIZE(hi3620_mux_clks),
2108c2ecf20Sopenharmony_ci			      clk_data);
2118c2ecf20Sopenharmony_ci	hisi_clk_register_divider(hi3620_div_clks, ARRAY_SIZE(hi3620_div_clks),
2128c2ecf20Sopenharmony_ci				  clk_data);
2138c2ecf20Sopenharmony_ci	hisi_clk_register_gate_sep(hi3620_separated_gate_clks,
2148c2ecf20Sopenharmony_ci				   ARRAY_SIZE(hi3620_separated_gate_clks),
2158c2ecf20Sopenharmony_ci				   clk_data);
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ciCLK_OF_DECLARE(hi3620_clk, "hisilicon,hi3620-clock", hi3620_clk_init);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistruct hisi_mmc_clock {
2208c2ecf20Sopenharmony_ci	unsigned int		id;
2218c2ecf20Sopenharmony_ci	const char		*name;
2228c2ecf20Sopenharmony_ci	const char		*parent_name;
2238c2ecf20Sopenharmony_ci	unsigned long		flags;
2248c2ecf20Sopenharmony_ci	u32			clken_reg;
2258c2ecf20Sopenharmony_ci	u32			clken_bit;
2268c2ecf20Sopenharmony_ci	u32			div_reg;
2278c2ecf20Sopenharmony_ci	u32			div_off;
2288c2ecf20Sopenharmony_ci	u32			div_bits;
2298c2ecf20Sopenharmony_ci	u32			drv_reg;
2308c2ecf20Sopenharmony_ci	u32			drv_off;
2318c2ecf20Sopenharmony_ci	u32			drv_bits;
2328c2ecf20Sopenharmony_ci	u32			sam_reg;
2338c2ecf20Sopenharmony_ci	u32			sam_off;
2348c2ecf20Sopenharmony_ci	u32			sam_bits;
2358c2ecf20Sopenharmony_ci};
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistruct clk_mmc {
2388c2ecf20Sopenharmony_ci	struct clk_hw	hw;
2398c2ecf20Sopenharmony_ci	u32		id;
2408c2ecf20Sopenharmony_ci	void __iomem	*clken_reg;
2418c2ecf20Sopenharmony_ci	u32		clken_bit;
2428c2ecf20Sopenharmony_ci	void __iomem	*div_reg;
2438c2ecf20Sopenharmony_ci	u32		div_off;
2448c2ecf20Sopenharmony_ci	u32		div_bits;
2458c2ecf20Sopenharmony_ci	void __iomem	*drv_reg;
2468c2ecf20Sopenharmony_ci	u32		drv_off;
2478c2ecf20Sopenharmony_ci	u32		drv_bits;
2488c2ecf20Sopenharmony_ci	void __iomem	*sam_reg;
2498c2ecf20Sopenharmony_ci	u32		sam_off;
2508c2ecf20Sopenharmony_ci	u32		sam_bits;
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci#define to_mmc(_hw) container_of(_hw, struct clk_mmc, hw)
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic struct hisi_mmc_clock hi3620_mmc_clks[] __initdata = {
2568c2ecf20Sopenharmony_ci	{ HI3620_SD_CIUCLK,	"sd_bclk1", "sd_clk", CLK_SET_RATE_PARENT, 0x1f8, 0, 0x1f8, 1, 3, 0x1f8, 4, 4, 0x1f8, 8, 4},
2578c2ecf20Sopenharmony_ci	{ HI3620_MMC_CIUCLK1,   "mmc_bclk1", "mmc_clk1", CLK_SET_RATE_PARENT, 0x1f8, 12, 0x1f8, 13, 3, 0x1f8, 16, 4, 0x1f8, 20, 4},
2588c2ecf20Sopenharmony_ci	{ HI3620_MMC_CIUCLK2,   "mmc_bclk2", "mmc_clk2", CLK_SET_RATE_PARENT, 0x1f8, 24, 0x1f8, 25, 3, 0x1f8, 28, 4, 0x1fc, 0, 4},
2598c2ecf20Sopenharmony_ci	{ HI3620_MMC_CIUCLK3,   "mmc_bclk3", "mmc_clk3", CLK_SET_RATE_PARENT, 0x1fc, 4, 0x1fc, 5, 3, 0x1fc, 8, 4, 0x1fc, 12, 4},
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic unsigned long mmc_clk_recalc_rate(struct clk_hw *hw,
2638c2ecf20Sopenharmony_ci		       unsigned long parent_rate)
2648c2ecf20Sopenharmony_ci{
2658c2ecf20Sopenharmony_ci	switch (parent_rate) {
2668c2ecf20Sopenharmony_ci	case 26000000:
2678c2ecf20Sopenharmony_ci		return 13000000;
2688c2ecf20Sopenharmony_ci	case 180000000:
2698c2ecf20Sopenharmony_ci		return 25000000;
2708c2ecf20Sopenharmony_ci	case 360000000:
2718c2ecf20Sopenharmony_ci		return 50000000;
2728c2ecf20Sopenharmony_ci	case 720000000:
2738c2ecf20Sopenharmony_ci		return 100000000;
2748c2ecf20Sopenharmony_ci	case 1440000000:
2758c2ecf20Sopenharmony_ci		return 180000000;
2768c2ecf20Sopenharmony_ci	default:
2778c2ecf20Sopenharmony_ci		return parent_rate;
2788c2ecf20Sopenharmony_ci	}
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic int mmc_clk_determine_rate(struct clk_hw *hw,
2828c2ecf20Sopenharmony_ci				  struct clk_rate_request *req)
2838c2ecf20Sopenharmony_ci{
2848c2ecf20Sopenharmony_ci	struct clk_mmc *mclk = to_mmc(hw);
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	if ((req->rate <= 13000000) && (mclk->id == HI3620_MMC_CIUCLK1)) {
2878c2ecf20Sopenharmony_ci		req->rate = 13000000;
2888c2ecf20Sopenharmony_ci		req->best_parent_rate = 26000000;
2898c2ecf20Sopenharmony_ci	} else if (req->rate <= 26000000) {
2908c2ecf20Sopenharmony_ci		req->rate = 25000000;
2918c2ecf20Sopenharmony_ci		req->best_parent_rate = 180000000;
2928c2ecf20Sopenharmony_ci	} else if (req->rate <= 52000000) {
2938c2ecf20Sopenharmony_ci		req->rate = 50000000;
2948c2ecf20Sopenharmony_ci		req->best_parent_rate = 360000000;
2958c2ecf20Sopenharmony_ci	} else if (req->rate <= 100000000) {
2968c2ecf20Sopenharmony_ci		req->rate = 100000000;
2978c2ecf20Sopenharmony_ci		req->best_parent_rate = 720000000;
2988c2ecf20Sopenharmony_ci	} else {
2998c2ecf20Sopenharmony_ci		/* max is 180M */
3008c2ecf20Sopenharmony_ci		req->rate = 180000000;
3018c2ecf20Sopenharmony_ci		req->best_parent_rate = 1440000000;
3028c2ecf20Sopenharmony_ci	}
3038c2ecf20Sopenharmony_ci	return -EINVAL;
3048c2ecf20Sopenharmony_ci}
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cistatic u32 mmc_clk_delay(u32 val, u32 para, u32 off, u32 len)
3078c2ecf20Sopenharmony_ci{
3088c2ecf20Sopenharmony_ci	u32 i;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	for (i = 0; i < len; i++) {
3118c2ecf20Sopenharmony_ci		if (para % 2)
3128c2ecf20Sopenharmony_ci			val |= 1 << (off + i);
3138c2ecf20Sopenharmony_ci		else
3148c2ecf20Sopenharmony_ci			val &= ~(1 << (off + i));
3158c2ecf20Sopenharmony_ci		para = para >> 1;
3168c2ecf20Sopenharmony_ci	}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	return val;
3198c2ecf20Sopenharmony_ci}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistatic int mmc_clk_set_timing(struct clk_hw *hw, unsigned long rate)
3228c2ecf20Sopenharmony_ci{
3238c2ecf20Sopenharmony_ci	struct clk_mmc *mclk = to_mmc(hw);
3248c2ecf20Sopenharmony_ci	unsigned long flags;
3258c2ecf20Sopenharmony_ci	u32 sam, drv, div, val;
3268c2ecf20Sopenharmony_ci	static DEFINE_SPINLOCK(mmc_clk_lock);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	switch (rate) {
3298c2ecf20Sopenharmony_ci	case 13000000:
3308c2ecf20Sopenharmony_ci		sam = 3;
3318c2ecf20Sopenharmony_ci		drv = 1;
3328c2ecf20Sopenharmony_ci		div = 1;
3338c2ecf20Sopenharmony_ci		break;
3348c2ecf20Sopenharmony_ci	case 25000000:
3358c2ecf20Sopenharmony_ci		sam = 13;
3368c2ecf20Sopenharmony_ci		drv = 6;
3378c2ecf20Sopenharmony_ci		div = 6;
3388c2ecf20Sopenharmony_ci		break;
3398c2ecf20Sopenharmony_ci	case 50000000:
3408c2ecf20Sopenharmony_ci		sam = 3;
3418c2ecf20Sopenharmony_ci		drv = 6;
3428c2ecf20Sopenharmony_ci		div = 6;
3438c2ecf20Sopenharmony_ci		break;
3448c2ecf20Sopenharmony_ci	case 100000000:
3458c2ecf20Sopenharmony_ci		sam = 6;
3468c2ecf20Sopenharmony_ci		drv = 4;
3478c2ecf20Sopenharmony_ci		div = 6;
3488c2ecf20Sopenharmony_ci		break;
3498c2ecf20Sopenharmony_ci	case 180000000:
3508c2ecf20Sopenharmony_ci		sam = 6;
3518c2ecf20Sopenharmony_ci		drv = 4;
3528c2ecf20Sopenharmony_ci		div = 7;
3538c2ecf20Sopenharmony_ci		break;
3548c2ecf20Sopenharmony_ci	default:
3558c2ecf20Sopenharmony_ci		return -EINVAL;
3568c2ecf20Sopenharmony_ci	}
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	spin_lock_irqsave(&mmc_clk_lock, flags);
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	val = readl_relaxed(mclk->clken_reg);
3618c2ecf20Sopenharmony_ci	val &= ~(1 << mclk->clken_bit);
3628c2ecf20Sopenharmony_ci	writel_relaxed(val, mclk->clken_reg);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci	val = readl_relaxed(mclk->sam_reg);
3658c2ecf20Sopenharmony_ci	val = mmc_clk_delay(val, sam, mclk->sam_off, mclk->sam_bits);
3668c2ecf20Sopenharmony_ci	writel_relaxed(val, mclk->sam_reg);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	val = readl_relaxed(mclk->drv_reg);
3698c2ecf20Sopenharmony_ci	val = mmc_clk_delay(val, drv, mclk->drv_off, mclk->drv_bits);
3708c2ecf20Sopenharmony_ci	writel_relaxed(val, mclk->drv_reg);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	val = readl_relaxed(mclk->div_reg);
3738c2ecf20Sopenharmony_ci	val = mmc_clk_delay(val, div, mclk->div_off, mclk->div_bits);
3748c2ecf20Sopenharmony_ci	writel_relaxed(val, mclk->div_reg);
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	val = readl_relaxed(mclk->clken_reg);
3778c2ecf20Sopenharmony_ci	val |= 1 << mclk->clken_bit;
3788c2ecf20Sopenharmony_ci	writel_relaxed(val, mclk->clken_reg);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&mmc_clk_lock, flags);
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	return 0;
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic int mmc_clk_prepare(struct clk_hw *hw)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	struct clk_mmc *mclk = to_mmc(hw);
3888c2ecf20Sopenharmony_ci	unsigned long rate;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	if (mclk->id == HI3620_MMC_CIUCLK1)
3918c2ecf20Sopenharmony_ci		rate = 13000000;
3928c2ecf20Sopenharmony_ci	else
3938c2ecf20Sopenharmony_ci		rate = 25000000;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	return mmc_clk_set_timing(hw, rate);
3968c2ecf20Sopenharmony_ci}
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistatic int mmc_clk_set_rate(struct clk_hw *hw, unsigned long rate,
3998c2ecf20Sopenharmony_ci			     unsigned long parent_rate)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	return mmc_clk_set_timing(hw, rate);
4028c2ecf20Sopenharmony_ci}
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_cistatic const struct clk_ops clk_mmc_ops = {
4058c2ecf20Sopenharmony_ci	.prepare = mmc_clk_prepare,
4068c2ecf20Sopenharmony_ci	.determine_rate = mmc_clk_determine_rate,
4078c2ecf20Sopenharmony_ci	.set_rate = mmc_clk_set_rate,
4088c2ecf20Sopenharmony_ci	.recalc_rate = mmc_clk_recalc_rate,
4098c2ecf20Sopenharmony_ci};
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_cistatic struct clk *hisi_register_clk_mmc(struct hisi_mmc_clock *mmc_clk,
4128c2ecf20Sopenharmony_ci			void __iomem *base, struct device_node *np)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	struct clk_mmc *mclk;
4158c2ecf20Sopenharmony_ci	struct clk *clk;
4168c2ecf20Sopenharmony_ci	struct clk_init_data init;
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	mclk = kzalloc(sizeof(*mclk), GFP_KERNEL);
4198c2ecf20Sopenharmony_ci	if (!mclk)
4208c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOMEM);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	init.name = mmc_clk->name;
4238c2ecf20Sopenharmony_ci	init.ops = &clk_mmc_ops;
4248c2ecf20Sopenharmony_ci	init.flags = mmc_clk->flags;
4258c2ecf20Sopenharmony_ci	init.parent_names = (mmc_clk->parent_name ? &mmc_clk->parent_name : NULL);
4268c2ecf20Sopenharmony_ci	init.num_parents = (mmc_clk->parent_name ? 1 : 0);
4278c2ecf20Sopenharmony_ci	mclk->hw.init = &init;
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	mclk->id = mmc_clk->id;
4308c2ecf20Sopenharmony_ci	mclk->clken_reg = base + mmc_clk->clken_reg;
4318c2ecf20Sopenharmony_ci	mclk->clken_bit = mmc_clk->clken_bit;
4328c2ecf20Sopenharmony_ci	mclk->div_reg = base + mmc_clk->div_reg;
4338c2ecf20Sopenharmony_ci	mclk->div_off = mmc_clk->div_off;
4348c2ecf20Sopenharmony_ci	mclk->div_bits = mmc_clk->div_bits;
4358c2ecf20Sopenharmony_ci	mclk->drv_reg = base + mmc_clk->drv_reg;
4368c2ecf20Sopenharmony_ci	mclk->drv_off = mmc_clk->drv_off;
4378c2ecf20Sopenharmony_ci	mclk->drv_bits = mmc_clk->drv_bits;
4388c2ecf20Sopenharmony_ci	mclk->sam_reg = base + mmc_clk->sam_reg;
4398c2ecf20Sopenharmony_ci	mclk->sam_off = mmc_clk->sam_off;
4408c2ecf20Sopenharmony_ci	mclk->sam_bits = mmc_clk->sam_bits;
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	clk = clk_register(NULL, &mclk->hw);
4438c2ecf20Sopenharmony_ci	if (WARN_ON(IS_ERR(clk)))
4448c2ecf20Sopenharmony_ci		kfree(mclk);
4458c2ecf20Sopenharmony_ci	return clk;
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cistatic void __init hi3620_mmc_clk_init(struct device_node *node)
4498c2ecf20Sopenharmony_ci{
4508c2ecf20Sopenharmony_ci	void __iomem *base;
4518c2ecf20Sopenharmony_ci	int i, num = ARRAY_SIZE(hi3620_mmc_clks);
4528c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	if (!node) {
4558c2ecf20Sopenharmony_ci		pr_err("failed to find pctrl node in DTS\n");
4568c2ecf20Sopenharmony_ci		return;
4578c2ecf20Sopenharmony_ci	}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	base = of_iomap(node, 0);
4608c2ecf20Sopenharmony_ci	if (!base) {
4618c2ecf20Sopenharmony_ci		pr_err("failed to map pctrl\n");
4628c2ecf20Sopenharmony_ci		return;
4638c2ecf20Sopenharmony_ci	}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
4668c2ecf20Sopenharmony_ci	if (WARN_ON(!clk_data))
4678c2ecf20Sopenharmony_ci		return;
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL);
4708c2ecf20Sopenharmony_ci	if (!clk_data->clks) {
4718c2ecf20Sopenharmony_ci		kfree(clk_data);
4728c2ecf20Sopenharmony_ci		return;
4738c2ecf20Sopenharmony_ci	}
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	for (i = 0; i < num; i++) {
4768c2ecf20Sopenharmony_ci		struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i];
4778c2ecf20Sopenharmony_ci		clk_data->clks[mmc_clk->id] =
4788c2ecf20Sopenharmony_ci			hisi_register_clk_mmc(mmc_clk, base, node);
4798c2ecf20Sopenharmony_ci	}
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci	clk_data->clk_num = num;
4828c2ecf20Sopenharmony_ci	of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
4838c2ecf20Sopenharmony_ci}
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ciCLK_OF_DECLARE(hi3620_mmc_clk, "hisilicon,hi3620-mmc-clock", hi3620_mmc_clk_init);
486