fsl_soc.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 <asm/atomic.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/time.h>
  37. #include <asm/prom.h>
  38. #include <sysdev/fsl_soc.h>
  39. #include <mm/mmu_decl.h>
  40. #include <asm/cpm2.h>
  41. extern void init_fcc_ioports(struct fs_platform_info*);
  42. extern void init_fec_ioports(struct fs_platform_info*);
  43. extern void init_smc_ioports(struct fs_uart_platform_info*);
  44. static phys_addr_t immrbase = -1;
  45. phys_addr_t get_immrbase(void)
  46. {
  47. struct device_node *soc;
  48. if (immrbase != -1)
  49. return immrbase;
  50. soc = of_find_node_by_type(NULL, "soc");
  51. if (soc) {
  52. int size;
  53. u32 naddr;
  54. const u32 *prop = of_get_property(soc, "#address-cells", &size);
  55. if (prop && size == 4)
  56. naddr = *prop;
  57. else
  58. naddr = 2;
  59. prop = of_get_property(soc, "ranges", &size);
  60. if (prop)
  61. immrbase = of_translate_address(soc, prop + naddr);
  62. of_node_put(soc);
  63. }
  64. return immrbase;
  65. }
  66. EXPORT_SYMBOL(get_immrbase);
  67. static u32 sysfreq = -1;
  68. u32 fsl_get_sys_freq(void)
  69. {
  70. struct device_node *soc;
  71. const u32 *prop;
  72. int size;
  73. if (sysfreq != -1)
  74. return sysfreq;
  75. soc = of_find_node_by_type(NULL, "soc");
  76. if (!soc)
  77. return -1;
  78. prop = of_get_property(soc, "clock-frequency", &size);
  79. if (!prop || size != sizeof(*prop) || *prop == 0)
  80. prop = of_get_property(soc, "bus-frequency", &size);
  81. if (prop && size == sizeof(*prop))
  82. sysfreq = *prop;
  83. of_node_put(soc);
  84. return sysfreq;
  85. }
  86. EXPORT_SYMBOL(fsl_get_sys_freq);
  87. #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
  88. static u32 brgfreq = -1;
  89. u32 get_brgfreq(void)
  90. {
  91. struct device_node *node;
  92. const unsigned int *prop;
  93. int size;
  94. if (brgfreq != -1)
  95. return brgfreq;
  96. node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
  97. if (node) {
  98. prop = of_get_property(node, "clock-frequency", &size);
  99. if (prop && size == 4)
  100. brgfreq = *prop;
  101. of_node_put(node);
  102. return brgfreq;
  103. }
  104. /* Legacy device binding -- will go away when no users are left. */
  105. node = of_find_node_by_type(NULL, "cpm");
  106. if (!node)
  107. node = of_find_compatible_node(NULL, NULL, "fsl,qe");
  108. if (!node)
  109. node = of_find_node_by_type(NULL, "qe");
  110. if (node) {
  111. prop = of_get_property(node, "brg-frequency", &size);
  112. if (prop && size == 4)
  113. brgfreq = *prop;
  114. if (brgfreq == -1 || brgfreq == 0) {
  115. prop = of_get_property(node, "bus-frequency", &size);
  116. if (prop && size == 4)
  117. brgfreq = *prop / 2;
  118. }
  119. of_node_put(node);
  120. }
  121. return brgfreq;
  122. }
  123. EXPORT_SYMBOL(get_brgfreq);
  124. static u32 fs_baudrate = -1;
  125. u32 get_baudrate(void)
  126. {
  127. struct device_node *node;
  128. if (fs_baudrate != -1)
  129. return fs_baudrate;
  130. node = of_find_node_by_type(NULL, "serial");
  131. if (node) {
  132. int size;
  133. const unsigned int *prop = of_get_property(node,
  134. "current-speed", &size);
  135. if (prop)
  136. fs_baudrate = *prop;
  137. of_node_put(node);
  138. }
  139. return fs_baudrate;
  140. }
  141. EXPORT_SYMBOL(get_baudrate);
  142. #endif /* CONFIG_CPM2 */
  143. #ifdef CONFIG_FIXED_PHY
  144. static int __init of_add_fixed_phys(void)
  145. {
  146. int ret;
  147. struct device_node *np;
  148. u32 *fixed_link;
  149. struct fixed_phy_status status = {};
  150. for_each_node_by_name(np, "ethernet") {
  151. fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
  152. if (!fixed_link)
  153. continue;
  154. status.link = 1;
  155. status.duplex = fixed_link[1];
  156. status.speed = fixed_link[2];
  157. status.pause = fixed_link[3];
  158. status.asym_pause = fixed_link[4];
  159. ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
  160. if (ret) {
  161. of_node_put(np);
  162. return ret;
  163. }
  164. }
  165. return 0;
  166. }
  167. arch_initcall(of_add_fixed_phys);
  168. #endif /* CONFIG_FIXED_PHY */
  169. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  170. {
  171. if (!phy_type)
  172. return FSL_USB2_PHY_NONE;
  173. if (!strcasecmp(phy_type, "ulpi"))
  174. return FSL_USB2_PHY_ULPI;
  175. if (!strcasecmp(phy_type, "utmi"))
  176. return FSL_USB2_PHY_UTMI;
  177. if (!strcasecmp(phy_type, "utmi_wide"))
  178. return FSL_USB2_PHY_UTMI_WIDE;
  179. if (!strcasecmp(phy_type, "serial"))
  180. return FSL_USB2_PHY_SERIAL;
  181. return FSL_USB2_PHY_NONE;
  182. }
  183. static int __init fsl_usb_of_init(void)
  184. {
  185. struct device_node *np;
  186. unsigned int i = 0;
  187. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
  188. *usb_dev_dr_client = NULL;
  189. int ret;
  190. for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
  191. struct resource r[2];
  192. struct fsl_usb2_platform_data usb_data;
  193. const unsigned char *prop = NULL;
  194. memset(&r, 0, sizeof(r));
  195. memset(&usb_data, 0, sizeof(usb_data));
  196. ret = of_address_to_resource(np, 0, &r[0]);
  197. if (ret)
  198. goto err;
  199. of_irq_to_resource(np, 0, &r[1]);
  200. usb_dev_mph =
  201. platform_device_register_simple("fsl-ehci", i, r, 2);
  202. if (IS_ERR(usb_dev_mph)) {
  203. ret = PTR_ERR(usb_dev_mph);
  204. goto err;
  205. }
  206. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  207. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  208. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  209. prop = of_get_property(np, "port0", NULL);
  210. if (prop)
  211. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  212. prop = of_get_property(np, "port1", NULL);
  213. if (prop)
  214. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  215. prop = of_get_property(np, "phy_type", NULL);
  216. usb_data.phy_mode = determine_usb_phy(prop);
  217. ret =
  218. platform_device_add_data(usb_dev_mph, &usb_data,
  219. sizeof(struct
  220. fsl_usb2_platform_data));
  221. if (ret)
  222. goto unreg_mph;
  223. i++;
  224. }
  225. for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
  226. struct resource r[2];
  227. struct fsl_usb2_platform_data usb_data;
  228. const unsigned char *prop = NULL;
  229. if (!of_device_is_available(np))
  230. continue;
  231. memset(&r, 0, sizeof(r));
  232. memset(&usb_data, 0, sizeof(usb_data));
  233. ret = of_address_to_resource(np, 0, &r[0]);
  234. if (ret)
  235. goto unreg_mph;
  236. of_irq_to_resource(np, 0, &r[1]);
  237. prop = of_get_property(np, "dr_mode", NULL);
  238. if (!prop || !strcmp(prop, "host")) {
  239. usb_data.operating_mode = FSL_USB2_DR_HOST;
  240. usb_dev_dr_host = platform_device_register_simple(
  241. "fsl-ehci", i, r, 2);
  242. if (IS_ERR(usb_dev_dr_host)) {
  243. ret = PTR_ERR(usb_dev_dr_host);
  244. goto err;
  245. }
  246. } else if (prop && !strcmp(prop, "peripheral")) {
  247. usb_data.operating_mode = FSL_USB2_DR_DEVICE;
  248. usb_dev_dr_client = platform_device_register_simple(
  249. "fsl-usb2-udc", i, r, 2);
  250. if (IS_ERR(usb_dev_dr_client)) {
  251. ret = PTR_ERR(usb_dev_dr_client);
  252. goto err;
  253. }
  254. } else if (prop && !strcmp(prop, "otg")) {
  255. usb_data.operating_mode = FSL_USB2_DR_OTG;
  256. usb_dev_dr_host = platform_device_register_simple(
  257. "fsl-ehci", i, r, 2);
  258. if (IS_ERR(usb_dev_dr_host)) {
  259. ret = PTR_ERR(usb_dev_dr_host);
  260. goto err;
  261. }
  262. usb_dev_dr_client = platform_device_register_simple(
  263. "fsl-usb2-udc", i, r, 2);
  264. if (IS_ERR(usb_dev_dr_client)) {
  265. ret = PTR_ERR(usb_dev_dr_client);
  266. goto err;
  267. }
  268. } else {
  269. ret = -EINVAL;
  270. goto err;
  271. }
  272. prop = of_get_property(np, "phy_type", NULL);
  273. usb_data.phy_mode = determine_usb_phy(prop);
  274. if (usb_dev_dr_host) {
  275. usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
  276. usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
  277. dev.coherent_dma_mask;
  278. if ((ret = platform_device_add_data(usb_dev_dr_host,
  279. &usb_data, sizeof(struct
  280. fsl_usb2_platform_data))))
  281. goto unreg_dr;
  282. }
  283. if (usb_dev_dr_client) {
  284. usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
  285. usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
  286. dev.coherent_dma_mask;
  287. if ((ret = platform_device_add_data(usb_dev_dr_client,
  288. &usb_data, sizeof(struct
  289. fsl_usb2_platform_data))))
  290. goto unreg_dr;
  291. }
  292. i++;
  293. }
  294. return 0;
  295. unreg_dr:
  296. if (usb_dev_dr_host)
  297. platform_device_unregister(usb_dev_dr_host);
  298. if (usb_dev_dr_client)
  299. platform_device_unregister(usb_dev_dr_client);
  300. unreg_mph:
  301. if (usb_dev_mph)
  302. platform_device_unregister(usb_dev_mph);
  303. err:
  304. return ret;
  305. }
  306. arch_initcall(fsl_usb_of_init);
  307. #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
  308. static __be32 __iomem *rstcr;
  309. static int __init setup_rstcr(void)
  310. {
  311. struct device_node *np;
  312. np = of_find_node_by_name(NULL, "global-utilities");
  313. if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
  314. rstcr = of_iomap(np, 0) + 0xb0;
  315. if (!rstcr)
  316. printk (KERN_EMERG "Error: reset control register "
  317. "not mapped!\n");
  318. } else
  319. printk (KERN_INFO "rstcr compatible register does not exist!\n");
  320. if (np)
  321. of_node_put(np);
  322. return 0;
  323. }
  324. arch_initcall(setup_rstcr);
  325. void fsl_rstcr_restart(char *cmd)
  326. {
  327. local_irq_disable();
  328. if (rstcr)
  329. /* set reset control register */
  330. out_be32(rstcr, 0x2); /* HRESET_REQ */
  331. while (1) ;
  332. }
  333. #endif
  334. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  335. struct platform_diu_data_ops diu_ops;
  336. EXPORT_SYMBOL(diu_ops);
  337. #endif