xref: /freebsd/sys/dev/cxgb/common/cxgb_ael1002.c (revision 9036240993b3c7d76e2403a71780c46f964ec0d0)
1b6d90eb7SKip Macy /**************************************************************************
2b6d90eb7SKip Macy 
319905d6dSKip Macy Copyright (c) 2007-2008, Chelsio Inc.
4b6d90eb7SKip Macy All rights reserved.
5b6d90eb7SKip Macy 
6b6d90eb7SKip Macy Redistribution and use in source and binary forms, with or without
7b6d90eb7SKip Macy modification, are permitted provided that the following conditions are met:
8b6d90eb7SKip Macy 
9b6d90eb7SKip Macy  1. Redistributions of source code must retain the above copyright notice,
10b6d90eb7SKip Macy     this list of conditions and the following disclaimer.
11b6d90eb7SKip Macy 
1210faa568SKip Macy  2. Neither the name of the Chelsio Corporation nor the names of its
13b6d90eb7SKip Macy     contributors may be used to endorse or promote products derived from
14b6d90eb7SKip Macy     this software without specific prior written permission.
15b6d90eb7SKip Macy 
16b6d90eb7SKip Macy THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17b6d90eb7SKip Macy AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b6d90eb7SKip Macy IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b6d90eb7SKip Macy ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20b6d90eb7SKip Macy LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21b6d90eb7SKip Macy CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22b6d90eb7SKip Macy SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23b6d90eb7SKip Macy INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24b6d90eb7SKip Macy CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25b6d90eb7SKip Macy ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26b6d90eb7SKip Macy POSSIBILITY OF SUCH DAMAGE.
27b6d90eb7SKip Macy 
28b6d90eb7SKip Macy ***************************************************************************/
29b6d90eb7SKip Macy 
30b6d90eb7SKip Macy #include <sys/cdefs.h>
31b6d90eb7SKip Macy __FBSDID("$FreeBSD$");
32b6d90eb7SKip Macy 
3310faa568SKip Macy #include <cxgb_include.h>
34b6d90eb7SKip Macy 
358e10660fSKip Macy #undef msleep
368e10660fSKip Macy #define msleep t3_os_sleep
378e10660fSKip Macy 
38b6d90eb7SKip Macy enum {
399b4de886SKip Macy 	PMD_RSD     = 10,   /* PMA/PMD receive signal detect register */
409b4de886SKip Macy 	PCS_STAT1_X = 24,   /* 10GBASE-X PCS status 1 register */
419b4de886SKip Macy 	PCS_STAT1_R = 32,   /* 10GBASE-R PCS status 1 register */
429b4de886SKip Macy 	XS_LN_STAT  = 24    /* XS lane status register */
439b4de886SKip Macy };
449b4de886SKip Macy 
459b4de886SKip Macy enum {
46b6d90eb7SKip Macy 	AEL100X_TX_DISABLE  = 9,
47b6d90eb7SKip Macy 	AEL100X_TX_CONFIG1  = 0xc002,
48b6d90eb7SKip Macy 	AEL1002_PWR_DOWN_HI = 0xc011,
49b6d90eb7SKip Macy 	AEL1002_PWR_DOWN_LO = 0xc012,
50b6d90eb7SKip Macy 	AEL1002_XFI_EQL     = 0xc015,
51b6d90eb7SKip Macy 	AEL1002_LB_EN       = 0xc017,
524af83c8cSKip Macy 	AEL_OPT_SETTINGS    = 0xc017,
539b4de886SKip Macy 	AEL_I2C_CTRL        = 0xc30a,
549b4de886SKip Macy 	AEL_I2C_DATA        = 0xc30b,
559b4de886SKip Macy 	AEL_I2C_STAT        = 0xc30c,
569b4de886SKip Macy 	AEL2005_GPIO_CTRL   = 0xc214,
579b4de886SKip Macy 	AEL2005_GPIO_STAT   = 0xc215,
58b6d90eb7SKip Macy };
59b6d90eb7SKip Macy 
609b4de886SKip Macy enum { edc_none, edc_sr, edc_twinax };
619b4de886SKip Macy 
629b4de886SKip Macy /* PHY module I2C device address */
639b4de886SKip Macy #define MODULE_DEV_ADDR 0xa0
649b4de886SKip Macy 
659b4de886SKip Macy #define AEL2005_MODDET_IRQ 4
669b4de886SKip Macy 
674af83c8cSKip Macy struct reg_val {
684af83c8cSKip Macy 	unsigned short mmd_addr;
694af83c8cSKip Macy 	unsigned short reg_addr;
704af83c8cSKip Macy 	unsigned short clear_bits;
714af83c8cSKip Macy 	unsigned short set_bits;
724af83c8cSKip Macy };
734af83c8cSKip Macy 
744af83c8cSKip Macy static int set_phy_regs(struct cphy *phy, const struct reg_val *rv)
754af83c8cSKip Macy {
764af83c8cSKip Macy 	int err;
774af83c8cSKip Macy 
784af83c8cSKip Macy 	for (err = 0; rv->mmd_addr && !err; rv++) {
794af83c8cSKip Macy 		if (rv->clear_bits == 0xffff)
804af83c8cSKip Macy 			err = mdio_write(phy, rv->mmd_addr, rv->reg_addr,
814af83c8cSKip Macy 					 rv->set_bits);
824af83c8cSKip Macy 		else
834af83c8cSKip Macy 			err = t3_mdio_change_bits(phy, rv->mmd_addr,
844af83c8cSKip Macy 						  rv->reg_addr, rv->clear_bits,
854af83c8cSKip Macy 						  rv->set_bits);
864af83c8cSKip Macy 	}
874af83c8cSKip Macy 	return err;
884af83c8cSKip Macy }
894af83c8cSKip Macy 
90b6d90eb7SKip Macy static void ael100x_txon(struct cphy *phy)
91b6d90eb7SKip Macy {
92b6d90eb7SKip Macy 	int tx_on_gpio = phy->addr == 0 ? F_GPIO7_OUT_VAL : F_GPIO2_OUT_VAL;
93b6d90eb7SKip Macy 
948e10660fSKip Macy 	msleep(100);
95b6d90eb7SKip Macy 	t3_set_reg_field(phy->adapter, A_T3DBG_GPIO_EN, 0, tx_on_gpio);
968e10660fSKip Macy 	msleep(30);
97b6d90eb7SKip Macy }
98b6d90eb7SKip Macy 
99b6d90eb7SKip Macy static int ael1002_power_down(struct cphy *phy, int enable)
100b6d90eb7SKip Macy {
101b6d90eb7SKip Macy 	int err;
102b6d90eb7SKip Macy 
103b6d90eb7SKip Macy 	err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_DISABLE, !!enable);
104b6d90eb7SKip Macy 	if (!err)
105b6d90eb7SKip Macy 		err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
106b6d90eb7SKip Macy 					  BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
107b6d90eb7SKip Macy 	return err;
108b6d90eb7SKip Macy }
109b6d90eb7SKip Macy 
110b6d90eb7SKip Macy static int ael1002_reset(struct cphy *phy, int wait)
111b6d90eb7SKip Macy {
112b6d90eb7SKip Macy 	int err;
113b6d90eb7SKip Macy 
114b6d90eb7SKip Macy 	if ((err = ael1002_power_down(phy, 0)) ||
115b6d90eb7SKip Macy 	    (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL100X_TX_CONFIG1, 1)) ||
116b6d90eb7SKip Macy 	    (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_HI, 0)) ||
117b6d90eb7SKip Macy 	    (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_PWR_DOWN_LO, 0)) ||
118b6d90eb7SKip Macy 	    (err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL1002_XFI_EQL, 0x18)) ||
119b6d90eb7SKip Macy 	    (err = t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL1002_LB_EN,
120b6d90eb7SKip Macy 				       0, 1 << 5)))
121b6d90eb7SKip Macy 		return err;
122b6d90eb7SKip Macy 	return 0;
123b6d90eb7SKip Macy }
124b6d90eb7SKip Macy 
125b6d90eb7SKip Macy static int ael1002_intr_noop(struct cphy *phy)
126b6d90eb7SKip Macy {
127b6d90eb7SKip Macy 	return 0;
128b6d90eb7SKip Macy }
129b6d90eb7SKip Macy 
1309b4de886SKip Macy /*
1319b4de886SKip Macy  * Get link status for a 10GBASE-R device.
1329b4de886SKip Macy  */
1339b4de886SKip Macy static int get_link_status_r(struct cphy *phy, int *link_ok, int *speed,
1349b4de886SKip Macy 			     int *duplex, int *fc)
135b6d90eb7SKip Macy {
136b6d90eb7SKip Macy 	if (link_ok) {
1379b4de886SKip Macy 		unsigned int stat0, stat1, stat2;
1389b4de886SKip Macy 		int err = mdio_read(phy, MDIO_DEV_PMA_PMD, PMD_RSD, &stat0);
139b6d90eb7SKip Macy 
1409b4de886SKip Macy 		if (!err)
1419b4de886SKip Macy 			err = mdio_read(phy, MDIO_DEV_PCS, PCS_STAT1_R, &stat1);
1429b4de886SKip Macy 		if (!err)
1439b4de886SKip Macy 			err = mdio_read(phy, MDIO_DEV_XGXS, XS_LN_STAT, &stat2);
144b6d90eb7SKip Macy 		if (err)
145b6d90eb7SKip Macy 			return err;
1469b4de886SKip Macy 		*link_ok = (stat0 & stat1 & (stat2 >> 12)) & 1;
147b6d90eb7SKip Macy 	}
148b6d90eb7SKip Macy 	if (speed)
149b6d90eb7SKip Macy 		*speed = SPEED_10000;
150b6d90eb7SKip Macy 	if (duplex)
151b6d90eb7SKip Macy 		*duplex = DUPLEX_FULL;
152b6d90eb7SKip Macy 	return 0;
153b6d90eb7SKip Macy }
154b6d90eb7SKip Macy 
155b6d90eb7SKip Macy #ifdef C99_NOT_SUPPORTED
156b6d90eb7SKip Macy static struct cphy_ops ael1002_ops = {
157b6d90eb7SKip Macy 	ael1002_reset,
158b6d90eb7SKip Macy 	ael1002_intr_noop,
159b6d90eb7SKip Macy 	ael1002_intr_noop,
160b6d90eb7SKip Macy 	ael1002_intr_noop,
161b6d90eb7SKip Macy 	ael1002_intr_noop,
162b6d90eb7SKip Macy 	NULL,
163b6d90eb7SKip Macy 	NULL,
164b6d90eb7SKip Macy 	NULL,
165b6d90eb7SKip Macy 	NULL,
166b6d90eb7SKip Macy 	NULL,
1679b4de886SKip Macy 	get_link_status_r,
168b6d90eb7SKip Macy 	ael1002_power_down,
169b6d90eb7SKip Macy };
170b6d90eb7SKip Macy #else
171b6d90eb7SKip Macy static struct cphy_ops ael1002_ops = {
172b6d90eb7SKip Macy 	.reset           = ael1002_reset,
173b6d90eb7SKip Macy 	.intr_enable     = ael1002_intr_noop,
174b6d90eb7SKip Macy 	.intr_disable    = ael1002_intr_noop,
175b6d90eb7SKip Macy 	.intr_clear      = ael1002_intr_noop,
176b6d90eb7SKip Macy 	.intr_handler    = ael1002_intr_noop,
1779b4de886SKip Macy 	.get_link_status = get_link_status_r,
178b6d90eb7SKip Macy 	.power_down      = ael1002_power_down,
179b6d90eb7SKip Macy };
180b6d90eb7SKip Macy #endif
181b6d90eb7SKip Macy 
1828e10660fSKip Macy int t3_ael1002_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr,
183b6d90eb7SKip Macy 			const struct mdio_ops *mdio_ops)
184b6d90eb7SKip Macy {
1858e10660fSKip Macy 	cphy_init(phy, adapter, phy_addr, &ael1002_ops, mdio_ops,
1868e10660fSKip Macy 		  SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
18719905d6dSKip Macy 		  "10GBASE-R");
188b6d90eb7SKip Macy 	ael100x_txon(phy);
1898e10660fSKip Macy 	return 0;
190b6d90eb7SKip Macy }
191b6d90eb7SKip Macy 
192b6d90eb7SKip Macy static int ael1006_reset(struct cphy *phy, int wait)
193b6d90eb7SKip Macy {
1942a1b9f07SGeorge V. Neville-Neil 	u32 gpio_out;
1952a1b9f07SGeorge V. Neville-Neil 	t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
1962a1b9f07SGeorge V. Neville-Neil 	/* Hack to reset the phy correctly */
1972a1b9f07SGeorge V. Neville-Neil 	/* Read out the current value */
1982a1b9f07SGeorge V. Neville-Neil 	gpio_out = t3_read_reg(phy->adapter, A_T3DBG_GPIO_EN);
1992a1b9f07SGeorge V. Neville-Neil 	/* Reset the phy */
2002a1b9f07SGeorge V. Neville-Neil 	gpio_out &= ~F_GPIO6_OUT_VAL;
2012a1b9f07SGeorge V. Neville-Neil 	t3_write_reg(phy->adapter, A_T3DBG_GPIO_EN, gpio_out);
2022a1b9f07SGeorge V. Neville-Neil 	msleep(125);
2032a1b9f07SGeorge V. Neville-Neil 	/* Take the phy out of reset */
2042a1b9f07SGeorge V. Neville-Neil 	gpio_out |= F_GPIO6_OUT_VAL;
2052a1b9f07SGeorge V. Neville-Neil 	t3_write_reg(phy->adapter, A_T3DBG_GPIO_EN, gpio_out);
2062a1b9f07SGeorge V. Neville-Neil 	msleep(125);
2072a1b9f07SGeorge V. Neville-Neil 	t3_phy_reset(phy, MDIO_DEV_PMA_PMD, wait);
20890362409SGeorge V. Neville-Neil 
20990362409SGeorge V. Neville-Neil        /* Phy loopback work around for ael1006 */
21090362409SGeorge V. Neville-Neil        /* Soft reset phy by toggling loopback  */
21190362409SGeorge V. Neville-Neil        msleep(125);
21290362409SGeorge V. Neville-Neil        /* Put phy into local loopback */
21390362409SGeorge V. Neville-Neil        t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR, 0, 1);
21490362409SGeorge V. Neville-Neil        msleep(125);
21590362409SGeorge V. Neville-Neil        /* Take phy out of local loopback */
21690362409SGeorge V. Neville-Neil        t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR, 1, 0);
21790362409SGeorge V. Neville-Neil 
2182a1b9f07SGeorge V. Neville-Neil 	return 0;
219b6d90eb7SKip Macy }
220b6d90eb7SKip Macy 
221b6d90eb7SKip Macy static int ael1006_power_down(struct cphy *phy, int enable)
222b6d90eb7SKip Macy {
223b6d90eb7SKip Macy 	return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, MII_BMCR,
224b6d90eb7SKip Macy 				   BMCR_PDOWN, enable ? BMCR_PDOWN : 0);
225b6d90eb7SKip Macy }
226b6d90eb7SKip Macy 
227b6d90eb7SKip Macy #ifdef C99_NOT_SUPPORTED
228b6d90eb7SKip Macy static struct cphy_ops ael1006_ops = {
229b6d90eb7SKip Macy 	ael1006_reset,
2304af83c8cSKip Macy 	t3_phy_lasi_intr_enable,
2314af83c8cSKip Macy 	t3_phy_lasi_intr_disable,
2324af83c8cSKip Macy 	t3_phy_lasi_intr_clear,
2334af83c8cSKip Macy 	t3_phy_lasi_intr_handler,
234b6d90eb7SKip Macy 	NULL,
235b6d90eb7SKip Macy 	NULL,
236b6d90eb7SKip Macy 	NULL,
237b6d90eb7SKip Macy 	NULL,
238b6d90eb7SKip Macy 	NULL,
2399b4de886SKip Macy 	get_link_status_r,
240b6d90eb7SKip Macy 	ael1006_power_down,
241b6d90eb7SKip Macy };
242b6d90eb7SKip Macy #else
243b6d90eb7SKip Macy static struct cphy_ops ael1006_ops = {
244b6d90eb7SKip Macy 	.reset           = ael1006_reset,
2454af83c8cSKip Macy 	.intr_enable     = t3_phy_lasi_intr_enable,
2464af83c8cSKip Macy 	.intr_disable    = t3_phy_lasi_intr_disable,
2474af83c8cSKip Macy 	.intr_clear      = t3_phy_lasi_intr_clear,
2484af83c8cSKip Macy 	.intr_handler    = t3_phy_lasi_intr_handler,
2499b4de886SKip Macy 	.get_link_status = get_link_status_r,
250b6d90eb7SKip Macy 	.power_down      = ael1006_power_down,
251b6d90eb7SKip Macy };
252b6d90eb7SKip Macy #endif
253b6d90eb7SKip Macy 
2548e10660fSKip Macy int t3_ael1006_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr,
255b6d90eb7SKip Macy 			const struct mdio_ops *mdio_ops)
256b6d90eb7SKip Macy {
2578e10660fSKip Macy 	cphy_init(phy, adapter, phy_addr, &ael1006_ops, mdio_ops,
2588e10660fSKip Macy 		  SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE,
2598e10660fSKip Macy 		  "10GBASE-SR");
260b6d90eb7SKip Macy 	ael100x_txon(phy);
2618e10660fSKip Macy 	return 0;
262b6d90eb7SKip Macy }
263b6d90eb7SKip Macy 
2644af83c8cSKip Macy static int ael2005_setup_sr_edc(struct cphy *phy)
2654af83c8cSKip Macy {
2669b4de886SKip Macy 	static struct reg_val regs[] = {
2679b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc003, 0xffff, 0x181 },
2689b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc010, 0xffff, 0x448a },
2699b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc04a, 0xffff, 0x5200 },
2709b4de886SKip Macy 		{ 0, 0, 0, 0 }
2719b4de886SKip Macy 	};
2724af83c8cSKip Macy 	static u16 sr_edc[] = {
2734af83c8cSKip Macy 		0xcc00, 0x2ff4,
2744af83c8cSKip Macy 		0xcc01, 0x3cd4,
2754af83c8cSKip Macy 		0xcc02, 0x2015,
2764af83c8cSKip Macy 		0xcc03, 0x3105,
2774af83c8cSKip Macy 		0xcc04, 0x6524,
2784af83c8cSKip Macy 		0xcc05, 0x27ff,
2794af83c8cSKip Macy 		0xcc06, 0x300f,
2804af83c8cSKip Macy 		0xcc07, 0x2c8b,
2814af83c8cSKip Macy 		0xcc08, 0x300b,
2824af83c8cSKip Macy 		0xcc09, 0x4009,
2834af83c8cSKip Macy 		0xcc0a, 0x400e,
2844af83c8cSKip Macy 		0xcc0b, 0x2f72,
2854af83c8cSKip Macy 		0xcc0c, 0x3002,
2864af83c8cSKip Macy 		0xcc0d, 0x1002,
2874af83c8cSKip Macy 		0xcc0e, 0x2172,
2884af83c8cSKip Macy 		0xcc0f, 0x3012,
2894af83c8cSKip Macy 		0xcc10, 0x1002,
2904af83c8cSKip Macy 		0xcc11, 0x25d2,
2914af83c8cSKip Macy 		0xcc12, 0x3012,
2924af83c8cSKip Macy 		0xcc13, 0x1002,
2934af83c8cSKip Macy 		0xcc14, 0xd01e,
2944af83c8cSKip Macy 		0xcc15, 0x27d2,
2954af83c8cSKip Macy 		0xcc16, 0x3012,
2964af83c8cSKip Macy 		0xcc17, 0x1002,
2974af83c8cSKip Macy 		0xcc18, 0x2004,
2984af83c8cSKip Macy 		0xcc19, 0x3c84,
2994af83c8cSKip Macy 		0xcc1a, 0x6436,
3004af83c8cSKip Macy 		0xcc1b, 0x2007,
3014af83c8cSKip Macy 		0xcc1c, 0x3f87,
3024af83c8cSKip Macy 		0xcc1d, 0x8676,
3034af83c8cSKip Macy 		0xcc1e, 0x40b7,
3044af83c8cSKip Macy 		0xcc1f, 0xa746,
3054af83c8cSKip Macy 		0xcc20, 0x4047,
3064af83c8cSKip Macy 		0xcc21, 0x5673,
3074af83c8cSKip Macy 		0xcc22, 0x2982,
3084af83c8cSKip Macy 		0xcc23, 0x3002,
3094af83c8cSKip Macy 		0xcc24, 0x13d2,
3104af83c8cSKip Macy 		0xcc25, 0x8bbd,
3114af83c8cSKip Macy 		0xcc26, 0x2862,
3124af83c8cSKip Macy 		0xcc27, 0x3012,
3134af83c8cSKip Macy 		0xcc28, 0x1002,
3144af83c8cSKip Macy 		0xcc29, 0x2092,
3154af83c8cSKip Macy 		0xcc2a, 0x3012,
3164af83c8cSKip Macy 		0xcc2b, 0x1002,
3174af83c8cSKip Macy 		0xcc2c, 0x5cc3,
3184af83c8cSKip Macy 		0xcc2d, 0x314,
3194af83c8cSKip Macy 		0xcc2e, 0x2942,
3204af83c8cSKip Macy 		0xcc2f, 0x3002,
3214af83c8cSKip Macy 		0xcc30, 0x1002,
3224af83c8cSKip Macy 		0xcc31, 0xd019,
3234af83c8cSKip Macy 		0xcc32, 0x2032,
3244af83c8cSKip Macy 		0xcc33, 0x3012,
3254af83c8cSKip Macy 		0xcc34, 0x1002,
3264af83c8cSKip Macy 		0xcc35, 0x2a04,
3274af83c8cSKip Macy 		0xcc36, 0x3c74,
3284af83c8cSKip Macy 		0xcc37, 0x6435,
3294af83c8cSKip Macy 		0xcc38, 0x2fa4,
3304af83c8cSKip Macy 		0xcc39, 0x3cd4,
3314af83c8cSKip Macy 		0xcc3a, 0x6624,
3324af83c8cSKip Macy 		0xcc3b, 0x5563,
3334af83c8cSKip Macy 		0xcc3c, 0x2d42,
3344af83c8cSKip Macy 		0xcc3d, 0x3002,
3354af83c8cSKip Macy 		0xcc3e, 0x13d2,
3364af83c8cSKip Macy 		0xcc3f, 0x464d,
3374af83c8cSKip Macy 		0xcc40, 0x2862,
3384af83c8cSKip Macy 		0xcc41, 0x3012,
3394af83c8cSKip Macy 		0xcc42, 0x1002,
3404af83c8cSKip Macy 		0xcc43, 0x2032,
3414af83c8cSKip Macy 		0xcc44, 0x3012,
3424af83c8cSKip Macy 		0xcc45, 0x1002,
3434af83c8cSKip Macy 		0xcc46, 0x2fb4,
3444af83c8cSKip Macy 		0xcc47, 0x3cd4,
3454af83c8cSKip Macy 		0xcc48, 0x6624,
3464af83c8cSKip Macy 		0xcc49, 0x5563,
3474af83c8cSKip Macy 		0xcc4a, 0x2d42,
3484af83c8cSKip Macy 		0xcc4b, 0x3002,
3494af83c8cSKip Macy 		0xcc4c, 0x13d2,
3504af83c8cSKip Macy 		0xcc4d, 0x2ed2,
3514af83c8cSKip Macy 		0xcc4e, 0x3002,
3524af83c8cSKip Macy 		0xcc4f, 0x1002,
3534af83c8cSKip Macy 		0xcc50, 0x2fd2,
3544af83c8cSKip Macy 		0xcc51, 0x3002,
3554af83c8cSKip Macy 		0xcc52, 0x1002,
3564af83c8cSKip Macy 		0xcc53, 0x004,
3574af83c8cSKip Macy 		0xcc54, 0x2942,
3584af83c8cSKip Macy 		0xcc55, 0x3002,
3594af83c8cSKip Macy 		0xcc56, 0x1002,
3604af83c8cSKip Macy 		0xcc57, 0x2092,
3614af83c8cSKip Macy 		0xcc58, 0x3012,
3624af83c8cSKip Macy 		0xcc59, 0x1002,
3634af83c8cSKip Macy 		0xcc5a, 0x5cc3,
3644af83c8cSKip Macy 		0xcc5b, 0x317,
3654af83c8cSKip Macy 		0xcc5c, 0x2f72,
3664af83c8cSKip Macy 		0xcc5d, 0x3002,
3674af83c8cSKip Macy 		0xcc5e, 0x1002,
3684af83c8cSKip Macy 		0xcc5f, 0x2942,
3694af83c8cSKip Macy 		0xcc60, 0x3002,
3704af83c8cSKip Macy 		0xcc61, 0x1002,
3714af83c8cSKip Macy 		0xcc62, 0x22cd,
3724af83c8cSKip Macy 		0xcc63, 0x301d,
3734af83c8cSKip Macy 		0xcc64, 0x2862,
3744af83c8cSKip Macy 		0xcc65, 0x3012,
3754af83c8cSKip Macy 		0xcc66, 0x1002,
3764af83c8cSKip Macy 		0xcc67, 0x2ed2,
3774af83c8cSKip Macy 		0xcc68, 0x3002,
3784af83c8cSKip Macy 		0xcc69, 0x1002,
3794af83c8cSKip Macy 		0xcc6a, 0x2d72,
3804af83c8cSKip Macy 		0xcc6b, 0x3002,
3814af83c8cSKip Macy 		0xcc6c, 0x1002,
3824af83c8cSKip Macy 		0xcc6d, 0x628f,
3834af83c8cSKip Macy 		0xcc6e, 0x2112,
3844af83c8cSKip Macy 		0xcc6f, 0x3012,
3854af83c8cSKip Macy 		0xcc70, 0x1002,
3864af83c8cSKip Macy 		0xcc71, 0x5aa3,
3874af83c8cSKip Macy 		0xcc72, 0x2dc2,
3884af83c8cSKip Macy 		0xcc73, 0x3002,
3894af83c8cSKip Macy 		0xcc74, 0x1312,
3904af83c8cSKip Macy 		0xcc75, 0x6f72,
3914af83c8cSKip Macy 		0xcc76, 0x1002,
3924af83c8cSKip Macy 		0xcc77, 0x2807,
3934af83c8cSKip Macy 		0xcc78, 0x31a7,
3944af83c8cSKip Macy 		0xcc79, 0x20c4,
3954af83c8cSKip Macy 		0xcc7a, 0x3c24,
3964af83c8cSKip Macy 		0xcc7b, 0x6724,
3974af83c8cSKip Macy 		0xcc7c, 0x1002,
3984af83c8cSKip Macy 		0xcc7d, 0x2807,
3994af83c8cSKip Macy 		0xcc7e, 0x3187,
4004af83c8cSKip Macy 		0xcc7f, 0x20c4,
4014af83c8cSKip Macy 		0xcc80, 0x3c24,
4024af83c8cSKip Macy 		0xcc81, 0x6724,
4034af83c8cSKip Macy 		0xcc82, 0x1002,
4044af83c8cSKip Macy 		0xcc83, 0x2514,
4054af83c8cSKip Macy 		0xcc84, 0x3c64,
4064af83c8cSKip Macy 		0xcc85, 0x6436,
4074af83c8cSKip Macy 		0xcc86, 0xdff4,
4084af83c8cSKip Macy 		0xcc87, 0x6436,
4094af83c8cSKip Macy 		0xcc88, 0x1002,
4104af83c8cSKip Macy 		0xcc89, 0x40a4,
4114af83c8cSKip Macy 		0xcc8a, 0x643c,
4124af83c8cSKip Macy 		0xcc8b, 0x4016,
4134af83c8cSKip Macy 		0xcc8c, 0x8c6c,
4144af83c8cSKip Macy 		0xcc8d, 0x2b24,
4154af83c8cSKip Macy 		0xcc8e, 0x3c24,
4164af83c8cSKip Macy 		0xcc8f, 0x6435,
4174af83c8cSKip Macy 		0xcc90, 0x1002,
4184af83c8cSKip Macy 		0xcc91, 0x2b24,
4194af83c8cSKip Macy 		0xcc92, 0x3c24,
4204af83c8cSKip Macy 		0xcc93, 0x643a,
4214af83c8cSKip Macy 		0xcc94, 0x4025,
4224af83c8cSKip Macy 		0xcc95, 0x8a5a,
4234af83c8cSKip Macy 		0xcc96, 0x1002,
4244af83c8cSKip Macy 		0xcc97, 0x2731,
4254af83c8cSKip Macy 		0xcc98, 0x3011,
4264af83c8cSKip Macy 		0xcc99, 0x1001,
4274af83c8cSKip Macy 		0xcc9a, 0xc7a0,
4284af83c8cSKip Macy 		0xcc9b, 0x100,
4294af83c8cSKip Macy 		0xcc9c, 0xc502,
4304af83c8cSKip Macy 		0xcc9d, 0x53ac,
4314af83c8cSKip Macy 		0xcc9e, 0xc503,
4324af83c8cSKip Macy 		0xcc9f, 0xd5d5,
4334af83c8cSKip Macy 		0xcca0, 0xc600,
4344af83c8cSKip Macy 		0xcca1, 0x2a6d,
4354af83c8cSKip Macy 		0xcca2, 0xc601,
4364af83c8cSKip Macy 		0xcca3, 0x2a4c,
4374af83c8cSKip Macy 		0xcca4, 0xc602,
4384af83c8cSKip Macy 		0xcca5, 0x111,
4394af83c8cSKip Macy 		0xcca6, 0xc60c,
4404af83c8cSKip Macy 		0xcca7, 0x5900,
4414af83c8cSKip Macy 		0xcca8, 0xc710,
4424af83c8cSKip Macy 		0xcca9, 0x700,
4434af83c8cSKip Macy 		0xccaa, 0xc718,
4444af83c8cSKip Macy 		0xccab, 0x700,
4454af83c8cSKip Macy 		0xccac, 0xc720,
4464af83c8cSKip Macy 		0xccad, 0x4700,
4474af83c8cSKip Macy 		0xccae, 0xc801,
4484af83c8cSKip Macy 		0xccaf, 0x7f50,
4494af83c8cSKip Macy 		0xccb0, 0xc802,
4504af83c8cSKip Macy 		0xccb1, 0x7760,
4514af83c8cSKip Macy 		0xccb2, 0xc803,
4524af83c8cSKip Macy 		0xccb3, 0x7fce,
4534af83c8cSKip Macy 		0xccb4, 0xc804,
4544af83c8cSKip Macy 		0xccb5, 0x5700,
4554af83c8cSKip Macy 		0xccb6, 0xc805,
4564af83c8cSKip Macy 		0xccb7, 0x5f11,
4574af83c8cSKip Macy 		0xccb8, 0xc806,
4584af83c8cSKip Macy 		0xccb9, 0x4751,
4594af83c8cSKip Macy 		0xccba, 0xc807,
4604af83c8cSKip Macy 		0xccbb, 0x57e1,
4614af83c8cSKip Macy 		0xccbc, 0xc808,
4624af83c8cSKip Macy 		0xccbd, 0x2700,
4634af83c8cSKip Macy 		0xccbe, 0xc809,
4644af83c8cSKip Macy 		0xccbf, 0x000,
4654af83c8cSKip Macy 		0xccc0, 0xc821,
4664af83c8cSKip Macy 		0xccc1, 0x002,
4674af83c8cSKip Macy 		0xccc2, 0xc822,
4684af83c8cSKip Macy 		0xccc3, 0x014,
4694af83c8cSKip Macy 		0xccc4, 0xc832,
4704af83c8cSKip Macy 		0xccc5, 0x1186,
4714af83c8cSKip Macy 		0xccc6, 0xc847,
4724af83c8cSKip Macy 		0xccc7, 0x1e02,
4734af83c8cSKip Macy 		0xccc8, 0xc013,
4744af83c8cSKip Macy 		0xccc9, 0xf341,
4754af83c8cSKip Macy 		0xccca, 0xc01a,
4764af83c8cSKip Macy 		0xcccb, 0x446,
4774af83c8cSKip Macy 		0xcccc, 0xc024,
4784af83c8cSKip Macy 		0xcccd, 0x1000,
4794af83c8cSKip Macy 		0xccce, 0xc025,
4804af83c8cSKip Macy 		0xcccf, 0xa00,
4814af83c8cSKip Macy 		0xccd0, 0xc026,
4824af83c8cSKip Macy 		0xccd1, 0xc0c,
4834af83c8cSKip Macy 		0xccd2, 0xc027,
4844af83c8cSKip Macy 		0xccd3, 0xc0c,
4854af83c8cSKip Macy 		0xccd4, 0xc029,
4864af83c8cSKip Macy 		0xccd5, 0x0a0,
4874af83c8cSKip Macy 		0xccd6, 0xc030,
4884af83c8cSKip Macy 		0xccd7, 0xa00,
4894af83c8cSKip Macy 		0xccd8, 0xc03c,
4904af83c8cSKip Macy 		0xccd9, 0x01c,
4914af83c8cSKip Macy 		0xccda, 0xc005,
4924af83c8cSKip Macy 		0xccdb, 0x7a06,
4934af83c8cSKip Macy 		0xccdc, 0x000,
4944af83c8cSKip Macy 		0xccdd, 0x2731,
4954af83c8cSKip Macy 		0xccde, 0x3011,
4964af83c8cSKip Macy 		0xccdf, 0x1001,
4974af83c8cSKip Macy 		0xcce0, 0xc620,
4984af83c8cSKip Macy 		0xcce1, 0x000,
4994af83c8cSKip Macy 		0xcce2, 0xc621,
5004af83c8cSKip Macy 		0xcce3, 0x03f,
5014af83c8cSKip Macy 		0xcce4, 0xc622,
5024af83c8cSKip Macy 		0xcce5, 0x000,
5034af83c8cSKip Macy 		0xcce6, 0xc623,
5044af83c8cSKip Macy 		0xcce7, 0x000,
5054af83c8cSKip Macy 		0xcce8, 0xc624,
5064af83c8cSKip Macy 		0xcce9, 0x000,
5074af83c8cSKip Macy 		0xccea, 0xc625,
5084af83c8cSKip Macy 		0xcceb, 0x000,
5094af83c8cSKip Macy 		0xccec, 0xc627,
5104af83c8cSKip Macy 		0xcced, 0x000,
5114af83c8cSKip Macy 		0xccee, 0xc628,
5124af83c8cSKip Macy 		0xccef, 0x000,
5134af83c8cSKip Macy 		0xccf0, 0xc62c,
5144af83c8cSKip Macy 		0xccf1, 0x000,
5154af83c8cSKip Macy 		0xccf2, 0x000,
5164af83c8cSKip Macy 		0xccf3, 0x2806,
5174af83c8cSKip Macy 		0xccf4, 0x3cb6,
5184af83c8cSKip Macy 		0xccf5, 0xc161,
5194af83c8cSKip Macy 		0xccf6, 0x6134,
5204af83c8cSKip Macy 		0xccf7, 0x6135,
5214af83c8cSKip Macy 		0xccf8, 0x5443,
5224af83c8cSKip Macy 		0xccf9, 0x303,
5234af83c8cSKip Macy 		0xccfa, 0x6524,
5244af83c8cSKip Macy 		0xccfb, 0x00b,
5254af83c8cSKip Macy 		0xccfc, 0x1002,
5264af83c8cSKip Macy 		0xccfd, 0x2104,
5274af83c8cSKip Macy 		0xccfe, 0x3c24,
5284af83c8cSKip Macy 		0xccff, 0x2105,
5294af83c8cSKip Macy 		0xcd00, 0x3805,
5304af83c8cSKip Macy 		0xcd01, 0x6524,
5314af83c8cSKip Macy 		0xcd02, 0xdff4,
5324af83c8cSKip Macy 		0xcd03, 0x4005,
5334af83c8cSKip Macy 		0xcd04, 0x6524,
5344af83c8cSKip Macy 		0xcd05, 0x1002,
5354af83c8cSKip Macy 		0xcd06, 0x5dd3,
5364af83c8cSKip Macy 		0xcd07, 0x306,
5374af83c8cSKip Macy 		0xcd08, 0x2ff7,
5384af83c8cSKip Macy 		0xcd09, 0x38f7,
5394af83c8cSKip Macy 		0xcd0a, 0x60b7,
5404af83c8cSKip Macy 		0xcd0b, 0xdffd,
5414af83c8cSKip Macy 		0xcd0c, 0x00a,
5424af83c8cSKip Macy 		0xcd0d, 0x1002,
5434af83c8cSKip Macy 		0xcd0e, 0
5444af83c8cSKip Macy 	};
5454af83c8cSKip Macy 	int i, err;
5464af83c8cSKip Macy 
5479b4de886SKip Macy 	err = set_phy_regs(phy, regs);
5489b4de886SKip Macy 	if (err)
5499b4de886SKip Macy 		return err;
5509b4de886SKip Macy 
5519b4de886SKip Macy 	msleep(50);
5529b4de886SKip Macy 
5539b4de886SKip Macy 	for (i = 0; i < ARRAY_SIZE(sr_edc) && !err; i += 2)
5544af83c8cSKip Macy 		err = mdio_write(phy, MDIO_DEV_PMA_PMD, sr_edc[i],
5554af83c8cSKip Macy 				 sr_edc[i + 1]);
5569b4de886SKip Macy 	if (!err)
5579b4de886SKip Macy 		phy->priv = edc_sr;
5584af83c8cSKip Macy 	return err;
5594af83c8cSKip Macy }
5604af83c8cSKip Macy 
5619b4de886SKip Macy static int ael2005_setup_twinax_edc(struct cphy *phy, int modtype)
5629b4de886SKip Macy {
5639b4de886SKip Macy 	static struct reg_val regs[] = {
5649b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc04a, 0xffff, 0x5a00 },
5659b4de886SKip Macy 		{ 0, 0, 0, 0 }
5669b4de886SKip Macy 	};
5679b4de886SKip Macy 	static struct reg_val preemphasis[] = {
5689b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc014, 0xffff, 0xfe16 },
5699b4de886SKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc015, 0xffff, 0xa000 },
5709b4de886SKip Macy 		{ 0, 0, 0, 0 }
5719b4de886SKip Macy 	};
5729b4de886SKip Macy 	static u16 twinax_edc[] = {
5739b4de886SKip Macy 		0xcc00, 0x4009,
5749b4de886SKip Macy 		0xcc01, 0x27ff,
5759b4de886SKip Macy 		0xcc02, 0x300f,
5769b4de886SKip Macy 		0xcc03, 0x40aa,
5779b4de886SKip Macy 		0xcc04, 0x401c,
5789b4de886SKip Macy 		0xcc05, 0x401e,
5799b4de886SKip Macy 		0xcc06, 0x2ff4,
5809b4de886SKip Macy 		0xcc07, 0x3cd4,
5819b4de886SKip Macy 		0xcc08, 0x2035,
5829b4de886SKip Macy 		0xcc09, 0x3145,
5839b4de886SKip Macy 		0xcc0a, 0x6524,
5849b4de886SKip Macy 		0xcc0b, 0x26a2,
5859b4de886SKip Macy 		0xcc0c, 0x3012,
5869b4de886SKip Macy 		0xcc0d, 0x1002,
5879b4de886SKip Macy 		0xcc0e, 0x29c2,
5889b4de886SKip Macy 		0xcc0f, 0x3002,
5899b4de886SKip Macy 		0xcc10, 0x1002,
5909b4de886SKip Macy 		0xcc11, 0x2072,
5919b4de886SKip Macy 		0xcc12, 0x3012,
5929b4de886SKip Macy 		0xcc13, 0x1002,
5939b4de886SKip Macy 		0xcc14, 0x22cd,
5949b4de886SKip Macy 		0xcc15, 0x301d,
5959b4de886SKip Macy 		0xcc16, 0x2e52,
5969b4de886SKip Macy 		0xcc17, 0x3012,
5979b4de886SKip Macy 		0xcc18, 0x1002,
5989b4de886SKip Macy 		0xcc19, 0x28e2,
5999b4de886SKip Macy 		0xcc1a, 0x3002,
6009b4de886SKip Macy 		0xcc1b, 0x1002,
6019b4de886SKip Macy 		0xcc1c, 0x628f,
6029b4de886SKip Macy 		0xcc1d, 0x2ac2,
6039b4de886SKip Macy 		0xcc1e, 0x3012,
6049b4de886SKip Macy 		0xcc1f, 0x1002,
6059b4de886SKip Macy 		0xcc20, 0x5553,
6069b4de886SKip Macy 		0xcc21, 0x2ae2,
6079b4de886SKip Macy 		0xcc22, 0x3002,
6089b4de886SKip Macy 		0xcc23, 0x1302,
6099b4de886SKip Macy 		0xcc24, 0x401e,
6109b4de886SKip Macy 		0xcc25, 0x2be2,
6119b4de886SKip Macy 		0xcc26, 0x3012,
6129b4de886SKip Macy 		0xcc27, 0x1002,
6139b4de886SKip Macy 		0xcc28, 0x2da2,
6149b4de886SKip Macy 		0xcc29, 0x3012,
6159b4de886SKip Macy 		0xcc2a, 0x1002,
6169b4de886SKip Macy 		0xcc2b, 0x2ba2,
6179b4de886SKip Macy 		0xcc2c, 0x3002,
6189b4de886SKip Macy 		0xcc2d, 0x1002,
6199b4de886SKip Macy 		0xcc2e, 0x5ee3,
6209b4de886SKip Macy 		0xcc2f, 0x305,
6219b4de886SKip Macy 		0xcc30, 0x400e,
6229b4de886SKip Macy 		0xcc31, 0x2bc2,
6239b4de886SKip Macy 		0xcc32, 0x3002,
6249b4de886SKip Macy 		0xcc33, 0x1002,
6259b4de886SKip Macy 		0xcc34, 0x2b82,
6269b4de886SKip Macy 		0xcc35, 0x3012,
6279b4de886SKip Macy 		0xcc36, 0x1002,
6289b4de886SKip Macy 		0xcc37, 0x5663,
6299b4de886SKip Macy 		0xcc38, 0x302,
6309b4de886SKip Macy 		0xcc39, 0x401e,
6319b4de886SKip Macy 		0xcc3a, 0x6f72,
6329b4de886SKip Macy 		0xcc3b, 0x1002,
6339b4de886SKip Macy 		0xcc3c, 0x628f,
6349b4de886SKip Macy 		0xcc3d, 0x2be2,
6359b4de886SKip Macy 		0xcc3e, 0x3012,
6369b4de886SKip Macy 		0xcc3f, 0x1002,
6379b4de886SKip Macy 		0xcc40, 0x22cd,
6389b4de886SKip Macy 		0xcc41, 0x301d,
6399b4de886SKip Macy 		0xcc42, 0x2e52,
6409b4de886SKip Macy 		0xcc43, 0x3012,
6419b4de886SKip Macy 		0xcc44, 0x1002,
6429b4de886SKip Macy 		0xcc45, 0x2522,
6439b4de886SKip Macy 		0xcc46, 0x3012,
6449b4de886SKip Macy 		0xcc47, 0x1002,
6459b4de886SKip Macy 		0xcc48, 0x2da2,
6469b4de886SKip Macy 		0xcc49, 0x3012,
6479b4de886SKip Macy 		0xcc4a, 0x1002,
6489b4de886SKip Macy 		0xcc4b, 0x2ca2,
6499b4de886SKip Macy 		0xcc4c, 0x3012,
6509b4de886SKip Macy 		0xcc4d, 0x1002,
6519b4de886SKip Macy 		0xcc4e, 0x2fa4,
6529b4de886SKip Macy 		0xcc4f, 0x3cd4,
6539b4de886SKip Macy 		0xcc50, 0x6624,
6549b4de886SKip Macy 		0xcc51, 0x410b,
6559b4de886SKip Macy 		0xcc52, 0x56b3,
6569b4de886SKip Macy 		0xcc53, 0x3c4,
6579b4de886SKip Macy 		0xcc54, 0x2fb2,
6589b4de886SKip Macy 		0xcc55, 0x3002,
6599b4de886SKip Macy 		0xcc56, 0x1002,
6609b4de886SKip Macy 		0xcc57, 0x220b,
6619b4de886SKip Macy 		0xcc58, 0x303b,
6629b4de886SKip Macy 		0xcc59, 0x56b3,
6639b4de886SKip Macy 		0xcc5a, 0x3c3,
6649b4de886SKip Macy 		0xcc5b, 0x866b,
6659b4de886SKip Macy 		0xcc5c, 0x400c,
6669b4de886SKip Macy 		0xcc5d, 0x23a2,
6679b4de886SKip Macy 		0xcc5e, 0x3012,
6689b4de886SKip Macy 		0xcc5f, 0x1002,
6699b4de886SKip Macy 		0xcc60, 0x2da2,
6709b4de886SKip Macy 		0xcc61, 0x3012,
6719b4de886SKip Macy 		0xcc62, 0x1002,
6729b4de886SKip Macy 		0xcc63, 0x2ca2,
6739b4de886SKip Macy 		0xcc64, 0x3012,
6749b4de886SKip Macy 		0xcc65, 0x1002,
6759b4de886SKip Macy 		0xcc66, 0x2fb4,
6769b4de886SKip Macy 		0xcc67, 0x3cd4,
6779b4de886SKip Macy 		0xcc68, 0x6624,
6789b4de886SKip Macy 		0xcc69, 0x56b3,
6799b4de886SKip Macy 		0xcc6a, 0x3c3,
6809b4de886SKip Macy 		0xcc6b, 0x866b,
6819b4de886SKip Macy 		0xcc6c, 0x401c,
6829b4de886SKip Macy 		0xcc6d, 0x2205,
6839b4de886SKip Macy 		0xcc6e, 0x3035,
6849b4de886SKip Macy 		0xcc6f, 0x5b53,
6859b4de886SKip Macy 		0xcc70, 0x2c52,
6869b4de886SKip Macy 		0xcc71, 0x3002,
6879b4de886SKip Macy 		0xcc72, 0x13c2,
6889b4de886SKip Macy 		0xcc73, 0x5cc3,
6899b4de886SKip Macy 		0xcc74, 0x317,
6909b4de886SKip Macy 		0xcc75, 0x2522,
6919b4de886SKip Macy 		0xcc76, 0x3012,
6929b4de886SKip Macy 		0xcc77, 0x1002,
6939b4de886SKip Macy 		0xcc78, 0x2da2,
6949b4de886SKip Macy 		0xcc79, 0x3012,
6959b4de886SKip Macy 		0xcc7a, 0x1002,
6969b4de886SKip Macy 		0xcc7b, 0x2b82,
6979b4de886SKip Macy 		0xcc7c, 0x3012,
6989b4de886SKip Macy 		0xcc7d, 0x1002,
6999b4de886SKip Macy 		0xcc7e, 0x5663,
7009b4de886SKip Macy 		0xcc7f, 0x303,
7019b4de886SKip Macy 		0xcc80, 0x401e,
7029b4de886SKip Macy 		0xcc81, 0x004,
7039b4de886SKip Macy 		0xcc82, 0x2c42,
7049b4de886SKip Macy 		0xcc83, 0x3012,
7059b4de886SKip Macy 		0xcc84, 0x1002,
7069b4de886SKip Macy 		0xcc85, 0x6f72,
7079b4de886SKip Macy 		0xcc86, 0x1002,
7089b4de886SKip Macy 		0xcc87, 0x628f,
7099b4de886SKip Macy 		0xcc88, 0x2304,
7109b4de886SKip Macy 		0xcc89, 0x3c84,
7119b4de886SKip Macy 		0xcc8a, 0x6436,
7129b4de886SKip Macy 		0xcc8b, 0xdff4,
7139b4de886SKip Macy 		0xcc8c, 0x6436,
7149b4de886SKip Macy 		0xcc8d, 0x2ff5,
7159b4de886SKip Macy 		0xcc8e, 0x3005,
7169b4de886SKip Macy 		0xcc8f, 0x8656,
7179b4de886SKip Macy 		0xcc90, 0xdfba,
7189b4de886SKip Macy 		0xcc91, 0x56a3,
7199b4de886SKip Macy 		0xcc92, 0xd05a,
7209b4de886SKip Macy 		0xcc93, 0x21c2,
7219b4de886SKip Macy 		0xcc94, 0x3012,
7229b4de886SKip Macy 		0xcc95, 0x1392,
7239b4de886SKip Macy 		0xcc96, 0xd05a,
7249b4de886SKip Macy 		0xcc97, 0x56a3,
7259b4de886SKip Macy 		0xcc98, 0xdfba,
7269b4de886SKip Macy 		0xcc99, 0x383,
7279b4de886SKip Macy 		0xcc9a, 0x6f72,
7289b4de886SKip Macy 		0xcc9b, 0x1002,
7299b4de886SKip Macy 		0xcc9c, 0x28c5,
7309b4de886SKip Macy 		0xcc9d, 0x3005,
7319b4de886SKip Macy 		0xcc9e, 0x4178,
7329b4de886SKip Macy 		0xcc9f, 0x5653,
7339b4de886SKip Macy 		0xcca0, 0x384,
7349b4de886SKip Macy 		0xcca1, 0x22b2,
7359b4de886SKip Macy 		0xcca2, 0x3012,
7369b4de886SKip Macy 		0xcca3, 0x1002,
7379b4de886SKip Macy 		0xcca4, 0x2be5,
7389b4de886SKip Macy 		0xcca5, 0x3005,
7399b4de886SKip Macy 		0xcca6, 0x41e8,
7409b4de886SKip Macy 		0xcca7, 0x5653,
7419b4de886SKip Macy 		0xcca8, 0x382,
7429b4de886SKip Macy 		0xcca9, 0x002,
7439b4de886SKip Macy 		0xccaa, 0x4258,
7449b4de886SKip Macy 		0xccab, 0x2474,
7459b4de886SKip Macy 		0xccac, 0x3c84,
7469b4de886SKip Macy 		0xccad, 0x6437,
7479b4de886SKip Macy 		0xccae, 0xdff4,
7489b4de886SKip Macy 		0xccaf, 0x6437,
7499b4de886SKip Macy 		0xccb0, 0x2ff5,
7509b4de886SKip Macy 		0xccb1, 0x3c05,
7519b4de886SKip Macy 		0xccb2, 0x8757,
7529b4de886SKip Macy 		0xccb3, 0xb888,
7539b4de886SKip Macy 		0xccb4, 0x9787,
7549b4de886SKip Macy 		0xccb5, 0xdff4,
7559b4de886SKip Macy 		0xccb6, 0x6724,
7569b4de886SKip Macy 		0xccb7, 0x866a,
7579b4de886SKip Macy 		0xccb8, 0x6f72,
7589b4de886SKip Macy 		0xccb9, 0x1002,
7599b4de886SKip Macy 		0xccba, 0x2d01,
7609b4de886SKip Macy 		0xccbb, 0x3011,
7619b4de886SKip Macy 		0xccbc, 0x1001,
7629b4de886SKip Macy 		0xccbd, 0xc620,
7639b4de886SKip Macy 		0xccbe, 0x14e5,
7649b4de886SKip Macy 		0xccbf, 0xc621,
7659b4de886SKip Macy 		0xccc0, 0xc53d,
7669b4de886SKip Macy 		0xccc1, 0xc622,
7679b4de886SKip Macy 		0xccc2, 0x3cbe,
7689b4de886SKip Macy 		0xccc3, 0xc623,
7699b4de886SKip Macy 		0xccc4, 0x4452,
7709b4de886SKip Macy 		0xccc5, 0xc624,
7719b4de886SKip Macy 		0xccc6, 0xc5c5,
7729b4de886SKip Macy 		0xccc7, 0xc625,
7739b4de886SKip Macy 		0xccc8, 0xe01e,
7749b4de886SKip Macy 		0xccc9, 0xc627,
7759b4de886SKip Macy 		0xccca, 0x000,
7769b4de886SKip Macy 		0xcccb, 0xc628,
7779b4de886SKip Macy 		0xcccc, 0x000,
7789b4de886SKip Macy 		0xcccd, 0xc62b,
7799b4de886SKip Macy 		0xccce, 0x000,
7809b4de886SKip Macy 		0xcccf, 0xc62c,
7819b4de886SKip Macy 		0xccd0, 0x000,
7829b4de886SKip Macy 		0xccd1, 0x000,
7839b4de886SKip Macy 		0xccd2, 0x2d01,
7849b4de886SKip Macy 		0xccd3, 0x3011,
7859b4de886SKip Macy 		0xccd4, 0x1001,
7869b4de886SKip Macy 		0xccd5, 0xc620,
7879b4de886SKip Macy 		0xccd6, 0x000,
7889b4de886SKip Macy 		0xccd7, 0xc621,
7899b4de886SKip Macy 		0xccd8, 0x000,
7909b4de886SKip Macy 		0xccd9, 0xc622,
7919b4de886SKip Macy 		0xccda, 0x0ce,
7929b4de886SKip Macy 		0xccdb, 0xc623,
7939b4de886SKip Macy 		0xccdc, 0x07f,
7949b4de886SKip Macy 		0xccdd, 0xc624,
7959b4de886SKip Macy 		0xccde, 0x032,
7969b4de886SKip Macy 		0xccdf, 0xc625,
7979b4de886SKip Macy 		0xcce0, 0x000,
7989b4de886SKip Macy 		0xcce1, 0xc627,
7999b4de886SKip Macy 		0xcce2, 0x000,
8009b4de886SKip Macy 		0xcce3, 0xc628,
8019b4de886SKip Macy 		0xcce4, 0x000,
8029b4de886SKip Macy 		0xcce5, 0xc62b,
8039b4de886SKip Macy 		0xcce6, 0x000,
8049b4de886SKip Macy 		0xcce7, 0xc62c,
8059b4de886SKip Macy 		0xcce8, 0x000,
8069b4de886SKip Macy 		0xcce9, 0x000,
8079b4de886SKip Macy 		0xccea, 0x2d01,
8089b4de886SKip Macy 		0xcceb, 0x3011,
8099b4de886SKip Macy 		0xccec, 0x1001,
8109b4de886SKip Macy 		0xcced, 0xc502,
8119b4de886SKip Macy 		0xccee, 0x609f,
8129b4de886SKip Macy 		0xccef, 0xc600,
8139b4de886SKip Macy 		0xccf0, 0x2a6e,
8149b4de886SKip Macy 		0xccf1, 0xc601,
8159b4de886SKip Macy 		0xccf2, 0x2a2c,
8169b4de886SKip Macy 		0xccf3, 0xc60c,
8179b4de886SKip Macy 		0xccf4, 0x5400,
8189b4de886SKip Macy 		0xccf5, 0xc710,
8199b4de886SKip Macy 		0xccf6, 0x700,
8209b4de886SKip Macy 		0xccf7, 0xc718,
8219b4de886SKip Macy 		0xccf8, 0x700,
8229b4de886SKip Macy 		0xccf9, 0xc720,
8239b4de886SKip Macy 		0xccfa, 0x4700,
8249b4de886SKip Macy 		0xccfb, 0xc728,
8259b4de886SKip Macy 		0xccfc, 0x700,
8269b4de886SKip Macy 		0xccfd, 0xc729,
8279b4de886SKip Macy 		0xccfe, 0x1207,
8289b4de886SKip Macy 		0xccff, 0xc801,
8299b4de886SKip Macy 		0xcd00, 0x7f50,
8309b4de886SKip Macy 		0xcd01, 0xc802,
8319b4de886SKip Macy 		0xcd02, 0x7760,
8329b4de886SKip Macy 		0xcd03, 0xc803,
8339b4de886SKip Macy 		0xcd04, 0x7fce,
8349b4de886SKip Macy 		0xcd05, 0xc804,
8359b4de886SKip Macy 		0xcd06, 0x520e,
8369b4de886SKip Macy 		0xcd07, 0xc805,
8379b4de886SKip Macy 		0xcd08, 0x5c11,
8389b4de886SKip Macy 		0xcd09, 0xc806,
8399b4de886SKip Macy 		0xcd0a, 0x3c51,
8409b4de886SKip Macy 		0xcd0b, 0xc807,
8419b4de886SKip Macy 		0xcd0c, 0x4061,
8429b4de886SKip Macy 		0xcd0d, 0xc808,
8439b4de886SKip Macy 		0xcd0e, 0x49c1,
8449b4de886SKip Macy 		0xcd0f, 0xc809,
8459b4de886SKip Macy 		0xcd10, 0x3840,
8469b4de886SKip Macy 		0xcd11, 0xc80a,
8479b4de886SKip Macy 		0xcd12, 0x000,
8489b4de886SKip Macy 		0xcd13, 0xc821,
8499b4de886SKip Macy 		0xcd14, 0x002,
8509b4de886SKip Macy 		0xcd15, 0xc822,
8519b4de886SKip Macy 		0xcd16, 0x046,
8529b4de886SKip Macy 		0xcd17, 0xc844,
8539b4de886SKip Macy 		0xcd18, 0x182f,
8549b4de886SKip Macy 		0xcd19, 0xc013,
8559b4de886SKip Macy 		0xcd1a, 0xf341,
8569b4de886SKip Macy 		0xcd1b, 0xc01a,
8579b4de886SKip Macy 		0xcd1c, 0x446,
8589b4de886SKip Macy 		0xcd1d, 0xc024,
8599b4de886SKip Macy 		0xcd1e, 0x1000,
8609b4de886SKip Macy 		0xcd1f, 0xc025,
8619b4de886SKip Macy 		0xcd20, 0xa00,
8629b4de886SKip Macy 		0xcd21, 0xc026,
8639b4de886SKip Macy 		0xcd22, 0xc0c,
8649b4de886SKip Macy 		0xcd23, 0xc027,
8659b4de886SKip Macy 		0xcd24, 0xc0c,
8669b4de886SKip Macy 		0xcd25, 0xc029,
8679b4de886SKip Macy 		0xcd26, 0x0a0,
8689b4de886SKip Macy 		0xcd27, 0xc030,
8699b4de886SKip Macy 		0xcd28, 0xa00,
8709b4de886SKip Macy 		0xcd29, 0xc03c,
8719b4de886SKip Macy 		0xcd2a, 0x01c,
8729b4de886SKip Macy 		0xcd2b, 0x000,
8739b4de886SKip Macy 		0xcd2c, 0x2b84,
8749b4de886SKip Macy 		0xcd2d, 0x3c74,
8759b4de886SKip Macy 		0xcd2e, 0x6435,
8769b4de886SKip Macy 		0xcd2f, 0xdff4,
8779b4de886SKip Macy 		0xcd30, 0x6435,
8789b4de886SKip Macy 		0xcd31, 0x2806,
8799b4de886SKip Macy 		0xcd32, 0x3006,
8809b4de886SKip Macy 		0xcd33, 0x8565,
8819b4de886SKip Macy 		0xcd34, 0x2b24,
8829b4de886SKip Macy 		0xcd35, 0x3c24,
8839b4de886SKip Macy 		0xcd36, 0x6436,
8849b4de886SKip Macy 		0xcd37, 0x1002,
8859b4de886SKip Macy 		0xcd38, 0x2b24,
8869b4de886SKip Macy 		0xcd39, 0x3c24,
8879b4de886SKip Macy 		0xcd3a, 0x6436,
8889b4de886SKip Macy 		0xcd3b, 0x4045,
8899b4de886SKip Macy 		0xcd3c, 0x8656,
8909b4de886SKip Macy 		0xcd3d, 0x1002,
8919b4de886SKip Macy 		0xcd3e, 0x2807,
8929b4de886SKip Macy 		0xcd3f, 0x31a7,
8939b4de886SKip Macy 		0xcd40, 0x20c4,
8949b4de886SKip Macy 		0xcd41, 0x3c24,
8959b4de886SKip Macy 		0xcd42, 0x6724,
8969b4de886SKip Macy 		0xcd43, 0x1002,
8979b4de886SKip Macy 		0xcd44, 0x2807,
8989b4de886SKip Macy 		0xcd45, 0x3187,
8999b4de886SKip Macy 		0xcd46, 0x20c4,
9009b4de886SKip Macy 		0xcd47, 0x3c24,
9019b4de886SKip Macy 		0xcd48, 0x6724,
9029b4de886SKip Macy 		0xcd49, 0x1002,
9039b4de886SKip Macy 		0xcd4a, 0x2514,
9049b4de886SKip Macy 		0xcd4b, 0x3c64,
9059b4de886SKip Macy 		0xcd4c, 0x6436,
9069b4de886SKip Macy 		0xcd4d, 0xdff4,
9079b4de886SKip Macy 		0xcd4e, 0x6436,
9089b4de886SKip Macy 		0xcd4f, 0x1002,
9099b4de886SKip Macy 		0xcd50, 0x2806,
9109b4de886SKip Macy 		0xcd51, 0x3cb6,
9119b4de886SKip Macy 		0xcd52, 0xc161,
9129b4de886SKip Macy 		0xcd53, 0x6134,
9139b4de886SKip Macy 		0xcd54, 0x6135,
9149b4de886SKip Macy 		0xcd55, 0x5443,
9159b4de886SKip Macy 		0xcd56, 0x303,
9169b4de886SKip Macy 		0xcd57, 0x6524,
9179b4de886SKip Macy 		0xcd58, 0x00b,
9189b4de886SKip Macy 		0xcd59, 0x1002,
9199b4de886SKip Macy 		0xcd5a, 0xd019,
9209b4de886SKip Macy 		0xcd5b, 0x2104,
9219b4de886SKip Macy 		0xcd5c, 0x3c24,
9229b4de886SKip Macy 		0xcd5d, 0x2105,
9239b4de886SKip Macy 		0xcd5e, 0x3805,
9249b4de886SKip Macy 		0xcd5f, 0x6524,
9259b4de886SKip Macy 		0xcd60, 0xdff4,
9269b4de886SKip Macy 		0xcd61, 0x4005,
9279b4de886SKip Macy 		0xcd62, 0x6524,
9289b4de886SKip Macy 		0xcd63, 0x2e8d,
9299b4de886SKip Macy 		0xcd64, 0x303d,
9309b4de886SKip Macy 		0xcd65, 0x5dd3,
9319b4de886SKip Macy 		0xcd66, 0x306,
9329b4de886SKip Macy 		0xcd67, 0x2ff7,
9339b4de886SKip Macy 		0xcd68, 0x38f7,
9349b4de886SKip Macy 		0xcd69, 0x60b7,
9359b4de886SKip Macy 		0xcd6a, 0xdffd,
9369b4de886SKip Macy 		0xcd6b, 0x00a,
9379b4de886SKip Macy 		0xcd6c, 0x1002,
9389b4de886SKip Macy 		0xcd6d, 0
9399b4de886SKip Macy 	};
9409b4de886SKip Macy 	int i, err;
9419b4de886SKip Macy 
9429b4de886SKip Macy 	err = set_phy_regs(phy, regs);
9439b4de886SKip Macy 	if (!err && modtype == phy_modtype_twinax_long)
9449b4de886SKip Macy 		err = set_phy_regs(phy, preemphasis);
9459b4de886SKip Macy 	if (err)
9469b4de886SKip Macy 		return err;
9479b4de886SKip Macy 
9489b4de886SKip Macy 	msleep(50);
9499b4de886SKip Macy 
9509b4de886SKip Macy 	for (i = 0; i < ARRAY_SIZE(twinax_edc) && !err; i += 2)
9519b4de886SKip Macy 		err = mdio_write(phy, MDIO_DEV_PMA_PMD, twinax_edc[i],
9529b4de886SKip Macy 				 twinax_edc[i + 1]);
9539b4de886SKip Macy 	if (!err)
9549b4de886SKip Macy 		phy->priv = edc_twinax;
9559b4de886SKip Macy 	return err;
9569b4de886SKip Macy }
9579b4de886SKip Macy 
9589b4de886SKip Macy static int ael2005_i2c_rd(struct cphy *phy, int dev_addr, int word_addr)
9599b4de886SKip Macy {
9609b4de886SKip Macy 	int i, err;
9619b4de886SKip Macy 	unsigned int stat, data;
9629b4de886SKip Macy 
9639b4de886SKip Macy 	err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL_I2C_CTRL,
9649b4de886SKip Macy 			 (dev_addr << 8) | (1 << 8) | word_addr);
9659b4de886SKip Macy 	if (err)
9669b4de886SKip Macy 		return err;
9679b4de886SKip Macy 
9689b4de886SKip Macy 	for (i = 0; i < 5; i++) {
9699b4de886SKip Macy 		msleep(1);
9709b4de886SKip Macy 		err = mdio_read(phy, MDIO_DEV_PMA_PMD, AEL_I2C_STAT, &stat);
9719b4de886SKip Macy 		if (err)
9729b4de886SKip Macy 			return err;
9739b4de886SKip Macy 		if ((stat & 3) == 1) {
9749b4de886SKip Macy 			err = mdio_read(phy, MDIO_DEV_PMA_PMD, AEL_I2C_DATA,
9759b4de886SKip Macy 					&data);
9769b4de886SKip Macy 			if (err)
9779b4de886SKip Macy 				return err;
9789b4de886SKip Macy 			return data >> 8;
9799b4de886SKip Macy 		}
9809b4de886SKip Macy 	}
9819b4de886SKip Macy 	CH_WARN(phy->adapter, "PHY %u I2C read of addr %u timed out\n",
9829b4de886SKip Macy 		phy->addr, word_addr);
9839b4de886SKip Macy 	return -ETIMEDOUT;
9849b4de886SKip Macy }
9859b4de886SKip Macy 
9869b4de886SKip Macy static int get_module_type(struct cphy *phy, int delay_ms)
9879b4de886SKip Macy {
9889b4de886SKip Macy 	int v;
9899b4de886SKip Macy 	unsigned int stat;
9909b4de886SKip Macy 
9919b4de886SKip Macy 	v = mdio_read(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_CTRL, &stat);
9929b4de886SKip Macy 	if (v)
9939b4de886SKip Macy 		return v;
9949b4de886SKip Macy 
9959b4de886SKip Macy 	if (stat & (1 << 8))			/* module absent */
9969b4de886SKip Macy 		return phy_modtype_none;
9979b4de886SKip Macy 
9989b4de886SKip Macy 	if (delay_ms)
9999b4de886SKip Macy 		msleep(delay_ms);
10009b4de886SKip Macy 
10019b4de886SKip Macy 	/* see SFF-8472 for below */
10029b4de886SKip Macy 	v = ael2005_i2c_rd(phy, MODULE_DEV_ADDR, 3);
10039b4de886SKip Macy 	if (v < 0)
10049b4de886SKip Macy 		return v;
10059b4de886SKip Macy 
10069b4de886SKip Macy 	if (v == 0x10)
10079b4de886SKip Macy 		return phy_modtype_sr;
10089b4de886SKip Macy 	if (v == 0x20)
10099b4de886SKip Macy 		return phy_modtype_lr;
10109b4de886SKip Macy 	if (v == 0x40)
10119b4de886SKip Macy 		return phy_modtype_lrm;
10129b4de886SKip Macy 
10139b4de886SKip Macy 	v = ael2005_i2c_rd(phy, MODULE_DEV_ADDR, 6);
10149b4de886SKip Macy 	if (v < 0)
10159b4de886SKip Macy 		return v;
10169b4de886SKip Macy 	if (v != 4)
10179b4de886SKip Macy 		goto unknown;
10189b4de886SKip Macy 
10199b4de886SKip Macy 	v = ael2005_i2c_rd(phy, MODULE_DEV_ADDR, 10);
10209b4de886SKip Macy 	if (v < 0)
10219b4de886SKip Macy 		return v;
10229b4de886SKip Macy 
10239b4de886SKip Macy 	if (v & 0x80) {
10249b4de886SKip Macy 		v = ael2005_i2c_rd(phy, MODULE_DEV_ADDR, 0x12);
10259b4de886SKip Macy 		if (v < 0)
10269b4de886SKip Macy 			return v;
10279b4de886SKip Macy 		return v > 10 ? phy_modtype_twinax_long : phy_modtype_twinax;
10289b4de886SKip Macy 	}
10299b4de886SKip Macy unknown:
10309b4de886SKip Macy 	return phy_modtype_unknown;
10319b4de886SKip Macy }
10329b4de886SKip Macy 
10339b4de886SKip Macy static int ael2005_intr_enable(struct cphy *phy)
10349b4de886SKip Macy {
10359b4de886SKip Macy 	int err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_CTRL, 0x200);
10369b4de886SKip Macy 	return err ? err : t3_phy_lasi_intr_enable(phy);
10379b4de886SKip Macy }
10389b4de886SKip Macy 
10399b4de886SKip Macy static int ael2005_intr_disable(struct cphy *phy)
10409b4de886SKip Macy {
10419b4de886SKip Macy 	int err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_CTRL, 0x100);
10429b4de886SKip Macy 	return err ? err : t3_phy_lasi_intr_disable(phy);
10439b4de886SKip Macy }
10449b4de886SKip Macy 
10459b4de886SKip Macy static int ael2005_intr_clear(struct cphy *phy)
10469b4de886SKip Macy {
10479b4de886SKip Macy 	int err = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_CTRL, 0xd00);
10489b4de886SKip Macy 	return err ? err : t3_phy_lasi_intr_clear(phy);
10499b4de886SKip Macy }
10509b4de886SKip Macy 
10514af83c8cSKip Macy static int ael2005_reset(struct cphy *phy, int wait)
10524af83c8cSKip Macy {
10534af83c8cSKip Macy 	static struct reg_val regs0[] = {
10544af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc001, 0, 1 << 5 },
10554af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc017, 0, 1 << 5 },
10564af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc013, 0xffff, 0xf341 },
10574af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc210, 0xffff, 0x8000 },
10584af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc210, 0xffff, 0x8100 },
10594af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc210, 0xffff, 0x8000 },
10604af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xc210, 0xffff, 0 },
10614af83c8cSKip Macy 		{ 0, 0, 0, 0 }
10624af83c8cSKip Macy 	};
10634af83c8cSKip Macy 	static struct reg_val regs1[] = {
10644af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xca00, 0xffff, 0x0080 },
10654af83c8cSKip Macy 		{ MDIO_DEV_PMA_PMD, 0xca12, 0xffff, 0 },
10664af83c8cSKip Macy 		{ 0, 0, 0, 0 }
10674af83c8cSKip Macy 	};
10684af83c8cSKip Macy 
10699b4de886SKip Macy 	int err, lasi_ctrl;
10709b4de886SKip Macy 
10719b4de886SKip Macy 	err = mdio_read(phy, MDIO_DEV_PMA_PMD, LASI_CTRL, &lasi_ctrl);
10729b4de886SKip Macy 	if (err)
10739b4de886SKip Macy 		return err;
10744af83c8cSKip Macy 
10754af83c8cSKip Macy 	err = t3_phy_reset(phy, MDIO_DEV_PMA_PMD, 0);
10764af83c8cSKip Macy 	if (err)
10774af83c8cSKip Macy 		return err;
10784af83c8cSKip Macy 
10794af83c8cSKip Macy 	msleep(125);
10809b4de886SKip Macy 	phy->priv = edc_none;
10814af83c8cSKip Macy 	err = set_phy_regs(phy, regs0);
10824af83c8cSKip Macy 	if (err)
10834af83c8cSKip Macy 		return err;
10844af83c8cSKip Macy 
10854af83c8cSKip Macy 	msleep(50);
10864af83c8cSKip Macy 
10879b4de886SKip Macy 	err = get_module_type(phy, 0);
10889b4de886SKip Macy 	if (err < 0)
10899b4de886SKip Macy 		return err;
10909b4de886SKip Macy 	phy->modtype = (u8)err;
10919b4de886SKip Macy 
10929b4de886SKip Macy 	if (err == phy_modtype_twinax || err == phy_modtype_twinax_long)
10939b4de886SKip Macy 		err = ael2005_setup_twinax_edc(phy, err);
10949b4de886SKip Macy 	else
10954af83c8cSKip Macy 		err = ael2005_setup_sr_edc(phy);
10964af83c8cSKip Macy 	if (err)
10974af83c8cSKip Macy 		return err;
10984af83c8cSKip Macy 
10999b4de886SKip Macy 	err = set_phy_regs(phy, regs1);
11009b4de886SKip Macy 	if (err)
11019b4de886SKip Macy 		return err;
11029b4de886SKip Macy 
11039b4de886SKip Macy 	/* reset wipes out interrupts, reenable them if they were on */
11049b4de886SKip Macy 	if (lasi_ctrl & 1)
11059b4de886SKip Macy 		err = ael2005_intr_enable(phy);
11069b4de886SKip Macy 	return err;
11079b4de886SKip Macy }
11089b4de886SKip Macy 
11099b4de886SKip Macy static int ael2005_intr_handler(struct cphy *phy)
11109b4de886SKip Macy {
11119b4de886SKip Macy 	unsigned int stat;
11129b4de886SKip Macy 	int ret, edc_needed, cause = 0;
11139b4de886SKip Macy 
11149b4de886SKip Macy 	ret = mdio_read(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_STAT, &stat);
11159b4de886SKip Macy 	if (ret)
11169b4de886SKip Macy 		return ret;
11179b4de886SKip Macy 
11189b4de886SKip Macy 	if (stat & AEL2005_MODDET_IRQ) {
11199b4de886SKip Macy 		ret = mdio_write(phy, MDIO_DEV_PMA_PMD, AEL2005_GPIO_CTRL,
11209b4de886SKip Macy 				 0xd00);
11219b4de886SKip Macy 		if (ret)
11229b4de886SKip Macy 			return ret;
11239b4de886SKip Macy 
11249b4de886SKip Macy 		/* modules have max 300 ms init time after hot plug */
11259b4de886SKip Macy 		ret = get_module_type(phy, 300);
11269b4de886SKip Macy 		if (ret < 0)
11279b4de886SKip Macy 			return ret;
11289b4de886SKip Macy 
11299b4de886SKip Macy 		phy->modtype = (u8)ret;
11309b4de886SKip Macy 		if (ret == phy_modtype_none)
11319b4de886SKip Macy 			edc_needed = phy->priv;       /* on unplug retain EDC */
11329b4de886SKip Macy 		else if (ret == phy_modtype_twinax ||
11339b4de886SKip Macy 			 ret == phy_modtype_twinax_long)
11349b4de886SKip Macy 			edc_needed = edc_twinax;
11359b4de886SKip Macy 		else
11369b4de886SKip Macy 			edc_needed = edc_sr;
11379b4de886SKip Macy 
11389b4de886SKip Macy 		if (edc_needed != phy->priv) {
11399b4de886SKip Macy 			ret = ael2005_reset(phy, 0);
11409b4de886SKip Macy 			return ret ? ret : cphy_cause_module_change;
11419b4de886SKip Macy 		}
11429b4de886SKip Macy 		cause = cphy_cause_module_change;
11439b4de886SKip Macy 	}
11449b4de886SKip Macy 
11459b4de886SKip Macy 	ret = t3_phy_lasi_intr_handler(phy);
11469b4de886SKip Macy 	return ret < 0 ? ret : ret + cause;
11474af83c8cSKip Macy }
11484af83c8cSKip Macy 
11494af83c8cSKip Macy #ifdef C99_NOT_SUPPORTED
11504af83c8cSKip Macy static struct cphy_ops ael2005_ops = {
11514af83c8cSKip Macy 	ael2005_reset,
11529b4de886SKip Macy 	ael2005_intr_enable,
11539b4de886SKip Macy 	ael2005_intr_disable,
11549b4de886SKip Macy 	ael2005_intr_clear,
11559b4de886SKip Macy 	ael2005_intr_handler,
11564af83c8cSKip Macy 	NULL,
11574af83c8cSKip Macy 	NULL,
11584af83c8cSKip Macy 	NULL,
11594af83c8cSKip Macy 	NULL,
11604af83c8cSKip Macy 	NULL,
11619b4de886SKip Macy 	get_link_status_r,
11624af83c8cSKip Macy 	ael1002_power_down,
11634af83c8cSKip Macy };
11644af83c8cSKip Macy #else
11654af83c8cSKip Macy static struct cphy_ops ael2005_ops = {
11664af83c8cSKip Macy 	.reset           = ael2005_reset,
11679b4de886SKip Macy 	.intr_enable     = ael2005_intr_enable,
11689b4de886SKip Macy 	.intr_disable    = ael2005_intr_disable,
11699b4de886SKip Macy 	.intr_clear      = ael2005_intr_clear,
11709b4de886SKip Macy 	.intr_handler    = ael2005_intr_handler,
11719b4de886SKip Macy 	.get_link_status = get_link_status_r,
11724af83c8cSKip Macy 	.power_down      = ael1002_power_down,
11734af83c8cSKip Macy };
11744af83c8cSKip Macy #endif
11754af83c8cSKip Macy 
11764af83c8cSKip Macy int t3_ael2005_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr,
11774af83c8cSKip Macy 			const struct mdio_ops *mdio_ops)
11784af83c8cSKip Macy {
11794af83c8cSKip Macy 	cphy_init(phy, adapter, phy_addr, &ael2005_ops, mdio_ops,
11809b4de886SKip Macy 		  SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_FIBRE |
11819b4de886SKip Macy 		  SUPPORTED_IRQ, "10GBASE-R");
11824af83c8cSKip Macy 	msleep(125);
11834af83c8cSKip Macy 	return t3_mdio_change_bits(phy, MDIO_DEV_PMA_PMD, AEL_OPT_SETTINGS, 0,
11844af83c8cSKip Macy 				   1 << 5);
11854af83c8cSKip Macy }
11864af83c8cSKip Macy 
11879b4de886SKip Macy /*
11889b4de886SKip Macy  * Get link status for a 10GBASE-X device.
11899b4de886SKip Macy  */
11909b4de886SKip Macy static int get_link_status_x(struct cphy *phy, int *link_ok, int *speed,
11919b4de886SKip Macy 			     int *duplex, int *fc)
11929b4de886SKip Macy {
11939b4de886SKip Macy 	if (link_ok) {
11949b4de886SKip Macy 		unsigned int stat0, stat1, stat2;
11959b4de886SKip Macy 		int err = mdio_read(phy, MDIO_DEV_PMA_PMD, PMD_RSD, &stat0);
11969b4de886SKip Macy 
11979b4de886SKip Macy 		if (!err)
11989b4de886SKip Macy 			err = mdio_read(phy, MDIO_DEV_PCS, PCS_STAT1_X, &stat1);
11999b4de886SKip Macy 		if (!err)
12009b4de886SKip Macy 			err = mdio_read(phy, MDIO_DEV_XGXS, XS_LN_STAT, &stat2);
12019b4de886SKip Macy 		if (err)
12029b4de886SKip Macy 			return err;
12039b4de886SKip Macy 		*link_ok = (stat0 & (stat1 >> 12) & (stat2 >> 12)) & 1;
12049b4de886SKip Macy 	}
12059b4de886SKip Macy 	if (speed)
12069b4de886SKip Macy 		*speed = SPEED_10000;
12079b4de886SKip Macy 	if (duplex)
12089b4de886SKip Macy 		*duplex = DUPLEX_FULL;
12099b4de886SKip Macy 	return 0;
12109b4de886SKip Macy }
12119b4de886SKip Macy 
1212b6d90eb7SKip Macy #ifdef C99_NOT_SUPPORTED
1213b6d90eb7SKip Macy static struct cphy_ops qt2045_ops = {
1214b6d90eb7SKip Macy 	ael1006_reset,
12154af83c8cSKip Macy 	t3_phy_lasi_intr_enable,
12164af83c8cSKip Macy 	t3_phy_lasi_intr_disable,
12174af83c8cSKip Macy 	t3_phy_lasi_intr_clear,
12184af83c8cSKip Macy 	t3_phy_lasi_intr_handler,
1219b6d90eb7SKip Macy 	NULL,
1220b6d90eb7SKip Macy 	NULL,
1221b6d90eb7SKip Macy 	NULL,
1222b6d90eb7SKip Macy 	NULL,
1223b6d90eb7SKip Macy 	NULL,
12249b4de886SKip Macy 	get_link_status_x,
1225b6d90eb7SKip Macy 	ael1006_power_down,
1226b6d90eb7SKip Macy };
1227b6d90eb7SKip Macy #else
1228b6d90eb7SKip Macy static struct cphy_ops qt2045_ops = {
1229b6d90eb7SKip Macy 	.reset           = ael1006_reset,
12304af83c8cSKip Macy 	.intr_enable     = t3_phy_lasi_intr_enable,
12314af83c8cSKip Macy 	.intr_disable    = t3_phy_lasi_intr_disable,
12324af83c8cSKip Macy 	.intr_clear      = t3_phy_lasi_intr_clear,
12334af83c8cSKip Macy 	.intr_handler    = t3_phy_lasi_intr_handler,
12349b4de886SKip Macy 	.get_link_status = get_link_status_x,
1235b6d90eb7SKip Macy 	.power_down      = ael1006_power_down,
1236b6d90eb7SKip Macy };
1237b6d90eb7SKip Macy #endif
1238b6d90eb7SKip Macy 
12398e10660fSKip Macy int t3_qt2045_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr,
1240b6d90eb7SKip Macy 		       const struct mdio_ops *mdio_ops)
1241b6d90eb7SKip Macy {
1242b6d90eb7SKip Macy 	unsigned int stat;
1243b6d90eb7SKip Macy 
12448e10660fSKip Macy 	cphy_init(phy, adapter, phy_addr, &qt2045_ops, mdio_ops,
12458e10660fSKip Macy 		  SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
12468e10660fSKip Macy 		  "10GBASE-CX4");
1247b6d90eb7SKip Macy 
1248b6d90eb7SKip Macy 	/*
1249b6d90eb7SKip Macy 	 * Some cards where the PHY is supposed to be at address 0 actually
1250b6d90eb7SKip Macy 	 * have it at 1.
1251b6d90eb7SKip Macy 	 */
1252b6d90eb7SKip Macy 	if (!phy_addr && !mdio_read(phy, MDIO_DEV_PMA_PMD, MII_BMSR, &stat) &&
1253b6d90eb7SKip Macy 	    stat == 0xffff)
1254b6d90eb7SKip Macy 		phy->addr = 1;
12558e10660fSKip Macy 	return 0;
1256b6d90eb7SKip Macy }
1257b6d90eb7SKip Macy 
1258b6d90eb7SKip Macy static int xaui_direct_reset(struct cphy *phy, int wait)
1259b6d90eb7SKip Macy {
1260b6d90eb7SKip Macy 	return 0;
1261b6d90eb7SKip Macy }
1262b6d90eb7SKip Macy 
1263b6d90eb7SKip Macy static int xaui_direct_get_link_status(struct cphy *phy, int *link_ok,
1264b6d90eb7SKip Macy 				       int *speed, int *duplex, int *fc)
1265b6d90eb7SKip Macy {
1266b6d90eb7SKip Macy 	if (link_ok) {
1267b6d90eb7SKip Macy 		unsigned int status;
1268b6d90eb7SKip Macy 
1269b6d90eb7SKip Macy 		status = t3_read_reg(phy->adapter,
1270ef72318fSKip Macy 				     XGM_REG(A_XGM_SERDES_STAT0, phy->addr)) |
1271ef72318fSKip Macy 			 t3_read_reg(phy->adapter,
1272ef72318fSKip Macy 				     XGM_REG(A_XGM_SERDES_STAT1, phy->addr)) |
1273ef72318fSKip Macy 			 t3_read_reg(phy->adapter,
1274ef72318fSKip Macy 				     XGM_REG(A_XGM_SERDES_STAT2, phy->addr)) |
1275ef72318fSKip Macy 			 t3_read_reg(phy->adapter,
1276ef72318fSKip Macy 				     XGM_REG(A_XGM_SERDES_STAT3, phy->addr));
1277b6d90eb7SKip Macy 		*link_ok = !(status & F_LOWSIG0);
1278b6d90eb7SKip Macy 	}
1279b6d90eb7SKip Macy 	if (speed)
1280b6d90eb7SKip Macy 		*speed = SPEED_10000;
1281b6d90eb7SKip Macy 	if (duplex)
1282b6d90eb7SKip Macy 		*duplex = DUPLEX_FULL;
1283b6d90eb7SKip Macy 	return 0;
1284b6d90eb7SKip Macy }
1285b6d90eb7SKip Macy 
1286b6d90eb7SKip Macy static int xaui_direct_power_down(struct cphy *phy, int enable)
1287b6d90eb7SKip Macy {
1288b6d90eb7SKip Macy 	return 0;
1289b6d90eb7SKip Macy }
1290b6d90eb7SKip Macy 
1291b6d90eb7SKip Macy #ifdef C99_NOT_SUPPORTED
1292b6d90eb7SKip Macy static struct cphy_ops xaui_direct_ops = {
1293b6d90eb7SKip Macy 	xaui_direct_reset,
1294b6d90eb7SKip Macy 	ael1002_intr_noop,
1295b6d90eb7SKip Macy 	ael1002_intr_noop,
1296b6d90eb7SKip Macy 	ael1002_intr_noop,
1297b6d90eb7SKip Macy 	ael1002_intr_noop,
1298b6d90eb7SKip Macy 	NULL,
1299b6d90eb7SKip Macy 	NULL,
1300b6d90eb7SKip Macy 	NULL,
1301b6d90eb7SKip Macy 	NULL,
1302b6d90eb7SKip Macy 	NULL,
1303b6d90eb7SKip Macy 	xaui_direct_get_link_status,
1304b6d90eb7SKip Macy 	xaui_direct_power_down,
1305b6d90eb7SKip Macy };
1306b6d90eb7SKip Macy #else
1307b6d90eb7SKip Macy static struct cphy_ops xaui_direct_ops = {
1308b6d90eb7SKip Macy 	.reset           = xaui_direct_reset,
1309b6d90eb7SKip Macy 	.intr_enable     = ael1002_intr_noop,
1310b6d90eb7SKip Macy 	.intr_disable    = ael1002_intr_noop,
1311b6d90eb7SKip Macy 	.intr_clear      = ael1002_intr_noop,
1312b6d90eb7SKip Macy 	.intr_handler    = ael1002_intr_noop,
1313b6d90eb7SKip Macy 	.get_link_status = xaui_direct_get_link_status,
1314b6d90eb7SKip Macy 	.power_down      = xaui_direct_power_down,
1315b6d90eb7SKip Macy };
1316b6d90eb7SKip Macy #endif
1317b6d90eb7SKip Macy 
13188e10660fSKip Macy int t3_xaui_direct_phy_prep(struct cphy *phy, adapter_t *adapter, int phy_addr,
1319b6d90eb7SKip Macy 			    const struct mdio_ops *mdio_ops)
1320b6d90eb7SKip Macy {
13218e10660fSKip Macy 	cphy_init(phy, adapter, phy_addr, &xaui_direct_ops, mdio_ops,
13228e10660fSKip Macy 		  SUPPORTED_10000baseT_Full | SUPPORTED_AUI | SUPPORTED_TP,
13238e10660fSKip Macy 		  "10GBASE-CX4");
13248e10660fSKip Macy 	return 0;
1325b6d90eb7SKip Macy }
1326