sde_rotator_base.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_ROTATOR_BASE_H__
  6. #define __SDE_ROTATOR_BASE_H__
  7. #include <linux/types.h>
  8. #include <linux/file.h>
  9. #include <linux/kref.h>
  10. #include <linux/kernel.h>
  11. #include <linux/regulator/consumer.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/interconnect.h>
  15. #include "sde_rotator_hwio.h"
  16. #include "sde_rotator_io_util.h"
  17. #include "sde_rotator_smmu.h"
  18. #include "sde_rotator_formats.h"
  19. #include <linux/pm_qos.h>
  20. /* HW Revisions for different targets */
  21. #define SDE_GET_MAJOR_REV(rev) ((rev) >> 28)
  22. #define SDE_GET_MAJOR_MINOR(rev) ((rev) >> 16)
  23. #define IS_SDE_MAJOR_SAME(rev1, rev2) \
  24. (SDE_GET_MAJOR_REV((rev1)) == SDE_GET_MAJOR_REV((rev2)))
  25. #define IS_SDE_MAJOR_MINOR_SAME(rev1, rev2) \
  26. (SDE_GET_MAJOR_MINOR(rev1) == SDE_GET_MAJOR_MINOR(rev2))
  27. #define SDE_MDP_REV(major, minor, step) \
  28. ((((major) & 0x000F) << 28) | \
  29. (((minor) & 0x0FFF) << 16) | \
  30. ((step) & 0xFFFF))
  31. #define SDE_MDP_HW_REV_107 SDE_MDP_REV(1, 0, 7) /* 8996 v1.0 */
  32. #define SDE_MDP_HW_REV_300 SDE_MDP_REV(3, 0, 0) /* 8998 v1.0 */
  33. #define SDE_MDP_HW_REV_301 SDE_MDP_REV(3, 0, 1) /* 8998 v1.1 */
  34. #define SDE_MDP_HW_REV_400 SDE_MDP_REV(4, 0, 0) /* sdm845 v1.0 */
  35. #define SDE_MDP_HW_REV_410 SDE_MDP_REV(4, 1, 0) /* sdm670 v1.0 */
  36. #define SDE_MDP_HW_REV_500 SDE_MDP_REV(5, 0, 0) /* sm8150 v1.0 */
  37. #define SDE_MDP_HW_REV_520 SDE_MDP_REV(5, 2, 0) /* sdmmagpie v1.0 */
  38. #define SDE_MDP_HW_REV_530 SDE_MDP_REV(5, 3, 0) /* sm6150 v1.0 */
  39. #define SDE_MDP_HW_REV_540 SDE_MDP_REV(5, 4, 0) /* sdmtrinket v1.0 */
  40. #define SDE_MDP_HW_REV_600 SDE_MDP_REV(6, 0, 0) /* msmnile+ v1.0 */
  41. #define SDE_MDP_HW_REV_630 SDE_MDP_REV(6, 3, 0) /* bengal v1.0 */
  42. #define SDE_MDP_VBIF_4_LEVEL_REMAPPER 4
  43. #define SDE_MDP_VBIF_8_LEVEL_REMAPPER 8
  44. /* XIN mapping */
  45. #define XIN_SSPP 0
  46. #define XIN_WRITEBACK 1
  47. #define MAX_XIN 2
  48. struct sde_mult_factor {
  49. uint32_t numer;
  50. uint32_t denom;
  51. };
  52. struct sde_mdp_set_ot_params {
  53. u32 xin_id;
  54. u32 num;
  55. u32 width;
  56. u32 height;
  57. u32 fps;
  58. u32 fmt;
  59. u32 reg_off_vbif_lim_conf;
  60. u32 reg_off_mdp_clk_ctrl;
  61. u32 bit_off_mdp_clk_ctrl;
  62. char __iomem *rotsts_base;
  63. u32 rotsts_busy_mask;
  64. };
  65. /*
  66. * struct sde_mdp_vbif_halt_params: parameters for issue halt request to vbif
  67. * @xin_id: xin port number of vbif
  68. * @reg_off_mdp_clk_ctrl: reg offset for vbif clock control
  69. * @bit_off_mdp_clk_ctrl: bit offset for vbif clock control
  70. * @xin_timeout: bit position indicates timeout on corresponding xin id
  71. */
  72. struct sde_mdp_vbif_halt_params {
  73. u32 xin_id;
  74. u32 reg_off_mdp_clk_ctrl;
  75. u32 bit_off_mdp_clk_ctrl;
  76. u32 xin_timeout;
  77. };
  78. enum sde_bus_vote_type {
  79. VOTE_INDEX_DISABLE,
  80. VOTE_INDEX_76_MHZ,
  81. VOTE_INDEX_150_MHZ,
  82. VOTE_INDEX_300_MHZ,
  83. VOTE_INDEX_MAX,
  84. };
  85. #define MAX_CLIENT_NAME_LEN 64
  86. enum sde_qos_settings {
  87. SDE_QOS_PER_PIPE_IB,
  88. SDE_QOS_OVERHEAD_FACTOR,
  89. SDE_QOS_CDP,
  90. SDE_QOS_OTLIM,
  91. SDE_QOS_PER_PIPE_LUT,
  92. SDE_QOS_SIMPLIFIED_PREFILL,
  93. SDE_QOS_VBLANK_PANIC_CTRL,
  94. SDE_QOS_LUT,
  95. SDE_QOS_DANGER_LUT,
  96. SDE_QOS_SAFE_LUT,
  97. SDE_QOS_MAX,
  98. };
  99. enum sde_inline_qos_settings {
  100. SDE_INLINE_QOS_LUT,
  101. SDE_INLINE_QOS_DANGER_LUT,
  102. SDE_INLINE_QOS_SAFE_LUT,
  103. SDE_INLINE_QOS_MAX,
  104. };
  105. /**
  106. * enum sde_rot_type: SDE rotator HW version
  107. * @SDE_ROT_TYPE_V1_0: V1.0 HW version
  108. * @SDE_ROT_TYPE_V1_1: V1.1 HW version
  109. */
  110. enum sde_rot_type {
  111. SDE_ROT_TYPE_V1_0 = 0x10000000,
  112. SDE_ROT_TYPE_V1_1 = 0x10010000,
  113. SDE_ROT_TYPE_MAX,
  114. };
  115. /**
  116. * enum sde_caps_settings: SDE rotator capability definition
  117. * @SDE_CAPS_R1_WB: MDSS V1.x WB block
  118. * @SDE_CAPS_R3_WB: MDSS V3.x WB block
  119. * @SDE_CAPS_R3_1P5_DOWNSCALE: 1.5x downscale rotator support
  120. * @SDE_CAPS_SBUF_1: stream buffer support for inline rotation
  121. * @SDE_CAPS_UBWC_2: universal bandwidth compression version 2
  122. * @SDE_CAPS_PARTIALWR: partial write override
  123. * @SDE_CAPS_HW_TIMESTAMP: rotator has hw timestamp support
  124. * @SDE_CAPS_UBWC_3: universal bandwidth compression version 3
  125. * @SDE_CAPS_UBWC_4: universal bandwidth compression version 4
  126. */
  127. enum sde_caps_settings {
  128. SDE_CAPS_R1_WB,
  129. SDE_CAPS_R3_WB,
  130. SDE_CAPS_R3_1P5_DOWNSCALE,
  131. SDE_CAPS_SEC_ATTACH_DETACH_SMMU,
  132. SDE_CAPS_SBUF_1,
  133. SDE_CAPS_UBWC_2,
  134. SDE_CAPS_PARTIALWR,
  135. SDE_CAPS_HW_TIMESTAMP,
  136. SDE_CAPS_UBWC_3,
  137. SDE_CAPS_UBWC_4,
  138. SDE_CAPS_MAX,
  139. };
  140. enum sde_bus_clients {
  141. SDE_ROT_RT,
  142. SDE_ROT_NRT,
  143. SDE_MAX_BUS_CLIENTS
  144. };
  145. enum sde_rot_op {
  146. SDE_ROT_RD,
  147. SDE_ROT_WR,
  148. SDE_ROT_OP_MAX
  149. };
  150. enum sde_rot_regdump_access {
  151. SDE_ROT_REGDUMP_READ,
  152. SDE_ROT_REGDUMP_WRITE,
  153. SDE_ROT_REGDUMP_VBIF,
  154. SDE_ROT_REGDUMP_MAX
  155. };
  156. struct reg_bus_client {
  157. char name[MAX_CLIENT_NAME_LEN];
  158. short usecase_ndx;
  159. u32 id;
  160. struct list_head list;
  161. };
  162. struct sde_smmu_client {
  163. struct device *dev;
  164. struct iommu_domain *rot_domain;
  165. struct sde_module_power mp;
  166. struct reg_bus_client *reg_bus_clt;
  167. bool domain_attached;
  168. int domain;
  169. u32 sid;
  170. };
  171. /*
  172. * struct sde_rot_bus_data: struct for bus setting
  173. * @ab: average bandwidth in kilobytes per second
  174. * @ib: peak bandwidth in kilobytes per second
  175. */
  176. struct sde_rot_bus_data {
  177. uint64_t ab; /* Arbitrated bandwidth */
  178. uint64_t ib; /* Instantaneous bandwidth */
  179. };
  180. /*
  181. * struct sde_rot_debug_bus: rotator debugbus header structure
  182. * @wr_addr: write address for debugbus controller
  183. * @block_id: rotator debugbus block id
  184. * @test_id: rotator debugbus test id
  185. */
  186. struct sde_rot_debug_bus {
  187. u32 wr_addr;
  188. u32 block_id;
  189. u32 test_id;
  190. };
  191. struct sde_rot_vbif_debug_bus {
  192. u32 disable_bus_addr;
  193. u32 block_bus_addr;
  194. u32 bit_offset;
  195. u32 block_cnt;
  196. u32 test_pnt_cnt;
  197. };
  198. struct sde_rot_regdump {
  199. char *name;
  200. u32 offset;
  201. u32 len;
  202. enum sde_rot_regdump_access access;
  203. u32 value;
  204. };
  205. struct sde_rot_lut_cfg {
  206. u32 creq_lut_0;
  207. u32 creq_lut_1;
  208. u32 danger_lut;
  209. u32 safe_lut;
  210. };
  211. struct sde_rot_data_type {
  212. u32 mdss_version;
  213. struct platform_device *pdev;
  214. struct platform_device *parent_pdev;
  215. struct sde_io_data sde_io;
  216. struct sde_io_data vbif_nrt_io;
  217. char __iomem *mdp_base;
  218. struct sde_smmu_client sde_smmu[SDE_IOMMU_MAX_DOMAIN];
  219. /* bitmap to track qos applicable settings */
  220. DECLARE_BITMAP(sde_qos_map, SDE_QOS_MAX);
  221. DECLARE_BITMAP(sde_inline_qos_map, SDE_QOS_MAX);
  222. /* bitmap to track capability settings */
  223. DECLARE_BITMAP(sde_caps_map, SDE_CAPS_MAX);
  224. u32 default_ot_rd_limit;
  225. u32 default_ot_wr_limit;
  226. u32 highest_bank_bit;
  227. u32 rot_block_size;
  228. /* register bus (AHB) */
  229. struct icc_path *reg_bus_hdl;
  230. u32 reg_bus_usecase_ndx;
  231. struct list_head reg_bus_clist;
  232. struct mutex reg_bus_lock;
  233. u32 *vbif_rt_qos;
  234. u32 *vbif_nrt_qos;
  235. u32 npriority_lvl;
  236. u32 vbif_xin_id[MAX_XIN];
  237. struct pm_qos_request pm_qos_rot_cpu_req;
  238. u32 rot_pm_qos_cpu_count;
  239. u32 rot_pm_qos_cpu_mask;
  240. u32 rot_pm_qos_cpu_dma_latency;
  241. u32 vbif_memtype_count;
  242. u32 *vbif_memtype;
  243. int iommu_attached;
  244. int iommu_ref_cnt;
  245. struct sde_rot_vbif_debug_bus *nrt_vbif_dbg_bus;
  246. u32 nrt_vbif_dbg_bus_size;
  247. struct sde_rot_debug_bus *rot_dbg_bus;
  248. u32 rot_dbg_bus_size;
  249. struct sde_rot_regdump *regdump;
  250. u32 regdump_size;
  251. void *sde_rot_hw;
  252. int sec_cam_en;
  253. u32 enable_cdp[SDE_ROT_OP_MAX];
  254. struct sde_rot_lut_cfg lut_cfg[SDE_ROT_OP_MAX];
  255. struct sde_rot_lut_cfg inline_lut_cfg[SDE_ROT_OP_MAX];
  256. bool clk_always_on;
  257. };
  258. int sde_rotator_base_init(struct sde_rot_data_type **pmdata,
  259. struct platform_device *pdev,
  260. const void *drvdata);
  261. void sde_rotator_base_destroy(struct sde_rot_data_type *data);
  262. struct sde_rot_data_type *sde_rot_get_mdata(void);
  263. struct reg_bus_client *sde_reg_bus_vote_client_create(char *client_name);
  264. void sde_reg_bus_vote_client_destroy(struct reg_bus_client *client);
  265. int sde_update_reg_bus_vote(struct reg_bus_client *bus_client, u32 usecase_ndx);
  266. u32 sde_apply_comp_ratio_factor(u32 quota,
  267. struct sde_mdp_format_params *fmt,
  268. struct sde_mult_factor *factor);
  269. u32 sde_mdp_get_ot_limit(u32 width, u32 height, u32 pixfmt, u32 fps, u32 is_rd);
  270. void sde_mdp_set_ot_limit(struct sde_mdp_set_ot_params *params);
  271. void vbif_lock(struct platform_device *parent_pdev);
  272. void vbif_unlock(struct platform_device *parent_pdev);
  273. void sde_mdp_halt_vbif_xin(struct sde_mdp_vbif_halt_params *params);
  274. int sde_mdp_init_vbif(void);
  275. const struct sde_rot_bus_data *sde_get_rot_reg_bus_value(u32 usecase_ndx);
  276. #define SDE_VBIF_WRITE(mdata, offset, value) \
  277. (sde_reg_w(&mdata->vbif_nrt_io, offset, value, 0))
  278. #define SDE_VBIF_READ(mdata, offset) \
  279. (sde_reg_r(&mdata->vbif_nrt_io, offset, 0))
  280. #define SDE_REG_WRITE(mdata, offset, value) \
  281. sde_reg_w(&mdata->sde_io, offset, value, 0)
  282. #define SDE_REG_READ(mdata, offset) \
  283. sde_reg_r(&mdata->sde_io, offset, 0)
  284. #define ATRACE_END(name) trace_rot_mark_write(current->tgid, name, 0)
  285. #define ATRACE_BEGIN(name) trace_rot_mark_write(current->tgid, name, 1)
  286. #define ATRACE_INT(name, value) \
  287. trace_rot_trace_counter(current->tgid, name, value)
  288. #endif /* __SDE_ROTATOR_BASE__ */