Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Atheros PHY drivers |
| 4 | * |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 5 | * Copyright 2011, 2013 Freescale Semiconductor, Inc. |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 6 | * author Andy Fleming |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 7 | */ |
Joe Hershberger | 14b4812 | 2018-07-25 12:59:22 -0500 | [diff] [blame] | 8 | #include <common.h> |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 9 | #include <phy.h> |
| 10 | |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 11 | #define AR803x_PHY_DEBUG_ADDR_REG 0x1d |
| 12 | #define AR803x_PHY_DEBUG_DATA_REG 0x1e |
| 13 | |
| 14 | #define AR803x_DEBUG_REG_5 0x5 |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 15 | #define AR803x_RGMII_TX_CLK_DLY BIT(8) |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 16 | |
| 17 | #define AR803x_DEBUG_REG_0 0x0 |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 18 | #define AR803x_RGMII_RX_CLK_DLY BIT(15) |
| 19 | |
Vladimir Oltean | 3e7330e | 2020-05-07 00:11:50 +0200 | [diff] [blame] | 20 | /* CLK_25M register is at MMD 7, address 0x8016 */ |
| 21 | #define AR803x_CLK_25M_SEL_REG 0x8016 |
| 22 | /* AR8035: Select frequency on CLK_25M pin through bits 4:3 */ |
| 23 | #define AR8035_CLK_25M_FREQ_25M (0 | 0) |
| 24 | #define AR8035_CLK_25M_FREQ_50M (0 | BIT(3)) |
| 25 | #define AR8035_CLK_25M_FREQ_62M (BIT(4) | 0) |
| 26 | #define AR8035_CLK_25M_FREQ_125M (BIT(4) | BIT(3)) |
| 27 | #define AR8035_CLK_25M_MASK GENMASK(4, 3) |
| 28 | |
Michael Walle | 69a107e | 2020-05-07 00:11:54 +0200 | [diff] [blame] | 29 | #define AR8021_PHY_ID 0x004dd040 |
| 30 | #define AR8031_PHY_ID 0x004dd074 |
| 31 | #define AR8035_PHY_ID 0x004dd072 |
| 32 | |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 33 | static int ar803x_debug_reg_read(struct phy_device *phydev, u16 reg) |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 34 | { |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 35 | int ret; |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 36 | |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 37 | ret = phy_write(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_ADDR_REG, |
| 38 | reg); |
| 39 | if (ret < 0) |
| 40 | return ret; |
| 41 | |
| 42 | return phy_read(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_DATA_REG); |
| 43 | } |
| 44 | |
| 45 | static int ar803x_debug_reg_mask(struct phy_device *phydev, u16 reg, |
| 46 | u16 clear, u16 set) |
| 47 | { |
| 48 | int val; |
| 49 | |
| 50 | val = ar803x_debug_reg_read(phydev, reg); |
| 51 | if (val < 0) |
| 52 | return val; |
| 53 | |
| 54 | val &= 0xffff; |
| 55 | val &= ~clear; |
| 56 | val |= set; |
| 57 | |
| 58 | return phy_write(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_DATA_REG, |
| 59 | val); |
| 60 | } |
| 61 | |
| 62 | static int ar803x_enable_rx_delay(struct phy_device *phydev, bool on) |
| 63 | { |
| 64 | u16 clear = 0, set = 0; |
| 65 | |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 66 | if (on) |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 67 | set = AR803x_RGMII_RX_CLK_DLY; |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 68 | else |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 69 | clear = AR803x_RGMII_RX_CLK_DLY; |
| 70 | |
| 71 | return ar803x_debug_reg_mask(phydev, AR803x_DEBUG_REG_0, clear, set); |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 74 | static int ar803x_enable_tx_delay(struct phy_device *phydev, bool on) |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 75 | { |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 76 | u16 clear = 0, set = 0; |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 77 | |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 78 | if (on) |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 79 | set = AR803x_RGMII_TX_CLK_DLY; |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 80 | else |
Michael Walle | fb4a465 | 2020-05-07 00:11:55 +0200 | [diff] [blame^] | 81 | clear = AR803x_RGMII_TX_CLK_DLY; |
| 82 | |
| 83 | return ar803x_debug_reg_mask(phydev, AR803x_DEBUG_REG_5, clear, set); |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 84 | } |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 85 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 86 | static int ar8021_config(struct phy_device *phydev) |
| 87 | { |
Vladimir Oltean | 1e37f75 | 2020-05-07 00:11:52 +0200 | [diff] [blame] | 88 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 89 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 90 | |
| 91 | ar803x_enable_tx_delay(phydev, true); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 92 | |
Zhao Qiang | 04f2ba4 | 2013-12-23 15:51:33 +0800 | [diff] [blame] | 93 | phydev->supported = phydev->drv->features; |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int ar8031_config(struct phy_device *phydev) |
| 98 | { |
| 99 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID || |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 100 | phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 101 | ar803x_enable_tx_delay(phydev, true); |
Vladimir Oltean | 3ccbb4b | 2020-05-07 00:11:51 +0200 | [diff] [blame] | 102 | else |
| 103 | ar803x_enable_tx_delay(phydev, false); |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 104 | |
| 105 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID || |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 106 | phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 107 | ar803x_enable_rx_delay(phydev, true); |
Vladimir Oltean | 3ccbb4b | 2020-05-07 00:11:51 +0200 | [diff] [blame] | 108 | else |
| 109 | ar803x_enable_rx_delay(phydev, false); |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 110 | |
| 111 | phydev->supported = phydev->drv->features; |
| 112 | |
| 113 | genphy_config_aneg(phydev); |
| 114 | genphy_restart_aneg(phydev); |
| 115 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 119 | static int ar8035_config(struct phy_device *phydev) |
| 120 | { |
| 121 | int regval; |
| 122 | |
Vladimir Oltean | 3e7330e | 2020-05-07 00:11:50 +0200 | [diff] [blame] | 123 | /* Configure CLK_25M output clock at 125 MHz */ |
| 124 | regval = phy_read_mmd(phydev, MDIO_MMD_AN, AR803x_CLK_25M_SEL_REG); |
| 125 | regval &= ~AR8035_CLK_25M_MASK; /* No surprises */ |
| 126 | regval |= AR8035_CLK_25M_FREQ_125M; |
| 127 | phy_write_mmd(phydev, MDIO_MMD_AN, AR803x_CLK_25M_SEL_REG, regval); |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 128 | |
Andrea Merello | 1e3e19f | 2016-05-26 18:24:28 +0200 | [diff] [blame] | 129 | if ((phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) || |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 130 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) |
| 131 | ar803x_enable_tx_delay(phydev, true); |
Vladimir Oltean | 3ccbb4b | 2020-05-07 00:11:51 +0200 | [diff] [blame] | 132 | else |
| 133 | ar803x_enable_tx_delay(phydev, false); |
Andrea Merello | 1e3e19f | 2016-05-26 18:24:28 +0200 | [diff] [blame] | 134 | |
| 135 | if ((phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) || |
Vladimir Oltean | 23d8b89 | 2020-05-07 00:11:49 +0200 | [diff] [blame] | 136 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)) |
| 137 | ar803x_enable_rx_delay(phydev, true); |
Vladimir Oltean | 3ccbb4b | 2020-05-07 00:11:51 +0200 | [diff] [blame] | 138 | else |
| 139 | ar803x_enable_rx_delay(phydev, false); |
Andrea Merello | 1e3e19f | 2016-05-26 18:24:28 +0200 | [diff] [blame] | 140 | |
Xiaobo Xie | aa09e68 | 2014-04-11 16:03:11 +0800 | [diff] [blame] | 141 | phydev->supported = phydev->drv->features; |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 142 | |
Alison Wang | 5dc3af8 | 2016-02-19 15:52:28 +0800 | [diff] [blame] | 143 | genphy_config_aneg(phydev); |
| 144 | genphy_restart_aneg(phydev); |
| 145 | |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Kim Phillips | 40c2c03 | 2012-10-29 13:34:33 +0000 | [diff] [blame] | 149 | static struct phy_driver AR8021_driver = { |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 150 | .name = "AR8021", |
Michael Walle | 69a107e | 2020-05-07 00:11:54 +0200 | [diff] [blame] | 151 | .uid = AR8021_PHY_ID, |
Michael Walle | a5eb659 | 2020-05-07 00:11:53 +0200 | [diff] [blame] | 152 | .mask = 0xfffffff0, |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 153 | .features = PHY_GBIT_FEATURES, |
| 154 | .config = ar8021_config, |
| 155 | .startup = genphy_startup, |
| 156 | .shutdown = genphy_shutdown, |
| 157 | }; |
| 158 | |
Heiko Schocher | 93ac9b8 | 2013-06-04 10:58:00 +0200 | [diff] [blame] | 159 | static struct phy_driver AR8031_driver = { |
Shengzhou Liu | 76f57c3 | 2013-08-08 16:33:35 +0800 | [diff] [blame] | 160 | .name = "AR8031/AR8033", |
Michael Walle | 69a107e | 2020-05-07 00:11:54 +0200 | [diff] [blame] | 161 | .uid = AR8031_PHY_ID, |
Fabio Estevam | 2edb606 | 2014-01-03 15:55:59 -0200 | [diff] [blame] | 162 | .mask = 0xffffffef, |
Heiko Schocher | 93ac9b8 | 2013-06-04 10:58:00 +0200 | [diff] [blame] | 163 | .features = PHY_GBIT_FEATURES, |
Mugunthan V N | 3e4537d | 2016-10-13 19:33:36 +0530 | [diff] [blame] | 164 | .config = ar8031_config, |
Heiko Schocher | 93ac9b8 | 2013-06-04 10:58:00 +0200 | [diff] [blame] | 165 | .startup = genphy_startup, |
| 166 | .shutdown = genphy_shutdown, |
| 167 | }; |
| 168 | |
| 169 | static struct phy_driver AR8035_driver = { |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 170 | .name = "AR8035", |
Michael Walle | 69a107e | 2020-05-07 00:11:54 +0200 | [diff] [blame] | 171 | .uid = AR8035_PHY_ID, |
Fabio Estevam | 2edb606 | 2014-01-03 15:55:59 -0200 | [diff] [blame] | 172 | .mask = 0xffffffef, |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 173 | .features = PHY_GBIT_FEATURES, |
| 174 | .config = ar8035_config, |
| 175 | .startup = genphy_startup, |
| 176 | .shutdown = genphy_shutdown, |
| 177 | }; |
| 178 | |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 179 | int phy_atheros_init(void) |
| 180 | { |
| 181 | phy_register(&AR8021_driver); |
Heiko Schocher | 93ac9b8 | 2013-06-04 10:58:00 +0200 | [diff] [blame] | 182 | phy_register(&AR8031_driver); |
Xie Xiaobo | dcc307e | 2013-04-10 16:23:39 +0800 | [diff] [blame] | 183 | phy_register(&AR8035_driver); |
Andy Fleming | 60ca78b | 2011-04-07 21:56:05 -0500 | [diff] [blame] | 184 | |
| 185 | return 0; |
| 186 | } |