xref: /rk3399_ARM-atf/drivers/marvell/comphy/phy-comphy-3700.c (revision 9554a186a76938f4f075138cdc570065624f2e50)
16f8de19fSKonstantin Porotchkin /*
2c9f138ebSMarek Behún  * Copyright (C) 2018-2021 Marvell International Ltd.
36f8de19fSKonstantin Porotchkin  *
46f8de19fSKonstantin Porotchkin  * SPDX-License-Identifier:     BSD-3-Clause
56f8de19fSKonstantin Porotchkin  * https://spdx.org/licenses
66f8de19fSKonstantin Porotchkin  */
76f8de19fSKonstantin Porotchkin 
86f8de19fSKonstantin Porotchkin #include <errno.h>
909d40e0eSAntonio Nino Diaz 
1009d40e0eSAntonio Nino Diaz #include <common/debug.h>
1109d40e0eSAntonio Nino Diaz #include <drivers/delay_timer.h>
1209d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1309d40e0eSAntonio Nino Diaz #include <lib/spinlock.h>
1409d40e0eSAntonio Nino Diaz 
156f8de19fSKonstantin Porotchkin #include <mvebu.h>
166f8de19fSKonstantin Porotchkin #include <mvebu_def.h>
175a91c439SPali Rohár #include <plat_marvell.h>
1809d40e0eSAntonio Nino Diaz 
196f8de19fSKonstantin Porotchkin #include "phy-comphy-3700.h"
206f8de19fSKonstantin Porotchkin #include "phy-comphy-common.h"
216f8de19fSKonstantin Porotchkin 
226f8de19fSKonstantin Porotchkin /*
236f8de19fSKonstantin Porotchkin  * COMPHY_INDIRECT_REG points to ahci address space but the ahci region used in
246f8de19fSKonstantin Porotchkin  * Linux is up to 0x178 so none will access it from Linux in runtime
256f8de19fSKonstantin Porotchkin  * concurrently.
266f8de19fSKonstantin Porotchkin  */
276f8de19fSKonstantin Porotchkin #define COMPHY_INDIRECT_REG	(MVEBU_REGS_BASE + 0xE0178)
286f8de19fSKonstantin Porotchkin 
296f8de19fSKonstantin Porotchkin /* The USB3_GBE1_PHY range is above USB3 registers used in dts */
306f8de19fSKonstantin Porotchkin #define USB3_GBE1_PHY		(MVEBU_REGS_BASE + 0x5C000)
316f8de19fSKonstantin Porotchkin #define COMPHY_SD_ADDR		(MVEBU_REGS_BASE + 0x1F000)
326f8de19fSKonstantin Porotchkin 
336f8de19fSKonstantin Porotchkin struct sgmii_phy_init_data_fix {
346f8de19fSKonstantin Porotchkin 	uint16_t addr;
356f8de19fSKonstantin Porotchkin 	uint16_t value;
366f8de19fSKonstantin Porotchkin };
376f8de19fSKonstantin Porotchkin 
386f8de19fSKonstantin Porotchkin /* Changes to 40M1G25 mode data required for running 40M3G125 init mode */
396f8de19fSKonstantin Porotchkin static struct sgmii_phy_init_data_fix sgmii_phy_init_fix[] = {
406f8de19fSKonstantin Porotchkin 	{0x005, 0x07CC}, {0x015, 0x0000}, {0x01B, 0x0000}, {0x01D, 0x0000},
416f8de19fSKonstantin Porotchkin 	{0x01E, 0x0000}, {0x01F, 0x0000}, {0x020, 0x0000}, {0x021, 0x0030},
426f8de19fSKonstantin Porotchkin 	{0x026, 0x0888}, {0x04D, 0x0152}, {0x04F, 0xA020}, {0x050, 0x07CC},
436f8de19fSKonstantin Porotchkin 	{0x053, 0xE9CA}, {0x055, 0xBD97}, {0x071, 0x3015}, {0x076, 0x03AA},
446f8de19fSKonstantin Porotchkin 	{0x07C, 0x0FDF}, {0x0C2, 0x3030}, {0x0C3, 0x8000}, {0x0E2, 0x5550},
456f8de19fSKonstantin Porotchkin 	{0x0E3, 0x12A4}, {0x0E4, 0x7D00}, {0x0E6, 0x0C83}, {0x101, 0xFCC0},
466f8de19fSKonstantin Porotchkin 	{0x104, 0x0C10}
476f8de19fSKonstantin Porotchkin };
486f8de19fSKonstantin Porotchkin 
496f8de19fSKonstantin Porotchkin /* 40M1G25 mode init data */
506f8de19fSKonstantin Porotchkin static uint16_t sgmii_phy_init[512] = {
516f8de19fSKonstantin Porotchkin 	/* 0       1       2       3       4       5       6       7 */
526f8de19fSKonstantin Porotchkin 	/*-----------------------------------------------------------*/
536f8de19fSKonstantin Porotchkin 	/* 8       9       A       B       C       D       E       F */
546f8de19fSKonstantin Porotchkin 	0x3110, 0xFD83, 0x6430, 0x412F, 0x82C0, 0x06FA, 0x4500, 0x6D26,	/* 00 */
556f8de19fSKonstantin Porotchkin 	0xAFC0, 0x8000, 0xC000, 0x0000, 0x2000, 0x49CC, 0x0BC9, 0x2A52,	/* 08 */
566f8de19fSKonstantin Porotchkin 	0x0BD2, 0x0CDE, 0x13D2, 0x0CE8, 0x1149, 0x10E0, 0x0000, 0x0000,	/* 10 */
576f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x4134, 0x0D2D, 0xFFFF,	/* 18 */
586f8de19fSKonstantin Porotchkin 	0xFFE0, 0x4030, 0x1016, 0x0030, 0x0000, 0x0800, 0x0866, 0x0000,	/* 20 */
596f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,	/* 28 */
606f8de19fSKonstantin Porotchkin 	0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/* 30 */
616f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x000F, 0x6A62, 0x1988, 0x3100, 0x3100, 0x3100,	/* 38 */
626f8de19fSKonstantin Porotchkin 	0x3100, 0xA708, 0x2430, 0x0830, 0x1030, 0x4610, 0xFF00, 0xFF00,	/* 40 */
636f8de19fSKonstantin Porotchkin 	0x0060, 0x1000, 0x0400, 0x0040, 0x00F0, 0x0155, 0x1100, 0xA02A,	/* 48 */
646f8de19fSKonstantin Porotchkin 	0x06FA, 0x0080, 0xB008, 0xE3ED, 0x5002, 0xB592, 0x7A80, 0x0001,	/* 50 */
656f8de19fSKonstantin Porotchkin 	0x020A, 0x8820, 0x6014, 0x8054, 0xACAA, 0xFC88, 0x2A02, 0x45CF,	/* 58 */
666f8de19fSKonstantin Porotchkin 	0x000F, 0x1817, 0x2860, 0x064F, 0x0000, 0x0204, 0x1800, 0x6000,	/* 60 */
676f8de19fSKonstantin Porotchkin 	0x810F, 0x4F23, 0x4000, 0x4498, 0x0850, 0x0000, 0x000E, 0x1002,	/* 68 */
686f8de19fSKonstantin Porotchkin 	0x9D3A, 0x3009, 0xD066, 0x0491, 0x0001, 0x6AB0, 0x0399, 0x3780,	/* 70 */
696f8de19fSKonstantin Porotchkin 	0x0040, 0x5AC0, 0x4A80, 0x0000, 0x01DF, 0x0000, 0x0007, 0x0000,	/* 78 */
706f8de19fSKonstantin Porotchkin 	0x2D54, 0x00A1, 0x4000, 0x0100, 0xA20A, 0x0000, 0x0000, 0x0000,	/* 80 */
716f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x7400, 0x0E81, 0x1000, 0x1242, 0x0210,	/* 88 */
726f8de19fSKonstantin Porotchkin 	0x80DF, 0x0F1F, 0x2F3F, 0x4F5F, 0x6F7F, 0x0F1F, 0x2F3F, 0x4F5F,	/* 90 */
736f8de19fSKonstantin Porotchkin 	0x6F7F, 0x4BAD, 0x0000, 0x0000, 0x0800, 0x0000, 0x2400, 0xB651,	/* 98 */
746f8de19fSKonstantin Porotchkin 	0xC9E0, 0x4247, 0x0A24, 0x0000, 0xAF19, 0x1004, 0x0000, 0x0000,	/* A0 */
756f8de19fSKonstantin Porotchkin 	0x0000, 0x0013, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/* A8 */
766f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/* B0 */
776f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000,	/* B8 */
786f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x3010, 0xFA00, 0x0000, 0x0000, 0x0000, 0x0003,	/* C0 */
796f8de19fSKonstantin Porotchkin 	0x1618, 0x8200, 0x8000, 0x0400, 0x050F, 0x0000, 0x0000, 0x0000,	/* C8 */
806f8de19fSKonstantin Porotchkin 	0x4C93, 0x0000, 0x1000, 0x1120, 0x0010, 0x1242, 0x1242, 0x1E00,	/* D0 */
816f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x00F8, 0x0000, 0x0041, 0x0800, 0x0000,	/* D8 */
826f8de19fSKonstantin Porotchkin 	0x82A0, 0x572E, 0x2490, 0x14A9, 0x4E00, 0x0000, 0x0803, 0x0541,	/* E0 */
836f8de19fSKonstantin Porotchkin 	0x0C15, 0x0000, 0x0000, 0x0400, 0x2626, 0x0000, 0x0000, 0x4200,	/* E8 */
846f8de19fSKonstantin Porotchkin 	0x0000, 0xAA55, 0x1020, 0x0000, 0x0000, 0x5010, 0x0000, 0x0000,	/* F0 */
856f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x5000, 0x0000, 0x0000, 0x0000, 0x02F2, 0x0000,	/* F8 */
866f8de19fSKonstantin Porotchkin 	0x101F, 0xFDC0, 0x4000, 0x8010, 0x0110, 0x0006, 0x0000, 0x0000,	/*100 */
876f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*108 */
886f8de19fSKonstantin Porotchkin 	0x04CF, 0x0000, 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04C6, 0x0000,	/*110 */
896f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*118 */
906f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*120 */
916f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*128 */
926f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*130 */
936f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*138 */
946f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*140 */
956f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*148 */
966f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*150 */
976f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*158 */
986f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*160 */
996f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*168 */
1006f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*170 */
1016f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x00F0, 0x08A2, 0x3112, 0x0A14, 0x0000,	/*178 */
1026f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*180 */
1036f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*188 */
1046f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*190 */
1056f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*198 */
1066f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1A0 */
1076f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1A8 */
1086f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1B0 */
1096f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1B8 */
1106f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1C0 */
1116f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1C8 */
1126f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1D0 */
1136f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1D8 */
1146f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1E0 */
1156f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1E8 */
1166f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,	/*1F0 */
1176f8de19fSKonstantin Porotchkin 	0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000	/*1F8 */
1186f8de19fSKonstantin Porotchkin };
1196f8de19fSKonstantin Porotchkin 
1206f8de19fSKonstantin Porotchkin /* PHY selector configures with corresponding modes */
mvebu_a3700_comphy_set_phy_selector(uint8_t comphy_index,uint32_t comphy_mode)12149b664e7SPali Rohár static int mvebu_a3700_comphy_set_phy_selector(uint8_t comphy_index,
1226f8de19fSKonstantin Porotchkin 						uint32_t comphy_mode)
1236f8de19fSKonstantin Porotchkin {
1246f8de19fSKonstantin Porotchkin 	uint32_t reg;
1256f8de19fSKonstantin Porotchkin 	int mode = COMPHY_GET_MODE(comphy_mode);
1266f8de19fSKonstantin Porotchkin 
1276f8de19fSKonstantin Porotchkin 	reg = mmio_read_32(MVEBU_COMPHY_REG_BASE + COMPHY_SELECTOR_PHY_REG);
1286f8de19fSKonstantin Porotchkin 	switch (mode) {
1296f8de19fSKonstantin Porotchkin 	case (COMPHY_SATA_MODE):
1306f8de19fSKonstantin Porotchkin 		/* SATA must be in Lane2 */
1316f8de19fSKonstantin Porotchkin 		if (comphy_index == COMPHY_LANE2)
1326f8de19fSKonstantin Porotchkin 			reg &= ~COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
1336f8de19fSKonstantin Porotchkin 		else
1346f8de19fSKonstantin Porotchkin 			goto error;
1356f8de19fSKonstantin Porotchkin 		break;
1366f8de19fSKonstantin Porotchkin 
1376f8de19fSKonstantin Porotchkin 	case (COMPHY_SGMII_MODE):
138a669983cSPali Rohár 	case (COMPHY_2500BASEX_MODE):
1396f8de19fSKonstantin Porotchkin 		if (comphy_index == COMPHY_LANE0)
1406f8de19fSKonstantin Porotchkin 			reg &= ~COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
1416f8de19fSKonstantin Porotchkin 		else if (comphy_index == COMPHY_LANE1)
1426f8de19fSKonstantin Porotchkin 			reg &= ~COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
1436f8de19fSKonstantin Porotchkin 		else
1446f8de19fSKonstantin Porotchkin 			goto error;
1456f8de19fSKonstantin Porotchkin 		break;
1466f8de19fSKonstantin Porotchkin 
1476f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3H_MODE):
1486f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3D_MODE):
1496f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3_MODE):
1506f8de19fSKonstantin Porotchkin 		if (comphy_index == COMPHY_LANE2)
1516f8de19fSKonstantin Porotchkin 			reg |= COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
1526f8de19fSKonstantin Porotchkin 		else if (comphy_index == COMPHY_LANE0)
1536f8de19fSKonstantin Porotchkin 			reg |= COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
1546f8de19fSKonstantin Porotchkin 		else
1556f8de19fSKonstantin Porotchkin 			goto error;
1566f8de19fSKonstantin Porotchkin 		break;
1576f8de19fSKonstantin Porotchkin 
1586f8de19fSKonstantin Porotchkin 	case (COMPHY_PCIE_MODE):
1596f8de19fSKonstantin Porotchkin 		/* PCIE must be in Lane1 */
1606f8de19fSKonstantin Porotchkin 		if (comphy_index == COMPHY_LANE1)
1616f8de19fSKonstantin Porotchkin 			reg |= COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
1626f8de19fSKonstantin Porotchkin 		else
1636f8de19fSKonstantin Porotchkin 			goto error;
1646f8de19fSKonstantin Porotchkin 		break;
1656f8de19fSKonstantin Porotchkin 
1666f8de19fSKonstantin Porotchkin 	default:
1676f8de19fSKonstantin Porotchkin 		goto error;
1686f8de19fSKonstantin Porotchkin 	}
1696f8de19fSKonstantin Porotchkin 
1706f8de19fSKonstantin Porotchkin 	mmio_write_32(MVEBU_COMPHY_REG_BASE + COMPHY_SELECTOR_PHY_REG, reg);
17149b664e7SPali Rohár 	return 0;
1726f8de19fSKonstantin Porotchkin error:
1736f8de19fSKonstantin Porotchkin 	ERROR("COMPHY[%d] mode[%d] is invalid\n", comphy_index, mode);
17449b664e7SPali Rohár 	return -EINVAL;
1756f8de19fSKonstantin Porotchkin }
1766f8de19fSKonstantin Porotchkin 
177629dd61fSMarek Behún /*
178629dd61fSMarek Behún  * This is something like the inverse of the previous function: for given
179629dd61fSMarek Behún  * lane it returns COMPHY_*_MODE.
180629dd61fSMarek Behún  *
181629dd61fSMarek Behún  * It is useful when powering the phy off.
182629dd61fSMarek Behún  *
183629dd61fSMarek Behún  * This function returns COMPHY_USB3_MODE even if the phy was configured
184629dd61fSMarek Behún  * with COMPHY_USB3D_MODE or COMPHY_USB3H_MODE. (The usb3 phy initialization
185629dd61fSMarek Behún  * code does not differentiate between these modes.)
186629dd61fSMarek Behún  * Also it returns COMPHY_SGMII_MODE even if the phy was configures with
187a669983cSPali Rohár  * COMPHY_2500BASEX_MODE. (The sgmii phy initialization code does differentiate
188629dd61fSMarek Behún  * between these modes, but it is irrelevant when powering the phy off.)
189629dd61fSMarek Behún  */
mvebu_a3700_comphy_get_mode(uint8_t comphy_index)190629dd61fSMarek Behún static int mvebu_a3700_comphy_get_mode(uint8_t comphy_index)
191629dd61fSMarek Behún {
192629dd61fSMarek Behún 	uint32_t reg;
193629dd61fSMarek Behún 
194629dd61fSMarek Behún 	reg = mmio_read_32(MVEBU_COMPHY_REG_BASE + COMPHY_SELECTOR_PHY_REG);
195629dd61fSMarek Behún 	switch (comphy_index) {
196629dd61fSMarek Behún 	case COMPHY_LANE0:
197629dd61fSMarek Behún 		if ((reg & COMPHY_SELECTOR_USB3_GBE1_SEL_BIT) != 0)
198629dd61fSMarek Behún 			return COMPHY_USB3_MODE;
199629dd61fSMarek Behún 		else
200629dd61fSMarek Behún 			return COMPHY_SGMII_MODE;
201629dd61fSMarek Behún 	case COMPHY_LANE1:
202629dd61fSMarek Behún 		if ((reg & COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT) != 0)
203629dd61fSMarek Behún 			return COMPHY_PCIE_MODE;
204629dd61fSMarek Behún 		else
205629dd61fSMarek Behún 			return COMPHY_SGMII_MODE;
206629dd61fSMarek Behún 	case COMPHY_LANE2:
207629dd61fSMarek Behún 		if ((reg & COMPHY_SELECTOR_USB3_PHY_SEL_BIT) != 0)
208629dd61fSMarek Behún 			return COMPHY_USB3_MODE;
209629dd61fSMarek Behún 		else
210629dd61fSMarek Behún 			return COMPHY_SATA_MODE;
211629dd61fSMarek Behún 	}
212629dd61fSMarek Behún 
213629dd61fSMarek Behún 	return COMPHY_UNUSED;
214629dd61fSMarek Behún }
215629dd61fSMarek Behún 
2166f8de19fSKonstantin Porotchkin /* It is only used for SATA and USB3 on comphy lane2. */
comphy_set_indirect(uintptr_t addr,uint32_t offset,uint16_t data,uint16_t mask,bool is_sata)2176f8de19fSKonstantin Porotchkin static void comphy_set_indirect(uintptr_t addr, uint32_t offset, uint16_t data,
218be33dce7SPali Rohár 				uint16_t mask, bool is_sata)
2196f8de19fSKonstantin Porotchkin {
2206f8de19fSKonstantin Porotchkin 	/*
2216f8de19fSKonstantin Porotchkin 	 * When Lane 2 PHY is for USB3, access the PHY registers
2226f8de19fSKonstantin Porotchkin 	 * through indirect Address and Data registers:
2236f8de19fSKonstantin Porotchkin 	 * INDIR_ACC_PHY_ADDR (RD00E0178h [31:0]),
2246f8de19fSKonstantin Porotchkin 	 * INDIR_ACC_PHY_DATA (RD00E017Ch [31:0]),
2256f8de19fSKonstantin Porotchkin 	 * within the SATA Host Controller registers, Lane 2 base register
2266f8de19fSKonstantin Porotchkin 	 * offset is 0x200
2276f8de19fSKonstantin Porotchkin 	 */
228be33dce7SPali Rohár 	if (is_sata) {
2296f8de19fSKonstantin Porotchkin 		mmio_write_32(addr + COMPHY_LANE2_INDIR_ADDR_OFFSET, offset);
230be33dce7SPali Rohár 	} else {
2316f8de19fSKonstantin Porotchkin 		mmio_write_32(addr + COMPHY_LANE2_INDIR_ADDR_OFFSET,
2326f8de19fSKonstantin Porotchkin 			      offset + USB3PHY_LANE2_REG_BASE_OFFSET);
233be33dce7SPali Rohár 	}
2346f8de19fSKonstantin Porotchkin 
2356f8de19fSKonstantin Porotchkin 	reg_set(addr + COMPHY_LANE2_INDIR_DATA_OFFSET, data, mask);
2366f8de19fSKonstantin Porotchkin }
2376f8de19fSKonstantin Porotchkin 
238be33dce7SPali Rohár /* It is only used for SATA on comphy lane2. */
comphy_sata_set_indirect(uintptr_t addr,uint32_t reg_offset,uint16_t data,uint16_t mask)239be33dce7SPali Rohár static void comphy_sata_set_indirect(uintptr_t addr, uint32_t reg_offset,
240be33dce7SPali Rohár 				     uint16_t data, uint16_t mask)
241be33dce7SPali Rohár {
242be33dce7SPali Rohár 	comphy_set_indirect(addr, reg_offset, data, mask, true);
243be33dce7SPali Rohár }
244be33dce7SPali Rohár 
245be33dce7SPali Rohár /* It is only used for USB3 indirect access on comphy lane2. */
comphy_usb3_set_indirect(uintptr_t addr,uint32_t reg_offset,uint16_t data,uint16_t mask)246be33dce7SPali Rohár static void comphy_usb3_set_indirect(uintptr_t addr, uint32_t reg_offset,
247be33dce7SPali Rohár 				     uint16_t data, uint16_t mask)
248be33dce7SPali Rohár {
249be33dce7SPali Rohár 	comphy_set_indirect(addr, reg_offset, data, mask, false);
250be33dce7SPali Rohár }
251be33dce7SPali Rohár 
252be33dce7SPali Rohár /* It is only used for USB3 direct access not on comphy lane2. */
comphy_usb3_set_direct(uintptr_t addr,uint32_t reg_offset,uint16_t data,uint16_t mask)2536f8de19fSKonstantin Porotchkin static void comphy_usb3_set_direct(uintptr_t addr, uint32_t reg_offset,
254be33dce7SPali Rohár 				   uint16_t data, uint16_t mask)
2556f8de19fSKonstantin Porotchkin {
2566f8de19fSKonstantin Porotchkin 	reg_set16((reg_offset * PHY_SHFT(USB3) + addr), data, mask);
2576f8de19fSKonstantin Porotchkin }
2586f8de19fSKonstantin Porotchkin 
comphy_sgmii_phy_init(uintptr_t sd_ip_addr,bool is_1gbps)2590694b813SPali Rohár static void comphy_sgmii_phy_init(uintptr_t sd_ip_addr, bool is_1gbps)
2606f8de19fSKonstantin Porotchkin {
2616f8de19fSKonstantin Porotchkin 	const int fix_arr_sz = ARRAY_SIZE(sgmii_phy_init_fix);
2626f8de19fSKonstantin Porotchkin 	int addr, fix_idx;
2636f8de19fSKonstantin Porotchkin 	uint16_t val;
2646f8de19fSKonstantin Porotchkin 
2656f8de19fSKonstantin Porotchkin 	fix_idx = 0;
2666f8de19fSKonstantin Porotchkin 	for (addr = 0; addr < 512; addr++) {
2676f8de19fSKonstantin Porotchkin 		/*
2686f8de19fSKonstantin Porotchkin 		 * All PHY register values are defined in full for 3.125Gbps
2696f8de19fSKonstantin Porotchkin 		 * SERDES speed. The values required for 1.25 Gbps are almost
2706f8de19fSKonstantin Porotchkin 		 * the same and only few registers should be "fixed" in
2716f8de19fSKonstantin Porotchkin 		 * comparison to 3.125 Gbps values. These register values are
2726f8de19fSKonstantin Porotchkin 		 * stored in "sgmii_phy_init_fix" array.
2736f8de19fSKonstantin Porotchkin 		 */
2740694b813SPali Rohár 		if (!is_1gbps && sgmii_phy_init_fix[fix_idx].addr == addr) {
2756f8de19fSKonstantin Porotchkin 			/* Use new value */
2766f8de19fSKonstantin Porotchkin 			val = sgmii_phy_init_fix[fix_idx].value;
2776f8de19fSKonstantin Porotchkin 			if (fix_idx < fix_arr_sz)
2786f8de19fSKonstantin Porotchkin 				fix_idx++;
2796f8de19fSKonstantin Porotchkin 		} else {
2806f8de19fSKonstantin Porotchkin 			val = sgmii_phy_init[addr];
2816f8de19fSKonstantin Porotchkin 		}
2826f8de19fSKonstantin Porotchkin 
2836f8de19fSKonstantin Porotchkin 		reg_set16(SGMIIPHY_ADDR(addr, sd_ip_addr), val, 0xFFFF);
2846f8de19fSKonstantin Porotchkin 	}
2856f8de19fSKonstantin Porotchkin }
2866f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_sata_power_on(uint8_t comphy_index,uint32_t comphy_mode)2876f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sata_power_on(uint8_t comphy_index,
2886f8de19fSKonstantin Porotchkin 					    uint32_t comphy_mode)
2896f8de19fSKonstantin Porotchkin {
29049b664e7SPali Rohár 	int ret;
2916f8de19fSKonstantin Porotchkin 	uint32_t offset, data = 0, ref_clk;
2926f8de19fSKonstantin Porotchkin 	uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG;
2936f8de19fSKonstantin Porotchkin 	int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode);
2946f8de19fSKonstantin Porotchkin 
2956f8de19fSKonstantin Porotchkin 	debug_enter();
2966f8de19fSKonstantin Porotchkin 
2976f8de19fSKonstantin Porotchkin 	/* Configure phy selector for SATA */
29849b664e7SPali Rohár 	ret = mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode);
29949b664e7SPali Rohár 	if (ret) {
30049b664e7SPali Rohár 		return ret;
30149b664e7SPali Rohár 	}
3026f8de19fSKonstantin Porotchkin 
3036f8de19fSKonstantin Porotchkin 	/* Clear phy isolation mode to make it work in normal mode */
304b3491336SMarek Behún 	offset =  COMPHY_ISOLATION_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET;
305be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, 0, PHY_ISOLATE_MODE);
3066f8de19fSKonstantin Porotchkin 
3076f8de19fSKonstantin Porotchkin 	/* 0. Check the Polarity invert bits */
3086f8de19fSKonstantin Porotchkin 	if (invert & COMPHY_POLARITY_TXD_INVERT)
3096f8de19fSKonstantin Porotchkin 		data |= TXD_INVERT_BIT;
3106f8de19fSKonstantin Porotchkin 	if (invert & COMPHY_POLARITY_RXD_INVERT)
3116f8de19fSKonstantin Porotchkin 		data |= RXD_INVERT_BIT;
3126f8de19fSKonstantin Porotchkin 
313b3491336SMarek Behún 	offset = COMPHY_SYNC_PATTERN + SATAPHY_LANE2_REG_BASE_OFFSET;
314be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, data, TXD_INVERT_BIT |
315be33dce7SPali Rohár 				 RXD_INVERT_BIT);
3166f8de19fSKonstantin Porotchkin 
3176f8de19fSKonstantin Porotchkin 	/* 1. Select 40-bit data width width */
3184c995d2dSMarek Behún 	offset = COMPHY_DIG_LOOPBACK_EN + SATAPHY_LANE2_REG_BASE_OFFSET;
319be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, DATA_WIDTH_40BIT,
320be33dce7SPali Rohár 				 SEL_DATA_WIDTH_MASK);
3216f8de19fSKonstantin Porotchkin 
3226f8de19fSKonstantin Porotchkin 	/* 2. Select reference clock(25M) and PHY mode (SATA) */
3236f8de19fSKonstantin Porotchkin 	offset = COMPHY_POWER_PLL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET;
3246f8de19fSKonstantin Porotchkin 	if (get_ref_clk() == 40)
3256ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_SERDES_40MHZ;
3266f8de19fSKonstantin Porotchkin 	else
3276ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_SERDES_25MHZ;
3286f8de19fSKonstantin Porotchkin 
329be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, ref_clk | PHY_MODE_SATA,
330be33dce7SPali Rohár 				 REF_FREF_SEL_MASK | PHY_MODE_MASK);
3316f8de19fSKonstantin Porotchkin 
3326f8de19fSKonstantin Porotchkin 	/* 3. Use maximum PLL rate (no power save) */
3336f8de19fSKonstantin Porotchkin 	offset = COMPHY_KVCO_CAL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET;
334be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, USE_MAX_PLL_RATE_BIT,
335be33dce7SPali Rohár 				 USE_MAX_PLL_RATE_BIT);
3366f8de19fSKonstantin Porotchkin 
3376f8de19fSKonstantin Porotchkin 	/* 4. Reset reserved bit */
338be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, COMPHY_RESERVED_REG, 0,
339be33dce7SPali Rohár 				 PHYCTRL_FRM_PIN_BIT);
3406f8de19fSKonstantin Porotchkin 
3416f8de19fSKonstantin Porotchkin 	/* 5. Set vendor-specific configuration (It is done in sata driver) */
3426f8de19fSKonstantin Porotchkin 	/* XXX: in U-Boot below sequence was executed in this place, in Linux
3436f8de19fSKonstantin Porotchkin 	 * not.  Now it is done only in U-Boot before this comphy
3446f8de19fSKonstantin Porotchkin 	 * initialization - tests shows that it works ok, but in case of any
3456f8de19fSKonstantin Porotchkin 	 * future problem it is left for reference.
3466f8de19fSKonstantin Porotchkin 	 *   reg_set(MVEBU_REGS_BASE + 0xe00a0, 0, 0xffffffff);
3476f8de19fSKonstantin Porotchkin 	 *   reg_set(MVEBU_REGS_BASE + 0xe00a4, BIT(6), BIT(6));
3486f8de19fSKonstantin Porotchkin 	 */
3496f8de19fSKonstantin Porotchkin 
3506f8de19fSKonstantin Porotchkin 	/* Wait for > 55 us to allow PLL be enabled */
3516f8de19fSKonstantin Porotchkin 	udelay(PLL_SET_DELAY_US);
3526f8de19fSKonstantin Porotchkin 
3536f8de19fSKonstantin Porotchkin 	/* Polling status */
3546f8de19fSKonstantin Porotchkin 	mmio_write_32(comphy_indir_regs + COMPHY_LANE2_INDIR_ADDR_OFFSET,
3554c995d2dSMarek Behún 		      COMPHY_DIG_LOOPBACK_EN + SATAPHY_LANE2_REG_BASE_OFFSET);
3566f8de19fSKonstantin Porotchkin 
3576f8de19fSKonstantin Porotchkin 	ret = polling_with_timeout(comphy_indir_regs +
3586f8de19fSKonstantin Porotchkin 				   COMPHY_LANE2_INDIR_DATA_OFFSET,
3596f8de19fSKonstantin Porotchkin 				   PLL_READY_TX_BIT, PLL_READY_TX_BIT,
3606f8de19fSKonstantin Porotchkin 				   COMPHY_PLL_TIMEOUT, REG_32BIT);
36149b664e7SPali Rohár 	if (ret) {
36249b664e7SPali Rohár 		return -ETIMEDOUT;
36349b664e7SPali Rohár 	}
3646f8de19fSKonstantin Porotchkin 
3656f8de19fSKonstantin Porotchkin 	debug_exit();
3666f8de19fSKonstantin Porotchkin 
36749b664e7SPali Rohár 	return 0;
3686f8de19fSKonstantin Porotchkin }
3696f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_sgmii_power_on(uint8_t comphy_index,uint32_t comphy_mode)3706f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sgmii_power_on(uint8_t comphy_index,
3716f8de19fSKonstantin Porotchkin 					     uint32_t comphy_mode)
3726f8de19fSKonstantin Porotchkin {
37349b664e7SPali Rohár 	int ret;
374c074f70cSPali Rohár 	uint32_t mask, data;
375c074f70cSPali Rohár 	uintptr_t offset;
3766f8de19fSKonstantin Porotchkin 	uintptr_t sd_ip_addr;
3776f8de19fSKonstantin Porotchkin 	int mode = COMPHY_GET_MODE(comphy_mode);
3786f8de19fSKonstantin Porotchkin 	int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode);
3796f8de19fSKonstantin Porotchkin 
3806f8de19fSKonstantin Porotchkin 	debug_enter();
3816f8de19fSKonstantin Porotchkin 
3826f8de19fSKonstantin Porotchkin 	/* Set selector */
38349b664e7SPali Rohár 	ret = mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode);
38449b664e7SPali Rohár 	if (ret) {
38549b664e7SPali Rohár 		return ret;
38649b664e7SPali Rohár 	}
3876f8de19fSKonstantin Porotchkin 
3886f8de19fSKonstantin Porotchkin 	/* Serdes IP Base address
3896f8de19fSKonstantin Porotchkin 	 * COMPHY Lane0 -- USB3/GBE1
3906f8de19fSKonstantin Porotchkin 	 * COMPHY Lane1 -- PCIe/GBE0
3916f8de19fSKonstantin Porotchkin 	 */
3926f8de19fSKonstantin Porotchkin 	if (comphy_index == COMPHY_LANE0) {
3936f8de19fSKonstantin Porotchkin 		/* Get usb3 and gbe */
3946f8de19fSKonstantin Porotchkin 		sd_ip_addr = USB3_GBE1_PHY;
3956f8de19fSKonstantin Porotchkin 	} else
3966f8de19fSKonstantin Porotchkin 		sd_ip_addr = COMPHY_SD_ADDR;
3976f8de19fSKonstantin Porotchkin 
3986f8de19fSKonstantin Porotchkin 	/*
3996f8de19fSKonstantin Porotchkin 	 * 1. Reset PHY by setting PHY input port PIN_RESET=1.
4006f8de19fSKonstantin Porotchkin 	 * 2. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep
4016f8de19fSKonstantin Porotchkin 	 *    PHY TXP/TXN output to idle state during PHY initialization
4026f8de19fSKonstantin Porotchkin 	 * 3. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0.
4036f8de19fSKonstantin Porotchkin 	 */
404c9f138ebSMarek Behún 	data = PIN_PU_IVREF_BIT | PIN_TX_IDLE_BIT | PIN_RESET_COMPHY_BIT;
4054d01bfe6SMarek Behún 	mask = data | PIN_RESET_CORE_BIT | PIN_PU_PLL_BIT | PIN_PU_RX_BIT |
4066f8de19fSKonstantin Porotchkin 		PIN_PU_TX_BIT;
4076f8de19fSKonstantin Porotchkin 	offset = MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index);
4086f8de19fSKonstantin Porotchkin 	reg_set(offset, data, mask);
4096f8de19fSKonstantin Porotchkin 
4106f8de19fSKonstantin Porotchkin 	/* 4. Release reset to the PHY by setting PIN_RESET=0. */
4116f8de19fSKonstantin Porotchkin 	data = 0;
4126f8de19fSKonstantin Porotchkin 	mask = PIN_RESET_COMPHY_BIT;
4136f8de19fSKonstantin Porotchkin 	reg_set(offset, data, mask);
4146f8de19fSKonstantin Porotchkin 
4156f8de19fSKonstantin Porotchkin 	/*
4166f8de19fSKonstantin Porotchkin 	 * 5. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide COMPHY
4176f8de19fSKonstantin Porotchkin 	 * bit rate
4186f8de19fSKonstantin Porotchkin 	 */
4196f8de19fSKonstantin Porotchkin 	if (mode == COMPHY_SGMII_MODE) {
4206f8de19fSKonstantin Porotchkin 		/* SGMII 1G, SerDes speed 1.25G */
4216f8de19fSKonstantin Porotchkin 		data |= SD_SPEED_1_25_G << GEN_RX_SEL_OFFSET;
4226f8de19fSKonstantin Porotchkin 		data |= SD_SPEED_1_25_G << GEN_TX_SEL_OFFSET;
423a669983cSPali Rohár 	} else if (mode == COMPHY_2500BASEX_MODE) {
424a669983cSPali Rohár 		/* 2500Base-X, SerDes speed 3.125G */
425bdcf44f1SMarek Behún 		data |= SD_SPEED_3_125_G << GEN_RX_SEL_OFFSET;
426bdcf44f1SMarek Behún 		data |= SD_SPEED_3_125_G << GEN_TX_SEL_OFFSET;
4276f8de19fSKonstantin Porotchkin 	} else {
4286f8de19fSKonstantin Porotchkin 		/* Other rates are not supported */
4296f8de19fSKonstantin Porotchkin 		ERROR("unsupported SGMII speed on comphy lane%d\n",
4306f8de19fSKonstantin Porotchkin 			comphy_index);
4316f8de19fSKonstantin Porotchkin 		return -EINVAL;
4326f8de19fSKonstantin Porotchkin 	}
4336f8de19fSKonstantin Porotchkin 	mask = GEN_RX_SEL_MASK | GEN_TX_SEL_MASK;
4346f8de19fSKonstantin Porotchkin 	reg_set(offset, data, mask);
4356f8de19fSKonstantin Porotchkin 
4366f8de19fSKonstantin Porotchkin 	/*
4376f8de19fSKonstantin Porotchkin 	 * 6. Wait 10mS for bandgap and reference clocks to stabilize; then
4386f8de19fSKonstantin Porotchkin 	 * start SW programming.
4396f8de19fSKonstantin Porotchkin 	 */
4406f8de19fSKonstantin Porotchkin 	mdelay(10);
4416f8de19fSKonstantin Porotchkin 
4426f8de19fSKonstantin Porotchkin 	/* 7. Program COMPHY register PHY_MODE */
4436f8de19fSKonstantin Porotchkin 	data = PHY_MODE_SGMII;
4446f8de19fSKonstantin Porotchkin 	mask = PHY_MODE_MASK;
4456f8de19fSKonstantin Porotchkin 	reg_set16(SGMIIPHY_ADDR(COMPHY_POWER_PLL_CTRL, sd_ip_addr), data, mask);
4466f8de19fSKonstantin Porotchkin 
4476f8de19fSKonstantin Porotchkin 	/*
4486f8de19fSKonstantin Porotchkin 	 * 8. Set COMPHY register REFCLK_SEL to select the correct REFCLK
4496f8de19fSKonstantin Porotchkin 	 * source
4506f8de19fSKonstantin Porotchkin 	 */
4516f8de19fSKonstantin Porotchkin 	data = 0;
4526f8de19fSKonstantin Porotchkin 	mask = PHY_REF_CLK_SEL;
4539cf978c6SMarek Behún 	reg_set16(SGMIIPHY_ADDR(COMPHY_MISC_CTRL0, sd_ip_addr), data, mask);
4546f8de19fSKonstantin Porotchkin 
4556f8de19fSKonstantin Porotchkin 	/*
4566f8de19fSKonstantin Porotchkin 	 * 9. Set correct reference clock frequency in COMPHY register
4576f8de19fSKonstantin Porotchkin 	 * REF_FREF_SEL.
4586f8de19fSKonstantin Porotchkin 	 */
4596f8de19fSKonstantin Porotchkin 	if (get_ref_clk() == 40)
4606ba97f83SMarek Behún 		data = REF_FREF_SEL_SERDES_50MHZ;
4616f8de19fSKonstantin Porotchkin 	else
4626ba97f83SMarek Behún 		data = REF_FREF_SEL_SERDES_25MHZ;
4636f8de19fSKonstantin Porotchkin 
4646f8de19fSKonstantin Porotchkin 	mask = REF_FREF_SEL_MASK;
4656f8de19fSKonstantin Porotchkin 	reg_set16(SGMIIPHY_ADDR(COMPHY_POWER_PLL_CTRL, sd_ip_addr), data, mask);
4666f8de19fSKonstantin Porotchkin 
4676f8de19fSKonstantin Porotchkin 	/* 10. Program COMPHY register PHY_GEN_MAX[1:0]
4686f8de19fSKonstantin Porotchkin 	 * This step is mentioned in the flow received from verification team.
4696f8de19fSKonstantin Porotchkin 	 * However the PHY_GEN_MAX value is only meaningful for other interfaces
4706f8de19fSKonstantin Porotchkin 	 * (not SGMII). For instance, it selects SATA speed 1.5/3/6 Gbps or PCIe
4716f8de19fSKonstantin Porotchkin 	 * speed 2.5/5 Gbps
4726f8de19fSKonstantin Porotchkin 	 */
4736f8de19fSKonstantin Porotchkin 
4746f8de19fSKonstantin Porotchkin 	/*
4756f8de19fSKonstantin Porotchkin 	 * 11. Program COMPHY register SEL_BITS to set correct parallel data
4766f8de19fSKonstantin Porotchkin 	 * bus width
4776f8de19fSKonstantin Porotchkin 	 */
4786f8de19fSKonstantin Porotchkin 	data = DATA_WIDTH_10BIT;
4796f8de19fSKonstantin Porotchkin 	mask = SEL_DATA_WIDTH_MASK;
4804c995d2dSMarek Behún 	reg_set16(SGMIIPHY_ADDR(COMPHY_DIG_LOOPBACK_EN, sd_ip_addr),
4814c995d2dSMarek Behún 		  data, mask);
4826f8de19fSKonstantin Porotchkin 
4836f8de19fSKonstantin Porotchkin 	/*
4846f8de19fSKonstantin Porotchkin 	 * 12. As long as DFE function needs to be enabled in any mode,
4856f8de19fSKonstantin Porotchkin 	 * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F
4866f8de19fSKonstantin Porotchkin 	 * for real chip during COMPHY power on.
4876f8de19fSKonstantin Porotchkin 	 * The step 14 exists (and empty) in the original initialization flow
4886f8de19fSKonstantin Porotchkin 	 * obtained from the verification team. According to the functional
4896f8de19fSKonstantin Porotchkin 	 * specification DFE_UPDATE_EN already has the default value 0x3F
4906f8de19fSKonstantin Porotchkin 	 */
4916f8de19fSKonstantin Porotchkin 
4926f8de19fSKonstantin Porotchkin 	/*
4936f8de19fSKonstantin Porotchkin 	 * 13. Program COMPHY GEN registers.
4946f8de19fSKonstantin Porotchkin 	 * These registers should be programmed based on the lab testing result
4956f8de19fSKonstantin Porotchkin 	 * to achieve optimal performance. Please contact the CEA group to get
4966f8de19fSKonstantin Porotchkin 	 * the related GEN table during real chip bring-up. We only required to
4976f8de19fSKonstantin Porotchkin 	 * run though the entire registers programming flow defined by
4986f8de19fSKonstantin Porotchkin 	 * "comphy_sgmii_phy_init" when the REF clock is 40 MHz. For REF clock
4996f8de19fSKonstantin Porotchkin 	 * 25 MHz the default values stored in PHY registers are OK.
5006f8de19fSKonstantin Porotchkin 	 */
5016f8de19fSKonstantin Porotchkin 	debug("Running C-DPI phy init %s mode\n",
502a669983cSPali Rohár 	      mode == COMPHY_2500BASEX_MODE ? "2G5" : "1G");
5036f8de19fSKonstantin Porotchkin 	if (get_ref_clk() == 40)
5040694b813SPali Rohár 		comphy_sgmii_phy_init(sd_ip_addr, mode != COMPHY_2500BASEX_MODE);
5056f8de19fSKonstantin Porotchkin 
5066f8de19fSKonstantin Porotchkin 	/*
5076f8de19fSKonstantin Porotchkin 	 * 14. [Simulation Only] should not be used for real chip.
5086f8de19fSKonstantin Porotchkin 	 * By pass power up calibration by programming EXT_FORCE_CAL_DONE
5096f8de19fSKonstantin Porotchkin 	 * (R02h[9]) to 1 to shorten COMPHY simulation time.
5106f8de19fSKonstantin Porotchkin 	 */
5116f8de19fSKonstantin Porotchkin 
5126f8de19fSKonstantin Porotchkin 	/*
5136f8de19fSKonstantin Porotchkin 	 * 15. [Simulation Only: should not be used for real chip]
5146f8de19fSKonstantin Porotchkin 	 * Program COMPHY register FAST_DFE_TIMER_EN=1 to shorten RX training
5156f8de19fSKonstantin Porotchkin 	 * simulation time.
5166f8de19fSKonstantin Porotchkin 	 */
5176f8de19fSKonstantin Porotchkin 
5186f8de19fSKonstantin Porotchkin 	/*
5196f8de19fSKonstantin Porotchkin 	 * 16. Check the PHY Polarity invert bit
5206f8de19fSKonstantin Porotchkin 	 */
5216f8de19fSKonstantin Porotchkin 	data = 0x0;
5226f8de19fSKonstantin Porotchkin 	if (invert & COMPHY_POLARITY_TXD_INVERT)
5236f8de19fSKonstantin Porotchkin 		data |= TXD_INVERT_BIT;
5246f8de19fSKonstantin Porotchkin 	if (invert & COMPHY_POLARITY_RXD_INVERT)
5256f8de19fSKonstantin Porotchkin 		data |= RXD_INVERT_BIT;
526ee4c70ebSPali Rohár 	mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
527b3491336SMarek Behún 	reg_set16(SGMIIPHY_ADDR(COMPHY_SYNC_PATTERN, sd_ip_addr), data, mask);
5286f8de19fSKonstantin Porotchkin 
5296f8de19fSKonstantin Porotchkin 	/*
5306f8de19fSKonstantin Porotchkin 	 * 17. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1 to
5316f8de19fSKonstantin Porotchkin 	 * start PHY power up sequence. All the PHY register programming should
5326f8de19fSKonstantin Porotchkin 	 * be done before PIN_PU_PLL=1. There should be no register programming
5336f8de19fSKonstantin Porotchkin 	 * for normal PHY operation from this point.
5346f8de19fSKonstantin Porotchkin 	 */
5356f8de19fSKonstantin Porotchkin 	reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index),
5366f8de19fSKonstantin Porotchkin 		PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT,
5376f8de19fSKonstantin Porotchkin 		PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT);
5386f8de19fSKonstantin Porotchkin 
5396f8de19fSKonstantin Porotchkin 	/*
5406f8de19fSKonstantin Porotchkin 	 * 18. Wait for PHY power up sequence to finish by checking output ports
5416f8de19fSKonstantin Porotchkin 	 * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1.
5426f8de19fSKonstantin Porotchkin 	 */
5436f8de19fSKonstantin Porotchkin 	ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE +
5446f8de19fSKonstantin Porotchkin 				   COMPHY_PHY_STATUS_OFFSET(comphy_index),
5456f8de19fSKonstantin Porotchkin 				   PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT,
5466f8de19fSKonstantin Porotchkin 				   PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT,
5476f8de19fSKonstantin Porotchkin 				   COMPHY_PLL_TIMEOUT, REG_32BIT);
54849b664e7SPali Rohár 	if (ret) {
5496f8de19fSKonstantin Porotchkin 		ERROR("Failed to lock PLL for SGMII PHY %d\n", comphy_index);
55049b664e7SPali Rohár 		return -ETIMEDOUT;
55149b664e7SPali Rohár 	}
5526f8de19fSKonstantin Porotchkin 
5536f8de19fSKonstantin Porotchkin 	/*
5546f8de19fSKonstantin Porotchkin 	 * 19. Set COMPHY input port PIN_TX_IDLE=0
5556f8de19fSKonstantin Porotchkin 	 */
5566f8de19fSKonstantin Porotchkin 	reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index),
5576f8de19fSKonstantin Porotchkin 		0x0, PIN_TX_IDLE_BIT);
5586f8de19fSKonstantin Porotchkin 
5596f8de19fSKonstantin Porotchkin 	/*
5606f8de19fSKonstantin Porotchkin 	 * 20. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1. To
5616f8de19fSKonstantin Porotchkin 	 * start RX initialization. PIN_RX_INIT_DONE will be cleared to 0 by the
5626f8de19fSKonstantin Porotchkin 	 * PHY After RX initialization is done, PIN_RX_INIT_DONE will be set to
5636f8de19fSKonstantin Porotchkin 	 * 1 by COMPHY Set PIN_RX_INIT=0 after PIN_RX_INIT_DONE= 1. Please
5646f8de19fSKonstantin Porotchkin 	 * refer to RX initialization part for details.
5656f8de19fSKonstantin Porotchkin 	 */
5666f8de19fSKonstantin Porotchkin 	reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index),
567ccec1bd5SPali Rohár 		PHY_RX_INIT_BIT, PHY_RX_INIT_BIT);
5686f8de19fSKonstantin Porotchkin 
5696f8de19fSKonstantin Porotchkin 	ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE +
5706f8de19fSKonstantin Porotchkin 				   COMPHY_PHY_STATUS_OFFSET(comphy_index),
5716f8de19fSKonstantin Porotchkin 				   PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT,
5726f8de19fSKonstantin Porotchkin 				   PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT,
5736f8de19fSKonstantin Porotchkin 				   COMPHY_PLL_TIMEOUT, REG_32BIT);
57449b664e7SPali Rohár 	if (ret) {
5756f8de19fSKonstantin Porotchkin 		ERROR("Failed to lock PLL for SGMII PHY %d\n", comphy_index);
57649b664e7SPali Rohár 		return -ETIMEDOUT;
57749b664e7SPali Rohár 	}
5786f8de19fSKonstantin Porotchkin 
5796f8de19fSKonstantin Porotchkin 	ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE +
5806f8de19fSKonstantin Porotchkin 				   COMPHY_PHY_STATUS_OFFSET(comphy_index),
5816f8de19fSKonstantin Porotchkin 				   PHY_RX_INIT_DONE_BIT, PHY_RX_INIT_DONE_BIT,
5826f8de19fSKonstantin Porotchkin 				   COMPHY_PLL_TIMEOUT, REG_32BIT);
58349b664e7SPali Rohár 	if (ret) {
5846f8de19fSKonstantin Porotchkin 		ERROR("Failed to init RX of SGMII PHY %d\n", comphy_index);
58549b664e7SPali Rohár 		return -ETIMEDOUT;
58649b664e7SPali Rohár 	}
5876f8de19fSKonstantin Porotchkin 
5886f8de19fSKonstantin Porotchkin 	debug_exit();
5896f8de19fSKonstantin Porotchkin 
59049b664e7SPali Rohár 	return 0;
5916f8de19fSKonstantin Porotchkin }
5926f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_sgmii_power_off(uint8_t comphy_index)593629dd61fSMarek Behún static int mvebu_a3700_comphy_sgmii_power_off(uint8_t comphy_index)
594629dd61fSMarek Behún {
595c074f70cSPali Rohár 	uintptr_t offset;
596c074f70cSPali Rohár 	uint32_t mask, data;
597629dd61fSMarek Behún 
598629dd61fSMarek Behún 	debug_enter();
599629dd61fSMarek Behún 
600629dd61fSMarek Behún 	data = PIN_RESET_CORE_BIT | PIN_RESET_COMPHY_BIT;
601ccec1bd5SPali Rohár 	mask = data;
602629dd61fSMarek Behún 	offset = MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index);
603629dd61fSMarek Behún 	reg_set(offset, data, mask);
604629dd61fSMarek Behún 
605629dd61fSMarek Behún 	debug_exit();
606629dd61fSMarek Behún 
60749b664e7SPali Rohár 	return 0;
608629dd61fSMarek Behún }
609629dd61fSMarek Behún 
mvebu_a3700_comphy_usb3_power_on(uint8_t comphy_index,uint32_t comphy_mode)6106f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_usb3_power_on(uint8_t comphy_index,
6116f8de19fSKonstantin Porotchkin 					    uint32_t comphy_mode)
6126f8de19fSKonstantin Porotchkin {
61349b664e7SPali Rohár 	int ret;
6146f8de19fSKonstantin Porotchkin 	uintptr_t reg_base = 0;
615c074f70cSPali Rohár 	uintptr_t addr;
616c074f70cSPali Rohár 	uint32_t mask, data, cfg, ref_clk;
6176f8de19fSKonstantin Porotchkin 	void (*usb3_reg_set)(uintptr_t addr, uint32_t reg_offset, uint16_t data,
618be33dce7SPali Rohár 			     uint16_t mask);
6196f8de19fSKonstantin Porotchkin 	int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode);
6206f8de19fSKonstantin Porotchkin 
6216f8de19fSKonstantin Porotchkin 	debug_enter();
6226f8de19fSKonstantin Porotchkin 
6236f8de19fSKonstantin Porotchkin 	/* Set phy seclector */
62449b664e7SPali Rohár 	ret = mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode);
62549b664e7SPali Rohár 	if (ret) {
62649b664e7SPali Rohár 		return ret;
62749b664e7SPali Rohár 	}
6286f8de19fSKonstantin Porotchkin 
6296f8de19fSKonstantin Porotchkin 	/* Set usb3 reg access func, Lane2 is indirect access */
6306f8de19fSKonstantin Porotchkin 	if (comphy_index == COMPHY_LANE2) {
631be33dce7SPali Rohár 		usb3_reg_set = &comphy_usb3_set_indirect;
6326f8de19fSKonstantin Porotchkin 		reg_base = COMPHY_INDIRECT_REG;
6336f8de19fSKonstantin Porotchkin 	} else {
6346f8de19fSKonstantin Porotchkin 		/* Get the direct access register resource and map */
6356f8de19fSKonstantin Porotchkin 		usb3_reg_set = &comphy_usb3_set_direct;
6366f8de19fSKonstantin Porotchkin 		reg_base = USB3_GBE1_PHY;
6376f8de19fSKonstantin Porotchkin 	}
6386f8de19fSKonstantin Porotchkin 
6396f8de19fSKonstantin Porotchkin 	/*
6406f8de19fSKonstantin Porotchkin 	 * 0. Set PHY OTG Control(0x5d034), bit 4, Power up OTG module The
6416f8de19fSKonstantin Porotchkin 	 * register belong to UTMI module, so it is set in UTMI phy driver.
6426f8de19fSKonstantin Porotchkin 	 */
6436f8de19fSKonstantin Porotchkin 
6446f8de19fSKonstantin Porotchkin 	/*
6456f8de19fSKonstantin Porotchkin 	 * 1. Set PRD_TXDEEMPH (3.5db de-emph)
6466f8de19fSKonstantin Porotchkin 	 */
6476f8de19fSKonstantin Porotchkin 	mask = PRD_TXDEEMPH0_MASK | PRD_TXMARGIN_MASK | PRD_TXSWING_MASK |
6486f8de19fSKonstantin Porotchkin 		CFG_TX_ALIGN_POS_MASK;
649b7b0575dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_LANE_CFG0, PRD_TXDEEMPH0_MASK, mask);
6506f8de19fSKonstantin Porotchkin 
6516f8de19fSKonstantin Porotchkin 	/*
6526f8de19fSKonstantin Porotchkin 	 * 2. Set BIT0: enable transmitter in high impedance mode
6536f8de19fSKonstantin Porotchkin 	 *    Set BIT[3:4]: delay 2 clock cycles for HiZ off latency
6546f8de19fSKonstantin Porotchkin 	 *    Set BIT6: Tx detect Rx at HiZ mode
6556f8de19fSKonstantin Porotchkin 	 *    Unset BIT15: set to 0 to set USB3 De-emphasize level to -3.5db
656b7b0575dSMarek Behún 	 *            together with bit 0 of COMPHY_LANE_CFG0 register
6576f8de19fSKonstantin Porotchkin 	 */
6586f8de19fSKonstantin Porotchkin 	mask = PRD_TXDEEMPH1_MASK | TX_DET_RX_MODE | GEN2_TX_DATA_DLY_MASK |
6596f8de19fSKonstantin Porotchkin 		TX_ELEC_IDLE_MODE_EN;
6606f8de19fSKonstantin Porotchkin 	data = TX_DET_RX_MODE | GEN2_TX_DATA_DLY_DEFT | TX_ELEC_IDLE_MODE_EN;
661b7b0575dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_LANE_CFG1, data, mask);
6626f8de19fSKonstantin Porotchkin 
6636f8de19fSKonstantin Porotchkin 	/*
6646f8de19fSKonstantin Porotchkin 	 * 3. Set Spread Spectrum Clock Enabled
6656f8de19fSKonstantin Porotchkin 	 */
666b7b0575dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_LANE_CFG4,
667be33dce7SPali Rohár 		     SPREAD_SPECTRUM_CLK_EN, SPREAD_SPECTRUM_CLK_EN);
6686f8de19fSKonstantin Porotchkin 
6696f8de19fSKonstantin Porotchkin 	/*
6706f8de19fSKonstantin Porotchkin 	 * 4. Set Override Margining Controls From the MAC:
6716f8de19fSKonstantin Porotchkin 	 *    Use margining signals from lane configuration
6726f8de19fSKonstantin Porotchkin 	 */
673b7b0575dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_TEST_MODE_CTRL,
674be33dce7SPali Rohár 		     MODE_MARGIN_OVERRIDE, REG_16_BIT_MASK);
6756f8de19fSKonstantin Porotchkin 
6766f8de19fSKonstantin Porotchkin 	/*
6776f8de19fSKonstantin Porotchkin 	 * 5. Set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles
6786f8de19fSKonstantin Porotchkin 	 *    set Mode Clock Source = PCLK is generated from REFCLK
6796f8de19fSKonstantin Porotchkin 	 */
680e585c84cSMarek Behún 	usb3_reg_set(reg_base, COMPHY_CLK_SRC_LO, 0x0,
681*e62ae2e2SMarek Behún 		     (MODE_CLK_SRC | BUNDLE_PERIOD_SEL |
682*e62ae2e2SMarek Behún 		      BUNDLE_PERIOD_SCALE_MASK | BUNDLE_SAMPLE_CTRL |
683*e62ae2e2SMarek Behún 		      PLL_READY_DLY_MASK));
6846f8de19fSKonstantin Porotchkin 
6856f8de19fSKonstantin Porotchkin 	/*
6866f8de19fSKonstantin Porotchkin 	 * 6. Set G2 Spread Spectrum Clock Amplitude at 4K
6876f8de19fSKonstantin Porotchkin 	 */
68830264e97SMarek Behún 	usb3_reg_set(reg_base, COMPHY_GEN2_SET2,
6893f9a0892SMarek Behún 		     GS2_TX_SSC_AMP_VALUE_20, GS2_TX_SSC_AMP_MASK);
6906f8de19fSKonstantin Porotchkin 
6916f8de19fSKonstantin Porotchkin 	/*
6926f8de19fSKonstantin Porotchkin 	 * 7. Unset G3 Spread Spectrum Clock Amplitude
6936f8de19fSKonstantin Porotchkin 	 *    set G3 TX and RX Register Master Current Select
6946f8de19fSKonstantin Porotchkin 	 */
6953f9a0892SMarek Behún 	mask = GS2_TX_SSC_AMP_MASK | GS2_VREG_RXTX_MAS_ISET_MASK |
6963f9a0892SMarek Behún 		GS2_RSVD_6_0_MASK;
69730264e97SMarek Behún 	usb3_reg_set(reg_base, COMPHY_GEN3_SET2,
6983f9a0892SMarek Behún 		     GS2_VREG_RXTX_MAS_ISET_60U, mask);
6996f8de19fSKonstantin Porotchkin 
7006f8de19fSKonstantin Porotchkin 	/*
7016f8de19fSKonstantin Porotchkin 	 * 8. Check crystal jumper setting and program the Power and PLL Control
7026f8de19fSKonstantin Porotchkin 	 * accordingly Change RX wait
7036f8de19fSKonstantin Porotchkin 	 */
7046f8de19fSKonstantin Porotchkin 	if (get_ref_clk() == 40) {
7056ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
7066f8de19fSKonstantin Porotchkin 		cfg = CFG_PM_RXDLOZ_WAIT_12_UNIT;
7076f8de19fSKonstantin Porotchkin 
7086f8de19fSKonstantin Porotchkin 	} else {
7096f8de19fSKonstantin Porotchkin 		/* 25 MHz */
7106ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
7116f8de19fSKonstantin Porotchkin 		cfg = CFG_PM_RXDLOZ_WAIT_7_UNIT;
7126f8de19fSKonstantin Porotchkin 	}
7136f8de19fSKonstantin Porotchkin 
7146f8de19fSKonstantin Porotchkin 	mask = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
7156f8de19fSKonstantin Porotchkin 		PU_TX_INTP_BIT | PU_DFE_BIT | PLL_LOCK_BIT | PHY_MODE_MASK |
7166f8de19fSKonstantin Porotchkin 		REF_FREF_SEL_MASK;
7176f8de19fSKonstantin Porotchkin 	data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
7186f8de19fSKonstantin Porotchkin 		PU_TX_INTP_BIT | PU_DFE_BIT | PHY_MODE_USB3 | ref_clk;
719be33dce7SPali Rohár 	usb3_reg_set(reg_base, COMPHY_POWER_PLL_CTRL, data,  mask);
7206f8de19fSKonstantin Porotchkin 
7216f8de19fSKonstantin Porotchkin 	mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
7226f8de19fSKonstantin Porotchkin 		CFG_PM_RXDLOZ_WAIT_MASK;
7236f8de19fSKonstantin Porotchkin 	data = CFG_PM_RXDEN_WAIT_1_UNIT  | cfg;
724b7b0575dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_PWR_MGM_TIM1, data, mask);
7256f8de19fSKonstantin Porotchkin 
7266f8de19fSKonstantin Porotchkin 	/*
7276f8de19fSKonstantin Porotchkin 	 * 9. Enable idle sync
7286f8de19fSKonstantin Porotchkin 	 */
72986f6b55dSMarek Behún 	data = IDLE_SYNC_EN_DEFAULT_VALUE | IDLE_SYNC_EN;
73086f6b55dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_IDLE_SYNC_EN, data, REG_16_BIT_MASK);
7316f8de19fSKonstantin Porotchkin 
7326f8de19fSKonstantin Porotchkin 	/*
7336f8de19fSKonstantin Porotchkin 	 * 10. Enable the output of 500M clock
7346f8de19fSKonstantin Porotchkin 	 */
7359cf978c6SMarek Behún 	data = MISC_CTRL0_DEFAULT_VALUE | CLK500M_EN;
7369cf978c6SMarek Behún 	usb3_reg_set(reg_base, COMPHY_MISC_CTRL0, data, REG_16_BIT_MASK);
7376f8de19fSKonstantin Porotchkin 
7386f8de19fSKonstantin Porotchkin 	/*
7396f8de19fSKonstantin Porotchkin 	 * 11. Set 20-bit data width
7406f8de19fSKonstantin Porotchkin 	 */
7414c995d2dSMarek Behún 	usb3_reg_set(reg_base, COMPHY_DIG_LOOPBACK_EN, DATA_WIDTH_20BIT,
742be33dce7SPali Rohár 		     REG_16_BIT_MASK);
7436f8de19fSKonstantin Porotchkin 
7446f8de19fSKonstantin Porotchkin 	/*
7456f8de19fSKonstantin Porotchkin 	 * 12. Override Speed_PLL value and use MAC PLL
7466f8de19fSKonstantin Porotchkin 	 */
7476f8de19fSKonstantin Porotchkin 	usb3_reg_set(reg_base, COMPHY_KVCO_CAL_CTRL,
7486f8de19fSKonstantin Porotchkin 		     (SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT),
749be33dce7SPali Rohár 		     REG_16_BIT_MASK);
7506f8de19fSKonstantin Porotchkin 
7516f8de19fSKonstantin Porotchkin 	/*
7526f8de19fSKonstantin Porotchkin 	 * 13. Check the Polarity invert bit
7536f8de19fSKonstantin Porotchkin 	 */
754ee4c70ebSPali Rohár 	data = 0U;
755ee4c70ebSPali Rohár 	if (invert & COMPHY_POLARITY_TXD_INVERT) {
756ee4c70ebSPali Rohár 		data |= TXD_INVERT_BIT;
757ee4c70ebSPali Rohár 	}
758ee4c70ebSPali Rohár 	if (invert & COMPHY_POLARITY_RXD_INVERT) {
759ee4c70ebSPali Rohár 		data |= RXD_INVERT_BIT;
760ee4c70ebSPali Rohár 	}
761ee4c70ebSPali Rohár 	mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
762b3491336SMarek Behún 	usb3_reg_set(reg_base, COMPHY_SYNC_PATTERN, data, mask);
7636f8de19fSKonstantin Porotchkin 
7646f8de19fSKonstantin Porotchkin 	/*
7656f8de19fSKonstantin Porotchkin 	 * 14. Set max speed generation to USB3.0 5Gbps
7666f8de19fSKonstantin Porotchkin 	 */
767b3491336SMarek Behún 	usb3_reg_set(reg_base, COMPHY_SYNC_MASK_GEN, PHY_GEN_MAX_USB3_5G,
768be33dce7SPali Rohár 		     PHY_GEN_MAX_MASK);
7696f8de19fSKonstantin Porotchkin 
7706f8de19fSKonstantin Porotchkin 	/*
7716f8de19fSKonstantin Porotchkin 	 * 15. Set capacitor value for FFE gain peaking to 0xF
7726f8de19fSKonstantin Porotchkin 	 */
77330264e97SMarek Behún 	usb3_reg_set(reg_base, COMPHY_GEN2_SET3,
7743f9a0892SMarek Behún 		     GS3_FFE_CAP_SEL_VALUE, GS3_FFE_CAP_SEL_MASK);
7756f8de19fSKonstantin Porotchkin 
7766f8de19fSKonstantin Porotchkin 	/*
7776f8de19fSKonstantin Porotchkin 	 * 16. Release SW reset
7786f8de19fSKonstantin Porotchkin 	 */
7796f8de19fSKonstantin Porotchkin 	data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32 | MODE_REFDIV_BY_4;
7806a14ac78SMarek Behún 	usb3_reg_set(reg_base, COMPHY_RST_CLK_CTRL, data, REG_16_BIT_MASK);
7816f8de19fSKonstantin Porotchkin 
7826f8de19fSKonstantin Porotchkin 	/* Wait for > 55 us to allow PCLK be enabled */
7836f8de19fSKonstantin Porotchkin 	udelay(PLL_SET_DELAY_US);
7846f8de19fSKonstantin Porotchkin 
7856f8de19fSKonstantin Porotchkin 	if (comphy_index == COMPHY_LANE2) {
7866eb04379SMarek Behún 		data = COMPHY_LANE_STAT1 + USB3PHY_LANE2_REG_BASE_OFFSET;
7876f8de19fSKonstantin Porotchkin 		mmio_write_32(reg_base + COMPHY_LANE2_INDIR_ADDR_OFFSET,
7886f8de19fSKonstantin Porotchkin 			      data);
7896f8de19fSKonstantin Porotchkin 
790b662232dSMarek Behún 		addr = reg_base + COMPHY_LANE2_INDIR_DATA_OFFSET;
7916f8de19fSKonstantin Porotchkin 		ret = polling_with_timeout(addr, TXDCLK_PCLK_EN, TXDCLK_PCLK_EN,
7926f8de19fSKonstantin Porotchkin 					   COMPHY_PLL_TIMEOUT, REG_32BIT);
7936f8de19fSKonstantin Porotchkin 	} else {
7946eb04379SMarek Behún 		ret = polling_with_timeout(LANE_STAT1_ADDR(USB3) + reg_base,
7956f8de19fSKonstantin Porotchkin 					   TXDCLK_PCLK_EN, TXDCLK_PCLK_EN,
7966f8de19fSKonstantin Porotchkin 					   COMPHY_PLL_TIMEOUT, REG_16BIT);
7976f8de19fSKonstantin Porotchkin 	}
79849b664e7SPali Rohár 	if (ret) {
7996f8de19fSKonstantin Porotchkin 		ERROR("Failed to lock USB3 PLL\n");
80049b664e7SPali Rohár 		return -ETIMEDOUT;
80149b664e7SPali Rohár 	}
8026f8de19fSKonstantin Porotchkin 
8036f8de19fSKonstantin Porotchkin 	debug_exit();
8046f8de19fSKonstantin Porotchkin 
80549b664e7SPali Rohár 	return 0;
8066f8de19fSKonstantin Porotchkin }
8076f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_pcie_power_on(uint8_t comphy_index,uint32_t comphy_mode)8086f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_pcie_power_on(uint8_t comphy_index,
8096f8de19fSKonstantin Porotchkin 					    uint32_t comphy_mode)
8106f8de19fSKonstantin Porotchkin {
8116f8de19fSKonstantin Porotchkin 	int ret;
8126f8de19fSKonstantin Porotchkin 	uint32_t ref_clk;
813ee4c70ebSPali Rohár 	uint32_t mask, data;
8146f8de19fSKonstantin Porotchkin 	int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode);
8156f8de19fSKonstantin Porotchkin 
8166f8de19fSKonstantin Porotchkin 	debug_enter();
8176f8de19fSKonstantin Porotchkin 
8180f3a1221SPali Rohár 	/* Configure phy selector for PCIe */
8190f3a1221SPali Rohár 	ret = mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode);
8200f3a1221SPali Rohár 	if (ret) {
8210f3a1221SPali Rohár 		return ret;
8220f3a1221SPali Rohár 	}
8230f3a1221SPali Rohár 
8246f8de19fSKonstantin Porotchkin 	/* 1. Enable max PLL. */
8256f8de19fSKonstantin Porotchkin 	reg_set16(LANE_CFG1_ADDR(PCIE) + COMPHY_SD_ADDR,
826ccec1bd5SPali Rohár 		  USE_MAX_PLL_RATE_EN, USE_MAX_PLL_RATE_EN);
8276f8de19fSKonstantin Porotchkin 
8286f8de19fSKonstantin Porotchkin 	/* 2. Select 20 bit SERDES interface. */
829e585c84cSMarek Behún 	reg_set16(CLK_SRC_LO_ADDR(PCIE) + COMPHY_SD_ADDR,
830ccec1bd5SPali Rohár 		  CFG_SEL_20B, CFG_SEL_20B);
8316f8de19fSKonstantin Porotchkin 
8326f8de19fSKonstantin Porotchkin 	/* 3. Force to use reg setting for PCIe mode */
8339cf978c6SMarek Behún 	reg_set16(MISC_CTRL1_ADDR(PCIE) + COMPHY_SD_ADDR,
834ccec1bd5SPali Rohár 		  SEL_BITS_PCIE_FORCE, SEL_BITS_PCIE_FORCE);
8356f8de19fSKonstantin Porotchkin 
8366f8de19fSKonstantin Porotchkin 	/* 4. Change RX wait */
8376f8de19fSKonstantin Porotchkin 	reg_set16(PWR_MGM_TIM1_ADDR(PCIE) + COMPHY_SD_ADDR,
8386f8de19fSKonstantin Porotchkin 		  CFG_PM_RXDEN_WAIT_1_UNIT | CFG_PM_RXDLOZ_WAIT_12_UNIT,
8396f8de19fSKonstantin Porotchkin 		  (CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
8406f8de19fSKonstantin Porotchkin 		   CFG_PM_RXDLOZ_WAIT_MASK));
8416f8de19fSKonstantin Porotchkin 
8426f8de19fSKonstantin Porotchkin 	/* 5. Enable idle sync */
84386f6b55dSMarek Behún 	reg_set16(IDLE_SYNC_EN_ADDR(PCIE) + COMPHY_SD_ADDR,
84486f6b55dSMarek Behún 		  IDLE_SYNC_EN_DEFAULT_VALUE | IDLE_SYNC_EN, REG_16_BIT_MASK);
8456f8de19fSKonstantin Porotchkin 
8466f8de19fSKonstantin Porotchkin 	/* 6. Enable the output of 100M/125M/500M clock */
8479cf978c6SMarek Behún 	reg_set16(MISC_CTRL0_ADDR(PCIE) + COMPHY_SD_ADDR,
8489cf978c6SMarek Behún 		  MISC_CTRL0_DEFAULT_VALUE | CLK500M_EN | TXDCLK_2X_SEL | CLK100M_125M_EN,
8496f8de19fSKonstantin Porotchkin 		  REG_16_BIT_MASK);
8506f8de19fSKonstantin Porotchkin 
8516f8de19fSKonstantin Porotchkin 	/*
8526f8de19fSKonstantin Porotchkin 	 * 7. Enable TX, PCIE global register, 0xd0074814, it is done in
8536f8de19fSKonstantin Porotchkin 	 * PCI-E driver
8546f8de19fSKonstantin Porotchkin 	 */
8556f8de19fSKonstantin Porotchkin 
8566f8de19fSKonstantin Porotchkin 	/*
8576f8de19fSKonstantin Porotchkin 	 * 8. Check crystal jumper setting and program the Power and PLL
8586f8de19fSKonstantin Porotchkin 	 * Control accordingly
8596f8de19fSKonstantin Porotchkin 	 */
8606f8de19fSKonstantin Porotchkin 
8616f8de19fSKonstantin Porotchkin 	if (get_ref_clk() == 40)
8626ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
8636f8de19fSKonstantin Porotchkin 	else
8646ba97f83SMarek Behún 		ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
8656f8de19fSKonstantin Porotchkin 
8666f8de19fSKonstantin Porotchkin 	reg_set16(PWR_PLL_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR,
8676f8de19fSKonstantin Porotchkin 		  (PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
8686f8de19fSKonstantin Porotchkin 		   PU_TX_INTP_BIT | PU_DFE_BIT | ref_clk | PHY_MODE_PCIE),
8696f8de19fSKonstantin Porotchkin 		  REG_16_BIT_MASK);
8706f8de19fSKonstantin Porotchkin 
8716f8de19fSKonstantin Porotchkin 	/* 9. Override Speed_PLL value and use MAC PLL */
8726f8de19fSKonstantin Porotchkin 	reg_set16(KVCO_CAL_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR,
8736f8de19fSKonstantin Porotchkin 		  SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT, REG_16_BIT_MASK);
8746f8de19fSKonstantin Porotchkin 
8756f8de19fSKonstantin Porotchkin 	/* 10. Check the Polarity invert bit */
876ee4c70ebSPali Rohár 	data = 0U;
877ee4c70ebSPali Rohár 	if (invert & COMPHY_POLARITY_TXD_INVERT) {
878ee4c70ebSPali Rohár 		data |= TXD_INVERT_BIT;
879ee4c70ebSPali Rohár 	}
880ee4c70ebSPali Rohár 	if (invert & COMPHY_POLARITY_RXD_INVERT) {
881ee4c70ebSPali Rohár 		data |= RXD_INVERT_BIT;
882ee4c70ebSPali Rohár 	}
883ee4c70ebSPali Rohár 	mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
884b3491336SMarek Behún 	reg_set16(SYNC_PATTERN_ADDR(PCIE) + COMPHY_SD_ADDR, data, mask);
8856f8de19fSKonstantin Porotchkin 
8866f8de19fSKonstantin Porotchkin 	/* 11. Release SW reset */
8874d01bfe6SMarek Behún 	data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32;
8884d01bfe6SMarek Behún 	mask = data | SOFT_RESET | MODE_REFDIV_MASK;
8896a14ac78SMarek Behún 	reg_set16(RST_CLK_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR, data, mask);
8906f8de19fSKonstantin Porotchkin 
8916f8de19fSKonstantin Porotchkin 	/* Wait for > 55 us to allow PCLK be enabled */
8926f8de19fSKonstantin Porotchkin 	udelay(PLL_SET_DELAY_US);
8936f8de19fSKonstantin Porotchkin 
8946eb04379SMarek Behún 	ret = polling_with_timeout(LANE_STAT1_ADDR(PCIE) + COMPHY_SD_ADDR,
8956f8de19fSKonstantin Porotchkin 				   TXDCLK_PCLK_EN, TXDCLK_PCLK_EN,
8966f8de19fSKonstantin Porotchkin 				   COMPHY_PLL_TIMEOUT, REG_16BIT);
89749b664e7SPali Rohár 	if (ret) {
8986f8de19fSKonstantin Porotchkin 		ERROR("Failed to lock PCIE PLL\n");
89949b664e7SPali Rohár 		return -ETIMEDOUT;
90049b664e7SPali Rohár 	}
9016f8de19fSKonstantin Porotchkin 
9026f8de19fSKonstantin Porotchkin 	debug_exit();
9036f8de19fSKonstantin Porotchkin 
90449b664e7SPali Rohár 	return 0;
9056f8de19fSKonstantin Porotchkin }
9066f8de19fSKonstantin Porotchkin 
mvebu_3700_comphy_power_on(uint8_t comphy_index,uint32_t comphy_mode)9076f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_power_on(uint8_t comphy_index, uint32_t comphy_mode)
9086f8de19fSKonstantin Porotchkin {
9096f8de19fSKonstantin Porotchkin 	int mode = COMPHY_GET_MODE(comphy_mode);
9106f8de19fSKonstantin Porotchkin 	int ret = 0;
9116f8de19fSKonstantin Porotchkin 
9126f8de19fSKonstantin Porotchkin 	debug_enter();
9136f8de19fSKonstantin Porotchkin 
9146f8de19fSKonstantin Porotchkin 	switch (mode) {
9156f8de19fSKonstantin Porotchkin 	case(COMPHY_SATA_MODE):
9166f8de19fSKonstantin Porotchkin 		ret = mvebu_a3700_comphy_sata_power_on(comphy_index,
9176f8de19fSKonstantin Porotchkin 						       comphy_mode);
9186f8de19fSKonstantin Porotchkin 		break;
9196f8de19fSKonstantin Porotchkin 	case(COMPHY_SGMII_MODE):
920a669983cSPali Rohár 	case(COMPHY_2500BASEX_MODE):
9216f8de19fSKonstantin Porotchkin 		ret = mvebu_a3700_comphy_sgmii_power_on(comphy_index,
9226f8de19fSKonstantin Porotchkin 							comphy_mode);
9236f8de19fSKonstantin Porotchkin 		break;
9246f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3_MODE):
9256f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3H_MODE):
9266f8de19fSKonstantin Porotchkin 		ret = mvebu_a3700_comphy_usb3_power_on(comphy_index,
9276f8de19fSKonstantin Porotchkin 						       comphy_mode);
9286f8de19fSKonstantin Porotchkin 		break;
9296f8de19fSKonstantin Porotchkin 	case (COMPHY_PCIE_MODE):
9306f8de19fSKonstantin Porotchkin 		ret = mvebu_a3700_comphy_pcie_power_on(comphy_index,
9316f8de19fSKonstantin Porotchkin 						       comphy_mode);
9326f8de19fSKonstantin Porotchkin 		break;
9336f8de19fSKonstantin Porotchkin 	default:
9346f8de19fSKonstantin Porotchkin 		ERROR("comphy%d: unsupported comphy mode\n", comphy_index);
9356f8de19fSKonstantin Porotchkin 		ret = -EINVAL;
9366f8de19fSKonstantin Porotchkin 		break;
9376f8de19fSKonstantin Porotchkin 	}
9386f8de19fSKonstantin Porotchkin 
9396f8de19fSKonstantin Porotchkin 	debug_exit();
9406f8de19fSKonstantin Porotchkin 
9416f8de19fSKonstantin Porotchkin 	return ret;
9426f8de19fSKonstantin Porotchkin }
9436f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_usb3_power_off(void)9446f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_usb3_power_off(void)
9456f8de19fSKonstantin Porotchkin {
9466f8de19fSKonstantin Porotchkin 	/*
9476f8de19fSKonstantin Porotchkin 	 * Currently the USB3 MAC will control the USB3 PHY to set it to low
9486f8de19fSKonstantin Porotchkin 	 * state, thus do not need to power off USB3 PHY again.
9496f8de19fSKonstantin Porotchkin 	 */
9506f8de19fSKonstantin Porotchkin 	debug_enter();
9516f8de19fSKonstantin Porotchkin 	debug_exit();
9526f8de19fSKonstantin Porotchkin 
9536f8de19fSKonstantin Porotchkin 	return 0;
9546f8de19fSKonstantin Porotchkin }
9556f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_sata_power_off(void)956fc299ce0SPali Rohár static int mvebu_a3700_comphy_sata_power_off(void)
9576f8de19fSKonstantin Porotchkin {
9586f8de19fSKonstantin Porotchkin 	uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG;
9596f8de19fSKonstantin Porotchkin 	uint32_t offset;
9606f8de19fSKonstantin Porotchkin 
9616f8de19fSKonstantin Porotchkin 	debug_enter();
9626f8de19fSKonstantin Porotchkin 
9636f8de19fSKonstantin Porotchkin 	/* Set phy isolation mode */
964b3491336SMarek Behún 	offset = COMPHY_ISOLATION_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET;
965be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, PHY_ISOLATE_MODE,
966be33dce7SPali Rohár 				 PHY_ISOLATE_MODE);
9676f8de19fSKonstantin Porotchkin 
9686f8de19fSKonstantin Porotchkin 	/* Power off PLL, Tx, Rx */
9696f8de19fSKonstantin Porotchkin 	offset = COMPHY_POWER_PLL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET;
970be33dce7SPali Rohár 	comphy_sata_set_indirect(comphy_indir_regs, offset, 0,
971be33dce7SPali Rohár 				 PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT);
9726f8de19fSKonstantin Porotchkin 
9736f8de19fSKonstantin Porotchkin 	debug_exit();
9746f8de19fSKonstantin Porotchkin 
9756f8de19fSKonstantin Porotchkin 	return 0;
9766f8de19fSKonstantin Porotchkin }
9776f8de19fSKonstantin Porotchkin 
mvebu_3700_comphy_power_off(uint8_t comphy_index,uint32_t comphy_mode)9786f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_power_off(uint8_t comphy_index, uint32_t comphy_mode)
9796f8de19fSKonstantin Porotchkin {
9806f8de19fSKonstantin Porotchkin 	int mode = COMPHY_GET_MODE(comphy_mode);
9816f8de19fSKonstantin Porotchkin 	int err = 0;
9826f8de19fSKonstantin Porotchkin 
9836f8de19fSKonstantin Porotchkin 	debug_enter();
9846f8de19fSKonstantin Porotchkin 
985629dd61fSMarek Behún 	if (!mode) {
986629dd61fSMarek Behún 		/*
987629dd61fSMarek Behún 		 * The user did not specify which mode should be powered off.
988629dd61fSMarek Behún 		 * In this case we can identify this by reading the phy selector
989629dd61fSMarek Behún 		 * register.
990629dd61fSMarek Behún 		 */
991629dd61fSMarek Behún 		mode = mvebu_a3700_comphy_get_mode(comphy_index);
992629dd61fSMarek Behún 	}
993629dd61fSMarek Behún 
9946f8de19fSKonstantin Porotchkin 	switch (mode) {
995629dd61fSMarek Behún 	case(COMPHY_SGMII_MODE):
996a669983cSPali Rohár 	case(COMPHY_2500BASEX_MODE):
997629dd61fSMarek Behún 		err = mvebu_a3700_comphy_sgmii_power_off(comphy_index);
998629dd61fSMarek Behún 		break;
9996f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3_MODE):
10006f8de19fSKonstantin Porotchkin 	case (COMPHY_USB3H_MODE):
10016f8de19fSKonstantin Porotchkin 		err = mvebu_a3700_comphy_usb3_power_off();
10026f8de19fSKonstantin Porotchkin 		break;
10036f8de19fSKonstantin Porotchkin 	case (COMPHY_SATA_MODE):
1004fc299ce0SPali Rohár 		err = mvebu_a3700_comphy_sata_power_off();
10056f8de19fSKonstantin Porotchkin 		break;
10066f8de19fSKonstantin Porotchkin 
10076f8de19fSKonstantin Porotchkin 	default:
10086f8de19fSKonstantin Porotchkin 		debug("comphy%d: power off is not implemented for mode %d\n",
10096f8de19fSKonstantin Porotchkin 		      comphy_index, mode);
10106f8de19fSKonstantin Porotchkin 		break;
10116f8de19fSKonstantin Porotchkin 	}
10126f8de19fSKonstantin Porotchkin 
10136f8de19fSKonstantin Porotchkin 	debug_exit();
10146f8de19fSKonstantin Porotchkin 
10156f8de19fSKonstantin Porotchkin 	return err;
10166f8de19fSKonstantin Porotchkin }
10176f8de19fSKonstantin Porotchkin 
mvebu_a3700_comphy_sata_is_pll_locked(void)10186f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sata_is_pll_locked(void)
10196f8de19fSKonstantin Porotchkin {
10206f8de19fSKonstantin Porotchkin 	uint32_t data, addr;
10216f8de19fSKonstantin Porotchkin 	uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG;
10226f8de19fSKonstantin Porotchkin 	int ret = 0;
10236f8de19fSKonstantin Porotchkin 
10246f8de19fSKonstantin Porotchkin 	debug_enter();
10256f8de19fSKonstantin Porotchkin 
10266f8de19fSKonstantin Porotchkin 	/* Polling status */
10276f8de19fSKonstantin Porotchkin 	mmio_write_32(comphy_indir_regs + COMPHY_LANE2_INDIR_ADDR_OFFSET,
10284c995d2dSMarek Behún 	       COMPHY_DIG_LOOPBACK_EN + SATAPHY_LANE2_REG_BASE_OFFSET);
10296f8de19fSKonstantin Porotchkin 	addr = comphy_indir_regs + COMPHY_LANE2_INDIR_DATA_OFFSET;
10306f8de19fSKonstantin Porotchkin 	data = polling_with_timeout(addr, PLL_READY_TX_BIT, PLL_READY_TX_BIT,
10316f8de19fSKonstantin Porotchkin 				    COMPHY_PLL_TIMEOUT, REG_32BIT);
10326f8de19fSKonstantin Porotchkin 
10336f8de19fSKonstantin Porotchkin 	if (data != 0) {
10346f8de19fSKonstantin Porotchkin 		ERROR("TX PLL is not locked\n");
10356f8de19fSKonstantin Porotchkin 		ret = -ETIMEDOUT;
10366f8de19fSKonstantin Porotchkin 	}
10376f8de19fSKonstantin Porotchkin 
10386f8de19fSKonstantin Porotchkin 	debug_exit();
10396f8de19fSKonstantin Porotchkin 
10406f8de19fSKonstantin Porotchkin 	return ret;
10416f8de19fSKonstantin Porotchkin }
10426f8de19fSKonstantin Porotchkin 
mvebu_3700_comphy_is_pll_locked(uint8_t comphy_index,uint32_t comphy_mode)10436f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_is_pll_locked(uint8_t comphy_index, uint32_t comphy_mode)
10446f8de19fSKonstantin Porotchkin {
10456f8de19fSKonstantin Porotchkin 	int mode = COMPHY_GET_MODE(comphy_mode);
10466f8de19fSKonstantin Porotchkin 	int ret = 0;
10476f8de19fSKonstantin Porotchkin 
10486f8de19fSKonstantin Porotchkin 	debug_enter();
10496f8de19fSKonstantin Porotchkin 
10506f8de19fSKonstantin Porotchkin 	switch (mode) {
10516f8de19fSKonstantin Porotchkin 	case(COMPHY_SATA_MODE):
10526f8de19fSKonstantin Porotchkin 		ret = mvebu_a3700_comphy_sata_is_pll_locked();
10536f8de19fSKonstantin Porotchkin 		break;
10546f8de19fSKonstantin Porotchkin 
10556f8de19fSKonstantin Porotchkin 	default:
10566f8de19fSKonstantin Porotchkin 		ERROR("comphy[%d] mode[%d] doesn't support PLL lock check\n",
10576f8de19fSKonstantin Porotchkin 			comphy_index, mode);
10586f8de19fSKonstantin Porotchkin 		ret = -EINVAL;
10596f8de19fSKonstantin Porotchkin 		break;
10606f8de19fSKonstantin Porotchkin 	}
10616f8de19fSKonstantin Porotchkin 
10626f8de19fSKonstantin Porotchkin 	debug_exit();
10636f8de19fSKonstantin Porotchkin 
10646f8de19fSKonstantin Porotchkin 	return ret;
10656f8de19fSKonstantin Porotchkin }
1066