cpu.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <ram.h>
  8. #include <asm/io.h>
  9. #include <linux/io.h>
  10. #include <linux/sizes.h>
  11. #include "mt76xx.h"
  12. #define STR_LEN 6
  13. #ifdef CONFIG_BOOT_ROM
  14. int mach_cpu_init(void)
  15. {
  16. ddr_calibrate();
  17. return 0;
  18. }
  19. #endif
  20. int dram_init(void)
  21. {
  22. gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, SZ_256M);
  23. return 0;
  24. }
  25. int print_cpuinfo(void)
  26. {
  27. static const char * const boot_str[] = { "PLL (3-Byte SPI Addr)",
  28. "PLL (4-Byte SPI Addr)",
  29. "XTAL (3-Byte SPI Addr)",
  30. "XTAL (4-Byte SPI Addr)" };
  31. const void *blob = gd->fdt_blob;
  32. void __iomem *sysc_base;
  33. char buf[STR_LEN + 1];
  34. fdt_addr_t base;
  35. fdt_size_t size;
  36. char *str;
  37. int node;
  38. u32 val;
  39. /* Get system controller base address */
  40. node = fdt_node_offset_by_compatible(blob, -1, "ralink,mt7620a-sysc");
  41. if (node < 0)
  42. return -FDT_ERR_NOTFOUND;
  43. base = fdtdec_get_addr_size_auto_noparent(blob, node, "reg",
  44. 0, &size, true);
  45. if (base == FDT_ADDR_T_NONE)
  46. return -EINVAL;
  47. sysc_base = ioremap_nocache(base, size);
  48. str = (char *)sysc_base + MT76XX_CHIPID_OFFS;
  49. snprintf(buf, STR_LEN + 1, "%s", str);
  50. val = readl(sysc_base + MT76XX_CHIP_REV_ID_OFFS);
  51. printf("CPU: %-*s Rev %ld.%ld - ", STR_LEN, buf,
  52. (val & GENMASK(11, 8)) >> 8, val & GENMASK(3, 0));
  53. val = (readl(sysc_base + MT76XX_SYSCFG0_OFFS) & GENMASK(3, 1)) >> 1;
  54. printf("Boot from %s\n", boot_str[val]);
  55. return 0;
  56. }