Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: rockchip-typec: Do the calibration more correctly

Calculate the calibration code as per the docs. The docs talk about
reading and averaging the pullup and pulldown calibration codes. They
also talk about adding in some adjustment codes. Let's do what the
docs say.

In practice this doesn't seem to matter a whole lot. On a device I
tested the pullup and pulldown codes were nearly the same (0x23 and
0x24) and the adjustment codes were 0.

Reviewed-by: Chris Zhong <zyw@rock-chips.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

authored by

Douglas Anderson and committed by
Kishon Vijay Abraham I
e023b1fb f85fd4c9

+18 -9
+18 -9
drivers/phy/rockchip/phy-rockchip-typec.c
··· 560 560 u16 val; 561 561 u16 tx_ana_ctrl_reg_1; 562 562 u16 tx_ana_ctrl_reg_2; 563 - s32 pu_calib_code; 563 + s32 pu_calib_code, pd_calib_code; 564 + s32 pu_adj, pd_adj; 565 + u16 calib; 566 + 567 + /* 568 + * Calculate calibration code as per docs: use an average of the 569 + * pull down and pull up. Then add in adjustments. 570 + */ 571 + val = readl(tcphy->base + CMN_TXPUCAL_CTRL); 572 + pu_calib_code = CMN_CALIB_CODE_POS(val); 573 + val = readl(tcphy->base + CMN_TXPDCAL_CTRL); 574 + pd_calib_code = CMN_CALIB_CODE_POS(val); 575 + val = readl(tcphy->base + CMN_TXPU_ADJ_CTRL); 576 + pu_adj = CMN_CALIB_CODE(val); 577 + val = readl(tcphy->base + CMN_TXPD_ADJ_CTRL); 578 + pd_adj = CMN_CALIB_CODE(val); 579 + calib = (pu_calib_code + pd_calib_code) / 2 + pu_adj + pd_adj; 564 580 565 581 /* disable txda_cal_latch_en for rewrite the calibration values */ 566 582 tx_ana_ctrl_reg_1 = readl(tcphy->base + TX_ANA_CTRL_REG_1); 567 583 tx_ana_ctrl_reg_1 &= ~TXDA_CAL_LATCH_EN; 568 584 writel(tx_ana_ctrl_reg_1, tcphy->base + TX_ANA_CTRL_REG_1); 569 585 570 - /* 571 - * read a resistor calibration code from CMN_TXPUCAL_CTRL[5:0] and 572 - * write it to TX_DIG_CTRL_REG_2[5:0]. 573 - */ 574 - val = readl(tcphy->base + CMN_TXPUCAL_CTRL); 575 - pu_calib_code = CMN_CALIB_CODE_POS(val); 576 - 577 586 /* write the calibration, then delay 10 ms as sample in docs */ 578 587 val = readl(tcphy->base + TX_DIG_CTRL_REG_2); 579 588 val &= ~(TX_RESCAL_CODE_MASK << TX_RESCAL_CODE_OFFSET); 580 - val |= pu_calib_code << TX_RESCAL_CODE_OFFSET; 589 + val |= calib << TX_RESCAL_CODE_OFFSET; 581 590 writel(val, tcphy->base + TX_DIG_CTRL_REG_2); 582 591 usleep_range(10000, 10050); 583 592