eth.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2016 BayLibre, SAS
  3. * Author: Neil Armstrong <narmstrong@baylibre.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/gxbb.h>
  11. #include <asm/arch/eth.h>
  12. #include <phy.h>
  13. /* Configure the Ethernet MAC with the requested interface mode
  14. * with some optional flags.
  15. */
  16. void meson_gx_eth_init(phy_interface_t mode, unsigned int flags)
  17. {
  18. switch (mode) {
  19. case PHY_INTERFACE_MODE_RGMII:
  20. case PHY_INTERFACE_MODE_RGMII_ID:
  21. case PHY_INTERFACE_MODE_RGMII_RXID:
  22. case PHY_INTERFACE_MODE_RGMII_TXID:
  23. /* Set RGMII mode */
  24. setbits_le32(GXBB_ETH_REG_0, GXBB_ETH_REG_0_PHY_INTF |
  25. GXBB_ETH_REG_0_TX_PHASE(1) |
  26. GXBB_ETH_REG_0_TX_RATIO(4) |
  27. GXBB_ETH_REG_0_PHY_CLK_EN |
  28. GXBB_ETH_REG_0_CLK_EN);
  29. break;
  30. case PHY_INTERFACE_MODE_RMII:
  31. /* Set RMII mode */
  32. out_le32(GXBB_ETH_REG_0, GXBB_ETH_REG_0_INVERT_RMII_CLK |
  33. GXBB_ETH_REG_0_CLK_EN);
  34. /* Use GXL RMII Internal PHY */
  35. if (IS_ENABLED(CONFIG_MESON_GXL) &&
  36. (flags & MESON_GXL_USE_INTERNAL_RMII_PHY)) {
  37. writel(0x10110181, GXBB_ETH_REG_2);
  38. writel(0xe40908ff, GXBB_ETH_REG_3);
  39. }
  40. break;
  41. default:
  42. printf("Invalid Ethernet interface mode\n");
  43. return;
  44. }
  45. /* Enable power and clock gate */
  46. setbits_le32(GXBB_GCLK_MPEG_1, GXBB_GCLK_MPEG_1_ETH);
  47. clrbits_le32(GXBB_MEM_PD_REG_0, GXBB_MEM_PD_REG_0_ETH_MASK);
  48. }