fsl_soc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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 gfar_mdio_of_init_one(struct device_node *np)
  169. {
  170. int k;
  171. struct device_node *child = NULL;
  172. struct gianfar_mdio_data mdio_data;
  173. struct platform_device *mdio_dev;
  174. struct resource res;
  175. int ret;
  176. memset(&res, 0, sizeof(res));
  177. memset(&mdio_data, 0, sizeof(mdio_data));
  178. ret = of_address_to_resource(np, 0, &res);
  179. if (ret)
  180. return ret;
  181. mdio_dev = platform_device_register_simple("fsl-gianfar_mdio",
  182. res.start&0xfffff, &res, 1);
  183. if (IS_ERR(mdio_dev))
  184. return PTR_ERR(mdio_dev);
  185. for (k = 0; k < 32; k++)
  186. mdio_data.irq[k] = PHY_POLL;
  187. while ((child = of_get_next_child(np, child)) != NULL) {
  188. int irq = irq_of_parse_and_map(child, 0);
  189. if (irq != NO_IRQ) {
  190. const u32 *id = of_get_property(child, "reg", NULL);
  191. mdio_data.irq[*id] = irq;
  192. }
  193. }
  194. ret = platform_device_add_data(mdio_dev, &mdio_data,
  195. sizeof(struct gianfar_mdio_data));
  196. if (ret)
  197. platform_device_unregister(mdio_dev);
  198. return ret;
  199. }
  200. static int __init gfar_mdio_of_init(void)
  201. {
  202. struct device_node *np = NULL;
  203. for_each_compatible_node(np, NULL, "fsl,gianfar-mdio")
  204. gfar_mdio_of_init_one(np);
  205. /* try the deprecated version */
  206. for_each_compatible_node(np, "mdio", "gianfar");
  207. gfar_mdio_of_init_one(np);
  208. return 0;
  209. }
  210. arch_initcall(gfar_mdio_of_init);
  211. static const char *gfar_tx_intr = "tx";
  212. static const char *gfar_rx_intr = "rx";
  213. static const char *gfar_err_intr = "error";
  214. static int __init gfar_of_init(void)
  215. {
  216. struct device_node *np;
  217. unsigned int i;
  218. struct platform_device *gfar_dev;
  219. struct resource res;
  220. int ret;
  221. for (np = NULL, i = 0;
  222. (np = of_find_compatible_node(np, "network", "gianfar")) != NULL;
  223. i++) {
  224. struct resource r[4];
  225. struct device_node *phy, *mdio;
  226. struct gianfar_platform_data gfar_data;
  227. const unsigned int *id;
  228. const char *model;
  229. const char *ctype;
  230. const void *mac_addr;
  231. const phandle *ph;
  232. int n_res = 2;
  233. if (!of_device_is_available(np))
  234. continue;
  235. memset(r, 0, sizeof(r));
  236. memset(&gfar_data, 0, sizeof(gfar_data));
  237. ret = of_address_to_resource(np, 0, &r[0]);
  238. if (ret)
  239. goto err;
  240. of_irq_to_resource(np, 0, &r[1]);
  241. model = of_get_property(np, "model", NULL);
  242. /* If we aren't the FEC we have multiple interrupts */
  243. if (model && strcasecmp(model, "FEC")) {
  244. r[1].name = gfar_tx_intr;
  245. r[2].name = gfar_rx_intr;
  246. of_irq_to_resource(np, 1, &r[2]);
  247. r[3].name = gfar_err_intr;
  248. of_irq_to_resource(np, 2, &r[3]);
  249. n_res += 2;
  250. }
  251. gfar_dev =
  252. platform_device_register_simple("fsl-gianfar", i, &r[0],
  253. n_res);
  254. if (IS_ERR(gfar_dev)) {
  255. ret = PTR_ERR(gfar_dev);
  256. goto err;
  257. }
  258. mac_addr = of_get_mac_address(np);
  259. if (mac_addr)
  260. memcpy(gfar_data.mac_addr, mac_addr, 6);
  261. if (model && !strcasecmp(model, "TSEC"))
  262. gfar_data.device_flags =
  263. FSL_GIANFAR_DEV_HAS_GIGABIT |
  264. FSL_GIANFAR_DEV_HAS_COALESCE |
  265. FSL_GIANFAR_DEV_HAS_RMON |
  266. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  267. if (model && !strcasecmp(model, "eTSEC"))
  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. FSL_GIANFAR_DEV_HAS_CSUM |
  274. FSL_GIANFAR_DEV_HAS_VLAN |
  275. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  276. ctype = of_get_property(np, "phy-connection-type", NULL);
  277. /* We only care about rgmii-id. The rest are autodetected */
  278. if (ctype && !strcmp(ctype, "rgmii-id"))
  279. gfar_data.interface = PHY_INTERFACE_MODE_RGMII_ID;
  280. else
  281. gfar_data.interface = PHY_INTERFACE_MODE_MII;
  282. if (of_get_property(np, "fsl,magic-packet", NULL))
  283. gfar_data.device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
  284. ph = of_get_property(np, "phy-handle", NULL);
  285. if (ph == NULL) {
  286. u32 *fixed_link;
  287. fixed_link = (u32 *)of_get_property(np, "fixed-link",
  288. NULL);
  289. if (!fixed_link) {
  290. ret = -ENODEV;
  291. goto unreg;
  292. }
  293. snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "0");
  294. gfar_data.phy_id = fixed_link[0];
  295. } else {
  296. phy = of_find_node_by_phandle(*ph);
  297. if (phy == NULL) {
  298. ret = -ENODEV;
  299. goto unreg;
  300. }
  301. mdio = of_get_parent(phy);
  302. id = of_get_property(phy, "reg", NULL);
  303. ret = of_address_to_resource(mdio, 0, &res);
  304. if (ret) {
  305. of_node_put(phy);
  306. of_node_put(mdio);
  307. goto unreg;
  308. }
  309. gfar_data.phy_id = *id;
  310. snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
  311. (unsigned long long)res.start&0xfffff);
  312. of_node_put(phy);
  313. of_node_put(mdio);
  314. }
  315. ret =
  316. platform_device_add_data(gfar_dev, &gfar_data,
  317. sizeof(struct
  318. gianfar_platform_data));
  319. if (ret)
  320. goto unreg;
  321. }
  322. return 0;
  323. unreg:
  324. platform_device_unregister(gfar_dev);
  325. err:
  326. return ret;
  327. }
  328. arch_initcall(gfar_of_init);
  329. #ifdef CONFIG_PPC_83xx
  330. static int __init mpc83xx_wdt_init(void)
  331. {
  332. struct resource r;
  333. struct device_node *np;
  334. struct platform_device *dev;
  335. u32 freq = fsl_get_sys_freq();
  336. int ret;
  337. np = of_find_compatible_node(NULL, "watchdog", "mpc83xx_wdt");
  338. if (!np) {
  339. ret = -ENODEV;
  340. goto nodev;
  341. }
  342. memset(&r, 0, sizeof(r));
  343. ret = of_address_to_resource(np, 0, &r);
  344. if (ret)
  345. goto err;
  346. dev = platform_device_register_simple("mpc83xx_wdt", 0, &r, 1);
  347. if (IS_ERR(dev)) {
  348. ret = PTR_ERR(dev);
  349. goto err;
  350. }
  351. ret = platform_device_add_data(dev, &freq, sizeof(freq));
  352. if (ret)
  353. goto unreg;
  354. of_node_put(np);
  355. return 0;
  356. unreg:
  357. platform_device_unregister(dev);
  358. err:
  359. of_node_put(np);
  360. nodev:
  361. return ret;
  362. }
  363. arch_initcall(mpc83xx_wdt_init);
  364. #endif
  365. static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
  366. {
  367. if (!phy_type)
  368. return FSL_USB2_PHY_NONE;
  369. if (!strcasecmp(phy_type, "ulpi"))
  370. return FSL_USB2_PHY_ULPI;
  371. if (!strcasecmp(phy_type, "utmi"))
  372. return FSL_USB2_PHY_UTMI;
  373. if (!strcasecmp(phy_type, "utmi_wide"))
  374. return FSL_USB2_PHY_UTMI_WIDE;
  375. if (!strcasecmp(phy_type, "serial"))
  376. return FSL_USB2_PHY_SERIAL;
  377. return FSL_USB2_PHY_NONE;
  378. }
  379. static int __init fsl_usb_of_init(void)
  380. {
  381. struct device_node *np;
  382. unsigned int i = 0;
  383. struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
  384. *usb_dev_dr_client = NULL;
  385. int ret;
  386. for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
  387. struct resource r[2];
  388. struct fsl_usb2_platform_data usb_data;
  389. const unsigned char *prop = NULL;
  390. memset(&r, 0, sizeof(r));
  391. memset(&usb_data, 0, sizeof(usb_data));
  392. ret = of_address_to_resource(np, 0, &r[0]);
  393. if (ret)
  394. goto err;
  395. of_irq_to_resource(np, 0, &r[1]);
  396. usb_dev_mph =
  397. platform_device_register_simple("fsl-ehci", i, r, 2);
  398. if (IS_ERR(usb_dev_mph)) {
  399. ret = PTR_ERR(usb_dev_mph);
  400. goto err;
  401. }
  402. usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
  403. usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
  404. usb_data.operating_mode = FSL_USB2_MPH_HOST;
  405. prop = of_get_property(np, "port0", NULL);
  406. if (prop)
  407. usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
  408. prop = of_get_property(np, "port1", NULL);
  409. if (prop)
  410. usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
  411. prop = of_get_property(np, "phy_type", NULL);
  412. usb_data.phy_mode = determine_usb_phy(prop);
  413. ret =
  414. platform_device_add_data(usb_dev_mph, &usb_data,
  415. sizeof(struct
  416. fsl_usb2_platform_data));
  417. if (ret)
  418. goto unreg_mph;
  419. i++;
  420. }
  421. for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
  422. struct resource r[2];
  423. struct fsl_usb2_platform_data usb_data;
  424. const unsigned char *prop = NULL;
  425. memset(&r, 0, sizeof(r));
  426. memset(&usb_data, 0, sizeof(usb_data));
  427. ret = of_address_to_resource(np, 0, &r[0]);
  428. if (ret)
  429. goto unreg_mph;
  430. of_irq_to_resource(np, 0, &r[1]);
  431. prop = of_get_property(np, "dr_mode", NULL);
  432. if (!prop || !strcmp(prop, "host")) {
  433. usb_data.operating_mode = FSL_USB2_DR_HOST;
  434. usb_dev_dr_host = platform_device_register_simple(
  435. "fsl-ehci", i, r, 2);
  436. if (IS_ERR(usb_dev_dr_host)) {
  437. ret = PTR_ERR(usb_dev_dr_host);
  438. goto err;
  439. }
  440. } else if (prop && !strcmp(prop, "peripheral")) {
  441. usb_data.operating_mode = FSL_USB2_DR_DEVICE;
  442. usb_dev_dr_client = platform_device_register_simple(
  443. "fsl-usb2-udc", i, r, 2);
  444. if (IS_ERR(usb_dev_dr_client)) {
  445. ret = PTR_ERR(usb_dev_dr_client);
  446. goto err;
  447. }
  448. } else if (prop && !strcmp(prop, "otg")) {
  449. usb_data.operating_mode = FSL_USB2_DR_OTG;
  450. usb_dev_dr_host = platform_device_register_simple(
  451. "fsl-ehci", i, r, 2);
  452. if (IS_ERR(usb_dev_dr_host)) {
  453. ret = PTR_ERR(usb_dev_dr_host);
  454. goto err;
  455. }
  456. usb_dev_dr_client = platform_device_register_simple(
  457. "fsl-usb2-udc", i, r, 2);
  458. if (IS_ERR(usb_dev_dr_client)) {
  459. ret = PTR_ERR(usb_dev_dr_client);
  460. goto err;
  461. }
  462. } else {
  463. ret = -EINVAL;
  464. goto err;
  465. }
  466. prop = of_get_property(np, "phy_type", NULL);
  467. usb_data.phy_mode = determine_usb_phy(prop);
  468. if (usb_dev_dr_host) {
  469. usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
  470. usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
  471. dev.coherent_dma_mask;
  472. if ((ret = platform_device_add_data(usb_dev_dr_host,
  473. &usb_data, sizeof(struct
  474. fsl_usb2_platform_data))))
  475. goto unreg_dr;
  476. }
  477. if (usb_dev_dr_client) {
  478. usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
  479. usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
  480. dev.coherent_dma_mask;
  481. if ((ret = platform_device_add_data(usb_dev_dr_client,
  482. &usb_data, sizeof(struct
  483. fsl_usb2_platform_data))))
  484. goto unreg_dr;
  485. }
  486. i++;
  487. }
  488. return 0;
  489. unreg_dr:
  490. if (usb_dev_dr_host)
  491. platform_device_unregister(usb_dev_dr_host);
  492. if (usb_dev_dr_client)
  493. platform_device_unregister(usb_dev_dr_client);
  494. unreg_mph:
  495. if (usb_dev_mph)
  496. platform_device_unregister(usb_dev_mph);
  497. err:
  498. return ret;
  499. }
  500. arch_initcall(fsl_usb_of_init);
  501. static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
  502. struct spi_board_info *board_infos,
  503. unsigned int num_board_infos,
  504. void (*activate_cs)(u8 cs, u8 polarity),
  505. void (*deactivate_cs)(u8 cs, u8 polarity))
  506. {
  507. struct device_node *np;
  508. unsigned int i = 0;
  509. for_each_compatible_node(np, type, compatible) {
  510. int ret;
  511. unsigned int j;
  512. const void *prop;
  513. struct resource res[2];
  514. struct platform_device *pdev;
  515. struct fsl_spi_platform_data pdata = {
  516. .activate_cs = activate_cs,
  517. .deactivate_cs = deactivate_cs,
  518. };
  519. memset(res, 0, sizeof(res));
  520. pdata.sysclk = sysclk;
  521. prop = of_get_property(np, "reg", NULL);
  522. if (!prop)
  523. goto err;
  524. pdata.bus_num = *(u32 *)prop;
  525. prop = of_get_property(np, "cell-index", NULL);
  526. if (prop)
  527. i = *(u32 *)prop;
  528. prop = of_get_property(np, "mode", NULL);
  529. if (prop && !strcmp(prop, "cpu-qe"))
  530. pdata.qe_mode = 1;
  531. for (j = 0; j < num_board_infos; j++) {
  532. if (board_infos[j].bus_num == pdata.bus_num)
  533. pdata.max_chipselect++;
  534. }
  535. if (!pdata.max_chipselect)
  536. continue;
  537. ret = of_address_to_resource(np, 0, &res[0]);
  538. if (ret)
  539. goto err;
  540. ret = of_irq_to_resource(np, 0, &res[1]);
  541. if (ret == NO_IRQ)
  542. goto err;
  543. pdev = platform_device_alloc("mpc83xx_spi", i);
  544. if (!pdev)
  545. goto err;
  546. ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  547. if (ret)
  548. goto unreg;
  549. ret = platform_device_add_resources(pdev, res,
  550. ARRAY_SIZE(res));
  551. if (ret)
  552. goto unreg;
  553. ret = platform_device_add(pdev);
  554. if (ret)
  555. goto unreg;
  556. goto next;
  557. unreg:
  558. platform_device_del(pdev);
  559. err:
  560. pr_err("%s: registration failed\n", np->full_name);
  561. next:
  562. i++;
  563. }
  564. return i;
  565. }
  566. int __init fsl_spi_init(struct spi_board_info *board_infos,
  567. unsigned int num_board_infos,
  568. void (*activate_cs)(u8 cs, u8 polarity),
  569. void (*deactivate_cs)(u8 cs, u8 polarity))
  570. {
  571. u32 sysclk = -1;
  572. int ret;
  573. #ifdef CONFIG_QUICC_ENGINE
  574. /* SPI controller is either clocked from QE or SoC clock */
  575. sysclk = get_brgfreq();
  576. #endif
  577. if (sysclk == -1) {
  578. sysclk = fsl_get_sys_freq();
  579. if (sysclk == -1)
  580. return -ENODEV;
  581. }
  582. ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
  583. num_board_infos, activate_cs, deactivate_cs);
  584. if (!ret)
  585. of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
  586. num_board_infos, activate_cs, deactivate_cs);
  587. return spi_register_board_info(board_infos, num_board_infos);
  588. }
  589. #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
  590. static __be32 __iomem *rstcr;
  591. static int __init setup_rstcr(void)
  592. {
  593. struct device_node *np;
  594. np = of_find_node_by_name(NULL, "global-utilities");
  595. if ((np && of_get_property(np, "fsl,has-rstcr", NULL))) {
  596. const u32 *prop = of_get_property(np, "reg", NULL);
  597. if (prop) {
  598. /* map reset control register
  599. * 0xE00B0 is offset of reset control register
  600. */
  601. rstcr = ioremap(get_immrbase() + *prop + 0xB0, 0xff);
  602. if (!rstcr)
  603. printk (KERN_EMERG "Error: reset control "
  604. "register not mapped!\n");
  605. }
  606. } else
  607. printk (KERN_INFO "rstcr compatible register does not exist!\n");
  608. if (np)
  609. of_node_put(np);
  610. return 0;
  611. }
  612. arch_initcall(setup_rstcr);
  613. void fsl_rstcr_restart(char *cmd)
  614. {
  615. local_irq_disable();
  616. if (rstcr)
  617. /* set reset control register */
  618. out_be32(rstcr, 0x2); /* HRESET_REQ */
  619. while (1) ;
  620. }
  621. #endif
  622. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  623. struct platform_diu_data_ops diu_ops = {
  624. .diu_size = 1280 * 1024 * 4, /* default one 1280x1024 buffer */
  625. };
  626. EXPORT_SYMBOL(diu_ops);
  627. int __init preallocate_diu_videomemory(void)
  628. {
  629. pr_debug("diu_size=%lu\n", diu_ops.diu_size);
  630. diu_ops.diu_mem = __alloc_bootmem(diu_ops.diu_size, 8, 0);
  631. if (!diu_ops.diu_mem) {
  632. printk(KERN_ERR "fsl-diu: cannot allocate %lu bytes\n",
  633. diu_ops.diu_size);
  634. return -ENOMEM;
  635. }
  636. pr_debug("diu_mem=%p\n", diu_ops.diu_mem);
  637. rh_init(&diu_ops.diu_rh_info, 4096, ARRAY_SIZE(diu_ops.diu_rh_block),
  638. diu_ops.diu_rh_block);
  639. return rh_attach_region(&diu_ops.diu_rh_info,
  640. (unsigned long) diu_ops.diu_mem,
  641. diu_ops.diu_size);
  642. }
  643. static int __init early_parse_diufb(char *p)
  644. {
  645. if (!p)
  646. return 1;
  647. diu_ops.diu_size = _ALIGN_UP(memparse(p, &p), 8);
  648. pr_debug("diu_size=%lu\n", diu_ops.diu_size);
  649. return 0;
  650. }
  651. early_param("diufb", early_parse_diufb);
  652. #endif