2 * Copyright (c) 2003-2012 Broadcom Corporation
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
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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
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.
36 #include <linux/device.h>
37 #include <linux/platform_device.h>
38 #include <linux/kernel.h>
39 #include <linux/init.h>
41 #include <linux/delay.h>
42 #include <linux/ioport.h>
43 #include <linux/resource.h>
44 #include <linux/phy.h>
46 #include <asm/netlogic/haldefs.h>
47 #include <asm/netlogic/common.h>
48 #include <asm/netlogic/xlr/fmn.h>
49 #include <asm/netlogic/xlr/xlr.h>
50 #include <asm/netlogic/psb-bootinfo.h>
51 #include <asm/netlogic/xlr/pic.h>
52 #include <asm/netlogic/xlr/iomap.h>
54 #include "platform_net.h"
57 #define MAX_NUM_GMAC 8
58 #define MAX_NUM_XLS_GMAC 8
59 #define MAX_NUM_XLR_GMAC 4
61 static u32 xlr_gmac_offsets[] = {
62 NETLOGIC_IO_GMAC_0_OFFSET, NETLOGIC_IO_GMAC_1_OFFSET,
63 NETLOGIC_IO_GMAC_2_OFFSET, NETLOGIC_IO_GMAC_3_OFFSET,
64 NETLOGIC_IO_GMAC_4_OFFSET, NETLOGIC_IO_GMAC_5_OFFSET,
65 NETLOGIC_IO_GMAC_6_OFFSET, NETLOGIC_IO_GMAC_7_OFFSET
68 static u32 xlr_gmac_irqs[] = { PIC_GMAC_0_IRQ, PIC_GMAC_1_IRQ,
69 PIC_GMAC_2_IRQ, PIC_GMAC_3_IRQ,
70 PIC_GMAC_4_IRQ, PIC_GMAC_5_IRQ,
71 PIC_GMAC_6_IRQ, PIC_GMAC_7_IRQ
74 static struct resource xlr_net0_res[8];
75 static struct resource xlr_net1_res[8];
76 static u32 __iomem *gmac4_addr;
77 static u32 __iomem *gpio_addr;
79 static void xlr_resource_init(struct resource *res, int offset, int irq)
83 res->start = CPHYSADDR(nlm_mmio_base(offset));
84 res->end = res->start + 0xfff;
85 res->flags = IORESOURCE_MEM;
89 res->start = res->end = irq;
90 res->flags = IORESOURCE_IRQ;
93 static struct platform_device *gmac_controller2_init(void *gmac0_addr)
96 static struct xlr_net_data ndata1 = {
97 .phy_interface = PHY_INTERFACE_MODE_SGMII,
98 .rfr_station = FMN_STNID_GMAC1_FR_0,
99 .bucket_size = xlr_board_fmn_config.bucket_size,
100 .gmac_fmn_info = &xlr_board_fmn_config.gmac[1],
103 static struct platform_device xlr_net_dev1 = {
106 .dev.platform_data = &ndata1,
109 gmac4_addr = ioremap(CPHYSADDR(
110 nlm_mmio_base(NETLOGIC_IO_GMAC_4_OFFSET)), 0xfff);
111 ndata1.serdes_addr = gmac4_addr;
112 ndata1.pcs_addr = gmac4_addr;
113 ndata1.mii_addr = gmac0_addr;
114 ndata1.gpio_addr = gpio_addr;
115 ndata1.cpu_mask = nlm_current_node()->coremask;
117 xlr_net_dev1.resource = xlr_net1_res;
119 for (mac = 0; mac < 4; mac++) {
120 ndata1.tx_stnid[mac] = FMN_STNID_GMAC1_TX0 + mac;
121 ndata1.phy_addr[mac] = mac + 4 + 0x10;
123 xlr_resource_init(&xlr_net1_res[mac * 2],
124 xlr_gmac_offsets[mac + 4],
125 xlr_gmac_irqs[mac + 4]);
127 xlr_net_dev1.num_resources = 8;
129 return &xlr_net_dev1;
132 static void xls_gmac_init(void)
135 struct platform_device *xlr_net_dev1;
136 void __iomem *gmac0_addr = ioremap(CPHYSADDR(
137 nlm_mmio_base(NETLOGIC_IO_GMAC_0_OFFSET)), 0xfff);
139 static struct xlr_net_data ndata0 = {
140 .rfr_station = FMN_STNID_GMACRFR_0,
141 .bucket_size = xlr_board_fmn_config.bucket_size,
142 .gmac_fmn_info = &xlr_board_fmn_config.gmac[0],
145 static struct platform_device xlr_net_dev0 = {
149 xlr_net_dev0.dev.platform_data = &ndata0;
150 ndata0.serdes_addr = gmac0_addr;
151 ndata0.pcs_addr = gmac0_addr;
152 ndata0.mii_addr = gmac0_addr;
154 /* Passing GPIO base for serdes init. Only needed on sgmii ports */
155 gpio_addr = ioremap(CPHYSADDR(
156 nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET)), 0xfff);
157 ndata0.gpio_addr = gpio_addr;
158 ndata0.cpu_mask = nlm_current_node()->coremask;
160 xlr_net_dev0.resource = xlr_net0_res;
162 switch (nlm_prom_info.board_major_version) {
164 /* first block RGMII or XAUI, use RGMII */
165 ndata0.phy_interface = PHY_INTERFACE_MODE_RGMII;
166 ndata0.tx_stnid[0] = FMN_STNID_GMAC0_TX0;
167 ndata0.phy_addr[0] = 0;
169 xlr_net_dev0.num_resources = 2;
171 xlr_resource_init(&xlr_net0_res[0], xlr_gmac_offsets[0],
173 platform_device_register(&xlr_net_dev0);
175 /* second block is XAUI, not supported yet */
178 /* default XLS config, all ports SGMII */
179 ndata0.phy_interface = PHY_INTERFACE_MODE_SGMII;
180 for (mac = 0; mac < 4; mac++) {
181 ndata0.tx_stnid[mac] = FMN_STNID_GMAC0_TX0 + mac;
182 ndata0.phy_addr[mac] = mac + 0x10;
184 xlr_resource_init(&xlr_net0_res[mac * 2],
185 xlr_gmac_offsets[mac],
188 xlr_net_dev0.num_resources = 8;
189 platform_device_register(&xlr_net_dev0);
191 xlr_net_dev1 = gmac_controller2_init(gmac0_addr);
192 platform_device_register(xlr_net_dev1);
196 static void xlr_gmac_init(void)
200 /* assume all GMACs for now */
201 static struct xlr_net_data ndata0 = {
202 .phy_interface = PHY_INTERFACE_MODE_RGMII,
205 .rfr_station = FMN_STNID_GMACRFR_0,
206 .bucket_size = xlr_board_fmn_config.bucket_size,
207 .gmac_fmn_info = &xlr_board_fmn_config.gmac[0],
212 static struct platform_device xlr_net_dev0 = {
215 .dev.platform_data = &ndata0,
217 ndata0.mii_addr = ioremap(CPHYSADDR(
218 nlm_mmio_base(NETLOGIC_IO_GMAC_0_OFFSET)), 0xfff);
220 ndata0.cpu_mask = nlm_current_node()->coremask;
222 for (mac = 0; mac < MAX_NUM_XLR_GMAC; mac++) {
223 ndata0.tx_stnid[mac] = FMN_STNID_GMAC0_TX0 + mac;
224 ndata0.phy_addr[mac] = mac;
225 xlr_resource_init(&xlr_net0_res[mac * 2], xlr_gmac_offsets[mac],
228 xlr_net_dev0.num_resources = 8;
229 xlr_net_dev0.resource = xlr_net0_res;
231 platform_device_register(&xlr_net_dev0);
234 static int __init xlr_net_init(void)
236 if (nlm_chip_is_xls())
244 arch_initcall(xlr_net_init);