platform_net.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (c) 2003-2012 Broadcom Corporation
  3. * All Rights Reserved
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * 1. Redistributions of source code must retain the above copyright
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the Broadcom
  10. * license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in
  20. * the documentation and/or other materials provided with the
  21. * distribution.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
  24. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  32. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  33. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <linux/device.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/kernel.h>
  38. #include <linux/init.h>
  39. #include <linux/io.h>
  40. #include <linux/delay.h>
  41. #include <linux/ioport.h>
  42. #include <linux/resource.h>
  43. #include <linux/phy.h>
  44. #include <asm/netlogic/haldefs.h>
  45. #include <asm/netlogic/common.h>
  46. #include <asm/netlogic/xlr/fmn.h>
  47. #include <asm/netlogic/xlr/xlr.h>
  48. #include <asm/netlogic/psb-bootinfo.h>
  49. #include <asm/netlogic/xlr/pic.h>
  50. #include <asm/netlogic/xlr/iomap.h>
  51. #include "platform_net.h"
  52. /* Linux Net */
  53. #define MAX_NUM_GMAC 8
  54. #define MAX_NUM_XLS_GMAC 8
  55. #define MAX_NUM_XLR_GMAC 4
  56. static u32 xlr_gmac_offsets[] = {
  57. NETLOGIC_IO_GMAC_0_OFFSET, NETLOGIC_IO_GMAC_1_OFFSET,
  58. NETLOGIC_IO_GMAC_2_OFFSET, NETLOGIC_IO_GMAC_3_OFFSET,
  59. NETLOGIC_IO_GMAC_4_OFFSET, NETLOGIC_IO_GMAC_5_OFFSET,
  60. NETLOGIC_IO_GMAC_6_OFFSET, NETLOGIC_IO_GMAC_7_OFFSET
  61. };
  62. static u32 xlr_gmac_irqs[] = { PIC_GMAC_0_IRQ, PIC_GMAC_1_IRQ,
  63. PIC_GMAC_2_IRQ, PIC_GMAC_3_IRQ,
  64. PIC_GMAC_4_IRQ, PIC_GMAC_5_IRQ,
  65. PIC_GMAC_6_IRQ, PIC_GMAC_7_IRQ
  66. };
  67. static struct resource xlr_net0_res[8];
  68. static struct resource xlr_net1_res[8];
  69. static u32 __iomem *gmac4_addr;
  70. static u32 __iomem *gpio_addr;
  71. static void xlr_resource_init(struct resource *res, int offset, int irq)
  72. {
  73. res->name = "gmac";
  74. res->start = CPHYSADDR(nlm_mmio_base(offset));
  75. res->end = res->start + 0xfff;
  76. res->flags = IORESOURCE_MEM;
  77. res++;
  78. res->name = "gmac";
  79. res->start = res->end = irq;
  80. res->flags = IORESOURCE_IRQ;
  81. }
  82. static struct platform_device *gmac_controller2_init(void *gmac0_addr)
  83. {
  84. int mac;
  85. static struct xlr_net_data ndata1 = {
  86. .phy_interface = PHY_INTERFACE_MODE_SGMII,
  87. .rfr_station = FMN_STNID_GMAC1_FR_0,
  88. .bucket_size = xlr_board_fmn_config.bucket_size,
  89. .gmac_fmn_info = &xlr_board_fmn_config.gmac[1],
  90. };
  91. static struct platform_device xlr_net_dev1 = {
  92. .name = "xlr-net",
  93. .id = 1,
  94. .dev.platform_data = &ndata1,
  95. };
  96. gmac4_addr = ioremap(CPHYSADDR(
  97. nlm_mmio_base(NETLOGIC_IO_GMAC_4_OFFSET)), 0xfff);
  98. ndata1.serdes_addr = gmac4_addr;
  99. ndata1.pcs_addr = gmac4_addr;
  100. ndata1.mii_addr = gmac0_addr;
  101. ndata1.gpio_addr = gpio_addr;
  102. ndata1.cpu_mask = nlm_current_node()->coremask;
  103. xlr_net_dev1.resource = xlr_net1_res;
  104. for (mac = 0; mac < 4; mac++) {
  105. ndata1.tx_stnid[mac] = FMN_STNID_GMAC1_TX0 + mac;
  106. ndata1.phy_addr[mac] = mac + 4 + 0x10;
  107. xlr_resource_init(&xlr_net1_res[mac * 2],
  108. xlr_gmac_offsets[mac + 4],
  109. xlr_gmac_irqs[mac + 4]);
  110. }
  111. xlr_net_dev1.num_resources = 8;
  112. return &xlr_net_dev1;
  113. }
  114. static void xls_gmac_init(void)
  115. {
  116. int mac;
  117. struct platform_device *xlr_net_dev1;
  118. void __iomem *gmac0_addr = ioremap(CPHYSADDR(
  119. nlm_mmio_base(NETLOGIC_IO_GMAC_0_OFFSET)), 0xfff);
  120. static struct xlr_net_data ndata0 = {
  121. .rfr_station = FMN_STNID_GMACRFR_0,
  122. .bucket_size = xlr_board_fmn_config.bucket_size,
  123. .gmac_fmn_info = &xlr_board_fmn_config.gmac[0],
  124. };
  125. static struct platform_device xlr_net_dev0 = {
  126. .name = "xlr-net",
  127. .id = 0,
  128. };
  129. xlr_net_dev0.dev.platform_data = &ndata0;
  130. ndata0.serdes_addr = gmac0_addr;
  131. ndata0.pcs_addr = gmac0_addr;
  132. ndata0.mii_addr = gmac0_addr;
  133. /* Passing GPIO base for serdes init. Only needed on sgmii ports */
  134. gpio_addr = ioremap(CPHYSADDR(
  135. nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET)), 0xfff);
  136. ndata0.gpio_addr = gpio_addr;
  137. ndata0.cpu_mask = nlm_current_node()->coremask;
  138. xlr_net_dev0.resource = xlr_net0_res;
  139. switch (nlm_prom_info.board_major_version) {
  140. case 12:
  141. /* first block RGMII or XAUI, use RGMII */
  142. ndata0.phy_interface = PHY_INTERFACE_MODE_RGMII;
  143. ndata0.tx_stnid[0] = FMN_STNID_GMAC0_TX0;
  144. ndata0.phy_addr[0] = 0;
  145. xlr_net_dev0.num_resources = 2;
  146. xlr_resource_init(&xlr_net0_res[0], xlr_gmac_offsets[0],
  147. xlr_gmac_irqs[0]);
  148. platform_device_register(&xlr_net_dev0);
  149. /* second block is XAUI, not supported yet */
  150. break;
  151. default:
  152. /* default XLS config, all ports SGMII */
  153. ndata0.phy_interface = PHY_INTERFACE_MODE_SGMII;
  154. for (mac = 0; mac < 4; mac++) {
  155. ndata0.tx_stnid[mac] = FMN_STNID_GMAC0_TX0 + mac;
  156. ndata0.phy_addr[mac] = mac + 0x10;
  157. xlr_resource_init(&xlr_net0_res[mac * 2],
  158. xlr_gmac_offsets[mac],
  159. xlr_gmac_irqs[mac]);
  160. }
  161. xlr_net_dev0.num_resources = 8;
  162. platform_device_register(&xlr_net_dev0);
  163. xlr_net_dev1 = gmac_controller2_init(gmac0_addr);
  164. platform_device_register(xlr_net_dev1);
  165. }
  166. }
  167. static void xlr_gmac_init(void)
  168. {
  169. int mac;
  170. /* assume all GMACs for now */
  171. static struct xlr_net_data ndata0 = {
  172. .phy_interface = PHY_INTERFACE_MODE_RGMII,
  173. .serdes_addr = NULL,
  174. .pcs_addr = NULL,
  175. .rfr_station = FMN_STNID_GMACRFR_0,
  176. .bucket_size = xlr_board_fmn_config.bucket_size,
  177. .gmac_fmn_info = &xlr_board_fmn_config.gmac[0],
  178. .gpio_addr = NULL,
  179. };
  180. static struct platform_device xlr_net_dev0 = {
  181. .name = "xlr-net",
  182. .id = 0,
  183. .dev.platform_data = &ndata0,
  184. };
  185. ndata0.mii_addr = ioremap(CPHYSADDR(
  186. nlm_mmio_base(NETLOGIC_IO_GMAC_0_OFFSET)), 0xfff);
  187. ndata0.cpu_mask = nlm_current_node()->coremask;
  188. for (mac = 0; mac < MAX_NUM_XLR_GMAC; mac++) {
  189. ndata0.tx_stnid[mac] = FMN_STNID_GMAC0_TX0 + mac;
  190. ndata0.phy_addr[mac] = mac;
  191. xlr_resource_init(&xlr_net0_res[mac * 2], xlr_gmac_offsets[mac],
  192. xlr_gmac_irqs[mac]);
  193. }
  194. xlr_net_dev0.num_resources = 8;
  195. xlr_net_dev0.resource = xlr_net0_res;
  196. platform_device_register(&xlr_net_dev0);
  197. }
  198. static int __init xlr_net_init(void)
  199. {
  200. if (nlm_chip_is_xls())
  201. xls_gmac_init();
  202. else
  203. xlr_gmac_init();
  204. return 0;
  205. }
  206. arch_initcall(xlr_net_init);