board: use do_div for divid operation
authorAo Xu <ao.xu@amlogic.com>
Thu, 2 Aug 2018 06:48:41 +0000 (14:48 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 9 Aug 2018 10:45:48 +0000 (03:45 -0700)
PD#169652: board: use do_div for divid operation

when dividend is 64bit number, divid operation should
use do_div, otherwise link stage will fail for 32bit
system.

Change-Id: Iff2fdc328e364cec6486ab64e2e0f630ccb8534d
Signed-off-by: Ao Xu <ao.xu@amlogic.com>
drivers/amlogic/media/common/codec_mm/codec_mm_scatter.c
drivers/amlogic/media/deinterlace/deinterlace.c
drivers/amlogic/media/enhancement/amvecm/amcsc.c
drivers/amlogic/media/enhancement/amvecm/amvecm.c
drivers/amlogic/media/video_processor/video_dev/amlvideo.c
drivers/amlogic/media/video_sink/video.c
drivers/amlogic/media/vin/tvin/vdin/vdin_ctl.c
drivers/amlogic/media/vin/tvin/vdin/vdin_drv.c
drivers/amlogic/mtd/boot.c
drivers/amlogic/mtd/rsv_manage.c
drivers/amlogic/vrtc/aml_vrtc.c

index 67099561dae7c65ab6ea8b28df86cb86895ac1a2..b5c2d22e555648a8f6af89c315d36d8b454ce2ec 100644 (file)
@@ -1866,8 +1866,12 @@ static int codec_mm_scatter_info_dump_in(
                        smgt->alloc_100ms_up_cnt
                        );
        {
-               int average_timeus = smgt->alloc_cnt == 0 ?
-                       0 : (int)(smgt->alloc_total_us/smgt->alloc_cnt);
+               int average_timeus;
+               u64 divider = smgt->alloc_total_us;
+
+               do_div(divider, smgt->alloc_cnt);
+               average_timeus = (smgt->alloc_cnt == 0 ?
+                       0 : (int)divider);
                BUFPRINT("\talloc time average us:%d\n",
                        average_timeus);
        }
index e1e19e7eaee57c7ed2113f43b553e0cf1bdf6752..6488b2ffd83d2bc5757b1d926ac95593007358ae 100644 (file)
@@ -579,6 +579,14 @@ int di_print_buf(char *buf, int len)
        return pos;
 }
 
