18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2016 Chen-Yu Tsai. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/clk.h> 78c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 88c2ecf20Sopenharmony_ci#include <linux/of_address.h> 98c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 108c2ecf20Sopenharmony_ci#include <linux/reset.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "ccu_common.h" 138c2ecf20Sopenharmony_ci#include "ccu_div.h" 148c2ecf20Sopenharmony_ci#include "ccu_gate.h" 158c2ecf20Sopenharmony_ci#include "ccu_reset.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "ccu-sun9i-a80-de.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(fe0_clk, "fe0", "fe0-div", 208c2ecf20Sopenharmony_ci 0x00, BIT(0), 0); 218c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(fe1_clk, "fe1", "fe1-div", 228c2ecf20Sopenharmony_ci 0x00, BIT(1), 0); 238c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(fe2_clk, "fe2", "fe2-div", 248c2ecf20Sopenharmony_ci 0x00, BIT(2), 0); 258c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(iep_deu0_clk, "iep-deu0", "de", 268c2ecf20Sopenharmony_ci 0x00, BIT(4), 0); 278c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(iep_deu1_clk, "iep-deu1", "de", 288c2ecf20Sopenharmony_ci 0x00, BIT(5), 0); 298c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(be0_clk, "be0", "be0-div", 308c2ecf20Sopenharmony_ci 0x00, BIT(8), 0); 318c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(be1_clk, "be1", "be1-div", 328c2ecf20Sopenharmony_ci 0x00, BIT(9), 0); 338c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(be2_clk, "be2", "be2-div", 348c2ecf20Sopenharmony_ci 0x00, BIT(10), 0); 358c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(iep_drc0_clk, "iep-drc0", "de", 368c2ecf20Sopenharmony_ci 0x00, BIT(12), 0); 378c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(iep_drc1_clk, "iep-drc1", "de", 388c2ecf20Sopenharmony_ci 0x00, BIT(13), 0); 398c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(merge_clk, "merge", "de", 408c2ecf20Sopenharmony_ci 0x00, BIT(20), 0); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_fe0_clk, "dram-fe0", "sdram", 438c2ecf20Sopenharmony_ci 0x04, BIT(0), 0); 448c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_fe1_clk, "dram-fe1", "sdram", 458c2ecf20Sopenharmony_ci 0x04, BIT(1), 0); 468c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_fe2_clk, "dram-fe2", "sdram", 478c2ecf20Sopenharmony_ci 0x04, BIT(2), 0); 488c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_deu0_clk, "dram-deu0", "sdram", 498c2ecf20Sopenharmony_ci 0x04, BIT(4), 0); 508c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_deu1_clk, "dram-deu1", "sdram", 518c2ecf20Sopenharmony_ci 0x04, BIT(5), 0); 528c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_be0_clk, "dram-be0", "sdram", 538c2ecf20Sopenharmony_ci 0x04, BIT(8), 0); 548c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_be1_clk, "dram-be1", "sdram", 558c2ecf20Sopenharmony_ci 0x04, BIT(9), 0); 568c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_be2_clk, "dram-be2", "sdram", 578c2ecf20Sopenharmony_ci 0x04, BIT(10), 0); 588c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_drc0_clk, "dram-drc0", "sdram", 598c2ecf20Sopenharmony_ci 0x04, BIT(12), 0); 608c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_drc1_clk, "dram-drc1", "sdram", 618c2ecf20Sopenharmony_ci 0x04, BIT(13), 0); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_fe0_clk, "bus-fe0", "bus-de", 648c2ecf20Sopenharmony_ci 0x08, BIT(0), 0); 658c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_fe1_clk, "bus-fe1", "bus-de", 668c2ecf20Sopenharmony_ci 0x08, BIT(1), 0); 678c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_fe2_clk, "bus-fe2", "bus-de", 688c2ecf20Sopenharmony_ci 0x08, BIT(2), 0); 698c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_deu0_clk, "bus-deu0", "bus-de", 708c2ecf20Sopenharmony_ci 0x08, BIT(4), 0); 718c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_deu1_clk, "bus-deu1", "bus-de", 728c2ecf20Sopenharmony_ci 0x08, BIT(5), 0); 738c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_be0_clk, "bus-be0", "bus-de", 748c2ecf20Sopenharmony_ci 0x08, BIT(8), 0); 758c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_be1_clk, "bus-be1", "bus-de", 768c2ecf20Sopenharmony_ci 0x08, BIT(9), 0); 778c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_be2_clk, "bus-be2", "bus-de", 788c2ecf20Sopenharmony_ci 0x08, BIT(10), 0); 798c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_drc0_clk, "bus-drc0", "bus-de", 808c2ecf20Sopenharmony_ci 0x08, BIT(12), 0); 818c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_drc1_clk, "bus-drc1", "bus-de", 828c2ecf20Sopenharmony_ci 0x08, BIT(13), 0); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(fe0_div_clk, "fe0-div", "de", 0x20, 0, 4, 0); 858c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(fe1_div_clk, "fe1-div", "de", 0x20, 4, 4, 0); 868c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(fe2_div_clk, "fe2-div", "de", 0x20, 8, 4, 0); 878c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(be0_div_clk, "be0-div", "de", 0x20, 16, 4, 0); 888c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(be1_div_clk, "be1-div", "de", 0x20, 20, 4, 0); 898c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(be2_div_clk, "be2-div", "de", 0x20, 24, 4, 0); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic struct ccu_common *sun9i_a80_de_clks[] = { 928c2ecf20Sopenharmony_ci &fe0_clk.common, 938c2ecf20Sopenharmony_ci &fe1_clk.common, 948c2ecf20Sopenharmony_ci &fe2_clk.common, 958c2ecf20Sopenharmony_ci &iep_deu0_clk.common, 968c2ecf20Sopenharmony_ci &iep_deu1_clk.common, 978c2ecf20Sopenharmony_ci &be0_clk.common, 988c2ecf20Sopenharmony_ci &be1_clk.common, 998c2ecf20Sopenharmony_ci &be2_clk.common, 1008c2ecf20Sopenharmony_ci &iep_drc0_clk.common, 1018c2ecf20Sopenharmony_ci &iep_drc1_clk.common, 1028c2ecf20Sopenharmony_ci &merge_clk.common, 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci &dram_fe0_clk.common, 1058c2ecf20Sopenharmony_ci &dram_fe1_clk.common, 1068c2ecf20Sopenharmony_ci &dram_fe2_clk.common, 1078c2ecf20Sopenharmony_ci &dram_deu0_clk.common, 1088c2ecf20Sopenharmony_ci &dram_deu1_clk.common, 1098c2ecf20Sopenharmony_ci &dram_be0_clk.common, 1108c2ecf20Sopenharmony_ci &dram_be1_clk.common, 1118c2ecf20Sopenharmony_ci &dram_be2_clk.common, 1128c2ecf20Sopenharmony_ci &dram_drc0_clk.common, 1138c2ecf20Sopenharmony_ci &dram_drc1_clk.common, 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci &bus_fe0_clk.common, 1168c2ecf20Sopenharmony_ci &bus_fe1_clk.common, 1178c2ecf20Sopenharmony_ci &bus_fe2_clk.common, 1188c2ecf20Sopenharmony_ci &bus_deu0_clk.common, 1198c2ecf20Sopenharmony_ci &bus_deu1_clk.common, 1208c2ecf20Sopenharmony_ci &bus_be0_clk.common, 1218c2ecf20Sopenharmony_ci &bus_be1_clk.common, 1228c2ecf20Sopenharmony_ci &bus_be2_clk.common, 1238c2ecf20Sopenharmony_ci &bus_drc0_clk.common, 1248c2ecf20Sopenharmony_ci &bus_drc1_clk.common, 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci &fe0_div_clk.common, 1278c2ecf20Sopenharmony_ci &fe1_div_clk.common, 1288c2ecf20Sopenharmony_ci &fe2_div_clk.common, 1298c2ecf20Sopenharmony_ci &be0_div_clk.common, 1308c2ecf20Sopenharmony_ci &be1_div_clk.common, 1318c2ecf20Sopenharmony_ci &be2_div_clk.common, 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistatic struct clk_hw_onecell_data sun9i_a80_de_hw_clks = { 1358c2ecf20Sopenharmony_ci .hws = { 1368c2ecf20Sopenharmony_ci [CLK_FE0] = &fe0_clk.common.hw, 1378c2ecf20Sopenharmony_ci [CLK_FE1] = &fe1_clk.common.hw, 1388c2ecf20Sopenharmony_ci [CLK_FE2] = &fe2_clk.common.hw, 1398c2ecf20Sopenharmony_ci [CLK_IEP_DEU0] = &iep_deu0_clk.common.hw, 1408c2ecf20Sopenharmony_ci [CLK_IEP_DEU1] = &iep_deu1_clk.common.hw, 1418c2ecf20Sopenharmony_ci [CLK_BE0] = &be0_clk.common.hw, 1428c2ecf20Sopenharmony_ci [CLK_BE1] = &be1_clk.common.hw, 1438c2ecf20Sopenharmony_ci [CLK_BE2] = &be2_clk.common.hw, 1448c2ecf20Sopenharmony_ci [CLK_IEP_DRC0] = &iep_drc0_clk.common.hw, 1458c2ecf20Sopenharmony_ci [CLK_IEP_DRC1] = &iep_drc1_clk.common.hw, 1468c2ecf20Sopenharmony_ci [CLK_MERGE] = &merge_clk.common.hw, 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci [CLK_DRAM_FE0] = &dram_fe0_clk.common.hw, 1498c2ecf20Sopenharmony_ci [CLK_DRAM_FE1] = &dram_fe1_clk.common.hw, 1508c2ecf20Sopenharmony_ci [CLK_DRAM_FE2] = &dram_fe2_clk.common.hw, 1518c2ecf20Sopenharmony_ci [CLK_DRAM_DEU0] = &dram_deu0_clk.common.hw, 1528c2ecf20Sopenharmony_ci [CLK_DRAM_DEU1] = &dram_deu1_clk.common.hw, 1538c2ecf20Sopenharmony_ci [CLK_DRAM_BE0] = &dram_be0_clk.common.hw, 1548c2ecf20Sopenharmony_ci [CLK_DRAM_BE1] = &dram_be1_clk.common.hw, 1558c2ecf20Sopenharmony_ci [CLK_DRAM_BE2] = &dram_be2_clk.common.hw, 1568c2ecf20Sopenharmony_ci [CLK_DRAM_DRC0] = &dram_drc0_clk.common.hw, 1578c2ecf20Sopenharmony_ci [CLK_DRAM_DRC1] = &dram_drc1_clk.common.hw, 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci [CLK_BUS_FE0] = &bus_fe0_clk.common.hw, 1608c2ecf20Sopenharmony_ci [CLK_BUS_FE1] = &bus_fe1_clk.common.hw, 1618c2ecf20Sopenharmony_ci [CLK_BUS_FE2] = &bus_fe2_clk.common.hw, 1628c2ecf20Sopenharmony_ci [CLK_BUS_DEU0] = &bus_deu0_clk.common.hw, 1638c2ecf20Sopenharmony_ci [CLK_BUS_DEU1] = &bus_deu1_clk.common.hw, 1648c2ecf20Sopenharmony_ci [CLK_BUS_BE0] = &bus_be0_clk.common.hw, 1658c2ecf20Sopenharmony_ci [CLK_BUS_BE1] = &bus_be1_clk.common.hw, 1668c2ecf20Sopenharmony_ci [CLK_BUS_BE2] = &bus_be2_clk.common.hw, 1678c2ecf20Sopenharmony_ci [CLK_BUS_DRC0] = &bus_drc0_clk.common.hw, 1688c2ecf20Sopenharmony_ci [CLK_BUS_DRC1] = &bus_drc1_clk.common.hw, 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci [CLK_FE0_DIV] = &fe0_div_clk.common.hw, 1718c2ecf20Sopenharmony_ci [CLK_FE1_DIV] = &fe1_div_clk.common.hw, 1728c2ecf20Sopenharmony_ci [CLK_FE2_DIV] = &fe2_div_clk.common.hw, 1738c2ecf20Sopenharmony_ci [CLK_BE0_DIV] = &be0_div_clk.common.hw, 1748c2ecf20Sopenharmony_ci [CLK_BE1_DIV] = &be1_div_clk.common.hw, 1758c2ecf20Sopenharmony_ci [CLK_BE2_DIV] = &be2_div_clk.common.hw, 1768c2ecf20Sopenharmony_ci }, 1778c2ecf20Sopenharmony_ci .num = CLK_NUMBER, 1788c2ecf20Sopenharmony_ci}; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cistatic struct ccu_reset_map sun9i_a80_de_resets[] = { 1818c2ecf20Sopenharmony_ci [RST_FE0] = { 0x0c, BIT(0) }, 1828c2ecf20Sopenharmony_ci [RST_FE1] = { 0x0c, BIT(1) }, 1838c2ecf20Sopenharmony_ci [RST_FE2] = { 0x0c, BIT(2) }, 1848c2ecf20Sopenharmony_ci [RST_DEU0] = { 0x0c, BIT(4) }, 1858c2ecf20Sopenharmony_ci [RST_DEU1] = { 0x0c, BIT(5) }, 1868c2ecf20Sopenharmony_ci [RST_BE0] = { 0x0c, BIT(8) }, 1878c2ecf20Sopenharmony_ci [RST_BE1] = { 0x0c, BIT(9) }, 1888c2ecf20Sopenharmony_ci [RST_BE2] = { 0x0c, BIT(10) }, 1898c2ecf20Sopenharmony_ci [RST_DRC0] = { 0x0c, BIT(12) }, 1908c2ecf20Sopenharmony_ci [RST_DRC1] = { 0x0c, BIT(13) }, 1918c2ecf20Sopenharmony_ci [RST_MERGE] = { 0x0c, BIT(20) }, 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic const struct sunxi_ccu_desc sun9i_a80_de_clk_desc = { 1958c2ecf20Sopenharmony_ci .ccu_clks = sun9i_a80_de_clks, 1968c2ecf20Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(sun9i_a80_de_clks), 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci .hw_clks = &sun9i_a80_de_hw_clks, 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci .resets = sun9i_a80_de_resets, 2018c2ecf20Sopenharmony_ci .num_resets = ARRAY_SIZE(sun9i_a80_de_resets), 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic int sun9i_a80_de_clk_probe(struct platform_device *pdev) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci struct resource *res; 2078c2ecf20Sopenharmony_ci struct clk *bus_clk; 2088c2ecf20Sopenharmony_ci struct reset_control *rstc; 2098c2ecf20Sopenharmony_ci void __iomem *reg; 2108c2ecf20Sopenharmony_ci int ret; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2138c2ecf20Sopenharmony_ci reg = devm_ioremap_resource(&pdev->dev, res); 2148c2ecf20Sopenharmony_ci if (IS_ERR(reg)) 2158c2ecf20Sopenharmony_ci return PTR_ERR(reg); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci bus_clk = devm_clk_get(&pdev->dev, "bus"); 2188c2ecf20Sopenharmony_ci if (IS_ERR(bus_clk)) { 2198c2ecf20Sopenharmony_ci ret = PTR_ERR(bus_clk); 2208c2ecf20Sopenharmony_ci if (ret != -EPROBE_DEFER) 2218c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Couldn't get bus clk: %d\n", ret); 2228c2ecf20Sopenharmony_ci return ret; 2238c2ecf20Sopenharmony_ci } 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); 2268c2ecf20Sopenharmony_ci if (IS_ERR(rstc)) { 2278c2ecf20Sopenharmony_ci ret = PTR_ERR(rstc); 2288c2ecf20Sopenharmony_ci if (ret != -EPROBE_DEFER) 2298c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 2308c2ecf20Sopenharmony_ci "Couldn't get reset control: %d\n", ret); 2318c2ecf20Sopenharmony_ci return ret; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci /* The bus clock needs to be enabled for us to access the registers */ 2358c2ecf20Sopenharmony_ci ret = clk_prepare_enable(bus_clk); 2368c2ecf20Sopenharmony_ci if (ret) { 2378c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret); 2388c2ecf20Sopenharmony_ci return ret; 2398c2ecf20Sopenharmony_ci } 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci /* The reset control needs to be asserted for the controls to work */ 2428c2ecf20Sopenharmony_ci ret = reset_control_deassert(rstc); 2438c2ecf20Sopenharmony_ci if (ret) { 2448c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 2458c2ecf20Sopenharmony_ci "Couldn't deassert reset control: %d\n", ret); 2468c2ecf20Sopenharmony_ci goto err_disable_clk; 2478c2ecf20Sopenharmony_ci } 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci ret = sunxi_ccu_probe(pdev->dev.of_node, reg, 2508c2ecf20Sopenharmony_ci &sun9i_a80_de_clk_desc); 2518c2ecf20Sopenharmony_ci if (ret) 2528c2ecf20Sopenharmony_ci goto err_assert_reset; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci return 0; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_cierr_assert_reset: 2578c2ecf20Sopenharmony_ci reset_control_assert(rstc); 2588c2ecf20Sopenharmony_cierr_disable_clk: 2598c2ecf20Sopenharmony_ci clk_disable_unprepare(bus_clk); 2608c2ecf20Sopenharmony_ci return ret; 2618c2ecf20Sopenharmony_ci} 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic const struct of_device_id sun9i_a80_de_clk_ids[] = { 2648c2ecf20Sopenharmony_ci { .compatible = "allwinner,sun9i-a80-de-clks" }, 2658c2ecf20Sopenharmony_ci { } 2668c2ecf20Sopenharmony_ci}; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_cistatic struct platform_driver sun9i_a80_de_clk_driver = { 2698c2ecf20Sopenharmony_ci .probe = sun9i_a80_de_clk_probe, 2708c2ecf20Sopenharmony_ci .driver = { 2718c2ecf20Sopenharmony_ci .name = "sun9i-a80-de-clks", 2728c2ecf20Sopenharmony_ci .of_match_table = sun9i_a80_de_clk_ids, 2738c2ecf20Sopenharmony_ci }, 2748c2ecf20Sopenharmony_ci}; 2758c2ecf20Sopenharmony_cibuiltin_platform_driver(sun9i_a80_de_clk_driver); 276