Le Sun 27/05/2007 à 23:19 Marvin Stark à écrit:
> I have the same problem here. My backlight is turned on after
> resuming but I get no screen. Do you have a workaround for this issue?

Just use a backlight tool to change your backlight in the resume
scripts.
If you have an intel video card I made some modification the the
existing tool in order to have a nice Command Line Interface.

Usage: backlight on                -- start backlight
       backlight off               -- stop backlight
       backlight save              -- save backlight status
       backlight restore DATA      -- restore backlight status
       backlight get               -- get backlight value
       backlight set [+|-]VALUE[%] -- set backlight value
backlight value varies between 31 and 148. The result of the save
command and the input to the restore command are hexadecimal numbers.

Attached the source code (if anyone interrested)

-- 
Mildred       <xmpp:[EMAIL PROTECTED]> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]
/*
 * Macbook Backlight Control
 * Copyright © 2006 Ryan Lortie <[EMAIL PROTECTED]>
 *
 * Nice CLI Copyright © 2007 Mildred <[EMAIL PROTECTED]>
 * HAL integration Copyright © 2007 Ryan Lortie <[EMAIL PROTECTED]>
 * using code Copyright © 2006 David Zeuthen <[EMAIL PROTECTED]>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of version 2 of the GNU General Public License as
 *   published by the Free Software Foundation.
 *
 *   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., 59 Temple Place, Suite 330, Boston, MA  02110 USA
 *
 * This program was written after I reverse engineered the
 * AppleIntelIntegratedFramebuffer.kext kernel extension in Mac OS X and
 * played with the register at the memory location I found therein.
 *
 * From my experiments, the register appears to have two halves.
 *
 * yyyyyyyyyyyyyyy0xxxxxxxxxxxxxxx0
 *
 * The top (y) bits appear to be the maximum brightness level and the
 * bottom (x) bits are the current brightness level.  0s are always 0.
 * The brightness level is, therefore, x/y.
 *
 * As my Macbook boots, y is set to 0x94 and x is set to 0x1f.  Going below
 * 0x1f produces odd results.  For example, if you come from above, the
 * backlight will completely turn off at 0x12 (18).  Coming from below,
 * however, you need to get to 0x15 (21) before the backlight comes back on.
 *
 * Since there is no clear cut boundry, I assume that this value specifies
 * a raw voltage.  Also, it appears that the bootup value of 0x1f corresponds
 * to the lowest level that Mac OS X will set the backlight I choose this
 * value as a minimum.
 *
 * For the maximum I do not let the value exceed the value in the upper 15
 * bits.
 *
 * Turning the backlight off entirely is not supported (as this is supported
 * by the kernel itself).  This utility is only for setting the brightness
 * of the backlight when it is enabled.
 */

#include <pci/pci.h>

#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

enum { FALSE, TRUE };

#define REGISTER_OFFSET       0x00061254
#define PAGE_SIZE             4096
#define PAGE_MASK             (PAGE_SIZE - 1)

#define ACCESS_OFFSET         (REGISTER_OFFSET & PAGE_MASK)
#define ACCESS_INDEX          (ACCESS_OFFSET >> 2)

#define MAX_VALUE 0x94
#define MIN_VALUE 0x1f
#define AVG_VALUE ((MIN_VALUE+MAX_VALUE)/2)

unsigned int *register_page;

static unsigned long determine_video_base_address (void) {
    struct pci_access *pacc;
    struct pci_dev *pdev;
    unsigned long address;
    int i;

    address = 0;

    pacc = pci_alloc ();
    pci_init (pacc);
    pci_scan_bus (pacc);

    for (pdev = pacc->devices; pdev; pdev = pdev->next){

        pci_fill_info (pdev, PCI_FILL_IDENT | PCI_FILL_BASES);

        if (pdev->vendor_id == 0x8086 && pdev->device_id == 0x27a2){
            for (i = 0; i < 6; i++) {
                if (pdev->size[i] == 512 * 1024) {
                    address = pdev->base_addr[i];
                    goto end;
                }
            }
        }

    }

end:
    pci_cleanup (pacc);
    return address;
}

static unsigned long register_get (void) {
    return register_page[ACCESS_INDEX];
}

static void register_set (unsigned long value) {
    register_page[ACCESS_INDEX] = value;
}

static void register_set_mask (unsigned long value, unsigned long mask) {
    unsigned long current = register_page[ACCESS_INDEX];
    register_page[ACCESS_INDEX] = (value&mask) | (current&(~mask));
}


