Commit d1b5e41e authored by Neil Armstrong's avatar Neil Armstrong

drm/meson: Add AFBCD module driver

This adds the driver for the ARM Framebuffer Compression decoders found
in the Amlogic GXM and G12A SoCs.

The Amlogic GXM and G12A AFBC decoder are totally different, the GXM only
handling only the AFBC v1.0 modes and the G12A decoder handling the
AFBC v1.2 modes.

The G12A AFBC decoder is an external IP integrated in the video pipeline,
and the GXM AFBC decoder seems to the an Amlogic custom decoder more
tighly integrated in the video pipeline.

The GXM AFBC decoder can handle only one AFBC plane for 2 available
OSD planes available in HW, and the G12A AFBC decoder can handle up
to 4 AFBC planes for up to 3 OSD planes available in HW.

The Amlogic GXM supports 16x16 SPARSE and 16x16 SPLIT AFBC buffers up
to 4k.

On the other side, for G12A SPLIT is mandatory in 16x16 block mode, but
for 4k modes 32x8+SPLIT AFBC buffers is manadatory for performances reasons.

The RDMA is used here to reset and program the AFBC decoder unit
on each vsync without involving the interrupt handler that can
be masked for a long period of time, producing display glitches.

For this we use the meson_rdma_writel_sync() which adds the register
write tuple (VPU register offset and register value) to the RDMA buffer
and write the value to the HW.

When enabled, the RDMA is enabled to rewrite the same sequence at the
next VSYNC event, until a new buffer is committed to the OSD plane.

