| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) Icenowy Zheng <icenowy@aosc.io> |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (C) 2015 NextThing Co |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or |
|---|
| 11 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 12 | | - * published by the Free Software Foundation; either version 2 of |
|---|
| 13 | | - * the License, or (at your option) any later version. |
|---|
| 14 | 10 | */ |
|---|
| 15 | 11 | |
|---|
| 16 | 12 | #include <drm/drm_atomic.h> |
|---|
| 17 | 13 | #include <drm/drm_atomic_helper.h> |
|---|
| 18 | 14 | #include <drm/drm_crtc.h> |
|---|
| 19 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 20 | 15 | #include <drm/drm_fb_cma_helper.h> |
|---|
| 16 | +#include <drm/drm_fourcc.h> |
|---|
| 21 | 17 | #include <drm/drm_gem_cma_helper.h> |
|---|
| 18 | +#include <drm/drm_gem_framebuffer_helper.h> |
|---|
| 22 | 19 | #include <drm/drm_plane_helper.h> |
|---|
| 23 | | -#include <drm/drmP.h> |
|---|
| 20 | +#include <drm/drm_probe_helper.h> |
|---|
| 24 | 21 | |
|---|
| 25 | | -#include "sun8i_ui_layer.h" |
|---|
| 26 | 22 | #include "sun8i_mixer.h" |
|---|
| 23 | +#include "sun8i_ui_layer.h" |
|---|
| 27 | 24 | #include "sun8i_ui_scaler.h" |
|---|
| 28 | 25 | |
|---|
| 29 | 26 | static void sun8i_ui_layer_enable(struct sun8i_mixer *mixer, int channel, |
|---|
| 30 | 27 | int overlay, bool enable, unsigned int zpos, |
|---|
| 31 | 28 | unsigned int old_zpos) |
|---|
| 32 | 29 | { |
|---|
| 33 | | - u32 val; |
|---|
| 30 | + u32 val, bld_base, ch_base; |
|---|
| 31 | + |
|---|
| 32 | + bld_base = sun8i_blender_base(mixer); |
|---|
| 33 | + ch_base = sun8i_channel_base(mixer, channel); |
|---|
| 34 | 34 | |
|---|
| 35 | 35 | DRM_DEBUG_DRIVER("%sabling channel %d overlay %d\n", |
|---|
| 36 | 36 | enable ? "En" : "Dis", channel, overlay); |
|---|
| .. | .. |
|---|
| 41 | 41 | val = 0; |
|---|
| 42 | 42 | |
|---|
| 43 | 43 | regmap_update_bits(mixer->engine.regs, |
|---|
| 44 | | - SUN8I_MIXER_CHAN_UI_LAYER_ATTR(channel, overlay), |
|---|
| 44 | + SUN8I_MIXER_CHAN_UI_LAYER_ATTR(ch_base, overlay), |
|---|
| 45 | 45 | SUN8I_MIXER_CHAN_UI_LAYER_ATTR_EN, val); |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | if (!enable || zpos != old_zpos) { |
|---|
| 48 | 48 | regmap_update_bits(mixer->engine.regs, |
|---|
| 49 | | - SUN8I_MIXER_BLEND_PIPE_CTL, |
|---|
| 49 | + SUN8I_MIXER_BLEND_PIPE_CTL(bld_base), |
|---|
| 50 | 50 | SUN8I_MIXER_BLEND_PIPE_CTL_EN(old_zpos), |
|---|
| 51 | 51 | 0); |
|---|
| 52 | 52 | |
|---|
| 53 | 53 | regmap_update_bits(mixer->engine.regs, |
|---|
| 54 | | - SUN8I_MIXER_BLEND_ROUTE, |
|---|
| 54 | + SUN8I_MIXER_BLEND_ROUTE(bld_base), |
|---|
| 55 | 55 | SUN8I_MIXER_BLEND_ROUTE_PIPE_MSK(old_zpos), |
|---|
| 56 | 56 | 0); |
|---|
| 57 | 57 | } |
|---|
| .. | .. |
|---|
| 60 | 60 | val = SUN8I_MIXER_BLEND_PIPE_CTL_EN(zpos); |
|---|
| 61 | 61 | |
|---|
| 62 | 62 | regmap_update_bits(mixer->engine.regs, |
|---|
| 63 | | - SUN8I_MIXER_BLEND_PIPE_CTL, val, val); |
|---|
| 63 | + SUN8I_MIXER_BLEND_PIPE_CTL(bld_base), |
|---|
| 64 | + val, val); |
|---|
| 64 | 65 | |
|---|
| 65 | 66 | val = channel << SUN8I_MIXER_BLEND_ROUTE_PIPE_SHIFT(zpos); |
|---|
| 66 | 67 | |
|---|
| 67 | 68 | regmap_update_bits(mixer->engine.regs, |
|---|
| 68 | | - SUN8I_MIXER_BLEND_ROUTE, |
|---|
| 69 | + SUN8I_MIXER_BLEND_ROUTE(bld_base), |
|---|
| 69 | 70 | SUN8I_MIXER_BLEND_ROUTE_PIPE_MSK(zpos), |
|---|
| 70 | 71 | val); |
|---|
| 71 | 72 | } |
|---|
| .. | .. |
|---|
| 77 | 78 | { |
|---|
| 78 | 79 | struct drm_plane_state *state = plane->state; |
|---|
| 79 | 80 | u32 src_w, src_h, dst_w, dst_h; |
|---|
| 81 | + u32 bld_base, ch_base; |
|---|
| 80 | 82 | u32 outsize, insize; |
|---|
| 81 | 83 | u32 hphase, vphase; |
|---|
| 82 | 84 | |
|---|
| 83 | 85 | DRM_DEBUG_DRIVER("Updating UI channel %d overlay %d\n", |
|---|
| 84 | 86 | channel, overlay); |
|---|
| 87 | + |
|---|
| 88 | + bld_base = sun8i_blender_base(mixer); |
|---|
| 89 | + ch_base = sun8i_channel_base(mixer, channel); |
|---|
| 85 | 90 | |
|---|
| 86 | 91 | src_w = drm_rect_width(&state->src) >> 16; |
|---|
| 87 | 92 | src_h = drm_rect_height(&state->src) >> 16; |
|---|
| .. | .. |
|---|
| 103 | 108 | regmap_write(mixer->engine.regs, |
|---|
| 104 | 109 | SUN8I_MIXER_GLOBAL_SIZE, |
|---|
| 105 | 110 | outsize); |
|---|
| 106 | | - regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_OUTSIZE, |
|---|
| 107 | | - outsize); |
|---|
| 111 | + regmap_write(mixer->engine.regs, |
|---|
| 112 | + SUN8I_MIXER_BLEND_OUTSIZE(bld_base), outsize); |
|---|
| 108 | 113 | |
|---|
| 109 | 114 | if (state->crtc) |
|---|
| 110 | 115 | interlaced = state->crtc->state->adjusted_mode.flags |
|---|
| .. | .. |
|---|
| 116 | 121 | val = 0; |
|---|
| 117 | 122 | |
|---|
| 118 | 123 | regmap_update_bits(mixer->engine.regs, |
|---|
| 119 | | - SUN8I_MIXER_BLEND_OUTCTL, |
|---|
| 124 | + SUN8I_MIXER_BLEND_OUTCTL(bld_base), |
|---|
| 120 | 125 | SUN8I_MIXER_BLEND_OUTCTL_INTERLACED, |
|---|
| 121 | 126 | val); |
|---|
| 122 | 127 | |
|---|
| .. | .. |
|---|
| 129 | 134 | state->src.x1 >> 16, state->src.y1 >> 16); |
|---|
| 130 | 135 | DRM_DEBUG_DRIVER("Layer source size W: %d H: %d\n", src_w, src_h); |
|---|
| 131 | 136 | regmap_write(mixer->engine.regs, |
|---|
| 132 | | - SUN8I_MIXER_CHAN_UI_LAYER_SIZE(channel, overlay), |
|---|
| 137 | + SUN8I_MIXER_CHAN_UI_LAYER_SIZE(ch_base, overlay), |
|---|
| 133 | 138 | insize); |
|---|
| 134 | 139 | regmap_write(mixer->engine.regs, |
|---|
| 135 | | - SUN8I_MIXER_CHAN_UI_OVL_SIZE(channel), |
|---|
| 140 | + SUN8I_MIXER_CHAN_UI_OVL_SIZE(ch_base), |
|---|
| 136 | 141 | insize); |
|---|
| 137 | 142 | |
|---|
| 138 | 143 | if (insize != outsize || hphase || vphase) { |
|---|
| .. | .. |
|---|
| 156 | 161 | state->dst.x1, state->dst.y1); |
|---|
| 157 | 162 | DRM_DEBUG_DRIVER("Layer destination size W: %d H: %d\n", dst_w, dst_h); |
|---|
| 158 | 163 | regmap_write(mixer->engine.regs, |
|---|
| 159 | | - SUN8I_MIXER_BLEND_ATTR_COORD(zpos), |
|---|
| 164 | + SUN8I_MIXER_BLEND_ATTR_COORD(bld_base, zpos), |
|---|
| 160 | 165 | SUN8I_MIXER_COORD(state->dst.x1, state->dst.y1)); |
|---|
| 161 | 166 | regmap_write(mixer->engine.regs, |
|---|
| 162 | | - SUN8I_MIXER_BLEND_ATTR_INSIZE(zpos), |
|---|
| 167 | + SUN8I_MIXER_BLEND_ATTR_INSIZE(bld_base, zpos), |
|---|
| 163 | 168 | outsize); |
|---|
| 164 | 169 | |
|---|
| 165 | 170 | return 0; |
|---|
| .. | .. |
|---|
| 169 | 174 | int overlay, struct drm_plane *plane) |
|---|
| 170 | 175 | { |
|---|
| 171 | 176 | struct drm_plane_state *state = plane->state; |
|---|
| 172 | | - const struct de2_fmt_info *fmt_info; |
|---|
| 173 | | - u32 val; |
|---|
| 177 | + const struct drm_format_info *fmt; |
|---|
| 178 | + u32 val, ch_base, hw_fmt; |
|---|
| 179 | + int ret; |
|---|
| 174 | 180 | |
|---|
| 175 | | - fmt_info = sun8i_mixer_format_info(state->fb->format->format); |
|---|
| 176 | | - if (!fmt_info || !fmt_info->rgb) { |
|---|
| 181 | + ch_base = sun8i_channel_base(mixer, channel); |
|---|
| 182 | + |
|---|
| 183 | + fmt = state->fb->format; |
|---|
| 184 | + ret = sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt); |
|---|
| 185 | + if (ret || fmt->is_yuv) { |
|---|
| 177 | 186 | DRM_DEBUG_DRIVER("Invalid format\n"); |
|---|
| 178 | 187 | return -EINVAL; |
|---|
| 179 | 188 | } |
|---|
| 180 | 189 | |
|---|
| 181 | | - val = fmt_info->de2_fmt << SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_OFFSET; |
|---|
| 190 | + val = hw_fmt << SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_OFFSET; |
|---|
| 182 | 191 | regmap_update_bits(mixer->engine.regs, |
|---|
| 183 | | - SUN8I_MIXER_CHAN_UI_LAYER_ATTR(channel, overlay), |
|---|
| 192 | + SUN8I_MIXER_CHAN_UI_LAYER_ATTR(ch_base, overlay), |
|---|
| 184 | 193 | SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_MASK, val); |
|---|
| 185 | 194 | |
|---|
| 186 | 195 | return 0; |
|---|
| .. | .. |
|---|
| 193 | 202 | struct drm_framebuffer *fb = state->fb; |
|---|
| 194 | 203 | struct drm_gem_cma_object *gem; |
|---|
| 195 | 204 | dma_addr_t paddr; |
|---|
| 205 | + u32 ch_base; |
|---|
| 196 | 206 | int bpp; |
|---|
| 207 | + |
|---|
| 208 | + ch_base = sun8i_channel_base(mixer, channel); |
|---|
| 197 | 209 | |
|---|
| 198 | 210 | /* Get the physical address of the buffer in memory */ |
|---|
| 199 | 211 | gem = drm_fb_cma_get_gem_obj(fb, 0); |
|---|
| .. | .. |
|---|
| 211 | 223 | /* Set the line width */ |
|---|
| 212 | 224 | DRM_DEBUG_DRIVER("Layer line width: %d bytes\n", fb->pitches[0]); |
|---|
| 213 | 225 | regmap_write(mixer->engine.regs, |
|---|
| 214 | | - SUN8I_MIXER_CHAN_UI_LAYER_PITCH(channel, overlay), |
|---|
| 226 | + SUN8I_MIXER_CHAN_UI_LAYER_PITCH(ch_base, overlay), |
|---|
| 215 | 227 | fb->pitches[0]); |
|---|
| 216 | 228 | |
|---|
| 217 | 229 | DRM_DEBUG_DRIVER("Setting buffer address to %pad\n", &paddr); |
|---|
| 218 | 230 | |
|---|
| 219 | 231 | regmap_write(mixer->engine.regs, |
|---|
| 220 | | - SUN8I_MIXER_CHAN_UI_LAYER_TOP_LADDR(channel, overlay), |
|---|
| 232 | + SUN8I_MIXER_CHAN_UI_LAYER_TOP_LADDR(ch_base, overlay), |
|---|
| 221 | 233 | lower_32_bits(paddr)); |
|---|
| 222 | 234 | |
|---|
| 223 | 235 | return 0; |
|---|
| .. | .. |
|---|
| 286 | 298 | true, zpos, old_zpos); |
|---|
| 287 | 299 | } |
|---|
| 288 | 300 | |
|---|
| 289 | | -static struct drm_plane_helper_funcs sun8i_ui_layer_helper_funcs = { |
|---|
| 301 | +static const struct drm_plane_helper_funcs sun8i_ui_layer_helper_funcs = { |
|---|
| 302 | + .prepare_fb = drm_gem_fb_prepare_fb, |
|---|
| 290 | 303 | .atomic_check = sun8i_ui_layer_atomic_check, |
|---|
| 291 | 304 | .atomic_disable = sun8i_ui_layer_atomic_disable, |
|---|
| 292 | 305 | .atomic_update = sun8i_ui_layer_atomic_update, |
|---|