dsi_phy_timing_calc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DSI_PHY_TIMING_CALC_H_
  6. #define _DSI_PHY_TIMING_CALC_H_
  7. #include <linux/math64.h>
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/slab.h>
  11. #include <linux/bitops.h>
  12. #include <linux/bitmap.h>
  13. #include <linux/errno.h>
  14. #include "dsi_defs.h"
  15. #include "dsi_phy_hw.h"
  16. #include "dsi_catalog.h"
  17. /**
  18. * struct timing_entry - Calculated values for each timing parameter.
  19. * @mipi_min:
  20. * @mipi_max:
  21. * @rec_min:
  22. * @rec_max:
  23. * @rec:
  24. * @reg_value: Value to be programmed in register.
  25. */
  26. struct timing_entry {
  27. s32 mipi_min;
  28. s32 mipi_max;
  29. s32 rec_min;
  30. s32 rec_max;
  31. s32 rec;
  32. u8 reg_value;
  33. };
  34. /**
  35. * struct phy_timing_desc - Timing parameters for DSI PHY.
  36. */
  37. struct phy_timing_desc {
  38. struct timing_entry clk_prepare;
  39. struct timing_entry clk_zero;
  40. struct timing_entry clk_trail;
  41. struct timing_entry hs_prepare;
  42. struct timing_entry hs_zero;
  43. struct timing_entry hs_trail;
  44. struct timing_entry hs_rqst;
  45. struct timing_entry hs_rqst_clk;
  46. struct timing_entry hs_exit;
  47. struct timing_entry ta_go;
  48. struct timing_entry ta_sure;
  49. struct timing_entry ta_set;
  50. struct timing_entry clk_post;
  51. struct timing_entry clk_pre;
  52. };
  53. /**
  54. * struct phy_clk_params - Clock parameters for PHY timing calculations.
  55. */
  56. struct phy_clk_params {
  57. u32 bitclk_mbps;
  58. u32 escclk_numer;
  59. u32 escclk_denom;
  60. u32 tlpx_numer_ns;
  61. u32 treot_ns;
  62. u32 clk_prep_buf;
  63. u32 clk_zero_buf;
  64. u32 clk_trail_buf;
  65. u32 hs_prep_buf;
  66. u32 hs_zero_buf;
  67. u32 hs_trail_buf;
  68. u32 hs_rqst_buf;
  69. u32 hs_exit_buf;
  70. u32 clk_pre_buf;
  71. u32 clk_post_buf;
  72. };
  73. /**
  74. * Various Ops needed for auto-calculation of DSI PHY timing parameters.
  75. */
  76. struct phy_timing_ops {
  77. void (*get_default_phy_params)(struct phy_clk_params *params,
  78. u32 phy_type);
  79. int32_t (*calc_clk_zero)(s64 rec_temp1, s64 mult);
  80. int32_t (*calc_clk_trail_rec_min)(s64 temp_mul,
  81. s64 frac, s64 mult);
  82. int32_t (*calc_clk_trail_rec_max)(s64 temp1, s64 mult);
  83. int32_t (*calc_hs_zero)(s64 temp1, s64 mult);
  84. void (*calc_hs_trail)(struct phy_clk_params *clk_params,
  85. struct phy_timing_desc *desc);
  86. void (*update_timing_params)(struct dsi_phy_per_lane_cfgs *timing,
  87. struct phy_timing_desc *desc, u32 phy_type);
  88. };
  89. #define roundup64(x, y) \
  90. ({ u64 _tmp = (x)+(y)-1; do_div(_tmp, y); _tmp * y; })
  91. /* DSI PHY timing functions for 14nm */
  92. void dsi_phy_hw_v2_0_get_default_phy_params(struct phy_clk_params *params,
  93. u32 phy_type);
  94. int32_t dsi_phy_hw_v2_0_calc_clk_zero(s64 rec_temp1, s64 mult);
  95. int32_t dsi_phy_hw_v2_0_calc_clk_trail_rec_min(s64 temp_mul,
  96. s64 frac, s64 mult);
  97. int32_t dsi_phy_hw_v2_0_calc_clk_trail_rec_max(s64 temp1, s64 mult);
  98. int32_t dsi_phy_hw_v2_0_calc_hs_zero(s64 temp1, s64 mult);
  99. void dsi_phy_hw_v2_0_calc_hs_trail(struct phy_clk_params *clk_params,
  100. struct phy_timing_desc *desc);
  101. void dsi_phy_hw_v2_0_update_timing_params(struct dsi_phy_per_lane_cfgs *timing,
  102. struct phy_timing_desc *desc, u32 phy_type);
  103. /* DSI PHY timing functions for 10nm */
  104. void dsi_phy_hw_v3_0_get_default_phy_params(struct phy_clk_params *params,
  105. u32 phy_type);
  106. int32_t dsi_phy_hw_v3_0_calc_clk_zero(s64 rec_temp1, s64 mult);
  107. int32_t dsi_phy_hw_v3_0_calc_clk_trail_rec_min(s64 temp_mul,
  108. s64 frac, s64 mult);
  109. int32_t dsi_phy_hw_v3_0_calc_clk_trail_rec_max(s64 temp1, s64 mult);
  110. int32_t dsi_phy_hw_v3_0_calc_hs_zero(s64 temp1, s64 mult);
  111. void dsi_phy_hw_v3_0_calc_hs_trail(struct phy_clk_params *clk_params,
  112. struct phy_timing_desc *desc);
  113. void dsi_phy_hw_v3_0_update_timing_params(struct dsi_phy_per_lane_cfgs *timing,
  114. struct phy_timing_desc *desc, u32 phy_type);
  115. /* DSI PHY timing functions for 7nm */
  116. void dsi_phy_hw_v4_0_get_default_phy_params(struct phy_clk_params *params,
  117. u32 phy_type);
  118. int32_t dsi_phy_hw_v4_0_calc_clk_zero(s64 rec_temp1, s64 mult);
  119. int32_t dsi_phy_hw_v4_0_calc_clk_trail_rec_min(s64 temp_mul,
  120. s64 frac, s64 mult);
  121. int32_t dsi_phy_hw_v4_0_calc_clk_trail_rec_max(s64 temp1, s64 mult);
  122. int32_t dsi_phy_hw_v4_0_calc_hs_zero(s64 temp1, s64 mult);
  123. void dsi_phy_hw_v4_0_calc_hs_trail(struct phy_clk_params *clk_params,
  124. struct phy_timing_desc *desc);
  125. void dsi_phy_hw_v4_0_update_timing_params(struct dsi_phy_per_lane_cfgs *timing,
  126. struct phy_timing_desc *desc, u32 phy_type);
  127. #endif /* _DSI_PHY_TIMING_CALC_H_ */