Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Ethernet driver for TI K2HK EVM. |
| 4 | * |
| 5 | * (C) Copyright 2012-2014 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 7 | */ |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 10 | #include <console.h> |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 11 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 12 | #include <dm.h> |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 13 | #include <dm/lists.h> |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 14 | |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 15 | #include <net.h> |
Khoronzhuk, Ivan | 3fe9362 | 2014-10-17 20:44:35 +0300 | [diff] [blame] | 16 | #include <phy.h> |
Khoronzhuk, Ivan | c05d05e | 2014-10-17 21:01:15 +0300 | [diff] [blame] | 17 | #include <errno.h> |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 18 | #include <miiphy.h> |
| 19 | #include <malloc.h> |
Khoronzhuk, Ivan | ef45471 | 2014-09-05 19:02:47 +0300 | [diff] [blame] | 20 | #include <asm/ti-common/keystone_nav.h> |
Khoronzhuk, Ivan | 0935cac | 2014-09-29 22:17:22 +0300 | [diff] [blame] | 21 | #include <asm/ti-common/keystone_net.h> |
Khoronzhuk, Ivan | a43febd | 2014-10-22 17:18:21 +0300 | [diff] [blame] | 22 | #include <asm/ti-common/keystone_serdes.h> |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 23 | #include <asm/arch/psc_defs.h> |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 24 | |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 25 | #include "cpsw_mdio.h" |
| 26 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 29 | #ifdef KEYSTONE2_EMAC_GIG_ENABLE |
| 30 | #define emac_gigabit_enable(x) keystone2_eth_gigabit_enable(x) |
| 31 | #else |
| 32 | #define emac_gigabit_enable(x) /* no gigabit to enable */ |
| 33 | #endif |
| 34 | |
| 35 | #define RX_BUFF_NUMS 24 |
| 36 | #define RX_BUFF_LEN 1520 |
| 37 | #define MAX_SIZE_STREAM_BUFFER RX_BUFF_LEN |
Khoronzhuk, Ivan | c05d05e | 2014-10-17 21:01:15 +0300 | [diff] [blame] | 38 | #define SGMII_ANEG_TIMEOUT 4000 |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 39 | |
| 40 | static u8 rx_buffs[RX_BUFF_NUMS * RX_BUFF_LEN] __aligned(16); |
| 41 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 42 | enum link_type { |
Mugunthan V N | 1de4066 | 2016-08-11 20:04:03 +0530 | [diff] [blame] | 43 | LINK_TYPE_SGMII_MAC_TO_MAC_AUTO = 0, |
| 44 | LINK_TYPE_SGMII_MAC_TO_PHY_MODE = 1, |
| 45 | LINK_TYPE_SGMII_MAC_TO_MAC_FORCED_MODE = 2, |
| 46 | LINK_TYPE_SGMII_MAC_TO_FIBRE_MODE = 3, |
| 47 | LINK_TYPE_SGMII_MAC_TO_PHY_NO_MDIO_MODE = 4, |
| 48 | LINK_TYPE_RGMII_LINK_MAC_PHY = 5, |
| 49 | LINK_TYPE_RGMII_LINK_MAC_MAC_FORCED = 6, |
| 50 | LINK_TYPE_RGMII_LINK_MAC_PHY_NO_MDIO = 7, |
| 51 | LINK_TYPE_10G_MAC_TO_PHY_MODE = 10, |
| 52 | LINK_TYPE_10G_MAC_TO_MAC_FORCED_MODE = 11, |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 53 | }; |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 54 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 55 | #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \ |
| 56 | ((mac)[2] << 16) | ((mac)[3] << 24)) |
| 57 | #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8)) |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 58 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 59 | #ifdef CONFIG_KSNET_NETCP_V1_0 |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 60 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 61 | #define EMAC_EMACSW_BASE_OFS 0x90800 |
| 62 | #define EMAC_EMACSW_PORT_BASE_OFS (EMAC_EMACSW_BASE_OFS + 0x60) |
| 63 | |
| 64 | /* CPSW Switch slave registers */ |
| 65 | #define CPGMACSL_REG_SA_LO 0x10 |
| 66 | #define CPGMACSL_REG_SA_HI 0x14 |
| 67 | |
| 68 | #define DEVICE_EMACSW_BASE(base, x) ((base) + EMAC_EMACSW_PORT_BASE_OFS + \ |
| 69 | (x) * 0x30) |
| 70 | |
Grygorii Strashko | af0cf21 | 2018-10-31 16:21:41 -0500 | [diff] [blame] | 71 | #elif defined(CONFIG_KSNET_NETCP_V1_5) |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 72 | |
| 73 | #define EMAC_EMACSW_PORT_BASE_OFS 0x222000 |
| 74 | |
| 75 | /* CPSW Switch slave registers */ |
| 76 | #define CPGMACSL_REG_SA_LO 0x308 |
| 77 | #define CPGMACSL_REG_SA_HI 0x30c |
| 78 | |
| 79 | #define DEVICE_EMACSW_BASE(base, x) ((base) + EMAC_EMACSW_PORT_BASE_OFS + \ |
| 80 | (x) * 0x1000) |
| 81 | |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | struct ks2_eth_priv { |
| 86 | struct udevice *dev; |
| 87 | struct phy_device *phydev; |
| 88 | struct mii_dev *mdio_bus; |
| 89 | int phy_addr; |
| 90 | phy_interface_t phy_if; |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 91 | int phy_of_handle; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 92 | int sgmii_link_type; |
| 93 | void *mdio_base; |
| 94 | struct rx_buff_desc net_rx_buffs; |
| 95 | struct pktdma_cfg *netcp_pktdma; |
| 96 | void *hd; |
| 97 | int slave_port; |
| 98 | enum link_type link_type; |
| 99 | bool emac_open; |
| 100 | bool has_mdio; |
| 101 | }; |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 102 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 103 | static void __attribute__((unused)) |
| 104 | keystone2_eth_gigabit_enable(struct udevice *dev) |
| 105 | { |
| 106 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Check if link detected is giga-bit |
| 110 | * If Gigabit mode detected, enable gigbit in MAC |
| 111 | */ |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 112 | if (priv->has_mdio) { |
| 113 | if (priv->phydev->speed != 1000) |
| 114 | return; |
| 115 | } |
| 116 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 117 | writel(readl(DEVICE_EMACSL_BASE(priv->slave_port - 1) + |
| 118 | CPGMACSL_REG_CTL) | |
| 119 | EMAC_MACCONTROL_GIGFORCE | EMAC_MACCONTROL_GIGABIT_ENABLE, |
| 120 | DEVICE_EMACSL_BASE(priv->slave_port - 1) + CPGMACSL_REG_CTL); |
| 121 | } |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 122 | |
Vitaly Andrianov | 4657a2d | 2015-09-19 16:26:50 +0530 | [diff] [blame] | 123 | #ifdef CONFIG_SOC_K2G |
| 124 | int keystone_rgmii_config(struct phy_device *phy_dev) |
| 125 | { |
| 126 | unsigned int i, status; |
| 127 | |
| 128 | i = 0; |
| 129 | do { |
| 130 | if (i > SGMII_ANEG_TIMEOUT) { |
| 131 | puts(" TIMEOUT !\n"); |
| 132 | phy_dev->link = 0; |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | if (ctrlc()) { |
| 137 | puts("user interrupt!\n"); |
| 138 | phy_dev->link = 0; |
| 139 | return -EINTR; |
| 140 | } |
| 141 | |
| 142 | if ((i++ % 500) == 0) |
| 143 | printf("."); |
| 144 | |
| 145 | udelay(1000); /* 1 ms */ |
| 146 | status = readl(RGMII_STATUS_REG); |
| 147 | } while (!(status & RGMII_REG_STATUS_LINK)); |
| 148 | |
| 149 | puts(" done\n"); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | #else |
Khoronzhuk, Ivan | c05d05e | 2014-10-17 21:01:15 +0300 | [diff] [blame] | 154 | int keystone_sgmii_config(struct phy_device *phy_dev, int port, int interface) |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 155 | { |
| 156 | unsigned int i, status, mask; |
| 157 | unsigned int mr_adv_ability, control; |
| 158 | |
| 159 | switch (interface) { |
| 160 | case SGMII_LINK_MAC_MAC_AUTONEG: |
| 161 | mr_adv_ability = (SGMII_REG_MR_ADV_ENABLE | |
| 162 | SGMII_REG_MR_ADV_LINK | |
| 163 | SGMII_REG_MR_ADV_FULL_DUPLEX | |
| 164 | SGMII_REG_MR_ADV_GIG_MODE); |
| 165 | control = (SGMII_REG_CONTROL_MASTER | |
| 166 | SGMII_REG_CONTROL_AUTONEG); |
| 167 | |
| 168 | break; |
| 169 | case SGMII_LINK_MAC_PHY: |
| 170 | case SGMII_LINK_MAC_PHY_FORCED: |
| 171 | mr_adv_ability = SGMII_REG_MR_ADV_ENABLE; |
| 172 | control = SGMII_REG_CONTROL_AUTONEG; |
| 173 | |
| 174 | break; |
| 175 | case SGMII_LINK_MAC_MAC_FORCED: |
| 176 | mr_adv_ability = (SGMII_REG_MR_ADV_ENABLE | |
| 177 | SGMII_REG_MR_ADV_LINK | |
| 178 | SGMII_REG_MR_ADV_FULL_DUPLEX | |
| 179 | SGMII_REG_MR_ADV_GIG_MODE); |
| 180 | control = SGMII_REG_CONTROL_MASTER; |
| 181 | |
| 182 | break; |
| 183 | case SGMII_LINK_MAC_FIBER: |
| 184 | mr_adv_ability = 0x20; |
| 185 | control = SGMII_REG_CONTROL_AUTONEG; |
| 186 | |
| 187 | break; |
| 188 | default: |
| 189 | mr_adv_ability = SGMII_REG_MR_ADV_ENABLE; |
| 190 | control = SGMII_REG_CONTROL_AUTONEG; |
| 191 | } |
| 192 | |
| 193 | __raw_writel(0, SGMII_CTL_REG(port)); |
| 194 | |
| 195 | /* |
| 196 | * Wait for the SerDes pll to lock, |
| 197 | * but don't trap if lock is never read |
| 198 | */ |
| 199 | for (i = 0; i < 1000; i++) { |
| 200 | udelay(2000); |
| 201 | status = __raw_readl(SGMII_STATUS_REG(port)); |
| 202 | if ((status & SGMII_REG_STATUS_LOCK) != 0) |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | __raw_writel(mr_adv_ability, SGMII_MRADV_REG(port)); |
| 207 | __raw_writel(control, SGMII_CTL_REG(port)); |
| 208 | |
| 209 | |
| 210 | mask = SGMII_REG_STATUS_LINK; |
| 211 | |
| 212 | if (control & SGMII_REG_CONTROL_AUTONEG) |
| 213 | mask |= SGMII_REG_STATUS_AUTONEG; |
| 214 | |
Khoronzhuk, Ivan | c05d05e | 2014-10-17 21:01:15 +0300 | [diff] [blame] | 215 | status = __raw_readl(SGMII_STATUS_REG(port)); |
| 216 | if ((status & mask) == mask) |
| 217 | return 0; |
| 218 | |
| 219 | printf("\n%s Waiting for SGMII auto negotiation to complete", |
| 220 | phy_dev->dev->name); |
| 221 | while ((status & mask) != mask) { |
| 222 | /* |
| 223 | * Timeout reached ? |
| 224 | */ |
| 225 | if (i > SGMII_ANEG_TIMEOUT) { |
| 226 | puts(" TIMEOUT !\n"); |
| 227 | phy_dev->link = 0; |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | if (ctrlc()) { |
| 232 | puts("user interrupt!\n"); |
| 233 | phy_dev->link = 0; |
| 234 | return -EINTR; |
| 235 | } |
| 236 | |
| 237 | if ((i++ % 500) == 0) |
| 238 | printf("."); |
| 239 | |
| 240 | udelay(1000); /* 1 ms */ |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 241 | status = __raw_readl(SGMII_STATUS_REG(port)); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 242 | } |
Khoronzhuk, Ivan | c05d05e | 2014-10-17 21:01:15 +0300 | [diff] [blame] | 243 | puts(" done\n"); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
Vitaly Andrianov | 4657a2d | 2015-09-19 16:26:50 +0530 | [diff] [blame] | 247 | #endif |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 248 | |
| 249 | int mac_sl_reset(u32 port) |
| 250 | { |
| 251 | u32 i, v; |
| 252 | |
| 253 | if (port >= DEVICE_N_GMACSL_PORTS) |
| 254 | return GMACSL_RET_INVALID_PORT; |
| 255 | |
| 256 | /* Set the soft reset bit */ |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 257 | writel(CPGMAC_REG_RESET_VAL_RESET, |
| 258 | DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 259 | |
| 260 | /* Wait for the bit to clear */ |
| 261 | for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) { |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 262 | v = readl(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 263 | if ((v & CPGMAC_REG_RESET_VAL_RESET_MASK) != |
| 264 | CPGMAC_REG_RESET_VAL_RESET) |
| 265 | return GMACSL_RET_OK; |
| 266 | } |
| 267 | |
| 268 | /* Timeout on the reset */ |
| 269 | return GMACSL_RET_WARN_RESET_INCOMPLETE; |
| 270 | } |
| 271 | |
| 272 | int mac_sl_config(u_int16_t port, struct mac_sl_cfg *cfg) |
| 273 | { |
| 274 | u32 v, i; |
| 275 | int ret = GMACSL_RET_OK; |
| 276 | |
| 277 | if (port >= DEVICE_N_GMACSL_PORTS) |
| 278 | return GMACSL_RET_INVALID_PORT; |
| 279 | |
| 280 | if (cfg->max_rx_len > CPGMAC_REG_MAXLEN_LEN) { |
| 281 | cfg->max_rx_len = CPGMAC_REG_MAXLEN_LEN; |
| 282 | ret = GMACSL_RET_WARN_MAXLEN_TOO_BIG; |
| 283 | } |
| 284 | |
| 285 | /* Must wait if the device is undergoing reset */ |
| 286 | for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) { |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 287 | v = readl(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 288 | if ((v & CPGMAC_REG_RESET_VAL_RESET_MASK) != |
| 289 | CPGMAC_REG_RESET_VAL_RESET) |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | if (i == DEVICE_EMACSL_RESET_POLL_COUNT) |
| 294 | return GMACSL_RET_CONFIG_FAIL_RESET_ACTIVE; |
| 295 | |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 296 | writel(cfg->max_rx_len, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_MAXLEN); |
| 297 | writel(cfg->ctl, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_CTL); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 298 | |
Vitaly Andrianov | 4657a2d | 2015-09-19 16:26:50 +0530 | [diff] [blame] | 299 | #ifndef CONFIG_SOC_K2HK |
Khoronzhuk, Ivan | ff11c76 | 2014-10-17 21:01:14 +0300 | [diff] [blame] | 300 | /* Map RX packet flow priority to 0 */ |
| 301 | writel(0, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RX_PRI_MAP); |
| 302 | #endif |
| 303 | |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | int ethss_config(u32 ctl, u32 max_pkt_size) |
| 308 | { |
| 309 | u32 i; |
| 310 | |
| 311 | /* Max length register */ |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 312 | writel(max_pkt_size, DEVICE_CPSW_BASE + CPSW_REG_MAXLEN); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 313 | |
| 314 | /* Control register */ |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 315 | writel(ctl, DEVICE_CPSW_BASE + CPSW_REG_CTL); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 316 | |
| 317 | /* All statistics enabled by default */ |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 318 | writel(CPSW_REG_VAL_STAT_ENABLE_ALL, |
| 319 | DEVICE_CPSW_BASE + CPSW_REG_STAT_PORT_EN); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 320 | |
| 321 | /* Reset and enable the ALE */ |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 322 | writel(CPSW_REG_VAL_ALE_CTL_RESET_AND_ENABLE | |
| 323 | CPSW_REG_VAL_ALE_CTL_BYPASS, |
| 324 | DEVICE_CPSW_BASE + CPSW_REG_ALE_CONTROL); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 325 | |
| 326 | /* All ports put into forward mode */ |
| 327 | for (i = 0; i < DEVICE_CPSW_NUM_PORTS; i++) |
Khoronzhuk, Ivan | e6c9428 | 2014-08-28 16:07:45 +0300 | [diff] [blame] | 328 | writel(CPSW_REG_VAL_PORTCTL_FORWARD_MODE, |
| 329 | DEVICE_CPSW_BASE + CPSW_REG_ALE_PORTCTL(i)); |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | int ethss_start(void) |
| 335 | { |
| 336 | int i; |
| 337 | struct mac_sl_cfg cfg; |
| 338 | |
| 339 | cfg.max_rx_len = MAX_SIZE_STREAM_BUFFER; |
| 340 | cfg.ctl = GMACSL_ENABLE | GMACSL_RX_ENABLE_EXT_CTL; |
| 341 | |
| 342 | for (i = 0; i < DEVICE_N_GMACSL_PORTS; i++) { |
| 343 | mac_sl_reset(i); |
| 344 | mac_sl_config(i, &cfg); |
| 345 | } |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | int ethss_stop(void) |
| 351 | { |
| 352 | int i; |
| 353 | |
| 354 | for (i = 0; i < DEVICE_N_GMACSL_PORTS; i++) |
| 355 | mac_sl_reset(i); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 360 | struct ks2_serdes ks2_serdes_sgmii_156p25mhz = { |
| 361 | .clk = SERDES_CLOCK_156P25M, |
| 362 | .rate = SERDES_RATE_5G, |
| 363 | .rate_mode = SERDES_QUARTER_RATE, |
| 364 | .intf = SERDES_PHY_SGMII, |
| 365 | .loopback = 0, |
| 366 | }; |
| 367 | |
| 368 | #ifndef CONFIG_SOC_K2G |
| 369 | static void keystone2_net_serdes_setup(void) |
| 370 | { |
| 371 | ks2_serdes_init(CONFIG_KSNET_SERDES_SGMII_BASE, |
| 372 | &ks2_serdes_sgmii_156p25mhz, |
| 373 | CONFIG_KSNET_SERDES_LANES_PER_SGMII); |
| 374 | |
| 375 | #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L) |
| 376 | ks2_serdes_init(CONFIG_KSNET_SERDES_SGMII2_BASE, |
| 377 | &ks2_serdes_sgmii_156p25mhz, |
| 378 | CONFIG_KSNET_SERDES_LANES_PER_SGMII); |
| 379 | #endif |
| 380 | |
| 381 | /* wait till setup */ |
| 382 | udelay(5000); |
| 383 | } |
| 384 | #endif |
| 385 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 386 | static int ks2_eth_start(struct udevice *dev) |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 387 | { |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 388 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
Hao Zhang | 92a16c8 | 2014-10-22 17:18:23 +0300 | [diff] [blame] | 389 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 390 | #ifdef CONFIG_SOC_K2G |
| 391 | keystone_rgmii_config(priv->phydev); |
| 392 | #else |
| 393 | keystone_sgmii_config(priv->phydev, priv->slave_port - 1, |
| 394 | priv->sgmii_link_type); |
Khoronzhuk, Ivan | 3c61502 | 2014-10-17 21:01:13 +0300 | [diff] [blame] | 395 | #endif |
| 396 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 397 | udelay(10000); |
| 398 | |
| 399 | /* On chip switch configuration */ |
| 400 | ethss_config(target_get_switch_ctl(), SWITCH_MAX_PKT_SIZE); |
| 401 | |
| 402 | qm_init(); |
| 403 | |
| 404 | if (ksnav_init(priv->netcp_pktdma, &priv->net_rx_buffs)) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 405 | pr_err("ksnav_init failed\n"); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 406 | goto err_knav_init; |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * Streaming switch configuration. If not present this |
| 411 | * statement is defined to void in target.h. |
| 412 | * If present this is usually defined to a series of register writes |
| 413 | */ |
| 414 | hw_config_streaming_switch(); |
| 415 | |
| 416 | if (priv->has_mdio) { |
| 417 | phy_startup(priv->phydev); |
| 418 | if (priv->phydev->link == 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 419 | pr_err("phy startup failed\n"); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 420 | goto err_phy_start; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | emac_gigabit_enable(dev); |
| 425 | |
| 426 | ethss_start(); |
| 427 | |
| 428 | priv->emac_open = true; |
| 429 | |
| 430 | return 0; |
| 431 | |
| 432 | err_phy_start: |
| 433 | ksnav_close(priv->netcp_pktdma); |
| 434 | err_knav_init: |
| 435 | qm_close(); |
| 436 | |
| 437 | return -EFAULT; |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 438 | } |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 439 | |
| 440 | static int ks2_eth_send(struct udevice *dev, void *packet, int length) |
| 441 | { |
| 442 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 443 | |
| 444 | genphy_update_link(priv->phydev); |
| 445 | if (priv->phydev->link == 0) |
| 446 | return -1; |
| 447 | |
| 448 | if (length < EMAC_MIN_ETHERNET_PKT_SIZE) |
| 449 | length = EMAC_MIN_ETHERNET_PKT_SIZE; |
| 450 | |
| 451 | return ksnav_send(priv->netcp_pktdma, (u32 *)packet, |
| 452 | length, (priv->slave_port) << 16); |
| 453 | } |
| 454 | |
| 455 | static int ks2_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
| 456 | { |
| 457 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 458 | int pkt_size; |
| 459 | u32 *pkt = NULL; |
| 460 | |
| 461 | priv->hd = ksnav_recv(priv->netcp_pktdma, &pkt, &pkt_size); |
| 462 | if (priv->hd == NULL) |
| 463 | return -EAGAIN; |
| 464 | |
| 465 | *packetp = (uchar *)pkt; |
| 466 | |
| 467 | return pkt_size; |
| 468 | } |
| 469 | |
| 470 | static int ks2_eth_free_pkt(struct udevice *dev, uchar *packet, |
| 471 | int length) |
| 472 | { |
| 473 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 474 | |
| 475 | ksnav_release_rxhd(priv->netcp_pktdma, priv->hd); |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static void ks2_eth_stop(struct udevice *dev) |
| 481 | { |
| 482 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 483 | |
| 484 | if (!priv->emac_open) |
| 485 | return; |
| 486 | ethss_stop(); |
| 487 | |
| 488 | ksnav_close(priv->netcp_pktdma); |
| 489 | qm_close(); |
| 490 | phy_shutdown(priv->phydev); |
| 491 | priv->emac_open = false; |
| 492 | } |
| 493 | |
| 494 | int ks2_eth_read_rom_hwaddr(struct udevice *dev) |
| 495 | { |
| 496 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 497 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 498 | u32 maca = 0; |
| 499 | u32 macb = 0; |
| 500 | |
| 501 | /* Read the e-fuse mac address */ |
| 502 | if (priv->slave_port == 1) { |
| 503 | maca = __raw_readl(MAC_ID_BASE_ADDR); |
| 504 | macb = __raw_readl(MAC_ID_BASE_ADDR + 4); |
| 505 | } |
| 506 | |
| 507 | pdata->enetaddr[0] = (macb >> 8) & 0xff; |
| 508 | pdata->enetaddr[1] = (macb >> 0) & 0xff; |
| 509 | pdata->enetaddr[2] = (maca >> 24) & 0xff; |
| 510 | pdata->enetaddr[3] = (maca >> 16) & 0xff; |
| 511 | pdata->enetaddr[4] = (maca >> 8) & 0xff; |
| 512 | pdata->enetaddr[5] = (maca >> 0) & 0xff; |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | int ks2_eth_write_hwaddr(struct udevice *dev) |
| 518 | { |
| 519 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 520 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 521 | |
| 522 | writel(mac_hi(pdata->enetaddr), |
| 523 | DEVICE_EMACSW_BASE(pdata->iobase, priv->slave_port - 1) + |
| 524 | CPGMACSL_REG_SA_HI); |
| 525 | writel(mac_lo(pdata->enetaddr), |
| 526 | DEVICE_EMACSW_BASE(pdata->iobase, priv->slave_port - 1) + |
| 527 | CPGMACSL_REG_SA_LO); |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int ks2_eth_probe(struct udevice *dev) |
| 533 | { |
| 534 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 535 | struct mii_dev *mdio_bus; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 536 | |
| 537 | priv->dev = dev; |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 538 | priv->emac_open = false; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 539 | |
| 540 | /* These clock enables has to be moved to common location */ |
| 541 | if (cpu_is_k2g()) |
| 542 | writel(KS2_ETHERNET_RGMII, KS2_ETHERNET_CFG); |
| 543 | |
| 544 | /* By default, select PA PLL clock as PA clock source */ |
| 545 | #ifndef CONFIG_SOC_K2G |
| 546 | if (psc_enable_module(KS2_LPSC_PA)) |
| 547 | return -EACCES; |
| 548 | #endif |
| 549 | if (psc_enable_module(KS2_LPSC_CPGMAC)) |
| 550 | return -EACCES; |
| 551 | if (psc_enable_module(KS2_LPSC_CRYPTO)) |
| 552 | return -EACCES; |
| 553 | |
| 554 | if (cpu_is_k2e() || cpu_is_k2l()) |
| 555 | pll_pa_clk_sel(); |
| 556 | |
Mugunthan V N | 1610a92 | 2016-08-02 12:01:11 +0530 | [diff] [blame] | 557 | priv->net_rx_buffs.buff_ptr = rx_buffs; |
| 558 | priv->net_rx_buffs.num_buffs = RX_BUFF_NUMS; |
| 559 | priv->net_rx_buffs.buff_len = RX_BUFF_LEN; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 560 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 561 | if (priv->slave_port == 1) { |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 562 | #ifndef CONFIG_SOC_K2G |
| 563 | keystone2_net_serdes_setup(); |
| 564 | #endif |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 565 | /* |
| 566 | * Register MDIO bus for slave 0 only, other slave have |
| 567 | * to re-use the same |
| 568 | */ |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 569 | mdio_bus = cpsw_mdio_init("ethernet-mdio", |
| 570 | (u32)priv->mdio_base, |
| 571 | EMAC_MDIO_CLOCK_FREQ, |
| 572 | EMAC_MDIO_BUS_FREQ); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 573 | if (!mdio_bus) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 574 | pr_err("MDIO alloc failed\n"); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 575 | return -ENOMEM; |
| 576 | } |
| 577 | priv->mdio_bus = mdio_bus; |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 578 | } else { |
| 579 | /* Get the MDIO bus from slave 0 device */ |
| 580 | struct ks2_eth_priv *parent_priv; |
| 581 | |
| 582 | parent_priv = dev_get_priv(dev->parent); |
| 583 | priv->mdio_bus = parent_priv->mdio_bus; |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 584 | priv->mdio_base = parent_priv->mdio_base; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 585 | } |
| 586 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 587 | priv->netcp_pktdma = &netcp_pktdma; |
| 588 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 589 | if (priv->has_mdio) { |
| 590 | priv->phydev = phy_connect(priv->mdio_bus, priv->phy_addr, |
| 591 | dev, priv->phy_if); |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 592 | #ifdef CONFIG_DM_ETH |
| 593 | if (priv->phy_of_handle) |
| 594 | priv->phydev->node = offset_to_ofnode(priv->phy_of_handle); |
| 595 | #endif |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 596 | phy_config(priv->phydev); |
| 597 | } |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | int ks2_eth_remove(struct udevice *dev) |
| 603 | { |
| 604 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 605 | |
Grygorii Strashko | 79d8127 | 2018-10-31 16:21:45 -0500 | [diff] [blame] | 606 | cpsw_mdio_free(priv->mdio_bus); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | static const struct eth_ops ks2_eth_ops = { |
| 612 | .start = ks2_eth_start, |
| 613 | .send = ks2_eth_send, |
| 614 | .recv = ks2_eth_recv, |
| 615 | .free_pkt = ks2_eth_free_pkt, |
| 616 | .stop = ks2_eth_stop, |
| 617 | .read_rom_hwaddr = ks2_eth_read_rom_hwaddr, |
| 618 | .write_hwaddr = ks2_eth_write_hwaddr, |
| 619 | }; |
| 620 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 621 | static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 622 | { |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 623 | const void *fdt = gd->fdt_blob; |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 624 | struct udevice *sl_dev; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 625 | int interfaces; |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 626 | int sec_slave; |
| 627 | int slave; |
| 628 | int ret; |
| 629 | char *slave_name; |
| 630 | |
| 631 | interfaces = fdt_subnode_offset(fdt, gbe, "interfaces"); |
Simon Glass | df87e6b | 2016-10-02 17:59:29 -0600 | [diff] [blame] | 632 | fdt_for_each_subnode(slave, fdt, interfaces) { |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 633 | int slave_no; |
| 634 | |
| 635 | slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); |
| 636 | if (slave_no == -ENOENT) |
| 637 | continue; |
| 638 | |
| 639 | if (slave_no == 0) { |
| 640 | /* This is the current eth device */ |
| 641 | *gbe_0 = slave; |
| 642 | } else { |
| 643 | /* Slave devices to be registered */ |
| 644 | slave_name = malloc(20); |
| 645 | snprintf(slave_name, 20, "netcp@slave-%d", slave_no); |
| 646 | ret = device_bind_driver_to_node(dev, "eth_ks2_sl", |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 647 | slave_name, offset_to_ofnode(slave), |
| 648 | &sl_dev); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 649 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 650 | pr_err("ks2_net - not able to bind slave interfaces\n"); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 651 | return ret; |
| 652 | } |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports"); |
Simon Glass | df87e6b | 2016-10-02 17:59:29 -0600 | [diff] [blame] | 657 | fdt_for_each_subnode(slave, fdt, sec_slave) { |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 658 | int slave_no; |
| 659 | |
| 660 | slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); |
| 661 | if (slave_no == -ENOENT) |
| 662 | continue; |
| 663 | |
| 664 | /* Slave devices to be registered */ |
| 665 | slave_name = malloc(20); |
| 666 | snprintf(slave_name, 20, "netcp@slave-%d", slave_no); |
| 667 | ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, |
Simon Glass | 45a2686 | 2017-05-18 20:09:07 -0600 | [diff] [blame] | 668 | offset_to_ofnode(slave), &sl_dev); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 669 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 670 | pr_err("ks2_net - not able to bind slave interfaces\n"); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 671 | return ret; |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | static int ks2_eth_parse_slave_interface(int netcp, int slave, |
| 679 | struct ks2_eth_priv *priv, |
| 680 | struct eth_pdata *pdata) |
| 681 | { |
| 682 | const void *fdt = gd->fdt_blob; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 683 | int mdio; |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 684 | int phy; |
| 685 | int dma_count; |
| 686 | u32 dma_channel[8]; |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 687 | const char *phy_mode; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 688 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 689 | priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1); |
| 690 | priv->net_rx_buffs.rx_flow = priv->slave_port * 8; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 691 | |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 692 | /* U-Boot slave port number starts with 1 instead of 0 */ |
| 693 | priv->slave_port += 1; |
| 694 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 695 | dma_count = fdtdec_get_int_array_count(fdt, netcp, |
| 696 | "ti,navigator-dmas", |
| 697 | dma_channel, 8); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 698 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 699 | if (dma_count > (2 * priv->slave_port)) { |
| 700 | int dma_idx; |
| 701 | |
| 702 | dma_idx = priv->slave_port * 2 - 1; |
| 703 | priv->net_rx_buffs.rx_flow = dma_channel[dma_idx]; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 704 | } |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 705 | |
| 706 | priv->link_type = fdtdec_get_int(fdt, slave, "link-interface", -1); |
| 707 | |
| 708 | phy = fdtdec_lookup_phandle(fdt, slave, "phy-handle"); |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 709 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 710 | if (phy >= 0) { |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 711 | priv->phy_of_handle = phy; |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 712 | priv->phy_addr = fdtdec_get_int(fdt, phy, "reg", -1); |
| 713 | |
| 714 | mdio = fdt_parent_offset(fdt, phy); |
| 715 | if (mdio < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 716 | pr_err("mdio dt not found\n"); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 717 | return -ENODEV; |
| 718 | } |
| 719 | priv->mdio_base = (void *)fdtdec_get_addr(fdt, mdio, "reg"); |
| 720 | } |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 721 | |
Mugunthan V N | 1de4066 | 2016-08-11 20:04:03 +0530 | [diff] [blame] | 722 | if (priv->link_type == LINK_TYPE_SGMII_MAC_TO_PHY_MODE) { |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 723 | priv->phy_if = PHY_INTERFACE_MODE_SGMII; |
| 724 | pdata->phy_interface = priv->phy_if; |
| 725 | priv->sgmii_link_type = SGMII_LINK_MAC_PHY; |
| 726 | priv->has_mdio = true; |
Mugunthan V N | 1de4066 | 2016-08-11 20:04:03 +0530 | [diff] [blame] | 727 | } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { |
Murali Karicheri | 55d5cb1 | 2019-02-21 12:02:03 -0500 | [diff] [blame] | 728 | phy_mode = fdt_getprop(fdt, slave, "phy-mode", NULL); |
| 729 | if (phy_mode) { |
| 730 | priv->phy_if = phy_get_interface_by_name(phy_mode); |
| 731 | if (priv->phy_if != PHY_INTERFACE_MODE_RGMII && |
| 732 | priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID && |
| 733 | priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID && |
| 734 | priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) { |
| 735 | pr_err("invalid phy-mode\n"); |
| 736 | return -EINVAL; |
| 737 | } |
| 738 | } else { |
| 739 | priv->phy_if = PHY_INTERFACE_MODE_RGMII; |
| 740 | } |
Mugunthan V N | 1de4066 | 2016-08-11 20:04:03 +0530 | [diff] [blame] | 741 | pdata->phy_interface = priv->phy_if; |
| 742 | priv->has_mdio = true; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 743 | } |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 744 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int ks2_sl_eth_ofdata_to_platdata(struct udevice *dev) |
| 749 | { |
| 750 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 751 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 752 | const void *fdt = gd->fdt_blob; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 753 | int slave = dev_of_offset(dev); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 754 | int interfaces; |
| 755 | int gbe; |
| 756 | int netcp_devices; |
| 757 | int netcp; |
| 758 | |
| 759 | interfaces = fdt_parent_offset(fdt, slave); |
| 760 | gbe = fdt_parent_offset(fdt, interfaces); |
| 761 | netcp_devices = fdt_parent_offset(fdt, gbe); |
| 762 | netcp = fdt_parent_offset(fdt, netcp_devices); |
| 763 | |
| 764 | ks2_eth_parse_slave_interface(netcp, slave, priv, pdata); |
| 765 | |
| 766 | pdata->iobase = fdtdec_get_addr(fdt, netcp, "reg"); |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int ks2_eth_ofdata_to_platdata(struct udevice *dev) |
| 772 | { |
| 773 | struct ks2_eth_priv *priv = dev_get_priv(dev); |
| 774 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 775 | const void *fdt = gd->fdt_blob; |
| 776 | int gbe_0 = -ENODEV; |
| 777 | int netcp_devices; |
| 778 | int gbe; |
| 779 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 780 | netcp_devices = fdt_subnode_offset(fdt, dev_of_offset(dev), |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 781 | "netcp-devices"); |
| 782 | gbe = fdt_subnode_offset(fdt, netcp_devices, "gbe"); |
| 783 | |
| 784 | ks2_eth_bind_slaves(dev, gbe, &gbe_0); |
| 785 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 786 | ks2_eth_parse_slave_interface(dev_of_offset(dev), gbe_0, priv, pdata); |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 787 | |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 788 | pdata->iobase = devfdt_get_addr(dev); |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | static const struct udevice_id ks2_eth_ids[] = { |
| 794 | { .compatible = "ti,netcp-1.0" }, |
| 795 | { } |
| 796 | }; |
| 797 | |
Mugunthan V N | a61f6a5 | 2016-08-02 12:01:12 +0530 | [diff] [blame] | 798 | U_BOOT_DRIVER(eth_ks2_slave) = { |
| 799 | .name = "eth_ks2_sl", |
| 800 | .id = UCLASS_ETH, |
| 801 | .ofdata_to_platdata = ks2_sl_eth_ofdata_to_platdata, |
| 802 | .probe = ks2_eth_probe, |
| 803 | .remove = ks2_eth_remove, |
| 804 | .ops = &ks2_eth_ops, |
| 805 | .priv_auto_alloc_size = sizeof(struct ks2_eth_priv), |
| 806 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 807 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 808 | }; |
Mugunthan V N | 6599f36 | 2016-02-02 15:51:33 +0530 | [diff] [blame] | 809 | |
| 810 | U_BOOT_DRIVER(eth_ks2) = { |
| 811 | .name = "eth_ks2", |
| 812 | .id = UCLASS_ETH, |
| 813 | .of_match = ks2_eth_ids, |
| 814 | .ofdata_to_platdata = ks2_eth_ofdata_to_platdata, |
| 815 | .probe = ks2_eth_probe, |
| 816 | .remove = ks2_eth_remove, |
| 817 | .ops = &ks2_eth_ops, |
| 818 | .priv_auto_alloc_size = sizeof(struct ks2_eth_priv), |
| 819 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 820 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 821 | }; |