summaryrefslogtreecommitdiff
path: root/drivers/net/macb.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-02-09 11:56:35 -0500
committerTom Rini <trini@konsulko.com>2017-02-09 11:56:35 -0500
commite1a71f8b339220fa74c9cd5d36ae9c444c492e83 (patch)
tree5eca7ff69f390f4c2f2df3459d3e2db3d91b7af9 /drivers/net/macb.c
parent6f57b19857b514f6e94e423c9bbe2d4b8973a0db (diff)
parenta5fd13ad1913d9c66c47666dbedac7703a48e502 (diff)
downloadu-boot-imx-e1a71f8b339220fa74c9cd5d36ae9c444c492e83.zip
u-boot-imx-e1a71f8b339220fa74c9cd5d36ae9c444c492e83.tar.gz
u-boot-imx-e1a71f8b339220fa74c9cd5d36ae9c444c492e83.tar.bz2
Merge branch 'master' of git://git.denx.de/u-boot-net
Diffstat (limited to 'drivers/net/macb.c')
-rw-r--r--drivers/net/macb.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 452fc3e..1c4bef9 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
+#include <clk.h>
#include <dm.h>
/*
@@ -112,6 +113,7 @@ struct macb_device {
struct mii_dev *bus;
#ifdef CONFIG_DM_ETH
+ unsigned long pclk_rate;
phy_interface_t phy_interface;
#endif
};
@@ -754,7 +756,11 @@ static int _macb_write_hwaddr(struct macb_device *macb, unsigned char *enetaddr)
static u32 macb_mdc_clk_div(int id, struct macb_device *macb)
{
u32 config;
+#ifdef CONFIG_DM_ETH
+ unsigned long macb_hz = macb->pclk_rate;
+#else
unsigned long macb_hz = get_macb_pclk_rate(id);
+#endif
if (macb_hz < 20000000)
config = MACB_BF(CLK, MACB_CLK_DIV8);
@@ -771,7 +777,12 @@ static u32 macb_mdc_clk_div(int id, struct macb_device *macb)
static u32 gem_mdc_clk_div(int id, struct macb_device *macb)
{
u32 config;
+
+#ifdef CONFIG_DM_ETH
+ unsigned long macb_hz = macb->pclk_rate;
+#else
unsigned long macb_hz = get_macb_pclk_rate(id);
+#endif
if (macb_hz < 20000000)
config = GEM_BF(CLK, GEM_CLK_DIV8);
@@ -991,13 +1002,36 @@ static const struct eth_ops macb_eth_ops = {
.write_hwaddr = macb_write_hwaddr,
};
+static int macb_enable_clk(struct udevice *dev)
+{
+ struct macb_device *macb = dev_get_priv(dev);
+ struct clk clk;
+ ulong clk_rate;
+ int ret;
+
+ ret = clk_get_by_index(dev, 0, &clk);
+ if (ret)
+ return -EINVAL;
+
+ ret = clk_enable(&clk);
+ if (ret)
+ return ret;
+
+ clk_rate = clk_get_rate(&clk);
+ if (!clk_rate)
+ return -EINVAL;
+
+ macb->pclk_rate = clk_rate;
+
+ return 0;
+}
+
static int macb_eth_probe(struct udevice *dev)
{
struct eth_pdata *pdata = dev_get_platdata(dev);
struct macb_device *macb = dev_get_priv(dev);
-
-#ifdef CONFIG_DM_ETH
const char *phy_mode;
+ int ret;
phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
NULL);
@@ -1007,11 +1041,15 @@ static int macb_eth_probe(struct udevice *dev)
debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
return -EINVAL;
}
-#endif
macb->regs = (void *)pdata->iobase;
+ ret = macb_enable_clk(dev);
+ if (ret)
+ return ret;
+
_macb_eth_initialize(macb);
+
#if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
int retval;
struct mii_dev *mdiodev = mdio_alloc();