blob: 83a7ccd98197947a8dcb5e9af12fa947ba55b8a4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Dave Liue732e9c2006-11-03 12:11:15 -06002/*
Kumar Gala09036992011-01-19 03:36:40 -06003 * Copyright (C) 2005, 2011 Freescale Semiconductor, Inc.
Dave Liue732e9c2006-11-03 12:11:15 -06004 *
5 * Author: Shlomi Gridish <gridish@freescale.com>
6 *
7 * Description: UCC ethernet driver -- PHY handling
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +01008 * Driver for UEC on QE
9 * Based on 8260_io/fcc_enet.c
Dave Liue732e9c2006-11-03 12:11:15 -060010 */
11#ifndef __UEC_PHY_H__
12#define __UEC_PHY_H__
13
14#define MII_end ((u32)-2)
15#define MII_read ((u32)-1)
16
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010017#define MIIMIND_BUSY 0x00000001
18#define MIIMIND_NOTVALID 0x00000004
Dave Liue732e9c2006-11-03 12:11:15 -060019
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010020#define UGETH_AN_TIMEOUT 2000
Dave Liue732e9c2006-11-03 12:11:15 -060021
Dave Liue732e9c2006-11-03 12:11:15 -060022/* Cicada Extended Control Register 1 */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010023#define MII_CIS8201_EXT_CON1 0x17
Dave Liue732e9c2006-11-03 12:11:15 -060024#define MII_CIS8201_EXTCON1_INIT 0x0000
25
26/* Cicada Interrupt Mask Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010027#define MII_CIS8201_IMASK 0x19
28#define MII_CIS8201_IMASK_IEN 0x8000
29#define MII_CIS8201_IMASK_SPEED 0x4000
30#define MII_CIS8201_IMASK_LINK 0x2000
Dave Liue732e9c2006-11-03 12:11:15 -060031#define MII_CIS8201_IMASK_DUPLEX 0x1000
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010032#define MII_CIS8201_IMASK_MASK 0xf000
Dave Liue732e9c2006-11-03 12:11:15 -060033
34/* Cicada Interrupt Status Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010035#define MII_CIS8201_ISTAT 0x1a
Dave Liue732e9c2006-11-03 12:11:15 -060036#define MII_CIS8201_ISTAT_STATUS 0x8000
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010037#define MII_CIS8201_ISTAT_SPEED 0x4000
38#define MII_CIS8201_ISTAT_LINK 0x2000
Dave Liue732e9c2006-11-03 12:11:15 -060039#define MII_CIS8201_ISTAT_DUPLEX 0x1000
40
41/* Cicada Auxiliary Control/Status Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010042#define MII_CIS8201_AUX_CONSTAT 0x1c
Dave Liue732e9c2006-11-03 12:11:15 -060043#define MII_CIS8201_AUXCONSTAT_INIT 0x0004
44#define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
45#define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
46#define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
47#define MII_CIS8201_AUXCONSTAT_100 0x0008
48
49/* 88E1011 PHY Status Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010050#define MII_M1011_PHY_SPEC_STATUS 0x11
51#define MII_M1011_PHY_SPEC_STATUS_1000 0x8000
52#define MII_M1011_PHY_SPEC_STATUS_100 0x4000
53#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
54#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
55#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
56#define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400
Dave Liue732e9c2006-11-03 12:11:15 -060057
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010058#define MII_M1011_IEVENT 0x13
59#define MII_M1011_IEVENT_CLEAR 0x0000
Dave Liue732e9c2006-11-03 12:11:15 -060060
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010061#define MII_M1011_IMASK 0x12
62#define MII_M1011_IMASK_INIT 0x6400
63#define MII_M1011_IMASK_CLEAR 0x0000
Dave Liue732e9c2006-11-03 12:11:15 -060064
Haiying Wang024e1e72008-09-24 11:42:12 -050065/* 88E1111 PHY Register */
66#define MII_M1111_PHY_EXT_CR 0x14
67#define MII_M1111_RX_DELAY 0x80
68#define MII_M1111_TX_DELAY 0x2
69#define MII_M1111_PHY_EXT_SR 0x1b
70#define MII_M1111_HWCFG_MODE_MASK 0xf
71#define MII_M1111_HWCFG_MODE_RGMII 0xb
72
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010073#define MII_DM9161_SCR 0x10
74#define MII_DM9161_SCR_INIT 0x0610
Dave Liue732e9c2006-11-03 12:11:15 -060075#define MII_DM9161_SCR_RMII_INIT 0x0710
76
77/* DM9161 Specified Configuration and Status Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010078#define MII_DM9161_SCSR 0x11
79#define MII_DM9161_SCSR_100F 0x8000
80#define MII_DM9161_SCSR_100H 0x4000
81#define MII_DM9161_SCSR_10F 0x2000
82#define MII_DM9161_SCSR_10H 0x1000
Dave Liue732e9c2006-11-03 12:11:15 -060083
84/* DM9161 Interrupt Register */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010085#define MII_DM9161_INTR 0x15
86#define MII_DM9161_INTR_PEND 0x8000
87#define MII_DM9161_INTR_DPLX_MASK 0x0800
88#define MII_DM9161_INTR_SPD_MASK 0x0400
89#define MII_DM9161_INTR_LINK_MASK 0x0200
90#define MII_DM9161_INTR_MASK 0x0100
91#define MII_DM9161_INTR_DPLX_CHANGE 0x0010
92#define MII_DM9161_INTR_SPD_CHANGE 0x0008
93#define MII_DM9161_INTR_LINK_CHANGE 0x0004
94#define MII_DM9161_INTR_INIT 0x0000
95#define MII_DM9161_INTR_STOP \
Dave Liue732e9c2006-11-03 12:11:15 -060096(MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
97 | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
98
99/* DM9161 10BT Configuration/Status */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100100#define MII_DM9161_10BTCSR 0x12
101#define MII_DM9161_10BTCSR_INIT 0x7800
Dave Liue732e9c2006-11-03 12:11:15 -0600102
103#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100104 SUPPORTED_10baseT_Full | \
105 SUPPORTED_100baseT_Half | \
106 SUPPORTED_100baseT_Full | \
107 SUPPORTED_Autoneg | \
108 SUPPORTED_TP | \
109 SUPPORTED_MII)
Dave Liue732e9c2006-11-03 12:11:15 -0600110
111#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100112 SUPPORTED_1000baseT_Half | \
113 SUPPORTED_1000baseT_Full)
Dave Liue732e9c2006-11-03 12:11:15 -0600114
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100115#define MII_READ_COMMAND 0x00000001
Dave Liue732e9c2006-11-03 12:11:15 -0600116
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100117#define MII_INTERRUPT_DISABLED 0x0
118#define MII_INTERRUPT_ENABLED 0x1
Dave Liue732e9c2006-11-03 12:11:15 -0600119
120#define SPEED_10 10
121#define SPEED_100 100
122#define SPEED_1000 1000
123
124/* Duplex, half or full. */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100125#define DUPLEX_HALF 0x00
126#define DUPLEX_FULL 0x01
Dave Liue732e9c2006-11-03 12:11:15 -0600127
128/* Indicates what features are supported by the interface. */
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100129#define SUPPORTED_10baseT_Half (1 << 0)
130#define SUPPORTED_10baseT_Full (1 << 1)
131#define SUPPORTED_100baseT_Half (1 << 2)
132#define SUPPORTED_100baseT_Full (1 << 3)
133#define SUPPORTED_1000baseT_Half (1 << 4)
134#define SUPPORTED_1000baseT_Full (1 << 5)
135#define SUPPORTED_Autoneg (1 << 6)
136#define SUPPORTED_TP (1 << 7)
137#define SUPPORTED_AUI (1 << 8)
138#define SUPPORTED_MII (1 << 9)
139#define SUPPORTED_FIBRE (1 << 10)
140#define SUPPORTED_BNC (1 << 11)
141#define SUPPORTED_10000baseT_Full (1 << 12)
Dave Liue732e9c2006-11-03 12:11:15 -0600142
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100143#define ADVERTISED_10baseT_Half (1 << 0)
144#define ADVERTISED_10baseT_Full (1 << 1)
145#define ADVERTISED_100baseT_Half (1 << 2)
146#define ADVERTISED_100baseT_Full (1 << 3)
147#define ADVERTISED_1000baseT_Half (1 << 4)
148#define ADVERTISED_1000baseT_Full (1 << 5)
149#define ADVERTISED_Autoneg (1 << 6)
150#define ADVERTISED_TP (1 << 7)
151#define ADVERTISED_AUI (1 << 8)
152#define ADVERTISED_MII (1 << 9)
153#define ADVERTISED_FIBRE (1 << 10)
154#define ADVERTISED_BNC (1 << 11)
155#define ADVERTISED_10000baseT_Full (1 << 12)
Dave Liue732e9c2006-11-03 12:11:15 -0600156
Dave Liue732e9c2006-11-03 12:11:15 -0600157/* Taken from mii_if_info and sungem_phy.h */
158struct uec_mii_info {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100159 /* Information about the PHY type */
160 /* And management functions */
161 struct phy_info *phyinfo;
Dave Liue732e9c2006-11-03 12:11:15 -0600162
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100163 struct eth_device *dev;
Dave Liue732e9c2006-11-03 12:11:15 -0600164
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100165 /* forced speed & duplex (no autoneg)
166 * partner speed & duplex & pause (autoneg)
167 */
168 int speed;
169 int duplex;
170 int pause;
Dave Liue732e9c2006-11-03 12:11:15 -0600171
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100172 /* The most recently read link state */
173 int link;
Dave Liue732e9c2006-11-03 12:11:15 -0600174
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100175 /* Enabled Interrupts */
176 u32 interrupts;
Dave Liue732e9c2006-11-03 12:11:15 -0600177
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100178 u32 advertising;
179 int autoneg;
180 int mii_id;
Dave Liue732e9c2006-11-03 12:11:15 -0600181
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100182 /* private data pointer */
183 /* For use by PHYs to maintain extra state */
184 void *priv;
Dave Liue732e9c2006-11-03 12:11:15 -0600185
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100186 /* Provided by ethernet driver */
187 int (*mdio_read) (struct eth_device * dev, int mii_id, int reg);
188 void (*mdio_write) (struct eth_device * dev, int mii_id, int reg,
189 int val);
Dave Liue732e9c2006-11-03 12:11:15 -0600190};
191
192/* struct phy_info: a structure which defines attributes for a PHY
193 *
194 * id will contain a number which represents the PHY. During
195 * startup, the driver will poll the PHY to find out what its
196 * UID--as defined by registers 2 and 3--is. The 32-bit result
197 * gotten from the PHY will be ANDed with phy_id_mask to
198 * discard any bits which may change based on revision numbers
199 * unimportant to functionality
200 *
201 * There are 6 commands which take a ugeth_mii_info structure.
202 * Each PHY must declare config_aneg, and read_status.
203 */
204struct phy_info {
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100205 u32 phy_id;
206 char *name;
207 unsigned int phy_id_mask;
208 u32 features;
Dave Liue732e9c2006-11-03 12:11:15 -0600209
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100210 /* Called to initialize the PHY */
211 int (*init) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600212
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100213 /* Called to suspend the PHY for power */
214 int (*suspend) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600215
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100216 /* Reconfigures autonegotiation (or disables it) */
217 int (*config_aneg) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600218
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100219 /* Determines the negotiated speed and duplex */
220 int (*read_status) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600221
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100222 /* Clears any pending interrupts */
223 int (*ack_interrupt) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600224
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100225 /* Enables or disables interrupts */
226 int (*config_intr) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600227
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100228 /* Clears up any memory if needed */
229 void (*close) (struct uec_mii_info * mii_info);
Dave Liue732e9c2006-11-03 12:11:15 -0600230};
231
Andy Flemingee0e9172007-08-14 00:14:25 -0500232struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info);
233void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum,
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100234 int value);
Andy Flemingee0e9172007-08-14 00:14:25 -0500235int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum);
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100236void mii_clear_phy_interrupt (struct uec_mii_info *mii_info);
237void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
238 u32 interrupts);
Dave Liue732e9c2006-11-03 12:11:15 -0600239#endif /* __UEC_PHY_H__ */