Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net> |
| 3 | * |
| 4 | * Based on: |
| 5 | * |
| 6 | * ---------------------------------------------------------------------------- |
| 7 | * |
| 8 | * dm644x_emac.h |
| 9 | * |
| 10 | * TI DaVinci (DM644X) EMAC peripheral driver header for DV-EVM |
| 11 | * |
| 12 | * Copyright (C) 2005 Texas Instruments. |
| 13 | * |
| 14 | * ---------------------------------------------------------------------------- |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 29 | * ---------------------------------------------------------------------------- |
| 30 | |
| 31 | * Modifications: |
| 32 | * ver. 1.0: Sep 2005, TI PSP Team - Created EMAC version for uBoot. |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #ifndef _DM644X_EMAC_H_ |
| 37 | #define _DM644X_EMAC_H_ |
| 38 | |
| 39 | #include <asm/arch/hardware.h> |
| 40 | |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 41 | #ifdef CONFIG_SOC_DM365 |
| 42 | #define EMAC_BASE_ADDR (0x01d07000) |
| 43 | #define EMAC_WRAPPER_BASE_ADDR (0x01d0a000) |
| 44 | #define EMAC_WRAPPER_RAM_ADDR (0x01d08000) |
| 45 | #define EMAC_MDIO_BASE_ADDR (0x01d0b000) |
| 46 | #else |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 47 | #define EMAC_BASE_ADDR (0x01c80000) |
| 48 | #define EMAC_WRAPPER_BASE_ADDR (0x01c81000) |
| 49 | #define EMAC_WRAPPER_RAM_ADDR (0x01c82000) |
| 50 | #define EMAC_MDIO_BASE_ADDR (0x01c84000) |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 51 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 52 | |
Sandeep Paulraj | 310baca | 2009-09-18 17:30:05 -0400 | [diff] [blame] | 53 | #ifdef CONFIG_SOC_DM646X |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 54 | /* MDIO module input frequency */ |
| 55 | #define EMAC_MDIO_BUS_FREQ 76500000 |
| 56 | /* MDIO clock output frequency */ |
| 57 | #define EMAC_MDIO_CLOCK_FREQ 2500000 /* 2.5 MHz */ |
| 58 | #elif defined(CONFIG_SOC_DM365) |
| 59 | /* MDIO module input frequency */ |
| 60 | #define EMAC_MDIO_BUS_FREQ 121500000 |
| 61 | /* MDIO clock output frequency */ |
| 62 | #define EMAC_MDIO_CLOCK_FREQ 2200000 /* 2.2 MHz */ |
| 63 | #else |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 64 | /* MDIO module input frequency */ |
| 65 | #define EMAC_MDIO_BUS_FREQ 99000000 /* PLL/6 - 99 MHz */ |
| 66 | /* MDIO clock output frequency */ |
| 67 | #define EMAC_MDIO_CLOCK_FREQ 2000000 /* 2.0 MHz */ |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | /* PHY mask - set only those phy number bits where phy is/can be connected */ |
| 71 | #define EMAC_MDIO_PHY_NUM 1 |
| 72 | #define EMAC_MDIO_PHY_MASK (1 << EMAC_MDIO_PHY_NUM) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 73 | |
| 74 | /* Ethernet Min/Max packet size */ |
| 75 | #define EMAC_MIN_ETHERNET_PKT_SIZE 60 |
| 76 | #define EMAC_MAX_ETHERNET_PKT_SIZE 1518 |
| 77 | #define EMAC_PKT_ALIGN 18 /* 1518 + 18 = 1536 (packet aligned on 32 byte boundry) */ |
| 78 | |
| 79 | /* Number of RX packet buffers |
| 80 | * NOTE: Only 1 buffer supported as of now |
| 81 | */ |
| 82 | #define EMAC_MAX_RX_BUFFERS 10 |
| 83 | |
| 84 | |
| 85 | /*********************************************** |
| 86 | ******** Internally used macros *************** |
| 87 | ***********************************************/ |
| 88 | |
| 89 | #define EMAC_CH_TX 1 |
| 90 | #define EMAC_CH_RX 0 |
| 91 | |
| 92 | /* Each descriptor occupies 4 words, lets start RX desc's at 0 and |
| 93 | * reserve space for 64 descriptors max |
| 94 | */ |
| 95 | #define EMAC_RX_DESC_BASE 0x0 |
| 96 | #define EMAC_TX_DESC_BASE 0x1000 |
| 97 | |
| 98 | /* EMAC Teardown value */ |
| 99 | #define EMAC_TEARDOWN_VALUE 0xfffffffc |
| 100 | |
| 101 | /* MII Status Register */ |
| 102 | #define MII_STATUS_REG 1 |
| 103 | |
| 104 | /* Number of statistics registers */ |
| 105 | #define EMAC_NUM_STATS 36 |
| 106 | |
| 107 | |
| 108 | /* EMAC Descriptor */ |
| 109 | typedef volatile struct _emac_desc |
| 110 | { |
| 111 | u_int32_t next; /* Pointer to next descriptor in chain */ |
| 112 | u_int8_t *buffer; /* Pointer to data buffer */ |
| 113 | u_int32_t buff_off_len; /* Buffer Offset(MSW) and Length(LSW) */ |
| 114 | u_int32_t pkt_flag_len; /* Packet Flags(MSW) and Length(LSW) */ |
| 115 | } emac_desc; |
| 116 | |
| 117 | /* CPPI bit positions */ |
| 118 | #define EMAC_CPPI_SOP_BIT (0x80000000) |
| 119 | #define EMAC_CPPI_EOP_BIT (0x40000000) |
| 120 | #define EMAC_CPPI_OWNERSHIP_BIT (0x20000000) |
| 121 | #define EMAC_CPPI_EOQ_BIT (0x10000000) |
| 122 | #define EMAC_CPPI_TEARDOWN_COMPLETE_BIT (0x08000000) |
| 123 | #define EMAC_CPPI_PASS_CRC_BIT (0x04000000) |
| 124 | |
| 125 | #define EMAC_CPPI_RX_ERROR_FRAME (0x03fc0000) |
| 126 | |
| 127 | #define EMAC_MACCONTROL_MIIEN_ENABLE (0x20) |
| 128 | #define EMAC_MACCONTROL_FULLDUPLEX_ENABLE (0x1) |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 129 | #define EMAC_MACCONTROL_GIGABIT_ENABLE (1 << 7) |
| 130 | #define EMAC_MACCONTROL_GIGFORCE (1 << 17) |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 131 | |
| 132 | #define EMAC_RXMBPENABLE_RXCAFEN_ENABLE (0x200000) |
| 133 | #define EMAC_RXMBPENABLE_RXBROADEN (0x2000) |
| 134 | |
| 135 | |
| 136 | #define MDIO_CONTROL_IDLE (0x80000000) |
| 137 | #define MDIO_CONTROL_ENABLE (0x40000000) |
| 138 | #define MDIO_CONTROL_FAULT_ENABLE (0x40000) |
| 139 | #define MDIO_CONTROL_FAULT (0x80000) |
| 140 | #define MDIO_USERACCESS0_GO (0x80000000) |
| 141 | #define MDIO_USERACCESS0_WRITE_READ (0x0) |
| 142 | #define MDIO_USERACCESS0_WRITE_WRITE (0x40000000) |
| 143 | #define MDIO_USERACCESS0_ACK (0x20000000) |
| 144 | |
| 145 | /* Ethernet MAC Registers Structure */ |
| 146 | typedef struct { |
| 147 | dv_reg TXIDVER; |
| 148 | dv_reg TXCONTROL; |
| 149 | dv_reg TXTEARDOWN; |
| 150 | u_int8_t RSVD0[4]; |
| 151 | dv_reg RXIDVER; |
| 152 | dv_reg RXCONTROL; |
| 153 | dv_reg RXTEARDOWN; |
| 154 | u_int8_t RSVD1[100]; |
| 155 | dv_reg TXINTSTATRAW; |
| 156 | dv_reg TXINTSTATMASKED; |
| 157 | dv_reg TXINTMASKSET; |
| 158 | dv_reg TXINTMASKCLEAR; |
| 159 | dv_reg MACINVECTOR; |
| 160 | u_int8_t RSVD2[12]; |
| 161 | dv_reg RXINTSTATRAW; |
| 162 | dv_reg RXINTSTATMASKED; |
| 163 | dv_reg RXINTMASKSET; |
| 164 | dv_reg RXINTMASKCLEAR; |
| 165 | dv_reg MACINTSTATRAW; |
| 166 | dv_reg MACINTSTATMASKED; |
| 167 | dv_reg MACINTMASKSET; |
| 168 | dv_reg MACINTMASKCLEAR; |
| 169 | u_int8_t RSVD3[64]; |
| 170 | dv_reg RXMBPENABLE; |
| 171 | dv_reg RXUNICASTSET; |
| 172 | dv_reg RXUNICASTCLEAR; |
| 173 | dv_reg RXMAXLEN; |
| 174 | dv_reg RXBUFFEROFFSET; |
| 175 | dv_reg RXFILTERLOWTHRESH; |
| 176 | u_int8_t RSVD4[8]; |
| 177 | dv_reg RX0FLOWTHRESH; |
| 178 | dv_reg RX1FLOWTHRESH; |
| 179 | dv_reg RX2FLOWTHRESH; |
| 180 | dv_reg RX3FLOWTHRESH; |
| 181 | dv_reg RX4FLOWTHRESH; |
| 182 | dv_reg RX5FLOWTHRESH; |
| 183 | dv_reg RX6FLOWTHRESH; |
| 184 | dv_reg RX7FLOWTHRESH; |
| 185 | dv_reg RX0FREEBUFFER; |
| 186 | dv_reg RX1FREEBUFFER; |
| 187 | dv_reg RX2FREEBUFFER; |
| 188 | dv_reg RX3FREEBUFFER; |
| 189 | dv_reg RX4FREEBUFFER; |
| 190 | dv_reg RX5FREEBUFFER; |
| 191 | dv_reg RX6FREEBUFFER; |
| 192 | dv_reg RX7FREEBUFFER; |
| 193 | dv_reg MACCONTROL; |
| 194 | dv_reg MACSTATUS; |
| 195 | dv_reg EMCONTROL; |
| 196 | dv_reg FIFOCONTROL; |
| 197 | dv_reg MACCONFIG; |
| 198 | dv_reg SOFTRESET; |
| 199 | u_int8_t RSVD5[88]; |
| 200 | dv_reg MACSRCADDRLO; |
| 201 | dv_reg MACSRCADDRHI; |
| 202 | dv_reg MACHASH1; |
| 203 | dv_reg MACHASH2; |
| 204 | dv_reg BOFFTEST; |
| 205 | dv_reg TPACETEST; |
| 206 | dv_reg RXPAUSE; |
| 207 | dv_reg TXPAUSE; |
| 208 | u_int8_t RSVD6[16]; |
| 209 | dv_reg RXGOODFRAMES; |
| 210 | dv_reg RXBCASTFRAMES; |
| 211 | dv_reg RXMCASTFRAMES; |
| 212 | dv_reg RXPAUSEFRAMES; |
| 213 | dv_reg RXCRCERRORS; |
| 214 | dv_reg RXALIGNCODEERRORS; |
| 215 | dv_reg RXOVERSIZED; |
| 216 | dv_reg RXJABBER; |
| 217 | dv_reg RXUNDERSIZED; |
| 218 | dv_reg RXFRAGMENTS; |
| 219 | dv_reg RXFILTERED; |
| 220 | dv_reg RXQOSFILTERED; |
| 221 | dv_reg RXOCTETS; |
| 222 | dv_reg TXGOODFRAMES; |
| 223 | dv_reg TXBCASTFRAMES; |
| 224 | dv_reg TXMCASTFRAMES; |
| 225 | dv_reg TXPAUSEFRAMES; |
| 226 | dv_reg TXDEFERRED; |
| 227 | dv_reg TXCOLLISION; |
| 228 | dv_reg TXSINGLECOLL; |
| 229 | dv_reg TXMULTICOLL; |
| 230 | dv_reg TXEXCESSIVECOLL; |
| 231 | dv_reg TXLATECOLL; |
| 232 | dv_reg TXUNDERRUN; |
| 233 | dv_reg TXCARRIERSENSE; |
| 234 | dv_reg TXOCTETS; |
| 235 | dv_reg FRAME64; |
| 236 | dv_reg FRAME65T127; |
| 237 | dv_reg FRAME128T255; |
| 238 | dv_reg FRAME256T511; |
| 239 | dv_reg FRAME512T1023; |
| 240 | dv_reg FRAME1024TUP; |
| 241 | dv_reg NETOCTETS; |
| 242 | dv_reg RXSOFOVERRUNS; |
| 243 | dv_reg RXMOFOVERRUNS; |
| 244 | dv_reg RXDMAOVERRUNS; |
| 245 | u_int8_t RSVD7[624]; |
| 246 | dv_reg MACADDRLO; |
| 247 | dv_reg MACADDRHI; |
| 248 | dv_reg MACINDEX; |
| 249 | u_int8_t RSVD8[244]; |
| 250 | dv_reg TX0HDP; |
| 251 | dv_reg TX1HDP; |
| 252 | dv_reg TX2HDP; |
| 253 | dv_reg TX3HDP; |
| 254 | dv_reg TX4HDP; |
| 255 | dv_reg TX5HDP; |
| 256 | dv_reg TX6HDP; |
| 257 | dv_reg TX7HDP; |
| 258 | dv_reg RX0HDP; |
| 259 | dv_reg RX1HDP; |
| 260 | dv_reg RX2HDP; |
| 261 | dv_reg RX3HDP; |
| 262 | dv_reg RX4HDP; |
| 263 | dv_reg RX5HDP; |
| 264 | dv_reg RX6HDP; |
| 265 | dv_reg RX7HDP; |
| 266 | dv_reg TX0CP; |
| 267 | dv_reg TX1CP; |
| 268 | dv_reg TX2CP; |
| 269 | dv_reg TX3CP; |
| 270 | dv_reg TX4CP; |
| 271 | dv_reg TX5CP; |
| 272 | dv_reg TX6CP; |
| 273 | dv_reg TX7CP; |
| 274 | dv_reg RX0CP; |
| 275 | dv_reg RX1CP; |
| 276 | dv_reg RX2CP; |
| 277 | dv_reg RX3CP; |
| 278 | dv_reg RX4CP; |
| 279 | dv_reg RX5CP; |
| 280 | dv_reg RX6CP; |
| 281 | dv_reg RX7CP; |
| 282 | } emac_regs; |
| 283 | |
| 284 | /* EMAC Wrapper Registers Structure */ |
| 285 | typedef struct { |
Sandeep Paulraj | 310baca | 2009-09-18 17:30:05 -0400 | [diff] [blame] | 286 | #if defined(CONFIG_SOC_DM646X) || defined(CONFIG_SOC_DM365) |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 287 | dv_reg IDVER; |
| 288 | dv_reg SOFTRST; |
| 289 | dv_reg EMCTRL; |
| 290 | #else |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 291 | u_int8_t RSVD0[4100]; |
| 292 | dv_reg EWCTL; |
| 293 | dv_reg EWINTTCNT; |
s-paulraj@ti.com | e338f7e | 2009-05-12 11:45:34 -0400 | [diff] [blame] | 294 | #endif |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 295 | } ewrap_regs; |
| 296 | |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 297 | /* EMAC MDIO Registers Structure */ |
| 298 | typedef struct { |
| 299 | dv_reg VERSION; |
| 300 | dv_reg CONTROL; |
| 301 | dv_reg ALIVE; |
| 302 | dv_reg LINK; |
| 303 | dv_reg LINKINTRAW; |
| 304 | dv_reg LINKINTMASKED; |
| 305 | u_int8_t RSVD0[8]; |
| 306 | dv_reg USERINTRAW; |
| 307 | dv_reg USERINTMASKED; |
| 308 | dv_reg USERINTMASKSET; |
| 309 | dv_reg USERINTMASKCLEAR; |
| 310 | u_int8_t RSVD1[80]; |
| 311 | dv_reg USERACCESS0; |
| 312 | dv_reg USERPHYSEL0; |
| 313 | dv_reg USERACCESS1; |
| 314 | dv_reg USERPHYSEL1; |
| 315 | } mdio_regs; |
| 316 | |
Jean-Christophe PLAGNIOL-VILLARD | bcf268b | 2008-08-31 04:45:42 +0200 | [diff] [blame] | 317 | int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data); |
| 318 | int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data); |
Sergey Kubushyn | e8f3912 | 2007-08-10 20:26:18 +0200 | [diff] [blame] | 319 | |
| 320 | typedef struct |
| 321 | { |
| 322 | char name[64]; |
| 323 | int (*init)(int phy_addr); |
| 324 | int (*is_phy_connected)(int phy_addr); |
| 325 | int (*get_link_speed)(int phy_addr); |
| 326 | int (*auto_negotiate)(int phy_addr); |
| 327 | } phy_t; |
| 328 | |
| 329 | #define PHY_LXT972 (0x001378e2) |
| 330 | int lxt972_is_phy_connected(int phy_addr); |
| 331 | int lxt972_get_link_speed(int phy_addr); |
| 332 | int lxt972_init_phy(int phy_addr); |
| 333 | int lxt972_auto_negotiate(int phy_addr); |
| 334 | |
| 335 | #define PHY_DP83848 (0x20005c90) |
| 336 | int dp83848_is_phy_connected(int phy_addr); |
| 337 | int dp83848_get_link_speed(int phy_addr); |
| 338 | int dp83848_init_phy(int phy_addr); |
| 339 | int dp83848_auto_negotiate(int phy_addr); |
| 340 | |
| 341 | #endif /* _DM644X_EMAC_H_ */ |