19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2763c5bd0SIcenowy Zheng /* 3763c5bd0SIcenowy Zheng * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.io> 4763c5bd0SIcenowy Zheng */ 5763c5bd0SIcenowy Zheng 6763c5bd0SIcenowy Zheng #include <linux/clk.h> 7763c5bd0SIcenowy Zheng #include <linux/clk-provider.h> 8763c5bd0SIcenowy Zheng #include <linux/of_address.h> 9763c5bd0SIcenowy Zheng #include <linux/of_platform.h> 10763c5bd0SIcenowy Zheng #include <linux/platform_device.h> 11763c5bd0SIcenowy Zheng #include <linux/reset.h> 12763c5bd0SIcenowy Zheng 13763c5bd0SIcenowy Zheng #include "ccu_common.h" 14763c5bd0SIcenowy Zheng #include "ccu_div.h" 15763c5bd0SIcenowy Zheng #include "ccu_gate.h" 16763c5bd0SIcenowy Zheng #include "ccu_reset.h" 17763c5bd0SIcenowy Zheng 18763c5bd0SIcenowy Zheng #include "ccu-sun8i-de2.h" 19763c5bd0SIcenowy Zheng 20763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(bus_mixer0_clk, "bus-mixer0", "bus-de", 21763c5bd0SIcenowy Zheng 0x04, BIT(0), 0); 22763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(bus_mixer1_clk, "bus-mixer1", "bus-de", 23763c5bd0SIcenowy Zheng 0x04, BIT(1), 0); 24763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(bus_wb_clk, "bus-wb", "bus-de", 25763c5bd0SIcenowy Zheng 0x04, BIT(2), 0); 2656808da9SJernej Skrabec static SUNXI_CCU_GATE(bus_rot_clk, "bus-rot", "bus-de", 2756808da9SJernej Skrabec 0x04, BIT(3), 0); 28763c5bd0SIcenowy Zheng 29763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(mixer0_clk, "mixer0", "mixer0-div", 30763c5bd0SIcenowy Zheng 0x00, BIT(0), CLK_SET_RATE_PARENT); 31763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(mixer1_clk, "mixer1", "mixer1-div", 32763c5bd0SIcenowy Zheng 0x00, BIT(1), CLK_SET_RATE_PARENT); 33763c5bd0SIcenowy Zheng static SUNXI_CCU_GATE(wb_clk, "wb", "wb-div", 34763c5bd0SIcenowy Zheng 0x00, BIT(2), CLK_SET_RATE_PARENT); 3556808da9SJernej Skrabec static SUNXI_CCU_GATE(rot_clk, "rot", "rot-div", 3656808da9SJernej Skrabec 0x00, BIT(3), CLK_SET_RATE_PARENT); 37763c5bd0SIcenowy Zheng 38763c5bd0SIcenowy Zheng static SUNXI_CCU_M(mixer0_div_clk, "mixer0-div", "de", 0x0c, 0, 4, 39763c5bd0SIcenowy Zheng CLK_SET_RATE_PARENT); 4019368d99SIcenowy Zheng static SUNXI_CCU_M(mixer1_div_clk, "mixer1-div", "de", 0x0c, 4, 4, 4119368d99SIcenowy Zheng CLK_SET_RATE_PARENT); 42763c5bd0SIcenowy Zheng static SUNXI_CCU_M(wb_div_clk, "wb-div", "de", 0x0c, 8, 4, 43763c5bd0SIcenowy Zheng CLK_SET_RATE_PARENT); 4456808da9SJernej Skrabec static SUNXI_CCU_M(rot_div_clk, "rot-div", "de", 0x0c, 0x0c, 4, 4556808da9SJernej Skrabec CLK_SET_RATE_PARENT); 46763c5bd0SIcenowy Zheng 47553c7d5bSMaxime Ripard static SUNXI_CCU_M(mixer0_div_a83_clk, "mixer0-div", "pll-de", 0x0c, 0, 4, 48553c7d5bSMaxime Ripard CLK_SET_RATE_PARENT); 49553c7d5bSMaxime Ripard static SUNXI_CCU_M(mixer1_div_a83_clk, "mixer1-div", "pll-de", 0x0c, 4, 4, 50553c7d5bSMaxime Ripard CLK_SET_RATE_PARENT); 51553c7d5bSMaxime Ripard static SUNXI_CCU_M(wb_div_a83_clk, "wb-div", "pll-de", 0x0c, 8, 4, 52553c7d5bSMaxime Ripard CLK_SET_RATE_PARENT); 53553c7d5bSMaxime Ripard 5456808da9SJernej Skrabec static struct ccu_common *sun50i_h6_de3_clks[] = { 5556808da9SJernej Skrabec &mixer0_clk.common, 5656808da9SJernej Skrabec &mixer1_clk.common, 5756808da9SJernej Skrabec &wb_clk.common, 5856808da9SJernej Skrabec 5956808da9SJernej Skrabec &bus_mixer0_clk.common, 6056808da9SJernej Skrabec &bus_mixer1_clk.common, 6156808da9SJernej Skrabec &bus_wb_clk.common, 6256808da9SJernej Skrabec 6356808da9SJernej Skrabec &mixer0_div_clk.common, 6456808da9SJernej Skrabec &mixer1_div_clk.common, 6556808da9SJernej Skrabec &wb_div_clk.common, 6656808da9SJernej Skrabec 6756808da9SJernej Skrabec &bus_rot_clk.common, 6856808da9SJernej Skrabec &rot_clk.common, 6956808da9SJernej Skrabec &rot_div_clk.common, 7056808da9SJernej Skrabec }; 7156808da9SJernej Skrabec 72763c5bd0SIcenowy Zheng static struct ccu_common *sun8i_a83t_de2_clks[] = { 73763c5bd0SIcenowy Zheng &mixer0_clk.common, 74763c5bd0SIcenowy Zheng &mixer1_clk.common, 75763c5bd0SIcenowy Zheng &wb_clk.common, 76763c5bd0SIcenowy Zheng 77763c5bd0SIcenowy Zheng &bus_mixer0_clk.common, 78763c5bd0SIcenowy Zheng &bus_mixer1_clk.common, 79763c5bd0SIcenowy Zheng &bus_wb_clk.common, 80763c5bd0SIcenowy Zheng 81553c7d5bSMaxime Ripard &mixer0_div_a83_clk.common, 82553c7d5bSMaxime Ripard &mixer1_div_a83_clk.common, 83553c7d5bSMaxime Ripard &wb_div_a83_clk.common, 84763c5bd0SIcenowy Zheng }; 85763c5bd0SIcenowy Zheng 8619368d99SIcenowy Zheng static struct ccu_common *sun8i_h3_de2_clks[] = { 8719368d99SIcenowy Zheng &mixer0_clk.common, 8819368d99SIcenowy Zheng &mixer1_clk.common, 8919368d99SIcenowy Zheng &wb_clk.common, 9019368d99SIcenowy Zheng 9119368d99SIcenowy Zheng &bus_mixer0_clk.common, 9219368d99SIcenowy Zheng &bus_mixer1_clk.common, 9319368d99SIcenowy Zheng &bus_wb_clk.common, 9419368d99SIcenowy Zheng 9519368d99SIcenowy Zheng &mixer0_div_clk.common, 9619368d99SIcenowy Zheng &mixer1_div_clk.common, 9719368d99SIcenowy Zheng &wb_div_clk.common, 9819368d99SIcenowy Zheng }; 9919368d99SIcenowy Zheng 100763c5bd0SIcenowy Zheng static struct ccu_common *sun8i_v3s_de2_clks[] = { 101763c5bd0SIcenowy Zheng &mixer0_clk.common, 102763c5bd0SIcenowy Zheng &wb_clk.common, 103763c5bd0SIcenowy Zheng 104763c5bd0SIcenowy Zheng &bus_mixer0_clk.common, 105763c5bd0SIcenowy Zheng &bus_wb_clk.common, 106763c5bd0SIcenowy Zheng 107763c5bd0SIcenowy Zheng &mixer0_div_clk.common, 108763c5bd0SIcenowy Zheng &wb_div_clk.common, 109763c5bd0SIcenowy Zheng }; 110763c5bd0SIcenowy Zheng 111763c5bd0SIcenowy Zheng static struct clk_hw_onecell_data sun8i_a83t_de2_hw_clks = { 112763c5bd0SIcenowy Zheng .hws = { 113763c5bd0SIcenowy Zheng [CLK_MIXER0] = &mixer0_clk.common.hw, 114763c5bd0SIcenowy Zheng [CLK_MIXER1] = &mixer1_clk.common.hw, 115763c5bd0SIcenowy Zheng [CLK_WB] = &wb_clk.common.hw, 116763c5bd0SIcenowy Zheng 117763c5bd0SIcenowy Zheng [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw, 118763c5bd0SIcenowy Zheng [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw, 119763c5bd0SIcenowy Zheng [CLK_BUS_WB] = &bus_wb_clk.common.hw, 120763c5bd0SIcenowy Zheng 121553c7d5bSMaxime Ripard [CLK_MIXER0_DIV] = &mixer0_div_a83_clk.common.hw, 122553c7d5bSMaxime Ripard [CLK_MIXER1_DIV] = &mixer1_div_a83_clk.common.hw, 123553c7d5bSMaxime Ripard [CLK_WB_DIV] = &wb_div_a83_clk.common.hw, 124763c5bd0SIcenowy Zheng }, 12556808da9SJernej Skrabec .num = CLK_NUMBER_WITHOUT_ROT, 126763c5bd0SIcenowy Zheng }; 127763c5bd0SIcenowy Zheng 12819368d99SIcenowy Zheng static struct clk_hw_onecell_data sun8i_h3_de2_hw_clks = { 12919368d99SIcenowy Zheng .hws = { 13019368d99SIcenowy Zheng [CLK_MIXER0] = &mixer0_clk.common.hw, 13119368d99SIcenowy Zheng [CLK_MIXER1] = &mixer1_clk.common.hw, 13219368d99SIcenowy Zheng [CLK_WB] = &wb_clk.common.hw, 13319368d99SIcenowy Zheng 13419368d99SIcenowy Zheng [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw, 13519368d99SIcenowy Zheng [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw, 13619368d99SIcenowy Zheng [CLK_BUS_WB] = &bus_wb_clk.common.hw, 13719368d99SIcenowy Zheng 13819368d99SIcenowy Zheng [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw, 13919368d99SIcenowy Zheng [CLK_MIXER1_DIV] = &mixer1_div_clk.common.hw, 14019368d99SIcenowy Zheng [CLK_WB_DIV] = &wb_div_clk.common.hw, 14119368d99SIcenowy Zheng }, 14256808da9SJernej Skrabec .num = CLK_NUMBER_WITHOUT_ROT, 14319368d99SIcenowy Zheng }; 14419368d99SIcenowy Zheng 145763c5bd0SIcenowy Zheng static struct clk_hw_onecell_data sun8i_v3s_de2_hw_clks = { 146763c5bd0SIcenowy Zheng .hws = { 147763c5bd0SIcenowy Zheng [CLK_MIXER0] = &mixer0_clk.common.hw, 148763c5bd0SIcenowy Zheng [CLK_WB] = &wb_clk.common.hw, 149763c5bd0SIcenowy Zheng 150763c5bd0SIcenowy Zheng [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw, 151763c5bd0SIcenowy Zheng [CLK_BUS_WB] = &bus_wb_clk.common.hw, 152763c5bd0SIcenowy Zheng 153763c5bd0SIcenowy Zheng [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw, 154763c5bd0SIcenowy Zheng [CLK_WB_DIV] = &wb_div_clk.common.hw, 155763c5bd0SIcenowy Zheng }, 15656808da9SJernej Skrabec .num = CLK_NUMBER_WITHOUT_ROT, 15756808da9SJernej Skrabec }; 15856808da9SJernej Skrabec 15956808da9SJernej Skrabec static struct clk_hw_onecell_data sun50i_h6_de3_hw_clks = { 16056808da9SJernej Skrabec .hws = { 16156808da9SJernej Skrabec [CLK_MIXER0] = &mixer0_clk.common.hw, 16256808da9SJernej Skrabec [CLK_MIXER1] = &mixer1_clk.common.hw, 16356808da9SJernej Skrabec [CLK_WB] = &wb_clk.common.hw, 16456808da9SJernej Skrabec [CLK_ROT] = &rot_clk.common.hw, 16556808da9SJernej Skrabec 16656808da9SJernej Skrabec [CLK_BUS_MIXER0] = &bus_mixer0_clk.common.hw, 16756808da9SJernej Skrabec [CLK_BUS_MIXER1] = &bus_mixer1_clk.common.hw, 16856808da9SJernej Skrabec [CLK_BUS_WB] = &bus_wb_clk.common.hw, 16956808da9SJernej Skrabec [CLK_BUS_ROT] = &bus_rot_clk.common.hw, 17056808da9SJernej Skrabec 17156808da9SJernej Skrabec [CLK_MIXER0_DIV] = &mixer0_div_clk.common.hw, 17256808da9SJernej Skrabec [CLK_MIXER1_DIV] = &mixer1_div_clk.common.hw, 17356808da9SJernej Skrabec [CLK_WB_DIV] = &wb_div_clk.common.hw, 17456808da9SJernej Skrabec [CLK_ROT_DIV] = &rot_div_clk.common.hw, 17556808da9SJernej Skrabec }, 17656808da9SJernej Skrabec .num = CLK_NUMBER_WITH_ROT, 177763c5bd0SIcenowy Zheng }; 178763c5bd0SIcenowy Zheng 179763c5bd0SIcenowy Zheng static struct ccu_reset_map sun8i_a83t_de2_resets[] = { 180763c5bd0SIcenowy Zheng [RST_MIXER0] = { 0x08, BIT(0) }, 181763c5bd0SIcenowy Zheng /* 182763c5bd0SIcenowy Zheng * For A83T, H3 and R40, mixer1 reset line is shared with wb, so 183763c5bd0SIcenowy Zheng * only RST_WB is exported here. 184763c5bd0SIcenowy Zheng * For V3s there's just no mixer1, so it also shares this struct. 185763c5bd0SIcenowy Zheng */ 186763c5bd0SIcenowy Zheng [RST_WB] = { 0x08, BIT(2) }, 187763c5bd0SIcenowy Zheng }; 188763c5bd0SIcenowy Zheng 189763c5bd0SIcenowy Zheng static struct ccu_reset_map sun50i_a64_de2_resets[] = { 190763c5bd0SIcenowy Zheng [RST_MIXER0] = { 0x08, BIT(0) }, 191763c5bd0SIcenowy Zheng [RST_MIXER1] = { 0x08, BIT(1) }, 192763c5bd0SIcenowy Zheng [RST_WB] = { 0x08, BIT(2) }, 193763c5bd0SIcenowy Zheng }; 194763c5bd0SIcenowy Zheng 195*2b48dcb7SJernej Skrabec static struct ccu_reset_map sun50i_h5_de2_resets[] = { 196*2b48dcb7SJernej Skrabec [RST_MIXER0] = { 0x08, BIT(0) }, 197*2b48dcb7SJernej Skrabec [RST_MIXER1] = { 0x08, BIT(1) }, 198*2b48dcb7SJernej Skrabec [RST_WB] = { 0x08, BIT(2) }, 199*2b48dcb7SJernej Skrabec }; 200*2b48dcb7SJernej Skrabec 20156808da9SJernej Skrabec static struct ccu_reset_map sun50i_h6_de3_resets[] = { 20256808da9SJernej Skrabec [RST_MIXER0] = { 0x08, BIT(0) }, 20356808da9SJernej Skrabec [RST_MIXER1] = { 0x08, BIT(1) }, 20456808da9SJernej Skrabec [RST_WB] = { 0x08, BIT(2) }, 20556808da9SJernej Skrabec [RST_ROT] = { 0x08, BIT(3) }, 20656808da9SJernej Skrabec }; 20756808da9SJernej Skrabec 208763c5bd0SIcenowy Zheng static const struct sunxi_ccu_desc sun8i_a83t_de2_clk_desc = { 209763c5bd0SIcenowy Zheng .ccu_clks = sun8i_a83t_de2_clks, 210763c5bd0SIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun8i_a83t_de2_clks), 211763c5bd0SIcenowy Zheng 212763c5bd0SIcenowy Zheng .hw_clks = &sun8i_a83t_de2_hw_clks, 213763c5bd0SIcenowy Zheng 214763c5bd0SIcenowy Zheng .resets = sun8i_a83t_de2_resets, 215763c5bd0SIcenowy Zheng .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets), 216763c5bd0SIcenowy Zheng }; 217763c5bd0SIcenowy Zheng 21819368d99SIcenowy Zheng static const struct sunxi_ccu_desc sun8i_h3_de2_clk_desc = { 21919368d99SIcenowy Zheng .ccu_clks = sun8i_h3_de2_clks, 22019368d99SIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun8i_h3_de2_clks), 22119368d99SIcenowy Zheng 22219368d99SIcenowy Zheng .hw_clks = &sun8i_h3_de2_hw_clks, 22319368d99SIcenowy Zheng 22419368d99SIcenowy Zheng .resets = sun8i_a83t_de2_resets, 22519368d99SIcenowy Zheng .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets), 22619368d99SIcenowy Zheng }; 22719368d99SIcenowy Zheng 228763c5bd0SIcenowy Zheng static const struct sunxi_ccu_desc sun50i_a64_de2_clk_desc = { 229cf4881c1SIcenowy Zheng .ccu_clks = sun8i_h3_de2_clks, 230cf4881c1SIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun8i_h3_de2_clks), 231763c5bd0SIcenowy Zheng 232cf4881c1SIcenowy Zheng .hw_clks = &sun8i_h3_de2_hw_clks, 233763c5bd0SIcenowy Zheng 234763c5bd0SIcenowy Zheng .resets = sun50i_a64_de2_resets, 235763c5bd0SIcenowy Zheng .num_resets = ARRAY_SIZE(sun50i_a64_de2_resets), 236763c5bd0SIcenowy Zheng }; 237763c5bd0SIcenowy Zheng 238*2b48dcb7SJernej Skrabec static const struct sunxi_ccu_desc sun50i_h5_de2_clk_desc = { 239*2b48dcb7SJernej Skrabec .ccu_clks = sun8i_h3_de2_clks, 240*2b48dcb7SJernej Skrabec .num_ccu_clks = ARRAY_SIZE(sun8i_h3_de2_clks), 241*2b48dcb7SJernej Skrabec 242*2b48dcb7SJernej Skrabec .hw_clks = &sun8i_h3_de2_hw_clks, 243*2b48dcb7SJernej Skrabec 244*2b48dcb7SJernej Skrabec .resets = sun50i_h5_de2_resets, 245*2b48dcb7SJernej Skrabec .num_resets = ARRAY_SIZE(sun50i_h5_de2_resets), 246*2b48dcb7SJernej Skrabec }; 247*2b48dcb7SJernej Skrabec 24856808da9SJernej Skrabec static const struct sunxi_ccu_desc sun50i_h6_de3_clk_desc = { 24956808da9SJernej Skrabec .ccu_clks = sun50i_h6_de3_clks, 25056808da9SJernej Skrabec .num_ccu_clks = ARRAY_SIZE(sun50i_h6_de3_clks), 25156808da9SJernej Skrabec 25256808da9SJernej Skrabec .hw_clks = &sun50i_h6_de3_hw_clks, 25356808da9SJernej Skrabec 25456808da9SJernej Skrabec .resets = sun50i_h6_de3_resets, 25556808da9SJernej Skrabec .num_resets = ARRAY_SIZE(sun50i_h6_de3_resets), 25656808da9SJernej Skrabec }; 25756808da9SJernej Skrabec 258763c5bd0SIcenowy Zheng static const struct sunxi_ccu_desc sun8i_v3s_de2_clk_desc = { 259763c5bd0SIcenowy Zheng .ccu_clks = sun8i_v3s_de2_clks, 260763c5bd0SIcenowy Zheng .num_ccu_clks = ARRAY_SIZE(sun8i_v3s_de2_clks), 261763c5bd0SIcenowy Zheng 262763c5bd0SIcenowy Zheng .hw_clks = &sun8i_v3s_de2_hw_clks, 263763c5bd0SIcenowy Zheng 264763c5bd0SIcenowy Zheng .resets = sun8i_a83t_de2_resets, 265763c5bd0SIcenowy Zheng .num_resets = ARRAY_SIZE(sun8i_a83t_de2_resets), 266763c5bd0SIcenowy Zheng }; 267763c5bd0SIcenowy Zheng 268763c5bd0SIcenowy Zheng static int sunxi_de2_clk_probe(struct platform_device *pdev) 269763c5bd0SIcenowy Zheng { 270763c5bd0SIcenowy Zheng struct resource *res; 271763c5bd0SIcenowy Zheng struct clk *bus_clk, *mod_clk; 272763c5bd0SIcenowy Zheng struct reset_control *rstc; 273763c5bd0SIcenowy Zheng void __iomem *reg; 274763c5bd0SIcenowy Zheng const struct sunxi_ccu_desc *ccu_desc; 275763c5bd0SIcenowy Zheng int ret; 276763c5bd0SIcenowy Zheng 277763c5bd0SIcenowy Zheng ccu_desc = of_device_get_match_data(&pdev->dev); 278763c5bd0SIcenowy Zheng if (!ccu_desc) 279763c5bd0SIcenowy Zheng return -EINVAL; 280763c5bd0SIcenowy Zheng 281763c5bd0SIcenowy Zheng res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 282763c5bd0SIcenowy Zheng reg = devm_ioremap_resource(&pdev->dev, res); 283763c5bd0SIcenowy Zheng if (IS_ERR(reg)) 284763c5bd0SIcenowy Zheng return PTR_ERR(reg); 285763c5bd0SIcenowy Zheng 286763c5bd0SIcenowy Zheng bus_clk = devm_clk_get(&pdev->dev, "bus"); 287763c5bd0SIcenowy Zheng if (IS_ERR(bus_clk)) { 288763c5bd0SIcenowy Zheng ret = PTR_ERR(bus_clk); 289763c5bd0SIcenowy Zheng if (ret != -EPROBE_DEFER) 290763c5bd0SIcenowy Zheng dev_err(&pdev->dev, "Couldn't get bus clk: %d\n", ret); 291763c5bd0SIcenowy Zheng return ret; 292763c5bd0SIcenowy Zheng } 293763c5bd0SIcenowy Zheng 294763c5bd0SIcenowy Zheng mod_clk = devm_clk_get(&pdev->dev, "mod"); 295763c5bd0SIcenowy Zheng if (IS_ERR(mod_clk)) { 296763c5bd0SIcenowy Zheng ret = PTR_ERR(mod_clk); 297763c5bd0SIcenowy Zheng if (ret != -EPROBE_DEFER) 298763c5bd0SIcenowy Zheng dev_err(&pdev->dev, "Couldn't get mod clk: %d\n", ret); 299763c5bd0SIcenowy Zheng return ret; 300763c5bd0SIcenowy Zheng } 301763c5bd0SIcenowy Zheng 302763c5bd0SIcenowy Zheng rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); 303763c5bd0SIcenowy Zheng if (IS_ERR(rstc)) { 3041f6d640cSWei Yongjun ret = PTR_ERR(rstc); 305763c5bd0SIcenowy Zheng if (ret != -EPROBE_DEFER) 306763c5bd0SIcenowy Zheng dev_err(&pdev->dev, 307763c5bd0SIcenowy Zheng "Couldn't get reset control: %d\n", ret); 308763c5bd0SIcenowy Zheng return ret; 309763c5bd0SIcenowy Zheng } 310763c5bd0SIcenowy Zheng 311763c5bd0SIcenowy Zheng /* The clocks need to be enabled for us to access the registers */ 312763c5bd0SIcenowy Zheng ret = clk_prepare_enable(bus_clk); 313763c5bd0SIcenowy Zheng if (ret) { 314763c5bd0SIcenowy Zheng dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret); 315763c5bd0SIcenowy Zheng return ret; 316763c5bd0SIcenowy Zheng } 317763c5bd0SIcenowy Zheng 318763c5bd0SIcenowy Zheng ret = clk_prepare_enable(mod_clk); 319763c5bd0SIcenowy Zheng if (ret) { 320763c5bd0SIcenowy Zheng dev_err(&pdev->dev, "Couldn't enable mod clk: %d\n", ret); 321763c5bd0SIcenowy Zheng goto err_disable_bus_clk; 322763c5bd0SIcenowy Zheng } 323763c5bd0SIcenowy Zheng 324763c5bd0SIcenowy Zheng /* The reset control needs to be asserted for the controls to work */ 325763c5bd0SIcenowy Zheng ret = reset_control_deassert(rstc); 326763c5bd0SIcenowy Zheng if (ret) { 327763c5bd0SIcenowy Zheng dev_err(&pdev->dev, 328763c5bd0SIcenowy Zheng "Couldn't deassert reset control: %d\n", ret); 329763c5bd0SIcenowy Zheng goto err_disable_mod_clk; 330763c5bd0SIcenowy Zheng } 331763c5bd0SIcenowy Zheng 332763c5bd0SIcenowy Zheng ret = sunxi_ccu_probe(pdev->dev.of_node, reg, ccu_desc); 333763c5bd0SIcenowy Zheng if (ret) 334763c5bd0SIcenowy Zheng goto err_assert_reset; 335763c5bd0SIcenowy Zheng 336763c5bd0SIcenowy Zheng return 0; 337763c5bd0SIcenowy Zheng 338763c5bd0SIcenowy Zheng err_assert_reset: 339763c5bd0SIcenowy Zheng reset_control_assert(rstc); 340763c5bd0SIcenowy Zheng err_disable_mod_clk: 341763c5bd0SIcenowy Zheng clk_disable_unprepare(mod_clk); 342763c5bd0SIcenowy Zheng err_disable_bus_clk: 343763c5bd0SIcenowy Zheng clk_disable_unprepare(bus_clk); 344763c5bd0SIcenowy Zheng return ret; 345763c5bd0SIcenowy Zheng } 346763c5bd0SIcenowy Zheng 347763c5bd0SIcenowy Zheng static const struct of_device_id sunxi_de2_clk_ids[] = { 348763c5bd0SIcenowy Zheng { 349763c5bd0SIcenowy Zheng .compatible = "allwinner,sun8i-a83t-de2-clk", 350763c5bd0SIcenowy Zheng .data = &sun8i_a83t_de2_clk_desc, 351763c5bd0SIcenowy Zheng }, 352763c5bd0SIcenowy Zheng { 35319368d99SIcenowy Zheng .compatible = "allwinner,sun8i-h3-de2-clk", 35419368d99SIcenowy Zheng .data = &sun8i_h3_de2_clk_desc, 35519368d99SIcenowy Zheng }, 35619368d99SIcenowy Zheng { 357763c5bd0SIcenowy Zheng .compatible = "allwinner,sun8i-v3s-de2-clk", 358763c5bd0SIcenowy Zheng .data = &sun8i_v3s_de2_clk_desc, 359763c5bd0SIcenowy Zheng }, 360763c5bd0SIcenowy Zheng { 36101951563SIcenowy Zheng .compatible = "allwinner,sun50i-a64-de2-clk", 36201951563SIcenowy Zheng .data = &sun50i_a64_de2_clk_desc, 36301951563SIcenowy Zheng }, 36401951563SIcenowy Zheng { 365763c5bd0SIcenowy Zheng .compatible = "allwinner,sun50i-h5-de2-clk", 366*2b48dcb7SJernej Skrabec .data = &sun50i_h5_de2_clk_desc, 367763c5bd0SIcenowy Zheng }, 36856808da9SJernej Skrabec { 36956808da9SJernej Skrabec .compatible = "allwinner,sun50i-h6-de3-clk", 37056808da9SJernej Skrabec .data = &sun50i_h6_de3_clk_desc, 37156808da9SJernej Skrabec }, 372763c5bd0SIcenowy Zheng { } 373763c5bd0SIcenowy Zheng }; 374763c5bd0SIcenowy Zheng 375763c5bd0SIcenowy Zheng static struct platform_driver sunxi_de2_clk_driver = { 376763c5bd0SIcenowy Zheng .probe = sunxi_de2_clk_probe, 377763c5bd0SIcenowy Zheng .driver = { 378763c5bd0SIcenowy Zheng .name = "sunxi-de2-clks", 379763c5bd0SIcenowy Zheng .of_match_table = sunxi_de2_clk_ids, 380763c5bd0SIcenowy Zheng }, 381763c5bd0SIcenowy Zheng }; 382763c5bd0SIcenowy Zheng builtin_platform_driver(sunxi_de2_clk_driver); 383