| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ARC PGU DRM driver. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com) |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | #include <drm/drm_atomic_helper.h> |
|---|
| 18 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 9 | +#include <drm/drm_device.h> |
|---|
| 19 | 10 | #include <drm/drm_fb_cma_helper.h> |
|---|
| 20 | 11 | #include <drm/drm_gem_cma_helper.h> |
|---|
| 21 | 12 | #include <drm/drm_plane_helper.h> |
|---|
| 13 | +#include <drm/drm_probe_helper.h> |
|---|
| 22 | 14 | #include <linux/clk.h> |
|---|
| 23 | 15 | #include <linux/platform_data/simplefb.h> |
|---|
| 24 | 16 | |
|---|
| .. | .. |
|---|
| 27 | 19 | |
|---|
| 28 | 20 | #define ENCODE_PGU_XY(x, y) ((((x) - 1) << 16) | ((y) - 1)) |
|---|
| 29 | 21 | |
|---|
| 30 | | -static struct simplefb_format supported_formats[] = { |
|---|
| 31 | | - { "r5g6b5", 16, {11, 5}, {5, 6}, {0, 5}, {0, 0}, DRM_FORMAT_RGB565 }, |
|---|
| 32 | | - { "r8g8b8", 24, {16, 8}, {8, 8}, {0, 8}, {0, 0}, DRM_FORMAT_RGB888 }, |
|---|
| 22 | +static const u32 arc_pgu_supported_formats[] = { |
|---|
| 23 | + DRM_FORMAT_RGB565, |
|---|
| 24 | + DRM_FORMAT_XRGB8888, |
|---|
| 25 | + DRM_FORMAT_ARGB8888, |
|---|
| 33 | 26 | }; |
|---|
| 34 | 27 | |
|---|
| 35 | 28 | static void arc_pgu_set_pxl_fmt(struct drm_crtc *crtc) |
|---|
| .. | .. |
|---|
| 37 | 30 | struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc); |
|---|
| 38 | 31 | const struct drm_framebuffer *fb = crtc->primary->state->fb; |
|---|
| 39 | 32 | uint32_t pixel_format = fb->format->format; |
|---|
| 40 | | - struct simplefb_format *format = NULL; |
|---|
| 33 | + u32 format = DRM_FORMAT_INVALID; |
|---|
| 41 | 34 | int i; |
|---|
| 35 | + u32 reg_ctrl; |
|---|
| 42 | 36 | |
|---|
| 43 | | - for (i = 0; i < ARRAY_SIZE(supported_formats); i++) { |
|---|
| 44 | | - if (supported_formats[i].fourcc == pixel_format) |
|---|
| 45 | | - format = &supported_formats[i]; |
|---|
| 37 | + for (i = 0; i < ARRAY_SIZE(arc_pgu_supported_formats); i++) { |
|---|
| 38 | + if (arc_pgu_supported_formats[i] == pixel_format) |
|---|
| 39 | + format = arc_pgu_supported_formats[i]; |
|---|
| 46 | 40 | } |
|---|
| 47 | 41 | |
|---|
| 48 | | - if (WARN_ON(!format)) |
|---|
| 42 | + if (WARN_ON(format == DRM_FORMAT_INVALID)) |
|---|
| 49 | 43 | return; |
|---|
| 50 | 44 | |
|---|
| 51 | | - if (format->fourcc == DRM_FORMAT_RGB888) |
|---|
| 52 | | - arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, |
|---|
| 53 | | - arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) | |
|---|
| 54 | | - ARCPGU_MODE_RGB888_MASK); |
|---|
| 55 | | - |
|---|
| 45 | + reg_ctrl = arc_pgu_read(arcpgu, ARCPGU_REG_CTRL); |
|---|
| 46 | + if (format == DRM_FORMAT_RGB565) |
|---|
| 47 | + reg_ctrl &= ~ARCPGU_MODE_XRGB8888; |
|---|
| 48 | + else |
|---|
| 49 | + reg_ctrl |= ARCPGU_MODE_XRGB8888; |
|---|
| 50 | + arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, reg_ctrl); |
|---|
| 56 | 51 | } |
|---|
| 57 | 52 | |
|---|
| 58 | 53 | static const struct drm_crtc_funcs arc_pgu_crtc_funcs = { |
|---|
| .. | .. |
|---|
| 142 | 137 | ~ARCPGU_CTRL_ENABLE_MASK); |
|---|
| 143 | 138 | } |
|---|
| 144 | 139 | |
|---|
| 145 | | -static void arc_pgu_crtc_atomic_begin(struct drm_crtc *crtc, |
|---|
| 146 | | - struct drm_crtc_state *state) |
|---|
| 147 | | -{ |
|---|
| 148 | | - struct drm_pending_vblank_event *event = crtc->state->event; |
|---|
| 149 | | - |
|---|
| 150 | | - if (event) { |
|---|
| 151 | | - crtc->state->event = NULL; |
|---|
| 152 | | - |
|---|
| 153 | | - spin_lock_irq(&crtc->dev->event_lock); |
|---|
| 154 | | - drm_crtc_send_vblank_event(crtc, event); |
|---|
| 155 | | - spin_unlock_irq(&crtc->dev->event_lock); |
|---|
| 156 | | - } |
|---|
| 157 | | -} |
|---|
| 158 | | - |
|---|
| 159 | 140 | static const struct drm_crtc_helper_funcs arc_pgu_crtc_helper_funcs = { |
|---|
| 160 | 141 | .mode_valid = arc_pgu_crtc_mode_valid, |
|---|
| 161 | | - .mode_set = drm_helper_crtc_mode_set, |
|---|
| 162 | | - .mode_set_base = drm_helper_crtc_mode_set_base, |
|---|
| 163 | 142 | .mode_set_nofb = arc_pgu_crtc_mode_set_nofb, |
|---|
| 164 | | - .atomic_begin = arc_pgu_crtc_atomic_begin, |
|---|
| 165 | 143 | .atomic_enable = arc_pgu_crtc_atomic_enable, |
|---|
| 166 | 144 | .atomic_disable = arc_pgu_crtc_atomic_disable, |
|---|
| 167 | 145 | }; |
|---|
| .. | .. |
|---|
| 186 | 164 | |
|---|
| 187 | 165 | static void arc_pgu_plane_destroy(struct drm_plane *plane) |
|---|
| 188 | 166 | { |
|---|
| 189 | | - drm_plane_helper_disable(plane, NULL); |
|---|
| 190 | 167 | drm_plane_cleanup(plane); |
|---|
| 191 | 168 | } |
|---|
| 192 | 169 | |
|---|
| .. | .. |
|---|
| 203 | 180 | { |
|---|
| 204 | 181 | struct arcpgu_drm_private *arcpgu = drm->dev_private; |
|---|
| 205 | 182 | struct drm_plane *plane = NULL; |
|---|
| 206 | | - u32 formats[ARRAY_SIZE(supported_formats)], i; |
|---|
| 207 | 183 | int ret; |
|---|
| 208 | 184 | |
|---|
| 209 | 185 | plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL); |
|---|
| 210 | 186 | if (!plane) |
|---|
| 211 | 187 | return ERR_PTR(-ENOMEM); |
|---|
| 212 | 188 | |
|---|
| 213 | | - for (i = 0; i < ARRAY_SIZE(supported_formats); i++) |
|---|
| 214 | | - formats[i] = supported_formats[i].fourcc; |
|---|
| 215 | | - |
|---|
| 216 | 189 | ret = drm_universal_plane_init(drm, plane, 0xff, &arc_pgu_plane_funcs, |
|---|
| 217 | | - formats, ARRAY_SIZE(formats), |
|---|
| 190 | + arc_pgu_supported_formats, |
|---|
| 191 | + ARRAY_SIZE(arc_pgu_supported_formats), |
|---|
| 218 | 192 | NULL, |
|---|
| 219 | 193 | DRM_PLANE_TYPE_PRIMARY, NULL); |
|---|
| 220 | 194 | if (ret) |
|---|