Skip to content

drm/phytium: Fix some Bugs in Phytium Display Engine #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025

Conversation

xuyan213
Copy link

@xuyan213 xuyan213 commented Apr 27, 2025

modified this files to support Phytium Display Engine more.

Summary by Sourcery

Add display scaling, BMC mode support, and PWM backlight control for Phytium display driver, along with various fixes and improvements.

New Features:

  • Implement display scaling using sinc filters.
  • Introduce support for BMC (Baseboard Management Controller) mode, affecting plane formats, CRTC initialization, and reset logic.
  • Add eDP backlight control via PWM and GPIO.
  • Add an ioctl to query if the device is operating in BMC mode.

Bug Fixes:

  • Use pfn_to_page for physical address translation in GEM.
  • Correct eDP backlight minimum and maximum level definitions.
  • Fix incorrect Hot Plug Detect (HPD) interrupt mask value.
  • Remove potentially incorrect framebuffer device destroy callback.

Enhancements:

  • Conditionally utilize NEON/FPU instructions for scaling calculations on relevant architectures.
  • Set the DRM driver name dynamically based on the detected hardware platform (e.g., PE220X).
  • Adjust the maximum reported display resolution for the PE220X platform.

Build:

  • Add specific FPU compiler flags for x86 architecture when building scaling code.

Chores:

  • Add a driver version string.

Copy link

sourcery-ai bot commented Apr 27, 2025

Reviewer's Guide by Sourcery

The pull request refactors the Phytium Display Engine driver to add support for display scaling, introduce specific handling for BMC mode (including disabling the cursor plane and using different primary formats), and change backlight/panel power control to use PWM and GPIO instead of command registers. It also includes architecture-specific FPU handling and various minor fixes.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implemented display scaling logic and configuration.
  • Added helper functions for calculating scaling factors and filter weights.
  • Implemented the main scaling configuration function.
  • Integrated scaling setup into the CRTC atomic enable path.
drivers/gpu/drm/phytium/phytium_crtc.c
Added specific handling and features for BMC mode operation.
  • Modified DC reset logic for BMC mode.
  • Added a specific primary format function for BMC mode.
  • Conditionally disabled the cursor plane creation in BMC mode.
  • Updated plane format selection based on BMC mode.
  • Set the bmc_mode flag in device info.
  • Added an ioctl to check BMC mode.
  • Made gamma enable conditional on BMC mode.
drivers/gpu/drm/phytium/phytium_crtc.c
drivers/gpu/drm/phytium/pe220x_dc.c
drivers/gpu/drm/phytium/phytium_plane.c
drivers/gpu/drm/phytium/phytium_pci.c
drivers/gpu/drm/phytium/phytium_platform.c
drivers/gpu/drm/phytium/phytium_display_drv.c
drivers/gpu/drm/phytium/pe220x_dc.h
Switched backlight and panel power control from command registers to PWM and GPIO.
  • Modified power on/off and enable/disable functions to use GPIOs and PWM.
  • Updated backlight get/set functions to interact with PWM.
  • Added resource handling (get/put) for PWM and GPIOs in platform initialization/finalization.
  • Updated device info structs to include PWM and backlight min level.
  • Assigned PWM device to DP struct.
drivers/gpu/drm/phytium/pe220x_dp.c
drivers/gpu/drm/phytium/phytium_platform.c
drivers/gpu/drm/phytium/phytium_display_drv.h
drivers/gpu/drm/phytium/phytium_dp.c
drivers/gpu/drm/phytium/phytium_panel.c
drivers/gpu/drm/phytium/pe220x_dp.h
drivers/gpu/drm/phytium/px210_dp.h
Added conditional includes and build flags for Floating Point Unit (FPU) usage.
  • Added conditional includes for NEON and FPU API headers based on architecture.
  • Added FPU CFLAGS to the Makefile for phytium_crtc.o on x86.
drivers/gpu/drm/phytium/phytium_crtc.c
drivers/gpu/drm/phytium/pe220x_dc.c
drivers/gpu/drm/phytium/px210_dc.c
drivers/gpu/drm/phytium/Makefile
Included various small fixes and updates.
  • Updated phys_to_page calls.
  • Removed phytium_fbdev_destroy function.
  • Updated HPD interrupt mask.
  • Reduced max display resolution for PE220X.
  • Changed logging levels for bpc/color format checks.
  • Added driver version string.