Then the Amlogic G12A is switched to RDMA, the Amlogic GXM Decoder
doesn't need a reset/reprogram at each vsync, but needs to keep the
vsync interrupt enabled to trigger the RDMA module.
Signed-off-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Reviewed-by: default avatarKevin Hilman <khilman@baylibre.com>
[narmstrong: fixed typo in commit log]
Link: https://patchwork.freedesktop.org/patch/msgid/20191021091509.3864-6-narmstrong@baylibre.com
parent 63fba242
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
meson-drm-y := meson_drv.o meson_plane.o meson_crtc.o meson_venc_cvbs.o meson-drm-y := meson_drv.o meson_plane.o meson_crtc.o meson_venc_cvbs.o
meson-drm-y += meson_viu.o meson_vpp.o meson_venc.o meson_vclk.o meson_overlay.o meson-drm-y += meson_viu.o meson_vpp.o meson_venc.o meson_vclk.o meson_overlay.o
meson-drm-y += meson_rdma.o meson-drm-y += meson_rdma.o meson_osd_afbcd.o
obj-$(CONFIG_DRM_MESON) += meson-drm.o obj-$(CONFIG_DRM_MESON) += meson-drm.o
obj-$(CONFIG_DRM_MESON_DW_HDMI) += meson_dw_hdmi.o obj-$(CONFIG_DRM_MESON_DW_HDMI) += meson_dw_hdmi.o
...@@ -28,10 +28,12 @@ ...@@ -28,10 +28,12 @@
#include "meson_drv.h" #include "meson_drv.h"
#include "meson_overlay.h" #include "meson_overlay.h"
#include "meson_plane.h" #include "meson_plane.h"
#include "meson_osd_afbcd.h"
#include "meson_registers.h" #include "meson_registers.h"
#include "meson_venc_cvbs.h" #include "meson_venc_cvbs.h"
#include "meson_viu.h" #include "meson_viu.h"
#include "meson_vpp.h" #include "meson_vpp.h"
#include "meson_rdma.h"
#define DRIVER_NAME "meson" #define DRIVER_NAME "meson"
#define DRIVER_DESC "Amlogic Meson DRM driver" #define DRIVER_DESC "Amlogic Meson DRM driver"
...@@ -184,6 +186,7 @@ static void meson_remove_framebuffers(void) ...@@ -184,6 +186,7 @@ static void meson_remove_framebuffers(void)
static int meson_drv_bind_master(struct device *dev, bool has_components) static int meson_drv_bind_master(struct device *dev, bool has_components)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
const struct meson_drm_match_data *match;
struct meson_drm *priv; struct meson_drm *priv;
struct drm_device *drm; struct drm_device *drm;
struct resource *res; struct resource *res;
...@@ -196,6 +199,10 @@ static int meson_drv_bind_master(struct device *dev, bool has_components) ...@@ -196,6 +199,10 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
return -ENODEV; return -ENODEV;
} }
match = of_device_get_match_data(dev);
if (!match)
return -ENODEV;
drm = drm_dev_alloc(&meson_driver, dev); drm = drm_dev_alloc(&meson_driver, dev);
if (IS_ERR(drm)) if (IS_ERR(drm))
return PTR_ERR(drm); return PTR_ERR(drm);
...@@ -208,8 +215,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components) ...@@ -208,8 +215,8 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
drm->dev_private = priv; drm->dev_private = priv;
priv->drm = drm; priv->drm = drm;
priv->dev = dev; priv->dev = dev;
priv->compat = match->compat;
priv->compat = (enum vpu_compatible)of_device_get_match_data(priv->dev); priv->afbcd.ops = match->afbcd_ops;
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpu"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpu");
regs = devm_ioremap_resource(dev, res); regs = devm_ioremap_resource(dev, res);
...@@ -289,6 +296,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components) ...@@ -289,6 +296,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
meson_venc_init(priv); meson_venc_init(priv);
meson_vpp_init(priv); meson_vpp_init(priv);
meson_viu_init(priv); meson_viu_init(priv);
if (priv->afbcd.ops) {
ret = priv->afbcd.ops->init(priv);
if (ret)
return ret;
}
/* Encoder Initialization */ /* Encoder Initialization */
...@@ -359,12 +371,16 @@ static void meson_drv_unbind(struct device *dev) ...@@ -359,12 +371,16 @@ static void meson_drv_unbind(struct device *dev)
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2); meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
} }
if (priv->afbcd.ops) {
priv->afbcd.ops->reset(priv);
meson_rdma_free(priv);
}
drm_dev_unregister(drm); drm_dev_unregister(drm);
drm_irq_uninstall(drm); drm_irq_uninstall(drm);
drm_kms_helper_poll_fini(drm); drm_kms_helper_poll_fini(drm);
drm_mode_config_cleanup(drm); drm_mode_config_cleanup(drm);
drm_dev_put(drm); drm_dev_put(drm);
} }
static const struct component_master_ops meson_drv_master_ops = { static const struct component_master_ops meson_drv_master_ops = {
...@@ -393,6 +409,8 @@ static int __maybe_unused meson_drv_pm_resume(struct device *dev) ...@@ -393,6 +409,8 @@ static int __maybe_unused meson_drv_pm_resume(struct device *dev)
meson_venc_init(priv); meson_venc_init(priv);
meson_vpp_init(priv); meson_vpp_init(priv);
meson_viu_init(priv); meson_viu_init(priv);
if (priv->afbcd.ops)
priv->afbcd.ops->init(priv);
drm_mode_config_helper_resume(priv->drm); drm_mode_config_helper_resume(priv->drm);
...@@ -481,15 +499,33 @@ static int meson_drv_probe(struct platform_device *pdev) ...@@ -481,15 +499,33 @@ static int meson_drv_probe(struct platform_device *pdev)
return 0; return 0;
}; };
static struct meson_drm_match_data meson_drm_gxbb_data = {
.compat = VPU_COMPATIBLE_GXBB,
};
static struct meson_drm_match_data meson_drm_gxl_data = {
.compat = VPU_COMPATIBLE_GXL,
};
static struct meson_drm_match_data meson_drm_gxm_data = {
.compat = VPU_COMPATIBLE_GXM,
.afbcd_ops = &meson_afbcd_gxm_ops,
};
static struct meson_drm_match_data meson_drm_g12a_data = {
.compat = VPU_COMPATIBLE_G12A,
.afbcd_ops = &meson_afbcd_g12a_ops,
};
static const struct of_device_id dt_match[] = { static const struct of_device_id dt_match[] = {
{ .compatible = "amlogic,meson-gxbb-vpu", { .compatible = "amlogic,meson-gxbb-vpu",
.data = (void *)VPU_COMPATIBLE_GXBB }, .data = (void *)&meson_drm_gxbb_data },
{ .compatible = "amlogic,meson-gxl-vpu", { .compatible = "amlogic,meson-gxl-vpu",
.data = (void *)VPU_COMPATIBLE_GXL }, .data = (void *)&meson_drm_gxl_data },
{ .compatible = "amlogic,meson-gxm-vpu", { .compatible = "amlogic,meson-gxm-vpu",
.data = (void *)VPU_COMPATIBLE_GXM }, .data = (void *)&meson_drm_gxm_data },
{ .compatible = "amlogic,meson-g12a-vpu", { .compatible = "amlogic,meson-g12a-vpu",
.data = (void *)VPU_COMPATIBLE_G12A }, .data = (void *)&meson_drm_g12a_data },
{} {}
}; };
MODULE_DEVICE_TABLE(of, dt_match); MODULE_DEVICE_TABLE(of, dt_match);
......
...@@ -16,6 +16,7 @@ struct drm_crtc; ...@@ -16,6 +16,7 @@ struct drm_crtc;
struct drm_device; struct drm_device;
struct drm_plane; struct drm_plane;
struct meson_drm; struct meson_drm;
struct meson_afbcd_ops;
enum vpu_compatible { enum vpu_compatible {
VPU_COMPATIBLE_GXBB = 0, VPU_COMPATIBLE_GXBB = 0,
...@@ -24,6 +25,11 @@ enum vpu_compatible { ...@@ -24,6 +25,11 @@ enum vpu_compatible {
VPU_COMPATIBLE_G12A = 3, VPU_COMPATIBLE_G12A = 3,
}; };
struct meson_drm_match_data {
enum vpu_compatible compat;
struct meson_afbcd_ops *afbcd_ops;
};
struct meson_drm { struct meson_drm {
struct device *dev; struct device *dev;
enum vpu_compatible compat; enum vpu_compatible compat;
...@@ -129,6 +135,12 @@ struct meson_drm { ...@@ -129,6 +135,12 @@ struct meson_drm {
uint32_t *addr; uint32_t *addr;
unsigned int offset; unsigned int offset;
} rdma; } rdma;
struct {
struct meson_afbcd_ops *ops;
u64 modifier;
u32 format;
} afbcd;
}; };
static inline int meson_vpu_is_compatible(struct meson_drm *priv, static inline int meson_vpu_is_compatible(struct meson_drm *priv,
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (C) 2019 BayLibre, SAS
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#ifndef __MESON_OSD_AFBCD_H
#define __MESON_OSD_AFBCD_H
#include "meson_drv.h"
/* This is an internal address used to transfer pixel from AFBC to the VIU */
#define MESON_G12A_AFBCD_OUT_ADDR 0x1000000
struct meson_afbcd_ops {
int (*init)(struct meson_drm *priv);
int (*reset)(struct meson_drm *priv);
int (*enable)(struct meson_drm *priv);
int (*disable)(struct meson_drm *priv);
int (*setup)(struct meson_drm *priv);
int (*fmt_to_blk_mode)(u64 modifier, uint32_t format);
bool (*supported_fmt)(u64 modifier, uint32_t format);
};
extern struct meson_afbcd_ops meson_afbcd_gxm_ops;
extern struct meson_afbcd_ops meson_afbcd_g12a_ops;
#endif /* __MESON_OSD_AFBCD_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment