Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 2 | /* |
Kumar Gala | 0903699 | 2011-01-19 03:36:40 -0600 | [diff] [blame] | 3 | * Copyright (C) 2005, 2011 Freescale Semiconductor, Inc. |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 4 | * |
| 5 | * Author: Shlomi Gridish <gridish@freescale.com> |
| 6 | * |
| 7 | * Description: UCC ethernet driver -- PHY handling |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 8 | * Driver for UEC on QE |
| 9 | * Based on 8260_io/fcc_enet.c |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 10 | */ |
| 11 | #ifndef __UEC_PHY_H__ |
| 12 | #define __UEC_PHY_H__ |
| 13 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 14 | #include <linux/bitops.h> |
| 15 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 16 | #define MII_end ((u32)-2) |
| 17 | #define MII_read ((u32)-1) |
| 18 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 19 | #define MIIMIND_BUSY 0x00000001 |
| 20 | #define MIIMIND_NOTVALID 0x00000004 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 21 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 22 | #define UGETH_AN_TIMEOUT 2000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 23 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 24 | /* Cicada Extended Control Register 1 */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 25 | #define MII_CIS8201_EXT_CON1 0x17 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 26 | #define MII_CIS8201_EXTCON1_INIT 0x0000 |
| 27 | |
| 28 | /* Cicada Interrupt Mask Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 29 | #define MII_CIS8201_IMASK 0x19 |
| 30 | #define MII_CIS8201_IMASK_IEN 0x8000 |
| 31 | #define MII_CIS8201_IMASK_SPEED 0x4000 |
| 32 | #define MII_CIS8201_IMASK_LINK 0x2000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 33 | #define MII_CIS8201_IMASK_DUPLEX 0x1000 |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 34 | #define MII_CIS8201_IMASK_MASK 0xf000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 35 | |
| 36 | /* Cicada Interrupt Status Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 37 | #define MII_CIS8201_ISTAT 0x1a |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 38 | #define MII_CIS8201_ISTAT_STATUS 0x8000 |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 39 | #define MII_CIS8201_ISTAT_SPEED 0x4000 |
| 40 | #define MII_CIS8201_ISTAT_LINK 0x2000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 41 | #define MII_CIS8201_ISTAT_DUPLEX 0x1000 |
| 42 | |
| 43 | /* Cicada Auxiliary Control/Status Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 44 | #define MII_CIS8201_AUX_CONSTAT 0x1c |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 45 | #define MII_CIS8201_AUXCONSTAT_INIT 0x0004 |
| 46 | #define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020 |
| 47 | #define MII_CIS8201_AUXCONSTAT_SPEED 0x0018 |
| 48 | #define MII_CIS8201_AUXCONSTAT_GBIT 0x0010 |
| 49 | #define MII_CIS8201_AUXCONSTAT_100 0x0008 |
| 50 | |
| 51 | /* 88E1011 PHY Status Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 52 | #define MII_M1011_PHY_SPEC_STATUS 0x11 |
| 53 | #define MII_M1011_PHY_SPEC_STATUS_1000 0x8000 |
| 54 | #define MII_M1011_PHY_SPEC_STATUS_100 0x4000 |
| 55 | #define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000 |
| 56 | #define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000 |
| 57 | #define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800 |
| 58 | #define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 59 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 60 | #define MII_M1011_IEVENT 0x13 |
| 61 | #define MII_M1011_IEVENT_CLEAR 0x0000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 62 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 63 | #define MII_M1011_IMASK 0x12 |
| 64 | #define MII_M1011_IMASK_INIT 0x6400 |
| 65 | #define MII_M1011_IMASK_CLEAR 0x0000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 66 | |
Haiying Wang | 024e1e7 | 2008-09-24 11:42:12 -0500 | [diff] [blame] | 67 | /* 88E1111 PHY Register */ |
| 68 | #define MII_M1111_PHY_EXT_CR 0x14 |
| 69 | #define MII_M1111_RX_DELAY 0x80 |
| 70 | #define MII_M1111_TX_DELAY 0x2 |
| 71 | #define MII_M1111_PHY_EXT_SR 0x1b |
| 72 | #define MII_M1111_HWCFG_MODE_MASK 0xf |
| 73 | #define MII_M1111_HWCFG_MODE_RGMII 0xb |
| 74 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 75 | #define MII_DM9161_SCR 0x10 |
| 76 | #define MII_DM9161_SCR_INIT 0x0610 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 77 | #define MII_DM9161_SCR_RMII_INIT 0x0710 |
| 78 | |
| 79 | /* DM9161 Specified Configuration and Status Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 80 | #define MII_DM9161_SCSR 0x11 |
| 81 | #define MII_DM9161_SCSR_100F 0x8000 |
| 82 | #define MII_DM9161_SCSR_100H 0x4000 |
| 83 | #define MII_DM9161_SCSR_10F 0x2000 |
| 84 | #define MII_DM9161_SCSR_10H 0x1000 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 85 | |
| 86 | /* DM9161 Interrupt Register */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 87 | #define MII_DM9161_INTR 0x15 |
| 88 | #define MII_DM9161_INTR_PEND 0x8000 |
| 89 | #define MII_DM9161_INTR_DPLX_MASK 0x0800 |
| 90 | #define MII_DM9161_INTR_SPD_MASK 0x0400 |
| 91 | #define MII_DM9161_INTR_LINK_MASK 0x0200 |
| 92 | #define MII_DM9161_INTR_MASK 0x0100 |
| 93 | #define MII_DM9161_INTR_DPLX_CHANGE 0x0010 |
| 94 | #define MII_DM9161_INTR_SPD_CHANGE 0x0008 |
| 95 | #define MII_DM9161_INTR_LINK_CHANGE 0x0004 |
| 96 | #define MII_DM9161_INTR_INIT 0x0000 |
| 97 | #define MII_DM9161_INTR_STOP \ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 98 | (MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK | \ |
| 99 | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 100 | |
| 101 | /* DM9161 10BT Configuration/Status */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 102 | #define MII_DM9161_10BTCSR 0x12 |
| 103 | #define MII_DM9161_10BTCSR_INIT 0x7800 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 104 | |
| 105 | #define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 106 | SUPPORTED_10baseT_Full | \ |
| 107 | SUPPORTED_100baseT_Half | \ |
| 108 | SUPPORTED_100baseT_Full | \ |
| 109 | SUPPORTED_Autoneg | \ |
| 110 | SUPPORTED_TP | \ |
| 111 | SUPPORTED_MII) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 112 | |
| 113 | #define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 114 | SUPPORTED_1000baseT_Half | \ |
| 115 | SUPPORTED_1000baseT_Full) |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 116 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 117 | #define MII_READ_COMMAND 0x00000001 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 118 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 119 | #define MII_INTERRUPT_DISABLED 0x0 |
| 120 | #define MII_INTERRUPT_ENABLED 0x1 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 121 | |
| 122 | #define SPEED_10 10 |
| 123 | #define SPEED_100 100 |
| 124 | #define SPEED_1000 1000 |
| 125 | |
| 126 | /* Duplex, half or full. */ |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 127 | #define DUPLEX_HALF 0x00 |
| 128 | #define DUPLEX_FULL 0x01 |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 129 | |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 130 | /* Taken from mii_if_info and sungem_phy.h */ |
| 131 | struct uec_mii_info { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 132 | /* Information about the PHY type */ |
| 133 | /* And management functions */ |
| 134 | struct phy_info *phyinfo; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 135 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 136 | struct eth_device *dev; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 137 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 138 | /* forced speed & duplex (no autoneg) |
| 139 | * partner speed & duplex & pause (autoneg) |
| 140 | */ |
| 141 | int speed; |
| 142 | int duplex; |
| 143 | int pause; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 144 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 145 | /* The most recently read link state */ |
| 146 | int link; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 147 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 148 | /* Enabled Interrupts */ |
| 149 | u32 interrupts; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 150 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 151 | u32 advertising; |
| 152 | int autoneg; |
| 153 | int mii_id; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 154 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 155 | /* private data pointer */ |
| 156 | /* For use by PHYs to maintain extra state */ |
| 157 | void *priv; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 158 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 159 | /* Provided by ethernet driver */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 160 | int (*mdio_read)(struct eth_device *dev, int mii_id, int reg); |
| 161 | void (*mdio_write)(struct eth_device *dev, int mii_id, int reg, |
| 162 | int val); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | /* struct phy_info: a structure which defines attributes for a PHY |
| 166 | * |
| 167 | * id will contain a number which represents the PHY. During |
| 168 | * startup, the driver will poll the PHY to find out what its |
| 169 | * UID--as defined by registers 2 and 3--is. The 32-bit result |
| 170 | * gotten from the PHY will be ANDed with phy_id_mask to |
| 171 | * discard any bits which may change based on revision numbers |
| 172 | * unimportant to functionality |
| 173 | * |
| 174 | * There are 6 commands which take a ugeth_mii_info structure. |
| 175 | * Each PHY must declare config_aneg, and read_status. |
| 176 | */ |
| 177 | struct phy_info { |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 178 | u32 phy_id; |
| 179 | char *name; |
| 180 | unsigned int phy_id_mask; |
| 181 | u32 features; |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 182 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 183 | /* Called to initialize the PHY */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 184 | int (*init)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 185 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 186 | /* Called to suspend the PHY for power */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 187 | int (*suspend)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 188 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 189 | /* Reconfigures autonegotiation (or disables it) */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 190 | int (*config_aneg)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 191 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 192 | /* Determines the negotiated speed and duplex */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 193 | int (*read_status)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 194 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 195 | /* Clears any pending interrupts */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 196 | int (*ack_interrupt)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 197 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 198 | /* Enables or disables interrupts */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 199 | int (*config_intr)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 200 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 201 | /* Clears up any memory if needed */ |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 202 | void (*close)(struct uec_mii_info *mii_info); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 203 | }; |
| 204 | |
Heiko Schocher | baf84a9 | 2020-05-25 07:27:26 +0200 | [diff] [blame] | 205 | struct phy_info *uec_get_phy_info(struct uec_mii_info *mii_info); |
| 206 | void uec_write_phy_reg(struct eth_device *dev, int mii_id, int regnum, |
| 207 | int value); |
| 208 | int uec_read_phy_reg(struct eth_device *dev, int mii_id, int regnum); |
| 209 | void mii_clear_phy_interrupt(struct uec_mii_info *mii_info); |
| 210 | void mii_configure_phy_interrupt(struct uec_mii_info *mii_info, |
| 211 | u32 interrupts); |
| 212 | void change_phy_interface_mode(struct eth_device *dev, |
| 213 | phy_interface_t type, int speed); |
Dave Liu | e732e9c | 2006-11-03 12:11:15 -0600 | [diff] [blame] | 214 | #endif /* __UEC_PHY_H__ */ |