drivers/gpu/drm/phytium/phytium_gem.c
drivers/gpu/drm/phytium/phytium_fbdev.c
drivers/gpu/drm/phytium/phytium_reg.h
drivers/gpu/drm/phytium/pe220x_dc.h
drivers/gpu/drm/phytium/phytium_dp.c
drivers/gpu/drm/phytium/phytium_display_drv.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign opsiff for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @xuyan213 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider refactoring duplicated code sections, such as the platform initialization and DC reset logic.
  • Explore using standard kernel APIs for the scaling calculations instead of custom floating-point math and manual FPU/NEON handling.
  • Review the placement and necessity of the architecture-specific FPU/NEON conditional compilation added in multiple files.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

uint32_t dst_size,
struct filter_blit_array *kernel_info)
{
uint32_t scale_factor;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting the weight computation and normalization loops in dc_calculate_sync_table() into a separate helper function to improve readability and maintainability.

It might help to extract parts of the inner loops from dc_calculate_sync_table() into separate helper functions. For example, consider moving the weight computation and normalization (the two inner loops) into a helper like:

static void compute_kernel_weights(float *fSubpixelSet, uint16_t *kernel_array,
                                   int kernel_half, int kernelSize, float f_subpixel_offset, float f_scale) {
    float fWeightSum = 0.0f;
    int kernel_pos, index;
    int padding = (MAXKERNELSIZE - kernelSize) / 2;
    for (kernel_pos = 0; kernel_pos < MAXKERNELSIZE; kernel_pos++) {
        index = kernel_pos - padding;
        if (index < 0 || index >= kernelSize) {
            fSubpixelSet[kernel_pos] = 0.0f;
        } else if (kernelSize == 1) {
            fSubpixelSet[kernel_pos] = 1.0f;
        } else {
            float fX = MATH_Add(MATH_I2Float(index - kernel_half), f_subpixel_offset);
            fX = MATH_Multiply(fX, f_scale);
            fSubpixelSet[kernel_pos] = dc_sinc_filter(fX, kernel_half);
        }
        fWeightSum = MATH_Add(fWeightSum, fSubpixelSet[kernel_pos]);
    }

    for (kernel_pos = 0; kernel_pos < MAXKERNELSIZE; kernel_pos++) {
        float fWeight = MATH_Divide(fSubpixelSet[kernel_pos], fWeightSum);
        if (fWeight == 0.0f)
            kernel_array[kernel_pos] = 0x0000;
        else if (fWeight >= 1.0f)
            kernel_array[kernel_pos] = 0x4000;
        else if (fWeight <= -1.0f)
            kernel_array[kernel_pos] = 0xC000;
        else
            kernel_array[kernel_pos] = (int16_t) MATH_Multiply(fWeight, 16384.0f);
    }
}

Then, in dc_calculate_sync_table() you simply call this helper inside your subpixel loop:

for (subpixel_pos = 0; subpixel_pos < SUBPIXELLOADCOUNT; subpixel_pos++) {
    float fSubpixelSet[MAXKERNELSIZE];
    compute_kernel_weights(fSubpixelSet, kernel_array, kernel_half,
                           kernel_info->kernelSize, f_subpixel_offset, f_scale);
    /* ... remaining adjustments and table update ... */
    kernel_array += MAXKERNELSIZE;
    f_subpixel_offset = MATH_Add(f_subpixel_offset, -f_subpixel_step);
}

This refactoring reduces nesting in the main function and isolates the weight computation logic, making it easier to maintain while preserving functionality.

@xuyan213
Copy link
Author

/retest

@@ -16,3 +16,8 @@ phytium-dc-drm-y := phytium_display_drv.o \

obj-$(CONFIG_DRM_PHYTIUM) += phytium-dc-drm.o
CFLAGS_REMOVE_phytium_crtc.o += -mgeneral-regs-only
ifeq ($(ARCH), x86)
FPU_CFLAGS += -mhard-float
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-19: error: unsupported option '-mhard-float' for target 'x86_64-linux-gnu'

@xuyan213
Copy link
Author

/retest

@Avenger-285714
Copy link
Collaborator

/retest

由于当前x86未开启phytium drm所以ci检测不出编译错误,clang的x86 target不支持-mhard-float

@@ -16,3 +16,12 @@ phytium-dc-drm-y := phytium_display_drv.o \

obj-$(CONFIG_DRM_PHYTIUM) += phytium-dc-drm.o
CFLAGS_REMOVE_phytium_crtc.o += -mgeneral-regs-only
ifeq ($(ARCH), x86)
ifeq ($(shell uname -m), x86_64)
FPU_CFLAGS +=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@xuyan213 xuyan213 force-pushed the drm branch 2 times, most recently from bb3406a to a1a1a15 Compare May 14, 2025 08:28
modified this files to support Phytium Display Engine  more.

Signed-off-by: Xu Yan <[email protected]>
Signed-off-by: Yang Xun <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
@Avenger-285714 Avenger-285714 merged commit 6a4f1c9 into deepin-community:linux-6.6.y May 14, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants