Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 97413924 authored by Qing Huang's avatar Qing Huang Committed by LuK1337
Browse files

minui: Add SPR support for drm

Enable SPR block in recovery and power off UI.

CRs-Fixed: 3433499
Change-Id: I0c12ca9dadbfd1cf1a83bf7e99e6794b24033f43
parent c8e69502
Loading
Loading
Loading
Loading
+116 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#include <memory>

#include <android-base/macros.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <drm_fourcc.h>
@@ -181,6 +182,98 @@ static int atomic_add_prop_to_plane(Plane* plane_res, drmModeAtomicReq* req, uin
  return 0;
}

static int SetupSprBlobV1(int fd, uint32_t* blob_id) {
  SPRPackType pack_type = SPRPackType::kPentile;
  SPRFilterType filter_type = SPRFilterType::kFourTap;
  SPRAdaptiveModeType adpative_mode = SPRAdaptiveModeType::kYYGM;

  drm_msm_spr_init_cfg spr_init_cfg;
  spr_init_cfg.cfg0 = 1;
  spr_init_cfg.cfg1 = 1;
  spr_init_cfg.cfg2 = 1;
  spr_init_cfg.cfg3 = 0;
  spr_init_cfg.flags = 0;
  spr_init_cfg.cfg4 = (pack_type == SPRPackType::kRGBW);
  spr_init_cfg.cfg5 = kDefaultColorPhaseIncrement.at(pack_type);
  spr_init_cfg.cfg6 = kDefaultColorPhaseRepeat.at(pack_type);
  spr_init_cfg.cfg7 = static_cast<uint16_t>(filter_type);
  spr_init_cfg.cfg8 = static_cast<uint16_t>(adpative_mode);
  if (pack_type == SPRPackType::kRGBW) {
    spr_init_cfg.cfg9 = 512;
    std::copy(kDefaultRGBWGains.begin(), kDefaultRGBWGains.end(), spr_init_cfg.cfg11);
  }
  spr_init_cfg.cfg10 = 0;
  std::copy(kDecimationRatioMap.at(pack_type).begin(), kDecimationRatioMap.at(pack_type).end(),
            spr_init_cfg.cfg11);
  std::copy(kDefaultOPRGains.begin(), kDefaultOPRGains.end(), spr_init_cfg.cfg13);
  std::copy(kDefaultAdaptiveStrengths.begin(), kDefaultAdaptiveStrengths.end(), spr_init_cfg.cfg14);
  std::copy(kDefaultOPROffsets.begin(), kDefaultOPROffsets.end(), spr_init_cfg.cfg15);
  std::copy(kDefaultFilterCoeffsMap.at(filter_type).begin(),
            kDefaultFilterCoeffsMap.at(filter_type).end(), spr_init_cfg.cfg16);
  std::copy(kDefaultColorPhaseMap.at(pack_type).begin(), kDefaultColorPhaseMap.at(pack_type).end(),
            spr_init_cfg.cfg17);

  if (drmModeCreatePropertyBlob(fd, &spr_init_cfg, sizeof(drm_msm_spr_init_cfg), blob_id)) {
    printf("failed to create spr blob\n");
    return -EINVAL;
  }

  return 0;
}

