]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/memory/emif.c
memory: emif: Fix the lpmode timeout calculation
[karo-tx-linux.git] / drivers / memory / emif.c
index ecbc1a996eb6e9a6da87f7468b3498e5df632547..897c39a8db864c5d6dfb86f4e814db662eee0437 100644 (file)
@@ -728,13 +728,17 @@ static u32 get_pwr_mgmt_ctrl(u32 freq, struct emif_data *emif, u32 ip_rev)
        /* Timeout based on DDR frequency */
        timeout = freq >= freq_threshold ? timeout_perf : timeout_pwr;
 
-       /* The value to be set in register is "log2(timeout) - 3" */
+       /*
+        * The value to be set in register is "log2(timeout) - 3"
+        * if timeout < 16 load 0 in register
+        * if timeout is not a power of 2, round to next highest power of 2
+        */
        if (timeout < 16) {
                timeout = 0;
        } else {
-               timeout = __fls(timeout) - 3;
                if (timeout & (timeout - 1))
-                       timeout++;
+                       timeout <<= 1;
+               timeout = __fls(timeout) - 3;
        }
 
        switch (lpmode) {