fsl_soc.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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/phy.h>
  25. #include <linux/fsl_devices.h>
  26. #include <linux/fs_enet_pd.h>
  27. #include <linux/fs_uart_pd.h>
  28. #include <asm/system.h>
  29. #include <asm/atomic.h>
  30. #include <asm/io.h>
  31. #include <asm/irq.h>
  32. #include <asm/time.h>
  33. #include <asm/prom.h>
  34. #include <sysdev/fsl_soc.h>
  35. #include <mm/mmu_decl.h>
  36. #include <asm/cpm2.h>
  37. extern void init_fcc_ioports(struct fs_platform_info*);
  38. extern void init_fec_ioports(struct fs_platform_info*);
  39. extern void init_smc_ioports(struct fs_uart_platform_info*);
  40. static phys_addr_t immrbase = -1;
  41. phys_addr_t get_immrbase(void)
  42. {
  43. struct device_node *soc;
  44. if (immrbase != -1)
  45. return immrbase;
  46. soc = of_find_node_by_type(NULL, "soc");
  47. if (soc) {
  48. unsigned int size;
  49. const void *prop = get_property(soc, "reg", &size);
  50. if (prop)
  51. immrbase = of_translate_address(soc, prop);
  52. of_node_put(soc);
  53. };
  54. return immrbase;
  55. }
  56. EXPORT_SYMBOL(get_immrbase);
  57. #if defined(CONFIG_CPM2) || defined(CONFIG_8xx)
  58. static u32 brgfreq = -1;
  59. u32 get_brgfreq(void)
  60. {
  61. struct device_node *node;
  62. if (brgfreq != -1)
  63. return brgfreq;
  64. node = of_find_node_by_type(NULL, "cpm");
  65. if (node) {
  66. unsigned int size;
  67. const unsigned int *prop = get_property(node, "brg-frequency",
  68. &size);
  69. if (prop)
  70. brgfreq = *prop;
  71. of_node_put(node);
  72. };
  73. return brgfreq;
  74. }
  75. EXPORT_SYMBOL(get_brgfreq);
  76. static u32 fs_baudrate = -1;
  77. u32 get_baudrate(void)
  78. {
  79. struct device_node *node;
  80. if (fs_baudrate != -1)
  81. return fs_baudrate;
  82. node = of_find_node_by_type(NULL, "serial");
  83. if (node) {
  84. unsigned int size;
  85. const unsigned int *prop = get_property(node, "current-speed",
  86. &size);
  87. if (prop)
  88. fs_baudrate = *prop;
  89. of_node_put(node);
  90. };
  91. return fs_baudrate;
  92. }
  93. EXPORT_SYMBOL(get_baudrate);
  94. #endif /* CONFIG_CPM2 */
  95. static int __init gfar_mdio_of_init(void)
  96. {
  97. struct device_node *np;
  98. unsigned int i;
  99. struct platform_device *mdio_dev;
  100. struct resource res;
  101. int ret;
  102. for (np = NULL, i = 0;
  103. (np = of_find_compatible_node(np, "mdio", "gianfar")) != NULL;
  104. i++) {
  105. int k;
  106. struct device_node *child = NULL;
  107. struct gianfar_mdio_data mdio_data;
  108. memset(&res, 0, sizeof(res));
  109. memset(&mdio_data, 0, sizeof(mdio_data));
  110. ret = of_address_to_resource(np, 0, &res);
  111. if (ret)
  112. goto err;
  113. mdio_dev =
  114. platform_device_register_simple("fsl-gianfar_mdio",
  115. res.start, &res, 1);
  116. if (IS_ERR(mdio_dev)) {
  117. ret = PTR_ERR(mdio_dev);
  118. goto err;
  119. }
  120. for (k = 0; k < 32; k++)
  121. mdio_data.irq[k] = PHY_POLL;
  122. while ((child = of_get_next_child(np, child)) != NULL) {
  123. int irq = irq_of_parse_and_map(child, 0);
  124. if (irq != NO_IRQ) {
  125. const u32 *id = get_property(child, "reg", NULL);
  126. mdio_data.irq[*id] = irq;
  127. }
  128. }
  129. ret =
  130. platform_device_add_data(mdio_dev, &mdio_data,
  131. sizeof(struct gianfar_mdio_data));
  132. if (ret)
  133. goto unreg;
  134. }
  135. return 0;
  136. unreg:
  137. platform_device_unregister(mdio_dev);
  138. err:
  139. return ret;
  140. }
  141. arch_initcall(gfar_mdio_of_init);
  142. static const char *gfar_tx_intr = "tx";
  143. static const char *gfar_rx_intr = "rx";
  144. static const char *gfar_err_intr = "error";
  145. static int __init gfar_of_init(void)
  146. {
  147. struct device_node *np;
  148. unsigned int i;
  149. struct platform_device *gfar_dev;
  150. struct resource res;
  151. int ret;
  152. for (np = NULL, i = 0;
  153. (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
  154. i++) {
  155. struct resource r[4];
  156. struct device_node *phy, *mdio;
  157. struct gianfar_platform_data gfar_data;
  158. const unsigned int *id;
  159. const char *model;
  160. const void *mac_addr;
  161. const phandle *ph;
  162. int n_res = 2;
  163. memset(r, 0, sizeof(r));
  164. memset(&gfar_data, 0, sizeof(gfar_data));
  165. ret = of_address_to_resource(np, 0, &r[0]);
  166. if (ret)
  167. goto err;
  168. of_irq_to_resource(np, 0, &r[1]);
  169. model = get_property(np, "model", NULL);
  170. /* If we aren't the FEC we have multiple interrupts */
  171. if (model && strcasecmp(model, "FEC")) {
  172. r[1].name = gfar_tx_intr;
  173. r[2].name = gfar_rx_intr;
  174. of_irq_to_resource(np, 1, &r[2]);
  175. r[3].name = gfar_err_intr;
  176. of_irq_to_resource(np, 2, &r[3]);
  177. n_res += 2;
  178. }
  179. gfar_dev =
  180. platform_device_register_simple("fsl-gianfar", i, &r[0],
  181. n_res);
  182. if (IS_ERR(gfar_dev)) {
  183. ret = PTR_ERR(gfar_dev);
  184. goto err;
  185. }
  186. mac_addr = get_property(np, "local-mac-address", NULL);
  187. if (mac_addr == NULL)
  188. mac_addr = get_property(np, "mac-address", NULL);
  189. if (mac_addr == NULL) {
  190. /* Obsolete */
  191. mac_addr = get_property(np, "address", NULL);
  192. }
  193. if (mac_addr)
  194. memcpy(gfar_data.mac_addr, mac_addr, 6);
  195. if (model && !strcasecmp(model, "TSEC"))
  196. gfar_data.device_flags =
  197. FSL_GIANFAR_DEV_HAS_GIGABIT |
  198. FSL_GIANFAR_DEV_HAS_COALESCE |
  199. FSL_GIANFAR_DEV_HAS_RMON |
  200. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  201. if (model && !strcasecmp(model, "eTSEC"))
  202. gfar_data.device_flags =
  203. FSL_GIANFAR_DEV_HAS_GIGABIT |
  204. FSL_GIANFAR_DEV_HAS_COALESCE |
  205. FSL_GIANFAR_DEV_HAS_RMON |
  206. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  207. FSL_GIANFAR_DEV_HAS_CSUM |
  208. FSL_GIANFAR_DEV_HAS_VLAN |
  209. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  210. ph = get_property(np, "phy-handle", NULL);
  211. phy = of_find_node_by_phandle(*ph);
  212. if (phy == NULL) {
  213. ret = -ENODEV;
  214. goto unreg;
  215. }
  216. mdio = of_get_parent(phy);
  217. id = get_property(phy, "reg", NULL);
  218. ret = of_address_to_resource(mdio, 0, &res);
  219. if (ret) {
  220. of_node_put(phy);
  221. of_node_put(mdio);
  222. goto unreg;
  223. }
  224. gfar_data.phy_id = *id;
  225. gfar_data.bus_id = res.start;
  226. of_node_put(phy);
  227. of_node_put(mdio);
  228. ret =
  229. platform_device_add_data(gfar_dev, &gfar_data,
  230. sizeof(struct
  231. gianfar_platform_data));
  232. if (ret)
  233. goto unreg;
  234. }
  235. return 0;
  236. unreg:
  237. platform_device_unregister(gfar_dev);
  238. err:
  239. return ret;
  240. }
  241. arch_initcall(gfar_of_init);
  242. static int __init fsl_i2c_of_init(void)
  243. {
  244. struct device_node *np;
  245. unsigned int i;
  246. struct platform_device *i2c_dev;
  247. int ret;
  248. for (np = NULL, i = 0;
  249. (np = of_find_compatible_node(np, "i2c", "fsl-i2c")) != NULL;
  250. i++) {
  251. struct resource r[2];
  252. struct fsl_i2c_platform_data i2c_data;
  253. const unsigned char *flags = NULL;
  254. memset(&r, 0, sizeof(r));
  255. memset(&i2c_data, 0, sizeof(i2c_data));
  256. ret = of_address_to_resource(np, 0, &r[0]);
  257. if (ret)
  258. goto err;
  259. of_irq_to_resource(np, 0, &r[1]);
  260. i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
  261. if (IS_ERR(i2c_dev)) {
  262. ret = PTR_ERR(i2c_dev);
  263. goto err;
  264. }
  265. i2c_data.device_flags = 0;
  266. flags = get_property(np, "dfsrr", NULL);
  267. if (flags)
  268. i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
  269. flags = get_property(np, "fsl5200-clocking", NULL);
  270. if (flags)
  271. i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
  272. ret =
  273. platform_device_add_data(i2c_dev, &i2c_data,
  274. sizeof(struct
  275. fsl_i2c_platform_data));
  276. if (ret)
  277. goto unreg;
  278. }
  279. return 0;
  280. unreg:
  281. platform_device_unregister(i2c_dev);
  282. err:
  283. return ret;
  284. }
  285. arch_initcall(fsl_i2c_of_init);
  286. #ifdef CONFIG_PPC_83xx
  287. static int __init mpc83xx_wdt_init(void)
  288. {
  289. struct resource r;
  290. struct device_node *soc, *np;
  291. struct platform_device *dev;
  292. const unsigned int *freq;
  293. int ret;
  294. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  295. if (!np) {
  296. ret = -ENODEV;
  297. goto nodev;
  298. }
  299. soc = of_find_node_by_type(NULL, "soc");
  300. if (!soc) {
  301. ret = -ENODEV;
  302. goto nosoc;
  303. }
  304. freq = get_property(soc, "bus-frequency", NULL);
  305. if (!freq) {
  306. ret = -ENODEV;
  307. goto err;
  308. }
  309. memset(&r, 0, sizeof(r));
  310. ret = of_address_to_resource(np, 0, &r);
  311. if (ret)
  312. goto err;
  313. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  314. if (IS_ERR(dev)) {
  315. ret = PTR_ERR(dev);
  316. goto err;
  317. }
  318. ret = platform_device_add_data(dev, freq, sizeof(int));
  319. if (ret)
  320. goto unreg;
  321. of_node_put(soc);
  322. of_node_put(np);
  323. return 0;
  324. unreg:
  325. platform_device_unregister(dev);
  326. err:
  327. of_node_put(soc);
  328. nosoc:
  329. of_node_put(np);
  330. nodev:
  331. return ret;
  332. }
  333. arch_initcall(mpc83xx_wdt_init);
  334. #endif
  335. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  336. {
  337. if (!phy_type)
  338. return FSL_USB2_PHY_NONE;
  339. if (!strcasecmp(phy_type, "ulpi"))
  340. return FSL_USB2_PHY_ULPI;
  341. if (!strcasecmp(phy_type, "utmi"))
  342. return FSL_USB2_PHY_UTMI;
  343. if (!strcasecmp(phy_type, "utmi_wide"))
  344. return FSL_USB2_PHY_UTMI_WIDE;
  345. if (!strcasecmp(phy_type, "serial"))
  346. return FSL_USB2_PHY_SERIAL;
  347. return FSL_USB2_PHY_NONE;
  348. }
  349. static int __init fsl_usb_of_init(void)
  350. {
  351. struct device_node *np;
  352. unsigned int i;
  353. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
  354. *usb_dev_dr_client = NULL;
  355. int ret;
  356. for (np = NULL, i = 0;
  357. (np = of_find_compatible_node(np, "usb", "fsl-usb2-mph")) != NULL;
  358. i++) {
  359. struct resource r[2];
  360. struct fsl_usb2_platform_data usb_data;
  361. const unsigned char *prop = NULL;
  362. memset(&r, 0, sizeof(r));
  363. memset(&usb_data, 0, sizeof(usb_data));
  364. ret = of_address_to_resource(np, 0, &r[0]);
  365. if (ret)
  366. goto err;
  367. of_irq_to_resource(np, 0, &r[1]);
  368. usb_dev_mph =
  369. platform_device_register_simple("fsl-ehci", i, r, 2);
  370. if (IS_ERR(usb_dev_mph)) {
  371. ret = PTR_ERR(usb_dev_mph);
  372. goto err;
  373. }
  374. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  375. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  376. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  377. prop = get_property(np, "port0", NULL);
  378. if (prop)
  379. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  380. prop = get_property(np, "port1", NULL);
  381. if (prop)
  382. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  383. prop = get_property(np, "phy_type", NULL);
  384. usb_data.phy_mode = determine_usb_phy(prop);
  385. ret =
  386. platform_device_add_data(usb_dev_mph, &usb_data,
  387. sizeof(struct
  388. fsl_usb2_platform_data));
  389. if (ret)
  390. goto unreg_mph;
  391. }
  392. for (np = NULL;
  393. (np = of_find_compatible_node(np, "usb", "fsl-usb2-dr")) != NULL;
  394. i++) {
  395. struct resource r[2];
  396. struct fsl_usb2_platform_data usb_data;
  397. const unsigned char *prop = NULL;
  398. memset(&r, 0, sizeof(r));
  399. memset(&usb_data, 0, sizeof(usb_data));
  400. ret = of_address_to_resource(np, 0, &r[0]);
  401. if (ret)
  402. goto unreg_mph;
  403. of_irq_to_resource(np, 0, &r[1]);
  404. prop = get_property(np, "dr_mode", NULL);
  405. if (!prop || !strcmp(prop, "host")) {
  406. usb_data.operating_mode = FSL_USB2_DR_HOST;
  407. usb_dev_dr_host = platform_device_register_simple(
  408. "fsl-ehci", i, r, 2);
  409. if (IS_ERR(usb_dev_dr_host)) {
  410. ret = PTR_ERR(usb_dev_dr_host);
  411. goto err;
  412. }
  413. } else if (prop && !strcmp(prop, "peripheral")) {
  414. usb_data.operating_mode = FSL_USB2_DR_DEVICE;
  415. usb_dev_dr_client = platform_device_register_simple(
  416. "fsl-usb2-udc", i, r, 2);
  417. if (IS_ERR(usb_dev_dr_client)) {
  418. ret = PTR_ERR(usb_dev_dr_client);
  419. goto err;
  420. }
  421. } else if (prop && !strcmp(prop, "otg")) {
  422. usb_data.operating_mode = FSL_USB2_DR_OTG;
  423. usb_dev_dr_host = platform_device_register_simple(
  424. "fsl-ehci", i, r, 2);
  425. if (IS_ERR(usb_dev_dr_host)) {
  426. ret = PTR_ERR(usb_dev_dr_host);
  427. goto err;
  428. }
  429. usb_dev_dr_client = platform_device_register_simple(
  430. "fsl-usb2-udc", i, r, 2);
  431. if (IS_ERR(usb_dev_dr_client)) {
  432. ret = PTR_ERR(usb_dev_dr_client);
  433. goto err;
  434. }
  435. } else {
  436. ret = -EINVAL;
  437. goto err;
  438. }
  439. prop = get_property(np, "phy_type", NULL);
  440. usb_data.phy_mode = determine_usb_phy(prop);
  441. if (usb_dev_dr_host) {
  442. usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
  443. usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
  444. dev.coherent_dma_mask;
  445. if ((ret = platform_device_add_data(usb_dev_dr_host,
  446. &usb_data, sizeof(struct
  447. fsl_usb2_platform_data))))
  448. goto unreg_dr;
  449. }
  450. if (usb_dev_dr_client) {
  451. usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
  452. usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
  453. dev.coherent_dma_mask;
  454. if ((ret = platform_device_add_data(usb_dev_dr_client,
  455. &usb_data, sizeof(struct
  456. fsl_usb2_platform_data))))
  457. goto unreg_dr;
  458. }
  459. }
  460. return 0;
  461. unreg_dr:
  462. if (usb_dev_dr_host)
  463. platform_device_unregister(usb_dev_dr_host);
  464. if (usb_dev_dr_client)
  465. platform_device_unregister(usb_dev_dr_client);
  466. unreg_mph:
  467. if (usb_dev_mph)
  468. platform_device_unregister(usb_dev_mph);
  469. err:
  470. return ret;
  471. }
  472. arch_initcall(fsl_usb_of_init);
  473. #ifdef CONFIG_CPM2
  474. extern void init_scc_ioports(struct fs_uart_platform_info*);
  475. static const char fcc_regs[] = "fcc_regs";
  476. static const char fcc_regs_c[] = "fcc_regs_c";
  477. static const char fcc_pram[] = "fcc_pram";
  478. static char bus_id[9][BUS_ID_SIZE];
  479. static int __init fs_enet_of_init(void)
  480. {
  481. struct device_node *np;
  482. unsigned int i;
  483. struct platform_device *fs_enet_dev;
  484. struct resource res;
  485. int ret;
  486. for (np = NULL, i = 0;
  487. (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
  488. i++) {
  489. struct resource r[4];
  490. struct device_node *phy, *mdio;
  491. struct fs_platform_info fs_enet_data;
  492. const unsigned int *id, *phy_addr, *phy_irq;
  493. const void *mac_addr;
  494. const phandle *ph;
  495. const char *model;
  496. memset(r, 0, sizeof(r));
  497. memset(&fs_enet_data, 0, sizeof(fs_enet_data));
  498. ret = of_address_to_resource(np, 0, &r[0]);
  499. if (ret)
  500. goto err;
  501. r[0].name = fcc_regs;
  502. ret = of_address_to_resource(np, 1, &r[1]);
  503. if (ret)
  504. goto err;
  505. r[1].name = fcc_pram;
  506. ret = of_address_to_resource(np, 2, &r[2]);
  507. if (ret)
  508. goto err;
  509. r[2].name = fcc_regs_c;
  510. fs_enet_data.fcc_regs_c = r[2].start;
  511. of_irq_to_resource(np, 0, &r[3]);
  512. fs_enet_dev =
  513. platform_device_register_simple("fsl-cpm-fcc", i, &r[0], 4);
  514. if (IS_ERR(fs_enet_dev)) {
  515. ret = PTR_ERR(fs_enet_dev);
  516. goto err;
  517. }
  518. model = get_property(np, "model", NULL);
  519. if (model == NULL) {
  520. ret = -ENODEV;
  521. goto unreg;
  522. }
  523. mac_addr = get_property(np, "mac-address", NULL);
  524. memcpy(fs_enet_data.macaddr, mac_addr, 6);
  525. ph = get_property(np, "phy-handle", NULL);
  526. phy = of_find_node_by_phandle(*ph);
  527. if (phy == NULL) {
  528. ret = -ENODEV;
  529. goto unreg;
  530. }
  531. phy_addr = get_property(phy, "reg", NULL);
  532. fs_enet_data.phy_addr = *phy_addr;
  533. phy_irq = get_property(phy, "interrupts", NULL);
  534. id = get_property(np, "device-id", NULL);
  535. fs_enet_data.fs_no = *id;
  536. strcpy(fs_enet_data.fs_type, model);
  537. mdio = of_get_parent(phy);
  538. ret = of_address_to_resource(mdio, 0, &res);
  539. if (ret) {
  540. of_node_put(phy);
  541. of_node_put(mdio);
  542. goto unreg;
  543. }
  544. fs_enet_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL));
  545. fs_enet_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL));
  546. if (strstr(model, "FCC")) {
  547. int fcc_index = *id - 1;
  548. const unsigned char *mdio_bb_prop;
  549. fs_enet_data.dpram_offset = (u32)cpm_dpram_addr(0);
  550. fs_enet_data.rx_ring = 32;
  551. fs_enet_data.tx_ring = 32;
  552. fs_enet_data.rx_copybreak = 240;
  553. fs_enet_data.use_napi = 0;
  554. fs_enet_data.napi_weight = 17;
  555. fs_enet_data.mem_offset = FCC_MEM_OFFSET(fcc_index);
  556. fs_enet_data.cp_page = CPM_CR_FCC_PAGE(fcc_index);
  557. fs_enet_data.cp_block = CPM_CR_FCC_SBLOCK(fcc_index);
  558. snprintf((char*)&bus_id[(*id)], BUS_ID_SIZE, "%x:%02x",
  559. (u32)res.start, fs_enet_data.phy_addr);
  560. fs_enet_data.bus_id = (char*)&bus_id[(*id)];
  561. fs_enet_data.init_ioports = init_fcc_ioports;
  562. mdio_bb_prop = get_property(phy, "bitbang", NULL);
  563. if (mdio_bb_prop) {
  564. struct platform_device *fs_enet_mdio_bb_dev;
  565. struct fs_mii_bb_platform_info fs_enet_mdio_bb_data;
  566. fs_enet_mdio_bb_dev =
  567. platform_device_register_simple("fsl-bb-mdio",
  568. i, NULL, 0);
  569. memset(&fs_enet_mdio_bb_data, 0,
  570. sizeof(struct fs_mii_bb_platform_info));
  571. fs_enet_mdio_bb_data.mdio_dat.bit =
  572. mdio_bb_prop[0];
  573. fs_enet_mdio_bb_data.mdio_dir.bit =
  574. mdio_bb_prop[1];
  575. fs_enet_mdio_bb_data.mdc_dat.bit =
  576. mdio_bb_prop[2];
  577. fs_enet_mdio_bb_data.mdio_port =
  578. mdio_bb_prop[3];
  579. fs_enet_mdio_bb_data.mdc_port =
  580. mdio_bb_prop[4];
  581. fs_enet_mdio_bb_data.delay =
  582. mdio_bb_prop[5];
  583. fs_enet_mdio_bb_data.irq[0] = phy_irq[0];
  584. fs_enet_mdio_bb_data.irq[1] = -1;
  585. fs_enet_mdio_bb_data.irq[2] = -1;
  586. fs_enet_mdio_bb_data.irq[3] = phy_irq[0];
  587. fs_enet_mdio_bb_data.irq[31] = -1;
  588. fs_enet_mdio_bb_data.mdio_dat.offset =
  589. (u32)&cpm2_immr->im_ioport.iop_pdatc;
  590. fs_enet_mdio_bb_data.mdio_dir.offset =
  591. (u32)&cpm2_immr->im_ioport.iop_pdirc;
  592. fs_enet_mdio_bb_data.mdc_dat.offset =
  593. (u32)&cpm2_immr->im_ioport.iop_pdatc;
  594. ret = platform_device_add_data(
  595. fs_enet_mdio_bb_dev,
  596. &fs_enet_mdio_bb_data,
  597. sizeof(struct fs_mii_bb_platform_info));
  598. if (ret)
  599. goto unreg;
  600. }
  601. of_node_put(phy);
  602. of_node_put(mdio);
  603. ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
  604. sizeof(struct
  605. fs_platform_info));
  606. if (ret)
  607. goto unreg;
  608. }
  609. }
  610. return 0;
  611. unreg:
  612. platform_device_unregister(fs_enet_dev);
  613. err:
  614. return ret;
  615. }
  616. arch_initcall(fs_enet_of_init);
  617. static const char scc_regs[] = "regs";
  618. static const char scc_pram[] = "pram";
  619. static int __init cpm_uart_of_init(void)
  620. {
  621. struct device_node *np;
  622. unsigned int i;
  623. struct platform_device *cpm_uart_dev;
  624. int ret;
  625. for (np = NULL, i = 0;
  626. (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
  627. i++) {
  628. struct resource r[3];
  629. struct fs_uart_platform_info cpm_uart_data;
  630. const int *id;
  631. const char *model;
  632. memset(r, 0, sizeof(r));
  633. memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
  634. ret = of_address_to_resource(np, 0, &r[0]);
  635. if (ret)
  636. goto err;
  637. r[0].name = scc_regs;
  638. ret = of_address_to_resource(np, 1, &r[1]);
  639. if (ret)
  640. goto err;
  641. r[1].name = scc_pram;
  642. of_irq_to_resource(np, 0, &r[2]);
  643. cpm_uart_dev =
  644. platform_device_register_simple("fsl-cpm-scc:uart", i, &r[0], 3);
  645. if (IS_ERR(cpm_uart_dev)) {
  646. ret = PTR_ERR(cpm_uart_dev);
  647. goto err;
  648. }
  649. id = get_property(np, "device-id", NULL);
  650. cpm_uart_data.fs_no = *id;
  651. model = (char*)get_property(np, "model", NULL);
  652. strcpy(cpm_uart_data.fs_type, model);
  653. cpm_uart_data.uart_clk = ppc_proc_freq;
  654. cpm_uart_data.tx_num_fifo = 4;
  655. cpm_uart_data.tx_buf_size = 32;
  656. cpm_uart_data.rx_num_fifo = 4;
  657. cpm_uart_data.rx_buf_size = 32;
  658. cpm_uart_data.clk_rx = *((u32 *) get_property(np, "rx-clock", NULL));
  659. cpm_uart_data.clk_tx = *((u32 *) get_property(np, "tx-clock", NULL));
  660. ret =
  661. platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
  662. sizeof(struct
  663. fs_uart_platform_info));
  664. if (ret)
  665. goto unreg;
  666. }
  667. return 0;
  668. unreg:
  669. platform_device_unregister(cpm_uart_dev);
  670. err:
  671. return ret;
  672. }
  673. arch_initcall(cpm_uart_of_init);
  674. #endif /* CONFIG_CPM2 */
  675. #ifdef CONFIG_8xx
  676. extern void init_scc_ioports(struct fs_platform_info*);
  677. extern int platform_device_skip(char *model, int id);
  678. static int __init fs_enet_mdio_of_init(void)
  679. {
  680. struct device_node *np;
  681. unsigned int i;
  682. struct platform_device *mdio_dev;
  683. struct resource res;
  684. int ret;
  685. for (np = NULL, i = 0;
  686. (np = of_find_compatible_node(np, "mdio", "fs_enet")) != NULL;
  687. i++) {
  688. struct fs_mii_fec_platform_info mdio_data;
  689. memset(&res, 0, sizeof(res));
  690. memset(&mdio_data, 0, sizeof(mdio_data));
  691. ret = of_address_to_resource(np, 0, &res);
  692. if (ret)
  693. goto err;
  694. mdio_dev =
  695. platform_device_register_simple("fsl-cpm-fec-mdio",
  696. res.start, &res, 1);
  697. if (IS_ERR(mdio_dev)) {
  698. ret = PTR_ERR(mdio_dev);
  699. goto err;
  700. }
  701. mdio_data.mii_speed = ((((ppc_proc_freq + 4999999) / 2500000) / 2) & 0x3F) << 1;
  702. ret =
  703. platform_device_add_data(mdio_dev, &mdio_data,
  704. sizeof(struct fs_mii_fec_platform_info));
  705. if (ret)
  706. goto unreg;
  707. }
  708. return 0;
  709. unreg:
  710. platform_device_unregister(mdio_dev);
  711. err:
  712. return ret;
  713. }
  714. arch_initcall(fs_enet_mdio_of_init);
  715. static const char *enet_regs = "regs";
  716. static const char *enet_pram = "pram";
  717. static const char *enet_irq = "interrupt";
  718. static char bus_id[9][BUS_ID_SIZE];
  719. static int __init fs_enet_of_init(void)
  720. {
  721. struct device_node *np;
  722. unsigned int i;
  723. struct platform_device *fs_enet_dev = NULL;
  724. struct resource res;
  725. int ret;
  726. for (np = NULL, i = 0;
  727. (np = of_find_compatible_node(np, "network", "fs_enet")) != NULL;
  728. i++) {
  729. struct resource r[4];
  730. struct device_node *phy = NULL, *mdio = NULL;
  731. struct fs_platform_info fs_enet_data;
  732. unsigned int *id, *phy_addr;
  733. void *mac_addr;
  734. phandle *ph;
  735. char *model;
  736. memset(r, 0, sizeof(r));
  737. memset(&fs_enet_data, 0, sizeof(fs_enet_data));
  738. model = (char *)get_property(np, "model", NULL);
  739. if (model == NULL) {
  740. ret = -ENODEV;
  741. goto unreg;
  742. }
  743. id = (u32 *) get_property(np, "device-id", NULL);
  744. fs_enet_data.fs_no = *id;
  745. if (platform_device_skip(model, *id))
  746. continue;
  747. ret = of_address_to_resource(np, 0, &r[0]);
  748. if (ret)
  749. goto err;
  750. r[0].name = enet_regs;
  751. mac_addr = (void *)get_property(np, "mac-address", NULL);
  752. memcpy(fs_enet_data.macaddr, mac_addr, 6);
  753. ph = (phandle *) get_property(np, "phy-handle", NULL);
  754. if (ph != NULL)
  755. phy = of_find_node_by_phandle(*ph);
  756. if (phy != NULL) {
  757. phy_addr = (u32 *) get_property(phy, "reg", NULL);
  758. fs_enet_data.phy_addr = *phy_addr;
  759. fs_enet_data.has_phy = 1;
  760. mdio = of_get_parent(phy);
  761. ret = of_address_to_resource(mdio, 0, &res);
  762. if (ret) {
  763. of_node_put(phy);
  764. of_node_put(mdio);
  765. goto unreg;
  766. }
  767. }
  768. model = (char*)get_property(np, "model", NULL);
  769. strcpy(fs_enet_data.fs_type, model);
  770. if (strstr(model, "FEC")) {
  771. r[1].start = r[1].end = irq_of_parse_and_map(np, 0);
  772. r[1].flags = IORESOURCE_IRQ;
  773. r[1].name = enet_irq;
  774. fs_enet_dev =
  775. platform_device_register_simple("fsl-cpm-fec", i, &r[0], 2);
  776. if (IS_ERR(fs_enet_dev)) {
  777. ret = PTR_ERR(fs_enet_dev);
  778. goto err;
  779. }
  780. fs_enet_data.rx_ring = 128;
  781. fs_enet_data.tx_ring = 16;
  782. fs_enet_data.rx_copybreak = 240;
  783. fs_enet_data.use_napi = 1;
  784. fs_enet_data.napi_weight = 17;
  785. snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%x:%02x",
  786. (u32)res.start, fs_enet_data.phy_addr);
  787. fs_enet_data.bus_id = (char*)&bus_id[i];
  788. fs_enet_data.init_ioports = init_fec_ioports;
  789. }
  790. if (strstr(model, "SCC")) {
  791. ret = of_address_to_resource(np, 1, &r[1]);
  792. if (ret)
  793. goto err;
  794. r[1].name = enet_pram;
  795. r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
  796. r[2].flags = IORESOURCE_IRQ;
  797. r[2].name = enet_irq;
  798. fs_enet_dev =
  799. platform_device_register_simple("fsl-cpm-scc", i, &r[0], 3);
  800. if (IS_ERR(fs_enet_dev)) {
  801. ret = PTR_ERR(fs_enet_dev);
  802. goto err;
  803. }
  804. fs_enet_data.rx_ring = 64;
  805. fs_enet_data.tx_ring = 8;
  806. fs_enet_data.rx_copybreak = 240;
  807. fs_enet_data.use_napi = 1;
  808. fs_enet_data.napi_weight = 17;
  809. snprintf((char*)&bus_id[i], BUS_ID_SIZE, "%s", "fixed@10:1");
  810. fs_enet_data.bus_id = (char*)&bus_id[i];
  811. fs_enet_data.init_ioports = init_scc_ioports;
  812. }
  813. of_node_put(phy);
  814. of_node_put(mdio);
  815. ret = platform_device_add_data(fs_enet_dev, &fs_enet_data,
  816. sizeof(struct
  817. fs_platform_info));
  818. if (ret)
  819. goto unreg;
  820. }
  821. return 0;
  822. unreg:
  823. platform_device_unregister(fs_enet_dev);
  824. err:
  825. return ret;
  826. }
  827. arch_initcall(fs_enet_of_init);
  828. static const char *smc_regs = "regs";
  829. static const char *smc_pram = "pram";
  830. static int __init cpm_smc_uart_of_init(void)
  831. {
  832. struct device_node *np;
  833. unsigned int i;
  834. struct platform_device *cpm_uart_dev;
  835. int ret;
  836. for (np = NULL, i = 0;
  837. (np = of_find_compatible_node(np, "serial", "cpm_uart")) != NULL;
  838. i++) {
  839. struct resource r[3];
  840. struct fs_uart_platform_info cpm_uart_data;
  841. int *id;
  842. char *model;
  843. memset(r, 0, sizeof(r));
  844. memset(&cpm_uart_data, 0, sizeof(cpm_uart_data));
  845. ret = of_address_to_resource(np, 0, &r[0]);
  846. if (ret)
  847. goto err;
  848. r[0].name = smc_regs;
  849. ret = of_address_to_resource(np, 1, &r[1]);
  850. if (ret)
  851. goto err;
  852. r[1].name = smc_pram;
  853. r[2].start = r[2].end = irq_of_parse_and_map(np, 0);
  854. r[2].flags = IORESOURCE_IRQ;
  855. cpm_uart_dev =
  856. platform_device_register_simple("fsl-cpm-smc:uart", i, &r[0], 3);
  857. if (IS_ERR(cpm_uart_dev)) {
  858. ret = PTR_ERR(cpm_uart_dev);
  859. goto err;
  860. }
  861. model = (char*)get_property(np, "model", NULL);
  862. strcpy(cpm_uart_data.fs_type, model);
  863. id = (int*)get_property(np, "device-id", NULL);
  864. cpm_uart_data.fs_no = *id;
  865. cpm_uart_data.uart_clk = ppc_proc_freq;
  866. cpm_uart_data.tx_num_fifo = 4;
  867. cpm_uart_data.tx_buf_size = 32;
  868. cpm_uart_data.rx_num_fifo = 4;
  869. cpm_uart_data.rx_buf_size = 32;
  870. ret =
  871. platform_device_add_data(cpm_uart_dev, &cpm_uart_data,
  872. sizeof(struct
  873. fs_uart_platform_info));
  874. if (ret)
  875. goto unreg;
  876. }
  877. return 0;
  878. unreg:
  879. platform_device_unregister(cpm_uart_dev);
  880. err:
  881. return ret;
  882. }
  883. arch_initcall(cpm_smc_uart_of_init);
  884. #endif /* CONFIG_8xx */