devtree.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * Based on reduced version of METAG
  6. */
  7. #include <linux/init.h>
  8. #include <linux/reboot.h>
  9. #include <linux/memblock.h>
  10. #include <linux/of.h>
  11. #include <linux/of_fdt.h>
  12. #include <asm/mach_desc.h>
  13. #include <asm/serial.h>
  14. #ifdef CONFIG_SERIAL_EARLYCON
  15. static unsigned int __initdata arc_base_baud;
  16. unsigned int __init arc_early_base_baud(void)
  17. {
  18. return arc_base_baud/16;
  19. }
  20. static void __init arc_set_early_base_baud(unsigned long dt_root)
  21. {
  22. if (of_flat_dt_is_compatible(dt_root, "abilis,arc-tb10x"))
  23. arc_base_baud = 166666666; /* Fixed 166.6MHz clk (TB10x) */
  24. else if (of_flat_dt_is_compatible(dt_root, "snps,arc-sdp") ||
  25. of_flat_dt_is_compatible(dt_root, "snps,hsdk"))
  26. arc_base_baud = 33333333; /* Fixed 33MHz clk (AXS10x & HSDK) */
  27. else
  28. arc_base_baud = 50000000; /* Fixed default 50MHz */
  29. }
  30. #else
  31. #define arc_set_early_base_baud(dt_root)
  32. #endif
  33. static const void * __init arch_get_next_mach(const char *const **match)
  34. {
  35. static const struct machine_desc *mdesc = __arch_info_begin;
  36. const struct machine_desc *m = mdesc;
  37. if (m >= __arch_info_end)
  38. return NULL;
  39. mdesc++;
  40. *match = m->dt_compat;
  41. return m;
  42. }
  43. /**
  44. * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
  45. * @dt: virtual address pointer to dt blob
  46. *
  47. * If a dtb was passed to the kernel, then use it to choose the correct
  48. * machine_desc and to setup the system.
  49. */
  50. const struct machine_desc * __init setup_machine_fdt(void *dt)
  51. {
  52. const struct machine_desc *mdesc;
  53. unsigned long dt_root;
  54. if (!early_init_dt_scan(dt, __pa(dt)))
  55. return NULL;
  56. mdesc = of_flat_dt_match_machine(NULL, arch_get_next_mach);
  57. if (!mdesc)
  58. machine_halt();
  59. dt_root = of_get_flat_dt_root();
  60. arc_set_early_base_baud(dt_root);
  61. return mdesc;
  62. }