setup.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/clk.h>
  14. #include <linux/clkdev.h>
  15. #include <linux/clk-provider.h>
  16. #include <asm/addrspace.h>
  17. #include <asm/io.h>
  18. #include <asm/bootinfo.h>
  19. #include <linux/of_fdt.h>
  20. #include <asm/reboot.h>
  21. #include <asm/time.h> /* for mips_hpt_frequency */
  22. #include <asm/prom.h>
  23. #include <asm/smp-ops.h>
  24. #include "mach-rtl83xx.h"
  25. extern int rtl838x_serial_init(void);
  26. extern struct rtl83xx_soc_info soc_info;
  27. u32 pll_reset_value;
  28. static void rtl838x_restart(char *command)
  29. {
  30. u32 pll = sw_r32(RTL838X_PLL_CML_CTRL);
  31. /* SoC reset vector (in flash memory): on RTL839x platform preferred way to reset */
  32. void (*f)(void) = (void *) 0xbfc00000;
  33. pr_info("System restart.\n");
  34. if (soc_info.family == RTL8390_FAMILY_ID) {
  35. f();
  36. /* If calling reset vector fails, reset entire chip */
  37. sw_w32(0xFFFFFFFF, RTL839X_RST_GLB_CTRL);
  38. /* If this fails, halt the CPU */
  39. while
  40. (1);
  41. }
  42. pr_info("PLL control register: %x, applying reset value %x\n",
  43. pll, pll_reset_value);
  44. sw_w32(3, RTL838X_INT_RW_CTRL);
  45. sw_w32(pll_reset_value, RTL838X_PLL_CML_CTRL);
  46. sw_w32(0, RTL838X_INT_RW_CTRL);
  47. pr_info("Resetting RTL838X SoC\n");
  48. /* Reset Global Control1 Register */
  49. sw_w32(1, RTL838X_RST_GLB_CTRL_1);
  50. }
  51. static void rtl838x_halt(void)
  52. {
  53. pr_info("System halted.\n");
  54. while(1);
  55. }
  56. void __init plat_mem_setup(void)
  57. {
  58. void *dtb;
  59. set_io_port_base(KSEG1);
  60. _machine_restart = rtl838x_restart;
  61. _machine_halt = rtl838x_halt;
  62. if (fw_passed_dtb) /* UHI interface */
  63. dtb = (void *)fw_passed_dtb;
  64. else if (__dtb_start != __dtb_end)
  65. dtb = (void *)__dtb_start;
  66. else
  67. panic("no dtb found");
  68. /*
  69. * Load the devicetree. This causes the chosen node to be
  70. * parsed resulting in our memory appearing
  71. */
  72. __dt_setup_arch(dtb);
  73. }
  74. void __init plat_time_init(void)
  75. {
  76. struct device_node *np;
  77. u32 freq = 500000000;
  78. np = of_find_node_by_name(NULL, "cpus");
  79. if (!np) {
  80. pr_err("Missing 'cpus' DT node, using default frequency.");
  81. } else {
  82. if (of_property_read_u32(np, "frequency", &freq) < 0)
  83. pr_err("No 'frequency' property in DT, using default.");
  84. else
  85. pr_info("CPU frequency from device tree: %d", freq);
  86. of_node_put(np);
  87. }
  88. mips_hpt_frequency = freq / 2;
  89. pll_reset_value = sw_r32(RTL838X_PLL_CML_CTRL);
  90. }