1 /***************************************************************************
2 toshiba_lib.c - description
5 copyright : (C) 2003 by Noberasco Michele
6 e-mail : 2001s098@educ.disi.unige.it
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
26 ***************************************************************************/
28 /***************************************************************************
29 Many thanks to Jonathan A. Buzzard for his Toshiba(tm) Linux Utilities
30 I could never have done this otherwise
31 ***************************************************************************/
36 #define UP_ONE_STEP -5
37 #define DOWN_ONE_STEP -6
45 #include <sys/types.h>
56 #include "toshiba_lib.h"
57 #include "lib_utils.h"
58 #include "power_management.h"
62 int Get_Fan_Status(void);
66 int toshiba_get_fan_status(int use_toshiba_hardware
)
68 if (use_toshiba_hardware
!= 2)
70 FILE *fp
= fopen("/proc/acpi/toshiba/fan", "r");
74 if (fscanf(fp
, "%*s%d", &result
) == 1)
81 if (!use_toshiba_hardware
) return PM_Error
;
84 if (Get_Fan_Status()<0x00)
86 fprintf(stderr
, "direct access to toshiba hardware failed:\n");
87 fprintf(stderr
, "cannot get fan status!\n");
91 if (Get_Fan_Status()==0x00) return 0;
96 void toshiba_set_fan_status(int status
)
99 static int enable_spinoff
=1;
104 if (toshiba_get_fan_status(2) == 1) return;
107 reg
.ecx
= HCI_ENABLE
;
110 if( toshiba_get_fan_status(2) == 1)
111 fprintf(stderr
, "toshiba_lib: cooling fan turned on\n");
113 fprintf(stderr
, "toshiba_lib: unable to turn on cooling fan\n");
119 if (toshiba_get_fan_status(2) == 0) return;
122 if ( (time(NULL
)-timer
) >= 15 ) enable_spinoff
=1;
128 if( toshiba_get_fan_status(2) == 0)
129 fprintf(stderr
, "toshiba_lib: cooling fan turned off\n");
131 fprintf(stderr
, "toshiba_lib: unable to turn off cooling fan\n");
135 fprintf(stderr
, "toshiba_lib: selected invalid fan status\n");
139 int acpi_set_lcd_brightness(int brightness
)
142 static int current_brightness
=-1;
143 int min_brightness
= 0;
144 static int max_brightness
;
146 if (current_brightness
== -1)
148 fp
= fopen("/proc/acpi/toshiba/lcd", "r");
151 fprintf(stderr
, "toshiba_lib: unable to set LCD brightness with ACPI.\n");
154 fscanf(fp
, "%*s%d%*s%d", ¤t_brightness
, &max_brightness
);
156 fprintf(stderr
, "toshiba_lib: min brightness is %d\n", min_brightness
);
157 fprintf(stderr
, "toshiba_lib: max brightness is %d\n", --max_brightness
);
158 fprintf(stderr
, "toshiba_lib: current brightness is %d\n", current_brightness
);
161 if (brightness
== TOSHIBA_LCD_MAX
) brightness
= max_brightness
;
162 if (brightness
== TOSHIBA_LCD_MIN
) brightness
= 0;
163 if (brightness
== TOSHIBA_LCD_MED
) brightness
= max_brightness
/2;
165 if (brightness
== UP_ONE_STEP
)
167 if (current_brightness
< max_brightness
) brightness
= current_brightness
+ 1;
170 if (brightness
== DOWN_ONE_STEP
)
172 if (current_brightness
> min_brightness
) brightness
= current_brightness
- 1;
176 if (maxBrightness
!= -1 && brightness
> maxBrightness
) brightness
= maxBrightness
;
177 if (minBrightness
!= -1 && brightness
< minBrightness
) brightness
= minBrightness
;
179 if (brightness
!= current_brightness
)
181 fp
= fopen("/proc/acpi/toshiba/lcd", "w");
184 fprintf(stderr
, "toshiba_lib: unable to set LCD brightness with ACPI.\n");
187 fprintf(fp
, "brightness:%d\n", brightness
);
189 fp
= fopen("/proc/acpi/toshiba/lcd", "r");
190 fscanf(fp
, "%*s%d", ¤t_brightness
);
192 if (brightness
== current_brightness
)
193 fprintf(stderr
, "toshiba_lib: set LCD brightness to %d\n", brightness
);
196 fprintf(stderr
, "toshiba_lib: unable to set LCD brightness with ACPI.\n");
201 usleep (125000); /* You must let some time pass between changes */
206 void hardware_set_lcd_brightness(int brightness
)
208 static int current_brightness
=-1;
210 static unsigned short lcdtype
=999;
218 reg
.ebx
= SCI_LCD_BRIGHTNESS
;
219 if (SciGet(®
)==SCI_SUCCESS
) lcdtype
= SCI_LCD_BRIGHTNESS
;
220 else lcdtype
= SCI_LCD_BACKLIGHT
;
221 reg
.ebx
= SCI_LCD_MAXBRIGHT
;
222 if (SciGet(®
)==SCI_SUCCESS
)
224 lcdtype
= SCI_LCD_MAXBRIGHT
;
227 fprintf(stderr
, "toshiba_lib: min brightness is %d\n", TOSHIBA_LCD_MIN
);
228 fprintf(stderr
, "toshiba_lib: max brightness is %d\n", TOSHIBA_LCD_MAX
);
233 if (brightness
== UP_ONE_STEP
)
234 {/* Right now this is broken... */
235 /*if (current_brightness < TOSHIBA_LCD_MAX) lcd = current_brightness + 1;
238 if (brightness
== DOWN_ONE_STEP
)
239 {/* Right now this is broken... */
240 /*if (current_brightness > TOSHIBA_LCD_MIN) lcd = current_brightness - 1;
244 if (maxBrightness
!= -1 && lcd
> maxBrightness
) lcd
= maxBrightness
;
245 if (minBrightness
!= -1 && lcd
< minBrightness
) lcd
= minBrightness
;
247 if (lcd
!= current_brightness
)
252 if (SciSet(®
)==SCI_FAILURE
)
253 fprintf(stderr
, "toshiba_lib: unable to set LCD brightness\n");
256 fprintf(stderr
, "toshiba_lib: changed LCD brightness to %d\n", lcd
);
257 current_brightness
=lcd
;
264 void toshiba_set_lcd_brightness(int brightness
, int use_hardware_call
)
266 static int acpi_ok
= 1;
268 if (!use_hardware_call
)
270 acpi_set_lcd_brightness(brightness
);
275 hardware_set_lcd_brightness(brightness
);
278 acpi_ok
= acpi_set_lcd_brightness(brightness
);
281 fprintf(stderr
, "Trying to control directly Toshiba lcd hardware\n");
282 hardware_set_lcd_brightness(brightness
);
286 void Toshiba_lcdBrightness_UpOneStep(int use_hardware
)
288 toshiba_set_lcd_brightness(UP_ONE_STEP
, use_hardware
);
291 void Toshiba_lcdBrightness_DownOneStep(int use_hardware
)
293 toshiba_set_lcd_brightness(DOWN_ONE_STEP
, use_hardware
);
296 /* Check if we are running on a Toshiba laptop */
297 int machine_is_toshiba(int *use_toshiba_hardware
)
301 DIR *toshiba_proc
= opendir("/proc/acpi/toshiba");
303 strcpy(toshiba_model
, "cannot get model without direct hardware access");
306 closedir(toshiba_proc
);
309 if (!use_toshiba_hardware
|| !(*use_toshiba_hardware
)) return result
;
311 /* do some quick checks on the laptop */
312 if (SciSupportCheck(&version
)==1)
314 *use_toshiba_hardware
= 0;
317 bios
= HciGetBiosVersion();
320 *use_toshiba_hardware
= 0;
323 if (HciGetMachineID(&id
)==HCI_FAILURE
)
325 *use_toshiba_hardware
= 0;
329 strcpy(toshiba_model
, "unknown model");
332 case 0xfc00: strcpy(toshiba_model
, "Satellite 2140CDS/2180CDT/2675DVD"); break;
333 case 0xfc01: strcpy(toshiba_model
, "Satellite 2710xDVD"); break;
334 case 0xfc02: strcpy(toshiba_model
, "Satellite Pro 4270CDT//4280CDT/4300CDT/4340CDT"); break;
335 case 0xfc04: strcpy(toshiba_model
, "Portege 3410CT, 3440CT"); break;
336 case 0xfc08: strcpy(toshiba_model
, "Satellite 2100CDS/CDT 1550CDS"); break;
337 case 0xfc09: strcpy(toshiba_model
, "Satellite 2610CDT, 2650XDVD"); break;
338 case 0xfc0a: strcpy(toshiba_model
, "Portage 7140"); break;
339 case 0xfc0b: strcpy(toshiba_model
, "Satellite Pro 4200"); break;
340 case 0xfc0c: strcpy(toshiba_model
, "Tecra 8100x"); break;
341 case 0xfc0f: strcpy(toshiba_model
, "Satellite 2060CDS/CDT"); break;
342 case 0xfc10: strcpy(toshiba_model
, "Satellite 2550/2590"); break;
343 case 0xfc11: strcpy(toshiba_model
, "Portage 3110CT"); break;
344 case 0xfc12: strcpy(toshiba_model
, "Portage 3300CT"); break;
345 case 0xfc13: strcpy(toshiba_model
, "Portage 7020CT"); break;
346 case 0xfc15: strcpy(toshiba_model
, "Satellite 4030/4030X/4050/4060/4070/4080/4090/4100X CDS/CDT"); break;
347 case 0xfc17: strcpy(toshiba_model
, "Satellite 2520/2540 CDS/CDT"); break;
348 case 0xfc18: strcpy(toshiba_model
, "Satellite 4000/4010 XCDT"); break;
349 case 0xfc19: strcpy(toshiba_model
, "Satellite 4000/4010/4020 CDS/CDT"); break;
350 case 0xfc1a: strcpy(toshiba_model
, "Tecra 8000x"); break;
351 case 0xfc1c: strcpy(toshiba_model
, "Satellite 2510CDS/CDT"); break;
352 case 0xfc1d: strcpy(toshiba_model
, "Portage 3020x"); break;
353 case 0xfc1f: strcpy(toshiba_model
, "Portage 7000CT/7010CT"); break;
354 case 0xfc39: strcpy(toshiba_model
, "T2200SX"); break;
355 case 0xfc40: strcpy(toshiba_model
, "T4500C"); break;
356 case 0xfc41: strcpy(toshiba_model
, "T4500"); break;
357 case 0xfc45: strcpy(toshiba_model
, "T4400SX/SXC"); break;
358 case 0xfc51: strcpy(toshiba_model
, "Satellite 2210CDT, 2770XDVD"); break;
359 case 0xfc52: strcpy(toshiba_model
, "Satellite 2775DVD, Dynabook Satellite DB60P/4DA"); break;
360 case 0xfc53: strcpy(toshiba_model
, "Portage 7200CT/7220CT, Satellite 4000CDT"); break;
361 case 0xfc54: strcpy(toshiba_model
, "Satellite 2800DVD"); break;
362 case 0xfc56: strcpy(toshiba_model
, "Portage 3480CT"); break;
363 case 0xfc57: strcpy(toshiba_model
, "Satellite 2250CDT"); break;
364 case 0xfc5a: strcpy(toshiba_model
, "Satellite Pro 4600"); break;
365 case 0xfc5d: strcpy(toshiba_model
, "Satellite 2805"); break;
366 case 0xfc5f: strcpy(toshiba_model
, "T3300SL"); break;
367 case 0xfc61: strcpy(toshiba_model
, "Tecra 8200"); break;
368 case 0xfc64: strcpy(toshiba_model
, "Satellite 1800"); break;
369 case 0xfc69: strcpy(toshiba_model
, "T1900C"); break;
370 case 0xfc70: strcpy(toshiba_model
, "Libretto L2"); break;
371 case 0xfc6a: strcpy(toshiba_model
, "T1900"); break;
372 case 0xfc6c: strcpy(toshiba_model
, "Satellite 5005 S504"); break;
373 case 0xfc6d: strcpy(toshiba_model
, "T1850C"); break;
374 case 0xfc6e: strcpy(toshiba_model
, "T1850"); break;
375 case 0xfc6f: strcpy(toshiba_model
, "T1800"); break;
376 case 0xfc71: strcpy(toshiba_model
, "Satellite Pro 6000"); break;
377 case 0xfc72: strcpy(toshiba_model
, "Satellite 1800"); break;
378 case 0xfc7d: strcpy(toshiba_model
, "Satellite Pro 6100"); break;
379 case 0xfc7e: strcpy(toshiba_model
, "T4600C"); break;
380 case 0xfc7f: strcpy(toshiba_model
, "T4600"); break;
381 case 0xfc8a: strcpy(toshiba_model
, "T6600C"); break;
382 case 0xfc91: strcpy(toshiba_model
, "T2400CT"); break;
383 case 0xfc97: strcpy(toshiba_model
, "T4800CT"); break;
384 case 0xfc99: strcpy(toshiba_model
, "T4700CS"); break;
385 case 0xfc9b: strcpy(toshiba_model
, "T4700CT"); break;
386 case 0xfc9d: strcpy(toshiba_model
, "T1950"); break;
387 case 0xfc9e: strcpy(toshiba_model
, "T3400/T3400CT"); break;
388 case 0xfca6: strcpy(toshiba_model
, "Portege 2010"); break;
389 case 0xfca9: strcpy(toshiba_model
, "Satellite 2410-303"); break;
390 case 0xfcb2: strcpy(toshiba_model
, "Libretto 30CT"); break;
391 case 0xfcba: strcpy(toshiba_model
, "T2150"); break;
392 case 0xfcbe: strcpy(toshiba_model
, "T4850CT"); break;
393 case 0xfcc0: strcpy(toshiba_model
, "Satellite Pro 420x"); break;
394 case 0xfcc1: strcpy(toshiba_model
, "Satellite 100x"); break;
395 case 0xfcc3: strcpy(toshiba_model
, "Tecra 710x/720x"); break;
396 case 0xfcc6: strcpy(toshiba_model
, "Satellite Pro 410x"); break;
397 case 0xfcca: strcpy(toshiba_model
, "Satellite Pro 400x"); break;
398 case 0xfccb: strcpy(toshiba_model
, "Portage 610CT"); break;
399 case 0xfccc: strcpy(toshiba_model
, "Tecra 700x"); break;
400 case 0xfccf: strcpy(toshiba_model
, "T4900CT"); break;
401 case 0xfcd0: strcpy(toshiba_model
, "Satellite 300x"); break;
402 case 0xfcd1: strcpy(toshiba_model
, "Tecra 750CDT"); break;
403 case 0xfcd2: strcpy(toshiba_model
, "Vision Connect -- what is this???"); break;
404 case 0xfcd3: strcpy(toshiba_model
, "Tecra 730XCDT"); break;
405 case 0xfcd4: strcpy(toshiba_model
, "Tecra 510x"); break;
406 case 0xfcd5: strcpy(toshiba_model
, "Satellite 200x"); break;
407 case 0xfcd7: strcpy(toshiba_model
, "Satellite Pro 430x"); break;
408 case 0xfcd8: strcpy(toshiba_model
, "Tecra 740x"); break;
409 case 0xfcd9: strcpy(toshiba_model
, "Portage 660CDT"); break;
410 case 0xfcda: strcpy(toshiba_model
, "Tecra 730CDT"); break;
411 case 0xfcdb: strcpy(toshiba_model
, "Portage 620CT"); break;
412 case 0xfcdc: strcpy(toshiba_model
, "Portage 650CT"); break;
413 case 0xfcdd: strcpy(toshiba_model
, "Satellite 110x"); break;
414 case 0xfcdf: strcpy(toshiba_model
, "Tecra 500x"); break;
415 case 0xfce0: strcpy(toshiba_model
, "Tecra 780DVD"); break;
416 case 0xfce2: strcpy(toshiba_model
, "Satellite 300x"); break;
417 case 0xfce3: strcpy(toshiba_model
, "Satellite 310x"); break;
418 case 0xfce4: strcpy(toshiba_model
, "Satellite Pro 490x"); break;
419 case 0xfce5: strcpy(toshiba_model
, "Libretto 100CT"); break;
420 case 0xfce6: strcpy(toshiba_model
, "Libretto 70CT"); break;
421 case 0xfce7: strcpy(toshiba_model
, "Tecra 540x/550x"); break;
422 case 0xfce8: strcpy(toshiba_model
, "Satellite Pro 470x/480x"); break;
423 case 0xfce9: strcpy(toshiba_model
, "Tecra 750DVD"); break;
424 case 0xfcea: strcpy(toshiba_model
, "Libretto 60"); break;
425 case 0xfceb: strcpy(toshiba_model
, "Libretto 50CT"); break;
426 case 0xfcec: strcpy(toshiba_model
, "Satellite 320x/330x, Satellite 2500CDS"); break;
427 case 0xfced: strcpy(toshiba_model
, "Tecra 520x/530x"); break;
428 case 0xfcef: strcpy(toshiba_model
, "Satellite 220x, Satellite Pro 440x/460x"); break;
430 fprintf(stderr
, "toshiba_lib: unrecognized machine identification:\n");
431 fprintf(stderr
, " machine id : 0x%04x BIOS version : %d.%d SCI version: %d.%d\n",
432 id
, (bios
& 0xff00)>>8, bios
& 0xff,
433 (version
& 0xff00)>>8, version
& 0xff);
434 fprintf(stderr
, "please report this info, along with your toshiba model,\n");
435 fprintf(stderr
, "to noberasco.gnu@disi.unige.it\n");
446 /* INTERNAL FUNCTIONS */
449 int Get_Fan_Status(void)
457 if ((reg
.eax
& 0xff00)!=HCI_SUCCESS
)
460 return (int) (reg
.ecx
& 0xff);
465 unsigned short save
=0,display
=512,sleep
=0,speed
=1,cooling
=1;
470 reg
.ebx
= SCI_BATTERY_SAVE
;
472 if (SciSet(®
)==SCI_SUCCESS
) user
= 0;
474 if ((save
==SCI_USER_SETTINGS
) || (user
==1))
476 reg
.ebx
= SCI_DISPLAY_AUTO
;
478 if (SciSet(®
)==SCI_FAILURE
) {}
479 reg
.ebx
= SCI_SLEEP_MODE
;
481 if (SciSet(®
)==SCI_FAILURE
) {}
482 reg
.ebx
= SCI_PROCESSING
;
484 if (SciSet(®
)==SCI_FAILURE
) {}
485 reg
.ebx
= SCI_COOLING_METHOD
;
487 if (SciSet(®
)==SCI_FAILURE
) {}
490 reg
.ebx
= SCI_BATTERY_SAVE
;
492 if (SciSet(®
)==SCI_FAILURE
) {}
493 reg
.ebx
= SCI_BATTERY_SAVE
;
495 if (SciSet(®
)==SCI_FAILURE
) {}
501 reg
.ecx
= HCI_DISABLE
;
505 reg
.ebx
= SCI_COOLING_METHOD
;