]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/tsec.c
x86: timer: tsc: Allow specifying clock rate from device tree again
[u-boot] / drivers / net / tsec.c
index be0f38288f3dd1806c86dc6f2da87cf676df3dd0..03a46da2f8a1519072e4f730d88e8194db6ba733 100644 (file)
@@ -1,11 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Freescale Three Speed Ethernet Controller driver
  *
  * Copyright 2004-2011, 2013 Freescale Semiconductor, Inc.
  * (C) Copyright 2003, Motorola, Inc.
  * author Andy Fleming
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
 #include <command.h>
 #include <tsec.h>
 #include <fsl_mdio.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <asm/processor.h>
 #include <asm/io.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 #ifndef CONFIG_DM_ETH
 /* Default initializations for TSEC controllers. */
 
@@ -74,11 +71,11 @@ static void tsec_configure_serdes(struct tsec_private *priv)
         * to the register offset used for external PHY accesses
         */
        tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
-                       0, TBI_ANA, TBIANA_SETTINGS);
+                             0, TBI_ANA, TBIANA_SETTINGS);
        tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
-                       0, TBI_TBICON, TBICON_CLK_SELECT);
+                             0, TBI_TBICON, TBICON_CLK_SELECT);
        tsec_local_mdio_write(priv->phyregs_sgmii, in_be32(&priv->regs->tbipa),
-                       0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS);
+                             0, TBI_CR, CONFIG_TSEC_TBICR_SETTINGS);
 }
 
 #ifdef CONFIG_MCAST_TFTP
@@ -116,7 +113,7 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int set)
        whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */
        whichreg = result >> 29; /* the 3 MSB = which reg to set it in */
 
-       value = 1 << (31-whichbit);
+       value = BIT(31 - whichbit);
 
        if (set)
                setbits_be32(&regs->hash.gaddr0 + whichreg, value);
@@ -171,7 +168,6 @@ static void init_registers(struct tsec __iomem *regs)
 
        out_be32(&regs->attr, ATTR_INIT_SETTINGS);
        out_be32(&regs->attreli, ATTRELI_INIT_SETTINGS);
-
 }
 
 /*
@@ -222,8 +218,8 @@ static void adjust_link(struct tsec_private *priv, struct phy_device *phydev)
        out_be32(&regs->maccfg2, maccfg2);
 
        printf("Speed: %d, %s duplex%s\n", phydev->speed,
-                       (phydev->duplex) ? "full" : "half",
-                       (phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
+              (phydev->duplex) ? "full" : "half",
+              (phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
 }
 
 /*
@@ -240,7 +236,7 @@ static int tsec_send(struct udevice *dev, void *packet, int length)
 {
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
        struct tsec __iomem *regs = priv->regs;
-       uint16_t status;
+       u16 status;
        int result = 0;
        int i;
 
@@ -287,7 +283,7 @@ static int tsec_recv(struct eth_device *dev)
 
        while (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
                int length = in_be16(&priv->rxbd[priv->rx_idx].length);
-               uint16_t status = in_be16(&priv->rxbd[priv->rx_idx].status);
+               u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
                uchar *packet = net_rx_packets[priv->rx_idx];
 
                /* Send the packet up if there were no errors */
