mv64x60_dev.c 11 KB

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