static int SetupSprBlobV2(int fd, uint32_t* blob_id) {
  SPRPackType pack_type = SPRPackType::kPentile;
  SPRFilterType filter_type = SPRFilterType::kFourTap;
  SPRAdaptiveModeType adpative_mode = SPRAdaptiveModeType::kYYGM;

  drm_msm_spr_init_cfg_v2 spr_init_cfg_v2;
  spr_init_cfg_v2.cfg0 = 1;
  spr_init_cfg_v2.cfg1 = 1;
  spr_init_cfg_v2.cfg2 = 1;
  spr_init_cfg_v2.cfg3 = 0;
  spr_init_cfg_v2.flags = 0;
  spr_init_cfg_v2.cfg4 = (pack_type == SPRPackType::kRGBW);
  spr_init_cfg_v2.cfg5 = kDefaultColorPhaseIncrement.at(pack_type);
  spr_init_cfg_v2.cfg6 = kDefaultColorPhaseRepeat.at(pack_type);
  spr_init_cfg_v2.cfg7 = static_cast<uint16_t>(filter_type);
  spr_init_cfg_v2.cfg8 = static_cast<uint16_t>(adpative_mode);
  if (pack_type == SPRPackType::kRGBW) {
    spr_init_cfg_v2.cfg9 = 512;
    std::copy(kDefaultRGBWGains.begin(), kDefaultRGBWGains.end(), spr_init_cfg_v2.cfg11);
  }
  spr_init_cfg_v2.cfg10 = 0;
  std::copy(kDecimationRatioMap.at(pack_type).begin(), kDecimationRatioMap.at(pack_type).end(),
            spr_init_cfg_v2.cfg11);
  std::copy(kDefaultOPRGains.begin(), kDefaultOPRGains.end(), spr_init_cfg_v2.cfg13);
  std::copy(kDefaultAdaptiveStrengths.begin(), kDefaultAdaptiveStrengths.end(),
            spr_init_cfg_v2.cfg14);
  std::copy(kDefaultOPROffsets.begin(), kDefaultOPROffsets.end(), spr_init_cfg_v2.cfg15);
  std::copy(kDefaultFilterCoeffsMap.at(filter_type).begin(),
            kDefaultFilterCoeffsMap.at(filter_type).end(), spr_init_cfg_v2.cfg16);
  std::copy(kDefaultColorPhaseMap.at(pack_type).begin(), kDefaultColorPhaseMap.at(pack_type).end(),
            spr_init_cfg_v2.cfg17);

  if (drmModeCreatePropertyBlob(fd, &spr_init_cfg_v2, sizeof(drm_msm_spr_init_cfg_v2), blob_id)) {
    printf("failed to create spr blob\n");
    return -EINVAL;
  }

  return 0;
}

static int SetupSprBlob(int fd, const std::string& prop_name, uint32_t* blob_id) {
  int ret = 0;
  if (prop_name == "SDE_SPR_INIT_CFG_V1") {
    ret = SetupSprBlobV1(fd, blob_id);
  } else if (prop_name == "SDE_SPR_INIT_CFG_V2") {
    ret = SetupSprBlobV2(fd, blob_id);
  } else {
    ret = -ENOENT;
  }

  return ret;
}

int MinuiBackendDrmQti::AtomicPopulatePlane(int plane, drmModeAtomicReqPtr atomic_req,
                                            DrmConnector index) {
  uint32_t src_x, src_y, src_w, src_h;
@@ -255,6 +348,10 @@ int MinuiBackendDrmQti::TeardownPipeline(drmModeAtomicReqPtr atomic_req, DrmConn
           0, index);
  add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "MODE_ID", 0, index);
  add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "ACTIVE", 0, index);
  if (spr_enabled) {
    add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, spr_prop_name.c_str(), 0,
             index);
  }

  for (i = 0; i < number_of_lms; i++) {
    ret =
@@ -283,6 +380,10 @@ int MinuiBackendDrmQti::SetupPipeline(drmModeAtomicReqPtr atomic_req, DrmConnect
    add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "MODE_ID",
             crtc_res.mode_blob_id, index);
    add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, "ACTIVE", 1, index);
    if (spr_enabled) {
      add_prop(&crtc_res, crtc, Crtc, drm[index].monitor_crtc->crtc_id, spr_prop_name.c_str(),
               crtc_res.spr_blob_id, index);
    }
  }

  /* Setup planes */
