Skip to content

Commit

Permalink
Tweak backlight control path configuration
Browse files Browse the repository at this point in the history
A way to explicitly define for backlight brightness control paths has
been implemented a long time ago. However it uses hard-coded key names
that do not follow the conventions used in the rest of the mce code base.

Fix configuration item naming and use constants instead of hard-coding.

Warn if number of possible brightness control files differs from the
number of possible maximum brightness files.

Add an example configuration ini-file.

[mce] Tweak backlight control path configuration. Fixes MER#977
  • Loading branch information
spiiroin committed May 7, 2015
1 parent e592a8b commit eca6671
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
21 changes: 21 additions & 0 deletions inifiles/backlight.ini
@@ -0,0 +1,21 @@
# Configuration file for MCE - display brightness control paths
#
# Normally MCE locates display backlight control files by probing
# few standard places under sysfs. In case the control files are
# in non-standard directories or probing produces false positive
# hits, a hardware adaptation specific configuration file should
# be used to define alternative sets of paths to check before
# generic probing.

[Display]

# Semicolon separated list of directories that contain writable
# "brightness" and readable "max_brightness" files.
#BrightnessDirectory=/sys/devices/i2c-0/0-0036/leds/lm3533-lcd-bl

# In case the control files do not follow the "brightness" and
# "max_brightness" pattern, semicolon separated list of full paths
# can be defined. Note that BrightnessPath and MaxBrightnessPath
# lists must have equal number of entries.
#BrightnessPath=/sys/path/to/brightness_file
#MaxBrightnessPath=/sys/path/to/max_brightness_file
53 changes: 32 additions & 21 deletions modules/display.c
Expand Up @@ -3918,7 +3918,7 @@ static gboolean mdy_display_type_probe_brightness(const gchar *dirpath,
return res;
}

/** Get the display type from [modules/display] config group
/** Get the display type from MCE_CONF_DISPLAY_GROUP config group
*
* @param display_type where to store the selected display type
*
Expand All @@ -3927,20 +3927,23 @@ static gboolean mdy_display_type_probe_brightness(const gchar *dirpath,

static gboolean mdy_display_type_get_from_config(display_type_t *display_type)
{
static const gchar group[] = "modules/display";

gboolean res = FALSE;
gchar *set = 0;
gchar *max = 0;

gchar **vdir = 0;
gchar **vset = 0;
gchar **vmax = 0;
gsize nset = 0;
gsize nmax = 0;

/* First check if we have a configured brightness directory
* that a) exists and b) contains both brightness and
* max_brightness files */
if( (vdir = mce_conf_get_string_list(group, "brightness_dir", 0)) ) {

vdir = mce_conf_get_string_list(MCE_CONF_DISPLAY_GROUP,
MCE_CONF_BACKLIGHT_DIRECTORY, 0);
if( vdir ) {
for( size_t i = 0; vdir[i]; ++i ) {
if( !*vdir[i] || g_access(vdir[i], F_OK) )
continue;
Expand All @@ -3952,24 +3955,32 @@ static gboolean mdy_display_type_get_from_config(display_type_t *display_type)

/* Then check if we can find mathes from possible brightness and
* max_brightness file lists */
if( !(vset = mce_conf_get_string_list(group, "brightness", 0)) )
goto EXIT;

if( !(vmax = mce_conf_get_string_list(group, "max_brightness", 0)) )
goto EXIT;
vset = mce_conf_get_string_list(MCE_CONF_DISPLAY_GROUP,
MCE_CONF_BACKLIGHT_PATH, &nset);

for( size_t i = 0; vset[i]; ++i ) {
if( *vset[i] && !g_access(vset[i], W_OK) ) {
set = g_strdup(vset[i]);
break;
}
vmax = mce_conf_get_string_list(MCE_CONF_DISPLAY_GROUP,
MCE_CONF_MAX_BACKLIGHT_PATH, &nmax);

if( nset != nmax ) {
mce_log(LL_WARN, "%s and %s do not have the same amount of "
"configuration entries",
MCE_CONF_BACKLIGHT_PATH, MCE_CONF_MAX_BACKLIGHT_PATH);
}

for( size_t i = 0; vmax[i]; ++i ) {
if( *vmax[i] && !g_access(vmax[i], R_OK) ) {
max = g_strdup(vmax[i]);
break;
}
if( nset > nmax )
nset = nmax;

for( gsize i = 0; i < nset; ++i ) {
if( *vset[i] == 0 || g_access(vset[i], W_OK) != 0 )
continue;

if( *vmax[i] == 0 || g_access(vmax[i], R_OK) != 0 )
continue;

set = g_strdup(vset[i]);
max = g_strdup(vmax[i]);
break;
}

EXIT:
Expand All @@ -3979,12 +3990,12 @@ static gboolean mdy_display_type_get_from_config(display_type_t *display_type)
mce_log(LL_NOTICE, "brightness path = %s", set);
mce_log(LL_NOTICE, "max_brightness path = %s", max);

mdy_brightness_level_output.path = set, set = 0;
mdy_brightness_level_maximum_path = max, max = 0;
mdy_brightness_level_output.path = set, set = 0;
mdy_brightness_level_maximum_path = max, max = 0;

mdy_cabc_mode_file = 0;
mdy_cabc_available_modes_file = 0;
mdy_cabc_is_supported = 0;
mdy_cabc_is_supported = 0;

*display_type = DISPLAY_TYPE_GENERIC;
res = TRUE;
Expand Down
12 changes: 12 additions & 0 deletions modules/display.h
Expand Up @@ -21,6 +21,18 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_

/** Name of the display backlight configuration group */
#define MCE_CONF_DISPLAY_GROUP "Display"

/** List of backlight control directories to try */
#define MCE_CONF_BACKLIGHT_DIRECTORY "BrightnessDirectory"

/** List of backlight control files to try */
#define MCE_CONF_BACKLIGHT_PATH "BrightnessPath"

/** List of max backlight control files to try */
#define MCE_CONF_MAX_BACKLIGHT_PATH "MaxBrightnessPath"

/** Default timeout for the high brightness mode; in seconds */
#define DEFAULT_HBM_TIMEOUT 1800 /* 30 min */

Expand Down

0 comments on commit eca6671

Please sign in to comment.