static int map_register_page (void) {
    long address;
    int fd;

    address = determine_video_base_address ();

    if (address == 0)
        return FALSE;

    fd = open ("/dev/mem", O_RDWR);

    if (fd < 0)
        return FALSE;

    register_page = mmap (
        NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
        MAP_SHARED, fd,
        (address + REGISTER_OFFSET) & ~PAGE_MASK);

    close (fd);

    if (register_page == MAP_FAILED)
        return FALSE;

    return TRUE;
}

static long backlight_get (void) {
  return (register_get() >> 1) & 0x7fff;
}

static void backlight_on(void) {
    long level = backlight_get();

    if(level < MIN_VALUE) level = MIN_VALUE;
    else if(level > MAX_VALUE) level = MAX_VALUE;

    register_set((MAX_VALUE << 17) | (level << 1));
}

static void backlight_off(void) {
    register_set_mask(0x00 << 1, 0x7fff << 1);
}

static void backlight_set (long value) {
    long max;

    max = register_get () >> 17;

    if (value > max)
        value = max;

    if (value < MIN_VALUE)
        value = MIN_VALUE;

    if (max != MAX_VALUE) {
        // Reset
        // backlight_on();
        max = MAX_VALUE;
    }

    register_set ((max << 17) | (value << 1));
}

static void backlight_change (long value){
    long old;

    old = backlight_get();
    backlight_set (old + value);
}

static int help(){
    fprintf(stderr, "Usage: backlight on                -- start backlight\n");
    fprintf(stderr, "       backlight off               -- stop backlight\n");
    fprintf(stderr, "       backlight save              -- save backlight status\n");
    fprintf(stderr, "       backlight restore DATA      -- restore backlight status\n");
    fprintf(stderr, "       backlight get               -- get backlight value\n");
    fprintf(stderr, "       backlight set [+|-]VALUE[%] -- set backlight value\n");
    fprintf(stderr, "backlight value varies between %d and %d. The result of the save\n"
        /**/        "command and the input to the restore command are hexadecimal numbers.\n",
        MIN_VALUE, MAX_VALUE);
    return 2;
}

static int error(){
    fprintf(stderr, "cannot map register page!\n");
    return 1;
}

int main(int argc, char** argv){
    int res = map_register_page();
    if(argc < 2){
        return help();
    }else if(!strcmp("on", argv[1])){
        if(!res) return error();
        backlight_on();
    }else if(!strcmp("off", argv[1])){
        if(!res) return error();
        backlight_off();
    }else if(!strcmp("save", argv[1])){
        if(!res) return error();
        printf("0x%08x\n", register_get());
    }else if(argc >= 3 && !strcmp("restore", argv[1])){
        if(!res) return error();
        register_set(strtol(argv[2], NULL, 0));
    }else if(!strcmp("get", argv[1])){
        if(!res) return error();
        int val = backlight_get();
        double percent = ((double) (val-MIN_VALUE))*100.0 / (double) (MAX_VALUE-MIN_VALUE);
        if(percent >= 0.0)
            printf("%.1f%% %ld\n", percent, val);
        else
            printf("off %ld\n", val);
    }else if(argc >= 3 && !strcmp("set", argv[1])){
        if(!res) return error();
        double value = atof(argv[2]);
        int currentvalue = backlight_get();
        if(strchr(argv[2], '%') && (value >= 0.0 || value <= 100.0)){
            value = value/100.0 * (double) (MAX_VALUE-MIN_VALUE);
            if(argv[2][0] != '-' && argv[2][0] != '+')
                value += MIN_VALUE;
        }
        if (argv[2][0] == '-' && currentvalue <= MIN_VALUE)
            backlight_off();
        else if (argv[2][0] == '-' || argv[2][0] == '+')
            backlight_change((int) value);
        else if (!strcmp("on", argv[2]))
            backlight_on();
        else if (!strcmp("off", argv[2]))
            backlight_off();
        else
            backlight_set((int) value);
    }else{
        return help();
    }
    return 0;
}

/***** Makefile *****

backlight: backlight.c
	sudo $(CC) $(CFLAGS) $+ -lpci -o $@
	sudo chown root: $@
	sudo chmod u+s $@

*/

/* kate: indent-width 4; space-indent on; replace-tabs off; replace-tabs-save off; */
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mactel-linux-users mailing list
Mactel-linux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mactel-linux-users

Reply via email to