little hack for Vaio

Replies:

Parents:

  • None.
I just made a little hack to adapt the brightness of the screen depending
on the power status. It is very simple (for now), you just have to
download the source from [1] (Content-Md5: PsXlGLtpbBn9/ygHdiXQVA==),
compile it, then two possibilities:
1/ you are paranoid
2/ you are not that paranoid, set the owner of the executable to 'root'
  and do a little chmod u+s on it.
It takes two mandatory parameters, the brightness when the Vaio is on AC
(from 0 to 255), and the value when it is on DC (same range).
I usually use ./power 100 42

I plan to add more features in the future, like allowing change of the
brightness value safely while this daemon is running (currently, there may
be race conditions if you want to run another program accessing the same
part of the BIOS, like the small program that just sets the brightness).
Automatic change when more power is used on DC (like when the fan is
starting)

It uses part of code [2] found on the web along with some relatively
cryptic information about the bios of those beasts.

[1] http://www.raubacapeu.net/people/yves/tools/power.c
[2] http://us1.samba.org/ftp/unpacked/picturebook/

--
~~Yves

Re: little hack for Vaio

Replies:

Parents:


--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

* [email protected] <[email protected]> [2001-04-17 16:33+0200]
> I plan to add more features in the future, like allowing change of the
> brightness value safely while this daemon is running (currently, there may
> be race conditions if you want to run another program accessing the same
> part of the BIOS, like the small program that just sets the brightness).
> Automatic change when more power is used on DC (like when the fan is
> starting)

This should be the job of apmd. apmd's job is to monitor APM events
and to do stuff when things happen. From apmd(8):

      Most uses of this daemon will use  the  proxy  command  to
      support  power  conservation  activities.  This command is
      searched for by default in /etc/apmd_proxy and is  invoked
      with one or two arguments:
 [..]
      change power
             This  presents  a  subset  of the APM driver "power
             change" events, specifically those where  AC  power
             was  added  or removed.  This will often modify the
             system wide power policy; for example, so that  IDE
             hard  drives  aggressively  enter standby mode when
             only battery power is available.

You just need to call a program to change the brightness (a strip down
version of your program is attached) and to make the apmd proxy run
the appropriate script in /etc/apm/events.d (attached too).

Here's the catch though: it doesn't work on my Vaio. :-)

It seems that the apmd doesn't receive any event (except "Event
0xad03: Unknown") when the power status changes. I am not that
surprised, because the remaining time indicator is broken too (see
[1]). Maybe it will work on others though...

 1. http://larve.net/people/hugo/2000/07/linux-vaio#apm
--
Hugo Haas <[email protected]> - http://larve.net/people/hugo/
Done and done.

--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="brightness.c"

#define DEV_EC0_DATA_REG 0x62
#define DEV_EC0_CST_REG  0x66

#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <sys/types.h>
#include <unistd.h>

void ecr_set8(u_int8_t addr, u_int8_t value) {
while (inb(DEV_EC0_CST_REG) & 3) usleep(1);
outb(0x81, DEV_EC0_CST_REG);
while (inb(DEV_EC0_CST_REG) & 2) usleep(1);
outb(addr, DEV_EC0_DATA_REG);
while (inb(DEV_EC0_CST_REG) & 2) usleep(1);
outb(value, DEV_EC0_DATA_REG);
while (inb(DEV_EC0_CST_REG) & 2) usleep(1);
}

int main (int argc, char **argv) {
 u_int8_t bright;

 if (argc == 2) {
   bright = atoi(argv[1]) & 0xFF;
 } else {
   printf("Usage: %s brightness_value\n", argv[0]);
   return(1);
 }

 iopl(3);
 ecr_set8(0x96, bright);
 return(0);
}

--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=brightness

#!/bin/sh

if [ "$1" != "change" ]; then
 exit 0
fi

if [ "$2" != "power" ]; then
 exit 0
fi

if on_ac_power >/dev/null; then
 /usr/local/sbin/brightness 0
else
 /usr/local/sbin/brightness 100
fi

--zYM0uCDKw75PZbzx--

Re: little hack for Vaio

Replies:

Parents:

On Tue, 17 Apr 2001, Hugo Haas wrote:

> This should be the job of apmd. apmd's job is to monitor APM events
> and to do stuff when things happen. From apmd(8):

That's what I tried first, unfortunately, it doesn't work, the event are
not sent... And of course it won't be able to monitor the fan.

> Here's the catch though: it doesn't work on my Vaio. :-)

Hum, did they change some calls? It is supposed to work on PC1 and 505
serie. It's time for you to give me a bios dump ;)

--
~~Yves

Re: little hack for Vaio

Replies:

  • None.

Parents:

* Yves Lafon <[email protected]> [2001-04-17 19:09+0200]
> > Here's the catch though: it doesn't work on my Vaio. :-)
>
> Hum, did they change some calls? It is supposed to work on PC1 and 505
> serie. It's time for you to give me a bios dump ;)

I was talking about the apmd solution, not the brightness setting
functions. I was hoping that it would work on other Vaios; apparently
not.

--
Hugo Haas <[email protected]> - http://larve.net/people/hugo/
Hey, did you hear that? Sounds like a giraffe is dying over there.

HURL: fogo mailing list archives, maintained by Gerald Oskoboiny