Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Forked from hadess/tmp.c
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invisiblek/19e6eeb3776be90c748a to your computer and use it in GitHub Desktop.
Save invisiblek/19e6eeb3776be90c748a to your computer and use it in GitHub Desktop.
Hack to control the keyboard backlight level on a ideapad y50
/* gcc -o tmp `pkg-config --libs --cflags glib-2.0` tmp.c
*
* # modprobe ec_sys
*
* # watch -n 0.1 hexdump -C /sys/kernel/debug/ec/ec0/io
*
* Modified for ideapad y50
*
* 00000000 00 00 00 03 00 00 28 00 10 10 80 00 08 43 00 00 |......(......C..|
* 00000000 00 00 00 02 00 00 28 00 10 10 80 00 08 43 00 00 |......(......C..|
* 00000000 00 00 00 02 00 00 28 00 10 10 80 00 08 43 00 00 |......(......C..|
*
* # ./tmp 0
* # ./tmp 1
* # ./tmp 2
*
*/
#include <glib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
char levels[] = {
0x03,
0x02,
0x00 // unsure here, cannot find where to enable high brightness
};
static void
usage (char **argv)
{
g_print ("%s [level]\n", argv[0]);
g_print ("Where level is between 1 and 3\n");
}
int main (int argc, char **argv)
{
int fd;
int level;
if (argc < 2) {
usage (argv);
return 1;
}
level = atoi(argv[1]);
if (level < 0 || level > 3) {
usage (argv);
return 1;
}
fd = open ("/sys/kernel/debug/ec/ec0/io", O_RDWR);
if (fd < 0) {
g_print ("open: %s\n", g_strerror (errno));
return 1;
}
if (lseek (fd, 0x3, SEEK_CUR) < 0) {
g_print ("seek: %s\n", g_strerror (errno));
return 1;
}
if (write (fd, &levels[level], 1) < 0) {
g_print ("write: %s\n", g_strerror (errno));
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment