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