| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. |
|---|
| 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 | 3 | */ |
|---|
| 12 | 4 | |
|---|
| 13 | 5 | #include "dpu_hwio.h" |
|---|
| 14 | 6 | #include "dpu_hw_catalog.h" |
|---|
| 15 | 7 | #include "dpu_hw_intf.h" |
|---|
| 16 | | -#include "dpu_dbg.h" |
|---|
| 17 | 8 | #include "dpu_kms.h" |
|---|
| 18 | 9 | |
|---|
| 19 | 10 | #define INTF_TIMING_ENGINE_EN 0x000 |
|---|
| .. | .. |
|---|
| 60 | 51 | #define INTF_TPG_RGB_MAPPING 0x11C |
|---|
| 61 | 52 | #define INTF_PROG_FETCH_START 0x170 |
|---|
| 62 | 53 | #define INTF_PROG_ROT_START 0x174 |
|---|
| 54 | +#define INTF_MUX 0x25C |
|---|
| 63 | 55 | |
|---|
| 64 | | -#define INTF_FRAME_LINE_COUNT_EN 0x0A8 |
|---|
| 65 | | -#define INTF_FRAME_COUNT 0x0AC |
|---|
| 66 | | -#define INTF_LINE_COUNT 0x0B0 |
|---|
| 67 | | - |
|---|
| 68 | | -#define INTF_MISR_CTRL 0x180 |
|---|
| 69 | | -#define INTF_MISR_SIGNATURE 0x184 |
|---|
| 70 | | - |
|---|
| 71 | | -static struct dpu_intf_cfg *_intf_offset(enum dpu_intf intf, |
|---|
| 72 | | - struct dpu_mdss_cfg *m, |
|---|
| 56 | +static const struct dpu_intf_cfg *_intf_offset(enum dpu_intf intf, |
|---|
| 57 | + const struct dpu_mdss_cfg *m, |
|---|
| 73 | 58 | void __iomem *addr, |
|---|
| 74 | 59 | struct dpu_hw_blk_reg_map *b) |
|---|
| 75 | 60 | { |
|---|
| .. | .. |
|---|
| 117 | 102 | display_v_end = ((vsync_period - p->v_front_porch) * hsync_period) + |
|---|
| 118 | 103 | p->hsync_skew - 1; |
|---|
| 119 | 104 | |
|---|
| 120 | | - if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP) { |
|---|
| 121 | | - display_v_start += p->hsync_pulse_width + p->h_back_porch; |
|---|
| 122 | | - display_v_end -= p->h_front_porch; |
|---|
| 123 | | - } |
|---|
| 124 | | - |
|---|
| 125 | 105 | hsync_start_x = p->h_back_porch + p->hsync_pulse_width; |
|---|
| 126 | 106 | hsync_end_x = hsync_period - p->h_front_porch - 1; |
|---|
| 127 | 107 | |
|---|
| .. | .. |
|---|
| 154 | 134 | hsync_ctl = (hsync_period << 16) | p->hsync_pulse_width; |
|---|
| 155 | 135 | display_hctl = (hsync_end_x << 16) | hsync_start_x; |
|---|
| 156 | 136 | |
|---|
| 137 | + if (ctx->cap->type == INTF_EDP || ctx->cap->type == INTF_DP) { |
|---|
| 138 | + active_h_start = hsync_start_x; |
|---|
| 139 | + active_h_end = active_h_start + p->xres - 1; |
|---|
| 140 | + active_v_start = display_v_start; |
|---|
| 141 | + active_v_end = active_v_start + (p->yres * hsync_period) - 1; |
|---|
| 142 | + |
|---|
| 143 | + display_v_start += p->hsync_pulse_width + p->h_back_porch; |
|---|
| 144 | + display_v_end -= p->h_front_porch; |
|---|
| 145 | + |
|---|
| 146 | + active_hctl = (active_h_end << 16) | active_h_start; |
|---|
| 147 | + display_hctl = active_hctl; |
|---|
| 148 | + } |
|---|
| 149 | + |
|---|
| 157 | 150 | den_polarity = 0; |
|---|
| 158 | 151 | if (ctx->cap->type == INTF_HDMI) { |
|---|
| 159 | 152 | hsync_polarity = p->yres >= 720 ? 0 : 1; |
|---|
| 160 | 153 | vsync_polarity = p->yres >= 720 ? 0 : 1; |
|---|
| 154 | + } else if (ctx->cap->type == INTF_DP) { |
|---|
| 155 | + hsync_polarity = p->hsync_polarity; |
|---|
| 156 | + vsync_polarity = p->vsync_polarity; |
|---|
| 161 | 157 | } else { |
|---|
| 162 | 158 | hsync_polarity = 0; |
|---|
| 163 | 159 | vsync_polarity = 0; |
|---|
| .. | .. |
|---|
| 230 | 226 | DPU_REG_WRITE(c, INTF_CONFIG, fetch_enable); |
|---|
| 231 | 227 | } |
|---|
| 232 | 228 | |
|---|
| 229 | +static void dpu_hw_intf_bind_pingpong_blk( |
|---|
| 230 | + struct dpu_hw_intf *intf, |
|---|
| 231 | + bool enable, |
|---|
| 232 | + const enum dpu_pingpong pp) |
|---|
| 233 | +{ |
|---|
| 234 | + struct dpu_hw_blk_reg_map *c = &intf->hw; |
|---|
| 235 | + u32 mux_cfg; |
|---|
| 236 | + |
|---|
| 237 | + mux_cfg = DPU_REG_READ(c, INTF_MUX); |
|---|
| 238 | + mux_cfg &= ~0xf; |
|---|
| 239 | + |
|---|
| 240 | + if (enable) |
|---|
| 241 | + mux_cfg |= (pp - PINGPONG_0) & 0x7; |
|---|
| 242 | + else |
|---|
| 243 | + mux_cfg |= 0xf; |
|---|
| 244 | + |
|---|
| 245 | + DPU_REG_WRITE(c, INTF_MUX, mux_cfg); |
|---|
| 246 | +} |
|---|
| 247 | + |
|---|
| 233 | 248 | static void dpu_hw_intf_get_status( |
|---|
| 234 | 249 | struct dpu_hw_intf *intf, |
|---|
| 235 | 250 | struct intf_status *s) |
|---|
| .. | .. |
|---|
| 244 | 259 | s->line_count = 0; |
|---|
| 245 | 260 | s->frame_count = 0; |
|---|
| 246 | 261 | } |
|---|
| 247 | | -} |
|---|
| 248 | | - |
|---|
| 249 | | -static void dpu_hw_intf_setup_misr(struct dpu_hw_intf *intf, |
|---|
| 250 | | - bool enable, u32 frame_count) |
|---|
| 251 | | -{ |
|---|
| 252 | | - struct dpu_hw_blk_reg_map *c = &intf->hw; |
|---|
| 253 | | - u32 config = 0; |
|---|
| 254 | | - |
|---|
| 255 | | - DPU_REG_WRITE(c, INTF_MISR_CTRL, MISR_CTRL_STATUS_CLEAR); |
|---|
| 256 | | - /* clear misr data */ |
|---|
| 257 | | - wmb(); |
|---|
| 258 | | - |
|---|
| 259 | | - if (enable) |
|---|
| 260 | | - config = (frame_count & MISR_FRAME_COUNT_MASK) | |
|---|
| 261 | | - MISR_CTRL_ENABLE | INTF_MISR_CTRL_FREE_RUN_MASK; |
|---|
| 262 | | - |
|---|
| 263 | | - DPU_REG_WRITE(c, INTF_MISR_CTRL, config); |
|---|
| 264 | | -} |
|---|
| 265 | | - |
|---|
| 266 | | -static u32 dpu_hw_intf_collect_misr(struct dpu_hw_intf *intf) |
|---|
| 267 | | -{ |
|---|
| 268 | | - struct dpu_hw_blk_reg_map *c = &intf->hw; |
|---|
| 269 | | - |
|---|
| 270 | | - return DPU_REG_READ(c, INTF_MISR_SIGNATURE); |
|---|
| 271 | 262 | } |
|---|
| 272 | 263 | |
|---|
| 273 | 264 | static u32 dpu_hw_intf_get_line_count(struct dpu_hw_intf *intf) |
|---|
| .. | .. |
|---|
| 289 | 280 | ops->setup_prg_fetch = dpu_hw_intf_setup_prg_fetch; |
|---|
| 290 | 281 | ops->get_status = dpu_hw_intf_get_status; |
|---|
| 291 | 282 | ops->enable_timing = dpu_hw_intf_enable_timing_engine; |
|---|
| 292 | | - ops->setup_misr = dpu_hw_intf_setup_misr; |
|---|
| 293 | | - ops->collect_misr = dpu_hw_intf_collect_misr; |
|---|
| 294 | 283 | ops->get_line_count = dpu_hw_intf_get_line_count; |
|---|
| 284 | + if (cap & BIT(DPU_INTF_INPUT_CTRL)) |
|---|
| 285 | + ops->bind_pingpong_blk = dpu_hw_intf_bind_pingpong_blk; |
|---|
| 295 | 286 | } |
|---|
| 296 | 287 | |
|---|
| 297 | | -static struct dpu_hw_blk_ops dpu_hw_ops = { |
|---|
| 298 | | - .start = NULL, |
|---|
| 299 | | - .stop = NULL, |
|---|
| 300 | | -}; |
|---|
| 288 | +static struct dpu_hw_blk_ops dpu_hw_ops; |
|---|
| 301 | 289 | |
|---|
| 302 | 290 | struct dpu_hw_intf *dpu_hw_intf_init(enum dpu_intf idx, |
|---|
| 303 | 291 | void __iomem *addr, |
|---|
| 304 | | - struct dpu_mdss_cfg *m) |
|---|
| 292 | + const struct dpu_mdss_cfg *m) |
|---|
| 305 | 293 | { |
|---|
| 306 | 294 | struct dpu_hw_intf *c; |
|---|
| 307 | | - struct dpu_intf_cfg *cfg; |
|---|
| 308 | | - int rc; |
|---|
| 295 | + const struct dpu_intf_cfg *cfg; |
|---|
| 309 | 296 | |
|---|
| 310 | 297 | c = kzalloc(sizeof(*c), GFP_KERNEL); |
|---|
| 311 | 298 | if (!c) |
|---|
| .. | .. |
|---|
| 326 | 313 | c->mdss = m; |
|---|
| 327 | 314 | _setup_intf_ops(&c->ops, c->cap->features); |
|---|
| 328 | 315 | |
|---|
| 329 | | - rc = dpu_hw_blk_init(&c->base, DPU_HW_BLK_INTF, idx, &dpu_hw_ops); |
|---|
| 330 | | - if (rc) { |
|---|
| 331 | | - DPU_ERROR("failed to init hw blk %d\n", rc); |
|---|
| 332 | | - goto blk_init_error; |
|---|
| 333 | | - } |
|---|
| 316 | + dpu_hw_blk_init(&c->base, DPU_HW_BLK_INTF, idx, &dpu_hw_ops); |
|---|
| 334 | 317 | |
|---|
| 335 | 318 | return c; |
|---|
| 336 | | - |
|---|
| 337 | | -blk_init_error: |
|---|
| 338 | | - kzfree(c); |
|---|
| 339 | | - |
|---|
| 340 | | - return ERR_PTR(rc); |
|---|
| 341 | 319 | } |
|---|
| 342 | 320 | |
|---|
| 343 | 321 | void dpu_hw_intf_destroy(struct dpu_hw_intf *intf) |
|---|