mv64x60_dev.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 <linux/of_platform.h>
  18. #include <linux/dma-mapping.h>
  19. #include <asm/prom.h>
  20. /* These functions provide the necessary setup for the mv64x60 drivers. */
  21. static struct of_device_id __initdata of_mv64x60_devices[] = {
  22. { .compatible = "marvell,mv64306-devctrl", },
  23. {}
  24. };
  25. /*
  26. * Create MPSC platform devices
  27. */
  28. static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
  29. {
  30. struct platform_device *pdev;
  31. struct resource r[2];
  32. struct mpsc_shared_pdata pdata;
  33. const phandle *ph;
  34. struct device_node *mpscrouting, *mpscintr;
  35. int err;
  36. ph = of_get_property(np, "mpscrouting", NULL);
  37. mpscrouting = of_find_node_by_phandle(*ph);
  38. if (!mpscrouting)
  39. return -ENODEV;
  40. err = of_address_to_resource(mpscrouting, 0, &r[0]);
  41. of_node_put(mpscrouting);
  42. if (err)
  43. return err;
  44. ph = of_get_property(np, "mpscintr", NULL);
  45. mpscintr = of_find_node_by_phandle(*ph);
  46. if (!mpscintr)
  47. return -ENODEV;
  48. err = of_address_to_resource(mpscintr, 0, &r[1]);
  49. of_node_put(mpscintr);
  50. if (err)
  51. return err;
  52. memset(&pdata, 0, sizeof(pdata));
  53. pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
  54. if (!pdev)
  55. return -ENOMEM;
  56. err = platform_device_add_resources(pdev, r, 2);
  57. if (err)
  58. goto error;
  59. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  60. if (err)
  61. goto error;
  62. err = platform_device_add(pdev);
  63. if (err)
  64. goto error;
  65. return 0;
  66. error:
  67. platform_device_put(pdev);
  68. return err;
  69. }
  70. static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
  71. {
  72. struct resource r[5];
  73. struct mpsc_pdata pdata;
  74. struct platform_device *pdev;
  75. const unsigned int *prop;
  76. const phandle *ph;
  77. struct device_node *sdma, *brg;
  78. int err;
  79. int port_number;
  80. /* only register the shared platform device the first time through */
  81. if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
  82. return err;
  83. memset(r, 0, sizeof(r));
  84. err = of_address_to_resource(np, 0, &r[0]);
  85. if (err)
  86. return err;
  87. of_irq_to_resource(np, 0, &r[4]);
  88. ph = of_get_property(np, "sdma", NULL);
  89. sdma = of_find_node_by_phandle(*ph);
  90. if (!sdma)
  91. return -ENODEV;
  92. of_irq_to_resource(sdma, 0, &r[3]);
  93. err = of_address_to_resource(sdma, 0, &r[1]);
  94. of_node_put(sdma);
  95. if (err)
  96. return err;
  97. ph = of_get_property(np, "brg", NULL);
  98. brg = of_find_node_by_phandle(*ph);
  99. if (!brg)
  100. return -ENODEV;
  101. err = of_address_to_resource(brg, 0, &r[2]);
  102. of_node_put(brg);
  103. if (err)
  104. return err;
  105. prop = of_get_property(np, "cell-index", NULL);
  106. if (!prop)
  107. return -ENODEV;
  108. port_number = *(int *)prop;
  109. memset(&pdata, 0, sizeof(pdata));
  110. pdata.cache_mgmt = 1; /* All current revs need this set */
  111. pdata.max_idle = 40; /* default */
  112. prop = of_get_property(np, "max_idle", NULL);
  113. if (prop)
  114. pdata.max_idle = *prop;
  115. prop = of_get_property(brg, "current-speed", NULL);
  116. if (prop)
  117. pdata.default_baud = *prop;
  118. /* Default is 8 bits, no parity, no flow control */
  119. pdata.default_bits = 8;
  120. pdata.default_parity = 'n';
  121. pdata.default_flow = 'n';
  122. prop = of_get_property(np, "chr_1", NULL);
  123. if (prop)
  124. pdata.chr_1_val = *prop;
  125. prop = of_get_property(np, "chr_2", NULL);
  126. if (prop)
  127. pdata.chr_2_val = *prop;
  128. prop = of_get_property(np, "chr_10", NULL);
  129. if (prop)
  130. pdata.chr_10_val = *prop;
  131. prop = of_get_property(np, "mpcr", NULL);
  132. if (prop)
  133. pdata.mpcr_val = *prop;
  134. prop = of_get_property(brg, "bcr", NULL);
  135. if (prop)
  136. pdata.bcr_val = *prop;
  137. pdata.brg_can_tune = 1; /* All current revs need this set */
  138. prop = of_get_property(brg, "clock-src", NULL);
  139. if (prop)
  140. pdata.brg_clk_src = *prop;
  141. prop = of_get_property(brg, "clock-frequency", NULL);
  142. if (prop)
  143. pdata.brg_clk_freq = *prop;
  144. pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
  145. if (!pdev)
  146. return -ENOMEM;
  147. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  148. err = platform_device_add_resources(pdev, r, 5);
  149. if (err)
  150. goto error;
  151. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  152. if (err)
  153. goto error;
  154. err = platform_device_add(pdev);
  155. if (err)
  156. goto error;
  157. return 0;
  158. error:
  159. platform_device_put(pdev);
  160. return err;
  161. }
  162. /*
  163. * Create mv64x60_eth platform devices
  164. */
  165. static struct platform_device * __init mv64x60_eth_register_shared_pdev(
  166. struct device_node *np, int id)
  167. {
  168. struct platform_device *pdev;
  169. struct resource r[1];
  170. int err;
  171. err = of_address_to_resource(np, 0, &r[0]);
  172. if (err)
  173. return ERR_PTR(err);
  174. pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, id,
  175. r, 1);
  176. return pdev;
  177. }
  178. static int __init mv64x60_eth_device_setup(struct device_node *np, int id,
  179. struct platform_device *shared_pdev)
  180. {
  181. struct resource r[1];
  182. struct mv643xx_eth_platform_data pdata;
  183. struct platform_device *pdev;
  184. struct device_node *phy;
  185. const u8 *mac_addr;
  186. const int *prop;
  187. const phandle *ph;
  188. int err;
  189. memset(r, 0, sizeof(r));
  190. of_irq_to_resource(np, 0, &r[0]);
  191. memset(&pdata, 0, sizeof(pdata));
  192. pdata.shared = shared_pdev;
  193. prop = of_get_property(np, "reg", NULL);
  194. if (!prop)
  195. return -ENODEV;
  196. pdata.port_number = *prop;
  197. mac_addr = of_get_mac_address(np);
  198. if (mac_addr)
  199. memcpy(pdata.mac_addr, mac_addr, 6);
  200. prop = of_get_property(np, "speed", NULL);
  201. if (prop)
  202. pdata.speed = *prop;
  203. prop = of_get_property(np, "tx_queue_size", NULL);
  204. if (prop)
  205. pdata.tx_queue_size = *prop;
  206. prop = of_get_property(np, "rx_queue_size", NULL);
  207. if (prop)
  208. pdata.rx_queue_size = *prop;
  209. prop = of_get_property(np, "tx_sram_addr", NULL);
  210. if (prop)
  211. pdata.tx_sram_addr = *prop;
  212. prop = of_get_property(np, "tx_sram_size", NULL);
  213. if (prop)
  214. pdata.tx_sram_size = *prop;
  215. prop = of_get_property(np, "rx_sram_addr", NULL);
  216. if (prop)
  217. pdata.rx_sram_addr = *prop;
  218. prop = of_get_property(np, "rx_sram_size", NULL);
  219. if (prop)
  220. pdata.rx_sram_size = *prop;
  221. ph = of_get_property(np, "phy", NULL);
  222. if (!ph)
  223. return -ENODEV;
  224. phy = of_find_node_by_phandle(*ph);
  225. if (phy == NULL)
  226. return -ENODEV;
  227. prop = of_get_property(phy, "reg", NULL);
  228. if (prop)
  229. pdata.phy_addr = MV643XX_ETH_PHY_ADDR(*prop);
  230. of_node_put(phy);
  231. pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
  232. if (!pdev)
  233. return -ENOMEM;
  234. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  235. err = platform_device_add_resources(pdev, r, 1);
  236. if (err)
  237. goto error;
  238. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  239. if (err)
  240. goto error;
  241. err = platform_device_add(pdev);
  242. if (err)
  243. goto error;
  244. return 0;
  245. error:
  246. platform_device_put(pdev);
  247. return err;
  248. }
  249. /*
  250. * Create mv64x60_i2c platform devices
  251. */
  252. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  253. {
  254. struct resource r[2];
  255. struct platform_device *pdev;
  256. struct mv64xxx_i2c_pdata pdata;
  257. const unsigned int *prop;
  258. int err;
  259. memset(r, 0, sizeof(r));
  260. err = of_address_to_resource(np, 0, &r[0]);
  261. if (err)
  262. return err;
  263. of_irq_to_resource(np, 0, &r[1]);
  264. memset(&pdata, 0, sizeof(pdata));
  265. pdata.freq_m = 8; /* default */
  266. prop = of_get_property(np, "freq_m", NULL);
  267. if (prop)
  268. pdata.freq_m = *prop;
  269. pdata.freq_m = 3; /* default */
  270. prop = of_get_property(np, "freq_n", NULL);
  271. if (prop)
  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. err = mv64x60_mpsc_device_setup(np, id++);
  340. if (err)
  341. printk(KERN_ERR "Failed to initialize MV64x60 "
  342. "serial device %s: error %d.\n",
  343. np->full_name, err);
  344. }
  345. id = 0;
  346. id2 = 0;
  347. for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
  348. pdev = mv64x60_eth_register_shared_pdev(np, id++);
  349. if (IS_ERR(pdev)) {
  350. err = PTR_ERR(pdev);
  351. printk(KERN_ERR "Failed to initialize MV64x60 "
  352. "network block %s: error %d.\n",
  353. np->full_name, err);
  354. continue;
  355. }
  356. for_each_child_of_node(np, np2) {
  357. if (!of_device_is_compatible(np2,
  358. "marvell,mv64360-eth"))
  359. continue;
  360. err = mv64x60_eth_device_setup(np2, id2++, pdev);
  361. if (err)
  362. printk(KERN_ERR "Failed to initialize "
  363. "MV64x60 network device %s: "
  364. "error %d.\n",
  365. np2->full_name, err);
  366. }
  367. }
  368. id = 0;
  369. for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") {
  370. err = mv64x60_i2c_device_setup(np, id++);
  371. if (err)
  372. printk(KERN_ERR "Failed to initialize MV64x60 I2C "
  373. "bus %s: error %d.\n",
  374. np->full_name, err);
  375. }
  376. /* support up to one watchdog timer */
  377. np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
  378. if (np) {
  379. if ((err = mv64x60_wdt_device_setup(np, id)))
  380. printk(KERN_ERR "Failed to initialize MV64x60 "
  381. "Watchdog %s: error %d.\n",
  382. np->full_name, err);
  383. of_node_put(np);
  384. }
  385. /* Now add every node that is on the device bus */
  386. for_each_compatible_node(np, NULL, "marvell,mv64360")
  387. of_platform_bus_probe(np, of_mv64x60_devices, NULL);
  388. return 0;
  389. }
  390. arch_initcall(mv64x60_device_setup);
  391. static int __init mv64x60_add_mpsc_console(void)
  392. {
  393. struct device_node *np = NULL;
  394. const char *prop;
  395. prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
  396. if (prop == NULL)
  397. goto not_mpsc;
  398. np = of_find_node_by_path(prop);
  399. if (!np)
  400. goto not_mpsc;
  401. if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
  402. goto not_mpsc;
  403. prop = of_get_property(np, "cell-index", NULL);
  404. if (!prop)
  405. goto not_mpsc;
  406. add_preferred_console("ttyMM", *(int *)prop, NULL);
  407. not_mpsc:
  408. return 0;
  409. }
  410. console_initcall(mv64x60_add_mpsc_console);