cpu.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <cpu.h>
  9. #include <dm.h>
  10. #include <errno.h>
  11. #include <asm/cache.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. #ifdef CONFIG_DISPLAY_CPUINFO
  14. int print_cpuinfo(void)
  15. {
  16. printf("CPU: Nios-II\n");
  17. return 0;
  18. }
  19. #endif /* CONFIG_DISPLAY_CPUINFO */
  20. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  21. {
  22. disable_interrupts();
  23. /* indirect call to go beyond 256MB limitation of toolchain */
  24. nios2_callr(CONFIG_SYS_RESET_ADDR);
  25. return 0;
  26. }
  27. int dcache_status(void)
  28. {
  29. return 1;
  30. }
  31. void dcache_enable(void)
  32. {
  33. flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
  34. }
  35. void dcache_disable(void)
  36. {
  37. flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
  38. }
  39. int arch_cpu_init_dm(void)
  40. {
  41. struct udevice *dev;
  42. int ret;
  43. ret = uclass_first_device(UCLASS_CPU, &dev);
  44. if (ret)
  45. return ret;
  46. if (!dev)
  47. return -ENODEV;
  48. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  49. return 0;
  50. }
  51. static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
  52. {
  53. const char *cpu_name = "Nios-II";
  54. if (size < strlen(cpu_name))
  55. return -ENOSPC;
  56. strcpy(buf, cpu_name);
  57. return 0;
  58. }
  59. static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
  60. {
  61. info->cpu_freq = gd->cpu_clk;
  62. info->features = (1 << CPU_FEAT_L1_CACHE) |
  63. (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
  64. return 0;
  65. }
  66. static int altera_nios2_get_count(struct udevice *dev)
  67. {
  68. return 1;
  69. }
  70. static int altera_nios2_probe(struct udevice *dev)
  71. {
  72. const void *blob = gd->fdt_blob;
  73. int node = dev->of_offset;
  74. gd->cpu_clk = fdtdec_get_int(blob, node,
  75. "clock-frequency", 0);
  76. gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
  77. "dcache-line-size", 0);
  78. gd->arch.icache_line_size = fdtdec_get_int(blob, node,
  79. "icache-line-size", 0);
  80. gd->arch.dcache_size = fdtdec_get_int(blob, node,
  81. "dcache-size", 0);
  82. gd->arch.icache_size = fdtdec_get_int(blob, node,
  83. "icache-size", 0);
  84. gd->arch.reset_addr = fdtdec_get_int(blob, node,
  85. "altr,reset-addr", 0);
  86. gd->arch.exception_addr = fdtdec_get_int(blob, node,
  87. "altr,exception-addr", 0);
  88. gd->arch.has_initda = fdtdec_get_int(blob, node,
  89. "altr,has-initda", 0);
  90. gd->arch.has_mmu = fdtdec_get_int(blob, node,
  91. "altr,has-mmu", 0);
  92. gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
  93. return 0;
  94. }
  95. static const struct cpu_ops altera_nios2_ops = {
  96. .get_desc = altera_nios2_get_desc,
  97. .get_info = altera_nios2_get_info,
  98. .get_count = altera_nios2_get_count,
  99. };
  100. static const struct udevice_id altera_nios2_ids[] = {
  101. { .compatible = "altr,nios2-1.0" },
  102. { .compatible = "altr,nios2-1.1" },
  103. { }
  104. };
  105. U_BOOT_DRIVER(altera_nios2) = {
  106. .name = "altera_nios2",
  107. .id = UCLASS_CPU,
  108. .of_match = altera_nios2_ids,
  109. .probe = altera_nios2_probe,
  110. .ops = &altera_nios2_ops,
  111. .flags = DM_FLAG_PRE_RELOC,
  112. };