blob: 8b28bc853111cb16dea9554b857a276824b2a33e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Neil Armstrong6915b102017-11-27 10:16:16 +01002/*
3 * Copyright (C) 2016 BayLibre, SAS
4 * Author: Neil Armstrong <narmstrong@baylibre.com>
Neil Armstrong6915b102017-11-27 10:16:16 +01005 */
6
7#include <common.h>
8#include <dm.h>
9#include <asm/io.h>
Neil Armstrongf0f37622018-04-11 17:13:45 +020010#include <asm/arch/gx.h>
Neil Armstrong6915b102017-11-27 10:16:16 +010011#include <asm/arch/eth.h>
12#include <phy.h>
13
14/* Configure the Ethernet MAC with the requested interface mode
15 * with some optional flags.
16 */
17void meson_gx_eth_init(phy_interface_t mode, unsigned int flags)
18{
19 switch (mode) {
20 case PHY_INTERFACE_MODE_RGMII:
21 case PHY_INTERFACE_MODE_RGMII_ID:
22 case PHY_INTERFACE_MODE_RGMII_RXID:
23 case PHY_INTERFACE_MODE_RGMII_TXID:
24 /* Set RGMII mode */
Neil Armstrongf0f37622018-04-11 17:13:45 +020025 setbits_le32(GX_ETH_REG_0, GX_ETH_REG_0_PHY_INTF |
26 GX_ETH_REG_0_TX_PHASE(1) |
27 GX_ETH_REG_0_TX_RATIO(4) |
28 GX_ETH_REG_0_PHY_CLK_EN |
29 GX_ETH_REG_0_CLK_EN);
Neil Armstrong6915b102017-11-27 10:16:16 +010030 break;
31
32 case PHY_INTERFACE_MODE_RMII:
33 /* Set RMII mode */
Neil Armstrongf0f37622018-04-11 17:13:45 +020034 out_le32(GX_ETH_REG_0, GX_ETH_REG_0_INVERT_RMII_CLK |
35 GX_ETH_REG_0_CLK_EN);
Neil Armstrong6915b102017-11-27 10:16:16 +010036
37 /* Use GXL RMII Internal PHY */
38 if (IS_ENABLED(CONFIG_MESON_GXL) &&
39 (flags & MESON_GXL_USE_INTERNAL_RMII_PHY)) {
Neil Armstrongf0f37622018-04-11 17:13:45 +020040 writel(0x10110181, GX_ETH_REG_2);
41 writel(0xe40908ff, GX_ETH_REG_3);
Neil Armstrong6915b102017-11-27 10:16:16 +010042 }
43
44 break;
45
46 default:
47 printf("Invalid Ethernet interface mode\n");
48 return;
49 }
50
Beniamino Galvani2e668af2018-06-14 13:43:40 +020051 /* Enable power gate */
Neil Armstrongf0f37622018-04-11 17:13:45 +020052 clrbits_le32(GX_MEM_PD_REG_0, GX_MEM_PD_REG_0_ETH_MASK);
Neil Armstrong6915b102017-11-27 10:16:16 +010053}