From 62406ca71ab0dc1f9b149c76c4888504ae292d76 Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Fri, 8 Jan 2016 16:30:47 +0800 Subject: [PATCH] CHROMIUM: pinctrl: tegra210: xusb: Fix improper HS_CURR_LEVEL Add HS_CURR_LEVEL range checking to avoid a USB2 failure. This is to make sure the value to be programmed for HS_CURR_LEVEL, the sum of fuse.hs_curr_level (e.g. 3) and hs_curr_level_offset (e.g. -4, specified in .dtsi file), is in valid range from 0 to 0x3F. BUG=None TEST=Set fuse.hs_curr_level to 3, value to be programmed (3-4= -1, use 0) is 0 and in valid range. Set fuse.hs_curr_level to 0x46, value to be programmed (0x46-4= 0x42, use 0x3f) is 0x3f and in valid range. Signed-off-by: Jim Lin Reviewed-on: https://chromium-review.googlesource.com/320980 Reviewed-by: Mark Kuo Reviewed-by: Andrew Bresticker (cherry picked from commit 634e9177c440766c11a8bda252216df1e2c1f5e0) Signed-off-by: David Riley Change-Id: I591fd1c0ed9a782ecf3c1d9a0db558ff54827ed9 Reviewed-on: https://chrome-internal-review.googlesource.com/245447 Reviewed-by: David Riley Commit-Queue: David Riley Tested-by: David Riley --- drivers/pinctrl/pinctrl-tegra210-xusb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinctrl-tegra210-xusb.c b/drivers/pinctrl/pinctrl-tegra210-xusb.c index 4475b79ccd58f..a129ab9a579ff 100644 --- a/drivers/pinctrl/pinctrl-tegra210-xusb.c +++ b/drivers/pinctrl/pinctrl-tegra210-xusb.c @@ -1148,9 +1148,9 @@ static int tegra210_utmi_phy_power_on(struct phy *phy) XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD | XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD2 | XUSB_PADCTL_USB2_OTG_PAD_CTL0_PD_ZI); - value |= (priv->fuse.hs_curr_level[port] + - utmi->hs_curr_level_offset) << - XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT; + value |= (((u32) clamp_val((s32) priv->fuse.hs_curr_level[port] + + utmi->hs_curr_level_offset, 0, 0x3f)) << + XUSB_PADCTL_USB2_OTG_PAD_CTL0_HS_CURR_LEVEL_SHIFT); padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL0(port)); value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(port));