xref: /openbmc/linux/drivers/clk/clk-aspeed.c (revision f798983982386a3f36ecc4bbdad2657d38bad3e3)
15eda5d79SJoel Stanley // SPDX-License-Identifier: GPL-2.0+
25eda5d79SJoel Stanley 
35eda5d79SJoel Stanley #define pr_fmt(fmt) "clk-aspeed: " fmt
45eda5d79SJoel Stanley 
55eda5d79SJoel Stanley #include <linux/clk-provider.h>
65eda5d79SJoel Stanley #include <linux/mfd/syscon.h>
75eda5d79SJoel Stanley #include <linux/of_address.h>
898f3118dSJoel Stanley #include <linux/of_device.h>
998f3118dSJoel Stanley #include <linux/platform_device.h>
105eda5d79SJoel Stanley #include <linux/regmap.h>
11*f7989839SJoel Stanley #include <linux/reset-controller.h>
125eda5d79SJoel Stanley #include <linux/slab.h>
135eda5d79SJoel Stanley #include <linux/spinlock.h>
145eda5d79SJoel Stanley 
155eda5d79SJoel Stanley #include <dt-bindings/clock/aspeed-clock.h>
165eda5d79SJoel Stanley 
175eda5d79SJoel Stanley #define ASPEED_NUM_CLKS		35
185eda5d79SJoel Stanley 
1999d01e0eSJoel Stanley #define ASPEED_RESET_CTRL	0x04
2099d01e0eSJoel Stanley #define ASPEED_CLK_SELECTION	0x08
2199d01e0eSJoel Stanley #define ASPEED_CLK_STOP_CTRL	0x0c
2299d01e0eSJoel Stanley #define ASPEED_MPLL_PARAM	0x20
2399d01e0eSJoel Stanley #define ASPEED_HPLL_PARAM	0x24
2499d01e0eSJoel Stanley #define  AST2500_HPLL_BYPASS_EN	BIT(20)
2599d01e0eSJoel Stanley #define  AST2400_HPLL_STRAPPED	BIT(18)
2699d01e0eSJoel Stanley #define  AST2400_HPLL_BYPASS_EN	BIT(17)
2799d01e0eSJoel Stanley #define ASPEED_MISC_CTRL	0x2c
2899d01e0eSJoel Stanley #define  UART_DIV13_EN		BIT(12)
295eda5d79SJoel Stanley #define ASPEED_STRAP		0x70
3099d01e0eSJoel Stanley #define  CLKIN_25MHZ_EN		BIT(23)
3199d01e0eSJoel Stanley #define  AST2400_CLK_SOURCE_SEL	BIT(18)
3299d01e0eSJoel Stanley #define ASPEED_CLK_SELECTION_2	0xd8
3399d01e0eSJoel Stanley 
3499d01e0eSJoel Stanley /* Globally visible clocks */
3599d01e0eSJoel Stanley static DEFINE_SPINLOCK(aspeed_clk_lock);
365eda5d79SJoel Stanley 
375eda5d79SJoel Stanley /* Keeps track of all clocks */
385eda5d79SJoel Stanley static struct clk_hw_onecell_data *aspeed_clk_data;
395eda5d79SJoel Stanley 
405eda5d79SJoel Stanley static void __iomem *scu_base;
415eda5d79SJoel Stanley 
425eda5d79SJoel Stanley /**
435eda5d79SJoel Stanley  * struct aspeed_gate_data - Aspeed gated clocks
445eda5d79SJoel Stanley  * @clock_idx: bit used to gate this clock in the clock register
455eda5d79SJoel Stanley  * @reset_idx: bit used to reset this IP in the reset register. -1 if no
465eda5d79SJoel Stanley  *             reset is required when enabling the clock
475eda5d79SJoel Stanley  * @name: the clock name
485eda5d79SJoel Stanley  * @parent_name: the name of the parent clock
495eda5d79SJoel Stanley  * @flags: standard clock framework flags
505eda5d79SJoel Stanley  */
515eda5d79SJoel Stanley struct aspeed_gate_data {
525eda5d79SJoel Stanley 	u8		clock_idx;
535eda5d79SJoel Stanley 	s8		reset_idx;
545eda5d79SJoel Stanley 	const char	*name;
555eda5d79SJoel Stanley 	const char	*parent_name;
565eda5d79SJoel Stanley 	unsigned long	flags;
575eda5d79SJoel Stanley };
585eda5d79SJoel Stanley 
595eda5d79SJoel Stanley /**
605eda5d79SJoel Stanley  * struct aspeed_clk_gate - Aspeed specific clk_gate structure
615eda5d79SJoel Stanley  * @hw:		handle between common and hardware-specific interfaces
625eda5d79SJoel Stanley  * @reg:	register controlling gate
635eda5d79SJoel Stanley  * @clock_idx:	bit used to gate this clock in the clock register
645eda5d79SJoel Stanley  * @reset_idx:	bit used to reset this IP in the reset register. -1 if no
655eda5d79SJoel Stanley  *		reset is required when enabling the clock
665eda5d79SJoel Stanley  * @flags:	hardware-specific flags
675eda5d79SJoel Stanley  * @lock:	register lock
685eda5d79SJoel Stanley  *
695eda5d79SJoel Stanley  * Some of the clocks in the Aspeed SoC must be put in reset before enabling.
705eda5d79SJoel Stanley  * This modified version of clk_gate allows an optional reset bit to be
715eda5d79SJoel Stanley  * specified.
725eda5d79SJoel Stanley  */
735eda5d79SJoel Stanley struct aspeed_clk_gate {
745eda5d79SJoel Stanley 	struct clk_hw	hw;
755eda5d79SJoel Stanley 	struct regmap	*map;
765eda5d79SJoel Stanley 	u8		clock_idx;
775eda5d79SJoel Stanley 	s8		reset_idx;
785eda5d79SJoel Stanley 	u8		flags;
795eda5d79SJoel Stanley 	spinlock_t	*lock;
805eda5d79SJoel Stanley };
815eda5d79SJoel Stanley 
825eda5d79SJoel Stanley #define to_aspeed_clk_gate(_hw) container_of(_hw, struct aspeed_clk_gate, hw)
835eda5d79SJoel Stanley 
845eda5d79SJoel Stanley /* TODO: ask Aspeed about the actual parent data */
855eda5d79SJoel Stanley static const struct aspeed_gate_data aspeed_gates[] = {
865eda5d79SJoel Stanley 	/*				 clk rst   name			parent	flags */
875eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_ECLK] =	{  0, -1, "eclk-gate",		"eclk",	0 }, /* Video Engine */
885eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_GCLK] =	{  1,  7, "gclk-gate",		NULL,	0 }, /* 2D engine */
895eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_MCLK] =	{  2, -1, "mclk-gate",		"mpll",	CLK_IS_CRITICAL }, /* SDRAM */
905eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_VCLK] =	{  3,  6, "vclk-gate",		NULL,	0 }, /* Video Capture */
915eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_BCLK] =	{  4, 10, "bclk-gate",		"bclk",	0 }, /* PCIe/PCI */
925eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_DCLK] =	{  5, -1, "dclk-gate",		NULL,	0 }, /* DAC */
935eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_REFCLK] =	{  6, -1, "refclk-gate",	"clkin", CLK_IS_CRITICAL },
945eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_USBPORT2CLK] =	{  7,  3, "usb-port2-gate",	NULL,	0 }, /* USB2.0 Host port 2 */
955eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_LCLK] =	{  8,  5, "lclk-gate",		NULL,	0 }, /* LPC */
965eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_USBUHCICLK] =	{  9, 15, "usb-uhci-gate",	NULL,	0 }, /* USB1.1 (requires port 2 enabled) */
975eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_D1CLK] =	{ 10, 13, "d1clk-gate",		NULL,	0 }, /* GFX CRT */
985eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_YCLK] =	{ 13,  4, "yclk-gate",		NULL,	0 }, /* HAC */
995eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_USBPORT1CLK] = { 14, 14, "usb-port1-gate",	NULL,	0 }, /* USB2 hub/USB2 host port 1/USB1.1 dev */
1005eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_UART1CLK] =	{ 15, -1, "uart1clk-gate",	"uart",	0 }, /* UART1 */
1015eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_UART2CLK] =	{ 16, -1, "uart2clk-gate",	"uart",	0 }, /* UART2 */
1025eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_UART5CLK] =	{ 17, -1, "uart5clk-gate",	"uart",	0 }, /* UART5 */
1035eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_ESPICLK] =	{ 19, -1, "espiclk-gate",	NULL,	0 }, /* eSPI */
1045eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_MAC1CLK] =	{ 20, 11, "mac1clk-gate",	"mac",	0 }, /* MAC1 */
1055eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_MAC2CLK] =	{ 21, 12, "mac2clk-gate",	"mac",	0 }, /* MAC2 */
1065eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_RSACLK] =	{ 24, -1, "rsaclk-gate",	NULL,	0 }, /* RSA */
1075eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_UART3CLK] =	{ 25, -1, "uart3clk-gate",	"uart",	0 }, /* UART3 */
1085eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_UART4CLK] =	{ 26, -1, "uart4clk-gate",	"uart",	0 }, /* UART4 */
1095eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_SDCLKCLK] =	{ 27, 16, "sdclk-gate",		NULL,	0 }, /* SDIO/SD */
1105eda5d79SJoel Stanley 	[ASPEED_CLK_GATE_LHCCLK] =	{ 28, -1, "lhclk-gate",		"lhclk", 0 }, /* LPC master/LPC+ */
1115eda5d79SJoel Stanley };
1125eda5d79SJoel Stanley 
11398f3118dSJoel Stanley static const struct clk_div_table ast2500_mac_div_table[] = {
11498f3118dSJoel Stanley 	{ 0x0, 4 }, /* Yep, really. Aspeed confirmed this is correct */
11598f3118dSJoel Stanley 	{ 0x1, 4 },
11698f3118dSJoel Stanley 	{ 0x2, 6 },
11798f3118dSJoel Stanley 	{ 0x3, 8 },
11898f3118dSJoel Stanley 	{ 0x4, 10 },
11998f3118dSJoel Stanley 	{ 0x5, 12 },
12098f3118dSJoel Stanley 	{ 0x6, 14 },
12198f3118dSJoel Stanley 	{ 0x7, 16 },
12298f3118dSJoel Stanley 	{ 0 }
12398f3118dSJoel Stanley };
12498f3118dSJoel Stanley 
12599d01e0eSJoel Stanley static const struct clk_div_table ast2400_div_table[] = {
12699d01e0eSJoel Stanley 	{ 0x0, 2 },
12799d01e0eSJoel Stanley 	{ 0x1, 4 },
12899d01e0eSJoel Stanley 	{ 0x2, 6 },
12999d01e0eSJoel Stanley 	{ 0x3, 8 },
13099d01e0eSJoel Stanley 	{ 0x4, 10 },
13199d01e0eSJoel Stanley 	{ 0x5, 12 },
13299d01e0eSJoel Stanley 	{ 0x6, 14 },
13399d01e0eSJoel Stanley 	{ 0x7, 16 },
13499d01e0eSJoel Stanley 	{ 0 }
13599d01e0eSJoel Stanley };
13699d01e0eSJoel Stanley 
13799d01e0eSJoel Stanley static const struct clk_div_table ast2500_div_table[] = {
13899d01e0eSJoel Stanley 	{ 0x0, 4 },
13999d01e0eSJoel Stanley 	{ 0x1, 8 },
14099d01e0eSJoel Stanley 	{ 0x2, 12 },
14199d01e0eSJoel Stanley 	{ 0x3, 16 },
14299d01e0eSJoel Stanley 	{ 0x4, 20 },
14399d01e0eSJoel Stanley 	{ 0x5, 24 },
14499d01e0eSJoel Stanley 	{ 0x6, 28 },
14599d01e0eSJoel Stanley 	{ 0x7, 32 },
14699d01e0eSJoel Stanley 	{ 0 }
14799d01e0eSJoel Stanley };
14899d01e0eSJoel Stanley 
14999d01e0eSJoel Stanley static struct clk_hw *aspeed_ast2400_calc_pll(const char *name, u32 val)
15099d01e0eSJoel Stanley {
15199d01e0eSJoel Stanley 	unsigned int mult, div;
15299d01e0eSJoel Stanley 
15399d01e0eSJoel Stanley 	if (val & AST2400_HPLL_BYPASS_EN) {
15499d01e0eSJoel Stanley 		/* Pass through mode */
15599d01e0eSJoel Stanley 		mult = div = 1;
15699d01e0eSJoel Stanley 	} else {
15799d01e0eSJoel Stanley 		/* F = 24Mhz * (2-OD) * [(N + 2) / (D + 1)] */
15899d01e0eSJoel Stanley 		u32 n = (val >> 5) & 0x3f;
15999d01e0eSJoel Stanley 		u32 od = (val >> 4) & 0x1;
16099d01e0eSJoel Stanley 		u32 d = val & 0xf;
16199d01e0eSJoel Stanley 
16299d01e0eSJoel Stanley 		mult = (2 - od) * (n + 2);
16399d01e0eSJoel Stanley 		div = d + 1;
16499d01e0eSJoel Stanley 	}
16599d01e0eSJoel Stanley 	return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
16699d01e0eSJoel Stanley 			mult, div);
16799d01e0eSJoel Stanley };
16899d01e0eSJoel Stanley 
16999d01e0eSJoel Stanley static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val)
17099d01e0eSJoel Stanley {
17199d01e0eSJoel Stanley 	unsigned int mult, div;
17299d01e0eSJoel Stanley 
17399d01e0eSJoel Stanley 	if (val & AST2500_HPLL_BYPASS_EN) {
17499d01e0eSJoel Stanley 		/* Pass through mode */
17599d01e0eSJoel Stanley 		mult = div = 1;
17699d01e0eSJoel Stanley 	} else {
17799d01e0eSJoel Stanley 		/* F = clkin * [(M+1) / (N+1)] / (P + 1) */
17899d01e0eSJoel Stanley 		u32 p = (val >> 13) & 0x3f;
17999d01e0eSJoel Stanley 		u32 m = (val >> 5) & 0xff;
18099d01e0eSJoel Stanley 		u32 n = val & 0x1f;
18199d01e0eSJoel Stanley 
18299d01e0eSJoel Stanley 		mult = (m + 1) / (n + 1);
18399d01e0eSJoel Stanley 		div = p + 1;
18499d01e0eSJoel Stanley 	}
18599d01e0eSJoel Stanley 
18699d01e0eSJoel Stanley 	return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
18799d01e0eSJoel Stanley 			mult, div);
18899d01e0eSJoel Stanley }
18999d01e0eSJoel Stanley 
19098f3118dSJoel Stanley struct aspeed_clk_soc_data {
19198f3118dSJoel Stanley 	const struct clk_div_table *div_table;
19298f3118dSJoel Stanley 	const struct clk_div_table *mac_div_table;
19398f3118dSJoel Stanley 	struct clk_hw *(*calc_pll)(const char *name, u32 val);
19498f3118dSJoel Stanley };
19598f3118dSJoel Stanley 
19698f3118dSJoel Stanley static const struct aspeed_clk_soc_data ast2500_data = {
19798f3118dSJoel Stanley 	.div_table = ast2500_div_table,
19898f3118dSJoel Stanley 	.mac_div_table = ast2500_mac_div_table,
19998f3118dSJoel Stanley 	.calc_pll = aspeed_ast2500_calc_pll,
20098f3118dSJoel Stanley };
20198f3118dSJoel Stanley 
20298f3118dSJoel Stanley static const struct aspeed_clk_soc_data ast2400_data = {
20398f3118dSJoel Stanley 	.div_table = ast2400_div_table,
20498f3118dSJoel Stanley 	.mac_div_table = ast2400_div_table,
20598f3118dSJoel Stanley 	.calc_pll = aspeed_ast2400_calc_pll,
20698f3118dSJoel Stanley };
20798f3118dSJoel Stanley 
20815ed8ce5SJoel Stanley static int aspeed_clk_enable(struct clk_hw *hw)
20915ed8ce5SJoel Stanley {
21015ed8ce5SJoel Stanley 	struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
21115ed8ce5SJoel Stanley 	unsigned long flags;
21215ed8ce5SJoel Stanley 	u32 clk = BIT(gate->clock_idx);
21315ed8ce5SJoel Stanley 	u32 rst = BIT(gate->reset_idx);
21415ed8ce5SJoel Stanley 
21515ed8ce5SJoel Stanley 	spin_lock_irqsave(gate->lock, flags);
21615ed8ce5SJoel Stanley 
21715ed8ce5SJoel Stanley 	if (gate->reset_idx >= 0) {
21815ed8ce5SJoel Stanley 		/* Put IP in reset */
21915ed8ce5SJoel Stanley 		regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, rst);
22015ed8ce5SJoel Stanley 
22115ed8ce5SJoel Stanley 		/* Delay 100us */
22215ed8ce5SJoel Stanley 		udelay(100);
22315ed8ce5SJoel Stanley 	}
22415ed8ce5SJoel Stanley 
22515ed8ce5SJoel Stanley 	/* Enable clock */
22615ed8ce5SJoel Stanley 	regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, 0);
22715ed8ce5SJoel Stanley 
22815ed8ce5SJoel Stanley 	if (gate->reset_idx >= 0) {
22915ed8ce5SJoel Stanley 		/* A delay of 10ms is specified by the ASPEED docs */
23015ed8ce5SJoel Stanley 		mdelay(10);
23115ed8ce5SJoel Stanley 
23215ed8ce5SJoel Stanley 		/* Take IP out of reset */
23315ed8ce5SJoel Stanley 		regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, 0);
23415ed8ce5SJoel Stanley 	}
23515ed8ce5SJoel Stanley 
23615ed8ce5SJoel Stanley 	spin_unlock_irqrestore(gate->lock, flags);
23715ed8ce5SJoel Stanley 
23815ed8ce5SJoel Stanley 	return 0;
23915ed8ce5SJoel Stanley }
24015ed8ce5SJoel Stanley 
24115ed8ce5SJoel Stanley static void aspeed_clk_disable(struct clk_hw *hw)
24215ed8ce5SJoel Stanley {
24315ed8ce5SJoel Stanley 	struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
24415ed8ce5SJoel Stanley 	unsigned long flags;
24515ed8ce5SJoel Stanley 	u32 clk = BIT(gate->clock_idx);
24615ed8ce5SJoel Stanley 
24715ed8ce5SJoel Stanley 	spin_lock_irqsave(gate->lock, flags);
24815ed8ce5SJoel Stanley 
24915ed8ce5SJoel Stanley 	regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, clk);
25015ed8ce5SJoel Stanley 
25115ed8ce5SJoel Stanley 	spin_unlock_irqrestore(gate->lock, flags);
25215ed8ce5SJoel Stanley }
25315ed8ce5SJoel Stanley 
25415ed8ce5SJoel Stanley static int aspeed_clk_is_enabled(struct clk_hw *hw)
25515ed8ce5SJoel Stanley {
25615ed8ce5SJoel Stanley 	struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
25715ed8ce5SJoel Stanley 	u32 clk = BIT(gate->clock_idx);
25815ed8ce5SJoel Stanley 	u32 reg;
25915ed8ce5SJoel Stanley 
26015ed8ce5SJoel Stanley 	regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
26115ed8ce5SJoel Stanley 
26215ed8ce5SJoel Stanley 	return (reg & clk) ? 0 : 1;
26315ed8ce5SJoel Stanley }
26415ed8ce5SJoel Stanley 
26515ed8ce5SJoel Stanley static const struct clk_ops aspeed_clk_gate_ops = {
26615ed8ce5SJoel Stanley 	.enable = aspeed_clk_enable,
26715ed8ce5SJoel Stanley 	.disable = aspeed_clk_disable,
26815ed8ce5SJoel Stanley 	.is_enabled = aspeed_clk_is_enabled,
26915ed8ce5SJoel Stanley };
27015ed8ce5SJoel Stanley 
271*f7989839SJoel Stanley /**
272*f7989839SJoel Stanley  * struct aspeed_reset - Aspeed reset controller
273*f7989839SJoel Stanley  * @map: regmap to access the containing system controller
274*f7989839SJoel Stanley  * @rcdev: reset controller device
275*f7989839SJoel Stanley  */
276*f7989839SJoel Stanley struct aspeed_reset {
277*f7989839SJoel Stanley 	struct regmap			*map;
278*f7989839SJoel Stanley 	struct reset_controller_dev	rcdev;
279*f7989839SJoel Stanley };
280*f7989839SJoel Stanley 
281*f7989839SJoel Stanley #define to_aspeed_reset(p) container_of((p), struct aspeed_reset, rcdev)
282*f7989839SJoel Stanley 
283*f7989839SJoel Stanley static const u8 aspeed_resets[] = {
284*f7989839SJoel Stanley 	[ASPEED_RESET_XDMA]	= 25,
285*f7989839SJoel Stanley 	[ASPEED_RESET_MCTP]	= 24,
286*f7989839SJoel Stanley 	[ASPEED_RESET_ADC]	= 23,
287*f7989839SJoel Stanley 	[ASPEED_RESET_JTAG_MASTER] = 22,
288*f7989839SJoel Stanley 	[ASPEED_RESET_MIC]	= 18,
289*f7989839SJoel Stanley 	[ASPEED_RESET_PWM]	=  9,
290*f7989839SJoel Stanley 	[ASPEED_RESET_PCIVGA]	=  8,
291*f7989839SJoel Stanley 	[ASPEED_RESET_I2C]	=  2,
292*f7989839SJoel Stanley 	[ASPEED_RESET_AHB]	=  1,
293*f7989839SJoel Stanley };
294*f7989839SJoel Stanley 
295*f7989839SJoel Stanley static int aspeed_reset_deassert(struct reset_controller_dev *rcdev,
296*f7989839SJoel Stanley 				 unsigned long id)
297*f7989839SJoel Stanley {
298*f7989839SJoel Stanley 	struct aspeed_reset *ar = to_aspeed_reset(rcdev);
299*f7989839SJoel Stanley 	u32 rst = BIT(aspeed_resets[id]);
300*f7989839SJoel Stanley 
301*f7989839SJoel Stanley 	return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, 0);
302*f7989839SJoel Stanley }
303*f7989839SJoel Stanley 
304*f7989839SJoel Stanley static int aspeed_reset_assert(struct reset_controller_dev *rcdev,
305*f7989839SJoel Stanley 			       unsigned long id)
306*f7989839SJoel Stanley {
307*f7989839SJoel Stanley 	struct aspeed_reset *ar = to_aspeed_reset(rcdev);
308*f7989839SJoel Stanley 	u32 rst = BIT(aspeed_resets[id]);
309*f7989839SJoel Stanley 
310*f7989839SJoel Stanley 	return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, rst);
311*f7989839SJoel Stanley }
312*f7989839SJoel Stanley 
313*f7989839SJoel Stanley static int aspeed_reset_status(struct reset_controller_dev *rcdev,
314*f7989839SJoel Stanley 			       unsigned long id)
315*f7989839SJoel Stanley {
316*f7989839SJoel Stanley 	struct aspeed_reset *ar = to_aspeed_reset(rcdev);
317*f7989839SJoel Stanley 	u32 val, rst = BIT(aspeed_resets[id]);
318*f7989839SJoel Stanley 	int ret;
319*f7989839SJoel Stanley 
320*f7989839SJoel Stanley 	ret = regmap_read(ar->map, ASPEED_RESET_CTRL, &val);
321*f7989839SJoel Stanley 	if (ret)
322*f7989839SJoel Stanley 		return ret;
323*f7989839SJoel Stanley 
324*f7989839SJoel Stanley 	return !!(val & rst);
325*f7989839SJoel Stanley }
326*f7989839SJoel Stanley 
327*f7989839SJoel Stanley static const struct reset_control_ops aspeed_reset_ops = {
328*f7989839SJoel Stanley 	.assert = aspeed_reset_assert,
329*f7989839SJoel Stanley 	.deassert = aspeed_reset_deassert,
330*f7989839SJoel Stanley 	.status = aspeed_reset_status,
331*f7989839SJoel Stanley };
332*f7989839SJoel Stanley 
33315ed8ce5SJoel Stanley static struct clk_hw *aspeed_clk_hw_register_gate(struct device *dev,
33415ed8ce5SJoel Stanley 		const char *name, const char *parent_name, unsigned long flags,
33515ed8ce5SJoel Stanley 		struct regmap *map, u8 clock_idx, u8 reset_idx,
33615ed8ce5SJoel Stanley 		u8 clk_gate_flags, spinlock_t *lock)
33715ed8ce5SJoel Stanley {
33815ed8ce5SJoel Stanley 	struct aspeed_clk_gate *gate;
33915ed8ce5SJoel Stanley 	struct clk_init_data init;
34015ed8ce5SJoel Stanley 	struct clk_hw *hw;
34115ed8ce5SJoel Stanley 	int ret;
34215ed8ce5SJoel Stanley 
34315ed8ce5SJoel Stanley 	gate = kzalloc(sizeof(*gate), GFP_KERNEL);
34415ed8ce5SJoel Stanley 	if (!gate)
34515ed8ce5SJoel Stanley 		return ERR_PTR(-ENOMEM);
34615ed8ce5SJoel Stanley 
34715ed8ce5SJoel Stanley 	init.name = name;
34815ed8ce5SJoel Stanley 	init.ops = &aspeed_clk_gate_ops;
34915ed8ce5SJoel Stanley 	init.flags = flags;
35015ed8ce5SJoel Stanley 	init.parent_names = parent_name ? &parent_name : NULL;
35115ed8ce5SJoel Stanley 	init.num_parents = parent_name ? 1 : 0;
35215ed8ce5SJoel Stanley 
35315ed8ce5SJoel Stanley 	gate->map = map;
35415ed8ce5SJoel Stanley 	gate->clock_idx = clock_idx;
35515ed8ce5SJoel Stanley 	gate->reset_idx = reset_idx;
35615ed8ce5SJoel Stanley 	gate->flags = clk_gate_flags;
35715ed8ce5SJoel Stanley 	gate->lock = lock;
35815ed8ce5SJoel Stanley 	gate->hw.init = &init;
35915ed8ce5SJoel Stanley 
36015ed8ce5SJoel Stanley 	hw = &gate->hw;
36115ed8ce5SJoel Stanley 	ret = clk_hw_register(dev, hw);
36215ed8ce5SJoel Stanley 	if (ret) {
36315ed8ce5SJoel Stanley 		kfree(gate);
36415ed8ce5SJoel Stanley 		hw = ERR_PTR(ret);
36515ed8ce5SJoel Stanley 	}
36615ed8ce5SJoel Stanley 
36715ed8ce5SJoel Stanley 	return hw;
36815ed8ce5SJoel Stanley }
36915ed8ce5SJoel Stanley 
37098f3118dSJoel Stanley static int aspeed_clk_probe(struct platform_device *pdev)
37198f3118dSJoel Stanley {
37298f3118dSJoel Stanley 	const struct aspeed_clk_soc_data *soc_data;
37398f3118dSJoel Stanley 	struct device *dev = &pdev->dev;
374*f7989839SJoel Stanley 	struct aspeed_reset *ar;
37598f3118dSJoel Stanley 	struct regmap *map;
37698f3118dSJoel Stanley 	struct clk_hw *hw;
37798f3118dSJoel Stanley 	u32 val, rate;
378*f7989839SJoel Stanley 	int i, ret;
37998f3118dSJoel Stanley 
38098f3118dSJoel Stanley 	map = syscon_node_to_regmap(dev->of_node);
38198f3118dSJoel Stanley 	if (IS_ERR(map)) {
38298f3118dSJoel Stanley 		dev_err(dev, "no syscon regmap\n");
38398f3118dSJoel Stanley 		return PTR_ERR(map);
38498f3118dSJoel Stanley 	}
38598f3118dSJoel Stanley 
386*f7989839SJoel Stanley 	ar = devm_kzalloc(dev, sizeof(*ar), GFP_KERNEL);
387*f7989839SJoel Stanley 	if (!ar)
388*f7989839SJoel Stanley 		return -ENOMEM;
389*f7989839SJoel Stanley 
390*f7989839SJoel Stanley 	ar->map = map;
391*f7989839SJoel Stanley 	ar->rcdev.owner = THIS_MODULE;
392*f7989839SJoel Stanley 	ar->rcdev.nr_resets = ARRAY_SIZE(aspeed_resets);
393*f7989839SJoel Stanley 	ar->rcdev.ops = &aspeed_reset_ops;
394*f7989839SJoel Stanley 	ar->rcdev.of_node = dev->of_node;
395*f7989839SJoel Stanley 
396*f7989839SJoel Stanley 	ret = devm_reset_controller_register(dev, &ar->rcdev);
397*f7989839SJoel Stanley 	if (ret) {
398*f7989839SJoel Stanley 		dev_err(dev, "could not register reset controller\n");
399*f7989839SJoel Stanley 		return ret;
400*f7989839SJoel Stanley 	}
401*f7989839SJoel Stanley 
40298f3118dSJoel Stanley 	/* SoC generations share common layouts but have different divisors */
40398f3118dSJoel Stanley 	soc_data = of_device_get_match_data(dev);
40498f3118dSJoel Stanley 	if (!soc_data) {
40598f3118dSJoel Stanley 		dev_err(dev, "no match data for platform\n");
40698f3118dSJoel Stanley 		return -EINVAL;
40798f3118dSJoel Stanley 	}
40898f3118dSJoel Stanley 
40998f3118dSJoel Stanley 	/* UART clock div13 setting */
41098f3118dSJoel Stanley 	regmap_read(map, ASPEED_MISC_CTRL, &val);
41198f3118dSJoel Stanley 	if (val & UART_DIV13_EN)
41298f3118dSJoel Stanley 		rate = 24000000 / 13;
41398f3118dSJoel Stanley 	else
41498f3118dSJoel Stanley 		rate = 24000000;
41598f3118dSJoel Stanley 	/* TODO: Find the parent data for the uart clock */
41698f3118dSJoel Stanley 	hw = clk_hw_register_fixed_rate(dev, "uart", NULL, 0, rate);
41798f3118dSJoel Stanley 	if (IS_ERR(hw))
41898f3118dSJoel Stanley 		return PTR_ERR(hw);
41998f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_UART] = hw;
42098f3118dSJoel Stanley 
42198f3118dSJoel Stanley 	/*
42298f3118dSJoel Stanley 	 * Memory controller (M-PLL) PLL. This clock is configured by the
42398f3118dSJoel Stanley 	 * bootloader, and is exposed to Linux as a read-only clock rate.
42498f3118dSJoel Stanley 	 */
42598f3118dSJoel Stanley 	regmap_read(map, ASPEED_MPLL_PARAM, &val);
42698f3118dSJoel Stanley 	hw = soc_data->calc_pll("mpll", val);
42798f3118dSJoel Stanley 	if (IS_ERR(hw))
42898f3118dSJoel Stanley 		return PTR_ERR(hw);
42998f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_MPLL] =	hw;
43098f3118dSJoel Stanley 
43198f3118dSJoel Stanley 	/* SD/SDIO clock divider (TODO: There's a gate too) */
43298f3118dSJoel Stanley 	hw = clk_hw_register_divider_table(dev, "sdio", "hpll", 0,
43398f3118dSJoel Stanley 			scu_base + ASPEED_CLK_SELECTION, 12, 3, 0,
43498f3118dSJoel Stanley 			soc_data->div_table,
43598f3118dSJoel Stanley 			&aspeed_clk_lock);
43698f3118dSJoel Stanley 	if (IS_ERR(hw))
43798f3118dSJoel Stanley 		return PTR_ERR(hw);
43898f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_SDIO] = hw;
43998f3118dSJoel Stanley 
44098f3118dSJoel Stanley 	/* MAC AHB bus clock divider */
44198f3118dSJoel Stanley 	hw = clk_hw_register_divider_table(dev, "mac", "hpll", 0,
44298f3118dSJoel Stanley 			scu_base + ASPEED_CLK_SELECTION, 16, 3, 0,
44398f3118dSJoel Stanley 			soc_data->mac_div_table,
44498f3118dSJoel Stanley 			&aspeed_clk_lock);
44598f3118dSJoel Stanley 	if (IS_ERR(hw))
44698f3118dSJoel Stanley 		return PTR_ERR(hw);
44798f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_MAC] = hw;
44898f3118dSJoel Stanley 
44998f3118dSJoel Stanley 	/* LPC Host (LHCLK) clock divider */
45098f3118dSJoel Stanley 	hw = clk_hw_register_divider_table(dev, "lhclk", "hpll", 0,
45198f3118dSJoel Stanley 			scu_base + ASPEED_CLK_SELECTION, 20, 3, 0,
45298f3118dSJoel Stanley 			soc_data->div_table,
45398f3118dSJoel Stanley 			&aspeed_clk_lock);
45498f3118dSJoel Stanley 	if (IS_ERR(hw))
45598f3118dSJoel Stanley 		return PTR_ERR(hw);
45698f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_LHCLK] = hw;
45798f3118dSJoel Stanley 
45898f3118dSJoel Stanley 	/* P-Bus (BCLK) clock divider */
45998f3118dSJoel Stanley 	hw = clk_hw_register_divider_table(dev, "bclk", "hpll", 0,
46098f3118dSJoel Stanley 			scu_base + ASPEED_CLK_SELECTION_2, 0, 2, 0,
46198f3118dSJoel Stanley 			soc_data->div_table,
46298f3118dSJoel Stanley 			&aspeed_clk_lock);
46398f3118dSJoel Stanley 	if (IS_ERR(hw))
46498f3118dSJoel Stanley 		return PTR_ERR(hw);
46598f3118dSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_BCLK] = hw;
46698f3118dSJoel Stanley 
46715ed8ce5SJoel Stanley 	/*
46815ed8ce5SJoel Stanley 	 * TODO: There are a number of clocks that not included in this driver
46915ed8ce5SJoel Stanley 	 * as more information is required:
47015ed8ce5SJoel Stanley 	 *   D2-PLL
47115ed8ce5SJoel Stanley 	 *   D-PLL
47215ed8ce5SJoel Stanley 	 *   YCLK
47315ed8ce5SJoel Stanley 	 *   RGMII
47415ed8ce5SJoel Stanley 	 *   RMII
47515ed8ce5SJoel Stanley 	 *   UART[1..5] clock source mux
47615ed8ce5SJoel Stanley 	 *   Video Engine (ECLK) mux and clock divider
47715ed8ce5SJoel Stanley 	 */
47815ed8ce5SJoel Stanley 
47915ed8ce5SJoel Stanley 	for (i = 0; i < ARRAY_SIZE(aspeed_gates); i++) {
48015ed8ce5SJoel Stanley 		const struct aspeed_gate_data *gd = &aspeed_gates[i];
48115ed8ce5SJoel Stanley 
48215ed8ce5SJoel Stanley 		hw = aspeed_clk_hw_register_gate(dev,
48315ed8ce5SJoel Stanley 				gd->name,
48415ed8ce5SJoel Stanley 				gd->parent_name,
48515ed8ce5SJoel Stanley 				gd->flags,
48615ed8ce5SJoel Stanley 				map,
48715ed8ce5SJoel Stanley 				gd->clock_idx,
48815ed8ce5SJoel Stanley 				gd->reset_idx,
48915ed8ce5SJoel Stanley 				CLK_GATE_SET_TO_DISABLE,
49015ed8ce5SJoel Stanley 				&aspeed_clk_lock);
49115ed8ce5SJoel Stanley 		if (IS_ERR(hw))
49215ed8ce5SJoel Stanley 			return PTR_ERR(hw);
49315ed8ce5SJoel Stanley 		aspeed_clk_data->hws[i] = hw;
49415ed8ce5SJoel Stanley 	}
49515ed8ce5SJoel Stanley 
49698f3118dSJoel Stanley 	return 0;
49798f3118dSJoel Stanley };
49898f3118dSJoel Stanley 
49998f3118dSJoel Stanley static const struct of_device_id aspeed_clk_dt_ids[] = {
50098f3118dSJoel Stanley 	{ .compatible = "aspeed,ast2400-scu", .data = &ast2400_data },
50198f3118dSJoel Stanley 	{ .compatible = "aspeed,ast2500-scu", .data = &ast2500_data },
50298f3118dSJoel Stanley 	{ }
50398f3118dSJoel Stanley };
50498f3118dSJoel Stanley 
50598f3118dSJoel Stanley static struct platform_driver aspeed_clk_driver = {
50698f3118dSJoel Stanley 	.probe  = aspeed_clk_probe,
50798f3118dSJoel Stanley 	.driver = {
50898f3118dSJoel Stanley 		.name = "aspeed-clk",
50998f3118dSJoel Stanley 		.of_match_table = aspeed_clk_dt_ids,
51098f3118dSJoel Stanley 		.suppress_bind_attrs = true,
51198f3118dSJoel Stanley 	},
51298f3118dSJoel Stanley };
51398f3118dSJoel Stanley builtin_platform_driver(aspeed_clk_driver);
51498f3118dSJoel Stanley 
51599d01e0eSJoel Stanley static void __init aspeed_ast2400_cc(struct regmap *map)
51699d01e0eSJoel Stanley {
51799d01e0eSJoel Stanley 	struct clk_hw *hw;
51899d01e0eSJoel Stanley 	u32 val, freq, div;
51999d01e0eSJoel Stanley 
52099d01e0eSJoel Stanley 	/*
52199d01e0eSJoel Stanley 	 * CLKIN is the crystal oscillator, 24, 48 or 25MHz selected by
52299d01e0eSJoel Stanley 	 * strapping
52399d01e0eSJoel Stanley 	 */
52499d01e0eSJoel Stanley 	regmap_read(map, ASPEED_STRAP, &val);
52599d01e0eSJoel Stanley 	if (val & CLKIN_25MHZ_EN)
52699d01e0eSJoel Stanley 		freq = 25000000;
52799d01e0eSJoel Stanley 	else if (val & AST2400_CLK_SOURCE_SEL)
52899d01e0eSJoel Stanley 		freq = 48000000;
52999d01e0eSJoel Stanley 	else
53099d01e0eSJoel Stanley 		freq = 24000000;
53199d01e0eSJoel Stanley 	hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq);
53299d01e0eSJoel Stanley 	pr_debug("clkin @%u MHz\n", freq / 1000000);
53399d01e0eSJoel Stanley 
53499d01e0eSJoel Stanley 	/*
53599d01e0eSJoel Stanley 	 * High-speed PLL clock derived from the crystal. This the CPU clock,
53699d01e0eSJoel Stanley 	 * and we assume that it is enabled
53799d01e0eSJoel Stanley 	 */
53899d01e0eSJoel Stanley 	regmap_read(map, ASPEED_HPLL_PARAM, &val);
53999d01e0eSJoel Stanley 	WARN(val & AST2400_HPLL_STRAPPED, "hpll is strapped not configured");
54099d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2400_calc_pll("hpll", val);
54199d01e0eSJoel Stanley 
54299d01e0eSJoel Stanley 	/*
54399d01e0eSJoel Stanley 	 * Strap bits 11:10 define the CPU/AHB clock frequency ratio (aka HCLK)
54499d01e0eSJoel Stanley 	 *   00: Select CPU:AHB = 1:1
54599d01e0eSJoel Stanley 	 *   01: Select CPU:AHB = 2:1
54699d01e0eSJoel Stanley 	 *   10: Select CPU:AHB = 4:1
54799d01e0eSJoel Stanley 	 *   11: Select CPU:AHB = 3:1
54899d01e0eSJoel Stanley 	 */
54999d01e0eSJoel Stanley 	regmap_read(map, ASPEED_STRAP, &val);
55099d01e0eSJoel Stanley 	val = (val >> 10) & 0x3;
55199d01e0eSJoel Stanley 	div = val + 1;
55299d01e0eSJoel Stanley 	if (div == 3)
55399d01e0eSJoel Stanley 		div = 4;
55499d01e0eSJoel Stanley 	else if (div == 4)
55599d01e0eSJoel Stanley 		div = 3;
55699d01e0eSJoel Stanley 	hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div);
55799d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw;
55899d01e0eSJoel Stanley 
55999d01e0eSJoel Stanley 	/* APB clock clock selection register SCU08 (aka PCLK) */
56099d01e0eSJoel Stanley 	hw = clk_hw_register_divider_table(NULL, "apb", "hpll", 0,
56199d01e0eSJoel Stanley 			scu_base + ASPEED_CLK_SELECTION, 23, 3, 0,
56299d01e0eSJoel Stanley 			ast2400_div_table,
56399d01e0eSJoel Stanley 			&aspeed_clk_lock);
56499d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_APB] = hw;
56599d01e0eSJoel Stanley }
56699d01e0eSJoel Stanley 
56799d01e0eSJoel Stanley static void __init aspeed_ast2500_cc(struct regmap *map)
56899d01e0eSJoel Stanley {
56999d01e0eSJoel Stanley 	struct clk_hw *hw;
57099d01e0eSJoel Stanley 	u32 val, freq, div;
57199d01e0eSJoel Stanley 
57299d01e0eSJoel Stanley 	/* CLKIN is the crystal oscillator, 24 or 25MHz selected by strapping */
57399d01e0eSJoel Stanley 	regmap_read(map, ASPEED_STRAP, &val);
57499d01e0eSJoel Stanley 	if (val & CLKIN_25MHZ_EN)
57599d01e0eSJoel Stanley 		freq = 25000000;
57699d01e0eSJoel Stanley 	else
57799d01e0eSJoel Stanley 		freq = 24000000;
57899d01e0eSJoel Stanley 	hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq);
57999d01e0eSJoel Stanley 	pr_debug("clkin @%u MHz\n", freq / 1000000);
58099d01e0eSJoel Stanley 
58199d01e0eSJoel Stanley 	/*
58299d01e0eSJoel Stanley 	 * High-speed PLL clock derived from the crystal. This the CPU clock,
58399d01e0eSJoel Stanley 	 * and we assume that it is enabled
58499d01e0eSJoel Stanley 	 */
58599d01e0eSJoel Stanley 	regmap_read(map, ASPEED_HPLL_PARAM, &val);
58699d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2500_calc_pll("hpll", val);
58799d01e0eSJoel Stanley 
58899d01e0eSJoel Stanley 	/* Strap bits 11:9 define the AXI/AHB clock frequency ratio (aka HCLK)*/
58999d01e0eSJoel Stanley 	regmap_read(map, ASPEED_STRAP, &val);
59099d01e0eSJoel Stanley 	val = (val >> 9) & 0x7;
59199d01e0eSJoel Stanley 	WARN(val == 0, "strapping is zero: cannot determine ahb clock");
59299d01e0eSJoel Stanley 	div = 2 * (val + 1);
59399d01e0eSJoel Stanley 	hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div);
59499d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw;
59599d01e0eSJoel Stanley 
59699d01e0eSJoel Stanley 	/* APB clock clock selection register SCU08 (aka PCLK) */
59799d01e0eSJoel Stanley 	regmap_read(map, ASPEED_CLK_SELECTION, &val);
59899d01e0eSJoel Stanley 	val = (val >> 23) & 0x7;
59999d01e0eSJoel Stanley 	div = 4 * (val + 1);
60099d01e0eSJoel Stanley 	hw = clk_hw_register_fixed_factor(NULL, "apb", "hpll", 0, 1, div);
60199d01e0eSJoel Stanley 	aspeed_clk_data->hws[ASPEED_CLK_APB] = hw;
60299d01e0eSJoel Stanley };
60399d01e0eSJoel Stanley 
6045eda5d79SJoel Stanley static void __init aspeed_cc_init(struct device_node *np)
6055eda5d79SJoel Stanley {
6065eda5d79SJoel Stanley 	struct regmap *map;
6075eda5d79SJoel Stanley 	u32 val;
6085eda5d79SJoel Stanley 	int ret;
6095eda5d79SJoel Stanley 	int i;
6105eda5d79SJoel Stanley 
6115eda5d79SJoel Stanley 	scu_base = of_iomap(np, 0);
6125eda5d79SJoel Stanley 	if (IS_ERR(scu_base))
6135eda5d79SJoel Stanley 		return;
6145eda5d79SJoel Stanley 
6155eda5d79SJoel Stanley 	aspeed_clk_data = kzalloc(sizeof(*aspeed_clk_data) +
6165eda5d79SJoel Stanley 			sizeof(*aspeed_clk_data->hws) * ASPEED_NUM_CLKS,
6175eda5d79SJoel Stanley 			GFP_KERNEL);
6185eda5d79SJoel Stanley 	if (!aspeed_clk_data)
6195eda5d79SJoel Stanley 		return;
6205eda5d79SJoel Stanley 
6215eda5d79SJoel Stanley 	/*
6225eda5d79SJoel Stanley 	 * This way all clocks fetched before the platform device probes,
6235eda5d79SJoel Stanley 	 * except those we assign here for early use, will be deferred.
6245eda5d79SJoel Stanley 	 */
6255eda5d79SJoel Stanley 	for (i = 0; i < ASPEED_NUM_CLKS; i++)
6265eda5d79SJoel Stanley 		aspeed_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
6275eda5d79SJoel Stanley 
6285eda5d79SJoel Stanley 	map = syscon_node_to_regmap(np);
6295eda5d79SJoel Stanley 	if (IS_ERR(map)) {
6305eda5d79SJoel Stanley 		pr_err("no syscon regmap\n");
6315eda5d79SJoel Stanley 		return;
6325eda5d79SJoel Stanley 	}
6335eda5d79SJoel Stanley 	/*
6345eda5d79SJoel Stanley 	 * We check that the regmap works on this very first access,
6355eda5d79SJoel Stanley 	 * but as this is an MMIO-backed regmap, subsequent regmap
6365eda5d79SJoel Stanley 	 * access is not going to fail and we skip error checks from
6375eda5d79SJoel Stanley 	 * this point.
6385eda5d79SJoel Stanley 	 */
6395eda5d79SJoel Stanley 	ret = regmap_read(map, ASPEED_STRAP, &val);
6405eda5d79SJoel Stanley 	if (ret) {
6415eda5d79SJoel Stanley 		pr_err("failed to read strapping register\n");
6425eda5d79SJoel Stanley 		return;
6435eda5d79SJoel Stanley 	}
6445eda5d79SJoel Stanley 
64599d01e0eSJoel Stanley 	if (of_device_is_compatible(np, "aspeed,ast2400-scu"))
64699d01e0eSJoel Stanley 		aspeed_ast2400_cc(map);
64799d01e0eSJoel Stanley 	else if (of_device_is_compatible(np, "aspeed,ast2500-scu"))
64899d01e0eSJoel Stanley 		aspeed_ast2500_cc(map);
64999d01e0eSJoel Stanley 	else
65099d01e0eSJoel Stanley 		pr_err("unknown platform, failed to add clocks\n");
65199d01e0eSJoel Stanley 
6525eda5d79SJoel Stanley 	aspeed_clk_data->num = ASPEED_NUM_CLKS;
6535eda5d79SJoel Stanley 	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_clk_data);
6545eda5d79SJoel Stanley 	if (ret)
6555eda5d79SJoel Stanley 		pr_err("failed to add DT provider: %d\n", ret);
6565eda5d79SJoel Stanley };
6575eda5d79SJoel Stanley CLK_OF_DECLARE_DRIVER(aspeed_cc_g5, "aspeed,ast2500-scu", aspeed_cc_init);
6585eda5d79SJoel Stanley CLK_OF_DECLARE_DRIVER(aspeed_cc_g4, "aspeed,ast2400-scu", aspeed_cc_init);
659