1c2cccb6dSAisheng Dong // SPDX-License-Identifier: GPL-2.0+ 2c2cccb6dSAisheng Dong /* 35964012cSDong Aisheng * Copyright 2018-2021 NXP 4c2cccb6dSAisheng Dong * Dong Aisheng <aisheng.dong@nxp.com> 5c2cccb6dSAisheng Dong */ 6c2cccb6dSAisheng Dong 7c2cccb6dSAisheng Dong #include <linux/clk-provider.h> 8c2cccb6dSAisheng Dong #include <linux/err.h> 9c2cccb6dSAisheng Dong #include <linux/io.h> 10c2cccb6dSAisheng Dong #include <linux/module.h> 11c2cccb6dSAisheng Dong #include <linux/of.h> 125964012cSDong Aisheng #include <linux/of_device.h> 13c2cccb6dSAisheng Dong #include <linux/platform_device.h> 14c2cccb6dSAisheng Dong #include <linux/slab.h> 15c2cccb6dSAisheng Dong 16c2cccb6dSAisheng Dong #include "clk-scu.h" 17c2cccb6dSAisheng Dong 18c2cccb6dSAisheng Dong #include <dt-bindings/firmware/imx/rsrc.h> 19c2cccb6dSAisheng Dong 20e4c0ca78SLiu Ying static const char *dc0_sels[] = { 21e4c0ca78SLiu Ying "clk_dummy", 22e4c0ca78SLiu Ying "clk_dummy", 23e4c0ca78SLiu Ying "dc0_pll0_clk", 24e4c0ca78SLiu Ying "dc0_pll1_clk", 25e4c0ca78SLiu Ying "dc0_bypass0_clk", 26e4c0ca78SLiu Ying }; 27e4c0ca78SLiu Ying 28*2924b0b0SDong Aisheng static const char * const enet0_rgmii_txc_sels[] = { 29*2924b0b0SDong Aisheng "enet0_ref_div", 30*2924b0b0SDong Aisheng "clk_dummy", 31*2924b0b0SDong Aisheng }; 32*2924b0b0SDong Aisheng 33*2924b0b0SDong Aisheng static const char * const enet1_rgmii_txc_sels[] = { 34*2924b0b0SDong Aisheng "enet1_ref_div", 35*2924b0b0SDong Aisheng "clk_dummy", 36*2924b0b0SDong Aisheng }; 37*2924b0b0SDong Aisheng 38c2cccb6dSAisheng Dong static int imx8qxp_clk_probe(struct platform_device *pdev) 39c2cccb6dSAisheng Dong { 40c2cccb6dSAisheng Dong struct device_node *ccm_node = pdev->dev.of_node; 415964012cSDong Aisheng const struct imx_clk_scu_rsrc_table *rsrc_table; 4291e91677SDong Aisheng int ret; 43c2cccb6dSAisheng Dong 445964012cSDong Aisheng rsrc_table = of_device_get_match_data(&pdev->dev); 455964012cSDong Aisheng ret = imx_clk_scu_init(ccm_node, rsrc_table); 46c2cccb6dSAisheng Dong if (ret) 47c2cccb6dSAisheng Dong return ret; 48c2cccb6dSAisheng Dong 49c2cccb6dSAisheng Dong /* ARM core */ 5091e91677SDong Aisheng imx_clk_scu("a35_clk", IMX_SC_R_A35, IMX_SC_PM_CLK_CPU); 51c2cccb6dSAisheng Dong 52c2cccb6dSAisheng Dong /* LSIO SS */ 5391e91677SDong Aisheng imx_clk_scu("pwm0_clk", IMX_SC_R_PWM_0, IMX_SC_PM_CLK_PER); 5491e91677SDong Aisheng imx_clk_scu("pwm1_clk", IMX_SC_R_PWM_1, IMX_SC_PM_CLK_PER); 5591e91677SDong Aisheng imx_clk_scu("pwm2_clk", IMX_SC_R_PWM_2, IMX_SC_PM_CLK_PER); 5691e91677SDong Aisheng imx_clk_scu("pwm3_clk", IMX_SC_R_PWM_3, IMX_SC_PM_CLK_PER); 5791e91677SDong Aisheng imx_clk_scu("pwm4_clk", IMX_SC_R_PWM_4, IMX_SC_PM_CLK_PER); 5891e91677SDong Aisheng imx_clk_scu("pwm5_clk", IMX_SC_R_PWM_5, IMX_SC_PM_CLK_PER); 5991e91677SDong Aisheng imx_clk_scu("pwm6_clk", IMX_SC_R_PWM_6, IMX_SC_PM_CLK_PER); 6091e91677SDong Aisheng imx_clk_scu("pwm7_clk", IMX_SC_R_PWM_7, IMX_SC_PM_CLK_PER); 6191e91677SDong Aisheng imx_clk_scu("gpt0_clk", IMX_SC_R_GPT_0, IMX_SC_PM_CLK_PER); 6291e91677SDong Aisheng imx_clk_scu("gpt1_clk", IMX_SC_R_GPT_1, IMX_SC_PM_CLK_PER); 6391e91677SDong Aisheng imx_clk_scu("gpt2_clk", IMX_SC_R_GPT_2, IMX_SC_PM_CLK_PER); 6491e91677SDong Aisheng imx_clk_scu("gpt3_clk", IMX_SC_R_GPT_3, IMX_SC_PM_CLK_PER); 6591e91677SDong Aisheng imx_clk_scu("gpt4_clk", IMX_SC_R_GPT_4, IMX_SC_PM_CLK_PER); 6691e91677SDong Aisheng imx_clk_scu("fspi0_clk", IMX_SC_R_FSPI_0, IMX_SC_PM_CLK_PER); 6791e91677SDong Aisheng imx_clk_scu("fspi1_clk", IMX_SC_R_FSPI_1, IMX_SC_PM_CLK_PER); 68c2cccb6dSAisheng Dong 69c2cccb6dSAisheng Dong /* ADMA SS */ 7091e91677SDong Aisheng imx_clk_scu("uart0_clk", IMX_SC_R_UART_0, IMX_SC_PM_CLK_PER); 7191e91677SDong Aisheng imx_clk_scu("uart1_clk", IMX_SC_R_UART_1, IMX_SC_PM_CLK_PER); 7291e91677SDong Aisheng imx_clk_scu("uart2_clk", IMX_SC_R_UART_2, IMX_SC_PM_CLK_PER); 7391e91677SDong Aisheng imx_clk_scu("uart3_clk", IMX_SC_R_UART_3, IMX_SC_PM_CLK_PER); 7491e91677SDong Aisheng imx_clk_scu("spi0_clk", IMX_SC_R_SPI_0, IMX_SC_PM_CLK_PER); 7591e91677SDong Aisheng imx_clk_scu("spi1_clk", IMX_SC_R_SPI_1, IMX_SC_PM_CLK_PER); 7691e91677SDong Aisheng imx_clk_scu("spi2_clk", IMX_SC_R_SPI_2, IMX_SC_PM_CLK_PER); 7791e91677SDong Aisheng imx_clk_scu("spi3_clk", IMX_SC_R_SPI_3, IMX_SC_PM_CLK_PER); 7891e91677SDong Aisheng imx_clk_scu("can0_clk", IMX_SC_R_CAN_0, IMX_SC_PM_CLK_PER); 7991e91677SDong Aisheng imx_clk_scu("i2c0_clk", IMX_SC_R_I2C_0, IMX_SC_PM_CLK_PER); 8091e91677SDong Aisheng imx_clk_scu("i2c1_clk", IMX_SC_R_I2C_1, IMX_SC_PM_CLK_PER); 8191e91677SDong Aisheng imx_clk_scu("i2c2_clk", IMX_SC_R_I2C_2, IMX_SC_PM_CLK_PER); 8291e91677SDong Aisheng imx_clk_scu("i2c3_clk", IMX_SC_R_I2C_3, IMX_SC_PM_CLK_PER); 8391e91677SDong Aisheng imx_clk_scu("ftm0_clk", IMX_SC_R_FTM_0, IMX_SC_PM_CLK_PER); 8491e91677SDong Aisheng imx_clk_scu("ftm1_clk", IMX_SC_R_FTM_1, IMX_SC_PM_CLK_PER); 8591e91677SDong Aisheng imx_clk_scu("adc0_clk", IMX_SC_R_ADC_0, IMX_SC_PM_CLK_PER); 8691e91677SDong Aisheng imx_clk_scu("pwm_clk", IMX_SC_R_LCD_0_PWM_0, IMX_SC_PM_CLK_PER); 8791e91677SDong Aisheng imx_clk_scu("lcd_clk", IMX_SC_R_LCD_0, IMX_SC_PM_CLK_PER); 88c2cccb6dSAisheng Dong 89c2cccb6dSAisheng Dong /* Connectivity */ 9091e91677SDong Aisheng imx_clk_scu("sdhc0_clk", IMX_SC_R_SDHC_0, IMX_SC_PM_CLK_PER); 9191e91677SDong Aisheng imx_clk_scu("sdhc1_clk", IMX_SC_R_SDHC_1, IMX_SC_PM_CLK_PER); 9291e91677SDong Aisheng imx_clk_scu("sdhc2_clk", IMX_SC_R_SDHC_2, IMX_SC_PM_CLK_PER); 93*2924b0b0SDong Aisheng imx_clk_scu("enet0_root_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_PER); 94*2924b0b0SDong Aisheng imx_clk_divider_gpr_scu("enet0_ref_div", "enet0_root_clk", IMX_SC_R_ENET_0, IMX_SC_C_CLKDIV); 95*2924b0b0SDong Aisheng imx_clk_mux_gpr_scu("enet0_rgmii_txc_sel", enet0_rgmii_txc_sels, ARRAY_SIZE(enet0_rgmii_txc_sels), IMX_SC_R_ENET_0, IMX_SC_C_TXCLK); 9691e91677SDong Aisheng imx_clk_scu("enet0_bypass_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_BYPASS); 97*2924b0b0SDong Aisheng imx_clk_scu("enet0_rgmii_rx_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_MISC0); 98*2924b0b0SDong Aisheng imx_clk_scu("enet1_root_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_PER); 99*2924b0b0SDong Aisheng imx_clk_divider_gpr_scu("enet1_ref_div", "enet1_root_clk", IMX_SC_R_ENET_1, IMX_SC_C_CLKDIV); 100*2924b0b0SDong Aisheng imx_clk_mux_gpr_scu("enet1_rgmii_txc_sel", enet1_rgmii_txc_sels, ARRAY_SIZE(enet1_rgmii_txc_sels), IMX_SC_R_ENET_1, IMX_SC_C_TXCLK); 10191e91677SDong Aisheng imx_clk_scu("enet1_bypass_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_BYPASS); 102*2924b0b0SDong Aisheng imx_clk_scu("enet1_rgmii_rx_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_MISC0); 10391e91677SDong Aisheng imx_clk_scu("gpmi_io_clk", IMX_SC_R_NAND, IMX_SC_PM_CLK_MST_BUS); 10491e91677SDong Aisheng imx_clk_scu("gpmi_bch_clk", IMX_SC_R_NAND, IMX_SC_PM_CLK_PER); 10591e91677SDong Aisheng imx_clk_scu("usb3_aclk_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_PER); 10691e91677SDong Aisheng imx_clk_scu("usb3_bus_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_MST_BUS); 10791e91677SDong Aisheng imx_clk_scu("usb3_lpm_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_MISC); 108c2cccb6dSAisheng Dong 109c2cccb6dSAisheng Dong /* Display controller SS */ 11091e91677SDong Aisheng imx_clk_scu2("dc0_disp0_clk", dc0_sels, ARRAY_SIZE(dc0_sels), IMX_SC_R_DC_0, IMX_SC_PM_CLK_MISC0); 11191e91677SDong Aisheng imx_clk_scu2("dc0_disp1_clk", dc0_sels, ARRAY_SIZE(dc0_sels), IMX_SC_R_DC_0, IMX_SC_PM_CLK_MISC1); 11291e91677SDong Aisheng imx_clk_scu("dc0_pll0_clk", IMX_SC_R_DC_0_PLL_0, IMX_SC_PM_CLK_PLL); 11391e91677SDong Aisheng imx_clk_scu("dc0_pll1_clk", IMX_SC_R_DC_0_PLL_1, IMX_SC_PM_CLK_PLL); 11491e91677SDong Aisheng imx_clk_scu("dc0_bypass0_clk", IMX_SC_R_DC_0_VIDEO0, IMX_SC_PM_CLK_BYPASS); 11591e91677SDong Aisheng imx_clk_scu("dc0_bypass1_clk", IMX_SC_R_DC_0_VIDEO1, IMX_SC_PM_CLK_BYPASS); 116c2cccb6dSAisheng Dong 117c2cccb6dSAisheng Dong /* MIPI-LVDS SS */ 11891e91677SDong Aisheng imx_clk_scu("mipi0_lvds_pixel_clk", IMX_SC_R_LVDS_0, IMX_SC_PM_CLK_MISC2); 11991e91677SDong Aisheng imx_clk_scu("mipi0_lvds_bypass_clk", IMX_SC_R_LVDS_0, IMX_SC_PM_CLK_BYPASS); 12091e91677SDong Aisheng imx_clk_scu("mipi0_lvds_phy_clk", IMX_SC_R_LVDS_0, IMX_SC_PM_CLK_MISC3); 12191e91677SDong Aisheng imx_clk_scu("mipi0_i2c0_clk", IMX_SC_R_MIPI_0_I2C_0, IMX_SC_PM_CLK_MISC2); 12291e91677SDong Aisheng imx_clk_scu("mipi0_i2c1_clk", IMX_SC_R_MIPI_0_I2C_1, IMX_SC_PM_CLK_MISC2); 12391e91677SDong Aisheng imx_clk_scu("mipi0_pwm0_clk", IMX_SC_R_MIPI_0_PWM_0, IMX_SC_PM_CLK_PER); 12491e91677SDong Aisheng imx_clk_scu("mipi1_lvds_pixel_clk", IMX_SC_R_LVDS_1, IMX_SC_PM_CLK_MISC2); 12591e91677SDong Aisheng imx_clk_scu("mipi1_lvds_bypass_clk", IMX_SC_R_LVDS_1, IMX_SC_PM_CLK_BYPASS); 12691e91677SDong Aisheng imx_clk_scu("mipi1_lvds_phy_clk", IMX_SC_R_LVDS_1, IMX_SC_PM_CLK_MISC3); 12791e91677SDong Aisheng imx_clk_scu("mipi1_i2c0_clk", IMX_SC_R_MIPI_1_I2C_0, IMX_SC_PM_CLK_MISC2); 12891e91677SDong Aisheng imx_clk_scu("mipi1_i2c1_clk", IMX_SC_R_MIPI_1_I2C_1, IMX_SC_PM_CLK_MISC2); 12991e91677SDong Aisheng imx_clk_scu("mipi1_pwm0_clk", IMX_SC_R_MIPI_1_PWM_0, IMX_SC_PM_CLK_PER); 130c2cccb6dSAisheng Dong 131c2cccb6dSAisheng Dong /* MIPI CSI SS */ 13291e91677SDong Aisheng imx_clk_scu("mipi_csi0_core_clk", IMX_SC_R_CSI_0, IMX_SC_PM_CLK_PER); 13391e91677SDong Aisheng imx_clk_scu("mipi_csi0_esc_clk", IMX_SC_R_CSI_0, IMX_SC_PM_CLK_MISC); 13491e91677SDong Aisheng imx_clk_scu("mipi_csi0_i2c0_clk", IMX_SC_R_CSI_0_I2C_0, IMX_SC_PM_CLK_PER); 13591e91677SDong Aisheng imx_clk_scu("mipi_csi0_pwm0_clk", IMX_SC_R_CSI_0_PWM_0, IMX_SC_PM_CLK_PER); 136c2cccb6dSAisheng Dong 137c2cccb6dSAisheng Dong /* GPU SS */ 13891e91677SDong Aisheng imx_clk_scu("gpu_core0_clk", IMX_SC_R_GPU_0_PID0, IMX_SC_PM_CLK_PER); 13991e91677SDong Aisheng imx_clk_scu("gpu_shader0_clk", IMX_SC_R_GPU_0_PID0, IMX_SC_PM_CLK_MISC); 140c2cccb6dSAisheng Dong 14177d8f306SDong Aisheng ret = of_clk_add_hw_provider(ccm_node, imx_scu_of_clk_src_get, imx_scu_clks); 14277d8f306SDong Aisheng if (ret) 14377d8f306SDong Aisheng imx_clk_scu_unregister(); 14477d8f306SDong Aisheng 14577d8f306SDong Aisheng return ret; 146c2cccb6dSAisheng Dong } 147c2cccb6dSAisheng Dong 148c2cccb6dSAisheng Dong static const struct of_device_id imx8qxp_match[] = { 149cd67d327SAisheng Dong { .compatible = "fsl,scu-clk", }, 1505964012cSDong Aisheng { .compatible = "fsl,imx8qxp-clk", &imx_clk_scu_rsrc_imx8qxp, }, 151afd0406bSDong Aisheng { .compatible = "fsl,imx8qm-clk", &imx_clk_scu_rsrc_imx8qm, }, 152c2cccb6dSAisheng Dong { /* sentinel */ } 153c2cccb6dSAisheng Dong }; 154c2cccb6dSAisheng Dong 155c2cccb6dSAisheng Dong static struct platform_driver imx8qxp_clk_driver = { 156c2cccb6dSAisheng Dong .driver = { 157c2cccb6dSAisheng Dong .name = "imx8qxp-clk", 158c2cccb6dSAisheng Dong .of_match_table = imx8qxp_match, 159c2cccb6dSAisheng Dong .suppress_bind_attrs = true, 160c2cccb6dSAisheng Dong }, 161c2cccb6dSAisheng Dong .probe = imx8qxp_clk_probe, 162c2cccb6dSAisheng Dong }; 163c2cccb6dSAisheng Dong builtin_platform_driver(imx8qxp_clk_driver); 164e0d0d4d8SAnson Huang 165e0d0d4d8SAnson Huang MODULE_AUTHOR("Aisheng Dong <aisheng.dong@nxp.com>"); 166e0d0d4d8SAnson Huang MODULE_DESCRIPTION("NXP i.MX8QXP clock driver"); 167e0d0d4d8SAnson Huang MODULE_LICENSE("GPL v2"); 168