blob: c24ab83c1a26151adb59a7b46d2b41f624a94b97 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Amit Singh Tomard194c0e2016-07-06 17:59:44 +05302/*
3 * (C) Copyright 2016
4 * Author: Amit Singh Tomar, amittomer25@gmail.com
5 *
Amit Singh Tomard194c0e2016-07-06 17:59:44 +05306 * Ethernet driver for H3/A64/A83T based SoC's
7 *
8 * It is derived from the work done by
9 * LABBE Corentin & Chen-Yu Tsai for Linux, THANKS!
10 *
11*/
12
Simon Glass63334482019-11-14 12:57:39 -070013#include <cpu_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060015#include <asm/cache.h>
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053016#include <asm/io.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/gpio.h>
19#include <common.h>
Jagan Tekicb63d282019-02-28 00:26:58 +053020#include <clk.h>
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053021#include <dm.h>
22#include <fdt_support.h>
Simon Glass9bc15642020-02-03 07:36:16 -070023#include <dm/device_compat.h>
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053024#include <linux/err.h>
25#include <malloc.h>
26#include <miiphy.h>
27#include <net.h>
Jagan Tekicb63d282019-02-28 00:26:58 +053028#include <reset.h>
Andre Przywara26e549b2018-04-04 01:31:15 +010029#include <dt-bindings/pinctrl/sun4i-a10.h>
Simon Glassfa4689a2019-12-06 21:41:35 -070030#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich3297b552017-02-22 19:46:41 +010031#include <asm-generic/gpio.h>
32#endif
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053033
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053034#define MDIO_CMD_MII_BUSY BIT(0)
35#define MDIO_CMD_MII_WRITE BIT(1)
36
37#define MDIO_CMD_MII_PHY_REG_ADDR_MASK 0x000001f0
38#define MDIO_CMD_MII_PHY_REG_ADDR_SHIFT 4
39#define MDIO_CMD_MII_PHY_ADDR_MASK 0x0001f000
40#define MDIO_CMD_MII_PHY_ADDR_SHIFT 12
41
42#define CONFIG_TX_DESCR_NUM 32
43#define CONFIG_RX_DESCR_NUM 32
Hans de Goedefcdb3b32016-07-27 17:31:17 +020044#define CONFIG_ETH_BUFSIZE 2048 /* Note must be dma aligned */
45
46/*
47 * The datasheet says that each descriptor can transfers up to 4096 bytes
48 * But later, the register documentation reduces that value to 2048,
49 * using 2048 cause strange behaviours and even BSP driver use 2047
50 */
51#define CONFIG_ETH_RXSIZE 2044 /* Note must fit in ETH_BUFSIZE */
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053052
53#define TX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_TX_DESCR_NUM)
54#define RX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_RX_DESCR_NUM)
55
56#define H3_EPHY_DEFAULT_VALUE 0x58000
57#define H3_EPHY_DEFAULT_MASK GENMASK(31, 15)
58#define H3_EPHY_ADDR_SHIFT 20
59#define REG_PHY_ADDR_MASK GENMASK(4, 0)
60#define H3_EPHY_LED_POL BIT(17) /* 1: active low, 0: active high */
61#define H3_EPHY_SHUTDOWN BIT(16) /* 1: shutdown, 0: power up */
62#define H3_EPHY_SELECT BIT(15) /* 1: internal PHY, 0: external PHY */
63
64#define SC_RMII_EN BIT(13)
65#define SC_EPIT BIT(2) /* 1: RGMII, 0: MII */
66#define SC_ETCS_MASK GENMASK(1, 0)
67#define SC_ETCS_EXT_GMII 0x1
68#define SC_ETCS_INT_GMII 0x2
Icenowy Zheng525dc442018-11-23 00:37:48 +010069#define SC_ETXDC_MASK GENMASK(12, 10)
70#define SC_ETXDC_OFFSET 10
71#define SC_ERXDC_MASK GENMASK(9, 5)
72#define SC_ERXDC_OFFSET 5
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053073
74#define CONFIG_MDIO_TIMEOUT (3 * CONFIG_SYS_HZ)
75
76#define AHB_GATE_OFFSET_EPHY 0
77
Lothar Feltenacb9a5b2018-07-13 10:45:27 +020078/* IO mux settings */
79#define SUN8I_IOMUX_H3 2
Lothar Feltene8cbced2018-07-13 10:45:28 +020080#define SUN8I_IOMUX_R40 5
Lothar Feltenacb9a5b2018-07-13 10:45:27 +020081#define SUN8I_IOMUX 4
Amit Singh Tomard194c0e2016-07-06 17:59:44 +053082
83/* H3/A64 EMAC Register's offset */
84#define EMAC_CTL0 0x00
85#define EMAC_CTL1 0x04
86#define EMAC_INT_STA 0x08
87#define EMAC_INT_EN 0x0c
88#define EMAC_TX_CTL0 0x10
89#define EMAC_TX_CTL1 0x14
90#define EMAC_TX_FLOW_CTL 0x1c
91#define EMAC_TX_DMA_DESC 0x20
92#define EMAC_RX_CTL0 0x24
93#define EMAC_RX_CTL1 0x28
94#define EMAC_RX_DMA_DESC 0x34
95#define EMAC_MII_CMD 0x48
96#define EMAC_MII_DATA 0x4c
97#define EMAC_ADDR0_HIGH 0x50
98#define EMAC_ADDR0_LOW 0x54
99#define EMAC_TX_DMA_STA 0xb0
100#define EMAC_TX_CUR_DESC 0xb4
101#define EMAC_TX_CUR_BUF 0xb8
102#define EMAC_RX_DMA_STA 0xc0
103#define EMAC_RX_CUR_DESC 0xc4
104
105DECLARE_GLOBAL_DATA_PTR;
106
107enum emac_variant {
108 A83T_EMAC = 1,
109 H3_EMAC,
110 A64_EMAC,
Lothar Feltene8cbced2018-07-13 10:45:28 +0200111 R40_GMAC,
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530112};
113
114struct emac_dma_desc {
115 u32 status;
116 u32 st;
117 u32 buf_addr;
118 u32 next;
119} __aligned(ARCH_DMA_MINALIGN);
120
121struct emac_eth_dev {
122 struct emac_dma_desc rx_chain[CONFIG_TX_DESCR_NUM];
123 struct emac_dma_desc tx_chain[CONFIG_RX_DESCR_NUM];
124 char rxbuffer[RX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN);
125 char txbuffer[TX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN);
126
127 u32 interface;
128 u32 phyaddr;
129 u32 link;
130 u32 speed;
131 u32 duplex;
132 u32 phy_configured;
133 u32 tx_currdescnum;
134 u32 rx_currdescnum;
135 u32 addr;
136 u32 tx_slot;
137 bool use_internal_phy;
138
139 enum emac_variant variant;
140 void *mac_reg;
141 phys_addr_t sysctl_reg;
142 struct phy_device *phydev;
143 struct mii_dev *bus;
Jagan Tekicb63d282019-02-28 00:26:58 +0530144 struct clk tx_clk;
Jagan Teki727ed792019-02-28 00:27:00 +0530145 struct clk ephy_clk;
Jagan Tekicb63d282019-02-28 00:26:58 +0530146 struct reset_ctl tx_rst;
Jagan Teki727ed792019-02-28 00:27:00 +0530147 struct reset_ctl ephy_rst;
Simon Glassfa4689a2019-12-06 21:41:35 -0700148#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich3297b552017-02-22 19:46:41 +0100149 struct gpio_desc reset_gpio;
150#endif
151};
152
153
154struct sun8i_eth_pdata {
155 struct eth_pdata eth_pdata;
156 u32 reset_delays[3];
Icenowy Zheng525dc442018-11-23 00:37:48 +0100157 int tx_delay_ps;
158 int rx_delay_ps;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530159};
160
Philipp Tomsich3297b552017-02-22 19:46:41 +0100161
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530162static int sun8i_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
163{
Philipp Tomsich3297b552017-02-22 19:46:41 +0100164 struct udevice *dev = bus->priv;
165 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530166 ulong start;
167 u32 miiaddr = 0;
168 int timeout = CONFIG_MDIO_TIMEOUT;
169
170 miiaddr &= ~MDIO_CMD_MII_WRITE;
171 miiaddr &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
172 miiaddr |= (reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
173 MDIO_CMD_MII_PHY_REG_ADDR_MASK;
174
175 miiaddr &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
176
177 miiaddr |= (addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
178 MDIO_CMD_MII_PHY_ADDR_MASK;
179
180 miiaddr |= MDIO_CMD_MII_BUSY;
181
182 writel(miiaddr, priv->mac_reg + EMAC_MII_CMD);
183
184 start = get_timer(0);
185 while (get_timer(start) < timeout) {
186 if (!(readl(priv->mac_reg + EMAC_MII_CMD) & MDIO_CMD_MII_BUSY))
187 return readl(priv->mac_reg + EMAC_MII_DATA);
188 udelay(10);
189 };
190
191 return -1;
192}
193
194static int sun8i_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
195 u16 val)
196{
Philipp Tomsich3297b552017-02-22 19:46:41 +0100197 struct udevice *dev = bus->priv;
198 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530199 ulong start;
200 u32 miiaddr = 0;
201 int ret = -1, timeout = CONFIG_MDIO_TIMEOUT;
202
203 miiaddr &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
204 miiaddr |= (reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
205 MDIO_CMD_MII_PHY_REG_ADDR_MASK;
206
207 miiaddr &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
208 miiaddr |= (addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
209 MDIO_CMD_MII_PHY_ADDR_MASK;
210
211 miiaddr |= MDIO_CMD_MII_WRITE;
212 miiaddr |= MDIO_CMD_MII_BUSY;
213
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530214 writel(val, priv->mac_reg + EMAC_MII_DATA);
Philipp Tomsich2b6dee12016-11-16 01:40:27 +0000215 writel(miiaddr, priv->mac_reg + EMAC_MII_CMD);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530216
217 start = get_timer(0);
218 while (get_timer(start) < timeout) {
219 if (!(readl(priv->mac_reg + EMAC_MII_CMD) &
220 MDIO_CMD_MII_BUSY)) {
221 ret = 0;
222 break;
223 }
224 udelay(10);
225 };
226
227 return ret;
228}
229
230static int _sun8i_write_hwaddr(struct emac_eth_dev *priv, u8 *mac_id)
231{
232 u32 macid_lo, macid_hi;
233
234 macid_lo = mac_id[0] + (mac_id[1] << 8) + (mac_id[2] << 16) +
235 (mac_id[3] << 24);
236 macid_hi = mac_id[4] + (mac_id[5] << 8);
237
238 writel(macid_hi, priv->mac_reg + EMAC_ADDR0_HIGH);
239 writel(macid_lo, priv->mac_reg + EMAC_ADDR0_LOW);
240
241 return 0;
242}
243
244static void sun8i_adjust_link(struct emac_eth_dev *priv,
245 struct phy_device *phydev)
246{
247 u32 v;
248
249 v = readl(priv->mac_reg + EMAC_CTL0);
250
251 if (phydev->duplex)
252 v |= BIT(0);
253 else
254 v &= ~BIT(0);
255
256 v &= ~0x0C;
257
258 switch (phydev->speed) {
259 case 1000:
260 break;
261 case 100:
262 v |= BIT(2);
263 v |= BIT(3);
264 break;
265 case 10:
266 v |= BIT(3);
267 break;
268 }
269 writel(v, priv->mac_reg + EMAC_CTL0);
270}
271
272static int sun8i_emac_set_syscon_ephy(struct emac_eth_dev *priv, u32 *reg)
273{
274 if (priv->use_internal_phy) {
275 /* H3 based SoC's that has an Internal 100MBit PHY
276 * needs to be configured and powered up before use
277 */
278 *reg &= ~H3_EPHY_DEFAULT_MASK;
279 *reg |= H3_EPHY_DEFAULT_VALUE;
280 *reg |= priv->phyaddr << H3_EPHY_ADDR_SHIFT;
281 *reg &= ~H3_EPHY_SHUTDOWN;
282 *reg |= H3_EPHY_SELECT;
283 } else
284 /* This is to select External Gigabit PHY on
285 * the boards with H3 SoC.
286 */
287 *reg &= ~H3_EPHY_SELECT;
288
289 return 0;
290}
291
Icenowy Zheng525dc442018-11-23 00:37:48 +0100292static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata,
293 struct emac_eth_dev *priv)
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530294{
295 int ret;
296 u32 reg;
297
Jagan Teki1cfc64c2019-02-28 00:26:51 +0530298 if (priv->variant == R40_GMAC) {
299 /* Select RGMII for R40 */
300 reg = readl(priv->sysctl_reg + 0x164);
301 reg |= CCM_GMAC_CTRL_TX_CLK_SRC_INT_RGMII |
302 CCM_GMAC_CTRL_GPIT_RGMII |
303 CCM_GMAC_CTRL_TX_CLK_DELAY(CONFIG_GMAC_TX_DELAY);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530304
Jagan Teki1cfc64c2019-02-28 00:26:51 +0530305 writel(reg, priv->sysctl_reg + 0x164);
Lothar Feltene8cbced2018-07-13 10:45:28 +0200306 return 0;
Jagan Teki1cfc64c2019-02-28 00:26:51 +0530307 }
308
309 reg = readl(priv->sysctl_reg + 0x30);
Lothar Feltene8cbced2018-07-13 10:45:28 +0200310
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530311 if (priv->variant == H3_EMAC) {
312 ret = sun8i_emac_set_syscon_ephy(priv, &reg);
313 if (ret)
314 return ret;
315 }
316
317 reg &= ~(SC_ETCS_MASK | SC_EPIT);
318 if (priv->variant == H3_EMAC || priv->variant == A64_EMAC)
319 reg &= ~SC_RMII_EN;
320
321 switch (priv->interface) {
322 case PHY_INTERFACE_MODE_MII:
323 /* default */
324 break;
325 case PHY_INTERFACE_MODE_RGMII:
326 reg |= SC_EPIT | SC_ETCS_INT_GMII;
327 break;
328 case PHY_INTERFACE_MODE_RMII:
329 if (priv->variant == H3_EMAC ||
330 priv->variant == A64_EMAC) {
331 reg |= SC_RMII_EN | SC_ETCS_EXT_GMII;
332 break;
333 }
334 /* RMII not supported on A83T */
335 default:
336 debug("%s: Invalid PHY interface\n", __func__);
337 return -EINVAL;
338 }
339
Icenowy Zheng525dc442018-11-23 00:37:48 +0100340 if (pdata->tx_delay_ps)
341 reg |= ((pdata->tx_delay_ps / 100) << SC_ETXDC_OFFSET)
342 & SC_ETXDC_MASK;
343
344 if (pdata->rx_delay_ps)
345 reg |= ((pdata->rx_delay_ps / 100) << SC_ERXDC_OFFSET)
346 & SC_ERXDC_MASK;
347
Andre Przywaraba3a96d2018-04-04 01:31:16 +0100348 writel(reg, priv->sysctl_reg + 0x30);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530349
350 return 0;
351}
352
353static int sun8i_phy_init(struct emac_eth_dev *priv, void *dev)
354{
355 struct phy_device *phydev;
356
357 phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
358 if (!phydev)
359 return -ENODEV;
360
361 phy_connect_dev(phydev, dev);
362
363 priv->phydev = phydev;
364 phy_config(priv->phydev);
365
366 return 0;
367}
368
369static void rx_descs_init(struct emac_eth_dev *priv)
370{
371 struct emac_dma_desc *desc_table_p = &priv->rx_chain[0];
372 char *rxbuffs = &priv->rxbuffer[0];
373 struct emac_dma_desc *desc_p;
374 u32 idx;
375
376 /* flush Rx buffers */
377 flush_dcache_range((uintptr_t)rxbuffs, (ulong)rxbuffs +
378 RX_TOTAL_BUFSIZE);
379
380 for (idx = 0; idx < CONFIG_RX_DESCR_NUM; idx++) {
381 desc_p = &desc_table_p[idx];
382 desc_p->buf_addr = (uintptr_t)&rxbuffs[idx * CONFIG_ETH_BUFSIZE]
383 ;
384 desc_p->next = (uintptr_t)&desc_table_p[idx + 1];
Hans de Goedefcdb3b32016-07-27 17:31:17 +0200385 desc_p->st |= CONFIG_ETH_RXSIZE;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530386 desc_p->status = BIT(31);
387 }
388
389 /* Correcting the last pointer of the chain */
390 desc_p->next = (uintptr_t)&desc_table_p[0];
391
392 flush_dcache_range((uintptr_t)priv->rx_chain,
393 (uintptr_t)priv->rx_chain +
394 sizeof(priv->rx_chain));
395
396 writel((uintptr_t)&desc_table_p[0], (priv->mac_reg + EMAC_RX_DMA_DESC));
397 priv->rx_currdescnum = 0;
398}
399
400static void tx_descs_init(struct emac_eth_dev *priv)
401{
402 struct emac_dma_desc *desc_table_p = &priv->tx_chain[0];
403 char *txbuffs = &priv->txbuffer[0];
404 struct emac_dma_desc *desc_p;
405 u32 idx;
406
407 for (idx = 0; idx < CONFIG_TX_DESCR_NUM; idx++) {
408 desc_p = &desc_table_p[idx];
409 desc_p->buf_addr = (uintptr_t)&txbuffs[idx * CONFIG_ETH_BUFSIZE]
410 ;
411 desc_p->next = (uintptr_t)&desc_table_p[idx + 1];
412 desc_p->status = (1 << 31);
413 desc_p->st = 0;
414 }
415
416 /* Correcting the last pointer of the chain */
417 desc_p->next = (uintptr_t)&desc_table_p[0];
418
419 /* Flush all Tx buffer descriptors */
420 flush_dcache_range((uintptr_t)priv->tx_chain,
421 (uintptr_t)priv->tx_chain +
422 sizeof(priv->tx_chain));
423
424 writel((uintptr_t)&desc_table_p[0], priv->mac_reg + EMAC_TX_DMA_DESC);
425 priv->tx_currdescnum = 0;
426}
427
428static int _sun8i_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr)
429{
430 u32 reg, v;
431 int timeout = 100;
432
433 reg = readl((priv->mac_reg + EMAC_CTL1));
434
435 if (!(reg & 0x1)) {
436 /* Soft reset MAC */
437 setbits_le32((priv->mac_reg + EMAC_CTL1), 0x1);
438 do {
439 reg = readl(priv->mac_reg + EMAC_CTL1);
440 } while ((reg & 0x01) != 0 && (--timeout));
441 if (!timeout) {
442 printf("%s: Timeout\n", __func__);
443 return -1;
444 }
445 }
446
447 /* Rewrite mac address after reset */
448 _sun8i_write_hwaddr(priv, enetaddr);
449
450 v = readl(priv->mac_reg + EMAC_TX_CTL1);
451 /* TX_MD Transmission starts after a full frame located in TX DMA FIFO*/
452 v |= BIT(1);
453 writel(v, priv->mac_reg + EMAC_TX_CTL1);
454
455 v = readl(priv->mac_reg + EMAC_RX_CTL1);
456 /* RX_MD RX DMA reads data from RX DMA FIFO to host memory after a
457 * complete frame has been written to RX DMA FIFO
458 */
459 v |= BIT(1);
460 writel(v, priv->mac_reg + EMAC_RX_CTL1);
461
462 /* DMA */
463 writel(8 << 24, priv->mac_reg + EMAC_CTL1);
464
465 /* Initialize rx/tx descriptors */
466 rx_descs_init(priv);
467 tx_descs_init(priv);
468
469 /* PHY Start Up */
Samuel Holland6a4d7992018-01-27 23:53:20 -0600470 phy_startup(priv->phydev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530471
472 sun8i_adjust_link(priv, priv->phydev);
473
474 /* Start RX DMA */
475 v = readl(priv->mac_reg + EMAC_RX_CTL1);
476 v |= BIT(30);
477 writel(v, priv->mac_reg + EMAC_RX_CTL1);
478 /* Start TX DMA */
479 v = readl(priv->mac_reg + EMAC_TX_CTL1);
480 v |= BIT(30);
481 writel(v, priv->mac_reg + EMAC_TX_CTL1);
482
483 /* Enable RX/TX */
484 setbits_le32(priv->mac_reg + EMAC_RX_CTL0, BIT(31));
485 setbits_le32(priv->mac_reg + EMAC_TX_CTL0, BIT(31));
486
487 return 0;
488}
489
490static int parse_phy_pins(struct udevice *dev)
491{
Lothar Feltenacb9a5b2018-07-13 10:45:27 +0200492 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530493 int offset;
494 const char *pin_name;
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100495 int drive, pull = SUN4I_PINCTRL_NO_PULL, i;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530496
Simon Glassdd79d6e2017-01-17 16:52:55 -0700497 offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530498 "pinctrl-0");
499 if (offset < 0) {
500 printf("WARNING: emac: cannot find pinctrl-0 node\n");
501 return offset;
502 }
503
504 drive = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
Andre Przywara26e549b2018-04-04 01:31:15 +0100505 "drive-strength", ~0);
506 if (drive != ~0) {
507 if (drive <= 10)
508 drive = SUN4I_PINCTRL_10_MA;
509 else if (drive <= 20)
510 drive = SUN4I_PINCTRL_20_MA;
511 else if (drive <= 30)
512 drive = SUN4I_PINCTRL_30_MA;
513 else
514 drive = SUN4I_PINCTRL_40_MA;
Andre Przywara26e549b2018-04-04 01:31:15 +0100515 }
516
517 if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-up", NULL))
518 pull = SUN4I_PINCTRL_PULL_UP;
Andre Przywara26e549b2018-04-04 01:31:15 +0100519 else if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-down", NULL))
520 pull = SUN4I_PINCTRL_PULL_DOWN;
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100521
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530522 for (i = 0; ; i++) {
523 int pin;
524
Simon Glassb0ea7402016-10-02 17:59:28 -0600525 pin_name = fdt_stringlist_get(gd->fdt_blob, offset,
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100526 "pins", i, NULL);
527 if (!pin_name)
528 break;
Andre Przywara26e549b2018-04-04 01:31:15 +0100529
530 pin = sunxi_name_to_gpio(pin_name);
531 if (pin < 0)
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530532 continue;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530533
Lothar Feltenacb9a5b2018-07-13 10:45:27 +0200534 if (priv->variant == H3_EMAC)
535 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX_H3);
Lothar Feltene8cbced2018-07-13 10:45:28 +0200536 else if (priv->variant == R40_GMAC)
537 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX_R40);
Lothar Feltenacb9a5b2018-07-13 10:45:27 +0200538 else
539 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX);
540
Andre Przywara26e549b2018-04-04 01:31:15 +0100541 if (drive != ~0)
542 sunxi_gpio_set_drv(pin, drive);
543 if (pull != ~0)
544 sunxi_gpio_set_pull(pin, pull);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530545 }
546
547 if (!i) {
Andre Przywara26e549b2018-04-04 01:31:15 +0100548 printf("WARNING: emac: cannot find pins property\n");
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530549 return -2;
550 }
551
552 return 0;
553}
554
555static int _sun8i_eth_recv(struct emac_eth_dev *priv, uchar **packetp)
556{
557 u32 status, desc_num = priv->rx_currdescnum;
558 struct emac_dma_desc *desc_p = &priv->rx_chain[desc_num];
559 int length = -EAGAIN;
560 int good_packet = 1;
561 uintptr_t desc_start = (uintptr_t)desc_p;
562 uintptr_t desc_end = desc_start +
563 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
564
565 ulong data_start = (uintptr_t)desc_p->buf_addr;
566 ulong data_end;
567
568 /* Invalidate entire buffer descriptor */
569 invalidate_dcache_range(desc_start, desc_end);
570
571 status = desc_p->status;
572
573 /* Check for DMA own bit */
574 if (!(status & BIT(31))) {
575 length = (desc_p->status >> 16) & 0x3FFF;
576
577 if (length < 0x40) {
578 good_packet = 0;
579 debug("RX: Bad Packet (runt)\n");
580 }
581
582 data_end = data_start + length;
583 /* Invalidate received data */
584 invalidate_dcache_range(rounddown(data_start,
585 ARCH_DMA_MINALIGN),
586 roundup(data_end,
587 ARCH_DMA_MINALIGN));
588 if (good_packet) {
Hans de Goedefcdb3b32016-07-27 17:31:17 +0200589 if (length > CONFIG_ETH_RXSIZE) {
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530590 printf("Received packet is too big (len=%d)\n",
591 length);
592 return -EMSGSIZE;
593 }
594 *packetp = (uchar *)(ulong)desc_p->buf_addr;
595 return length;
596 }
597 }
598
599 return length;
600}
601
602static int _sun8i_emac_eth_send(struct emac_eth_dev *priv, void *packet,
603 int len)
604{
605 u32 v, desc_num = priv->tx_currdescnum;
606 struct emac_dma_desc *desc_p = &priv->tx_chain[desc_num];
607 uintptr_t desc_start = (uintptr_t)desc_p;
608 uintptr_t desc_end = desc_start +
609 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
610
611 uintptr_t data_start = (uintptr_t)desc_p->buf_addr;
612 uintptr_t data_end = data_start +
613 roundup(len, ARCH_DMA_MINALIGN);
614
615 /* Invalidate entire buffer descriptor */
616 invalidate_dcache_range(desc_start, desc_end);
617
618 desc_p->st = len;
619 /* Mandatory undocumented bit */
620 desc_p->st |= BIT(24);
621
622 memcpy((void *)data_start, packet, len);
623
624 /* Flush data to be sent */
625 flush_dcache_range(data_start, data_end);
626
627 /* frame end */
628 desc_p->st |= BIT(30);
629 desc_p->st |= BIT(31);
630
631 /*frame begin */
632 desc_p->st |= BIT(29);
633 desc_p->status = BIT(31);
634
635 /*Descriptors st and status field has changed, so FLUSH it */
636 flush_dcache_range(desc_start, desc_end);
637
638 /* Move to next Descriptor and wrap around */
639 if (++desc_num >= CONFIG_TX_DESCR_NUM)
640 desc_num = 0;
641 priv->tx_currdescnum = desc_num;
642
643 /* Start the DMA */
644 v = readl(priv->mac_reg + EMAC_TX_CTL1);
645 v |= BIT(31);/* mandatory */
646 v |= BIT(30);/* mandatory */
647 writel(v, priv->mac_reg + EMAC_TX_CTL1);
648
649 return 0;
650}
651
652static int sun8i_eth_write_hwaddr(struct udevice *dev)
653{
654 struct eth_pdata *pdata = dev_get_platdata(dev);
655 struct emac_eth_dev *priv = dev_get_priv(dev);
656
657 return _sun8i_write_hwaddr(priv, pdata->enetaddr);
658}
659
Jagan Tekicb63d282019-02-28 00:26:58 +0530660static int sun8i_emac_board_setup(struct emac_eth_dev *priv)
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530661{
Jagan Tekicb63d282019-02-28 00:26:58 +0530662 int ret;
663
664 ret = clk_enable(&priv->tx_clk);
665 if (ret) {
666 dev_err(dev, "failed to enable TX clock\n");
667 return ret;
668 }
669
670 if (reset_valid(&priv->tx_rst)) {
671 ret = reset_deassert(&priv->tx_rst);
672 if (ret) {
673 dev_err(dev, "failed to deassert TX reset\n");
674 goto err_tx_clk;
675 }
676 }
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530677
Jagan Teki727ed792019-02-28 00:27:00 +0530678 /* Only H3/H5 have clock controls for internal EPHY */
679 if (clk_valid(&priv->ephy_clk)) {
680 ret = clk_enable(&priv->ephy_clk);
681 if (ret) {
682 dev_err(dev, "failed to enable EPHY TX clock\n");
683 return ret;
684 }
685 }
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530686
Jagan Teki727ed792019-02-28 00:27:00 +0530687 if (reset_valid(&priv->ephy_rst)) {
688 ret = reset_deassert(&priv->ephy_rst);
689 if (ret) {
690 dev_err(dev, "failed to deassert EPHY TX clock\n");
691 return ret;
Lothar Feltenacb9a5b2018-07-13 10:45:27 +0200692 }
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530693 }
694
Jagan Tekicb63d282019-02-28 00:26:58 +0530695 return 0;
Lothar Feltene8cbced2018-07-13 10:45:28 +0200696
Jagan Tekicb63d282019-02-28 00:26:58 +0530697err_tx_clk:
698 clk_disable(&priv->tx_clk);
699 return ret;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530700}
701
Simon Glassfa4689a2019-12-06 21:41:35 -0700702#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich3297b552017-02-22 19:46:41 +0100703static int sun8i_mdio_reset(struct mii_dev *bus)
704{
705 struct udevice *dev = bus->priv;
706 struct emac_eth_dev *priv = dev_get_priv(dev);
707 struct sun8i_eth_pdata *pdata = dev_get_platdata(dev);
708 int ret;
709
710 if (!dm_gpio_is_valid(&priv->reset_gpio))
711 return 0;
712
713 /* reset the phy */
714 ret = dm_gpio_set_value(&priv->reset_gpio, 0);
715 if (ret)
716 return ret;
717
718 udelay(pdata->reset_delays[0]);
719
720 ret = dm_gpio_set_value(&priv->reset_gpio, 1);
721 if (ret)
722 return ret;
723
724 udelay(pdata->reset_delays[1]);
725
726 ret = dm_gpio_set_value(&priv->reset_gpio, 0);
727 if (ret)
728 return ret;
729
730 udelay(pdata->reset_delays[2]);
731
732 return 0;
733}
734#endif
735
736static int sun8i_mdio_init(const char *name, struct udevice *priv)
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530737{
738 struct mii_dev *bus = mdio_alloc();
739
740 if (!bus) {
741 debug("Failed to allocate MDIO bus\n");
742 return -ENOMEM;
743 }
744
745 bus->read = sun8i_mdio_read;
746 bus->write = sun8i_mdio_write;
747 snprintf(bus->name, sizeof(bus->name), name);
748 bus->priv = (void *)priv;
Simon Glassfa4689a2019-12-06 21:41:35 -0700749#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich3297b552017-02-22 19:46:41 +0100750 bus->reset = sun8i_mdio_reset;
751#endif
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530752
753 return mdio_register(bus);
754}
755
756static int sun8i_emac_eth_start(struct udevice *dev)
757{
758 struct eth_pdata *pdata = dev_get_platdata(dev);
759
760 return _sun8i_emac_eth_init(dev->priv, pdata->enetaddr);
761}
762
763static int sun8i_emac_eth_send(struct udevice *dev, void *packet, int length)
764{
765 struct emac_eth_dev *priv = dev_get_priv(dev);
766
767 return _sun8i_emac_eth_send(priv, packet, length);
768}
769
770static int sun8i_emac_eth_recv(struct udevice *dev, int flags, uchar **packetp)
771{
772 struct emac_eth_dev *priv = dev_get_priv(dev);
773
774 return _sun8i_eth_recv(priv, packetp);
775}
776
777static int _sun8i_free_pkt(struct emac_eth_dev *priv)
778{
779 u32 desc_num = priv->rx_currdescnum;
780 struct emac_dma_desc *desc_p = &priv->rx_chain[desc_num];
781 uintptr_t desc_start = (uintptr_t)desc_p;
782 uintptr_t desc_end = desc_start +
783 roundup(sizeof(u32), ARCH_DMA_MINALIGN);
784
785 /* Make the current descriptor valid again */
786 desc_p->status |= BIT(31);
787
788 /* Flush Status field of descriptor */
789 flush_dcache_range(desc_start, desc_end);
790
791 /* Move to next desc and wrap-around condition. */
792 if (++desc_num >= CONFIG_RX_DESCR_NUM)
793 desc_num = 0;
794 priv->rx_currdescnum = desc_num;
795
796 return 0;
797}
798
799static int sun8i_eth_free_pkt(struct udevice *dev, uchar *packet,
800 int length)
801{
802 struct emac_eth_dev *priv = dev_get_priv(dev);
803
804 return _sun8i_free_pkt(priv);
805}
806
807static void sun8i_emac_eth_stop(struct udevice *dev)
808{
809 struct emac_eth_dev *priv = dev_get_priv(dev);
810
811 /* Stop Rx/Tx transmitter */
812 clrbits_le32(priv->mac_reg + EMAC_RX_CTL0, BIT(31));
813 clrbits_le32(priv->mac_reg + EMAC_TX_CTL0, BIT(31));
814
815 /* Stop TX DMA */
816 clrbits_le32(priv->mac_reg + EMAC_TX_CTL1, BIT(30));
817
818 phy_shutdown(priv->phydev);
819}
820
821static int sun8i_emac_eth_probe(struct udevice *dev)
822{
Icenowy Zheng525dc442018-11-23 00:37:48 +0100823 struct sun8i_eth_pdata *sun8i_pdata = dev_get_platdata(dev);
824 struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530825 struct emac_eth_dev *priv = dev_get_priv(dev);
Jagan Tekicb63d282019-02-28 00:26:58 +0530826 int ret;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530827
828 priv->mac_reg = (void *)pdata->iobase;
829
Jagan Tekicb63d282019-02-28 00:26:58 +0530830 ret = sun8i_emac_board_setup(priv);
831 if (ret)
832 return ret;
833
Icenowy Zheng525dc442018-11-23 00:37:48 +0100834 sun8i_emac_set_syscon(sun8i_pdata, priv);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530835
Philipp Tomsich3297b552017-02-22 19:46:41 +0100836 sun8i_mdio_init(dev->name, dev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530837 priv->bus = miiphy_get_dev_by_name(dev->name);
838
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530839 return sun8i_phy_init(priv, dev);
840}
841
842static const struct eth_ops sun8i_emac_eth_ops = {
843 .start = sun8i_emac_eth_start,
844 .write_hwaddr = sun8i_eth_write_hwaddr,
845 .send = sun8i_emac_eth_send,
846 .recv = sun8i_emac_eth_recv,
847 .free_pkt = sun8i_eth_free_pkt,
848 .stop = sun8i_emac_eth_stop,
849};
850
Jagan Teki727ed792019-02-28 00:27:00 +0530851static int sun8i_get_ephy_nodes(struct emac_eth_dev *priv)
852{
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200853 int emac_node, ephy_node, ret, ephy_handle;
854
855 emac_node = fdt_path_offset(gd->fdt_blob,
856 "/soc/ethernet@1c30000");
857 if (emac_node < 0) {
858 debug("failed to get emac node\n");
859 return emac_node;
860 }
861 ephy_handle = fdtdec_lookup_phandle(gd->fdt_blob,
862 emac_node, "phy-handle");
Jagan Teki727ed792019-02-28 00:27:00 +0530863
864 /* look for mdio-mux node for internal PHY node */
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200865 ephy_node = fdt_path_offset(gd->fdt_blob,
866 "/soc/ethernet@1c30000/mdio-mux/mdio@1/ethernet-phy@1");
867 if (ephy_node < 0) {
Jagan Teki727ed792019-02-28 00:27:00 +0530868 debug("failed to get mdio-mux with internal PHY\n");
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200869 return ephy_node;
Jagan Teki727ed792019-02-28 00:27:00 +0530870 }
871
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200872 /* This is not the phy we are looking for */
873 if (ephy_node != ephy_handle)
874 return 0;
875
876 ret = fdt_node_check_compatible(gd->fdt_blob, ephy_node,
Jagan Teki727ed792019-02-28 00:27:00 +0530877 "allwinner,sun8i-h3-mdio-internal");
878 if (ret < 0) {
879 debug("failed to find mdio-internal node\n");
880 return ret;
881 }
882
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200883 ret = clk_get_by_index_nodev(offset_to_ofnode(ephy_node), 0,
Jagan Teki727ed792019-02-28 00:27:00 +0530884 &priv->ephy_clk);
885 if (ret) {
886 dev_err(dev, "failed to get EPHY TX clock\n");
887 return ret;
888 }
889
Emmanuel Vadot98be8be2019-07-19 22:26:38 +0200890 ret = reset_get_by_index_nodev(offset_to_ofnode(ephy_node), 0,
Jagan Teki727ed792019-02-28 00:27:00 +0530891 &priv->ephy_rst);
892 if (ret) {
893 dev_err(dev, "failed to get EPHY TX reset\n");
894 return ret;
895 }
896
897 priv->use_internal_phy = true;
898
899 return 0;
900}
901
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530902static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)
903{
Philipp Tomsich3297b552017-02-22 19:46:41 +0100904 struct sun8i_eth_pdata *sun8i_pdata = dev_get_platdata(dev);
905 struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530906 struct emac_eth_dev *priv = dev_get_priv(dev);
907 const char *phy_mode;
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100908 const fdt32_t *reg;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700909 int node = dev_of_offset(dev);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530910 int offset = 0;
Simon Glassfa4689a2019-12-06 21:41:35 -0700911#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich3297b552017-02-22 19:46:41 +0100912 int reset_flags = GPIOD_IS_OUT;
Philipp Tomsich3297b552017-02-22 19:46:41 +0100913#endif
Jagan Tekicb63d282019-02-28 00:26:58 +0530914 int ret;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530915
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100916 pdata->iobase = devfdt_get_addr(dev);
Andre Przywaraba3a96d2018-04-04 01:31:16 +0100917 if (pdata->iobase == FDT_ADDR_T_NONE) {
918 debug("%s: Cannot find MAC base address\n", __func__);
919 return -EINVAL;
920 }
921
Lothar Feltene8cbced2018-07-13 10:45:28 +0200922 priv->variant = dev_get_driver_data(dev);
923
924 if (!priv->variant) {
925 printf("%s: Missing variant\n", __func__);
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100926 return -EINVAL;
927 }
Lothar Feltene8cbced2018-07-13 10:45:28 +0200928
Jagan Tekicb63d282019-02-28 00:26:58 +0530929 ret = clk_get_by_name(dev, "stmmaceth", &priv->tx_clk);
930 if (ret) {
931 dev_err(dev, "failed to get TX clock\n");
932 return ret;
933 }
934
935 ret = reset_get_by_name(dev, "stmmaceth", &priv->tx_rst);
936 if (ret && ret != -ENOENT) {
937 dev_err(dev, "failed to get TX reset\n");
938 return ret;
939 }
940
Jagan Teki1cfc64c2019-02-28 00:26:51 +0530941 offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "syscon");
942 if (offset < 0) {
943 debug("%s: cannot find syscon node\n", __func__);
944 return -EINVAL;
945 }
946
947 reg = fdt_getprop(gd->fdt_blob, offset, "reg", NULL);
948 if (!reg) {
949 debug("%s: cannot find reg property in syscon node\n",
950 __func__);
951 return -EINVAL;
952 }
953 priv->sysctl_reg = fdt_translate_address((void *)gd->fdt_blob,
954 offset, reg);
955 if (priv->sysctl_reg == FDT_ADDR_T_NONE) {
956 debug("%s: Cannot find syscon base address\n", __func__);
957 return -EINVAL;
Andre Przywaraba3a96d2018-04-04 01:31:16 +0100958 }
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530959
960 pdata->phy_interface = -1;
961 priv->phyaddr = -1;
962 priv->use_internal_phy = false;
963
Andre Przywara94f3bbd2018-04-04 01:31:20 +0100964 offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
Andre Przywaraba3a96d2018-04-04 01:31:16 +0100965 if (offset < 0) {
966 debug("%s: Cannot find PHY address\n", __func__);
967 return -EINVAL;
968 }
969 priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530970
Simon Glassdd79d6e2017-01-17 16:52:55 -0700971 phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530972
973 if (phy_mode)
974 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
975 printf("phy interface%d\n", pdata->phy_interface);
976
977 if (pdata->phy_interface == -1) {
978 debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
979 return -EINVAL;
980 }
981
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530982 if (priv->variant == H3_EMAC) {
Jagan Teki727ed792019-02-28 00:27:00 +0530983 ret = sun8i_get_ephy_nodes(priv);
984 if (ret)
985 return ret;
Amit Singh Tomard194c0e2016-07-06 17:59:44 +0530986 }
987
988 priv->interface = pdata->phy_interface;
989
990 if (!priv->use_internal_phy)
991 parse_phy_pins(dev);
992
Icenowy Zheng525dc442018-11-23 00:37:48 +0100993 sun8i_pdata->tx_delay_ps = fdtdec_get_int(gd->fdt_blob, node,
994 "allwinner,tx-delay-ps", 0);
995 if (sun8i_pdata->tx_delay_ps < 0 || sun8i_pdata->tx_delay_ps > 700)
996 printf("%s: Invalid TX delay value %d\n", __func__,
997 sun8i_pdata->tx_delay_ps);
998
999 sun8i_pdata->rx_delay_ps = fdtdec_get_int(gd->fdt_blob, node,
1000 "allwinner,rx-delay-ps", 0);
1001 if (sun8i_pdata->rx_delay_ps < 0 || sun8i_pdata->rx_delay_ps > 3100)
1002 printf("%s: Invalid RX delay value %d\n", __func__,
1003 sun8i_pdata->rx_delay_ps);
1004
Simon Glassfa4689a2019-12-06 21:41:35 -07001005#if CONFIG_IS_ENABLED(DM_GPIO)
Simon Glass7a494432017-05-17 17:18:09 -06001006 if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
Philipp Tomsich3297b552017-02-22 19:46:41 +01001007 "snps,reset-active-low"))
1008 reset_flags |= GPIOD_ACTIVE_LOW;
1009
1010 ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
1011 &priv->reset_gpio, reset_flags);
1012
1013 if (ret == 0) {
Simon Glass7a494432017-05-17 17:18:09 -06001014 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
Philipp Tomsich3297b552017-02-22 19:46:41 +01001015 "snps,reset-delays-us",
1016 sun8i_pdata->reset_delays, 3);
1017 } else if (ret == -ENOENT) {
1018 ret = 0;
1019 }
1020#endif
1021
Amit Singh Tomard194c0e2016-07-06 17:59:44 +05301022 return 0;
1023}
1024
1025static const struct udevice_id sun8i_emac_eth_ids[] = {
1026 {.compatible = "allwinner,sun8i-h3-emac", .data = (uintptr_t)H3_EMAC },
1027 {.compatible = "allwinner,sun50i-a64-emac",
1028 .data = (uintptr_t)A64_EMAC },
1029 {.compatible = "allwinner,sun8i-a83t-emac",
1030 .data = (uintptr_t)A83T_EMAC },
Lothar Feltene8cbced2018-07-13 10:45:28 +02001031 {.compatible = "allwinner,sun8i-r40-gmac",
1032 .data = (uintptr_t)R40_GMAC },
Amit Singh Tomard194c0e2016-07-06 17:59:44 +05301033 { }
1034};
1035
1036U_BOOT_DRIVER(eth_sun8i_emac) = {
1037 .name = "eth_sun8i_emac",
1038 .id = UCLASS_ETH,
1039 .of_match = sun8i_emac_eth_ids,
1040 .ofdata_to_platdata = sun8i_emac_eth_ofdata_to_platdata,
1041 .probe = sun8i_emac_eth_probe,
1042 .ops = &sun8i_emac_eth_ops,
1043 .priv_auto_alloc_size = sizeof(struct emac_eth_dev),
Philipp Tomsich3297b552017-02-22 19:46:41 +01001044 .platdata_auto_alloc_size = sizeof(struct sun8i_eth_pdata),
Amit Singh Tomard194c0e2016-07-06 17:59:44 +05301045 .flags = DM_FLAG_ALLOC_PRIV_DMA,
1046};