@@ -323,8 +319,8 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 
        if (!(in_be16(&priv->rxbd[priv->rx_idx].status) & RXBD_EMPTY)) {
                int length = in_be16(&priv->rxbd[priv->rx_idx].length);
-               uint16_t status = in_be16(&priv->rxbd[priv->rx_idx].status);
-               uint32_t buf;
+               u16 status = in_be16(&priv->rxbd[priv->rx_idx].status);
+               u32 buf;
 
                /* Send the packet up if there were no errors */
                if (!(status & RXBD_STATS)) {
@@ -347,7 +343,7 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp)
 static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length)
 {
        struct tsec_private *priv = (struct tsec_private *)dev->priv;
-       uint16_t status;
+       u16 status;
 
        out_be16(&priv->rxbd[priv->rx_idx].length, 0);
 
@@ -427,7 +423,8 @@ void redundant_init(struct tsec_private *priv)
        clrbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
 
        do {
-               uint16_t status;
+               u16 status;
+
                tsec_send(priv->dev, (void *)pkt, sizeof(pkt));
 
                /* Wait for buffer to be received */
@@ -478,7 +475,7 @@ void redundant_init(struct tsec_private *priv)
 static void startup_tsec(struct tsec_private *priv)
 {
        struct tsec __iomem *regs = priv->regs;
-       uint16_t status;
+       u16 status;
        int i;
 
        /* reset the indices to zero */
@@ -532,7 +529,7 @@ static void startup_tsec(struct tsec_private *priv)
  * This allows U-Boot to find the first active controller.
  */
 #ifndef CONFIG_DM_ETH
-static int tsec_init(struct eth_device *dev, bd_t * bd)
+static int tsec_init(struct eth_device *dev, bd_t *bd)
 #else
 static int tsec_init(struct udevice *dev)
 #endif
@@ -616,22 +613,23 @@ static phy_interface_t tsec_get_interface(struct tsec_private *priv)
        }
 
        if (ecntrl & ECNTRL_REDUCED_MODE) {
+               phy_interface_t interface;
+
                if (ecntrl & ECNTRL_REDUCED_MII_MODE)
                        return PHY_INTERFACE_MODE_RMII;
-               else {
-                       phy_interface_t interface = priv->interface;
-
-                       /*
-                        * This isn't autodetected, so it must
-                        * be set by the platform code.
-                        */
-                       if ((interface == PHY_INTERFACE_MODE_RGMII_ID) ||
-                           (interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
-                           (interface == PHY_INTERFACE_MODE_RGMII_RXID))
-                               return interface;
-
-                       return PHY_INTERFACE_MODE_RGMII;
-               }
+
+               interface = priv->interface;
+
+               /*
+                * This isn't autodetected, so it must
+                * be set by the platform code.
+                */
+               if (interface == PHY_INTERFACE_MODE_RGMII_ID ||
+                   interface == PHY_INTERFACE_MODE_RGMII_TXID ||
+                   interface == PHY_INTERFACE_MODE_RGMII_RXID)
+                       return interface;
+
+               return PHY_INTERFACE_MODE_RGMII;
        }
 
        if (priv->flags & TSEC_GIGABIT)
@@ -691,17 +689,19 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
        int i;
        struct tsec_private *priv;
 
-       dev = (struct eth_device *)malloc(sizeof *dev);
+       dev = (struct eth_device *)malloc(sizeof(*dev));
 
-       if (NULL == dev)
+       if (!dev)
                return 0;
 
-       memset(dev, 0, sizeof *dev);
+       memset(dev, 0, sizeof(*dev));
 
        priv = (struct tsec_private *)malloc(sizeof(*priv));
 
-       if (NULL == priv)
+       if (!priv) {
+               free(dev);
                return 0;
+       }
 
        priv->regs = tsec_info->regs;
        priv->phyregs_sgmii = tsec_info->miiregs_sgmii;
@@ -747,10 +747,11 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
 int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
 {
        int i;
-       int ret, count = 0;
+       int count = 0;
 
        for (i = 0; i < num; i++) {
-               ret = tsec_initialize(bis, &tsecs[i]);
+               int ret = tsec_initialize(bis, &tsecs[i]);
+
                if (ret > 0)
                        count += ret;
        }
@@ -775,45 +776,44 @@ int tsec_probe(struct udevice *dev)
        struct tsec_private *priv = dev_get_priv(dev);
        struct eth_pdata *pdata = dev_get_platdata(dev);
        struct fsl_pq_mdio_info mdio_info;
-       int offset = 0;
-       int reg;
+       struct ofnode_phandle_args phandle_args;
+       ofnode parent;
        const char *phy_mode;
        int ret;
 
-       pdata->iobase = (phys_addr_t)dev_get_addr(dev);
+       pdata->iobase = (phys_addr_t)dev_read_addr(dev);
        priv->regs = (struct tsec *)pdata->iobase;
 
-       offset = fdtdec_lookup_phandle(gd->fdt_blob, dev->of_offset,
-                                      "phy-handle");
-       if (offset > 0) {
-               reg = fdtdec_get_int(gd->fdt_blob, offset, "reg", 0);
-               priv->phyaddr = reg;
-       } else {
+       if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+                                      &phandle_args)) {
                debug("phy-handle does not exist under tsec %s\n", dev->name);
                return -ENOENT;
+       } else {
+               int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
+
+               priv->phyaddr = reg;
        }
 
-       offset = fdt_parent_offset(gd->fdt_blob, offset);
-       if (offset > 0) {
-               reg = fdtdec_get_int(gd->fdt_blob, offset, "reg", 0);
-               priv->phyregs_sgmii = (struct tsec_mii_mng *)(reg + 0x520);
+       parent = ofnode_get_parent(phandle_args.node);
+       if (ofnode_valid(parent)) {
+               int reg = ofnode_get_addr_index(parent, 0);
+
+               priv->phyregs_sgmii = (struct tsec_mii_mng *)reg;
        } else {
                debug("No parent node for PHY?\n");
                return -ENOENT;
        }
 
-       offset = fdtdec_lookup_phandle(gd->fdt_blob, dev->of_offset,
-                                      "tbi-handle");
-       if (offset > 0) {
-               reg = fdtdec_get_int(gd->fdt_blob, offset, "reg",
-                                    CONFIG_SYS_TBIPA_VALUE);
-               priv->tbiaddr = reg;
-       } else {
+       if (dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
+                                      &phandle_args)) {
                priv->tbiaddr = CONFIG_SYS_TBIPA_VALUE;
+       } else {
+               int reg = ofnode_read_u32_default(phandle_args.node, "reg",
+                                                 CONFIG_SYS_TBIPA_VALUE);
+               priv->tbiaddr = reg;
        }
 
-       phy_mode = fdt_getprop(gd->fdt_blob, dev->of_offset,
-                              "phy-connection-type", NULL);
+       phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
        if (phy_mode)
                pdata->phy_interface = phy_get_interface_by_name(phy_mode);
        if (pdata->phy_interface == -1) {