1 // SPDX-License-Identifier: GPL-2.0+
5 * Derived from linux/arch/mips/bcm63xx/cpu.c:
17 #define REV_CHIPID_SHIFT 16
18 #define REV_CHIPID_MASK (0xffff << REV_CHIPID_SHIFT)
19 #define REV_LONG_CHIPID_SHIFT 12
20 #define REV_LONG_CHIPID_MASK (0xfffff << REV_LONG_CHIPID_SHIFT)
21 #define REV_REVID_SHIFT 0
22 #define REV_REVID_MASK (0xff << REV_REVID_SHIFT)
24 #define REG_BCM6328_OTP 0x62c
25 #define BCM6328_TP1_DISABLED BIT(9)
27 #define REG_BCM6318_STRAP_OVRDBUS 0x900
28 #define OVRDBUS_6318_FREQ_SHIFT 23
29 #define OVRDBUS_6318_FREQ_MASK (0x3 << OVRDBUS_6318_FREQ_SHIFT)
31 #define REG_BCM6328_MISC_STRAPBUS 0x1a40
32 #define STRAPBUS_6328_FCVO_SHIFT 7
33 #define STRAPBUS_6328_FCVO_MASK (0x1f << STRAPBUS_6328_FCVO_SHIFT)
35 #define REG_BCM6348_PERF_MIPSPLLCFG 0x34
36 #define MIPSPLLCFG_6348_M1CPU_SHIFT 6
37 #define MIPSPLLCFG_6348_M1CPU_MASK (0x7 << MIPSPLLCFG_6348_M1CPU_SHIFT)
38 #define MIPSPLLCFG_6348_N2_SHIFT 15
39 #define MIPSPLLCFG_6348_N2_MASK (0x1F << MIPSPLLCFG_6348_N2_SHIFT)
40 #define MIPSPLLCFG_6348_N1_SHIFT 20
41 #define MIPSPLLCFG_6348_N1_MASK (0x7 << MIPSPLLCFG_6348_N1_SHIFT)
43 #define REG_BCM6358_DDR_DMIPSPLLCFG 0x12b8
44 #define DMIPSPLLCFG_6358_M1_SHIFT 0
45 #define DMIPSPLLCFG_6358_M1_MASK (0xff << DMIPSPLLCFG_6358_M1_SHIFT)
46 #define DMIPSPLLCFG_6358_N1_SHIFT 23
47 #define DMIPSPLLCFG_6358_N1_MASK (0x3f << DMIPSPLLCFG_6358_N1_SHIFT)
48 #define DMIPSPLLCFG_6358_N2_SHIFT 29
49 #define DMIPSPLLCFG_6358_N2_MASK (0x7 << DMIPSPLLCFG_6358_N2_SHIFT)
51 #define REG_BCM6362_MISC_STRAPBUS 0x1814
52 #define STRAPBUS_6362_FCVO_SHIFT 1
53 #define STRAPBUS_6362_FCVO_MASK (0x1f << STRAPBUS_6362_FCVO_SHIFT)
55 #define REG_BCM6368_DDR_DMIPSPLLCFG 0x12a0
56 #define DMIPSPLLCFG_6368_P1_SHIFT 0
57 #define DMIPSPLLCFG_6368_P1_MASK (0xf << DMIPSPLLCFG_6368_P1_SHIFT)
58 #define DMIPSPLLCFG_6368_P2_SHIFT 4
59 #define DMIPSPLLCFG_6368_P2_MASK (0xf << DMIPSPLLCFG_6368_P2_SHIFT)
60 #define DMIPSPLLCFG_6368_NDIV_SHIFT 16
61 #define DMIPSPLLCFG_6368_NDIV_MASK (0x1ff << DMIPSPLLCFG_6368_NDIV_SHIFT)
62 #define REG_BCM6368_DDR_DMIPSPLLDIV 0x12a4
63 #define DMIPSPLLDIV_6368_MDIV_SHIFT 0
64 #define DMIPSPLLDIV_6368_MDIV_MASK (0xff << DMIPSPLLDIV_6368_MDIV_SHIFT)
66 #define REG_BCM63268_MISC_STRAPBUS 0x1814
67 #define STRAPBUS_63268_FCVO_SHIFT 21
68 #define STRAPBUS_63268_FCVO_MASK (0xf << STRAPBUS_63268_FCVO_SHIFT)
70 #define REG_BCM6838_OTP_BRCMBITS0 0x440
71 #define VIPER_6838_FREQ_SHIFT 18
72 #define VIPER_6838_FREQ_MASK (0x7 << VIPER_6838_FREQ_SHIFT)
74 struct bmips_cpu_priv;
77 int (*get_cpu_desc)(struct bmips_cpu_priv *priv, char *buf, int size);
78 ulong (*get_cpu_freq)(struct bmips_cpu_priv *);
79 int (*get_cpu_count)(struct bmips_cpu_priv *);
82 struct bmips_cpu_priv {
84 const struct bmips_cpu_hw *hw;
87 /* Specific CPU Ops */
88 static int bmips_short_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
91 unsigned short cpu_id;
92 unsigned char cpu_rev;
95 val = readl_be(priv->regs);
96 cpu_id = (val & REV_CHIPID_MASK) >> REV_CHIPID_SHIFT;
97 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
99 snprintf(buf, size, "BCM%04X%02X", cpu_id, cpu_rev);
104 static int bmips_long_cpu_desc(struct bmips_cpu_priv *priv, char *buf,
108 unsigned char cpu_rev;
111 val = readl_be(priv->regs);
112 cpu_id = (val & REV_LONG_CHIPID_MASK) >> REV_LONG_CHIPID_SHIFT;
113 cpu_rev = (val & REV_REVID_MASK) >> REV_REVID_SHIFT;
115 snprintf(buf, size, "BCM%05X%02X", cpu_id, cpu_rev);
120 static ulong bcm3380_get_cpu_freq(struct bmips_cpu_priv *priv)
125 static ulong bcm6318_get_cpu_freq(struct bmips_cpu_priv *priv)
127 unsigned int mips_pll_fcvo;
129 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6318_STRAP_OVRDBUS);
130 mips_pll_fcvo = (mips_pll_fcvo & OVRDBUS_6318_FREQ_MASK)
131 >> OVRDBUS_6318_FREQ_SHIFT;
133 switch (mips_pll_fcvo) {
147 static ulong bcm6328_get_cpu_freq(struct bmips_cpu_priv *priv)
149 unsigned int mips_pll_fcvo;
151 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6328_MISC_STRAPBUS);
152 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6328_FCVO_MASK)
153 >> STRAPBUS_6328_FCVO_SHIFT;
155 switch (mips_pll_fcvo) {
174 static ulong bcm6338_get_cpu_freq(struct bmips_cpu_priv *priv)
179 static ulong bcm6348_get_cpu_freq(struct bmips_cpu_priv *priv)
181 unsigned int tmp, n1, n2, m1;
183 tmp = readl_be(priv->regs + REG_BCM6348_PERF_MIPSPLLCFG);
184 n1 = (tmp & MIPSPLLCFG_6348_N1_MASK) >> MIPSPLLCFG_6348_N1_SHIFT;
185 n2 = (tmp & MIPSPLLCFG_6348_N2_MASK) >> MIPSPLLCFG_6348_N2_SHIFT;
186 m1 = (tmp & MIPSPLLCFG_6348_M1CPU_MASK) >> MIPSPLLCFG_6348_M1CPU_SHIFT;
188 return (16 * 1000000 * (n1 + 1) * (n2 + 2)) / (m1 + 1);
191 static ulong bcm6358_get_cpu_freq(struct bmips_cpu_priv *priv)
193 unsigned int tmp, n1, n2, m1;
195 tmp = readl_be(priv->regs + REG_BCM6358_DDR_DMIPSPLLCFG);
196 n1 = (tmp & DMIPSPLLCFG_6358_N1_MASK) >> DMIPSPLLCFG_6358_N1_SHIFT;
197 n2 = (tmp & DMIPSPLLCFG_6358_N2_MASK) >> DMIPSPLLCFG_6358_N2_SHIFT;
198 m1 = (tmp & DMIPSPLLCFG_6358_M1_MASK) >> DMIPSPLLCFG_6358_M1_SHIFT;
200 return (16 * 1000000 * n1 * n2) / m1;
203 static ulong bcm6362_get_cpu_freq(struct bmips_cpu_priv *priv)
205 unsigned int mips_pll_fcvo;
207 mips_pll_fcvo = readl_be(priv->regs + REG_BCM6362_MISC_STRAPBUS);
208 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_6362_FCVO_MASK)
209 >> STRAPBUS_6362_FCVO_SHIFT;
211 switch (mips_pll_fcvo) {
241 static ulong bcm6368_get_cpu_freq(struct bmips_cpu_priv *priv)
243 unsigned int tmp, p1, p2, ndiv, m1;
245 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLCFG);
246 p1 = (tmp & DMIPSPLLCFG_6368_P1_MASK) >> DMIPSPLLCFG_6368_P1_SHIFT;
247 p2 = (tmp & DMIPSPLLCFG_6368_P2_MASK) >> DMIPSPLLCFG_6368_P2_SHIFT;
248 ndiv = (tmp & DMIPSPLLCFG_6368_NDIV_MASK) >>
249 DMIPSPLLCFG_6368_NDIV_SHIFT;
251 tmp = readl_be(priv->regs + REG_BCM6368_DDR_DMIPSPLLDIV);
252 m1 = (tmp & DMIPSPLLDIV_6368_MDIV_MASK) >> DMIPSPLLDIV_6368_MDIV_SHIFT;
254 return (((64 * 1000000) / p1) * p2 * ndiv) / m1;
257 static ulong bcm63268_get_cpu_freq(struct bmips_cpu_priv *priv)
259 unsigned int mips_pll_fcvo;
261 mips_pll_fcvo = readl_be(priv->regs + REG_BCM63268_MISC_STRAPBUS);
262 mips_pll_fcvo = (mips_pll_fcvo & STRAPBUS_63268_FCVO_MASK)
263 >> STRAPBUS_63268_FCVO_SHIFT;
265 switch (mips_pll_fcvo) {
280 static ulong bcm6838_get_cpu_freq(struct bmips_cpu_priv *priv)
282 unsigned int mips_viper_freq;
284 mips_viper_freq = readl_be(priv->regs + REG_BCM6838_OTP_BRCMBITS0);
285 mips_viper_freq = (mips_viper_freq & VIPER_6838_FREQ_MASK)
286 >> VIPER_6838_FREQ_SHIFT;
288 switch (mips_viper_freq) {
300 static int bcm6328_get_cpu_count(struct bmips_cpu_priv *priv)
302 u32 val = readl_be(priv->regs + REG_BCM6328_OTP);
304 if (val & BCM6328_TP1_DISABLED)
310 static int bcm6345_get_cpu_count(struct bmips_cpu_priv *priv)
315 static int bcm6358_get_cpu_count(struct bmips_cpu_priv *priv)
320 static const struct bmips_cpu_hw bmips_cpu_bcm3380 = {
321 .get_cpu_desc = bmips_short_cpu_desc,
322 .get_cpu_freq = bcm3380_get_cpu_freq,
323 .get_cpu_count = bcm6358_get_cpu_count,
326 static const struct bmips_cpu_hw bmips_cpu_bcm6318 = {
327 .get_cpu_desc = bmips_short_cpu_desc,
328 .get_cpu_freq = bcm6318_get_cpu_freq,
329 .get_cpu_count = bcm6345_get_cpu_count,
332 static const struct bmips_cpu_hw bmips_cpu_bcm6328 = {
333 .get_cpu_desc = bmips_long_cpu_desc,
334 .get_cpu_freq = bcm6328_get_cpu_freq,
335 .get_cpu_count = bcm6328_get_cpu_count,
338 static const struct bmips_cpu_hw bmips_cpu_bcm6338 = {
339 .get_cpu_desc = bmips_short_cpu_desc,
340 .get_cpu_freq = bcm6338_get_cpu_freq,
341 .get_cpu_count = bcm6345_get_cpu_count,
344 static const struct bmips_cpu_hw bmips_cpu_bcm6348 = {
345 .get_cpu_desc = bmips_short_cpu_desc,
346 .get_cpu_freq = bcm6348_get_cpu_freq,
347 .get_cpu_count = bcm6345_get_cpu_count,
350 static const struct bmips_cpu_hw bmips_cpu_bcm6358 = {
351 .get_cpu_desc = bmips_short_cpu_desc,
352 .get_cpu_freq = bcm6358_get_cpu_freq,
353 .get_cpu_count = bcm6358_get_cpu_count,
356 static const struct bmips_cpu_hw bmips_cpu_bcm6362 = {
357 .get_cpu_desc = bmips_short_cpu_desc,
358 .get_cpu_freq = bcm6362_get_cpu_freq,
359 .get_cpu_count = bcm6358_get_cpu_count,
362 static const struct bmips_cpu_hw bmips_cpu_bcm6368 = {
363 .get_cpu_desc = bmips_short_cpu_desc,
364 .get_cpu_freq = bcm6368_get_cpu_freq,
365 .get_cpu_count = bcm6358_get_cpu_count,
368 static const struct bmips_cpu_hw bmips_cpu_bcm63268 = {
369 .get_cpu_desc = bmips_long_cpu_desc,
370 .get_cpu_freq = bcm63268_get_cpu_freq,
371 .get_cpu_count = bcm6358_get_cpu_count,
374 static const struct bmips_cpu_hw bmips_cpu_bcm6838 = {
375 .get_cpu_desc = bmips_short_cpu_desc,
376 .get_cpu_freq = bcm6838_get_cpu_freq,
377 .get_cpu_count = bcm6358_get_cpu_count,
380 /* Generic CPU Ops */
381 static int bmips_cpu_get_desc(struct udevice *dev, char *buf, int size)
383 struct bmips_cpu_priv *priv = dev_get_priv(dev);
384 const struct bmips_cpu_hw *hw = priv->hw;
386 return hw->get_cpu_desc(priv, buf, size);
389 static int bmips_cpu_get_info(struct udevice *dev, struct cpu_info *info)
391 struct bmips_cpu_priv *priv = dev_get_priv(dev);
392 const struct bmips_cpu_hw *hw = priv->hw;
394 info->cpu_freq = hw->get_cpu_freq(priv);
395 info->features = BIT(CPU_FEAT_L1_CACHE);
396 info->features |= BIT(CPU_FEAT_MMU);
397 info->features |= BIT(CPU_FEAT_DEVICE_ID);
402 static int bmips_cpu_get_count(struct udevice *dev)
404 struct bmips_cpu_priv *priv = dev_get_priv(dev);
405 const struct bmips_cpu_hw *hw = priv->hw;
407 return hw->get_cpu_count(priv);
410 static int bmips_cpu_get_vendor(struct udevice *dev, char *buf, int size)
412 snprintf(buf, size, "Broadcom");
417 static const struct cpu_ops bmips_cpu_ops = {
418 .get_desc = bmips_cpu_get_desc,
419 .get_info = bmips_cpu_get_info,
420 .get_count = bmips_cpu_get_count,
421 .get_vendor = bmips_cpu_get_vendor,
424 /* BMIPS CPU driver */
425 int bmips_cpu_bind(struct udevice *dev)
427 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
429 plat->cpu_id = dev_read_u32_default(dev, "reg", -1);
430 plat->device_id = read_c0_prid();
435 int bmips_cpu_probe(struct udevice *dev)
437 struct bmips_cpu_priv *priv = dev_get_priv(dev);
438 const struct bmips_cpu_hw *hw =
439 (const struct bmips_cpu_hw *)dev_get_driver_data(dev);
441 priv->regs = dev_remap_addr(dev_get_parent(dev));
450 static const struct udevice_id bmips_cpu_ids[] = {
452 .compatible = "brcm,bcm3380-cpu",
453 .data = (ulong)&bmips_cpu_bcm3380,
455 .compatible = "brcm,bcm6318-cpu",
456 .data = (ulong)&bmips_cpu_bcm6318,
458 .compatible = "brcm,bcm6328-cpu",
459 .data = (ulong)&bmips_cpu_bcm6328,
461 .compatible = "brcm,bcm6338-cpu",
462 .data = (ulong)&bmips_cpu_bcm6338,
464 .compatible = "brcm,bcm6348-cpu",
465 .data = (ulong)&bmips_cpu_bcm6348,
467 .compatible = "brcm,bcm6358-cpu",
468 .data = (ulong)&bmips_cpu_bcm6358,
470 .compatible = "brcm,bcm6362-cpu",
471 .data = (ulong)&bmips_cpu_bcm6362,
473 .compatible = "brcm,bcm6368-cpu",
474 .data = (ulong)&bmips_cpu_bcm6368,
476 .compatible = "brcm,bcm63268-cpu",
477 .data = (ulong)&bmips_cpu_bcm63268,
479 .compatible = "brcm,bcm6838-cpu",
480 .data = (ulong)&bmips_cpu_bcm6838,
485 U_BOOT_DRIVER(bmips_cpu_drv) = {
488 .of_match = bmips_cpu_ids,
489 .bind = bmips_cpu_bind,
490 .probe = bmips_cpu_probe,
491 .priv_auto_alloc_size = sizeof(struct bmips_cpu_priv),
492 .ops = &bmips_cpu_ops,
493 .flags = DM_FLAG_PRE_RELOC,
496 #ifdef CONFIG_DISPLAY_CPUINFO
497 int print_cpuinfo(void)
504 err = uclass_get_device(UCLASS_CPU, 0, &dev);
508 err = cpu_get_info(dev, &cpu);
512 err = cpu_get_desc(dev, desc, sizeof(desc));
516 printf("Chip ID: %s, MIPS: ", desc);
517 print_freq(cpu.cpu_freq, "\n");