fsl_soc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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, "local-mac-address", NULL);
  137. if (mac_addr == NULL)
  138. mac_addr = get_property(np, "mac-address", NULL);
  139. if (mac_addr == NULL) {
  140. /* Obsolete */
  141. mac_addr = get_property(np, "address", NULL);
  142. }
  143. if (mac_addr)
  144. memcpy(gfar_data.mac_addr, mac_addr, 6);
  145. if (model && !strcasecmp(model, "TSEC"))
  146. gfar_data.device_flags =
  147. FSL_GIANFAR_DEV_HAS_GIGABIT |
  148. FSL_GIANFAR_DEV_HAS_COALESCE |
  149. FSL_GIANFAR_DEV_HAS_RMON |
  150. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  151. if (model && !strcasecmp(model, "eTSEC"))
  152. gfar_data.device_flags =
  153. FSL_GIANFAR_DEV_HAS_GIGABIT |
  154. FSL_GIANFAR_DEV_HAS_COALESCE |
  155. FSL_GIANFAR_DEV_HAS_RMON |
  156. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  157. FSL_GIANFAR_DEV_HAS_CSUM |
  158. FSL_GIANFAR_DEV_HAS_VLAN |
  159. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  160. ph = get_property(np, "phy-handle", NULL);
  161. phy = of_find_node_by_phandle(*ph);
  162. if (phy == NULL) {
  163. ret = -ENODEV;
  164. goto unreg;
  165. }
  166. mdio = of_get_parent(phy);
  167. id = get_property(phy, "reg", NULL);
  168. ret = of_address_to_resource(mdio, 0, &res);
  169. if (ret) {
  170. of_node_put(phy);
  171. of_node_put(mdio);
  172. goto unreg;
  173. }
  174. gfar_data.phy_id = *id;
  175. gfar_data.bus_id = res.start;
  176. of_node_put(phy);
  177. of_node_put(mdio);
  178. ret =
  179. platform_device_add_data(gfar_dev, &gfar_data,
  180. sizeof(struct
  181. gianfar_platform_data));
  182. if (ret)
  183. goto unreg;
  184. }
  185. return 0;
  186. unreg:
  187. platform_device_unregister(gfar_dev);
  188. err:
  189. return ret;
  190. }
  191. arch_initcall(gfar_of_init);
  192. static int __init fsl_i2c_of_init(void)
  193. {
  194. struct device_node *np;
  195. unsigned int i;
  196. struct platform_device *i2c_dev;
  197. int ret;
  198. for (np = NULL, i = 0;
  199. (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
  200. i++) {
  201. struct resource r[2];
  202. struct fsl_i2c_platform_data i2c_data;
  203. const unsigned char *flags = NULL;
  204. memset(&r, 0, sizeof(r));
  205. memset(&i2c_data, 0, sizeof(i2c_data));
  206. ret = of_address_to_resource(np, 0, &r[0]);
  207. if (ret)
  208. goto err;
  209. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  210. r[1].flags = IORESOURCE_IRQ;
  211. i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
  212. if (IS_ERR(i2c_dev)) {
  213. ret = PTR_ERR(i2c_dev);
  214. goto err;
  215. }
  216. i2c_data.device_flags = 0;
  217. flags = get_property(np, "dfsrr", NULL);
  218. if (flags)
  219. i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
  220. flags = get_property(np, "fsl5200-clocking", NULL);
  221. if (flags)
  222. i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
  223. ret =
  224. platform_device_add_data(i2c_dev, &i2c_data,
  225. sizeof(struct
  226. fsl_i2c_platform_data));
  227. if (ret)
  228. goto unreg;
  229. }
  230. return 0;
  231. unreg:
  232. platform_device_unregister(i2c_dev);
  233. err:
  234. return ret;
  235. }
  236. arch_initcall(fsl_i2c_of_init);
  237. #ifdef CONFIG_PPC_83xx
  238. static int __init mpc83xx_wdt_init(void)
  239. {
  240. struct resource r;
  241. struct device_node *soc, *np;
  242. struct platform_device *dev;
  243. const unsigned int *freq;
  244. int ret;
  245. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  246. if (!np) {
  247. ret = -ENODEV;
  248. goto nodev;
  249. }
  250. soc = of_find_node_by_type(NULL, "soc");
  251. if (!soc) {
  252. ret = -ENODEV;
  253. goto nosoc;
  254. }
  255. freq = get_property(soc, "bus-frequency", NULL);
  256. if (!freq) {
  257. ret = -ENODEV;
  258. goto err;
  259. }
  260. memset(&r, 0, sizeof(r));
  261. ret = of_address_to_resource(np, 0, &r);
  262. if (ret)
  263. goto err;
  264. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  265. if (IS_ERR(dev)) {
  266. ret = PTR_ERR(dev);
  267. goto err;
  268. }
  269. ret = platform_device_add_data(dev, freq, sizeof(int));
  270. if (ret)
  271. goto unreg;
  272. of_node_put(soc);
  273. of_node_put(np);
  274. return 0;
  275. unreg:
  276. platform_device_unregister(dev);
  277. err:
  278. of_node_put(soc);
  279. nosoc:
  280. of_node_put(np);
  281. nodev:
  282. return ret;
  283. }
  284. arch_initcall(mpc83xx_wdt_init);
  285. #endif
  286. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  287. {
  288. if (!phy_type)
  289. return FSL_USB2_PHY_NONE;
  290. if (!strcasecmp(phy_type, "ulpi"))
  291. return FSL_USB2_PHY_ULPI;
  292. if (!strcasecmp(phy_type, "utmi"))
  293. return FSL_USB2_PHY_UTMI;
  294. if (!strcasecmp(phy_type, "utmi_wide"))
  295. return FSL_USB2_PHY_UTMI_WIDE;
  296. if (!strcasecmp(phy_type, "serial"))
  297. return FSL_USB2_PHY_SERIAL;
  298. return FSL_USB2_PHY_NONE;
  299. }
  300. static int __init fsl_usb_of_init(void)
  301. {
  302. struct device_node *np;
  303. unsigned int i;
  304. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
  305. int ret;
  306. for (np = NULL, i = 0;
  307. (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
  308. i++) {
  309. struct resource r[2];
  310. struct fsl_usb2_platform_data usb_data;
  311. const unsigned char *prop = NULL;
  312. memset(&r, 0, sizeof(r));
  313. memset(&usb_data, 0, sizeof(usb_data));
  314. ret = of_address_to_resource(np, 0, &r[0]);
  315. if (ret)
  316. goto err;
  317. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  318. r[1].flags = IORESOURCE_IRQ;
  319. usb_dev_mph =
  320. platform_device_register_simple("fsl-ehci", i, r, 2);
  321. if (IS_ERR(usb_dev_mph)) {
  322. ret = PTR_ERR(usb_dev_mph);
  323. goto err;
  324. }
  325. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  326. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  327. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  328. prop = get_property(np, "port0", NULL);
  329. if (prop)
  330. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  331. prop = get_property(np, "port1", NULL);
  332. if (prop)
  333. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  334. prop = get_property(np, "phy_type", NULL);
  335. usb_data.phy_mode = determine_usb_phy(prop);
  336. ret =
  337. platform_device_add_data(usb_dev_mph, &usb_data,
  338. sizeof(struct
  339. fsl_usb2_platform_data));
  340. if (ret)
  341. goto unreg_mph;
  342. }
  343. for (np = NULL;
  344. (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
  345. i++) {
  346. struct resource r[2];
  347. struct fsl_usb2_platform_data usb_data;
  348. const unsigned char *prop = NULL;
  349. memset(&r, 0, sizeof(r));
  350. memset(&usb_data, 0, sizeof(usb_data));
  351. ret = of_address_to_resource(np, 0, &r[0]);
  352. if (ret)
  353. goto unreg_mph;
  354. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  355. r[1].flags = IORESOURCE_IRQ;
  356. usb_dev_dr =
  357. platform_device_register_simple("fsl-ehci", i, r, 2);
  358. if (IS_ERR(usb_dev_dr)) {
  359. ret = PTR_ERR(usb_dev_dr);
  360. goto err;
  361. }
  362. usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
  363. usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
  364. usb_data.operating_mode = FSL_USB2_DR_HOST;
  365. prop = get_property(np, "phy_type", NULL);
  366. usb_data.phy_mode = determine_usb_phy(prop);
  367. ret =
  368. platform_device_add_data(usb_dev_dr, &usb_data,
  369. sizeof(struct
  370. fsl_usb2_platform_data));
  371. if (ret)
  372. goto unreg_dr;
  373. }
  374. return 0;
  375. unreg_dr:
  376. if (usb_dev_dr)
  377. platform_device_unregister(usb_dev_dr);
  378. unreg_mph:
  379. if (usb_dev_mph)
  380. platform_device_unregister(usb_dev_mph);
  381. err:
  382. return ret;
  383. }
  384. arch_initcall(fsl_usb_of_init);