ddr: altera: Fix ad-hoc iterative division implementation
[oweals/u-boot.git] / drivers / ddr / altera / sequencer.c
index 35ecc67560772aef3de4d727b0f06944d12c6e04..28e32ff57501b797712d5fdfce159e832a401501 100644 (file)
@@ -732,14 +732,18 @@ scc_mgr_apply_group_all_out_delay_add_all_ranks(const u32 write_group,
        }
 }
 
-/* optimization used to recover some slots in ddr3 inst_rom */
-/* could be applied to other protocols if we wanted to */
+/**
+ * set_jump_as_return() - Return instruction optimization
+ *
+ * Optimization used to recover some slots in ddr3 inst_rom could be
+ * applied to other protocols if we wanted to
+ */
 static void set_jump_as_return(void)
 {
        /*
-        * to save space, we replace return with jump to special shared
+        * To save space, we replace return with jump to special shared
         * RETURN instruction so we set the counter to large value so that
-        * we always jump
+        * we always jump.
         */
        writel(0xff, &sdr_rw_load_mgr_regs->load_cntr0);
        writel(RW_MGR_RETURN, &sdr_rw_load_jump_mgr_regs->load_jump_add0);
@@ -2181,7 +2185,6 @@ static uint32_t rw_mgr_mem_calibrate_vfifo(uint32_t read_group,
 {
        uint32_t p, d, rank_bgn, sr;
        uint32_t dtaps_per_ptap;
-       uint32_t tmp_delay;
        uint32_t bit_chk;
        uint32_t grp_calibrated;
        uint32_t write_group, write_test_bgn;
@@ -2196,14 +2199,8 @@ static uint32_t rw_mgr_mem_calibrate_vfifo(uint32_t read_group,
        write_test_bgn = test_bgn;
 
        /* USER Determine number of delay taps for each phase tap */
-       dtaps_per_ptap = 0;
-       tmp_delay = 0;
-       while (tmp_delay < IO_DELAY_PER_OPA_TAP) {
-               dtaps_per_ptap++;
-               tmp_delay += IO_DELAY_PER_DQS_EN_DCHAIN_TAP;
-       }
-       dtaps_per_ptap--;
-       tmp_delay = 0;
+       dtaps_per_ptap = DIV_ROUND_UP(IO_DELAY_PER_OPA_TAP,
+                                     IO_DELAY_PER_DQS_EN_DCHAIN_TAP) - 1;
 
        /* update info for sims */
        reg_file_set_group(read_group);