Lines Matching +full:sata +full:- +full:port

1 // SPDX-License-Identifier: GPL-2.0-or-later
27 /* The older SATA PHY registers duplicated per port registers within the map,
28 * rather than having a separate map per port.
194 static inline void __iomem *brcm_sata_ctrl_base(struct brcm_sata_port *port) in brcm_sata_ctrl_base() argument
196 struct brcm_sata_phy *priv = port->phy_priv; in brcm_sata_ctrl_base()
199 switch (priv->version) { in brcm_sata_ctrl_base()
204 dev_err(priv->dev, "invalid phy version\n"); in brcm_sata_ctrl_base()
208 return priv->ctrl_base + (port->portnum * size); in brcm_sata_ctrl_base()
211 static void brcm_sata_phy_wr(struct brcm_sata_port *port, u32 bank, in brcm_sata_phy_wr() argument
214 struct brcm_sata_phy *priv = port->phy_priv; in brcm_sata_phy_wr()
215 void __iomem *pcb_base = priv->phy_base; in brcm_sata_phy_wr()
218 if (priv->version == BRCM_SATA_PHY_STB_40NM) in brcm_sata_phy_wr()
219 bank += (port->portnum * SATA_PCB_REG_40NM_SPACE_SIZE); in brcm_sata_phy_wr()
221 pcb_base += (port->portnum * SATA_PCB_REG_28NM_SPACE_SIZE); in brcm_sata_phy_wr()
229 static u32 brcm_sata_phy_rd(struct brcm_sata_port *port, u32 bank, u32 ofs) in brcm_sata_phy_rd() argument
231 struct brcm_sata_phy *priv = port->phy_priv; in brcm_sata_phy_rd()
232 void __iomem *pcb_base = priv->phy_base; in brcm_sata_phy_rd()
234 if (priv->version == BRCM_SATA_PHY_STB_40NM) in brcm_sata_phy_rd()
235 bank += (port->portnum * SATA_PCB_REG_40NM_SPACE_SIZE); in brcm_sata_phy_rd()
237 pcb_base += (port->portnum * SATA_PCB_REG_28NM_SPACE_SIZE); in brcm_sata_phy_rd()
248 static void brcm_stb_sata_ssc_init(struct brcm_sata_port *port) in brcm_stb_sata_ssc_init() argument
250 struct brcm_sata_phy *priv = port->phy_priv; in brcm_stb_sata_ssc_init()
255 brcm_sata_phy_wr(port, TXPMD_REG_BANK, TXPMD_CONTROL1, ~tmp, tmp); in brcm_stb_sata_ssc_init()
258 brcm_sata_phy_wr(port, TXPMD_REG_BANK, TXPMD_TX_FREQ_CTRL_CONTROL2, in brcm_stb_sata_ssc_init()
263 if (port->ssc_en) { in brcm_stb_sata_ssc_init()
264 dev_info(priv->dev, "enabling SSC on port%d\n", port->portnum); in brcm_stb_sata_ssc_init()
270 brcm_sata_phy_wr(port, TXPMD_REG_BANK, TXPMD_TX_FREQ_CTRL_CONTROL3, in brcm_stb_sata_ssc_init()
277 static int brcm_stb_sata_rxaeq_init(struct brcm_sata_port *port) in brcm_stb_sata_rxaeq_init() argument
281 switch (port->rxaeq_mode) { in brcm_stb_sata_rxaeq_init()
293 if (port->rxaeq_val > AEQ_FRC_EQ_VAL_MASK) in brcm_stb_sata_rxaeq_init()
294 return -EINVAL; in brcm_stb_sata_rxaeq_init()
295 tmp |= port->rxaeq_val << AEQ_FRC_EQ_VAL_SHIFT; in brcm_stb_sata_rxaeq_init()
299 brcm_sata_phy_wr(port, AEQRX_REG_BANK_0, reg, ~tmp, tmp); in brcm_stb_sata_rxaeq_init()
300 brcm_sata_phy_wr(port, AEQRX_REG_BANK_1, reg, ~tmp, tmp); in brcm_stb_sata_rxaeq_init()
305 static int brcm_stb_sata_init(struct brcm_sata_port *port) in brcm_stb_sata_init() argument
307 brcm_stb_sata_ssc_init(port); in brcm_stb_sata_init()
309 return brcm_stb_sata_rxaeq_init(port); in brcm_stb_sata_init()
312 static int brcm_stb_sata_16nm_ssc_init(struct brcm_sata_port *port) in brcm_stb_sata_16nm_ssc_init() argument
317 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL6, 0, 0x141); in brcm_stb_sata_16nm_ssc_init()
320 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL8, 0, 0xc006); in brcm_stb_sata_16nm_ssc_init()
324 brcm_sata_phy_wr(port, AEQRX_REG_BANK_0, AEQ_FRC_EQ, in brcm_stb_sata_16nm_ssc_init()
330 if (port->ssc_en) in brcm_stb_sata_16nm_ssc_init()
334 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_CDR_CONTROL1, in brcm_stb_sata_16nm_ssc_init()
341 if (port->ssc_en) in brcm_stb_sata_16nm_ssc_init()
349 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_CDR_CDR_PROP_BW, ~tmp, in brcm_stb_sata_16nm_ssc_init()
356 if (port->ssc_en) in brcm_stb_sata_16nm_ssc_init()
362 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_CDR_CDR_ACQ_INTEG_BW, in brcm_stb_sata_16nm_ssc_init()
369 if (port->ssc_en) in brcm_stb_sata_16nm_ssc_init()
375 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_CDR_CDR_LOCK_INTEG_BW, in brcm_stb_sata_16nm_ssc_init()
380 if (port->ssc_en) in brcm_stb_sata_16nm_ssc_init()
384 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_FREQ_MON_CONTROL1, in brcm_stb_sata_16nm_ssc_init()
388 switch (port->tx_amplitude_val) { in brcm_stb_sata_16nm_ssc_init()
407 brcm_sata_phy_wr(port, BLOCK1_REG_BANK, BLOCK1_TEST_TX, ~tmp, in brcm_stb_sata_16nm_ssc_init()
411 brcm_sata_phy_wr(port, TX_REG_BANK, TX_ACTRL5, ~TX_ACTRL5_SSC_EN, in brcm_stb_sata_16nm_ssc_init()
412 port->ssc_en ? TX_ACTRL5_SSC_EN : 0); in brcm_stb_sata_16nm_ssc_init()
417 static int brcm_stb_sata_16nm_init(struct brcm_sata_port *port) in brcm_stb_sata_16nm_init() argument
419 return brcm_stb_sata_16nm_ssc_init(port); in brcm_stb_sata_16nm_init()
422 /* NS2 SATA PLL1 defaults were characterized by H/W group */
427 static int brcm_ns2_sata_init(struct brcm_sata_port *port) in brcm_ns2_sata_init() argument
431 void __iomem *ctrl_base = brcm_sata_ctrl_base(port); in brcm_ns2_sata_init()
432 struct device *dev = port->phy_priv->dev; in brcm_ns2_sata_init()
440 brcm_sata_phy_wr(port, OOB_REG_BANK, OOB_CTRL1, 0x0, val); in brcm_ns2_sata_init()
445 brcm_sata_phy_wr(port, OOB_REG_BANK, OOB_CTRL2, 0x0, val); in brcm_ns2_sata_init()
449 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL2, 0x0, val); in brcm_ns2_sata_init()
451 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL3, 0x0, val); in brcm_ns2_sata_init()
453 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL4, 0x0, val); in brcm_ns2_sata_init()
457 brcm_sata_phy_wr(port, BLOCK0_REG_BANK, BLOCK0_SPARE, in brcm_ns2_sata_init()
470 val = brcm_sata_phy_rd(port, BLOCK0_REG_BANK, in brcm_ns2_sata_init()
475 try--; in brcm_ns2_sata_init()
479 dev_err(dev, "port%d PLL did not lock\n", port->portnum); in brcm_ns2_sata_init()
480 return -ETIMEDOUT; in brcm_ns2_sata_init()
483 dev_dbg(dev, "port%d initialized\n", port->portnum); in brcm_ns2_sata_init()
488 static int brcm_nsp_sata_init(struct brcm_sata_port *port) in brcm_nsp_sata_init() argument
490 struct device *dev = port->phy_priv->dev; in brcm_nsp_sata_init()
495 if (port->portnum == 0) in brcm_nsp_sata_init()
497 else if (port->portnum == 1) in brcm_nsp_sata_init()
500 return -EINVAL; in brcm_nsp_sata_init()
507 brcm_sata_phy_wr(port, oob_bank, OOB_CTRL1, 0x0, val); in brcm_nsp_sata_init()
513 brcm_sata_phy_wr(port, oob_bank, OOB_CTRL2, 0x0, val); in brcm_nsp_sata_init()
516 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_ACTRL2, in brcm_nsp_sata_init()
520 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_CAP_CONTROL, in brcm_nsp_sata_init()
524 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_REG_BANK_0_PLLCONTROL_0, in brcm_nsp_sata_init()
527 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_REG_BANK_0_PLLCONTROL_0, in brcm_nsp_sata_init()
530 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_REG_BANK_0_PLLCONTROL_0, in brcm_nsp_sata_init()
535 while (--try) { in brcm_nsp_sata_init()
536 val = brcm_sata_phy_rd(port, BLOCK0_REG_BANK, in brcm_nsp_sata_init()
544 dev_err(dev, "port%d PLL did not lock\n", port->portnum); in brcm_nsp_sata_init()
545 return -ETIMEDOUT; in brcm_nsp_sata_init()
548 dev_dbg(dev, "port%d initialized\n", port->portnum); in brcm_nsp_sata_init()
561 static int brcm_sr_sata_init(struct brcm_sata_port *port) in brcm_sr_sata_init() argument
563 struct device *dev = port->phy_priv->dev; in brcm_sr_sata_init()
568 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL2, 0x0, val); in brcm_sr_sata_init()
570 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL3, 0x0, val); in brcm_sr_sata_init()
572 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL4, 0x0, val); in brcm_sr_sata_init()
576 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_ACTRL6, 0x0, val); in brcm_sr_sata_init()
581 val = brcm_sata_phy_rd(port, BLOCK0_REG_BANK, in brcm_sr_sata_init()
586 try--; in brcm_sr_sata_init()
591 dev_err(dev, "port%d PLL did not lock\n", port->portnum); in brcm_sr_sata_init()
592 return -ETIMEDOUT; in brcm_sr_sata_init()
596 brcm_sata_phy_wr(port, TX_REG_BANK, TX_ACTRL0, in brcm_sr_sata_init()
604 brcm_sata_phy_wr(port, OOB_REG_BANK, OOB_CTRL1, 0x0, val); in brcm_sr_sata_init()
608 brcm_sata_phy_wr(port, OOB_REG_BANK, OOB_CTRL2, 0x0, val); in brcm_sr_sata_init()
613 static int brcm_dsl_sata_init(struct brcm_sata_port *port) in brcm_dsl_sata_init() argument
615 struct device *dev = port->phy_priv->dev; in brcm_dsl_sata_init()
619 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL7, 0, 0x873); in brcm_dsl_sata_init()
621 brcm_sata_phy_wr(port, PLL1_REG_BANK, PLL1_ACTRL6, 0, 0xc000); in brcm_dsl_sata_init()
623 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_REG_BANK_0_PLLCONTROL_0, in brcm_dsl_sata_init()
627 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_REG_BANK_0_PLLCONTROL_0, in brcm_dsl_sata_init()
631 brcm_sata_phy_wr(port, AEQRX_REG_BANK_1, AEQRX_SLCAL0_CTRL0, in brcm_dsl_sata_init()
634 brcm_sata_phy_wr(port, AEQRX_REG_BANK_1, AEQRX_SLCAL1_CTRL0, in brcm_dsl_sata_init()
638 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_CAP_CHARGE_TIME, 0, 0x32); in brcm_dsl_sata_init()
640 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_VCO_CAL_THRESH, 0, 0xa); in brcm_dsl_sata_init()
642 brcm_sata_phy_wr(port, PLL_REG_BANK_0, PLL_FREQ_DET_TIME, 0, 0x64); in brcm_dsl_sata_init()
648 tmp = brcm_sata_phy_rd(port, BLOCK0_REG_BANK, in brcm_dsl_sata_init()
653 try--; in brcm_dsl_sata_init()
658 dev_err(dev, "port%d PLL did not lock\n", port->portnum); in brcm_dsl_sata_init()
659 return -ETIMEDOUT; in brcm_dsl_sata_init()
662 dev_dbg(dev, "port%d initialized\n", port->portnum); in brcm_dsl_sata_init()
670 struct brcm_sata_port *port = phy_get_drvdata(phy); in brcm_sata_phy_init() local
672 switch (port->phy_priv->version) { in brcm_sata_phy_init()
674 rc = brcm_stb_sata_16nm_init(port); in brcm_sata_phy_init()
678 rc = brcm_stb_sata_init(port); in brcm_sata_phy_init()
681 rc = brcm_ns2_sata_init(port); in brcm_sata_phy_init()
684 rc = brcm_nsp_sata_init(port); in brcm_sata_phy_init()
687 rc = brcm_sr_sata_init(port); in brcm_sata_phy_init()
690 rc = brcm_dsl_sata_init(port); in brcm_sata_phy_init()
693 rc = -ENODEV; in brcm_sata_phy_init()
699 static void brcm_stb_sata_calibrate(struct brcm_sata_port *port) in brcm_stb_sata_calibrate() argument
703 brcm_sata_phy_wr(port, RXPMD_REG_BANK, RXPMD_RX_FREQ_MON_CONTROL1, in brcm_stb_sata_calibrate()
709 struct brcm_sata_port *port = phy_get_drvdata(phy); in brcm_sata_phy_calibrate() local
710 int rc = -EOPNOTSUPP; in brcm_sata_phy_calibrate()
712 switch (port->phy_priv->version) { in brcm_sata_phy_calibrate()
715 brcm_stb_sata_calibrate(port); in brcm_sata_phy_calibrate()
732 { .compatible = "brcm,bcm7216-sata-phy",
734 { .compatible = "brcm,bcm7445-sata-phy",
736 { .compatible = "brcm,bcm7425-sata-phy",
738 { .compatible = "brcm,iproc-ns2-sata-phy",
740 { .compatible = "brcm,iproc-nsp-sata-phy",
742 { .compatible = "brcm,iproc-sr-sata-phy",
744 { .compatible = "brcm,bcm63138-sata-phy",
753 struct device *dev = &pdev->dev; in brcm_sata_phy_probe()
754 struct device_node *dn = dev->of_node; in brcm_sata_phy_probe()
761 return -ENODEV; in brcm_sata_phy_probe()
765 return -ENOMEM; in brcm_sata_phy_probe()
767 priv->dev = dev; in brcm_sata_phy_probe()
769 priv->phy_base = devm_platform_ioremap_resource_byname(pdev, "phy"); in brcm_sata_phy_probe()
770 if (IS_ERR(priv->phy_base)) in brcm_sata_phy_probe()
771 return PTR_ERR(priv->phy_base); in brcm_sata_phy_probe()
775 priv->version = (uintptr_t)of_id->data; in brcm_sata_phy_probe()
777 priv->version = BRCM_SATA_PHY_STB_28NM; in brcm_sata_phy_probe()
779 if (priv->version == BRCM_SATA_PHY_IPROC_NS2) { in brcm_sata_phy_probe()
780 priv->ctrl_base = devm_platform_ioremap_resource_byname(pdev, "phy-ctrl"); in brcm_sata_phy_probe()
781 if (IS_ERR(priv->ctrl_base)) in brcm_sata_phy_probe()
782 return PTR_ERR(priv->ctrl_base); in brcm_sata_phy_probe()
787 struct brcm_sata_port *port; in brcm_sata_phy_probe() local
792 return -EINVAL; in brcm_sata_phy_probe()
797 return -EINVAL; in brcm_sata_phy_probe()
799 if (priv->phys[id].phy) { in brcm_sata_phy_probe()
800 dev_err(dev, "already registered port %u\n", id); in brcm_sata_phy_probe()
801 return -EINVAL; in brcm_sata_phy_probe()
804 port = &priv->phys[id]; in brcm_sata_phy_probe()
805 port->portnum = id; in brcm_sata_phy_probe()
806 port->phy_priv = priv; in brcm_sata_phy_probe()
807 port->phy = devm_phy_create(dev, child, &phy_ops); in brcm_sata_phy_probe()
808 port->rxaeq_mode = RXAEQ_MODE_OFF; in brcm_sata_phy_probe()
809 if (!of_property_read_string(child, "brcm,rxaeq-mode", in brcm_sata_phy_probe()
811 port->rxaeq_mode = rxaeq_to_val(rxaeq_mode); in brcm_sata_phy_probe()
812 if (port->rxaeq_mode == RXAEQ_MODE_MANUAL) in brcm_sata_phy_probe()
813 of_property_read_u32(child, "brcm,rxaeq-value", in brcm_sata_phy_probe()
814 &port->rxaeq_val); in brcm_sata_phy_probe()
816 of_property_read_u32(child, "brcm,tx-amplitude-millivolt", in brcm_sata_phy_probe()
817 &port->tx_amplitude_val); in brcm_sata_phy_probe()
819 port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc"); in brcm_sata_phy_probe()
820 if (IS_ERR(port->phy)) { in brcm_sata_phy_probe()
822 return PTR_ERR(port->phy); in brcm_sata_phy_probe()
825 phy_set_drvdata(port->phy, port); in brcm_sata_phy_probe()
835 dev_info(dev, "registered %d port(s)\n", count); in brcm_sata_phy_probe()
844 .name = "brcm-sata-phy",
849 MODULE_DESCRIPTION("Broadcom SATA PHY driver");
853 MODULE_ALIAS("platform:phy-brcm-sata");