fsl_soc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /*
  2. * FSL SoC setup code
  3. *
  4. * Maintained by Kumar Gala (see MAINTAINERS for contact information)
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/major.h>
  16. #include <linux/delay.h>
  17. #include <linux/irq.h>
  18. #include <linux/module.h>
  19. #include <linux/device.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/fsl_devices.h>
  22. #include <asm/system.h>
  23. #include <asm/atomic.h>
  24. #include <asm/io.h>
  25. #include <asm/irq.h>
  26. #include <asm/prom.h>
  27. #include <sysdev/fsl_soc.h>
  28. #include <mm/mmu_decl.h>
  29. static phys_addr_t immrbase = -1;
  30. phys_addr_t get_immrbase(void)
  31. {
  32. struct device_node *soc;
  33. if (immrbase != -1)
  34. return immrbase;
  35. soc = of_find_node_by_type(NULL, "soc");
  36. if (soc) {
  37. unsigned int size;
  38. void *prop = get_property(soc, "reg", &size);
  39. immrbase = of_translate_address(soc, prop);
  40. of_node_put(soc);
  41. };
  42. return immrbase;
  43. }
  44. EXPORT_SYMBOL(get_immrbase);
  45. static int __init gfar_mdio_of_init(void)
  46. {
  47. struct device_node *np;
  48. unsigned int i;
  49. struct platform_device *mdio_dev;
  50. struct resource res;
  51. int ret;
  52. for (np = NULL, i = 0;
  53. (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
  54. i++) {
  55. int k;
  56. struct device_node *child = NULL;
  57. struct gianfar_mdio_data mdio_data;
  58. memset(&res, 0, sizeof(res));
  59. memset(&mdio_data, 0, sizeof(mdio_data));
  60. ret = of_address_to_resource(np, 0, &res);
  61. if (ret)
  62. goto err;
  63. mdio_dev =
  64. platform_device_register_simple("fsl-gianfar_mdio",
  65. res.start, &res, 1);
  66. if (IS_ERR(mdio_dev)) {
  67. ret = PTR_ERR(mdio_dev);
  68. goto err;
  69. }
  70. for (k = 0; k < 32; k++)
  71. mdio_data.irq[k] = -1;
  72. while ((child = of_get_next_child(np, child)) != NULL) {
  73. if (child->n_intrs) {
  74. u32 *id =
  75. (u32 *) get_property(child, "reg", NULL);
  76. mdio_data.irq[*id] = child->intrs[0].line;
  77. }
  78. }
  79. ret =
  80. platform_device_add_data(mdio_dev, &mdio_data,
  81. sizeof(struct gianfar_mdio_data));
  82. if (ret)
  83. goto unreg;
  84. }
  85. return 0;
  86. unreg:
  87. platform_device_unregister(mdio_dev);
  88. err:
  89. return ret;
  90. }
  91. arch_initcall(gfar_mdio_of_init);
  92. static const char *gfar_tx_intr = "tx";
  93. static const char *gfar_rx_intr = "rx";
  94. static const char *gfar_err_intr = "error";
  95. static int __init gfar_of_init(void)
  96. {
  97. struct device_node *np;
  98. unsigned int i;
  99. struct platform_device *gfar_dev;
  100. struct resource res;
  101. int ret;
  102. for (np = NULL, i = 0;
  103. (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
  104. i++) {
  105. struct resource r[4];
  106. struct device_node *phy, *mdio;
  107. struct gianfar_platform_data gfar_data;
  108. unsigned int *id;
  109. char *model;
  110. void *mac_addr;
  111. phandle *ph;
  112. memset(r, 0, sizeof(r));
  113. memset(&gfar_data, 0, sizeof(gfar_data));
  114. ret = of_address_to_resource(np, 0, &r[0]);
  115. if (ret)
  116. goto err;
  117. r[1].start = np->intrs[0].line;
  118. r[1].end = np->intrs[0].line;
  119. r[1].flags = IORESOURCE_IRQ;
  120. model = get_property(np, "model", NULL);
  121. /* If we aren't the FEC we have multiple interrupts */
  122. if (model && strcasecmp(model, "FEC")) {
  123. r[1].name = gfar_tx_intr;
  124. r[2].name = gfar_rx_intr;
  125. r[2].start = np->intrs[1].line;
  126. r[2].end = np->intrs[1].line;
  127. r[2].flags = IORESOURCE_IRQ;
  128. r[3].name = gfar_err_intr;
  129. r[3].start = np->intrs[2].line;
  130. r[3].end = np->intrs[2].line;
  131. r[3].flags = IORESOURCE_IRQ;
  132. }
  133. gfar_dev =
  134. platform_device_register_simple("fsl-gianfar", i, &r[0],
  135. np->n_intrs + 1);
  136. if (IS_ERR(gfar_dev)) {
  137. ret = PTR_ERR(gfar_dev);
  138. goto err;
  139. }
  140. mac_addr = get_property(np, "local-mac-address", NULL);
  141. if (mac_addr == NULL)
  142. mac_addr = get_property(np, "mac-address", NULL);
  143. if (mac_addr == NULL) {
  144. /* Obsolete */
  145. mac_addr = get_property(np, "address", NULL);
  146. }
  147. if (mac_addr)
  148. memcpy(gfar_data.mac_addr, mac_addr, 6);
  149. if (model && !strcasecmp(model, "TSEC"))
  150. gfar_data.device_flags =
  151. FSL_GIANFAR_DEV_HAS_GIGABIT |
  152. FSL_GIANFAR_DEV_HAS_COALESCE |
  153. FSL_GIANFAR_DEV_HAS_RMON |
  154. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  155. if (model && !strcasecmp(model, "eTSEC"))
  156. gfar_data.device_flags =
  157. FSL_GIANFAR_DEV_HAS_GIGABIT |
  158. FSL_GIANFAR_DEV_HAS_COALESCE |
  159. FSL_GIANFAR_DEV_HAS_RMON |
  160. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  161. FSL_GIANFAR_DEV_HAS_CSUM |
  162. FSL_GIANFAR_DEV_HAS_VLAN |
  163. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  164. ph = (phandle *) get_property(np, "phy-handle", NULL);
  165. phy = of_find_node_by_phandle(*ph);
  166. if (phy == NULL) {
  167. ret = -ENODEV;
  168. goto unreg;
  169. }
  170. mdio = of_get_parent(phy);
  171. id = (u32 *) get_property(phy, "reg", NULL);
  172. ret = of_address_to_resource(mdio, 0, &res);
  173. if (ret) {
  174. of_node_put(phy);
  175. of_node_put(mdio);
  176. goto unreg;
  177. }
  178. gfar_data.phy_id = *id;
  179. gfar_data.bus_id = res.start;
  180. of_node_put(phy);
  181. of_node_put(mdio);
  182. ret =
  183. platform_device_add_data(gfar_dev, &gfar_data,
  184. sizeof(struct
  185. gianfar_platform_data));
  186. if (ret)
  187. goto unreg;
  188. }
  189. return 0;
  190. unreg:
  191. platform_device_unregister(gfar_dev);
  192. err:
  193. return ret;
  194. }
  195. arch_initcall(gfar_of_init);
  196. static int __init fsl_i2c_of_init(void)
  197. {
  198. struct device_node *np;
  199. unsigned int i;
  200. struct platform_device *i2c_dev;
  201. int ret;
  202. for (np = NULL, i = 0;
  203. (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
  204. i++) {
  205. struct resource r[2];
  206. struct fsl_i2c_platform_data i2c_data;
  207. unsigned char *flags = NULL;
  208. memset(&r, 0, sizeof(r));
  209. memset(&i2c_data, 0, sizeof(i2c_data));
  210. ret = of_address_to_resource(np, 0, &r[0]);
  211. if (ret)
  212. goto err;
  213. r[1].start = np->intrs[0].line;
  214. r[1].end = np->intrs[0].line;
  215. r[1].flags = IORESOURCE_IRQ;
  216. i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
  217. if (IS_ERR(i2c_dev)) {
  218. ret = PTR_ERR(i2c_dev);
  219. goto err;
  220. }
  221. i2c_data.device_flags = 0;
  222. flags = get_property(np, "dfsrr", NULL);
  223. if (flags)
  224. i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
  225. flags = get_property(np, "fsl5200-clocking", NULL);
  226. if (flags)
  227. i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
  228. ret =
  229. platform_device_add_data(i2c_dev, &i2c_data,
  230. sizeof(struct
  231. fsl_i2c_platform_data));
  232. if (ret)
  233. goto unreg;
  234. }
  235. return 0;
  236. unreg:
  237. platform_device_unregister(i2c_dev);
  238. err:
  239. return ret;
  240. }
  241. arch_initcall(fsl_i2c_of_init);
  242. #ifdef CONFIG_PPC_83xx
  243. static int __init mpc83xx_wdt_init(void)
  244. {
  245. struct resource r;
  246. struct device_node *soc, *np;
  247. struct platform_device *dev;
  248. unsigned int *freq;
  249. int ret;
  250. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  251. if (!np) {
  252. ret = -ENODEV;
  253. goto nodev;
  254. }
  255. soc = of_find_node_by_type(NULL, "soc");
  256. if (!soc) {
  257. ret = -ENODEV;
  258. goto nosoc;
  259. }
  260. freq = (unsigned int *)get_property(soc, "bus-frequency", NULL);
  261. if (!freq) {
  262. ret = -ENODEV;
  263. goto err;
  264. }
  265. memset(&r, 0, sizeof(r));
  266. ret = of_address_to_resource(np, 0, &r);
  267. if (ret)
  268. goto err;
  269. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  270. if (IS_ERR(dev)) {
  271. ret = PTR_ERR(dev);
  272. goto err;
  273. }
  274. ret = platform_device_add_data(dev, freq, sizeof(int));
  275. if (ret)
  276. goto unreg;
  277. of_node_put(soc);
  278. of_node_put(np);
  279. return 0;
  280. unreg:
  281. platform_device_unregister(dev);
  282. err:
  283. of_node_put(soc);
  284. nosoc:
  285. of_node_put(np);
  286. nodev:
  287. return ret;
  288. }
  289. arch_initcall(mpc83xx_wdt_init);
  290. #endif
  291. static enum fsl_usb2_phy_modes determine_usb_phy(char * phy_type)
  292. {
  293. if (!phy_type)
  294. return FSL_USB2_PHY_NONE;
  295. if (!strcasecmp(phy_type, "ulpi"))
  296. return FSL_USB2_PHY_ULPI;
  297. if (!strcasecmp(phy_type, "utmi"))
  298. return FSL_USB2_PHY_UTMI;
  299. if (!strcasecmp(phy_type, "utmi_wide"))
  300. return FSL_USB2_PHY_UTMI_WIDE;
  301. if (!strcasecmp(phy_type, "serial"))
  302. return FSL_USB2_PHY_SERIAL;
  303. return FSL_USB2_PHY_NONE;
  304. }
  305. static int __init fsl_usb_of_init(void)
  306. {
  307. struct device_node *np;
  308. unsigned int i;
  309. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
  310. int ret;
  311. for (np = NULL, i = 0;
  312. (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
  313. i++) {
  314. struct resource r[2];
  315. struct fsl_usb2_platform_data usb_data;
  316. unsigned char *prop = NULL;
  317. memset(&r, 0, sizeof(r));
  318. memset(&usb_data, 0, sizeof(usb_data));
  319. ret = of_address_to_resource(np, 0, &r[0]);
  320. if (ret)
  321. goto err;
  322. r[1].start = np->intrs[0].line;
  323. r[1].end = np->intrs[0].line;
  324. r[1].flags = IORESOURCE_IRQ;
  325. usb_dev_mph =
  326. platform_device_register_simple("fsl-ehci", i, r, 2);
  327. if (IS_ERR(usb_dev_mph)) {
  328. ret = PTR_ERR(usb_dev_mph);
  329. goto err;
  330. }
  331. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  332. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  333. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  334. prop = get_property(np, "port0", NULL);
  335. if (prop)
  336. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  337. prop = get_property(np, "port1", NULL);
  338. if (prop)
  339. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  340. prop = get_property(np, "phy_type", NULL);
  341. usb_data.phy_mode = determine_usb_phy(prop);
  342. ret =
  343. platform_device_add_data(usb_dev_mph, &usb_data,
  344. sizeof(struct
  345. fsl_usb2_platform_data));
  346. if (ret)
  347. goto unreg_mph;
  348. }
  349. for (np = NULL;
  350. (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
  351. i++) {
  352. struct resource r[2];
  353. struct fsl_usb2_platform_data usb_data;
  354. unsigned char *prop = NULL;
  355. memset(&r, 0, sizeof(r));
  356. memset(&usb_data, 0, sizeof(usb_data));
  357. ret = of_address_to_resource(np, 0, &r[0]);
  358. if (ret)
  359. goto unreg_mph;
  360. r[1].start = np->intrs[0].line;
  361. r[1].end = np->intrs[0].line;
  362. r[1].flags = IORESOURCE_IRQ;
  363. usb_dev_dr =
  364. platform_device_register_simple("fsl-ehci", i, r, 2);
  365. if (IS_ERR(usb_dev_dr)) {
  366. ret = PTR_ERR(usb_dev_dr);
  367. goto err;
  368. }
  369. usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
  370. usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
  371. usb_data.operating_mode = FSL_USB2_DR_HOST;
  372. prop = get_property(np, "phy_type", NULL);
  373. usb_data.phy_mode = determine_usb_phy(prop);
  374. ret =
  375. platform_device_add_data(usb_dev_dr, &usb_data,
  376. sizeof(struct
  377. fsl_usb2_platform_data));
  378. if (ret)
  379. goto unreg_dr;
  380. }
  381. return 0;
  382. unreg_dr:
  383. if (usb_dev_dr)
  384. platform_device_unregister(usb_dev_dr);
  385. unreg_mph:
  386. if (usb_dev_mph)
  387. platform_device_unregister(usb_dev_mph);
  388. err:
  389. return ret;
  390. }
  391. arch_initcall(fsl_usb_of_init);