blob: f924b2a14dd1fb956d611bf8274d045f061d98b2 [file] [log] [blame]
Dave Liu7737d5c2006-11-03 12:11:15 -06001/*
Kumar Gala2b21ec92011-01-19 03:36:40 -06002 * Copyright (C) 2005, 2011 Freescale Semiconductor, Inc.
Dave Liu7737d5c2006-11-03 12:11:15 -06003 *
4 * Author: Shlomi Gridish <gridish@freescale.com>
5 *
6 * Description: UCC ethernet driver -- PHY handling
Wolfgang Denkdd520bf2006-11-30 18:02:20 +01007 * Driver for UEC on QE
8 * Based on 8260_io/fcc_enet.c
Dave Liu7737d5c2006-11-03 12:11:15 -06009 *
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010010 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
Dave Liu7737d5c2006-11-03 12:11:15 -060012 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16#ifndef __UEC_PHY_H__
17#define __UEC_PHY_H__
18
19#define MII_end ((u32)-2)
20#define MII_read ((u32)-1)
21
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010022#define MIIMIND_BUSY 0x00000001
23#define MIIMIND_NOTVALID 0x00000004
Dave Liu7737d5c2006-11-03 12:11:15 -060024
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010025#define UGETH_AN_TIMEOUT 2000
Dave Liu7737d5c2006-11-03 12:11:15 -060026
Dave Liu7737d5c2006-11-03 12:11:15 -060027/* Cicada Extended Control Register 1 */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010028#define MII_CIS8201_EXT_CON1 0x17
Dave Liu7737d5c2006-11-03 12:11:15 -060029#define MII_CIS8201_EXTCON1_INIT 0x0000
30
31/* Cicada Interrupt Mask Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010032#define MII_CIS8201_IMASK 0x19
33#define MII_CIS8201_IMASK_IEN 0x8000
34#define MII_CIS8201_IMASK_SPEED 0x4000
35#define MII_CIS8201_IMASK_LINK 0x2000
Dave Liu7737d5c2006-11-03 12:11:15 -060036#define MII_CIS8201_IMASK_DUPLEX 0x1000
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010037#define MII_CIS8201_IMASK_MASK 0xf000
Dave Liu7737d5c2006-11-03 12:11:15 -060038
39/* Cicada Interrupt Status Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010040#define MII_CIS8201_ISTAT 0x1a
Dave Liu7737d5c2006-11-03 12:11:15 -060041#define MII_CIS8201_ISTAT_STATUS 0x8000
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010042#define MII_CIS8201_ISTAT_SPEED 0x4000
43#define MII_CIS8201_ISTAT_LINK 0x2000
Dave Liu7737d5c2006-11-03 12:11:15 -060044#define MII_CIS8201_ISTAT_DUPLEX 0x1000
45
46/* Cicada Auxiliary Control/Status Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010047#define MII_CIS8201_AUX_CONSTAT 0x1c
Dave Liu7737d5c2006-11-03 12:11:15 -060048#define MII_CIS8201_AUXCONSTAT_INIT 0x0004
49#define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
50#define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
51#define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
52#define MII_CIS8201_AUXCONSTAT_100 0x0008
53
54/* 88E1011 PHY Status Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010055#define MII_M1011_PHY_SPEC_STATUS 0x11
56#define MII_M1011_PHY_SPEC_STATUS_1000 0x8000
57#define MII_M1011_PHY_SPEC_STATUS_100 0x4000
58#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
59#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
60#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
61#define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400
Dave Liu7737d5c2006-11-03 12:11:15 -060062
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010063#define MII_M1011_IEVENT 0x13
64#define MII_M1011_IEVENT_CLEAR 0x0000
Dave Liu7737d5c2006-11-03 12:11:15 -060065
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010066#define MII_M1011_IMASK 0x12
67#define MII_M1011_IMASK_INIT 0x6400
68#define MII_M1011_IMASK_CLEAR 0x0000
Dave Liu7737d5c2006-11-03 12:11:15 -060069
Haiying Wang41410ee2008-09-24 11:42:12 -050070/* 88E1111 PHY Register */
71#define MII_M1111_PHY_EXT_CR 0x14
72#define MII_M1111_RX_DELAY 0x80
73#define MII_M1111_TX_DELAY 0x2
74#define MII_M1111_PHY_EXT_SR 0x1b
75#define MII_M1111_HWCFG_MODE_MASK 0xf
76#define MII_M1111_HWCFG_MODE_RGMII 0xb
77
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010078#define MII_DM9161_SCR 0x10
79#define MII_DM9161_SCR_INIT 0x0610
Dave Liu7737d5c2006-11-03 12:11:15 -060080#define MII_DM9161_SCR_RMII_INIT 0x0710
81
82/* DM9161 Specified Configuration and Status Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010083#define MII_DM9161_SCSR 0x11
84#define MII_DM9161_SCSR_100F 0x8000
85#define MII_DM9161_SCSR_100H 0x4000
86#define MII_DM9161_SCSR_10F 0x2000
87#define MII_DM9161_SCSR_10H 0x1000
Dave Liu7737d5c2006-11-03 12:11:15 -060088
89/* DM9161 Interrupt Register */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010090#define MII_DM9161_INTR 0x15
91#define MII_DM9161_INTR_PEND 0x8000
92#define MII_DM9161_INTR_DPLX_MASK 0x0800
93#define MII_DM9161_INTR_SPD_MASK 0x0400
94#define MII_DM9161_INTR_LINK_MASK 0x0200
95#define MII_DM9161_INTR_MASK 0x0100
96#define MII_DM9161_INTR_DPLX_CHANGE 0x0010
97#define MII_DM9161_INTR_SPD_CHANGE 0x0008
98#define MII_DM9161_INTR_LINK_CHANGE 0x0004
99#define MII_DM9161_INTR_INIT 0x0000
100#define MII_DM9161_INTR_STOP \
Dave Liu7737d5c2006-11-03 12:11:15 -0600101(MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
102 | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
103
104/* DM9161 10BT Configuration/Status */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100105#define MII_DM9161_10BTCSR 0x12
106#define MII_DM9161_10BTCSR_INIT 0x7800
Dave Liu7737d5c2006-11-03 12:11:15 -0600107
108#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100109 SUPPORTED_10baseT_Full | \
110 SUPPORTED_100baseT_Half | \
111 SUPPORTED_100baseT_Full | \
112 SUPPORTED_Autoneg | \
113 SUPPORTED_TP | \
114 SUPPORTED_MII)
Dave Liu7737d5c2006-11-03 12:11:15 -0600115
116#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100117 SUPPORTED_1000baseT_Half | \
118 SUPPORTED_1000baseT_Full)
Dave Liu7737d5c2006-11-03 12:11:15 -0600119
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100120#define MII_READ_COMMAND 0x00000001
Dave Liu7737d5c2006-11-03 12:11:15 -0600121
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100122#define MII_INTERRUPT_DISABLED 0x0
123#define MII_INTERRUPT_ENABLED 0x1
Dave Liu7737d5c2006-11-03 12:11:15 -0600124
125#define SPEED_10 10
126#define SPEED_100 100
127#define SPEED_1000 1000
128
129/* Duplex, half or full. */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100130#define DUPLEX_HALF 0x00
131#define DUPLEX_FULL 0x01
Dave Liu7737d5c2006-11-03 12:11:15 -0600132
133/* Indicates what features are supported by the interface. */
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100134#define SUPPORTED_10baseT_Half (1 << 0)
135#define SUPPORTED_10baseT_Full (1 << 1)
136#define SUPPORTED_100baseT_Half (1 << 2)
137#define SUPPORTED_100baseT_Full (1 << 3)
138#define SUPPORTED_1000baseT_Half (1 << 4)
139#define SUPPORTED_1000baseT_Full (1 << 5)
140#define SUPPORTED_Autoneg (1 << 6)
141#define SUPPORTED_TP (1 << 7)
142#define SUPPORTED_AUI (1 << 8)
143#define SUPPORTED_MII (1 << 9)
144#define SUPPORTED_FIBRE (1 << 10)
145#define SUPPORTED_BNC (1 << 11)
146#define SUPPORTED_10000baseT_Full (1 << 12)
Dave Liu7737d5c2006-11-03 12:11:15 -0600147
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100148#define ADVERTISED_10baseT_Half (1 << 0)
149#define ADVERTISED_10baseT_Full (1 << 1)
150#define ADVERTISED_100baseT_Half (1 << 2)
151#define ADVERTISED_100baseT_Full (1 << 3)
152#define ADVERTISED_1000baseT_Half (1 << 4)
153#define ADVERTISED_1000baseT_Full (1 << 5)
154#define ADVERTISED_Autoneg (1 << 6)
155#define ADVERTISED_TP (1 << 7)
156#define ADVERTISED_AUI (1 << 8)
157#define ADVERTISED_MII (1 << 9)
158#define ADVERTISED_FIBRE (1 << 10)
159#define ADVERTISED_BNC (1 << 11)
160#define ADVERTISED_10000baseT_Full (1 << 12)
Dave Liu7737d5c2006-11-03 12:11:15 -0600161
Dave Liu7737d5c2006-11-03 12:11:15 -0600162/* Taken from mii_if_info and sungem_phy.h */
163struct uec_mii_info {
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100164 /* Information about the PHY type */
165 /* And management functions */
166 struct phy_info *phyinfo;
Dave Liu7737d5c2006-11-03 12:11:15 -0600167
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100168 struct eth_device *dev;
Dave Liu7737d5c2006-11-03 12:11:15 -0600169
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100170 /* forced speed & duplex (no autoneg)
171 * partner speed & duplex & pause (autoneg)
172 */
173 int speed;
174 int duplex;
175 int pause;
Dave Liu7737d5c2006-11-03 12:11:15 -0600176
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100177 /* The most recently read link state */
178 int link;
Dave Liu7737d5c2006-11-03 12:11:15 -0600179
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100180 /* Enabled Interrupts */
181 u32 interrupts;
Dave Liu7737d5c2006-11-03 12:11:15 -0600182
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100183 u32 advertising;
184 int autoneg;
185 int mii_id;
Dave Liu7737d5c2006-11-03 12:11:15 -0600186
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100187 /* private data pointer */
188 /* For use by PHYs to maintain extra state */
189 void *priv;
Dave Liu7737d5c2006-11-03 12:11:15 -0600190
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100191 /* Provided by ethernet driver */
192 int (*mdio_read) (struct eth_device * dev, int mii_id, int reg);
193 void (*mdio_write) (struct eth_device * dev, int mii_id, int reg,
194 int val);
Dave Liu7737d5c2006-11-03 12:11:15 -0600195};
196
197/* struct phy_info: a structure which defines attributes for a PHY
198 *
199 * id will contain a number which represents the PHY. During
200 * startup, the driver will poll the PHY to find out what its
201 * UID--as defined by registers 2 and 3--is. The 32-bit result
202 * gotten from the PHY will be ANDed with phy_id_mask to
203 * discard any bits which may change based on revision numbers
204 * unimportant to functionality
205 *
206 * There are 6 commands which take a ugeth_mii_info structure.
207 * Each PHY must declare config_aneg, and read_status.
208 */
209struct phy_info {
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100210 u32 phy_id;
211 char *name;
212 unsigned int phy_id_mask;
213 u32 features;
Dave Liu7737d5c2006-11-03 12:11:15 -0600214
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100215 /* Called to initialize the PHY */
216 int (*init) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600217
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100218 /* Called to suspend the PHY for power */
219 int (*suspend) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600220
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100221 /* Reconfigures autonegotiation (or disables it) */
222 int (*config_aneg) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600223
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100224 /* Determines the negotiated speed and duplex */
225 int (*read_status) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600226
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100227 /* Clears any pending interrupts */
228 int (*ack_interrupt) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600229
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100230 /* Enables or disables interrupts */
231 int (*config_intr) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600232
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100233 /* Clears up any memory if needed */
234 void (*close) (struct uec_mii_info * mii_info);
Dave Liu7737d5c2006-11-03 12:11:15 -0600235};
236
Andy Flemingda9d4612007-08-14 00:14:25 -0500237struct phy_info *uec_get_phy_info (struct uec_mii_info *mii_info);
238void uec_write_phy_reg (struct eth_device *dev, int mii_id, int regnum,
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100239 int value);
Andy Flemingda9d4612007-08-14 00:14:25 -0500240int uec_read_phy_reg (struct eth_device *dev, int mii_id, int regnum);
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100241void mii_clear_phy_interrupt (struct uec_mii_info *mii_info);
242void mii_configure_phy_interrupt (struct uec_mii_info *mii_info,
243 u32 interrupts);
Dave Liu7737d5c2006-11-03 12:11:15 -0600244#endif /* __UEC_PHY_H__ */