Skip to content
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

[f5121] Xiaomi Redmi 5 Plus (vince) compatibility fixes #43

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions inifiles/60-f5121.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ BlueDirectory=/sys/class/leds/blue
#RedMaxBrightnessFile=/sys/class/leds/red/max_brightness
#RedBlinkFile=/sys/class/leds/red/blink
# ... and similarly for Green and Blue.

# Optional max_brightness override
# At least in Sony Xperia X / f5121 max_brightness files do not
# contain true maximum brightness. Additionally the values that
# are present by default are such that they cause led color
# representation to be skewed. In such cases these configuration
# entries can be used for overriding max_brightness content for
# all / select channels.
#MaxBrightnessOverride=255
#RedMaxBrightnessOverride=255
#GreenMaxBrightnessOverride=255
#BlueMaxBrightnessOverride=255
8 changes: 8 additions & 0 deletions inifiles/60-vince.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[LEDConfigHybris]

# Vince is compatible with f5121 backend
BackEnd=f5121

RedDirectory=/sys/class/leds/red
GreenDirectory=/sys/class/leds/red
BlueDirectory=/sys/class/leds/red
28 changes: 21 additions & 7 deletions sysfs-led-f5121.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct
const char *max_brightness;
const char *brightness;
const char *blink;
const char *max_brightness_override;
} led_paths_f5121_t;

typedef struct
Expand Down Expand Up @@ -127,17 +128,24 @@ led_channel_f5121_probe(led_channel_f5121_t *self,
if( !sysfsval_open_rw(self->cached_blink, path->blink) )
goto cleanup;

if( !sysfsval_open_ro(self->cached_max_brightness, path->max_brightness) )
if( !sysfsval_open_rw(self->cached_max_brightness, path->max_brightness) )
goto cleanup;

/* The 'max_brightness' seems to be dynamic. Make an attempt
* to set it to an artificially high value and assume that kernel
* side will cap the value to the true maximum... */
#if 0 // TODO: make a QUIRK out of this
sysfsval_set(self->cached_max_brightness, 255);
#endif
/* If MaxBrightnessOverride has been configured, it will be used
* instead of content of max_brightness file.
*/

int max_brightness_override = 0;
if( path->max_brightness_override )
max_brightness_override = strtol(path->max_brightness_override, NULL, 0);
if( max_brightness_override > 0 )
sysfsval_set(self->cached_max_brightness, max_brightness_override);

sysfsval_refresh(self->cached_max_brightness);

mce_log(LOG_DEBUG, "%s: effective = %d", path->max_brightness,
sysfsval_get(self->cached_max_brightness));

if( sysfsval_get(self->cached_max_brightness) <= 0 )
goto cleanup;

Expand Down Expand Up @@ -259,16 +267,19 @@ led_control_f5121_static_probe(led_channel_f5121_t *channel)
.max_brightness = "/sys/class/leds/led:rgb_red/max_brightness",
.brightness = "/sys/class/leds/led:rgb_red/brightness",
.blink = "/sys/class/leds/led:rgb_red/blink",
.max_brightness_override = "255",
},
{
.max_brightness = "/sys/class/leds/led:rgb_green/max_brightness",
.brightness = "/sys/class/leds/led:rgb_green/brightness",
.blink = "/sys/class/leds/led:rgb_green/blink",
.max_brightness_override = "255",
},
{
.max_brightness = "/sys/class/leds/led:rgb_blue/max_brightness",
.brightness = "/sys/class/leds/led:rgb_blue/brightness",
.blink = "/sys/class/leds/led:rgb_blue/blink",
.max_brightness_override = "255",
},
},
{
Expand Down Expand Up @@ -313,6 +324,9 @@ led_control_f5121_dynamic_probe(led_channel_f5121_t *channel)
OBJCONF_FILE(led_paths_f5121_t, brightness, Brightness),
OBJCONF_FILE(led_paths_f5121_t, max_brightness, MaxBrightness),
OBJCONF_FILE(led_paths_f5121_t, blink, Blink),

OBJCONF_STRING(led_paths_f5121_t, max_brightness_override, MaxBrightnessOverride, NULL),

OBJCONF_STOP
};

Expand Down
9 changes: 9 additions & 0 deletions sysfs-val.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct sysfsval_t
char *sv_path;
int sv_file;
int sv_curr;
int sv_mode;
};

/* ========================================================================= *
Expand Down Expand Up @@ -77,6 +78,7 @@ sysfsval_ctor(sysfsval_t *self)
self->sv_path = 0;
self->sv_file = -1;
self->sv_curr = -1;
self->sv_mode = O_RDONLY;
}

/** Release all dynamically allocated resources used by sysfsval_t object
Expand Down Expand Up @@ -171,6 +173,8 @@ sysfsval_open_ex(sysfsval_t *self, const char *path, mode_t mode)

mce_log(LOG_DEBUG, "%s: opened", sysfsval_path(self));

self->sv_mode = mode;

/* Note: Current value is not fetched by default */

ack = true;
Expand All @@ -189,6 +193,8 @@ sysfsval_open_ex(sysfsval_t *self, const char *path, mode_t mode)
void
sysfsval_close(sysfsval_t *self)
{
self->sv_mode = O_RDONLY;

if( self->sv_file != -1 ) {
mce_log(LOG_DEBUG, "%s: closed", sysfsval_path(self));
close(self->sv_file), self->sv_file = -1;
Expand Down Expand Up @@ -242,6 +248,9 @@ sysfsval_set(sysfsval_t *self, int value)
if( prev == self->sv_curr )
goto EXIT;

if( self->sv_mode == O_RDONLY )
goto EXIT;

/* If file is closed: assume it was optional and do not
* spam journal with transitions related to it */
if( self->sv_file == -1 )
Expand Down