mach-mxs.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright 2012 Freescale Semiconductor, Inc.
  3. * Copyright 2012 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/err.h>
  15. #include <linux/init.h>
  16. #include <linux/init.h>
  17. #include <linux/irqdomain.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/of_platform.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/time.h>
  22. #include <mach/common.h>
  23. static int __init mxs_icoll_add_irq_domain(struct device_node *np,
  24. struct device_node *interrupt_parent)
  25. {
  26. irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL);
  27. return 0;
  28. }
  29. static int __init mxs_gpio_add_irq_domain(struct device_node *np,
  30. struct device_node *interrupt_parent)
  31. {
  32. static int gpio_irq_base = MXS_GPIO_IRQ_START;
  33. irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL);
  34. gpio_irq_base += 32;
  35. return 0;
  36. }
  37. static const struct of_device_id mxs_irq_match[] __initconst = {
  38. { .compatible = "fsl,mxs-icoll", .data = mxs_icoll_add_irq_domain, },
  39. { .compatible = "fsl,mxs-gpio", .data = mxs_gpio_add_irq_domain, },
  40. { /* sentinel */ }
  41. };
  42. static void __init mxs_dt_init_irq(void)
  43. {
  44. icoll_init_irq();
  45. of_irq_init(mxs_irq_match);
  46. }
  47. static void __init imx23_timer_init(void)
  48. {
  49. mx23_clocks_init();
  50. }
  51. static struct sys_timer imx23_timer = {
  52. .init = imx23_timer_init,
  53. };
  54. static void __init imx28_timer_init(void)
  55. {
  56. mx28_clocks_init();
  57. }
  58. static struct sys_timer imx28_timer = {
  59. .init = imx28_timer_init,
  60. };
  61. enum mac_oui {
  62. OUI_FSL,
  63. OUI_DENX,
  64. };
  65. static void __init update_fec_mac_prop(enum mac_oui oui)
  66. {
  67. struct device_node *np, *from = NULL;
  68. struct property *oldmac, *newmac;
  69. const u32 *ocotp = mxs_get_ocotp();
  70. u8 *macaddr;
  71. u32 val;
  72. int i;
  73. for (i = 0; i < 2; i++) {
  74. np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
  75. if (!np)
  76. return;
  77. from = np;
  78. newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
  79. if (!newmac)
  80. return;
  81. newmac->value = newmac + 1;
  82. newmac->length = 6;
  83. newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
  84. if (!newmac->name) {
  85. kfree(newmac);
  86. return;
  87. }
  88. /*
  89. * OCOTP only stores the last 4 octets for each mac address,
  90. * so hard-code OUI here.
  91. */
  92. macaddr = newmac->value;
  93. switch (oui) {
  94. case OUI_FSL:
  95. macaddr[0] = 0x00;
  96. macaddr[1] = 0x04;
  97. macaddr[2] = 0x9f;
  98. break;
  99. case OUI_DENX:
  100. macaddr[0] = 0xc0;
  101. macaddr[1] = 0xe5;
  102. macaddr[2] = 0x4e;
  103. break;
  104. }
  105. val = ocotp[i];
  106. macaddr[3] = (val >> 16) & 0xff;
  107. macaddr[4] = (val >> 8) & 0xff;
  108. macaddr[5] = (val >> 0) & 0xff;
  109. oldmac = of_find_property(np, newmac->name, NULL);
  110. if (oldmac)
  111. prom_update_property(np, newmac, oldmac);
  112. else
  113. prom_add_property(np, newmac);
  114. }
  115. }
  116. static void __init imx28_evk_init(void)
  117. {
  118. struct clk *clk;
  119. /* Enable fec phy clock */
  120. clk = clk_get_sys("enet_out", NULL);
  121. if (!IS_ERR(clk))
  122. clk_prepare_enable(clk);
  123. update_fec_mac_prop(OUI_FSL);
  124. }
  125. static void __init mxs_machine_init(void)
  126. {
  127. if (of_machine_is_compatible("fsl,imx28-evk"))
  128. imx28_evk_init();
  129. of_platform_populate(NULL, of_default_bus_match_table,
  130. NULL, NULL);
  131. }
  132. static const char *imx23_dt_compat[] __initdata = {
  133. "fsl,imx23-evk",
  134. "fsl,imx23",
  135. NULL,
  136. };
  137. static const char *imx28_dt_compat[] __initdata = {
  138. "fsl,imx28-evk",
  139. "fsl,imx28",
  140. NULL,
  141. };
  142. DT_MACHINE_START(IMX23, "Freescale i.MX23 (Device Tree)")
  143. .map_io = mx23_map_io,
  144. .init_irq = mxs_dt_init_irq,
  145. .timer = &imx23_timer,
  146. .init_machine = mxs_machine_init,
  147. .dt_compat = imx23_dt_compat,
  148. .restart = mxs_restart,
  149. MACHINE_END
  150. DT_MACHINE_START(IMX28, "Freescale i.MX28 (Device Tree)")
  151. .map_io = mx28_map_io,
  152. .init_irq = mxs_dt_init_irq,
  153. .timer = &imx28_timer,
  154. .init_machine = mxs_machine_init,
  155. .dt_compat = imx28_dt_compat,
  156. .restart = mxs_restart,
  157. MACHINE_END