1 // SPDX-License-Identifier: GPL-2.0+
5 * Derived from linux/arch/mips/bcm63xx/cpu.c:
16 #include <linux/bitops.h>
18 #define REV_CHIPID_SHIFT 16
19 #define REV_CHIPID_MASK (0xffff << REV_CHIPID_SHIFT)
20 #define REV_LONG_CHIPID_SHIFT 12
21 #define REV_LONG_CHIPID_MASK (0xfffff << REV_LONG_CHIPID_SHIFT)
22 #define REV_REVID_SHIFT 0
23 #define REV_REVID_MASK (0xff << REV_REVID_SHIFT)
25 #define REG_BCM6328_OTP 0x62c
26 #define BCM6328_TP1_DISABLED BIT(9)
28 #define REG_BCM6318_STRAP_OVRDBUS 0x900
29 #define OVRDBUS_6318_FREQ_SHIFT 23
30 #define OVRDBUS_6318_FREQ_MASK (0x3 << OVRDBUS_6318_FREQ_SHIFT)
32 #define REG_BCM6328_MISC_STRAPBUS 0x1a40
33 #define STRAPBUS_6328_FCVO_SHIFT 7
34 #define STRAPBUS_6328_FCVO_MASK (0x1f << STRAPBUS_6328_FCVO_SHIFT)
36 #define REG_BCM6348_PERF_MIPSPLLCFG 0x34
37 #define MIPSPLLCFG_6348_M1CPU_SHIFT 6
38 #define MIPSPLLCFG_6348_M1CPU_MASK (0x7 << MIPSPLLCFG_6348_M1CPU_SHIFT)
39 #define MIPSPLLCFG_6348_N2_SHIFT 15
40 #define MIPSPLLCFG_6348_N2_MASK (0x1F << MIPSPLLCFG_6348_N2_SHIFT)
41 #define MIPSPLLCFG_6348_N1_SHIFT 20
42 #define MIPSPLLCFG_6348_N1_MASK (0x7 << MIPSPLLCFG_6348_N1_SHIFT)
44 #define REG_BCM6358_DDR_DMIPSPLLCFG 0x12b8
45 #define DMIPSPLLCFG_6358_M1_SHIFT 0
46 #define DMIPSPLLCFG_6358_M1_MASK (0xff << DMIPSPLLCFG_6358_M1_SHIFT)
47 #define DMIPSPLLCFG_6358_N1_SHIFT 23
48 #define DMIPSPLLCFG_6358_N1_MASK (0x3f << DMIPSPLLCFG_6358_N1_SHIFT)
49 #define DMIPSPLLCFG_6358_N2_SHIFT 29
50 #define DMIPSPLLCFG_6358_N2_MASK (0x7 << DMIPSPLLCFG_6358_N2_SHIFT)
52 #define REG_BCM6362_MISC_STRAPBUS 0x1814
53 #define STRAPBUS_6362_FCVO_SHIFT 1
54 #define STRAPBUS_6362_FCVO_MASK (0x1f << STRAPBUS_6362_FCVO_SHIFT)
56 #define REG_BCM6368_DDR_DMIPSPLLCFG 0x12a0
57 #define DMIPSPLLCFG_6368_P1_SHIFT 0
58 #define DMIPSPLLCFG_6368_P1_MASK (0xf << DMIPSPLLCFG_6368_P1_SHIFT)
59 #define DMIPSPLLCFG_6368_P2_SHIFT 4
60 #define DMIPSPLLCFG_6368_P2_MASK (0xf << DMIPSPLLCFG_6368_P2_SHIFT)
61 #define DMIPSPLLCFG_6368_NDIV_SHIFT 16
62 #define DMIPSPLLCFG_6368_NDIV_MASK (0x1ff << DMIPSPLLCFG_6368_NDIV_SHIFT)
63 #define REG_BCM6368_DDR_DMIPSPLLDIV 0x12a4
64 #define DMIPSPLLDIV_6368_MDIV_SHIFT 0
65 #define DMIPSPLLDIV_6368_MDIV_MASK (0xff << DMIPSPLLDIV_6368_MDIV_SHIFT)
67 #define REG_BCM63268_MISC_STRAPBUS 0x1814
68 #define STRAPBUS_63268_FCVO_SHIFT 21
69 #define STRAPBUS_63268_FCVO_MASK (0xf << STRAPBUS_63268_FCVO_SHIFT)
71 #define REG_BCM6838_OTP_BRCMBITS0 0x440
72 #define VIPER_6838_FREQ_SHIFT 18
73 #define VIPER_6838_FREQ_MASK (0x7 << VIPER_6838_FREQ_SHIFT)
75 struct bmips_cpu_priv;
78 int (*get_cpu_desc)(struct bmips_cpu_priv *priv, char *buf, int size);
79 ulong (*get_cpu_freq)(struct bmips_cpu_priv *);
80 int (*get_cpu_count)(struct bmips_cpu_priv *);
83 struct bmips_cpu_priv {
85 const struct bmips_cpu_hw *hw;
88 /* Specific CPU Ops */
89 static int bmips_short_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
92 unsigned short cpu_id;
93 unsigned char cpu_rev;
96 val = readl_be(priv->regs);
97 cpu_id = (val & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
98 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
100 snprintf(buf, size, "BCM%04X%02X", cpu_id, cpu_rev);
105 static int bmips_long_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
109 unsigned char cpu_rev;
112 val = readl_be(priv->regs);
113 cpu_id = (val & REV_LONG_CHIPID_MASK) >> REV_LONG_CHIPID_SHIFT;
114 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
116 snprintf(buf, size, "BCM%05X%02X", cpu_id, cpu_rev);
121 static ulong bcm3380_get_cpu_freq(struct bmips_cpu_priv *priv)
126 static ulong bcm6318_get_cpu_freq(struct bmips_cpu_priv *priv)
128 unsigned int mips_pll_fcvo;
130 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6318_STRAP_OVRDBUS);
131 mips_pll_fcvo = (mips_pll_fcvo & OVRDBUS_6318_FREQ_MASK)
132 >> OVRDBUS_6318_FREQ_SHIFT;
134 switch (mips_pll_fcvo) {
148 static ulong bcm6328_get_cpu_freq(struct bmips_cpu_priv *priv)
150 unsigned int mips_pll_fcvo;
152 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6328_MISC_STRAPBUS);
153 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6328_FCVO_MASK)
154 >> STRAPBUS_6328_FCVO_SHIFT;
156 switch (mips_pll_fcvo) {
175 static ulong bcm6338_get_cpu_freq(struct bmips_cpu_priv *priv)
180 static ulong bcm6348_get_cpu_freq(struct bmips_cpu_priv *priv)
182 unsigned int tmp, n1, n2, m1;
184 tmp = readl_be(priv->regs + REG_BCM6348_PERF_MIPSPLLCFG);
185 n1 = (tmp & MIPSPLLCFG_6348_N1_MASK) >> MIPSPLLCFG_6348_N1_SHIFT;
186 n2 = (tmp & MIPSPLLCFG_6348_N2_MASK) >> MIPSPLLCFG_6348_N2_SHIFT;
187 m1 = (tmp & MIPSPLLCFG_6348_M1CPU_MASK) >> MIPSPLLCFG_6348_M1CPU_SHIFT;
189 return (16 * 1000000 * (n1 + 1) * (n2 + 2)) / (m1 + 1);
192 static ulong bcm6358_get_cpu_freq(struct bmips_cpu_priv *priv)
194 unsigned int tmp, n1, n2, m1;
196 tmp = readl_be(priv->regs + REG_BCM6358_DDR_DMIPSPLLCFG);
197 n1 = (tmp & DMIPSPLLCFG_6358_N1_MASK) >> DMIPSPLLCFG_6358_N1_SHIFT;
198 n2 = (tmp & DMIPSPLLCFG_6358_N2_MASK) >> DMIPSPLLCFG_6358_N2_SHIFT;
199 m1 = (tmp & DMIPSPLLCFG_6358_M1_MASK) >> DMIPSPLLCFG_6358_M1_SHIFT;
201 return (16 * 1000000 * n1 * n2) / m1;
204 static ulong bcm6362_get_cpu_freq(struct bmips_cpu_priv *priv)
206 unsigned int mips_pll_fcvo;
208 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6362_MISC_STRAPBUS);
209 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6362_FCVO_MASK)
210 >> STRAPBUS_6362_FCVO_SHIFT;
212 switch (mips_pll_fcvo) {
242 static ulong bcm6368_get_cpu_freq(struct bmips_cpu_priv *priv)
244 unsigned int tmp, p1, p2, ndiv, m1;
246 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLCFG);
247 p1 = (tmp & DMIPSPLLCFG_6368_P1_MASK) >> DMIPSPLLCFG_6368_P1_SHIFT;
248 p2 = (tmp & DMIPSPLLCFG_6368_P2_MASK) >> DMIPSPLLCFG_6368_P2_SHIFT;
249 ndiv = (tmp & DMIPSPLLCFG_6368_NDIV_MASK) >>
250 DMIPSPLLCFG_6368_NDIV_SHIFT;
252 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLDIV);
253 m1 = (tmp & DMIPSPLLDIV_6368_MDIV_MASK) >> DMIPSPLLDIV_6368_MDIV_SHIFT;
255 return (((64 * 1000000) / p1) * p2 * ndiv) / m1;
258 static ulong bcm63268_get_cpu_freq(struct bmips_cpu_priv *priv)
260 unsigned int mips_pll_fcvo;
262 mips_pll_fcvo = readl_be(priv->regs + REG_BCM63268_MISC_STRAPBUS);
263 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_63268_FCVO_MASK)
264 >> STRAPBUS_63268_FCVO_SHIFT;
266 switch (mips_pll_fcvo) {
281 static ulong bcm6838_get_cpu_freq(struct bmips_cpu_priv *priv)
283 unsigned int mips_viper_freq;
285 mips_viper_freq = readl_be(priv->regs + REG_BCM6838_OTP_BRCMBITS0);
286 mips_viper_freq = (mips_viper_freq & VIPER_6838_FREQ_MASK)
287 >> VIPER_6838_FREQ_SHIFT;
289 switch (mips_viper_freq) {
301 static int bcm6328_get_cpu_count(struct bmips_cpu_priv *priv)
303 u32 val = readl_be(priv->regs + REG_BCM6328_OTP);
305 if (val & BCM6328_TP1_DISABLED)
311 static int bcm6345_get_cpu_count(struct bmips_cpu_priv *priv)
316 static int bcm6358_get_cpu_count(struct bmips_cpu_priv *priv)
321 static const struct bmips_cpu_hw bmips_cpu_bcm3380 = {
322 .get_cpu_desc = bmips_short_cpu_desc,
323 .get_cpu_freq = bcm3380_get_cpu_freq,
324 .get_cpu_count = bcm6358_get_cpu_count,
327 static const struct bmips_cpu_hw bmips_cpu_bcm6318 = {
328 .get_cpu_desc = bmips_short_cpu_desc,
329 .get_cpu_freq = bcm6318_get_cpu_freq,
330 .get_cpu_count = bcm6345_get_cpu_count,
333 static const struct bmips_cpu_hw bmips_cpu_bcm6328 = {
334 .get_cpu_desc = bmips_long_cpu_desc,
335 .get_cpu_freq = bcm6328_get_cpu_freq,
336 .get_cpu_count = bcm6328_get_cpu_count,
339 static const struct bmips_cpu_hw bmips_cpu_bcm6338 = {
340 .get_cpu_desc = bmips_short_cpu_desc,
341 .get_cpu_freq = bcm6338_get_cpu_freq,
342 .get_cpu_count = bcm6345_get_cpu_count,
345 static const struct bmips_cpu_hw bmips_cpu_bcm6348 = {
346 .get_cpu_desc = bmips_short_cpu_desc,
347 .get_cpu_freq = bcm6348_get_cpu_freq,
348 .get_cpu_count = bcm6345_get_cpu_count,
351 static const struct bmips_cpu_hw bmips_cpu_bcm6358 = {
352 .get_cpu_desc = bmips_short_cpu_desc,
353 .get_cpu_freq = bcm6358_get_cpu_freq,
354 .get_cpu_count = bcm6358_get_cpu_count,
357 static const struct bmips_cpu_hw bmips_cpu_bcm6362 = {
358 .get_cpu_desc = bmips_short_cpu_desc,
359 .get_cpu_freq = bcm6362_get_cpu_freq,
360 .get_cpu_count = bcm6358_get_cpu_count,
363 static const struct bmips_cpu_hw bmips_cpu_bcm6368 = {
364 .get_cpu_desc = bmips_short_cpu_desc,
365 .get_cpu_freq = bcm6368_get_cpu_freq,
366 .get_cpu_count = bcm6358_get_cpu_count,
369 static const struct bmips_cpu_hw bmips_cpu_bcm63268 = {
370 .get_cpu_desc = bmips_long_cpu_desc,
371 .get_cpu_freq = bcm63268_get_cpu_freq,
372 .get_cpu_count = bcm6358_get_cpu_count,
375 static const struct bmips_cpu_hw bmips_cpu_bcm6838 = {
376 .get_cpu_desc = bmips_short_cpu_desc,
377 .get_cpu_freq = bcm6838_get_cpu_freq,
378 .get_cpu_count = bcm6358_get_cpu_count,
381 /* Generic CPU Ops */
382 static int bmips_cpu_get_desc(const struct udevice *dev, char *buf, int size)
384 struct bmips_cpu_priv *priv = dev_get_priv(dev);
385 const struct bmips_cpu_hw *hw = priv->hw;
387 return hw->get_cpu_desc(priv, buf, size);
390 static int bmips_cpu_get_info(const struct udevice *dev, struct cpu_info *info)
392 struct bmips_cpu_priv *priv = dev_get_priv(dev);
393 const struct bmips_cpu_hw *hw = priv->hw;
395 info->cpu_freq = hw->get_cpu_freq(priv);
396 info->features = BIT(CPU_FEAT_L1_CACHE);
397 info->features |= BIT(CPU_FEAT_MMU);
398 info->features |= BIT(CPU_FEAT_DEVICE_ID);
403 static int bmips_cpu_get_count(const struct udevice *dev)
405 struct bmips_cpu_priv *priv = dev_get_priv(dev);
406 const struct bmips_cpu_hw *hw = priv->hw;
408 return hw->get_cpu_count(priv);
411 static int bmips_cpu_get_vendor(const struct udevice *dev, char *buf, int size)
413 snprintf(buf, size, "Broadcom");
418 static const struct cpu_ops bmips_cpu_ops = {
419 .get_desc = bmips_cpu_get_desc,
420 .get_info = bmips_cpu_get_info,
421 .get_count = bmips_cpu_get_count,
422 .get_vendor = bmips_cpu_get_vendor,
425 /* BMIPS CPU driver */
426 int bmips_cpu_bind(struct udevice *dev)
428 struct cpu_platdata *plat = dev_get_parent_plat(dev);
430 plat->cpu_id = dev_read_u32_default(dev, "reg", -1);
431 plat->device_id = read_c0_prid();
436 int bmips_cpu_probe(struct udevice *dev)
438 struct bmips_cpu_priv *priv = dev_get_priv(dev);
439 const struct bmips_cpu_hw *hw =
440 (const struct bmips_cpu_hw *)dev_get_driver_data(dev);
442 priv->regs = dev_remap_addr(dev_get_parent(dev));
451 static const struct udevice_id bmips_cpu_ids[] = {
453 .compatible = "brcm,bcm3380-cpu",
454 .data = (ulong)&bmips_cpu_bcm3380,
456 .compatible = "brcm,bcm6318-cpu",
457 .data = (ulong)&bmips_cpu_bcm6318,
459 .compatible = "brcm,bcm6328-cpu",
460 .data = (ulong)&bmips_cpu_bcm6328,
462 .compatible = "brcm,bcm6338-cpu",
463 .data = (ulong)&bmips_cpu_bcm6338,
465 .compatible = "brcm,bcm6348-cpu",
466 .data = (ulong)&bmips_cpu_bcm6348,
468 .compatible = "brcm,bcm6358-cpu",
469 .data = (ulong)&bmips_cpu_bcm6358,
471 .compatible = "brcm,bcm6362-cpu",
472 .data = (ulong)&bmips_cpu_bcm6362,
474 .compatible = "brcm,bcm6368-cpu",
475 .data = (ulong)&bmips_cpu_bcm6368,
477 .compatible = "brcm,bcm63268-cpu",
478 .data = (ulong)&bmips_cpu_bcm63268,
480 .compatible = "brcm,bcm6838-cpu",
481 .data = (ulong)&bmips_cpu_bcm6838,
486 U_BOOT_DRIVER(bmips_cpu_drv) = {
489 .of_match = bmips_cpu_ids,
490 .bind = bmips_cpu_bind,
491 .probe = bmips_cpu_probe,
492 .priv_auto = sizeof(struct bmips_cpu_priv),
493 .ops = &bmips_cpu_ops,
494 .flags = DM_FLAG_PRE_RELOC,
497 #ifdef CONFIG_DISPLAY_CPUINFO
498 int print_cpuinfo(void)
505 err = uclass_get_device(UCLASS_CPU, 0, &dev);
509 err = cpu_get_info(dev, &cpu);
513 err = cpu_get_desc(dev, desc, sizeof(desc));
517 printf("Chip ID: %s, MIPS: ", desc);
518 print_freq(cpu.cpu_freq, "\n");