18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Hi3516CV300 Clock and Reset Generator Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2016 HiSilicon Technologies Co., Ltd. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <dt-bindings/clock/hi3516cv300-clock.h> 98c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/of_device.h> 128c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 138c2ecf20Sopenharmony_ci#include "clk.h" 148c2ecf20Sopenharmony_ci#include "crg.h" 158c2ecf20Sopenharmony_ci#include "reset.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* hi3516CV300 core CRG */ 188c2ecf20Sopenharmony_ci#define HI3516CV300_INNER_CLK_OFFSET 64 198c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_3M 65 208c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_6M 66 218c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_24M 67 228c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_49P5 68 238c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_50M 69 248c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_83P3M 70 258c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_99M 71 268c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_100M 72 278c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_148P5M 73 288c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_198M 74 298c2ecf20Sopenharmony_ci#define HI3516CV300_FIXED_297M 75 308c2ecf20Sopenharmony_ci#define HI3516CV300_UART_MUX 76 318c2ecf20Sopenharmony_ci#define HI3516CV300_FMC_MUX 77 328c2ecf20Sopenharmony_ci#define HI3516CV300_MMC0_MUX 78 338c2ecf20Sopenharmony_ci#define HI3516CV300_MMC1_MUX 79 348c2ecf20Sopenharmony_ci#define HI3516CV300_MMC2_MUX 80 358c2ecf20Sopenharmony_ci#define HI3516CV300_MMC3_MUX 81 368c2ecf20Sopenharmony_ci#define HI3516CV300_PWM_MUX 82 378c2ecf20Sopenharmony_ci#define HI3516CV300_CRG_NR_CLKS 128 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic const struct hisi_fixed_rate_clock hi3516cv300_fixed_rate_clks[] = { 408c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_3M, "3m", NULL, 0, 3000000, }, 418c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_6M, "6m", NULL, 0, 6000000, }, 428c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_24M, "24m", NULL, 0, 24000000, }, 438c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_49P5, "49.5m", NULL, 0, 49500000, }, 448c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_50M, "50m", NULL, 0, 50000000, }, 458c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_83P3M, "83.3m", NULL, 0, 83300000, }, 468c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_99M, "99m", NULL, 0, 99000000, }, 478c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_100M, "100m", NULL, 0, 100000000, }, 488c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_148P5M, "148.5m", NULL, 0, 148500000, }, 498c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_198M, "198m", NULL, 0, 198000000, }, 508c2ecf20Sopenharmony_ci { HI3516CV300_FIXED_297M, "297m", NULL, 0, 297000000, }, 518c2ecf20Sopenharmony_ci { HI3516CV300_APB_CLK, "apb", NULL, 0, 50000000, }, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic const char *const uart_mux_p[] = {"24m", "6m"}; 558c2ecf20Sopenharmony_cistatic const char *const fmc_mux_p[] = { 568c2ecf20Sopenharmony_ci "24m", "83.3m", "148.5m", "198m", "297m" 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_cistatic const char *const mmc_mux_p[] = {"49.5m"}; 598c2ecf20Sopenharmony_cistatic const char *const mmc2_mux_p[] = {"99m", "49.5m"}; 608c2ecf20Sopenharmony_cistatic const char *const pwm_mux_p[] = {"3m", "50m", "24m", "24m"}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic u32 uart_mux_table[] = {0, 1}; 638c2ecf20Sopenharmony_cistatic u32 fmc_mux_table[] = {0, 1, 2, 3, 4}; 648c2ecf20Sopenharmony_cistatic u32 mmc_mux_table[] = {0}; 658c2ecf20Sopenharmony_cistatic u32 mmc2_mux_table[] = {0, 2}; 668c2ecf20Sopenharmony_cistatic u32 pwm_mux_table[] = {0, 1, 2, 3}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic const struct hisi_mux_clock hi3516cv300_mux_clks[] = { 698c2ecf20Sopenharmony_ci { HI3516CV300_UART_MUX, "uart_mux", uart_mux_p, ARRAY_SIZE(uart_mux_p), 708c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xe4, 19, 1, 0, uart_mux_table, }, 718c2ecf20Sopenharmony_ci { HI3516CV300_FMC_MUX, "fmc_mux", fmc_mux_p, ARRAY_SIZE(fmc_mux_p), 728c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xc0, 2, 3, 0, fmc_mux_table, }, 738c2ecf20Sopenharmony_ci { HI3516CV300_MMC0_MUX, "mmc0_mux", mmc_mux_p, ARRAY_SIZE(mmc_mux_p), 748c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xc4, 4, 2, 0, mmc_mux_table, }, 758c2ecf20Sopenharmony_ci { HI3516CV300_MMC1_MUX, "mmc1_mux", mmc_mux_p, ARRAY_SIZE(mmc_mux_p), 768c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xc4, 12, 2, 0, mmc_mux_table, }, 778c2ecf20Sopenharmony_ci { HI3516CV300_MMC2_MUX, "mmc2_mux", mmc2_mux_p, ARRAY_SIZE(mmc2_mux_p), 788c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xc4, 20, 2, 0, mmc2_mux_table, }, 798c2ecf20Sopenharmony_ci { HI3516CV300_MMC3_MUX, "mmc3_mux", mmc_mux_p, ARRAY_SIZE(mmc_mux_p), 808c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0xc8, 4, 2, 0, mmc_mux_table, }, 818c2ecf20Sopenharmony_ci { HI3516CV300_PWM_MUX, "pwm_mux", pwm_mux_p, ARRAY_SIZE(pwm_mux_p), 828c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0x38, 2, 2, 0, pwm_mux_table, }, 838c2ecf20Sopenharmony_ci}; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic const struct hisi_gate_clock hi3516cv300_gate_clks[] = { 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci { HI3516CV300_UART0_CLK, "clk_uart0", "uart_mux", CLK_SET_RATE_PARENT, 888c2ecf20Sopenharmony_ci 0xe4, 15, 0, }, 898c2ecf20Sopenharmony_ci { HI3516CV300_UART1_CLK, "clk_uart1", "uart_mux", CLK_SET_RATE_PARENT, 908c2ecf20Sopenharmony_ci 0xe4, 16, 0, }, 918c2ecf20Sopenharmony_ci { HI3516CV300_UART2_CLK, "clk_uart2", "uart_mux", CLK_SET_RATE_PARENT, 928c2ecf20Sopenharmony_ci 0xe4, 17, 0, }, 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci { HI3516CV300_SPI0_CLK, "clk_spi0", "100m", CLK_SET_RATE_PARENT, 958c2ecf20Sopenharmony_ci 0xe4, 13, 0, }, 968c2ecf20Sopenharmony_ci { HI3516CV300_SPI1_CLK, "clk_spi1", "100m", CLK_SET_RATE_PARENT, 978c2ecf20Sopenharmony_ci 0xe4, 14, 0, }, 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci { HI3516CV300_FMC_CLK, "clk_fmc", "fmc_mux", CLK_SET_RATE_PARENT, 1008c2ecf20Sopenharmony_ci 0xc0, 1, 0, }, 1018c2ecf20Sopenharmony_ci { HI3516CV300_MMC0_CLK, "clk_mmc0", "mmc0_mux", CLK_SET_RATE_PARENT, 1028c2ecf20Sopenharmony_ci 0xc4, 1, 0, }, 1038c2ecf20Sopenharmony_ci { HI3516CV300_MMC1_CLK, "clk_mmc1", "mmc1_mux", CLK_SET_RATE_PARENT, 1048c2ecf20Sopenharmony_ci 0xc4, 9, 0, }, 1058c2ecf20Sopenharmony_ci { HI3516CV300_MMC2_CLK, "clk_mmc2", "mmc2_mux", CLK_SET_RATE_PARENT, 1068c2ecf20Sopenharmony_ci 0xc4, 17, 0, }, 1078c2ecf20Sopenharmony_ci { HI3516CV300_MMC3_CLK, "clk_mmc3", "mmc3_mux", CLK_SET_RATE_PARENT, 1088c2ecf20Sopenharmony_ci 0xc8, 1, 0, }, 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci { HI3516CV300_ETH_CLK, "clk_eth", NULL, 0, 0xec, 1, 0, }, 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci { HI3516CV300_DMAC_CLK, "clk_dmac", NULL, 0, 0xd8, 5, 0, }, 1138c2ecf20Sopenharmony_ci { HI3516CV300_PWM_CLK, "clk_pwm", "pwm_mux", CLK_SET_RATE_PARENT, 1148c2ecf20Sopenharmony_ci 0x38, 1, 0, }, 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci { HI3516CV300_USB2_BUS_CLK, "clk_usb2_bus", NULL, 0, 0xb8, 0, 0, }, 1178c2ecf20Sopenharmony_ci { HI3516CV300_USB2_OHCI48M_CLK, "clk_usb2_ohci48m", NULL, 0, 1188c2ecf20Sopenharmony_ci 0xb8, 1, 0, }, 1198c2ecf20Sopenharmony_ci { HI3516CV300_USB2_OHCI12M_CLK, "clk_usb2_ohci12m", NULL, 0, 1208c2ecf20Sopenharmony_ci 0xb8, 2, 0, }, 1218c2ecf20Sopenharmony_ci { HI3516CV300_USB2_OTG_UTMI_CLK, "clk_usb2_otg_utmi", NULL, 0, 1228c2ecf20Sopenharmony_ci 0xb8, 3, 0, }, 1238c2ecf20Sopenharmony_ci { HI3516CV300_USB2_HST_PHY_CLK, "clk_usb2_hst_phy", NULL, 0, 1248c2ecf20Sopenharmony_ci 0xb8, 4, 0, }, 1258c2ecf20Sopenharmony_ci { HI3516CV300_USB2_UTMI0_CLK, "clk_usb2_utmi0", NULL, 0, 0xb8, 5, 0, }, 1268c2ecf20Sopenharmony_ci { HI3516CV300_USB2_PHY_CLK, "clk_usb2_phy", NULL, 0, 0xb8, 7, 0, }, 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic struct hisi_clock_data *hi3516cv300_clk_register( 1308c2ecf20Sopenharmony_ci struct platform_device *pdev) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci struct hisi_clock_data *clk_data; 1338c2ecf20Sopenharmony_ci int ret; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci clk_data = hisi_clk_alloc(pdev, HI3516CV300_CRG_NR_CLKS); 1368c2ecf20Sopenharmony_ci if (!clk_data) 1378c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci ret = hisi_clk_register_fixed_rate(hi3516cv300_fixed_rate_clks, 1408c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_fixed_rate_clks), clk_data); 1418c2ecf20Sopenharmony_ci if (ret) 1428c2ecf20Sopenharmony_ci return ERR_PTR(ret); 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci ret = hisi_clk_register_mux(hi3516cv300_mux_clks, 1458c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_mux_clks), clk_data); 1468c2ecf20Sopenharmony_ci if (ret) 1478c2ecf20Sopenharmony_ci goto unregister_fixed_rate; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci ret = hisi_clk_register_gate(hi3516cv300_gate_clks, 1508c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_gate_clks), clk_data); 1518c2ecf20Sopenharmony_ci if (ret) 1528c2ecf20Sopenharmony_ci goto unregister_mux; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci ret = of_clk_add_provider(pdev->dev.of_node, 1558c2ecf20Sopenharmony_ci of_clk_src_onecell_get, &clk_data->clk_data); 1568c2ecf20Sopenharmony_ci if (ret) 1578c2ecf20Sopenharmony_ci goto unregister_gate; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci return clk_data; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciunregister_gate: 1628c2ecf20Sopenharmony_ci hisi_clk_unregister_gate(hi3516cv300_gate_clks, 1638c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_gate_clks), clk_data); 1648c2ecf20Sopenharmony_ciunregister_mux: 1658c2ecf20Sopenharmony_ci hisi_clk_unregister_mux(hi3516cv300_mux_clks, 1668c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_mux_clks), clk_data); 1678c2ecf20Sopenharmony_ciunregister_fixed_rate: 1688c2ecf20Sopenharmony_ci hisi_clk_unregister_fixed_rate(hi3516cv300_fixed_rate_clks, 1698c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_fixed_rate_clks), clk_data); 1708c2ecf20Sopenharmony_ci return ERR_PTR(ret); 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistatic void hi3516cv300_clk_unregister(struct platform_device *pdev) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci struct hisi_crg_dev *crg = platform_get_drvdata(pdev); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci of_clk_del_provider(pdev->dev.of_node); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci hisi_clk_unregister_gate(hi3516cv300_gate_clks, 1808c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_gate_clks), crg->clk_data); 1818c2ecf20Sopenharmony_ci hisi_clk_unregister_mux(hi3516cv300_mux_clks, 1828c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_mux_clks), crg->clk_data); 1838c2ecf20Sopenharmony_ci hisi_clk_unregister_fixed_rate(hi3516cv300_fixed_rate_clks, 1848c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_fixed_rate_clks), crg->clk_data); 1858c2ecf20Sopenharmony_ci} 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic const struct hisi_crg_funcs hi3516cv300_crg_funcs = { 1888c2ecf20Sopenharmony_ci .register_clks = hi3516cv300_clk_register, 1898c2ecf20Sopenharmony_ci .unregister_clks = hi3516cv300_clk_unregister, 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/* hi3516CV300 sysctrl CRG */ 1938c2ecf20Sopenharmony_ci#define HI3516CV300_SYSCTRL_NR_CLKS 16 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic const char *const wdt_mux_p[] __initconst = { "3m", "apb" }; 1968c2ecf20Sopenharmony_cistatic u32 wdt_mux_table[] = {0, 1}; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic const struct hisi_mux_clock hi3516cv300_sysctrl_mux_clks[] = { 1998c2ecf20Sopenharmony_ci { HI3516CV300_WDT_CLK, "wdt", wdt_mux_p, ARRAY_SIZE(wdt_mux_p), 2008c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0x0, 23, 1, 0, wdt_mux_table, }, 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic struct hisi_clock_data *hi3516cv300_sysctrl_clk_register( 2048c2ecf20Sopenharmony_ci struct platform_device *pdev) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci struct hisi_clock_data *clk_data; 2078c2ecf20Sopenharmony_ci int ret; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci clk_data = hisi_clk_alloc(pdev, HI3516CV300_SYSCTRL_NR_CLKS); 2108c2ecf20Sopenharmony_ci if (!clk_data) 2118c2ecf20Sopenharmony_ci return ERR_PTR(-ENOMEM); 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci ret = hisi_clk_register_mux(hi3516cv300_sysctrl_mux_clks, 2148c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), clk_data); 2158c2ecf20Sopenharmony_ci if (ret) 2168c2ecf20Sopenharmony_ci return ERR_PTR(ret); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci ret = of_clk_add_provider(pdev->dev.of_node, 2208c2ecf20Sopenharmony_ci of_clk_src_onecell_get, &clk_data->clk_data); 2218c2ecf20Sopenharmony_ci if (ret) 2228c2ecf20Sopenharmony_ci goto unregister_mux; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci return clk_data; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ciunregister_mux: 2278c2ecf20Sopenharmony_ci hisi_clk_unregister_mux(hi3516cv300_sysctrl_mux_clks, 2288c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), clk_data); 2298c2ecf20Sopenharmony_ci return ERR_PTR(ret); 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic void hi3516cv300_sysctrl_clk_unregister(struct platform_device *pdev) 2338c2ecf20Sopenharmony_ci{ 2348c2ecf20Sopenharmony_ci struct hisi_crg_dev *crg = platform_get_drvdata(pdev); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci of_clk_del_provider(pdev->dev.of_node); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci hisi_clk_unregister_mux(hi3516cv300_sysctrl_mux_clks, 2398c2ecf20Sopenharmony_ci ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), 2408c2ecf20Sopenharmony_ci crg->clk_data); 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic const struct hisi_crg_funcs hi3516cv300_sysctrl_funcs = { 2448c2ecf20Sopenharmony_ci .register_clks = hi3516cv300_sysctrl_clk_register, 2458c2ecf20Sopenharmony_ci .unregister_clks = hi3516cv300_sysctrl_clk_unregister, 2468c2ecf20Sopenharmony_ci}; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cistatic const struct of_device_id hi3516cv300_crg_match_table[] = { 2498c2ecf20Sopenharmony_ci { 2508c2ecf20Sopenharmony_ci .compatible = "hisilicon,hi3516cv300-crg", 2518c2ecf20Sopenharmony_ci .data = &hi3516cv300_crg_funcs 2528c2ecf20Sopenharmony_ci }, 2538c2ecf20Sopenharmony_ci { 2548c2ecf20Sopenharmony_ci .compatible = "hisilicon,hi3516cv300-sysctrl", 2558c2ecf20Sopenharmony_ci .data = &hi3516cv300_sysctrl_funcs 2568c2ecf20Sopenharmony_ci }, 2578c2ecf20Sopenharmony_ci { } 2588c2ecf20Sopenharmony_ci}; 2598c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, hi3516cv300_crg_match_table); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic int hi3516cv300_crg_probe(struct platform_device *pdev) 2628c2ecf20Sopenharmony_ci{ 2638c2ecf20Sopenharmony_ci struct hisi_crg_dev *crg; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); 2668c2ecf20Sopenharmony_ci if (!crg) 2678c2ecf20Sopenharmony_ci return -ENOMEM; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci crg->funcs = of_device_get_match_data(&pdev->dev); 2708c2ecf20Sopenharmony_ci if (!crg->funcs) 2718c2ecf20Sopenharmony_ci return -ENOENT; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci crg->rstc = hisi_reset_init(pdev); 2748c2ecf20Sopenharmony_ci if (!crg->rstc) 2758c2ecf20Sopenharmony_ci return -ENOMEM; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci crg->clk_data = crg->funcs->register_clks(pdev); 2788c2ecf20Sopenharmony_ci if (IS_ERR(crg->clk_data)) { 2798c2ecf20Sopenharmony_ci hisi_reset_exit(crg->rstc); 2808c2ecf20Sopenharmony_ci return PTR_ERR(crg->clk_data); 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, crg); 2848c2ecf20Sopenharmony_ci return 0; 2858c2ecf20Sopenharmony_ci} 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cistatic int hi3516cv300_crg_remove(struct platform_device *pdev) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci struct hisi_crg_dev *crg = platform_get_drvdata(pdev); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci hisi_reset_exit(crg->rstc); 2928c2ecf20Sopenharmony_ci crg->funcs->unregister_clks(pdev); 2938c2ecf20Sopenharmony_ci return 0; 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistatic struct platform_driver hi3516cv300_crg_driver = { 2978c2ecf20Sopenharmony_ci .probe = hi3516cv300_crg_probe, 2988c2ecf20Sopenharmony_ci .remove = hi3516cv300_crg_remove, 2998c2ecf20Sopenharmony_ci .driver = { 3008c2ecf20Sopenharmony_ci .name = "hi3516cv300-crg", 3018c2ecf20Sopenharmony_ci .of_match_table = hi3516cv300_crg_match_table, 3028c2ecf20Sopenharmony_ci }, 3038c2ecf20Sopenharmony_ci}; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_cistatic int __init hi3516cv300_crg_init(void) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci return platform_driver_register(&hi3516cv300_crg_driver); 3088c2ecf20Sopenharmony_ci} 3098c2ecf20Sopenharmony_cicore_initcall(hi3516cv300_crg_init); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_cistatic void __exit hi3516cv300_crg_exit(void) 3128c2ecf20Sopenharmony_ci{ 3138c2ecf20Sopenharmony_ci platform_driver_unregister(&hi3516cv300_crg_driver); 3148c2ecf20Sopenharmony_ci} 3158c2ecf20Sopenharmony_cimodule_exit(hi3516cv300_crg_exit); 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 3188c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("HiSilicon Hi3516CV300 CRG Driver"); 319