1 // SPDX-License-Identifier: GPL-2.0+
3 * sni_ave.c - Socionext UniPhier AVE ethernet driver
4 * Copyright 2016-2018 Socionext inc.
10 #include <fdt_support.h>
18 #include <asm/cache.h>
19 #include <dm/device_compat.h>
20 #include <linux/bitops.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
24 #include <linux/iopoll.h>
26 #define AVE_GRST_DELAY_MSEC 40
27 #define AVE_MIN_XMITSIZE 60
28 #define AVE_SEND_TIMEOUT_COUNT 1000
29 #define AVE_MDIO_TIMEOUT_USEC 10000
30 #define AVE_HALT_TIMEOUT_USEC 10000
32 /* General Register Group */
33 #define AVE_IDR 0x000 /* ID */
34 #define AVE_VR 0x004 /* Version */
35 #define AVE_GRR 0x008 /* Global Reset */
36 #define AVE_CFGR 0x00c /* Configuration */
38 /* Interrupt Register Group */
39 #define AVE_GIMR 0x100 /* Global Interrupt Mask */
40 #define AVE_GISR 0x104 /* Global Interrupt Status */
42 /* MAC Register Group */
43 #define AVE_TXCR 0x200 /* TX Setup */
44 #define AVE_RXCR 0x204 /* RX Setup */
45 #define AVE_RXMAC1R 0x208 /* MAC address (lower) */
46 #define AVE_RXMAC2R 0x20c /* MAC address (upper) */
47 #define AVE_MDIOCTR 0x214 /* MDIO Control */
48 #define AVE_MDIOAR 0x218 /* MDIO Address */
49 #define AVE_MDIOWDR 0x21c /* MDIO Data */
50 #define AVE_MDIOSR 0x220 /* MDIO Status */
51 #define AVE_MDIORDR 0x224 /* MDIO Rd Data */
53 /* Descriptor Control Register Group */
54 #define AVE_DESCC 0x300 /* Descriptor Control */
55 #define AVE_TXDC 0x304 /* TX Descriptor Configuration */
56 #define AVE_RXDC 0x308 /* RX Descriptor Ring0 Configuration */
57 #define AVE_IIRQC 0x34c /* Interval IRQ Control */
59 /* 64bit descriptor memory */
60 #define AVE_DESC_SIZE_64 12 /* Descriptor Size */
61 #define AVE_TXDM_64 0x1000 /* Tx Descriptor Memory */
62 #define AVE_RXDM_64 0x1c00 /* Rx Descriptor Memory */
64 /* 32bit descriptor memory */
65 #define AVE_DESC_SIZE_32 8 /* Descriptor Size */
66 #define AVE_TXDM_32 0x1000 /* Tx Descriptor Memory */
67 #define AVE_RXDM_32 0x1800 /* Rx Descriptor Memory */
69 /* RMII Bridge Register Group */
70 #define AVE_RSTCTRL 0x8028 /* Reset control */
71 #define AVE_RSTCTRL_RMIIRST BIT(16)
72 #define AVE_LINKSEL 0x8034 /* Link speed setting */
73 #define AVE_LINKSEL_100M BIT(0)
76 #define AVE_GRR_PHYRST BIT(4) /* Reset external PHY */
77 #define AVE_GRR_GRST BIT(0) /* Reset all MAC */
80 #define AVE_CFGR_MII BIT(27) /* Func mode (1:MII/RMII, 0:RGMII) */
82 /* AVE_GISR (common with GIMR) */
83 #define AVE_GIMR_CLR 0
84 #define AVE_GISR_CLR GENMASK(31, 0)
87 #define AVE_TXCR_FLOCTR BIT(18) /* Flow control */
88 #define AVE_TXCR_TXSPD_1G BIT(17)
89 #define AVE_TXCR_TXSPD_100 BIT(16)
92 #define AVE_RXCR_RXEN BIT(30) /* Rx enable */
93 #define AVE_RXCR_FDUPEN BIT(22) /* Interface mode */
94 #define AVE_RXCR_FLOCTR BIT(21) /* Flow control */
97 #define AVE_MDIOCTR_RREQ BIT(3) /* Read request */
98 #define AVE_MDIOCTR_WREQ BIT(2) /* Write request */
101 #define AVE_MDIOSR_STS BIT(0) /* access status */
104 #define AVE_DESCC_RXDSTPSTS BIT(20)
105 #define AVE_DESCC_RD0 BIT(8) /* Enable Rx descriptor Ring0 */
106 #define AVE_DESCC_RXDSTP BIT(4) /* Pause Rx descriptor */
107 #define AVE_DESCC_TD BIT(0) /* Enable Tx descriptor */
110 #define AVE_DESC_SIZE(priv, num) \
111 ((num) * ((priv)->data->is_desc_64bit ? AVE_DESC_SIZE_64 : \
114 /* Command status for descriptor */
115 #define AVE_STS_OWN BIT(31) /* Descriptor ownership */
116 #define AVE_STS_OK BIT(27) /* Normal transmit */
117 #define AVE_STS_1ST BIT(26) /* Head of buffer chain */
118 #define AVE_STS_LAST BIT(25) /* Tail of buffer chain */
119 #define AVE_STS_PKTLEN_TX_MASK GENMASK(15, 0)
120 #define AVE_STS_PKTLEN_RX_MASK GENMASK(10, 0)
122 #define AVE_DESC_OFS_CMDSTS 0
123 #define AVE_DESC_OFS_ADDRL 4
124 #define AVE_DESC_OFS_ADDRU 8
126 /* Parameter for ethernet frame */
127 #define AVE_RXCR_MTU 1518
130 #define SG_ETPINMODE 0x540
131 #define SG_ETPINMODE_EXTPHY BIT(1) /* for LD11 */
132 #define SG_ETPINMODE_RMII(ins) BIT(ins)
134 #define AVE_MAX_CLKS 4
135 #define AVE_MAX_RSTS 2
145 struct clk clk[AVE_MAX_CLKS];
147 struct reset_ctl rst[AVE_MAX_RSTS];
148 struct regmap *regmap;
149 unsigned int regmap_arg;
152 struct phy_device *phydev;
161 u8 tx_adj_packetbuf[PKTSIZE_ALIGN + PKTALIGN];
164 const struct ave_soc_data *data;
167 struct ave_soc_data {
169 const char *clock_names[AVE_MAX_CLKS];
170 const char *reset_names[AVE_MAX_RSTS];
171 int (*get_pinmode)(struct ave_private *priv);
174 static u32 ave_desc_read(struct ave_private *priv, enum desc_id id, int entry,
180 if (priv->data->is_desc_64bit) {
181 desc_size = AVE_DESC_SIZE_64;
182 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_64 : AVE_RXDM_64;
184 desc_size = AVE_DESC_SIZE_32;
185 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_32 : AVE_RXDM_32;
188 addr += entry * desc_size + offset;
190 return readl(priv->iobase + addr);
193 static u32 ave_desc_read_cmdsts(struct ave_private *priv, enum desc_id id,
196 return ave_desc_read(priv, id, entry, AVE_DESC_OFS_CMDSTS);
199 static void ave_desc_write(struct ave_private *priv, enum desc_id id,
200 int entry, int offset, u32 val)
205 if (priv->data->is_desc_64bit) {
206 desc_size = AVE_DESC_SIZE_64;
207 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_64 : AVE_RXDM_64;
209 desc_size = AVE_DESC_SIZE_32;
210 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_32 : AVE_RXDM_32;
213 addr += entry * desc_size + offset;
214 writel(val, priv->iobase + addr);
217 static void ave_desc_write_cmdsts(struct ave_private *priv, enum desc_id id,
220 ave_desc_write(priv, id, entry, AVE_DESC_OFS_CMDSTS, val);
223 static void ave_desc_write_addr(struct ave_private *priv, enum desc_id id,
224 int entry, uintptr_t paddr)
226 ave_desc_write(priv, id, entry,
227 AVE_DESC_OFS_ADDRL, lower_32_bits(paddr));
228 if (priv->data->is_desc_64bit)
229 ave_desc_write(priv, id, entry,
230 AVE_DESC_OFS_ADDRU, upper_32_bits(paddr));
233 static void ave_cache_invalidate(uintptr_t vaddr, int len)
235 invalidate_dcache_range(rounddown(vaddr, ARCH_DMA_MINALIGN),
236 roundup(vaddr + len, ARCH_DMA_MINALIGN));
239 static void ave_cache_flush(uintptr_t vaddr, int len)
241 flush_dcache_range(rounddown(vaddr, ARCH_DMA_MINALIGN),
242 roundup(vaddr + len, ARCH_DMA_MINALIGN));
245 static int ave_mdiobus_read(struct mii_dev *bus,
246 int phyid, int devad, int regnum)
248 struct ave_private *priv = bus->priv;
253 writel((phyid << 8) | regnum, priv->iobase + AVE_MDIOAR);
256 mdioctl = readl(priv->iobase + AVE_MDIOCTR);
257 writel(mdioctl | AVE_MDIOCTR_RREQ, priv->iobase + AVE_MDIOCTR);
259 ret = readl_poll_timeout(priv->iobase + AVE_MDIOSR, mdiosr,
260 !(mdiosr & AVE_MDIOSR_STS),
261 AVE_MDIO_TIMEOUT_USEC);
263 pr_err("%s: failed to read from mdio (phy:%d reg:%x)\n",
264 priv->phydev->dev->name, phyid, regnum);
268 return readl(priv->iobase + AVE_MDIORDR) & GENMASK(15, 0);
271 static int ave_mdiobus_write(struct mii_dev *bus,
272 int phyid, int devad, int regnum, u16 val)
274 struct ave_private *priv = bus->priv;
279 writel((phyid << 8) | regnum, priv->iobase + AVE_MDIOAR);
282 writel(val, priv->iobase + AVE_MDIOWDR);
285 mdioctl = readl(priv->iobase + AVE_MDIOCTR);
286 writel((mdioctl | AVE_MDIOCTR_WREQ) & ~AVE_MDIOCTR_RREQ,
287 priv->iobase + AVE_MDIOCTR);
289 ret = readl_poll_timeout(priv->iobase + AVE_MDIOSR, mdiosr,
290 !(mdiosr & AVE_MDIOSR_STS),
291 AVE_MDIO_TIMEOUT_USEC);
293 pr_err("%s: failed to write to mdio (phy:%d reg:%x)\n",
294 priv->phydev->dev->name, phyid, regnum);
299 static int ave_adjust_link(struct ave_private *priv)
301 struct phy_device *phydev = priv->phydev;
302 struct eth_pdata *pdata = dev_get_platdata(phydev->dev);
303 u32 val, txcr, rxcr, rxcr_org;
304 u16 rmt_adv = 0, lcl_adv = 0;
307 /* set RGMII speed */
308 val = readl(priv->iobase + AVE_TXCR);
309 val &= ~(AVE_TXCR_TXSPD_100 | AVE_TXCR_TXSPD_1G);
311 if (phy_interface_is_rgmii(phydev) && phydev->speed == SPEED_1000)
312 val |= AVE_TXCR_TXSPD_1G;
313 else if (phydev->speed == SPEED_100)
314 val |= AVE_TXCR_TXSPD_100;
316 writel(val, priv->iobase + AVE_TXCR);
318 /* set RMII speed (100M/10M only) */
319 if (!phy_interface_is_rgmii(phydev)) {
320 val = readl(priv->iobase + AVE_LINKSEL);
321 if (phydev->speed == SPEED_10)
322 val &= ~AVE_LINKSEL_100M;
324 val |= AVE_LINKSEL_100M;
325 writel(val, priv->iobase + AVE_LINKSEL);
328 /* check current RXCR/TXCR */
329 rxcr = readl(priv->iobase + AVE_RXCR);
330 txcr = readl(priv->iobase + AVE_TXCR);
333 if (phydev->duplex) {
334 rxcr |= AVE_RXCR_FDUPEN;
337 rmt_adv |= LPA_PAUSE_CAP;
338 if (phydev->asym_pause)
339 rmt_adv |= LPA_PAUSE_ASYM;
340 if (phydev->advertising & ADVERTISED_Pause)
341 lcl_adv |= ADVERTISE_PAUSE_CAP;
342 if (phydev->advertising & ADVERTISED_Asym_Pause)
343 lcl_adv |= ADVERTISE_PAUSE_ASYM;
345 cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
346 if (cap & FLOW_CTRL_TX)
347 txcr |= AVE_TXCR_FLOCTR;
349 txcr &= ~AVE_TXCR_FLOCTR;
350 if (cap & FLOW_CTRL_RX)
351 rxcr |= AVE_RXCR_FLOCTR;
353 rxcr &= ~AVE_RXCR_FLOCTR;
355 rxcr &= ~AVE_RXCR_FDUPEN;
356 rxcr &= ~AVE_RXCR_FLOCTR;
357 txcr &= ~AVE_TXCR_FLOCTR;
360 if (rxcr_org != rxcr) {
362 writel(rxcr & ~AVE_RXCR_RXEN, priv->iobase + AVE_RXCR);
363 /* change and enable TX/Rx mac */
364 writel(txcr, priv->iobase + AVE_TXCR);
365 writel(rxcr, priv->iobase + AVE_RXCR);
368 pr_notice("%s: phy:%s speed:%d mac:%pM\n",
369 phydev->dev->name, phydev->drv->name, phydev->speed,
375 static int ave_mdiobus_init(struct ave_private *priv, const char *name)
377 struct mii_dev *bus = mdio_alloc();
382 bus->read = ave_mdiobus_read;
383 bus->write = ave_mdiobus_write;
384 snprintf(bus->name, sizeof(bus->name), "%s", name);
387 return mdio_register(bus);
390 static int ave_phy_init(struct ave_private *priv, void *dev)
392 struct phy_device *phydev;
393 int mask = GENMASK(31, 0), ret;
395 phydev = phy_find_by_mask(priv->bus, mask, priv->phy_mode);
399 phy_connect_dev(phydev, dev);
401 phydev->supported &= PHY_GBIT_FEATURES;
402 if (priv->max_speed) {
403 ret = phy_set_supported(phydev, priv->max_speed);
407 phydev->advertising = phydev->supported;
409 priv->phydev = phydev;
415 static void ave_stop(struct udevice *dev)
417 struct ave_private *priv = dev_get_priv(dev);
421 val = readl(priv->iobase + AVE_GRR);
425 val = readl(priv->iobase + AVE_RXCR);
426 val &= ~AVE_RXCR_RXEN;
427 writel(val, priv->iobase + AVE_RXCR);
429 writel(0, priv->iobase + AVE_DESCC);
430 ret = readl_poll_timeout(priv->iobase + AVE_DESCC, val, !val,
431 AVE_HALT_TIMEOUT_USEC);
433 pr_warn("%s: halt timeout\n", priv->phydev->dev->name);
435 writel(AVE_GRR_GRST, priv->iobase + AVE_GRR);
437 phy_shutdown(priv->phydev);
440 static void ave_reset(struct ave_private *priv)
444 /* reset RMII register */
445 val = readl(priv->iobase + AVE_RSTCTRL);
446 val &= ~AVE_RSTCTRL_RMIIRST;
447 writel(val, priv->iobase + AVE_RSTCTRL);
450 writel(AVE_GRR_GRST | AVE_GRR_PHYRST, priv->iobase + AVE_GRR);
451 mdelay(AVE_GRST_DELAY_MSEC);
453 /* 1st, negate PHY reset only */
454 writel(AVE_GRR_GRST, priv->iobase + AVE_GRR);
455 mdelay(AVE_GRST_DELAY_MSEC);
458 writel(0, priv->iobase + AVE_GRR);
459 mdelay(AVE_GRST_DELAY_MSEC);
461 /* negate RMII register */
462 val = readl(priv->iobase + AVE_RSTCTRL);
463 val |= AVE_RSTCTRL_RMIIRST;
464 writel(val, priv->iobase + AVE_RSTCTRL);
467 static int ave_start(struct udevice *dev)
469 struct ave_private *priv = dev_get_priv(dev);
477 priv->rx_off = 2; /* RX data has 2byte offsets */
480 (void *)roundup((uintptr_t)&priv->tx_adj_packetbuf[0],
482 priv->rx_siz = (PKTSIZE_ALIGN - priv->rx_off);
485 if (priv->phy_mode != PHY_INTERFACE_MODE_RGMII)
487 writel(val, priv->iobase + AVE_CFGR);
489 /* use one descriptor for Tx */
490 writel(AVE_DESC_SIZE(priv, 1) << 16, priv->iobase + AVE_TXDC);
491 ave_desc_write_cmdsts(priv, AVE_DESCID_TX, 0, 0);
492 ave_desc_write_addr(priv, AVE_DESCID_TX, 0, 0);
494 /* use PKTBUFSRX descriptors for Rx */
495 writel(AVE_DESC_SIZE(priv, PKTBUFSRX) << 16, priv->iobase + AVE_RXDC);
496 for (i = 0; i < PKTBUFSRX; i++) {
497 paddr = (uintptr_t)net_rx_packets[i];
498 ave_cache_flush(paddr, priv->rx_siz + priv->rx_off);
499 ave_desc_write_addr(priv, AVE_DESCID_RX, i, paddr);
500 ave_desc_write_cmdsts(priv, AVE_DESCID_RX, i, priv->rx_siz);
503 writel(AVE_GISR_CLR, priv->iobase + AVE_GISR);
504 writel(AVE_GIMR_CLR, priv->iobase + AVE_GIMR);
506 writel(AVE_RXCR_RXEN | AVE_RXCR_FDUPEN | AVE_RXCR_FLOCTR | AVE_RXCR_MTU,
507 priv->iobase + AVE_RXCR);
508 writel(AVE_DESCC_RD0 | AVE_DESCC_TD, priv->iobase + AVE_DESCC);
510 phy_startup(priv->phydev);
511 ave_adjust_link(priv);
516 static int ave_write_hwaddr(struct udevice *dev)
518 struct ave_private *priv = dev_get_priv(dev);
519 struct eth_pdata *pdata = dev_get_platdata(dev);
520 u8 *mac = pdata->enetaddr;
522 writel(mac[0] | mac[1] << 8 | mac[2] << 16 | mac[3] << 24,
523 priv->iobase + AVE_RXMAC1R);
524 writel(mac[4] | mac[5] << 8, priv->iobase + AVE_RXMAC2R);
529 static int ave_send(struct udevice *dev, void *packet, int length)
531 struct ave_private *priv = dev_get_priv(dev);
536 /* adjust alignment for descriptor */
537 if ((uintptr_t)ptr & 0x3) {
538 memcpy(priv->tx_adj_buf, (const void *)ptr, length);
539 ptr = priv->tx_adj_buf;
542 /* padding for minimum length */
543 if (length < AVE_MIN_XMITSIZE) {
544 memset(ptr + length, 0, AVE_MIN_XMITSIZE - length);
545 length = AVE_MIN_XMITSIZE;
548 /* check ownership and wait for previous xmit done */
549 count = AVE_SEND_TIMEOUT_COUNT;
551 val = ave_desc_read_cmdsts(priv, AVE_DESCID_TX, 0);
552 } while ((val & AVE_STS_OWN) && --count);
556 ave_cache_flush((uintptr_t)ptr, length);
557 ave_desc_write_addr(priv, AVE_DESCID_TX, 0, (uintptr_t)ptr);
559 val = AVE_STS_OWN | AVE_STS_1ST | AVE_STS_LAST |
560 (length & AVE_STS_PKTLEN_TX_MASK);
561 ave_desc_write_cmdsts(priv, AVE_DESCID_TX, 0, val);
564 count = AVE_SEND_TIMEOUT_COUNT;
566 val = ave_desc_read_cmdsts(priv, AVE_DESCID_TX, 0);
567 } while ((val & AVE_STS_OWN) && --count);
571 if (!(val & AVE_STS_OK))
572 pr_warn("%s: bad send packet status:%08x\n",
573 priv->phydev->dev->name, le32_to_cpu(val));
578 static int ave_recv(struct udevice *dev, int flags, uchar **packetp)
580 struct ave_private *priv = dev_get_priv(dev);
586 cmdsts = ave_desc_read_cmdsts(priv, AVE_DESCID_RX,
588 if (!(cmdsts & AVE_STS_OWN))
589 /* hardware ownership, no received packets */
592 ptr = net_rx_packets[priv->rx_pos] + priv->rx_off;
593 if (cmdsts & AVE_STS_OK)
596 pr_warn("%s: bad packet[%d] status:%08x ptr:%p\n",
597 priv->phydev->dev->name, priv->rx_pos,
598 le32_to_cpu(cmdsts), ptr);
601 length = cmdsts & AVE_STS_PKTLEN_RX_MASK;
603 /* invalidate after DMA is done */
604 ave_cache_invalidate((uintptr_t)ptr, length);
610 static int ave_free_packet(struct udevice *dev, uchar *packet, int length)
612 struct ave_private *priv = dev_get_priv(dev);
614 ave_cache_flush((uintptr_t)net_rx_packets[priv->rx_pos],
615 priv->rx_siz + priv->rx_off);
617 ave_desc_write_cmdsts(priv, AVE_DESCID_RX,
618 priv->rx_pos, priv->rx_siz);
620 if (++priv->rx_pos >= PKTBUFSRX)
626 static int ave_pro4_get_pinmode(struct ave_private *priv)
628 u32 reg, mask, val = 0;
630 if (priv->regmap_arg > 0)
633 mask = SG_ETPINMODE_RMII(0);
635 switch (priv->phy_mode) {
636 case PHY_INTERFACE_MODE_RMII:
637 val = SG_ETPINMODE_RMII(0);
639 case PHY_INTERFACE_MODE_MII:
640 case PHY_INTERFACE_MODE_RGMII:
646 regmap_read(priv->regmap, SG_ETPINMODE, ®);
649 regmap_write(priv->regmap, SG_ETPINMODE, reg);
654 static int ave_ld11_get_pinmode(struct ave_private *priv)
656 u32 reg, mask, val = 0;
658 if (priv->regmap_arg > 0)
661 mask = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII(0);
663 switch (priv->phy_mode) {
664 case PHY_INTERFACE_MODE_INTERNAL:
666 case PHY_INTERFACE_MODE_RMII:
667 val = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII(0);
673 regmap_read(priv->regmap, SG_ETPINMODE, ®);
676 regmap_write(priv->regmap, SG_ETPINMODE, reg);
681 static int ave_ld20_get_pinmode(struct ave_private *priv)
683 u32 reg, mask, val = 0;
685 if (priv->regmap_arg > 0)
688 mask = SG_ETPINMODE_RMII(0);
690 switch (priv->phy_mode) {
691 case PHY_INTERFACE_MODE_RMII:
692 val = SG_ETPINMODE_RMII(0);
694 case PHY_INTERFACE_MODE_RGMII:
700 regmap_read(priv->regmap, SG_ETPINMODE, ®);
703 regmap_write(priv->regmap, SG_ETPINMODE, reg);
708 static int ave_pxs3_get_pinmode(struct ave_private *priv)
710 u32 reg, mask, val = 0;
712 if (priv->regmap_arg > 1)
715 mask = SG_ETPINMODE_RMII(priv->regmap_arg);
717 switch (priv->phy_mode) {
718 case PHY_INTERFACE_MODE_RMII:
719 val = SG_ETPINMODE_RMII(priv->regmap_arg);
721 case PHY_INTERFACE_MODE_RGMII:
727 regmap_read(priv->regmap, SG_ETPINMODE, ®);
730 regmap_write(priv->regmap, SG_ETPINMODE, reg);
735 static int ave_ofdata_to_platdata(struct udevice *dev)
737 struct eth_pdata *pdata = dev_get_platdata(dev);
738 struct ave_private *priv = dev_get_priv(dev);
739 struct ofnode_phandle_args args;
740 const char *phy_mode;
745 priv->data = (const struct ave_soc_data *)dev_get_driver_data(dev);
749 pdata->iobase = dev_read_addr(dev);
750 pdata->phy_interface = -1;
751 phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
754 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
755 if (pdata->phy_interface == -1) {
756 dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
760 pdata->max_speed = 0;
761 valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed",
764 pdata->max_speed = fdt32_to_cpu(*valp);
766 for (nc = 0; nc < AVE_MAX_CLKS; nc++) {
767 name = priv->data->clock_names[nc];
770 ret = clk_get_by_name(dev, name, &priv->clk[nc]);
772 dev_err(dev, "Failed to get clocks property: %d\n",
779 for (nr = 0; nr < AVE_MAX_RSTS; nr++) {
780 name = priv->data->reset_names[nr];
783 ret = reset_get_by_name(dev, name, &priv->rst[nr]);
785 dev_err(dev, "Failed to get resets property: %d\n",
792 ret = dev_read_phandle_with_args(dev, "socionext,syscon-phy-mode",
795 dev_err(dev, "Failed to get syscon-phy-mode property: %d\n",
800 priv->regmap = syscon_node_to_regmap(args.node);
801 if (IS_ERR(priv->regmap)) {
802 ret = PTR_ERR(priv->regmap);
803 dev_err(dev, "can't get syscon: %d\n", ret);
807 if (args.args_count != 1) {
809 dev_err(dev, "Invalid argument of syscon-phy-mode\n");
813 priv->regmap_arg = args.args[0];
819 reset_free(&priv->rst[nr]);
822 clk_free(&priv->clk[nc]);
827 static int ave_probe(struct udevice *dev)
829 struct eth_pdata *pdata = dev_get_platdata(dev);
830 struct ave_private *priv = dev_get_priv(dev);
833 priv->data = (const struct ave_soc_data *)dev_get_driver_data(dev);
837 priv->iobase = pdata->iobase;
838 priv->phy_mode = pdata->phy_interface;
839 priv->max_speed = pdata->max_speed;
841 ret = priv->data->get_pinmode(priv);
843 dev_err(dev, "Invalid phy-mode\n");
847 for (nc = 0; nc < priv->nclks; nc++) {
848 ret = clk_enable(&priv->clk[nc]);
850 dev_err(dev, "Failed to enable clk: %d\n", ret);
851 goto out_clk_release;
855 for (nr = 0; nr < priv->nrsts; nr++) {
856 ret = reset_deassert(&priv->rst[nr]);
858 dev_err(dev, "Failed to deassert reset: %d\n", ret);
859 goto out_reset_release;
865 ret = ave_mdiobus_init(priv, dev->name);
867 dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
868 goto out_reset_release;
871 priv->bus = miiphy_get_dev_by_name(dev->name);
873 ret = ave_phy_init(priv, dev);
875 dev_err(dev, "Failed to initialize phy: %d\n", ret);
876 goto out_mdiobus_release;
882 mdio_unregister(priv->bus);
883 mdio_free(priv->bus);
885 reset_release_all(priv->rst, nr);
887 clk_release_all(priv->clk, nc);
892 static int ave_remove(struct udevice *dev)
894 struct ave_private *priv = dev_get_priv(dev);
897 mdio_unregister(priv->bus);
898 mdio_free(priv->bus);
899 reset_release_all(priv->rst, priv->nrsts);
900 clk_release_all(priv->clk, priv->nclks);
905 static const struct eth_ops ave_ops = {
910 .free_pkt = ave_free_packet,
911 .write_hwaddr = ave_write_hwaddr,
914 static const struct ave_soc_data ave_pro4_data = {
915 .is_desc_64bit = false,
917 "gio", "ether", "ether-gb", "ether-phy",
922 .get_pinmode = ave_pro4_get_pinmode,
925 static const struct ave_soc_data ave_pxs2_data = {
926 .is_desc_64bit = false,
933 .get_pinmode = ave_pro4_get_pinmode,
936 static const struct ave_soc_data ave_ld11_data = {
937 .is_desc_64bit = false,
944 .get_pinmode = ave_ld11_get_pinmode,
947 static const struct ave_soc_data ave_ld20_data = {
948 .is_desc_64bit = true,
955 .get_pinmode = ave_ld20_get_pinmode,
958 static const struct ave_soc_data ave_pxs3_data = {
959 .is_desc_64bit = false,
966 .get_pinmode = ave_pxs3_get_pinmode,
969 static const struct udevice_id ave_ids[] = {
971 .compatible = "socionext,uniphier-pro4-ave4",
972 .data = (ulong)&ave_pro4_data,
975 .compatible = "socionext,uniphier-pxs2-ave4",
976 .data = (ulong)&ave_pxs2_data,
979 .compatible = "socionext,uniphier-ld11-ave4",
980 .data = (ulong)&ave_ld11_data,
983 .compatible = "socionext,uniphier-ld20-ave4",
984 .data = (ulong)&ave_ld20_data,
987 .compatible = "socionext,uniphier-pxs3-ave4",
988 .data = (ulong)&ave_pxs3_data,
993 U_BOOT_DRIVER(ave) = {
998 .remove = ave_remove,
999 .ofdata_to_platdata = ave_ofdata_to_platdata,
1001 .priv_auto = sizeof(struct ave_private),
1002 .platdata_auto = sizeof(struct eth_pdata),