1 // SPDX-License-Identifier: GPL-2.0+
3 * Meson GXL Internal PHY Driver
5 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
6 * Copyright (C) 2016 BayLibre, SAS. All rights reserved.
7 * Author: Neil Armstrong <narmstrong@baylibre.com>
11 #include <linux/bitops.h>
15 /* This function is provided to cope with the possible failures of this phy
16 * during aneg process. When aneg fails, the PHY reports that aneg is done
17 * but the value found in MII_LPA is wrong:
18 * - Early failures: MII_LPA is just 0x0001. if MII_EXPANSION reports that
19 * the link partner (LP) supports aneg but the LP never acked our base
20 * code word, it is likely that we never sent it to begin with.
21 * - Late failures: MII_LPA is filled with a value which seems to make sense
22 * but it actually is not what the LP is advertising. It seems that we
23 * can detect this using a magic bit in the WOL bank (reg 12 - bit 12).
24 * If this particular bit is not set when aneg is reported being done,
25 * it means MII_LPA is likely to be wrong.
27 * In both case, forcing a restart of the aneg process solve the problem.
28 * When this failure happens, the first retry is usually successful but,
29 * in some cases, it may take up to 6 retries to get a decent result
31 int meson_gxl_startup(struct phy_device *phydev)
33 unsigned int retries = 10;
34 int ret, wol, lpa, exp;
37 ret = genphy_update_link(phydev);
41 if (phydev->autoneg == AUTONEG_ENABLE) {
42 /* Need to access WOL bank, make sure the access is open */
43 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
46 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
49 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
52 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
56 /* Request LPI_STATUS WOL register */
57 ret = phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x8D80);
61 /* Read LPI_STATUS value */
62 wol = phy_read(phydev, MDIO_DEVAD_NONE, 0x15);
66 lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
70 exp = phy_read(phydev, MDIO_DEVAD_NONE, MII_EXPANSION);
74 if (!(wol & BIT(12)) ||
75 ((exp & EXPANSION_NWAY) && !(lpa & LPA_LPACK))) {
77 /* Looks like aneg failed after all */
79 printf("%s LPA corruption max attempts\n",
84 printf("%s LPA corruption - aneg restart\n",
87 ret = genphy_restart_aneg(phydev);
97 return genphy_parse_link(phydev);
100 static int meson_gxl_phy_config(struct phy_device *phydev)
102 /* Enable Analog and DSP register Bank access by */
103 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
104 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
105 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0000);
106 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x0400);
108 /* Write Analog register 23 */
109 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x8E0D);
110 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x4417);
112 /* Enable fractional PLL */
113 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x0005);
114 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1B);
116 /* Program fraction FR_PLL_DIV1 */
117 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x029A);
118 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1D);
120 /* Program fraction FR_PLL_DIV1 */
121 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0xAAAA);
122 phy_write(phydev, MDIO_DEVAD_NONE, 0x14, 0x5C1C);
124 return genphy_config(phydev);
127 static struct phy_driver meson_gxl_phy_driver = {
128 .name = "Meson GXL Internal PHY",
131 .features = PHY_BASIC_FEATURES,
132 .config = &meson_gxl_phy_config,
133 .startup = &meson_gxl_startup,
134 .shutdown = &genphy_shutdown,
137 int phy_meson_gxl_init(void)
139 phy_register(&meson_gxl_phy_driver);