board-dt.c 4.7 KB

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