kirkwood.c 4.7 KB

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