mv64x60_dev.c 11 KB

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