mv64x60_dev.c 11 KB

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