Lines Matching refs:pll
78 static void print_pll(struct device *dev, struct ccs_pll *pll) in print_pll() argument
85 { &pll->vt_fr, &pll->vt_bk, PLL_VT }, in print_pll()
86 { &pll->op_fr, &pll->op_bk, PLL_OP } in print_pll()
90 dev_dbg(dev, "ext_clk_freq_hz\t\t%u\n", pll->ext_clk_freq_hz); in print_pll()
95 if (pll->flags & CCS_PLL_FLAG_DUAL_PLL || in print_pll()
108 if (!(pll->flags & CCS_PLL_FLAG_NO_OP_CLOCKS) || in print_pll()
123 pll->pixel_rate_pixel_array); in print_pll()
125 pll->pixel_rate_csi); in print_pll()
128 pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", in print_pll()
129 pll->flags & PLL_FL(LINK_DECOUPLED) ? " link-decoupled" : "", in print_pll()
130 pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ? in print_pll()
132 pll->flags & PLL_FL(FLEXIBLE_OP_PIX_CLK_DIV) ? in print_pll()
134 pll->flags & PLL_FL(FIFO_DERATING) ? " fifo-derating" : "", in print_pll()
135 pll->flags & PLL_FL(FIFO_OVERRATING) ? " fifo-overrating" : "", in print_pll()
136 pll->flags & PLL_FL(DUAL_PLL) ? " dual-pll" : "", in print_pll()
137 pll->flags & PLL_FL(OP_SYS_DDR) ? " op-sys-ddr" : "", in print_pll()
138 pll->flags & PLL_FL(OP_PIX_DDR) ? " op-pix-ddr" : ""); in print_pll()
153 struct ccs_pll *pll, unsigned int which) in check_fr_bounds() argument
162 pll_fr = &pll->op_fr; in check_fr_bounds()
165 pll_fr = &pll->vt_fr; in check_fr_bounds()
193 struct ccs_pll *pll, unsigned int which) in check_bk_bounds() argument
201 if (pll->flags & CCS_PLL_FLAG_NO_OP_CLOCKS) in check_bk_bounds()
205 pll_bk = &pll->op_bk; in check_bk_bounds()
208 pll_bk = &pll->vt_bk; in check_bk_bounds()
233 static int check_ext_bounds(struct device *dev, struct ccs_pll *pll) in check_ext_bounds() argument
235 if (!(pll->flags & CCS_PLL_FLAG_FIFO_DERATING) && in check_ext_bounds()
236 pll->pixel_rate_pixel_array > pll->pixel_rate_csi) { in check_ext_bounds()
241 if (!(pll->flags & CCS_PLL_FLAG_FIFO_OVERRATING) && in check_ext_bounds()
242 pll->pixel_rate_pixel_array < pll->pixel_rate_csi) { in check_ext_bounds()
252 struct ccs_pll *pll, struct ccs_pll_branch_fr *pll_fr, in ccs_pll_find_vt_sys_div() argument
292 struct ccs_pll *pll, u32 mul, u32 div) in __ccs_pll_calculate_vt_tree() argument
296 struct ccs_pll_branch_fr *pll_fr = &pll->vt_fr; in __ccs_pll_calculate_vt_tree()
297 struct ccs_pll_branch_bk *pll_bk = &pll->vt_bk; in __ccs_pll_calculate_vt_tree()
303 pll->ext_clk_freq_hz / pll_fr->pre_pll_clk_div; in __ccs_pll_calculate_vt_tree()
325 ccs_pll_find_vt_sys_div(dev, lim, pll, pll_fr, vt_div, vt_div, in __ccs_pll_calculate_vt_tree()
370 pll->pixel_rate_pixel_array = in __ccs_pll_calculate_vt_tree()
371 pll_bk->pix_clk_freq_hz * pll->vt_lanes; in __ccs_pll_calculate_vt_tree()
378 struct ccs_pll *pll) in ccs_pll_calculate_vt_tree() argument
381 struct ccs_pll_branch_fr *pll_fr = &pll->vt_fr; in ccs_pll_calculate_vt_tree()
386 pre_div = gcd(pll->pixel_rate_csi, in ccs_pll_calculate_vt_tree()
387 pll->ext_clk_freq_hz * pll->vt_lanes); in ccs_pll_calculate_vt_tree()
388 pre_mul = pll->pixel_rate_csi / pre_div; in ccs_pll_calculate_vt_tree()
389 pre_div = pll->ext_clk_freq_hz * pll->vt_lanes / pre_div; in ccs_pll_calculate_vt_tree()
394 DIV_ROUND_UP(pll->ext_clk_freq_hz, in ccs_pll_calculate_vt_tree()
398 pll->ext_clk_freq_hz / in ccs_pll_calculate_vt_tree()
407 (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : in ccs_pll_calculate_vt_tree()
419 rval = __ccs_pll_calculate_vt_tree(dev, lim, pll, in ccs_pll_calculate_vt_tree()
424 rval = check_fr_bounds(dev, lim, pll, PLL_VT); in ccs_pll_calculate_vt_tree()
428 rval = check_bk_bounds(dev, lim, pll, PLL_VT); in ccs_pll_calculate_vt_tree()
441 struct ccs_pll *pll, struct ccs_pll_branch_fr *pll_fr, in ccs_pll_calculate_vt() argument
451 if (pll->flags & CCS_PLL_FLAG_NO_OP_CLOCKS) in ccs_pll_calculate_vt()
458 if (!(pll->flags & CCS_PLL_FLAG_FIFO_DERATING)) { in ccs_pll_calculate_vt()
461 * pll->vt_lanes * phy_const / pll->op_lanes in ccs_pll_calculate_vt()
462 / (PHY_CONST_DIV << op_pix_ddr(pll->flags)); in ccs_pll_calculate_vt()
472 / pll->binning_horizontal) in ccs_pll_calculate_vt()
473 vt_op_binning_div = pll->binning_horizontal; in ccs_pll_calculate_vt()
489 dev_dbg(dev, "scale_m: %u\n", pll->scale_m); in ccs_pll_calculate_vt()
491 DIV_ROUND_UP(pll->bits_per_pixel in ccs_pll_calculate_vt()
492 * op_pll_bk->sys_clk_div * pll->scale_n in ccs_pll_calculate_vt()
493 * pll->vt_lanes * phy_const, in ccs_pll_calculate_vt()
494 (pll->flags & in ccs_pll_calculate_vt()
496 pll->csi2.lanes : 1) in ccs_pll_calculate_vt()
497 * vt_op_binning_div * pll->scale_m in ccs_pll_calculate_vt()
498 * PHY_CONST_DIV << op_pix_ddr(pll->flags)); in ccs_pll_calculate_vt()
520 ccs_pll_find_vt_sys_div(dev, lim, pll, pll_fr, min_vt_div, in ccs_pll_calculate_vt()
562 pll->vt_bk.sys_clk_div = DIV_ROUND_UP(vt_div, best_pix_div); in ccs_pll_calculate_vt()
563 pll->vt_bk.pix_clk_div = best_pix_div; in ccs_pll_calculate_vt()
565 pll->vt_bk.sys_clk_freq_hz = in ccs_pll_calculate_vt()
566 pll_fr->pll_op_clk_freq_hz / pll->vt_bk.sys_clk_div; in ccs_pll_calculate_vt()
567 pll->vt_bk.pix_clk_freq_hz = in ccs_pll_calculate_vt()
568 pll->vt_bk.sys_clk_freq_hz / pll->vt_bk.pix_clk_div; in ccs_pll_calculate_vt()
571 pll->pixel_rate_pixel_array = in ccs_pll_calculate_vt()
572 pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes; in ccs_pll_calculate_vt()
590 struct ccs_pll *pll, struct ccs_pll_branch_fr *op_pll_fr, in ccs_pll_calculate_op() argument
620 / (pll->ext_clk_freq_hz / in ccs_pll_calculate_op()
637 pll->ext_clk_freq_hz / in ccs_pll_calculate_op()
672 op_pll_fr->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz in ccs_pll_calculate_op()
678 if (pll->flags & CCS_PLL_FLAG_LANE_SPEED_MODEL) in ccs_pll_calculate_op()
680 (pll->bits_per_pixel in ccs_pll_calculate_op()
681 * pll->op_lanes * (phy_const << op_sys_ddr(pll->flags)) in ccs_pll_calculate_op()
682 / PHY_CONST_DIV / pll->csi2.lanes / l) in ccs_pll_calculate_op()
683 >> op_pix_ddr(pll->flags); in ccs_pll_calculate_op()
686 (pll->bits_per_pixel in ccs_pll_calculate_op()
687 * (phy_const << op_sys_ddr(pll->flags)) in ccs_pll_calculate_op()
688 / PHY_CONST_DIV / l) >> op_pix_ddr(pll->flags); in ccs_pll_calculate_op()
691 (op_sys_clk_freq_hz_sdr >> op_pix_ddr(pll->flags)) in ccs_pll_calculate_op()
694 op_sys_clk_freq_hz_sdr >> op_sys_ddr(pll->flags); in ccs_pll_calculate_op()
702 struct ccs_pll *pll) in ccs_pll_calculate() argument
708 bool cphy = pll->bus_type == CCS_PLL_BUS_TYPE_CSI2_CPHY; in ccs_pll_calculate()
714 u32 l = (!pll->op_bits_per_lane || in ccs_pll_calculate()
715 pll->op_bits_per_lane >= pll->bits_per_pixel) ? 1 : 2; in ccs_pll_calculate()
719 if (!(pll->flags & CCS_PLL_FLAG_LANE_SPEED_MODEL)) { in ccs_pll_calculate()
720 pll->op_lanes = 1; in ccs_pll_calculate()
721 pll->vt_lanes = 1; in ccs_pll_calculate()
724 if (pll->flags & CCS_PLL_FLAG_DUAL_PLL) { in ccs_pll_calculate()
727 op_pll_fr = &pll->op_fr; in ccs_pll_calculate()
728 op_pll_bk = &pll->op_bk; in ccs_pll_calculate()
729 } else if (pll->flags & CCS_PLL_FLAG_NO_OP_CLOCKS) { in ccs_pll_calculate()
737 op_pll_fr = &pll->vt_fr; in ccs_pll_calculate()
738 op_pll_bk = &pll->vt_bk; in ccs_pll_calculate()
742 op_pll_fr = &pll->vt_fr; in ccs_pll_calculate()
743 op_pll_bk = &pll->op_bk; in ccs_pll_calculate()
746 if (!pll->op_lanes || !pll->vt_lanes || !pll->bits_per_pixel || in ccs_pll_calculate()
747 !pll->ext_clk_freq_hz || !pll->link_freq || !pll->scale_m || in ccs_pll_calculate()
759 if (!(pll->flags & CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV) && in ccs_pll_calculate()
760 (pll->bits_per_pixel * pll->op_lanes) % in ccs_pll_calculate()
761 (pll->csi2.lanes * l << op_pix_ddr(pll->flags))) { in ccs_pll_calculate()
763 pll->bits_per_pixel, pll->op_lanes, pll->csi2.lanes, l); in ccs_pll_calculate()
767 dev_dbg(dev, "vt_lanes: %u\n", pll->vt_lanes); in ccs_pll_calculate()
768 dev_dbg(dev, "op_lanes: %u\n", pll->op_lanes); in ccs_pll_calculate()
770 dev_dbg(dev, "binning: %ux%u\n", pll->binning_horizontal, in ccs_pll_calculate()
771 pll->binning_vertical); in ccs_pll_calculate()
773 switch (pll->bus_type) { in ccs_pll_calculate()
776 op_sys_clk_freq_hz_sdr = pll->link_freq * 2 in ccs_pll_calculate()
777 * (pll->flags & CCS_PLL_FLAG_LANE_SPEED_MODEL ? in ccs_pll_calculate()
778 1 : pll->csi2.lanes); in ccs_pll_calculate()
784 pll->pixel_rate_csi = in ccs_pll_calculate()
786 * (pll->flags & CCS_PLL_FLAG_LANE_SPEED_MODEL ? in ccs_pll_calculate()
787 pll->csi2.lanes : 1) * PHY_CONST_DIV, in ccs_pll_calculate()
788 phy_const * pll->bits_per_pixel * l); in ccs_pll_calculate()
795 clk_div_even(pll->ext_clk_freq_hz / in ccs_pll_calculate()
800 DIV_ROUND_UP(pll->ext_clk_freq_hz, in ccs_pll_calculate()
806 pll->ext_clk_freq_hz << op_pix_ddr(pll->flags)); in ccs_pll_calculate()
808 div = (pll->ext_clk_freq_hz << op_pix_ddr(pll->flags)) / i; in ccs_pll_calculate()
817 pll->ext_clk_freq_hz)))); in ccs_pll_calculate()
824 (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : in ccs_pll_calculate()
826 rval = ccs_pll_calculate_op(dev, lim, op_lim_fr, op_lim_bk, pll, in ccs_pll_calculate()
833 rval = check_fr_bounds(dev, lim, pll, in ccs_pll_calculate()
834 pll->flags & CCS_PLL_FLAG_DUAL_PLL ? in ccs_pll_calculate()
839 rval = check_bk_bounds(dev, lim, pll, PLL_OP); in ccs_pll_calculate()
843 if (pll->flags & CCS_PLL_FLAG_DUAL_PLL) in ccs_pll_calculate()
846 ccs_pll_calculate_vt(dev, lim, op_lim_bk, pll, op_pll_fr, in ccs_pll_calculate()
849 rval = check_bk_bounds(dev, lim, pll, PLL_VT); in ccs_pll_calculate()
852 rval = check_ext_bounds(dev, pll); in ccs_pll_calculate()
865 if (pll->flags & CCS_PLL_FLAG_DUAL_PLL) { in ccs_pll_calculate()
866 rval = ccs_pll_calculate_vt_tree(dev, lim, pll); in ccs_pll_calculate()
872 print_pll(dev, pll); in ccs_pll_calculate()