setup.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Setup for the Realtek RTL838X SoC:
  4. * Memory, Timer and Serial
  5. *
  6. * Copyright (C) 2020 B. Koblitz
  7. * based on the original BSP by
  8. * Copyright (C) 2006-2012 Tony Wu ([email protected])
  9. *
  10. */
  11. #include <linux/console.h>
  12. #include <linux/init.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/clk.h>
  16. #include <linux/delay.h>
  17. #include <linux/of_fdt.h>
  18. #include <linux/irqchip.h>
  19. #include <asm/addrspace.h>
  20. #include <asm/io.h>
  21. #include <asm/bootinfo.h>
  22. #include <asm/time.h>
  23. #include <asm/prom.h>
  24. #include <asm/smp-ops.h>
  25. #include "mach-rtl83xx.h"
  26. extern struct rtl83xx_soc_info soc_info;
  27. void __init plat_mem_setup(void)
  28. {
  29. void *dtb;
  30. set_io_port_base(KSEG1);
  31. if (fw_passed_dtb) /* UHI interface */
  32. dtb = (void *)fw_passed_dtb;
  33. else if (&__dtb_start[0] != &__dtb_end[0])
  34. dtb = (void *)__dtb_start;
  35. else
  36. panic("no dtb found");
  37. /*
  38. * Load the devicetree. This causes the chosen node to be
  39. * parsed resulting in our memory appearing
  40. */
  41. __dt_setup_arch(dtb);
  42. }
  43. void plat_time_init_fallback(void)
  44. {
  45. struct device_node *np;
  46. u32 freq = 500000000;
  47. np = of_find_node_by_name(NULL, "cpus");
  48. if (!np) {
  49. pr_err("Missing 'cpus' DT node, using default frequency.");
  50. } else {
  51. if (of_property_read_u32(np, "frequency", &freq) < 0)
  52. pr_err("No 'frequency' property in DT, using default.");
  53. else
  54. pr_info("CPU frequency from device tree: %dMHz", freq / 1000000);
  55. of_node_put(np);
  56. }
  57. mips_hpt_frequency = freq / 2;
  58. }
  59. void __init plat_time_init(void)
  60. {
  61. /*
  62. * Initialization routine resembles generic MIPS plat_time_init() with
  63. * lazy error handling. The final fallback is only needed until we have
  64. * converted all device trees to new clock syntax.
  65. */
  66. struct device_node *np;
  67. struct clk *clk;
  68. of_clk_init(NULL);
  69. mips_hpt_frequency = 0;
  70. np = of_get_cpu_node(0, NULL);
  71. if (!np) {
  72. pr_err("Failed to get CPU node\n");
  73. } else {
  74. clk = of_clk_get(np, 0);
  75. if (IS_ERR(clk)) {
  76. pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk));
  77. } else {
  78. mips_hpt_frequency = clk_get_rate(clk) / 2;
  79. clk_put(clk);
  80. }
  81. }
  82. if (!mips_hpt_frequency)
  83. plat_time_init_fallback();
  84. timer_probe();
  85. }
  86. void __init arch_init_irq(void)
  87. {
  88. irqchip_init();
  89. }