Hi, I'm attaching a qick hack that I'm using to control the display brightness on my NV17 based pbook. Simply pass the brightness (1-15) as argument on the comman line. This is quiet usefull when using offb since adjusting the brighness only works with rivafb. Cheers, -- Guido
/*
* nvbrightness: set brightness on NV based pbooks
* (c) 2004 Guido Guenther <agx@sigxcpu.org>
*/
#include <asm/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/fcntl.h>
#include <stdlib.h>
typedef int Bool;
typedef unsigned int U032;
#define CRTC0_BASE (0x91000000 + 0x00600000)
#define BACKLIGHT 0x81C
#define PMC_BASE 0x91000000
#define REG_BASE (PMC_BASE + 0x1000)
#define BRIGHT_OFF 0xF0
volatile U032* regbase;
volatile U032* crtc0base;
Bool
NVMapRegs()
{
int fd;
if( ! (fd = open("/dev/mem", O_RDWR))) {
printf("Failed to open /dev/mem\n");
return 0;
}
regbase = (U032*)mmap(0,
sizeof(4096),PROT_READ | PROT_WRITE, MAP_SHARED,
fd, (off_t)REG_BASE);
if ( ! regbase )
return 0;
crtc0base = (U032*)mmap(0,
sizeof(4096),PROT_READ | PROT_WRITE, MAP_SHARED,
fd, (off_t)CRTC0_BASE);
if ( ! crtc0base )
return 0;
return 1;
}
/* unmap NVRegs */
void
NVUnmapRegs()
{
munmap((U032*)regbase, sizeof(4096));
munmap((U032*)crtc0base, sizeof(4096));
}
int main(int argc, char** argv)
{
U032 tmp, level;
if( argc != 2) {
printf("Usage: %s brightness\n",argv[0]);
return 1;
}
level = atoi(argv[1]);
if(!NVMapRegs()) {
return 1;
}
tmp = regbase[BRIGHT_OFF/4] & 0x0000FFFF;
tmp |= (1 << 31); // backlight bit
switch(level) {
case 15: tmp |= 0x05340000; break;
default:
tmp |= (341 + (level * 53)) << 16;
}
regbase[BRIGHT_OFF/4] = tmp;
NVUnmapRegs();
return 0;
}
Attachment:
signature.asc
Description: Digital signature