devtree.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Based on reduced version of METAG
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/reboot.h>
  12. #include <linux/memblock.h>
  13. #include <linux/of.h>
  14. #include <linux/of_fdt.h>
  15. #include <asm/prom.h>
  16. #include <asm/clk.h>
  17. #include <asm/mach_desc.h>
  18. static const void * __init arch_get_next_mach(const char *const **match)
  19. {
  20. static const struct machine_desc *mdesc = __arch_info_begin;
  21. const struct machine_desc *m = mdesc;
  22. if (m >= __arch_info_end)
  23. return NULL;
  24. mdesc++;
  25. *match = m->dt_compat;
  26. return m;
  27. }
  28. /**
  29. * setup_machine_fdt - Machine setup when an dtb was passed to the kernel
  30. * @dt: virtual address pointer to dt blob
  31. *
  32. * If a dtb was passed to the kernel, then use it to choose the correct
  33. * machine_desc and to setup the system.
  34. */
  35. const struct machine_desc * __init setup_machine_fdt(void *dt)
  36. {
  37. const struct machine_desc *mdesc;
  38. unsigned long dt_root;
  39. void *clk;
  40. unsigned long len;
  41. if (!early_init_dt_scan(dt))
  42. return NULL;
  43. mdesc = of_flat_dt_match_machine(NULL, arch_get_next_mach);
  44. if (!mdesc)
  45. machine_halt();
  46. dt_root = of_get_flat_dt_root();
  47. clk = of_get_flat_dt_prop(dt_root, "clock-frequency", &len);
  48. if (clk)
  49. arc_set_core_freq(of_read_ulong(clk, len/4));
  50. return mdesc;
  51. }