Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __SDE_ROTATOR_BASE_H__ |
| 14 | #define __SDE_ROTATOR_BASE_H__ |
| 15 | |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/file.h> |
| 18 | #include <linux/kref.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/regulator/consumer.h> |
| 21 | |
| 22 | #include "sde_rotator_hwio.h" |
| 23 | #include "sde_rotator_io_util.h" |
| 24 | #include "sde_rotator_smmu.h" |
| 25 | #include "sde_rotator_formats.h" |
| 26 | |
Alan Kwong | 8365a58 | 2016-12-28 10:22:42 -0800 | [diff] [blame] | 27 | /* HW Revisions for different targets */ |
| 28 | #define SDE_GET_MAJOR_REV(rev) ((rev) >> 28) |
| 29 | #define SDE_GET_MAJOR_MINOR(rev) ((rev) >> 16) |
| 30 | #define IS_SDE_MAJOR_MINOR_SAME(rev1, rev2) \ |
| 31 | (SDE_GET_MAJOR_MINOR(rev1) == SDE_GET_MAJOR_MINOR(rev2)) |
| 32 | |
| 33 | #define SDE_MDP_REV(major, minor, step) \ |
| 34 | ((((major) & 0x000F) << 28) | \ |
| 35 | (((minor) & 0x0FFF) << 16) | \ |
| 36 | ((step) & 0xFFFF)) |
| 37 | |
| 38 | #define SDE_MDP_HW_REV_107 SDE_MDP_REV(1, 0, 7) /* 8996 v1.0 */ |
| 39 | #define SDE_MDP_HW_REV_300 SDE_MDP_REV(3, 0, 0) /* 8998 v1.0 */ |
| 40 | #define SDE_MDP_HW_REV_301 SDE_MDP_REV(3, 0, 1) /* 8998 v1.1 */ |
| 41 | #define SDE_MDP_HW_REV_400 SDE_MDP_REV(4, 0, 0) /* sdm845 v1.0 */ |
Jayant Shekhar | 292e0a2 | 2017-09-12 15:23:24 +0530 | [diff] [blame^] | 42 | #define SDE_MDP_HW_REV_410 SDE_MDP_REV(4, 1, 0) /* sdm670 v1.0 */ |
Alan Kwong | 8365a58 | 2016-12-28 10:22:42 -0800 | [diff] [blame] | 43 | |
Veera Sundaram Sankaran | e15dd22 | 2017-04-20 08:13:08 -0700 | [diff] [blame] | 44 | #define SDE_MDP_VBIF_4_LEVEL_REMAPPER 4 |
| 45 | #define SDE_MDP_VBIF_8_LEVEL_REMAPPER 8 |
| 46 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 47 | struct sde_mult_factor { |
| 48 | uint32_t numer; |
| 49 | uint32_t denom; |
| 50 | }; |
| 51 | |
| 52 | struct sde_mdp_set_ot_params { |
| 53 | u32 xin_id; |
| 54 | u32 num; |
| 55 | u32 width; |
| 56 | u32 height; |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 57 | u32 fps; |
| 58 | u32 fmt; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 59 | u32 reg_off_vbif_lim_conf; |
| 60 | u32 reg_off_mdp_clk_ctrl; |
| 61 | u32 bit_off_mdp_clk_ctrl; |
Benjamin Chan | 1b94f95 | 2017-01-23 17:42:30 -0500 | [diff] [blame] | 62 | char __iomem *rotsts_base; |
| 63 | u32 rotsts_busy_mask; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | enum sde_bus_vote_type { |
| 67 | VOTE_INDEX_DISABLE, |
| 68 | VOTE_INDEX_19_MHZ, |
| 69 | VOTE_INDEX_40_MHZ, |
| 70 | VOTE_INDEX_80_MHZ, |
| 71 | VOTE_INDEX_MAX, |
| 72 | }; |
| 73 | |
| 74 | #define MAX_CLIENT_NAME_LEN 64 |
| 75 | |
| 76 | enum sde_qos_settings { |
| 77 | SDE_QOS_PER_PIPE_IB, |
| 78 | SDE_QOS_OVERHEAD_FACTOR, |
| 79 | SDE_QOS_CDP, |
| 80 | SDE_QOS_OTLIM, |
| 81 | SDE_QOS_PER_PIPE_LUT, |
| 82 | SDE_QOS_SIMPLIFIED_PREFILL, |
| 83 | SDE_QOS_VBLANK_PANIC_CTRL, |
Veera Sundaram Sankaran | f13fb32 | 2017-05-11 15:42:28 -0700 | [diff] [blame] | 84 | SDE_QOS_LUT, |
| 85 | SDE_QOS_DANGER_LUT, |
| 86 | SDE_QOS_SAFE_LUT, |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 87 | SDE_QOS_MAX, |
| 88 | }; |
| 89 | |
Veera Sundaram Sankaran | f13fb32 | 2017-05-11 15:42:28 -0700 | [diff] [blame] | 90 | enum sde_inline_qos_settings { |
| 91 | SDE_INLINE_QOS_LUT, |
| 92 | SDE_INLINE_QOS_DANGER_LUT, |
| 93 | SDE_INLINE_QOS_SAFE_LUT, |
| 94 | SDE_INLINE_QOS_MAX, |
| 95 | }; |
| 96 | |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 97 | /** |
| 98 | * enum sde_rot_type: SDE rotator HW version |
| 99 | * @SDE_ROT_TYPE_V1_0: V1.0 HW version |
| 100 | * @SDE_ROT_TYPE_V1_1: V1.1 HW version |
| 101 | */ |
| 102 | enum sde_rot_type { |
| 103 | SDE_ROT_TYPE_V1_0 = 0x10000000, |
| 104 | SDE_ROT_TYPE_V1_1 = 0x10010000, |
| 105 | SDE_ROT_TYPE_MAX, |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * enum sde_caps_settings: SDE rotator capability definition |
| 110 | * @SDE_CAPS_R1_WB: MDSS V1.x WB block |
| 111 | * @SDE_CAPS_R3_WB: MDSS V3.x WB block |
| 112 | * @SDE_CAPS_R3_1P5_DOWNSCALE: 1.5x downscale rotator support |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 113 | * @SDE_CAPS_SBUF_1: stream buffer support for inline rotation |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 114 | * @SDE_CAPS_UBWC_2: universal bandwidth compression version 2 |
Clarence Ip | 22fed4c | 2017-05-16 15:30:51 -0400 | [diff] [blame] | 115 | * @SDE_CAPS_PARTIALWR: partial write override |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 116 | */ |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 117 | enum sde_caps_settings { |
| 118 | SDE_CAPS_R1_WB, |
| 119 | SDE_CAPS_R3_WB, |
Benjamin Chan | fb6faa3 | 2016-08-16 17:21:01 -0400 | [diff] [blame] | 120 | SDE_CAPS_R3_1P5_DOWNSCALE, |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 121 | SDE_CAPS_SEC_ATTACH_DETACH_SMMU, |
Alan Kwong | 6bc6462 | 2017-02-04 17:36:03 -0800 | [diff] [blame] | 122 | SDE_CAPS_SBUF_1, |
Alan Kwong | fb8eeb2 | 2017-02-06 15:00:03 -0800 | [diff] [blame] | 123 | SDE_CAPS_UBWC_2, |
Clarence Ip | 22fed4c | 2017-05-16 15:30:51 -0400 | [diff] [blame] | 124 | SDE_CAPS_PARTIALWR, |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 125 | SDE_CAPS_MAX, |
| 126 | }; |
| 127 | |
| 128 | enum sde_bus_clients { |
| 129 | SDE_ROT_RT, |
| 130 | SDE_ROT_NRT, |
| 131 | SDE_MAX_BUS_CLIENTS |
| 132 | }; |
| 133 | |
Veera Sundaram Sankaran | 3f0141e | 2017-05-10 18:19:29 -0700 | [diff] [blame] | 134 | enum sde_rot_op { |
| 135 | SDE_ROT_RD, |
| 136 | SDE_ROT_WR, |
| 137 | SDE_ROT_OP_MAX |
| 138 | }; |
| 139 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 140 | enum sde_rot_regdump_access { |
| 141 | SDE_ROT_REGDUMP_READ, |
| 142 | SDE_ROT_REGDUMP_WRITE, |
Benjamin Chan | 59a0605 | 2017-01-12 18:06:03 -0500 | [diff] [blame] | 143 | SDE_ROT_REGDUMP_VBIF, |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 144 | SDE_ROT_REGDUMP_MAX |
| 145 | }; |
| 146 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 147 | struct reg_bus_client { |
| 148 | char name[MAX_CLIENT_NAME_LEN]; |
| 149 | short usecase_ndx; |
| 150 | u32 id; |
| 151 | struct list_head list; |
| 152 | }; |
| 153 | |
| 154 | struct sde_smmu_client { |
| 155 | struct device *dev; |
| 156 | struct dma_iommu_mapping *mmu_mapping; |
| 157 | struct sde_module_power mp; |
| 158 | struct reg_bus_client *reg_bus_clt; |
| 159 | bool domain_attached; |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 160 | int domain; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 163 | /* |
| 164 | * struct sde_rot_debug_bus: rotator debugbus header structure |
| 165 | * @wr_addr: write address for debugbus controller |
| 166 | * @block_id: rotator debugbus block id |
| 167 | * @test_id: rotator debugbus test id |
| 168 | */ |
| 169 | struct sde_rot_debug_bus { |
| 170 | u32 wr_addr; |
| 171 | u32 block_id; |
| 172 | u32 test_id; |
| 173 | }; |
| 174 | |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 175 | struct sde_rot_vbif_debug_bus { |
| 176 | u32 disable_bus_addr; |
| 177 | u32 block_bus_addr; |
| 178 | u32 bit_offset; |
| 179 | u32 block_cnt; |
| 180 | u32 test_pnt_cnt; |
| 181 | }; |
| 182 | |
| 183 | struct sde_rot_regdump { |
| 184 | char *name; |
| 185 | u32 offset; |
| 186 | u32 len; |
| 187 | enum sde_rot_regdump_access access; |
| 188 | }; |
| 189 | |
Veera Sundaram Sankaran | f13fb32 | 2017-05-11 15:42:28 -0700 | [diff] [blame] | 190 | struct sde_rot_lut_cfg { |
| 191 | u32 creq_lut_0; |
| 192 | u32 creq_lut_1; |
| 193 | u32 danger_lut; |
| 194 | u32 safe_lut; |
| 195 | }; |
| 196 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 197 | struct sde_rot_data_type { |
| 198 | u32 mdss_version; |
| 199 | |
| 200 | struct platform_device *pdev; |
| 201 | struct sde_io_data sde_io; |
| 202 | struct sde_io_data vbif_nrt_io; |
| 203 | char __iomem *mdp_base; |
| 204 | |
| 205 | struct sde_smmu_client sde_smmu[SDE_IOMMU_MAX_DOMAIN]; |
| 206 | |
| 207 | /* bitmap to track qos applicable settings */ |
| 208 | DECLARE_BITMAP(sde_qos_map, SDE_QOS_MAX); |
Veera Sundaram Sankaran | f13fb32 | 2017-05-11 15:42:28 -0700 | [diff] [blame] | 209 | DECLARE_BITMAP(sde_inline_qos_map, SDE_QOS_MAX); |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 210 | |
| 211 | /* bitmap to track capability settings */ |
| 212 | DECLARE_BITMAP(sde_caps_map, SDE_CAPS_MAX); |
| 213 | |
| 214 | u32 default_ot_rd_limit; |
| 215 | u32 default_ot_wr_limit; |
| 216 | u32 highest_bank_bit; |
| 217 | u32 rot_block_size; |
| 218 | |
| 219 | /* register bus (AHB) */ |
| 220 | u32 reg_bus_hdl; |
| 221 | u32 reg_bus_usecase_ndx; |
| 222 | struct list_head reg_bus_clist; |
| 223 | struct mutex reg_bus_lock; |
| 224 | |
| 225 | u32 *vbif_rt_qos; |
| 226 | u32 *vbif_nrt_qos; |
| 227 | u32 npriority_lvl; |
| 228 | |
Alan Kwong | 9bdbb08 | 2017-06-30 14:20:48 -0400 | [diff] [blame] | 229 | u32 vbif_memtype_count; |
| 230 | u32 *vbif_memtype; |
| 231 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 232 | int iommu_attached; |
| 233 | int iommu_ref_cnt; |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 234 | |
| 235 | struct sde_rot_vbif_debug_bus *nrt_vbif_dbg_bus; |
| 236 | u32 nrt_vbif_dbg_bus_size; |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 237 | struct sde_rot_debug_bus *rot_dbg_bus; |
| 238 | u32 rot_dbg_bus_size; |
Benjamin Chan | 53e3bce | 2016-08-31 14:43:29 -0400 | [diff] [blame] | 239 | |
| 240 | struct sde_rot_regdump *regdump; |
| 241 | u32 regdump_size; |
| 242 | |
| 243 | void *sde_rot_hw; |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 244 | int sec_cam_en; |
| 245 | |
Veera Sundaram Sankaran | 3f0141e | 2017-05-10 18:19:29 -0700 | [diff] [blame] | 246 | u32 enable_cdp[SDE_ROT_OP_MAX]; |
| 247 | |
Veera Sundaram Sankaran | f13fb32 | 2017-05-11 15:42:28 -0700 | [diff] [blame] | 248 | struct sde_rot_lut_cfg lut_cfg[SDE_ROT_OP_MAX]; |
| 249 | struct sde_rot_lut_cfg inline_lut_cfg[SDE_ROT_OP_MAX]; |
| 250 | |
Abhijit Kulkarni | 298c823 | 2016-09-26 22:32:10 -0700 | [diff] [blame] | 251 | struct ion_client *iclient; |
Benjamin Chan | 2d6411a | 2017-03-28 18:01:53 -0400 | [diff] [blame] | 252 | |
| 253 | bool clk_always_on; |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | int sde_rotator_base_init(struct sde_rot_data_type **pmdata, |
| 257 | struct platform_device *pdev, |
| 258 | const void *drvdata); |
| 259 | |
| 260 | void sde_rotator_base_destroy(struct sde_rot_data_type *data); |
| 261 | |
| 262 | struct sde_rot_data_type *sde_rot_get_mdata(void); |
| 263 | |
| 264 | struct reg_bus_client *sde_reg_bus_vote_client_create(char *client_name); |
| 265 | |
| 266 | void sde_reg_bus_vote_client_destroy(struct reg_bus_client *client); |
| 267 | |
| 268 | int sde_update_reg_bus_vote(struct reg_bus_client *bus_client, u32 usecase_ndx); |
| 269 | |
| 270 | u32 sde_apply_comp_ratio_factor(u32 quota, |
| 271 | struct sde_mdp_format_params *fmt, |
| 272 | struct sde_mult_factor *factor); |
| 273 | |
Alan Kwong | effb5ee | 2016-03-12 19:47:45 -0500 | [diff] [blame] | 274 | u32 sde_mdp_get_ot_limit(u32 width, u32 height, u32 pixfmt, u32 fps, u32 is_rd); |
| 275 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 276 | void sde_mdp_set_ot_limit(struct sde_mdp_set_ot_params *params); |
| 277 | |
Alan Kwong | 9bdbb08 | 2017-06-30 14:20:48 -0400 | [diff] [blame] | 278 | int sde_mdp_init_vbif(void); |
| 279 | |
Adrian Salido-Moreno | 5c15038 | 2016-04-06 09:29:37 -0700 | [diff] [blame] | 280 | #define SDE_VBIF_WRITE(mdata, offset, value) \ |
| 281 | (sde_reg_w(&mdata->vbif_nrt_io, offset, value, 0)) |
| 282 | #define SDE_VBIF_READ(mdata, offset) \ |
| 283 | (sde_reg_r(&mdata->vbif_nrt_io, offset, 0)) |
| 284 | #define SDE_REG_WRITE(mdata, offset, value) \ |
| 285 | sde_reg_w(&mdata->sde_io, offset, value, 0) |
| 286 | #define SDE_REG_READ(mdata, offset) \ |
| 287 | sde_reg_r(&mdata->sde_io, offset, 0) |
| 288 | |
| 289 | #define ATRACE_END(name) trace_rot_mark_write(current->tgid, name, 0) |
| 290 | #define ATRACE_BEGIN(name) trace_rot_mark_write(current->tgid, name, 1) |
| 291 | #define ATRACE_INT(name, value) \ |
| 292 | trace_rot_trace_counter(current->tgid, name, value) |
| 293 | |
| 294 | #endif /* __SDE_ROTATOR_BASE__ */ |