intel_extreme: set/get brightness in legacy mode for gen2,i915GM,i945GM
untested, see #15448 Change-Id: Iaf0cdacd39ebadfc143b072bdd6f5435a1394f45 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5222 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
1043e934e4
commit
6c02429697
@@ -398,7 +398,9 @@ enum {
|
||||
|
||||
INTEL_GET_DEVICE_NAME,
|
||||
INTEL_ALLOCATE_GRAPHICS_MEMORY,
|
||||
INTEL_FREE_GRAPHICS_MEMORY
|
||||
INTEL_FREE_GRAPHICS_MEMORY,
|
||||
INTEL_GET_BRIGHTNESS_LEGACY,
|
||||
INTEL_SET_BRIGHTNESS_LEGACY
|
||||
};
|
||||
|
||||
// retrieve the area_id of the kernel/accelerant shared info
|
||||
@@ -422,6 +424,12 @@ struct intel_free_graphics_memory {
|
||||
addr_t buffer_base;
|
||||
};
|
||||
|
||||
// brightness legacy
|
||||
struct intel_brightness_legacy {
|
||||
uint32 magic;
|
||||
uint8 lpc;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Register definitions, taken from X driver
|
||||
|
||||
@@ -535,6 +543,9 @@ struct intel_free_graphics_memory {
|
||||
#define BDW_GTT_SIZE_4MB (2 << 6)
|
||||
#define BDW_GTT_SIZE_8MB (3 << 6)
|
||||
|
||||
// Gen2, i915GM, i945GM
|
||||
#define LEGACY_BACKLIGHT_BRIGHTNESS 0xf4
|
||||
|
||||
// graphics page translation table
|
||||
#define INTEL_PAGE_TABLE_CONTROL 0x02020
|
||||
#define PAGE_TABLE_ENABLED 0x00000001
|
||||
@@ -1218,6 +1229,7 @@ struct intel_free_graphics_memory {
|
||||
#define MCH_BLC_PWM_CTL (0x1254 | REGS_NORTH_PIPE_AND_PORT)
|
||||
// Linux VLV_BLC_PWM_CTL (one register per pipe) or BLC_PWM_CTL (a single register that can be
|
||||
// programmed for use on either pipe)
|
||||
#define BLM_LEGACY_MODE (1 << 16)
|
||||
|
||||
// ring buffer commands
|
||||
|
||||
|
||||
@@ -633,6 +633,13 @@ intel_set_brightness(float brightness)
|
||||
} else {
|
||||
// On older devices there is a single register with both period and duty cycle
|
||||
uint32 tmp = read32(intel_get_backlight_register(true));
|
||||
bool legacyMode = false;
|
||||
if (gInfo->shared_info->device_type.Generation() == 2
|
||||
|| gInfo->shared_info->device_type.IsModel(INTEL_MODEL_915M)
|
||||
|| gInfo->shared_info->device_type.IsModel(INTEL_MODEL_945M)) {
|
||||
legacyMode = (tmp & BLM_LEGACY_MODE) != 0;
|
||||
}
|
||||
|
||||
uint32_t period = tmp >> 16;
|
||||
|
||||
uint32_t mask = 0xffff;
|
||||
@@ -645,7 +652,21 @@ intel_set_brightness(float brightness)
|
||||
shift = 1;
|
||||
period = tmp >> 17;
|
||||
}
|
||||
if (legacyMode)
|
||||
period *= 0xfe;
|
||||
uint32_t duty = (uint32_t)(period * brightness);
|
||||
if (legacyMode) {
|
||||
uint8 lpc = duty / 0xff + 1;
|
||||
duty /= lpc;
|
||||
|
||||
// set pci config reg with lpc
|
||||
intel_brightness_legacy brightnessLegacy;
|
||||
brightnessLegacy.magic = INTEL_PRIVATE_DATA_MAGIC;
|
||||
brightnessLegacy.lpc = lpc;
|
||||
ioctl(gInfo->device, INTEL_SET_BRIGHTNESS_LEGACY, &brightnessLegacy,
|
||||
sizeof(brightnessLegacy));
|
||||
}
|
||||
|
||||
duty = std::max(duty, (uint32_t)gInfo->shared_info->min_brightness);
|
||||
duty <<= shift;
|
||||
|
||||
@@ -671,9 +692,25 @@ intel_get_brightness(float* brightness)
|
||||
period = read32(intel_get_backlight_register(true));
|
||||
duty = read32(intel_get_backlight_register(false));
|
||||
} else {
|
||||
period = read32(intel_get_backlight_register(true)) >> 16;
|
||||
uint32 tmp = read32(intel_get_backlight_register(true));
|
||||
bool legacyMode = false;
|
||||
if (gInfo->shared_info->device_type.Generation() == 2
|
||||
|| gInfo->shared_info->device_type.IsModel(INTEL_MODEL_915M)
|
||||
|| gInfo->shared_info->device_type.IsModel(INTEL_MODEL_945M)) {
|
||||
legacyMode = (tmp & BLM_LEGACY_MODE) != 0;
|
||||
}
|
||||
period = tmp >> 16;
|
||||
duty = read32(intel_get_backlight_register(false)) & 0xffff;
|
||||
if (legacyMode) {
|
||||
period *= 0xff;
|
||||
|
||||
// get lpc from pci config reg
|
||||
intel_brightness_legacy brightnessLegacy;
|
||||
brightnessLegacy.magic = INTEL_PRIVATE_DATA_MAGIC;
|
||||
ioctl(gInfo->device, INTEL_GET_BRIGHTNESS_LEGACY, &brightnessLegacy,
|
||||
sizeof(brightnessLegacy));
|
||||
duty *= brightnessLegacy.lpc;
|
||||
}
|
||||
if (gInfo->shared_info->device_type.Generation() < 4) {
|
||||
period >>= 1;
|
||||
duty >>= 1;
|
||||
|
||||
@@ -337,6 +337,27 @@ device_ioctl(void* data, uint32 op, void* buffer, size_t bufferLength)
|
||||
break;
|
||||
}
|
||||
|
||||
case INTEL_GET_BRIGHTNESS_LEGACY:
|
||||
case INTEL_SET_BRIGHTNESS_LEGACY:
|
||||
{
|
||||
intel_brightness_legacy brightnessLegacy;
|
||||
if (user_memcpy(&brightnessLegacy, buffer,
|
||||
sizeof(brightnessLegacy)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
if (brightnessLegacy.magic != INTEL_PRIVATE_DATA_MAGIC)
|
||||
break;
|
||||
if (op == INTEL_GET_BRIGHTNESS_LEGACY) {
|
||||
brightnessLegacy.lpc = get_pci_config(info->pci, LEGACY_BACKLIGHT_BRIGHTNESS, 1);
|
||||
// copy result
|
||||
if (user_memcpy(buffer, &brightnessLegacy, sizeof(brightnessLegacy)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
} else {
|
||||
set_pci_config(info->pci, LEGACY_BACKLIGHT_BRIGHTNESS, 1, brightnessLegacy.lpc);
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
default:
|
||||
ERROR("ioctl() unknown message %" B_PRIu32 " (length = %"
|
||||
B_PRIuSIZE ")\n", op, bufferLength);
|
||||
|
||||
Reference in New Issue
Block a user