18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
48c2ecf20Sopenharmony_ci#include <linux/init.h>
58c2ecf20Sopenharmony_ci#include <linux/of.h>
68c2ecf20Sopenharmony_ci#include <linux/of_device.h>
78c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm3368-clock.h>
108c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm6318-clock.h>
118c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm6328-clock.h>
128c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm6358-clock.h>
138c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm6362-clock.h>
148c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm6368-clock.h>
158c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm63268-clock.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct clk_bcm63xx_table_entry {
188c2ecf20Sopenharmony_ci	const char * const name;
198c2ecf20Sopenharmony_ci	u8 bit;
208c2ecf20Sopenharmony_ci	unsigned long flags;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct clk_bcm63xx_hw {
248c2ecf20Sopenharmony_ci	void __iomem *regs;
258c2ecf20Sopenharmony_ci	spinlock_t lock;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	struct clk_hw_onecell_data data;
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm3368_clocks[] = {
318c2ecf20Sopenharmony_ci	{
328c2ecf20Sopenharmony_ci		.name = "mac",
338c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_MAC,
348c2ecf20Sopenharmony_ci	}, {
358c2ecf20Sopenharmony_ci		.name = "tc",
368c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_TC,
378c2ecf20Sopenharmony_ci	}, {
388c2ecf20Sopenharmony_ci		.name = "us_top",
398c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_US_TOP,
408c2ecf20Sopenharmony_ci	}, {
418c2ecf20Sopenharmony_ci		.name = "ds_top",
428c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_DS_TOP,
438c2ecf20Sopenharmony_ci	}, {
448c2ecf20Sopenharmony_ci		.name = "acm",
458c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_ACM,
468c2ecf20Sopenharmony_ci	}, {
478c2ecf20Sopenharmony_ci		.name = "spi",
488c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_SPI,
498c2ecf20Sopenharmony_ci	}, {
508c2ecf20Sopenharmony_ci		.name = "usbs",
518c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_USBS,
528c2ecf20Sopenharmony_ci	}, {
538c2ecf20Sopenharmony_ci		.name = "bmu",
548c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_BMU,
558c2ecf20Sopenharmony_ci	}, {
568c2ecf20Sopenharmony_ci		.name = "pcm",
578c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_PCM,
588c2ecf20Sopenharmony_ci	}, {
598c2ecf20Sopenharmony_ci		.name = "ntp",
608c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_NTP,
618c2ecf20Sopenharmony_ci	}, {
628c2ecf20Sopenharmony_ci		.name = "acp_b",
638c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_ACP_B,
648c2ecf20Sopenharmony_ci	}, {
658c2ecf20Sopenharmony_ci		.name = "acp_a",
668c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_ACP_A,
678c2ecf20Sopenharmony_ci	}, {
688c2ecf20Sopenharmony_ci		.name = "emusb",
698c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_EMUSB,
708c2ecf20Sopenharmony_ci	}, {
718c2ecf20Sopenharmony_ci		.name = "enet0",
728c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_ENET0,
738c2ecf20Sopenharmony_ci	}, {
748c2ecf20Sopenharmony_ci		.name = "enet1",
758c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_ENET1,
768c2ecf20Sopenharmony_ci	}, {
778c2ecf20Sopenharmony_ci		.name = "usbsu",
788c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_USBSU,
798c2ecf20Sopenharmony_ci	}, {
808c2ecf20Sopenharmony_ci		.name = "ephy",
818c2ecf20Sopenharmony_ci		.bit = BCM3368_CLK_EPHY,
828c2ecf20Sopenharmony_ci	}, {
838c2ecf20Sopenharmony_ci		/* sentinel */
848c2ecf20Sopenharmony_ci	},
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6318_clocks[] = {
888c2ecf20Sopenharmony_ci	{
898c2ecf20Sopenharmony_ci		.name = "adsl_asb",
908c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_ADSL_ASB,
918c2ecf20Sopenharmony_ci	}, {
928c2ecf20Sopenharmony_ci		.name = "usb_asb",
938c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_USB_ASB,
948c2ecf20Sopenharmony_ci	}, {
958c2ecf20Sopenharmony_ci		.name = "mips_asb",
968c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_MIPS_ASB,
978c2ecf20Sopenharmony_ci	}, {
988c2ecf20Sopenharmony_ci		.name = "pcie_asb",
998c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PCIE_ASB,
1008c2ecf20Sopenharmony_ci	}, {
1018c2ecf20Sopenharmony_ci		.name = "phymips_asb",
1028c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PHYMIPS_ASB,
1038c2ecf20Sopenharmony_ci	}, {
1048c2ecf20Sopenharmony_ci		.name = "robosw_asb",
1058c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_ROBOSW_ASB,
1068c2ecf20Sopenharmony_ci	}, {
1078c2ecf20Sopenharmony_ci		.name = "sar_asb",
1088c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_SAR_ASB,
1098c2ecf20Sopenharmony_ci	}, {
1108c2ecf20Sopenharmony_ci		.name = "sdr_asb",
1118c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_SDR_ASB,
1128c2ecf20Sopenharmony_ci	}, {
1138c2ecf20Sopenharmony_ci		.name = "swreg_asb",
1148c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_SWREG_ASB,
1158c2ecf20Sopenharmony_ci	}, {
1168c2ecf20Sopenharmony_ci		.name = "periph_asb",
1178c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PERIPH_ASB,
1188c2ecf20Sopenharmony_ci	}, {
1198c2ecf20Sopenharmony_ci		.name = "cpubus160",
1208c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_CPUBUS160,
1218c2ecf20Sopenharmony_ci	}, {
1228c2ecf20Sopenharmony_ci		.name = "adsl",
1238c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_ADSL,
1248c2ecf20Sopenharmony_ci	}, {
1258c2ecf20Sopenharmony_ci		.name = "sar125",
1268c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_SAR125,
1278c2ecf20Sopenharmony_ci	}, {
1288c2ecf20Sopenharmony_ci		.name = "mips",
1298c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_MIPS,
1308c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
1318c2ecf20Sopenharmony_ci	}, {
1328c2ecf20Sopenharmony_ci		.name = "pcie",
1338c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PCIE,
1348c2ecf20Sopenharmony_ci	}, {
1358c2ecf20Sopenharmony_ci		.name = "robosw250",
1368c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_ROBOSW250,
1378c2ecf20Sopenharmony_ci	}, {
1388c2ecf20Sopenharmony_ci		.name = "robosw025",
1398c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_ROBOSW025,
1408c2ecf20Sopenharmony_ci	}, {
1418c2ecf20Sopenharmony_ci		.name = "sdr",
1428c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_SDR,
1438c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
1448c2ecf20Sopenharmony_ci	}, {
1458c2ecf20Sopenharmony_ci		.name = "usbd",
1468c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_USBD,
1478c2ecf20Sopenharmony_ci	}, {
1488c2ecf20Sopenharmony_ci		.name = "hsspi",
1498c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_HSSPI,
1508c2ecf20Sopenharmony_ci	}, {
1518c2ecf20Sopenharmony_ci		.name = "pcie25",
1528c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PCIE25,
1538c2ecf20Sopenharmony_ci	}, {
1548c2ecf20Sopenharmony_ci		.name = "phymips",
1558c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_PHYMIPS,
1568c2ecf20Sopenharmony_ci	}, {
1578c2ecf20Sopenharmony_ci		.name = "afe",
1588c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_AFE,
1598c2ecf20Sopenharmony_ci	}, {
1608c2ecf20Sopenharmony_ci		.name = "qproc",
1618c2ecf20Sopenharmony_ci		.bit = BCM6318_CLK_QPROC,
1628c2ecf20Sopenharmony_ci	}, {
1638c2ecf20Sopenharmony_ci		/* sentinel */
1648c2ecf20Sopenharmony_ci	},
1658c2ecf20Sopenharmony_ci};
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6318_ubus_clocks[] = {
1688c2ecf20Sopenharmony_ci	{
1698c2ecf20Sopenharmony_ci		.name = "adsl-ubus",
1708c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_ADSL,
1718c2ecf20Sopenharmony_ci	}, {
1728c2ecf20Sopenharmony_ci		.name = "arb-ubus",
1738c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_ARB,
1748c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
1758c2ecf20Sopenharmony_ci	}, {
1768c2ecf20Sopenharmony_ci		.name = "mips-ubus",
1778c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_MIPS,
1788c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
1798c2ecf20Sopenharmony_ci	}, {
1808c2ecf20Sopenharmony_ci		.name = "pcie-ubus",
1818c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_PCIE,
1828c2ecf20Sopenharmony_ci	}, {
1838c2ecf20Sopenharmony_ci		.name = "periph-ubus",
1848c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_PERIPH,
1858c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
1868c2ecf20Sopenharmony_ci	}, {
1878c2ecf20Sopenharmony_ci		.name = "phymips-ubus",
1888c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_PHYMIPS,
1898c2ecf20Sopenharmony_ci	}, {
1908c2ecf20Sopenharmony_ci		.name = "robosw-ubus",
1918c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_ROBOSW,
1928c2ecf20Sopenharmony_ci	}, {
1938c2ecf20Sopenharmony_ci		.name = "sar-ubus",
1948c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_SAR,
1958c2ecf20Sopenharmony_ci	}, {
1968c2ecf20Sopenharmony_ci		.name = "sdr-ubus",
1978c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_SDR,
1988c2ecf20Sopenharmony_ci	}, {
1998c2ecf20Sopenharmony_ci		.name = "usb-ubus",
2008c2ecf20Sopenharmony_ci		.bit = BCM6318_UCLK_USB,
2018c2ecf20Sopenharmony_ci	}, {
2028c2ecf20Sopenharmony_ci		/* sentinel */
2038c2ecf20Sopenharmony_ci	},
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6328_clocks[] = {
2078c2ecf20Sopenharmony_ci	{
2088c2ecf20Sopenharmony_ci		.name = "phy_mips",
2098c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_PHYMIPS,
2108c2ecf20Sopenharmony_ci	}, {
2118c2ecf20Sopenharmony_ci		.name = "adsl_qproc",
2128c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_ADSL_QPROC,
2138c2ecf20Sopenharmony_ci	}, {
2148c2ecf20Sopenharmony_ci		.name = "adsl_afe",
2158c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_ADSL_AFE,
2168c2ecf20Sopenharmony_ci	}, {
2178c2ecf20Sopenharmony_ci		.name = "adsl",
2188c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_ADSL,
2198c2ecf20Sopenharmony_ci	}, {
2208c2ecf20Sopenharmony_ci		.name = "mips",
2218c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_MIPS,
2228c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
2238c2ecf20Sopenharmony_ci	}, {
2248c2ecf20Sopenharmony_ci		.name = "sar",
2258c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_SAR,
2268c2ecf20Sopenharmony_ci	}, {
2278c2ecf20Sopenharmony_ci		.name = "pcm",
2288c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_PCM,
2298c2ecf20Sopenharmony_ci	}, {
2308c2ecf20Sopenharmony_ci		.name = "usbd",
2318c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_USBD,
2328c2ecf20Sopenharmony_ci	}, {
2338c2ecf20Sopenharmony_ci		.name = "usbh",
2348c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_USBH,
2358c2ecf20Sopenharmony_ci	}, {
2368c2ecf20Sopenharmony_ci		.name = "hsspi",
2378c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_HSSPI,
2388c2ecf20Sopenharmony_ci	}, {
2398c2ecf20Sopenharmony_ci		.name = "pcie",
2408c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_PCIE,
2418c2ecf20Sopenharmony_ci	}, {
2428c2ecf20Sopenharmony_ci		.name = "robosw",
2438c2ecf20Sopenharmony_ci		.bit = BCM6328_CLK_ROBOSW,
2448c2ecf20Sopenharmony_ci	}, {
2458c2ecf20Sopenharmony_ci		/* sentinel */
2468c2ecf20Sopenharmony_ci	},
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6358_clocks[] = {
2508c2ecf20Sopenharmony_ci	{
2518c2ecf20Sopenharmony_ci		.name = "enet",
2528c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_ENET,
2538c2ecf20Sopenharmony_ci	}, {
2548c2ecf20Sopenharmony_ci		.name = "adslphy",
2558c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_ADSLPHY,
2568c2ecf20Sopenharmony_ci	}, {
2578c2ecf20Sopenharmony_ci		.name = "pcm",
2588c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_PCM,
2598c2ecf20Sopenharmony_ci	}, {
2608c2ecf20Sopenharmony_ci		.name = "spi",
2618c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_SPI,
2628c2ecf20Sopenharmony_ci	}, {
2638c2ecf20Sopenharmony_ci		.name = "usbs",
2648c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_USBS,
2658c2ecf20Sopenharmony_ci	}, {
2668c2ecf20Sopenharmony_ci		.name = "sar",
2678c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_SAR,
2688c2ecf20Sopenharmony_ci	}, {
2698c2ecf20Sopenharmony_ci		.name = "emusb",
2708c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_EMUSB,
2718c2ecf20Sopenharmony_ci	}, {
2728c2ecf20Sopenharmony_ci		.name = "enet0",
2738c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_ENET0,
2748c2ecf20Sopenharmony_ci	}, {
2758c2ecf20Sopenharmony_ci		.name = "enet1",
2768c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_ENET1,
2778c2ecf20Sopenharmony_ci	}, {
2788c2ecf20Sopenharmony_ci		.name = "usbsu",
2798c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_USBSU,
2808c2ecf20Sopenharmony_ci	}, {
2818c2ecf20Sopenharmony_ci		.name = "ephy",
2828c2ecf20Sopenharmony_ci		.bit = BCM6358_CLK_EPHY,
2838c2ecf20Sopenharmony_ci	}, {
2848c2ecf20Sopenharmony_ci		/* sentinel */
2858c2ecf20Sopenharmony_ci	},
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6362_clocks[] = {
2898c2ecf20Sopenharmony_ci	{
2908c2ecf20Sopenharmony_ci		.name = "adsl_qproc",
2918c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_ADSL_QPROC,
2928c2ecf20Sopenharmony_ci	}, {
2938c2ecf20Sopenharmony_ci		.name = "adsl_afe",
2948c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_ADSL_AFE,
2958c2ecf20Sopenharmony_ci	}, {
2968c2ecf20Sopenharmony_ci		.name = "adsl",
2978c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_ADSL,
2988c2ecf20Sopenharmony_ci	}, {
2998c2ecf20Sopenharmony_ci		.name = "mips",
3008c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_MIPS,
3018c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
3028c2ecf20Sopenharmony_ci	}, {
3038c2ecf20Sopenharmony_ci		.name = "wlan_ocp",
3048c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_WLAN_OCP,
3058c2ecf20Sopenharmony_ci	}, {
3068c2ecf20Sopenharmony_ci		.name = "swpkt_usb",
3078c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_SWPKT_USB,
3088c2ecf20Sopenharmony_ci	}, {
3098c2ecf20Sopenharmony_ci		.name = "swpkt_sar",
3108c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_SWPKT_SAR,
3118c2ecf20Sopenharmony_ci	}, {
3128c2ecf20Sopenharmony_ci		.name = "sar",
3138c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_SAR,
3148c2ecf20Sopenharmony_ci	}, {
3158c2ecf20Sopenharmony_ci		.name = "robosw",
3168c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_ROBOSW,
3178c2ecf20Sopenharmony_ci	}, {
3188c2ecf20Sopenharmony_ci		.name = "pcm",
3198c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_PCM,
3208c2ecf20Sopenharmony_ci	}, {
3218c2ecf20Sopenharmony_ci		.name = "usbd",
3228c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_USBD,
3238c2ecf20Sopenharmony_ci	}, {
3248c2ecf20Sopenharmony_ci		.name = "usbh",
3258c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_USBH,
3268c2ecf20Sopenharmony_ci	}, {
3278c2ecf20Sopenharmony_ci		.name = "ipsec",
3288c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_IPSEC,
3298c2ecf20Sopenharmony_ci	}, {
3308c2ecf20Sopenharmony_ci		.name = "spi",
3318c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_SPI,
3328c2ecf20Sopenharmony_ci	}, {
3338c2ecf20Sopenharmony_ci		.name = "hsspi",
3348c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_HSSPI,
3358c2ecf20Sopenharmony_ci	}, {
3368c2ecf20Sopenharmony_ci		.name = "pcie",
3378c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_PCIE,
3388c2ecf20Sopenharmony_ci	}, {
3398c2ecf20Sopenharmony_ci		.name = "fap",
3408c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_FAP,
3418c2ecf20Sopenharmony_ci	}, {
3428c2ecf20Sopenharmony_ci		.name = "phymips",
3438c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_PHYMIPS,
3448c2ecf20Sopenharmony_ci	}, {
3458c2ecf20Sopenharmony_ci		.name = "nand",
3468c2ecf20Sopenharmony_ci		.bit = BCM6362_CLK_NAND,
3478c2ecf20Sopenharmony_ci	}, {
3488c2ecf20Sopenharmony_ci		/* sentinel */
3498c2ecf20Sopenharmony_ci	},
3508c2ecf20Sopenharmony_ci};
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm6368_clocks[] = {
3538c2ecf20Sopenharmony_ci	{
3548c2ecf20Sopenharmony_ci		.name = "vdsl_qproc",
3558c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_VDSL_QPROC,
3568c2ecf20Sopenharmony_ci	}, {
3578c2ecf20Sopenharmony_ci		.name = "vdsl_afe",
3588c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_VDSL_AFE,
3598c2ecf20Sopenharmony_ci	}, {
3608c2ecf20Sopenharmony_ci		.name = "vdsl_bonding",
3618c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_VDSL_BONDING,
3628c2ecf20Sopenharmony_ci	}, {
3638c2ecf20Sopenharmony_ci		.name = "vdsl",
3648c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_VDSL,
3658c2ecf20Sopenharmony_ci	}, {
3668c2ecf20Sopenharmony_ci		.name = "phymips",
3678c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_PHYMIPS,
3688c2ecf20Sopenharmony_ci	}, {
3698c2ecf20Sopenharmony_ci		.name = "swpkt_usb",
3708c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_SWPKT_USB,
3718c2ecf20Sopenharmony_ci	}, {
3728c2ecf20Sopenharmony_ci		.name = "swpkt_sar",
3738c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_SWPKT_SAR,
3748c2ecf20Sopenharmony_ci	}, {
3758c2ecf20Sopenharmony_ci		.name = "spi",
3768c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_SPI,
3778c2ecf20Sopenharmony_ci	}, {
3788c2ecf20Sopenharmony_ci		.name = "usbd",
3798c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_USBD,
3808c2ecf20Sopenharmony_ci	}, {
3818c2ecf20Sopenharmony_ci		.name = "sar",
3828c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_SAR,
3838c2ecf20Sopenharmony_ci	}, {
3848c2ecf20Sopenharmony_ci		.name = "robosw",
3858c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_ROBOSW,
3868c2ecf20Sopenharmony_ci	}, {
3878c2ecf20Sopenharmony_ci		.name = "utopia",
3888c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_UTOPIA,
3898c2ecf20Sopenharmony_ci	}, {
3908c2ecf20Sopenharmony_ci		.name = "pcm",
3918c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_PCM,
3928c2ecf20Sopenharmony_ci	}, {
3938c2ecf20Sopenharmony_ci		.name = "usbh",
3948c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_USBH,
3958c2ecf20Sopenharmony_ci	}, {
3968c2ecf20Sopenharmony_ci		.name = "disable_gless",
3978c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_DIS_GLESS,
3988c2ecf20Sopenharmony_ci	}, {
3998c2ecf20Sopenharmony_ci		.name = "nand",
4008c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_NAND,
4018c2ecf20Sopenharmony_ci	}, {
4028c2ecf20Sopenharmony_ci		.name = "ipsec",
4038c2ecf20Sopenharmony_ci		.bit = BCM6368_CLK_IPSEC,
4048c2ecf20Sopenharmony_ci	}, {
4058c2ecf20Sopenharmony_ci		/* sentinel */
4068c2ecf20Sopenharmony_ci	},
4078c2ecf20Sopenharmony_ci};
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_cistatic const struct clk_bcm63xx_table_entry bcm63268_clocks[] = {
4108c2ecf20Sopenharmony_ci	{
4118c2ecf20Sopenharmony_ci		.name = "disable_gless",
4128c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_DIS_GLESS,
4138c2ecf20Sopenharmony_ci	}, {
4148c2ecf20Sopenharmony_ci		.name = "vdsl_qproc",
4158c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_VDSL_QPROC,
4168c2ecf20Sopenharmony_ci	}, {
4178c2ecf20Sopenharmony_ci		.name = "vdsl_afe",
4188c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_VDSL_AFE,
4198c2ecf20Sopenharmony_ci	}, {
4208c2ecf20Sopenharmony_ci		.name = "vdsl",
4218c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_VDSL,
4228c2ecf20Sopenharmony_ci	}, {
4238c2ecf20Sopenharmony_ci		.name = "mips",
4248c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_MIPS,
4258c2ecf20Sopenharmony_ci		.flags = CLK_IS_CRITICAL,
4268c2ecf20Sopenharmony_ci	}, {
4278c2ecf20Sopenharmony_ci		.name = "wlan_ocp",
4288c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_WLAN_OCP,
4298c2ecf20Sopenharmony_ci	}, {
4308c2ecf20Sopenharmony_ci		.name = "dect",
4318c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_DECT,
4328c2ecf20Sopenharmony_ci	}, {
4338c2ecf20Sopenharmony_ci		.name = "fap0",
4348c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_FAP0,
4358c2ecf20Sopenharmony_ci	}, {
4368c2ecf20Sopenharmony_ci		.name = "fap1",
4378c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_FAP1,
4388c2ecf20Sopenharmony_ci	}, {
4398c2ecf20Sopenharmony_ci		.name = "sar",
4408c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_SAR,
4418c2ecf20Sopenharmony_ci	}, {
4428c2ecf20Sopenharmony_ci		.name = "robosw",
4438c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_ROBOSW,
4448c2ecf20Sopenharmony_ci	}, {
4458c2ecf20Sopenharmony_ci		.name = "pcm",
4468c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_PCM,
4478c2ecf20Sopenharmony_ci	}, {
4488c2ecf20Sopenharmony_ci		.name = "usbd",
4498c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_USBD,
4508c2ecf20Sopenharmony_ci	}, {
4518c2ecf20Sopenharmony_ci		.name = "usbh",
4528c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_USBH,
4538c2ecf20Sopenharmony_ci	}, {
4548c2ecf20Sopenharmony_ci		.name = "ipsec",
4558c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_IPSEC,
4568c2ecf20Sopenharmony_ci	}, {
4578c2ecf20Sopenharmony_ci		.name = "spi",
4588c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_SPI,
4598c2ecf20Sopenharmony_ci	}, {
4608c2ecf20Sopenharmony_ci		.name = "hsspi",
4618c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_HSSPI,
4628c2ecf20Sopenharmony_ci	}, {
4638c2ecf20Sopenharmony_ci		.name = "pcie",
4648c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_PCIE,
4658c2ecf20Sopenharmony_ci	}, {
4668c2ecf20Sopenharmony_ci		.name = "phymips",
4678c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_PHYMIPS,
4688c2ecf20Sopenharmony_ci	}, {
4698c2ecf20Sopenharmony_ci		.name = "gmac",
4708c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_GMAC,
4718c2ecf20Sopenharmony_ci	}, {
4728c2ecf20Sopenharmony_ci		.name = "nand",
4738c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_NAND,
4748c2ecf20Sopenharmony_ci	}, {
4758c2ecf20Sopenharmony_ci		.name = "tbus",
4768c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_TBUS,
4778c2ecf20Sopenharmony_ci	}, {
4788c2ecf20Sopenharmony_ci		.name = "robosw250",
4798c2ecf20Sopenharmony_ci		.bit = BCM63268_CLK_ROBOSW250,
4808c2ecf20Sopenharmony_ci	}, {
4818c2ecf20Sopenharmony_ci		/* sentinel */
4828c2ecf20Sopenharmony_ci	},
4838c2ecf20Sopenharmony_ci};
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_cistatic int clk_bcm63xx_probe(struct platform_device *pdev)
4868c2ecf20Sopenharmony_ci{
4878c2ecf20Sopenharmony_ci	const struct clk_bcm63xx_table_entry *entry, *table;
4888c2ecf20Sopenharmony_ci	struct clk_bcm63xx_hw *hw;
4898c2ecf20Sopenharmony_ci	u8 maxbit = 0;
4908c2ecf20Sopenharmony_ci	int i, ret;
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	table = of_device_get_match_data(&pdev->dev);
4938c2ecf20Sopenharmony_ci	if (!table)
4948c2ecf20Sopenharmony_ci		return -EINVAL;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	for (entry = table; entry->name; entry++)
4978c2ecf20Sopenharmony_ci		maxbit = max_t(u8, maxbit, entry->bit);
4988c2ecf20Sopenharmony_ci	maxbit++;
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci	hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
5018c2ecf20Sopenharmony_ci			  GFP_KERNEL);
5028c2ecf20Sopenharmony_ci	if (!hw)
5038c2ecf20Sopenharmony_ci		return -ENOMEM;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	platform_set_drvdata(pdev, hw);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci	spin_lock_init(&hw->lock);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	hw->data.num = maxbit;
5108c2ecf20Sopenharmony_ci	for (i = 0; i < maxbit; i++)
5118c2ecf20Sopenharmony_ci		hw->data.hws[i] = ERR_PTR(-ENODEV);
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci	hw->regs = devm_platform_ioremap_resource(pdev, 0);
5148c2ecf20Sopenharmony_ci	if (IS_ERR(hw->regs))
5158c2ecf20Sopenharmony_ci		return PTR_ERR(hw->regs);
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	for (entry = table; entry->name; entry++) {
5188c2ecf20Sopenharmony_ci		struct clk_hw *clk;
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci		clk = clk_hw_register_gate(&pdev->dev, entry->name, NULL,
5218c2ecf20Sopenharmony_ci					   entry->flags, hw->regs, entry->bit,
5228c2ecf20Sopenharmony_ci					   CLK_GATE_BIG_ENDIAN, &hw->lock);
5238c2ecf20Sopenharmony_ci		if (IS_ERR(clk)) {
5248c2ecf20Sopenharmony_ci			ret = PTR_ERR(clk);
5258c2ecf20Sopenharmony_ci			goto out_err;
5268c2ecf20Sopenharmony_ci		}
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci		hw->data.hws[entry->bit] = clk;
5298c2ecf20Sopenharmony_ci	}
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci	ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
5328c2ecf20Sopenharmony_ci				     &hw->data);
5338c2ecf20Sopenharmony_ci	if (!ret)
5348c2ecf20Sopenharmony_ci		return 0;
5358c2ecf20Sopenharmony_ciout_err:
5368c2ecf20Sopenharmony_ci	for (i = 0; i < hw->data.num; i++) {
5378c2ecf20Sopenharmony_ci		if (!IS_ERR(hw->data.hws[i]))
5388c2ecf20Sopenharmony_ci			clk_hw_unregister_gate(hw->data.hws[i]);
5398c2ecf20Sopenharmony_ci	}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	return ret;
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic int clk_bcm63xx_remove(struct platform_device *pdev)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	struct clk_bcm63xx_hw *hw = platform_get_drvdata(pdev);
5478c2ecf20Sopenharmony_ci	int i;
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	of_clk_del_provider(pdev->dev.of_node);
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci	for (i = 0; i < hw->data.num; i++) {
5528c2ecf20Sopenharmony_ci		if (!IS_ERR(hw->data.hws[i]))
5538c2ecf20Sopenharmony_ci			clk_hw_unregister_gate(hw->data.hws[i]);
5548c2ecf20Sopenharmony_ci	}
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	return 0;
5578c2ecf20Sopenharmony_ci}
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_cistatic const struct of_device_id clk_bcm63xx_dt_ids[] = {
5608c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm3368-clocks", .data = &bcm3368_clocks, },
5618c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6318-clocks", .data = &bcm6318_clocks, },
5628c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6318-ubus-clocks", .data = &bcm6318_ubus_clocks, },
5638c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6328-clocks", .data = &bcm6328_clocks, },
5648c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6358-clocks", .data = &bcm6358_clocks, },
5658c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6362-clocks", .data = &bcm6362_clocks, },
5668c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm6368-clocks", .data = &bcm6368_clocks, },
5678c2ecf20Sopenharmony_ci	{ .compatible = "brcm,bcm63268-clocks", .data = &bcm63268_clocks, },
5688c2ecf20Sopenharmony_ci	{ }
5698c2ecf20Sopenharmony_ci};
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_cistatic struct platform_driver clk_bcm63xx = {
5728c2ecf20Sopenharmony_ci	.probe = clk_bcm63xx_probe,
5738c2ecf20Sopenharmony_ci	.remove = clk_bcm63xx_remove,
5748c2ecf20Sopenharmony_ci	.driver = {
5758c2ecf20Sopenharmony_ci		.name = "bcm63xx-clock",
5768c2ecf20Sopenharmony_ci		.of_match_table = clk_bcm63xx_dt_ids,
5778c2ecf20Sopenharmony_ci	},
5788c2ecf20Sopenharmony_ci};
5798c2ecf20Sopenharmony_cibuiltin_platform_driver(clk_bcm63xx);
580