Lines Matching refs:ctx
593 static void cmu_wr(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
596 void __iomem *sds_base = ctx->sds_base;
610 static void cmu_rd(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
613 void __iomem *sds_base = ctx->sds_base;
624 static void cmu_toggle1to0(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
629 cmu_rd(ctx, cmu_type, reg, &val);
631 cmu_wr(ctx, cmu_type, reg, val);
632 cmu_rd(ctx, cmu_type, reg, &val);
634 cmu_wr(ctx, cmu_type, reg, val);
637 static void cmu_clrbits(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
642 cmu_rd(ctx, cmu_type, reg, &val);
644 cmu_wr(ctx, cmu_type, reg, val);
647 static void cmu_setbits(struct xgene_phy_ctx *ctx, enum cmu_type_t cmu_type,
652 cmu_rd(ctx, cmu_type, reg, &val);
654 cmu_wr(ctx, cmu_type, reg, val);
657 static void serdes_wr(struct xgene_phy_ctx *ctx, int lane, u32 reg, u32 data)
659 void __iomem *sds_base = ctx->sds_base;
672 static void serdes_rd(struct xgene_phy_ctx *ctx, int lane, u32 reg, u32 *data)
674 void __iomem *sds_base = ctx->sds_base;
683 static void serdes_clrbits(struct xgene_phy_ctx *ctx, int lane, u32 reg,
688 serdes_rd(ctx, lane, reg, &val);
690 serdes_wr(ctx, lane, reg, val);
693 static void serdes_setbits(struct xgene_phy_ctx *ctx, int lane, u32 reg,
698 serdes_rd(ctx, lane, reg, &val);
700 serdes_wr(ctx, lane, reg, val);
703 static void xgene_phy_cfg_cmu_clk_type(struct xgene_phy_ctx *ctx,
710 cmu_rd(ctx, cmu_type, CMU_REG12, &val);
712 cmu_wr(ctx, cmu_type, CMU_REG12, val);
714 cmu_wr(ctx, cmu_type, CMU_REG13, 0x0222);
715 cmu_wr(ctx, cmu_type, CMU_REG14, 0x2225);
720 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
722 cmu_wr(ctx, cmu_type, CMU_REG0, val);
724 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
726 cmu_wr(ctx, cmu_type, CMU_REG1, val);
727 dev_dbg(ctx->dev, "Set external reference clock\n");
730 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
732 cmu_wr(ctx, cmu_type, CMU_REG0, val);
734 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
736 cmu_wr(ctx, cmu_type, CMU_REG1, val);
737 dev_dbg(ctx->dev, "Set internal reference clock\n");
745 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
747 cmu_wr(ctx, cmu_type, CMU_REG1, val);
749 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
751 cmu_wr(ctx, cmu_type, CMU_REG1, val);
752 dev_dbg(ctx->dev,
757 static void xgene_phy_sata_cfg_cmu_core(struct xgene_phy_ctx *ctx,
766 cmu_rd(ctx, cmu_type, CMU_REG34, &val);
771 cmu_wr(ctx, cmu_type, CMU_REG34, val);
775 cmu_rd(ctx, cmu_type, CMU_REG0, &val);
780 cmu_wr(ctx, cmu_type, CMU_REG0, val);
783 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
793 cmu_wr(ctx, cmu_type, CMU_REG1, val);
796 cmu_clrbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
799 cmu_rd(ctx, cmu_type, CMU_REG2, &val);
817 cmu_wr(ctx, cmu_type, CMU_REG2, val);
820 cmu_rd(ctx, cmu_type, CMU_REG3, &val);
832 cmu_wr(ctx, cmu_type, CMU_REG3, val);
835 cmu_rd(ctx, cmu_type, CMU_REG26, &val);
837 cmu_wr(ctx, cmu_type, CMU_REG26, val);
840 cmu_rd(ctx, cmu_type, CMU_REG5, &val);
847 cmu_wr(ctx, cmu_type, CMU_REG5, val);
850 cmu_rd(ctx, cmu_type, CMU_REG6, &val);
853 cmu_wr(ctx, cmu_type, CMU_REG6, val);
857 cmu_rd(ctx, cmu_type, CMU_REG9, &val);
867 cmu_wr(ctx, cmu_type, CMU_REG9, val);
870 cmu_rd(ctx, cmu_type, CMU_REG10, &val);
872 cmu_wr(ctx, cmu_type, CMU_REG10, val);
876 cmu_rd(ctx, cmu_type, CMU_REG16, &val);
883 cmu_wr(ctx, cmu_type, CMU_REG16, val);
886 cmu_rd(ctx, cmu_type, CMU_REG30, &val);
889 cmu_wr(ctx, cmu_type, CMU_REG30, val);
892 cmu_wr(ctx, cmu_type, CMU_REG31, 0xF);
894 cmu_rd(ctx, cmu_type, CMU_REG32, &val);
900 cmu_wr(ctx, cmu_type, CMU_REG32, val);
904 cmu_wr(ctx, cmu_type, CMU_REG34, 0x8d27);
906 cmu_wr(ctx, cmu_type, CMU_REG34, 0x873c);
909 cmu_wr(ctx, cmu_type, CMU_REG37, 0xF00F);
912 static void xgene_phy_ssc_enable(struct xgene_phy_ctx *ctx,
918 cmu_rd(ctx, cmu_type, CMU_REG35, &val);
920 cmu_wr(ctx, cmu_type, CMU_REG35, val);
923 cmu_rd(ctx, cmu_type, CMU_REG36, &val);
927 cmu_wr(ctx, cmu_type, CMU_REG36, val);
930 cmu_clrbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
931 cmu_setbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
934 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
938 static void xgene_phy_sata_cfg_lanes(struct xgene_phy_ctx *ctx)
946 serdes_wr(ctx, lane, RXTX_REG147, 0x6);
949 serdes_rd(ctx, lane, RXTX_REG0, &val);
953 serdes_wr(ctx, lane, RXTX_REG0, val);
956 serdes_rd(ctx, lane, RXTX_REG1, &val);
959 ctx->sata_param.txboostgain[lane * 3 +
960 ctx->sata_param.speed[lane]]);
961 serdes_wr(ctx, lane, RXTX_REG1, val);
965 serdes_rd(ctx, lane, RXTX_REG2, &val);
969 serdes_wr(ctx, lane, RXTX_REG2, val);
972 serdes_rd(ctx, lane, RXTX_REG4, &val);
974 serdes_wr(ctx, lane, RXTX_REG4, val);
977 serdes_rd(ctx, lane, RXTX_REG1, &val);
980 serdes_wr(ctx, lane, RXTX_REG1, val);
984 serdes_rd(ctx, lane, RXTX_REG5, &val);
986 ctx->sata_param.txprecursor_cn1[lane * 3 +
987 ctx->sata_param.speed[lane]]);
989 ctx->sata_param.txpostcursor_cp1[lane * 3 +
990 ctx->sata_param.speed[lane]]);
992 ctx->sata_param.txprecursor_cn2[lane * 3 +
993 ctx->sata_param.speed[lane]]);
994 serdes_wr(ctx, lane, RXTX_REG5, val);
997 serdes_rd(ctx, lane, RXTX_REG6, &val);
999 ctx->sata_param.txamplitude[lane * 3 +
1000 ctx->sata_param.speed[lane]]);
1005 serdes_wr(ctx, lane, RXTX_REG6, val);
1008 serdes_rd(ctx, lane, RXTX_REG7, &val);
1011 serdes_wr(ctx, lane, RXTX_REG7, val);
1014 serdes_rd(ctx, lane, RXTX_REG8, &val);
1020 serdes_wr(ctx, lane, RXTX_REG8, val);
1023 serdes_rd(ctx, lane, RXTX_REG11, &val);
1025 serdes_wr(ctx, lane, RXTX_REG11, val);
1028 serdes_rd(ctx, lane, RXTX_REG12, &val);
1032 serdes_wr(ctx, lane, RXTX_REG12, val);
1035 serdes_rd(ctx, lane, RXTX_REG26, &val);
1038 serdes_wr(ctx, lane, RXTX_REG26, val);
1040 serdes_wr(ctx, lane, RXTX_REG28, 0x0);
1043 serdes_wr(ctx, lane, RXTX_REG31, 0x0);
1046 serdes_rd(ctx, lane, RXTX_REG61, &val);
1050 serdes_wr(ctx, lane, RXTX_REG61, val);
1052 serdes_rd(ctx, lane, RXTX_REG62, &val);
1054 serdes_wr(ctx, lane, RXTX_REG62, val);
1059 serdes_rd(ctx, lane, reg, &val);
1063 serdes_wr(ctx, lane, reg, val);
1069 serdes_rd(ctx, lane, reg, &val);
1073 serdes_wr(ctx, lane, reg, val);
1079 serdes_rd(ctx, lane, reg, &val);
1083 serdes_wr(ctx, lane, reg, val);
1086 serdes_rd(ctx, lane, RXTX_REG102, &val);
1088 serdes_wr(ctx, lane, RXTX_REG102, val);
1090 serdes_wr(ctx, lane, RXTX_REG114, 0xffe0);
1092 serdes_rd(ctx, lane, RXTX_REG125, &val);
1094 ctx->sata_param.txeyedirection[lane * 3 +
1095 ctx->sata_param.speed[lane]]);
1097 ctx->sata_param.txeyetuning[lane * 3 +
1098 ctx->sata_param.speed[lane]]);
1100 serdes_wr(ctx, lane, RXTX_REG125, val);
1102 serdes_rd(ctx, lane, RXTX_REG127, &val);
1104 serdes_wr(ctx, lane, RXTX_REG127, val);
1106 serdes_rd(ctx, lane, RXTX_REG128, &val);
1108 serdes_wr(ctx, lane, RXTX_REG128, val);
1110 serdes_rd(ctx, lane, RXTX_REG145, &val);
1120 serdes_wr(ctx, lane, RXTX_REG145, val);
1128 serdes_wr(ctx, lane, reg, 0xFFFF);
1133 static int xgene_phy_cal_rdy_chk(struct xgene_phy_ctx *ctx,
1137 void __iomem *csr_serdes = ctx->sds_base;
1146 cmu_setbits(ctx, cmu_type, CMU_REG5, CMU_REG5_PLL_RESETB_MASK);
1153 cmu_rd(ctx, cmu_type, CMU_REG1, &val);
1155 cmu_wr(ctx, cmu_type, CMU_REG1, val);
1162 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
1179 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1182 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1183 cmu_toggle1to0(ctx, cmu_type, CMU_REG17,
1190 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1193 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1194 cmu_toggle1to0(ctx, cmu_type, CMU_REG16,
1197 cmu_rd(ctx, cmu_type, CMU_REG17, &val);
1200 cmu_wr(ctx, cmu_type, CMU_REG17, val);
1201 cmu_toggle1to0(ctx, cmu_type, CMU_REG16,
1208 cmu_rd(ctx, cmu_type, CMU_REG7, &val);
1218 cmu_rd(ctx, cmu_type, CMU_REG7, &val);
1219 dev_dbg(ctx->dev, "PLL calibration %s\n",
1222 dev_err(ctx->dev,
1226 dev_dbg(ctx->dev, "PLL calibration successful\n");
1228 cmu_rd(ctx, cmu_type, CMU_REG15, &val);
1229 dev_dbg(ctx->dev, "PHY Tx is %sready\n", val & 0x300 ? "" : "not ");
1233 static void xgene_phy_pdwn_force_vco(struct xgene_phy_ctx *ctx,
1239 dev_dbg(ctx->dev, "Reset VCO and re-start again\n");
1241 cmu_rd(ctx, cmu_type, CMU_REG16, &val);
1243 cmu_wr(ctx, cmu_type, CMU_REG16, val);
1246 cmu_toggle1to0(ctx, cmu_type, CMU_REG0, CMU_REG0_PDOWN_MASK);
1247 cmu_toggle1to0(ctx, cmu_type, CMU_REG32,
1251 static int xgene_phy_hw_init_sata(struct xgene_phy_ctx *ctx,
1254 void __iomem *sds_base = ctx->sds_base;
1259 dev_dbg(ctx->dev, "Reset PHY\n");
1273 ctx->sata_param.txspeed[ctx->sata_param.speed[0]]);
1276 dev_dbg(ctx->dev, "Set the customer pin mode to SATA\n");
1282 xgene_phy_cfg_cmu_clk_type(ctx, PHY_CMU, clk_type);
1285 xgene_phy_sata_cfg_cmu_core(ctx, PHY_CMU, clk_type);
1289 xgene_phy_ssc_enable(ctx, PHY_CMU);
1292 xgene_phy_sata_cfg_lanes(ctx);
1303 if (!xgene_phy_cal_rdy_chk(ctx, PHY_CMU, clk_type))
1306 xgene_phy_pdwn_force_vco(ctx, PHY_CMU, clk_type);
1310 dev_err(ctx->dev, "PLL calibration failed\n");
1315 static int xgene_phy_hw_initialize(struct xgene_phy_ctx *ctx,
1321 dev_dbg(ctx->dev, "PHY init clk type %d\n", clk_type);
1323 if (ctx->mode == MODE_SATA) {
1324 rc = xgene_phy_hw_init_sata(ctx, clk_type, ssc_enable);
1328 dev_err(ctx->dev, "Un-supported customer pin mode %d\n",
1329 ctx->mode);
1342 static void xgene_phy_force_lat_summer_cal(struct xgene_phy_ctx *ctx, int lane)
1370 serdes_setbits(ctx, lane, RXTX_REG127,
1377 serdes_clrbits(ctx, lane, RXTX_REG127,
1386 serdes_setbits(ctx, lane, RXTX_REG127,
1393 serdes_clrbits(ctx, lane, RXTX_REG127,
1397 serdes_wr(ctx, lane, RXTX_REG28, 0x7);
1398 serdes_wr(ctx, lane, RXTX_REG31, 0x7e00);
1399 serdes_clrbits(ctx, lane, RXTX_REG4,
1401 serdes_clrbits(ctx, lane, RXTX_REG7,
1404 serdes_wr(ctx, lane, serdes_reg[i].reg,
1408 static void xgene_phy_reset_rxd(struct xgene_phy_ctx *ctx, int lane)
1411 serdes_clrbits(ctx, lane, RXTX_REG7, RXTX_REG7_RESETB_RXD_MASK);
1414 serdes_setbits(ctx, lane, RXTX_REG7, RXTX_REG7_RESETB_RXD_MASK);
1422 static void xgene_phy_gen_avg_val(struct xgene_phy_ctx *ctx, int lane)
1436 dev_dbg(ctx->dev, "Generating avg calibration value for lane %d\n",
1440 serdes_setbits(ctx, lane, RXTX_REG12,
1443 serdes_wr(ctx, lane, RXTX_REG28, 0x0000);
1445 serdes_wr(ctx, lane, RXTX_REG31, 0x0000);
1456 xgene_phy_force_lat_summer_cal(ctx, lane);
1458 serdes_rd(ctx, lane, RXTX_REG21, &val);
1463 serdes_rd(ctx, lane, RXTX_REG22, &val);
1468 serdes_rd(ctx, lane, RXTX_REG23, &val);
1472 serdes_rd(ctx, lane, RXTX_REG24, &val);
1476 serdes_rd(ctx, lane, RXTX_REG121, &val);
1492 dev_dbg(ctx->dev, "Iteration %d:\n", avg_loop);
1493 dev_dbg(ctx->dev, "DO 0x%x XO 0x%x EO 0x%x SO 0x%x\n",
1496 dev_dbg(ctx->dev, "DE 0x%x XE 0x%x EE 0x%x SE 0x%x\n",
1499 dev_dbg(ctx->dev, "SUM 0x%x\n", sum_cal_itr);
1502 dev_err(ctx->dev,
1506 xgene_phy_reset_rxd(ctx, lane);
1510 serdes_rd(ctx, lane, RXTX_REG127, &val);
1515 serdes_wr(ctx, lane, RXTX_REG127, val);
1517 serdes_rd(ctx, lane, RXTX_REG128, &val);
1522 serdes_wr(ctx, lane, RXTX_REG128, val);
1524 serdes_rd(ctx, lane, RXTX_REG129, &val);
1529 serdes_wr(ctx, lane, RXTX_REG129, val);
1531 serdes_rd(ctx, lane, RXTX_REG130, &val);
1536 serdes_wr(ctx, lane, RXTX_REG130, val);
1539 serdes_rd(ctx, lane, RXTX_REG14, &val);
1542 serdes_wr(ctx, lane, RXTX_REG14, val);
1544 dev_dbg(ctx->dev, "Average Value:\n");
1545 dev_dbg(ctx->dev, "DO 0x%x XO 0x%x EO 0x%x SO 0x%x\n",
1550 dev_dbg(ctx->dev, "DE 0x%x XE 0x%x EE 0x%x SE 0x%x\n",
1555 dev_dbg(ctx->dev, "SUM 0x%x\n",
1558 serdes_rd(ctx, lane, RXTX_REG14, &val);
1560 serdes_wr(ctx, lane, RXTX_REG14, val);
1561 dev_dbg(ctx->dev, "Enable Manual Summer calibration\n");
1563 serdes_rd(ctx, lane, RXTX_REG127, &val);
1565 dev_dbg(ctx->dev, "Enable Manual Latch calibration\n");
1566 serdes_wr(ctx, lane, RXTX_REG127, val);
1569 serdes_rd(ctx, lane, RXTX_REG12, &val);
1571 serdes_wr(ctx, lane, RXTX_REG12, val);
1573 serdes_wr(ctx, lane, RXTX_REG28, 0x0007);
1575 serdes_wr(ctx, lane, RXTX_REG31, 0x7e00);
1580 struct xgene_phy_ctx *ctx = phy_get_drvdata(phy);
1584 rc = xgene_phy_hw_initialize(ctx, CLK_EXT_DIFF, SSC_DISABLE);
1586 dev_err(ctx->dev, "PHY initialize failed %d\n", rc);
1591 if (!IS_ERR(ctx->clk)) {
1593 clk_prepare_enable(ctx->clk);
1594 clk_disable_unprepare(ctx->clk);
1595 clk_prepare_enable(ctx->clk);
1600 xgene_phy_gen_avg_val(ctx, i);
1602 dev_dbg(ctx->dev, "PHY initialized\n");
1614 struct xgene_phy_ctx *ctx = dev_get_drvdata(dev);
1621 ctx->mode = args->args[0];
1622 return ctx->phy;
1646 struct xgene_phy_ctx *ctx;
1658 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
1659 if (!ctx)
1662 ctx->dev = &pdev->dev;
1665 ctx->sds_base = devm_ioremap_resource(&pdev->dev, res);
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);