From: gimli <gi...@da...> - 2006-04-16 22:27:35
|
Great work. Nicolas Boichat wrote: > Hi, > > I just got initial support for LCD backlight control (source code > attached), it helps saving battery, and your eyes .-) > > Compile it with: > gcc backlight.c -o backlight > > and run it, as root: > # ./backlight (get current value) > Current value : 14 > # ./backlight 15 (set value (15 is maximum, 0 minimum)) > > Maybe it should be integrated in the kernel, but I don't know where > (ACPI??). Does anyone know if 0xB2 and 0xB3 are standard registers? > > Tested with Bootcamp, I don't know whether it also works with the legacy > EFI. > > Best regards, > > Nicolas > > > > > ------------------------------------------------------------------------ > > /* > * Apple Macbook Pro LCD backlight control > * > * Copyright (C) 2006 Nicolas Boichat <ni...@bo...> > * > * This program is free software; you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > * the Free Software Foundation; either version 2 of the License, or > * (at your option) any later version. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > * GNU General Public License for more details. > * > * You should have received a copy of the GNU General Public License > * along with this program; if not, write to the Free Software > * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. > * > */ > > #include <stdio.h> > #include <sys/io.h> > #include <stdlib.h> > > int main(int argc, char** argv) { > int value = -1; > > if (argc > 2) { > printf("Usage:\n"); > printf("%s : read current value\n", argv[0]); > printf("%s value : write value [0-15]\n", argv[0]); > } > > if (argc == 2) { > value = atoi(argv[1]); > if ((value < 0) || (value > 15)) { > printf("Invalid value (should be between 0 and 15).\n"); > exit(0); > } > } > > if (ioperm(0xB2, 0xB3, 1) < 0) { > perror("ioperm failed (you should be root)."); > exit(1); > } > > if (value < 0) { > outb(0x03, 0xB3); > outb(0xBF, 0xB2); > char t = inb(0xB3) >> 4; > printf("Current value : %d\n", t); > } > else { > outb(0x04 | (value << 4), 0xB3); > outb(0xBF, 0xB2); > } > > return 0; > } |