162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2014 Linaro Ltd.
462306a36Sopenharmony_ci * Copyright (c) 2014 Hisilicon Limited.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/of_address.h>
862306a36Sopenharmony_ci#include <dt-bindings/clock/hix5hd2-clock.h>
962306a36Sopenharmony_ci#include <linux/slab.h>
1062306a36Sopenharmony_ci#include <linux/delay.h>
1162306a36Sopenharmony_ci#include "clk.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistatic struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] __initdata = {
1462306a36Sopenharmony_ci	{ HIX5HD2_FIXED_1200M, "1200m", NULL, 0, 1200000000, },
1562306a36Sopenharmony_ci	{ HIX5HD2_FIXED_400M, "400m", NULL, 0, 400000000, },
1662306a36Sopenharmony_ci	{ HIX5HD2_FIXED_48M, "48m", NULL, 0, 48000000, },
1762306a36Sopenharmony_ci	{ HIX5HD2_FIXED_24M, "24m", NULL, 0, 24000000, },
1862306a36Sopenharmony_ci	{ HIX5HD2_FIXED_600M, "600m", NULL, 0, 600000000, },
1962306a36Sopenharmony_ci	{ HIX5HD2_FIXED_300M, "300m", NULL, 0, 300000000, },
2062306a36Sopenharmony_ci	{ HIX5HD2_FIXED_75M, "75m", NULL, 0, 75000000, },
2162306a36Sopenharmony_ci	{ HIX5HD2_FIXED_200M, "200m", NULL, 0, 200000000, },
2262306a36Sopenharmony_ci	{ HIX5HD2_FIXED_100M, "100m", NULL, 0, 100000000, },
2362306a36Sopenharmony_ci	{ HIX5HD2_FIXED_40M, "40m", NULL, 0, 40000000, },
2462306a36Sopenharmony_ci	{ HIX5HD2_FIXED_150M, "150m", NULL, 0, 150000000, },
2562306a36Sopenharmony_ci	{ HIX5HD2_FIXED_1728M, "1728m", NULL, 0, 1728000000, },
2662306a36Sopenharmony_ci	{ HIX5HD2_FIXED_28P8M, "28p8m", NULL, 0, 28000000, },
2762306a36Sopenharmony_ci	{ HIX5HD2_FIXED_432M, "432m", NULL, 0, 432000000, },
2862306a36Sopenharmony_ci	{ HIX5HD2_FIXED_345P6M, "345p6m", NULL, 0, 345000000, },
2962306a36Sopenharmony_ci	{ HIX5HD2_FIXED_288M, "288m", NULL, 0, 288000000, },
3062306a36Sopenharmony_ci	{ HIX5HD2_FIXED_60M,	"60m", NULL, 0, 60000000, },
3162306a36Sopenharmony_ci	{ HIX5HD2_FIXED_750M, "750m", NULL, 0, 750000000, },
3262306a36Sopenharmony_ci	{ HIX5HD2_FIXED_500M, "500m", NULL, 0, 500000000, },
3362306a36Sopenharmony_ci	{ HIX5HD2_FIXED_54M,	"54m", NULL, 0, 54000000, },
3462306a36Sopenharmony_ci	{ HIX5HD2_FIXED_27M, "27m", NULL, 0, 27000000, },
3562306a36Sopenharmony_ci	{ HIX5HD2_FIXED_1500M, "1500m", NULL, 0, 1500000000, },
3662306a36Sopenharmony_ci	{ HIX5HD2_FIXED_375M, "375m", NULL, 0, 375000000, },
3762306a36Sopenharmony_ci	{ HIX5HD2_FIXED_187M, "187m", NULL, 0, 187000000, },
3862306a36Sopenharmony_ci	{ HIX5HD2_FIXED_250M, "250m", NULL, 0, 250000000, },
3962306a36Sopenharmony_ci	{ HIX5HD2_FIXED_125M, "125m", NULL, 0, 125000000, },
4062306a36Sopenharmony_ci	{ HIX5HD2_FIXED_2P02M, "2m", NULL, 0, 2000000, },
4162306a36Sopenharmony_ci	{ HIX5HD2_FIXED_50M, "50m", NULL, 0, 50000000, },
4262306a36Sopenharmony_ci	{ HIX5HD2_FIXED_25M, "25m", NULL, 0, 25000000, },
4362306a36Sopenharmony_ci	{ HIX5HD2_FIXED_83M, "83m", NULL, 0, 83333333, },
4462306a36Sopenharmony_ci};
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistatic const char *const sfc_mux_p[] __initconst = {
4762306a36Sopenharmony_ci		"24m", "150m", "200m", "100m", "75m", };
4862306a36Sopenharmony_cistatic u32 sfc_mux_table[] = {0, 4, 5, 6, 7};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistatic const char *const sdio_mux_p[] __initconst = {
5162306a36Sopenharmony_ci		"75m", "100m", "50m", "15m", };
5262306a36Sopenharmony_cistatic u32 sdio_mux_table[] = {0, 1, 2, 3};
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic const char *const fephy_mux_p[] __initconst = { "25m", "125m"};
5562306a36Sopenharmony_cistatic u32 fephy_mux_table[] = {0, 1};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistatic struct hisi_mux_clock hix5hd2_mux_clks[] __initdata = {
5962306a36Sopenharmony_ci	{ HIX5HD2_SFC_MUX, "sfc_mux", sfc_mux_p, ARRAY_SIZE(sfc_mux_p),
6062306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x5c, 8, 3, 0, sfc_mux_table, },
6162306a36Sopenharmony_ci	{ HIX5HD2_MMC_MUX, "mmc_mux", sdio_mux_p, ARRAY_SIZE(sdio_mux_p),
6262306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0xa0, 8, 2, 0, sdio_mux_table, },
6362306a36Sopenharmony_ci	{ HIX5HD2_SD_MUX, "sd_mux", sdio_mux_p, ARRAY_SIZE(sdio_mux_p),
6462306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x9c, 8, 2, 0, sdio_mux_table, },
6562306a36Sopenharmony_ci	{ HIX5HD2_FEPHY_MUX, "fephy_mux",
6662306a36Sopenharmony_ci		fephy_mux_p, ARRAY_SIZE(fephy_mux_p),
6762306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x120, 8, 2, 0, fephy_mux_table, },
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic struct hisi_gate_clock hix5hd2_gate_clks[] __initdata = {
7162306a36Sopenharmony_ci	/* sfc */
7262306a36Sopenharmony_ci	{ HIX5HD2_SFC_CLK, "clk_sfc", "sfc_mux",
7362306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x5c, 0, 0, },
7462306a36Sopenharmony_ci	{ HIX5HD2_SFC_RST, "rst_sfc", "clk_sfc",
7562306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x5c, 4, CLK_GATE_SET_TO_DISABLE, },
7662306a36Sopenharmony_ci	/* sdio0 */
7762306a36Sopenharmony_ci	{ HIX5HD2_SD_BIU_CLK, "clk_sd_biu", "200m",
7862306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x9c, 0, 0, },
7962306a36Sopenharmony_ci	{ HIX5HD2_SD_CIU_CLK, "clk_sd_ciu", "sd_mux",
8062306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x9c, 1, 0, },
8162306a36Sopenharmony_ci	{ HIX5HD2_SD_CIU_RST, "rst_sd_ciu", "clk_sd_ciu",
8262306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x9c, 4, CLK_GATE_SET_TO_DISABLE, },
8362306a36Sopenharmony_ci	/* sdio1 */
8462306a36Sopenharmony_ci	{ HIX5HD2_MMC_BIU_CLK, "clk_mmc_biu", "200m",
8562306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0xa0, 0, 0, },
8662306a36Sopenharmony_ci	{ HIX5HD2_MMC_CIU_CLK, "clk_mmc_ciu", "mmc_mux",
8762306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0xa0, 1, 0, },
8862306a36Sopenharmony_ci	{ HIX5HD2_MMC_CIU_RST, "rst_mmc_ciu", "clk_mmc_ciu",
8962306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0xa0, 4, CLK_GATE_SET_TO_DISABLE, },
9062306a36Sopenharmony_ci	/* gsf */
9162306a36Sopenharmony_ci	{ HIX5HD2_FWD_BUS_CLK, "clk_fwd_bus", NULL, 0, 0xcc, 0, 0, },
9262306a36Sopenharmony_ci	{ HIX5HD2_FWD_SYS_CLK, "clk_fwd_sys", "clk_fwd_bus", 0, 0xcc, 5, 0, },
9362306a36Sopenharmony_ci	{ HIX5HD2_MAC0_PHY_CLK, "clk_fephy", "clk_fwd_sys",
9462306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x120, 0, 0, },
9562306a36Sopenharmony_ci	/* wdg0 */
9662306a36Sopenharmony_ci	{ HIX5HD2_WDG0_CLK, "clk_wdg0", "24m",
9762306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x178, 0, 0, },
9862306a36Sopenharmony_ci	{ HIX5HD2_WDG0_RST, "rst_wdg0", "clk_wdg0",
9962306a36Sopenharmony_ci		CLK_SET_RATE_PARENT, 0x178, 4, CLK_GATE_SET_TO_DISABLE, },
10062306a36Sopenharmony_ci	/* I2C */
10162306a36Sopenharmony_ci	{HIX5HD2_I2C0_CLK, "clk_i2c0", "100m",
10262306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 4, 0, },
10362306a36Sopenharmony_ci	{HIX5HD2_I2C0_RST, "rst_i2c0", "clk_i2c0",
10462306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 5, CLK_GATE_SET_TO_DISABLE, },
10562306a36Sopenharmony_ci	{HIX5HD2_I2C1_CLK, "clk_i2c1", "100m",
10662306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 8, 0, },
10762306a36Sopenharmony_ci	{HIX5HD2_I2C1_RST, "rst_i2c1", "clk_i2c1",
10862306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 9, CLK_GATE_SET_TO_DISABLE, },
10962306a36Sopenharmony_ci	{HIX5HD2_I2C2_CLK, "clk_i2c2", "100m",
11062306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 12, 0, },
11162306a36Sopenharmony_ci	{HIX5HD2_I2C2_RST, "rst_i2c2", "clk_i2c2",
11262306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 13, CLK_GATE_SET_TO_DISABLE, },
11362306a36Sopenharmony_ci	{HIX5HD2_I2C3_CLK, "clk_i2c3", "100m",
11462306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 16, 0, },
11562306a36Sopenharmony_ci	{HIX5HD2_I2C3_RST, "rst_i2c3", "clk_i2c3",
11662306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 17, CLK_GATE_SET_TO_DISABLE, },
11762306a36Sopenharmony_ci	{HIX5HD2_I2C4_CLK, "clk_i2c4", "100m",
11862306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 20, 0, },
11962306a36Sopenharmony_ci	{HIX5HD2_I2C4_RST, "rst_i2c4", "clk_i2c4",
12062306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 21, CLK_GATE_SET_TO_DISABLE, },
12162306a36Sopenharmony_ci	{HIX5HD2_I2C5_CLK, "clk_i2c5", "100m",
12262306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 0, 0, },
12362306a36Sopenharmony_ci	{HIX5HD2_I2C5_RST, "rst_i2c5", "clk_i2c5",
12462306a36Sopenharmony_ci		 CLK_SET_RATE_PARENT, 0x06c, 1, CLK_GATE_SET_TO_DISABLE, },
12562306a36Sopenharmony_ci};
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_cienum hix5hd2_clk_type {
12862306a36Sopenharmony_ci	TYPE_COMPLEX,
12962306a36Sopenharmony_ci	TYPE_ETHER,
13062306a36Sopenharmony_ci};
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_cistruct hix5hd2_complex_clock {
13362306a36Sopenharmony_ci	const char	*name;
13462306a36Sopenharmony_ci	const char	*parent_name;
13562306a36Sopenharmony_ci	u32		id;
13662306a36Sopenharmony_ci	u32		ctrl_reg;
13762306a36Sopenharmony_ci	u32		ctrl_clk_mask;
13862306a36Sopenharmony_ci	u32		ctrl_rst_mask;
13962306a36Sopenharmony_ci	u32		phy_reg;
14062306a36Sopenharmony_ci	u32		phy_clk_mask;
14162306a36Sopenharmony_ci	u32		phy_rst_mask;
14262306a36Sopenharmony_ci	enum hix5hd2_clk_type type;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct hix5hd2_clk_complex {
14662306a36Sopenharmony_ci	struct clk_hw	hw;
14762306a36Sopenharmony_ci	u32		id;
14862306a36Sopenharmony_ci	void __iomem	*ctrl_reg;
14962306a36Sopenharmony_ci	u32		ctrl_clk_mask;
15062306a36Sopenharmony_ci	u32		ctrl_rst_mask;
15162306a36Sopenharmony_ci	void __iomem	*phy_reg;
15262306a36Sopenharmony_ci	u32		phy_clk_mask;
15362306a36Sopenharmony_ci	u32		phy_rst_mask;
15462306a36Sopenharmony_ci};
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cistatic struct hix5hd2_complex_clock hix5hd2_complex_clks[] __initdata = {
15762306a36Sopenharmony_ci	{"clk_mac0", "clk_fephy", HIX5HD2_MAC0_CLK,
15862306a36Sopenharmony_ci		0xcc, 0xa, 0x500, 0x120, 0, 0x10, TYPE_ETHER},
15962306a36Sopenharmony_ci	{"clk_mac1", "clk_fwd_sys", HIX5HD2_MAC1_CLK,
16062306a36Sopenharmony_ci		0xcc, 0x14, 0xa00, 0x168, 0x2, 0, TYPE_ETHER},
16162306a36Sopenharmony_ci	{"clk_sata", NULL, HIX5HD2_SATA_CLK,
16262306a36Sopenharmony_ci		0xa8, 0x1f, 0x300, 0xac, 0x1, 0x0, TYPE_COMPLEX},
16362306a36Sopenharmony_ci	{"clk_usb", NULL, HIX5HD2_USB_CLK,
16462306a36Sopenharmony_ci		0xb8, 0xff, 0x3f000, 0xbc, 0x7, 0x3f00, TYPE_COMPLEX},
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define to_complex_clk(_hw) container_of(_hw, struct hix5hd2_clk_complex, hw)
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_cistatic int clk_ether_prepare(struct clk_hw *hw)
17062306a36Sopenharmony_ci{
17162306a36Sopenharmony_ci	struct hix5hd2_clk_complex *clk = to_complex_clk(hw);
17262306a36Sopenharmony_ci	u32 val;
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci	val = readl_relaxed(clk->ctrl_reg);
17562306a36Sopenharmony_ci	val |= clk->ctrl_clk_mask | clk->ctrl_rst_mask;
17662306a36Sopenharmony_ci	writel_relaxed(val, clk->ctrl_reg);
17762306a36Sopenharmony_ci	val &= ~(clk->ctrl_rst_mask);
17862306a36Sopenharmony_ci	writel_relaxed(val, clk->ctrl_reg);
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	val = readl_relaxed(clk->phy_reg);
18162306a36Sopenharmony_ci	val |= clk->phy_clk_mask;
18262306a36Sopenharmony_ci	val &= ~(clk->phy_rst_mask);
18362306a36Sopenharmony_ci	writel_relaxed(val, clk->phy_reg);
18462306a36Sopenharmony_ci	mdelay(10);
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci	val &= ~(clk->phy_clk_mask);
18762306a36Sopenharmony_ci	val |= clk->phy_rst_mask;
18862306a36Sopenharmony_ci	writel_relaxed(val, clk->phy_reg);
18962306a36Sopenharmony_ci	mdelay(10);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci	val |= clk->phy_clk_mask;
19262306a36Sopenharmony_ci	val &= ~(clk->phy_rst_mask);
19362306a36Sopenharmony_ci	writel_relaxed(val, clk->phy_reg);
19462306a36Sopenharmony_ci	mdelay(30);
19562306a36Sopenharmony_ci	return 0;
19662306a36Sopenharmony_ci}
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_cistatic void clk_ether_unprepare(struct clk_hw *hw)
19962306a36Sopenharmony_ci{
20062306a36Sopenharmony_ci	struct hix5hd2_clk_complex *clk = to_complex_clk(hw);
20162306a36Sopenharmony_ci	u32 val;
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci	val = readl_relaxed(clk->ctrl_reg);
20462306a36Sopenharmony_ci	val &= ~(clk->ctrl_clk_mask);
20562306a36Sopenharmony_ci	writel_relaxed(val, clk->ctrl_reg);
20662306a36Sopenharmony_ci}
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cistatic const struct clk_ops clk_ether_ops = {
20962306a36Sopenharmony_ci	.prepare = clk_ether_prepare,
21062306a36Sopenharmony_ci	.unprepare = clk_ether_unprepare,
21162306a36Sopenharmony_ci};
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_cistatic int clk_complex_enable(struct clk_hw *hw)
21462306a36Sopenharmony_ci{
21562306a36Sopenharmony_ci	struct hix5hd2_clk_complex *clk = to_complex_clk(hw);
21662306a36Sopenharmony_ci	u32 val;
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci	val = readl_relaxed(clk->ctrl_reg);
21962306a36Sopenharmony_ci	val |= clk->ctrl_clk_mask;
22062306a36Sopenharmony_ci	val &= ~(clk->ctrl_rst_mask);
22162306a36Sopenharmony_ci	writel_relaxed(val, clk->ctrl_reg);
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	val = readl_relaxed(clk->phy_reg);
22462306a36Sopenharmony_ci	val |= clk->phy_clk_mask;
22562306a36Sopenharmony_ci	val &= ~(clk->phy_rst_mask);
22662306a36Sopenharmony_ci	writel_relaxed(val, clk->phy_reg);
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci	return 0;
22962306a36Sopenharmony_ci}
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_cistatic void clk_complex_disable(struct clk_hw *hw)
23262306a36Sopenharmony_ci{
23362306a36Sopenharmony_ci	struct hix5hd2_clk_complex *clk = to_complex_clk(hw);
23462306a36Sopenharmony_ci	u32 val;
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci	val = readl_relaxed(clk->ctrl_reg);
23762306a36Sopenharmony_ci	val |= clk->ctrl_rst_mask;
23862306a36Sopenharmony_ci	val &= ~(clk->ctrl_clk_mask);
23962306a36Sopenharmony_ci	writel_relaxed(val, clk->ctrl_reg);
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	val = readl_relaxed(clk->phy_reg);
24262306a36Sopenharmony_ci	val |= clk->phy_rst_mask;
24362306a36Sopenharmony_ci	val &= ~(clk->phy_clk_mask);
24462306a36Sopenharmony_ci	writel_relaxed(val, clk->phy_reg);
24562306a36Sopenharmony_ci}
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_cistatic const struct clk_ops clk_complex_ops = {
24862306a36Sopenharmony_ci	.enable = clk_complex_enable,
24962306a36Sopenharmony_ci	.disable = clk_complex_disable,
25062306a36Sopenharmony_ci};
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_cistatic void __init
25362306a36Sopenharmony_cihix5hd2_clk_register_complex(struct hix5hd2_complex_clock *clks, int nums,
25462306a36Sopenharmony_ci			     struct hisi_clock_data *data)
25562306a36Sopenharmony_ci{
25662306a36Sopenharmony_ci	void __iomem *base = data->base;
25762306a36Sopenharmony_ci	int i;
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	for (i = 0; i < nums; i++) {
26062306a36Sopenharmony_ci		struct hix5hd2_clk_complex *p_clk;
26162306a36Sopenharmony_ci		struct clk *clk;
26262306a36Sopenharmony_ci		struct clk_init_data init;
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci		p_clk = kzalloc(sizeof(*p_clk), GFP_KERNEL);
26562306a36Sopenharmony_ci		if (!p_clk)
26662306a36Sopenharmony_ci			return;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci		init.name = clks[i].name;
26962306a36Sopenharmony_ci		if (clks[i].type == TYPE_ETHER)
27062306a36Sopenharmony_ci			init.ops = &clk_ether_ops;
27162306a36Sopenharmony_ci		else
27262306a36Sopenharmony_ci			init.ops = &clk_complex_ops;
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci		init.flags = 0;
27562306a36Sopenharmony_ci		init.parent_names =
27662306a36Sopenharmony_ci			(clks[i].parent_name ? &clks[i].parent_name : NULL);
27762306a36Sopenharmony_ci		init.num_parents = (clks[i].parent_name ? 1 : 0);
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci		p_clk->ctrl_reg = base + clks[i].ctrl_reg;
28062306a36Sopenharmony_ci		p_clk->ctrl_clk_mask = clks[i].ctrl_clk_mask;
28162306a36Sopenharmony_ci		p_clk->ctrl_rst_mask = clks[i].ctrl_rst_mask;
28262306a36Sopenharmony_ci		p_clk->phy_reg = base + clks[i].phy_reg;
28362306a36Sopenharmony_ci		p_clk->phy_clk_mask = clks[i].phy_clk_mask;
28462306a36Sopenharmony_ci		p_clk->phy_rst_mask = clks[i].phy_rst_mask;
28562306a36Sopenharmony_ci		p_clk->hw.init = &init;
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci		clk = clk_register(NULL, &p_clk->hw);
28862306a36Sopenharmony_ci		if (IS_ERR(clk)) {
28962306a36Sopenharmony_ci			kfree(p_clk);
29062306a36Sopenharmony_ci			pr_err("%s: failed to register clock %s\n",
29162306a36Sopenharmony_ci			       __func__, clks[i].name);
29262306a36Sopenharmony_ci			continue;
29362306a36Sopenharmony_ci		}
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci		data->clk_data.clks[clks[i].id] = clk;
29662306a36Sopenharmony_ci	}
29762306a36Sopenharmony_ci}
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_cistatic void __init hix5hd2_clk_init(struct device_node *np)
30062306a36Sopenharmony_ci{
30162306a36Sopenharmony_ci	struct hisi_clock_data *clk_data;
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci	clk_data = hisi_clk_init(np, HIX5HD2_NR_CLKS);
30462306a36Sopenharmony_ci	if (!clk_data)
30562306a36Sopenharmony_ci		return;
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci	hisi_clk_register_fixed_rate(hix5hd2_fixed_rate_clks,
30862306a36Sopenharmony_ci				     ARRAY_SIZE(hix5hd2_fixed_rate_clks),
30962306a36Sopenharmony_ci				     clk_data);
31062306a36Sopenharmony_ci	hisi_clk_register_mux(hix5hd2_mux_clks, ARRAY_SIZE(hix5hd2_mux_clks),
31162306a36Sopenharmony_ci					clk_data);
31262306a36Sopenharmony_ci	hisi_clk_register_gate(hix5hd2_gate_clks,
31362306a36Sopenharmony_ci			ARRAY_SIZE(hix5hd2_gate_clks), clk_data);
31462306a36Sopenharmony_ci	hix5hd2_clk_register_complex(hix5hd2_complex_clks,
31562306a36Sopenharmony_ci				     ARRAY_SIZE(hix5hd2_complex_clks),
31662306a36Sopenharmony_ci				     clk_data);
31762306a36Sopenharmony_ci}
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ciCLK_OF_DECLARE(hix5hd2_clk, "hisilicon,hix5hd2-clock", hix5hd2_clk_init);
320