kirkwood.c 4.6 KB

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