Skip to content

Commit 25aaacd

Browse files
nmenongregkh
authored andcommitted
memory: emif: handle overflow for timing for LP mode
In case the custom timings provide values which overflow the maximum possible field value, warn and use maximum permissible value. Signed-off-by: Nishanth Menon <nm@ti.com> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com> Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9ea03de commit 25aaacd

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎drivers/memory/emif.c‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
715715
u32 timeout_perf = EMIF_LP_MODE_TIMEOUT_PERFORMANCE;
716716
u32 timeout_pwr = EMIF_LP_MODE_TIMEOUT_POWER;
717717
u32 freq_threshold = EMIF_LP_MODE_FREQ_THRESHOLD;
718+
u32 mask;
719+
u8 shift;
718720

719721
struct emif_custom_configs *cust_cfgs = emif->plat_data->custom_configs;
720722

@@ -743,27 +745,45 @@ static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
743745

744746
switch (lpmode) {
745747
case EMIF_LP_MODE_CLOCK_STOP:
746-
pwr_mgmt_ctrl = (timeout << CS_TIM_SHIFT) |
747-
SR_TIM_MASK | PD_TIM_MASK;
748+
shift = CS_TIM_SHIFT;
749+
mask = CS_TIM_MASK;
748750
break;
749751
case EMIF_LP_MODE_SELF_REFRESH:
750752
/* Workaround for errata i735 */
751753
if (timeout < 6)
752754
timeout = 6;
753755

754-
pwr_mgmt_ctrl = (timeout << SR_TIM_SHIFT) |
755-
CS_TIM_MASK | PD_TIM_MASK;
756+
shift = SR_TIM_SHIFT;
757+
mask = SR_TIM_MASK;
756758
break;
757759
case EMIF_LP_MODE_PWR_DN:
758-
pwr_mgmt_ctrl = (timeout << PD_TIM_SHIFT) |
759-
CS_TIM_MASK | SR_TIM_MASK;
760+
shift = PD_TIM_SHIFT;
761+
mask = PD_TIM_MASK;
760762
break;
761763
case EMIF_LP_MODE_DISABLE:
762764
default:
763-
pwr_mgmt_ctrl = CS_TIM_MASK |
764-
PD_TIM_MASK | SR_TIM_MASK;
765+
mask = 0;
766+
shift = 0;
767+
break;
768+
}
769+
/* Round to maximum in case of overflow, BUT warn! */
770+
if (lpmode != EMIF_LP_MODE_DISABLE && timeout > mask >> shift) {
771+
pr_err("TIMEOUT Overflow - lpmode=%d perf=%d pwr=%d freq=%d\n",
772+
lpmode,
773+
timeout_perf,
774+
timeout_pwr,
775+
freq_threshold);
776+
WARN(1, "timeout=0x%02x greater than 0x%02x. Using max\n",
777+
timeout, mask >> shift);
778+
timeout = mask >> shift;
765779
}
766780

781+
/* Setup required timing */
782+
pwr_mgmt_ctrl = (timeout << shift) & mask;
783+
/* setup a default mask for rest of the modes */
784+
pwr_mgmt_ctrl |= (SR_TIM_MASK | CS_TIM_MASK | PD_TIM_MASK) &
785+
~mask;
786+
767787
/* No CS_TIM in EMIF_4D5 */
768788
if (ip_rev == EMIF_4D5)
769789
pwr_mgmt_ctrl &= ~CS_TIM_MASK;

0 commit comments

Comments
 (0)