blob: b2823701a4118cdf9a76fa867ce696ffe8d5e779 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng8ee443b2015-03-20 17:12:20 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * Intel Platform Controller Hub EG20T (codename Topcliff) GMAC Driver
Bin Meng8ee443b2015-03-20 17:12:20 +08006 */
7
8#include <common.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07009#include <cpu_func.h>
Bin Mengca19a792015-08-27 22:25:57 -070010#include <dm.h>
Bin Meng8ee443b2015-03-20 17:12:20 +080011#include <errno.h>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <malloc.h>
Bin Meng8ee443b2015-03-20 17:12:20 +080013#include <asm/io.h>
14#include <pci.h>
Bin Meng8ee443b2015-03-20 17:12:20 +080015#include <miiphy.h>
16#include "pch_gbe.h"
17
18#if !defined(CONFIG_PHYLIB)
19# error "PCH Gigabit Ethernet driver requires PHYLIB - missing CONFIG_PHYLIB"
20#endif
21
22static struct pci_device_id supported[] = {
Bin Mengca19a792015-08-27 22:25:57 -070023 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_GBE) },
Bin Meng8ee443b2015-03-20 17:12:20 +080024 { }
25};
26
27static void pch_gbe_mac_read(struct pch_gbe_regs *mac_regs, u8 *addr)
28{
29 u32 macid_hi, macid_lo;
30
31 macid_hi = readl(&mac_regs->mac_adr[0].high);
32 macid_lo = readl(&mac_regs->mac_adr[0].low) & 0xffff;
33 debug("pch_gbe: macid_hi %#x macid_lo %#x\n", macid_hi, macid_lo);
34
35 addr[0] = (u8)(macid_hi & 0xff);
36 addr[1] = (u8)((macid_hi >> 8) & 0xff);
37 addr[2] = (u8)((macid_hi >> 16) & 0xff);
38 addr[3] = (u8)((macid_hi >> 24) & 0xff);
39 addr[4] = (u8)(macid_lo & 0xff);
40 addr[5] = (u8)((macid_lo >> 8) & 0xff);
41}
42
43static int pch_gbe_mac_write(struct pch_gbe_regs *mac_regs, u8 *addr)
44{
45 u32 macid_hi, macid_lo;
46 ulong start;
47
48 macid_hi = addr[0] + (addr[1] << 8) + (addr[2] << 16) + (addr[3] << 24);
49 macid_lo = addr[4] + (addr[5] << 8);
50
51 writel(macid_hi, &mac_regs->mac_adr[0].high);
52 writel(macid_lo, &mac_regs->mac_adr[0].low);
53 writel(0xfffe, &mac_regs->addr_mask);
54
55 start = get_timer(0);
56 while (get_timer(start) < PCH_GBE_TIMEOUT) {
57 if (!(readl(&mac_regs->addr_mask) & PCH_GBE_BUSY))
58 return 0;
59
60 udelay(10);
61 }
62
63 return -ETIME;
64}
65
Bin Mengca19a792015-08-27 22:25:57 -070066static int pch_gbe_reset(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +080067{
Bin Mengca19a792015-08-27 22:25:57 -070068 struct pch_gbe_priv *priv = dev_get_priv(dev);
69 struct eth_pdata *plat = dev_get_platdata(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +080070 struct pch_gbe_regs *mac_regs = priv->mac_regs;
71 ulong start;
72
73 priv->rx_idx = 0;
74 priv->tx_idx = 0;
75
76 writel(PCH_GBE_ALL_RST, &mac_regs->reset);
77
78 /*
79 * Configure the MAC to RGMII mode after reset
80 *
81 * For some unknown reason, we must do the configuration here right
82 * after resetting the whole MAC, otherwise the reset bit in the RESET
83 * register will never be cleared by the hardware. And there is another
84 * way of having the same magic, that is to configure the MODE register
85 * to have the MAC work in MII/GMII mode, which is how current Linux
86 * pch_gbe driver does. Since anyway we need program the MAC to RGMII
87 * mode in the driver, we just do it here.
88 *
89 * Note: this behavior is not documented in the hardware manual.
90 */
91 writel(PCH_GBE_RGMII_MODE_RGMII | PCH_GBE_CHIP_TYPE_INTERNAL,
92 &mac_regs->rgmii_ctrl);
93
94 start = get_timer(0);
95 while (get_timer(start) < PCH_GBE_TIMEOUT) {
96 if (!(readl(&mac_regs->reset) & PCH_GBE_ALL_RST)) {
97 /*
98 * Soft reset clears hardware MAC address registers,
99 * so we have to reload MAC address here in order to
100 * make linux pch_gbe driver happy.
101 */
Bin Mengca19a792015-08-27 22:25:57 -0700102 return pch_gbe_mac_write(mac_regs, plat->enetaddr);
Bin Meng8ee443b2015-03-20 17:12:20 +0800103 }
104
105 udelay(10);
106 }
107
108 debug("pch_gbe: reset timeout\n");
109 return -ETIME;
110}
111
Bin Mengca19a792015-08-27 22:25:57 -0700112static void pch_gbe_rx_descs_init(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800113{
Bin Mengca19a792015-08-27 22:25:57 -0700114 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800115 struct pch_gbe_regs *mac_regs = priv->mac_regs;
116 struct pch_gbe_rx_desc *rx_desc = &priv->rx_desc[0];
117 int i;
118
119 memset(rx_desc, 0, sizeof(struct pch_gbe_rx_desc) * PCH_GBE_DESC_NUM);
120 for (i = 0; i < PCH_GBE_DESC_NUM; i++)
Paul Burton52e727c2017-04-30 21:57:07 +0200121 rx_desc[i].buffer_addr = dm_pci_virt_to_mem(priv->dev,
Paul Burtondb225f12017-04-30 21:57:06 +0200122 priv->rx_buff[i]);
Bin Meng8ee443b2015-03-20 17:12:20 +0800123
Paul Burton2303bff2017-04-30 21:57:08 +0200124 flush_dcache_range((ulong)rx_desc, (ulong)&rx_desc[PCH_GBE_DESC_NUM]);
125
Paul Burton52e727c2017-04-30 21:57:07 +0200126 writel(dm_pci_virt_to_mem(priv->dev, rx_desc),
Bin Meng8ee443b2015-03-20 17:12:20 +0800127 &mac_regs->rx_dsc_base);
128 writel(sizeof(struct pch_gbe_rx_desc) * (PCH_GBE_DESC_NUM - 1),
129 &mac_regs->rx_dsc_size);
130
Paul Burton52e727c2017-04-30 21:57:07 +0200131 writel(dm_pci_virt_to_mem(priv->dev, rx_desc + 1),
Bin Meng8ee443b2015-03-20 17:12:20 +0800132 &mac_regs->rx_dsc_sw_p);
133}
134
Bin Mengca19a792015-08-27 22:25:57 -0700135static void pch_gbe_tx_descs_init(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800136{
Bin Mengca19a792015-08-27 22:25:57 -0700137 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800138 struct pch_gbe_regs *mac_regs = priv->mac_regs;
139 struct pch_gbe_tx_desc *tx_desc = &priv->tx_desc[0];
140
141 memset(tx_desc, 0, sizeof(struct pch_gbe_tx_desc) * PCH_GBE_DESC_NUM);
142
Paul Burton2303bff2017-04-30 21:57:08 +0200143 flush_dcache_range((ulong)tx_desc, (ulong)&tx_desc[PCH_GBE_DESC_NUM]);
144
Paul Burton52e727c2017-04-30 21:57:07 +0200145 writel(dm_pci_virt_to_mem(priv->dev, tx_desc),
Bin Meng8ee443b2015-03-20 17:12:20 +0800146 &mac_regs->tx_dsc_base);
147 writel(sizeof(struct pch_gbe_tx_desc) * (PCH_GBE_DESC_NUM - 1),
148 &mac_regs->tx_dsc_size);
Paul Burton52e727c2017-04-30 21:57:07 +0200149 writel(dm_pci_virt_to_mem(priv->dev, tx_desc + 1),
Bin Meng8ee443b2015-03-20 17:12:20 +0800150 &mac_regs->tx_dsc_sw_p);
151}
152
153static void pch_gbe_adjust_link(struct pch_gbe_regs *mac_regs,
154 struct phy_device *phydev)
155{
156 if (!phydev->link) {
157 printf("%s: No link.\n", phydev->dev->name);
158 return;
159 }
160
161 clrbits_le32(&mac_regs->rgmii_ctrl,
162 PCH_GBE_RGMII_RATE_2_5M | PCH_GBE_CRS_SEL);
163 clrbits_le32(&mac_regs->mode,
164 PCH_GBE_MODE_GMII_ETHER | PCH_GBE_MODE_FULL_DUPLEX);
165
166 switch (phydev->speed) {
167 case 1000:
168 setbits_le32(&mac_regs->rgmii_ctrl, PCH_GBE_RGMII_RATE_125M);
169 setbits_le32(&mac_regs->mode, PCH_GBE_MODE_GMII_ETHER);
170 break;
171 case 100:
172 setbits_le32(&mac_regs->rgmii_ctrl, PCH_GBE_RGMII_RATE_25M);
173 setbits_le32(&mac_regs->mode, PCH_GBE_MODE_MII_ETHER);
174 break;
175 case 10:
176 setbits_le32(&mac_regs->rgmii_ctrl, PCH_GBE_RGMII_RATE_2_5M);
177 setbits_le32(&mac_regs->mode, PCH_GBE_MODE_MII_ETHER);
178 break;
179 }
180
181 if (phydev->duplex) {
182 setbits_le32(&mac_regs->rgmii_ctrl, PCH_GBE_CRS_SEL);
183 setbits_le32(&mac_regs->mode, PCH_GBE_MODE_FULL_DUPLEX);
184 }
185
186 printf("Speed: %d, %s duplex\n", phydev->speed,
187 (phydev->duplex) ? "full" : "half");
188
189 return;
190}
191
Bin Mengca19a792015-08-27 22:25:57 -0700192static int pch_gbe_start(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800193{
Bin Mengca19a792015-08-27 22:25:57 -0700194 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800195 struct pch_gbe_regs *mac_regs = priv->mac_regs;
196
197 if (pch_gbe_reset(dev))
198 return -1;
199
200 pch_gbe_rx_descs_init(dev);
201 pch_gbe_tx_descs_init(dev);
202
203 /* Enable frame bursting */
204 writel(PCH_GBE_MODE_FR_BST, &mac_regs->mode);
205 /* Disable TCP/IP accelerator */
206 writel(PCH_GBE_RX_TCPIPACC_OFF, &mac_regs->tcpip_acc);
207 /* Disable RX flow control */
208 writel(0, &mac_regs->rx_fctrl);
209 /* Configure RX/TX mode */
210 writel(PCH_GBE_RH_ALM_EMP_16 | PCH_GBE_RH_ALM_FULL_16 |
211 PCH_GBE_RH_RD_TRG_32, &mac_regs->rx_mode);
212 writel(PCH_GBE_TM_TH_TX_STRT_32 | PCH_GBE_TM_TH_ALM_EMP_16 |
213 PCH_GBE_TM_TH_ALM_FULL_32 | PCH_GBE_TM_ST_AND_FD |
214 PCH_GBE_TM_SHORT_PKT, &mac_regs->tx_mode);
215
216 /* Start up the PHY */
217 if (phy_startup(priv->phydev)) {
218 printf("Could not initialize PHY %s\n",
219 priv->phydev->dev->name);
220 return -1;
221 }
222
223 pch_gbe_adjust_link(mac_regs, priv->phydev);
224
225 if (!priv->phydev->link)
226 return -1;
227
228 /* Enable TX & RX */
229 writel(PCH_GBE_RX_DMA_EN | PCH_GBE_TX_DMA_EN, &mac_regs->dma_ctrl);
230 writel(PCH_GBE_MRE_MAC_RX_EN, &mac_regs->mac_rx_en);
231
232 return 0;
233}
234
Bin Mengca19a792015-08-27 22:25:57 -0700235static void pch_gbe_stop(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800236{
Bin Mengca19a792015-08-27 22:25:57 -0700237 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800238
239 pch_gbe_reset(dev);
240
241 phy_shutdown(priv->phydev);
242}
243
Bin Mengca19a792015-08-27 22:25:57 -0700244static int pch_gbe_send(struct udevice *dev, void *packet, int length)
Bin Meng8ee443b2015-03-20 17:12:20 +0800245{
Bin Mengca19a792015-08-27 22:25:57 -0700246 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800247 struct pch_gbe_regs *mac_regs = priv->mac_regs;
248 struct pch_gbe_tx_desc *tx_head, *tx_desc;
249 u16 frame_ctrl = 0;
250 u32 int_st;
251 ulong start;
252
Paul Burton2303bff2017-04-30 21:57:08 +0200253 flush_dcache_range((ulong)packet, (ulong)packet + length);
254
Bin Meng8ee443b2015-03-20 17:12:20 +0800255 tx_head = &priv->tx_desc[0];
256 tx_desc = &priv->tx_desc[priv->tx_idx];
257
258 if (length < 64)
259 frame_ctrl |= PCH_GBE_TXD_CTRL_APAD;
260
Paul Burton52e727c2017-04-30 21:57:07 +0200261 tx_desc->buffer_addr = dm_pci_virt_to_mem(priv->dev, packet);
Bin Meng8ee443b2015-03-20 17:12:20 +0800262 tx_desc->length = length;
263 tx_desc->tx_words_eob = length + 3;
264 tx_desc->tx_frame_ctrl = frame_ctrl;
265 tx_desc->dma_status = 0;
266 tx_desc->gbec_status = 0;
267
Paul Burton2303bff2017-04-30 21:57:08 +0200268 flush_dcache_range((ulong)tx_desc, (ulong)&tx_desc[1]);
269
Bin Meng8ee443b2015-03-20 17:12:20 +0800270 /* Test the wrap-around condition */
271 if (++priv->tx_idx >= PCH_GBE_DESC_NUM)
272 priv->tx_idx = 0;
273
Paul Burton52e727c2017-04-30 21:57:07 +0200274 writel(dm_pci_virt_to_mem(priv->dev, tx_head + priv->tx_idx),
Bin Meng8ee443b2015-03-20 17:12:20 +0800275 &mac_regs->tx_dsc_sw_p);
276
277 start = get_timer(0);
278 while (get_timer(start) < PCH_GBE_TIMEOUT) {
279 int_st = readl(&mac_regs->int_st);
280 if (int_st & PCH_GBE_INT_TX_CMPLT)
281 return 0;
282
283 udelay(10);
284 }
285
286 debug("pch_gbe: sent failed\n");
287 return -ETIME;
288}
289
Bin Mengca19a792015-08-27 22:25:57 -0700290static int pch_gbe_recv(struct udevice *dev, int flags, uchar **packetp)
Bin Meng8ee443b2015-03-20 17:12:20 +0800291{
Bin Mengca19a792015-08-27 22:25:57 -0700292 struct pch_gbe_priv *priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800293 struct pch_gbe_regs *mac_regs = priv->mac_regs;
Bin Mengca19a792015-08-27 22:25:57 -0700294 struct pch_gbe_rx_desc *rx_desc;
Paul Burton52e727c2017-04-30 21:57:07 +0200295 ulong hw_desc, length;
296 void *buffer;
Bin Meng8ee443b2015-03-20 17:12:20 +0800297
Bin Meng8ee443b2015-03-20 17:12:20 +0800298 rx_desc = &priv->rx_desc[priv->rx_idx];
299
300 readl(&mac_regs->int_st);
301 hw_desc = readl(&mac_regs->rx_dsc_hw_p_hld);
302
303 /* Just return if not receiving any packet */
Paul Burton52e727c2017-04-30 21:57:07 +0200304 if (virt_to_phys(rx_desc) == hw_desc)
Bin Mengca19a792015-08-27 22:25:57 -0700305 return -EAGAIN;
Bin Meng8ee443b2015-03-20 17:12:20 +0800306
Paul Burton2303bff2017-04-30 21:57:08 +0200307 /* Invalidate the descriptor */
308 invalidate_dcache_range((ulong)rx_desc, (ulong)&rx_desc[1]);
309
Bin Meng8ee443b2015-03-20 17:12:20 +0800310 length = rx_desc->rx_words_eob - 3 - ETH_FCS_LEN;
Paul Burton52e727c2017-04-30 21:57:07 +0200311 buffer = dm_pci_mem_to_virt(priv->dev, rx_desc->buffer_addr, length, 0);
Paul Burton2303bff2017-04-30 21:57:08 +0200312 invalidate_dcache_range((ulong)buffer, (ulong)buffer + length);
Paul Burton52e727c2017-04-30 21:57:07 +0200313 *packetp = (uchar *)buffer;
Bin Mengca19a792015-08-27 22:25:57 -0700314
315 return length;
316}
317
318static int pch_gbe_free_pkt(struct udevice *dev, uchar *packet, int length)
319{
320 struct pch_gbe_priv *priv = dev_get_priv(dev);
321 struct pch_gbe_regs *mac_regs = priv->mac_regs;
322 struct pch_gbe_rx_desc *rx_head = &priv->rx_desc[0];
323 int rx_swp;
Bin Meng8ee443b2015-03-20 17:12:20 +0800324
325 /* Test the wrap-around condition */
326 if (++priv->rx_idx >= PCH_GBE_DESC_NUM)
327 priv->rx_idx = 0;
328 rx_swp = priv->rx_idx;
329 if (++rx_swp >= PCH_GBE_DESC_NUM)
330 rx_swp = 0;
331
Paul Burton52e727c2017-04-30 21:57:07 +0200332 writel(dm_pci_virt_to_mem(priv->dev, rx_head + rx_swp),
Bin Meng8ee443b2015-03-20 17:12:20 +0800333 &mac_regs->rx_dsc_sw_p);
334
Bin Mengca19a792015-08-27 22:25:57 -0700335 return 0;
Bin Meng8ee443b2015-03-20 17:12:20 +0800336}
337
338static int pch_gbe_mdio_ready(struct pch_gbe_regs *mac_regs)
339{
340 ulong start = get_timer(0);
341
342 while (get_timer(start) < PCH_GBE_TIMEOUT) {
343 if (readl(&mac_regs->miim) & PCH_GBE_MIIM_OPER_READY)
344 return 0;
345
346 udelay(10);
347 }
348
349 return -ETIME;
350}
351
352static int pch_gbe_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
353{
354 struct pch_gbe_regs *mac_regs = bus->priv;
355 u32 miim;
356
357 if (pch_gbe_mdio_ready(mac_regs))
358 return -ETIME;
359
360 miim = (addr << PCH_GBE_MIIM_PHY_ADDR_SHIFT) |
361 (reg << PCH_GBE_MIIM_REG_ADDR_SHIFT) |
362 PCH_GBE_MIIM_OPER_READ;
363 writel(miim, &mac_regs->miim);
364
365 if (pch_gbe_mdio_ready(mac_regs))
366 return -ETIME;
367
368 return readl(&mac_regs->miim) & 0xffff;
369}
370
371static int pch_gbe_mdio_write(struct mii_dev *bus, int addr, int devad,
372 int reg, u16 val)
373{
374 struct pch_gbe_regs *mac_regs = bus->priv;
375 u32 miim;
376
377 if (pch_gbe_mdio_ready(mac_regs))
378 return -ETIME;
379
380 miim = (addr << PCH_GBE_MIIM_PHY_ADDR_SHIFT) |
381 (reg << PCH_GBE_MIIM_REG_ADDR_SHIFT) |
382 PCH_GBE_MIIM_OPER_WRITE | val;
383 writel(miim, &mac_regs->miim);
384
385 if (pch_gbe_mdio_ready(mac_regs))
386 return -ETIME;
387 else
388 return 0;
389}
390
Bin Mengca19a792015-08-27 22:25:57 -0700391static int pch_gbe_mdio_init(const char *name, struct pch_gbe_regs *mac_regs)
Bin Meng8ee443b2015-03-20 17:12:20 +0800392{
393 struct mii_dev *bus;
394
395 bus = mdio_alloc();
396 if (!bus) {
397 debug("pch_gbe: failed to allocate MDIO bus\n");
398 return -ENOMEM;
399 }
400
401 bus->read = pch_gbe_mdio_read;
402 bus->write = pch_gbe_mdio_write;
Ben Whitten192bc692015-12-30 13:05:58 +0000403 strcpy(bus->name, name);
Bin Meng8ee443b2015-03-20 17:12:20 +0800404
405 bus->priv = (void *)mac_regs;
406
407 return mdio_register(bus);
408}
409
Bin Mengca19a792015-08-27 22:25:57 -0700410static int pch_gbe_phy_init(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800411{
Bin Mengca19a792015-08-27 22:25:57 -0700412 struct pch_gbe_priv *priv = dev_get_priv(dev);
413 struct eth_pdata *plat = dev_get_platdata(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800414 struct phy_device *phydev;
415 int mask = 0xffffffff;
416
Bin Mengca19a792015-08-27 22:25:57 -0700417 phydev = phy_find_by_mask(priv->bus, mask, plat->phy_interface);
Bin Meng8ee443b2015-03-20 17:12:20 +0800418 if (!phydev) {
419 printf("pch_gbe: cannot find the phy\n");
420 return -1;
421 }
422
423 phy_connect_dev(phydev, dev);
424
425 phydev->supported &= PHY_GBIT_FEATURES;
426 phydev->advertising = phydev->supported;
427
428 priv->phydev = phydev;
429 phy_config(phydev);
430
Bin Mengca19a792015-08-27 22:25:57 -0700431 return 0;
Bin Meng8ee443b2015-03-20 17:12:20 +0800432}
433
Bin Meng339613e2018-07-29 00:11:22 -0700434static int pch_gbe_probe(struct udevice *dev)
Bin Meng8ee443b2015-03-20 17:12:20 +0800435{
Bin Meng8ee443b2015-03-20 17:12:20 +0800436 struct pch_gbe_priv *priv;
Bin Mengca19a792015-08-27 22:25:57 -0700437 struct eth_pdata *plat = dev_get_platdata(dev);
Paul Burton154bf122016-09-08 07:47:33 +0100438 void *iobase;
Paul Burton43979cb2017-04-30 21:57:05 +0200439 int err;
Bin Meng8ee443b2015-03-20 17:12:20 +0800440
Bin Meng8ee443b2015-03-20 17:12:20 +0800441 /*
442 * The priv structure contains the descriptors and frame buffers which
Bin Mengca19a792015-08-27 22:25:57 -0700443 * need a strict buswidth alignment (64 bytes). This is guaranteed by
444 * DM_FLAG_ALLOC_PRIV_DMA flag in the U_BOOT_DRIVER.
Bin Meng8ee443b2015-03-20 17:12:20 +0800445 */
Bin Mengca19a792015-08-27 22:25:57 -0700446 priv = dev_get_priv(dev);
Bin Meng8ee443b2015-03-20 17:12:20 +0800447
Bin Mengc52ac3f2016-02-02 05:57:59 -0800448 priv->dev = dev;
Bin Meng8ee443b2015-03-20 17:12:20 +0800449
Paul Burton154bf122016-09-08 07:47:33 +0100450 iobase = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_1, PCI_REGION_MEM);
Bin Meng8ee443b2015-03-20 17:12:20 +0800451
Paul Burton154bf122016-09-08 07:47:33 +0100452 plat->iobase = (ulong)iobase;
Bin Meng8ee443b2015-03-20 17:12:20 +0800453 priv->mac_regs = (struct pch_gbe_regs *)iobase;
454
Bin Meng8ee443b2015-03-20 17:12:20 +0800455 /* Read MAC address from SROM and initialize dev->enetaddr with it */
Bin Mengca19a792015-08-27 22:25:57 -0700456 pch_gbe_mac_read(priv->mac_regs, plat->enetaddr);
Bin Meng8ee443b2015-03-20 17:12:20 +0800457
Bin Mengca19a792015-08-27 22:25:57 -0700458 plat->phy_interface = PHY_INTERFACE_MODE_RGMII;
Bin Meng8ee443b2015-03-20 17:12:20 +0800459 pch_gbe_mdio_init(dev->name, priv->mac_regs);
460 priv->bus = miiphy_get_dev_by_name(dev->name);
461
Paul Burton43979cb2017-04-30 21:57:05 +0200462 err = pch_gbe_reset(dev);
463 if (err)
464 return err;
465
Bin Meng8ee443b2015-03-20 17:12:20 +0800466 return pch_gbe_phy_init(dev);
467}
Bin Mengca19a792015-08-27 22:25:57 -0700468
Bin Meng339613e2018-07-29 00:11:22 -0700469static int pch_gbe_remove(struct udevice *dev)
Bin Meng3f616b62015-10-07 21:32:39 -0700470{
471 struct pch_gbe_priv *priv = dev_get_priv(dev);
472
473 free(priv->phydev);
474 mdio_unregister(priv->bus);
475 mdio_free(priv->bus);
476
477 return 0;
478}
479
Bin Mengca19a792015-08-27 22:25:57 -0700480static const struct eth_ops pch_gbe_ops = {
481 .start = pch_gbe_start,
482 .send = pch_gbe_send,
483 .recv = pch_gbe_recv,
484 .free_pkt = pch_gbe_free_pkt,
485 .stop = pch_gbe_stop,
486};
487
488static const struct udevice_id pch_gbe_ids[] = {
489 { .compatible = "intel,pch-gbe" },
490 { }
491};
492
493U_BOOT_DRIVER(eth_pch_gbe) = {
494 .name = "pch_gbe",
495 .id = UCLASS_ETH,
496 .of_match = pch_gbe_ids,
497 .probe = pch_gbe_probe,
Bin Meng3f616b62015-10-07 21:32:39 -0700498 .remove = pch_gbe_remove,
Bin Mengca19a792015-08-27 22:25:57 -0700499 .ops = &pch_gbe_ops,
500 .priv_auto_alloc_size = sizeof(struct pch_gbe_priv),
501 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
502 .flags = DM_FLAG_ALLOC_PRIV_DMA,
503};
504
505U_BOOT_PCI_DEVICE(eth_pch_gbe, supported);