From 69fdc6be3bca0243c8fe939bb81ce92ea616e1dd Mon Sep 17 00:00:00 2001 From: Anarchos Date: Fri, 17 Dec 2021 16:25:25 +0100 Subject: [PATCH] radeon_hd : control of brightness -detect if model > HD600 -apply change by calling ATOM_TRANSMITTER_ACTION_BL_BRIGHTNESS_CONTROL and ATOM_TRANSMITTER_ACTION_LCD_BLON Author : Anarchos Change-Id: I30b9dd66c71e05427b827fc3ef2c7fa6c498646f Reviewed-on: https://review.haiku-os.org/c/haiku/+/2786 Tested-by: Commit checker robot Reviewed-by: Alex von Gluck IV Reviewed-by: Adrien Destugues --- .../accelerants/radeon_hd/accelerant_protos.h | 4 ++ src/add-ons/accelerants/radeon_hd/hooks.cpp | 4 ++ src/add-ons/accelerants/radeon_hd/mode.cpp | 63 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/src/add-ons/accelerants/radeon_hd/accelerant_protos.h b/src/add-ons/accelerants/radeon_hd/accelerant_protos.h index 1f75ee39b0..324d005f13 100644 --- a/src/add-ons/accelerants/radeon_hd/accelerant_protos.h +++ b/src/add-ons/accelerants/radeon_hd/accelerant_protos.h @@ -38,6 +38,10 @@ status_t radeon_get_pixel_clock_limits(display_mode* mode, uint32* low, uint32* high); status_t radeon_get_edid_info(void* info, size_t size, uint32* edid_version); +//brightness +status_t radeon_set_brightness(float brightness); +status_t radeon_get_brightness(float* brightness); + // accelerant engine uint32 radeon_accelerant_engine_count(void); status_t radeon_acquire_engine(uint32 capabilities, uint32 maxWait, diff --git a/src/add-ons/accelerants/radeon_hd/hooks.cpp b/src/add-ons/accelerants/radeon_hd/hooks.cpp index 238c9624e8..2c6a69b2aa 100644 --- a/src/add-ons/accelerants/radeon_hd/hooks.cpp +++ b/src/add-ons/accelerants/radeon_hd/hooks.cpp @@ -54,6 +54,10 @@ get_accelerant_hook(uint32 feature, void* data) return (void*)radeon_set_display_mode; case B_GET_DISPLAY_MODE: return (void*)radeon_get_display_mode; + case B_GET_BRIGHTNESS: + return (void*)radeon_get_brightness; + case B_SET_BRIGHTNESS: + return (void*)radeon_set_brightness; /* memory controller */ case B_GET_FRAME_BUFFER_CONFIG: diff --git a/src/add-ons/accelerants/radeon_hd/mode.cpp b/src/add-ons/accelerants/radeon_hd/mode.cpp index d6494b81f4..664e3fe9d3 100644 --- a/src/add-ons/accelerants/radeon_hd/mode.cpp +++ b/src/add-ons/accelerants/radeon_hd/mode.cpp @@ -445,3 +445,66 @@ get_mode_bpp(display_mode* mode) __func__); return 32; } + + +static uint32_t +radeon_get_backlight_register() +{ + // R600 and up is 0x172c else its 0x0018 + if (gInfo->shared_info->chipsetID >= RADEON_R600) + return 0x172c; + return 0x0018; +} + + +status_t +radeon_set_brightness(float brightness) +{ + TRACE("%s (%f)\n", __func__, brightness); + + if (brightness < 0 || brightness > 1) + return B_BAD_VALUE; + + uint32_t backlightReg = radeon_get_backlight_register(); + uint8_t brightnessRaw = (uint8_t)ceilf(brightness * 255); + uint32_t level = Read32(OUT, backlightReg); + TRACE("brightness level = %lx\n", level); + level &= ~ATOM_S2_CURRENT_BL_LEVEL_MASK; + level |= (( brightnessRaw << ATOM_S2_CURRENT_BL_LEVEL_SHIFT ) + & ATOM_S2_CURRENT_BL_LEVEL_MASK); + TRACE("new brightness level = %lx\n", level); + + Write32(OUT, backlightReg, level); + + //TODO crtcID = 0: see create_mode + // TODO: multi-monitor? for now we use VESA and not gDisplay edid + uint8 crtcID = 0; + //TODO : test if it is a LCD ? + uint32 connectorIndex = gDisplay[crtcID]->connectorIndex; + connector_info* connector = gConnector[connectorIndex]; + pll_info* pll = &connector->encoder.pll; + + transmitter_dig_setup(connectorIndex, pll->pixelClock, + 0, 0, ATOM_TRANSMITTER_ACTION_BL_BRIGHTNESS_CONTROL); + transmitter_dig_setup(connectorIndex, pll->pixelClock, + 0, 0, ATOM_TRANSMITTER_ACTION_LCD_BLON); + + return B_OK; +} + + +status_t +radeon_get_brightness(float* brightness) +{ + TRACE("%s\n", __func__); + + if (brightness == NULL) + return B_BAD_VALUE; + + uint32_t backlightReg = Read32(OUT, radeon_get_backlight_register()); + uint8_t brightnessRaw = ((backlightReg & ATOM_S2_CURRENT_BL_LEVEL_MASK) >> + ATOM_S2_CURRENT_BL_LEVEL_SHIFT); + *brightness = (float)brightnessRaw / 255; + + return B_OK; +}