+static u64 cur_to_msecs(void)
+{
+       u64 cur = sched_clock();
+
+       do_div(cur, NSEC_PER_MSEC);
+       return cur;
+}
+
 /* static int log_seq = 0; */
 int di_print(const char *fmt, ...)
 {
@@ -589,7 +597,7 @@ int di_print(const char *fmt, ...)
 
        if (di_printk_flag & 1) {
                if (di_log_flag & DI_LOG_PRECISE_TIMESTAMP)
-                       pr_dbg("%llums:", sched_clock()/NSEC_PER_MSEC);
+                       pr_dbg("%llums:", cur_to_msecs());
                va_start(args, fmt);
                vprintk(fmt, args);
                va_end(args);
@@ -3044,8 +3052,8 @@ static void pre_de_process(void)
        if (mpeg2vdin_flag)
                RDMA_WR_BITS(DI_PRE_CTRL, 1, 13, 1);
        #endif
-       di_pre_stru.irq_time[0] = sched_clock()/NSEC_PER_MSEC;
-       di_pre_stru.irq_time[1] = sched_clock()/NSEC_PER_MSEC;
+       di_pre_stru.irq_time[0] = cur_to_msecs();
+       di_pre_stru.irq_time[1] = cur_to_msecs();
 #ifdef CONFIG_AMLOGIC_MEDIA_RDMA
        if (di_pre_rdma_enable & 0x2)
                rdma_config(de_devp->rdma_handle, RDMA_TRIGGER_MANUAL);
@@ -4337,7 +4345,7 @@ static irqreturn_t de_irq(int irq, void *dev_instance)
 
        if (flag) {
                di_pre_stru.irq_time[0] =
-                       (sched_clock()/NSEC_PER_MSEC - di_pre_stru.irq_time[0]);
+                       (cur_to_msecs() - di_pre_stru.irq_time[0]);
                trace_di_pre("PRE-IRQ-0",
                        di_pre_stru.field_count_for_cont,
                        di_pre_stru.irq_time[0]);
@@ -4380,7 +4388,7 @@ static irqreturn_t post_irq(int irq, void *dev_instance)
                di_post_stru.de_post_process_done = 1;
                di_post_stru.post_de_busy = 0;
                di_post_stru.irq_time =
-                       (sched_clock()/NSEC_PER_MSEC - di_post_stru.irq_time);
+                       (cur_to_msecs() - di_post_stru.irq_time);
                trace_di_post("POST-IRQ-1",
                                di_post_stru.post_wr_cnt,
                                di_post_stru.irq_time);
@@ -5248,7 +5256,7 @@ static void di_post_process(void)
                        di_buf, 0, vf_p->width-1,
                        0, vf_p->height-1, vf_p);
                di_post_stru.post_de_busy = 1;
-               di_post_stru.irq_time = sched_clock()/NSEC_PER_MSEC;
+               di_post_stru.irq_time = cur_to_msecs();
        } else {
                di_post_stru.de_post_process_done = 1;
        }
@@ -6376,7 +6384,7 @@ static void di_pre_trigger_work(struct di_pre_stru_s *pre_stru_p)
        if (pre_stru_p->pre_de_busy && init_flag) {
                pre_stru_p->pre_de_busy_timer_count++;
                if (pre_stru_p->pre_de_busy_timer_count >= nr_done_check_cnt &&
-               ((sched_clock()/NSEC_PER_MSEC - di_pre_stru.irq_time[1]) >
+               ((cur_to_msecs() - di_pre_stru.irq_time[1]) >
                (10*nr_done_check_cnt))) {
                        if (di_dbg_mask & 4) {
                                dump_mif_size_state(&di_pre_stru,
@@ -6395,8 +6403,7 @@ static void di_pre_trigger_work(struct di_pre_stru_s *pre_stru_p)
                                pr_info("DI*****wait %d timeout 0x%x(%d ms)*****\n",
                                        pre_stru_p->field_count_for_cont,
                                        Rd(DI_INTR_CTRL),
-                                       (unsigned int)(sched_clock()/
-                                       NSEC_PER_MSEC -
+                                       (unsigned int)(cur_to_msecs() -
                                        di_pre_stru.irq_time[1]));
                        }
                }
index bc21a5653a9073cdd3443d764df50c1cdb02aea2..2dc3d67822a01f6c5586f8c80e0d34e9f0a6cf37 100644 (file)
@@ -3709,21 +3709,28 @@ static void mtx_dot_mul(
        int64_t (*out)[3], int32_t norm)
 {
        int i, j;
+       int64_t tmp;
 
        for (i = 0; i < 3; i++)
-               for (j = 0; j < 3; j++)
-                       out[i][j] = (a[i][j] * b[i][j] + (norm >> 1)) / norm;
+               for (j = 0; j < 3; j++) {
+                       tmp = a[i][j] * b[i][j] + (norm >> 1);
+                       div_s64(tmp, norm);
+                       out[i][j] = tmp;
+               }
 }
 
 static void mtx_mul(int64_t (*a)[3], int64_t *b, int64_t *out, int32_t norm)
 {
        int j, k;
+       int64_t tmp;
 
        for (j = 0; j < 3; j++) {
                out[j] = 0;
                for (k = 0; k < 3; k++)
                        out[j] += a[k][j] * b[k];
-               out[j] = (out[j] + (norm >> 1)) / norm;
+               tmp = out[j] + (norm >> 1);
+               div_s64(tmp, norm);
+               out[j] = tmp;
        }
 }
 
@@ -3732,13 +3739,16 @@ static void mtx_mul_mtx(
        int64_t (*out)[3], int32_t norm)
 {
        int i, j, k;
+       int64_t tmp;
 
        for (i = 0; i < 3; i++)
                for (j = 0; j < 3; j++) {
                        out[i][j] = 0;
                        for (k = 0; k < 3; k++)
                                out[i][j] += a[k][j] * b[i][k];
-                       out[i][j] = (out[i][j] + (norm >> 1)) / norm;
+                       tmp = out[i][j] + (norm >> 1);
+                       div_s64(tmp, norm);
+                       out[i][j] = tmp;
                }
 }
 
@@ -3748,6 +3758,7 @@ static void inverse_3x3(
 {
        int i, j;
        int64_t determinant = 0;
+       int64_t tmp;
 
        for (i = 0; i < 3; i++)
                determinant +=
@@ -3762,8 +3773,9 @@ static void inverse_3x3(
                        out[j][i] -= (in[(i + 1) % 3][(j + 2) % 3]
                                * in[(i + 2) % 3][(j + 1) % 3]);
                        out[j][i] = (out[j][i] * norm) << (obl - 1);
-                       out[j][i] =
-                               (out[j][i] + (determinant >> 1)) / determinant;
+                       tmp = out[j][i] + (determinant >> 1);
+                       div_s64(tmp, determinant);
+                       out[j][i] = tmp;
                }
        }
 }
@@ -3779,6 +3791,7 @@ static void calc_T(
        int64_t C[3];
        int64_t D[3][3];
        int64_t E[3][3];
+       int64_t tmp;
 
        for (i = 0; i < 4; i++)
                z[i] = norm - prmy[i][0] - prmy[i][1];
@@ -3788,9 +3801,13 @@ static void calc_T(
                        A[i][j] = prmy[i][j];
                A[i][2] = z[i];
        }
-       B[0] = (norm * prmy[3][0] * 2 / prmy[3][1] + 1) >> 1;
+       tmp = norm * prmy[3][0] * 2;
+       div_s64(tmp, prmy[3][1]);
+       B[0] = (tmp + 1) >> 1;
        B[1] = norm;
-       B[2] = (norm * z[3] * 2 / prmy[3][1] + 1) >> 1;
+       tmp = norm * z[3] * 2;
+       div_s64(tmp, prmy[3][1]);
+       B[2] = (tmp + 1) >> 1;
        inverse_3x3(A, D, norm, obl);
        mtx_mul(D, B, C, norm);
        for (i = 0; i < 3; i++)
index 765f2f5c1803d2683390fdd166af1fc7f95e6101..bf9cd01dc02cf4ffc2c4c08d08d68ce6c31c8907 100644 (file)
@@ -685,6 +685,7 @@ static unsigned int vpp_luma_max;
 void vpp_get_vframe_hist_info(struct vframe_s *vf)
 {
        unsigned int hist_height, hist_width;
+       u64 divid;
 
        hist_height = READ_VPP_REG_BITS(VPP_IN_H_V_SIZE, 0, 13);
        hist_width = READ_VPP_REG_BITS(VPP_IN_H_V_SIZE, 16, 13);
@@ -845,10 +846,10 @@ void vpp_get_vframe_hist_info(struct vframe_s *vf)
                        VI_HIST_ON_BIN_63_BIT, VI_HIST_ON_BIN_63_WID);
        if (debug_game_mode_1 &&
                (vpp_luma_max != vf->prop.hist.vpp_luma_max)) {
-               vf->ready_clock_hist[1] = sched_clock();
+               divid = vf->ready_clock_hist[1] = sched_clock();
+               do_div(divid, 1000);
                pr_info("vpp output done %lld us. luma_max(0x%x-->0x%x)\n",
-                       vf->ready_clock_hist[1]/1000,
-                       vpp_luma_max, vf->prop.hist.vpp_luma_max);
+                       divid, vpp_luma_max, vf->prop.hist.vpp_luma_max);
                vpp_luma_max = vf->prop.hist.vpp_luma_max;
        }
 }
index 828db504ad6751be9cf2e8de3d199819bfb86702..946350d29a93b053f43614eda8691b87ebddd69b 100644 (file)
@@ -509,6 +509,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
        struct vivi_dev *dev = video_drvdata(file);
        int ret = 0;
        u64 pts_us64 = 0;
+       u64 pts_tmp;
        struct vframe_s *next_vf;
 
        if (vfq_level(&dev->q_ready) > AMLVIDEO_POOL_SIZE - 1)
@@ -532,9 +533,13 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
                dev->first_frame = 1;
                pts_us64 = 0;
        } else {
+               pts_tmp = DUR2PTS(dev->vf->duration) * 100;
+               do_div(pts_tmp, 9);
                pts_us64 = dev->last_pts_us64
-                       + (DUR2PTS(dev->vf->duration))*100/9;
-               dev->vf->pts = pts_us64*9/100;
+                       + pts_tmp;
+               pts_tmp = pts_us64*9;
+               do_div(pts_tmp, 100);
+               dev->vf->pts = pts_tmp;
                /*AMLVIDEO_WARN("pts= %d, dev->vf->duration= %d\n",*/
                        /*dev->vf->pts, (DUR2PTS(dev->vf->duration)));*/
        }
index 70f622c4ead883a78ae8b85a0cfce15c432bf59f..cc3768ce6aa4e53178d956a5a657273efc1e450f 100644 (file)
@@ -2402,12 +2402,22 @@ bool has_enhanced_layer(struct vframe_s *vf)
        return req.dv_enhance_exist;
 }
 u32 property_changed_true;
+
+static u64 func_div(u64 number, u32 divid)
+{
+       u64 tmp = number;
+
+       do_div(tmp, divid);
+       return tmp;
+}
+
 static void vsync_toggle_frame(struct vframe_s *vf)
 {
        u32 first_picture = 0;
        unsigned long flags = 0;
        bool vf_with_el = false;
        bool force_toggle = false;
+       long long *clk_array;
 
        if (vf == NULL)
                return;
@@ -2530,18 +2540,26 @@ static void vsync_toggle_frame(struct vframe_s *vf)
 #endif
                        if (debug_flag & DEBUG_FLAG_LATENCY) {
                                vf->ready_clock[3] = sched_clock();
-                               pr_info("video toggle latency %lld ms video get latency %lld ms vdin put latency %lld ms. first %lld ms.\n",
-                                       vf->ready_clock[3]/1000,
-                                       vf->ready_clock[2]/1000,
-                                       vf->ready_clock[1]/1000,
-                                       vf->ready_clock[0]/1000);
+                               pr_info("video toggle latency %lld ms,"
+                                       "video get latency %lld ms,"
+                                       "vdin put latency %lld ms,"
+                                       "first %lld ms.\n",
+                                       func_div(vf->ready_clock[3], 1000),
+                                       func_div(vf->ready_clock[2], 1000),
+                                       func_div(vf->ready_clock[1], 1000),
+                                       func_div(vf->ready_clock[0], 1000));
                                cur_dispbuf->ready_clock[4] = sched_clock();
-                               pr_info("video put latency %lld ms video toggle latency %lld ms video get latency %lld ms vdin put latency %lld ms. first %lld ms.\n",
-                                       cur_dispbuf->ready_clock[4]/1000,
-                                       cur_dispbuf->ready_clock[3]/1000,
-                                       cur_dispbuf->ready_clock[2]/1000,
-                                       cur_dispbuf->ready_clock[1]/1000,
-                                       cur_dispbuf->ready_clock[0]/1000);
+                               clk_array = cur_dispbuf->ready_clock;
+                               pr_info("video put latency %lld ms,"
+                                       "video toggle latency %lld ms,"
+                                       "video get latency %lld ms,"
+                                       "vdin put latency %lld ms,"
+                                       "first %lld ms.\n",
+                                       func_div(*(clk_array + 4), 1000),
+                                       func_div(*(clk_array + 3), 1000),
+                                       func_div(*(clk_array + 2), 1000),
+                                       func_div(*(clk_array + 1), 1000),
+                                       func_div(*clk_array, 1000));
                        }
                }
 
@@ -5318,9 +5336,9 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                        if (debug_flag & DEBUG_FLAG_LATENCY) {
                                vf->ready_clock[2] = sched_clock();
                                pr_info("video get latency %lld ms vdin put latency %lld ms. first %lld ms.\n",
-                               vf->ready_clock[2]/1000,
-                               vf->ready_clock[1]/1000,
-                               vf->ready_clock[0]/1000);
+                               func_div(vf->ready_clock[2], 1000),
+                               func_div(vf->ready_clock[1], 1000),
+                               func_div(vf->ready_clock[0], 1000));
                        }
                        if (video_vf_dirty_put(vf))
                                break;
index 1b8e3307d154e3c24cd528d61b994f381ffc00df..b4b6cc6cd35e49e7a8aa68024f73693767956aa1 100644 (file)
@@ -2212,6 +2212,7 @@ void vdin_set_vframe_prop_info(struct vframe_s *vf,
                struct vdin_dev_s *devp)
 {
        unsigned int offset = devp->addr_offset;
+       u64 divid;
        struct vframe_bbar_s bbar = {0};
 #ifdef CONFIG_AML_LOCAL_DIMMING
        /*int i;*/
@@ -2408,10 +2409,10 @@ void vdin_set_vframe_prop_info(struct vframe_s *vf,
        vf->prop.meas.vs_cycle = devp->cycle;
        if ((vdin_ctl_dbg & (1 << 8)) &&
                (vdin_luma_max != vf->prop.hist.luma_max)) {
-               vf->ready_clock_hist[0] = sched_clock();
+               divid = vf->ready_clock_hist[0] = sched_clock();
+               do_div(divid, 1000);
                pr_info("vdin write done %lld us. lum_max(0x%x-->0x%x)\n",
-                       vf->ready_clock_hist[0]/1000,
-                       vdin_luma_max, vf->prop.hist.luma_max);
+                       divid, vdin_luma_max, vf->prop.hist.luma_max);
                vdin_luma_max = vf->prop.hist.luma_max;
        }
 #if 0
index 64ff21e6b4175e54ab28e8c9ccf61faba4dfeaef..e8fc2c7148a9ebcb08b26c3ec1cacc27e635b495 100644 (file)
@@ -1140,6 +1140,12 @@ static void vdin_backup_histgram(struct vframe_s *vf, struct vdin_dev_s *devp)
                devp->parm.histgram[i] = vf->prop.hist.gamma[i];
 }
 
+static u64 func_div(u64 cur, u32 divid)
+{
+       do_div(cur, divid);
+       return cur;
+}
+
 /*
  *VDIN_FLAG_RDMA_ENABLE=1
  *     provider_vf_put(devp->last_wr_vfe, devp->vfp);
@@ -1163,6 +1169,7 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
        unsigned int offset = 0, vf_drop_cnt = 0;
        enum tvin_trans_fmt trans_fmt;
        struct tvin_sig_property_s *prop, *pre_prop;
+       long long *clk_array;
 
        /* debug interrupt interval time
         *
@@ -1241,9 +1248,10 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
                        if (time_en) {
                                devp->last_wr_vfe->vf.ready_clock[1] =
                                        sched_clock();
-                               pr_info("vdin put latency %lld us. first %lld us.\n",
-                               devp->last_wr_vfe->vf.ready_clock[1]/1000,
-                               devp->last_wr_vfe->vf.ready_clock[0]/1000);
+                               clk_array = devp->last_wr_vfe->vf.ready_clock;
+                               pr_info("vdin put latency %lld us, first %lld us.\n",
+                                       func_div(*(clk_array + 1), 1000),
+                                       func_div(*clk_array, 1000));
                        }
                } else {
                        devp->vdin_irq_flag = 15;
@@ -1482,9 +1490,10 @@ irqreturn_t vdin_isr(int irq, void *dev_id)
                        provider_vf_put(curr_wr_vfe, devp->vfp);
                        if (vdin_dbg_en) {
                                curr_wr_vfe->vf.ready_clock[1] = sched_clock();
-                               pr_info("vdin put latency %lld us. first %lld us.\n",
-                                       curr_wr_vfe->vf.ready_clock[1]/1000,
-                                       curr_wr_vfe->vf.ready_clock[0]/1000);
+                               clk_array = curr_wr_vfe->vf.ready_clock;
+                               pr_info("vdin put latency %lld us, first %lld us.\n",
+                                       func_div(*(clk_array + 1), 1000),
+                                       func_div(*clk_array, 1000));
                        }
                } else {
                        devp->vdin_irq_flag = 15;
index d03313031cdbdfe0cedc22f1eb029ed5ae941c3e..492996ac7c5f3f5afa7a8bbf6c38cdf1894a1492 100644 (file)
@@ -222,7 +222,8 @@ int m3_nand_boot_read_page_hwecc(struct mtd_info *mtd,
        struct _ext_info *p_ext_info = NULL;
        struct nand_setup *p_nand_setup = NULL;
        int each_boot_pages, boot_num;
-       loff_t ofs;
+       uint64_t ofs, tmp;
+       uint32_t remainder;
 
        u8 type = aml_chip->new_nand_info.type;
 
@@ -333,7 +334,9 @@ int m3_nand_boot_read_page_hwecc(struct mtd_info *mtd,
        read_page++;
 READ_BAD_BLOCK:
        ofs = (read_page << chip->page_shift);
-       if (!(ofs % mtd->erasesize)) {
+       tmp = ofs;
+       div_u64_rem(tmp, mtd->erasesize, &remainder);
+       if (!remainder) {
                if (chip->block_bad(mtd, ofs)) {
                        read_page +=
                        1 << (chip->phys_erase_shift-chip->page_shift);
@@ -493,7 +496,8 @@ int m3_nand_boot_write_page(struct mtd_info *mtd, struct nand_chip *chip,
        uint32_t priv_slc_page;
        int en_slc = 0, each_boot_pages, boot_num;
        u8 type = aml_chip->new_nand_info.type;
-       loff_t ofs;
+       uint64_t ofs, tmp;
+       uint32_t remainder;
 
        new_nand_info = &aml_chip->new_nand_info;
        slc_program_info = &new_nand_info->slc_program_info;
@@ -577,7 +581,9 @@ int m3_nand_boot_write_page(struct mtd_info *mtd, struct nand_chip *chip,
 
 WRITE_BAD_BLOCK:
        ofs = (write_page << chip->page_shift);
-       if (!(ofs % mtd->erasesize)) {
+       tmp = ofs;
+       div_u64_rem(tmp, mtd->erasesize, &remainder);
+       if (!remainder) {
                if (chip->block_bad(mtd, ofs)) {
                        write_page +=
                        1 << (chip->phys_erase_shift-chip->page_shift);
index 72d9e048fad622d24dd380ba5454f207a07d103f..7e9ed0abca530c9c20960e1f9aca3239c4238d7b 100644 (file)
@@ -969,11 +969,12 @@ int aml_nand_scan_rsv_info(struct mtd_info *mtd,
        struct oobinfo_t *oobinfo;
        struct free_node_t *free_node, *tmp_node = NULL;
        unsigned char oob_buf[sizeof(struct oobinfo_t)];
-       loff_t offset;
+       uint64_t offset;
        unsigned char *data_buf, good_addr[256] = {0};
        int start_blk, max_scan_blk, i, k, scan_status = 0, env_status = 0;
        int phys_erase_shift, pages_per_blk, page_num;
        int error = 0, ret = 0;
+       uint32_t  remainder;
 
        data_buf = aml_chip->rsv_data_buf;
        oobinfo = (struct oobinfo_t *)oob_buf;
@@ -1008,7 +1009,8 @@ RE_RSV_INFO:
                pr_info("blk check good but read failed: %llx, %d\n",
                        (uint64_t)offset, error);
                offset += nandrsv_info->size;
-               if ((scan_status++ > 6) || (!(offset % mtd->erasesize))) {
+               div_u64_rem(offset, mtd->erasesize, &remainder);
+               if ((scan_status++ > 6) || (!remainder)) {
                        pr_info("ECC error, scan ONE block exit\n");
                        scan_status = 0;
                        continue;
index 95819b9d37e391ca75b89b7134a958e58fd9c1ea..063cb4eaddbd09a615b594dc7cce5eb5024be13a 100644 (file)
@@ -67,13 +67,14 @@ static int parse_init_date(const char *date)
 static u32 timere_read(void)
 {
        u32 time = 0;
-       unsigned long te = 0, temp = 0;
+       unsigned long long te = 0, temp = 0;
 
        /*timeE high+low, first read low, second read high*/
        te = readl(timere_low_vaddr);
        temp =  readl(timere_high_vaddr);
        te += (temp << 32);
-       time = (u32)(te / 1000000);
+       do_div(te, 1000000);
+       time = (u32)te;
        pr_debug("----------time_e: %us\n", time);
        return time;
 }