Lines Matching refs:ctx

594 static void cmu_wr(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
597 void __iomem *sds_base = ctx->sds_base;
611 static void cmu_rd(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
614 void __iomem *sds_base = ctx->sds_base;
625 static void cmu_toggle1to0(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
630 cmu_rd(ctx, cmu_type, reg, &val);
632 cmu_wr(ctx, cmu_type, reg, val);
633 cmu_rd(ctx, cmu_type, reg, &val);
635 cmu_wr(ctx, cmu_type, reg, val);
638 static void cmu_clrbits(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
643 cmu_rd(ctx, cmu_type, reg, &val);
645 cmu_wr(ctx, cmu_type, reg, val);
648 static void cmu_setbits(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
653 cmu_rd(ctx, cmu_type, reg, &val);
655 cmu_wr(ctx, cmu_type, reg, val);
658 static void serdes_wr(struct xgene_phy_ctx *ctx, int lane, u32 reg, u32 data)
660 void __iomem *sds_base = ctx->sds_base;
673 static void serdes_rd(struct xgene_phy_ctx *ctx, int lane, u32 reg, u32 *data)
675 void __iomem *sds_base = ctx->sds_base;
684 static void serdes_clrbits(struct xgene_phy_ctx *ctx, int lane, u32 reg,
689 serdes_rd(ctx, lane, reg, &val);
691 serdes_wr(ctx, lane, reg, val);
694 static void serdes_setbits(struct xgene_phy_ctx *ctx, int lane, u32 reg,
699 serdes_rd(ctx, lane, reg, &val);
701 serdes_wr(ctx, lane, reg, val);
704 static void xgene_phy_cfg_cmu_clk_type(struct xgene_phy_ctx *ctx,
711 cmu_rd(ctx, cmu_type, CMU_REG12, &val);
713 cmu_wr(ctx, cmu_type, CMU_REG12, val);
715 cmu_wr(ctx, cmu_type, CMU_REG13, 0x0222);
716 cmu_wr(ctx, cmu_type, CMU_REG14, 0x2225);
721 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
723 cmu_wr(ctx, cmu_type, CMU_REG0, val);
725 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
727 cmu_wr(ctx, cmu_type, CMU_REG1, val);
728 dev_dbg(ctx->dev, "Set external reference clock\n");
731 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
733 cmu_wr(ctx, cmu_type, CMU_REG0, val);
735 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
737 cmu_wr(ctx, cmu_type, CMU_REG1, val);
738 dev_dbg(ctx->dev, "Set internal reference clock\n");
746 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
748 cmu_wr(ctx, cmu_type, CMU_REG1, val);
750 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
752 cmu_wr(ctx, cmu_type, CMU_REG1, val);
753 dev_dbg(ctx->dev,
758 static void xgene_phy_sata_cfg_cmu_core(struct xgene_phy_ctx *ctx,
767 cmu_rd(ctx, cmu_type, CMU_REG34, &val);
772 cmu_wr(ctx, cmu_type, CMU_REG34, val);
776 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
781 cmu_wr(ctx, cmu_type, CMU_REG0, val);
784 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
794 cmu_wr(ctx, cmu_type, CMU_REG1, val);
797 cmu_clrbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
800 cmu_rd(ctx, cmu_type, CMU_REG2, &val);
818 cmu_wr(ctx, cmu_type, CMU_REG2, val);
821 cmu_rd(ctx, cmu_type, CMU_REG3, &val);
833 cmu_wr(ctx, cmu_type, CMU_REG3, val);
836 cmu_rd(ctx, cmu_type, CMU_REG26, &val);
838 cmu_wr(ctx, cmu_type, CMU_REG26, val);
841 cmu_rd(ctx, cmu_type, CMU_REG5, &val);
848 cmu_wr(ctx, cmu_type, CMU_REG5, val);
851 cmu_rd(ctx, cmu_type, CMU_REG6, &val);
854 cmu_wr(ctx, cmu_type, CMU_REG6, val);
858 cmu_rd(ctx, cmu_type, CMU_REG9, &val);
868 cmu_wr(ctx, cmu_type, CMU_REG9, val);
871 cmu_rd(ctx, cmu_type, CMU_REG10, &val);
873 cmu_wr(ctx, cmu_type, CMU_REG10, val);
877 cmu_rd(ctx, cmu_type, CMU_REG16, &val);
884 cmu_wr(ctx, cmu_type, CMU_REG16, val);
887 cmu_rd(ctx, cmu_type, CMU_REG30, &val);
890 cmu_wr(ctx, cmu_type, CMU_REG30, val);
893 cmu_wr(ctx, cmu_type, CMU_REG31, 0xF);
895 cmu_rd(ctx, cmu_type, CMU_REG32, &val);
901 cmu_wr(ctx, cmu_type, CMU_REG32, val);
905 cmu_wr(ctx, cmu_type, CMU_REG34, 0x8d27);
907 cmu_wr(ctx, cmu_type, CMU_REG34, 0x873c);
910 cmu_wr(ctx, cmu_type, CMU_REG37, 0xF00F);
913 static void xgene_phy_ssc_enable(struct xgene_phy_ctx *ctx,
919 cmu_rd(ctx, cmu_type, CMU_REG35, &val);
921 cmu_wr(ctx, cmu_type, CMU_REG35, val);
924 cmu_rd(ctx, cmu_type, CMU_REG36, &val);
928 cmu_wr(ctx, cmu_type, CMU_REG36, val);
931 cmu_clrbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
932 cmu_setbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
935 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
939 static void xgene_phy_sata_cfg_lanes(struct xgene_phy_ctx *ctx)
947 serdes_wr(ctx, lane, RXTX_REG147, 0x6);
950 serdes_rd(ctx, lane, RXTX_REG0, &val);
954 serdes_wr(ctx, lane, RXTX_REG0, val);
957 serdes_rd(ctx, lane, RXTX_REG1, &val);
960 ctx->sata_param.txboostgain[lane * 3 +
961 ctx->sata_param.speed[lane]]);
962 serdes_wr(ctx, lane, RXTX_REG1, val);
967 serdes_rd(ctx, lane, RXTX_REG2, &val);
971 serdes_wr(ctx, lane, RXTX_REG2, val);
974 serdes_rd(ctx, lane, RXTX_REG4, &val);
976 serdes_wr(ctx, lane, RXTX_REG4, val);
979 serdes_rd(ctx, lane, RXTX_REG1, &val);
982 serdes_wr(ctx, lane, RXTX_REG1, val);
986 serdes_rd(ctx, lane, RXTX_REG5, &val);
988 ctx->sata_param.txprecursor_cn1[lane * 3 +
989 ctx->sata_param.speed[lane]]);
991 ctx->sata_param.txpostcursor_cp1[lane * 3 +
992 ctx->sata_param.speed[lane]]);
994 ctx->sata_param.txprecursor_cn2[lane * 3 +
995 ctx->sata_param.speed[lane]]);
996 serdes_wr(ctx, lane, RXTX_REG5, val);
999 serdes_rd(ctx, lane, RXTX_REG6, &val);
1001 ctx->sata_param.txamplitude[lane * 3 +
1002 ctx->sata_param.speed[lane]]);
1007 serdes_wr(ctx, lane, RXTX_REG6, val);
1010 serdes_rd(ctx, lane, RXTX_REG7, &val);
1013 serdes_wr(ctx, lane, RXTX_REG7, val);
1016 serdes_rd(ctx, lane, RXTX_REG8, &val);
1022 serdes_wr(ctx, lane, RXTX_REG8, val);
1025 serdes_rd(ctx, lane, RXTX_REG11, &val);
1027 serdes_wr(ctx, lane, RXTX_REG11, val);
1030 serdes_rd(ctx, lane, RXTX_REG12, &val);
1034 serdes_wr(ctx, lane, RXTX_REG12, val);
1037 serdes_rd(ctx, lane, RXTX_REG26, &val);
1040 serdes_wr(ctx, lane, RXTX_REG26, val);
1042 serdes_wr(ctx, lane, RXTX_REG28, 0x0);
1045 serdes_wr(ctx, lane, RXTX_REG31, 0x0);
1048 serdes_rd(ctx, lane, RXTX_REG61, &val);
1052 serdes_wr(ctx, lane, RXTX_REG61, val);
1054 serdes_rd(ctx, lane, RXTX_REG62, &val);
1056 serdes_wr(ctx, lane, RXTX_REG62, val);
1061 serdes_rd(ctx, lane, reg, &val);
1065 serdes_wr(ctx, lane, reg, val);
1071 serdes_rd(ctx, lane, reg, &val);
1075 serdes_wr(ctx, lane, reg, val);
1081 serdes_rd(ctx, lane, reg, &val);
1085 serdes_wr(ctx, lane, reg, val);
1088 serdes_rd(ctx, lane, RXTX_REG102, &val);
1090 serdes_wr(ctx, lane, RXTX_REG102, val);
1092 serdes_wr(ctx, lane, RXTX_REG114, 0xffe0);
1094 serdes_rd(ctx, lane, RXTX_REG125, &val);
1096 ctx->sata_param.txeyedirection[lane * 3 +
1097 ctx->sata_param.speed[lane]]);
1099 ctx->sata_param.txeyetuning[lane * 3 +
1100 ctx->sata_param.speed[lane]]);
1102 serdes_wr(ctx, lane, RXTX_REG125, val);
1104 serdes_rd(ctx, lane, RXTX_REG127, &val);
1106 serdes_wr(ctx, lane, RXTX_REG127, val);
1108 serdes_rd(ctx, lane, RXTX_REG128, &val);
1110 serdes_wr(ctx, lane, RXTX_REG128, val);
1112 serdes_rd(ctx, lane, RXTX_REG145, &val);
1122 serdes_wr(ctx, lane, RXTX_REG145, val);
1130 serdes_wr(ctx, lane, reg, 0xFFFF);
1135 static int xgene_phy_cal_rdy_chk(struct xgene_phy_ctx *ctx,
1139 void __iomem *csr_serdes = ctx->sds_base;
1148 cmu_setbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
1155 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
1157 cmu_wr(ctx, cmu_type, CMU_REG1, val);
1164 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
1181 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1184 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1185 cmu_toggle1to0(ctx, cmu_type, CMU_REG17,
1192 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1195 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1196 cmu_toggle1to0(ctx, cmu_type, CMU_REG16,
1199 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1202 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1203 cmu_toggle1to0(ctx, cmu_type, CMU_REG16,
1210 cmu_rd(ctx, cmu_type, CMU_REG7, &val);
1220 cmu_rd(ctx, cmu_type, CMU_REG7, &val);
1221 dev_dbg(ctx->dev, "PLL calibration %s\n",
1224 dev_err(ctx->dev,
1228 dev_dbg(ctx->dev, "PLL calibration successful\n");
1230 cmu_rd(ctx, cmu_type, CMU_REG15, &val);
1231 dev_dbg(ctx->dev, "PHY Tx is %sready\n", val & 0x300 ? "" : "not ");
1235 static void xgene_phy_pdwn_force_vco(struct xgene_phy_ctx *ctx,
1241 dev_dbg(ctx->dev, "Reset VCO and re-start again\n");
1243 cmu_rd(ctx, cmu_type, CMU_REG16, &val);
1245 cmu_wr(ctx, cmu_type, CMU_REG16, val);
1248 cmu_toggle1to0(ctx, cmu_type, CMU_REG0, CMU_REG0_PDOWN_MASK);
1249 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
1253 static int xgene_phy_hw_init_sata(struct xgene_phy_ctx *ctx,
1256 void __iomem *sds_base = ctx->sds_base;
1261 dev_dbg(ctx->dev, "Reset PHY\n");
1275 ctx->sata_param.txspeed[ctx->sata_param.speed[0]]);
1278 dev_dbg(ctx->dev, "Set the customer pin mode to SATA\n");
1284 xgene_phy_cfg_cmu_clk_type(ctx, PHY_CMU, clk_type);
1287 xgene_phy_sata_cfg_cmu_core(ctx, PHY_CMU, clk_type);
1291 xgene_phy_ssc_enable(ctx, PHY_CMU);
1294 xgene_phy_sata_cfg_lanes(ctx);
1305 if (!xgene_phy_cal_rdy_chk(ctx, PHY_CMU, clk_type))
1308 xgene_phy_pdwn_force_vco(ctx, PHY_CMU, clk_type);
1312 dev_err(ctx->dev, "PLL calibration failed\n");
1317 static int xgene_phy_hw_initialize(struct xgene_phy_ctx *ctx,
1323 dev_dbg(ctx->dev, "PHY init clk type %d\n", clk_type);
1325 if (ctx->mode == MODE_SATA) {
1326 rc = xgene_phy_hw_init_sata(ctx, clk_type, ssc_enable);
1330 dev_err(ctx->dev, "Un-supported customer pin mode %d\n",
1331 ctx->mode);
1344 static void xgene_phy_force_lat_summer_cal(struct xgene_phy_ctx *ctx, int lane)
1372 serdes_setbits(ctx, lane, RXTX_REG127,
1379 serdes_clrbits(ctx, lane, RXTX_REG127,
1388 serdes_setbits(ctx, lane, RXTX_REG127,
1395 serdes_clrbits(ctx, lane, RXTX_REG127,
1399 serdes_wr(ctx, lane, RXTX_REG28, 0x7);
1400 serdes_wr(ctx, lane, RXTX_REG31, 0x7e00);
1401 serdes_clrbits(ctx, lane, RXTX_REG4,
1403 serdes_clrbits(ctx, lane, RXTX_REG7,
1406 serdes_wr(ctx, lane, serdes_reg[i].reg,
1410 static void xgene_phy_reset_rxd(struct xgene_phy_ctx *ctx, int lane)
1413 serdes_clrbits(ctx, lane, RXTX_REG7, RXTX_REG7_RESETB_RXD_MASK);
1416 serdes_setbits(ctx, lane, RXTX_REG7, RXTX_REG7_RESETB_RXD_MASK);
1424 static void xgene_phy_gen_avg_val(struct xgene_phy_ctx *ctx, int lane)
1438 dev_dbg(ctx->dev, "Generating avg calibration value for lane %d\n",
1442 serdes_setbits(ctx, lane, RXTX_REG12,
1445 serdes_wr(ctx, lane, RXTX_REG28, 0x0000);
1447 serdes_wr(ctx, lane, RXTX_REG31, 0x0000);
1458 xgene_phy_force_lat_summer_cal(ctx, lane);
1460 serdes_rd(ctx, lane, RXTX_REG21, &val);
1465 serdes_rd(ctx, lane, RXTX_REG22, &val);
1470 serdes_rd(ctx, lane, RXTX_REG23, &val);
1474 serdes_rd(ctx, lane, RXTX_REG24, &val);
1478 serdes_rd(ctx, lane, RXTX_REG121, &val);
1494 dev_dbg(ctx->dev, "Iteration %d:\n", avg_loop);
1495 dev_dbg(ctx->dev, "DO 0x%x XO 0x%x EO 0x%x SO 0x%x\n",
1498 dev_dbg(ctx->dev, "DE 0x%x XE 0x%x EE 0x%x SE 0x%x\n",
1501 dev_dbg(ctx->dev, "SUM 0x%x\n", sum_cal_itr);
1504 dev_err(ctx->dev,
1508 xgene_phy_reset_rxd(ctx, lane);
1512 serdes_rd(ctx, lane, RXTX_REG127, &val);
1517 serdes_wr(ctx, lane, RXTX_REG127, val);
1519 serdes_rd(ctx, lane, RXTX_REG128, &val);
1524 serdes_wr(ctx, lane, RXTX_REG128, val);
1526 serdes_rd(ctx, lane, RXTX_REG129, &val);
1531 serdes_wr(ctx, lane, RXTX_REG129, val);
1533 serdes_rd(ctx, lane, RXTX_REG130, &val);
1538 serdes_wr(ctx, lane, RXTX_REG130, val);
1541 serdes_rd(ctx, lane, RXTX_REG14, &val);
1544 serdes_wr(ctx, lane, RXTX_REG14, val);
1546 dev_dbg(ctx->dev, "Average Value:\n");
1547 dev_dbg(ctx->dev, "DO 0x%x XO 0x%x EO 0x%x SO 0x%x\n",
1552 dev_dbg(ctx->dev, "DE 0x%x XE 0x%x EE 0x%x SE 0x%x\n",
1557 dev_dbg(ctx->dev, "SUM 0x%x\n",
1560 serdes_rd(ctx, lane, RXTX_REG14, &val);
1562 serdes_wr(ctx, lane, RXTX_REG14, val);
1563 dev_dbg(ctx->dev, "Enable Manual Summer calibration\n");
1565 serdes_rd(ctx, lane, RXTX_REG127, &val);
1567 dev_dbg(ctx->dev, "Enable Manual Latch calibration\n");
1568 serdes_wr(ctx, lane, RXTX_REG127, val);
1571 serdes_rd(ctx, lane, RXTX_REG12, &val);
1573 serdes_wr(ctx, lane, RXTX_REG12, val);
1575 serdes_wr(ctx, lane, RXTX_REG28, 0x0007);
1577 serdes_wr(ctx, lane, RXTX_REG31, 0x7e00);
1582 struct xgene_phy_ctx *ctx = phy_get_drvdata(phy);
1586 rc = xgene_phy_hw_initialize(ctx, CLK_EXT_DIFF, SSC_DISABLE);
1588 dev_err(ctx->dev, "PHY initialize failed %d\n", rc);
1593 if (!IS_ERR(ctx->clk)) {
1595 clk_prepare_enable(ctx->clk);
1596 clk_disable_unprepare(ctx->clk);
1597 clk_prepare_enable(ctx->clk);
1602 xgene_phy_gen_avg_val(ctx, i);
1604 dev_dbg(ctx->dev, "PHY initialized\n");
1616 struct xgene_phy_ctx *ctx = dev_get_drvdata(dev);
1623 ctx->mode = args->args[0];
1624 return ctx->phy;
1648 struct xgene_phy_ctx *ctx;
1659 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1660 if (!ctx)
1663 ctx->dev = &pdev->dev;
1665 ctx->sds_base = devm_platform_ioremap_resource(pdev, 0);
1666 if (IS_ERR(ctx->sds_base))
1667 return PTR_ERR(ctx->sds_base);
1670 ctx->clk = clk_get(&pdev->dev, NULL);
1674 ctx->sata_param.txeyetuning, 6, default_txeye_tuning, 1);
1676 ctx->sata_param.txeyedirection, 6, default_txeye_direction, 1);
1678 ctx->sata_param.txboostgain, 6, default_txboost_gain, 1);
1680 ctx->sata_param.txamplitude, 6, default_txamp, 13300);
1682 ctx->sata_param.txprecursor_cn1, 6, default_txcn1, 18200);
1684 ctx->sata_param.txprecursor_cn2, 6, default_txcn2, 18200);
1686 ctx->sata_param.txpostcursor_cp1, 6, default_txcp1, 18200);
1688 ctx->sata_param.txspeed, 3, default_spd, 1);
1690 ctx->sata_param.speed[i] = 2; /* Default to Gen3 */
1692 platform_set_drvdata(pdev, ctx);
1694 ctx->phy = devm_phy_create(ctx->dev, NULL, &xgene_phy_ops);
1695 if (IS_ERR(ctx->phy)) {
1697 return PTR_ERR(ctx->phy);
1699 phy_set_drvdata(ctx->phy, ctx);
1701 phy_provider = devm_of_phy_provider_register(ctx->dev, xgene_phy_xlate);