Subject: Kernel patch for console.c (Laptop Backlight)

From: [email-masked] ("Alexander During")
Date: 14 Apr 1994 06:56:55 GMT

Hello Fello Linuxers!

This is the patch onto drivers/char/console.c that I announced some three 
weeks ago, just before I left for holiday, so here are my apologies for 
sending the actual code rather late.

Again, here is what I know about the computer: It may be called Notebook 3500
by some manufacturers, in Germany it is sold by Computer Revolution and Vobis
as 386 or 486 versions. You have dark blue writings on some keys, notably the
following:

	Esc:	PopUp
	Enter:	Stand By
	CsrUp:	Norm
	CsrDn:	Sleep
	F5:	A-M
	F6:	Bold
	F7:	L/C

The key marked Fn is between left Crtl and left Alt. The driver that comes
for DOS is called note3500.sys. 

There has been some discussion following my posting, so I feel the thing is
no really state-of-the-art as far as sophistication goes. The change I
would like to see is to see blankscreen() called by a blanking routine, not
hardcoded as one. These changes, however, go directly into blank_screen()
and unblank_screen(). I do not feel very much like having user-installable
blanking routines, for a simple reason: When I work with virtual consoles
instead of X, I do this to have my RAM free for computations, compiles,
&c. It seems rather baroque to me to add too much functionality to a bare
metal interface. But this is my personal opinion.

About this division thing; I will see if it comes out in the next kernel
release, because I strongly feel that both, the routine to blank the screen
and the one to perform hardware specific twiddling should be visible for
user programs and neither do I know what to do to make a function externally
callable, nor do I want to meddle with the ways of Linus.

Now for the patch. Obviously it just toggles one bit. I add a test program
to check out beforehand whether this works. Try the program, if it goes well,
apply the patch. 

The computer in question has alot more features, most prominently switching
between internal (=LCD) and external screen, en-/disabling colour and so on.
I have been asked to implement these as well and I am working on it, but 
while the backlight twiddling is done within a loadable driver, all the rest
involves the VGA-BIOS and this is somewhat larger, read: harder to see through
than the driver code. As a matter of fact, the interfacing looks like all the
things that couldn't be squeezed into the BIOS have been put into the driver
and so the division of functionality is less than well structured.
Next thing is, I don't have an external monitor here in Japan... 

As we are at it, instead of wading through the source listing, if somebody
could point me to something that enables me to debug along the 16h interrupt,
perhaps using a Linux box via a serial line, I guess it would speed up things.

=============================== Patch ===================================
1556,1566d1555
< 
< /* Now comes the addition to switch off backlight of my LCD screen*/
< 	if (((jiffies-timer_table[BLANK_TIMER].expires) & ~3L)==0L) {
< 	/* call this only if due to timeout, not if called by X */
< 	/* the & allows 3 jiffies to go by before the call reaches us */
< 		outb(0x84, 0x3c4); /* EGA sequencer index*/
< 		outb(inb(0x3c5) & 0xbf, 0x3c5); /* turn off backlight bit */
< 		outb(0x00, 0x3da); /* VGA feature contr.: acknowledge */
< 	}
< /* End of LCD insertions. Alex heisei 6/03/17 */
< 
1580,1586d1568
< 
< /* switch LCD back on */
< 	outb(0x84, 0x3c4); /* EGA sequencer index*/
< 	outb(inb(0x3c5) | 0x40, 0x3c5); /* turn on backlight bit */
< 	outb(0x00, 0x3da); /* VGA feature contr.: acknowledge */
< /* End of LCD insertions. Alex heisei 6/03/17 */
< 
=============================== End of patch ============================

=============================== Test program ============================

/* setscreen.c  Compile this with gcc -o setscreen -O2 setscreen.c */

#include <unistd.h>
#include <stdio.h>
#include <asm/io.h>

#define EGASEQU 0x3c4
#define EGAPORT 0x3c5
#define VGAPORT 0x3da

typedef struct _attribute {
  char *name;
  char ormask;
  char andmask;
} attribute;

attribute capability[] = {
  { "backlit",   0x40, 0xff},
  { "nolight",   0x00, 0xbf},
  { NULL, 0x00, 0xbf}
};

void usage(char *name)

{
  int i;

  printf("Usage: %s options\n", name);
  printf("Available options are:");
  for (i=0; capability[i].name; i++)
    printf(" %s", capability[i].name);
  printf(".\n");
}

int main(int argc, char **argv)

{
  int j,i,p;

  if (argc<2) {
    usage(argv[0]);
    return -1;
  }

  if (ioperm(EGASEQU, 1L, 1) || ioperm(EGAPORT, 1L, 1) || ioperm(VGAPORT, 1L, 1)) {
    printf("This program must be run with root permissions.\n");
    return -2;
  };

  for(i=1; i<argc; i++) {
    for(j=0; ; j++) {
      if (capability[j].name==NULL) {
	printf("Unknown option: %s\n", argv[i]);
	return -3;
      };
      if (!strcmp(argv[i], capability[j].name)) {
	outb(0x84, EGASEQU);
	p=inb(EGAPORT);
        if (capability[j].ormask)
	  outb(p | capability[j].ormask, EGAPORT);
	else
	  outb(p & capability[j].andmask, EGAPORT);
	outb(0, VGAPORT);
	break;
      }
    }
  }

  return 0;
}
	
======================== End of test program ============================

You best test this with the following command line:

setscreen nolight; setscreen backlit

You screen should blink. If it doesn't, hit Crtl-Alt-Del and power-cycle.
Or whatever. In any case, you can't use this method and it's best to clear
all side effects. I have no testing equipment, so I can't guarantee for
anything. If your computer breaks, I am sorry, but not liable for anything.
Really. I don't have any money anyway, so don't even try sueing me.

If there are other persons that have this kind of computer and at least some
documentation about it, I would gladly take over the task to write a patch
for console.c that handles the Fn key and the functions connected with it
(though probably not halting of the disk). Please send me anything you have
via either e-mail ([email-masked]) or to

	Alexander D\"uring
	Watanabe Bldg. 305
	Nakano-ku, Matsugaoka 2-2-13
	Tokyo 165
	Japan

Thanks for listening.
--
As MS-DOS is very abstruse, \\it's also quite tricky to use. \\So many give in
and try typing 'win'. \\But that means completely to lose.
Alexander D\"uring, Physics Department, Waseda University, Tokyo, Japan.
Statistical Physics, Linux, Shakespeare. --- This space for rent ---