developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 1 | Index: drivers/net/phy/Kconfig |
| 2 | =================================================================== |
| 3 | --- a/drivers/net/phy/Kconfig |
| 4 | +++ b/drivers/net/phy/Kconfig |
| 5 | @@ -345,6 +345,11 @@ config SFP |
| 6 | depends on HWMON || HWMON=n |
| 7 | select MDIO_I2C |
| 8 | |
| 9 | +config AIROHA_EN8801S_PHY |
| 10 | + tristate "Drivers for Airoha EN8801S Gigabit PHYs" |
| 11 | + ---help--- |
| 12 | + Currently supports the Airoha EN8801S PHY. |
| 13 | + |
| 14 | config ADIN_PHY |
| 15 | tristate "Analog Devices Industrial Ethernet PHYs" |
| 16 | help |
| 17 | Index: drivers/net/phy/Makefile |
| 18 | =================================================================== |
| 19 | --- a/drivers/net/phy/Makefile |
| 20 | +++ b/drivers/net/phy/Makefile |
| 21 | @@ -67,6 +67,7 @@ aquantia-objs += aquantia_main.o |
| 22 | ifdef CONFIG_HWMON |
| 23 | aquantia-objs += aquantia_hwmon.o |
| 24 | endif |
| 25 | +obj-$(CONFIG_AIROHA_EN8801S_PHY) += en8801s.o |
| 26 | obj-$(CONFIG_AQUANTIA_PHY) += aquantia.o |
| 27 | obj-$(CONFIG_AX88796B_PHY) += ax88796b.o |
| 28 | obj-$(CONFIG_AT803X_PHY) += at803x.o |
| 29 | Index: drivers/net/phy/en8801s.c |
| 30 | =================================================================== |
| 31 | --- /dev/null |
| 32 | +++ b/drivers/net/phy/en8801s.c |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 33 | @@ -0,0 +1,434 @@ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 34 | +// SPDX-License-Identifier: GPL-2.0 |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 35 | +/* FILE NAME: en8801s.c |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 36 | + * PURPOSE: |
| 37 | + * EN8801S phy driver for Linux |
| 38 | + * NOTES: |
| 39 | + * |
| 40 | + */ |
| 41 | + |
| 42 | +/* INCLUDE FILE DECLARATIONS |
| 43 | + */ |
| 44 | + |
| 45 | +#include <linux/kernel.h> |
| 46 | +#include <linux/string.h> |
| 47 | +#include <linux/errno.h> |
| 48 | +#include <linux/unistd.h> |
| 49 | +#include <linux/interrupt.h> |
| 50 | +#include <linux/init.h> |
| 51 | +#include <linux/delay.h> |
| 52 | +#include <linux/netdevice.h> |
| 53 | +#include <linux/etherdevice.h> |
| 54 | +#include <linux/skbuff.h> |
| 55 | +#include <linux/spinlock.h> |
| 56 | +#include <linux/mm.h> |
| 57 | +#include <linux/module.h> |
| 58 | +#include <linux/mii.h> |
| 59 | +#include <linux/ethtool.h> |
| 60 | +#include <linux/phy.h> |
| 61 | +#include <linux/delay.h> |
| 62 | + |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 63 | +#include <linux/uaccess.h> |
| 64 | +#include <linux/version.h> |
| 65 | + |
| 66 | +#include "en8801s.h" |
| 67 | + |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 68 | +MODULE_DESCRIPTION("Airoha EN8801S PHY drivers"); |
| 69 | +MODULE_AUTHOR("Airoha"); |
| 70 | +MODULE_LICENSE("GPL"); |
| 71 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 72 | +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)) |
| 73 | +#define phydev_mdio_bus(dev) ((dev)->bus) |
| 74 | +#else |
| 75 | +#define phydev_mdio_bus(dev) ((dev)->mdio.bus) |
| 76 | +#endif |
| 77 | + |
| 78 | +enum { |
| 79 | + PHY_STATE_DONE = 0, |
| 80 | + PHY_STATE_INIT = 1, |
| 81 | + PHY_STATE_PROCESS = 2, |
| 82 | +}; |
| 83 | + |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 84 | +/************************************************************************ |
| 85 | +* F U N C T I O N S |
| 86 | +************************************************************************/ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 87 | +static unsigned int airoha_cl45_write(struct mii_bus *bus, u32 port, u32 devad, u32 reg, u16 val) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 88 | +{ |
| 89 | + mdiobus_write(bus, port, MII_MMD_ACC_CTL_REG, devad); |
| 90 | + mdiobus_write(bus, port, MII_MMD_ADDR_DATA_REG, reg); |
| 91 | + mdiobus_write(bus, port, MII_MMD_ACC_CTL_REG, MMD_OP_MODE_DATA | devad); |
| 92 | + mdiobus_write(bus, port, MII_MMD_ADDR_DATA_REG, val); |
| 93 | + return 0; |
| 94 | +} |
| 95 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 96 | +static unsigned int airoha_cl45_read(struct mii_bus *bus, u32 port, u32 devad, u32 reg, u32 *read_data) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 97 | +{ |
| 98 | + mdiobus_write(bus, port, MII_MMD_ACC_CTL_REG, devad); |
| 99 | + mdiobus_write(bus, port, MII_MMD_ADDR_DATA_REG, reg); |
| 100 | + mdiobus_write(bus, port, MII_MMD_ACC_CTL_REG, MMD_OP_MODE_DATA | devad); |
| 101 | + *read_data = mdiobus_read(bus, port, MII_MMD_ADDR_DATA_REG); |
| 102 | + return 0; |
| 103 | +} |
| 104 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 105 | +static unsigned int airoha_cl22_read(struct mii_bus *ebus, unsigned int phy_addr, unsigned int phy_register, unsigned int *read_data) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 106 | +{ |
| 107 | + *read_data = mdiobus_read(ebus, phy_addr, phy_register); |
| 108 | + return 0; |
| 109 | +} |
| 110 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 111 | +static unsigned int airoha_cl22_write(struct mii_bus *ebus, unsigned int phy_addr, unsigned int phy_register, unsigned int write_data) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 112 | +{ |
| 113 | + mdiobus_write(ebus, phy_addr, phy_register, write_data); |
| 114 | + return 0; |
| 115 | +} |
| 116 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 117 | +static void airoha_pbus_write(struct mii_bus *ebus, unsigned long pbus_id, unsigned long pbus_address, unsigned long pbus_data) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 118 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 119 | + airoha_cl22_write(ebus, pbus_id, 0x1F, (unsigned int)(pbus_address >> 6)); |
| 120 | + airoha_cl22_write(ebus, pbus_id, (unsigned int)((pbus_address >> 2) & 0xf), (unsigned int)(pbus_data & 0xFFFF)); |
| 121 | + airoha_cl22_write(ebus, pbus_id, 0x10, (unsigned int)(pbus_data >> 16)); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 122 | + return; |
| 123 | +} |
| 124 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 125 | +static unsigned long airoha_pbus_read(struct mii_bus *ebus, unsigned long pbus_id, unsigned long pbus_address) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 126 | +{ |
| 127 | + unsigned long pbus_data; |
| 128 | + unsigned int pbus_data_low, pbus_data_high; |
| 129 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 130 | + airoha_cl22_write(ebus, pbus_id, 0x1F, (unsigned int)(pbus_address >> 6)); |
| 131 | + airoha_cl22_read(ebus, pbus_id, (unsigned int)((pbus_address >> 2) & 0xf), &pbus_data_low); |
| 132 | + airoha_cl22_read(ebus, pbus_id, 0x10, &pbus_data_high); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 133 | + pbus_data = (pbus_data_high << 16) + pbus_data_low; |
| 134 | + return pbus_data; |
| 135 | +} |
| 136 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 137 | +/* Airoha Token Ring Write function */ |
| 138 | +static void airoha_tr_reg_write(struct mii_bus *ebus, unsigned long tr_address, unsigned long tr_data) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 139 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 140 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x1F, 0x52b5); /* page select */ |
| 141 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x11, (unsigned int)(tr_data & 0xffff)); |
| 142 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x12, (unsigned int)(tr_data >> 16)); |
| 143 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x10, (unsigned int)(tr_address | TrReg_WR)); |
| 144 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x1F, 0x0); /* page resetore */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 145 | + return; |
| 146 | +} |
| 147 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 148 | +/* Airoha Token Ring Read function */ |
| 149 | +static unsigned long airoha_tr_reg_read(struct mii_bus *ebus, unsigned long tr_address) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 150 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 151 | + unsigned long tr_data; |
| 152 | + unsigned int tr_data_low, tr_data_high; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 153 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 154 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x1F, 0x52b5); /* page select */ |
| 155 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x10, (unsigned int)(tr_address | TrReg_RD)); |
| 156 | + airoha_cl22_read(ebus, EN8801S_MDIO_PHY_ID, 0x11, &tr_data_low); |
| 157 | + airoha_cl22_read(ebus, EN8801S_MDIO_PHY_ID, 0x12, &tr_data_high); |
| 158 | + airoha_cl22_write(ebus, EN8801S_MDIO_PHY_ID, 0x1F, 0x0); /* page resetore */ |
| 159 | + tr_data = (tr_data_high << 16) + tr_data_low; |
| 160 | + return tr_data; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 161 | +} |
| 162 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 163 | +static void en8801s_led_init(struct phy_device *phydev) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 164 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 165 | + struct mii_bus *mbus = phydev_mdio_bus(phydev); |
| 166 | + u32 reg_value; |
| 167 | + |
| 168 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x186c, 0x3); |
| 169 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0X1870, 0x100); |
| 170 | + reg_value = (airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1880) & ~(0x3)); |
| 171 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1880, reg_value); |
| 172 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x21, 0x8008); |
| 173 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x22, 0x600); |
| 174 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x23, 0xc00); |
| 175 | + /* LED0: 10M/100M */ |
| 176 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x24, 0x8006); |
| 177 | + /* LED0: blink 10M/100M Tx/Rx */ |
| 178 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x25, 0x3c); |
| 179 | + /* LED1: 1000M */ |
| 180 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x26, 0x8001); |
| 181 | + /* LED1: blink 1000M Tx/Rx */ |
| 182 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1f, 0x27, 0x3); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 183 | +} |
| 184 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 185 | +static int en8801s_phy_process(struct phy_device *phydev) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 186 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 187 | + struct mii_bus *mbus = phydev_mdio_bus(phydev); |
| 188 | + u32 reg_value = 0; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 189 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 190 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x19e0); |
| 191 | + reg_value |= (1 << 0); |
| 192 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x19e0, reg_value); |
| 193 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x19e0); |
| 194 | + reg_value &= ~(1 << 0); |
| 195 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x19e0, reg_value); |
| 196 | + return 0; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 197 | +} |
| 198 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 199 | +static int en8801s_phase1_init(struct phy_device *phydev) |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 200 | +{ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 201 | + unsigned long pbus_data; |
| 202 | + unsigned int pbusAddress; |
| 203 | + u32 reg_value; |
| 204 | + int retry; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 205 | + struct mii_bus *mbus = phydev_mdio_bus(phydev); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 206 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 207 | + msleep(1500); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 208 | + |
| 209 | + pbusAddress = EN8801S_PBUS_DEFAULT_ID; |
| 210 | + retry = MAX_OUI_CHECK; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 211 | + while (1) { |
| 212 | + pbus_data = airoha_pbus_read(mbus, pbusAddress, EN8801S_RG_ETHER_PHY_OUI); /* PHY OUI */ |
| 213 | + if (EN8801S_PBUS_OUI == pbus_data) { |
| 214 | + pbus_data = airoha_pbus_read(mbus, pbusAddress, EN8801S_RG_SMI_ADDR); /* SMI ADDR */ |
| 215 | + pbus_data = (pbus_data & 0xffff0000) | (unsigned long)(EN8801S_PBUS_PHY_ID << 8) | (unsigned long)(EN8801S_MDIO_PHY_ID); |
| 216 | + phydev_info(phydev, "SMI_ADDR=%lx (renew)\n", pbus_data); |
| 217 | + airoha_pbus_write(mbus, pbusAddress, EN8801S_RG_SMI_ADDR, pbus_data); |
| 218 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_BUCK_CTL, 0x03); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 219 | + mdelay(10); |
| 220 | + break; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 221 | + } else { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 222 | + pbusAddress = EN8801S_PBUS_PHY_ID; |
| 223 | + } |
| 224 | + retry --; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 225 | + if (0 == retry) { |
| 226 | + phydev_err(phydev, "Probe fail !\n"); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 227 | + return 0; |
| 228 | + } |
| 229 | + } |
| 230 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 231 | + reg_value = (airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL) & 0xfffffffc) | 0x10 | (EN8801S_RX_POLARITY << 1) | EN8801S_TX_POLARITY; |
| 232 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL, reg_value); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 233 | + mdelay(10); |
| 234 | + reg_value &= 0xffffffef; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 235 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL, reg_value); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 236 | + |
| 237 | + retry = MAX_RETRY; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 238 | + while (1) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 239 | + mdelay(10); |
| 240 | + reg_value = phy_read(phydev, MII_PHYSID2); |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 241 | + if (reg_value == EN8801S_PHY_ID2) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 242 | + break; /* wait GPHY ready */ |
| 243 | + } |
| 244 | + retry--; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 245 | + if (0 == retry) { |
| 246 | + phydev_err(phydev, "Initialize fail !\n"); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 247 | + return 0; |
| 248 | + } |
| 249 | + } |
| 250 | + /* Software Reset PHY */ |
| 251 | + reg_value = phy_read(phydev, MII_BMCR); |
| 252 | + reg_value |= BMCR_RESET; |
| 253 | + phy_write(phydev, MII_BMCR, reg_value); |
| 254 | + retry = MAX_RETRY; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 255 | + do { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 256 | + mdelay(10); |
| 257 | + reg_value = phy_read(phydev, MII_BMCR); |
| 258 | + retry--; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 259 | + if (0 == retry) { |
| 260 | + phydev_err(phydev, "Reset fail !\n"); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 261 | + return 0; |
| 262 | + } |
| 263 | + } while (reg_value & BMCR_RESET); |
| 264 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 265 | + phydev->dev_flags = PHY_STATE_INIT; |
| 266 | + |
| 267 | + phydev_info(phydev, "Phase1 initialize OK ! (%s)\n", EN8801S_DRIVER_VERSION); |
| 268 | + return 0; |
| 269 | +} |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 270 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 271 | +static int en8801s_phase2_init(struct phy_device *phydev) |
| 272 | +{ |
| 273 | + gephy_all_REG_LpiReg1Ch GPHY_RG_LPI_1C; |
| 274 | + gephy_all_REG_dev1Eh_reg324h GPHY_RG_1E_324; |
| 275 | + gephy_all_REG_dev1Eh_reg012h GPHY_RG_1E_012; |
| 276 | + gephy_all_REG_dev1Eh_reg017h GPHY_RG_1E_017; |
| 277 | + unsigned long pbus_data; |
| 278 | + u32 reg_value; |
| 279 | + int retry; |
| 280 | + struct mii_bus *mbus = phydev_mdio_bus(phydev); |
| 281 | + |
| 282 | + reg_value = (airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL) & 0xfffffffc) | 0x10 | (EN8801S_RX_POLARITY << 1) | EN8801S_TX_POLARITY; |
| 283 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL, reg_value); |
| 284 | + mdelay(10); |
| 285 | + reg_value &= 0xffffffef; |
| 286 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, EN8801S_RG_LTR_CTL, reg_value); |
| 287 | + |
| 288 | + pbus_data = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1690); |
| 289 | + pbus_data |= (1 << 31); |
| 290 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1690, pbus_data); |
| 291 | + |
| 292 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c000c00); |
| 293 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x10, 0xD801); |
| 294 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0, 0x9140); |
| 295 | + |
| 296 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0A14, 0x0003); |
| 297 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c000c00); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 298 | + /* Set FCM control */ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 299 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1404, 0x004b); |
| 300 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x140c, 0x0007); |
| 301 | + |
| 302 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x142c, 0x05050505); |
| 303 | + pbus_data = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1440); |
| 304 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1440, pbus_data & ~(1 << 11)); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 305 | + /* Set GPHY Perfomance*/ |
| 306 | + /* Token Ring */ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 307 | + airoha_tr_reg_write(mbus, RgAddr_PMA_01h, 0x6FB90A); |
| 308 | + airoha_tr_reg_write(mbus, RgAddr_PMA_18h, 0x0E2F00); |
| 309 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_06h, 0x2EBAEF); |
| 310 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_11h, 0x040001); |
| 311 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_03h, 0x000004); |
| 312 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_1Ch, 0x003210); |
| 313 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_14h, 0x00024A); |
| 314 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_0Ch, 0x00704D); |
| 315 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_0Dh, 0x02314F); |
| 316 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_10h, 0x005010); |
| 317 | + airoha_tr_reg_write(mbus, RgAddr_DSPF_0Fh, 0x003028); |
| 318 | + airoha_tr_reg_write(mbus, RgAddr_TR_26h, 0x444444); |
| 319 | + airoha_tr_reg_write(mbus, RgAddr_R1000DEC_15h, 0x0055A0); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 320 | + /* CL22 & CL45 */ |
| 321 | + phy_write(phydev, 0x1f, 0x03); |
| 322 | + GPHY_RG_LPI_1C.DATA = phy_read(phydev, RgAddr_LpiReg1Ch); |
| 323 | + GPHY_RG_LPI_1C.DataBitField.smi_deton_th = 0x0C; |
| 324 | + phy_write(phydev, RgAddr_LpiReg1Ch, GPHY_RG_LPI_1C.DATA); |
| 325 | + phy_write(phydev, 0x1f, 0x0); |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 326 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x122, 0xffff); |
| 327 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x234, 0x0180); |
| 328 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x238, 0x0120); |
| 329 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x120, 0x9014); |
| 330 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x239, 0x0117); |
| 331 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x14A, 0xEE20); |
| 332 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x19B, 0x0111); |
| 333 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1F, 0x268, 0x07F4); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 334 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 335 | + airoha_cl45_read(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x324, ®_value); |
| 336 | + GPHY_RG_1E_324.DATA = (u16)reg_value; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 337 | + GPHY_RG_1E_324.DataBitField.smi_det_deglitch_off = 0; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 338 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x324, (u32)GPHY_RG_1E_324.DATA); |
| 339 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x19E, 0xC2); |
| 340 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x013, 0x0); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 341 | + |
| 342 | + /* EFUSE */ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 343 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1C08, 0x40000040); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 344 | + retry = MAX_RETRY; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 345 | + while (0 != retry) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 346 | + mdelay(1); |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 347 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1C08); |
| 348 | + if ((reg_value & (1 << 30)) == 0) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 349 | + break; |
| 350 | + } |
| 351 | + retry--; |
| 352 | + } |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 353 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1C38); /* RAW#2 */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 354 | + GPHY_RG_1E_012.DataBitField.da_tx_i2mpb_a_tbt = reg_value & 0x03f; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 355 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x12, (u32)GPHY_RG_1E_012.DATA); |
| 356 | + GPHY_RG_1E_017.DataBitField.da_tx_i2mpb_b_tbt = (reg_value >> 8) & 0x03f; |
| 357 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x12, (u32)GPHY_RG_1E_017.DATA); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 358 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 359 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1C08, 0x40400040); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 360 | + retry = MAX_RETRY; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 361 | + while (0 != retry) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 362 | + mdelay(1); |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 363 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1C08); |
| 364 | + if ((reg_value & (1 << 30)) == 0) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 365 | + break; |
| 366 | + } |
| 367 | + retry--; |
| 368 | + } |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 369 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1C30); /* RAW#16 */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 370 | + GPHY_RG_1E_324.DataBitField.smi_det_deglitch_off = (reg_value >> 12) & 0x01; |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 371 | + airoha_cl45_write(mbus, EN8801S_MDIO_PHY_ID, 0x1E, 0x324, (u32)GPHY_RG_1E_324.DATA); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 372 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 373 | + en8801s_led_init(phydev); |
| 374 | + |
| 375 | + phydev_info(phydev, "Phase2 initialize OK !\n"); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 376 | + return 0; |
| 377 | +} |
| 378 | + |
| 379 | +static int en8801s_read_status(struct phy_device *phydev) |
| 380 | +{ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 381 | + int ret, preSpeed = phydev->speed; |
| 382 | + struct mii_bus *mbus = phydev_mdio_bus(phydev); |
| 383 | + u32 reg_value; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 384 | + |
| 385 | + ret = genphy_read_status(phydev); |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 386 | + if (LINK_DOWN == phydev->link) preSpeed = phydev->speed = 0; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 387 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 388 | + if (phydev->dev_flags == PHY_STATE_PROCESS) { |
| 389 | + en8801s_phy_process(phydev); |
| 390 | + phydev->dev_flags = PHY_STATE_DONE; |
| 391 | + } |
| 392 | + |
| 393 | + if ((preSpeed != phydev->speed) && (LINK_UP == phydev->link)) { |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 394 | + preSpeed = phydev->speed; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 395 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 396 | + if (phydev->dev_flags == PHY_STATE_INIT) { |
| 397 | + en8801s_phase2_init(phydev); |
| 398 | + phydev->dev_flags = PHY_STATE_PROCESS; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 399 | + } |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 400 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 401 | + if (preSpeed == SPEED_10) { |
| 402 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1694); |
| 403 | + reg_value |= (1 << 31); |
| 404 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1694, reg_value); |
| 405 | + phydev->dev_flags = PHY_STATE_PROCESS; |
| 406 | + } else { |
| 407 | + reg_value = airoha_pbus_read(mbus, EN8801S_PBUS_PHY_ID, 0x1694); |
| 408 | + reg_value &= ~(1 << 31); |
| 409 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1694, reg_value); |
| 410 | + phydev->dev_flags = PHY_STATE_PROCESS; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 411 | + } |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 412 | + |
| 413 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c000c00); |
| 414 | + if (SPEED_1000 == preSpeed) { |
| 415 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x10, 0xD801); |
| 416 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0, 0x9140); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 417 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 418 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0A14, 0x0003); |
| 419 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c000c00); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 420 | + mdelay(2); /* delay 2 ms */ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 421 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1404, 0x004b); |
| 422 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x140c, 0x0007); |
| 423 | + } else if (SPEED_100 == preSpeed) { |
| 424 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x10, 0xD401); |
| 425 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0, 0x9140); |
| 426 | + |
| 427 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0A14, 0x0007); |
| 428 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c11); |
| 429 | + mdelay(2); /* delay 2 ms */ |
| 430 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1404, 0x0027); |
| 431 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x140c, 0x0007); |
| 432 | + } else if (SPEED_10 == preSpeed) { |
| 433 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x10, 0xD001); |
| 434 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0, 0x9140); |
| 435 | + |
| 436 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0A14, 0x000b); |
| 437 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x0600, 0x0c11); |
| 438 | + mdelay(2); /* delay 2 ms */ |
| 439 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x1404, 0x0027); |
| 440 | + airoha_pbus_write(mbus, EN8801S_PBUS_PHY_ID, 0x140c, 0x0007); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 441 | + } |
| 442 | + } |
| 443 | + return ret; |
| 444 | +} |
| 445 | + |
| 446 | +static struct phy_driver Airoha_driver[] = { |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 447 | + { |
| 448 | + .phy_id = EN8801S_PHY_ID, |
| 449 | + .name = "Airoha EN8801S", |
| 450 | + .phy_id_mask = 0x0ffffff0, |
| 451 | + .features = PHY_GBIT_FEATURES, |
| 452 | + .config_init = en8801s_phase1_init, |
| 453 | + .config_aneg = genphy_config_aneg, |
| 454 | + .read_status = en8801s_read_status, |
| 455 | + .suspend = genphy_suspend, |
| 456 | + .resume = genphy_resume, |
| 457 | + } |
| 458 | +}; |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 459 | + |
| 460 | +module_phy_driver(Airoha_driver); |
| 461 | + |
| 462 | +static struct mdio_device_id __maybe_unused Airoha_tbl[] = { |
| 463 | + { EN8801S_PHY_ID, 0x0ffffff0 }, |
| 464 | + { } |
| 465 | +}; |
| 466 | + |
| 467 | +MODULE_DEVICE_TABLE(mdio, Airoha_tbl); |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 468 | Index: drivers/net/phy/en8801s.h |
| 469 | =================================================================== |
| 470 | --- /dev/null |
| 471 | +++ b/drivers/net/phy/en8801s.h |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 472 | @@ -0,0 +1,158 @@ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 473 | +// SPDX-License-Identifier: GPL-2.0 |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 474 | +/* FILE NAME: en8801s.h |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 475 | + * PURPOSE: |
| 476 | + * Define EN8801S driver function |
| 477 | + * |
| 478 | + * NOTES: |
| 479 | + * |
| 480 | + */ |
| 481 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 482 | +#ifndef __EN8801S_H |
| 483 | +#define __EN8801S_H |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 484 | + |
| 485 | +/* NAMING DECLARATIONS |
| 486 | + */ |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 487 | +#define EN8801S_DRIVER_VERSION "1.1.0" |
| 488 | + |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 489 | +#define PHY_ADDRESS_RANGE 0x18 |
| 490 | +#define EN8801S_PBUS_DEFAULT_ID 0x1e |
| 491 | +#define EN8801S_MDIO_PHY_ID 0x18 /* Range PHY_ADDRESS_RANGE .. 0x1e */ |
| 492 | +#define EN8801S_PBUS_PHY_ID (EN8801S_MDIO_PHY_ID + 1) |
| 493 | + |
| 494 | +#define EN8801S_RG_ETHER_PHY_OUI 0x19a4 |
| 495 | +#define EN8801S_RG_SMI_ADDR 0x19a8 |
| 496 | +#define EN8801S_RG_BUCK_CTL 0x1a20 |
| 497 | +#define EN8801S_RG_LTR_CTL 0x0cf8 |
| 498 | + |
| 499 | +#define EN8801S_PBUS_OUI 0x17a5 |
| 500 | +#define EN8801S_PHY_ID1 0x03a2 |
| 501 | +#define EN8801S_PHY_ID2 0x9461 |
| 502 | +#define EN8801S_PHY_ID (unsigned long)((EN8801S_PHY_ID1 << 16) | EN8801S_PHY_ID2) |
| 503 | + |
| 504 | +#define DEV1E_REG013_VALUE 0 |
| 505 | +#define DEV1E_REG19E_VALUE 0xC2 |
| 506 | +#define DEV1E_REG324_VALUE 0x200 |
| 507 | + |
| 508 | +#define TRUE 1 |
| 509 | +#define FALSE 0 |
| 510 | +#define LINK_UP 1 |
| 511 | +#define LINK_DOWN 0 |
| 512 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 513 | +//#define TEST_BOARD |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 514 | +#if defined(TEST_BOARD) |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 515 | +/* SFP sample for verification */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 516 | +#define EN8801S_TX_POLARITY 1 |
| 517 | +#define EN8801S_RX_POLARITY 0 |
| 518 | +#else |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 519 | +/* chip on board */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 520 | +#define EN8801S_TX_POLARITY 0 |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 521 | +#define EN8801S_RX_POLARITY 1 /* The pin default assignment is set to 1 */ |
developer | 7e3c5b7 | 2022-02-21 21:38:33 +0800 | [diff] [blame] | 522 | +#endif |
| 523 | + |
| 524 | +#define MAX_RETRY 5 |
| 525 | +#define MAX_OUI_CHECK 2 |
| 526 | +/* CL45 MDIO control */ |
| 527 | +#define MII_MMD_ACC_CTL_REG 0x0d |
| 528 | +#define MII_MMD_ADDR_DATA_REG 0x0e |
| 529 | +#define MMD_OP_MODE_DATA BIT(14) |
| 530 | + |
| 531 | +#define MAX_TRG_COUNTER 5 |
| 532 | + |
| 533 | +/* CL22 Reg Support Page Select */ |
| 534 | +#define RgAddr_Reg1Fh 0x1f |
| 535 | +#define CL22_Page_Reg 0x0000 |
| 536 | +#define CL22_Page_ExtReg 0x0001 |
| 537 | +#define CL22_Page_MiscReg 0x0002 |
| 538 | +#define CL22_Page_LpiReg 0x0003 |
| 539 | +#define CL22_Page_tReg 0x02A3 |
| 540 | +#define CL22_Page_TrReg 0x52B5 |
| 541 | + |
| 542 | +/* CL45 Reg Support DEVID */ |
| 543 | +#define DEVID_03 0x03 |
| 544 | +#define DEVID_07 0x07 |
| 545 | +#define DEVID_1E 0x1E |
| 546 | +#define DEVID_1F 0x1F |
| 547 | + |
| 548 | +/* TokenRing Reg Access */ |
| 549 | +#define TrReg_PKT_XMT_STA 0x8000 |
| 550 | +#define TrReg_WR 0x8000 |
| 551 | +#define TrReg_RD 0xA000 |
| 552 | + |
| 553 | +#define RgAddr_LpiReg1Ch 0x1c |
| 554 | +#define RgAddr_PMA_01h 0x0f82 |
| 555 | +#define RgAddr_PMA_18h 0x0fb0 |
| 556 | +#define RgAddr_DSPF_03h 0x1686 |
| 557 | +#define RgAddr_DSPF_06h 0x168c |
| 558 | +#define RgAddr_DSPF_0Ch 0x1698 |
| 559 | +#define RgAddr_DSPF_0Dh 0x169a |
| 560 | +#define RgAddr_DSPF_0Fh 0x169e |
| 561 | +#define RgAddr_DSPF_10h 0x16a0 |
| 562 | +#define RgAddr_DSPF_11h 0x16a2 |
| 563 | +#define RgAddr_DSPF_14h 0x16a8 |
| 564 | +#define RgAddr_DSPF_1Ch 0x16b8 |
| 565 | +#define RgAddr_TR_26h 0x0ecc |
| 566 | +#define RgAddr_R1000DEC_15h 0x03aa |
| 567 | + |
| 568 | +/* DATA TYPE DECLARATIONS |
| 569 | + */ |
| 570 | +typedef struct |
| 571 | +{ |
| 572 | + u16 DATA_Lo; |
| 573 | + u16 DATA_Hi; |
| 574 | +}TR_DATA_T; |
| 575 | + |
| 576 | +typedef union |
| 577 | +{ |
| 578 | + struct |
| 579 | + { |
| 580 | + /* b[15:00] */ |
| 581 | + u16 smi_deton_wt : 3; |
| 582 | + u16 smi_det_mdi_inv : 1; |
| 583 | + u16 smi_detoff_wt : 3; |
| 584 | + u16 smi_sigdet_debouncing_en : 1; |
| 585 | + u16 smi_deton_th : 6; |
| 586 | + u16 rsv_14 : 2; |
| 587 | + } DataBitField; |
| 588 | + u16 DATA; |
| 589 | +} gephy_all_REG_LpiReg1Ch, *Pgephy_all_REG_LpiReg1Ch; |
| 590 | + |
| 591 | +typedef union |
| 592 | +{ |
| 593 | + struct |
| 594 | + { |
| 595 | + /* b[15:00] */ |
| 596 | + u16 rg_smi_detcnt_max : 6; |
| 597 | + u16 rsv_6 : 2; |
| 598 | + u16 rg_smi_det_max_en : 1; |
| 599 | + u16 smi_det_deglitch_off : 1; |
| 600 | + u16 rsv_10 : 6; |
| 601 | + } DataBitField; |
| 602 | + u16 DATA; |
| 603 | +} gephy_all_REG_dev1Eh_reg324h, *Pgephy_all_REG_dev1Eh_reg324h; |
| 604 | + |
| 605 | +typedef union |
| 606 | +{ |
| 607 | + struct |
| 608 | + { |
| 609 | + /* b[15:00] */ |
| 610 | + u16 da_tx_i2mpb_a_tbt : 6; |
| 611 | + u16 rsv_6 : 4; |
| 612 | + u16 da_tx_i2mpb_a_gbe : 6; |
| 613 | + } DataBitField; |
| 614 | + u16 DATA; |
| 615 | +} gephy_all_REG_dev1Eh_reg012h, *Pgephy_all_REG_dev1Eh_reg012h; |
| 616 | + |
| 617 | +typedef union |
| 618 | +{ |
| 619 | + struct |
| 620 | + { |
| 621 | + /* b[15:00] */ |
| 622 | + u16 da_tx_i2mpb_b_tbt : 6; |
| 623 | + u16 rsv_6 : 2; |
| 624 | + u16 da_tx_i2mpb_b_gbe : 6; |
| 625 | + u16 rsv_14 : 2; |
| 626 | + } DataBitField; |
| 627 | + u16 DATA; |
| 628 | +} gephy_all_REG_dev1Eh_reg017h, *Pgephy_all_REG_dev1Eh_reg017h; |
| 629 | + |
developer | 87e071e | 2022-08-04 16:26:17 +0800 | [diff] [blame] | 630 | +#endif /* End of __EN8801S_H */ |