mv64x60_dev.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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, "cell-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. pdata.max_idle = 40; /* default */
  111. prop = of_get_property(np, "max_idle", NULL);
  112. if (prop)
  113. pdata.max_idle = *prop;
  114. prop = of_get_property(brg, "current-speed", NULL);
  115. if (prop)
  116. pdata.default_baud = *prop;
  117. /* Default is 8 bits, no parity, no flow control */
  118. pdata.default_bits = 8;
  119. pdata.default_parity = 'n';
  120. pdata.default_flow = 'n';
  121. prop = of_get_property(np, "chr_1", NULL);
  122. if (prop)
  123. pdata.chr_1_val = *prop;
  124. prop = of_get_property(np, "chr_2", NULL);
  125. if (prop)
  126. pdata.chr_2_val = *prop;
  127. prop = of_get_property(np, "chr_10", NULL);
  128. if (prop)
  129. pdata.chr_10_val = *prop;
  130. prop = of_get_property(np, "mpcr", NULL);
  131. if (prop)
  132. pdata.mpcr_val = *prop;
  133. prop = of_get_property(brg, "bcr", NULL);
  134. if (prop)
  135. pdata.bcr_val = *prop;
  136. pdata.brg_can_tune = 1; /* All current revs need this set */
  137. prop = of_get_property(brg, "clock-src", NULL);
  138. if (prop)
  139. pdata.brg_clk_src = *prop;
  140. prop = of_get_property(brg, "clock-frequency", NULL);
  141. if (prop)
  142. pdata.brg_clk_freq = *prop;
  143. pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
  144. if (!pdev)
  145. return -ENOMEM;
  146. err = platform_device_add_resources(pdev, r, 5);
  147. if (err)
  148. goto error;
  149. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  150. if (err)
  151. goto error;
  152. err = platform_device_add(pdev);
  153. if (err)
  154. goto error;
  155. return 0;
  156. error:
  157. platform_device_put(pdev);
  158. return err;
  159. }
  160. /*
  161. * Create mv64x60_eth platform devices
  162. */
  163. static int __init eth_register_shared_pdev(struct device_node *np)
  164. {
  165. struct platform_device *pdev;
  166. struct resource r[1];
  167. int err;
  168. np = of_get_parent(np);
  169. if (!np)
  170. return -ENODEV;
  171. err = of_address_to_resource(np, 0, &r[0]);
  172. of_node_put(np);
  173. if (err)
  174. return err;
  175. pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0,
  176. r, 1);
  177. if (IS_ERR(pdev))
  178. return PTR_ERR(pdev);
  179. return 0;
  180. }
  181. static int __init mv64x60_eth_device_setup(struct device_node *np, int id)
  182. {
  183. struct resource r[1];
  184. struct mv643xx_eth_platform_data pdata;
  185. struct platform_device *pdev;
  186. struct device_node *phy;
  187. const u8 *mac_addr;
  188. const int *prop;
  189. const phandle *ph;
  190. int err;
  191. /* only register the shared platform device the first time through */
  192. if (id == 0 && (err = eth_register_shared_pdev(np)))
  193. return err;
  194. memset(r, 0, sizeof(r));
  195. of_irq_to_resource(np, 0, &r[0]);
  196. memset(&pdata, 0, sizeof(pdata));
  197. prop = of_get_property(np, "block-index", NULL);
  198. if (!prop)
  199. return -ENODEV;
  200. pdata.port_number = *prop;
  201. mac_addr = of_get_mac_address(np);
  202. if (mac_addr)
  203. memcpy(pdata.mac_addr, mac_addr, 6);
  204. prop = of_get_property(np, "speed", NULL);
  205. if (prop)
  206. pdata.speed = *prop;
  207. prop = of_get_property(np, "tx_queue_size", NULL);
  208. if (prop)
  209. pdata.tx_queue_size = *prop;
  210. prop = of_get_property(np, "rx_queue_size", NULL);
  211. if (prop)
  212. pdata.rx_queue_size = *prop;
  213. prop = of_get_property(np, "tx_sram_addr", NULL);
  214. if (prop)
  215. pdata.tx_sram_addr = *prop;
  216. prop = of_get_property(np, "tx_sram_size", NULL);
  217. if (prop)
  218. pdata.tx_sram_size = *prop;
  219. prop = of_get_property(np, "rx_sram_addr", NULL);
  220. if (prop)
  221. pdata.rx_sram_addr = *prop;
  222. prop = of_get_property(np, "rx_sram_size", NULL);
  223. if (prop)
  224. pdata.rx_sram_size = *prop;
  225. ph = of_get_property(np, "phy", NULL);
  226. if (!ph)
  227. return -ENODEV;
  228. phy = of_find_node_by_phandle(*ph);
  229. if (phy == NULL)
  230. return -ENODEV;
  231. prop = of_get_property(phy, "reg", NULL);
  232. if (prop) {
  233. pdata.force_phy_addr = 1;
  234. pdata.phy_addr = *prop;
  235. }
  236. of_node_put(phy);
  237. pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number);
  238. if (!pdev)
  239. return -ENOMEM;
  240. err = platform_device_add_resources(pdev, r, 1);
  241. if (err)
  242. goto error;
  243. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  244. if (err)
  245. goto error;
  246. err = platform_device_add(pdev);
  247. if (err)
  248. goto error;
  249. return 0;
  250. error:
  251. platform_device_put(pdev);
  252. return err;
  253. }
  254. /*
  255. * Create mv64x60_i2c platform devices
  256. */
  257. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  258. {
  259. struct resource r[2];
  260. struct platform_device *pdev;
  261. struct mv64xxx_i2c_pdata pdata;
  262. const unsigned int *prop;
  263. int err;
  264. memset(r, 0, sizeof(r));
  265. err = of_address_to_resource(np, 0, &r[0]);
  266. if (err)
  267. return err;
  268. of_irq_to_resource(np, 0, &r[1]);
  269. memset(&pdata, 0, sizeof(pdata));
  270. pdata.freq_m = 8; /* default */
  271. prop = of_get_property(np, "freq_m", NULL);
  272. if (!prop)
  273. return -ENODEV;
  274. pdata.freq_m = *prop;
  275. pdata.freq_m = 3; /* default */
  276. prop = of_get_property(np, "freq_n", NULL);
  277. if (!prop)
  278. return -ENODEV;
  279. pdata.freq_n = *prop;
  280. pdata.timeout = 1000; /* default: 1 second */
  281. pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
  282. if (!pdev)
  283. return -ENOMEM;
  284. err = platform_device_add_resources(pdev, r, 2);
  285. if (err)
  286. goto error;
  287. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  288. if (err)
  289. goto error;
  290. err = platform_device_add(pdev);
  291. if (err)
  292. goto error;
  293. return 0;
  294. error:
  295. platform_device_put(pdev);
  296. return err;
  297. }
  298. /*
  299. * Create mv64x60_wdt platform devices
  300. */
  301. static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
  302. {
  303. struct resource r;
  304. struct platform_device *pdev;
  305. struct mv64x60_wdt_pdata pdata;
  306. const unsigned int *prop;
  307. int err;
  308. err = of_address_to_resource(np, 0, &r);
  309. if (err)
  310. return err;
  311. memset(&pdata, 0, sizeof(pdata));
  312. pdata.timeout = 10; /* Default: 10 seconds */
  313. np = of_get_parent(np);
  314. if (!np)
  315. return -ENODEV;
  316. prop = of_get_property(np, "clock-frequency", NULL);
  317. of_node_put(np);
  318. if (!prop)
  319. return -ENODEV;
  320. pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
  321. pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
  322. if (!pdev)
  323. return -ENOMEM;
  324. err = platform_device_add_resources(pdev, &r, 1);
  325. if (err)
  326. goto error;
  327. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  328. if (err)
  329. goto error;
  330. err = platform_device_add(pdev);
  331. if (err)
  332. goto error;
  333. return 0;
  334. error:
  335. platform_device_put(pdev);
  336. return err;
  337. }
  338. static int __init mv64x60_device_setup(void)
  339. {
  340. struct device_node *np = NULL;
  341. int id;
  342. int err;
  343. id = 0;
  344. for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc")
  345. if ((err = mv64x60_mpsc_device_setup(np, id++)))
  346. goto error;
  347. id = 0;
  348. for_each_compatible_node(np, "network", "marvell,mv64360-eth")
  349. if ((err = mv64x60_eth_device_setup(np, id++)))
  350. goto error;
  351. id = 0;
  352. for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c")
  353. if ((err = mv64x60_i2c_device_setup(np, id++)))
  354. goto error;
  355. /* support up to one watchdog timer */
  356. np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
  357. if (np) {
  358. if ((err = mv64x60_wdt_device_setup(np, id)))
  359. goto error;
  360. of_node_put(np);
  361. }
  362. return 0;
  363. error:
  364. of_node_put(np);
  365. return err;
  366. }
  367. arch_initcall(mv64x60_device_setup);
  368. static int __init mv64x60_add_mpsc_console(void)
  369. {
  370. struct device_node *np = NULL;
  371. const char *prop;
  372. prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
  373. if (prop == NULL)
  374. goto not_mpsc;
  375. np = of_find_node_by_path(prop);
  376. if (!np)
  377. goto not_mpsc;
  378. if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
  379. goto not_mpsc;
  380. prop = of_get_property(np, "cell-index", NULL);
  381. if (!prop)
  382. goto not_mpsc;
  383. add_preferred_console("ttyMM", *(int *)prop, NULL);
  384. not_mpsc:
  385. return 0;
  386. }
  387. console_initcall(mv64x60_add_mpsc_console);