| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/mmio.h> |
| 5 |
#include <edid.h> |
| 6 |
#include <soc/addressmap.h> |
| 7 |
#include <soc/ddp.h> |
| 8 |
|
| 9 |
#define SIZE(w, h) ((u32)(h) << 16 | (w)) |
| 10 |
|
| 11 |
static void blender_config(struct blender *reg, u16 width, u16 height, |
| 12 |
enum mtk_disp_blender_layer type) |
| 13 |
{ |
| 14 |
setbits32(®->shadow_ctl, BIT(2)); |
| 15 |
|
| 16 |
switch (type) { |
| 17 |
case FIRST_BLENDER: |
| 18 |
clrsetbits32(®->datapath_con, BIT(4) | BIT(5), BIT(5)); |
| 19 |
break; |
| 20 |
case LAST_BLENDER: |
| 21 |
clrsetbits32(®->datapath_con, BIT(0) | BIT(4) | BIT(5), BIT(0) | BIT(4)); |
| 22 |
break; |
| 23 |
case SINGLE_BLENDER: |
| 24 |
clrsetbits32(®->datapath_con, BIT(4) | BIT(5), BIT(4)); |
| 25 |
break; |
| 26 |
case OTHER_BLENDER: |
| 27 |
clrsetbits32(®->datapath_con, BIT(0) | BIT(4) | BIT(5), BIT(0) | BIT(5)); |
| 28 |
break; |
| 29 |
default: |
| 30 |
printk(BIOS_ERR, "%s: unknown blender type %d\n", __func__, type); |
| 31 |
break; |
| 32 |
} |
| 33 |
|
| 34 |
write32(®->roi_size, SIZE(width, height)); |
| 35 |
write32(®->bld_l_size, SIZE(width, height)); |
| 36 |
write32(®->bg_clr, 0xFF000000); |
| 37 |
} |
| 38 |
|
| 39 |
static void blender_start(struct blender *reg) |
| 40 |
{ |
| 41 |
setbits32(®->bld_en, BIT(0)); |
| 42 |
} |
| 43 |
|
| 44 |
static void outproc_config(struct outproc *reg, u16 width, u16 height) |
| 45 |
{ |
| 46 |
setbits32(®->shadow_ctl, BIT(2)); |
| 47 |
setbits32(®->datapath_con, BIT(26)); |
| 48 |
write32(®->roi_size, SIZE(width, height)); |
| 49 |
} |
| 50 |
|
| 51 |
static void outproc_start(struct outproc *reg) |
| 52 |
{ |
| 53 |
setbits32(®->outproc_en, BIT(0)); |
| 54 |
} |
| 55 |
|
| 56 |
static void mdp_rsz_config(struct disp_mdp_rsz_regs *reg, u16 width, u16 height) |
| 57 |
{ |
| 58 |
write32(®->input_size, SIZE(width, height)); |
| 59 |
write32(®->output_size, SIZE(width, height)); |
| 60 |
} |
| 61 |
|
| 62 |
static void mdp_rsz_start(struct disp_mdp_rsz_regs *reg) |
| 63 |
{ |
| 64 |
clrbits32(®->en, BIT(0)); |
| 65 |
} |
| 66 |
|
| 67 |
static void postmask_config(struct disp_postmask_regs *reg, u16 width, u16 height) |
| 68 |
{ |
| 69 |
write32(®->size, SIZE(width, height)); |
| 70 |
setbits32(®->cfg, BIT(0)); |
| 71 |
} |
| 72 |
|
| 73 |
static void postmask_start(struct disp_postmask_regs *reg) |
| 74 |
{ |
| 75 |
setbits32(®->en, BIT(0)); |
| 76 |
} |
| 77 |
|
| 78 |
static void tdshp_config(struct disp_tdshp_regs *reg, u16 width, u16 height) |
| 79 |
{ |
| 80 |
write32(®->input_size, SIZE(width, height)); |
| 81 |
write32(®->output_size, SIZE(width, height)); |
| 82 |
write32(®->output_offset, 0x0); |
| 83 |
write32(®->cfg, 0x1); |
| 84 |
setbits32(®->tdshp_00, BIT(31)); |
| 85 |
} |
| 86 |
|
| 87 |
static void tdshp_start(struct disp_tdshp_regs *reg) |
| 88 |
{ |
| 89 |
setbits32(®->ctrl, BIT(0)); |
| 90 |
} |
| 91 |
|
| 92 |
static void ccorr_config(struct disp_ccorr_regs *reg, u16 width, u16 height) |
| 93 |
{ |
| 94 |
write32(®->size, SIZE(width, height)); |
| 95 |
setbits32(®->cfg, BIT(1)); |
| 96 |
} |
| 97 |
|
| 98 |
static void ccorr_start(struct disp_ccorr_regs *reg) |
| 99 |
{ |
| 100 |
setbits32(®->en, BIT(0)); |
| 101 |
} |
| 102 |
|
| 103 |
static void gamma_config(struct disp_gamma_regs *reg, u16 width, u16 height) |
| 104 |
{ |
| 105 |
write32(®->size, SIZE(width, height)); |
| 106 |
} |
| 107 |
|
| 108 |
static void gamma_start(struct disp_gamma_regs *reg) |
| 109 |
{ |
| 110 |
setbits32(®->en, BIT(0)); |
| 111 |
} |
| 112 |
|
| 113 |
static void dither_config(struct disp_dither_regs *reg, u16 width, u16 height) |
| 114 |
{ |
| 115 |
write32(®->size, SIZE(width, height)); |
| 116 |
setbits32(®->cfg, BIT(0)); |
| 117 |
} |
| 118 |
|
| 119 |
static void dither_start(struct disp_dither_regs *reg) |
| 120 |
{ |
| 121 |
setbits32(®->en, BIT(0)); |
| 122 |
} |
| 123 |
|
| 124 |
static void disp_config_main_path_connection(enum disp_path_sel path) |
| 125 |
{ |
| 126 |
|
| 127 |
setbits32(&ovlsys_cfg->bypass_mux_shadow, BIT(0)); |
| 128 |
write32(&ovlsys_cfg->cb_con, 0xFF << 16); |
| 129 |
setbits32(&ovlsys_cfg->rsz_in_cb2, BIT(1)); |
| 130 |
setbits32(&ovlsys_cfg->exdma_out_cb3, BIT(2)); |
| 131 |
setbits32(&ovlsys_cfg->blender_out_cb4, BIT(0)); |
| 132 |
setbits32(&ovlsys_cfg->outproc_out_cb0, BIT(0)); |
| 133 |
|
| 134 |
|
| 135 |
write32(&mmsys_cfg->bypass_mux_shadow, 0xFF << 16 | BIT(0)); |
| 136 |
setbits32(&mmsys_cfg->pq_in_cb0, BIT(0)); |
| 137 |
setbits32(&mmsys_cfg->disp_mdp_rsz0_mout, BIT(0)); |
| 138 |
write32(&mmsys_cfg->disp_tdshp0_sout, 0x2); |
| 139 |
write32(&mmsys_cfg->disp_ccorr0_sel, 0x2); |
| 140 |
write32(&mmsys_cfg->disp_ccorr0_sout, 0x1); |
| 141 |
write32(&mmsys_cfg->disp_ccorr1_sel, 0x1); |
| 142 |
write32(&mmsys_cfg->disp_ccorr1_sout, 0x1); |
| 143 |
write32(&mmsys_cfg->disp_gamma0_sel, 0x1); |
| 144 |
write32(&mmsys_cfg->disp_postmask_sout, 0x0); |
| 145 |
setbits32(&mmsys_cfg->pq_out_cb0, BIT(1)); |
| 146 |
setbits32(&mmsys_cfg->panel_comp_out_cb1, BIT(1)); |
| 147 |
|
| 148 |
|
| 149 |
write32(&mmsys1_cfg->bypass_mux_shadow, 0xFF << 16 | BIT(0)); |
| 150 |
setbits32(&mmsys1_cfg->splitter_in_cb1, BIT(5)); |
| 151 |
setbits32(&mmsys1_cfg->splitter_out_cb9, BIT(10)); |
| 152 |
setbits32(&mmsys1_cfg->comp_out_cb6, BIT(0)); |
| 153 |
if (path == DISP_PATH_EDP) |
| 154 |
setbits32(&mmsys1_cfg->merge_out_cb0, BIT(9)); |
| 155 |
else |
| 156 |
setbits32(&mmsys1_cfg->merge_out_cb0, BIT(0)); |
| 157 |
} |
| 158 |
|
| 159 |
static void async_config(u16 width, u16 height) |
| 160 |
{ |
| 161 |
write32(&ovlsys_cfg->relay5_size, SIZE(width, height)); |
| 162 |
write32(&mmsys_cfg->dl_in_relay0, BIT(30) | SIZE(width, height)); |
| 163 |
write32(&mmsys_cfg->dl_out_relay1, BIT(30) | SIZE(width, height)); |
| 164 |
write32(&mmsys1_cfg->dl_in_relay21, BIT(30) | SIZE(width, height)); |
| 165 |
} |
| 166 |
|
| 167 |
static void disp_config_main_path_mutex(enum disp_path_sel path) |
| 168 |
{ |
| 169 |
u32 val; |
| 170 |
|
| 171 |
|
| 172 |
write32(&mmsys_mutex[OVL0]->mutex[0].mod, MUTEX_MOD_OVL_MAIN_PATH); |
| 173 |
write32(&mmsys_mutex[OVL0]->mutex[0].mod1, MUTEX_MOD1_OVL_MAIN_PATH); |
| 174 |
|
| 175 |
|
| 176 |
write32(&mmsys_mutex[DISP0]->mutex[0].mod, MUTEX_MOD_DISP_MAIN_PATH); |
| 177 |
write32(&mmsys_mutex[DISP0]->mutex[0].mod1, MUTEX_MOD1_DISP_MAIN_PATH); |
| 178 |
|
| 179 |
|
| 180 |
if (path == DISP_PATH_EDP) |
| 181 |
write32(&mmsys_mutex[DISP1]->mutex[0].mod, MUTEX_MOD_DISP1_MAIN_PATH_EDP); |
| 182 |
else |
| 183 |
write32(&mmsys_mutex[DISP1]->mutex[0].mod, MUTEX_MOD_DISP1_MAIN_PATH_DSI0); |
| 184 |
|
| 185 |
|
| 186 |
if (path == DISP_PATH_EDP) |
| 187 |
val = MUTEX_SOF_DVO | (MUTEX_SOF_DVO << 7); |
| 188 |
else |
| 189 |
val = MUTEX_SOF_DSI0 | (MUTEX_SOF_DSI0 << 7); |
| 190 |
write32(&mmsys_mutex[OVL0]->mutex[0].ctl, val); |
| 191 |
write32(&mmsys_mutex[DISP0]->mutex[0].ctl, val); |
| 192 |
write32(&mmsys_mutex[DISP1]->mutex[0].ctl, val); |
| 193 |
|
| 194 |
|
| 195 |
write32(&mmsys_mutex[OVL0]->mutex[0].en, BIT(0)); |
| 196 |
write32(&mmsys_mutex[DISP0]->mutex[0].en, BIT(0)); |
| 197 |
write32(&mmsys_mutex[DISP1]->mutex[0].en, BIT(0)); |
| 198 |
} |
| 199 |
|
| 200 |
static void main_disp_path_setup(u16 width, u16 height, u32 vrefresh, enum disp_path_sel path) |
| 201 |
{ |
| 202 |
int i; |
| 203 |
enum mtk_disp_blender_layer blender_type[ARRAY_SIZE(blenders)] = { |
| 204 |
FIRST_BLENDER, |
| 205 |
OTHER_BLENDER, |
| 206 |
OTHER_BLENDER, |
| 207 |
LAST_BLENDER, |
| 208 |
}; |
| 209 |
|
| 210 |
|
| 211 |
for (i = 0; i < ARRAY_SIZE(blenders); i++) { |
| 212 |
blender_config(blenders[i], width, height, blender_type[i]); |
| 213 |
blender_start(blenders[i]); |
| 214 |
} |
| 215 |
|
| 216 |
outproc_config(outproc0_reg, width, height); |
| 217 |
outproc_start(outproc0_reg); |
| 218 |
|
| 219 |
|
| 220 |
mdp_rsz_config(disp_mdp_rsz0_reg, width, height); |
| 221 |
mdp_rsz_start(disp_mdp_rsz0_reg); |
| 222 |
tdshp_config(disp_tdshp0_reg, width, height); |
| 223 |
tdshp_start(disp_tdshp0_reg); |
| 224 |
ccorr_config(disp_ccorr0_reg, width, height); |
| 225 |
ccorr_start(disp_ccorr0_reg); |
| 226 |
ccorr_config(disp_ccorr1_reg, width, height); |
| 227 |
ccorr_start(disp_ccorr1_reg); |
| 228 |
gamma_config(disp_gamma0_reg, width, height); |
| 229 |
gamma_start(disp_gamma0_reg); |
| 230 |
postmask_config(disp_postmask0_reg, width, height); |
| 231 |
postmask_start(disp_postmask0_reg); |
| 232 |
dither_config(disp_dither0_reg, width, height); |
| 233 |
dither_start(disp_dither0_reg); |
| 234 |
|
| 235 |
|
| 236 |
async_config(width, height); |
| 237 |
|
| 238 |
|
| 239 |
disp_config_main_path_connection(path); |
| 240 |
|
| 241 |
|
| 242 |
disp_config_main_path_mutex(path); |
| 243 |
} |
| 244 |
|
| 245 |
static void disp_clock_on(void) |
| 246 |
{ |
| 247 |
clrbits32(&mmsys_cfg->mmsys_cg_con0, CG_CON_ALL); |
| 248 |
clrbits32(&mmsys_cfg->mmsys_cg_con1, CG_CON_ALL); |
| 249 |
clrbits32(&mmsys_cfg->mmsys_cg_con2, CG_CON_ALL); |
| 250 |
clrbits32(&mmsys1_cfg->mmsys_cg_con0, CG_CON_ALL); |
| 251 |
clrbits32(&mmsys1_cfg->mmsys_cg_con1, CG_CON_ALL); |
| 252 |
clrbits32(&mmsys1_cfg->mmsys_cg_con2, CG_CON_ALL); |
| 253 |
clrbits32(&ovlsys_cfg->mmsys_cg_con0, CG_CON_ALL); |
| 254 |
clrbits32(&ovlsys_cfg->mmsys_cg_con1, CG_CON_ALL); |
| 255 |
clrbits32(&ovlsys_cfg->mmsys_cg_con2, CG_CON_ALL); |
| 256 |
} |
| 257 |
|
| 258 |
static void ovlsys_layer_config(u32 fmt, u32 bpp, u16 width, u16 height) |
| 259 |
{ |
| 260 |
|
| 261 |
write32(&exdma2_reg->roi_size, SIZE(width, height)); |
| 262 |
write32(&exdma2_reg->ovl_l_size, SIZE(width, height)); |
| 263 |
write32(&exdma2_reg->pitch, (width * bpp) & 0xFFFF); |
| 264 |
write32(&exdma2_reg->ovl_l_clrfmt, fmt); |
| 265 |
|
| 266 |
|
| 267 |
clrsetbits32(&exdma2_reg->rdma_burst_ctl, BIT(28) | BIT(30) | BIT(31), |
| 268 |
BIT(28) | BIT(31)); |
| 269 |
setbits32(&exdma2_reg->dummy, BIT(2) | BIT(3)); |
| 270 |
setbits32(&exdma2_reg->datapath_con, BIT(0) | BIT(24) | BIT(25)); |
| 271 |
clrsetbits32(&exdma2_reg->ovl_mout, BIT(0) | BIT(1), BIT(1)); |
| 272 |
write32(&exdma2_reg->gdrdy_period, 0xFFFFFFFF); |
| 273 |
|
| 274 |
|
| 275 |
setbits32(&exdma2_reg->rdma0_ctl, BIT(0)); |
| 276 |
setbits32(&blenders[0]->bld_l_fmt, fmt); |
| 277 |
} |
| 278 |
|
| 279 |
void mtk_ddp_init(void) |
| 280 |
{ |
| 281 |
disp_clock_on(); |
| 282 |
} |
| 283 |
|
| 284 |
void mtk_ddp_mode_set(const struct edid *edid, enum disp_path_sel path) |
| 285 |
{ |
| 286 |
u32 fmt = OVL_INFMT_RGBA8888; |
| 287 |
u32 bpp = edid->framebuffer_bits_per_pixel / 8; |
| 288 |
u32 width = edid->mode.ha; |
| 289 |
u32 height = edid->mode.va; |
| 290 |
u32 vrefresh = edid->mode.refresh; |
| 291 |
|
| 292 |
printk(BIOS_DEBUG, "%s: display resolution: %ux%u@%u bpp %u\n", __func__, width, height, |
| 293 |
vrefresh, bpp); |
| 294 |
|
| 295 |
if (!vrefresh) { |
| 296 |
if (!width || !height) |
| 297 |
vrefresh = 60; |
| 298 |
else |
| 299 |
vrefresh = edid->mode.pixel_clock * 1000 / |
| 300 |
((width + edid->mode.hbl) * (height + edid->mode.vbl)); |
| 301 |
|
| 302 |
printk(BIOS_WARNING, "%s: vrefresh is not provided; using %u\n", __func__, |
| 303 |
vrefresh); |
| 304 |
} |
| 305 |
|
| 306 |
if (width > 0x1FFF || height > 0x1FFF) |
| 307 |
printk(BIOS_WARNING, "%s: w/h: %d/%d exceed hw limit %u\n", __func__, |
| 308 |
width, height, 0x1FFF); |
| 309 |
|
| 310 |
main_disp_path_setup(width, height, vrefresh, path); |
| 311 |
ovlsys_layer_config(fmt, bpp, width, height); |
| 312 |
} |