16f8de19fSKonstantin Porotchkin /* 26f8de19fSKonstantin Porotchkin * Copyright (C) 2018 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> 17*5a91c439SPali 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 */ 1216f8de19fSKonstantin Porotchkin static void 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): 1386f8de19fSKonstantin Porotchkin case (COMPHY_HS_SGMII_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); 1716f8de19fSKonstantin Porotchkin return; 1726f8de19fSKonstantin Porotchkin error: 1736f8de19fSKonstantin Porotchkin ERROR("COMPHY[%d] mode[%d] is invalid\n", comphy_index, mode); 1746f8de19fSKonstantin Porotchkin } 1756f8de19fSKonstantin Porotchkin 176629dd61fSMarek Behún /* 177629dd61fSMarek Behún * This is something like the inverse of the previous function: for given 178629dd61fSMarek Behún * lane it returns COMPHY_*_MODE. 179629dd61fSMarek Behún * 180629dd61fSMarek Behún * It is useful when powering the phy off. 181629dd61fSMarek Behún * 182629dd61fSMarek Behún * This function returns COMPHY_USB3_MODE even if the phy was configured 183629dd61fSMarek Behún * with COMPHY_USB3D_MODE or COMPHY_USB3H_MODE. (The usb3 phy initialization 184629dd61fSMarek Behún * code does not differentiate between these modes.) 185629dd61fSMarek Behún * Also it returns COMPHY_SGMII_MODE even if the phy was configures with 186629dd61fSMarek Behún * COMPHY_HS_SGMII_MODE. (The sgmii phy initialization code does differentiate 187629dd61fSMarek Behún * between these modes, but it is irrelevant when powering the phy off.) 188629dd61fSMarek Behún */ 189629dd61fSMarek Behún static int mvebu_a3700_comphy_get_mode(uint8_t comphy_index) 190629dd61fSMarek Behún { 191629dd61fSMarek Behún uint32_t reg; 192629dd61fSMarek Behún 193629dd61fSMarek Behún reg = mmio_read_32(MVEBU_COMPHY_REG_BASE + COMPHY_SELECTOR_PHY_REG); 194629dd61fSMarek Behún switch (comphy_index) { 195629dd61fSMarek Behún case COMPHY_LANE0: 196629dd61fSMarek Behún if ((reg & COMPHY_SELECTOR_USB3_GBE1_SEL_BIT) != 0) 197629dd61fSMarek Behún return COMPHY_USB3_MODE; 198629dd61fSMarek Behún else 199629dd61fSMarek Behún return COMPHY_SGMII_MODE; 200629dd61fSMarek Behún case COMPHY_LANE1: 201629dd61fSMarek Behún if ((reg & COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT) != 0) 202629dd61fSMarek Behún return COMPHY_PCIE_MODE; 203629dd61fSMarek Behún else 204629dd61fSMarek Behún return COMPHY_SGMII_MODE; 205629dd61fSMarek Behún case COMPHY_LANE2: 206629dd61fSMarek Behún if ((reg & COMPHY_SELECTOR_USB3_PHY_SEL_BIT) != 0) 207629dd61fSMarek Behún return COMPHY_USB3_MODE; 208629dd61fSMarek Behún else 209629dd61fSMarek Behún return COMPHY_SATA_MODE; 210629dd61fSMarek Behún } 211629dd61fSMarek Behún 212629dd61fSMarek Behún return COMPHY_UNUSED; 213629dd61fSMarek Behún } 214629dd61fSMarek Behún 2156f8de19fSKonstantin Porotchkin /* It is only used for SATA and USB3 on comphy lane2. */ 2166f8de19fSKonstantin Porotchkin static void comphy_set_indirect(uintptr_t addr, uint32_t offset, uint16_t data, 2176f8de19fSKonstantin Porotchkin uint16_t mask, int mode) 2186f8de19fSKonstantin Porotchkin { 2196f8de19fSKonstantin Porotchkin /* 2206f8de19fSKonstantin Porotchkin * When Lane 2 PHY is for USB3, access the PHY registers 2216f8de19fSKonstantin Porotchkin * through indirect Address and Data registers: 2226f8de19fSKonstantin Porotchkin * INDIR_ACC_PHY_ADDR (RD00E0178h [31:0]), 2236f8de19fSKonstantin Porotchkin * INDIR_ACC_PHY_DATA (RD00E017Ch [31:0]), 2246f8de19fSKonstantin Porotchkin * within the SATA Host Controller registers, Lane 2 base register 2256f8de19fSKonstantin Porotchkin * offset is 0x200 2266f8de19fSKonstantin Porotchkin */ 2276f8de19fSKonstantin Porotchkin if (mode == COMPHY_UNUSED) 2286f8de19fSKonstantin Porotchkin return; 2296f8de19fSKonstantin Porotchkin 2306f8de19fSKonstantin Porotchkin if (mode == COMPHY_SATA_MODE) 2316f8de19fSKonstantin Porotchkin mmio_write_32(addr + COMPHY_LANE2_INDIR_ADDR_OFFSET, offset); 2326f8de19fSKonstantin Porotchkin else 2336f8de19fSKonstantin Porotchkin mmio_write_32(addr + COMPHY_LANE2_INDIR_ADDR_OFFSET, 2346f8de19fSKonstantin Porotchkin offset + USB3PHY_LANE2_REG_BASE_OFFSET); 2356f8de19fSKonstantin Porotchkin 2366f8de19fSKonstantin Porotchkin reg_set(addr + COMPHY_LANE2_INDIR_DATA_OFFSET, data, mask); 2376f8de19fSKonstantin Porotchkin } 2386f8de19fSKonstantin Porotchkin 2396f8de19fSKonstantin Porotchkin /* It is only used USB3 direct access not on comphy lane2. */ 2406f8de19fSKonstantin Porotchkin static void comphy_usb3_set_direct(uintptr_t addr, uint32_t reg_offset, 2416f8de19fSKonstantin Porotchkin uint16_t data, uint16_t mask, int mode) 2426f8de19fSKonstantin Porotchkin { 2436f8de19fSKonstantin Porotchkin reg_set16((reg_offset * PHY_SHFT(USB3) + addr), data, mask); 2446f8de19fSKonstantin Porotchkin } 2456f8de19fSKonstantin Porotchkin 2466f8de19fSKonstantin Porotchkin static void comphy_sgmii_phy_init(uint32_t comphy_index, uint32_t mode, 2476f8de19fSKonstantin Porotchkin uintptr_t sd_ip_addr) 2486f8de19fSKonstantin Porotchkin { 2496f8de19fSKonstantin Porotchkin const int fix_arr_sz = ARRAY_SIZE(sgmii_phy_init_fix); 2506f8de19fSKonstantin Porotchkin int addr, fix_idx; 2516f8de19fSKonstantin Porotchkin uint16_t val; 2526f8de19fSKonstantin Porotchkin 2536f8de19fSKonstantin Porotchkin fix_idx = 0; 2546f8de19fSKonstantin Porotchkin for (addr = 0; addr < 512; addr++) { 2556f8de19fSKonstantin Porotchkin /* 2566f8de19fSKonstantin Porotchkin * All PHY register values are defined in full for 3.125Gbps 2576f8de19fSKonstantin Porotchkin * SERDES speed. The values required for 1.25 Gbps are almost 2586f8de19fSKonstantin Porotchkin * the same and only few registers should be "fixed" in 2596f8de19fSKonstantin Porotchkin * comparison to 3.125 Gbps values. These register values are 2606f8de19fSKonstantin Porotchkin * stored in "sgmii_phy_init_fix" array. 2616f8de19fSKonstantin Porotchkin */ 2626f8de19fSKonstantin Porotchkin if ((mode != COMPHY_SGMII_MODE) && 2636f8de19fSKonstantin Porotchkin (sgmii_phy_init_fix[fix_idx].addr == addr)) { 2646f8de19fSKonstantin Porotchkin /* Use new value */ 2656f8de19fSKonstantin Porotchkin val = sgmii_phy_init_fix[fix_idx].value; 2666f8de19fSKonstantin Porotchkin if (fix_idx < fix_arr_sz) 2676f8de19fSKonstantin Porotchkin fix_idx++; 2686f8de19fSKonstantin Porotchkin } else { 2696f8de19fSKonstantin Porotchkin val = sgmii_phy_init[addr]; 2706f8de19fSKonstantin Porotchkin } 2716f8de19fSKonstantin Porotchkin 2726f8de19fSKonstantin Porotchkin reg_set16(SGMIIPHY_ADDR(addr, sd_ip_addr), val, 0xFFFF); 2736f8de19fSKonstantin Porotchkin } 2746f8de19fSKonstantin Porotchkin } 2756f8de19fSKonstantin Porotchkin 2766f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sata_power_on(uint8_t comphy_index, 2776f8de19fSKonstantin Porotchkin uint32_t comphy_mode) 2786f8de19fSKonstantin Porotchkin { 2796f8de19fSKonstantin Porotchkin int ret = 0; 2806f8de19fSKonstantin Porotchkin uint32_t offset, data = 0, ref_clk; 2816f8de19fSKonstantin Porotchkin uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG; 2826f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 2836f8de19fSKonstantin Porotchkin int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode); 2846f8de19fSKonstantin Porotchkin 2856f8de19fSKonstantin Porotchkin debug_enter(); 2866f8de19fSKonstantin Porotchkin 2876f8de19fSKonstantin Porotchkin /* Configure phy selector for SATA */ 2886f8de19fSKonstantin Porotchkin mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode); 2896f8de19fSKonstantin Porotchkin 2906f8de19fSKonstantin Porotchkin /* Clear phy isolation mode to make it work in normal mode */ 2916f8de19fSKonstantin Porotchkin offset = COMPHY_ISOLATION_CTRL_REG + SATAPHY_LANE2_REG_BASE_OFFSET; 2926f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, 0, PHY_ISOLATE_MODE, 2936f8de19fSKonstantin Porotchkin mode); 2946f8de19fSKonstantin Porotchkin 2956f8de19fSKonstantin Porotchkin /* 0. Check the Polarity invert bits */ 2966f8de19fSKonstantin Porotchkin if (invert & COMPHY_POLARITY_TXD_INVERT) 2976f8de19fSKonstantin Porotchkin data |= TXD_INVERT_BIT; 2986f8de19fSKonstantin Porotchkin if (invert & COMPHY_POLARITY_RXD_INVERT) 2996f8de19fSKonstantin Porotchkin data |= RXD_INVERT_BIT; 3006f8de19fSKonstantin Porotchkin 3016f8de19fSKonstantin Porotchkin offset = COMPHY_SYNC_PATTERN_REG + SATAPHY_LANE2_REG_BASE_OFFSET; 3026f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, data, TXD_INVERT_BIT | 3036f8de19fSKonstantin Porotchkin RXD_INVERT_BIT, mode); 3046f8de19fSKonstantin Porotchkin 3056f8de19fSKonstantin Porotchkin /* 1. Select 40-bit data width width */ 3066f8de19fSKonstantin Porotchkin offset = COMPHY_LOOPBACK_REG0 + SATAPHY_LANE2_REG_BASE_OFFSET; 3076f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, DATA_WIDTH_40BIT, 3086f8de19fSKonstantin Porotchkin SEL_DATA_WIDTH_MASK, mode); 3096f8de19fSKonstantin Porotchkin 3106f8de19fSKonstantin Porotchkin /* 2. Select reference clock(25M) and PHY mode (SATA) */ 3116f8de19fSKonstantin Porotchkin offset = COMPHY_POWER_PLL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET; 3126f8de19fSKonstantin Porotchkin if (get_ref_clk() == 40) 3136f8de19fSKonstantin Porotchkin ref_clk = REF_CLOCK_SPEED_40M; 3146f8de19fSKonstantin Porotchkin else 3156f8de19fSKonstantin Porotchkin ref_clk = REF_CLOCK_SPEED_25M; 3166f8de19fSKonstantin Porotchkin 3176f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, ref_clk | PHY_MODE_SATA, 3186f8de19fSKonstantin Porotchkin REF_FREF_SEL_MASK | PHY_MODE_MASK, mode); 3196f8de19fSKonstantin Porotchkin 3206f8de19fSKonstantin Porotchkin /* 3. Use maximum PLL rate (no power save) */ 3216f8de19fSKonstantin Porotchkin offset = COMPHY_KVCO_CAL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET; 3226f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, USE_MAX_PLL_RATE_BIT, 3236f8de19fSKonstantin Porotchkin USE_MAX_PLL_RATE_BIT, mode); 3246f8de19fSKonstantin Porotchkin 3256f8de19fSKonstantin Porotchkin /* 4. Reset reserved bit */ 3266f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, COMPHY_RESERVED_REG, 0, 3276f8de19fSKonstantin Porotchkin PHYCTRL_FRM_PIN_BIT, mode); 3286f8de19fSKonstantin Porotchkin 3296f8de19fSKonstantin Porotchkin /* 5. Set vendor-specific configuration (It is done in sata driver) */ 3306f8de19fSKonstantin Porotchkin /* XXX: in U-Boot below sequence was executed in this place, in Linux 3316f8de19fSKonstantin Porotchkin * not. Now it is done only in U-Boot before this comphy 3326f8de19fSKonstantin Porotchkin * initialization - tests shows that it works ok, but in case of any 3336f8de19fSKonstantin Porotchkin * future problem it is left for reference. 3346f8de19fSKonstantin Porotchkin * reg_set(MVEBU_REGS_BASE + 0xe00a0, 0, 0xffffffff); 3356f8de19fSKonstantin Porotchkin * reg_set(MVEBU_REGS_BASE + 0xe00a4, BIT(6), BIT(6)); 3366f8de19fSKonstantin Porotchkin */ 3376f8de19fSKonstantin Porotchkin 3386f8de19fSKonstantin Porotchkin /* Wait for > 55 us to allow PLL be enabled */ 3396f8de19fSKonstantin Porotchkin udelay(PLL_SET_DELAY_US); 3406f8de19fSKonstantin Porotchkin 3416f8de19fSKonstantin Porotchkin /* Polling status */ 3426f8de19fSKonstantin Porotchkin mmio_write_32(comphy_indir_regs + COMPHY_LANE2_INDIR_ADDR_OFFSET, 3436f8de19fSKonstantin Porotchkin COMPHY_LOOPBACK_REG0 + SATAPHY_LANE2_REG_BASE_OFFSET); 3446f8de19fSKonstantin Porotchkin 3456f8de19fSKonstantin Porotchkin ret = polling_with_timeout(comphy_indir_regs + 3466f8de19fSKonstantin Porotchkin COMPHY_LANE2_INDIR_DATA_OFFSET, 3476f8de19fSKonstantin Porotchkin PLL_READY_TX_BIT, PLL_READY_TX_BIT, 3486f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 3496f8de19fSKonstantin Porotchkin 3506f8de19fSKonstantin Porotchkin debug_exit(); 3516f8de19fSKonstantin Porotchkin 3526f8de19fSKonstantin Porotchkin return ret; 3536f8de19fSKonstantin Porotchkin } 3546f8de19fSKonstantin Porotchkin 3556f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sgmii_power_on(uint8_t comphy_index, 3566f8de19fSKonstantin Porotchkin uint32_t comphy_mode) 3576f8de19fSKonstantin Porotchkin { 3586f8de19fSKonstantin Porotchkin int ret = 0; 3596f8de19fSKonstantin Porotchkin uint32_t mask, data, offset; 3606f8de19fSKonstantin Porotchkin uintptr_t sd_ip_addr; 3616f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 3626f8de19fSKonstantin Porotchkin int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode); 3636f8de19fSKonstantin Porotchkin 3646f8de19fSKonstantin Porotchkin debug_enter(); 3656f8de19fSKonstantin Porotchkin 3666f8de19fSKonstantin Porotchkin /* Set selector */ 3676f8de19fSKonstantin Porotchkin mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode); 3686f8de19fSKonstantin Porotchkin 3696f8de19fSKonstantin Porotchkin /* Serdes IP Base address 3706f8de19fSKonstantin Porotchkin * COMPHY Lane0 -- USB3/GBE1 3716f8de19fSKonstantin Porotchkin * COMPHY Lane1 -- PCIe/GBE0 3726f8de19fSKonstantin Porotchkin */ 3736f8de19fSKonstantin Porotchkin if (comphy_index == COMPHY_LANE0) { 3746f8de19fSKonstantin Porotchkin /* Get usb3 and gbe */ 3756f8de19fSKonstantin Porotchkin sd_ip_addr = USB3_GBE1_PHY; 3766f8de19fSKonstantin Porotchkin } else 3776f8de19fSKonstantin Porotchkin sd_ip_addr = COMPHY_SD_ADDR; 3786f8de19fSKonstantin Porotchkin 3796f8de19fSKonstantin Porotchkin /* 3806f8de19fSKonstantin Porotchkin * 1. Reset PHY by setting PHY input port PIN_RESET=1. 3816f8de19fSKonstantin Porotchkin * 2. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep 3826f8de19fSKonstantin Porotchkin * PHY TXP/TXN output to idle state during PHY initialization 3836f8de19fSKonstantin Porotchkin * 3. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0. 3846f8de19fSKonstantin Porotchkin */ 3856f8de19fSKonstantin Porotchkin data = PIN_PU_IVEREF_BIT | PIN_TX_IDLE_BIT | PIN_RESET_COMPHY_BIT; 3866f8de19fSKonstantin Porotchkin mask = PIN_RESET_CORE_BIT | PIN_PU_PLL_BIT | PIN_PU_RX_BIT | 3876f8de19fSKonstantin Porotchkin PIN_PU_TX_BIT; 3886f8de19fSKonstantin Porotchkin offset = MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index); 3896f8de19fSKonstantin Porotchkin reg_set(offset, data, mask); 3906f8de19fSKonstantin Porotchkin 3916f8de19fSKonstantin Porotchkin /* 4. Release reset to the PHY by setting PIN_RESET=0. */ 3926f8de19fSKonstantin Porotchkin data = 0; 3936f8de19fSKonstantin Porotchkin mask = PIN_RESET_COMPHY_BIT; 3946f8de19fSKonstantin Porotchkin reg_set(offset, data, mask); 3956f8de19fSKonstantin Porotchkin 3966f8de19fSKonstantin Porotchkin /* 3976f8de19fSKonstantin Porotchkin * 5. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide COMPHY 3986f8de19fSKonstantin Porotchkin * bit rate 3996f8de19fSKonstantin Porotchkin */ 4006f8de19fSKonstantin Porotchkin if (mode == COMPHY_SGMII_MODE) { 4016f8de19fSKonstantin Porotchkin /* SGMII 1G, SerDes speed 1.25G */ 4026f8de19fSKonstantin Porotchkin data |= SD_SPEED_1_25_G << GEN_RX_SEL_OFFSET; 4036f8de19fSKonstantin Porotchkin data |= SD_SPEED_1_25_G << GEN_TX_SEL_OFFSET; 4046f8de19fSKonstantin Porotchkin } else if (mode == COMPHY_HS_SGMII_MODE) { 4056f8de19fSKonstantin Porotchkin /* HS SGMII (2.5G), SerDes speed 3.125G */ 4066f8de19fSKonstantin Porotchkin data |= SD_SPEED_2_5_G << GEN_RX_SEL_OFFSET; 4076f8de19fSKonstantin Porotchkin data |= SD_SPEED_2_5_G << GEN_TX_SEL_OFFSET; 4086f8de19fSKonstantin Porotchkin } else { 4096f8de19fSKonstantin Porotchkin /* Other rates are not supported */ 4106f8de19fSKonstantin Porotchkin ERROR("unsupported SGMII speed on comphy lane%d\n", 4116f8de19fSKonstantin Porotchkin comphy_index); 4126f8de19fSKonstantin Porotchkin return -EINVAL; 4136f8de19fSKonstantin Porotchkin } 4146f8de19fSKonstantin Porotchkin mask = GEN_RX_SEL_MASK | GEN_TX_SEL_MASK; 4156f8de19fSKonstantin Porotchkin reg_set(offset, data, mask); 4166f8de19fSKonstantin Porotchkin 4176f8de19fSKonstantin Porotchkin /* 4186f8de19fSKonstantin Porotchkin * 6. Wait 10mS for bandgap and reference clocks to stabilize; then 4196f8de19fSKonstantin Porotchkin * start SW programming. 4206f8de19fSKonstantin Porotchkin */ 4216f8de19fSKonstantin Porotchkin mdelay(10); 4226f8de19fSKonstantin Porotchkin 4236f8de19fSKonstantin Porotchkin /* 7. Program COMPHY register PHY_MODE */ 4246f8de19fSKonstantin Porotchkin data = PHY_MODE_SGMII; 4256f8de19fSKonstantin Porotchkin mask = PHY_MODE_MASK; 4266f8de19fSKonstantin Porotchkin reg_set16(SGMIIPHY_ADDR(COMPHY_POWER_PLL_CTRL, sd_ip_addr), data, mask); 4276f8de19fSKonstantin Porotchkin 4286f8de19fSKonstantin Porotchkin /* 4296f8de19fSKonstantin Porotchkin * 8. Set COMPHY register REFCLK_SEL to select the correct REFCLK 4306f8de19fSKonstantin Porotchkin * source 4316f8de19fSKonstantin Porotchkin */ 4326f8de19fSKonstantin Porotchkin data = 0; 4336f8de19fSKonstantin Porotchkin mask = PHY_REF_CLK_SEL; 4346f8de19fSKonstantin Porotchkin reg_set16(SGMIIPHY_ADDR(COMPHY_MISC_REG0_ADDR, sd_ip_addr), data, mask); 4356f8de19fSKonstantin Porotchkin 4366f8de19fSKonstantin Porotchkin /* 4376f8de19fSKonstantin Porotchkin * 9. Set correct reference clock frequency in COMPHY register 4386f8de19fSKonstantin Porotchkin * REF_FREF_SEL. 4396f8de19fSKonstantin Porotchkin */ 4406f8de19fSKonstantin Porotchkin if (get_ref_clk() == 40) 4416f8de19fSKonstantin Porotchkin data = REF_CLOCK_SPEED_50M; 4426f8de19fSKonstantin Porotchkin else 4436f8de19fSKonstantin Porotchkin data = REF_CLOCK_SPEED_25M; 4446f8de19fSKonstantin Porotchkin 4456f8de19fSKonstantin Porotchkin mask = REF_FREF_SEL_MASK; 4466f8de19fSKonstantin Porotchkin reg_set16(SGMIIPHY_ADDR(COMPHY_POWER_PLL_CTRL, sd_ip_addr), data, mask); 4476f8de19fSKonstantin Porotchkin 4486f8de19fSKonstantin Porotchkin /* 10. Program COMPHY register PHY_GEN_MAX[1:0] 4496f8de19fSKonstantin Porotchkin * This step is mentioned in the flow received from verification team. 4506f8de19fSKonstantin Porotchkin * However the PHY_GEN_MAX value is only meaningful for other interfaces 4516f8de19fSKonstantin Porotchkin * (not SGMII). For instance, it selects SATA speed 1.5/3/6 Gbps or PCIe 4526f8de19fSKonstantin Porotchkin * speed 2.5/5 Gbps 4536f8de19fSKonstantin Porotchkin */ 4546f8de19fSKonstantin Porotchkin 4556f8de19fSKonstantin Porotchkin /* 4566f8de19fSKonstantin Porotchkin * 11. Program COMPHY register SEL_BITS to set correct parallel data 4576f8de19fSKonstantin Porotchkin * bus width 4586f8de19fSKonstantin Porotchkin */ 4596f8de19fSKonstantin Porotchkin data = DATA_WIDTH_10BIT; 4606f8de19fSKonstantin Porotchkin mask = SEL_DATA_WIDTH_MASK; 4616f8de19fSKonstantin Porotchkin reg_set16(SGMIIPHY_ADDR(COMPHY_LOOPBACK_REG0, sd_ip_addr), data, mask); 4626f8de19fSKonstantin Porotchkin 4636f8de19fSKonstantin Porotchkin /* 4646f8de19fSKonstantin Porotchkin * 12. As long as DFE function needs to be enabled in any mode, 4656f8de19fSKonstantin Porotchkin * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F 4666f8de19fSKonstantin Porotchkin * for real chip during COMPHY power on. 4676f8de19fSKonstantin Porotchkin * The step 14 exists (and empty) in the original initialization flow 4686f8de19fSKonstantin Porotchkin * obtained from the verification team. According to the functional 4696f8de19fSKonstantin Porotchkin * specification DFE_UPDATE_EN already has the default value 0x3F 4706f8de19fSKonstantin Porotchkin */ 4716f8de19fSKonstantin Porotchkin 4726f8de19fSKonstantin Porotchkin /* 4736f8de19fSKonstantin Porotchkin * 13. Program COMPHY GEN registers. 4746f8de19fSKonstantin Porotchkin * These registers should be programmed based on the lab testing result 4756f8de19fSKonstantin Porotchkin * to achieve optimal performance. Please contact the CEA group to get 4766f8de19fSKonstantin Porotchkin * the related GEN table during real chip bring-up. We only required to 4776f8de19fSKonstantin Porotchkin * run though the entire registers programming flow defined by 4786f8de19fSKonstantin Porotchkin * "comphy_sgmii_phy_init" when the REF clock is 40 MHz. For REF clock 4796f8de19fSKonstantin Porotchkin * 25 MHz the default values stored in PHY registers are OK. 4806f8de19fSKonstantin Porotchkin */ 4816f8de19fSKonstantin Porotchkin debug("Running C-DPI phy init %s mode\n", 4826f8de19fSKonstantin Porotchkin mode == COMPHY_HS_SGMII_MODE ? "2G5" : "1G"); 4836f8de19fSKonstantin Porotchkin if (get_ref_clk() == 40) 4846f8de19fSKonstantin Porotchkin comphy_sgmii_phy_init(comphy_index, mode, sd_ip_addr); 4856f8de19fSKonstantin Porotchkin 4866f8de19fSKonstantin Porotchkin /* 4876f8de19fSKonstantin Porotchkin * 14. [Simulation Only] should not be used for real chip. 4886f8de19fSKonstantin Porotchkin * By pass power up calibration by programming EXT_FORCE_CAL_DONE 4896f8de19fSKonstantin Porotchkin * (R02h[9]) to 1 to shorten COMPHY simulation time. 4906f8de19fSKonstantin Porotchkin */ 4916f8de19fSKonstantin Porotchkin 4926f8de19fSKonstantin Porotchkin /* 4936f8de19fSKonstantin Porotchkin * 15. [Simulation Only: should not be used for real chip] 4946f8de19fSKonstantin Porotchkin * Program COMPHY register FAST_DFE_TIMER_EN=1 to shorten RX training 4956f8de19fSKonstantin Porotchkin * simulation time. 4966f8de19fSKonstantin Porotchkin */ 4976f8de19fSKonstantin Porotchkin 4986f8de19fSKonstantin Porotchkin /* 4996f8de19fSKonstantin Porotchkin * 16. Check the PHY Polarity invert bit 5006f8de19fSKonstantin Porotchkin */ 5016f8de19fSKonstantin Porotchkin data = 0x0; 5026f8de19fSKonstantin Porotchkin if (invert & COMPHY_POLARITY_TXD_INVERT) 5036f8de19fSKonstantin Porotchkin data |= TXD_INVERT_BIT; 5046f8de19fSKonstantin Porotchkin if (invert & COMPHY_POLARITY_RXD_INVERT) 5056f8de19fSKonstantin Porotchkin data |= RXD_INVERT_BIT; 506ee4c70ebSPali Rohár mask = TXD_INVERT_BIT | RXD_INVERT_BIT; 507ee4c70ebSPali Rohár reg_set16(SGMIIPHY_ADDR(COMPHY_SYNC_PATTERN_REG, sd_ip_addr), data, mask); 5086f8de19fSKonstantin Porotchkin 5096f8de19fSKonstantin Porotchkin /* 5106f8de19fSKonstantin Porotchkin * 17. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1 to 5116f8de19fSKonstantin Porotchkin * start PHY power up sequence. All the PHY register programming should 5126f8de19fSKonstantin Porotchkin * be done before PIN_PU_PLL=1. There should be no register programming 5136f8de19fSKonstantin Porotchkin * for normal PHY operation from this point. 5146f8de19fSKonstantin Porotchkin */ 5156f8de19fSKonstantin Porotchkin reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index), 5166f8de19fSKonstantin Porotchkin PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT, 5176f8de19fSKonstantin Porotchkin PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT); 5186f8de19fSKonstantin Porotchkin 5196f8de19fSKonstantin Porotchkin /* 5206f8de19fSKonstantin Porotchkin * 18. Wait for PHY power up sequence to finish by checking output ports 5216f8de19fSKonstantin Porotchkin * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1. 5226f8de19fSKonstantin Porotchkin */ 5236f8de19fSKonstantin Porotchkin ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE + 5246f8de19fSKonstantin Porotchkin COMPHY_PHY_STATUS_OFFSET(comphy_index), 5256f8de19fSKonstantin Porotchkin PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT, 5266f8de19fSKonstantin Porotchkin PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT, 5276f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 5286f8de19fSKonstantin Porotchkin if (ret) 5296f8de19fSKonstantin Porotchkin ERROR("Failed to lock PLL for SGMII PHY %d\n", comphy_index); 5306f8de19fSKonstantin Porotchkin 5316f8de19fSKonstantin Porotchkin /* 5326f8de19fSKonstantin Porotchkin * 19. Set COMPHY input port PIN_TX_IDLE=0 5336f8de19fSKonstantin Porotchkin */ 5346f8de19fSKonstantin Porotchkin reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index), 5356f8de19fSKonstantin Porotchkin 0x0, PIN_TX_IDLE_BIT); 5366f8de19fSKonstantin Porotchkin 5376f8de19fSKonstantin Porotchkin /* 5386f8de19fSKonstantin Porotchkin * 20. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1. To 5396f8de19fSKonstantin Porotchkin * start RX initialization. PIN_RX_INIT_DONE will be cleared to 0 by the 5406f8de19fSKonstantin Porotchkin * PHY After RX initialization is done, PIN_RX_INIT_DONE will be set to 5416f8de19fSKonstantin Porotchkin * 1 by COMPHY Set PIN_RX_INIT=0 after PIN_RX_INIT_DONE= 1. Please 5426f8de19fSKonstantin Porotchkin * refer to RX initialization part for details. 5436f8de19fSKonstantin Porotchkin */ 5446f8de19fSKonstantin Porotchkin reg_set(MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index), 545ccec1bd5SPali Rohár PHY_RX_INIT_BIT, PHY_RX_INIT_BIT); 5466f8de19fSKonstantin Porotchkin 5476f8de19fSKonstantin Porotchkin ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE + 5486f8de19fSKonstantin Porotchkin COMPHY_PHY_STATUS_OFFSET(comphy_index), 5496f8de19fSKonstantin Porotchkin PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT, 5506f8de19fSKonstantin Porotchkin PHY_PLL_READY_TX_BIT | PHY_PLL_READY_RX_BIT, 5516f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 5526f8de19fSKonstantin Porotchkin if (ret) 5536f8de19fSKonstantin Porotchkin ERROR("Failed to lock PLL for SGMII PHY %d\n", comphy_index); 5546f8de19fSKonstantin Porotchkin 5556f8de19fSKonstantin Porotchkin 5566f8de19fSKonstantin Porotchkin ret = polling_with_timeout(MVEBU_COMPHY_REG_BASE + 5576f8de19fSKonstantin Porotchkin COMPHY_PHY_STATUS_OFFSET(comphy_index), 5586f8de19fSKonstantin Porotchkin PHY_RX_INIT_DONE_BIT, PHY_RX_INIT_DONE_BIT, 5596f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 5606f8de19fSKonstantin Porotchkin if (ret) 5616f8de19fSKonstantin Porotchkin ERROR("Failed to init RX of SGMII PHY %d\n", comphy_index); 5626f8de19fSKonstantin Porotchkin 5636f8de19fSKonstantin Porotchkin debug_exit(); 5646f8de19fSKonstantin Porotchkin 5656f8de19fSKonstantin Porotchkin return ret; 5666f8de19fSKonstantin Porotchkin } 5676f8de19fSKonstantin Porotchkin 568629dd61fSMarek Behún static int mvebu_a3700_comphy_sgmii_power_off(uint8_t comphy_index) 569629dd61fSMarek Behún { 570629dd61fSMarek Behún int ret = 0; 571629dd61fSMarek Behún uint32_t mask, data, offset; 572629dd61fSMarek Behún 573629dd61fSMarek Behún debug_enter(); 574629dd61fSMarek Behún 575629dd61fSMarek Behún data = PIN_RESET_CORE_BIT | PIN_RESET_COMPHY_BIT; 576ccec1bd5SPali Rohár mask = data; 577629dd61fSMarek Behún offset = MVEBU_COMPHY_REG_BASE + COMPHY_PHY_CFG1_OFFSET(comphy_index); 578629dd61fSMarek Behún reg_set(offset, data, mask); 579629dd61fSMarek Behún 580629dd61fSMarek Behún debug_exit(); 581629dd61fSMarek Behún 582629dd61fSMarek Behún return ret; 583629dd61fSMarek Behún } 584629dd61fSMarek Behún 5856f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_usb3_power_on(uint8_t comphy_index, 5866f8de19fSKonstantin Porotchkin uint32_t comphy_mode) 5876f8de19fSKonstantin Porotchkin { 5886f8de19fSKonstantin Porotchkin int ret = 0; 5896f8de19fSKonstantin Porotchkin uintptr_t reg_base = 0; 5906f8de19fSKonstantin Porotchkin uint32_t mask, data, addr, cfg, ref_clk; 5916f8de19fSKonstantin Porotchkin void (*usb3_reg_set)(uintptr_t addr, uint32_t reg_offset, uint16_t data, 5926f8de19fSKonstantin Porotchkin uint16_t mask, int mode); 5936f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 5946f8de19fSKonstantin Porotchkin int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode); 5956f8de19fSKonstantin Porotchkin 5966f8de19fSKonstantin Porotchkin debug_enter(); 5976f8de19fSKonstantin Porotchkin 5986f8de19fSKonstantin Porotchkin /* Set phy seclector */ 5996f8de19fSKonstantin Porotchkin mvebu_a3700_comphy_set_phy_selector(comphy_index, comphy_mode); 6006f8de19fSKonstantin Porotchkin 6016f8de19fSKonstantin Porotchkin /* Set usb3 reg access func, Lane2 is indirect access */ 6026f8de19fSKonstantin Porotchkin if (comphy_index == COMPHY_LANE2) { 6036f8de19fSKonstantin Porotchkin usb3_reg_set = &comphy_set_indirect; 6046f8de19fSKonstantin Porotchkin reg_base = COMPHY_INDIRECT_REG; 6056f8de19fSKonstantin Porotchkin } else { 6066f8de19fSKonstantin Porotchkin /* Get the direct access register resource and map */ 6076f8de19fSKonstantin Porotchkin usb3_reg_set = &comphy_usb3_set_direct; 6086f8de19fSKonstantin Porotchkin reg_base = USB3_GBE1_PHY; 6096f8de19fSKonstantin Porotchkin } 6106f8de19fSKonstantin Porotchkin 6116f8de19fSKonstantin Porotchkin /* 6126f8de19fSKonstantin Porotchkin * 0. Set PHY OTG Control(0x5d034), bit 4, Power up OTG module The 6136f8de19fSKonstantin Porotchkin * register belong to UTMI module, so it is set in UTMI phy driver. 6146f8de19fSKonstantin Porotchkin */ 6156f8de19fSKonstantin Porotchkin 6166f8de19fSKonstantin Porotchkin /* 6176f8de19fSKonstantin Porotchkin * 1. Set PRD_TXDEEMPH (3.5db de-emph) 6186f8de19fSKonstantin Porotchkin */ 6196f8de19fSKonstantin Porotchkin mask = PRD_TXDEEMPH0_MASK | PRD_TXMARGIN_MASK | PRD_TXSWING_MASK | 6206f8de19fSKonstantin Porotchkin CFG_TX_ALIGN_POS_MASK; 6216f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_LANE_CFG0_ADDR, PRD_TXDEEMPH0_MASK, 6226f8de19fSKonstantin Porotchkin mask, mode); 6236f8de19fSKonstantin Porotchkin 6246f8de19fSKonstantin Porotchkin /* 6256f8de19fSKonstantin Porotchkin * 2. Set BIT0: enable transmitter in high impedance mode 6266f8de19fSKonstantin Porotchkin * Set BIT[3:4]: delay 2 clock cycles for HiZ off latency 6276f8de19fSKonstantin Porotchkin * Set BIT6: Tx detect Rx at HiZ mode 6286f8de19fSKonstantin Porotchkin * Unset BIT15: set to 0 to set USB3 De-emphasize level to -3.5db 6296f8de19fSKonstantin Porotchkin * together with bit 0 of COMPHY_REG_LANE_CFG0_ADDR register 6306f8de19fSKonstantin Porotchkin */ 6316f8de19fSKonstantin Porotchkin mask = PRD_TXDEEMPH1_MASK | TX_DET_RX_MODE | GEN2_TX_DATA_DLY_MASK | 6326f8de19fSKonstantin Porotchkin TX_ELEC_IDLE_MODE_EN; 6336f8de19fSKonstantin Porotchkin data = TX_DET_RX_MODE | GEN2_TX_DATA_DLY_DEFT | TX_ELEC_IDLE_MODE_EN; 6346f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_LANE_CFG1_ADDR, data, mask, mode); 6356f8de19fSKonstantin Porotchkin 6366f8de19fSKonstantin Porotchkin /* 6376f8de19fSKonstantin Porotchkin * 3. Set Spread Spectrum Clock Enabled 6386f8de19fSKonstantin Porotchkin */ 6396f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_LANE_CFG4_ADDR, 6406f8de19fSKonstantin Porotchkin SPREAD_SPECTRUM_CLK_EN, SPREAD_SPECTRUM_CLK_EN, mode); 6416f8de19fSKonstantin Porotchkin 6426f8de19fSKonstantin Porotchkin /* 6436f8de19fSKonstantin Porotchkin * 4. Set Override Margining Controls From the MAC: 6446f8de19fSKonstantin Porotchkin * Use margining signals from lane configuration 6456f8de19fSKonstantin Porotchkin */ 6466f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_TEST_MODE_CTRL_ADDR, 6476f8de19fSKonstantin Porotchkin MODE_MARGIN_OVERRIDE, REG_16_BIT_MASK, mode); 6486f8de19fSKonstantin Porotchkin 6496f8de19fSKonstantin Porotchkin /* 6506f8de19fSKonstantin Porotchkin * 5. Set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles 6516f8de19fSKonstantin Porotchkin * set Mode Clock Source = PCLK is generated from REFCLK 6526f8de19fSKonstantin Porotchkin */ 6536f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_GLOB_CLK_SRC_LO_ADDR, 0x0, 6546f8de19fSKonstantin Porotchkin (MODE_CLK_SRC | BUNDLE_PERIOD_SEL | BUNDLE_PERIOD_SCALE | 6556f8de19fSKonstantin Porotchkin BUNDLE_SAMPLE_CTRL | PLL_READY_DLY), mode); 6566f8de19fSKonstantin Porotchkin 6576f8de19fSKonstantin Porotchkin /* 6586f8de19fSKonstantin Porotchkin * 6. Set G2 Spread Spectrum Clock Amplitude at 4K 6596f8de19fSKonstantin Porotchkin */ 6606f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_GEN2_SET_2, 6616f8de19fSKonstantin Porotchkin G2_TX_SSC_AMP_VALUE_20, G2_TX_SSC_AMP_MASK, mode); 6626f8de19fSKonstantin Porotchkin 6636f8de19fSKonstantin Porotchkin /* 6646f8de19fSKonstantin Porotchkin * 7. Unset G3 Spread Spectrum Clock Amplitude 6656f8de19fSKonstantin Porotchkin * set G3 TX and RX Register Master Current Select 6666f8de19fSKonstantin Porotchkin */ 6676f8de19fSKonstantin Porotchkin mask = G3_TX_SSC_AMP_MASK | G3_VREG_RXTX_MAS_ISET_MASK | 6686f8de19fSKonstantin Porotchkin RSVD_PH03FH_6_0_MASK; 6696f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_GEN2_SET_3, 6706f8de19fSKonstantin Porotchkin G3_VREG_RXTX_MAS_ISET_60U, mask, mode); 6716f8de19fSKonstantin Porotchkin 6726f8de19fSKonstantin Porotchkin /* 6736f8de19fSKonstantin Porotchkin * 8. Check crystal jumper setting and program the Power and PLL Control 6746f8de19fSKonstantin Porotchkin * accordingly Change RX wait 6756f8de19fSKonstantin Porotchkin */ 6766f8de19fSKonstantin Porotchkin if (get_ref_clk() == 40) { 6776f8de19fSKonstantin Porotchkin ref_clk = REF_CLOCK_SPEED_40M; 6786f8de19fSKonstantin Porotchkin cfg = CFG_PM_RXDLOZ_WAIT_12_UNIT; 6796f8de19fSKonstantin Porotchkin 6806f8de19fSKonstantin Porotchkin } else { 6816f8de19fSKonstantin Porotchkin /* 25 MHz */ 6826f8de19fSKonstantin Porotchkin ref_clk = USB3_REF_CLOCK_SPEED_25M; 6836f8de19fSKonstantin Porotchkin cfg = CFG_PM_RXDLOZ_WAIT_7_UNIT; 6846f8de19fSKonstantin Porotchkin } 6856f8de19fSKonstantin Porotchkin 6866f8de19fSKonstantin Porotchkin mask = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT | 6876f8de19fSKonstantin Porotchkin PU_TX_INTP_BIT | PU_DFE_BIT | PLL_LOCK_BIT | PHY_MODE_MASK | 6886f8de19fSKonstantin Porotchkin REF_FREF_SEL_MASK; 6896f8de19fSKonstantin Porotchkin data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT | 6906f8de19fSKonstantin Porotchkin PU_TX_INTP_BIT | PU_DFE_BIT | PHY_MODE_USB3 | ref_clk; 6916f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_POWER_PLL_CTRL, data, mask, mode); 6926f8de19fSKonstantin Porotchkin 6936f8de19fSKonstantin Porotchkin mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK | 6946f8de19fSKonstantin Porotchkin CFG_PM_RXDLOZ_WAIT_MASK; 6956f8de19fSKonstantin Porotchkin data = CFG_PM_RXDEN_WAIT_1_UNIT | cfg; 6966f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_PWR_MGM_TIM1_ADDR, data, mask, mode); 6976f8de19fSKonstantin Porotchkin 6986f8de19fSKonstantin Porotchkin /* 6996f8de19fSKonstantin Porotchkin * 9. Enable idle sync 7006f8de19fSKonstantin Porotchkin */ 7016f8de19fSKonstantin Porotchkin data = UNIT_CTRL_DEFAULT_VALUE | IDLE_SYNC_EN; 7026f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_UNIT_CTRL_ADDR, data, REG_16_BIT_MASK, 7036f8de19fSKonstantin Porotchkin mode); 7046f8de19fSKonstantin Porotchkin 7056f8de19fSKonstantin Porotchkin /* 7066f8de19fSKonstantin Porotchkin * 10. Enable the output of 500M clock 7076f8de19fSKonstantin Porotchkin */ 7086f8de19fSKonstantin Porotchkin data = MISC_REG0_DEFAULT_VALUE | CLK500M_EN; 7096f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_MISC_REG0_ADDR, data, REG_16_BIT_MASK, 7106f8de19fSKonstantin Porotchkin mode); 7116f8de19fSKonstantin Porotchkin 7126f8de19fSKonstantin Porotchkin /* 7136f8de19fSKonstantin Porotchkin * 11. Set 20-bit data width 7146f8de19fSKonstantin Porotchkin */ 7156f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_LOOPBACK_REG0, DATA_WIDTH_20BIT, 7166f8de19fSKonstantin Porotchkin REG_16_BIT_MASK, mode); 7176f8de19fSKonstantin Porotchkin 7186f8de19fSKonstantin Porotchkin /* 7196f8de19fSKonstantin Porotchkin * 12. Override Speed_PLL value and use MAC PLL 7206f8de19fSKonstantin Porotchkin */ 7216f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_KVCO_CAL_CTRL, 7226f8de19fSKonstantin Porotchkin (SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT), 7236f8de19fSKonstantin Porotchkin REG_16_BIT_MASK, mode); 7246f8de19fSKonstantin Porotchkin 7256f8de19fSKonstantin Porotchkin /* 7266f8de19fSKonstantin Porotchkin * 13. Check the Polarity invert bit 7276f8de19fSKonstantin Porotchkin */ 728ee4c70ebSPali Rohár data = 0U; 729ee4c70ebSPali Rohár if (invert & COMPHY_POLARITY_TXD_INVERT) { 730ee4c70ebSPali Rohár data |= TXD_INVERT_BIT; 731ee4c70ebSPali Rohár } 732ee4c70ebSPali Rohár if (invert & COMPHY_POLARITY_RXD_INVERT) { 733ee4c70ebSPali Rohár data |= RXD_INVERT_BIT; 734ee4c70ebSPali Rohár } 735ee4c70ebSPali Rohár mask = TXD_INVERT_BIT | RXD_INVERT_BIT; 736ee4c70ebSPali Rohár usb3_reg_set(reg_base, COMPHY_SYNC_PATTERN_REG, data, mask, mode); 7376f8de19fSKonstantin Porotchkin 7386f8de19fSKonstantin Porotchkin /* 7396f8de19fSKonstantin Porotchkin * 14. Set max speed generation to USB3.0 5Gbps 7406f8de19fSKonstantin Porotchkin */ 7416f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_SYNC_MASK_GEN_REG, PHY_GEN_USB3_5G, 7426f8de19fSKonstantin Porotchkin PHY_GEN_MAX_MASK, mode); 7436f8de19fSKonstantin Porotchkin 7446f8de19fSKonstantin Porotchkin /* 7456f8de19fSKonstantin Porotchkin * 15. Set capacitor value for FFE gain peaking to 0xF 7466f8de19fSKonstantin Porotchkin */ 7476f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_GEN3_SETTINGS_3, 7486f8de19fSKonstantin Porotchkin COMPHY_GEN_FFE_CAP_SEL_VALUE, COMPHY_GEN_FFE_CAP_SEL_MASK, 7496f8de19fSKonstantin Porotchkin mode); 7506f8de19fSKonstantin Porotchkin 7516f8de19fSKonstantin Porotchkin /* 7526f8de19fSKonstantin Porotchkin * 16. Release SW reset 7536f8de19fSKonstantin Porotchkin */ 7546f8de19fSKonstantin Porotchkin data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32 | MODE_REFDIV_BY_4; 7556f8de19fSKonstantin Porotchkin usb3_reg_set(reg_base, COMPHY_REG_GLOB_PHY_CTRL0_ADDR, data, 7566f8de19fSKonstantin Porotchkin REG_16_BIT_MASK, mode); 7576f8de19fSKonstantin Porotchkin 7586f8de19fSKonstantin Porotchkin /* Wait for > 55 us to allow PCLK be enabled */ 7596f8de19fSKonstantin Porotchkin udelay(PLL_SET_DELAY_US); 7606f8de19fSKonstantin Porotchkin 7616f8de19fSKonstantin Porotchkin if (comphy_index == COMPHY_LANE2) { 762b662232dSMarek Behún data = COMPHY_REG_LANE_STATUS1_ADDR + USB3PHY_LANE2_REG_BASE_OFFSET; 7636f8de19fSKonstantin Porotchkin mmio_write_32(reg_base + COMPHY_LANE2_INDIR_ADDR_OFFSET, 7646f8de19fSKonstantin Porotchkin data); 7656f8de19fSKonstantin Porotchkin 766b662232dSMarek Behún addr = reg_base + COMPHY_LANE2_INDIR_DATA_OFFSET; 7676f8de19fSKonstantin Porotchkin ret = polling_with_timeout(addr, TXDCLK_PCLK_EN, TXDCLK_PCLK_EN, 7686f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 7696f8de19fSKonstantin Porotchkin } else { 7706f8de19fSKonstantin Porotchkin ret = polling_with_timeout(LANE_STATUS1_ADDR(USB3) + reg_base, 7716f8de19fSKonstantin Porotchkin TXDCLK_PCLK_EN, TXDCLK_PCLK_EN, 7726f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_16BIT); 7736f8de19fSKonstantin Porotchkin } 7746f8de19fSKonstantin Porotchkin if (ret) 7756f8de19fSKonstantin Porotchkin ERROR("Failed to lock USB3 PLL\n"); 7766f8de19fSKonstantin Porotchkin 7776f8de19fSKonstantin Porotchkin debug_exit(); 7786f8de19fSKonstantin Porotchkin 7796f8de19fSKonstantin Porotchkin return ret; 7806f8de19fSKonstantin Porotchkin } 7816f8de19fSKonstantin Porotchkin 7826f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_pcie_power_on(uint8_t comphy_index, 7836f8de19fSKonstantin Porotchkin uint32_t comphy_mode) 7846f8de19fSKonstantin Porotchkin { 7856f8de19fSKonstantin Porotchkin int ret; 7866f8de19fSKonstantin Porotchkin uint32_t ref_clk; 787ee4c70ebSPali Rohár uint32_t mask, data; 7886f8de19fSKonstantin Porotchkin int invert = COMPHY_GET_POLARITY_INVERT(comphy_mode); 7896f8de19fSKonstantin Porotchkin 7906f8de19fSKonstantin Porotchkin debug_enter(); 7916f8de19fSKonstantin Porotchkin 7926f8de19fSKonstantin Porotchkin /* 1. Enable max PLL. */ 7936f8de19fSKonstantin Porotchkin reg_set16(LANE_CFG1_ADDR(PCIE) + COMPHY_SD_ADDR, 794ccec1bd5SPali Rohár USE_MAX_PLL_RATE_EN, USE_MAX_PLL_RATE_EN); 7956f8de19fSKonstantin Porotchkin 7966f8de19fSKonstantin Porotchkin /* 2. Select 20 bit SERDES interface. */ 7976f8de19fSKonstantin Porotchkin reg_set16(GLOB_CLK_SRC_LO_ADDR(PCIE) + COMPHY_SD_ADDR, 798ccec1bd5SPali Rohár CFG_SEL_20B, CFG_SEL_20B); 7996f8de19fSKonstantin Porotchkin 8006f8de19fSKonstantin Porotchkin /* 3. Force to use reg setting for PCIe mode */ 8016f8de19fSKonstantin Porotchkin reg_set16(MISC_REG1_ADDR(PCIE) + COMPHY_SD_ADDR, 802ccec1bd5SPali Rohár SEL_BITS_PCIE_FORCE, SEL_BITS_PCIE_FORCE); 8036f8de19fSKonstantin Porotchkin 8046f8de19fSKonstantin Porotchkin /* 4. Change RX wait */ 8056f8de19fSKonstantin Porotchkin reg_set16(PWR_MGM_TIM1_ADDR(PCIE) + COMPHY_SD_ADDR, 8066f8de19fSKonstantin Porotchkin CFG_PM_RXDEN_WAIT_1_UNIT | CFG_PM_RXDLOZ_WAIT_12_UNIT, 8076f8de19fSKonstantin Porotchkin (CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK | 8086f8de19fSKonstantin Porotchkin CFG_PM_RXDLOZ_WAIT_MASK)); 8096f8de19fSKonstantin Porotchkin 8106f8de19fSKonstantin Porotchkin /* 5. Enable idle sync */ 8116f8de19fSKonstantin Porotchkin reg_set16(UNIT_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR, 8126f8de19fSKonstantin Porotchkin UNIT_CTRL_DEFAULT_VALUE | IDLE_SYNC_EN, REG_16_BIT_MASK); 8136f8de19fSKonstantin Porotchkin 8146f8de19fSKonstantin Porotchkin /* 6. Enable the output of 100M/125M/500M clock */ 8156f8de19fSKonstantin Porotchkin reg_set16(MISC_REG0_ADDR(PCIE) + COMPHY_SD_ADDR, 81640d08192SPali Rohár MISC_REG0_DEFAULT_VALUE | CLK500M_EN | TXDCLK_2X_SEL | CLK100M_125M_EN, 8176f8de19fSKonstantin Porotchkin REG_16_BIT_MASK); 8186f8de19fSKonstantin Porotchkin 8196f8de19fSKonstantin Porotchkin /* 8206f8de19fSKonstantin Porotchkin * 7. Enable TX, PCIE global register, 0xd0074814, it is done in 8216f8de19fSKonstantin Porotchkin * PCI-E driver 8226f8de19fSKonstantin Porotchkin */ 8236f8de19fSKonstantin Porotchkin 8246f8de19fSKonstantin Porotchkin /* 8256f8de19fSKonstantin Porotchkin * 8. Check crystal jumper setting and program the Power and PLL 8266f8de19fSKonstantin Porotchkin * Control accordingly 8276f8de19fSKonstantin Porotchkin */ 8286f8de19fSKonstantin Porotchkin 8296f8de19fSKonstantin Porotchkin if (get_ref_clk() == 40) 8306f8de19fSKonstantin Porotchkin ref_clk = REF_CLOCK_SPEED_40M; 8316f8de19fSKonstantin Porotchkin else 8326f8de19fSKonstantin Porotchkin ref_clk = PCIE_REF_CLOCK_SPEED_25M; 8336f8de19fSKonstantin Porotchkin 8346f8de19fSKonstantin Porotchkin reg_set16(PWR_PLL_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR, 8356f8de19fSKonstantin Porotchkin (PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT | 8366f8de19fSKonstantin Porotchkin PU_TX_INTP_BIT | PU_DFE_BIT | ref_clk | PHY_MODE_PCIE), 8376f8de19fSKonstantin Porotchkin REG_16_BIT_MASK); 8386f8de19fSKonstantin Porotchkin 8396f8de19fSKonstantin Porotchkin /* 9. Override Speed_PLL value and use MAC PLL */ 8406f8de19fSKonstantin Porotchkin reg_set16(KVCO_CAL_CTRL_ADDR(PCIE) + COMPHY_SD_ADDR, 8416f8de19fSKonstantin Porotchkin SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT, REG_16_BIT_MASK); 8426f8de19fSKonstantin Porotchkin 8436f8de19fSKonstantin Porotchkin /* 10. Check the Polarity invert bit */ 844ee4c70ebSPali Rohár data = 0U; 845ee4c70ebSPali Rohár if (invert & COMPHY_POLARITY_TXD_INVERT) { 846ee4c70ebSPali Rohár data |= TXD_INVERT_BIT; 847ee4c70ebSPali Rohár } 848ee4c70ebSPali Rohár if (invert & COMPHY_POLARITY_RXD_INVERT) { 849ee4c70ebSPali Rohár data |= RXD_INVERT_BIT; 850ee4c70ebSPali Rohár } 851ee4c70ebSPali Rohár mask = TXD_INVERT_BIT | RXD_INVERT_BIT; 852ee4c70ebSPali Rohár reg_set16(SYNC_PATTERN_REG_ADDR(PCIE) + COMPHY_SD_ADDR, data, mask); 8536f8de19fSKonstantin Porotchkin 8546f8de19fSKonstantin Porotchkin /* 11. Release SW reset */ 8556f8de19fSKonstantin Porotchkin reg_set16(GLOB_PHY_CTRL0_ADDR(PCIE) + COMPHY_SD_ADDR, 8566f8de19fSKonstantin Porotchkin MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32, 8576f8de19fSKonstantin Porotchkin SOFT_RESET | MODE_REFDIV); 8586f8de19fSKonstantin Porotchkin 8596f8de19fSKonstantin Porotchkin /* Wait for > 55 us to allow PCLK be enabled */ 8606f8de19fSKonstantin Porotchkin udelay(PLL_SET_DELAY_US); 8616f8de19fSKonstantin Porotchkin 8626f8de19fSKonstantin Porotchkin ret = polling_with_timeout(LANE_STATUS1_ADDR(PCIE) + COMPHY_SD_ADDR, 8636f8de19fSKonstantin Porotchkin TXDCLK_PCLK_EN, TXDCLK_PCLK_EN, 8646f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_16BIT); 8656f8de19fSKonstantin Porotchkin if (ret) 8666f8de19fSKonstantin Porotchkin ERROR("Failed to lock PCIE PLL\n"); 8676f8de19fSKonstantin Porotchkin 8686f8de19fSKonstantin Porotchkin debug_exit(); 8696f8de19fSKonstantin Porotchkin 8706f8de19fSKonstantin Porotchkin return ret; 8716f8de19fSKonstantin Porotchkin } 8726f8de19fSKonstantin Porotchkin 8736f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_power_on(uint8_t comphy_index, uint32_t comphy_mode) 8746f8de19fSKonstantin Porotchkin { 8756f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 8766f8de19fSKonstantin Porotchkin int ret = 0; 8776f8de19fSKonstantin Porotchkin 8786f8de19fSKonstantin Porotchkin debug_enter(); 8796f8de19fSKonstantin Porotchkin 8806f8de19fSKonstantin Porotchkin switch (mode) { 8816f8de19fSKonstantin Porotchkin case(COMPHY_SATA_MODE): 8826f8de19fSKonstantin Porotchkin ret = mvebu_a3700_comphy_sata_power_on(comphy_index, 8836f8de19fSKonstantin Porotchkin comphy_mode); 8846f8de19fSKonstantin Porotchkin break; 8856f8de19fSKonstantin Porotchkin case(COMPHY_SGMII_MODE): 8866f8de19fSKonstantin Porotchkin case(COMPHY_HS_SGMII_MODE): 8876f8de19fSKonstantin Porotchkin ret = mvebu_a3700_comphy_sgmii_power_on(comphy_index, 8886f8de19fSKonstantin Porotchkin comphy_mode); 8896f8de19fSKonstantin Porotchkin break; 8906f8de19fSKonstantin Porotchkin case (COMPHY_USB3_MODE): 8916f8de19fSKonstantin Porotchkin case (COMPHY_USB3H_MODE): 8926f8de19fSKonstantin Porotchkin ret = mvebu_a3700_comphy_usb3_power_on(comphy_index, 8936f8de19fSKonstantin Porotchkin comphy_mode); 8946f8de19fSKonstantin Porotchkin break; 8956f8de19fSKonstantin Porotchkin case (COMPHY_PCIE_MODE): 8966f8de19fSKonstantin Porotchkin ret = mvebu_a3700_comphy_pcie_power_on(comphy_index, 8976f8de19fSKonstantin Porotchkin comphy_mode); 8986f8de19fSKonstantin Porotchkin break; 8996f8de19fSKonstantin Porotchkin default: 9006f8de19fSKonstantin Porotchkin ERROR("comphy%d: unsupported comphy mode\n", comphy_index); 9016f8de19fSKonstantin Porotchkin ret = -EINVAL; 9026f8de19fSKonstantin Porotchkin break; 9036f8de19fSKonstantin Porotchkin } 9046f8de19fSKonstantin Porotchkin 9056f8de19fSKonstantin Porotchkin debug_exit(); 9066f8de19fSKonstantin Porotchkin 9076f8de19fSKonstantin Porotchkin return ret; 9086f8de19fSKonstantin Porotchkin } 9096f8de19fSKonstantin Porotchkin 9106f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_usb3_power_off(void) 9116f8de19fSKonstantin Porotchkin { 9126f8de19fSKonstantin Porotchkin /* 9136f8de19fSKonstantin Porotchkin * Currently the USB3 MAC will control the USB3 PHY to set it to low 9146f8de19fSKonstantin Porotchkin * state, thus do not need to power off USB3 PHY again. 9156f8de19fSKonstantin Porotchkin */ 9166f8de19fSKonstantin Porotchkin debug_enter(); 9176f8de19fSKonstantin Porotchkin debug_exit(); 9186f8de19fSKonstantin Porotchkin 9196f8de19fSKonstantin Porotchkin return 0; 9206f8de19fSKonstantin Porotchkin } 9216f8de19fSKonstantin Porotchkin 9226f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sata_power_off(uint32_t comphy_mode) 9236f8de19fSKonstantin Porotchkin { 9246f8de19fSKonstantin Porotchkin uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG; 9256f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 9266f8de19fSKonstantin Porotchkin uint32_t offset; 9276f8de19fSKonstantin Porotchkin 9286f8de19fSKonstantin Porotchkin debug_enter(); 9296f8de19fSKonstantin Porotchkin 9306f8de19fSKonstantin Porotchkin /* Set phy isolation mode */ 9316f8de19fSKonstantin Porotchkin offset = COMPHY_ISOLATION_CTRL_REG + SATAPHY_LANE2_REG_BASE_OFFSET; 9326f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, PHY_ISOLATE_MODE, 9336f8de19fSKonstantin Porotchkin PHY_ISOLATE_MODE, mode); 9346f8de19fSKonstantin Porotchkin 9356f8de19fSKonstantin Porotchkin /* Power off PLL, Tx, Rx */ 9366f8de19fSKonstantin Porotchkin offset = COMPHY_POWER_PLL_CTRL + SATAPHY_LANE2_REG_BASE_OFFSET; 9376f8de19fSKonstantin Porotchkin comphy_set_indirect(comphy_indir_regs, offset, 0, 9386f8de19fSKonstantin Porotchkin PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT, mode); 9396f8de19fSKonstantin Porotchkin 9406f8de19fSKonstantin Porotchkin debug_exit(); 9416f8de19fSKonstantin Porotchkin 9426f8de19fSKonstantin Porotchkin return 0; 9436f8de19fSKonstantin Porotchkin } 9446f8de19fSKonstantin Porotchkin 9456f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_power_off(uint8_t comphy_index, uint32_t comphy_mode) 9466f8de19fSKonstantin Porotchkin { 9476f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 9486f8de19fSKonstantin Porotchkin int err = 0; 9496f8de19fSKonstantin Porotchkin 9506f8de19fSKonstantin Porotchkin debug_enter(); 9516f8de19fSKonstantin Porotchkin 952629dd61fSMarek Behún if (!mode) { 953629dd61fSMarek Behún /* 954629dd61fSMarek Behún * The user did not specify which mode should be powered off. 955629dd61fSMarek Behún * In this case we can identify this by reading the phy selector 956629dd61fSMarek Behún * register. 957629dd61fSMarek Behún */ 958629dd61fSMarek Behún mode = mvebu_a3700_comphy_get_mode(comphy_index); 959629dd61fSMarek Behún } 960629dd61fSMarek Behún 9616f8de19fSKonstantin Porotchkin switch (mode) { 962629dd61fSMarek Behún case(COMPHY_SGMII_MODE): 963629dd61fSMarek Behún case(COMPHY_HS_SGMII_MODE): 964629dd61fSMarek Behún err = mvebu_a3700_comphy_sgmii_power_off(comphy_index); 965629dd61fSMarek Behún break; 9666f8de19fSKonstantin Porotchkin case (COMPHY_USB3_MODE): 9676f8de19fSKonstantin Porotchkin case (COMPHY_USB3H_MODE): 9686f8de19fSKonstantin Porotchkin err = mvebu_a3700_comphy_usb3_power_off(); 9696f8de19fSKonstantin Porotchkin break; 9706f8de19fSKonstantin Porotchkin case (COMPHY_SATA_MODE): 9716f8de19fSKonstantin Porotchkin err = mvebu_a3700_comphy_sata_power_off(comphy_mode); 9726f8de19fSKonstantin Porotchkin break; 9736f8de19fSKonstantin Porotchkin 9746f8de19fSKonstantin Porotchkin default: 9756f8de19fSKonstantin Porotchkin debug("comphy%d: power off is not implemented for mode %d\n", 9766f8de19fSKonstantin Porotchkin comphy_index, mode); 9776f8de19fSKonstantin Porotchkin break; 9786f8de19fSKonstantin Porotchkin } 9796f8de19fSKonstantin Porotchkin 9806f8de19fSKonstantin Porotchkin debug_exit(); 9816f8de19fSKonstantin Porotchkin 9826f8de19fSKonstantin Porotchkin return err; 9836f8de19fSKonstantin Porotchkin } 9846f8de19fSKonstantin Porotchkin 9856f8de19fSKonstantin Porotchkin static int mvebu_a3700_comphy_sata_is_pll_locked(void) 9866f8de19fSKonstantin Porotchkin { 9876f8de19fSKonstantin Porotchkin uint32_t data, addr; 9886f8de19fSKonstantin Porotchkin uintptr_t comphy_indir_regs = COMPHY_INDIRECT_REG; 9896f8de19fSKonstantin Porotchkin int ret = 0; 9906f8de19fSKonstantin Porotchkin 9916f8de19fSKonstantin Porotchkin debug_enter(); 9926f8de19fSKonstantin Porotchkin 9936f8de19fSKonstantin Porotchkin /* Polling status */ 9946f8de19fSKonstantin Porotchkin mmio_write_32(comphy_indir_regs + COMPHY_LANE2_INDIR_ADDR_OFFSET, 9956f8de19fSKonstantin Porotchkin COMPHY_LOOPBACK_REG0 + SATAPHY_LANE2_REG_BASE_OFFSET); 9966f8de19fSKonstantin Porotchkin addr = comphy_indir_regs + COMPHY_LANE2_INDIR_DATA_OFFSET; 9976f8de19fSKonstantin Porotchkin data = polling_with_timeout(addr, PLL_READY_TX_BIT, PLL_READY_TX_BIT, 9986f8de19fSKonstantin Porotchkin COMPHY_PLL_TIMEOUT, REG_32BIT); 9996f8de19fSKonstantin Porotchkin 10006f8de19fSKonstantin Porotchkin if (data != 0) { 10016f8de19fSKonstantin Porotchkin ERROR("TX PLL is not locked\n"); 10026f8de19fSKonstantin Porotchkin ret = -ETIMEDOUT; 10036f8de19fSKonstantin Porotchkin } 10046f8de19fSKonstantin Porotchkin 10056f8de19fSKonstantin Porotchkin debug_exit(); 10066f8de19fSKonstantin Porotchkin 10076f8de19fSKonstantin Porotchkin return ret; 10086f8de19fSKonstantin Porotchkin } 10096f8de19fSKonstantin Porotchkin 10106f8de19fSKonstantin Porotchkin int mvebu_3700_comphy_is_pll_locked(uint8_t comphy_index, uint32_t comphy_mode) 10116f8de19fSKonstantin Porotchkin { 10126f8de19fSKonstantin Porotchkin int mode = COMPHY_GET_MODE(comphy_mode); 10136f8de19fSKonstantin Porotchkin int ret = 0; 10146f8de19fSKonstantin Porotchkin 10156f8de19fSKonstantin Porotchkin debug_enter(); 10166f8de19fSKonstantin Porotchkin 10176f8de19fSKonstantin Porotchkin switch (mode) { 10186f8de19fSKonstantin Porotchkin case(COMPHY_SATA_MODE): 10196f8de19fSKonstantin Porotchkin ret = mvebu_a3700_comphy_sata_is_pll_locked(); 10206f8de19fSKonstantin Porotchkin break; 10216f8de19fSKonstantin Porotchkin 10226f8de19fSKonstantin Porotchkin default: 10236f8de19fSKonstantin Porotchkin ERROR("comphy[%d] mode[%d] doesn't support PLL lock check\n", 10246f8de19fSKonstantin Porotchkin comphy_index, mode); 10256f8de19fSKonstantin Porotchkin ret = -EINVAL; 10266f8de19fSKonstantin Porotchkin break; 10276f8de19fSKonstantin Porotchkin } 10286f8de19fSKonstantin Porotchkin 10296f8de19fSKonstantin Porotchkin debug_exit(); 10306f8de19fSKonstantin Porotchkin 10316f8de19fSKonstantin Porotchkin return ret; 10326f8de19fSKonstantin Porotchkin } 1033