mv64x60_dev.c 11 KB

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