@@ -641,6 +742,7 @@ GRSurface* MinuiBackendDrmQti::Init() {
  drmModeRes* res = nullptr;
  drm_fd = -1;

  spr_enabled = android::base::GetIntProperty("vendor.display.enable_spr", 0);
  number_of_lms = DEFAULT_NUM_LMS;
  /* Consider DRM devices in order. */
  for (int i = 0; i < DRM_MAX_MINOR; i++) {
@@ -729,8 +831,14 @@ GRSurface* MinuiBackendDrmQti::Init() {
  if (!crtc_res.props_info)
    return NULL;
  else
    for (int j = 0; j < (int)crtc_res.props->count_props; ++j)
    for (int j = 0; j < (int)crtc_res.props->count_props; ++j) {
      crtc_res.props_info[j] = drmModeGetProperty(drm_fd, crtc_res.props->props[j]);
      /* Get spr property name */
      if (!strcmp(crtc_res.props_info[j]->name, "SDE_SPR_INIT_CFG_V1") ||
          !strcmp(crtc_res.props_info[j]->name, "SDE_SPR_INIT_CFG_V2")) {
        spr_prop_name = crtc_res.props_info[j]->name;
      }
    }

  /* Set connector resources */
  conn_res.props = drmModeObjectGetProperties(drm_fd, drm[DRM_MAIN].monitor_connector->connector_id,
@@ -783,6 +891,13 @@ GRSurface* MinuiBackendDrmQti::Init() {
    return NULL;
  }

  /* Setup spr blob id if enabled */
  if (spr_enabled) {
    if (SetupSprBlob(drm_fd, spr_prop_name, &crtc_res.spr_blob_id)) {
      return NULL;
    }
  }

  /* Save fb_prop_id*/
  uint32_t prop_id;
  prop_id = find_plane_prop_id(plane_res[0].plane->plane_id, "FB_ID", plane_res);
+137 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <stddef.h>
#include <stdint.h>

#include <array>
#include <map>
#include <memory>

#include <xf86drmMode.h>
@@ -30,10 +32,97 @@
#define NUM_PLANES 4
#define DEFAULT_NUM_LMS 2

#define SPR_INIT_PARAM_SIZE_1 4
#define SPR_INIT_PARAM_SIZE_2 5
#define SPR_INIT_PARAM_SIZE_3 16
#define SPR_INIT_PARAM_SIZE_4 24
#define SPR_INIT_PARAM_SIZE_5 32
#define SPR_INIT_PARAM_SIZE_6 7

enum class SPRPackType {
  kPentile,
  kRGBW,
  kYYGW,
  kYYGM,
  kDelta3,
  kMax = 0xFF,
};

enum class SPRFilterType {
  kPixelDrop,
  kBilinear,
  kFourTap,
  kAdaptive,
  k2DAvg,
  kMax = 0xFF,
};

enum class SPRAdaptiveModeType {
  kYYGM,
  kYYGW,
  kMax = 0xFF,
};

static const std::map<SPRPackType, uint32_t> kDefaultColorPhaseIncrement = {
  { { { SPRPackType::kPentile }, { 8 } },
    { { SPRPackType::kYYGM }, { 6 } },
    { { SPRPackType::kYYGW }, { 6 } },
    { { SPRPackType::kDelta3 }, { 6 } },
    { { SPRPackType::kRGBW }, { 8 } } }
};
static const std::map<SPRPackType, uint32_t> kDefaultColorPhaseRepeat = {
  { { { SPRPackType::kPentile }, { 2 } },
    { { SPRPackType::kYYGM }, { 2 } },
    { { SPRPackType::kYYGW }, { 2 } },
    { { SPRPackType::kDelta3 }, { 2 } },
    { { SPRPackType::kRGBW }, { 2 } } }
};
static const std::map<SPRPackType, std::array<uint16_t, SPR_INIT_PARAM_SIZE_1>> kDecimationRatioMap{
  {
      { { SPRPackType::kPentile }, { 1, 0, 1, 0 } },
      { { SPRPackType::kYYGM }, { 2, 2, 2, 0 } },
      { { SPRPackType::kYYGW }, { 2, 2, 2, 0 } },
      { { SPRPackType::kRGBW }, { 1, 1, 1, 1 } },
  }
};
static const std::map<SPRFilterType, std::array<int16_t, SPR_INIT_PARAM_SIZE_3>>
    kDefaultFilterCoeffsMap{
      { { { SPRFilterType::kPixelDrop }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
        { { SPRFilterType::kBilinear },
          { 0, 512, 0, 0, -33, 443, 110, -8, -23, 279, 279, -23, -8, 110, 443, -33 } },
        { { SPRFilterType::kFourTap },
          { 128, 256, 128, 0, 86, 241, 164, 21, 52, 204, 204, 52, 21, 164, 241, 86 } },
        { { SPRFilterType::kAdaptive },
          { 0, 256, 256, 0, 0, 256, 256, 0, 0, 256, 256, 0, 0, 256, 256, 0 } } }
    };
static const std::map<SPRPackType, std::array<int16_t, SPR_INIT_PARAM_SIZE_4>>
    kDefaultColorPhaseMap{
      { { { SPRPackType::kPentile },
          { -2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
        { { SPRPackType::kYYGM },
          { -3, 0, 0, 0, 0, 0, -1, 2, 1, 1, 0, 0, 1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
        { { SPRPackType::kYYGW },
          { -4, 2, 0, 0, 0, -1, 2, 2, 0, -1, -1, -1, 2, 2, -1, -1, -1, 2, 0, 0, 0, 0, 0, 0 } },
        { { SPRPackType::kDelta3 },
          { -3, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
        { { SPRPackType::kRGBW },
          { -4, 0, 0, 0, 0, 0, -2, 2, 0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 2, -2, 0, 0, 0, 0 } } }
    };
static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_1> kDefaultRGBWGains = { 1024, 1024, 1024,
                                                                               341 };
static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_1> kDefaultOPRGains = { 341, 341, 341, 0 };
static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_2> kDefaultAdaptiveStrengths = { 0, 4, 8, 12,
                                                                                       16 };
static const std::array<uint16_t, SPR_INIT_PARAM_SIZE_5> kDefaultOPROffsets = {
  0,    132,  264,  396,  529,  661,  793,  925,  1057, 1189, 1321, 1453, 1586, 1718, 1850, 1982,
  2114, 2246, 2378, 2510, 2643, 2775, 2907, 3039, 3171, 3303, 3435, 3567, 3700, 3832, 3964, 4095
};

struct Crtc {
  drmModeObjectProperties* props;
  drmModePropertyRes** props_info;
  uint32_t mode_blob_id;
  uint32_t spr_blob_id;
};

struct Connector {
@@ -47,6 +136,52 @@ struct Plane {
  drmModePropertyRes** props_info;
};

struct drm_msm_spr_init_cfg {
  __u64 flags;
  __u16 cfg0;
  __u16 cfg1;
  __u16 cfg2;
  __u16 cfg3;
  __u16 cfg4;
  __u16 cfg5;
  __u16 cfg6;
  __u16 cfg7;
  __u16 cfg8;
  __u16 cfg9;
  __u32 cfg10;
  __u16 cfg11[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg12[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg13[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg14[SPR_INIT_PARAM_SIZE_2];
  __u16 cfg15[SPR_INIT_PARAM_SIZE_5];
  int cfg16[SPR_INIT_PARAM_SIZE_3];
  int cfg17[SPR_INIT_PARAM_SIZE_4];
};

struct drm_msm_spr_init_cfg_v2 {
  __u64 flags;
  __u16 cfg0;
  __u16 cfg1;
  __u16 cfg2;
  __u16 cfg3;
  __u16 cfg4;
  __u16 cfg5;
  __u16 cfg6;
  __u16 cfg7;
  __u16 cfg8;
  __u16 cfg9;
  __u32 cfg10;
  __u16 cfg11[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg12[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg13[SPR_INIT_PARAM_SIZE_1];
  __u16 cfg14[SPR_INIT_PARAM_SIZE_2];
  __u16 cfg15[SPR_INIT_PARAM_SIZE_5];
  int cfg16[SPR_INIT_PARAM_SIZE_3];
  int cfg17[SPR_INIT_PARAM_SIZE_4];
  __u16 cfg18_en;
  __u8 cfg18[SPR_INIT_PARAM_SIZE_6];
};

class GRSurfaceDrmQti : public GRSurface {
 public:
  ~GRSurfaceDrmQti() override;
@@ -111,4 +246,6 @@ class MinuiBackendDrmQti : public MinuiBackend {
  struct Connector conn_res;
  struct Plane plane_res[NUM_PLANES];
  uint32_t number_of_lms;
  uint32_t spr_enabled;
  std::string spr_prop_name;
};