fsl_soc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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_platform.h>
  25. #include <linux/phy.h>
  26. #include <linux/phy_fixed.h>
  27. #include <linux/spi/spi.h>
  28. #include <linux/fsl_devices.h>
  29. #include <linux/fs_enet_pd.h>
  30. #include <linux/fs_uart_pd.h>
  31. #include <asm/system.h>
  32. #include <asm/atomic.h>
  33. #include <asm/io.h>
  34. #include <asm/irq.h>
  35. #include <asm/time.h>
  36. #include <asm/prom.h>
  37. #include <sysdev/fsl_soc.h>
  38. #include <mm/mmu_decl.h>
  39. #include <asm/cpm2.h>
  40. extern void init_fcc_ioports(struct fs_platform_info*);
  41. extern void init_fec_ioports(struct fs_platform_info*);
  42. extern void init_smc_ioports(struct fs_uart_platform_info*);
  43. static phys_addr_t immrbase = -1;
  44. phys_addr_t get_immrbase(void)
  45. {
  46. struct device_node *soc;
  47. if (immrbase != -1)
  48. return immrbase;
  49. soc = of_find_node_by_type(NULL, "soc");
  50. if (soc) {
  51. int size;
  52. u32 naddr;
  53. const u32 *prop = of_get_property(soc, "#address-cells", &size);
  54. if (prop && size == 4)
  55. naddr = *prop;
  56. else
  57. naddr = 2;
  58. prop = of_get_property(soc, "ranges", &size);
  59. if (prop)
  60. immrbase = of_translate_address(soc, prop + naddr);
  61. of_node_put(soc);
  62. }
  63. return immrbase;
  64. }
  65. EXPORT_SYMBOL(get_immrbase);
  66. static u32 sysfreq = -1;
  67. u32 fsl_get_sys_freq(void)
  68. {
  69. struct device_node *soc;
  70. const u32 *prop;
  71. int size;
  72. if (sysfreq != -1)
  73. return sysfreq;
  74. soc = of_find_node_by_type(NULL, "soc");
  75. if (!soc)
  76. return -1;
  77. prop = of_get_property(soc, "clock-frequency", &size);
  78. if (!prop || size != sizeof(*prop) || *prop == 0)
  79. prop = of_get_property(soc, "bus-frequency", &size);
  80. if (prop && size == sizeof(*prop))
  81. sysfreq = *prop;
  82. of_node_put(soc);
  83. return sysfreq;
  84. }
  85. EXPORT_SYMBOL(fsl_get_sys_freq);
  86. #if defined(CONFIG_CPM2) || defined(CONFIG_QUICC_ENGINE) || defined(CONFIG_8xx)
  87. static u32 brgfreq = -1;
  88. u32 get_brgfreq(void)
  89. {
  90. struct device_node *node;
  91. const unsigned int *prop;
  92. int size;
  93. if (brgfreq != -1)
  94. return brgfreq;
  95. node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
  96. if (node) {
  97. prop = of_get_property(node, "clock-frequency", &size);
  98. if (prop && size == 4)
  99. brgfreq = *prop;
  100. of_node_put(node);
  101. return brgfreq;
  102. }
  103. /* Legacy device binding -- will go away when no users are left. */
  104. node = of_find_node_by_type(NULL, "cpm");
  105. if (!node)
  106. node = of_find_compatible_node(NULL, NULL, "fsl,qe");
  107. if (!node)
  108. node = of_find_node_by_type(NULL, "qe");
  109. if (node) {
  110. prop = of_get_property(node, "brg-frequency", &size);
  111. if (prop && size == 4)
  112. brgfreq = *prop;
  113. if (brgfreq == -1 || brgfreq == 0) {
  114. prop = of_get_property(node, "bus-frequency", &size);
  115. if (prop && size == 4)
  116. brgfreq = *prop / 2;
  117. }
  118. of_node_put(node);
  119. }
  120. return brgfreq;
  121. }
  122. EXPORT_SYMBOL(get_brgfreq);
  123. static u32 fs_baudrate = -1;
  124. u32 get_baudrate(void)
  125. {
  126. struct device_node *node;
  127. if (fs_baudrate != -1)
  128. return fs_baudrate;
  129. node = of_find_node_by_type(NULL, "serial");
  130. if (node) {
  131. int size;
  132. const unsigned int *prop = of_get_property(node,
  133. "current-speed", &size);
  134. if (prop)
  135. fs_baudrate = *prop;
  136. of_node_put(node);
  137. }
  138. return fs_baudrate;
  139. }
  140. EXPORT_SYMBOL(get_baudrate);
  141. #endif /* CONFIG_CPM2 */
  142. #ifdef CONFIG_FIXED_PHY
  143. static int __init of_add_fixed_phys(void)
  144. {
  145. int ret;
  146. struct device_node *np;
  147. u32 *fixed_link;
  148. struct fixed_phy_status status = {};
  149. for_each_node_by_name(np, "ethernet") {
  150. fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
  151. if (!fixed_link)
  152. continue;
  153. status.link = 1;
  154. status.duplex = fixed_link[1];
  155. status.speed = fixed_link[2];
  156. status.pause = fixed_link[3];
  157. status.asym_pause = fixed_link[4];
  158. ret = fixed_phy_add(PHY_POLL, fixed_link[0], &status);
  159. if (ret) {
  160. of_node_put(np);
  161. return ret;
  162. }
  163. }
  164. return 0;
  165. }
  166. arch_initcall(of_add_fixed_phys);
  167. #endif /* CONFIG_FIXED_PHY */
  168. static int __init gfar_mdio_of_init(void)
  169. {
  170. struct device_node *np = NULL;
  171. struct platform_device *mdio_dev;
  172. struct resource res;
  173. int ret;
  174. np = of_find_compatible_node(np, NULL, "fsl,gianfar-mdio");
  175. /* try the deprecated version */
  176. if (!np)
  177. np = of_find_compatible_node(np, "mdio", "gianfar");
  178. if (np) {
  179. int k;
  180. struct device_node *child = NULL;
  181. struct gianfar_mdio_data mdio_data;
  182. memset(&res, 0, sizeof(res));
  183. memset(&mdio_data, 0, sizeof(mdio_data));
  184. ret = of_address_to_resource(np, 0, &res);
  185. if (ret)
  186. goto err;
  187. mdio_dev =
  188. platform_device_register_simple("fsl-gianfar_mdio",
  189. res.start, &res, 1);
  190. if (IS_ERR(mdio_dev)) {
  191. ret = PTR_ERR(mdio_dev);
  192. goto err;
  193. }
  194. for (k = 0; k < 32; k++)
  195. mdio_data.irq[k] = PHY_POLL;
  196. while ((child = of_get_next_child(np, child)) != NULL) {
  197. int irq = irq_of_parse_and_map(child, 0);
  198. if (irq != NO_IRQ) {
  199. const u32 *id = of_get_property(child,
  200. "reg", NULL);
  201. mdio_data.irq[*id] = irq;
  202. }
  203. }
  204. ret =
  205. platform_device_add_data(mdio_dev, &mdio_data,
  206. sizeof(struct gianfar_mdio_data));
  207. if (ret)
  208. goto unreg;
  209. }
  210. of_node_put(np);
  211. return 0;
  212. unreg:
  213. platform_device_unregister(mdio_dev);
  214. err:
  215. of_node_put(np);
  216. return ret;
  217. }
  218. arch_initcall(gfar_mdio_of_init);
  219. static const char *gfar_tx_intr = "tx";
  220. static const char *gfar_rx_intr = "rx";
  221. static const char *gfar_err_intr = "error";
  222. static int __init gfar_of_init(void)
  223. {
  224. struct device_node *np;
  225. unsigned int i;
  226. struct platform_device *gfar_dev;
  227. struct resource res;
  228. int ret;
  229. for (np = NULL, i = 0;
  230. (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
  231. i++) {
  232. struct resource r[4];
  233. struct device_node *phy, *mdio;
  234. struct gianfar_platform_data gfar_data;
  235. const unsigned int *id;
  236. const char *model;
  237. const char *ctype;
  238. const void *mac_addr;
  239. const phandle *ph;
  240. int n_res = 2;
  241. memset(r, 0, sizeof(r));
  242. memset(&gfar_data, 0, sizeof(gfar_data));
  243. ret = of_address_to_resource(np, 0, &r[0]);
  244. if (ret)
  245. goto err;
  246. of_irq_to_resource(np, 0, &r[1]);
  247. model = of_get_property(np, "model", NULL);
  248. /* If we aren't the FEC we have multiple interrupts */
  249. if (model && strcasecmp(model, "FEC")) {
  250. r[1].name = gfar_tx_intr;
  251. r[2].name = gfar_rx_intr;
  252. of_irq_to_resource(np, 1, &r[2]);
  253. r[3].name = gfar_err_intr;
  254. of_irq_to_resource(np, 2, &r[3]);
  255. n_res += 2;
  256. }
  257. gfar_dev =
  258. platform_device_register_simple("fsl-gianfar", i, &r[0],
  259. n_res);
  260. if (IS_ERR(gfar_dev)) {
  261. ret = PTR_ERR(gfar_dev);
  262. goto err;
  263. }
  264. mac_addr = of_get_mac_address(np);
  265. if (mac_addr)
  266. memcpy(gfar_data.mac_addr, mac_addr, 6);
  267. if (model && !strcasecmp(model, "TSEC"))
  268. gfar_data.device_flags =
  269. FSL_GIANFAR_DEV_HAS_GIGABIT |
  270. FSL_GIANFAR_DEV_HAS_COALESCE |
  271. FSL_GIANFAR_DEV_HAS_RMON |
  272. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  273. if (model && !strcasecmp(model, "eTSEC"))
  274. gfar_data.device_flags =
  275. FSL_GIANFAR_DEV_HAS_GIGABIT |
  276. FSL_GIANFAR_DEV_HAS_COALESCE |
  277. FSL_GIANFAR_DEV_HAS_RMON |
  278. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  279. FSL_GIANFAR_DEV_HAS_CSUM |
  280. FSL_GIANFAR_DEV_HAS_VLAN |
  281. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  282. ctype = of_get_property(np, "phy-connection-type", NULL);
  283. /* We only care about rgmii-id. The rest are autodetected */
  284. if (ctype && !strcmp(ctype, "rgmii-id"))
  285. gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
  286. else
  287. gfar_data.interface = PHY_INTERFACE_MODE_MII;
  288. ph = of_get_property(np, "phy-handle", NULL);
  289. if (ph == NULL) {
  290. u32 *fixed_link;
  291. fixed_link = (u32 *)of_get_property(np, "fixed-link",
  292. NULL);
  293. if (!fixed_link) {
  294. ret = -ENODEV;
  295. goto unreg;
  296. }
  297. snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
  298. gfar_data.phy_id = fixed_link[0];
  299. } else {
  300. phy = of_find_node_by_phandle(*ph);
  301. if (phy == NULL) {
  302. ret = -ENODEV;
  303. goto unreg;
  304. }
  305. mdio = of_get_parent(phy);
  306. id = of_get_property(phy, "reg", NULL);
  307. ret = of_address_to_resource(mdio, 0, &res);
  308. if (ret) {
  309. of_node_put(phy);
  310. of_node_put(mdio);
  311. goto unreg;
  312. }
  313. gfar_data.phy_id = *id;
  314. snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
  315. (unsigned long long)res.start);
  316. of_node_put(phy);
  317. of_node_put(mdio);
  318. }
  319. ret =
  320. platform_device_add_data(gfar_dev, &gfar_data,
  321. sizeof(struct
  322. gianfar_platform_data));
  323. if (ret)
  324. goto unreg;
  325. }
  326. return 0;
  327. unreg:
  328. platform_device_unregister(gfar_dev);
  329. err:
  330. return ret;
  331. }
  332. arch_initcall(gfar_of_init);
  333. #ifdef CONFIG_I2C_BOARDINFO
  334. #include <linux/i2c.h>
  335. struct i2c_driver_device {
  336. char *of_device;
  337. char *i2c_type;
  338. };
  339. static struct i2c_driver_device i2c_devices[] __initdata = {
  340. {"ricoh,rs5c372a", "rs5c372a"},
  341. {"ricoh,rs5c372b", "rs5c372b"},
  342. {"ricoh,rv5c386", "rv5c386"},
  343. {"ricoh,rv5c387a", "rv5c387a"},
  344. {"dallas,ds1307", "ds1307"},
  345. {"dallas,ds1337", "ds1337"},
  346. {"dallas,ds1338", "ds1338"},
  347. {"dallas,ds1339", "ds1339"},
  348. {"dallas,ds1340", "ds1340"},
  349. {"stm,m41t00", "m41t00"},
  350. {"dallas,ds1374", "rtc-ds1374"},
  351. };
  352. static int __init of_find_i2c_driver(struct device_node *node,
  353. struct i2c_board_info *info)
  354. {
  355. int i;
  356. for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
  357. if (!of_device_is_compatible(node, i2c_devices[i].of_device))
  358. continue;
  359. if (strlcpy(info->type, i2c_devices[i].i2c_type,
  360. I2C_NAME_SIZE) >= I2C_NAME_SIZE)
  361. return -ENOMEM;
  362. return 0;
  363. }
  364. pr_warning("fsl_soc.c: unrecognized i2c node %s\n",
  365. (const char *) of_get_property(node, "compatible", NULL));
  366. return -ENODEV;
  367. }
  368. static void __init of_register_i2c_devices(struct device_node *adap_node,
  369. int bus_num)
  370. {
  371. struct device_node *node = NULL;
  372. while ((node = of_get_next_child(adap_node, node))) {
  373. struct i2c_board_info info = {};
  374. const u32 *addr;
  375. int len;
  376. addr = of_get_property(node, "reg", &len);
  377. if (!addr || len < sizeof(int) || *addr > (1 << 10) - 1) {
  378. printk(KERN_WARNING "fsl_soc.c: invalid i2c device entry\n");
  379. continue;
  380. }
  381. info.irq = irq_of_parse_and_map(node, 0);
  382. if (info.irq == NO_IRQ)
  383. info.irq = -1;
  384. if (of_find_i2c_driver(node, &info) < 0)
  385. continue;
  386. info.addr = *addr;
  387. i2c_register_board_info(bus_num, &info, 1);
  388. }
  389. }
  390. static int __init fsl_i2c_of_init(void)
  391. {
  392. struct device_node *np;
  393. unsigned int i = 0;
  394. struct platform_device *i2c_dev;
  395. int ret;
  396. for_each_compatible_node(np, NULL, "fsl-i2c") {
  397. struct resource r[2];
  398. struct fsl_i2c_platform_data i2c_data;
  399. const unsigned char *flags = NULL;
  400. memset(&r, 0, sizeof(r));
  401. memset(&i2c_data, 0, sizeof(i2c_data));
  402. ret = of_address_to_resource(np, 0, &r[0]);
  403. if (ret)
  404. goto err;
  405. of_irq_to_resource(np, 0, &r[1]);
  406. i2c_dev = platform_device_register_simple("fsl-i2c", i, r, 2);
  407. if (IS_ERR(i2c_dev)) {
  408. ret = PTR_ERR(i2c_dev);
  409. goto err;
  410. }
  411. i2c_data.device_flags = 0;
  412. flags = of_get_property(np, "dfsrr", NULL);
  413. if (flags)
  414. i2c_data.device_flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
  415. flags = of_get_property(np, "fsl5200-clocking", NULL);
  416. if (flags)
  417. i2c_data.device_flags |= FSL_I2C_DEV_CLOCK_5200;
  418. ret =
  419. platform_device_add_data(i2c_dev, &i2c_data,
  420. sizeof(struct
  421. fsl_i2c_platform_data));
  422. if (ret)
  423. goto unreg;
  424. of_register_i2c_devices(np, i++);
  425. }
  426. return 0;
  427. unreg:
  428. platform_device_unregister(i2c_dev);
  429. err:
  430. return ret;
  431. }
  432. arch_initcall(fsl_i2c_of_init);
  433. #endif
  434. #ifdef CONFIG_PPC_83xx
  435. static int __init mpc83xx_wdt_init(void)
  436. {
  437. struct resource r;
  438. struct device_node *np;
  439. struct platform_device *dev;
  440. u32 freq = fsl_get_sys_freq();
  441. int ret;
  442. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  443. if (!np) {
  444. ret = -ENODEV;
  445. goto nodev;
  446. }
  447. memset(&r, 0, sizeof(r));
  448. ret = of_address_to_resource(np, 0, &r);
  449. if (ret)
  450. goto err;
  451. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  452. if (IS_ERR(dev)) {
  453. ret = PTR_ERR(dev);
  454. goto err;
  455. }
  456. ret = platform_device_add_data(dev, &freq, sizeof(freq));
  457. if (ret)
  458. goto unreg;
  459. of_node_put(np);
  460. return 0;
  461. unreg:
  462. platform_device_unregister(dev);
  463. err:
  464. of_node_put(np);
  465. nodev:
  466. return ret;
  467. }
  468. arch_initcall(mpc83xx_wdt_init);
  469. #endif
  470. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  471. {
  472. if (!phy_type)
  473. return FSL_USB2_PHY_NONE;
  474. if (!strcasecmp(phy_type, "ulpi"))
  475. return FSL_USB2_PHY_ULPI;
  476. if (!strcasecmp(phy_type, "utmi"))
  477. return FSL_USB2_PHY_UTMI;
  478. if (!strcasecmp(phy_type, "utmi_wide"))
  479. return FSL_USB2_PHY_UTMI_WIDE;
  480. if (!strcasecmp(phy_type, "serial"))
  481. return FSL_USB2_PHY_SERIAL;
  482. return FSL_USB2_PHY_NONE;
  483. }
  484. static int __init fsl_usb_of_init(void)
  485. {
  486. struct device_node *np;
  487. unsigned int i = 0;
  488. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
  489. *usb_dev_dr_client = NULL;
  490. int ret;
  491. for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
  492. struct resource r[2];
  493. struct fsl_usb2_platform_data usb_data;
  494. const unsigned char *prop = NULL;
  495. memset(&r, 0, sizeof(r));
  496. memset(&usb_data, 0, sizeof(usb_data));
  497. ret = of_address_to_resource(np, 0, &r[0]);
  498. if (ret)
  499. goto err;
  500. of_irq_to_resource(np, 0, &r[1]);
  501. usb_dev_mph =
  502. platform_device_register_simple("fsl-ehci", i, r, 2);
  503. if (IS_ERR(usb_dev_mph)) {
  504. ret = PTR_ERR(usb_dev_mph);
  505. goto err;
  506. }
  507. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  508. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  509. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  510. prop = of_get_property(np, "port0", NULL);
  511. if (prop)
  512. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  513. prop = of_get_property(np, "port1", NULL);
  514. if (prop)
  515. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  516. prop = of_get_property(np, "phy_type", NULL);
  517. usb_data.phy_mode = determine_usb_phy(prop);
  518. ret =
  519. platform_device_add_data(usb_dev_mph, &usb_data,
  520. sizeof(struct
  521. fsl_usb2_platform_data));
  522. if (ret)
  523. goto unreg_mph;
  524. i++;
  525. }
  526. for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
  527. struct resource r[2];
  528. struct fsl_usb2_platform_data usb_data;
  529. const unsigned char *prop = NULL;
  530. memset(&r, 0, sizeof(r));
  531. memset(&usb_data, 0, sizeof(usb_data));
  532. ret = of_address_to_resource(np, 0, &r[0]);
  533. if (ret)
  534. goto unreg_mph;
  535. of_irq_to_resource(np, 0, &r[1]);
  536. prop = of_get_property(np, "dr_mode", NULL);
  537. if (!prop || !strcmp(prop, "host")) {
  538. usb_data.operating_mode = FSL_USB2_DR_HOST;
  539. usb_dev_dr_host = platform_device_register_simple(
  540. "fsl-ehci", i, r, 2);
  541. if (IS_ERR(usb_dev_dr_host)) {
  542. ret = PTR_ERR(usb_dev_dr_host);
  543. goto err;
  544. }
  545. } else if (prop && !strcmp(prop, "peripheral")) {
  546. usb_data.operating_mode = FSL_USB2_DR_DEVICE;
  547. usb_dev_dr_client = platform_device_register_simple(
  548. "fsl-usb2-udc", i, r, 2);
  549. if (IS_ERR(usb_dev_dr_client)) {
  550. ret = PTR_ERR(usb_dev_dr_client);
  551. goto err;
  552. }
  553. } else if (prop && !strcmp(prop, "otg")) {
  554. usb_data.operating_mode = FSL_USB2_DR_OTG;
  555. usb_dev_dr_host = platform_device_register_simple(
  556. "fsl-ehci", i, r, 2);
  557. if (IS_ERR(usb_dev_dr_host)) {
  558. ret = PTR_ERR(usb_dev_dr_host);
  559. goto err;
  560. }
  561. usb_dev_dr_client = platform_device_register_simple(
  562. "fsl-usb2-udc", i, r, 2);
  563. if (IS_ERR(usb_dev_dr_client)) {
  564. ret = PTR_ERR(usb_dev_dr_client);
  565. goto err;
  566. }
  567. } else {
  568. ret = -EINVAL;
  569. goto err;
  570. }
  571. prop = of_get_property(np, "phy_type", NULL);
  572. usb_data.phy_mode = determine_usb_phy(prop);
  573. if (usb_dev_dr_host) {
  574. usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
  575. usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
  576. dev.coherent_dma_mask;
  577. if ((ret = platform_device_add_data(usb_dev_dr_host,
  578. &usb_data, sizeof(struct
  579. fsl_usb2_platform_data))))
  580. goto unreg_dr;
  581. }
  582. if (usb_dev_dr_client) {
  583. usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
  584. usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
  585. dev.coherent_dma_mask;
  586. if ((ret = platform_device_add_data(usb_dev_dr_client,
  587. &usb_data, sizeof(struct
  588. fsl_usb2_platform_data))))
  589. goto unreg_dr;
  590. }
  591. i++;
  592. }
  593. return 0;
  594. unreg_dr:
  595. if (usb_dev_dr_host)
  596. platform_device_unregister(usb_dev_dr_host);
  597. if (usb_dev_dr_client)
  598. platform_device_unregister(usb_dev_dr_client);
  599. unreg_mph:
  600. if (usb_dev_mph)
  601. platform_device_unregister(usb_dev_mph);
  602. err:
  603. return ret;
  604. }
  605. arch_initcall(fsl_usb_of_init);
  606. static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
  607. struct spi_board_info *board_infos,
  608. unsigned int num_board_infos,
  609. void (*activate_cs)(u8 cs, u8 polarity),
  610. void (*deactivate_cs)(u8 cs, u8 polarity))
  611. {
  612. struct device_node *np;
  613. unsigned int i = 0;
  614. for_each_compatible_node(np, type, compatible) {
  615. int ret;
  616. unsigned int j;
  617. const void *prop;
  618. struct resource res[2];
  619. struct platform_device *pdev;
  620. struct fsl_spi_platform_data pdata = {
  621. .activate_cs = activate_cs,
  622. .deactivate_cs = deactivate_cs,
  623. };
  624. memset(res, 0, sizeof(res));
  625. pdata.sysclk = sysclk;
  626. prop = of_get_property(np, "reg", NULL);
  627. if (!prop)
  628. goto err;
  629. pdata.bus_num = *(u32 *)prop;
  630. prop = of_get_property(np, "cell-index", NULL);
  631. if (prop)
  632. i = *(u32 *)prop;
  633. prop = of_get_property(np, "mode", NULL);
  634. if (prop && !strcmp(prop, "cpu-qe"))
  635. pdata.qe_mode = 1;
  636. for (j = 0; j < num_board_infos; j++) {
  637. if (board_infos[j].bus_num == pdata.bus_num)
  638. pdata.max_chipselect++;
  639. }
  640. if (!pdata.max_chipselect)
  641. continue;
  642. ret = of_address_to_resource(np, 0, &res[0]);
  643. if (ret)
  644. goto err;
  645. ret = of_irq_to_resource(np, 0, &res[1]);
  646. if (ret == NO_IRQ)
  647. goto err;
  648. pdev = platform_device_alloc("mpc83xx_spi", i);
  649. if (!pdev)
  650. goto err;
  651. ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  652. if (ret)
  653. goto unreg;
  654. ret = platform_device_add_resources(pdev, res,
  655. ARRAY_SIZE(res));
  656. if (ret)
  657. goto unreg;
  658. ret = platform_device_add(pdev);
  659. if (ret)
  660. goto unreg;
  661. goto next;
  662. unreg:
  663. platform_device_del(pdev);
  664. err:
  665. pr_err("%s: registration failed\n", np->full_name);
  666. next:
  667. i++;
  668. }
  669. return i;
  670. }
  671. int __init fsl_spi_init(struct spi_board_info *board_infos,
  672. unsigned int num_board_infos,
  673. void (*activate_cs)(u8 cs, u8 polarity),
  674. void (*deactivate_cs)(u8 cs, u8 polarity))
  675. {
  676. u32 sysclk = -1;
  677. int ret;
  678. #ifdef CONFIG_QUICC_ENGINE
  679. /* SPI controller is either clocked from QE or SoC clock */
  680. sysclk = get_brgfreq();
  681. #endif
  682. if (sysclk == -1) {
  683. sysclk = fsl_get_sys_freq();
  684. if (sysclk == -1)
  685. return -ENODEV;
  686. }
  687. ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
  688. num_board_infos, activate_cs, deactivate_cs);
  689. if (!ret)
  690. of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
  691. num_board_infos, activate_cs, deactivate_cs);
  692. return spi_register_board_info(board_infos, num_board_infos);
  693. }
  694. #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
  695. static __be32 __iomem *rstcr;
  696. static int __init setup_rstcr(void)
  697. {
  698. struct device_node *np;
  699. np = of_find_node_by_name(NULL, "global-utilities");
  700. if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
  701. const u32 *prop = of_get_property(np, "reg", NULL);
  702. if (prop) {
  703. /* map reset control register
  704. * 0xE00B0 is offset of reset control register
  705. */
  706. rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
  707. if (!rstcr)
  708. printk (KERN_EMERG "Error: reset control "
  709. "register not mapped!\n");
  710. }
  711. } else
  712. printk (KERN_INFO "rstcr compatible register does not exist!\n");
  713. if (np)
  714. of_node_put(np);
  715. return 0;
  716. }
  717. arch_initcall(setup_rstcr);
  718. void fsl_rstcr_restart(char *cmd)
  719. {
  720. local_irq_disable();
  721. if (rstcr)
  722. /* set reset control register */
  723. out_be32(rstcr, 0x2); /* HRESET_REQ */
  724. while (1) ;
  725. }
  726. #endif
  727. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  728. struct platform_diu_data_ops diu_ops = {
  729. .diu_size = 1280 * 1024 * 4, /* default one 1280x1024 buffer */
  730. };
  731. EXPORT_SYMBOL(diu_ops);
  732. int __init preallocate_diu_videomemory(void)
  733. {
  734. pr_debug("diu_size=%lu\n", diu_ops.diu_size);
  735. diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0);
  736. if (!diu_ops.diu_mem) {
  737. printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n",
  738. diu_ops.diu_size);
  739. return -ENOMEM;
  740. }
  741. pr_debug("diu_mem=%p\n", diu_ops.diu_mem);
  742. rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block),
  743. diu_ops.diu_rh_block);
  744. return rh_attach_region(&diu_ops.diu_rh_info,
  745. (unsigned long) diu_ops.diu_mem,
  746. diu_ops.diu_size);
  747. }
  748. static int __init early_parse_diufb(char *p)
  749. {
  750. if (!p)
  751. return 1;
  752. diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8);
  753. pr_debug("diu_size=%lu\n", diu_ops.diu_size);
  754. return 0;
  755. }
  756. early_param("diufb", early_parse_diufb);
  757. #endif