dev-enet.c 7.7 KB

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