mv64x60_dev.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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.force_phy_addr = 1;
  233. pdata.phy_addr = *prop;
  234. }
  235. of_node_put(phy);
  236. pdev = platform_device_alloc(MV643XX_ETH_NAME, id);
  237. if (!pdev)
  238. return -ENOMEM;
  239. err = platform_device_add_resources(pdev, r, 1);
  240. if (err)
  241. goto error;
  242. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  243. if (err)
  244. goto error;
  245. err = platform_device_add(pdev);
  246. if (err)
  247. goto error;
  248. return 0;
  249. error:
  250. platform_device_put(pdev);
  251. return err;
  252. }
  253. /*
  254. * Create mv64x60_i2c platform devices
  255. */
  256. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  257. {
  258. struct resource r[2];
  259. struct platform_device *pdev;
  260. struct mv64xxx_i2c_pdata pdata;
  261. const unsigned int *prop;
  262. int err;
  263. memset(r, 0, sizeof(r));
  264. err = of_address_to_resource(np, 0, &r[0]);
  265. if (err)
  266. return err;
  267. of_irq_to_resource(np, 0, &r[1]);
  268. memset(&pdata, 0, sizeof(pdata));
  269. pdata.freq_m = 8; /* default */
  270. prop = of_get_property(np, "freq_m", NULL);
  271. if (prop)
  272. pdata.freq_m = *prop;
  273. pdata.freq_m = 3; /* default */
  274. prop = of_get_property(np, "freq_n", NULL);
  275. if (prop)
  276. pdata.freq_n = *prop;
  277. pdata.timeout = 1000; /* default: 1 second */
  278. pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
  279. if (!pdev)
  280. return -ENOMEM;
  281. err = platform_device_add_resources(pdev, r, 2);
  282. if (err)
  283. goto error;
  284. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  285. if (err)
  286. goto error;
  287. err = platform_device_add(pdev);
  288. if (err)
  289. goto error;
  290. return 0;
  291. error:
  292. platform_device_put(pdev);
  293. return err;
  294. }
  295. /*
  296. * Create mv64x60_wdt platform devices
  297. */
  298. static int __init mv64x60_wdt_device_setup(struct device_node *np, int id)
  299. {
  300. struct resource r;
  301. struct platform_device *pdev;
  302. struct mv64x60_wdt_pdata pdata;
  303. const unsigned int *prop;
  304. int err;
  305. err = of_address_to_resource(np, 0, &r);
  306. if (err)
  307. return err;
  308. memset(&pdata, 0, sizeof(pdata));
  309. pdata.timeout = 10; /* Default: 10 seconds */
  310. np = of_get_parent(np);
  311. if (!np)
  312. return -ENODEV;
  313. prop = of_get_property(np, "clock-frequency", NULL);
  314. of_node_put(np);
  315. if (!prop)
  316. return -ENODEV;
  317. pdata.bus_clk = *prop / 1000000; /* wdt driver wants freq in MHz */
  318. pdev = platform_device_alloc(MV64x60_WDT_NAME, id);
  319. if (!pdev)
  320. return -ENOMEM;
  321. err = platform_device_add_resources(pdev, &r, 1);
  322. if (err)
  323. goto error;
  324. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  325. if (err)
  326. goto error;
  327. err = platform_device_add(pdev);
  328. if (err)
  329. goto error;
  330. return 0;
  331. error:
  332. platform_device_put(pdev);
  333. return err;
  334. }
  335. static int __init mv64x60_device_setup(void)
  336. {
  337. struct device_node *np, *np2;
  338. struct platform_device *pdev;
  339. int id, id2;
  340. int err;
  341. id = 0;
  342. for_each_compatible_node(np, "serial", "marvell,mv64360-mpsc") {
  343. err = mv64x60_mpsc_device_setup(np, id++);
  344. if (err)
  345. printk(KERN_ERR "Failed to initialize MV64x60 "
  346. "serial device %s: error %d.\n",
  347. np->full_name, err);
  348. }
  349. id = 0;
  350. id2 = 0;
  351. for_each_compatible_node(np, NULL, "marvell,mv64360-eth-group") {
  352. pdev = mv64x60_eth_register_shared_pdev(np, id++);
  353. if (IS_ERR(pdev)) {
  354. err = PTR_ERR(pdev);
  355. printk(KERN_ERR "Failed to initialize MV64x60 "
  356. "network block %s: error %d.\n",
  357. np->full_name, err);
  358. continue;
  359. }
  360. for_each_child_of_node(np, np2) {
  361. if (!of_device_is_compatible(np2,
  362. "marvell,mv64360-eth"))
  363. continue;
  364. err = mv64x60_eth_device_setup(np2, id2++, pdev);
  365. if (err)
  366. printk(KERN_ERR "Failed to initialize "
  367. "MV64x60 network device %s: "
  368. "error %d.\n",
  369. np2->full_name, err);
  370. }
  371. }
  372. id = 0;
  373. for_each_compatible_node(np, "i2c", "marvell,mv64360-i2c") {
  374. err = mv64x60_i2c_device_setup(np, id++);
  375. if (err)
  376. printk(KERN_ERR "Failed to initialize MV64x60 I2C "
  377. "bus %s: error %d.\n",
  378. np->full_name, err);
  379. }
  380. /* support up to one watchdog timer */
  381. np = of_find_compatible_node(np, NULL, "marvell,mv64360-wdt");
  382. if (np) {
  383. if ((err = mv64x60_wdt_device_setup(np, id)))
  384. printk(KERN_ERR "Failed to initialize MV64x60 "
  385. "Watchdog %s: error %d.\n",
  386. np->full_name, err);
  387. of_node_put(np);
  388. }
  389. /* Now add every node that is on the device bus */
  390. for_each_compatible_node(np, NULL, "marvell,mv64360")
  391. of_platform_bus_probe(np, of_mv64x60_devices, NULL);
  392. return 0;
  393. }
  394. arch_initcall(mv64x60_device_setup);
  395. static int __init mv64x60_add_mpsc_console(void)
  396. {
  397. struct device_node *np = NULL;
  398. const char *prop;
  399. prop = of_get_property(of_chosen, "linux,stdout-path", NULL);
  400. if (prop == NULL)
  401. goto not_mpsc;
  402. np = of_find_node_by_path(prop);
  403. if (!np)
  404. goto not_mpsc;
  405. if (!of_device_is_compatible(np, "marvell,mv64360-mpsc"))
  406. goto not_mpsc;
  407. prop = of_get_property(np, "cell-index", NULL);
  408. if (!prop)
  409. goto not_mpsc;
  410. add_preferred_console("ttyMM", *(int *)prop, NULL);
  411. not_mpsc:
  412. return 0;
  413. }
  414. console_initcall(mv64x60_add_mpsc_console);