Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: ACPI display brightness on Lenovo Thinkpad T430s
Hi,
FWIW, I've been successfully using the following patch for quite some
time. It allows to set the brightness on Intel hw with wsconsctl and
xrandr --output XXX --set BACKLIGHT YYY.
It doesn't use ACPI though, but relies on the code in the DRM/KMS kernel
driver.
Regards,
Aymeric
diff -r 6b4d07813856 sys/external/bsd/drm2/dist/drm/i915/intel_panel.c
--- a/sys/external/bsd/drm2/dist/drm/i915/intel_panel.c Sun Mar 07 19:06:20 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/intel_panel.c Thu Mar 11 14:52:04 2021 +0100
@@ -432,7 +432,7 @@
return target_val;
}
-#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+#if 1
/* Scale user_level in range [0..user_max] to [hw_min..hw_max]. */
static inline u32 scale_user_to_hw(struct intel_connector *connector,
u32 user_level, u32 user_max)
@@ -677,9 +677,11 @@
panel->backlight.set(connector, level);
}
-#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
+#if 1
+void intel_panel_set_backlight(struct intel_connector *, u32, u32);
+
/* set backlight brightness to level in range [0..max], scaling wrt hw min */
-static void intel_panel_set_backlight(struct intel_connector *connector,
+void intel_panel_set_backlight(struct intel_connector *connector,
u32 user_level, u32 user_max)
{
struct drm_device *dev = connector->base.dev;
diff -r 6b4d07813856 sys/external/bsd/drm2/i915drm/intelfb.c
--- a/sys/external/bsd/drm2/i915drm/intelfb.c Sun Mar 07 19:06:20 2021 +0000
+++ b/sys/external/bsd/drm2/i915drm/intelfb.c Thu Mar 11 14:52:04 2021 +0100
@@ -55,12 +55,18 @@
static paddr_t intelfb_drmfb_mmapfb(struct drmfb_softc *, off_t, int);
+static int intelfb_get_brightness(void *, int *);
+static int intelfb_set_brightness(void *, int);
+static int intelfb_upd_brightness(void *, int);
+
struct intelfb_softc {
struct drmfb_softc sc_drmfb; /* XXX Must be first. */
device_t sc_dev;
struct intelfb_attach_args sc_ifa;
bus_space_handle_t sc_fb_bsh;
struct i915drmkms_task sc_attach_task;
+ struct genfb_parameter_callback genfb_brightness_params;
+ int current_brightness;
bool sc_mapped:1;
bool sc_scheduled:1;
bool sc_attached:1;
@@ -97,6 +103,8 @@
sc->sc_scheduled = false;
sc->sc_attached = false;
+ sc->current_brightness = 255;
+
aprint_naive("\n");
aprint_normal("\n");
@@ -166,6 +174,7 @@
struct intelfb_softc *const sc = container_of(task,
struct intelfb_softc, sc_attach_task);
const struct intelfb_attach_args *const ifa = &sc->sc_ifa;
+ prop_dictionary_t dict = device_properties(sc->sc_dev);
const struct drmfb_attach_args da = {
.da_dev = sc->sc_dev,
.da_fb_helper = ifa->ifa_fb_helper,
@@ -176,6 +185,17 @@
};
int error;
+ sc->genfb_brightness_params.gpc_cookie = sc;
+ sc->genfb_brightness_params.gpc_get_parameter = intelfb_get_brightness;
+ sc->genfb_brightness_params.gpc_set_parameter = intelfb_set_brightness;
+ sc->genfb_brightness_params.gpc_upd_parameter = intelfb_upd_brightness;
+
+ if (!prop_dictionary_set_uint64(dict, "brightness_callback",
+ (uint64_t) (intptr_t) &sc->genfb_brightness_params)) {
+ aprint_error_dev(sc->sc_dev,
+ "Could not set brightness callback");
+ }
+
error = drmfb_attach(&sc->sc_drmfb, &da);
if (error) {
aprint_error_dev(sc->sc_dev, "failed to attach drmfb: %d\n",
@@ -218,3 +238,45 @@
i915_gem_obj_ggtt_offset(fbdev->fb->obj) + offset,
prot, BUS_SPACE_MAP_PREFETCHABLE);
}
+
+static int
+intelfb_get_brightness(void *cookie, int *valp) {
+ struct intelfb_softc *sc = cookie;
+
+ *valp = sc->current_brightness;
+
+ return 0;
+}
+
+void intel_panel_set_backlight(struct intel_connector *, u32, u32);
+
+static int
+intelfb_set_brightness(void *cookie, int val) {
+ struct intelfb_softc *sc = cookie;
+ struct drm_fb_helper *const fb_helper = sc->sc_ifa.ifa_fb_helper;
+ unsigned i;
+
+ sc->current_brightness = val;
+
+ for (i = 0; i < fb_helper->connector_count; i++) {
+ struct intel_connector *const connector =
+ (struct intel_connector *const)
+ fb_helper->connector_info[i]->connector;
+ intel_panel_set_backlight(connector, val, 255);
+ }
+
+ return 0;
+}
+
+static int
+intelfb_upd_brightness(void *cookie, int delta) {
+ struct intelfb_softc *sc = cookie;
+ int new_val = sc->current_brightness + delta;
+
+ if (new_val < 0)
+ new_val = 0;
+ if (new_val > 255)
+ new_val = 255;
+
+ return intelfb_set_brightness(cookie, new_val);
+}
Home |
Main Index |
Thread Index |
Old Index