setup.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/delay.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/irqchip.h>
  18. #include <asm/addrspace.h>
  19. #include <asm/io.h>
  20. #include <asm/bootinfo.h>
  21. #include <asm/time.h>
  22. #include <asm/prom.h>
  23. #include <asm/smp-ops.h>
  24. #include "mach-rtl83xx.h"
  25. extern struct rtl83xx_soc_info soc_info;
  26. static void __init rtl838x_setup(void)
  27. {
  28. /* Setup System LED. Bit 15 then allows to toggle it */
  29. sw_w32_mask(0, 3 << 16, RTL838X_LED_GLB_CTRL);
  30. }
  31. static void __init rtl839x_setup(void)
  32. {
  33. /* Setup System LED. Bit 14 of RTL839X_LED_GLB_CTRL then allows to toggle it */
  34. sw_w32_mask(0, 3 << 15, RTL839X_LED_GLB_CTRL);
  35. }
  36. static void __init rtl930x_setup(void)
  37. {
  38. if (soc_info.id == 0x9302)
  39. sw_w32_mask(0, 3 << 13, RTL9302_LED_GLB_CTRL);
  40. else
  41. sw_w32_mask(0, 3 << 13, RTL930X_LED_GLB_CTRL);
  42. }
  43. static void __init rtl931x_setup(void)
  44. {
  45. sw_w32_mask(0, 3 << 12, RTL931X_LED_GLB_CTRL);
  46. }
  47. void __init plat_mem_setup(void)
  48. {
  49. void *dtb;
  50. set_io_port_base(KSEG1);
  51. if (fw_passed_dtb) /* UHI interface */
  52. dtb = (void *)fw_passed_dtb;
  53. else if (&__dtb_start[0] != &__dtb_end[0])
  54. dtb = (void *)__dtb_start;
  55. else
  56. panic("no dtb found");
  57. /*
  58. * Load the devicetree. This causes the chosen node to be
  59. * parsed resulting in our memory appearing
  60. */
  61. __dt_setup_arch(dtb);
  62. switch (soc_info.family) {
  63. case RTL8380_FAMILY_ID:
  64. rtl838x_setup();
  65. break;
  66. case RTL8390_FAMILY_ID:
  67. rtl839x_setup();
  68. break;
  69. case RTL9300_FAMILY_ID:
  70. rtl930x_setup();
  71. break;
  72. case RTL9310_FAMILY_ID:
  73. rtl931x_setup();
  74. break;
  75. }
  76. }
  77. void __init plat_time_init(void)
  78. {
  79. struct device_node *np;
  80. u32 freq = 500000000;
  81. of_clk_init(NULL);
  82. timer_probe();
  83. np = of_find_node_by_name(NULL, "cpus");
  84. if (!np) {
  85. pr_err("Missing 'cpus' DT node, using default frequency.");
  86. } else {
  87. if (of_property_read_u32(np, "frequency", &freq) < 0)
  88. pr_err("No 'frequency' property in DT, using default.");
  89. else
  90. pr_info("CPU frequency from device tree: %dMHz", freq / 1000000);
  91. of_node_put(np);
  92. }
  93. mips_hpt_frequency = freq / 2;
  94. }
  95. void __init arch_init_irq(void)
  96. {
  97. irqchip_init();
  98. }