Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5954b91 authored by Vijayavardhan Vennapusa's avatar Vijayavardhan Vennapusa Committed by Gerrit - the friendly Code Review server
Browse files

usb: phy: qusb: Allow support for fused tune2 value correction



Update the TUNE2 parameter by adjusting the programmed tune2 value
with the correction value, if mentioned in dtsi to improve rise/fall times.
In case efuse register value is zero after correction, write previous TUNE2
register value as it is instead of writing hardcoded value. And correction
value should be between [-10 5] in order to take into consideration while
updating TUNE2 register with fused value.

Change-Id: Iaf61705bfd0c7b2cb62de8816c912f05876f001c
Signed-off-by: default avatarVijayavardhan Vennapusa <vvreddy@codeaurora.org>
Signed-off-by: default avatarChandana Kishori Chiluveru <cchiluve@codeaurora.org>
parent 9e999ccd
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -179,6 +179,8 @@ Optional properties:
 - qcom,major-rev: provide major revision number to differentiate power up sequence. default is 2.0
 - qcom,major-rev: provide major revision number to differentiate power up sequence. default is 2.0
 - pinctrl-names/pinctrl-0/1: The GPIOs configured as output function. Names represents "active"
 - pinctrl-names/pinctrl-0/1: The GPIOs configured as output function. Names represents "active"
   state when attached in host mode and "suspend" state when detached.
   state when attached in host mode and "suspend" state when detached.
 - qcom,tune2-efuse-correction: The value to be adjusted from fused value for
   improved rise/fall times.


Example:
Example:
	qusb_phy: qusb@f9b39000 {
	qusb_phy: qusb@f9b39000 {
+25 −13
Original line number Original line Diff line number Diff line
@@ -69,10 +69,6 @@
#define QUSB2PHY_PORT_TUNE3             0x88
#define QUSB2PHY_PORT_TUNE3             0x88
#define QUSB2PHY_PORT_TUNE4             0x8C
#define QUSB2PHY_PORT_TUNE4             0x8C


/* In case Efuse register shows zero, use this value */
#define TUNE2_DEFAULT_HIGH_NIBBLE	0xB
#define TUNE2_DEFAULT_LOW_NIBBLE	0x3

/* Get TUNE2's high nibble value read from efuse */
/* Get TUNE2's high nibble value read from efuse */
#define TUNE2_HIGH_NIBBLE_VAL(val, pos, mask)	((val >> pos) & mask)
#define TUNE2_HIGH_NIBBLE_VAL(val, pos, mask)	((val >> pos) & mask)


@@ -127,6 +123,7 @@ struct qusb_phy {
	u32			tune2_val;
	u32			tune2_val;
	int			tune2_efuse_bit_pos;
	int			tune2_efuse_bit_pos;
	int			tune2_efuse_num_of_bits;
	int			tune2_efuse_num_of_bits;
	int			tune2_efuse_correction;


	bool			power_enabled;
	bool			power_enabled;
	bool			clocks_enabled;
	bool			clocks_enabled;
@@ -351,6 +348,7 @@ static void qusb_phy_get_tune2_param(struct qusb_phy *qphy)
{
{
	u8 num_of_bits;
	u8 num_of_bits;
	u32 bit_mask = 1;
	u32 bit_mask = 1;
	u8 reg_val;


	pr_debug("%s(): num_of_bits:%d bit_pos:%d\n", __func__,
	pr_debug("%s(): num_of_bits:%d bit_pos:%d\n", __func__,
				qphy->tune2_efuse_num_of_bits,
				qphy->tune2_efuse_num_of_bits,
@@ -364,9 +362,8 @@ static void qusb_phy_get_tune2_param(struct qusb_phy *qphy)


	/*
	/*
	 * Read EFUSE register having TUNE2 parameter's high nibble.
	 * Read EFUSE register having TUNE2 parameter's high nibble.
	 * If efuse register shows value as 0x0, then use default value
	 * If efuse register shows value as 0x0, then use previous value
	 * as 0xB as high nibble. Otherwise use efuse register based
	 * as it is. Otherwise use efuse register based value for this purpose.
	 * value for this purpose.
	 */
	 */
	qphy->tune2_val = readl_relaxed(qphy->tune2_efuse_reg);
	qphy->tune2_val = readl_relaxed(qphy->tune2_efuse_reg);
	pr_debug("%s(): bit_mask:%d efuse based tune2 value:%d\n",
	pr_debug("%s(): bit_mask:%d efuse based tune2 value:%d\n",
@@ -375,12 +372,24 @@ static void qusb_phy_get_tune2_param(struct qusb_phy *qphy)
	qphy->tune2_val = TUNE2_HIGH_NIBBLE_VAL(qphy->tune2_val,
	qphy->tune2_val = TUNE2_HIGH_NIBBLE_VAL(qphy->tune2_val,
				qphy->tune2_efuse_bit_pos, bit_mask);
				qphy->tune2_efuse_bit_pos, bit_mask);


	if (!qphy->tune2_val)
	/* Update higher nibble of TUNE2 value for better rise/fall times */
		qphy->tune2_val = TUNE2_DEFAULT_HIGH_NIBBLE;
	if (qphy->tune2_efuse_correction && qphy->tune2_val) {
		if (qphy->tune2_efuse_correction > 5 ||
				qphy->tune2_efuse_correction < -10)
			pr_warn("Correction value is out of range : %d\n",
					qphy->tune2_efuse_correction);
		else
			qphy->tune2_val = qphy->tune2_val +
						qphy->tune2_efuse_correction;
	}

	reg_val = readb_relaxed(qphy->base + QUSB2PHY_PORT_TUNE2);
	if (qphy->tune2_val) {
		reg_val  &= 0x0f;
		reg_val |= (qphy->tune2_val << 4);
	}


	/* Get TUNE2 byte value using high and low nibble value */
	qphy->tune2_val = reg_val;
	qphy->tune2_val = ((qphy->tune2_val << 0x4) |
					TUNE2_DEFAULT_LOW_NIBBLE);
}
}


static void qusb_phy_write_seq(void __iomem *base, u32 *seq, int cnt,
static void qusb_phy_write_seq(void __iomem *base, u32 *seq, int cnt,
@@ -488,7 +497,7 @@ static int qusb_phy_init(struct usb_phy *phy)
	 * and try to read EFUSE value only once i.e. not every USB
	 * and try to read EFUSE value only once i.e. not every USB
	 * cable connect case.
	 * cable connect case.
	 */
	 */
	if (qphy->tune2_efuse_reg) {
	if (qphy->tune2_efuse_reg && !tune2) {
		if (!qphy->tune2_val)
		if (!qphy->tune2_val)
			qusb_phy_get_tune2_param(qphy);
			qusb_phy_get_tune2_param(qphy);


@@ -869,6 +878,9 @@ static int qusb_phy_probe(struct platform_device *pdev)
						"qcom,tune2-efuse-num-bits",
						"qcom,tune2-efuse-num-bits",
						&qphy->tune2_efuse_num_of_bits);
						&qphy->tune2_efuse_num_of_bits);
			}
			}
			of_property_read_u32(dev->of_node,
						"qcom,tune2-efuse-correction",
						&qphy->tune2_efuse_correction);


			if (ret) {
			if (ret) {
				dev_err(dev, "DT Value for tune2 efuse is invalid.\n");
				dev_err(dev, "DT Value for tune2 efuse is invalid.\n");