mv64x60_dev.c 11 KB

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