1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2019 Broadcom Ltd.
7 #include <spl_ddrinit.h>
8 #include <asm/arch/cpu.h>
9 #include <asm/arch/misc.h>
12 #if defined(CONFIG_BCMBCA_PMC)
15 #include "asm/arch/BPCM.h"
18 #if defined(CONFIG_TPL_BUILD)
19 static void cci400_enable(void)
21 CCI400
->secr_acc
|= SECURE_ACCESS_UNSECURE_ENABLE
;
24 static void enable_ns_access(void)
26 BIUCFG
->aux
.permission
|= 0xff;
30 #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
31 static void swrw(unsigned int ps
, unsigned int reg
, unsigned int val
)
34 unsigned int cmd1
= 0;
35 unsigned int reg0
= 0;
37 PROCMON
->SSBMaster
.control
= SWR_EN
;
40 /* no need read reg0 in case that we write to it , we know wal :) */
44 cmd1
= SWR_READ_CMD_P
| SET_ADDR(ps
, 0);
45 PROCMON
->SSBMaster
.control
= cmd1
;
47 reg0
= PROCMON
->SSBMaster
.rd_data
;
50 PROCMON
->SSBMaster
.wr_data
= val
;
51 cmd
= SWR_WR_CMD_P
| SET_ADDR(ps
, reg
);
52 PROCMON
->SSBMaster
.control
= cmd
;
54 /*toggele bit 1 reg0 this load the new regs value */
55 cmd1
= SWR_WR_CMD_P
| SET_ADDR(ps
, 0);
56 PROCMON
->SSBMaster
.wr_data
= reg0
& ~0x2;
57 PROCMON
->SSBMaster
.control
= cmd1
;
59 PROCMON
->SSBMaster
.wr_data
= reg0
| 0x2;
60 PROCMON
->SSBMaster
.control
= cmd1
;
62 PROCMON
->SSBMaster
.wr_data
= reg0
& ~0x2;
63 PROCMON
->SSBMaster
.control
= cmd1
;
67 static void bcm_setsw(void)
76 #if defined(CONFIG_TPL_BUILD)
77 #define CLOCK_RESET_XTAL_CONTROL_BIT_PD_DRV (17)
78 static void disable_xtal_clk(void)
83 ret
= ReadBPCMRegister(PMB_ADDR_CHIP_CLKRST
,
84 CLKRSTBPCMRegOffset(xtal_control
), &data
);
86 data
|= (0x1 << CLOCK_RESET_XTAL_CONTROL_BIT_PD_DRV
);
88 ret
|= WriteBPCMRegister(PMB_ADDR_CHIP_CLKRST
,
89 CLKRSTBPCMRegOffset(xtal_control
), data
);
92 printf("Failed to disable xtal clk\n");
96 void boost_cpu_clock(void)
98 unsigned int clk_index
, cpu_clock
;
99 unsigned int chipId
= 0;
101 bcm_otp_get_chipid(&chipId
);
103 if (chipId
== 0x5 || chipId
== 0x2)
106 if (pll_ch_freq_set(PMB_ADDR_BIU_PLL
, 0, 3))
107 printf("Error: failed to set CPU clock\n");
109 else if ( !bcm_otp_get_cpu_clk(&clk_index
) )
110 cpu_clock
= 500 + 500*(2-clk_index
);
114 /* configure AXI clock */
115 if (pll_ch_freq_set(PMB_ADDR_BIU_PLL
, 2, 4))
116 printf("Error: failed to set AXI clock\n");
118 /* Change cpu to fast clock */
119 if ((MISC
->miscStrapBus
)&MISC_STRAP_BUS_CPU_SLOW_FREQ
)
122 PLL_CTRL_REG ctrl_reg
;
123 stat
= ReadBPCMRegister(PMB_ADDR_BIU_PLL
, PLLBPCMRegOffset(resets
), &ctrl_reg
.Reg32
);
124 ctrl_reg
.Bits
.byp_wait
= 0;
125 stat
|= WriteBPCMRegister(PMB_ADDR_BIU_PLL
, PLLBPCMRegOffset(resets
), ctrl_reg
.Reg32
);
127 printf("Error: failed to set cpu fast mode\n");
130 printf("CPU Clock: %dMHz\n", cpu_clock
);
132 stat
= PowerOnDevice(PMB_ADDR_RDPPLL
);
134 stat
= pll_ch_freq_set(PMB_ADDR_RDPPLL
, 0, 2);
135 stat
|= pll_ch_freq_set(PMB_ADDR_RDPPLL
, 1, 1);
138 printf("Error: Failed to set RDPPLL\n");
143 int arch_cpu_init(void)
145 #if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)
146 spl_ddrinit_prepare();
147 // enable system timer
148 BIUCFG
->TSO_CNTCR
|= 1;
151 /* enable unalgined access */
152 set_sctlr(get_sctlr() & ~CR_A
);
155 #if defined(CONFIG_TPL_BUILD)
163 #if !defined(CONFIG_SPL_BUILD)
164 void print_chipinfo(void)
166 char *mktname
= NULL
;
167 char *nr_cores
= NULL
;
168 unsigned int cpu_speed
, rdp_speed
, chipId
;
169 unsigned int revId
= PERF
->RevID
& REV_ID_MASK
;
171 if (bcm_otp_get_chipid(&chipId
)) {
225 printf("Chip ID: BCM%s_%X\n",mktname
,revId
);
227 pll_ch_freq_get(PMB_ADDR_BIU_PLL
, 0, &cpu_speed
);
228 printf("Broadcom B53 %s Core: %dMHz\n", nr_cores
, cpu_speed
);
230 get_rdp_freq(&rdp_speed
);
231 printf("RDP: %dMHz\n",rdp_speed
);
235 int bcmbca_get_boot_device(void)
237 unsigned int bootsel
= ((MISC
->miscStrapBus
& MISC_STRAP_BUS_BOOT_SEL0_4_MASK
) >> MISC_STRAP_BUS_BOOT_SEL0_4_SHIFT
) |
238 ((MISC
->miscStrapBus
& MISC_STRAP_BUS_BOOT_SEL5_MASK
) >> BOOT_SEL5_STRAP_ADJ_SHIFT
);
240 if ((bootsel
& BOOT_SEL_STRAP_BOOT_SEL_NAND_MASK
) == BOOT_SEL_STRAP_NAND
)
241 return BOOT_DEVICE_NAND
;
243 if ((bootsel
& BOOT_SEL_STRAP_BOOT_SEL_MASK
) == BOOT_SEL_STRAP_SPI_NAND
)
244 return BOOT_DEVICE_SPI
;
246 if ((bootsel
& BOOT_SEL_STRAP_BOOT_SEL_MASK
) == BOOT_SEL_STRAP_EMMC
)
247 return BOOT_DEVICE_MMC1
;
249 printf("Error: boot_sel straps are not set correctly\n");
251 return BOOT_DEVICE_NONE
;
254 #if !defined(CONFIG_TPL_ATF)
255 void boot_secondary_cpu(unsigned long vector
)
258 uint32_t nr_cpus
= 4;
259 ARM_CONTROL_REG ctrl_reg
;
261 printf("boot secondary cpu from 0x%lx\n", vector
);
263 while (cpu
< nr_cpus
) {
266 BIUCFG
->cluster
[0].rvbar_addr
[cpu
] = vector
>> 8;
267 stat
= PowerOnDevice(PMB_ADDR_ORION_CPU0
+ cpu
);
268 if (stat
!= kPMC_NO_ERROR
)
269 printf("failed to power on secondary cpu %d - sts %d\n", cpu
, stat
);
271 stat
= ReadBPCMRegister(PMB_ADDR_BIU_BPCM
, ARMBPCMRegOffset(arm_control
), &ctrl_reg
.Reg32
);
272 ctrl_reg
.Bits
.cpu_reset_n
&= ~(0x1 << cpu
);
273 stat
|= WriteBPCMRegister(PMB_ADDR_BIU_BPCM
, ARMBPCMRegOffset(arm_control
), ctrl_reg
.Reg32
);
274 if (stat
!= kPMC_NO_ERROR
)
275 printf("failed to boot secondary cpu %d - sts %d\n", cpu
, stat
);