blob: 45ac11849509f43e3630a82fc37cc51ea616c7fd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Amit Singh Tomara29710c2016-07-06 17:59:44 +05302/*
3 * (C) Copyright 2016
4 * Author: Amit Singh Tomar, amittomer25@gmail.com
5 *
Amit Singh Tomara29710c2016-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 Glass1eb69ae2019-11-14 12:57:39 -070013#include <cpu_func.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060015#include <asm/cache.h>
Amit Singh Tomara29710c2016-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 Tekid3a2c052019-02-28 00:26:58 +053020#include <clk.h>
Amit Singh Tomara29710c2016-07-06 17:59:44 +053021#include <dm.h>
22#include <fdt_support.h>
Simon Glass336d4612020-02-03 07:36:16 -070023#include <dm/device_compat.h>
Simon Glassc05ed002020-05-10 11:40:11 -060024#include <linux/delay.h>
Amit Singh Tomara29710c2016-07-06 17:59:44 +053025#include <linux/err.h>
26#include <malloc.h>
27#include <miiphy.h>
28#include <net.h>
Jagan Tekid3a2c052019-02-28 00:26:58 +053029#include <reset.h>
Andre Przywarac0341172018-04-04 01:31:15 +010030#include <dt-bindings/pinctrl/sun4i-a10.h>
Simon Glassbcee8d62019-12-06 21:41:35 -070031#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich4d555ae2017-02-22 19:46:41 +010032#include <asm-generic/gpio.h>
33#endif
Amit Singh Tomara29710c2016-07-06 17:59:44 +053034
Amit Singh Tomara29710c2016-07-06 17:59:44 +053035#define MDIO_CMD_MII_BUSY BIT(0)
36#define MDIO_CMD_MII_WRITE BIT(1)
37
38#define MDIO_CMD_MII_PHY_REG_ADDR_MASK 0x000001f0
39#define MDIO_CMD_MII_PHY_REG_ADDR_SHIFT 4
40#define MDIO_CMD_MII_PHY_ADDR_MASK 0x0001f000
41#define MDIO_CMD_MII_PHY_ADDR_SHIFT 12
42
43#define CONFIG_TX_DESCR_NUM 32
44#define CONFIG_RX_DESCR_NUM 32
Hans de Goede40694372016-07-27 17:31:17 +020045#define CONFIG_ETH_BUFSIZE 2048 /* Note must be dma aligned */
46
47/*
48 * The datasheet says that each descriptor can transfers up to 4096 bytes
49 * But later, the register documentation reduces that value to 2048,
50 * using 2048 cause strange behaviours and even BSP driver use 2047
51 */
52#define CONFIG_ETH_RXSIZE 2044 /* Note must fit in ETH_BUFSIZE */
Amit Singh Tomara29710c2016-07-06 17:59:44 +053053
54#define TX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_TX_DESCR_NUM)
55#define RX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_RX_DESCR_NUM)
56
57#define H3_EPHY_DEFAULT_VALUE 0x58000
58#define H3_EPHY_DEFAULT_MASK GENMASK(31, 15)
59#define H3_EPHY_ADDR_SHIFT 20
60#define REG_PHY_ADDR_MASK GENMASK(4, 0)
61#define H3_EPHY_LED_POL BIT(17) /* 1: active low, 0: active high */
62#define H3_EPHY_SHUTDOWN BIT(16) /* 1: shutdown, 0: power up */
63#define H3_EPHY_SELECT BIT(15) /* 1: internal PHY, 0: external PHY */
64
65#define SC_RMII_EN BIT(13)
66#define SC_EPIT BIT(2) /* 1: RGMII, 0: MII */
67#define SC_ETCS_MASK GENMASK(1, 0)
68#define SC_ETCS_EXT_GMII 0x1
69#define SC_ETCS_INT_GMII 0x2
Icenowy Zheng9b16ede2018-11-23 00:37:48 +010070#define SC_ETXDC_MASK GENMASK(12, 10)
71#define SC_ETXDC_OFFSET 10
72#define SC_ERXDC_MASK GENMASK(9, 5)
73#define SC_ERXDC_OFFSET 5
Amit Singh Tomara29710c2016-07-06 17:59:44 +053074
75#define CONFIG_MDIO_TIMEOUT (3 * CONFIG_SYS_HZ)
76
77#define AHB_GATE_OFFSET_EPHY 0
78
Lothar Feltenc6a21d62018-07-13 10:45:27 +020079/* IO mux settings */
80#define SUN8I_IOMUX_H3 2
Lothar Feltene46d73f2018-07-13 10:45:28 +020081#define SUN8I_IOMUX_R40 5
Lothar Feltenc6a21d62018-07-13 10:45:27 +020082#define SUN8I_IOMUX 4
Amit Singh Tomara29710c2016-07-06 17:59:44 +053083
84/* H3/A64 EMAC Register's offset */
85#define EMAC_CTL0 0x00
86#define EMAC_CTL1 0x04
87#define EMAC_INT_STA 0x08
88#define EMAC_INT_EN 0x0c
89#define EMAC_TX_CTL0 0x10
90#define EMAC_TX_CTL1 0x14
91#define EMAC_TX_FLOW_CTL 0x1c
92#define EMAC_TX_DMA_DESC 0x20
93#define EMAC_RX_CTL0 0x24
94#define EMAC_RX_CTL1 0x28
95#define EMAC_RX_DMA_DESC 0x34
96#define EMAC_MII_CMD 0x48
97#define EMAC_MII_DATA 0x4c
98#define EMAC_ADDR0_HIGH 0x50
99#define EMAC_ADDR0_LOW 0x54
100#define EMAC_TX_DMA_STA 0xb0
101#define EMAC_TX_CUR_DESC 0xb4
102#define EMAC_TX_CUR_BUF 0xb8
103#define EMAC_RX_DMA_STA 0xc0
104#define EMAC_RX_CUR_DESC 0xc4
105
106DECLARE_GLOBAL_DATA_PTR;
107
108enum emac_variant {
109 A83T_EMAC = 1,
110 H3_EMAC,
111 A64_EMAC,
Lothar Feltene46d73f2018-07-13 10:45:28 +0200112 R40_GMAC,
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530113};
114
115struct emac_dma_desc {
116 u32 status;
117 u32 st;
118 u32 buf_addr;
119 u32 next;
120} __aligned(ARCH_DMA_MINALIGN);
121
122struct emac_eth_dev {
123 struct emac_dma_desc rx_chain[CONFIG_TX_DESCR_NUM];
124 struct emac_dma_desc tx_chain[CONFIG_RX_DESCR_NUM];
125 char rxbuffer[RX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN);
126 char txbuffer[TX_TOTAL_BUFSIZE] __aligned(ARCH_DMA_MINALIGN);
127
128 u32 interface;
129 u32 phyaddr;
130 u32 link;
131 u32 speed;
132 u32 duplex;
133 u32 phy_configured;
134 u32 tx_currdescnum;
135 u32 rx_currdescnum;
136 u32 addr;
137 u32 tx_slot;
138 bool use_internal_phy;
139
140 enum emac_variant variant;
141 void *mac_reg;
142 phys_addr_t sysctl_reg;
143 struct phy_device *phydev;
144 struct mii_dev *bus;
Jagan Tekid3a2c052019-02-28 00:26:58 +0530145 struct clk tx_clk;
Jagan Teki23484532019-02-28 00:27:00 +0530146 struct clk ephy_clk;
Jagan Tekid3a2c052019-02-28 00:26:58 +0530147 struct reset_ctl tx_rst;
Jagan Teki23484532019-02-28 00:27:00 +0530148 struct reset_ctl ephy_rst;
Simon Glassbcee8d62019-12-06 21:41:35 -0700149#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100150 struct gpio_desc reset_gpio;
151#endif
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530152};
153
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100154
155struct sun8i_eth_pdata {
156 struct eth_pdata eth_pdata;
157 u32 reset_delays[3];
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100158 int tx_delay_ps;
159 int rx_delay_ps;
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100160};
161
162
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530163static int sun8i_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
164{
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100165 struct udevice *dev = bus->priv;
166 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530167 ulong start;
168 u32 miiaddr = 0;
169 int timeout = CONFIG_MDIO_TIMEOUT;
170
171 miiaddr &= ~MDIO_CMD_MII_WRITE;
172 miiaddr &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
173 miiaddr |= (reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
174 MDIO_CMD_MII_PHY_REG_ADDR_MASK;
175
176 miiaddr &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
177
178 miiaddr |= (addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
179 MDIO_CMD_MII_PHY_ADDR_MASK;
180
181 miiaddr |= MDIO_CMD_MII_BUSY;
182
183 writel(miiaddr, priv->mac_reg + EMAC_MII_CMD);
184
185 start = get_timer(0);
186 while (get_timer(start) < timeout) {
187 if (!(readl(priv->mac_reg + EMAC_MII_CMD) & MDIO_CMD_MII_BUSY))
188 return readl(priv->mac_reg + EMAC_MII_DATA);
189 udelay(10);
190 };
191
192 return -1;
193}
194
195static int sun8i_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
196 u16 val)
197{
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100198 struct udevice *dev = bus->priv;
199 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530200 ulong start;
201 u32 miiaddr = 0;
202 int ret = -1, timeout = CONFIG_MDIO_TIMEOUT;
203
204 miiaddr &= ~MDIO_CMD_MII_PHY_REG_ADDR_MASK;
205 miiaddr |= (reg << MDIO_CMD_MII_PHY_REG_ADDR_SHIFT) &
206 MDIO_CMD_MII_PHY_REG_ADDR_MASK;
207
208 miiaddr &= ~MDIO_CMD_MII_PHY_ADDR_MASK;
209 miiaddr |= (addr << MDIO_CMD_MII_PHY_ADDR_SHIFT) &
210 MDIO_CMD_MII_PHY_ADDR_MASK;
211
212 miiaddr |= MDIO_CMD_MII_WRITE;
213 miiaddr |= MDIO_CMD_MII_BUSY;
214
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530215 writel(val, priv->mac_reg + EMAC_MII_DATA);
Philipp Tomsich1deeecb2016-11-16 01:40:27 +0000216 writel(miiaddr, priv->mac_reg + EMAC_MII_CMD);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530217
218 start = get_timer(0);
219 while (get_timer(start) < timeout) {
220 if (!(readl(priv->mac_reg + EMAC_MII_CMD) &
221 MDIO_CMD_MII_BUSY)) {
222 ret = 0;
223 break;
224 }
225 udelay(10);
226 };
227
228 return ret;
229}
230
231static int _sun8i_write_hwaddr(struct emac_eth_dev *priv, u8 *mac_id)
232{
233 u32 macid_lo, macid_hi;
234
235 macid_lo = mac_id[0] + (mac_id[1] << 8) + (mac_id[2] << 16) +
236 (mac_id[3] << 24);
237 macid_hi = mac_id[4] + (mac_id[5] << 8);
238
239 writel(macid_hi, priv->mac_reg + EMAC_ADDR0_HIGH);
240 writel(macid_lo, priv->mac_reg + EMAC_ADDR0_LOW);
241
242 return 0;
243}
244
245static void sun8i_adjust_link(struct emac_eth_dev *priv,
246 struct phy_device *phydev)
247{
248 u32 v;
249
250 v = readl(priv->mac_reg + EMAC_CTL0);
251
252 if (phydev->duplex)
253 v |= BIT(0);
254 else
255 v &= ~BIT(0);
256
257 v &= ~0x0C;
258
259 switch (phydev->speed) {
260 case 1000:
261 break;
262 case 100:
263 v |= BIT(2);
264 v |= BIT(3);
265 break;
266 case 10:
267 v |= BIT(3);
268 break;
269 }
270 writel(v, priv->mac_reg + EMAC_CTL0);
271}
272
273static int sun8i_emac_set_syscon_ephy(struct emac_eth_dev *priv, u32 *reg)
274{
275 if (priv->use_internal_phy) {
276 /* H3 based SoC's that has an Internal 100MBit PHY
277 * needs to be configured and powered up before use
278 */
279 *reg &= ~H3_EPHY_DEFAULT_MASK;
280 *reg |= H3_EPHY_DEFAULT_VALUE;
281 *reg |= priv->phyaddr << H3_EPHY_ADDR_SHIFT;
282 *reg &= ~H3_EPHY_SHUTDOWN;
283 *reg |= H3_EPHY_SELECT;
284 } else
285 /* This is to select External Gigabit PHY on
286 * the boards with H3 SoC.
287 */
288 *reg &= ~H3_EPHY_SELECT;
289
290 return 0;
291}
292
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100293static int sun8i_emac_set_syscon(struct sun8i_eth_pdata *pdata,
294 struct emac_eth_dev *priv)
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530295{
296 int ret;
297 u32 reg;
298
Jagan Teki695f6042019-02-28 00:26:51 +0530299 if (priv->variant == R40_GMAC) {
300 /* Select RGMII for R40 */
301 reg = readl(priv->sysctl_reg + 0x164);
302 reg |= CCM_GMAC_CTRL_TX_CLK_SRC_INT_RGMII |
303 CCM_GMAC_CTRL_GPIT_RGMII |
304 CCM_GMAC_CTRL_TX_CLK_DELAY(CONFIG_GMAC_TX_DELAY);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530305
Jagan Teki695f6042019-02-28 00:26:51 +0530306 writel(reg, priv->sysctl_reg + 0x164);
Lothar Feltene46d73f2018-07-13 10:45:28 +0200307 return 0;
Jagan Teki695f6042019-02-28 00:26:51 +0530308 }
309
310 reg = readl(priv->sysctl_reg + 0x30);
Lothar Feltene46d73f2018-07-13 10:45:28 +0200311
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530312 if (priv->variant == H3_EMAC) {
313 ret = sun8i_emac_set_syscon_ephy(priv, &reg);
314 if (ret)
315 return ret;
316 }
317
318 reg &= ~(SC_ETCS_MASK | SC_EPIT);
319 if (priv->variant == H3_EMAC || priv->variant == A64_EMAC)
320 reg &= ~SC_RMII_EN;
321
322 switch (priv->interface) {
323 case PHY_INTERFACE_MODE_MII:
324 /* default */
325 break;
326 case PHY_INTERFACE_MODE_RGMII:
327 reg |= SC_EPIT | SC_ETCS_INT_GMII;
328 break;
329 case PHY_INTERFACE_MODE_RMII:
330 if (priv->variant == H3_EMAC ||
331 priv->variant == A64_EMAC) {
332 reg |= SC_RMII_EN | SC_ETCS_EXT_GMII;
333 break;
334 }
335 /* RMII not supported on A83T */
336 default:
337 debug("%s: Invalid PHY interface\n", __func__);
338 return -EINVAL;
339 }
340
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100341 if (pdata->tx_delay_ps)
342 reg |= ((pdata->tx_delay_ps / 100) << SC_ETXDC_OFFSET)
343 & SC_ETXDC_MASK;
344
345 if (pdata->rx_delay_ps)
346 reg |= ((pdata->rx_delay_ps / 100) << SC_ERXDC_OFFSET)
347 & SC_ERXDC_MASK;
348
Andre Przywara12afd952018-04-04 01:31:16 +0100349 writel(reg, priv->sysctl_reg + 0x30);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530350
351 return 0;
352}
353
354static int sun8i_phy_init(struct emac_eth_dev *priv, void *dev)
355{
356 struct phy_device *phydev;
357
358 phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
359 if (!phydev)
360 return -ENODEV;
361
362 phy_connect_dev(phydev, dev);
363
364 priv->phydev = phydev;
365 phy_config(priv->phydev);
366
367 return 0;
368}
369
370static void rx_descs_init(struct emac_eth_dev *priv)
371{
372 struct emac_dma_desc *desc_table_p = &priv->rx_chain[0];
373 char *rxbuffs = &priv->rxbuffer[0];
374 struct emac_dma_desc *desc_p;
375 u32 idx;
376
377 /* flush Rx buffers */
378 flush_dcache_range((uintptr_t)rxbuffs, (ulong)rxbuffs +
379 RX_TOTAL_BUFSIZE);
380
381 for (idx = 0; idx < CONFIG_RX_DESCR_NUM; idx++) {
382 desc_p = &desc_table_p[idx];
383 desc_p->buf_addr = (uintptr_t)&rxbuffs[idx * CONFIG_ETH_BUFSIZE]
384 ;
385 desc_p->next = (uintptr_t)&desc_table_p[idx + 1];
Hans de Goede40694372016-07-27 17:31:17 +0200386 desc_p->st |= CONFIG_ETH_RXSIZE;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530387 desc_p->status = BIT(31);
388 }
389
390 /* Correcting the last pointer of the chain */
391 desc_p->next = (uintptr_t)&desc_table_p[0];
392
393 flush_dcache_range((uintptr_t)priv->rx_chain,
394 (uintptr_t)priv->rx_chain +
395 sizeof(priv->rx_chain));
396
397 writel((uintptr_t)&desc_table_p[0], (priv->mac_reg + EMAC_RX_DMA_DESC));
398 priv->rx_currdescnum = 0;
399}
400
401static void tx_descs_init(struct emac_eth_dev *priv)
402{
403 struct emac_dma_desc *desc_table_p = &priv->tx_chain[0];
404 char *txbuffs = &priv->txbuffer[0];
405 struct emac_dma_desc *desc_p;
406 u32 idx;
407
408 for (idx = 0; idx < CONFIG_TX_DESCR_NUM; idx++) {
409 desc_p = &desc_table_p[idx];
410 desc_p->buf_addr = (uintptr_t)&txbuffs[idx * CONFIG_ETH_BUFSIZE]
411 ;
412 desc_p->next = (uintptr_t)&desc_table_p[idx + 1];
413 desc_p->status = (1 << 31);
414 desc_p->st = 0;
415 }
416
417 /* Correcting the last pointer of the chain */
418 desc_p->next = (uintptr_t)&desc_table_p[0];
419
420 /* Flush all Tx buffer descriptors */
421 flush_dcache_range((uintptr_t)priv->tx_chain,
422 (uintptr_t)priv->tx_chain +
423 sizeof(priv->tx_chain));
424
425 writel((uintptr_t)&desc_table_p[0], priv->mac_reg + EMAC_TX_DMA_DESC);
426 priv->tx_currdescnum = 0;
427}
428
429static int _sun8i_emac_eth_init(struct emac_eth_dev *priv, u8 *enetaddr)
430{
431 u32 reg, v;
432 int timeout = 100;
433
434 reg = readl((priv->mac_reg + EMAC_CTL1));
435
436 if (!(reg & 0x1)) {
437 /* Soft reset MAC */
438 setbits_le32((priv->mac_reg + EMAC_CTL1), 0x1);
439 do {
440 reg = readl(priv->mac_reg + EMAC_CTL1);
441 } while ((reg & 0x01) != 0 && (--timeout));
442 if (!timeout) {
443 printf("%s: Timeout\n", __func__);
444 return -1;
445 }
446 }
447
448 /* Rewrite mac address after reset */
449 _sun8i_write_hwaddr(priv, enetaddr);
450
451 v = readl(priv->mac_reg + EMAC_TX_CTL1);
452 /* TX_MD Transmission starts after a full frame located in TX DMA FIFO*/
453 v |= BIT(1);
454 writel(v, priv->mac_reg + EMAC_TX_CTL1);
455
456 v = readl(priv->mac_reg + EMAC_RX_CTL1);
457 /* RX_MD RX DMA reads data from RX DMA FIFO to host memory after a
458 * complete frame has been written to RX DMA FIFO
459 */
460 v |= BIT(1);
461 writel(v, priv->mac_reg + EMAC_RX_CTL1);
462
463 /* DMA */
464 writel(8 << 24, priv->mac_reg + EMAC_CTL1);
465
466 /* Initialize rx/tx descriptors */
467 rx_descs_init(priv);
468 tx_descs_init(priv);
469
470 /* PHY Start Up */
Samuel Holland2d530182018-01-27 23:53:20 -0600471 phy_startup(priv->phydev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530472
473 sun8i_adjust_link(priv, priv->phydev);
474
475 /* Start RX DMA */
476 v = readl(priv->mac_reg + EMAC_RX_CTL1);
477 v |= BIT(30);
478 writel(v, priv->mac_reg + EMAC_RX_CTL1);
479 /* Start TX DMA */
480 v = readl(priv->mac_reg + EMAC_TX_CTL1);
481 v |= BIT(30);
482 writel(v, priv->mac_reg + EMAC_TX_CTL1);
483
484 /* Enable RX/TX */
485 setbits_le32(priv->mac_reg + EMAC_RX_CTL0, BIT(31));
486 setbits_le32(priv->mac_reg + EMAC_TX_CTL0, BIT(31));
487
488 return 0;
489}
490
491static int parse_phy_pins(struct udevice *dev)
492{
Lothar Feltenc6a21d62018-07-13 10:45:27 +0200493 struct emac_eth_dev *priv = dev_get_priv(dev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530494 int offset;
495 const char *pin_name;
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100496 int drive, pull = SUN4I_PINCTRL_NO_PULL, i;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530497
Simon Glasse160f7d2017-01-17 16:52:55 -0700498 offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530499 "pinctrl-0");
500 if (offset < 0) {
501 printf("WARNING: emac: cannot find pinctrl-0 node\n");
502 return offset;
503 }
504
505 drive = fdt_getprop_u32_default_node(gd->fdt_blob, offset, 0,
Andre Przywarac0341172018-04-04 01:31:15 +0100506 "drive-strength", ~0);
507 if (drive != ~0) {
508 if (drive <= 10)
509 drive = SUN4I_PINCTRL_10_MA;
510 else if (drive <= 20)
511 drive = SUN4I_PINCTRL_20_MA;
512 else if (drive <= 30)
513 drive = SUN4I_PINCTRL_30_MA;
514 else
515 drive = SUN4I_PINCTRL_40_MA;
Andre Przywarac0341172018-04-04 01:31:15 +0100516 }
517
518 if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-up", NULL))
519 pull = SUN4I_PINCTRL_PULL_UP;
Andre Przywarac0341172018-04-04 01:31:15 +0100520 else if (fdt_get_property(gd->fdt_blob, offset, "bias-pull-down", NULL))
521 pull = SUN4I_PINCTRL_PULL_DOWN;
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100522
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530523 for (i = 0; ; i++) {
524 int pin;
525
Simon Glassb02e4042016-10-02 17:59:28 -0600526 pin_name = fdt_stringlist_get(gd->fdt_blob, offset,
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100527 "pins", i, NULL);
528 if (!pin_name)
529 break;
Andre Przywarac0341172018-04-04 01:31:15 +0100530
531 pin = sunxi_name_to_gpio(pin_name);
532 if (pin < 0)
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530533 continue;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530534
Lothar Feltenc6a21d62018-07-13 10:45:27 +0200535 if (priv->variant == H3_EMAC)
536 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX_H3);
Lothar Feltene46d73f2018-07-13 10:45:28 +0200537 else if (priv->variant == R40_GMAC)
538 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX_R40);
Lothar Feltenc6a21d62018-07-13 10:45:27 +0200539 else
540 sunxi_gpio_set_cfgpin(pin, SUN8I_IOMUX);
541
Andre Przywarac0341172018-04-04 01:31:15 +0100542 if (drive != ~0)
543 sunxi_gpio_set_drv(pin, drive);
544 if (pull != ~0)
545 sunxi_gpio_set_pull(pin, pull);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530546 }
547
548 if (!i) {
Andre Przywarac0341172018-04-04 01:31:15 +0100549 printf("WARNING: emac: cannot find pins property\n");
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530550 return -2;
551 }
552
553 return 0;
554}
555
556static int _sun8i_eth_recv(struct emac_eth_dev *priv, uchar **packetp)
557{
558 u32 status, desc_num = priv->rx_currdescnum;
559 struct emac_dma_desc *desc_p = &priv->rx_chain[desc_num];
560 int length = -EAGAIN;
561 int good_packet = 1;
562 uintptr_t desc_start = (uintptr_t)desc_p;
563 uintptr_t desc_end = desc_start +
564 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
565
566 ulong data_start = (uintptr_t)desc_p->buf_addr;
567 ulong data_end;
568
569 /* Invalidate entire buffer descriptor */
570 invalidate_dcache_range(desc_start, desc_end);
571
572 status = desc_p->status;
573
574 /* Check for DMA own bit */
575 if (!(status & BIT(31))) {
576 length = (desc_p->status >> 16) & 0x3FFF;
577
578 if (length < 0x40) {
579 good_packet = 0;
580 debug("RX: Bad Packet (runt)\n");
581 }
582
583 data_end = data_start + length;
584 /* Invalidate received data */
585 invalidate_dcache_range(rounddown(data_start,
586 ARCH_DMA_MINALIGN),
587 roundup(data_end,
588 ARCH_DMA_MINALIGN));
589 if (good_packet) {
Hans de Goede40694372016-07-27 17:31:17 +0200590 if (length > CONFIG_ETH_RXSIZE) {
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530591 printf("Received packet is too big (len=%d)\n",
592 length);
593 return -EMSGSIZE;
594 }
595 *packetp = (uchar *)(ulong)desc_p->buf_addr;
596 return length;
597 }
598 }
599
600 return length;
601}
602
603static int _sun8i_emac_eth_send(struct emac_eth_dev *priv, void *packet,
604 int len)
605{
606 u32 v, desc_num = priv->tx_currdescnum;
607 struct emac_dma_desc *desc_p = &priv->tx_chain[desc_num];
608 uintptr_t desc_start = (uintptr_t)desc_p;
609 uintptr_t desc_end = desc_start +
610 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
611
612 uintptr_t data_start = (uintptr_t)desc_p->buf_addr;
613 uintptr_t data_end = data_start +
614 roundup(len, ARCH_DMA_MINALIGN);
615
616 /* Invalidate entire buffer descriptor */
617 invalidate_dcache_range(desc_start, desc_end);
618
619 desc_p->st = len;
620 /* Mandatory undocumented bit */
621 desc_p->st |= BIT(24);
622
623 memcpy((void *)data_start, packet, len);
624
625 /* Flush data to be sent */
626 flush_dcache_range(data_start, data_end);
627
628 /* frame end */
629 desc_p->st |= BIT(30);
630 desc_p->st |= BIT(31);
631
632 /*frame begin */
633 desc_p->st |= BIT(29);
634 desc_p->status = BIT(31);
635
636 /*Descriptors st and status field has changed, so FLUSH it */
637 flush_dcache_range(desc_start, desc_end);
638
639 /* Move to next Descriptor and wrap around */
640 if (++desc_num >= CONFIG_TX_DESCR_NUM)
641 desc_num = 0;
642 priv->tx_currdescnum = desc_num;
643
644 /* Start the DMA */
645 v = readl(priv->mac_reg + EMAC_TX_CTL1);
646 v |= BIT(31);/* mandatory */
647 v |= BIT(30);/* mandatory */
648 writel(v, priv->mac_reg + EMAC_TX_CTL1);
649
650 return 0;
651}
652
653static int sun8i_eth_write_hwaddr(struct udevice *dev)
654{
655 struct eth_pdata *pdata = dev_get_platdata(dev);
656 struct emac_eth_dev *priv = dev_get_priv(dev);
657
658 return _sun8i_write_hwaddr(priv, pdata->enetaddr);
659}
660
Jagan Tekid3a2c052019-02-28 00:26:58 +0530661static int sun8i_emac_board_setup(struct emac_eth_dev *priv)
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530662{
Jagan Tekid3a2c052019-02-28 00:26:58 +0530663 int ret;
664
665 ret = clk_enable(&priv->tx_clk);
666 if (ret) {
667 dev_err(dev, "failed to enable TX clock\n");
668 return ret;
669 }
670
671 if (reset_valid(&priv->tx_rst)) {
672 ret = reset_deassert(&priv->tx_rst);
673 if (ret) {
674 dev_err(dev, "failed to deassert TX reset\n");
675 goto err_tx_clk;
676 }
677 }
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530678
Jagan Teki23484532019-02-28 00:27:00 +0530679 /* Only H3/H5 have clock controls for internal EPHY */
680 if (clk_valid(&priv->ephy_clk)) {
681 ret = clk_enable(&priv->ephy_clk);
682 if (ret) {
683 dev_err(dev, "failed to enable EPHY TX clock\n");
684 return ret;
685 }
686 }
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530687
Jagan Teki23484532019-02-28 00:27:00 +0530688 if (reset_valid(&priv->ephy_rst)) {
689 ret = reset_deassert(&priv->ephy_rst);
690 if (ret) {
691 dev_err(dev, "failed to deassert EPHY TX clock\n");
692 return ret;
Lothar Feltenc6a21d62018-07-13 10:45:27 +0200693 }
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530694 }
695
Jagan Tekid3a2c052019-02-28 00:26:58 +0530696 return 0;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530697
Jagan Tekid3a2c052019-02-28 00:26:58 +0530698err_tx_clk:
699 clk_disable(&priv->tx_clk);
700 return ret;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530701}
702
Simon Glassbcee8d62019-12-06 21:41:35 -0700703#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100704static int sun8i_mdio_reset(struct mii_dev *bus)
705{
706 struct udevice *dev = bus->priv;
707 struct emac_eth_dev *priv = dev_get_priv(dev);
708 struct sun8i_eth_pdata *pdata = dev_get_platdata(dev);
709 int ret;
710
711 if (!dm_gpio_is_valid(&priv->reset_gpio))
712 return 0;
713
714 /* reset the phy */
715 ret = dm_gpio_set_value(&priv->reset_gpio, 0);
716 if (ret)
717 return ret;
718
719 udelay(pdata->reset_delays[0]);
720
721 ret = dm_gpio_set_value(&priv->reset_gpio, 1);
722 if (ret)
723 return ret;
724
725 udelay(pdata->reset_delays[1]);
726
727 ret = dm_gpio_set_value(&priv->reset_gpio, 0);
728 if (ret)
729 return ret;
730
731 udelay(pdata->reset_delays[2]);
732
733 return 0;
734}
735#endif
736
737static int sun8i_mdio_init(const char *name, struct udevice *priv)
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530738{
739 struct mii_dev *bus = mdio_alloc();
740
741 if (!bus) {
742 debug("Failed to allocate MDIO bus\n");
743 return -ENOMEM;
744 }
745
746 bus->read = sun8i_mdio_read;
747 bus->write = sun8i_mdio_write;
748 snprintf(bus->name, sizeof(bus->name), name);
749 bus->priv = (void *)priv;
Simon Glassbcee8d62019-12-06 21:41:35 -0700750#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100751 bus->reset = sun8i_mdio_reset;
752#endif
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530753
754 return mdio_register(bus);
755}
756
757static int sun8i_emac_eth_start(struct udevice *dev)
758{
759 struct eth_pdata *pdata = dev_get_platdata(dev);
760
761 return _sun8i_emac_eth_init(dev->priv, pdata->enetaddr);
762}
763
764static int sun8i_emac_eth_send(struct udevice *dev, void *packet, int length)
765{
766 struct emac_eth_dev *priv = dev_get_priv(dev);
767
768 return _sun8i_emac_eth_send(priv, packet, length);
769}
770
771static int sun8i_emac_eth_recv(struct udevice *dev, int flags, uchar **packetp)
772{
773 struct emac_eth_dev *priv = dev_get_priv(dev);
774
775 return _sun8i_eth_recv(priv, packetp);
776}
777
778static int _sun8i_free_pkt(struct emac_eth_dev *priv)
779{
780 u32 desc_num = priv->rx_currdescnum;
781 struct emac_dma_desc *desc_p = &priv->rx_chain[desc_num];
782 uintptr_t desc_start = (uintptr_t)desc_p;
783 uintptr_t desc_end = desc_start +
784 roundup(sizeof(u32), ARCH_DMA_MINALIGN);
785
786 /* Make the current descriptor valid again */
787 desc_p->status |= BIT(31);
788
789 /* Flush Status field of descriptor */
790 flush_dcache_range(desc_start, desc_end);
791
792 /* Move to next desc and wrap-around condition. */
793 if (++desc_num >= CONFIG_RX_DESCR_NUM)
794 desc_num = 0;
795 priv->rx_currdescnum = desc_num;
796
797 return 0;
798}
799
800static int sun8i_eth_free_pkt(struct udevice *dev, uchar *packet,
801 int length)
802{
803 struct emac_eth_dev *priv = dev_get_priv(dev);
804
805 return _sun8i_free_pkt(priv);
806}
807
808static void sun8i_emac_eth_stop(struct udevice *dev)
809{
810 struct emac_eth_dev *priv = dev_get_priv(dev);
811
812 /* Stop Rx/Tx transmitter */
813 clrbits_le32(priv->mac_reg + EMAC_RX_CTL0, BIT(31));
814 clrbits_le32(priv->mac_reg + EMAC_TX_CTL0, BIT(31));
815
816 /* Stop TX DMA */
817 clrbits_le32(priv->mac_reg + EMAC_TX_CTL1, BIT(30));
818
819 phy_shutdown(priv->phydev);
820}
821
822static int sun8i_emac_eth_probe(struct udevice *dev)
823{
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100824 struct sun8i_eth_pdata *sun8i_pdata = dev_get_platdata(dev);
825 struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530826 struct emac_eth_dev *priv = dev_get_priv(dev);
Jagan Tekid3a2c052019-02-28 00:26:58 +0530827 int ret;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530828
829 priv->mac_reg = (void *)pdata->iobase;
830
Jagan Tekid3a2c052019-02-28 00:26:58 +0530831 ret = sun8i_emac_board_setup(priv);
832 if (ret)
833 return ret;
834
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100835 sun8i_emac_set_syscon(sun8i_pdata, priv);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530836
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100837 sun8i_mdio_init(dev->name, dev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530838 priv->bus = miiphy_get_dev_by_name(dev->name);
839
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530840 return sun8i_phy_init(priv, dev);
841}
842
843static const struct eth_ops sun8i_emac_eth_ops = {
844 .start = sun8i_emac_eth_start,
845 .write_hwaddr = sun8i_eth_write_hwaddr,
846 .send = sun8i_emac_eth_send,
847 .recv = sun8i_emac_eth_recv,
848 .free_pkt = sun8i_eth_free_pkt,
849 .stop = sun8i_emac_eth_stop,
850};
851
Jagan Teki23484532019-02-28 00:27:00 +0530852static int sun8i_get_ephy_nodes(struct emac_eth_dev *priv)
853{
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200854 int emac_node, ephy_node, ret, ephy_handle;
855
856 emac_node = fdt_path_offset(gd->fdt_blob,
857 "/soc/ethernet@1c30000");
858 if (emac_node < 0) {
859 debug("failed to get emac node\n");
860 return emac_node;
861 }
862 ephy_handle = fdtdec_lookup_phandle(gd->fdt_blob,
863 emac_node, "phy-handle");
Jagan Teki23484532019-02-28 00:27:00 +0530864
865 /* look for mdio-mux node for internal PHY node */
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200866 ephy_node = fdt_path_offset(gd->fdt_blob,
867 "/soc/ethernet@1c30000/mdio-mux/mdio@1/ethernet-phy@1");
868 if (ephy_node < 0) {
Jagan Teki23484532019-02-28 00:27:00 +0530869 debug("failed to get mdio-mux with internal PHY\n");
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200870 return ephy_node;
Jagan Teki23484532019-02-28 00:27:00 +0530871 }
872
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200873 /* This is not the phy we are looking for */
874 if (ephy_node != ephy_handle)
875 return 0;
876
877 ret = fdt_node_check_compatible(gd->fdt_blob, ephy_node,
Jagan Teki23484532019-02-28 00:27:00 +0530878 "allwinner,sun8i-h3-mdio-internal");
879 if (ret < 0) {
880 debug("failed to find mdio-internal node\n");
881 return ret;
882 }
883
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200884 ret = clk_get_by_index_nodev(offset_to_ofnode(ephy_node), 0,
Jagan Teki23484532019-02-28 00:27:00 +0530885 &priv->ephy_clk);
886 if (ret) {
887 dev_err(dev, "failed to get EPHY TX clock\n");
888 return ret;
889 }
890
Emmanuel Vadotd53e5222019-07-19 22:26:38 +0200891 ret = reset_get_by_index_nodev(offset_to_ofnode(ephy_node), 0,
Jagan Teki23484532019-02-28 00:27:00 +0530892 &priv->ephy_rst);
893 if (ret) {
894 dev_err(dev, "failed to get EPHY TX reset\n");
895 return ret;
896 }
897
898 priv->use_internal_phy = true;
899
900 return 0;
901}
902
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530903static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)
904{
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100905 struct sun8i_eth_pdata *sun8i_pdata = dev_get_platdata(dev);
906 struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530907 struct emac_eth_dev *priv = dev_get_priv(dev);
908 const char *phy_mode;
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100909 const fdt32_t *reg;
Simon Glasse160f7d2017-01-17 16:52:55 -0700910 int node = dev_of_offset(dev);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530911 int offset = 0;
Simon Glassbcee8d62019-12-06 21:41:35 -0700912#if CONFIG_IS_ENABLED(DM_GPIO)
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100913 int reset_flags = GPIOD_IS_OUT;
Philipp Tomsich4d555ae2017-02-22 19:46:41 +0100914#endif
Jagan Tekid3a2c052019-02-28 00:26:58 +0530915 int ret;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530916
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100917 pdata->iobase = devfdt_get_addr(dev);
Andre Przywara12afd952018-04-04 01:31:16 +0100918 if (pdata->iobase == FDT_ADDR_T_NONE) {
919 debug("%s: Cannot find MAC base address\n", __func__);
920 return -EINVAL;
921 }
922
Lothar Feltene46d73f2018-07-13 10:45:28 +0200923 priv->variant = dev_get_driver_data(dev);
924
925 if (!priv->variant) {
926 printf("%s: Missing variant\n", __func__);
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100927 return -EINVAL;
Andre Przywara12afd952018-04-04 01:31:16 +0100928 }
Lothar Feltene46d73f2018-07-13 10:45:28 +0200929
Jagan Tekid3a2c052019-02-28 00:26:58 +0530930 ret = clk_get_by_name(dev, "stmmaceth", &priv->tx_clk);
931 if (ret) {
932 dev_err(dev, "failed to get TX clock\n");
933 return ret;
934 }
935
936 ret = reset_get_by_name(dev, "stmmaceth", &priv->tx_rst);
937 if (ret && ret != -ENOENT) {
938 dev_err(dev, "failed to get TX reset\n");
939 return ret;
940 }
941
Jagan Teki695f6042019-02-28 00:26:51 +0530942 offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "syscon");
943 if (offset < 0) {
944 debug("%s: cannot find syscon node\n", __func__);
945 return -EINVAL;
946 }
947
948 reg = fdt_getprop(gd->fdt_blob, offset, "reg", NULL);
949 if (!reg) {
950 debug("%s: cannot find reg property in syscon node\n",
951 __func__);
952 return -EINVAL;
953 }
954 priv->sysctl_reg = fdt_translate_address((void *)gd->fdt_blob,
955 offset, reg);
956 if (priv->sysctl_reg == FDT_ADDR_T_NONE) {
957 debug("%s: Cannot find syscon base address\n", __func__);
958 return -EINVAL;
Andre Przywara12afd952018-04-04 01:31:16 +0100959 }
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530960
961 pdata->phy_interface = -1;
962 priv->phyaddr = -1;
963 priv->use_internal_phy = false;
964
Andre Przywaraecd0cec2018-04-04 01:31:20 +0100965 offset = fdtdec_lookup_phandle(gd->fdt_blob, node, "phy-handle");
Andre Przywara12afd952018-04-04 01:31:16 +0100966 if (offset < 0) {
967 debug("%s: Cannot find PHY address\n", __func__);
968 return -EINVAL;
969 }
970 priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530971
Simon Glasse160f7d2017-01-17 16:52:55 -0700972 phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530973
974 if (phy_mode)
975 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
976 printf("phy interface%d\n", pdata->phy_interface);
977
978 if (pdata->phy_interface == -1) {
979 debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
980 return -EINVAL;
981 }
982
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530983 if (priv->variant == H3_EMAC) {
Jagan Teki23484532019-02-28 00:27:00 +0530984 ret = sun8i_get_ephy_nodes(priv);
985 if (ret)
986 return ret;
Amit Singh Tomara29710c2016-07-06 17:59:44 +0530987 }
988
989 priv->interface = pdata->phy_interface;
990
991 if (!priv->use_internal_phy)
992 parse_phy_pins(dev);
993
Icenowy Zheng9b16ede2018-11-23 00:37:48 +0100994 sun8i_pdata->tx_delay_ps = fdtdec_get_int(gd->fdt_blob, node,
995 "allwinner,tx-delay-ps", 0);
996 if (sun8i_pdata->tx_delay_ps < 0 || sun8i_pdata->tx_delay_ps > 700)
997 printf("%s: Invalid TX delay value %d\n", __func__,
998 sun8i_pdata->tx_delay_ps);
999
1000 sun8i_pdata->rx_delay_ps = fdtdec_get_int(gd->fdt_blob, node,
1001 "allwinner,rx-delay-ps", 0);
1002 if (sun8i_pdata->rx_delay_ps < 0 || sun8i_pdata->rx_delay_ps > 3100)
1003 printf("%s: Invalid RX delay value %d\n", __func__,
1004 sun8i_pdata->rx_delay_ps);
1005
Simon Glassbcee8d62019-12-06 21:41:35 -07001006#if CONFIG_IS_ENABLED(DM_GPIO)
Simon Glassda409cc2017-05-17 17:18:09 -06001007 if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
Philipp Tomsich4d555ae2017-02-22 19:46:41 +01001008 "snps,reset-active-low"))
1009 reset_flags |= GPIOD_ACTIVE_LOW;
1010
1011 ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
1012 &priv->reset_gpio, reset_flags);
1013
1014 if (ret == 0) {
Simon Glassda409cc2017-05-17 17:18:09 -06001015 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
Philipp Tomsich4d555ae2017-02-22 19:46:41 +01001016 "snps,reset-delays-us",
1017 sun8i_pdata->reset_delays, 3);
1018 } else if (ret == -ENOENT) {
1019 ret = 0;
1020 }
1021#endif
1022
Amit Singh Tomara29710c2016-07-06 17:59:44 +05301023 return 0;
1024}
1025
1026static const struct udevice_id sun8i_emac_eth_ids[] = {
1027 {.compatible = "allwinner,sun8i-h3-emac", .data = (uintptr_t)H3_EMAC },
1028 {.compatible = "allwinner,sun50i-a64-emac",
1029 .data = (uintptr_t)A64_EMAC },
1030 {.compatible = "allwinner,sun8i-a83t-emac",
1031 .data = (uintptr_t)A83T_EMAC },
Lothar Feltene46d73f2018-07-13 10:45:28 +02001032 {.compatible = "allwinner,sun8i-r40-gmac",
1033 .data = (uintptr_t)R40_GMAC },
Amit Singh Tomara29710c2016-07-06 17:59:44 +05301034 { }
1035};
1036
1037U_BOOT_DRIVER(eth_sun8i_emac) = {
1038 .name = "eth_sun8i_emac",
1039 .id = UCLASS_ETH,
1040 .of_match = sun8i_emac_eth_ids,
1041 .ofdata_to_platdata = sun8i_emac_eth_ofdata_to_platdata,
1042 .probe = sun8i_emac_eth_probe,
1043 .ops = &sun8i_emac_eth_ops,
1044 .priv_auto_alloc_size = sizeof(struct emac_eth_dev),
Philipp Tomsich4d555ae2017-02-22 19:46:41 +01001045 .platdata_auto_alloc_size = sizeof(struct sun8i_eth_pdata),
Amit Singh Tomara29710c2016-07-06 17:59:44 +05301046 .flags = DM_FLAG_ALLOC_PRIV_DMA,
1047};