kirkwood.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright 2012 (C), Jason Cooper <jason@lakedaemon.net>
  3. *
  4. * arch/arm/mach-mvebu/kirkwood.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/clk.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/mbus.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_net.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/slab.h>
  21. #include <asm/hardware/cache-feroceon-l2.h>
  22. #include <asm/mach/arch.h>
  23. #include <asm/mach/map.h>
  24. #include "kirkwood.h"
  25. #include "kirkwood-pm.h"
  26. #include "common.h"
  27. #include "board.h"
  28. static struct resource kirkwood_cpufreq_resources[] = {
  29. [0] = {
  30. .start = CPU_CONTROL_PHYS,
  31. .end = CPU_CONTROL_PHYS + 3,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. };
  35. static struct platform_device kirkwood_cpufreq_device = {
  36. .name = "kirkwood-cpufreq",
  37. .id = -1,
  38. .num_resources = ARRAY_SIZE(kirkwood_cpufreq_resources),
  39. .resource = kirkwood_cpufreq_resources,
  40. };
  41. static void __init kirkwood_cpufreq_init(void)
  42. {
  43. platform_device_register(&kirkwood_cpufreq_device);
  44. }
  45. static struct resource kirkwood_cpuidle_resource[] = {
  46. {
  47. .flags = IORESOURCE_MEM,
  48. .start = DDR_OPERATION_BASE,
  49. .end = DDR_OPERATION_BASE + 3,
  50. },
  51. };
  52. static struct platform_device kirkwood_cpuidle = {
  53. .name = "kirkwood_cpuidle",
  54. .id = -1,
  55. .resource = kirkwood_cpuidle_resource,
  56. .num_resources = 1,
  57. };
  58. static void __init kirkwood_cpuidle_init(void)
  59. {
  60. platform_device_register(&kirkwood_cpuidle);
  61. }
  62. #define MV643XX_ETH_MAC_ADDR_LOW 0x0414
  63. #define MV643XX_ETH_MAC_ADDR_HIGH 0x0418
  64. static void __init kirkwood_dt_eth_fixup(void)
  65. {
  66. struct device_node *np;
  67. /*
  68. * The ethernet interfaces forget the MAC address assigned by u-boot
  69. * if the clocks are turned off. Usually, u-boot on kirkwood boards
  70. * has no DT support to properly set local-mac-address property.
  71. * As a workaround, we get the MAC address from mv643xx_eth registers
  72. * and update the port device node if no valid MAC address is set.
  73. */
  74. for_each_compatible_node(np, NULL, "marvell,kirkwood-eth-port") {
  75. struct device_node *pnp = of_get_parent(np);
  76. struct clk *clk;
  77. struct property *pmac;
  78. void __iomem *io;
  79. u8 *macaddr;
  80. u32 reg;
  81. if (!pnp)
  82. continue;
  83. /* skip disabled nodes or nodes with valid MAC address*/
  84. if (!of_device_is_available(pnp) || of_get_mac_address(np))
  85. goto eth_fixup_skip;
  86. clk = of_clk_get(pnp, 0);
  87. if (IS_ERR(clk))
  88. goto eth_fixup_skip;
  89. io = of_iomap(pnp, 0);
  90. if (!io)
  91. goto eth_fixup_no_map;
  92. /* ensure port clock is not gated to not hang CPU */
  93. clk_prepare_enable(clk);
  94. /* store MAC address register contents in local-mac-address */
  95. pr_err(FW_INFO "%s: local-mac-address is not set\n",
  96. np->full_name);
  97. pmac = kzalloc(sizeof(*pmac) + 6, GFP_KERNEL);
  98. if (!pmac)
  99. goto eth_fixup_no_mem;
  100. pmac->value = pmac + 1;
  101. pmac->length = 6;
  102. pmac->name = kstrdup("local-mac-address", GFP_KERNEL);
  103. if (!pmac->name) {
  104. kfree(pmac);
  105. goto eth_fixup_no_mem;
  106. }
  107. macaddr = pmac->value;
  108. reg = readl(io + MV643XX_ETH_MAC_ADDR_HIGH);
  109. macaddr[0] = (reg >> 24) & 0xff;
  110. macaddr[1] = (reg >> 16) & 0xff;
  111. macaddr[2] = (reg >> 8) & 0xff;
  112. macaddr[3] = reg & 0xff;
  113. reg = readl(io + MV643XX_ETH_MAC_ADDR_LOW);
  114. macaddr[4] = (reg >> 8) & 0xff;
  115. macaddr[5] = reg & 0xff;
  116. of_update_property(np, pmac);
  117. eth_fixup_no_mem:
  118. iounmap(io);
  119. clk_disable_unprepare(clk);
  120. eth_fixup_no_map:
  121. clk_put(clk);
  122. eth_fixup_skip:
  123. of_node_put(pnp);
  124. }
  125. }
  126. /*
  127. * Disable propagation of mbus errors to the CPU local bus, as this
  128. * causes mbus errors (which can occur for example for PCI aborts) to
  129. * throw CPU aborts, which we're not set up to deal with.
  130. */
  131. void kirkwood_disable_mbus_error_propagation(void)
  132. {
  133. void __iomem *cpu_config;
  134. cpu_config = ioremap(CPU_CONFIG_PHYS, 4);
  135. writel(readl(cpu_config) & ~CPU_CONFIG_ERROR_PROP, cpu_config);
  136. }
  137. static struct of_dev_auxdata auxdata[] __initdata = {
  138. OF_DEV_AUXDATA("marvell,kirkwood-audio", 0xf10a0000,
  139. "mvebu-audio", NULL),
  140. { /* sentinel */ }
  141. };
  142. static void __init kirkwood_dt_init(void)
  143. {
  144. kirkwood_disable_mbus_error_propagation();
  145. BUG_ON(mvebu_mbus_dt_init(false));
  146. #ifdef CONFIG_CACHE_FEROCEON_L2
  147. feroceon_of_init();
  148. #endif
  149. kirkwood_cpufreq_init();
  150. kirkwood_cpuidle_init();
  151. kirkwood_pm_init();
  152. kirkwood_dt_eth_fixup();
  153. if (of_machine_is_compatible("lacie,netxbig"))
  154. netxbig_init();
  155. of_platform_populate(NULL, of_default_bus_match_table, auxdata, NULL);
  156. }
  157. static const char * const kirkwood_dt_board_compat[] = {
  158. "marvell,kirkwood",
  159. NULL
  160. };
  161. DT_MACHINE_START(KIRKWOOD_DT, "Marvell Kirkwood (Flattened Device Tree)")
  162. /* Maintainer: Jason Cooper <jason@lakedaemon.net> */
  163. .init_machine = kirkwood_dt_init,
  164. .restart = mvebu_restart,
  165. .dt_compat = kirkwood_dt_board_compat,
  166. MACHINE_END