mv64x60_dev.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*
  2. * Platform device setup for Marvell mv64360/mv64460 host bridges (Discovery)
  3. *
  4. * Author: Dale Farnsworth <dale@farnsworth.org>
  5. *
  6. * 2007 (c) MontaVista, Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/console.h>
  15. #include <linux/mv643xx.h>
  16. #include <linux/platform_device.h>
  17. #include <asm/prom.h>
  18. /*
  19. * These functions provide the necessary setup for the mv64x60 drivers.
  20. * These drivers are unusual in that they work on both the MIPS and PowerPC
  21. * architectures. Because of that, the drivers do not support the normal
  22. * PowerPC of_platform_bus_type. They support platform_bus_type instead.
  23. */
  24. /*
  25. * Create MPSC platform devices
  26. */
  27. static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
  28. {
  29. struct platform_device *pdev;
  30. struct resource r[2];
  31. struct mpsc_shared_pdata pdata;
  32. const phandle *ph;
  33. struct device_node *mpscrouting, *mpscintr;
  34. int err;
  35. ph = of_get_property(np, "mpscrouting", NULL);
  36. mpscrouting = of_find_node_by_phandle(*ph);
  37. if (!mpscrouting)
  38. return -ENODEV;
  39. err = of_address_to_resource(mpscrouting, 0, &r[0]);
  40. of_node_put(mpscrouting);
  41. if (err)
  42. return err;
  43. ph = of_get_property(np, "mpscintr", NULL);
  44. mpscintr = of_find_node_by_phandle(*ph);
  45. if (!mpscintr)
  46. return -ENODEV;
  47. err = of_address_to_resource(mpscintr, 0, &r[1]);
  48. of_node_put(mpscintr);
  49. if (err)
  50. return err;
  51. memset(&pdata, 0, sizeof(pdata));
  52. pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
  53. if (!pdev)
  54. return -ENOMEM;
  55. err = platform_device_add_resources(pdev, r, 2);
  56. if (err)
  57. goto error;
  58. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  59. if (err)
  60. goto error;
  61. err = platform_device_add(pdev);
  62. if (err)
  63. goto error;
  64. return 0;
  65. error:
  66. platform_device_put(pdev);
  67. return err;
  68. }
  69. static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
  70. {
  71. struct resource r[5];
  72. struct mpsc_pdata pdata;
  73. struct platform_device *pdev;
  74. const unsigned int *prop;
  75. const phandle *ph;
  76. struct device_node *sdma, *brg;
  77. int err;
  78. int port_number;
  79. /* only register the shared platform device the first time through */
  80. if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
  81. return err;
  82. memset(r, 0, sizeof(r));
  83. err = of_address_to_resource(np, 0, &r[0]);
  84. if (err)
  85. return err;
  86. of_irq_to_resource(np, 0, &r[4]);
  87. ph = of_get_property(np, "sdma", NULL);
  88. sdma = of_find_node_by_phandle(*ph);
  89. if (!sdma)
  90. return -ENODEV;
  91. of_irq_to_resource(sdma, 0, &r[3]);
  92. err = of_address_to_resource(sdma, 0, &r[1]);
  93. of_node_put(sdma);
  94. if (err)
  95. return err;
  96. ph = of_get_property(np, "brg", NULL);
  97. brg = of_find_node_by_phandle(*ph);
  98. if (!brg)
  99. return -ENODEV;
  100. err = of_address_to_resource(brg, 0, &r[2]);
  101. of_node_put(brg);
  102. if (err)
  103. return err;
  104. prop = of_get_property(np, "block-index", NULL);
  105. if (!prop)
  106. return -ENODEV;
  107. port_number = *(int *)prop;
  108. memset(&pdata, 0, sizeof(pdata));
  109. pdata.cache_mgmt = 1; /* All current revs need this set */
  110. prop = of_get_property(np, "max_idle", NULL);
  111. if (prop)
  112. pdata.max_idle = *prop;
  113. prop = of_get_property(brg, "current-speed", NULL);
  114. if (prop)
  115. pdata.default_baud = *prop;
  116. /* Default is 8 bits, no parity, no flow control */
  117. pdata.default_bits = 8;
  118. pdata.default_parity = 'n';
  119. pdata.default_flow = 'n';
  120. prop = of_get_property(np, "chr_1", NULL);
  121. if (prop)
  122. pdata.chr_1_val = *prop;
  123. prop = of_get_property(np, "chr_2", NULL);
  124. if (prop)
  125. pdata.chr_2_val = *prop;
  126. prop = of_get_property(np, "chr_10", NULL);
  127. if (prop)
  128. pdata.chr_10_val = *prop;
  129. prop = of_get_property(np, "mpcr", NULL);
  130. if (prop)
  131. pdata.mpcr_val = *prop;
  132. prop = of_get_property(brg, "bcr", NULL);
  133. if (prop)
  134. pdata.bcr_val = *prop;
  135. pdata.brg_can_tune = 1; /* All current revs need this set */
  136. prop = of_get_property(brg, "clock-src", NULL);
  137. if (prop)
  138. pdata.brg_clk_src = *prop;
  139. prop = of_get_property(brg, "clock-frequency", NULL);
  140. if (prop)
  141. pdata.brg_clk_freq = *prop;
  142. pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
  143. if (!pdev)
  144. return -ENOMEM;
  145. err = platform_device_add_resources(pdev, r, 5);
  146. if (err)
  147. goto error;
  148. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  149. if (err)
  150. goto error;
  151. err = platform_device_add(pdev);
  152. if (err)
  153. goto error;
  154. return 0;
  155. error:
  156. platform_device_put(pdev);
  157. return err;
  158. }
  159. /*
  160. * Create mv64x60_eth platform devices
  161. */
  162. static int __init eth_register_shared_pdev(struct device_node *np)
  163. {
  164. struct platform_device *pdev;
  165. struct resource r[1];
  166. int err;
  167. np = of_get_parent(np);
  168. if (!np)
  169. return -ENODEV;
  170. err = of_address_to_resource(np, 0, &r[0]);
  171. of_node_put(np);
  172. if (err)
  173. return err;
  174. pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0,
  175. r, 1);
  176. if (IS_ERR(pdev))
  177. return PTR_ERR(pdev);
  178. return 0;
  179. }
  180. static int __init mv64x60_eth_device_setup(struct device_node *np, int id)
  181. {
  182. struct resource r[1];
  183. struct mv643xx_eth_platform_data pdata;
  184. struct platform_device *pdev;
  185. struct device_node *phy;
  186. const u8 *mac_addr;
  187. const int *prop;
  188. const phandle *ph;
  189. int err;
  190. /* only register the shared platform device the first time through */
  191. if (id == 0 && (err = eth_register_shared_pdev(np)))
  192. return err;;
  193. memset(r, 0, sizeof(r));
  194. of_irq_to_resource(np, 0, &r[0]);
  195. memset(&pdata, 0, sizeof(pdata));
  196. prop = of_get_property(np, "block-index", NULL);
  197. if (!prop)
  198. return -ENODEV;
  199. pdata.port_number = *prop;
  200. mac_addr = of_get_mac_address(np);
  201. if (mac_addr)
  202. memcpy(pdata.mac_addr, mac_addr, 6);
  203. prop = of_get_property(np, "speed", NULL);
  204. if (prop)
  205. pdata.speed = *prop;
  206. prop = of_get_property(np, "tx_queue_size", NULL);
  207. if (prop)
  208. pdata.tx_queue_size = *prop;
  209. prop = of_get_property(np, "rx_queue_size", NULL);
  210. if (prop)
  211. pdata.rx_queue_size = *prop;
  212. prop = of_get_property(np, "tx_sram_addr", NULL);
  213. if (prop)
  214. pdata.tx_sram_addr = *prop;
  215. prop = of_get_property(np, "tx_sram_size", NULL);
  216. if (prop)
  217. pdata.tx_sram_size = *prop;
  218. prop = of_get_property(np, "rx_sram_addr", NULL);
  219. if (prop)
  220. pdata.rx_sram_addr = *prop;
  221. prop = of_get_property(np, "rx_sram_size", NULL);
  222. if (prop)
  223. pdata.rx_sram_size = *prop;
  224. ph = of_get_property(np, "phy", NULL);
  225. if (!ph)
  226. return -ENODEV;
  227. phy = of_find_node_by_phandle(*ph);
  228. if (phy == NULL)
  229. return -ENODEV;
  230. prop = of_get_property(phy, "reg", NULL);
  231. if (prop) {
  232. pdata.force_phy_addr = 1;
  233. pdata.phy_addr = *prop;
  234. }
  235. of_node_put(phy);
  236. pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number);
  237. if (!pdev)
  238. return -ENOMEM;
  239. err = platform_device_add_resources(pdev, r, 1);
  240. if (err)
  241. goto error;
  242. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  243. if (err)
  244. goto error;
  245. err = platform_device_add(pdev);
  246. if (err)
  247. goto error;
  248. return 0;
  249. error:
  250. platform_device_put(pdev);
  251. return err;
  252. }
  253. /*
  254. * Create mv64x60_i2c platform devices
  255. */
  256. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  257. {
  258. struct resource r[2];
  259. struct platform_device *pdev;
  260. struct mv64xxx_i2c_pdata pdata;
  261. const unsigned int *prop;
  262. int err;
  263. memset(r, 0, sizeof(r));
  264. err = of_address_to_resource(np, 0, &r[0]);
  265. if (err)
  266. return err;
  267. of_irq_to_resource(np, 0, &r[1]);
  268. memset(&pdata, 0, sizeof(pdata));
  269. prop = of_get_property(np, "freq_m", NULL);
  270. if (!prop)
  271. return -ENODEV;
  272. pdata.freq_m = *prop;
  273. prop = of_get_property(np, "freq_n", NULL);
  274. if (!prop)
  275. return -ENODEV;
  276. pdata.freq_n = *prop;
  277. prop = of_get_property(np, "timeout", NULL);
  278. if (prop)
  279. pdata.timeout = *prop;
  280. else
  281. pdata.timeout = 1000; /* 1 second */
  282. prop = of_get_property(np, "retries", NULL);
  283. if (prop)
  284. pdata.retries = *prop;
  285. else
  286. pdata.retries = 1;
  287. pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
  288. if (!pdev)
  289. return -ENOMEM;
  290. err = platform_device_add_resources(pdev, r, 2);
  291. if (err)
  292. goto error;
  293. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  294. if (err)
  295. goto error;
  296. err = platform_device_add(pdev);
  297. if (err)
  298. goto error;
  299. return 0;
  300. error:
  301. platform_device_put(pdev);
  302. return err;
  303. }
  304. /*
  305. * Create mv64x60_wdt platform devices
  306. */
  307. static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
  308. {
  309. struct resource r;
  310. struct platform_device *pdev;
  311. struct mv64x60_wdt_pdata pdata;
  312. const unsigned int *prop;
  313. int err;
  314. err = of_address_to_resource(np, 0, &r);
  315. if (err)
  316. return err;
  317. memset(&pdata, 0, sizeof(pdata));
  318. prop = of_get_property(np, "timeout", NULL);
  319. if (!prop)
  320. return -ENODEV;
  321. pdata.timeout = *prop;
  322. np = of_get_parent(np);
  323. if (!np)
  324. return -ENODEV;
  325. prop = of_get_property(np, "clock-frequency", NULL);
  326. of_node_put(np);
  327. if (!prop)
  328. return -ENODEV;
  329. pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
  330. pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
  331. if (!pdev)
  332. return -ENOMEM;
  333. err = platform_device_add_resources(pdev, &r, 1);
  334. if (err)
  335. goto error;
  336. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  337. if (err)
  338. goto error;
  339. err = platform_device_add(pdev);
  340. if (err)
  341. goto error;
  342. return 0;
  343. error:
  344. platform_device_put(pdev);
  345. return err;
  346. }
  347. static int __init mv64x60_device_setup(void)
  348. {
  349. struct device_node *np = NULL;
  350. int id;
  351. int err;
  352. for (id = 0;
  353. (np = of_find_compatible_node(np, "serial", "marvell,mpsc")); id++)
  354. if ((err = mv64x60_mpsc_device_setup(np, id)))
  355. goto error;
  356. for (id = 0;
  357. (np = of_find_compatible_node(np, "network",
  358. "marvell,mv64x60-eth"));
  359. id++)
  360. if ((err = mv64x60_eth_device_setup(np, id)))
  361. goto error;
  362. for (id = 0;
  363. (np = of_find_compatible_node(np, "i2c", "marvell,mv64x60-i2c"));
  364. id++)
  365. if ((err = mv64x60_i2c_device_setup(np, id)))
  366. goto error;
  367. /* support up to one watchdog timer */
  368. np = of_find_compatible_node(np, NULL, "marvell,mv64x60-wdt");
  369. if (np) {
  370. if ((err = mv64x60_wdt_device_setup(np, id)))
  371. goto error;
  372. of_node_put(np);
  373. }
  374. return 0;
  375. error:
  376. of_node_put(np);
  377. return err;
  378. }
  379. arch_initcall(mv64x60_device_setup);
  380. static int __init mv64x60_add_mpsc_console(void)
  381. {
  382. struct device_node *np = NULL;
  383. const char *prop;
  384. prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
  385. if (prop == NULL)
  386. goto not_mpsc;
  387. np = of_find_node_by_path(prop);
  388. if (!np)
  389. goto not_mpsc;
  390. if (!of_device_is_compatible(np, "marvell,mpsc"))
  391. goto not_mpsc;
  392. prop = of_get_property(np, "block-index", NULL);
  393. if (!prop)
  394. goto not_mpsc;
  395. add_preferred_console("ttyMM", *(int *)prop, NULL);
  396. not_mpsc:
  397. return 0;
  398. }
  399. console_initcall(mv64x60_add_mpsc_console);