Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 2 | /* |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 3 | * Freescale Three Speed Ethernet Controller driver |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 4 | * |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 5 | * Copyright 2004-2011, 2013 Freescale Semiconductor, Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 6 | * (C) Copyright 2003, Motorola, Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 7 | * author Andy Fleming |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 11 | #include <common.h> |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 12 | #include <dm.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 13 | #include <malloc.h> |
| 14 | #include <net.h> |
| 15 | #include <command.h> |
Andy Fleming | c067fc1 | 2008-08-31 16:33:25 -0500 | [diff] [blame] | 16 | #include <tsec.h> |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 17 | #include <fsl_mdio.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 18 | #include <linux/errno.h> |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 19 | #include <asm/processor.h> |
Alison Wang | 32cc591 | 2014-09-05 13:52:38 +0800 | [diff] [blame] | 20 | #include <asm/io.h> |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 21 | |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 22 | #ifndef CONFIG_DM_ETH |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 23 | /* Default initializations for TSEC controllers. */ |
| 24 | |
| 25 | static struct tsec_info_struct tsec_info[] = { |
| 26 | #ifdef CONFIG_TSEC1 |
| 27 | STD_TSEC_INFO(1), /* TSEC1 */ |
| 28 | #endif |
| 29 | #ifdef CONFIG_TSEC2 |
| 30 | STD_TSEC_INFO(2), /* TSEC2 */ |
| 31 | #endif |
| 32 | #ifdef CONFIG_MPC85XX_FEC |
| 33 | { |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 34 | .regs = TSEC_GET_REGS(2, 0x2000), |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 35 | .devname = CONFIG_MPC85XX_FEC_NAME, |
| 36 | .phyaddr = FEC_PHY_ADDR, |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 37 | .flags = FEC_FLAGS, |
| 38 | .mii_devname = DEFAULT_MII_NAME |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 39 | }, /* FEC */ |
| 40 | #endif |
| 41 | #ifdef CONFIG_TSEC3 |
| 42 | STD_TSEC_INFO(3), /* TSEC3 */ |
| 43 | #endif |
| 44 | #ifdef CONFIG_TSEC4 |
| 45 | STD_TSEC_INFO(4), /* TSEC4 */ |
| 46 | #endif |
| 47 | }; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 48 | #endif /* CONFIG_DM_ETH */ |
Andy Fleming | fecff2b | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 49 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 50 | #define TBIANA_SETTINGS ( \ |
| 51 | TBIANA_ASYMMETRIC_PAUSE \ |
| 52 | | TBIANA_SYMMETRIC_PAUSE \ |
| 53 | | TBIANA_FULL_DUPLEX \ |
| 54 | ) |
| 55 | |
Felix Radensky | 27f98e0 | 2010-06-28 01:57:39 +0300 | [diff] [blame] | 56 | /* By default force the TBI PHY into 1000Mbps full duplex when in SGMII mode */ |
| 57 | #ifndef CONFIG_TSEC_TBICR_SETTINGS |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 58 | #define CONFIG_TSEC_TBICR_SETTINGS ( \ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 59 | TBICR_PHY_RESET \ |
Kumar Gala | c1457f9 | 2010-12-01 22:55:54 -0600 | [diff] [blame] | 60 | | TBICR_ANEG_ENABLE \ |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 61 | | TBICR_FULL_DUPLEX \ |
| 62 | | TBICR_SPEED1_SET \ |
| 63 | ) |
Felix Radensky | 27f98e0 | 2010-06-28 01:57:39 +0300 | [diff] [blame] | 64 | #endif /* CONFIG_TSEC_TBICR_SETTINGS */ |
Peter Tyser | 583c1f4 | 2009-11-03 17:52:07 -0600 | [diff] [blame] | 65 | |
Andy Fleming | ac65e07 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 66 | /* Configure the TBI for SGMII operation */ |
| 67 | static void tsec_configure_serdes(struct tsec_private *priv) |
| 68 | { |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 69 | /* |
| 70 | * Access TBI PHY registers at given TSEC register offset as opposed |
| 71 | * to the register offset used for external PHY accesses |
| 72 | */ |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 73 | tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 74 | 0, TBI_ANA, TBIANA_SETTINGS); |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 75 | tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 76 | 0, TBI_TBICON, TBICON_CLK_SELECT); |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 77 | tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa), |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 78 | 0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS); |
David Updegraff | 0451b01 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Chris Packham | bbe1857 | 2018-11-26 21:00:28 +1300 | [diff] [blame] | 81 | /* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c |
| 82 | * and this is the ethernet-crc method needed for TSEC -- and perhaps |
| 83 | * some other adapter -- hash tables |
| 84 | */ |
| 85 | #define CRCPOLY_LE 0xedb88320 |
| 86 | static u32 ether_crc(size_t len, unsigned char const *p) |
| 87 | { |
| 88 | int i; |
| 89 | u32 crc; |
| 90 | |
| 91 | crc = ~0; |
| 92 | while (len--) { |
| 93 | crc ^= *p++; |
| 94 | for (i = 0; i < 8; i++) |
| 95 | crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); |
| 96 | } |
| 97 | /* an reverse the bits, cuz of way they arrive -- last-first */ |
| 98 | crc = (crc >> 16) | (crc << 16); |
| 99 | crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00); |
| 100 | crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0); |
| 101 | crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc); |
| 102 | crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa); |
| 103 | return crc; |
| 104 | } |
| 105 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 106 | /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */ |
| 107 | |
| 108 | /* Set the appropriate hash bit for the given addr */ |
| 109 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 110 | /* |
| 111 | * The algorithm works like so: |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 112 | * 1) Take the Destination Address (ie the multicast address), and |
| 113 | * do a CRC on it (little endian), and reverse the bits of the |
| 114 | * result. |
| 115 | * 2) Use the 8 most significant bits as a hash into a 256-entry |
| 116 | * table. The table is controlled through 8 32-bit registers: |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 117 | * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is entry |
| 118 | * 255. This means that the 3 most significant bits in the |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 119 | * hash index which gaddr register to use, and the 5 other bits |
| 120 | * indicate which bit (assuming an IBM numbering scheme, which |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 121 | * for PowerPC (tm) is usually the case) in the register holds |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 122 | * the entry. |
| 123 | */ |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 124 | #ifndef CONFIG_DM_ETH |
Chris Packham | a55ef7f | 2018-11-26 21:00:29 +1300 | [diff] [blame] | 125 | static int tsec_mcast_addr(struct eth_device *dev, const u8 *mcast_mac, |
| 126 | int join) |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 127 | #else |
Chris Packham | a55ef7f | 2018-11-26 21:00:29 +1300 | [diff] [blame] | 128 | static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join) |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 129 | #endif |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 130 | { |
Claudiu Manoil | 766c894 | 2013-09-30 12:44:41 +0300 | [diff] [blame] | 131 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 132 | struct tsec __iomem *regs = priv->regs; |
| 133 | u32 result, value; |
| 134 | u8 whichbit, whichreg; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 135 | |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 136 | result = ether_crc(MAC_ADDR_LEN, mcast_mac); |
| 137 | whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */ |
| 138 | whichreg = result >> 29; /* the 3 MSB = which reg to set it in */ |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 139 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 140 | value = BIT(31 - whichbit); |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 141 | |
Chris Packham | a55ef7f | 2018-11-26 21:00:29 +1300 | [diff] [blame] | 142 | if (join) |
Claudiu Manoil | 461511b | 2013-09-30 12:44:40 +0300 | [diff] [blame] | 143 | setbits_be32(®s->hash.gaddr0 + whichreg, value); |
| 144 | else |
| 145 | clrbits_be32(®s->hash.gaddr0 + whichreg, value); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 146 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 147 | return 0; |
| 148 | } |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 149 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 150 | /* |
| 151 | * Initialized required registers to appropriate values, zeroing |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 152 | * those we don't care about (unless zero is bad, in which case, |
| 153 | * choose a more appropriate value) |
| 154 | */ |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 155 | static void init_registers(struct tsec __iomem *regs) |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 156 | { |
| 157 | /* Clear IEVENT */ |
| 158 | out_be32(®s->ievent, IEVENT_INIT_CLEAR); |
| 159 | |
| 160 | out_be32(®s->imask, IMASK_INIT_CLEAR); |
| 161 | |
| 162 | out_be32(®s->hash.iaddr0, 0); |
| 163 | out_be32(®s->hash.iaddr1, 0); |
| 164 | out_be32(®s->hash.iaddr2, 0); |
| 165 | out_be32(®s->hash.iaddr3, 0); |
| 166 | out_be32(®s->hash.iaddr4, 0); |
| 167 | out_be32(®s->hash.iaddr5, 0); |
| 168 | out_be32(®s->hash.iaddr6, 0); |
| 169 | out_be32(®s->hash.iaddr7, 0); |
| 170 | |
| 171 | out_be32(®s->hash.gaddr0, 0); |
| 172 | out_be32(®s->hash.gaddr1, 0); |
| 173 | out_be32(®s->hash.gaddr2, 0); |
| 174 | out_be32(®s->hash.gaddr3, 0); |
| 175 | out_be32(®s->hash.gaddr4, 0); |
| 176 | out_be32(®s->hash.gaddr5, 0); |
| 177 | out_be32(®s->hash.gaddr6, 0); |
| 178 | out_be32(®s->hash.gaddr7, 0); |
| 179 | |
| 180 | out_be32(®s->rctrl, 0x00000000); |
| 181 | |
| 182 | /* Init RMON mib registers */ |
Claudiu Manoil | a18ab90 | 2013-09-30 12:44:46 +0300 | [diff] [blame] | 183 | memset((void *)®s->rmon, 0, sizeof(regs->rmon)); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 184 | |
| 185 | out_be32(®s->rmon.cam1, 0xffffffff); |
| 186 | out_be32(®s->rmon.cam2, 0xffffffff); |
| 187 | |
| 188 | out_be32(®s->mrblr, MRBLR_INIT_SETTINGS); |
| 189 | |
| 190 | out_be32(®s->minflr, MINFLR_INIT_SETTINGS); |
| 191 | |
| 192 | out_be32(®s->attr, ATTR_INIT_SETTINGS); |
| 193 | out_be32(®s->attreli, ATTRELI_INIT_SETTINGS); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 194 | } |
| 195 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 196 | /* |
| 197 | * Configure maccfg2 based on negotiated speed and duplex |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 198 | * reported by PHY handling code |
| 199 | */ |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 200 | static void adjust_link(struct tsec_private *priv, struct phy_device *phydev) |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 201 | { |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 202 | struct tsec __iomem *regs = priv->regs; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 203 | u32 ecntrl, maccfg2; |
| 204 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 205 | if (!phydev->link) { |
| 206 | printf("%s: No link.\n", phydev->dev->name); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | |
| 210 | /* clear all bits relative with interface mode */ |
| 211 | ecntrl = in_be32(®s->ecntrl); |
| 212 | ecntrl &= ~ECNTRL_R100; |
| 213 | |
| 214 | maccfg2 = in_be32(®s->maccfg2); |
| 215 | maccfg2 &= ~(MACCFG2_IF | MACCFG2_FULL_DUPLEX); |
| 216 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 217 | if (phydev->duplex) |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 218 | maccfg2 |= MACCFG2_FULL_DUPLEX; |
| 219 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 220 | switch (phydev->speed) { |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 221 | case 1000: |
| 222 | maccfg2 |= MACCFG2_GMII; |
| 223 | break; |
| 224 | case 100: |
| 225 | case 10: |
| 226 | maccfg2 |= MACCFG2_MII; |
| 227 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 228 | /* |
| 229 | * Set R100 bit in all modes although |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 230 | * it is only used in RGMII mode |
| 231 | */ |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 232 | if (phydev->speed == 100) |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 233 | ecntrl |= ECNTRL_R100; |
| 234 | break; |
| 235 | default: |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 236 | printf("%s: Speed was bad\n", phydev->dev->name); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | |
| 240 | out_be32(®s->ecntrl, ecntrl); |
| 241 | out_be32(®s->maccfg2, maccfg2); |
wdenk | f41ff3b | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 242 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 243 | printf("Speed: %d, %s duplex%s\n", phydev->speed, |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 244 | (phydev->duplex) ? "full" : "half", |
| 245 | (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 246 | } |
wdenk | bfad55d | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 247 | |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 248 | /* |
| 249 | * This returns the status bits of the device. The return value |
| 250 | * is never checked, and this is what the 8260 driver did, so we |
| 251 | * do the same. Presumably, this would be zero if there were no |
| 252 | * errors |
| 253 | */ |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 254 | #ifndef CONFIG_DM_ETH |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 255 | static int tsec_send(struct eth_device *dev, void *packet, int length) |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 256 | #else |
| 257 | static int tsec_send(struct udevice *dev, void *packet, int length) |
| 258 | #endif |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 259 | { |
| 260 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 261 | struct tsec __iomem *regs = priv->regs; |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 262 | u16 status; |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 263 | int result = 0; |
| 264 | int i; |
| 265 | |
| 266 | /* Find an empty buffer descriptor */ |
| 267 | for (i = 0; |
| 268 | in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY; |
| 269 | i++) { |
| 270 | if (i >= TOUT_LOOP) { |
| 271 | debug("%s: tsec: tx buffers full\n", dev->name); |
| 272 | return result; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | out_be32(&priv->txbd[priv->tx_idx].bufptr, (u32)packet); |
| 277 | out_be16(&priv->txbd[priv->tx_idx].length, length); |
| 278 | status = in_be16(&priv->txbd[priv->tx_idx].status); |
| 279 | out_be16(&priv->txbd[priv->tx_idx].status, status | |
| 280 | (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT)); |
| 281 | |
| 282 | /* Tell the DMA to go */ |
| 283 | out_be32(®s->tstat, TSTAT_CLEAR_THALT); |
| 284 | |
| 285 | /* Wait for buffer to be transmitted */ |
| 286 | for (i = 0; |
| 287 | in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY; |
| 288 | i++) { |
| 289 | if (i >= TOUT_LOOP) { |
| 290 | debug("%s: tsec: tx error\n", dev->name); |
| 291 | return result; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | priv->tx_idx = (priv->tx_idx + 1) % TX_BUF_CNT; |
| 296 | result = in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_STATS; |
| 297 | |
| 298 | return result; |
| 299 | } |
| 300 | |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 301 | #ifndef CONFIG_DM_ETH |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 302 | static int tsec_recv(struct eth_device *dev) |
| 303 | { |
| 304 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 305 | struct tsec __iomem *regs = priv->regs; |
| 306 | |
| 307 | while (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) { |
| 308 | int length = in_be16(&priv->rxbd[priv->rx_idx].length); |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 309 | u16 status = in_be16(&priv->rxbd[priv->rx_idx].status); |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 310 | uchar *packet = net_rx_packets[priv->rx_idx]; |
| 311 | |
| 312 | /* Send the packet up if there were no errors */ |
| 313 | if (!(status & RXBD_STATS)) |
| 314 | net_process_received_packet(packet, length - 4); |
| 315 | else |
| 316 | printf("Got error %x\n", (status & RXBD_STATS)); |
| 317 | |
| 318 | out_be16(&priv->rxbd[priv->rx_idx].length, 0); |
| 319 | |
| 320 | status = RXBD_EMPTY; |
| 321 | /* Set the wrap bit if this is the last element in the list */ |
| 322 | if ((priv->rx_idx + 1) == PKTBUFSRX) |
| 323 | status |= RXBD_WRAP; |
| 324 | out_be16(&priv->rxbd[priv->rx_idx].status, status); |
| 325 | |
| 326 | priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX; |
| 327 | } |
| 328 | |
| 329 | if (in_be32(®s->ievent) & IEVENT_BSY) { |
| 330 | out_be32(®s->ievent, IEVENT_BSY); |
| 331 | out_be32(®s->rstat, RSTAT_CLEAR_RHALT); |
| 332 | } |
| 333 | |
| 334 | return -1; |
| 335 | } |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 336 | #else |
| 337 | static int tsec_recv(struct udevice *dev, int flags, uchar **packetp) |
| 338 | { |
| 339 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 340 | struct tsec __iomem *regs = priv->regs; |
| 341 | int ret = -1; |
| 342 | |
| 343 | if (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) { |
| 344 | int length = in_be16(&priv->rxbd[priv->rx_idx].length); |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 345 | u16 status = in_be16(&priv->rxbd[priv->rx_idx].status); |
| 346 | u32 buf; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 347 | |
| 348 | /* Send the packet up if there were no errors */ |
| 349 | if (!(status & RXBD_STATS)) { |
| 350 | buf = in_be32(&priv->rxbd[priv->rx_idx].bufptr); |
| 351 | *packetp = (uchar *)buf; |
| 352 | ret = length - 4; |
| 353 | } else { |
| 354 | printf("Got error %x\n", (status & RXBD_STATS)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | if (in_be32(®s->ievent) & IEVENT_BSY) { |
| 359 | out_be32(®s->ievent, IEVENT_BSY); |
| 360 | out_be32(®s->rstat, RSTAT_CLEAR_RHALT); |
| 361 | } |
| 362 | |
| 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 367 | { |
| 368 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 369 | u16 status; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 370 | |
| 371 | out_be16(&priv->rxbd[priv->rx_idx].length, 0); |
| 372 | |
| 373 | status = RXBD_EMPTY; |
| 374 | /* Set the wrap bit if this is the last element in the list */ |
| 375 | if ((priv->rx_idx + 1) == PKTBUFSRX) |
| 376 | status |= RXBD_WRAP; |
| 377 | out_be16(&priv->rxbd[priv->rx_idx].status, status); |
| 378 | |
| 379 | priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX; |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | #endif |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 384 | |
| 385 | /* Stop the interface */ |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 386 | #ifndef CONFIG_DM_ETH |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 387 | static void tsec_halt(struct eth_device *dev) |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 388 | #else |
| 389 | static void tsec_halt(struct udevice *dev) |
| 390 | #endif |
Bin Meng | 80b1a1c | 2016-01-11 22:41:21 -0800 | [diff] [blame] | 391 | { |
| 392 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 393 | struct tsec __iomem *regs = priv->regs; |
| 394 | |
| 395 | clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); |
| 396 | setbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); |
| 397 | |
| 398 | while ((in_be32(®s->ievent) & (IEVENT_GRSC | IEVENT_GTSC)) |
| 399 | != (IEVENT_GRSC | IEVENT_GTSC)) |
| 400 | ; |
| 401 | |
| 402 | clrbits_be32(®s->maccfg1, MACCFG1_TX_EN | MACCFG1_RX_EN); |
| 403 | |
| 404 | /* Shut down the PHY, as needed */ |
| 405 | phy_shutdown(priv->phydev); |
| 406 | } |
| 407 | |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 408 | #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129 |
| 409 | /* |
| 410 | * When MACCFG1[Rx_EN] is enabled during system boot as part |
| 411 | * of the eTSEC port initialization sequence, |
| 412 | * the eTSEC Rx logic may not be properly initialized. |
| 413 | */ |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 414 | void redundant_init(struct tsec_private *priv) |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 415 | { |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 416 | struct tsec __iomem *regs = priv->regs; |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 417 | uint t, count = 0; |
| 418 | int fail = 1; |
| 419 | static const u8 pkt[] = { |
| 420 | 0x00, 0x1e, 0x4f, 0x12, 0xcb, 0x2c, 0x00, 0x25, |
| 421 | 0x64, 0xbb, 0xd1, 0xab, 0x08, 0x00, 0x45, 0x00, |
| 422 | 0x00, 0x5c, 0xdd, 0x22, 0x00, 0x00, 0x80, 0x01, |
| 423 | 0x1f, 0x71, 0x0a, 0xc1, 0x14, 0x22, 0x0a, 0xc1, |
| 424 | 0x14, 0x6a, 0x08, 0x00, 0xef, 0x7e, 0x02, 0x00, |
| 425 | 0x94, 0x05, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, |
| 426 | 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, |
| 427 | 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, |
| 428 | 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 429 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
| 430 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, |
| 431 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
| 432 | 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, |
| 433 | 0x71, 0x72}; |
| 434 | |
| 435 | /* Enable promiscuous mode */ |
| 436 | setbits_be32(®s->rctrl, 0x8); |
| 437 | /* Enable loopback mode */ |
| 438 | setbits_be32(®s->maccfg1, MACCFG1_LOOPBACK); |
| 439 | /* Enable transmit and receive */ |
| 440 | setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 441 | |
| 442 | /* Tell the DMA it is clear to go */ |
| 443 | setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS); |
| 444 | out_be32(®s->tstat, TSTAT_CLEAR_THALT); |
| 445 | out_be32(®s->rstat, RSTAT_CLEAR_RHALT); |
| 446 | clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); |
| 447 | |
| 448 | do { |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 449 | u16 status; |
| 450 | |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 451 | tsec_send(priv->dev, (void *)pkt, sizeof(pkt)); |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 452 | |
| 453 | /* Wait for buffer to be received */ |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 454 | for (t = 0; |
| 455 | in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY; |
Bin Meng | 76f5399 | 2016-01-11 22:41:19 -0800 | [diff] [blame] | 456 | t++) { |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 457 | if (t >= 10 * TOUT_LOOP) { |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 458 | printf("%s: tsec: rx error\n", priv->dev->name); |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 459 | break; |
| 460 | } |
| 461 | } |
| 462 | |
Bin Meng | 76f5399 | 2016-01-11 22:41:19 -0800 | [diff] [blame] | 463 | if (!memcmp(pkt, net_rx_packets[priv->rx_idx], sizeof(pkt))) |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 464 | fail = 0; |
| 465 | |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 466 | out_be16(&priv->rxbd[priv->rx_idx].length, 0); |
Claudiu Manoil | eec416b | 2013-10-04 19:13:53 +0300 | [diff] [blame] | 467 | status = RXBD_EMPTY; |
Bin Meng | 76f5399 | 2016-01-11 22:41:19 -0800 | [diff] [blame] | 468 | if ((priv->rx_idx + 1) == PKTBUFSRX) |
Claudiu Manoil | eec416b | 2013-10-04 19:13:53 +0300 | [diff] [blame] | 469 | status |= RXBD_WRAP; |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 470 | out_be16(&priv->rxbd[priv->rx_idx].status, status); |
Bin Meng | 76f5399 | 2016-01-11 22:41:19 -0800 | [diff] [blame] | 471 | priv->rx_idx = (priv->rx_idx + 1) % PKTBUFSRX; |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 472 | |
| 473 | if (in_be32(®s->ievent) & IEVENT_BSY) { |
| 474 | out_be32(®s->ievent, IEVENT_BSY); |
| 475 | out_be32(®s->rstat, RSTAT_CLEAR_RHALT); |
| 476 | } |
| 477 | if (fail) { |
| 478 | printf("loopback recv packet error!\n"); |
| 479 | clrbits_be32(®s->maccfg1, MACCFG1_RX_EN); |
| 480 | udelay(1000); |
| 481 | setbits_be32(®s->maccfg1, MACCFG1_RX_EN); |
| 482 | } |
| 483 | } while ((count++ < 4) && (fail == 1)); |
| 484 | |
| 485 | if (fail) |
| 486 | panic("eTSEC init fail!\n"); |
| 487 | /* Disable promiscuous mode */ |
| 488 | clrbits_be32(®s->rctrl, 0x8); |
| 489 | /* Disable loopback mode */ |
| 490 | clrbits_be32(®s->maccfg1, MACCFG1_LOOPBACK); |
| 491 | } |
| 492 | #endif |
| 493 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 494 | /* |
| 495 | * Set up the buffers and their descriptors, and bring up the |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 496 | * interface |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 497 | */ |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 498 | static void startup_tsec(struct tsec_private *priv) |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 499 | { |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 500 | struct tsec __iomem *regs = priv->regs; |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 501 | u16 status; |
Claudiu Manoil | eec416b | 2013-10-04 19:13:53 +0300 | [diff] [blame] | 502 | int i; |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 503 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 504 | /* reset the indices to zero */ |
Bin Meng | 76f5399 | 2016-01-11 22:41:19 -0800 | [diff] [blame] | 505 | priv->rx_idx = 0; |
| 506 | priv->tx_idx = 0; |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 507 | #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129 |
| 508 | uint svr; |
| 509 | #endif |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 510 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 511 | /* Point to the buffer descriptors */ |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 512 | out_be32(®s->tbase, (u32)&priv->txbd[0]); |
| 513 | out_be32(®s->rbase, (u32)&priv->rxbd[0]); |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 514 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 515 | /* Initialize the Rx Buffer descriptors */ |
| 516 | for (i = 0; i < PKTBUFSRX; i++) { |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 517 | out_be16(&priv->rxbd[i].status, RXBD_EMPTY); |
| 518 | out_be16(&priv->rxbd[i].length, 0); |
| 519 | out_be32(&priv->rxbd[i].bufptr, (u32)net_rx_packets[i]); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 520 | } |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 521 | status = in_be16(&priv->rxbd[PKTBUFSRX - 1].status); |
| 522 | out_be16(&priv->rxbd[PKTBUFSRX - 1].status, status | RXBD_WRAP); |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 523 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 524 | /* Initialize the TX Buffer Descriptors */ |
| 525 | for (i = 0; i < TX_BUF_CNT; i++) { |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 526 | out_be16(&priv->txbd[i].status, 0); |
| 527 | out_be16(&priv->txbd[i].length, 0); |
| 528 | out_be32(&priv->txbd[i].bufptr, 0); |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 529 | } |
Bin Meng | 1120c54 | 2016-01-11 22:41:20 -0800 | [diff] [blame] | 530 | status = in_be16(&priv->txbd[TX_BUF_CNT - 1].status); |
| 531 | out_be16(&priv->txbd[TX_BUF_CNT - 1].status, status | TXBD_WRAP); |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 532 | |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 533 | #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_ETSEC129 |
| 534 | svr = get_svr(); |
| 535 | if ((SVR_MAJ(svr) == 1) || IS_SVR_REV(svr, 2, 0)) |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 536 | redundant_init(priv); |
chenhui zhao | c8caa8a | 2011-10-03 08:38:50 -0500 | [diff] [blame] | 537 | #endif |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 538 | /* Enable Transmit and Receive */ |
| 539 | setbits_be32(®s->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 540 | |
| 541 | /* Tell the DMA it is clear to go */ |
| 542 | setbits_be32(®s->dmactrl, DMACTRL_INIT_SETTINGS); |
| 543 | out_be32(®s->tstat, TSTAT_CLEAR_THALT); |
| 544 | out_be32(®s->rstat, RSTAT_CLEAR_RHALT); |
| 545 | clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); |
Wolfgang Denk | f0c4e46 | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 548 | /* |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 549 | * Initializes data structures and registers for the controller, |
| 550 | * and brings the interface up. Returns the link status, meaning |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 551 | * that it returns success if the link is up, failure otherwise. |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 552 | * This allows U-Boot to find the first active controller. |
Jon Loeliger | b7ced08 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 553 | */ |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 554 | #ifndef CONFIG_DM_ETH |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 555 | static int tsec_init(struct eth_device *dev, bd_t *bd) |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 556 | #else |
| 557 | static int tsec_init(struct udevice *dev) |
| 558 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 559 | { |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 560 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 561 | #ifdef CONFIG_DM_ETH |
| 562 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 563 | #endif |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 564 | struct tsec __iomem *regs = priv->regs; |
Claudiu Manoil | dcb38fe | 2013-09-30 12:44:47 +0300 | [diff] [blame] | 565 | u32 tempval; |
Timur Tabi | 4238746 | 2012-07-09 08:52:43 +0000 | [diff] [blame] | 566 | int ret; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 567 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 568 | /* Make sure the controller is stopped */ |
| 569 | tsec_halt(dev); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 570 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 571 | /* Init MACCFG2. Defaults to GMII */ |
| 572 | out_be32(®s->maccfg2, MACCFG2_INIT_SETTINGS); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 573 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 574 | /* Init ECNTRL */ |
| 575 | out_be32(®s->ecntrl, ECNTRL_INIT_SETTINGS); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 576 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 577 | /* |
| 578 | * Copy the station address into the address registers. |
Claudiu Manoil | dcb38fe | 2013-09-30 12:44:47 +0300 | [diff] [blame] | 579 | * For a station address of 0x12345678ABCD in transmission |
| 580 | * order (BE), MACnADDR1 is set to 0xCDAB7856 and |
| 581 | * MACnADDR2 is set to 0x34120000. |
| 582 | */ |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 583 | #ifndef CONFIG_DM_ETH |
Claudiu Manoil | dcb38fe | 2013-09-30 12:44:47 +0300 | [diff] [blame] | 584 | tempval = (dev->enetaddr[5] << 24) | (dev->enetaddr[4] << 16) | |
| 585 | (dev->enetaddr[3] << 8) | dev->enetaddr[2]; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 586 | #else |
| 587 | tempval = (pdata->enetaddr[5] << 24) | (pdata->enetaddr[4] << 16) | |
| 588 | (pdata->enetaddr[3] << 8) | pdata->enetaddr[2]; |
| 589 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 590 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 591 | out_be32(®s->macstnaddr1, tempval); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 592 | |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 593 | #ifndef CONFIG_DM_ETH |
Claudiu Manoil | dcb38fe | 2013-09-30 12:44:47 +0300 | [diff] [blame] | 594 | tempval = (dev->enetaddr[1] << 24) | (dev->enetaddr[0] << 16); |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 595 | #else |
| 596 | tempval = (pdata->enetaddr[1] << 24) | (pdata->enetaddr[0] << 16); |
| 597 | #endif |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 598 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 599 | out_be32(®s->macstnaddr2, tempval); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 600 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 601 | /* Clear out (for the most part) the other registers */ |
| 602 | init_registers(regs); |
| 603 | |
| 604 | /* Ready the device for tx/rx */ |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 605 | startup_tsec(priv); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 606 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 607 | /* Start up the PHY */ |
Timur Tabi | 4238746 | 2012-07-09 08:52:43 +0000 | [diff] [blame] | 608 | ret = phy_startup(priv->phydev); |
| 609 | if (ret) { |
| 610 | printf("Could not initialize PHY %s\n", |
| 611 | priv->phydev->dev->name); |
| 612 | return ret; |
| 613 | } |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 614 | |
| 615 | adjust_link(priv, priv->phydev); |
| 616 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 617 | /* If there's no link, fail */ |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 618 | return priv->phydev->link ? 0 : -1; |
| 619 | } |
| 620 | |
| 621 | static phy_interface_t tsec_get_interface(struct tsec_private *priv) |
| 622 | { |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 623 | struct tsec __iomem *regs = priv->regs; |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 624 | u32 ecntrl; |
| 625 | |
| 626 | ecntrl = in_be32(®s->ecntrl); |
| 627 | |
| 628 | if (ecntrl & ECNTRL_SGMII_MODE) |
| 629 | return PHY_INTERFACE_MODE_SGMII; |
| 630 | |
| 631 | if (ecntrl & ECNTRL_TBI_MODE) { |
| 632 | if (ecntrl & ECNTRL_REDUCED_MODE) |
| 633 | return PHY_INTERFACE_MODE_RTBI; |
| 634 | else |
| 635 | return PHY_INTERFACE_MODE_TBI; |
| 636 | } |
| 637 | |
| 638 | if (ecntrl & ECNTRL_REDUCED_MODE) { |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 639 | phy_interface_t interface; |
| 640 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 641 | if (ecntrl & ECNTRL_REDUCED_MII_MODE) |
| 642 | return PHY_INTERFACE_MODE_RMII; |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 643 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 644 | interface = priv->interface; |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 645 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 646 | /* |
| 647 | * This isn't autodetected, so it must |
| 648 | * be set by the platform code. |
| 649 | */ |
| 650 | if (interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 651 | interface == PHY_INTERFACE_MODE_RGMII_TXID || |
| 652 | interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 653 | return interface; |
| 654 | |
| 655 | return PHY_INTERFACE_MODE_RGMII; |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (priv->flags & TSEC_GIGABIT) |
| 659 | return PHY_INTERFACE_MODE_GMII; |
| 660 | |
| 661 | return PHY_INTERFACE_MODE_MII; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 662 | } |
| 663 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 664 | /* |
| 665 | * Discover which PHY is attached to the device, and configure it |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 666 | * properly. If the PHY is not recognized, then return 0 |
| 667 | * (failure). Otherwise, return 1 |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 668 | */ |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 669 | static int init_phy(struct tsec_private *priv) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 670 | { |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 671 | struct phy_device *phydev; |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 672 | struct tsec __iomem *regs = priv->regs; |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 673 | u32 supported = (SUPPORTED_10baseT_Half | |
| 674 | SUPPORTED_10baseT_Full | |
| 675 | SUPPORTED_100baseT_Half | |
| 676 | SUPPORTED_100baseT_Full); |
| 677 | |
| 678 | if (priv->flags & TSEC_GIGABIT) |
| 679 | supported |= SUPPORTED_1000baseT_Full; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 680 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 681 | /* Assign a Physical address to the TBI */ |
Bin Meng | 74314f1 | 2016-01-11 22:41:25 -0800 | [diff] [blame] | 682 | out_be32(®s->tbipa, priv->tbiaddr); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 683 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 684 | priv->interface = tsec_get_interface(priv); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 685 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 686 | if (priv->interface == PHY_INTERFACE_MODE_SGMII) |
| 687 | tsec_configure_serdes(priv); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 688 | |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 689 | phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev, |
| 690 | priv->interface); |
Claudiu Manoil | fe56fec | 2013-12-10 15:21:04 +0200 | [diff] [blame] | 691 | if (!phydev) |
| 692 | return 0; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 693 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 694 | phydev->supported &= supported; |
| 695 | phydev->advertising = phydev->supported; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 696 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 697 | priv->phydev = phydev; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 698 | |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 699 | phy_config(phydev); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 700 | |
| 701 | return 1; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 704 | #ifndef CONFIG_DM_ETH |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 705 | /* |
| 706 | * Initialize device structure. Returns success if PHY |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 707 | * initialization succeeded (i.e. if it recognizes the PHY) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 708 | */ |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 709 | static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info) |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 710 | { |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 711 | struct eth_device *dev; |
| 712 | int i; |
| 713 | struct tsec_private *priv; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 714 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 715 | dev = (struct eth_device *)malloc(sizeof(*dev)); |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 716 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 717 | if (!dev) |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 718 | return 0; |
wdenk | 78924a7 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 719 | |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 720 | memset(dev, 0, sizeof(*dev)); |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 721 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 722 | priv = (struct tsec_private *)malloc(sizeof(*priv)); |
| 723 | |
Mario Six | 878b1d2 | 2018-01-15 11:08:22 +0100 | [diff] [blame] | 724 | if (!priv) { |
| 725 | free(dev); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 726 | return 0; |
Mario Six | 878b1d2 | 2018-01-15 11:08:22 +0100 | [diff] [blame] | 727 | } |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 728 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 729 | priv->regs = tsec_info->regs; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 730 | priv->phyregs_sgmii = tsec_info->miiregs_sgmii; |
| 731 | |
| 732 | priv->phyaddr = tsec_info->phyaddr; |
Bin Meng | 74314f1 | 2016-01-11 22:41:25 -0800 | [diff] [blame] | 733 | priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 734 | priv->flags = tsec_info->flags; |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 735 | |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 736 | strcpy(dev->name, tsec_info->devname); |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 737 | priv->interface = tsec_info->interface; |
| 738 | priv->bus = miiphy_get_dev_by_name(tsec_info->mii_devname); |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 739 | priv->dev = dev; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 740 | dev->iobase = 0; |
| 741 | dev->priv = priv; |
| 742 | dev->init = tsec_init; |
| 743 | dev->halt = tsec_halt; |
| 744 | dev->send = tsec_send; |
| 745 | dev->recv = tsec_recv; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 746 | dev->mcast = tsec_mcast_addr; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 747 | |
Bin Meng | 79cd33a | 2016-01-11 22:41:18 -0800 | [diff] [blame] | 748 | /* Tell U-Boot to get the addr from the env */ |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 749 | for (i = 0; i < 6; i++) |
| 750 | dev->enetaddr[i] = 0; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 751 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 752 | eth_register(dev); |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 753 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 754 | /* Reset the MAC */ |
| 755 | setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET); |
| 756 | udelay(2); /* Soft Reset must be asserted for 3 TX clocks */ |
| 757 | clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET); |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 758 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 759 | /* Try to initialize PHY here, and return */ |
Bin Meng | e86a6cd | 2016-01-11 22:41:22 -0800 | [diff] [blame] | 760 | return init_phy(priv); |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 761 | } |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 762 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 763 | /* |
| 764 | * Initialize all the TSEC devices |
| 765 | * |
| 766 | * Returns the number of TSEC devices that were initialized |
| 767 | */ |
| 768 | int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num) |
| 769 | { |
| 770 | int i; |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 771 | int count = 0; |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 772 | |
| 773 | for (i = 0; i < num; i++) { |
Mario Six | c29fcc7 | 2018-01-15 11:08:21 +0100 | [diff] [blame] | 774 | int ret = tsec_initialize(bis, &tsecs[i]); |
| 775 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 776 | if (ret > 0) |
| 777 | count += ret; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 778 | } |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 779 | |
| 780 | return count; |
David Updegraff | 7280da7 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 781 | } |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 782 | |
| 783 | int tsec_standard_init(bd_t *bis) |
| 784 | { |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 785 | struct fsl_pq_mdio_info info; |
| 786 | |
Claudiu Manoil | cd0c412 | 2013-09-30 12:44:42 +0300 | [diff] [blame] | 787 | info.regs = TSEC_GET_MDIO_REGS_BASE(1); |
Andy Fleming | 422effd | 2011-04-08 02:10:54 -0500 | [diff] [blame] | 788 | info.name = DEFAULT_MII_NAME; |
| 789 | |
| 790 | fsl_pq_mdio_init(bis, &info); |
| 791 | |
Mingkai Hu | e0653bf | 2011-01-27 12:52:46 +0800 | [diff] [blame] | 792 | return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info)); |
| 793 | } |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 794 | #else /* CONFIG_DM_ETH */ |
| 795 | int tsec_probe(struct udevice *dev) |
| 796 | { |
| 797 | struct tsec_private *priv = dev_get_priv(dev); |
| 798 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 799 | struct fsl_pq_mdio_info mdio_info; |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 800 | struct ofnode_phandle_args phandle_args; |
| 801 | ofnode parent; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 802 | const char *phy_mode; |
| 803 | int ret; |
| 804 | |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 805 | pdata->iobase = (phys_addr_t)dev_read_addr(dev); |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 806 | priv->regs = (struct tsec *)pdata->iobase; |
| 807 | |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 808 | if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, |
| 809 | &phandle_args)) { |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 810 | debug("phy-handle does not exist under tsec %s\n", dev->name); |
| 811 | return -ENOENT; |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 812 | } else { |
| 813 | int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); |
| 814 | |
| 815 | priv->phyaddr = reg; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 816 | } |
| 817 | |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 818 | parent = ofnode_get_parent(phandle_args.node); |
| 819 | if (ofnode_valid(parent)) { |
Mario Six | 0ccad96 | 2018-04-27 14:52:57 +0200 | [diff] [blame] | 820 | int reg = ofnode_get_addr_index(parent, 0); |
| 821 | |
| 822 | priv->phyregs_sgmii = (struct tsec_mii_mng *)reg; |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 823 | } else { |
| 824 | debug("No parent node for PHY?\n"); |
| 825 | return -ENOENT; |
| 826 | } |
| 827 | |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 828 | if (dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0, |
| 829 | &phandle_args)) { |
Bin Meng | 74314f1 | 2016-01-11 22:41:25 -0800 | [diff] [blame] | 830 | priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE; |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 831 | } else { |
| 832 | int reg = ofnode_read_u32_default(phandle_args.node, "reg", |
| 833 | CONFIG_SYS_TBIPA_VALUE); |
| 834 | priv->tbiaddr = reg; |
Bin Meng | 74314f1 | 2016-01-11 22:41:25 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Mario Six | 00ba055 | 2018-01-15 11:08:23 +0100 | [diff] [blame] | 837 | phy_mode = dev_read_prop(dev, "phy-connection-type", NULL); |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 838 | if (phy_mode) |
| 839 | pdata->phy_interface = phy_get_interface_by_name(phy_mode); |
| 840 | if (pdata->phy_interface == -1) { |
| 841 | debug("Invalid PHY interface '%s'\n", phy_mode); |
| 842 | return -EINVAL; |
| 843 | } |
| 844 | priv->interface = pdata->phy_interface; |
| 845 | |
| 846 | /* Initialize flags */ |
| 847 | priv->flags = TSEC_GIGABIT; |
| 848 | if (priv->interface == PHY_INTERFACE_MODE_SGMII) |
| 849 | priv->flags |= TSEC_SGMII; |
| 850 | |
| 851 | mdio_info.regs = priv->phyregs_sgmii; |
| 852 | mdio_info.name = (char *)dev->name; |
| 853 | ret = fsl_pq_mdio_init(NULL, &mdio_info); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | |
| 857 | /* Reset the MAC */ |
| 858 | setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET); |
| 859 | udelay(2); /* Soft Reset must be asserted for 3 TX clocks */ |
| 860 | clrbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET); |
| 861 | |
| 862 | priv->dev = dev; |
| 863 | priv->bus = miiphy_get_dev_by_name(dev->name); |
| 864 | |
| 865 | /* Try to initialize PHY here, and return */ |
| 866 | return !init_phy(priv); |
| 867 | } |
| 868 | |
| 869 | int tsec_remove(struct udevice *dev) |
| 870 | { |
| 871 | struct tsec_private *priv = dev->priv; |
| 872 | |
| 873 | free(priv->phydev); |
| 874 | mdio_unregister(priv->bus); |
| 875 | mdio_free(priv->bus); |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | static const struct eth_ops tsec_ops = { |
| 881 | .start = tsec_init, |
| 882 | .send = tsec_send, |
| 883 | .recv = tsec_recv, |
| 884 | .free_pkt = tsec_free_pkt, |
| 885 | .stop = tsec_halt, |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 886 | .mcast = tsec_mcast_addr, |
Bin Meng | 1048f61 | 2016-01-11 22:41:24 -0800 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | static const struct udevice_id tsec_ids[] = { |
| 890 | { .compatible = "fsl,tsec" }, |
| 891 | { } |
| 892 | }; |
| 893 | |
| 894 | U_BOOT_DRIVER(eth_tsec) = { |
| 895 | .name = "tsec", |
| 896 | .id = UCLASS_ETH, |
| 897 | .of_match = tsec_ids, |
| 898 | .probe = tsec_probe, |
| 899 | .remove = tsec_remove, |
| 900 | .ops = &tsec_ops, |
| 901 | .priv_auto_alloc_size = sizeof(struct tsec_private), |
| 902 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 903 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 904 | }; |
| 905 | #endif /* CONFIG_DM_ETH */ |