0006-MIPS-ralink-adds-OF-code.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. From 4b2f9abbbaf3463a0fc1a65afeb0d12f890ada35 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <[email protected]>
  3. Date: Sun, 20 Jan 2013 22:02:01 +0100
  4. Subject: [PATCH 06/79] MIPS: ralink: adds OF code
  5. Until there is a generic MIPS way of handing the DTB over from bootloader to
  6. kernel we rely on a built in devicetrees. The OF code also remaps those register
  7. ranges that we use global in our drivers.
  8. Signed-off-by: John Crispin <[email protected]>
  9. Signed-off-by: Gabor Juhos <[email protected]>
  10. Patchwork: http://patchwork.linux-mips.org/patch/4895/
  11. ---
  12. arch/mips/ralink/of.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
  13. 1 file changed, 107 insertions(+)
  14. create mode 100644 arch/mips/ralink/of.c
  15. diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
  16. new file mode 100644
  17. index 0000000..4165e70
  18. --- /dev/null
  19. +++ b/arch/mips/ralink/of.c
  20. @@ -0,0 +1,107 @@
  21. +/*
  22. + * This program is free software; you can redistribute it and/or modify it
  23. + * under the terms of the GNU General Public License version 2 as published
  24. + * by the Free Software Foundation.
  25. + *
  26. + * Copyright (C) 2008 Imre Kaloz <[email protected]>
  27. + * Copyright (C) 2008-2009 Gabor Juhos <[email protected]>
  28. + * Copyright (C) 2013 John Crispin <[email protected]>
  29. + */
  30. +
  31. +#include <linux/io.h>
  32. +#include <linux/clk.h>
  33. +#include <linux/init.h>
  34. +#include <linux/of_fdt.h>
  35. +#include <linux/kernel.h>
  36. +#include <linux/bootmem.h>
  37. +#include <linux/of_platform.h>
  38. +#include <linux/of_address.h>
  39. +
  40. +#include <asm/reboot.h>
  41. +#include <asm/bootinfo.h>
  42. +#include <asm/addrspace.h>
  43. +
  44. +#include "common.h"
  45. +
  46. +__iomem void *rt_sysc_membase;
  47. +__iomem void *rt_memc_membase;
  48. +
  49. +extern struct boot_param_header __dtb_start;
  50. +
  51. +__iomem void *plat_of_remap_node(const char *node)
  52. +{
  53. + struct resource res;
  54. + struct device_node *np;
  55. +
  56. + np = of_find_compatible_node(NULL, NULL, node);
  57. + if (!np)
  58. + panic("Failed to find %s node", node);
  59. +
  60. + if (of_address_to_resource(np, 0, &res))
  61. + panic("Failed to get resource for %s", node);
  62. +
  63. + if ((request_mem_region(res.start,
  64. + resource_size(&res),
  65. + res.name) < 0))
  66. + panic("Failed to request resources for %s", node);
  67. +
  68. + return ioremap_nocache(res.start, resource_size(&res));
  69. +}
  70. +
  71. +void __init device_tree_init(void)
  72. +{
  73. + unsigned long base, size;
  74. + void *fdt_copy;
  75. +
  76. + if (!initial_boot_params)
  77. + return;
  78. +
  79. + base = virt_to_phys((void *)initial_boot_params);
  80. + size = be32_to_cpu(initial_boot_params->totalsize);
  81. +
  82. + /* Before we do anything, lets reserve the dt blob */
  83. + reserve_bootmem(base, size, BOOTMEM_DEFAULT);
  84. +
  85. + /* The strings in the flattened tree are referenced directly by the
  86. + * device tree, so copy the flattened device tree from init memory
  87. + * to regular memory.
  88. + */
  89. + fdt_copy = alloc_bootmem(size);
  90. + memcpy(fdt_copy, initial_boot_params, size);
  91. + initial_boot_params = fdt_copy;
  92. +
  93. + unflatten_device_tree();
  94. +
  95. + /* free the space reserved for the dt blob */
  96. + free_bootmem(base, size);
  97. +}
  98. +
  99. +void __init plat_mem_setup(void)
  100. +{
  101. + set_io_port_base(KSEG1);
  102. +
  103. + /*
  104. + * Load the builtin devicetree. This causes the chosen node to be
  105. + * parsed resulting in our memory appearing
  106. + */
  107. + __dt_setup_arch(&__dtb_start);
  108. +}
  109. +
  110. +static int __init plat_of_setup(void)
  111. +{
  112. + static struct of_device_id of_ids[3];
  113. + int len = sizeof(of_ids[0].compatible);
  114. +
  115. + if (!of_have_populated_dt())
  116. + panic("device tree not present");
  117. +
  118. + strncpy(of_ids[0].compatible, soc_info.compatible, len);
  119. + strncpy(of_ids[1].compatible, "palmbus", len);
  120. +
  121. + if (of_platform_populate(NULL, of_ids, NULL, NULL))
  122. + panic("failed to populate DT\n");
  123. +
  124. + return 0;
  125. +}
  126. +
  127. +arch_initcall(plat_of_setup);
  128. --
  129. 1.7.10.4