xref: /openbmc/linux/drivers/clk/imx/clk-imx8qxp.c (revision cd67d3272768aa3f44c0f7cc71b82a112dce01fa)
1c2cccb6dSAisheng Dong // SPDX-License-Identifier: GPL-2.0+
2c2cccb6dSAisheng Dong /*
3c2cccb6dSAisheng Dong  * Copyright 2018 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>
12c2cccb6dSAisheng Dong #include <linux/platform_device.h>
13c2cccb6dSAisheng Dong #include <linux/slab.h>
14c2cccb6dSAisheng Dong 
15c2cccb6dSAisheng Dong #include "clk-scu.h"
16c2cccb6dSAisheng Dong 
1708972760SAisheng Dong #include <dt-bindings/clock/imx8-clock.h>
18c2cccb6dSAisheng Dong #include <dt-bindings/firmware/imx/rsrc.h>
19c2cccb6dSAisheng Dong 
20c2cccb6dSAisheng Dong static int imx8qxp_clk_probe(struct platform_device *pdev)
21c2cccb6dSAisheng Dong {
22c2cccb6dSAisheng Dong 	struct device_node *ccm_node = pdev->dev.of_node;
23c2cccb6dSAisheng Dong 	struct clk_hw_onecell_data *clk_data;
24c2cccb6dSAisheng Dong 	struct clk_hw **clks;
25c2cccb6dSAisheng Dong 	int ret, i;
26c2cccb6dSAisheng Dong 
27c2cccb6dSAisheng Dong 	ret = imx_clk_scu_init();
28c2cccb6dSAisheng Dong 	if (ret)
29c2cccb6dSAisheng Dong 		return ret;
30c2cccb6dSAisheng Dong 
31c2cccb6dSAisheng Dong 	clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hws,
3208972760SAisheng Dong 				IMX_SCU_CLK_END), GFP_KERNEL);
33c2cccb6dSAisheng Dong 	if (!clk_data)
34c2cccb6dSAisheng Dong 		return -ENOMEM;
35c2cccb6dSAisheng Dong 
3608972760SAisheng Dong 	clk_data->num = IMX_SCU_CLK_END;
37c2cccb6dSAisheng Dong 	clks = clk_data->hws;
38c2cccb6dSAisheng Dong 
39c2cccb6dSAisheng Dong 	/* Fixed clocks */
4008972760SAisheng Dong 	clks[IMX_CLK_DUMMY]		= clk_hw_register_fixed_rate(NULL, "dummy", NULL, 0, 0);
4108972760SAisheng Dong 	clks[IMX_ADMA_IPG_CLK_ROOT] 	= clk_hw_register_fixed_rate(NULL, "dma_ipg_clk_root", NULL, 0, 120000000);
4208972760SAisheng Dong 	clks[IMX_CONN_AXI_CLK_ROOT]	= clk_hw_register_fixed_rate(NULL, "conn_axi_clk_root", NULL, 0, 333333333);
4308972760SAisheng Dong 	clks[IMX_CONN_AHB_CLK_ROOT]	= clk_hw_register_fixed_rate(NULL, "conn_ahb_clk_root", NULL, 0, 166666666);
4408972760SAisheng Dong 	clks[IMX_CONN_IPG_CLK_ROOT]	= clk_hw_register_fixed_rate(NULL, "conn_ipg_clk_root", NULL, 0, 83333333);
4508972760SAisheng Dong 	clks[IMX_DC_AXI_EXT_CLK]	= clk_hw_register_fixed_rate(NULL, "dc_axi_ext_clk_root", NULL, 0, 800000000);
4608972760SAisheng Dong 	clks[IMX_DC_AXI_INT_CLK]	= clk_hw_register_fixed_rate(NULL, "dc_axi_int_clk_root", NULL, 0, 400000000);
4708972760SAisheng Dong 	clks[IMX_DC_CFG_CLK]		= clk_hw_register_fixed_rate(NULL, "dc_cfg_clk_root", NULL, 0, 100000000);
4808972760SAisheng Dong 	clks[IMX_MIPI_IPG_CLK]		= clk_hw_register_fixed_rate(NULL, "mipi_ipg_clk_root", NULL, 0, 120000000);
4908972760SAisheng Dong 	clks[IMX_IMG_AXI_CLK]		= clk_hw_register_fixed_rate(NULL, "img_axi_clk_root", NULL, 0, 400000000);
5008972760SAisheng Dong 	clks[IMX_IMG_IPG_CLK]		= clk_hw_register_fixed_rate(NULL, "img_ipg_clk_root", NULL, 0, 200000000);
5108972760SAisheng Dong 	clks[IMX_IMG_PXL_CLK]		= clk_hw_register_fixed_rate(NULL, "img_pxl_clk_root", NULL, 0, 600000000);
5208972760SAisheng Dong 	clks[IMX_HSIO_AXI_CLK]		= clk_hw_register_fixed_rate(NULL, "hsio_axi_clk_root", NULL, 0, 400000000);
5308972760SAisheng Dong 	clks[IMX_HSIO_PER_CLK]		= clk_hw_register_fixed_rate(NULL, "hsio_per_clk_root", NULL, 0, 133333333);
5408972760SAisheng Dong 	clks[IMX_LSIO_MEM_CLK]		= clk_hw_register_fixed_rate(NULL, "lsio_mem_clk_root", NULL, 0, 200000000);
5508972760SAisheng Dong 	clks[IMX_LSIO_BUS_CLK]		= clk_hw_register_fixed_rate(NULL, "lsio_bus_clk_root", NULL, 0, 100000000);
56c2cccb6dSAisheng Dong 
57c2cccb6dSAisheng Dong 	/* ARM core */
5808972760SAisheng Dong 	clks[IMX_A35_CLK]		= imx_clk_scu("a35_clk", IMX_SC_R_A35, IMX_SC_PM_CLK_CPU);
59c2cccb6dSAisheng Dong 
60c2cccb6dSAisheng Dong 	/* LSIO SS */
6108972760SAisheng Dong 	clks[IMX_LSIO_PWM0_CLK]		= imx_clk_scu("pwm0_clk", IMX_SC_R_PWM_0, IMX_SC_PM_CLK_PER);
6208972760SAisheng Dong 	clks[IMX_LSIO_PWM1_CLK]		= imx_clk_scu("pwm1_clk", IMX_SC_R_PWM_1, IMX_SC_PM_CLK_PER);
6308972760SAisheng Dong 	clks[IMX_LSIO_PWM2_CLK]		= imx_clk_scu("pwm2_clk", IMX_SC_R_PWM_2, IMX_SC_PM_CLK_PER);
6408972760SAisheng Dong 	clks[IMX_LSIO_PWM3_CLK]		= imx_clk_scu("pwm3_clk", IMX_SC_R_PWM_3, IMX_SC_PM_CLK_PER);
6508972760SAisheng Dong 	clks[IMX_LSIO_PWM4_CLK]		= imx_clk_scu("pwm4_clk", IMX_SC_R_PWM_4, IMX_SC_PM_CLK_PER);
6608972760SAisheng Dong 	clks[IMX_LSIO_PWM5_CLK]		= imx_clk_scu("pwm5_clk", IMX_SC_R_PWM_5, IMX_SC_PM_CLK_PER);
6708972760SAisheng Dong 	clks[IMX_LSIO_PWM6_CLK]		= imx_clk_scu("pwm6_clk", IMX_SC_R_PWM_6, IMX_SC_PM_CLK_PER);
6808972760SAisheng Dong 	clks[IMX_LSIO_PWM7_CLK]		= imx_clk_scu("pwm7_clk", IMX_SC_R_PWM_7, IMX_SC_PM_CLK_PER);
6908972760SAisheng Dong 	clks[IMX_LSIO_GPT0_CLK]		= imx_clk_scu("gpt0_clk", IMX_SC_R_GPT_0, IMX_SC_PM_CLK_PER);
7008972760SAisheng Dong 	clks[IMX_LSIO_GPT1_CLK]		= imx_clk_scu("gpt1_clk", IMX_SC_R_GPT_1, IMX_SC_PM_CLK_PER);
7108972760SAisheng Dong 	clks[IMX_LSIO_GPT2_CLK]		= imx_clk_scu("gpt2_clk", IMX_SC_R_GPT_2, IMX_SC_PM_CLK_PER);
7208972760SAisheng Dong 	clks[IMX_LSIO_GPT3_CLK]		= imx_clk_scu("gpt3_clk", IMX_SC_R_GPT_3, IMX_SC_PM_CLK_PER);
7308972760SAisheng Dong 	clks[IMX_LSIO_GPT4_CLK]		= imx_clk_scu("gpt4_clk", IMX_SC_R_GPT_4, IMX_SC_PM_CLK_PER);
7408972760SAisheng Dong 	clks[IMX_LSIO_FSPI0_CLK]	= imx_clk_scu("fspi0_clk", IMX_SC_R_FSPI_0, IMX_SC_PM_CLK_PER);
7508972760SAisheng Dong 	clks[IMX_LSIO_FSPI1_CLK]	= imx_clk_scu("fspi1_clk", IMX_SC_R_FSPI_1, IMX_SC_PM_CLK_PER);
76c2cccb6dSAisheng Dong 
77c2cccb6dSAisheng Dong 	/* ADMA SS */
7808972760SAisheng Dong 	clks[IMX_ADMA_UART0_CLK]	= imx_clk_scu("uart0_clk", IMX_SC_R_UART_0, IMX_SC_PM_CLK_PER);
7908972760SAisheng Dong 	clks[IMX_ADMA_UART1_CLK]	= imx_clk_scu("uart1_clk", IMX_SC_R_UART_1, IMX_SC_PM_CLK_PER);
8008972760SAisheng Dong 	clks[IMX_ADMA_UART2_CLK]	= imx_clk_scu("uart2_clk", IMX_SC_R_UART_2, IMX_SC_PM_CLK_PER);
8108972760SAisheng Dong 	clks[IMX_ADMA_UART3_CLK]	= imx_clk_scu("uart3_clk", IMX_SC_R_UART_3, IMX_SC_PM_CLK_PER);
8208972760SAisheng Dong 	clks[IMX_ADMA_SPI0_CLK]		= imx_clk_scu("spi0_clk",  IMX_SC_R_SPI_0, IMX_SC_PM_CLK_PER);
8308972760SAisheng Dong 	clks[IMX_ADMA_SPI1_CLK]		= imx_clk_scu("spi1_clk",  IMX_SC_R_SPI_1, IMX_SC_PM_CLK_PER);
8408972760SAisheng Dong 	clks[IMX_ADMA_SPI2_CLK]		= imx_clk_scu("spi2_clk",  IMX_SC_R_SPI_2, IMX_SC_PM_CLK_PER);
8508972760SAisheng Dong 	clks[IMX_ADMA_SPI3_CLK]		= imx_clk_scu("spi3_clk",  IMX_SC_R_SPI_3, IMX_SC_PM_CLK_PER);
8608972760SAisheng Dong 	clks[IMX_ADMA_CAN0_CLK]		= imx_clk_scu("can0_clk",  IMX_SC_R_CAN_0, IMX_SC_PM_CLK_PER);
8708972760SAisheng Dong 	clks[IMX_ADMA_I2C0_CLK]		= imx_clk_scu("i2c0_clk",  IMX_SC_R_I2C_0, IMX_SC_PM_CLK_PER);
8808972760SAisheng Dong 	clks[IMX_ADMA_I2C1_CLK]		= imx_clk_scu("i2c1_clk",  IMX_SC_R_I2C_1, IMX_SC_PM_CLK_PER);
8908972760SAisheng Dong 	clks[IMX_ADMA_I2C2_CLK]		= imx_clk_scu("i2c2_clk",  IMX_SC_R_I2C_2, IMX_SC_PM_CLK_PER);
9008972760SAisheng Dong 	clks[IMX_ADMA_I2C3_CLK]		= imx_clk_scu("i2c3_clk",  IMX_SC_R_I2C_3, IMX_SC_PM_CLK_PER);
9108972760SAisheng Dong 	clks[IMX_ADMA_FTM0_CLK]		= imx_clk_scu("ftm0_clk",  IMX_SC_R_FTM_0, IMX_SC_PM_CLK_PER);
9208972760SAisheng Dong 	clks[IMX_ADMA_FTM1_CLK]		= imx_clk_scu("ftm1_clk",  IMX_SC_R_FTM_1, IMX_SC_PM_CLK_PER);
9308972760SAisheng Dong 	clks[IMX_ADMA_ADC0_CLK]		= imx_clk_scu("adc0_clk",  IMX_SC_R_ADC_0, IMX_SC_PM_CLK_PER);
9408972760SAisheng Dong 	clks[IMX_ADMA_PWM_CLK]		= imx_clk_scu("pwm_clk",   IMX_SC_R_LCD_0_PWM_0, IMX_SC_PM_CLK_PER);
9508972760SAisheng Dong 	clks[IMX_ADMA_LCD_CLK]		= imx_clk_scu("lcd_clk",   IMX_SC_R_LCD_0, IMX_SC_PM_CLK_PER);
96c2cccb6dSAisheng Dong 
97c2cccb6dSAisheng Dong 	/* Connectivity */
9808972760SAisheng Dong 	clks[IMX_CONN_SDHC0_CLK]	= imx_clk_scu("sdhc0_clk", IMX_SC_R_SDHC_0, IMX_SC_PM_CLK_PER);
9908972760SAisheng Dong 	clks[IMX_CONN_SDHC1_CLK]	= imx_clk_scu("sdhc1_clk", IMX_SC_R_SDHC_1, IMX_SC_PM_CLK_PER);
10008972760SAisheng Dong 	clks[IMX_CONN_SDHC2_CLK]	= imx_clk_scu("sdhc2_clk", IMX_SC_R_SDHC_2, IMX_SC_PM_CLK_PER);
10108972760SAisheng Dong 	clks[IMX_CONN_ENET0_ROOT_CLK]	= imx_clk_scu("enet0_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_PER);
10208972760SAisheng Dong 	clks[IMX_CONN_ENET0_BYPASS_CLK]	= imx_clk_scu("enet0_bypass_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_BYPASS);
10308972760SAisheng Dong 	clks[IMX_CONN_ENET0_RGMII_CLK]	= imx_clk_scu("enet0_rgmii_clk", IMX_SC_R_ENET_0, IMX_SC_PM_CLK_MISC0);
10408972760SAisheng Dong 	clks[IMX_CONN_ENET1_ROOT_CLK]	= imx_clk_scu("enet1_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_PER);
10508972760SAisheng Dong 	clks[IMX_CONN_ENET1_BYPASS_CLK]	= imx_clk_scu("enet1_bypass_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_BYPASS);
10608972760SAisheng Dong 	clks[IMX_CONN_ENET1_RGMII_CLK]	= imx_clk_scu("enet1_rgmii_clk", IMX_SC_R_ENET_1, IMX_SC_PM_CLK_MISC0);
10708972760SAisheng Dong 	clks[IMX_CONN_GPMI_BCH_IO_CLK]	= imx_clk_scu("gpmi_io_clk", IMX_SC_R_NAND, IMX_SC_PM_CLK_MST_BUS);
10808972760SAisheng Dong 	clks[IMX_CONN_GPMI_BCH_CLK]	= imx_clk_scu("gpmi_bch_clk", IMX_SC_R_NAND, IMX_SC_PM_CLK_PER);
10908972760SAisheng Dong 	clks[IMX_CONN_USB2_ACLK]	= imx_clk_scu("usb3_aclk_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_PER);
11008972760SAisheng Dong 	clks[IMX_CONN_USB2_BUS_CLK]	= imx_clk_scu("usb3_bus_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_MST_BUS);
11108972760SAisheng Dong 	clks[IMX_CONN_USB2_LPM_CLK]	= imx_clk_scu("usb3_lpm_div", IMX_SC_R_USB_2, IMX_SC_PM_CLK_MISC);
112c2cccb6dSAisheng Dong 
113c2cccb6dSAisheng Dong 	/* Display controller SS */
11408972760SAisheng Dong 	clks[IMX_DC0_DISP0_CLK]		= imx_clk_scu("dc0_disp0_clk", IMX_SC_R_DC_0, IMX_SC_PM_CLK_MISC0);
11508972760SAisheng Dong 	clks[IMX_DC0_DISP1_CLK]		= imx_clk_scu("dc0_disp1_clk", IMX_SC_R_DC_0, IMX_SC_PM_CLK_MISC1);
116c2cccb6dSAisheng Dong 
117c2cccb6dSAisheng Dong 	/* MIPI-LVDS SS */
11808972760SAisheng Dong 	clks[IMX_MIPI0_I2C0_CLK]	= imx_clk_scu("mipi0_i2c0_clk", IMX_SC_R_MIPI_0_I2C_0, IMX_SC_PM_CLK_MISC2);
11908972760SAisheng Dong 	clks[IMX_MIPI0_I2C1_CLK]	= imx_clk_scu("mipi0_i2c1_clk", IMX_SC_R_MIPI_0_I2C_1, IMX_SC_PM_CLK_MISC2);
120c2cccb6dSAisheng Dong 
121c2cccb6dSAisheng Dong 	/* MIPI CSI SS */
12208972760SAisheng Dong 	clks[IMX_CSI0_CORE_CLK]		= imx_clk_scu("mipi_csi0_core_clk", IMX_SC_R_CSI_0, IMX_SC_PM_CLK_PER);
12308972760SAisheng Dong 	clks[IMX_CSI0_ESC_CLK]		= imx_clk_scu("mipi_csi0_esc_clk",  IMX_SC_R_CSI_0, IMX_SC_PM_CLK_MISC);
12408972760SAisheng Dong 	clks[IMX_CSI0_I2C0_CLK]		= imx_clk_scu("mipi_csi0_i2c0_clk", IMX_SC_R_CSI_0_I2C_0, IMX_SC_PM_CLK_PER);
12508972760SAisheng Dong 	clks[IMX_CSI0_PWM0_CLK]		= imx_clk_scu("mipi_csi0_pwm0_clk", IMX_SC_R_CSI_0_PWM_0, IMX_SC_PM_CLK_PER);
126c2cccb6dSAisheng Dong 
127c2cccb6dSAisheng Dong 	/* GPU SS */
12808972760SAisheng Dong 	clks[IMX_GPU0_CORE_CLK]		= imx_clk_scu("gpu_core0_clk",	 IMX_SC_R_GPU_0_PID0, IMX_SC_PM_CLK_PER);
12908972760SAisheng Dong 	clks[IMX_GPU0_SHADER_CLK]	= imx_clk_scu("gpu_shader0_clk", IMX_SC_R_GPU_0_PID0, IMX_SC_PM_CLK_MISC);
130c2cccb6dSAisheng Dong 
131c2cccb6dSAisheng Dong 	for (i = 0; i < clk_data->num; i++) {
132c2cccb6dSAisheng Dong 		if (IS_ERR(clks[i]))
133c2cccb6dSAisheng Dong 			pr_warn("i.MX clk %u: register failed with %ld\n",
134c2cccb6dSAisheng Dong 				i, PTR_ERR(clks[i]));
135c2cccb6dSAisheng Dong 	}
136c2cccb6dSAisheng Dong 
137c2cccb6dSAisheng Dong 	return of_clk_add_hw_provider(ccm_node, of_clk_hw_onecell_get, clk_data);
138c2cccb6dSAisheng Dong }
139c2cccb6dSAisheng Dong 
140c2cccb6dSAisheng Dong static const struct of_device_id imx8qxp_match[] = {
141*cd67d327SAisheng Dong 	{ .compatible = "fsl,scu-clk", },
142c2cccb6dSAisheng Dong 	{ .compatible = "fsl,imx8qxp-clk", },
143c2cccb6dSAisheng Dong 	{ /* sentinel */ }
144c2cccb6dSAisheng Dong };
145c2cccb6dSAisheng Dong 
146c2cccb6dSAisheng Dong static struct platform_driver imx8qxp_clk_driver = {
147c2cccb6dSAisheng Dong 	.driver = {
148c2cccb6dSAisheng Dong 		.name = "imx8qxp-clk",
149c2cccb6dSAisheng Dong 		.of_match_table = imx8qxp_match,
150c2cccb6dSAisheng Dong 		.suppress_bind_attrs = true,
151c2cccb6dSAisheng Dong 	},
152c2cccb6dSAisheng Dong 	.probe = imx8qxp_clk_probe,
153c2cccb6dSAisheng Dong };
154c2cccb6dSAisheng Dong builtin_platform_driver(imx8qxp_clk_driver);
155