mv64x60_dev.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. static int __init mv64x60_device_setup(void)
  159. {
  160. struct device_node *np = NULL;
  161. int id;
  162. int err;
  163. for (id = 0;
  164. (np = of_find_compatible_node(np, "serial", "marvell,mpsc")); id++)
  165. if ((err = mv64x60_mpsc_device_setup(np, id)))
  166. goto error;
  167. return 0;
  168. error:
  169. of_node_put(np);
  170. return err;
  171. }
  172. arch_initcall(mv64x60_device_setup);