fsl_soc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. const 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. const u32 *id = get_property(child, "reg", NULL);
  74. mdio_data.irq[*id] = irq_of_parse_and_map(child, 0);
  75. }
  76. ret =
  77. platform_device_add_data(mdio_dev, &mdio_data,
  78. sizeof(struct gianfar_mdio_data));
  79. if (ret)
  80. goto unreg;
  81. }
  82. return 0;
  83. unreg:
  84. platform_device_unregister(mdio_dev);
  85. err:
  86. return ret;
  87. }
  88. arch_initcall(gfar_mdio_of_init);
  89. static const char *gfar_tx_intr = "tx";
  90. static const char *gfar_rx_intr = "rx";
  91. static const char *gfar_err_intr = "error";
  92. static int __init gfar_of_init(void)
  93. {
  94. struct device_node *np;
  95. unsigned int i;
  96. struct platform_device *gfar_dev;
  97. struct resource res;
  98. int ret;
  99. for (np = NULL, i = 0;
  100. (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
  101. i++) {
  102. struct resource r[4];
  103. struct device_node *phy, *mdio;
  104. struct gianfar_platform_data gfar_data;
  105. const unsigned int *id;
  106. const char *model;
  107. const void *mac_addr;
  108. const phandle *ph;
  109. int n_res = 1;
  110. memset(r, 0, sizeof(r));
  111. memset(&gfar_data, 0, sizeof(gfar_data));
  112. ret = of_address_to_resource(np, 0, &r[0]);
  113. if (ret)
  114. goto err;
  115. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  116. r[1].flags = IORESOURCE_IRQ;
  117. model = get_property(np, "model", NULL);
  118. /* If we aren't the FEC we have multiple interrupts */
  119. if (model && strcasecmp(model, "FEC")) {
  120. r[1].name = gfar_tx_intr;
  121. r[2].name = gfar_rx_intr;
  122. r[2].start = r[2].end = irq_of_parse_and_map(np, 1);
  123. r[2].flags = IORESOURCE_IRQ;
  124. r[3].name = gfar_err_intr;
  125. r[3].start = r[3].end = irq_of_parse_and_map(np, 2);
  126. r[3].flags = IORESOURCE_IRQ;
  127. n_res += 2;
  128. }
  129. gfar_dev =
  130. platform_device_register_simple("fsl-gianfar", i, &r[0],
  131. n_res + 1);
  132. if (IS_ERR(gfar_dev)) {
  133. ret = PTR_ERR(gfar_dev);
  134. goto err;
  135. }
  136. mac_addr = get_property(np, "address", NULL);
  137. memcpy(gfar_data.mac_addr, mac_addr, 6);
  138. if (model && !strcasecmp(model, "TSEC"))
  139. gfar_data.device_flags =
  140. FSL_GIANFAR_DEV_HAS_GIGABIT |
  141. FSL_GIANFAR_DEV_HAS_COALESCE |
  142. FSL_GIANFAR_DEV_HAS_RMON |
  143. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  144. if (model && !strcasecmp(model, "eTSEC"))
  145. gfar_data.device_flags =
  146. FSL_GIANFAR_DEV_HAS_GIGABIT |
  147. FSL_GIANFAR_DEV_HAS_COALESCE |
  148. FSL_GIANFAR_DEV_HAS_RMON |
  149. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  150. FSL_GIANFAR_DEV_HAS_CSUM |
  151. FSL_GIANFAR_DEV_HAS_VLAN |
  152. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  153. ph = get_property(np, "phy-handle", NULL);
  154. phy = of_find_node_by_phandle(*ph);
  155. if (phy == NULL) {
  156. ret = -ENODEV;
  157. goto unreg;
  158. }
  159. mdio = of_get_parent(phy);
  160. id = get_property(phy, "reg", NULL);
  161. ret = of_address_to_resource(mdio, 0, &res);
  162. if (ret) {
  163. of_node_put(phy);
  164. of_node_put(mdio);
  165. goto unreg;
  166. }
  167. gfar_data.phy_id = *id;
  168. gfar_data.bus_id = res.start;
  169. of_node_put(phy);
  170. of_node_put(mdio);
  171. ret =
  172. platform_device_add_data(gfar_dev, &gfar_data,
  173. sizeof(struct
  174. gianfar_platform_data));
  175. if (ret)
  176. goto unreg;
  177. }
  178. return 0;
  179. unreg:
  180. platform_device_unregister(gfar_dev);
  181. err:
  182. return ret;
  183. }
  184. arch_initcall(gfar_of_init);
  185. static int __init fsl_i2c_of_init(void)
  186. {
  187. struct device_node *np;
  188. unsigned int i;
  189. struct platform_device *i2c_dev;
  190. int ret;
  191. for (np = NULL, i = 0;
  192. (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
  193. i++) {
  194. struct resource r[2];
  195. struct fsl_i2c_platform_data i2c_data;
  196. const unsigned char *flags = NULL;
  197. memset(&r, 0, sizeof(r));
  198. memset(&i2c_data, 0, sizeof(i2c_data));
  199. ret = of_address_to_resource(np, 0, &r[0]);
  200. if (ret)
  201. goto err;
  202. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  203. r[1].flags = IORESOURCE_IRQ;
  204. i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
  205. if (IS_ERR(i2c_dev)) {
  206. ret = PTR_ERR(i2c_dev);
  207. goto err;
  208. }
  209. i2c_data.device_flags = 0;
  210. flags = get_property(np, "dfsrr", NULL);
  211. if (flags)
  212. i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
  213. flags = get_property(np, "fsl5200-clocking", NULL);
  214. if (flags)
  215. i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
  216. ret =
  217. platform_device_add_data(i2c_dev, &i2c_data,
  218. sizeof(struct
  219. fsl_i2c_platform_data));
  220. if (ret)
  221. goto unreg;
  222. }
  223. return 0;
  224. unreg:
  225. platform_device_unregister(i2c_dev);
  226. err:
  227. return ret;
  228. }
  229. arch_initcall(fsl_i2c_of_init);
  230. #ifdef CONFIG_PPC_83xx
  231. static int __init mpc83xx_wdt_init(void)
  232. {
  233. struct resource r;
  234. struct device_node *soc, *np;
  235. struct platform_device *dev;
  236. const unsigned int *freq;
  237. int ret;
  238. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  239. if (!np) {
  240. ret = -ENODEV;
  241. goto nodev;
  242. }
  243. soc = of_find_node_by_type(NULL, "soc");
  244. if (!soc) {
  245. ret = -ENODEV;
  246. goto nosoc;
  247. }
  248. freq = get_property(soc, "bus-frequency", NULL);
  249. if (!freq) {
  250. ret = -ENODEV;
  251. goto err;
  252. }
  253. memset(&r, 0, sizeof(r));
  254. ret = of_address_to_resource(np, 0, &r);
  255. if (ret)
  256. goto err;
  257. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  258. if (IS_ERR(dev)) {
  259. ret = PTR_ERR(dev);
  260. goto err;
  261. }
  262. ret = platform_device_add_data(dev, freq, sizeof(int));
  263. if (ret)
  264. goto unreg;
  265. of_node_put(soc);
  266. of_node_put(np);
  267. return 0;
  268. unreg:
  269. platform_device_unregister(dev);
  270. err:
  271. of_node_put(soc);
  272. nosoc:
  273. of_node_put(np);
  274. nodev:
  275. return ret;
  276. }
  277. arch_initcall(mpc83xx_wdt_init);
  278. #endif
  279. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  280. {
  281. if (!phy_type)
  282. return FSL_USB2_PHY_NONE;
  283. if (!strcasecmp(phy_type, "ulpi"))
  284. return FSL_USB2_PHY_ULPI;
  285. if (!strcasecmp(phy_type, "utmi"))
  286. return FSL_USB2_PHY_UTMI;
  287. if (!strcasecmp(phy_type, "utmi_wide"))
  288. return FSL_USB2_PHY_UTMI_WIDE;
  289. if (!strcasecmp(phy_type, "serial"))
  290. return FSL_USB2_PHY_SERIAL;
  291. return FSL_USB2_PHY_NONE;
  292. }
  293. static int __init fsl_usb_of_init(void)
  294. {
  295. struct device_node *np;
  296. unsigned int i;
  297. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
  298. int ret;
  299. for (np = NULL, i = 0;
  300. (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
  301. i++) {
  302. struct resource r[2];
  303. struct fsl_usb2_platform_data usb_data;
  304. const unsigned char *prop = NULL;
  305. memset(&r, 0, sizeof(r));
  306. memset(&usb_data, 0, sizeof(usb_data));
  307. ret = of_address_to_resource(np, 0, &r[0]);
  308. if (ret)
  309. goto err;
  310. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  311. r[1].flags = IORESOURCE_IRQ;
  312. usb_dev_mph =
  313. platform_device_register_simple("fsl-ehci", i, r, 2);
  314. if (IS_ERR(usb_dev_mph)) {
  315. ret = PTR_ERR(usb_dev_mph);
  316. goto err;
  317. }
  318. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  319. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  320. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  321. prop = get_property(np, "port0", NULL);
  322. if (prop)
  323. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  324. prop = get_property(np, "port1", NULL);
  325. if (prop)
  326. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  327. prop = get_property(np, "phy_type", NULL);
  328. usb_data.phy_mode = determine_usb_phy(prop);
  329. ret =
  330. platform_device_add_data(usb_dev_mph, &usb_data,
  331. sizeof(struct
  332. fsl_usb2_platform_data));
  333. if (ret)
  334. goto unreg_mph;
  335. }
  336. for (np = NULL;
  337. (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
  338. i++) {
  339. struct resource r[2];
  340. struct fsl_usb2_platform_data usb_data;
  341. const unsigned char *prop = NULL;
  342. memset(&r, 0, sizeof(r));
  343. memset(&usb_data, 0, sizeof(usb_data));
  344. ret = of_address_to_resource(np, 0, &r[0]);
  345. if (ret)
  346. goto unreg_mph;
  347. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  348. r[1].flags = IORESOURCE_IRQ;
  349. usb_dev_dr =
  350. platform_device_register_simple("fsl-ehci", i, r, 2);
  351. if (IS_ERR(usb_dev_dr)) {
  352. ret = PTR_ERR(usb_dev_dr);
  353. goto err;
  354. }
  355. usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
  356. usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
  357. usb_data.operating_mode = FSL_USB2_DR_HOST;
  358. prop = get_property(np, "phy_type", NULL);
  359. usb_data.phy_mode = determine_usb_phy(prop);
  360. ret =
  361. platform_device_add_data(usb_dev_dr, &usb_data,
  362. sizeof(struct
  363. fsl_usb2_platform_data));
  364. if (ret)
  365. goto unreg_dr;
  366. }
  367. return 0;
  368. unreg_dr:
  369. if (usb_dev_dr)
  370. platform_device_unregister(usb_dev_dr);
  371. unreg_mph:
  372. if (usb_dev_mph)
  373. platform_device_unregister(usb_dev_mph);
  374. err:
  375. return ret;
  376. }
  377. arch_initcall(fsl_usb_of_init);