blob: 182f84c38af74572985d14c13e92123952b0bdb1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy069fa832017-07-06 10:23:22 +02002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Christophe Leroy069fa832017-07-06 10:23:22 +02005 */
6
Christophe Leroy069fa832017-07-06 10:23:22 +02007#include <command.h>
Simon Glassf11478f2019-12-28 10:45:07 -07008#include <hang.h>
Christophe Leroy069fa832017-07-06 10:23:22 +02009#include <malloc.h>
10#include <net.h>
Christophe Leroy4a4750b2017-07-13 15:10:08 +020011#include <netdev.h>
Christophe Leroy10ff63a2018-03-16 17:20:43 +010012#include <asm/cpm_8xx.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020014#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020016
17#include <phy.h>
Simon Glasscaefa322019-11-14 12:57:31 -070018#include <linux/mii.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020019
20DECLARE_GLOBAL_DATA_PTR;
21
Christophe Leroy069fa832017-07-06 10:23:22 +020022/* define WANT_MII when MII support is required */
23#if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_FEC1_PHY) || defined(CONFIG_FEC2_PHY)
24#define WANT_MII
25#else
26#undef WANT_MII
27#endif
28
29#if defined(WANT_MII)
30#include <miiphy.h>
31
32#if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
33#error "CONFIG_MII has to be defined!"
34#endif
35
36#endif
37
38#if defined(CONFIG_RMII) && !defined(WANT_MII)
39#error RMII support is unusable without a working PHY.
40#endif
41
42#ifdef CONFIG_SYS_DISCOVER_PHY
Christophe Leroy69ef96d2022-05-12 15:48:51 +020043static int mii_discover_phy(struct udevice *dev);
Christophe Leroy069fa832017-07-06 10:23:22 +020044#endif
45
46int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg);
47int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
48 u16 value);
49
50static struct ether_fcc_info_s
51{
52 int ether_index;
53 int fecp_offset;
54 int phy_addr;
55 int actual_phy_addr;
56 int initialized;
57}
58 ether_fcc_info[] = {
59#if defined(CONFIG_ETHER_ON_FEC1)
60 {
61 0,
62 offsetof(immap_t, im_cpm.cp_fec1),
Christophe Leroy069fa832017-07-06 10:23:22 +020063 CONFIG_FEC1_PHY,
Christophe Leroy069fa832017-07-06 10:23:22 +020064 -1,
65 0,
66
67 },
68#endif
69#if defined(CONFIG_ETHER_ON_FEC2)
70 {
71 1,
72 offsetof(immap_t, im_cpm.cp_fec2),
Christophe Leroy069fa832017-07-06 10:23:22 +020073 CONFIG_FEC2_PHY,
Christophe Leroy069fa832017-07-06 10:23:22 +020074 -1,
75 0,
76 },
77#endif
78};
79
80/* Ethernet Transmit and Receive Buffers */
81#define DBUF_LENGTH 1520
82
83#define TX_BUF_CNT 2
84
85#define TOUT_LOOP 100
86
87#define PKT_MAXBUF_SIZE 1518
88#define PKT_MINBUF_SIZE 64
89#define PKT_MAXBLR_SIZE 1520
90
91#ifdef __GNUC__
Christophe Leroy48f896d2017-07-06 10:33:17 +020092static char txbuf[DBUF_LENGTH] __aligned(8);
Christophe Leroy069fa832017-07-06 10:23:22 +020093#else
94#error txbuf must be aligned.
95#endif
96
97static uint rxIdx; /* index of the current RX buffer */
98static uint txIdx; /* index of the current TX buffer */
99
100/*
101 * FEC Ethernet Tx and Rx buffer descriptors allocated at the
102 * immr->udata_bd address on Dual-Port RAM
103 * Provide for Double Buffering
104 */
105
Christophe Leroy394f9b32017-07-06 10:33:13 +0200106struct common_buf_desc {
Christophe Leroy48f896d2017-07-06 10:33:17 +0200107 cbd_t rxbd[PKTBUFSRX]; /* Rx BD */
108 cbd_t txbd[TX_BUF_CNT]; /* Tx BD */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200109};
Christophe Leroy069fa832017-07-06 10:23:22 +0200110
Christophe Leroy394f9b32017-07-06 10:33:13 +0200111static struct common_buf_desc __iomem *rtx;
Christophe Leroy069fa832017-07-06 10:23:22 +0200112
Christophe Leroy069fa832017-07-06 10:23:22 +0200113#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
114static void __mii_init(void);
115#endif
116
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200117static int fec_probe(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200118{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200119 struct ether_fcc_info_s *efis = dev_get_priv(dev);
120 int index = dev_get_driver_data(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200121 int i;
122
123 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++) {
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200124 if (ether_fcc_info[i].ether_index != index)
125 continue;
Christophe Leroy069fa832017-07-06 10:23:22 +0200126
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200127 memcpy(efis, &ether_fcc_info[i], sizeof(*efis));
Christophe Leroy069fa832017-07-06 10:23:22 +0200128
Christophe Leroy069fa832017-07-06 10:23:22 +0200129 efis->actual_phy_addr = -1;
130
Christophe Leroy069fa832017-07-06 10:23:22 +0200131#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
132 int retval;
133 struct mii_dev *mdiodev = mdio_alloc();
134 if (!mdiodev)
135 return -ENOMEM;
Vladimir Oltean1e70f9f2021-09-27 14:21:53 +0300136 strlcpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
Christophe Leroy069fa832017-07-06 10:23:22 +0200137 mdiodev->read = fec8xx_miiphy_read;
138 mdiodev->write = fec8xx_miiphy_write;
139
140 retval = mdio_register(mdiodev);
141 if (retval < 0)
142 return retval;
143#endif
144 }
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200145 return 0;
Christophe Leroy069fa832017-07-06 10:23:22 +0200146}
147
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200148static int fec_send(struct udevice *dev, void *packet, int length)
Christophe Leroy069fa832017-07-06 10:23:22 +0200149{
150 int j, rc;
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200151 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200152 fec_t __iomem *fecp =
153 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
Christophe Leroy069fa832017-07-06 10:23:22 +0200154
155 /* section 16.9.23.3
156 * Wait for ready
157 */
158 j = 0;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200159 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
160 (j < TOUT_LOOP)) {
Christophe Leroy069fa832017-07-06 10:23:22 +0200161 udelay(1);
162 j++;
163 }
Christophe Leroy48f896d2017-07-06 10:33:17 +0200164 if (j >= TOUT_LOOP)
Christophe Leroy069fa832017-07-06 10:23:22 +0200165 printf("TX not ready\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200166
Christophe Leroy394f9b32017-07-06 10:33:13 +0200167 out_be32(&rtx->txbd[txIdx].cbd_bufaddr, (uint)packet);
168 out_be16(&rtx->txbd[txIdx].cbd_datlen, length);
169 setbits_be16(&rtx->txbd[txIdx].cbd_sc,
170 BD_ENET_TX_READY | BD_ENET_TX_LAST);
Christophe Leroy069fa832017-07-06 10:23:22 +0200171
172 /* Activate transmit Buffer Descriptor polling */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200173 /* Descriptor polling active */
174 out_be32(&fecp->fec_x_des_active, 0x01000000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200175
176 j = 0;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200177 while ((in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_READY) &&
178 (j < TOUT_LOOP)) {
Christophe Leroy069fa832017-07-06 10:23:22 +0200179 udelay(1);
180 j++;
181 }
Christophe Leroy48f896d2017-07-06 10:33:17 +0200182 if (j >= TOUT_LOOP)
Christophe Leroy069fa832017-07-06 10:23:22 +0200183 printf("TX timeout\n");
Christophe Leroy48f896d2017-07-06 10:33:17 +0200184
Christophe Leroy069fa832017-07-06 10:23:22 +0200185 /* return only status bits */;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200186 rc = in_be16(&rtx->txbd[txIdx].cbd_sc) & BD_ENET_TX_STATS;
Christophe Leroy069fa832017-07-06 10:23:22 +0200187
188 txIdx = (txIdx + 1) % TX_BUF_CNT;
189
190 return rc;
191}
192
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200193static int fec_recv(struct udevice *dev, int flags, uchar **packetp)
Christophe Leroy069fa832017-07-06 10:23:22 +0200194{
Christophe Leroy069fa832017-07-06 10:23:22 +0200195 int length;
196
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200197 /* section 16.9.23.2 */
198 if (in_be16(&rtx->rxbd[rxIdx].cbd_sc) & BD_ENET_RX_EMPTY)
199 return -EAGAIN;
Christophe Leroy069fa832017-07-06 10:23:22 +0200200
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200201 length = in_be16(&rtx->rxbd[rxIdx].cbd_datlen);
Christophe Leroy069fa832017-07-06 10:23:22 +0200202
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200203 if (!(in_be16(&rtx->rxbd[rxIdx].cbd_sc) & 0x003f)) {
204 uchar *rx = net_rx_packets[rxIdx];
Christophe Leroy069fa832017-07-06 10:23:22 +0200205
206#if defined(CONFIG_CMD_CDP)
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200207 if ((rx[0] & 1) != 0 &&
208 memcmp((uchar *)rx, net_bcast_ethaddr, 6) != 0 &&
209 !is_cdp_packet((uchar *)rx))
210 return 0;
Christophe Leroy069fa832017-07-06 10:23:22 +0200211#endif
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200212 *packetp = rx;
Christophe Leroy069fa832017-07-06 10:23:22 +0200213
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200214 return length - 4;
215 } else {
216 return 0;
217 }
218}
Christophe Leroy069fa832017-07-06 10:23:22 +0200219
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200220static int fec_free_pkt(struct udevice *dev, uchar *packet, int length)
221{
222 struct ether_fcc_info_s *efis = dev_get_priv(dev);
223 fec_t __iomem *fecp =
224 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
225
226 /* Give the buffer back to the FEC. */
227 out_be16(&rtx->rxbd[rxIdx].cbd_datlen, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200228
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200229 /* wrap around buffer index when necessary */
230 if ((rxIdx + 1) >= PKTBUFSRX) {
231 out_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc,
232 BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
233 rxIdx = 0;
234 } else {
235 out_be16(&rtx->rxbd[rxIdx].cbd_sc, BD_ENET_RX_EMPTY);
236 rxIdx++;
Christophe Leroy069fa832017-07-06 10:23:22 +0200237 }
238
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200239 /* Try to fill Buffer Descriptors */
240 /* Descriptor polling active */
241 out_be32(&fecp->fec_r_des_active, 0x01000000);
242
243 return 0;
Christophe Leroy069fa832017-07-06 10:23:22 +0200244}
245
246/**************************************************************
247 *
248 * FEC Ethernet Initialization Routine
249 *
250 *************************************************************/
251
252#define FEC_ECNTRL_PINMUX 0x00000004
253#define FEC_ECNTRL_ETHER_EN 0x00000002
254#define FEC_ECNTRL_RESET 0x00000001
255
256#define FEC_RCNTRL_BC_REJ 0x00000010
257#define FEC_RCNTRL_PROM 0x00000008
258#define FEC_RCNTRL_MII_MODE 0x00000004
259#define FEC_RCNTRL_DRT 0x00000002
260#define FEC_RCNTRL_LOOP 0x00000001
261
262#define FEC_TCNTRL_FDEN 0x00000004
263#define FEC_TCNTRL_HBC 0x00000002
264#define FEC_TCNTRL_GTS 0x00000001
265
266#define FEC_RESET_DELAY 50
267
268#if defined(CONFIG_RMII)
269
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200270static inline void fec_10Mbps(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200271{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200272 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200273 int fecidx = efis->ether_index;
274 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200275 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200276
277 if ((unsigned int)fecidx >= 2)
278 hang();
279
Christophe Leroy394f9b32017-07-06 10:33:13 +0200280 setbits_be32(&immr->im_cpm.cp_cptr, mask);
Christophe Leroy069fa832017-07-06 10:23:22 +0200281}
282
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200283static inline void fec_100Mbps(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200284{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200285 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200286 int fecidx = efis->ether_index;
287 uint mask = (fecidx == 0) ? 0x0000010 : 0x0000008;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200288 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200289
290 if ((unsigned int)fecidx >= 2)
291 hang();
292
Christophe Leroy394f9b32017-07-06 10:33:13 +0200293 clrbits_be32(&immr->im_cpm.cp_cptr, mask);
Christophe Leroy069fa832017-07-06 10:23:22 +0200294}
295
296#endif
297
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200298static inline void fec_full_duplex(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200299{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200300 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200301 fec_t __iomem *fecp =
302 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
Christophe Leroy069fa832017-07-06 10:23:22 +0200303
Christophe Leroy394f9b32017-07-06 10:33:13 +0200304 clrbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
305 setbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
Christophe Leroy069fa832017-07-06 10:23:22 +0200306}
307
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200308static inline void fec_half_duplex(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200309{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200310 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200311 fec_t __iomem *fecp =
312 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
Christophe Leroy069fa832017-07-06 10:23:22 +0200313
Christophe Leroy394f9b32017-07-06 10:33:13 +0200314 setbits_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_DRT);
315 clrbits_be32(&fecp->fec_x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
Christophe Leroy069fa832017-07-06 10:23:22 +0200316}
317
318static void fec_pin_init(int fecidx)
319{
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900320 struct bd_info *bd = gd->bd;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200321 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200322
323 /*
324 * Set MII speed to 2.5 MHz or slightly below.
325 *
326 * According to the MPC860T (Rev. D) Fast ethernet controller user
327 * manual (6.2.14),
328 * the MII management interface clock must be less than or equal
329 * to 2.5 MHz.
330 * This MDC frequency is equal to system clock / (2 * MII_SPEED).
331 * Then MII_SPEED = system_clock / 2 * 2,5 MHz.
332 *
333 * All MII configuration is done via FEC1 registers:
334 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200335 out_be32(&immr->im_cpm.cp_fec1.fec_mii_speed,
336 ((bd->bi_intfreq + 4999999) / 5000000) << 1);
Christophe Leroy069fa832017-07-06 10:23:22 +0200337
Christophe Leroy23da3732017-07-06 10:33:21 +0200338#if defined(CONFIG_MPC885) && defined(WANT_MII)
Christophe Leroy069fa832017-07-06 10:23:22 +0200339 /* use MDC for MII */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200340 setbits_be16(&immr->im_ioport.iop_pdpar, 0x0080);
341 clrbits_be16(&immr->im_ioport.iop_pddir, 0x0080);
Christophe Leroy069fa832017-07-06 10:23:22 +0200342#endif
343
344 if (fecidx == 0) {
345#if defined(CONFIG_ETHER_ON_FEC1)
346
Christophe Leroy23da3732017-07-06 10:33:21 +0200347#if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
Christophe Leroy069fa832017-07-06 10:23:22 +0200348
349#if !defined(CONFIG_RMII)
350
Christophe Leroy394f9b32017-07-06 10:33:13 +0200351 setbits_be16(&immr->im_ioport.iop_papar, 0xf830);
352 setbits_be16(&immr->im_ioport.iop_padir, 0x0830);
353 clrbits_be16(&immr->im_ioport.iop_padir, 0xf000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200354
Christophe Leroy394f9b32017-07-06 10:33:13 +0200355 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00001001);
356 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00001001);
Christophe Leroy069fa832017-07-06 10:23:22 +0200357
Christophe Leroy394f9b32017-07-06 10:33:13 +0200358 setbits_be16(&immr->im_ioport.iop_pcpar, 0x000c);
359 clrbits_be16(&immr->im_ioport.iop_pcdir, 0x000c);
Christophe Leroy069fa832017-07-06 10:23:22 +0200360
Christophe Leroy394f9b32017-07-06 10:33:13 +0200361 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000003);
362 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000003);
363 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000003);
Christophe Leroy069fa832017-07-06 10:23:22 +0200364
Christophe Leroy394f9b32017-07-06 10:33:13 +0200365 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
Christophe Leroy069fa832017-07-06 10:23:22 +0200366
367#else
368
369#if !defined(CONFIG_FEC1_PHY_NORXERR)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200370 setbits_be16(&immr->im_ioport.iop_papar, 0x1000);
371 clrbits_be16(&immr->im_ioport.iop_padir, 0x1000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200372#endif
Christophe Leroy394f9b32017-07-06 10:33:13 +0200373 setbits_be16(&immr->im_ioport.iop_papar, 0xe810);
374 setbits_be16(&immr->im_ioport.iop_padir, 0x0810);
375 clrbits_be16(&immr->im_ioport.iop_padir, 0xe000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200376
Christophe Leroy394f9b32017-07-06 10:33:13 +0200377 setbits_be32(&immr->im_cpm.cp_pbpar, 0x00000001);
378 clrbits_be32(&immr->im_cpm.cp_pbdir, 0x00000001);
Christophe Leroy069fa832017-07-06 10:23:22 +0200379
Christophe Leroy394f9b32017-07-06 10:33:13 +0200380 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000100);
381 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000050);
Christophe Leroy069fa832017-07-06 10:23:22 +0200382
383#endif /* !CONFIG_RMII */
384
385#else
386 /*
387 * Configure all of port D for MII.
388 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200389 out_be16(&immr->im_ioport.iop_pdpar, 0x1fff);
390 out_be16(&immr->im_ioport.iop_pddir, 0x1fff);
Christophe Leroy35982952017-07-07 10:16:42 +0200391
392#if defined(CONFIG_TARGET_MCR3000)
393 out_be16(&immr->im_ioport.iop_papar, 0xBBFF);
394 out_be16(&immr->im_ioport.iop_padir, 0x04F0);
395 out_be16(&immr->im_ioport.iop_paodr, 0x0000);
396
397 out_be32(&immr->im_cpm.cp_pbpar, 0x000133FF);
398 out_be32(&immr->im_cpm.cp_pbdir, 0x0003BF0F);
399 out_be16(&immr->im_cpm.cp_pbodr, 0x0000);
400
401 out_be16(&immr->im_ioport.iop_pcpar, 0x0400);
402 out_be16(&immr->im_ioport.iop_pcdir, 0x0080);
403 out_be16(&immr->im_ioport.iop_pcso , 0x0D53);
404 out_be16(&immr->im_ioport.iop_pcint, 0x0000);
405
406 out_be16(&immr->im_ioport.iop_pdpar, 0x03FE);
407 out_be16(&immr->im_ioport.iop_pddir, 0x1C09);
408
409 setbits_be32(&immr->im_ioport.utmode, 0x80);
410#endif
Christophe Leroy069fa832017-07-06 10:23:22 +0200411#endif
412
413#endif /* CONFIG_ETHER_ON_FEC1 */
414 } else if (fecidx == 1) {
Christophe Leroy069fa832017-07-06 10:23:22 +0200415#if defined(CONFIG_ETHER_ON_FEC2)
416
Christophe Leroy23da3732017-07-06 10:33:21 +0200417#if defined(CONFIG_MPC885) /* MPC87x/88x have got 2 FECs and different pinout */
Christophe Leroy069fa832017-07-06 10:23:22 +0200418
419#if !defined(CONFIG_RMII)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200420 setbits_be32(&immr->im_cpm.cp_pepar, 0x0003fffc);
421 setbits_be32(&immr->im_cpm.cp_pedir, 0x0003fffc);
422 clrbits_be32(&immr->im_cpm.cp_peso, 0x000087fc);
423 setbits_be32(&immr->im_cpm.cp_peso, 0x00037800);
Christophe Leroy069fa832017-07-06 10:23:22 +0200424
Christophe Leroy394f9b32017-07-06 10:33:13 +0200425 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
Christophe Leroy069fa832017-07-06 10:23:22 +0200426#else
427
428#if !defined(CONFIG_FEC2_PHY_NORXERR)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200429 setbits_be32(&immr->im_cpm.cp_pepar, 0x00000010);
430 setbits_be32(&immr->im_cpm.cp_pedir, 0x00000010);
431 clrbits_be32(&immr->im_cpm.cp_peso, 0x00000010);
Christophe Leroy069fa832017-07-06 10:23:22 +0200432#endif
Christophe Leroy394f9b32017-07-06 10:33:13 +0200433 setbits_be32(&immr->im_cpm.cp_pepar, 0x00039620);
434 setbits_be32(&immr->im_cpm.cp_pedir, 0x00039620);
435 setbits_be32(&immr->im_cpm.cp_peso, 0x00031000);
436 clrbits_be32(&immr->im_cpm.cp_peso, 0x00008620);
Christophe Leroy069fa832017-07-06 10:23:22 +0200437
Christophe Leroy394f9b32017-07-06 10:33:13 +0200438 setbits_be32(&immr->im_cpm.cp_cptr, 0x00000080);
439 clrbits_be32(&immr->im_cpm.cp_cptr, 0x00000028);
Christophe Leroy069fa832017-07-06 10:23:22 +0200440#endif /* CONFIG_RMII */
441
Christophe Leroy23da3732017-07-06 10:33:21 +0200442#endif /* CONFIG_MPC885 */
Christophe Leroy069fa832017-07-06 10:23:22 +0200443
444#endif /* CONFIG_ETHER_ON_FEC2 */
Christophe Leroy069fa832017-07-06 10:23:22 +0200445 }
446}
447
Christophe Leroy394f9b32017-07-06 10:33:13 +0200448static int fec_reset(fec_t __iomem *fecp)
Christophe Leroy069fa832017-07-06 10:23:22 +0200449{
450 int i;
451
452 /* Whack a reset.
453 * A delay is required between a reset of the FEC block and
454 * initialization of other FEC registers because the reset takes
455 * some time to complete. If you don't delay, subsequent writes
456 * to FEC registers might get killed by the reset routine which is
457 * still in progress.
458 */
459
Christophe Leroy394f9b32017-07-06 10:33:13 +0200460 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
461 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
462 (i < FEC_RESET_DELAY); ++i)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200463 udelay(1);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200464
Christophe Leroy069fa832017-07-06 10:23:22 +0200465 if (i == FEC_RESET_DELAY)
466 return -1;
467
468 return 0;
469}
470
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200471static int fec_start(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200472{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200473 struct eth_pdata *plat = dev_get_plat(dev);
474 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200475 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
476 fec_t __iomem *fecp =
477 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
Christophe Leroy069fa832017-07-06 10:23:22 +0200478 int i;
479
480#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
481 /* the MII interface is connected to FEC1
482 * so for the miiphy_xxx function to work we must
483 * call mii_init since fec_halt messes the thing up
484 */
485 if (efis->ether_index != 0)
486 __mii_init();
487#endif
488
489 if (fec_reset(fecp) < 0)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200490 printf("FEC_RESET_DELAY timeout\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200491
492 /* We use strictly polling mode only
493 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200494 out_be32(&fecp->fec_imask, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200495
496 /* Clear any pending interrupt
497 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200498 out_be32(&fecp->fec_ievent, 0xffc0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200499
500 /* No need to set the IVEC register */
501
502 /* Set station address
503 */
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200504#define ea plat->enetaddr
Christophe Leroy394f9b32017-07-06 10:33:13 +0200505 out_be32(&fecp->fec_addr_low, (ea[0] << 24) | (ea[1] << 16) |
506 (ea[2] << 8) | ea[3]);
507 out_be16(&fecp->fec_addr_high, (ea[4] << 8) | ea[5]);
Christophe Leroy069fa832017-07-06 10:23:22 +0200508#undef ea
509
510#if defined(CONFIG_CMD_CDP)
511 /*
512 * Turn on multicast address hash table
513 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200514 out_be32(&fecp->fec_hash_table_high, 0xffffffff);
515 out_be32(&fecp->fec_hash_table_low, 0xffffffff);
Christophe Leroy069fa832017-07-06 10:23:22 +0200516#else
517 /* Clear multicast address hash table
518 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200519 out_be32(&fecp->fec_hash_table_high, 0);
520 out_be32(&fecp->fec_hash_table_low, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200521#endif
522
523 /* Set maximum receive buffer size.
524 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200525 out_be32(&fecp->fec_r_buff_size, PKT_MAXBLR_SIZE);
Christophe Leroy069fa832017-07-06 10:23:22 +0200526
527 /* Set maximum frame length
528 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200529 out_be32(&fecp->fec_r_hash, PKT_MAXBUF_SIZE);
Christophe Leroy069fa832017-07-06 10:23:22 +0200530
531 /*
Christophe Leroy48f896d2017-07-06 10:33:17 +0200532 * Setup Buffers and Buffer Descriptors
Christophe Leroy069fa832017-07-06 10:23:22 +0200533 */
534 rxIdx = 0;
535 txIdx = 0;
536
537 if (!rtx)
Christophe Leroy394f9b32017-07-06 10:33:13 +0200538 rtx = (struct common_buf_desc __iomem *)
539 (immr->im_cpm.cp_dpmem + CPM_FEC_BASE);
Christophe Leroy069fa832017-07-06 10:23:22 +0200540 /*
541 * Setup Receiver Buffer Descriptors (13.14.24.18)
542 * Settings:
543 * Empty, Wrap
544 */
545 for (i = 0; i < PKTBUFSRX; i++) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200546 out_be16(&rtx->rxbd[i].cbd_sc, BD_ENET_RX_EMPTY);
547 out_be16(&rtx->rxbd[i].cbd_datlen, 0); /* Reset */
548 out_be32(&rtx->rxbd[i].cbd_bufaddr, (uint)net_rx_packets[i]);
Christophe Leroy069fa832017-07-06 10:23:22 +0200549 }
Christophe Leroy394f9b32017-07-06 10:33:13 +0200550 setbits_be16(&rtx->rxbd[PKTBUFSRX - 1].cbd_sc, BD_ENET_RX_WRAP);
Christophe Leroy069fa832017-07-06 10:23:22 +0200551
552 /*
553 * Setup Ethernet Transmitter Buffer Descriptors (13.14.24.19)
554 * Settings:
555 * Last, Tx CRC
556 */
557 for (i = 0; i < TX_BUF_CNT; i++) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200558 out_be16(&rtx->txbd[i].cbd_sc, BD_ENET_TX_LAST | BD_ENET_TX_TC);
559 out_be16(&rtx->txbd[i].cbd_datlen, 0); /* Reset */
560 out_be32(&rtx->txbd[i].cbd_bufaddr, (uint)txbuf);
Christophe Leroy069fa832017-07-06 10:23:22 +0200561 }
Christophe Leroy394f9b32017-07-06 10:33:13 +0200562 setbits_be16(&rtx->txbd[TX_BUF_CNT - 1].cbd_sc, BD_ENET_TX_WRAP);
Christophe Leroy069fa832017-07-06 10:23:22 +0200563
564 /* Set receive and transmit descriptor base
565 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200566 out_be32(&fecp->fec_r_des_start, (__force unsigned int)rtx->rxbd);
567 out_be32(&fecp->fec_x_des_start, (__force unsigned int)rtx->txbd);
Christophe Leroy069fa832017-07-06 10:23:22 +0200568
569 /* Enable MII mode
570 */
571 /* Half duplex mode */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200572 out_be32(&fecp->fec_r_cntrl, FEC_RCNTRL_MII_MODE | FEC_RCNTRL_DRT);
573 out_be32(&fecp->fec_x_cntrl, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200574
575 /* Enable big endian and don't care about SDMA FC.
576 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200577 out_be32(&fecp->fec_fun_code, 0x78000000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200578
579 /*
580 * Setup the pin configuration of the FEC
581 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200582 fec_pin_init(efis->ether_index);
Christophe Leroy069fa832017-07-06 10:23:22 +0200583
584 rxIdx = 0;
585 txIdx = 0;
586
587 /*
588 * Now enable the transmit and receive processing
589 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200590 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
Christophe Leroy069fa832017-07-06 10:23:22 +0200591
592 if (efis->phy_addr == -1) {
593#ifdef CONFIG_SYS_DISCOVER_PHY
594 /*
595 * wait for the PHY to wake up after reset
596 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200597 efis->actual_phy_addr = mii_discover_phy(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200598
599 if (efis->actual_phy_addr == -1) {
Christophe Leroy48f896d2017-07-06 10:33:17 +0200600 printf("Unable to discover phy!\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200601 return -1;
602 }
603#else
604 efis->actual_phy_addr = -1;
605#endif
606 } else {
607 efis->actual_phy_addr = efis->phy_addr;
608 }
609
610#if defined(CONFIG_MII) && defined(CONFIG_RMII)
611 /*
612 * adapt the RMII speed to the speed of the phy
613 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200614 if (miiphy_speed(dev->name, efis->actual_phy_addr) == _100BASET)
615 fec_100Mbps(dev);
616 else
617 fec_10Mbps(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200618#endif
619
620#if defined(CONFIG_MII)
621 /*
622 * adapt to the half/full speed settings
623 */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200624 if (miiphy_duplex(dev->name, efis->actual_phy_addr) == FULL)
625 fec_full_duplex(dev);
626 else
627 fec_half_duplex(dev);
Christophe Leroy069fa832017-07-06 10:23:22 +0200628#endif
629
630 /* And last, try to fill Rx Buffer Descriptors */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200631 /* Descriptor polling active */
632 out_be32(&fecp->fec_r_des_active, 0x01000000);
Christophe Leroy069fa832017-07-06 10:23:22 +0200633
634 efis->initialized = 1;
635
636 return 0;
637}
638
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200639static void fec_stop(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200640{
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200641 struct ether_fcc_info_s *efis = dev_get_priv(dev);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200642 fec_t __iomem *fecp =
643 (fec_t __iomem *)(CONFIG_SYS_IMMR + efis->fecp_offset);
Christophe Leroy069fa832017-07-06 10:23:22 +0200644 int i;
645
646 /* avoid halt if initialized; mii gets stuck otherwise */
647 if (!efis->initialized)
648 return;
649
650 /* Whack a reset.
651 * A delay is required between a reset of the FEC block and
652 * initialization of other FEC registers because the reset takes
653 * some time to complete. If you don't delay, subsequent writes
654 * to FEC registers might get killed by the reset routine which is
655 * still in progress.
656 */
657
Christophe Leroy394f9b32017-07-06 10:33:13 +0200658 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
659 for (i = 0; (in_be32(&fecp->fec_ecntrl) & FEC_ECNTRL_RESET) &&
660 (i < FEC_RESET_DELAY); ++i)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200661 udelay(1);
Christophe Leroy394f9b32017-07-06 10:33:13 +0200662
Christophe Leroy069fa832017-07-06 10:23:22 +0200663 if (i == FEC_RESET_DELAY) {
Christophe Leroy48f896d2017-07-06 10:33:17 +0200664 printf("FEC_RESET_DELAY timeout\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200665 return;
666 }
667
668 efis->initialized = 0;
669}
670
671#if defined(CONFIG_SYS_DISCOVER_PHY) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
672
673/* Make MII read/write commands for the FEC.
674*/
675
676#define mk_mii_read(ADDR, REG) (0x60020000 | ((ADDR << 23) | \
677 (REG & 0x1f) << 18))
678
679#define mk_mii_write(ADDR, REG, VAL) (0x50020000 | ((ADDR << 23) | \
680 (REG & 0x1f) << 18) | \
681 (VAL & 0xffff))
682
683/* Interrupt events/masks.
684*/
685#define FEC_ENET_HBERR ((uint)0x80000000) /* Heartbeat error */
686#define FEC_ENET_BABR ((uint)0x40000000) /* Babbling receiver */
687#define FEC_ENET_BABT ((uint)0x20000000) /* Babbling transmitter */
688#define FEC_ENET_GRA ((uint)0x10000000) /* Graceful stop complete */
689#define FEC_ENET_TXF ((uint)0x08000000) /* Full frame transmitted */
690#define FEC_ENET_TXB ((uint)0x04000000) /* A buffer was transmitted */
691#define FEC_ENET_RXF ((uint)0x02000000) /* Full frame received */
692#define FEC_ENET_RXB ((uint)0x01000000) /* A buffer was received */
693#define FEC_ENET_MII ((uint)0x00800000) /* MII interrupt */
694#define FEC_ENET_EBERR ((uint)0x00400000) /* SDMA bus error */
695
696/* send command to phy using mii, wait for result */
697static uint
698mii_send(uint mii_cmd)
699{
700 uint mii_reply;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200701 fec_t __iomem *ep;
Christophe Leroy069fa832017-07-06 10:23:22 +0200702 int cnt;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200703 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroy069fa832017-07-06 10:23:22 +0200704
Christophe Leroy394f9b32017-07-06 10:33:13 +0200705 ep = &immr->im_cpm.cp_fec;
Christophe Leroy069fa832017-07-06 10:23:22 +0200706
Christophe Leroy394f9b32017-07-06 10:33:13 +0200707 out_be32(&ep->fec_mii_data, mii_cmd); /* command to phy */
Christophe Leroy069fa832017-07-06 10:23:22 +0200708
709 /* wait for mii complete */
710 cnt = 0;
Christophe Leroy394f9b32017-07-06 10:33:13 +0200711 while (!(in_be32(&ep->fec_ievent) & FEC_ENET_MII)) {
Christophe Leroy069fa832017-07-06 10:23:22 +0200712 if (++cnt > 1000) {
713 printf("mii_send STUCK!\n");
714 break;
715 }
716 }
Christophe Leroy394f9b32017-07-06 10:33:13 +0200717 mii_reply = in_be32(&ep->fec_mii_data); /* result from phy */
718 out_be32(&ep->fec_ievent, FEC_ENET_MII); /* clear MII complete */
Christophe Leroy48f896d2017-07-06 10:33:17 +0200719 return mii_reply & 0xffff; /* data read from phy */
Christophe Leroy069fa832017-07-06 10:23:22 +0200720}
721#endif
722
723#if defined(CONFIG_SYS_DISCOVER_PHY)
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200724static int mii_discover_phy(struct udevice *dev)
Christophe Leroy069fa832017-07-06 10:23:22 +0200725{
726#define MAX_PHY_PASSES 11
727 uint phyno;
728 int pass;
729 uint phytype;
730 int phyaddr;
731
732 phyaddr = -1; /* didn't find a PHY yet */
733 for (pass = 1; pass <= MAX_PHY_PASSES && phyaddr < 0; ++pass) {
734 if (pass > 1) {
735 /* PHY may need more time to recover from reset.
736 * The LXT970 needs 50ms typical, no maximum is
737 * specified, so wait 10ms before try again.
738 * With 11 passes this gives it 100ms to wake up.
739 */
740 udelay(10000); /* wait 10ms */
741 }
742 for (phyno = 0; phyno < 32 && phyaddr < 0; ++phyno) {
743 phytype = mii_send(mk_mii_read(phyno, MII_PHYSID2));
744 if (phytype != 0xffff) {
745 phyaddr = phyno;
746 phytype |= mii_send(mk_mii_read(phyno,
747 MII_PHYSID1)) << 16;
748 }
749 }
750 }
Christophe Leroy48f896d2017-07-06 10:33:17 +0200751 if (phyaddr < 0)
Christophe Leroy069fa832017-07-06 10:23:22 +0200752 printf("No PHY device found.\n");
Christophe Leroy48f896d2017-07-06 10:33:17 +0200753
Christophe Leroy069fa832017-07-06 10:23:22 +0200754 return phyaddr;
755}
756#endif /* CONFIG_SYS_DISCOVER_PHY */
757
758#if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && !defined(CONFIG_BITBANGMII)
759
760/****************************************************************************
761 * mii_init -- Initialize the MII via FEC 1 for MII command without ethernet
762 * This function is a subset of eth_init
763 ****************************************************************************
764 */
765static void __mii_init(void)
766{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200767 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
768 fec_t __iomem *fecp = &immr->im_cpm.cp_fec;
Christophe Leroy069fa832017-07-06 10:23:22 +0200769
770 if (fec_reset(fecp) < 0)
Christophe Leroy48f896d2017-07-06 10:33:17 +0200771 printf("FEC_RESET_DELAY timeout\n");
Christophe Leroy069fa832017-07-06 10:23:22 +0200772
773 /* We use strictly polling mode only
774 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200775 out_be32(&fecp->fec_imask, 0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200776
777 /* Clear any pending interrupt
778 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200779 out_be32(&fecp->fec_ievent, 0xffc0);
Christophe Leroy069fa832017-07-06 10:23:22 +0200780
781 /* Now enable the transmit and receive processing
782 */
Christophe Leroy394f9b32017-07-06 10:33:13 +0200783 out_be32(&fecp->fec_ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
Christophe Leroy069fa832017-07-06 10:23:22 +0200784}
785
Christophe Leroy48f896d2017-07-06 10:33:17 +0200786void mii_init(void)
Christophe Leroy069fa832017-07-06 10:23:22 +0200787{
788 int i;
789
790 __mii_init();
791
792 /* Setup the pin configuration of the FEC(s)
793 */
794 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
795 fec_pin_init(ether_fcc_info[i].ether_index);
796}
797
798/*****************************************************************************
799 * Read and write a MII PHY register, routines used by MII Utilities
800 *
801 * FIXME: These routines are expected to return 0 on success, but mii_send
802 * does _not_ return an error code. Maybe 0xFFFF means error, i.e.
803 * no PHY connected...
804 * For now always return 0.
805 * FIXME: These routines only work after calling eth_init() at least once!
806 * Otherwise they hang in mii_send() !!! Sorry!
807 *****************************************************************************/
808
809int fec8xx_miiphy_read(struct mii_dev *bus, int addr, int devad, int reg)
810{
811 unsigned short value = 0;
812 short rdreg; /* register working value */
813
814 rdreg = mii_send(mk_mii_read(addr, reg));
815
816 value = rdreg;
817 return value;
818}
819
820int fec8xx_miiphy_write(struct mii_dev *bus, int addr, int devad, int reg,
821 u16 value)
822{
823 (void)mii_send(mk_mii_write(addr, reg, value));
824
825 return 0;
826}
827#endif
Christophe Leroy69ef96d2022-05-12 15:48:51 +0200828
829static const struct eth_ops fec_ops = {
830 .start = fec_start,
831 .send = fec_send,
832 .recv = fec_recv,
833 .stop = fec_stop,
834 .free_pkt = fec_free_pkt,
835};
836
837static const struct udevice_id fec_ids[] = {
838#ifdef CONFIG_ETHER_ON_FEC1
839 {
840 .compatible = "fsl,pq1-fec1",
841 .data = 0,
842 },
843#endif
844#ifdef CONFIG_ETHER_ON_FEC2
845 {
846 .compatible = "fsl,pq1-fec2",
847 .data = 1,
848 },
849#endif
850 { }
851};
852
853U_BOOT_DRIVER(fec) = {
854 .name = "fec",
855 .id = UCLASS_ETH,
856 .of_match = fec_ids,
857 .probe = fec_probe,
858 .ops = &fec_ops,
859 .priv_auto = sizeof(struct ether_fcc_info_s),
860 .plat_auto = sizeof(struct eth_pdata),
861};