2 * Copyright 2014 Broadcom Corporation.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/errno.h>
10 #include <asm/arch/sysmap.h>
11 #include <asm/kona-common/clk.h>
14 #define WR_ACCESS_ADDR ESUB_CLK_BASE_ADDR
15 #define WR_ACCESS_PASSWORD 0xA5A500
17 #define PLLE_POST_RESETB_ADDR (ESUB_CLK_BASE_ADDR + 0x00000C00)
19 #define PLLE_RESETB_ADDR (ESUB_CLK_BASE_ADDR + 0x00000C58)
20 #define PLLE_RESETB_I_PLL_RESETB_PLLE_MASK 0x00010000
21 #define PLLE_POST_RESETB_I_POST_RESETB_PLLE_MASK 0x00000001
23 #define PLL_LOCK_ADDR (ESUB_CLK_BASE_ADDR + 0x00000C38)
24 #define PLL_LOCK_PLL_LOCK_PLLE_MASK 0x00000001
26 #define ESW_SYS_DIV_ADDR (ESUB_CLK_BASE_ADDR + 0x00000A04)
27 #define ESW_SYS_DIV_PLL_SELECT_MASK 0x00000300
28 #define ESW_SYS_DIV_DIV_MASK 0x0000001C
29 #define ESW_SYS_DIV_PLL_VAR_208M_CLK_SELECT 0x00000100
30 #define ESW_SYS_DIV_DIV_SELECT 0x4
31 #define ESW_SYS_DIV_TRIGGER_MASK 0x00000001
33 #define ESUB_AXI_DIV_DEBUG_ADDR (ESUB_CLK_BASE_ADDR + 0x00000E04)
34 #define ESUB_AXI_DIV_DEBUG_PLL_SELECT_MASK 0x0000001C
35 #define ESUB_AXI_DIV_DEBUG_PLL_SELECT_OVERRIDE_MASK 0x00000040
36 #define ESUB_AXI_DIV_DEBUG_PLL_VAR_208M_CLK_SELECT 0x0
37 #define ESUB_AXI_DIV_DEBUG_TRIGGER_MASK 0x00000001
39 #define PLL_MAX_RETRY 100
41 /* Enable appropriate clocks for Ethernet */
42 int clk_eth_enable(void)
46 rc = clk_get_and_enable("esub_ccu_clk");
48 /* Enable Access to CCU registers */
49 writel((1 | WR_ACCESS_PASSWORD), WR_ACCESS_ADDR);
51 writel(readl(PLLE_POST_RESETB_ADDR) &
52 ~PLLE_POST_RESETB_I_POST_RESETB_PLLE_MASK,
53 PLLE_POST_RESETB_ADDR);
55 /* Take PLL out of reset and put into normal mode */
56 writel(readl(PLLE_RESETB_ADDR) | PLLE_RESETB_I_PLL_RESETB_PLLE_MASK,
59 /* Wait for PLL lock */
61 while (retry_count < PLL_MAX_RETRY) {
63 if (readl(PLL_LOCK_ADDR) & PLL_LOCK_PLL_LOCK_PLLE_MASK) {
71 printf("%s: ETH-PLL lock timeout, Ethernet is not enabled!\n",
76 writel(readl(PLLE_POST_RESETB_ADDR) |
77 PLLE_POST_RESETB_I_POST_RESETB_PLLE_MASK,
78 PLLE_POST_RESETB_ADDR);
80 /* Switch esw_sys_clk to use 104MHz(208MHz/2) clock */
81 writel((readl(ESW_SYS_DIV_ADDR) &
82 ~(ESW_SYS_DIV_PLL_SELECT_MASK | ESW_SYS_DIV_DIV_MASK)) |
83 ESW_SYS_DIV_PLL_VAR_208M_CLK_SELECT | ESW_SYS_DIV_DIV_SELECT,
86 writel(readl(ESW_SYS_DIV_ADDR) | ESW_SYS_DIV_TRIGGER_MASK,
89 /* Wait for trigger complete */
92 while (retry_count < PLL_MAX_RETRY) {
94 if (!(readl(ESW_SYS_DIV_ADDR) & ESW_SYS_DIV_TRIGGER_MASK)) {
102 printf("%s: SYS CLK Trigger timeout, Ethernet is not enabled!\n",
107 /* switch Esub AXI clock to 208MHz */
108 writel((readl(ESUB_AXI_DIV_DEBUG_ADDR) &
109 ~(ESUB_AXI_DIV_DEBUG_PLL_SELECT_MASK |
110 ESUB_AXI_DIV_DEBUG_PLL_SELECT_OVERRIDE_MASK |
111 ESUB_AXI_DIV_DEBUG_TRIGGER_MASK)) |
112 ESUB_AXI_DIV_DEBUG_PLL_VAR_208M_CLK_SELECT |
113 ESUB_AXI_DIV_DEBUG_PLL_SELECT_OVERRIDE_MASK,
114 ESUB_AXI_DIV_DEBUG_ADDR);
116 writel(readl(ESUB_AXI_DIV_DEBUG_ADDR) |
117 ESUB_AXI_DIV_DEBUG_TRIGGER_MASK,
118 ESUB_AXI_DIV_DEBUG_ADDR);
120 /* Wait for trigger complete */
123 while (retry_count < PLL_MAX_RETRY) {
125 if (!(readl(ESUB_AXI_DIV_DEBUG_ADDR) &
126 ESUB_AXI_DIV_DEBUG_TRIGGER_MASK)) {
134 printf("%s: AXI CLK Trigger timeout, Ethernet is not enabled!\n",
139 /* Disable Access to CCU registers */
140 writel(WR_ACCESS_PASSWORD, WR_ACCESS_ADDR);