1 // SPDX-License-Identifier: GPL-2.0+
3 * sni_ave.c - Socionext UniPhier AVE ethernet driver
4 * Copyright 2016-2018 Socionext inc.
9 #include <fdt_support.h>
11 #include <linux/iopoll.h>
18 #define AVE_GRST_DELAY_MSEC 40
19 #define AVE_MIN_XMITSIZE 60
20 #define AVE_SEND_TIMEOUT_COUNT 1000
21 #define AVE_MDIO_TIMEOUT_USEC 10000
22 #define AVE_HALT_TIMEOUT_USEC 10000
24 /* General Register Group */
25 #define AVE_IDR 0x000 /* ID */
26 #define AVE_VR 0x004 /* Version */
27 #define AVE_GRR 0x008 /* Global Reset */
28 #define AVE_CFGR 0x00c /* Configuration */
30 /* Interrupt Register Group */
31 #define AVE_GIMR 0x100 /* Global Interrupt Mask */
32 #define AVE_GISR 0x104 /* Global Interrupt Status */
34 /* MAC Register Group */
35 #define AVE_TXCR 0x200 /* TX Setup */
36 #define AVE_RXCR 0x204 /* RX Setup */
37 #define AVE_RXMAC1R 0x208 /* MAC address (lower) */
38 #define AVE_RXMAC2R 0x20c /* MAC address (upper) */
39 #define AVE_MDIOCTR 0x214 /* MDIO Control */
40 #define AVE_MDIOAR 0x218 /* MDIO Address */
41 #define AVE_MDIOWDR 0x21c /* MDIO Data */
42 #define AVE_MDIOSR 0x220 /* MDIO Status */
43 #define AVE_MDIORDR 0x224 /* MDIO Rd Data */
45 /* Descriptor Control Register Group */
46 #define AVE_DESCC 0x300 /* Descriptor Control */
47 #define AVE_TXDC 0x304 /* TX Descriptor Configuration */
48 #define AVE_RXDC 0x308 /* RX Descriptor Ring0 Configuration */
49 #define AVE_IIRQC 0x34c /* Interval IRQ Control */
51 /* 64bit descriptor memory */
52 #define AVE_DESC_SIZE_64 12 /* Descriptor Size */
53 #define AVE_TXDM_64 0x1000 /* Tx Descriptor Memory */
54 #define AVE_RXDM_64 0x1c00 /* Rx Descriptor Memory */
56 /* 32bit descriptor memory */
57 #define AVE_DESC_SIZE_32 8 /* Descriptor Size */
58 #define AVE_TXDM_32 0x1000 /* Tx Descriptor Memory */
59 #define AVE_RXDM_32 0x1800 /* Rx Descriptor Memory */
61 /* RMII Bridge Register Group */
62 #define AVE_RSTCTRL 0x8028 /* Reset control */
63 #define AVE_RSTCTRL_RMIIRST BIT(16)
64 #define AVE_LINKSEL 0x8034 /* Link speed setting */
65 #define AVE_LINKSEL_100M BIT(0)
68 #define AVE_GRR_PHYRST BIT(4) /* Reset external PHY */
69 #define AVE_GRR_GRST BIT(0) /* Reset all MAC */
72 #define AVE_CFGR_MII BIT(27) /* Func mode (1:MII/RMII, 0:RGMII) */
74 /* AVE_GISR (common with GIMR) */
75 #define AVE_GIMR_CLR 0
76 #define AVE_GISR_CLR GENMASK(31, 0)
79 #define AVE_TXCR_FLOCTR BIT(18) /* Flow control */
80 #define AVE_TXCR_TXSPD_1G BIT(17)
81 #define AVE_TXCR_TXSPD_100 BIT(16)
84 #define AVE_RXCR_RXEN BIT(30) /* Rx enable */
85 #define AVE_RXCR_FDUPEN BIT(22) /* Interface mode */
86 #define AVE_RXCR_FLOCTR BIT(21) /* Flow control */
89 #define AVE_MDIOCTR_RREQ BIT(3) /* Read request */
90 #define AVE_MDIOCTR_WREQ BIT(2) /* Write request */
93 #define AVE_MDIOSR_STS BIT(0) /* access status */
96 #define AVE_DESCC_RXDSTPSTS BIT(20)
97 #define AVE_DESCC_RD0 BIT(8) /* Enable Rx descriptor Ring0 */
98 #define AVE_DESCC_RXDSTP BIT(4) /* Pause Rx descriptor */
99 #define AVE_DESCC_TD BIT(0) /* Enable Tx descriptor */
102 #define AVE_DESC_SIZE(priv, num) \
103 ((num) * ((priv)->data->is_desc_64bit ? AVE_DESC_SIZE_64 : \
106 /* Command status for descriptor */
107 #define AVE_STS_OWN BIT(31) /* Descriptor ownership */
108 #define AVE_STS_OK BIT(27) /* Normal transmit */
109 #define AVE_STS_1ST BIT(26) /* Head of buffer chain */
110 #define AVE_STS_LAST BIT(25) /* Tail of buffer chain */
111 #define AVE_STS_PKTLEN_TX_MASK GENMASK(15, 0)
112 #define AVE_STS_PKTLEN_RX_MASK GENMASK(10, 0)
114 #define AVE_DESC_OFS_CMDSTS 0
115 #define AVE_DESC_OFS_ADDRL 4
116 #define AVE_DESC_OFS_ADDRU 8
118 /* Parameter for ethernet frame */
119 #define AVE_RXCR_MTU 1518
122 #define SG_ETPINMODE 0x540
123 #define SG_ETPINMODE_EXTPHY BIT(1) /* for LD11 */
124 #define SG_ETPINMODE_RMII(ins) BIT(ins)
126 #define AVE_MAX_CLKS 4
127 #define AVE_MAX_RSTS 2
137 struct clk clk[AVE_MAX_CLKS];
139 struct reset_ctl rst[AVE_MAX_RSTS];
140 struct regmap *regmap;
141 unsigned int regmap_arg;
144 struct phy_device *phydev;
153 u8 tx_adj_packetbuf[PKTSIZE_ALIGN + PKTALIGN];
156 const struct ave_soc_data *data;
159 struct ave_soc_data {
161 const char *clock_names[AVE_MAX_CLKS];
162 const char *reset_names[AVE_MAX_RSTS];
163 int (*get_pinmode)(struct ave_private *priv);
166 static u32 ave_desc_read(struct ave_private *priv, enum desc_id id, int entry,
172 if (priv->data->is_desc_64bit) {
173 desc_size = AVE_DESC_SIZE_64;
174 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_64 : AVE_RXDM_64;
176 desc_size = AVE_DESC_SIZE_32;
177 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_32 : AVE_RXDM_32;
180 addr += entry * desc_size + offset;
182 return readl(priv->iobase + addr);
185 static u32 ave_desc_read_cmdsts(struct ave_private *priv, enum desc_id id,
188 return ave_desc_read(priv, id, entry, AVE_DESC_OFS_CMDSTS);
191 static void ave_desc_write(struct ave_private *priv, enum desc_id id,
192 int entry, int offset, u32 val)
197 if (priv->data->is_desc_64bit) {
198 desc_size = AVE_DESC_SIZE_64;
199 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_64 : AVE_RXDM_64;
201 desc_size = AVE_DESC_SIZE_32;
202 addr = (id == AVE_DESCID_TX) ? AVE_TXDM_32 : AVE_RXDM_32;
205 addr += entry * desc_size + offset;
206 writel(val, priv->iobase + addr);
209 static void ave_desc_write_cmdsts(struct ave_private *priv, enum desc_id id,
212 ave_desc_write(priv, id, entry, AVE_DESC_OFS_CMDSTS, val);
215 static void ave_desc_write_addr(struct ave_private *priv, enum desc_id id,
216 int entry, uintptr_t paddr)
218 ave_desc_write(priv, id, entry,
219 AVE_DESC_OFS_ADDRL, lower_32_bits(paddr));
220 if (priv->data->is_desc_64bit)
221 ave_desc_write(priv, id, entry,
222 AVE_DESC_OFS_ADDRU, upper_32_bits(paddr));
225 static void ave_cache_invalidate(uintptr_t vaddr, int len)
227 invalidate_dcache_range(rounddown(vaddr, ARCH_DMA_MINALIGN),
228 roundup(vaddr + len, ARCH_DMA_MINALIGN));
231 static void ave_cache_flush(uintptr_t vaddr, int len)
233 flush_dcache_range(rounddown(vaddr, ARCH_DMA_MINALIGN),
234 roundup(vaddr + len, ARCH_DMA_MINALIGN));
237 static int ave_mdiobus_read(struct mii_dev *bus,
238 int phyid, int devad, int regnum)
240 struct ave_private *priv = bus->priv;
245 writel((phyid << 8) | regnum, priv->iobase + AVE_MDIOAR);
248 mdioctl = readl(priv->iobase + AVE_MDIOCTR);
249 writel(mdioctl | AVE_MDIOCTR_RREQ, priv->iobase + AVE_MDIOCTR);
251 ret = readl_poll_timeout(priv->iobase + AVE_MDIOSR, mdiosr,
252 !(mdiosr & AVE_MDIOSR_STS),
253 AVE_MDIO_TIMEOUT_USEC);
255 pr_err("%s: failed to read from mdio (phy:%d reg:%x)\n",
256 priv->phydev->dev->name, phyid, regnum);
260 return readl(priv->iobase + AVE_MDIORDR) & GENMASK(15, 0);
263 static int ave_mdiobus_write(struct mii_dev *bus,
264 int phyid, int devad, int regnum, u16 val)
266 struct ave_private *priv = bus->priv;
271 writel((phyid << 8) | regnum, priv->iobase + AVE_MDIOAR);
274 writel(val, priv->iobase + AVE_MDIOWDR);
277 mdioctl = readl(priv->iobase + AVE_MDIOCTR);
278 writel((mdioctl | AVE_MDIOCTR_WREQ) & ~AVE_MDIOCTR_RREQ,
279 priv->iobase + AVE_MDIOCTR);
281 ret = readl_poll_timeout(priv->iobase + AVE_MDIOSR, mdiosr,
282 !(mdiosr & AVE_MDIOSR_STS),
283 AVE_MDIO_TIMEOUT_USEC);
285 pr_err("%s: failed to write to mdio (phy:%d reg:%x)\n",
286 priv->phydev->dev->name, phyid, regnum);
291 static int ave_adjust_link(struct ave_private *priv)
293 struct phy_device *phydev = priv->phydev;
294 struct eth_pdata *pdata = dev_get_platdata(phydev->dev);
295 u32 val, txcr, rxcr, rxcr_org;
296 u16 rmt_adv = 0, lcl_adv = 0;
299 /* set RGMII speed */
300 val = readl(priv->iobase + AVE_TXCR);
301 val &= ~(AVE_TXCR_TXSPD_100 | AVE_TXCR_TXSPD_1G);
303 if (phy_interface_is_rgmii(phydev) && phydev->speed == SPEED_1000)
304 val |= AVE_TXCR_TXSPD_1G;
305 else if (phydev->speed == SPEED_100)
306 val |= AVE_TXCR_TXSPD_100;
308 writel(val, priv->iobase + AVE_TXCR);
310 /* set RMII speed (100M/10M only) */
311 if (!phy_interface_is_rgmii(phydev)) {
312 val = readl(priv->iobase + AVE_LINKSEL);
313 if (phydev->speed == SPEED_10)
314 val &= ~AVE_LINKSEL_100M;
316 val |= AVE_LINKSEL_100M;
317 writel(val, priv->iobase + AVE_LINKSEL);
320 /* check current RXCR/TXCR */
321 rxcr = readl(priv->iobase + AVE_RXCR);
322 txcr = readl(priv->iobase + AVE_TXCR);
325 if (phydev->duplex) {
326 rxcr |= AVE_RXCR_FDUPEN;
329 rmt_adv |= LPA_PAUSE_CAP;
330 if (phydev->asym_pause)
331 rmt_adv |= LPA_PAUSE_ASYM;
332 if (phydev->advertising & ADVERTISED_Pause)
333 lcl_adv |= ADVERTISE_PAUSE_CAP;
334 if (phydev->advertising & ADVERTISED_Asym_Pause)
335 lcl_adv |= ADVERTISE_PAUSE_ASYM;
337 cap = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
338 if (cap & FLOW_CTRL_TX)
339 txcr |= AVE_TXCR_FLOCTR;
341 txcr &= ~AVE_TXCR_FLOCTR;
342 if (cap & FLOW_CTRL_RX)
343 rxcr |= AVE_RXCR_FLOCTR;
345 rxcr &= ~AVE_RXCR_FLOCTR;
347 rxcr &= ~AVE_RXCR_FDUPEN;
348 rxcr &= ~AVE_RXCR_FLOCTR;
349 txcr &= ~AVE_TXCR_FLOCTR;
352 if (rxcr_org != rxcr) {
354 writel(rxcr & ~AVE_RXCR_RXEN, priv->iobase + AVE_RXCR);
355 /* change and enable TX/Rx mac */
356 writel(txcr, priv->iobase + AVE_TXCR);
357 writel(rxcr, priv->iobase + AVE_RXCR);
360 pr_notice("%s: phy:%s speed:%d mac:%pM\n",
361 phydev->dev->name, phydev->drv->name, phydev->speed,
367 static int ave_mdiobus_init(struct ave_private *priv, const char *name)
369 struct mii_dev *bus = mdio_alloc();
374 bus->read = ave_mdiobus_read;
375 bus->write = ave_mdiobus_write;
376 snprintf(bus->name, sizeof(bus->name), "%s", name);
379 return mdio_register(bus);
382 static int ave_phy_init(struct ave_private *priv, void *dev)
384 struct phy_device *phydev;
385 int mask = GENMASK(31, 0), ret;
387 phydev = phy_find_by_mask(priv->bus, mask, priv->phy_mode);
391 phy_connect_dev(phydev, dev);
393 phydev->supported &= PHY_GBIT_FEATURES;
394 if (priv->max_speed) {
395 ret = phy_set_supported(phydev, priv->max_speed);
399 phydev->advertising = phydev->supported;
401 priv->phydev = phydev;
407 static void ave_stop(struct udevice *dev)
409 struct ave_private *priv = dev_get_priv(dev);
413 val = readl(priv->iobase + AVE_GRR);
417 val = readl(priv->iobase + AVE_RXCR);
418 val &= ~AVE_RXCR_RXEN;
419 writel(val, priv->iobase + AVE_RXCR);
421 writel(0, priv->iobase + AVE_DESCC);
422 ret = readl_poll_timeout(priv->iobase + AVE_DESCC, val, !val,
423 AVE_HALT_TIMEOUT_USEC);
425 pr_warn("%s: halt timeout\n", priv->phydev->dev->name);
427 writel(AVE_GRR_GRST, priv->iobase + AVE_GRR);
429 phy_shutdown(priv->phydev);
432 static void ave_reset(struct ave_private *priv)
436 /* reset RMII register */
437 val = readl(priv->iobase + AVE_RSTCTRL);
438 val &= ~AVE_RSTCTRL_RMIIRST;
439 writel(val, priv->iobase + AVE_RSTCTRL);
442 writel(AVE_GRR_GRST | AVE_GRR_PHYRST, priv->iobase + AVE_GRR);
443 mdelay(AVE_GRST_DELAY_MSEC);
445 /* 1st, negate PHY reset only */
446 writel(AVE_GRR_GRST, priv->iobase + AVE_GRR);
447 mdelay(AVE_GRST_DELAY_MSEC);
450 writel(0, priv->iobase + AVE_GRR);
451 mdelay(AVE_GRST_DELAY_MSEC);
453 /* negate RMII register */
454 val = readl(priv->iobase + AVE_RSTCTRL);
455 val |= AVE_RSTCTRL_RMIIRST;
456 writel(val, priv->iobase + AVE_RSTCTRL);
459 static int ave_start(struct udevice *dev)
461 struct ave_private *priv = dev_get_priv(dev);
469 priv->rx_off = 2; /* RX data has 2byte offsets */
472 (void *)roundup((uintptr_t)&priv->tx_adj_packetbuf[0],
474 priv->rx_siz = (PKTSIZE_ALIGN - priv->rx_off);
477 if (priv->phy_mode != PHY_INTERFACE_MODE_RGMII)
479 writel(val, priv->iobase + AVE_CFGR);
481 /* use one descriptor for Tx */
482 writel(AVE_DESC_SIZE(priv, 1) << 16, priv->iobase + AVE_TXDC);
483 ave_desc_write_cmdsts(priv, AVE_DESCID_TX, 0, 0);
484 ave_desc_write_addr(priv, AVE_DESCID_TX, 0, 0);
486 /* use PKTBUFSRX descriptors for Rx */
487 writel(AVE_DESC_SIZE(priv, PKTBUFSRX) << 16, priv->iobase + AVE_RXDC);
488 for (i = 0; i < PKTBUFSRX; i++) {
489 paddr = (uintptr_t)net_rx_packets[i];
490 ave_cache_flush(paddr, priv->rx_siz + priv->rx_off);
491 ave_desc_write_addr(priv, AVE_DESCID_RX, i, paddr);
492 ave_desc_write_cmdsts(priv, AVE_DESCID_RX, i, priv->rx_siz);
495 writel(AVE_GISR_CLR, priv->iobase + AVE_GISR);
496 writel(AVE_GIMR_CLR, priv->iobase + AVE_GIMR);
498 writel(AVE_RXCR_RXEN | AVE_RXCR_FDUPEN | AVE_RXCR_FLOCTR | AVE_RXCR_MTU,
499 priv->iobase + AVE_RXCR);
500 writel(AVE_DESCC_RD0 | AVE_DESCC_TD, priv->iobase + AVE_DESCC);
502 phy_startup(priv->phydev);
503 ave_adjust_link(priv);
508 static int ave_write_hwaddr(struct udevice *dev)
510 struct ave_private *priv = dev_get_priv(dev);
511 struct eth_pdata *pdata = dev_get_platdata(dev);
512 u8 *mac = pdata->enetaddr;
514 writel(mac[0] | mac[1] << 8 | mac[2] << 16 | mac[3] << 24,
515 priv->iobase + AVE_RXMAC1R);
516 writel(mac[4] | mac[5] << 8, priv->iobase + AVE_RXMAC2R);
521 static int ave_send(struct udevice *dev, void *packet, int length)
523 struct ave_private *priv = dev_get_priv(dev);
528 /* adjust alignment for descriptor */
529 if ((uintptr_t)ptr & 0x3) {
530 memcpy(priv->tx_adj_buf, (const void *)ptr, length);
531 ptr = priv->tx_adj_buf;
534 /* padding for minimum length */
535 if (length < AVE_MIN_XMITSIZE) {
536 memset(ptr + length, 0, AVE_MIN_XMITSIZE - length);
537 length = AVE_MIN_XMITSIZE;
540 /* check ownership and wait for previous xmit done */
541 count = AVE_SEND_TIMEOUT_COUNT;
543 val = ave_desc_read_cmdsts(priv, AVE_DESCID_TX, 0);
544 } while ((val & AVE_STS_OWN) && --count);
548 ave_cache_flush((uintptr_t)ptr, length);
549 ave_desc_write_addr(priv, AVE_DESCID_TX, 0, (uintptr_t)ptr);
551 val = AVE_STS_OWN | AVE_STS_1ST | AVE_STS_LAST |
552 (length & AVE_STS_PKTLEN_TX_MASK);
553 ave_desc_write_cmdsts(priv, AVE_DESCID_TX, 0, val);
556 count = AVE_SEND_TIMEOUT_COUNT;
558 val = ave_desc_read_cmdsts(priv, AVE_DESCID_TX, 0);
559 } while ((val & AVE_STS_OWN) && --count);
563 if (!(val & AVE_STS_OK))
564 pr_warn("%s: bad send packet status:%08x\n",
565 priv->phydev->dev->name, le32_to_cpu(val));
570 static int ave_recv(struct udevice *dev, int flags, uchar **packetp)
572 struct ave_private *priv = dev_get_priv(dev);
578 cmdsts = ave_desc_read_cmdsts(priv, AVE_DESCID_RX,
580 if (!(cmdsts & AVE_STS_OWN))
581 /* hardware ownership, no received packets */
584 ptr = net_rx_packets[priv->rx_pos] + priv->rx_off;
585 if (cmdsts & AVE_STS_OK)
588 pr_warn("%s: bad packet[%d] status:%08x ptr:%p\n",
589 priv->phydev->dev->name, priv->rx_pos,
590 le32_to_cpu(cmdsts), ptr);
593 length = cmdsts & AVE_STS_PKTLEN_RX_MASK;
595 /* invalidate after DMA is done */
596 ave_cache_invalidate((uintptr_t)ptr, length);
602 static int ave_free_packet(struct udevice *dev, uchar *packet, int length)
604 struct ave_private *priv = dev_get_priv(dev);
606 ave_cache_flush((uintptr_t)net_rx_packets[priv->rx_pos],
607 priv->rx_siz + priv->rx_off);
609 ave_desc_write_cmdsts(priv, AVE_DESCID_RX,
610 priv->rx_pos, priv->rx_siz);
612 if (++priv->rx_pos >= PKTBUFSRX)
618 static int ave_pro4_get_pinmode(struct ave_private *priv)
620 u32 reg, mask, val = 0;
622 if (priv->regmap_arg > 0)
625 mask = SG_ETPINMODE_RMII(0);
627 switch (priv->phy_mode) {
628 case PHY_INTERFACE_MODE_RMII:
629 val = SG_ETPINMODE_RMII(0);
631 case PHY_INTERFACE_MODE_MII:
632 case PHY_INTERFACE_MODE_RGMII:
638 regmap_read(priv->regmap, SG_ETPINMODE, ®);
641 regmap_write(priv->regmap, SG_ETPINMODE, reg);
646 static int ave_ld11_get_pinmode(struct ave_private *priv)
648 u32 reg, mask, val = 0;
650 if (priv->regmap_arg > 0)
653 mask = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII(0);
655 switch (priv->phy_mode) {
656 case PHY_INTERFACE_MODE_INTERNAL:
658 case PHY_INTERFACE_MODE_RMII:
659 val = SG_ETPINMODE_EXTPHY | SG_ETPINMODE_RMII(0);
665 regmap_read(priv->regmap, SG_ETPINMODE, ®);
668 regmap_write(priv->regmap, SG_ETPINMODE, reg);
673 static int ave_ld20_get_pinmode(struct ave_private *priv)
675 u32 reg, mask, val = 0;
677 if (priv->regmap_arg > 0)
680 mask = SG_ETPINMODE_RMII(0);
682 switch (priv->phy_mode) {
683 case PHY_INTERFACE_MODE_RMII:
684 val = SG_ETPINMODE_RMII(0);
686 case PHY_INTERFACE_MODE_RGMII:
692 regmap_read(priv->regmap, SG_ETPINMODE, ®);
695 regmap_write(priv->regmap, SG_ETPINMODE, reg);
700 static int ave_pxs3_get_pinmode(struct ave_private *priv)
702 u32 reg, mask, val = 0;
704 if (priv->regmap_arg > 1)
707 mask = SG_ETPINMODE_RMII(priv->regmap_arg);
709 switch (priv->phy_mode) {
710 case PHY_INTERFACE_MODE_RMII:
711 val = SG_ETPINMODE_RMII(priv->regmap_arg);
713 case PHY_INTERFACE_MODE_RGMII:
719 regmap_read(priv->regmap, SG_ETPINMODE, ®);
722 regmap_write(priv->regmap, SG_ETPINMODE, reg);
727 static int ave_ofdata_to_platdata(struct udevice *dev)
729 struct eth_pdata *pdata = dev_get_platdata(dev);
730 struct ave_private *priv = dev_get_priv(dev);
731 struct ofnode_phandle_args args;
732 const char *phy_mode;
737 priv->data = (const struct ave_soc_data *)dev_get_driver_data(dev);
741 pdata->iobase = devfdt_get_addr(dev);
742 pdata->phy_interface = -1;
743 phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
746 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
747 if (pdata->phy_interface == -1) {
748 dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
752 pdata->max_speed = 0;
753 valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed",
756 pdata->max_speed = fdt32_to_cpu(*valp);
758 for (nc = 0; nc < AVE_MAX_CLKS; nc++) {
759 name = priv->data->clock_names[nc];
762 ret = clk_get_by_name(dev, name, &priv->clk[nc]);
764 dev_err(dev, "Failed to get clocks property: %d\n",
771 for (nr = 0; nr < AVE_MAX_RSTS; nr++) {
772 name = priv->data->reset_names[nr];
775 ret = reset_get_by_name(dev, name, &priv->rst[nr]);
777 dev_err(dev, "Failed to get resets property: %d\n",
784 ret = dev_read_phandle_with_args(dev, "socionext,syscon-phy-mode",
787 dev_err(dev, "Failed to get syscon-phy-mode property: %d\n",
792 priv->regmap = syscon_node_to_regmap(args.node);
793 if (IS_ERR(priv->regmap)) {
794 ret = PTR_ERR(priv->regmap);
795 dev_err(dev, "can't get syscon: %d\n", ret);
799 if (args.args_count != 1) {
801 dev_err(dev, "Invalid argument of syscon-phy-mode\n");
805 priv->regmap_arg = args.args[0];
811 reset_free(&priv->rst[nr]);
814 clk_free(&priv->clk[nc]);
819 static int ave_probe(struct udevice *dev)
821 struct eth_pdata *pdata = dev_get_platdata(dev);
822 struct ave_private *priv = dev_get_priv(dev);
825 priv->data = (const struct ave_soc_data *)dev_get_driver_data(dev);
829 priv->iobase = pdata->iobase;
830 priv->phy_mode = pdata->phy_interface;
831 priv->max_speed = pdata->max_speed;
833 ret = priv->data->get_pinmode(priv);
835 dev_err(dev, "Invalid phy-mode\n");
839 for (nc = 0; nc < priv->nclks; nc++) {
840 ret = clk_enable(&priv->clk[nc]);
842 dev_err(dev, "Failed to enable clk: %d\n", ret);
843 goto out_clk_release;
847 for (nr = 0; nr < priv->nrsts; nr++) {
848 ret = reset_deassert(&priv->rst[nr]);
850 dev_err(dev, "Failed to deassert reset: %d\n", ret);
851 goto out_reset_release;
857 ret = ave_mdiobus_init(priv, dev->name);
859 dev_err(dev, "Failed to initialize mdiobus: %d\n", ret);
860 goto out_reset_release;
863 priv->bus = miiphy_get_dev_by_name(dev->name);
865 ret = ave_phy_init(priv, dev);
867 dev_err(dev, "Failed to initialize phy: %d\n", ret);
868 goto out_mdiobus_release;
874 mdio_unregister(priv->bus);
875 mdio_free(priv->bus);
877 reset_release_all(priv->rst, nr);
879 clk_release_all(priv->clk, nc);
884 static int ave_remove(struct udevice *dev)
886 struct ave_private *priv = dev_get_priv(dev);
889 mdio_unregister(priv->bus);
890 mdio_free(priv->bus);
891 reset_release_all(priv->rst, priv->nrsts);
892 clk_release_all(priv->clk, priv->nclks);
897 static const struct eth_ops ave_ops = {
902 .free_pkt = ave_free_packet,
903 .write_hwaddr = ave_write_hwaddr,
906 static const struct ave_soc_data ave_pro4_data = {
907 .is_desc_64bit = false,
909 "gio", "ether", "ether-gb", "ether-phy",
914 .get_pinmode = ave_pro4_get_pinmode,
917 static const struct ave_soc_data ave_pxs2_data = {
918 .is_desc_64bit = false,
925 .get_pinmode = ave_pro4_get_pinmode,
928 static const struct ave_soc_data ave_ld11_data = {
929 .is_desc_64bit = false,
936 .get_pinmode = ave_ld11_get_pinmode,
939 static const struct ave_soc_data ave_ld20_data = {
940 .is_desc_64bit = true,
947 .get_pinmode = ave_ld20_get_pinmode,
950 static const struct ave_soc_data ave_pxs3_data = {
951 .is_desc_64bit = false,
958 .get_pinmode = ave_pxs3_get_pinmode,
961 static const struct udevice_id ave_ids[] = {
963 .compatible = "socionext,uniphier-pro4-ave4",
964 .data = (ulong)&ave_pro4_data,
967 .compatible = "socionext,uniphier-pxs2-ave4",
968 .data = (ulong)&ave_pxs2_data,
971 .compatible = "socionext,uniphier-ld11-ave4",
972 .data = (ulong)&ave_ld11_data,
975 .compatible = "socionext,uniphier-ld20-ave4",
976 .data = (ulong)&ave_ld20_data,
979 .compatible = "socionext,uniphier-pxs3-ave4",
980 .data = (ulong)&ave_pxs3_data,
985 U_BOOT_DRIVER(ave) = {
990 .remove = ave_remove,
991 .ofdata_to_platdata = ave_ofdata_to_platdata,
993 .priv_auto_alloc_size = sizeof(struct ave_private),
994 .platdata_auto_alloc_size = sizeof(struct eth_pdata),