mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
fcd70cd36b
Having the probe helper stuff (which pretty much everyone needs) in the drm_crtc_helper.h file (which atomic drivers should never need) is confusing. Split them out. To make sure I actually achieved the goal here I went through all drivers. And indeed, all atomic drivers are now free of drm_crtc_helper.h includes. v2: Make it compile. There was so much compile fail on arm drivers that I figured I'll better not include any of the acks on v1. v3: Massive rebase because i915 has lost a lot of drmP.h includes, but not all: Through drm_crtc_helper.h > drm_modeset_helper.h -> drmP.h there was still one, which this patch largely removes. Which means rolling out lots more includes all over. This will also conflict with ongoing drmP.h cleanup by others I expect. v3: Rebase on top of atomic bochs. v4: Review from Laurent for bridge/rcar/omap/shmob/core bits: - (re)move some of the added includes, use the better include files in other places (all suggested from Laurent adopted unchanged). - sort alphabetically v5: Actually try to sort them, and while at it, sort all the ones I touch. v6: Rebase onto i915 changes. v7: Rebase once more. Acked-by: Harry Wentland <harry.wentland@amd.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Cc: Sam Ravnborg <sam@ravnborg.org> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Acked-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> Acked-by: Jani Nikula <jani.nikula@intel.com> Acked-by: Neil Armstrong <narmstrong@baylibre.com> Acked-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com> Acked-by: CK Hu <ck.hu@mediatek.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Cc: linux-arm-kernel@lists.infradead.org Cc: virtualization@lists.linux-foundation.org Cc: etnaviv@lists.freedesktop.org Cc: linux-samsung-soc@vger.kernel.org Cc: intel-gfx@lists.freedesktop.org Cc: linux-mediatek@lists.infradead.org Cc: linux-amlogic@lists.infradead.org Cc: linux-arm-msm@vger.kernel.org Cc: freedreno@lists.freedesktop.org Cc: nouveau@lists.freedesktop.org Cc: spice-devel@lists.freedesktop.org Cc: amd-gfx@lists.freedesktop.org Cc: linux-renesas-soc@vger.kernel.org Cc: linux-rockchip@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Cc: linux-tegra@vger.kernel.org Cc: xen-devel@lists.xen.org Link: https://patchwork.freedesktop.org/patch/msgid/20190117210334.13234-1-daniel.vetter@ffwll.ch
248 lines
7.3 KiB
C
248 lines
7.3 KiB
C
/*
|
|
* ARC PGU DRM driver.
|
|
*
|
|
* Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_device.h>
|
|
#include <drm/drm_fb_cma_helper.h>
|
|
#include <drm/drm_gem_cma_helper.h>
|
|
#include <drm/drm_vblank.h>
|
|
#include <drm/drm_plane_helper.h>
|
|
#include <drm/drm_probe_helper.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/platform_data/simplefb.h>
|
|
|
|
#include "arcpgu.h"
|
|
#include "arcpgu_regs.h"
|
|
|
|
#define ENCODE_PGU_XY(x, y) ((((x) - 1) << 16) | ((y) - 1))
|
|
|
|
static struct simplefb_format supported_formats[] = {
|
|
{ "r5g6b5", 16, {11, 5}, {5, 6}, {0, 5}, {0, 0}, DRM_FORMAT_RGB565 },
|
|
{ "r8g8b8", 24, {16, 8}, {8, 8}, {0, 8}, {0, 0}, DRM_FORMAT_RGB888 },
|
|
};
|
|
|
|
static void arc_pgu_set_pxl_fmt(struct drm_crtc *crtc)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
const struct drm_framebuffer *fb = crtc->primary->state->fb;
|
|
uint32_t pixel_format = fb->format->format;
|
|
struct simplefb_format *format = NULL;
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
|
|
if (supported_formats[i].fourcc == pixel_format)
|
|
format = &supported_formats[i];
|
|
}
|
|
|
|
if (WARN_ON(!format))
|
|
return;
|
|
|
|
if (format->fourcc == DRM_FORMAT_RGB888)
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL,
|
|
arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) |
|
|
ARCPGU_MODE_RGB888_MASK);
|
|
|
|
}
|
|
|
|
static const struct drm_crtc_funcs arc_pgu_crtc_funcs = {
|
|
.destroy = drm_crtc_cleanup,
|
|
.set_config = drm_atomic_helper_set_config,
|
|
.page_flip = drm_atomic_helper_page_flip,
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
|
};
|
|
|
|
static enum drm_mode_status arc_pgu_crtc_mode_valid(struct drm_crtc *crtc,
|
|
const struct drm_display_mode *mode)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
long rate, clk_rate = mode->clock * 1000;
|
|
long diff = clk_rate / 200; /* +-0.5% allowed by HDMI spec */
|
|
|
|
rate = clk_round_rate(arcpgu->clk, clk_rate);
|
|
if ((max(rate, clk_rate) - min(rate, clk_rate) < diff) && (rate > 0))
|
|
return MODE_OK;
|
|
|
|
return MODE_NOCLOCK;
|
|
}
|
|
|
|
static void arc_pgu_crtc_mode_set_nofb(struct drm_crtc *crtc)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
struct drm_display_mode *m = &crtc->state->adjusted_mode;
|
|
u32 val;
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_FMT,
|
|
ENCODE_PGU_XY(m->crtc_htotal, m->crtc_vtotal));
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_HSYNC,
|
|
ENCODE_PGU_XY(m->crtc_hsync_start - m->crtc_hdisplay,
|
|
m->crtc_hsync_end - m->crtc_hdisplay));
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_VSYNC,
|
|
ENCODE_PGU_XY(m->crtc_vsync_start - m->crtc_vdisplay,
|
|
m->crtc_vsync_end - m->crtc_vdisplay));
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_ACTIVE,
|
|
ENCODE_PGU_XY(m->crtc_hblank_end - m->crtc_hblank_start,
|
|
m->crtc_vblank_end - m->crtc_vblank_start));
|
|
|
|
val = arc_pgu_read(arcpgu, ARCPGU_REG_CTRL);
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PVSYNC)
|
|
val |= ARCPGU_CTRL_VS_POL_MASK << ARCPGU_CTRL_VS_POL_OFST;
|
|
else
|
|
val &= ~(ARCPGU_CTRL_VS_POL_MASK << ARCPGU_CTRL_VS_POL_OFST);
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PHSYNC)
|
|
val |= ARCPGU_CTRL_HS_POL_MASK << ARCPGU_CTRL_HS_POL_OFST;
|
|
else
|
|
val &= ~(ARCPGU_CTRL_HS_POL_MASK << ARCPGU_CTRL_HS_POL_OFST);
|
|
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, val);
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_STRIDE, 0);
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_START_SET, 1);
|
|
|
|
arc_pgu_set_pxl_fmt(crtc);
|
|
|
|
clk_set_rate(arcpgu->clk, m->crtc_clock * 1000);
|
|
}
|
|
|
|
static void arc_pgu_crtc_atomic_enable(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *old_state)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
clk_prepare_enable(arcpgu->clk);
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL,
|
|
arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) |
|
|
ARCPGU_CTRL_ENABLE_MASK);
|
|
}
|
|
|
|
static void arc_pgu_crtc_atomic_disable(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *old_state)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = crtc_to_arcpgu_priv(crtc);
|
|
|
|
clk_disable_unprepare(arcpgu->clk);
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_CTRL,
|
|
arc_pgu_read(arcpgu, ARCPGU_REG_CTRL) &
|
|
~ARCPGU_CTRL_ENABLE_MASK);
|
|
}
|
|
|
|
static void arc_pgu_crtc_atomic_begin(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *state)
|
|
{
|
|
struct drm_pending_vblank_event *event = crtc->state->event;
|
|
|
|
if (event) {
|
|
crtc->state->event = NULL;
|
|
|
|
spin_lock_irq(&crtc->dev->event_lock);
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
spin_unlock_irq(&crtc->dev->event_lock);
|
|
}
|
|
}
|
|
|
|
static const struct drm_crtc_helper_funcs arc_pgu_crtc_helper_funcs = {
|
|
.mode_valid = arc_pgu_crtc_mode_valid,
|
|
.mode_set_nofb = arc_pgu_crtc_mode_set_nofb,
|
|
.atomic_begin = arc_pgu_crtc_atomic_begin,
|
|
.atomic_enable = arc_pgu_crtc_atomic_enable,
|
|
.atomic_disable = arc_pgu_crtc_atomic_disable,
|
|
};
|
|
|
|
static void arc_pgu_plane_atomic_update(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu;
|
|
struct drm_gem_cma_object *gem;
|
|
|
|
if (!plane->state->crtc || !plane->state->fb)
|
|
return;
|
|
|
|
arcpgu = crtc_to_arcpgu_priv(plane->state->crtc);
|
|
gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
|
|
arc_pgu_write(arcpgu, ARCPGU_REG_BUF0_ADDR, gem->paddr);
|
|
}
|
|
|
|
static const struct drm_plane_helper_funcs arc_pgu_plane_helper_funcs = {
|
|
.atomic_update = arc_pgu_plane_atomic_update,
|
|
};
|
|
|
|
static void arc_pgu_plane_destroy(struct drm_plane *plane)
|
|
{
|
|
drm_plane_cleanup(plane);
|
|
}
|
|
|
|
static const struct drm_plane_funcs arc_pgu_plane_funcs = {
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
.destroy = arc_pgu_plane_destroy,
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
};
|
|
|
|
static struct drm_plane *arc_pgu_plane_init(struct drm_device *drm)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = drm->dev_private;
|
|
struct drm_plane *plane = NULL;
|
|
u32 formats[ARRAY_SIZE(supported_formats)], i;
|
|
int ret;
|
|
|
|
plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
|
|
if (!plane)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_formats); i++)
|
|
formats[i] = supported_formats[i].fourcc;
|
|
|
|
ret = drm_universal_plane_init(drm, plane, 0xff, &arc_pgu_plane_funcs,
|
|
formats, ARRAY_SIZE(formats),
|
|
NULL,
|
|
DRM_PLANE_TYPE_PRIMARY, NULL);
|
|
if (ret)
|
|
return ERR_PTR(ret);
|
|
|
|
drm_plane_helper_add(plane, &arc_pgu_plane_helper_funcs);
|
|
arcpgu->plane = plane;
|
|
|
|
return plane;
|
|
}
|
|
|
|
int arc_pgu_setup_crtc(struct drm_device *drm)
|
|
{
|
|
struct arcpgu_drm_private *arcpgu = drm->dev_private;
|
|
struct drm_plane *primary;
|
|
int ret;
|
|
|
|
primary = arc_pgu_plane_init(drm);
|
|
if (IS_ERR(primary))
|
|
return PTR_ERR(primary);
|
|
|
|
ret = drm_crtc_init_with_planes(drm, &arcpgu->crtc, primary, NULL,
|
|
&arc_pgu_crtc_funcs, NULL);
|
|
if (ret) {
|
|
arc_pgu_plane_destroy(primary);
|
|
return ret;
|
|
}
|
|
|
|
drm_crtc_helper_add(&arcpgu->crtc, &arc_pgu_crtc_helper_funcs);
|
|
return 0;
|
|
}
|