mv64x60_dev.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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/mv643xx.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/prom.h>
  17. /*
  18. * These functions provide the necessary setup for the mv64x60 drivers.
  19. * These drivers are unusual in that they work on both the MIPS and PowerPC
  20. * architectures. Because of that, the drivers do not support the normal
  21. * PowerPC of_platform_bus_type. They support platform_bus_type instead.
  22. */
  23. /*
  24. * Create MPSC platform devices
  25. */
  26. static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
  27. {
  28. struct platform_device *pdev;
  29. struct resource r[2];
  30. struct mpsc_shared_pdata pdata;
  31. const phandle *ph;
  32. struct device_node *mpscrouting, *mpscintr;
  33. int err;
  34. ph = of_get_property(np, "mpscrouting", NULL);
  35. mpscrouting = of_find_node_by_phandle(*ph);
  36. if (!mpscrouting)
  37. return -ENODEV;
  38. err = of_address_to_resource(mpscrouting, 0, &r[0]);
  39. of_node_put(mpscrouting);
  40. if (err)
  41. return err;
  42. ph = of_get_property(np, "mpscintr", NULL);
  43. mpscintr = of_find_node_by_phandle(*ph);
  44. if (!mpscintr)
  45. return -ENODEV;
  46. err = of_address_to_resource(mpscintr, 0, &r[1]);
  47. of_node_put(mpscintr);
  48. if (err)
  49. return err;
  50. memset(&pdata, 0, sizeof(pdata));
  51. pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
  52. if (!pdev)
  53. return -ENOMEM;
  54. err = platform_device_add_resources(pdev, r, 2);
  55. if (err)
  56. goto error;
  57. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  58. if (err)
  59. goto error;
  60. err = platform_device_add(pdev);
  61. if (err)
  62. goto error;
  63. return 0;
  64. error:
  65. platform_device_put(pdev);
  66. return err;
  67. }
  68. static int __init mv64x60_mpsc_device_setup(struct device_node *np, int id)
  69. {
  70. struct resource r[5];
  71. struct mpsc_pdata pdata;
  72. struct platform_device *pdev;
  73. const unsigned int *prop;
  74. const phandle *ph;
  75. struct device_node *sdma, *brg;
  76. int err;
  77. int port_number;
  78. /* only register the shared platform device the first time through */
  79. if (id == 0 && (err = mv64x60_mpsc_register_shared_pdev(np)))
  80. return err;
  81. memset(r, 0, sizeof(r));
  82. err = of_address_to_resource(np, 0, &r[0]);
  83. if (err)
  84. return err;
  85. of_irq_to_resource(np, 0, &r[4]);
  86. ph = of_get_property(np, "sdma", NULL);
  87. sdma = of_find_node_by_phandle(*ph);
  88. if (!sdma)
  89. return -ENODEV;
  90. of_irq_to_resource(sdma, 0, &r[3]);
  91. err = of_address_to_resource(sdma, 0, &r[1]);
  92. of_node_put(sdma);
  93. if (err)
  94. return err;
  95. ph = of_get_property(np, "brg", NULL);
  96. brg = of_find_node_by_phandle(*ph);
  97. if (!brg)
  98. return -ENODEV;
  99. err = of_address_to_resource(brg, 0, &r[2]);
  100. of_node_put(brg);
  101. if (err)
  102. return err;
  103. prop = of_get_property(np, "block-index", NULL);
  104. if (!prop)
  105. return -ENODEV;
  106. port_number = *(int *)prop;
  107. memset(&pdata, 0, sizeof(pdata));
  108. pdata.cache_mgmt = 1; /* All current revs need this set */
  109. prop = of_get_property(np, "max_idle", NULL);
  110. if (prop)
  111. pdata.max_idle = *prop;
  112. prop = of_get_property(brg, "current-speed", NULL);
  113. if (prop)
  114. pdata.default_baud = *prop;
  115. /* Default is 8 bits, no parity, no flow control */
  116. pdata.default_bits = 8;
  117. pdata.default_parity = 'n';
  118. pdata.default_flow = 'n';
  119. prop = of_get_property(np, "chr_1", NULL);
  120. if (prop)
  121. pdata.chr_1_val = *prop;
  122. prop = of_get_property(np, "chr_2", NULL);
  123. if (prop)
  124. pdata.chr_2_val = *prop;
  125. prop = of_get_property(np, "chr_10", NULL);
  126. if (prop)
  127. pdata.chr_10_val = *prop;
  128. prop = of_get_property(np, "mpcr", NULL);
  129. if (prop)
  130. pdata.mpcr_val = *prop;
  131. prop = of_get_property(brg, "bcr", NULL);
  132. if (prop)
  133. pdata.bcr_val = *prop;
  134. pdata.brg_can_tune = 1; /* All current revs need this set */
  135. prop = of_get_property(brg, "clock-src", NULL);
  136. if (prop)
  137. pdata.brg_clk_src = *prop;
  138. prop = of_get_property(brg, "clock-frequency", NULL);
  139. if (prop)
  140. pdata.brg_clk_freq = *prop;
  141. pdev = platform_device_alloc(MPSC_CTLR_NAME, port_number);
  142. if (!pdev)
  143. return -ENOMEM;
  144. err = platform_device_add_resources(pdev, r, 5);
  145. if (err)
  146. goto error;
  147. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  148. if (err)
  149. goto error;
  150. err = platform_device_add(pdev);
  151. if (err)
  152. goto error;
  153. return 0;
  154. error:
  155. platform_device_put(pdev);
  156. return err;
  157. }
  158. /*
  159. * Create mv64x60_eth platform devices
  160. */
  161. static int __init eth_register_shared_pdev(struct device_node *np)
  162. {
  163. struct platform_device *pdev;
  164. struct resource r[1];
  165. int err;
  166. np = of_get_parent(np);
  167. if (!np)
  168. return -ENODEV;
  169. err = of_address_to_resource(np, 0, &r[0]);
  170. of_node_put(np);
  171. if (err)
  172. return err;
  173. pdev = platform_device_register_simple(MV643XX_ETH_SHARED_NAME, 0,
  174. r, 1);
  175. if (IS_ERR(pdev))
  176. return PTR_ERR(pdev);
  177. return 0;
  178. }
  179. static int __init mv64x60_eth_device_setup(struct device_node *np, int id)
  180. {
  181. struct resource r[1];
  182. struct mv643xx_eth_platform_data pdata;
  183. struct platform_device *pdev;
  184. struct device_node *phy;
  185. const u8 *mac_addr;
  186. const int *prop;
  187. const phandle *ph;
  188. int err;
  189. /* only register the shared platform device the first time through */
  190. if (id == 0 && (err = eth_register_shared_pdev(np)))
  191. return err;;
  192. memset(r, 0, sizeof(r));
  193. of_irq_to_resource(np, 0, &r[0]);
  194. memset(&pdata, 0, sizeof(pdata));
  195. prop = of_get_property(np, "block-index", NULL);
  196. if (!prop)
  197. return -ENODEV;
  198. pdata.port_number = *prop;
  199. mac_addr = of_get_mac_address(np);
  200. if (mac_addr)
  201. memcpy(pdata.mac_addr, mac_addr, 6);
  202. prop = of_get_property(np, "speed", NULL);
  203. if (prop)
  204. pdata.speed = *prop;
  205. prop = of_get_property(np, "tx_queue_size", NULL);
  206. if (prop)
  207. pdata.tx_queue_size = *prop;
  208. prop = of_get_property(np, "rx_queue_size", NULL);
  209. if (prop)
  210. pdata.rx_queue_size = *prop;
  211. prop = of_get_property(np, "tx_sram_addr", NULL);
  212. if (prop)
  213. pdata.tx_sram_addr = *prop;
  214. prop = of_get_property(np, "tx_sram_size", NULL);
  215. if (prop)
  216. pdata.tx_sram_size = *prop;
  217. prop = of_get_property(np, "rx_sram_addr", NULL);
  218. if (prop)
  219. pdata.rx_sram_addr = *prop;
  220. prop = of_get_property(np, "rx_sram_size", NULL);
  221. if (prop)
  222. pdata.rx_sram_size = *prop;
  223. ph = of_get_property(np, "phy", NULL);
  224. if (!ph)
  225. return -ENODEV;
  226. phy = of_find_node_by_phandle(*ph);
  227. if (phy == NULL)
  228. return -ENODEV;
  229. prop = of_get_property(phy, "reg", NULL);
  230. if (prop) {
  231. pdata.force_phy_addr = 1;
  232. pdata.phy_addr = *prop;
  233. }
  234. of_node_put(phy);
  235. pdev = platform_device_alloc(MV643XX_ETH_NAME, pdata.port_number);
  236. if (!pdev)
  237. return -ENOMEM;
  238. err = platform_device_add_resources(pdev, r, 1);
  239. if (err)
  240. goto error;
  241. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  242. if (err)
  243. goto error;
  244. err = platform_device_add(pdev);
  245. if (err)
  246. goto error;
  247. return 0;
  248. error:
  249. platform_device_put(pdev);
  250. return err;
  251. }
  252. /*
  253. * Create mv64x60_i2c platform devices
  254. */
  255. static int __init mv64x60_i2c_device_setup(struct device_node *np, int id)
  256. {
  257. struct resource r[2];
  258. struct platform_device *pdev;
  259. struct mv64xxx_i2c_pdata pdata;
  260. const unsigned int *prop;
  261. int err;
  262. memset(r, 0, sizeof(r));
  263. err = of_address_to_resource(np, 0, &r[0]);
  264. if (err)
  265. return err;
  266. of_irq_to_resource(np, 0, &r[1]);
  267. memset(&pdata, 0, sizeof(pdata));
  268. prop = of_get_property(np, "freq_m", NULL);
  269. if (!prop)
  270. return -ENODEV;
  271. pdata.freq_m = *prop;
  272. prop = of_get_property(np, "freq_n", NULL);
  273. if (!prop)
  274. return -ENODEV;
  275. pdata.freq_n = *prop;
  276. prop = of_get_property(np, "timeout", NULL);
  277. if (prop)
  278. pdata.timeout = *prop;
  279. else
  280. pdata.timeout = 1000; /* 1 second */
  281. prop = of_get_property(np, "retries", NULL);
  282. if (prop)
  283. pdata.retries = *prop;
  284. else
  285. pdata.retries = 1;
  286. pdev = platform_device_alloc(MV64XXX_I2C_CTLR_NAME, id);
  287. if (!pdev)
  288. return -ENOMEM;
  289. err = platform_device_add_resources(pdev, r, 2);
  290. if (err)
  291. goto error;
  292. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  293. if (err)
  294. goto error;
  295. err = platform_device_add(pdev);
  296. if (err)
  297. goto error;
  298. return 0;
  299. error:
  300. platform_device_put(pdev);
  301. return err;
  302. }
  303. static int __init mv64x60_device_setup(void)
  304. {
  305. struct device_node *np = NULL;
  306. int id;
  307. int err;
  308. for (id = 0;
  309. (np = of_find_compatible_node(np, "serial", "marvell,mpsc")); id++)
  310. if ((err = mv64x60_mpsc_device_setup(np, id)))
  311. goto error;
  312. for (id = 0;
  313. (np = of_find_compatible_node(np, "network",
  314. "marvell,mv64x60-eth"));
  315. id++)
  316. if ((err = mv64x60_eth_device_setup(np, id)))
  317. goto error;
  318. for (id = 0;
  319. (np = of_find_compatible_node(np, "i2c", "marvell,mv64x60-i2c"));
  320. id++)
  321. if ((err = mv64x60_i2c_device_setup(np, id)))
  322. goto error;
  323. return 0;
  324. error:
  325. of_node_put(np);
  326. return err;
  327. }
  328. arch_initcall(mv64x60_device_setup);