drm/meson: viu: add AFBC modules routing functions
authorNeil Armstrong <narmstrong@baylibre.com>
Mon, 21 Oct 2019 09:15:07 +0000 (11:15 +0200)
committerNeil Armstrong <narmstrong@baylibre.com>
Tue, 10 Dec 2019 09:09:38 +0000 (10:09 +0100)
The Amlogic G12A AFBC Decoder pixel input need to be routed diferently
than the Amlogic GXM AFBC decoder, this adds support for routing the
VIU OSD1 pixel source to the AFBC "Mali Unpack" module.

This "Mali Unpack" module is also configured with a static RGBA mapping
for now until we support more pixel formats.

Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191021091509.3864-8-narmstrong@baylibre.com
drivers/gpu/drm/meson/meson_viu.c
drivers/gpu/drm/meson/meson_viu.h

index 68cf2c2eca5fe4ab5153b0d7faca33550748ba4c..fc246248226bcf22e6b409f7e3254565a13a1ca7 100644 (file)
@@ -7,6 +7,9 @@
  */
 
 #include <linux/export.h>
+#include <linux/bitfield.h>
+
+#include <drm/drm_fourcc.h>
 
 #include "meson_drv.h"
 #include "meson_viu.h"
@@ -335,6 +338,79 @@ void meson_viu_osd1_reset(struct meson_drm *priv)
        meson_viu_load_matrix(priv);
 }
 
+#define OSD1_MALI_ORDER_ABGR                           \
+       (FIELD_PREP(VIU_OSD1_MALI_AFBCD_A_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_A) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_B_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_B) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_G_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_G) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_R_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_R))
+
+#define OSD1_MALI_ORDER_ARGB                           \
+       (FIELD_PREP(VIU_OSD1_MALI_AFBCD_A_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_A) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_B_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_R) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_G_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_G) |          \
+        FIELD_PREP(VIU_OSD1_MALI_AFBCD_R_REORDER,      \
+                   VIU_OSD1_MALI_REORDER_B))
+
+void meson_viu_g12a_enable_osd1_afbc(struct meson_drm *priv)
+{
+       u32 afbc_order = OSD1_MALI_ORDER_ARGB;
+
+       /* Enable Mali AFBC Unpack */
+       writel_bits_relaxed(VIU_OSD1_MALI_UNPACK_EN,
+                           VIU_OSD1_MALI_UNPACK_EN,
+                           priv->io_base + _REG(VIU_OSD1_MALI_UNPACK_CTRL));
+
+       switch (priv->afbcd.format) {
+       case DRM_FORMAT_XBGR8888:
+       case DRM_FORMAT_ABGR8888:
+               afbc_order = OSD1_MALI_ORDER_ABGR;
+               break;
+       }
+
+       /* Setup RGBA Reordering */
+       writel_bits_relaxed(VIU_OSD1_MALI_AFBCD_A_REORDER |
+                           VIU_OSD1_MALI_AFBCD_B_REORDER |
+                           VIU_OSD1_MALI_AFBCD_G_REORDER |
+                           VIU_OSD1_MALI_AFBCD_R_REORDER,
+                           afbc_order,
+                           priv->io_base + _REG(VIU_OSD1_MALI_UNPACK_CTRL));
+
+       /* Select AFBCD path for OSD1 */
+       writel_bits_relaxed(OSD_PATH_OSD_AXI_SEL_OSD1_AFBCD,
+                           OSD_PATH_OSD_AXI_SEL_OSD1_AFBCD,
+                           priv->io_base + _REG(OSD_PATH_MISC_CTRL));
+}
+
+void meson_viu_g12a_disable_osd1_afbc(struct meson_drm *priv)
+{
+       /* Disable AFBCD path for OSD1 */
+       writel_bits_relaxed(OSD_PATH_OSD_AXI_SEL_OSD1_AFBCD, 0,
+                           priv->io_base + _REG(OSD_PATH_MISC_CTRL));
+
+       /* Disable AFBCD unpack */
+       writel_bits_relaxed(VIU_OSD1_MALI_UNPACK_EN, 0,
+                           priv->io_base + _REG(VIU_OSD1_MALI_UNPACK_CTRL));
+}
+
+void meson_viu_gxm_enable_osd1_afbc(struct meson_drm *priv)
+{
+       writel_bits_relaxed(MALI_AFBC_MISC, FIELD_PREP(MALI_AFBC_MISC, 0x90),
+                           priv->io_base + _REG(VIU_MISC_CTRL1));
+}
+
+void meson_viu_gxm_disable_osd1_afbc(struct meson_drm *priv)
+{
+       writel_bits_relaxed(MALI_AFBC_MISC, FIELD_PREP(MALI_AFBC_MISC, 0x00),
+                           priv->io_base + _REG(VIU_MISC_CTRL1));
+}
+
 static inline uint32_t meson_viu_osd_burst_length_reg(uint32_t length)
 {
        uint32_t val = (((length & 0x80) % 24) / 12);
@@ -420,8 +496,13 @@ void meson_viu_init(struct meson_drm *priv)
 
                writel_bits_relaxed(DOLBY_BYPASS_EN(0xc), DOLBY_BYPASS_EN(0xc),
                                    priv->io_base + _REG(DOLBY_PATH_CTRL));
+
+               meson_viu_g12a_disable_osd1_afbc(priv);
        }
 
+       if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
+               meson_viu_gxm_disable_osd1_afbc(priv);
+
        priv->viu.osd1_enabled = false;
        priv->viu.osd1_commit = false;
        priv->viu.osd1_interlace = false;
index e297772d967f465404748068ab6e819164b56fc5..e4a2f24d7c384d1bc4dcd59ccc2b056f5f978ff7 100644 (file)
 #define OSD_PENDING_STAT_CLEAN BIT(1)
 
 void meson_viu_osd1_reset(struct meson_drm *priv);
+void meson_viu_g12a_enable_osd1_afbc(struct meson_drm *priv);
+void meson_viu_g12a_disable_osd1_afbc(struct meson_drm *priv);
+void meson_viu_gxm_enable_osd1_afbc(struct meson_drm *priv);
+void meson_viu_gxm_disable_osd1_afbc(struct meson_drm *priv);
 void meson_viu_init(struct meson_drm *priv);
 
 #endif /* __MESON_VIU_H */