setup.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. void __init plat_mem_setup(void)
  52. {
  53. void *dtb;
  54. set_io_port_base(KSEG1);
  55. _machine_restart = rtl838x_restart;
  56. if (fw_passed_dtb) /* UHI interface */
  57. dtb = (void *)fw_passed_dtb;
  58. else if (__dtb_start != __dtb_end)
  59. dtb = (void *)__dtb_start;
  60. else
  61. panic("no dtb found");
  62. /*
  63. * Load the devicetree. This causes the chosen node to be
  64. * parsed resulting in our memory appearing
  65. */
  66. __dt_setup_arch(dtb);
  67. }
  68. void __init plat_time_init(void)
  69. {
  70. struct device_node *np;
  71. u32 freq = 500000000;
  72. np = of_find_node_by_name(NULL, "cpus");
  73. if (!np) {
  74. pr_err("Missing 'cpus' DT node, using default frequency.");
  75. } else {
  76. if (of_property_read_u32(np, "frequency", &freq) < 0)
  77. pr_err("No 'frequency' property in DT, using default.");
  78. else
  79. pr_info("CPU frequency from device tree: %d", freq);
  80. of_node_put(np);
  81. }
  82. mips_hpt_frequency = freq / 2;
  83. pll_reset_value = sw_r32(RTL838X_PLL_CML_CTRL);
  84. }