fsl_soc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * FSL SoC setup code
  3. *
  4. * Maintained by Kumar Gala (see MAINTAINERS for contact information)
  5. *
  6. * 2006 (c) MontaVista Software, Inc.
  7. * Vitaly Bordug <vbordug@ru.mvista.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/stddef.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/major.h>
  19. #include <linux/delay.h>
  20. #include <linux/irq.h>
  21. #include <linux/module.h>
  22. #include <linux/device.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/of.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/phy.h>
  27. #include <linux/phy_fixed.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/fsl_devices.h>
  30. #include <linux/fs_enet_pd.h>
  31. #include <linux/fs_uart_pd.h>
  32. #include <asm/system.h>
  33. #include <linux/atomic.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/time.h>
  37. #include <asm/prom.h>
  38. #include <asm/machdep.h>
  39. #include <sysdev/fsl_soc.h>
  40. #include <mm/mmu_decl.h>
  41. #include <asm/cpm2.h>
  42. #include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
  43. extern void init_fcc_ioports(struct fs_platform_info*);
  44. extern void init_fec_ioports(struct fs_platform_info*);
  45. extern void init_smc_ioports(struct fs_uart_platform_info*);
  46. static phys_addr_t immrbase = -1;
  47. phys_addr_t get_immrbase(void)
  48. {
  49. struct device_node *soc;
  50. if (immrbase != -1)
  51. return immrbase;
  52. soc = of_find_node_by_type(NULL, "soc");
  53. if (soc) {
  54. int size;
  55. u32 naddr;
  56. const u32 *prop = of_get_property(soc, "#address-cells", &size);
  57. if (prop && size == 4)
  58. naddr = *prop;
  59. else
  60. naddr = 2;
  61. prop = of_get_property(soc, "ranges", &size);
  62. if (prop)
  63. immrbase = of_translate_address(soc, prop + naddr);
  64. of_node_put(soc);
  65. }
  66. return immrbase;
  67. }
  68. EXPORT_SYMBOL(get_immrbase);
  69. static u32 sysfreq = -1;
  70. u32 fsl_get_sys_freq(void)
  71. {
  72. struct device_node *soc;
  73. const u32 *prop;
  74. int size;
  75. if (sysfreq != -1)
  76. return sysfreq;
  77. soc = of_find_node_by_type(NULL, "soc");
  78. if (!soc)
  79. return -1;
  80. prop = of_get_property(soc, "clock-frequency", &size);
  81. if (!prop || size != sizeof(*prop) || *prop == 0)
  82. prop = of_get_property(soc, "bus-frequency", &size);
  83. if (prop && size == sizeof(*prop))
  84. sysfreq = *prop;
  85. of_node_put(soc);
  86. return sysfreq;
  87. }
  88. EXPORT_SYMBOL(fsl_get_sys_freq);
  89. #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
  90. static u32 brgfreq = -1;
  91. u32 get_brgfreq(void)
  92. {
  93. struct device_node *node;
  94. const unsigned int *prop;
  95. int size;
  96. if (brgfreq != -1)
  97. return brgfreq;
  98. node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
  99. if (node) {
  100. prop = of_get_property(node, "clock-frequency", &size);
  101. if (prop && size == 4)
  102. brgfreq = *prop;
  103. of_node_put(node);
  104. return brgfreq;
  105. }
  106. /* Legacy device binding -- will go away when no users are left. */
  107. node = of_find_node_by_type(NULL, "cpm");
  108. if (!node)
  109. node = of_find_compatible_node(NULL, NULL, "fsl,qe");
  110. if (!node)
  111. node = of_find_node_by_type(NULL, "qe");
  112. if (node) {
  113. prop = of_get_property(node, "brg-frequency", &size);
  114. if (prop && size == 4)
  115. brgfreq = *prop;
  116. if (brgfreq == -1 || brgfreq == 0) {
  117. prop = of_get_property(node, "bus-frequency", &size);
  118. if (prop && size == 4)
  119. brgfreq = *prop / 2;
  120. }
  121. of_node_put(node);
  122. }
  123. return brgfreq;
  124. }
  125. EXPORT_SYMBOL(get_brgfreq);
  126. static u32 fs_baudrate = -1;
  127. u32 get_baudrate(void)
  128. {
  129. struct device_node *node;
  130. if (fs_baudrate != -1)
  131. return fs_baudrate;
  132. node = of_find_node_by_type(NULL, "serial");
  133. if (node) {
  134. int size;
  135. const unsigned int *prop = of_get_property(node,
  136. "current-speed", &size);
  137. if (prop)
  138. fs_baudrate = *prop;
  139. of_node_put(node);
  140. }
  141. return fs_baudrate;
  142. }
  143. EXPORT_SYMBOL(get_baudrate);
  144. #endif /* CONFIG_CPM2 */
  145. #ifdef CONFIG_FIXED_PHY
  146. static int __init of_add_fixed_phys(void)
  147. {
  148. int ret;
  149. struct device_node *np;
  150. u32 *fixed_link;
  151. struct fixed_phy_status status = {};
  152. for_each_node_by_name(np, "ethernet") {
  153. fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
  154. if (!fixed_link)
  155. continue;
  156. status.link = 1;
  157. status.duplex = fixed_link[1];
  158. status.speed = fixed_link[2];
  159. status.pause = fixed_link[3];
  160. status.asym_pause = fixed_link[4];
  161. ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
  162. if (ret) {
  163. of_node_put(np);
  164. return ret;
  165. }
  166. }
  167. return 0;
  168. }
  169. arch_initcall(of_add_fixed_phys);
  170. #endif /* CONFIG_FIXED_PHY */
  171. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  172. static __be32 __iomem *rstcr;
  173. static int __init setup_rstcr(void)
  174. {
  175. struct device_node *np;
  176. for_each_node_by_name(np, "global-utilities") {
  177. if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
  178. rstcr = of_iomap(np, 0) + 0xb0;
  179. if (!rstcr)
  180. printk (KERN_ERR "Error: reset control "
  181. "register not mapped!\n");
  182. break;
  183. }
  184. }
  185. if (!rstcr && ppc_md.restart == fsl_rstcr_restart)
  186. printk(KERN_ERR "No RSTCR register, warm reboot won't work\n");
  187. if (np)
  188. of_node_put(np);
  189. return 0;
  190. }
  191. arch_initcall(setup_rstcr);
  192. void fsl_rstcr_restart(char *cmd)
  193. {
  194. local_irq_disable();
  195. if (rstcr)
  196. /* set reset control register */
  197. out_be32(rstcr, 0x2); /* HRESET_REQ */
  198. while (1) ;
  199. }
  200. #endif
  201. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  202. struct platform_diu_data_ops diu_ops;
  203. EXPORT_SYMBOL(diu_ops);
  204. #endif
  205. /*
  206. * Restart the current partition
  207. *
  208. * This function should be assigned to the ppc_md.restart function pointer,
  209. * to initiate a partition restart when we're running under the Freescale
  210. * hypervisor.
  211. */
  212. void fsl_hv_restart(char *cmd)
  213. {
  214. pr_info("hv restart\n");
  215. fh_partition_restart(-1);
  216. }
  217. /*
  218. * Halt the current partition
  219. *
  220. * This function should be assigned to the ppc_md.power_off and ppc_md.halt
  221. * function pointers, to shut down the partition when we're running under
  222. * the Freescale hypervisor.
  223. */
  224. void fsl_hv_halt(void)
  225. {
  226. pr_info("hv exit\n");
  227. fh_partition_stop(-1);
  228. }