mach-mxs.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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/mxsfb.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_platform.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/time.h>
  23. #include <mach/common.h>
  24. static struct fb_videomode mx23evk_video_modes[] = {
  25. {
  26. .name = "Samsung-LMS430HF02",
  27. .refresh = 60,
  28. .xres = 480,
  29. .yres = 272,
  30. .pixclock = 108096, /* picosecond (9.2 MHz) */
  31. .left_margin = 15,
  32. .right_margin = 8,
  33. .upper_margin = 12,
  34. .lower_margin = 4,
  35. .hsync_len = 1,
  36. .vsync_len = 1,
  37. .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT |
  38. FB_SYNC_DOTCLK_FAILING_ACT,
  39. },
  40. };
  41. static struct fb_videomode mx28evk_video_modes[] = {
  42. {
  43. .name = "Seiko-43WVF1G",
  44. .refresh = 60,
  45. .xres = 800,
  46. .yres = 480,
  47. .pixclock = 29851, /* picosecond (33.5 MHz) */
  48. .left_margin = 89,
  49. .right_margin = 164,
  50. .upper_margin = 23,
  51. .lower_margin = 10,
  52. .hsync_len = 10,
  53. .vsync_len = 10,
  54. .sync = FB_SYNC_DATA_ENABLE_HIGH_ACT |
  55. FB_SYNC_DOTCLK_FAILING_ACT,
  56. },
  57. };
  58. static struct mxsfb_platform_data mxsfb_pdata __initdata;
  59. static struct of_dev_auxdata mxs_auxdata_lookup[] __initdata = {
  60. OF_DEV_AUXDATA("fsl,imx23-lcdif", 0x80030000, NULL, &mxsfb_pdata),
  61. OF_DEV_AUXDATA("fsl,imx28-lcdif", 0x80030000, NULL, &mxsfb_pdata),
  62. { /* sentinel */ }
  63. };
  64. static int __init mxs_icoll_add_irq_domain(struct device_node *np,
  65. struct device_node *interrupt_parent)
  66. {
  67. irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL);
  68. return 0;
  69. }
  70. static int __init mxs_gpio_add_irq_domain(struct device_node *np,
  71. struct device_node *interrupt_parent)
  72. {
  73. static int gpio_irq_base = MXS_GPIO_IRQ_START;
  74. irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL);
  75. gpio_irq_base += 32;
  76. return 0;
  77. }
  78. static const struct of_device_id mxs_irq_match[] __initconst = {
  79. { .compatible = "fsl,mxs-icoll", .data = mxs_icoll_add_irq_domain, },
  80. { .compatible = "fsl,mxs-gpio", .data = mxs_gpio_add_irq_domain, },
  81. { /* sentinel */ }
  82. };
  83. static void __init mxs_dt_init_irq(void)
  84. {
  85. icoll_init_irq();
  86. of_irq_init(mxs_irq_match);
  87. }
  88. static void __init imx23_timer_init(void)
  89. {
  90. mx23_clocks_init();
  91. }
  92. static struct sys_timer imx23_timer = {
  93. .init = imx23_timer_init,
  94. };
  95. static void __init imx28_timer_init(void)
  96. {
  97. mx28_clocks_init();
  98. }
  99. static struct sys_timer imx28_timer = {
  100. .init = imx28_timer_init,
  101. };
  102. enum mac_oui {
  103. OUI_FSL,
  104. OUI_DENX,
  105. };
  106. static void __init update_fec_mac_prop(enum mac_oui oui)
  107. {
  108. struct device_node *np, *from = NULL;
  109. struct property *oldmac, *newmac;
  110. const u32 *ocotp = mxs_get_ocotp();
  111. u8 *macaddr;
  112. u32 val;
  113. int i;
  114. for (i = 0; i < 2; i++) {
  115. np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
  116. if (!np)
  117. return;
  118. from = np;
  119. newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
  120. if (!newmac)
  121. return;
  122. newmac->value = newmac + 1;
  123. newmac->length = 6;
  124. newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
  125. if (!newmac->name) {
  126. kfree(newmac);
  127. return;
  128. }
  129. /*
  130. * OCOTP only stores the last 4 octets for each mac address,
  131. * so hard-code OUI here.
  132. */
  133. macaddr = newmac->value;
  134. switch (oui) {
  135. case OUI_FSL:
  136. macaddr[0] = 0x00;
  137. macaddr[1] = 0x04;
  138. macaddr[2] = 0x9f;
  139. break;
  140. case OUI_DENX:
  141. macaddr[0] = 0xc0;
  142. macaddr[1] = 0xe5;
  143. macaddr[2] = 0x4e;
  144. break;
  145. }
  146. val = ocotp[i];
  147. macaddr[3] = (val >> 16) & 0xff;
  148. macaddr[4] = (val >> 8) & 0xff;
  149. macaddr[5] = (val >> 0) & 0xff;
  150. oldmac = of_find_property(np, newmac->name, NULL);
  151. if (oldmac)
  152. prom_update_property(np, newmac, oldmac);
  153. else
  154. prom_add_property(np, newmac);
  155. }
  156. }
  157. static void __init imx23_evk_init(void)
  158. {
  159. mxsfb_pdata.mode_list = mx23evk_video_modes;
  160. mxsfb_pdata.mode_count = ARRAY_SIZE(mx23evk_video_modes);
  161. mxsfb_pdata.default_bpp = 32;
  162. mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
  163. }
  164. static void __init imx28_evk_init(void)
  165. {
  166. struct clk *clk;
  167. /* Enable fec phy clock */
  168. clk = clk_get_sys("enet_out", NULL);
  169. if (!IS_ERR(clk))
  170. clk_prepare_enable(clk);
  171. update_fec_mac_prop(OUI_FSL);
  172. mxsfb_pdata.mode_list = mx28evk_video_modes;
  173. mxsfb_pdata.mode_count = ARRAY_SIZE(mx28evk_video_modes);
  174. mxsfb_pdata.default_bpp = 32;
  175. mxsfb_pdata.ld_intf_width = STMLCDIF_24BIT;
  176. }
  177. static void __init mxs_machine_init(void)
  178. {
  179. if (of_machine_is_compatible("fsl,imx28-evk"))
  180. imx28_evk_init();
  181. else if (of_machine_is_compatible("fsl,imx23-evk"))
  182. imx23_evk_init();
  183. of_platform_populate(NULL, of_default_bus_match_table,
  184. mxs_auxdata_lookup, NULL);
  185. }
  186. static const char *imx23_dt_compat[] __initdata = {
  187. "fsl,imx23-evk",
  188. "fsl,imx23",
  189. NULL,
  190. };
  191. static const char *imx28_dt_compat[] __initdata = {
  192. "crystalfontz,cfa10036",
  193. "fsl,imx28-evk",
  194. "fsl,imx28",
  195. NULL,
  196. };
  197. DT_MACHINE_START(IMX23, "Freescale i.MX23 (Device Tree)")
  198. .map_io = mx23_map_io,
  199. .init_irq = mxs_dt_init_irq,
  200. .timer = &imx23_timer,
  201. .init_machine = mxs_machine_init,
  202. .dt_compat = imx23_dt_compat,
  203. .restart = mxs_restart,
  204. MACHINE_END
  205. DT_MACHINE_START(IMX28, "Freescale i.MX28 (Device Tree)")
  206. .map_io = mx28_map_io,
  207. .init_irq = mxs_dt_init_irq,
  208. .timer = &imx28_timer,
  209. .init_machine = mxs_machine_init,
  210. .dt_compat = imx28_dt_compat,
  211. .restart = mxs_restart,
  212. MACHINE_END