diff options
Diffstat (limited to 'arch/arm/mach-imx/mach-imx7d.c')
-rw-r--r-- | arch/arm/mach-imx/mach-imx7d.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/arch/arm/mach-imx/mach-imx7d.c b/arch/arm/mach-imx/mach-imx7d.c index 3f335974723f..7f9ea3c6dcd4 100644 --- a/arch/arm/mach-imx/mach-imx7d.c +++ b/arch/arm/mach-imx/mach-imx7d.c @@ -5,6 +5,7 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/irqchip.h> #include <linux/mfd/syscon.h> #include <linux/mfd/syscon/imx7-iomuxc-gpr.h> @@ -93,15 +94,48 @@ static void __init imx7d_enet_mdio_fixup(void) static void __init imx7d_enet_clk_sel(void) { + struct device_node *np = NULL; + struct clk *enet_out_clk; struct regmap *gpr; gpr = syscon_regmap_lookup_by_compatible("fsl,imx7d-iomuxc-gpr"); - if (!IS_ERR(gpr)) { - regmap_update_bits(gpr, IOMUXC_GPR1, IMX7D_GPR1_ENET_TX_CLK_SEL_MASK, 0); - regmap_update_bits(gpr, IOMUXC_GPR1, IMX7D_GPR1_ENET_CLK_DIR_MASK, 0); - } else { + if (IS_ERR(gpr)) { pr_err("failed to find fsl,imx7d-iomux-gpr regmap\n"); + return; } + + do { + int id; + u32 clk_sel_mask, clk_dir_mask; + + np = of_find_compatible_node(np, NULL, "fsl,imx7d-fec"); + if (!np) + return; + + /* Determine controller ID by ethernet alias */ + id = of_alias_get_id(np, "ethernet"); + clk_sel_mask = id == 0 ? IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK : + IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK; + clk_dir_mask = id == 0 ? IMX7D_GPR1_ENET1_CLK_DIR_MASK : + IMX7D_GPR1_ENET2_CLK_DIR_MASK; + + enet_out_clk = of_clk_get_by_name(np, "enet_out"); + + if (IS_ERR(enet_out_clk)) { + pr_info("%s: fec%d: failed to get enet_out clock, assuming ext. clock source\n", + __func__, id + 1); + /* use external clock for PHY */ + regmap_update_bits(gpr, IOMUXC_GPR1, clk_sel_mask, clk_sel_mask); + regmap_update_bits(gpr, IOMUXC_GPR1, clk_dir_mask, 0); + } else { + pr_info("%s: fec%d: found enet_out clock, assuming internal clock source\n", + __func__, id + 1); + /* use internal clock generation and output it to PHY */ + regmap_update_bits(gpr, IOMUXC_GPR1, clk_sel_mask, 0); + regmap_update_bits(gpr, IOMUXC_GPR1, clk_dir_mask, clk_dir_mask); + clk_put(enet_out_clk); + } + } while (np); } static inline void imx7d_enet_init(void) |