dev-enet.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/export.h>
  12. #include <bcm63xx_dev_enet.h>
  13. #include <bcm63xx_io.h>
  14. #include <bcm63xx_regs.h>
  15. #ifdef BCMCPU_RUNTIME_DETECT
  16. static const unsigned long bcm6348_regs_enetdmac[] = {
  17. [ENETDMAC_CHANCFG] = ENETDMAC_CHANCFG_REG,
  18. [ENETDMAC_IR] = ENETDMAC_IR_REG,
  19. [ENETDMAC_IRMASK] = ENETDMAC_IRMASK_REG,
  20. [ENETDMAC_MAXBURST] = ENETDMAC_MAXBURST_REG,
  21. };
  22. static const unsigned long bcm6345_regs_enetdmac[] = {
  23. [ENETDMAC_CHANCFG] = ENETDMA_6345_CHANCFG_REG,
  24. [ENETDMAC_IR] = ENETDMA_6345_IR_REG,
  25. [ENETDMAC_IRMASK] = ENETDMA_6345_IRMASK_REG,
  26. [ENETDMAC_MAXBURST] = ENETDMA_6345_MAXBURST_REG,
  27. [ENETDMAC_BUFALLOC] = ENETDMA_6345_BUFALLOC_REG,
  28. [ENETDMAC_RSTART] = ENETDMA_6345_RSTART_REG,
  29. [ENETDMAC_FC] = ENETDMA_6345_FC_REG,
  30. [ENETDMAC_LEN] = ENETDMA_6345_LEN_REG,
  31. };
  32. const unsigned long *bcm63xx_regs_enetdmac;
  33. EXPORT_SYMBOL(bcm63xx_regs_enetdmac);
  34. static __init void bcm63xx_enetdmac_regs_init(void)
  35. {
  36. if (BCMCPU_IS_6345())
  37. bcm63xx_regs_enetdmac = bcm6345_regs_enetdmac;
  38. else
  39. bcm63xx_regs_enetdmac = bcm6348_regs_enetdmac;
  40. }
  41. #else
  42. static __init void bcm63xx_enetdmac_regs_init(void) { }
  43. #endif
  44. static struct resource shared_res[] = {
  45. {
  46. .start = -1, /* filled at runtime */
  47. .end = -1, /* filled at runtime */
  48. .flags = IORESOURCE_MEM,
  49. },
  50. {
  51. .start = -1, /* filled at runtime */
  52. .end = -1, /* filled at runtime */
  53. .flags = IORESOURCE_MEM,
  54. },
  55. {
  56. .start = -1, /* filled at runtime */
  57. .end = -1, /* filled at runtime */
  58. .flags = IORESOURCE_MEM,
  59. },
  60. };
  61. static struct platform_device bcm63xx_enet_shared_device = {
  62. .name = "bcm63xx_enet_shared",
  63. .id = 0,
  64. .num_resources = ARRAY_SIZE(shared_res),
  65. .resource = shared_res,
  66. };
  67. static int shared_device_registered;
  68. static struct resource enet0_res[] = {
  69. {
  70. .start = -1, /* filled at runtime */
  71. .end = -1, /* filled at runtime */
  72. .flags = IORESOURCE_MEM,
  73. },
  74. {
  75. .start = -1, /* filled at runtime */
  76. .flags = IORESOURCE_IRQ,
  77. },
  78. {
  79. .start = -1, /* filled at runtime */
  80. .flags = IORESOURCE_IRQ,
  81. },
  82. {
  83. .start = -1, /* filled at runtime */
  84. .flags = IORESOURCE_IRQ,
  85. },
  86. };
  87. static struct bcm63xx_enet_platform_data enet0_pd;
  88. static struct platform_device bcm63xx_enet0_device = {
  89. .name = "bcm63xx_enet",
  90. .id = 0,
  91. .num_resources = ARRAY_SIZE(enet0_res),
  92. .resource = enet0_res,
  93. .dev = {
  94. .platform_data = &enet0_pd,
  95. },
  96. };
  97. static struct resource enet1_res[] = {
  98. {
  99. .start = -1, /* filled at runtime */
  100. .end = -1, /* filled at runtime */
  101. .flags = IORESOURCE_MEM,
  102. },
  103. {
  104. .start = -1, /* filled at runtime */
  105. .flags = IORESOURCE_IRQ,
  106. },
  107. {
  108. .start = -1, /* filled at runtime */
  109. .flags = IORESOURCE_IRQ,
  110. },
  111. {
  112. .start = -1, /* filled at runtime */
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. };
  116. static struct bcm63xx_enet_platform_data enet1_pd;
  117. static struct platform_device bcm63xx_enet1_device = {
  118. .name = "bcm63xx_enet",
  119. .id = 1,
  120. .num_resources = ARRAY_SIZE(enet1_res),
  121. .resource = enet1_res,
  122. .dev = {
  123. .platform_data = &enet1_pd,
  124. },
  125. };
  126. static struct resource enetsw_res[] = {
  127. {
  128. /* start & end filled at runtime */
  129. .flags = IORESOURCE_MEM,
  130. },
  131. {
  132. /* start filled at runtime */
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. {
  136. /* start filled at runtime */
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. };
  140. static struct bcm63xx_enetsw_platform_data enetsw_pd;
  141. static struct platform_device bcm63xx_enetsw_device = {
  142. .name = "bcm63xx_enetsw",
  143. .num_resources = ARRAY_SIZE(enetsw_res),
  144. .resource = enetsw_res,
  145. .dev = {
  146. .platform_data = &enetsw_pd,
  147. },
  148. };
  149. static int __init register_shared(void)
  150. {
  151. int ret, chan_count;
  152. if (shared_device_registered)
  153. return 0;
  154. bcm63xx_enetdmac_regs_init();
  155. shared_res[0].start = bcm63xx_regset_address(RSET_ENETDMA);
  156. shared_res[0].end = shared_res[0].start;
  157. if (BCMCPU_IS_6345())
  158. shared_res[0].end += (RSET_6345_ENETDMA_SIZE) - 1;
  159. else
  160. shared_res[0].end += (RSET_ENETDMA_SIZE) - 1;
  161. if (BCMCPU_IS_6328() || BCMCPU_IS_6362() || BCMCPU_IS_6368())
  162. chan_count = 32;
  163. else if (BCMCPU_IS_6345())
  164. chan_count = 8;
  165. else
  166. chan_count = 16;
  167. shared_res[1].start = bcm63xx_regset_address(RSET_ENETDMAC);
  168. shared_res[1].end = shared_res[1].start;
  169. shared_res[1].end += RSET_ENETDMAC_SIZE(chan_count) - 1;
  170. shared_res[2].start = bcm63xx_regset_address(RSET_ENETDMAS);
  171. shared_res[2].end = shared_res[2].start;
  172. shared_res[2].end += RSET_ENETDMAS_SIZE(chan_count) - 1;
  173. ret = platform_device_register(&bcm63xx_enet_shared_device);
  174. if (ret)
  175. return ret;
  176. shared_device_registered = 1;
  177. return 0;
  178. }
  179. int __init bcm63xx_enet_register(int unit,
  180. const struct bcm63xx_enet_platform_data *pd)
  181. {
  182. struct platform_device *pdev;
  183. struct bcm63xx_enet_platform_data *dpd;
  184. int ret;
  185. if (unit > 1)
  186. return -ENODEV;
  187. if (unit == 1 && (BCMCPU_IS_6338() || BCMCPU_IS_6345()))
  188. return -ENODEV;
  189. ret = register_shared();
  190. if (ret)
  191. return ret;
  192. if (unit == 0) {
  193. enet0_res[0].start = bcm63xx_regset_address(RSET_ENET0);
  194. enet0_res[0].end = enet0_res[0].start;
  195. enet0_res[0].end += RSET_ENET_SIZE - 1;
  196. enet0_res[1].start = bcm63xx_get_irq_number(IRQ_ENET0);
  197. enet0_res[2].start = bcm63xx_get_irq_number(IRQ_ENET0_RXDMA);
  198. enet0_res[3].start = bcm63xx_get_irq_number(IRQ_ENET0_TXDMA);
  199. pdev = &bcm63xx_enet0_device;
  200. } else {
  201. enet1_res[0].start = bcm63xx_regset_address(RSET_ENET1);
  202. enet1_res[0].end = enet1_res[0].start;
  203. enet1_res[0].end += RSET_ENET_SIZE - 1;
  204. enet1_res[1].start = bcm63xx_get_irq_number(IRQ_ENET1);
  205. enet1_res[2].start = bcm63xx_get_irq_number(IRQ_ENET1_RXDMA);
  206. enet1_res[3].start = bcm63xx_get_irq_number(IRQ_ENET1_TXDMA);
  207. pdev = &bcm63xx_enet1_device;
  208. }
  209. /* copy given platform data */
  210. dpd = pdev->dev.platform_data;
  211. memcpy(dpd, pd, sizeof(*pd));
  212. /* adjust them in case internal phy is used */
  213. if (dpd->use_internal_phy) {
  214. /* internal phy only exists for enet0 */
  215. if (unit == 1)
  216. return -ENODEV;
  217. dpd->phy_id = 1;
  218. dpd->has_phy_interrupt = 1;
  219. dpd->phy_interrupt = bcm63xx_get_irq_number(IRQ_ENET_PHY);
  220. }
  221. dpd->dma_chan_en_mask = ENETDMAC_CHANCFG_EN_MASK;
  222. dpd->dma_chan_int_mask = ENETDMAC_IR_PKTDONE_MASK;
  223. if (BCMCPU_IS_6345()) {
  224. dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_CHAINING_MASK;
  225. dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_WRAP_EN_MASK;
  226. dpd->dma_chan_en_mask |= ENETDMAC_CHANCFG_FLOWC_EN_MASK;
  227. dpd->dma_chan_int_mask |= ENETDMA_IR_BUFDONE_MASK;
  228. dpd->dma_chan_int_mask |= ENETDMA_IR_NOTOWNER_MASK;
  229. dpd->dma_chan_width = ENETDMA_6345_CHAN_WIDTH;
  230. dpd->dma_desc_shift = ENETDMA_6345_DESC_SHIFT;
  231. } else {
  232. dpd->dma_has_sram = true;
  233. dpd->dma_chan_width = ENETDMA_CHAN_WIDTH;
  234. }
  235. ret = platform_device_register(pdev);
  236. if (ret)
  237. return ret;
  238. return 0;
  239. }
  240. int __init
  241. bcm63xx_enetsw_register(const struct bcm63xx_enetsw_platform_data *pd)
  242. {
  243. int ret;
  244. if (!BCMCPU_IS_6328() && !BCMCPU_IS_6362() && !BCMCPU_IS_6368())
  245. return -ENODEV;
  246. ret = register_shared();
  247. if (ret)
  248. return ret;
  249. enetsw_res[0].start = bcm63xx_regset_address(RSET_ENETSW);
  250. enetsw_res[0].end = enetsw_res[0].start;
  251. enetsw_res[0].end += RSET_ENETSW_SIZE - 1;
  252. enetsw_res[1].start = bcm63xx_get_irq_number(IRQ_ENETSW_RXDMA0);
  253. enetsw_res[2].start = bcm63xx_get_irq_number(IRQ_ENETSW_TXDMA0);
  254. if (!enetsw_res[2].start)
  255. enetsw_res[2].start = -1;
  256. memcpy(bcm63xx_enetsw_device.dev.platform_data, pd, sizeof(*pd));
  257. if (BCMCPU_IS_6328())
  258. enetsw_pd.num_ports = ENETSW_PORTS_6328;
  259. else if (BCMCPU_IS_6362() || BCMCPU_IS_6368())
  260. enetsw_pd.num_ports = ENETSW_PORTS_6368;
  261. enetsw_pd.dma_has_sram = true;
  262. enetsw_pd.dma_chan_width = ENETDMA_CHAN_WIDTH;
  263. enetsw_pd.dma_chan_en_mask = ENETDMAC_CHANCFG_EN_MASK;
  264. enetsw_pd.dma_chan_int_mask = ENETDMAC_IR_PKTDONE_MASK;
  265. ret = platform_device_register(&bcm63xx_enetsw_device);
  266. if (ret)
  267. return ret;
  268. return 0;
  269. }