blob: c97c87da52fe451f99d49c82eba2a3b5237ef7b4 [file] [log] [blame]
Padmanabhan Komanduru56611ef2016-12-19 12:21:11 +05301/*
2 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#define pr_fmt(fmt) "dsi-phy-timing:" fmt
15#include "dsi_phy_timing_calc.h"
16
17void dsi_phy_hw_v3_0_get_default_phy_params(
18 struct phy_clk_params *params)
19{
20 params->clk_prep_buf = 0;
21 params->clk_zero_buf = 0;
22 params->clk_trail_buf = 0;
23 params->hs_prep_buf = 0;
24 params->hs_zero_buf = 0;
25 params->hs_trail_buf = 0;
26 params->hs_rqst_buf = 0;
27 params->hs_exit_buf = 0;
28}
29
30int32_t dsi_phy_hw_v3_0_calc_clk_zero(s64 rec_temp1, s64 mult)
31{
32 s64 rec_temp2, rec_temp3;
33
34 rec_temp2 = (rec_temp1 - mult);
35 rec_temp3 = roundup(div_s64(rec_temp2, 8), mult);
36 return (div_s64(rec_temp3, mult) - 1);
37}
38
39int32_t dsi_phy_hw_v3_0_calc_clk_trail_rec_min(s64 temp_mul,
40 s64 frac, s64 mult)
41{
42 s64 rec_temp1, rec_temp2, rec_temp3;
43
44 rec_temp1 = temp_mul + frac;
45 rec_temp2 = div_s64(rec_temp1, 8);
46 rec_temp3 = roundup(rec_temp2, mult);
47 return (div_s64(rec_temp3, mult) - 1);
48}
49
50int32_t dsi_phy_hw_v3_0_calc_clk_trail_rec_max(s64 temp1, s64 mult)
51{
52 s64 rec_temp2;
53
54 rec_temp2 = temp1 / 8;
55 return (div_s64(rec_temp2, mult) - 1);
56}
57
58int32_t dsi_phy_hw_v3_0_calc_hs_zero(s64 temp1, s64 mult)
59{
60 s64 rec_temp2, rec_min;
61
62 rec_temp2 = roundup((temp1 / 8), mult);
63 rec_min = rec_temp2 - (1 * mult);
64 return div_s64(rec_min, mult);
65}
66
67void dsi_phy_hw_v3_0_calc_hs_trail(struct phy_clk_params *clk_params,
68 struct phy_timing_desc *desc)
69{
70 s64 rec_temp1;
71 struct timing_entry *t = &desc->hs_trail;
72
73 t->rec_min = DIV_ROUND_UP(
74 (t->mipi_min * clk_params->bitclk_mbps),
75 (8 * clk_params->tlpx_numer_ns)) - 1;
76
77 rec_temp1 = (t->mipi_max * clk_params->bitclk_mbps);
78 t->rec_max =
79 (div_s64(rec_temp1, (8 * clk_params->tlpx_numer_ns))) - 1;
80}
81
82void dsi_phy_hw_v3_0_update_timing_params(
83 struct dsi_phy_per_lane_cfgs *timing,
84 struct phy_timing_desc *desc)
85{
86 timing->lane_v3[0] = 0x00;
87 timing->lane_v3[1] = desc->clk_zero.reg_value;
88 timing->lane_v3[2] = desc->clk_prepare.reg_value;
89 timing->lane_v3[3] = desc->clk_trail.reg_value;
90 timing->lane_v3[4] = desc->hs_exit.reg_value;
91 timing->lane_v3[5] = desc->hs_zero.reg_value;
92 timing->lane_v3[6] = desc->hs_prepare.reg_value;
93 timing->lane_v3[7] = desc->hs_trail.reg_value;
94 timing->lane_v3[8] = desc->hs_rqst.reg_value;
95 timing->lane_v3[9] = 0x03;
96 timing->lane_v3[10] = 0x04;
97 timing->lane_v3[11] = 0x00;
98
99 pr_debug("[%d %d %d %d]\n", timing->lane_v3[0],
100 timing->lane_v3[1], timing->lane_v3[2], timing->lane_v3[3]);
101 pr_debug("[%d %d %d %d]\n", timing->lane_v3[4],
102 timing->lane_v3[5], timing->lane_v3[6], timing->lane_v3[7]);
103 pr_debug("[%d %d %d %d]\n", timing->lane_v3[8],
104 timing->lane_v3[9], timing->lane_v3[10], timing->lane_v3[11]);
105 timing->count_per_lane = 12;
106}
107