board-dt.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
  3. *
  4. * arch/arm/mach-kirkwood/board-dt.c
  5. *
  6. * Flattened Device Tree board initialization
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_net.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/clocksource.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/irqchip.h>
  22. #include <linux/kexec.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <mach/bridge-regs.h>
  26. #include <linux/platform_data/usb-ehci-orion.h>
  27. #include <plat/irq.h>
  28. #include <plat/common.h>
  29. #include "common.h"
  30. /*
  31. * There are still devices that doesn't know about DT yet. Get clock
  32. * gates here and add a clock lookup alias, so that old platform
  33. * devices still work.
  34. */
  35. static void __init kirkwood_legacy_clk_init(void)
  36. {
  37. struct device_node *np = of_find_compatible_node(
  38. NULL, NULL, "marvell,kirkwood-gating-clock");
  39. struct of_phandle_args clkspec;
  40. struct clk *clk;
  41. clkspec.np = np;
  42. clkspec.args_count = 1;
  43. /*
  44. * The ethernet interfaces forget the MAC address assigned by
  45. * u-boot if the clocks are turned off. Until proper DT support
  46. * is available we always enable them for now.
  47. */
  48. clkspec.args[0] = CGC_BIT_GE0;
  49. clk = of_clk_get_from_provider(&clkspec);
  50. clk_prepare_enable(clk);
  51. clkspec.args[0] = CGC_BIT_GE1;
  52. clk = of_clk_get_from_provider(&clkspec);
  53. clk_prepare_enable(clk);
  54. }
  55. #define MV643XX_ETH_MAC_ADDR_LOW 0x0414
  56. #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
  57. static void __init kirkwood_dt_eth_fixup(void)
  58. {
  59. struct device_node *np;
  60. /*
  61. * The ethernet interfaces forget the MAC address assigned by u-boot
  62. * if the clocks are turned off. Usually, u-boot on kirkwood boards
  63. * has no DT support to properly set local-mac-address property.
  64. * As a workaround, we get the MAC address from mv643xx_eth registers
  65. * and update the port device node if no valid MAC address is set.
  66. */
  67. for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
  68. struct device_node *pnp = of_get_parent(np);
  69. struct clk *clk;
  70. struct property *pmac;
  71. void __iomem *io;
  72. u8 *macaddr;
  73. u32 reg;
  74. if (!pnp)
  75. continue;
  76. /* skip disabled nodes or nodes with valid MAC address*/
  77. if (!of_device_is_available(pnp) || of_get_mac_address(np))
  78. goto eth_fixup_skip;
  79. clk = of_clk_get(pnp, 0);
  80. if (IS_ERR(clk))
  81. goto eth_fixup_skip;
  82. io = of_iomap(pnp, 0);
  83. if (!io)
  84. goto eth_fixup_no_map;
  85. /* ensure port clock is not gated to not hang CPU */
  86. clk_prepare_enable(clk);
  87. /* store MAC address register contents in local-mac-address */
  88. pr_err(FW_INFO "%s: local-mac-address is not set\n",
  89. np->full_name);
  90. pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
  91. if (!pmac)
  92. goto eth_fixup_no_mem;
  93. pmac->value = pmac + 1;
  94. pmac->length = 6;
  95. pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
  96. if (!pmac->name) {
  97. kfree(pmac);
  98. goto eth_fixup_no_mem;
  99. }
  100. macaddr = pmac->value;
  101. reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
  102. macaddr[0] = (reg >> 24) & 0xff;
  103. macaddr[1] = (reg >> 16) & 0xff;
  104. macaddr[2] = (reg >> 8) & 0xff;
  105. macaddr[3] = reg & 0xff;
  106. reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
  107. macaddr[4] = (reg >> 8) & 0xff;
  108. macaddr[5] = reg & 0xff;
  109. of_update_property(np, pmac);
  110. eth_fixup_no_mem:
  111. iounmap(io);
  112. clk_disable_unprepare(clk);
  113. eth_fixup_no_map:
  114. clk_put(clk);
  115. eth_fixup_skip:
  116. of_node_put(pnp);
  117. }
  118. }
  119. static void __init kirkwood_dt_time_init(void)
  120. {
  121. of_clk_init(NULL);
  122. clocksource_of_init();
  123. }
  124. static void __init kirkwood_dt_init(void)
  125. {
  126. pr_info("Kirkwood: %s, TCLK=%d.\n", kirkwood_id(), kirkwood_tclk);
  127. /*
  128. * Disable propagation of mbus errors to the CPU local bus,
  129. * as this causes mbus errors (which can occur for example
  130. * for PCI aborts) to throw CPU aborts, which we're not set
  131. * up to deal with.
  132. */
  133. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  134. BUG_ON(mvebu_mbus_dt_init());
  135. kirkwood_setup_wins();
  136. kirkwood_l2_init();
  137. kirkwood_cpufreq_init();
  138. kirkwood_cpuidle_init();
  139. /* Setup clocks for legacy devices */
  140. kirkwood_legacy_clk_init();
  141. kirkwood_pm_init();
  142. kirkwood_dt_eth_fixup();
  143. #ifdef CONFIG_KEXEC
  144. kexec_reinit = kirkwood_enable_pcie;
  145. #endif
  146. if (of_machine_is_compatible("marvell,mv88f6281gtw-ge"))
  147. mv88f6281gtw_ge_init();
  148. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  149. }
  150. static const char * const kirkwood_dt_board_compat[] = {
  151. "marvell,kirkwood",
  152. NULL
  153. };
  154. DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
  155. /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
  156. .map_io = kirkwood_map_io,
  157. .init_time = kirkwood_dt_time_init,
  158. .init_machine = kirkwood_dt_init,
  159. .restart = kirkwood_restart,
  160. .dt_compat = kirkwood_dt_board_compat,
  161. MACHINE_END