xref: /openbmc/linux/drivers/clk/imx/clk-imx8qxp-lpcg.c (revision e0d0d4d86c766335066d7c241fbe42fbd67d4198)
11e3121bfSAisheng Dong // SPDX-License-Identifier: GPL-2.0+
21e3121bfSAisheng Dong /*
31e3121bfSAisheng Dong  * Copyright 2018 NXP
41e3121bfSAisheng Dong  *	Dong Aisheng <aisheng.dong@nxp.com>
51e3121bfSAisheng Dong  */
61e3121bfSAisheng Dong 
71e3121bfSAisheng Dong #include <linux/clk-provider.h>
81e3121bfSAisheng Dong #include <linux/err.h>
91e3121bfSAisheng Dong #include <linux/io.h>
101e3121bfSAisheng Dong #include <linux/module.h>
111e3121bfSAisheng Dong #include <linux/of.h>
121e3121bfSAisheng Dong #include <linux/of_device.h>
131e3121bfSAisheng Dong #include <linux/platform_device.h>
141e3121bfSAisheng Dong #include <linux/slab.h>
151e3121bfSAisheng Dong 
161e3121bfSAisheng Dong #include "clk-scu.h"
171e3121bfSAisheng Dong #include "clk-imx8qxp-lpcg.h"
181e3121bfSAisheng Dong 
1908972760SAisheng Dong #include <dt-bindings/clock/imx8-clock.h>
201e3121bfSAisheng Dong 
211e3121bfSAisheng Dong /*
221e3121bfSAisheng Dong  * struct imx8qxp_lpcg_data - Description of one LPCG clock
231e3121bfSAisheng Dong  * @id: clock ID
241e3121bfSAisheng Dong  * @name: clock name
251e3121bfSAisheng Dong  * @parent: parent clock name
261e3121bfSAisheng Dong  * @flags: common clock flags
271e3121bfSAisheng Dong  * @offset: offset of this LPCG clock
281e3121bfSAisheng Dong  * @bit_idx: bit index of this LPCG clock
291e3121bfSAisheng Dong  * @hw_gate: whether supports HW autogate
301e3121bfSAisheng Dong  *
311e3121bfSAisheng Dong  * This structure describes one LPCG clock
321e3121bfSAisheng Dong  */
331e3121bfSAisheng Dong struct imx8qxp_lpcg_data {
341e3121bfSAisheng Dong 	int id;
351e3121bfSAisheng Dong 	char *name;
361e3121bfSAisheng Dong 	char *parent;
371e3121bfSAisheng Dong 	unsigned long flags;
381e3121bfSAisheng Dong 	u32 offset;
391e3121bfSAisheng Dong 	u8 bit_idx;
401e3121bfSAisheng Dong 	bool hw_gate;
411e3121bfSAisheng Dong };
421e3121bfSAisheng Dong 
431e3121bfSAisheng Dong /*
441e3121bfSAisheng Dong  * struct imx8qxp_ss_lpcg - Description of one subsystem LPCG clocks
451e3121bfSAisheng Dong  * @lpcg: LPCG clocks array of one subsystem
461e3121bfSAisheng Dong  * @num_lpcg: the number of LPCG clocks
471e3121bfSAisheng Dong  * @num_max: the maximum number of LPCG clocks
481e3121bfSAisheng Dong  *
491e3121bfSAisheng Dong  * This structure describes each subsystem LPCG clocks information
501e3121bfSAisheng Dong  * which then will be used to create respective LPCGs clocks
511e3121bfSAisheng Dong  */
521e3121bfSAisheng Dong struct imx8qxp_ss_lpcg {
531e3121bfSAisheng Dong 	const struct imx8qxp_lpcg_data *lpcg;
541e3121bfSAisheng Dong 	u8 num_lpcg;
551e3121bfSAisheng Dong 	u8 num_max;
561e3121bfSAisheng Dong };
571e3121bfSAisheng Dong 
581e3121bfSAisheng Dong static const struct imx8qxp_lpcg_data imx8qxp_lpcg_adma[] = {
5908972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART0_IPG_CLK, "uart0_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_0_LPCG, 16, 0, },
6008972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART0_BAUD_CLK, "uart0_lpcg_baud_clk", "uart0_clk", 0, ADMA_LPUART_0_LPCG, 0, 0, },
6108972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART1_IPG_CLK, "uart1_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_1_LPCG, 16, 0, },
6208972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART1_BAUD_CLK, "uart1_lpcg_baud_clk", "uart1_clk", 0, ADMA_LPUART_1_LPCG, 0, 0, },
6308972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART2_IPG_CLK, "uart2_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_2_LPCG, 16, 0, },
6408972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART2_BAUD_CLK, "uart2_lpcg_baud_clk", "uart2_clk", 0, ADMA_LPUART_2_LPCG, 0, 0, },
6508972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART3_IPG_CLK, "uart3_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_3_LPCG, 16, 0, },
6608972760SAisheng Dong 	{ IMX_ADMA_LPCG_UART3_BAUD_CLK, "uart3_lpcg_baud_clk", "uart3_clk", 0, ADMA_LPUART_3_LPCG, 0, 0, },
6708972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C0_IPG_CLK, "i2c0_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_0_LPCG, 16, 0, },
6808972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C0_CLK, "i2c0_lpcg_clk", "i2c0_clk", 0, ADMA_LPI2C_0_LPCG, 0, 0, },
6908972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C1_IPG_CLK, "i2c1_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_1_LPCG, 16, 0, },
7008972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C1_CLK, "i2c1_lpcg_clk", "i2c1_clk", 0, ADMA_LPI2C_1_LPCG, 0, 0, },
7108972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C2_IPG_CLK, "i2c2_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_2_LPCG, 16, 0, },
7208972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C2_CLK, "i2c2_lpcg_clk", "i2c2_clk", 0, ADMA_LPI2C_2_LPCG, 0, 0, },
7308972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C3_IPG_CLK, "i2c3_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_3_LPCG, 16, 0, },
7408972760SAisheng Dong 	{ IMX_ADMA_LPCG_I2C3_CLK, "i2c3_lpcg_clk", "i2c3_clk", 0, ADMA_LPI2C_3_LPCG, 0, 0, },
756ad7cb71SDaniel Baluta 
766ad7cb71SDaniel Baluta 	{ IMX_ADMA_LPCG_DSP_CORE_CLK, "dsp_lpcg_core_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 28, 0, },
776ad7cb71SDaniel Baluta 	{ IMX_ADMA_LPCG_DSP_IPG_CLK, "dsp_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 20, 0, },
786ad7cb71SDaniel Baluta 	{ IMX_ADMA_LPCG_DSP_ADB_CLK, "dsp_lpcg_adb_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 16, 0, },
796ad7cb71SDaniel Baluta 	{ IMX_ADMA_LPCG_OCRAM_IPG_CLK, "ocram_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_OCRAM_LPCG, 16, 0, },
801e3121bfSAisheng Dong };
811e3121bfSAisheng Dong 
821e3121bfSAisheng Dong static const struct imx8qxp_ss_lpcg imx8qxp_ss_adma = {
831e3121bfSAisheng Dong 	.lpcg = imx8qxp_lpcg_adma,
841e3121bfSAisheng Dong 	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_adma),
8508972760SAisheng Dong 	.num_max = IMX_ADMA_LPCG_CLK_END,
861e3121bfSAisheng Dong };
871e3121bfSAisheng Dong 
881e3121bfSAisheng Dong static const struct imx8qxp_lpcg_data imx8qxp_lpcg_conn[] = {
8908972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC0_PER_CLK, "sdhc0_lpcg_per_clk", "sdhc0_clk", 0, CONN_USDHC_0_LPCG, 0, 0, },
9008972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC0_IPG_CLK, "sdhc0_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_0_LPCG, 16, 0, },
9108972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC0_HCLK, "sdhc0_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_0_LPCG, 20, 0, },
9208972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC1_PER_CLK, "sdhc1_lpcg_per_clk", "sdhc1_clk", 0, CONN_USDHC_1_LPCG, 0, 0, },
9308972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC1_IPG_CLK, "sdhc1_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_1_LPCG, 16, 0, },
9408972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC1_HCLK, "sdhc1_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_1_LPCG, 20, 0, },
9508972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC2_PER_CLK, "sdhc2_lpcg_per_clk", "sdhc2_clk", 0, CONN_USDHC_2_LPCG, 0, 0, },
9608972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC2_IPG_CLK, "sdhc2_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_2_LPCG, 16, 0, },
9708972760SAisheng Dong 	{ IMX_CONN_LPCG_SDHC2_HCLK, "sdhc2_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_2_LPCG, 20, 0, },
9808972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET0_ROOT_CLK, "enet0_ipg_root_clk", "enet0_clk", 0, CONN_ENET_0_LPCG, 0, 0, },
9908972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET0_TX_CLK, "enet0_tx_clk", "enet0_clk", 0, CONN_ENET_0_LPCG, 4, 0, },
10008972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET0_AHB_CLK, "enet0_ahb_clk", "conn_axi_clk_root", 0, CONN_ENET_0_LPCG, 8, 0, },
10108972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET0_IPG_S_CLK, "enet0_ipg_s_clk", "conn_ipg_clk_root", 0, CONN_ENET_0_LPCG, 20, 0, },
10208972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET0_IPG_CLK, "enet0_ipg_clk", "enet0_ipg_s_clk", 0, CONN_ENET_0_LPCG, 16, 0, },
10308972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET1_ROOT_CLK, "enet1_ipg_root_clk", "enet1_clk", 0, CONN_ENET_1_LPCG, 0, 0, },
10408972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET1_TX_CLK, "enet1_tx_clk", "enet1_clk", 0, CONN_ENET_1_LPCG, 4, 0, },
10508972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET1_AHB_CLK, "enet1_ahb_clk", "conn_axi_clk_root", 0, CONN_ENET_1_LPCG, 8, 0, },
10608972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET1_IPG_S_CLK, "enet1_ipg_s_clk", "conn_ipg_clk_root", 0, CONN_ENET_1_LPCG, 20, 0, },
10708972760SAisheng Dong 	{ IMX_CONN_LPCG_ENET1_IPG_CLK, "enet1_ipg_clk", "enet0_ipg_s_clk", 0, CONN_ENET_1_LPCG, 16, 0, },
1081e3121bfSAisheng Dong };
1091e3121bfSAisheng Dong 
1101e3121bfSAisheng Dong static const struct imx8qxp_ss_lpcg imx8qxp_ss_conn = {
1111e3121bfSAisheng Dong 	.lpcg = imx8qxp_lpcg_conn,
1121e3121bfSAisheng Dong 	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_conn),
11308972760SAisheng Dong 	.num_max = IMX_CONN_LPCG_CLK_END,
1141e3121bfSAisheng Dong };
1151e3121bfSAisheng Dong 
1161e3121bfSAisheng Dong static const struct imx8qxp_lpcg_data imx8qxp_lpcg_lsio[] = {
11708972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM0_IPG_CLK, "pwm0_lpcg_ipg_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 0, 0, },
11808972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM0_IPG_HF_CLK, "pwm0_lpcg_ipg_hf_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 4, 0, },
11908972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM0_IPG_S_CLK, "pwm0_lpcg_ipg_s_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 16, 0, },
12008972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM0_IPG_SLV_CLK, "pwm0_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_0_LPCG, 20, 0, },
12108972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM0_IPG_MSTR_CLK, "pwm0_lpcg_ipg_mstr_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 24, 0, },
12208972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM1_IPG_CLK, "pwm1_lpcg_ipg_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 0, 0, },
12308972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM1_IPG_HF_CLK, "pwm1_lpcg_ipg_hf_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 4, 0, },
12408972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM1_IPG_S_CLK, "pwm1_lpcg_ipg_s_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 16, 0, },
12508972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM1_IPG_SLV_CLK, "pwm1_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_1_LPCG, 20, 0, },
12608972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM1_IPG_MSTR_CLK, "pwm1_lpcg_ipg_mstr_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 24, 0, },
12708972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM2_IPG_CLK, "pwm2_lpcg_ipg_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 0, 0, },
12808972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM2_IPG_HF_CLK, "pwm2_lpcg_ipg_hf_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 4, 0, },
12908972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM2_IPG_S_CLK, "pwm2_lpcg_ipg_s_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 16, 0, },
13008972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM2_IPG_SLV_CLK, "pwm2_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_2_LPCG, 20, 0, },
13108972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM2_IPG_MSTR_CLK, "pwm2_lpcg_ipg_mstr_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 24, 0, },
13208972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM3_IPG_CLK, "pwm3_lpcg_ipg_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 0, 0, },
13308972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM3_IPG_HF_CLK, "pwm3_lpcg_ipg_hf_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 4, 0, },
13408972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM3_IPG_S_CLK, "pwm3_lpcg_ipg_s_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 16, 0, },
13508972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM3_IPG_SLV_CLK, "pwm3_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_3_LPCG, 20, 0, },
13608972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM3_IPG_MSTR_CLK, "pwm3_lpcg_ipg_mstr_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 24, 0, },
13708972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM4_IPG_CLK, "pwm4_lpcg_ipg_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 0, 0, },
13808972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM4_IPG_HF_CLK, "pwm4_lpcg_ipg_hf_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 4, 0, },
13908972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM4_IPG_S_CLK, "pwm4_lpcg_ipg_s_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 16, 0, },
14008972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM4_IPG_SLV_CLK, "pwm4_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_4_LPCG, 20, 0, },
14108972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM4_IPG_MSTR_CLK, "pwm4_lpcg_ipg_mstr_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 24, 0, },
14208972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM5_IPG_CLK, "pwm5_lpcg_ipg_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 0, 0, },
14308972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM5_IPG_HF_CLK, "pwm5_lpcg_ipg_hf_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 4, 0, },
14408972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM5_IPG_S_CLK, "pwm5_lpcg_ipg_s_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 16, 0, },
14508972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM5_IPG_SLV_CLK, "pwm5_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_5_LPCG, 20, 0, },
14608972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM5_IPG_MSTR_CLK, "pwm5_lpcg_ipg_mstr_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 24, 0, },
14708972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM6_IPG_CLK, "pwm6_lpcg_ipg_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 0, 0, },
14808972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM6_IPG_HF_CLK, "pwm6_lpcg_ipg_hf_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 4, 0, },
14908972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM6_IPG_S_CLK, "pwm6_lpcg_ipg_s_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 16, 0, },
15008972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM6_IPG_SLV_CLK, "pwm6_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_6_LPCG, 20, 0, },
15108972760SAisheng Dong 	{ IMX_LSIO_LPCG_PWM6_IPG_MSTR_CLK, "pwm6_lpcg_ipg_mstr_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 24, 0, },
1521e3121bfSAisheng Dong };
1531e3121bfSAisheng Dong 
1541e3121bfSAisheng Dong static const struct imx8qxp_ss_lpcg imx8qxp_ss_lsio = {
1551e3121bfSAisheng Dong 	.lpcg = imx8qxp_lpcg_lsio,
1561e3121bfSAisheng Dong 	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_lsio),
15708972760SAisheng Dong 	.num_max = IMX_LSIO_LPCG_CLK_END,
1581e3121bfSAisheng Dong };
1591e3121bfSAisheng Dong 
1601e3121bfSAisheng Dong static int imx8qxp_lpcg_clk_probe(struct platform_device *pdev)
1611e3121bfSAisheng Dong {
1621e3121bfSAisheng Dong 	struct device *dev = &pdev->dev;
1631e3121bfSAisheng Dong 	struct device_node *np = dev->of_node;
1641e3121bfSAisheng Dong 	struct clk_hw_onecell_data *clk_data;
1651e3121bfSAisheng Dong 	const struct imx8qxp_ss_lpcg *ss_lpcg;
1661e3121bfSAisheng Dong 	const struct imx8qxp_lpcg_data *lpcg;
1671e3121bfSAisheng Dong 	struct resource *res;
1681e3121bfSAisheng Dong 	struct clk_hw **clks;
1691e3121bfSAisheng Dong 	void __iomem *base;
1701e3121bfSAisheng Dong 	int i;
1711e3121bfSAisheng Dong 
1721e3121bfSAisheng Dong 	ss_lpcg = of_device_get_match_data(dev);
1731e3121bfSAisheng Dong 	if (!ss_lpcg)
1741e3121bfSAisheng Dong 		return -ENODEV;
1751e3121bfSAisheng Dong 
176249fce6fSLeonard Crestez 	/*
177249fce6fSLeonard Crestez 	 * Please don't replace this with devm_platform_ioremap_resource.
178249fce6fSLeonard Crestez 	 *
179249fce6fSLeonard Crestez 	 * devm_platform_ioremap_resource calls devm_ioremap_resource which
180249fce6fSLeonard Crestez 	 * differs from devm_ioremap by also calling devm_request_mem_region
181249fce6fSLeonard Crestez 	 * and preventing other mappings in the same area.
182249fce6fSLeonard Crestez 	 *
183249fce6fSLeonard Crestez 	 * On imx8 the LPCG nodes map entire subsystems and overlap
184249fce6fSLeonard Crestez 	 * peripherals, this means that using devm_platform_ioremap_resource
185249fce6fSLeonard Crestez 	 * will cause many devices to fail to probe including serial ports.
186249fce6fSLeonard Crestez 	 */
1871e3121bfSAisheng Dong 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
18848504619SWei Yongjun 	if (!res)
18948504619SWei Yongjun 		return -EINVAL;
1901e3121bfSAisheng Dong 	base = devm_ioremap(dev, res->start, resource_size(res));
1911e3121bfSAisheng Dong 	if (!base)
1921e3121bfSAisheng Dong 		return -ENOMEM;
1931e3121bfSAisheng Dong 
1941e3121bfSAisheng Dong 	clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hws,
1951e3121bfSAisheng Dong 				ss_lpcg->num_max), GFP_KERNEL);
1961e3121bfSAisheng Dong 	if (!clk_data)
1971e3121bfSAisheng Dong 		return -ENOMEM;
1981e3121bfSAisheng Dong 
1991e3121bfSAisheng Dong 	clk_data->num = ss_lpcg->num_max;
2001e3121bfSAisheng Dong 	clks = clk_data->hws;
2011e3121bfSAisheng Dong 
2021e3121bfSAisheng Dong 	for (i = 0; i < ss_lpcg->num_lpcg; i++) {
2031e3121bfSAisheng Dong 		lpcg = ss_lpcg->lpcg + i;
2041e3121bfSAisheng Dong 		clks[lpcg->id] = imx_clk_lpcg_scu(lpcg->name, lpcg->parent,
2051e3121bfSAisheng Dong 						  lpcg->flags, base + lpcg->offset,
2061e3121bfSAisheng Dong 						  lpcg->bit_idx, lpcg->hw_gate);
2071e3121bfSAisheng Dong 	}
2081e3121bfSAisheng Dong 
2091e3121bfSAisheng Dong 	for (i = 0; i < clk_data->num; i++) {
2101e3121bfSAisheng Dong 		if (IS_ERR(clks[i]))
2111e3121bfSAisheng Dong 			pr_warn("i.MX clk %u: register failed with %ld\n",
2121e3121bfSAisheng Dong 				i, PTR_ERR(clks[i]));
2131e3121bfSAisheng Dong 	}
2141e3121bfSAisheng Dong 
2151e3121bfSAisheng Dong 	return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
2161e3121bfSAisheng Dong }
2171e3121bfSAisheng Dong 
2181e3121bfSAisheng Dong static const struct of_device_id imx8qxp_lpcg_match[] = {
2191e3121bfSAisheng Dong 	{ .compatible = "fsl,imx8qxp-lpcg-adma", &imx8qxp_ss_adma, },
2201e3121bfSAisheng Dong 	{ .compatible = "fsl,imx8qxp-lpcg-conn", &imx8qxp_ss_conn, },
2211e3121bfSAisheng Dong 	{ .compatible = "fsl,imx8qxp-lpcg-lsio", &imx8qxp_ss_lsio, },
2221e3121bfSAisheng Dong 	{ /* sentinel */ }
2231e3121bfSAisheng Dong };
2241e3121bfSAisheng Dong 
2251e3121bfSAisheng Dong static struct platform_driver imx8qxp_lpcg_clk_driver = {
2261e3121bfSAisheng Dong 	.driver = {
2271e3121bfSAisheng Dong 		.name = "imx8qxp-lpcg-clk",
2281e3121bfSAisheng Dong 		.of_match_table = imx8qxp_lpcg_match,
2291e3121bfSAisheng Dong 		.suppress_bind_attrs = true,
2301e3121bfSAisheng Dong 	},
2311e3121bfSAisheng Dong 	.probe = imx8qxp_lpcg_clk_probe,
2321e3121bfSAisheng Dong };
2331e3121bfSAisheng Dong 
2341e3121bfSAisheng Dong builtin_platform_driver(imx8qxp_lpcg_clk_driver);
235*e0d0d4d8SAnson Huang 
236*e0d0d4d8SAnson Huang MODULE_AUTHOR("Aisheng Dong <aisheng.dong@nxp.com>");
237*e0d0d4d8SAnson Huang MODULE_DESCRIPTION("NXP i.MX8QXP LPCG clock driver");
238*e0d0d4d8SAnson Huang MODULE_LICENSE("GPL v2");
239