18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2018 NXP
48c2ecf20Sopenharmony_ci *	Dong Aisheng <aisheng.dong@nxp.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
88c2ecf20Sopenharmony_ci#include <linux/err.h>
98c2ecf20Sopenharmony_ci#include <linux/io.h>
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/of.h>
128c2ecf20Sopenharmony_ci#include <linux/of_device.h>
138c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
148c2ecf20Sopenharmony_ci#include <linux/slab.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "clk-scu.h"
178c2ecf20Sopenharmony_ci#include "clk-imx8qxp-lpcg.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <dt-bindings/clock/imx8-clock.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * struct imx8qxp_lpcg_data - Description of one LPCG clock
238c2ecf20Sopenharmony_ci * @id: clock ID
248c2ecf20Sopenharmony_ci * @name: clock name
258c2ecf20Sopenharmony_ci * @parent: parent clock name
268c2ecf20Sopenharmony_ci * @flags: common clock flags
278c2ecf20Sopenharmony_ci * @offset: offset of this LPCG clock
288c2ecf20Sopenharmony_ci * @bit_idx: bit index of this LPCG clock
298c2ecf20Sopenharmony_ci * @hw_gate: whether supports HW autogate
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * This structure describes one LPCG clock
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_cistruct imx8qxp_lpcg_data {
348c2ecf20Sopenharmony_ci	int id;
358c2ecf20Sopenharmony_ci	char *name;
368c2ecf20Sopenharmony_ci	char *parent;
378c2ecf20Sopenharmony_ci	unsigned long flags;
388c2ecf20Sopenharmony_ci	u32 offset;
398c2ecf20Sopenharmony_ci	u8 bit_idx;
408c2ecf20Sopenharmony_ci	bool hw_gate;
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * struct imx8qxp_ss_lpcg - Description of one subsystem LPCG clocks
458c2ecf20Sopenharmony_ci * @lpcg: LPCG clocks array of one subsystem
468c2ecf20Sopenharmony_ci * @num_lpcg: the number of LPCG clocks
478c2ecf20Sopenharmony_ci * @num_max: the maximum number of LPCG clocks
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * This structure describes each subsystem LPCG clocks information
508c2ecf20Sopenharmony_ci * which then will be used to create respective LPCGs clocks
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_cistruct imx8qxp_ss_lpcg {
538c2ecf20Sopenharmony_ci	const struct imx8qxp_lpcg_data *lpcg;
548c2ecf20Sopenharmony_ci	u8 num_lpcg;
558c2ecf20Sopenharmony_ci	u8 num_max;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic const struct imx8qxp_lpcg_data imx8qxp_lpcg_adma[] = {
598c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART0_IPG_CLK, "uart0_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_0_LPCG, 16, 0, },
608c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART0_BAUD_CLK, "uart0_lpcg_baud_clk", "uart0_clk", 0, ADMA_LPUART_0_LPCG, 0, 0, },
618c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART1_IPG_CLK, "uart1_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_1_LPCG, 16, 0, },
628c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART1_BAUD_CLK, "uart1_lpcg_baud_clk", "uart1_clk", 0, ADMA_LPUART_1_LPCG, 0, 0, },
638c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART2_IPG_CLK, "uart2_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_2_LPCG, 16, 0, },
648c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART2_BAUD_CLK, "uart2_lpcg_baud_clk", "uart2_clk", 0, ADMA_LPUART_2_LPCG, 0, 0, },
658c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART3_IPG_CLK, "uart3_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPUART_3_LPCG, 16, 0, },
668c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_UART3_BAUD_CLK, "uart3_lpcg_baud_clk", "uart3_clk", 0, ADMA_LPUART_3_LPCG, 0, 0, },
678c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C0_IPG_CLK, "i2c0_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_0_LPCG, 16, 0, },
688c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C0_CLK, "i2c0_lpcg_clk", "i2c0_clk", 0, ADMA_LPI2C_0_LPCG, 0, 0, },
698c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C1_IPG_CLK, "i2c1_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_1_LPCG, 16, 0, },
708c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C1_CLK, "i2c1_lpcg_clk", "i2c1_clk", 0, ADMA_LPI2C_1_LPCG, 0, 0, },
718c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C2_IPG_CLK, "i2c2_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_2_LPCG, 16, 0, },
728c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C2_CLK, "i2c2_lpcg_clk", "i2c2_clk", 0, ADMA_LPI2C_2_LPCG, 0, 0, },
738c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C3_IPG_CLK, "i2c3_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_LPI2C_3_LPCG, 16, 0, },
748c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_I2C3_CLK, "i2c3_lpcg_clk", "i2c3_clk", 0, ADMA_LPI2C_3_LPCG, 0, 0, },
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_DSP_CORE_CLK, "dsp_lpcg_core_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 28, 0, },
778c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_DSP_IPG_CLK, "dsp_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 20, 0, },
788c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_DSP_ADB_CLK, "dsp_lpcg_adb_clk", "dma_ipg_clk_root", 0, ADMA_HIFI_LPCG, 16, 0, },
798c2ecf20Sopenharmony_ci	{ IMX_ADMA_LPCG_OCRAM_IPG_CLK, "ocram_lpcg_ipg_clk", "dma_ipg_clk_root", 0, ADMA_OCRAM_LPCG, 16, 0, },
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic const struct imx8qxp_ss_lpcg imx8qxp_ss_adma = {
838c2ecf20Sopenharmony_ci	.lpcg = imx8qxp_lpcg_adma,
848c2ecf20Sopenharmony_ci	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_adma),
858c2ecf20Sopenharmony_ci	.num_max = IMX_ADMA_LPCG_CLK_END,
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic const struct imx8qxp_lpcg_data imx8qxp_lpcg_conn[] = {
898c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC0_PER_CLK, "sdhc0_lpcg_per_clk", "sdhc0_clk", 0, CONN_USDHC_0_LPCG, 0, 0, },
908c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC0_IPG_CLK, "sdhc0_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_0_LPCG, 16, 0, },
918c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC0_HCLK, "sdhc0_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_0_LPCG, 20, 0, },
928c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC1_PER_CLK, "sdhc1_lpcg_per_clk", "sdhc1_clk", 0, CONN_USDHC_1_LPCG, 0, 0, },
938c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC1_IPG_CLK, "sdhc1_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_1_LPCG, 16, 0, },
948c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC1_HCLK, "sdhc1_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_1_LPCG, 20, 0, },
958c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC2_PER_CLK, "sdhc2_lpcg_per_clk", "sdhc2_clk", 0, CONN_USDHC_2_LPCG, 0, 0, },
968c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC2_IPG_CLK, "sdhc2_lpcg_ipg_clk", "conn_ipg_clk_root", 0, CONN_USDHC_2_LPCG, 16, 0, },
978c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_SDHC2_HCLK, "sdhc2_lpcg_ahb_clk", "conn_axi_clk_root", 0, CONN_USDHC_2_LPCG, 20, 0, },
988c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET0_ROOT_CLK, "enet0_ipg_root_clk", "enet0_clk", 0, CONN_ENET_0_LPCG, 0, 0, },
998c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET0_TX_CLK, "enet0_tx_clk", "enet0_clk", 0, CONN_ENET_0_LPCG, 4, 0, },
1008c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET0_AHB_CLK, "enet0_ahb_clk", "conn_axi_clk_root", 0, CONN_ENET_0_LPCG, 8, 0, },
1018c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET0_IPG_S_CLK, "enet0_ipg_s_clk", "conn_ipg_clk_root", 0, CONN_ENET_0_LPCG, 20, 0, },
1028c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET0_IPG_CLK, "enet0_ipg_clk", "enet0_ipg_s_clk", 0, CONN_ENET_0_LPCG, 16, 0, },
1038c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET1_ROOT_CLK, "enet1_ipg_root_clk", "enet1_clk", 0, CONN_ENET_1_LPCG, 0, 0, },
1048c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET1_TX_CLK, "enet1_tx_clk", "enet1_clk", 0, CONN_ENET_1_LPCG, 4, 0, },
1058c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET1_AHB_CLK, "enet1_ahb_clk", "conn_axi_clk_root", 0, CONN_ENET_1_LPCG, 8, 0, },
1068c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET1_IPG_S_CLK, "enet1_ipg_s_clk", "conn_ipg_clk_root", 0, CONN_ENET_1_LPCG, 20, 0, },
1078c2ecf20Sopenharmony_ci	{ IMX_CONN_LPCG_ENET1_IPG_CLK, "enet1_ipg_clk", "enet0_ipg_s_clk", 0, CONN_ENET_1_LPCG, 16, 0, },
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic const struct imx8qxp_ss_lpcg imx8qxp_ss_conn = {
1118c2ecf20Sopenharmony_ci	.lpcg = imx8qxp_lpcg_conn,
1128c2ecf20Sopenharmony_ci	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_conn),
1138c2ecf20Sopenharmony_ci	.num_max = IMX_CONN_LPCG_CLK_END,
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic const struct imx8qxp_lpcg_data imx8qxp_lpcg_lsio[] = {
1178c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM0_IPG_CLK, "pwm0_lpcg_ipg_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 0, 0, },
1188c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM0_IPG_HF_CLK, "pwm0_lpcg_ipg_hf_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 4, 0, },
1198c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM0_IPG_S_CLK, "pwm0_lpcg_ipg_s_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 16, 0, },
1208c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM0_IPG_SLV_CLK, "pwm0_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_0_LPCG, 20, 0, },
1218c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM0_IPG_MSTR_CLK, "pwm0_lpcg_ipg_mstr_clk", "pwm0_clk", 0, LSIO_PWM_0_LPCG, 24, 0, },
1228c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM1_IPG_CLK, "pwm1_lpcg_ipg_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 0, 0, },
1238c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM1_IPG_HF_CLK, "pwm1_lpcg_ipg_hf_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 4, 0, },
1248c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM1_IPG_S_CLK, "pwm1_lpcg_ipg_s_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 16, 0, },
1258c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM1_IPG_SLV_CLK, "pwm1_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_1_LPCG, 20, 0, },
1268c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM1_IPG_MSTR_CLK, "pwm1_lpcg_ipg_mstr_clk", "pwm1_clk", 0, LSIO_PWM_1_LPCG, 24, 0, },
1278c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM2_IPG_CLK, "pwm2_lpcg_ipg_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 0, 0, },
1288c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM2_IPG_HF_CLK, "pwm2_lpcg_ipg_hf_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 4, 0, },
1298c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM2_IPG_S_CLK, "pwm2_lpcg_ipg_s_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 16, 0, },
1308c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM2_IPG_SLV_CLK, "pwm2_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_2_LPCG, 20, 0, },
1318c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM2_IPG_MSTR_CLK, "pwm2_lpcg_ipg_mstr_clk", "pwm2_clk", 0, LSIO_PWM_2_LPCG, 24, 0, },
1328c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM3_IPG_CLK, "pwm3_lpcg_ipg_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 0, 0, },
1338c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM3_IPG_HF_CLK, "pwm3_lpcg_ipg_hf_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 4, 0, },
1348c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM3_IPG_S_CLK, "pwm3_lpcg_ipg_s_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 16, 0, },
1358c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM3_IPG_SLV_CLK, "pwm3_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_3_LPCG, 20, 0, },
1368c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM3_IPG_MSTR_CLK, "pwm3_lpcg_ipg_mstr_clk", "pwm3_clk", 0, LSIO_PWM_3_LPCG, 24, 0, },
1378c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM4_IPG_CLK, "pwm4_lpcg_ipg_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 0, 0, },
1388c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM4_IPG_HF_CLK, "pwm4_lpcg_ipg_hf_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 4, 0, },
1398c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM4_IPG_S_CLK, "pwm4_lpcg_ipg_s_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 16, 0, },
1408c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM4_IPG_SLV_CLK, "pwm4_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_4_LPCG, 20, 0, },
1418c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM4_IPG_MSTR_CLK, "pwm4_lpcg_ipg_mstr_clk", "pwm4_clk", 0, LSIO_PWM_4_LPCG, 24, 0, },
1428c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM5_IPG_CLK, "pwm5_lpcg_ipg_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 0, 0, },
1438c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM5_IPG_HF_CLK, "pwm5_lpcg_ipg_hf_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 4, 0, },
1448c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM5_IPG_S_CLK, "pwm5_lpcg_ipg_s_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 16, 0, },
1458c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM5_IPG_SLV_CLK, "pwm5_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_5_LPCG, 20, 0, },
1468c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM5_IPG_MSTR_CLK, "pwm5_lpcg_ipg_mstr_clk", "pwm5_clk", 0, LSIO_PWM_5_LPCG, 24, 0, },
1478c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM6_IPG_CLK, "pwm6_lpcg_ipg_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 0, 0, },
1488c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM6_IPG_HF_CLK, "pwm6_lpcg_ipg_hf_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 4, 0, },
1498c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM6_IPG_S_CLK, "pwm6_lpcg_ipg_s_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 16, 0, },
1508c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM6_IPG_SLV_CLK, "pwm6_lpcg_ipg_slv_clk", "lsio_bus_clk_root", 0, LSIO_PWM_6_LPCG, 20, 0, },
1518c2ecf20Sopenharmony_ci	{ IMX_LSIO_LPCG_PWM6_IPG_MSTR_CLK, "pwm6_lpcg_ipg_mstr_clk", "pwm6_clk", 0, LSIO_PWM_6_LPCG, 24, 0, },
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic const struct imx8qxp_ss_lpcg imx8qxp_ss_lsio = {
1558c2ecf20Sopenharmony_ci	.lpcg = imx8qxp_lpcg_lsio,
1568c2ecf20Sopenharmony_ci	.num_lpcg = ARRAY_SIZE(imx8qxp_lpcg_lsio),
1578c2ecf20Sopenharmony_ci	.num_max = IMX_LSIO_LPCG_CLK_END,
1588c2ecf20Sopenharmony_ci};
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic int imx8qxp_lpcg_clk_probe(struct platform_device *pdev)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
1638c2ecf20Sopenharmony_ci	struct device_node *np = dev->of_node;
1648c2ecf20Sopenharmony_ci	struct clk_hw_onecell_data *clk_data;
1658c2ecf20Sopenharmony_ci	const struct imx8qxp_ss_lpcg *ss_lpcg;
1668c2ecf20Sopenharmony_ci	const struct imx8qxp_lpcg_data *lpcg;
1678c2ecf20Sopenharmony_ci	struct resource *res;
1688c2ecf20Sopenharmony_ci	struct clk_hw **clks;
1698c2ecf20Sopenharmony_ci	void __iomem *base;
1708c2ecf20Sopenharmony_ci	int i;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	ss_lpcg = of_device_get_match_data(dev);
1738c2ecf20Sopenharmony_ci	if (!ss_lpcg)
1748c2ecf20Sopenharmony_ci		return -ENODEV;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	/*
1778c2ecf20Sopenharmony_ci	 * Please don't replace this with devm_platform_ioremap_resource.
1788c2ecf20Sopenharmony_ci	 *
1798c2ecf20Sopenharmony_ci	 * devm_platform_ioremap_resource calls devm_ioremap_resource which
1808c2ecf20Sopenharmony_ci	 * differs from devm_ioremap by also calling devm_request_mem_region
1818c2ecf20Sopenharmony_ci	 * and preventing other mappings in the same area.
1828c2ecf20Sopenharmony_ci	 *
1838c2ecf20Sopenharmony_ci	 * On imx8 the LPCG nodes map entire subsystems and overlap
1848c2ecf20Sopenharmony_ci	 * peripherals, this means that using devm_platform_ioremap_resource
1858c2ecf20Sopenharmony_ci	 * will cause many devices to fail to probe including serial ports.
1868c2ecf20Sopenharmony_ci	 */
1878c2ecf20Sopenharmony_ci	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1888c2ecf20Sopenharmony_ci	if (!res)
1898c2ecf20Sopenharmony_ci		return -EINVAL;
1908c2ecf20Sopenharmony_ci	base = devm_ioremap(dev, res->start, resource_size(res));
1918c2ecf20Sopenharmony_ci	if (!base)
1928c2ecf20Sopenharmony_ci		return -ENOMEM;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	clk_data = devm_kzalloc(&pdev->dev, struct_size(clk_data, hws,
1958c2ecf20Sopenharmony_ci				ss_lpcg->num_max), GFP_KERNEL);
1968c2ecf20Sopenharmony_ci	if (!clk_data)
1978c2ecf20Sopenharmony_ci		return -ENOMEM;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	clk_data->num = ss_lpcg->num_max;
2008c2ecf20Sopenharmony_ci	clks = clk_data->hws;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	for (i = 0; i < ss_lpcg->num_lpcg; i++) {
2038c2ecf20Sopenharmony_ci		lpcg = ss_lpcg->lpcg + i;
2048c2ecf20Sopenharmony_ci		clks[lpcg->id] = imx_clk_lpcg_scu(lpcg->name, lpcg->parent,
2058c2ecf20Sopenharmony_ci						  lpcg->flags, base + lpcg->offset,
2068c2ecf20Sopenharmony_ci						  lpcg->bit_idx, lpcg->hw_gate);
2078c2ecf20Sopenharmony_ci	}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	for (i = 0; i < clk_data->num; i++) {
2108c2ecf20Sopenharmony_ci		if (IS_ERR(clks[i]))
2118c2ecf20Sopenharmony_ci			pr_warn("i.MX clk %u: register failed with %ld\n",
2128c2ecf20Sopenharmony_ci				i, PTR_ERR(clks[i]));
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistatic const struct of_device_id imx8qxp_lpcg_match[] = {
2198c2ecf20Sopenharmony_ci	{ .compatible = "fsl,imx8qxp-lpcg-adma", &imx8qxp_ss_adma, },
2208c2ecf20Sopenharmony_ci	{ .compatible = "fsl,imx8qxp-lpcg-conn", &imx8qxp_ss_conn, },
2218c2ecf20Sopenharmony_ci	{ .compatible = "fsl,imx8qxp-lpcg-lsio", &imx8qxp_ss_lsio, },
2228c2ecf20Sopenharmony_ci	{ /* sentinel */ }
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic struct platform_driver imx8qxp_lpcg_clk_driver = {
2268c2ecf20Sopenharmony_ci	.driver = {
2278c2ecf20Sopenharmony_ci		.name = "imx8qxp-lpcg-clk",
2288c2ecf20Sopenharmony_ci		.of_match_table = imx8qxp_lpcg_match,
2298c2ecf20Sopenharmony_ci		.suppress_bind_attrs = true,
2308c2ecf20Sopenharmony_ci	},
2318c2ecf20Sopenharmony_ci	.probe = imx8qxp_lpcg_clk_probe,
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cimodule_platform_driver(imx8qxp_lpcg_clk_driver);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ciMODULE_AUTHOR("Aisheng Dong <aisheng.dong@nxp.com>");
2378c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NXP i.MX8QXP LPCG clock driver");
2388c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
239