mv64x60_dev.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 struct platform_device * __init mv64x60_eth_register_shared_pdev(
  164. struct device_node *np, int id)
  165. {
  166. struct platform_device *pdev;
  167. struct resource r[1];
  168. int err;
  169. err = of_address_to_resource(np, 0, &r[0]);
  170. if (err)
  171. return ERR_PTR(err);
  172. pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
  173. r, 1);
  174. return pdev;
  175. }
  176. static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
  177. struct platform_device *shared_pdev)
  178. {
  179. struct resource r[1];
  180. struct mv643xx_eth_platform_data pdata;
  181. struct platform_device *pdev;
  182. struct device_node *phy;
  183. const u8 *mac_addr;
  184. const int *prop;
  185. const phandle *ph;
  186. int err;
  187. memset(r, 0, sizeof(r));
  188. of_irq_to_resource(np, 0, &r[0]);
  189. memset(&pdata, 0, sizeof(pdata));
  190. prop = of_get_property(np, "reg", NULL);
  191. if (!prop)
  192. return -ENODEV;
  193. pdata.port_number = *prop;
  194. mac_addr = of_get_mac_address(np);
  195. if (mac_addr)
  196. memcpy(pdata.mac_addr, mac_addr, 6);
  197. prop = of_get_property(np, "speed", NULL);
  198. if (prop)
  199. pdata.speed = *prop;
  200. prop = of_get_property(np, "tx_queue_size", NULL);
  201. if (prop)
  202. pdata.tx_queue_size = *prop;
  203. prop = of_get_property(np, "rx_queue_size", NULL);
  204. if (prop)
  205. pdata.rx_queue_size = *prop;
  206. prop = of_get_property(np, "tx_sram_addr", NULL);
  207. if (prop)
  208. pdata.tx_sram_addr = *prop;
  209. prop = of_get_property(np, "tx_sram_size", NULL);
  210. if (prop)
  211. pdata.tx_sram_size = *prop;
  212. prop = of_get_property(np, "rx_sram_addr", NULL);
  213. if (prop)
  214. pdata.rx_sram_addr = *prop;
  215. prop = of_get_property(np, "rx_sram_size", NULL);
  216. if (prop)
  217. pdata.rx_sram_size = *prop;
  218. ph = of_get_property(np, "phy", NULL);
  219. if (!ph)
  220. return -ENODEV;
  221. phy = of_find_node_by_phandle(*ph);
  222. if (phy == NULL)
  223. return -ENODEV;
  224. prop = of_get_property(phy, "reg", NULL);
  225. if (prop) {
  226. pdata.force_phy_addr = 1;
  227. pdata.phy_addr = *prop;
  228. }
  229. of_node_put(phy);
  230. pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
  231. if (!pdev)
  232. return -ENOMEM;
  233. err = platform_device_add_resources(pdev, r, 1);
  234. if (err)
  235. goto error;
  236. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  237. if (err)
  238. goto error;
  239. err = platform_device_add(pdev);
  240. if (err)
  241. goto error;
  242. return 0;
  243. error:
  244. platform_device_put(pdev);
  245. return err;
  246. }
  247. /*
  248. * Create mv64x60_i2c platform devices
  249. */
  250. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  251. {
  252. struct resource r[2];
  253. struct platform_device *pdev;
  254. struct mv64xxx_i2c_pdata pdata;
  255. const unsigned int *prop;
  256. int err;
  257. memset(r, 0, sizeof(r));
  258. err = of_address_to_resource(np, 0, &r[0]);
  259. if (err)
  260. return err;
  261. of_irq_to_resource(np, 0, &r[1]);
  262. memset(&pdata, 0, sizeof(pdata));
  263. pdata.freq_m = 8; /* default */
  264. prop = of_get_property(np, "freq_m", NULL);
  265. if (!prop)
  266. return -ENODEV;
  267. pdata.freq_m = *prop;
  268. pdata.freq_m = 3; /* default */
  269. prop = of_get_property(np, "freq_n", NULL);
  270. if (!prop)
  271. return -ENODEV;
  272. pdata.freq_n = *prop;
  273. pdata.timeout = 1000; /* default: 1 second */
  274. pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
  275. if (!pdev)
  276. return -ENOMEM;
  277. err = platform_device_add_resources(pdev, r, 2);
  278. if (err)
  279. goto error;
  280. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  281. if (err)
  282. goto error;
  283. err = platform_device_add(pdev);
  284. if (err)
  285. goto error;
  286. return 0;
  287. error:
  288. platform_device_put(pdev);
  289. return err;
  290. }
  291. /*
  292. * Create mv64x60_wdt platform devices
  293. */
  294. static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
  295. {
  296. struct resource r;
  297. struct platform_device *pdev;
  298. struct mv64x60_wdt_pdata pdata;
  299. const unsigned int *prop;
  300. int err;
  301. err = of_address_to_resource(np, 0, &r);
  302. if (err)
  303. return err;
  304. memset(&pdata, 0, sizeof(pdata));
  305. pdata.timeout = 10; /* Default: 10 seconds */
  306. np = of_get_parent(np);
  307. if (!np)
  308. return -ENODEV;
  309. prop = of_get_property(np, "clock-frequency", NULL);
  310. of_node_put(np);
  311. if (!prop)
  312. return -ENODEV;
  313. pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
  314. pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
  315. if (!pdev)
  316. return -ENOMEM;
  317. err = platform_device_add_resources(pdev, &r, 1);
  318. if (err)
  319. goto error;
  320. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  321. if (err)
  322. goto error;
  323. err = platform_device_add(pdev);
  324. if (err)
  325. goto error;
  326. return 0;
  327. error:
  328. platform_device_put(pdev);
  329. return err;
  330. }
  331. static int __init mv64x60_device_setup(void)
  332. {
  333. struct device_node *np, *np2;
  334. struct platform_device *pdev;
  335. int id, id2;
  336. int err;
  337. id = 0;
  338. for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc")
  339. if ((err = mv64x60_mpsc_device_setup(np, id++)))
  340. goto error;
  341. id = 0;
  342. id2 = 0;
  343. for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
  344. pdev = mv64x60_eth_register_shared_pdev(np, id++);
  345. if (IS_ERR(pdev)) {
  346. err = PTR_ERR(pdev);
  347. goto error;
  348. }
  349. for_each_child_of_node(np, np2) {
  350. if (!of_device_is_compatible(np2,
  351. "marvell,mv64360-eth"))
  352. continue;
  353. err = mv64x60_eth_device_setup(np2, id2++, pdev);
  354. if (err) {
  355. of_node_put(np2);
  356. goto error;
  357. }
  358. }
  359. }
  360. id = 0;
  361. for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c")
  362. if ((err = mv64x60_i2c_device_setup(np, id++)))
  363. goto error;
  364. /* support up to one watchdog timer */
  365. np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
  366. if (np) {
  367. if ((err = mv64x60_wdt_device_setup(np, id)))
  368. goto error;
  369. of_node_put(np);
  370. }
  371. return 0;
  372. error:
  373. of_node_put(np);
  374. return err;
  375. }
  376. arch_initcall(mv64x60_device_setup);
  377. static int __init mv64x60_add_mpsc_console(void)
  378. {
  379. struct device_node *np = NULL;
  380. const char *prop;
  381. prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
  382. if (prop == NULL)
  383. goto not_mpsc;
  384. np = of_find_node_by_path(prop);
  385. if (!np)
  386. goto not_mpsc;
  387. if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
  388. goto not_mpsc;
  389. prop = of_get_property(np, "cell-index", NULL);
  390. if (!prop)
  391. goto not_mpsc;
  392. add_preferred_console("ttyMM", *(int *)prop, NULL);
  393. not_mpsc:
  394. return 0;
  395. }
  396. console_initcall(mv64x60_add_mpsc_console);