blob: ea52888ff45fe2434f1d0a9f1ca2e04e2dd1936d [file] [log] [blame]
Sergey Kubushyne8f39122007-08-10 20:26:18 +02001/*
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.come338f7e2009-05-12 11:45:34 -040041#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)
Nick Thompsond5ee6f62009-12-18 13:33:07 +000046#define DAVINCI_EMAC_VERSION2
47#elif defined(CONFIG_SOC_DA8XX)
48#define EMAC_BASE_ADDR DAVINCI_EMAC_CNTRL_REGS_BASE
49#define EMAC_WRAPPER_BASE_ADDR DAVINCI_EMAC_WRAPPER_CNTRL_REGS_BASE
50#define EMAC_WRAPPER_RAM_ADDR DAVINCI_EMAC_WRAPPER_RAM_BASE
51#define EMAC_MDIO_BASE_ADDR DAVINCI_MDIO_CNTRL_REGS_BASE
52#define DAVINCI_EMAC_VERSION2
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -040053#else
Sergey Kubushyne8f39122007-08-10 20:26:18 +020054#define EMAC_BASE_ADDR (0x01c80000)
55#define EMAC_WRAPPER_BASE_ADDR (0x01c81000)
56#define EMAC_WRAPPER_RAM_ADDR (0x01c82000)
57#define EMAC_MDIO_BASE_ADDR (0x01c84000)
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -040058#endif
Sergey Kubushyne8f39122007-08-10 20:26:18 +020059
Sandeep Paulraj310baca2009-09-18 17:30:05 -040060#ifdef CONFIG_SOC_DM646X
Nick Thompsond5ee6f62009-12-18 13:33:07 +000061#define DAVINCI_EMAC_VERSION2
62#define DAVINCI_EMAC_GIG_ENABLE
63#endif
64
65#ifdef CONFIG_SOC_DM646X
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -040066/* MDIO module input frequency */
67#define EMAC_MDIO_BUS_FREQ 76500000
68/* MDIO clock output frequency */
69#define EMAC_MDIO_CLOCK_FREQ 2500000 /* 2.5 MHz */
70#elif defined(CONFIG_SOC_DM365)
71/* MDIO module input frequency */
72#define EMAC_MDIO_BUS_FREQ 121500000
73/* MDIO clock output frequency */
74#define EMAC_MDIO_CLOCK_FREQ 2200000 /* 2.2 MHz */
Nick Thompsond5ee6f62009-12-18 13:33:07 +000075#elif defined(CONFIG_SOC_DA8XX)
76/* MDIO module input frequency */
77#define EMAC_MDIO_BUS_FREQ clk_get(DAVINCI_MDIO_CLKID)
78/* MDIO clock output frequency */
79#define EMAC_MDIO_CLOCK_FREQ 2000000 /* 2.0 MHz */
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -040080#else
Sergey Kubushyne8f39122007-08-10 20:26:18 +020081/* MDIO module input frequency */
82#define EMAC_MDIO_BUS_FREQ 99000000 /* PLL/6 - 99 MHz */
83/* MDIO clock output frequency */
84#define EMAC_MDIO_CLOCK_FREQ 2000000 /* 2.0 MHz */
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -040085#endif
86
Sergey Kubushyne8f39122007-08-10 20:26:18 +020087/* Ethernet Min/Max packet size */
88#define EMAC_MIN_ETHERNET_PKT_SIZE 60
89#define EMAC_MAX_ETHERNET_PKT_SIZE 1518
90#define EMAC_PKT_ALIGN 18 /* 1518 + 18 = 1536 (packet aligned on 32 byte boundry) */
91
92/* Number of RX packet buffers
93 * NOTE: Only 1 buffer supported as of now
94 */
95#define EMAC_MAX_RX_BUFFERS 10
96
97
98/***********************************************
99 ******** Internally used macros ***************
100 ***********************************************/
101
102#define EMAC_CH_TX 1
103#define EMAC_CH_RX 0
104
105/* Each descriptor occupies 4 words, lets start RX desc's at 0 and
106 * reserve space for 64 descriptors max
107 */
108#define EMAC_RX_DESC_BASE 0x0
109#define EMAC_TX_DESC_BASE 0x1000
110
111/* EMAC Teardown value */
112#define EMAC_TEARDOWN_VALUE 0xfffffffc
113
114/* MII Status Register */
115#define MII_STATUS_REG 1
116
117/* Number of statistics registers */
118#define EMAC_NUM_STATS 36
119
120
121/* EMAC Descriptor */
122typedef volatile struct _emac_desc
123{
124 u_int32_t next; /* Pointer to next descriptor in chain */
125 u_int8_t *buffer; /* Pointer to data buffer */
126 u_int32_t buff_off_len; /* Buffer Offset(MSW) and Length(LSW) */
127 u_int32_t pkt_flag_len; /* Packet Flags(MSW) and Length(LSW) */
128} emac_desc;
129
130/* CPPI bit positions */
131#define EMAC_CPPI_SOP_BIT (0x80000000)
132#define EMAC_CPPI_EOP_BIT (0x40000000)
133#define EMAC_CPPI_OWNERSHIP_BIT (0x20000000)
134#define EMAC_CPPI_EOQ_BIT (0x10000000)
135#define EMAC_CPPI_TEARDOWN_COMPLETE_BIT (0x08000000)
136#define EMAC_CPPI_PASS_CRC_BIT (0x04000000)
137
138#define EMAC_CPPI_RX_ERROR_FRAME (0x03fc0000)
139
140#define EMAC_MACCONTROL_MIIEN_ENABLE (0x20)
141#define EMAC_MACCONTROL_FULLDUPLEX_ENABLE (0x1)
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -0400142#define EMAC_MACCONTROL_GIGABIT_ENABLE (1 << 7)
143#define EMAC_MACCONTROL_GIGFORCE (1 << 17)
Nick Thompsond5ee6f62009-12-18 13:33:07 +0000144#define EMAC_MACCONTROL_RMIISPEED_100 (1 << 15)
145
146#define EMAC_MAC_ADDR_MATCH (1 << 19)
147#define EMAC_MAC_ADDR_IS_VALID (1 << 20)
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200148
149#define EMAC_RXMBPENABLE_RXCAFEN_ENABLE (0x200000)
150#define EMAC_RXMBPENABLE_RXBROADEN (0x2000)
151
152
153#define MDIO_CONTROL_IDLE (0x80000000)
154#define MDIO_CONTROL_ENABLE (0x40000000)
155#define MDIO_CONTROL_FAULT_ENABLE (0x40000)
156#define MDIO_CONTROL_FAULT (0x80000)
157#define MDIO_USERACCESS0_GO (0x80000000)
158#define MDIO_USERACCESS0_WRITE_READ (0x0)
159#define MDIO_USERACCESS0_WRITE_WRITE (0x40000000)
160#define MDIO_USERACCESS0_ACK (0x20000000)
161
162/* Ethernet MAC Registers Structure */
163typedef struct {
164 dv_reg TXIDVER;
165 dv_reg TXCONTROL;
166 dv_reg TXTEARDOWN;
167 u_int8_t RSVD0[4];
168 dv_reg RXIDVER;
169 dv_reg RXCONTROL;
170 dv_reg RXTEARDOWN;
171 u_int8_t RSVD1[100];
172 dv_reg TXINTSTATRAW;
173 dv_reg TXINTSTATMASKED;
174 dv_reg TXINTMASKSET;
175 dv_reg TXINTMASKCLEAR;
176 dv_reg MACINVECTOR;
177 u_int8_t RSVD2[12];
178 dv_reg RXINTSTATRAW;
179 dv_reg RXINTSTATMASKED;
180 dv_reg RXINTMASKSET;
181 dv_reg RXINTMASKCLEAR;
182 dv_reg MACINTSTATRAW;
183 dv_reg MACINTSTATMASKED;
184 dv_reg MACINTMASKSET;
185 dv_reg MACINTMASKCLEAR;
186 u_int8_t RSVD3[64];
187 dv_reg RXMBPENABLE;
188 dv_reg RXUNICASTSET;
189 dv_reg RXUNICASTCLEAR;
190 dv_reg RXMAXLEN;
191 dv_reg RXBUFFEROFFSET;
192 dv_reg RXFILTERLOWTHRESH;
193 u_int8_t RSVD4[8];
194 dv_reg RX0FLOWTHRESH;
195 dv_reg RX1FLOWTHRESH;
196 dv_reg RX2FLOWTHRESH;
197 dv_reg RX3FLOWTHRESH;
198 dv_reg RX4FLOWTHRESH;
199 dv_reg RX5FLOWTHRESH;
200 dv_reg RX6FLOWTHRESH;
201 dv_reg RX7FLOWTHRESH;
202 dv_reg RX0FREEBUFFER;
203 dv_reg RX1FREEBUFFER;
204 dv_reg RX2FREEBUFFER;
205 dv_reg RX3FREEBUFFER;
206 dv_reg RX4FREEBUFFER;
207 dv_reg RX5FREEBUFFER;
208 dv_reg RX6FREEBUFFER;
209 dv_reg RX7FREEBUFFER;
210 dv_reg MACCONTROL;
211 dv_reg MACSTATUS;
212 dv_reg EMCONTROL;
213 dv_reg FIFOCONTROL;
214 dv_reg MACCONFIG;
215 dv_reg SOFTRESET;
216 u_int8_t RSVD5[88];
217 dv_reg MACSRCADDRLO;
218 dv_reg MACSRCADDRHI;
219 dv_reg MACHASH1;
220 dv_reg MACHASH2;
221 dv_reg BOFFTEST;
222 dv_reg TPACETEST;
223 dv_reg RXPAUSE;
224 dv_reg TXPAUSE;
225 u_int8_t RSVD6[16];
226 dv_reg RXGOODFRAMES;
227 dv_reg RXBCASTFRAMES;
228 dv_reg RXMCASTFRAMES;
229 dv_reg RXPAUSEFRAMES;
230 dv_reg RXCRCERRORS;
231 dv_reg RXALIGNCODEERRORS;
232 dv_reg RXOVERSIZED;
233 dv_reg RXJABBER;
234 dv_reg RXUNDERSIZED;
235 dv_reg RXFRAGMENTS;
236 dv_reg RXFILTERED;
237 dv_reg RXQOSFILTERED;
238 dv_reg RXOCTETS;
239 dv_reg TXGOODFRAMES;
240 dv_reg TXBCASTFRAMES;
241 dv_reg TXMCASTFRAMES;
242 dv_reg TXPAUSEFRAMES;
243 dv_reg TXDEFERRED;
244 dv_reg TXCOLLISION;
245 dv_reg TXSINGLECOLL;
246 dv_reg TXMULTICOLL;
247 dv_reg TXEXCESSIVECOLL;
248 dv_reg TXLATECOLL;
249 dv_reg TXUNDERRUN;
250 dv_reg TXCARRIERSENSE;
251 dv_reg TXOCTETS;
252 dv_reg FRAME64;
253 dv_reg FRAME65T127;
254 dv_reg FRAME128T255;
255 dv_reg FRAME256T511;
256 dv_reg FRAME512T1023;
257 dv_reg FRAME1024TUP;
258 dv_reg NETOCTETS;
259 dv_reg RXSOFOVERRUNS;
260 dv_reg RXMOFOVERRUNS;
261 dv_reg RXDMAOVERRUNS;
262 u_int8_t RSVD7[624];
263 dv_reg MACADDRLO;
264 dv_reg MACADDRHI;
265 dv_reg MACINDEX;
266 u_int8_t RSVD8[244];
267 dv_reg TX0HDP;
268 dv_reg TX1HDP;
269 dv_reg TX2HDP;
270 dv_reg TX3HDP;
271 dv_reg TX4HDP;
272 dv_reg TX5HDP;
273 dv_reg TX6HDP;
274 dv_reg TX7HDP;
275 dv_reg RX0HDP;
276 dv_reg RX1HDP;
277 dv_reg RX2HDP;
278 dv_reg RX3HDP;
279 dv_reg RX4HDP;
280 dv_reg RX5HDP;
281 dv_reg RX6HDP;
282 dv_reg RX7HDP;
283 dv_reg TX0CP;
284 dv_reg TX1CP;
285 dv_reg TX2CP;
286 dv_reg TX3CP;
287 dv_reg TX4CP;
288 dv_reg TX5CP;
289 dv_reg TX6CP;
290 dv_reg TX7CP;
291 dv_reg RX0CP;
292 dv_reg RX1CP;
293 dv_reg RX2CP;
294 dv_reg RX3CP;
295 dv_reg RX4CP;
296 dv_reg RX5CP;
297 dv_reg RX6CP;
298 dv_reg RX7CP;
299} emac_regs;
300
301/* EMAC Wrapper Registers Structure */
302typedef struct {
Nick Thompsond5ee6f62009-12-18 13:33:07 +0000303#ifdef DAVINCI_EMAC_VERSION2
304 dv_reg idver;
305 dv_reg softrst;
306 dv_reg emctrl;
307 dv_reg c0rxthreshen;
308 dv_reg c0rxen;
309 dv_reg c0txen;
310 dv_reg c0miscen;
311 dv_reg c1rxthreshen;
312 dv_reg c1rxen;
313 dv_reg c1txen;
314 dv_reg c1miscen;
315 dv_reg c2rxthreshen;
316 dv_reg c2rxen;
317 dv_reg c2txen;
318 dv_reg c2miscen;
319 dv_reg c0rxthreshstat;
320 dv_reg c0rxstat;
321 dv_reg c0txstat;
322 dv_reg c0miscstat;
323 dv_reg c1rxthreshstat;
324 dv_reg c1rxstat;
325 dv_reg c1txstat;
326 dv_reg c1miscstat;
327 dv_reg c2rxthreshstat;
328 dv_reg c2rxstat;
329 dv_reg c2txstat;
330 dv_reg c2miscstat;
331 dv_reg c0rximax;
332 dv_reg c0tximax;
333 dv_reg c1rximax;
334 dv_reg c1tximax;
335 dv_reg c2rximax;
336 dv_reg c2tximax;
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -0400337#else
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200338 u_int8_t RSVD0[4100];
339 dv_reg EWCTL;
340 dv_reg EWINTTCNT;
s-paulraj@ti.come338f7e2009-05-12 11:45:34 -0400341#endif
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200342} ewrap_regs;
343
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200344/* EMAC MDIO Registers Structure */
345typedef struct {
346 dv_reg VERSION;
347 dv_reg CONTROL;
348 dv_reg ALIVE;
349 dv_reg LINK;
350 dv_reg LINKINTRAW;
351 dv_reg LINKINTMASKED;
352 u_int8_t RSVD0[8];
353 dv_reg USERINTRAW;
354 dv_reg USERINTMASKED;
355 dv_reg USERINTMASKSET;
356 dv_reg USERINTMASKCLEAR;
357 u_int8_t RSVD1[80];
358 dv_reg USERACCESS0;
359 dv_reg USERPHYSEL0;
360 dv_reg USERACCESS1;
361 dv_reg USERPHYSEL1;
362} mdio_regs;
363
Jean-Christophe PLAGNIOL-VILLARDbcf268b2008-08-31 04:45:42 +0200364int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data);
365int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data);
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200366
367typedef struct
368{
369 char name[64];
370 int (*init)(int phy_addr);
371 int (*is_phy_connected)(int phy_addr);
372 int (*get_link_speed)(int phy_addr);
373 int (*auto_negotiate)(int phy_addr);
374} phy_t;
375
Heiko Schochera1a218e2011-09-18 19:49:25 +0000376#define PHY_KSZ8873 (0x00221450)
377int ksz8873_is_phy_connected(int phy_addr);
378int ksz8873_get_link_speed(int phy_addr);
379int ksz8873_init_phy(int phy_addr);
380int ksz8873_auto_negotiate(int phy_addr);
381
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200382#define PHY_LXT972 (0x001378e2)
383int lxt972_is_phy_connected(int phy_addr);
384int lxt972_get_link_speed(int phy_addr);
385int lxt972_init_phy(int phy_addr);
386int lxt972_auto_negotiate(int phy_addr);
387
388#define PHY_DP83848 (0x20005c90)
389int dp83848_is_phy_connected(int phy_addr);
390int dp83848_get_link_speed(int phy_addr);
391int dp83848_init_phy(int phy_addr);
392int dp83848_auto_negotiate(int phy_addr);
393
Sandeep Paulraj3c86e5e2010-12-28 15:43:16 -0500394#define PHY_ET1011C (0x282f013)
395int et1011c_get_link_speed(int phy_addr);
396
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200397#endif /* _DM644X_EMAC_H_ */