1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
5 * Derived from linux/arch/mips/bcm63xx/cpu.c:
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2009 Florian Fainelli <florian@openwrt.org>
16 #define REV_CHIPID_SHIFT 16
17 #define REV_CHIPID_MASK (0xffff << REV_CHIPID_SHIFT)
18 #define REV_LONG_CHIPID_SHIFT 12
19 #define REV_LONG_CHIPID_MASK (0xfffff << REV_LONG_CHIPID_SHIFT)
20 #define REV_REVID_SHIFT 0
21 #define REV_REVID_MASK (0xff << REV_REVID_SHIFT)
23 #define REG_BCM6328_OTP 0x62c
24 #define BCM6328_TP1_DISABLED BIT(9)
26 #define REG_BCM6318_STRAP_OVRDBUS 0x900
27 #define OVRDBUS_6318_FREQ_SHIFT 23
28 #define OVRDBUS_6318_FREQ_MASK (0x3 << OVRDBUS_6318_FREQ_SHIFT)
30 #define REG_BCM6328_MISC_STRAPBUS 0x1a40
31 #define STRAPBUS_6328_FCVO_SHIFT 7
32 #define STRAPBUS_6328_FCVO_MASK (0x1f << STRAPBUS_6328_FCVO_SHIFT)
34 #define REG_BCM6348_PERF_MIPSPLLCFG 0x34
35 #define MIPSPLLCFG_6348_M1CPU_SHIFT 6
36 #define MIPSPLLCFG_6348_M1CPU_MASK (0x7 << MIPSPLLCFG_6348_M1CPU_SHIFT)
37 #define MIPSPLLCFG_6348_N2_SHIFT 15
38 #define MIPSPLLCFG_6348_N2_MASK (0x1F << MIPSPLLCFG_6348_N2_SHIFT)
39 #define MIPSPLLCFG_6348_N1_SHIFT 20
40 #define MIPSPLLCFG_6348_N1_MASK (0x7 << MIPSPLLCFG_6348_N1_SHIFT)
42 #define REG_BCM6358_DDR_DMIPSPLLCFG 0x12b8
43 #define DMIPSPLLCFG_6358_M1_SHIFT 0
44 #define DMIPSPLLCFG_6358_M1_MASK (0xff << DMIPSPLLCFG_6358_M1_SHIFT)
45 #define DMIPSPLLCFG_6358_N1_SHIFT 23
46 #define DMIPSPLLCFG_6358_N1_MASK (0x3f << DMIPSPLLCFG_6358_N1_SHIFT)
47 #define DMIPSPLLCFG_6358_N2_SHIFT 29
48 #define DMIPSPLLCFG_6358_N2_MASK (0x7 << DMIPSPLLCFG_6358_N2_SHIFT)
50 #define REG_BCM6362_MISC_STRAPBUS 0x1814
51 #define STRAPBUS_6362_FCVO_SHIFT 1
52 #define STRAPBUS_6362_FCVO_MASK (0x1f << STRAPBUS_6362_FCVO_SHIFT)
54 #define REG_BCM6368_DDR_DMIPSPLLCFG 0x12a0
55 #define DMIPSPLLCFG_6368_P1_SHIFT 0
56 #define DMIPSPLLCFG_6368_P1_MASK (0xf << DMIPSPLLCFG_6368_P1_SHIFT)
57 #define DMIPSPLLCFG_6368_P2_SHIFT 4
58 #define DMIPSPLLCFG_6368_P2_MASK (0xf << DMIPSPLLCFG_6368_P2_SHIFT)
59 #define DMIPSPLLCFG_6368_NDIV_SHIFT 16
60 #define DMIPSPLLCFG_6368_NDIV_MASK (0x1ff << DMIPSPLLCFG_6368_NDIV_SHIFT)
61 #define REG_BCM6368_DDR_DMIPSPLLDIV 0x12a4
62 #define DMIPSPLLDIV_6368_MDIV_SHIFT 0
63 #define DMIPSPLLDIV_6368_MDIV_MASK (0xff << DMIPSPLLDIV_6368_MDIV_SHIFT)
65 #define REG_BCM63268_MISC_STRAPBUS 0x1814
66 #define STRAPBUS_63268_FCVO_SHIFT 21
67 #define STRAPBUS_63268_FCVO_MASK (0xf << STRAPBUS_63268_FCVO_SHIFT)
69 #define REG_BCM6838_OTP_BRCMBITS0 0x440
70 #define VIPER_6838_FREQ_SHIFT 18
71 #define VIPER_6838_FREQ_MASK (0x7 << VIPER_6838_FREQ_SHIFT)
73 struct bmips_cpu_priv;
76 int (*get_cpu_desc)(struct bmips_cpu_priv *priv, char *buf, int size);
77 ulong (*get_cpu_freq)(struct bmips_cpu_priv *);
78 int (*get_cpu_count)(struct bmips_cpu_priv *);
81 struct bmips_cpu_priv {
83 const struct bmips_cpu_hw *hw;
86 /* Specific CPU Ops */
87 static int bmips_short_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
90 unsigned short cpu_id;
91 unsigned char cpu_rev;
94 val = readl_be(priv->regs);
95 cpu_id = (val & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
96 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
98 snprintf(buf, size, "BCM%04X%02X", cpu_id, cpu_rev);
103 static int bmips_long_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
107 unsigned char cpu_rev;
110 val = readl_be(priv->regs);
111 cpu_id = (val & REV_LONG_CHIPID_MASK) >> REV_LONG_CHIPID_SHIFT;
112 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
114 snprintf(buf, size, "BCM%05X%02X", cpu_id, cpu_rev);
119 static ulong bcm3380_get_cpu_freq(struct bmips_cpu_priv *priv)
124 static ulong bcm6318_get_cpu_freq(struct bmips_cpu_priv *priv)
126 unsigned int mips_pll_fcvo;
128 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6318_STRAP_OVRDBUS);
129 mips_pll_fcvo = (mips_pll_fcvo & OVRDBUS_6318_FREQ_MASK)
130 >> OVRDBUS_6318_FREQ_SHIFT;
132 switch (mips_pll_fcvo) {
146 static ulong bcm6328_get_cpu_freq(struct bmips_cpu_priv *priv)
148 unsigned int mips_pll_fcvo;
150 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6328_MISC_STRAPBUS);
151 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6328_FCVO_MASK)
152 >> STRAPBUS_6328_FCVO_SHIFT;
154 switch (mips_pll_fcvo) {
173 static ulong bcm6338_get_cpu_freq(struct bmips_cpu_priv *priv)
178 static ulong bcm6348_get_cpu_freq(struct bmips_cpu_priv *priv)
180 unsigned int tmp, n1, n2, m1;
182 tmp = readl_be(priv->regs + REG_BCM6348_PERF_MIPSPLLCFG);
183 n1 = (tmp & MIPSPLLCFG_6348_N1_MASK) >> MIPSPLLCFG_6348_N1_SHIFT;
184 n2 = (tmp & MIPSPLLCFG_6348_N2_MASK) >> MIPSPLLCFG_6348_N2_SHIFT;
185 m1 = (tmp & MIPSPLLCFG_6348_M1CPU_MASK) >> MIPSPLLCFG_6348_M1CPU_SHIFT;
187 return (16 * 1000000 * (n1 + 1) * (n2 + 2)) / (m1 + 1);
190 static ulong bcm6358_get_cpu_freq(struct bmips_cpu_priv *priv)
192 unsigned int tmp, n1, n2, m1;
194 tmp = readl_be(priv->regs + REG_BCM6358_DDR_DMIPSPLLCFG);
195 n1 = (tmp & DMIPSPLLCFG_6358_N1_MASK) >> DMIPSPLLCFG_6358_N1_SHIFT;
196 n2 = (tmp & DMIPSPLLCFG_6358_N2_MASK) >> DMIPSPLLCFG_6358_N2_SHIFT;
197 m1 = (tmp & DMIPSPLLCFG_6358_M1_MASK) >> DMIPSPLLCFG_6358_M1_SHIFT;
199 return (16 * 1000000 * n1 * n2) / m1;
202 static ulong bcm6362_get_cpu_freq(struct bmips_cpu_priv *priv)
204 unsigned int mips_pll_fcvo;
206 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6362_MISC_STRAPBUS);
207 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6362_FCVO_MASK)
208 >> STRAPBUS_6362_FCVO_SHIFT;
210 switch (mips_pll_fcvo) {
240 static ulong bcm6368_get_cpu_freq(struct bmips_cpu_priv *priv)
242 unsigned int tmp, p1, p2, ndiv, m1;
244 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLCFG);
245 p1 = (tmp & DMIPSPLLCFG_6368_P1_MASK) >> DMIPSPLLCFG_6368_P1_SHIFT;
246 p2 = (tmp & DMIPSPLLCFG_6368_P2_MASK) >> DMIPSPLLCFG_6368_P2_SHIFT;
247 ndiv = (tmp & DMIPSPLLCFG_6368_NDIV_MASK) >>
248 DMIPSPLLCFG_6368_NDIV_SHIFT;
250 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLDIV);
251 m1 = (tmp & DMIPSPLLDIV_6368_MDIV_MASK) >> DMIPSPLLDIV_6368_MDIV_SHIFT;
253 return (((64 * 1000000) / p1) * p2 * ndiv) / m1;
256 static ulong bcm63268_get_cpu_freq(struct bmips_cpu_priv *priv)
258 unsigned int mips_pll_fcvo;
260 mips_pll_fcvo = readl_be(priv->regs + REG_BCM63268_MISC_STRAPBUS);
261 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_63268_FCVO_MASK)
262 >> STRAPBUS_63268_FCVO_SHIFT;
264 switch (mips_pll_fcvo) {
279 static ulong bcm6838_get_cpu_freq(struct bmips_cpu_priv *priv)
281 unsigned int mips_viper_freq;
283 mips_viper_freq = readl_be(priv->regs + REG_BCM6838_OTP_BRCMBITS0);
284 mips_viper_freq = (mips_viper_freq & VIPER_6838_FREQ_MASK)
285 >> VIPER_6838_FREQ_SHIFT;
287 switch (mips_viper_freq) {
299 static int bcm6328_get_cpu_count(struct bmips_cpu_priv *priv)
301 u32 val = readl_be(priv->regs + REG_BCM6328_OTP);
303 if (val & BCM6328_TP1_DISABLED)
309 static int bcm6345_get_cpu_count(struct bmips_cpu_priv *priv)
314 static int bcm6358_get_cpu_count(struct bmips_cpu_priv *priv)
319 static const struct bmips_cpu_hw bmips_cpu_bcm3380 = {
320 .get_cpu_desc = bmips_short_cpu_desc,
321 .get_cpu_freq = bcm3380_get_cpu_freq,
322 .get_cpu_count = bcm6358_get_cpu_count,
325 static const struct bmips_cpu_hw bmips_cpu_bcm6318 = {
326 .get_cpu_desc = bmips_short_cpu_desc,
327 .get_cpu_freq = bcm6318_get_cpu_freq,
328 .get_cpu_count = bcm6345_get_cpu_count,
331 static const struct bmips_cpu_hw bmips_cpu_bcm6328 = {
332 .get_cpu_desc = bmips_long_cpu_desc,
333 .get_cpu_freq = bcm6328_get_cpu_freq,
334 .get_cpu_count = bcm6328_get_cpu_count,
337 static const struct bmips_cpu_hw bmips_cpu_bcm6338 = {
338 .get_cpu_desc = bmips_short_cpu_desc,
339 .get_cpu_freq = bcm6338_get_cpu_freq,
340 .get_cpu_count = bcm6345_get_cpu_count,
343 static const struct bmips_cpu_hw bmips_cpu_bcm6348 = {
344 .get_cpu_desc = bmips_short_cpu_desc,
345 .get_cpu_freq = bcm6348_get_cpu_freq,
346 .get_cpu_count = bcm6345_get_cpu_count,
349 static const struct bmips_cpu_hw bmips_cpu_bcm6358 = {
350 .get_cpu_desc = bmips_short_cpu_desc,
351 .get_cpu_freq = bcm6358_get_cpu_freq,
352 .get_cpu_count = bcm6358_get_cpu_count,
355 static const struct bmips_cpu_hw bmips_cpu_bcm6362 = {
356 .get_cpu_desc = bmips_short_cpu_desc,
357 .get_cpu_freq = bcm6362_get_cpu_freq,
358 .get_cpu_count = bcm6358_get_cpu_count,
361 static const struct bmips_cpu_hw bmips_cpu_bcm6368 = {
362 .get_cpu_desc = bmips_short_cpu_desc,
363 .get_cpu_freq = bcm6368_get_cpu_freq,
364 .get_cpu_count = bcm6358_get_cpu_count,
367 static const struct bmips_cpu_hw bmips_cpu_bcm63268 = {
368 .get_cpu_desc = bmips_long_cpu_desc,
369 .get_cpu_freq = bcm63268_get_cpu_freq,
370 .get_cpu_count = bcm6358_get_cpu_count,
373 static const struct bmips_cpu_hw bmips_cpu_bcm6838 = {
374 .get_cpu_desc = bmips_short_cpu_desc,
375 .get_cpu_freq = bcm6838_get_cpu_freq,
376 .get_cpu_count = bcm6358_get_cpu_count,
379 /* Generic CPU Ops */
380 static int bmips_cpu_get_desc(struct udevice *dev, char *buf, int size)
382 struct bmips_cpu_priv *priv = dev_get_priv(dev);
383 const struct bmips_cpu_hw *hw = priv->hw;
385 return hw->get_cpu_desc(priv, buf, size);
388 static int bmips_cpu_get_info(struct udevice *dev, struct cpu_info *info)
390 struct bmips_cpu_priv *priv = dev_get_priv(dev);
391 const struct bmips_cpu_hw *hw = priv->hw;
393 info->cpu_freq = hw->get_cpu_freq(priv);
394 info->features = BIT(CPU_FEAT_L1_CACHE);
395 info->features |= BIT(CPU_FEAT_MMU);
396 info->features |= BIT(CPU_FEAT_DEVICE_ID);
401 static int bmips_cpu_get_count(struct udevice *dev)
403 struct bmips_cpu_priv *priv = dev_get_priv(dev);
404 const struct bmips_cpu_hw *hw = priv->hw;
406 return hw->get_cpu_count(priv);
409 static int bmips_cpu_get_vendor(struct udevice *dev, char *buf, int size)
411 snprintf(buf, size, "Broadcom");
416 static const struct cpu_ops bmips_cpu_ops = {
417 .get_desc = bmips_cpu_get_desc,
418 .get_info = bmips_cpu_get_info,
419 .get_count = bmips_cpu_get_count,
420 .get_vendor = bmips_cpu_get_vendor,
423 /* BMIPS CPU driver */
424 int bmips_cpu_bind(struct udevice *dev)
426 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
428 plat->cpu_id = dev_read_u32_default(dev, "reg", -1);
429 plat->device_id = read_c0_prid();
434 int bmips_cpu_probe(struct udevice *dev)
436 struct bmips_cpu_priv *priv = dev_get_priv(dev);
437 const struct bmips_cpu_hw *hw =
438 (const struct bmips_cpu_hw *)dev_get_driver_data(dev);
440 priv->regs = dev_remap_addr(dev_get_parent(dev));
449 static const struct udevice_id bmips_cpu_ids[] = {
451 .compatible = "brcm,bcm3380-cpu",
452 .data = (ulong)&bmips_cpu_bcm3380,
454 .compatible = "brcm,bcm6318-cpu",
455 .data = (ulong)&bmips_cpu_bcm6318,
457 .compatible = "brcm,bcm6328-cpu",
458 .data = (ulong)&bmips_cpu_bcm6328,
460 .compatible = "brcm,bcm6338-cpu",
461 .data = (ulong)&bmips_cpu_bcm6338,
463 .compatible = "brcm,bcm6348-cpu",
464 .data = (ulong)&bmips_cpu_bcm6348,
466 .compatible = "brcm,bcm6358-cpu",
467 .data = (ulong)&bmips_cpu_bcm6358,
469 .compatible = "brcm,bcm6362-cpu",
470 .data = (ulong)&bmips_cpu_bcm6362,
472 .compatible = "brcm,bcm6368-cpu",
473 .data = (ulong)&bmips_cpu_bcm6368,
475 .compatible = "brcm,bcm63268-cpu",
476 .data = (ulong)&bmips_cpu_bcm63268,
478 .compatible = "brcm,bcm6838-cpu",
479 .data = (ulong)&bmips_cpu_bcm6838,
484 U_BOOT_DRIVER(bmips_cpu_drv) = {
487 .of_match = bmips_cpu_ids,
488 .bind = bmips_cpu_bind,
489 .probe = bmips_cpu_probe,
490 .priv_auto_alloc_size = sizeof(struct bmips_cpu_priv),
491 .ops = &bmips_cpu_ops,
492 .flags = DM_FLAG_PRE_RELOC,
495 #ifdef CONFIG_DISPLAY_CPUINFO
496 int print_cpuinfo(void)
503 err = uclass_get_device(UCLASS_CPU, 0, &dev);
507 err = cpu_get_info(dev, &cpu);
511 err = cpu_get_desc(dev, desc, sizeof(desc));
515 printf("Chip ID: %s, MIPS: ", desc);
516 print_freq(cpu.cpu_freq, "\n");