acpi_toshiba.c (131284) | acpi_toshiba.c (133630) |
---|---|
1/*- 2 * Copyright (c) 2003 Hiroyuki Aizu <aizu@navi.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Hiroyuki Aizu <aizu@navi.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_toshiba.c 131284 2004-06-29 19:05:20Z njl $"); | 29__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_toshiba.c 133630 2004-08-13 06:22:35Z njl $"); |
30 31#include "opt_acpi.h" 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/module.h> 35#include <sys/bus.h> 36 37#include "acpi.h" --- 104 unchanged lines hidden (view full) --- 142static int hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg); 143static void hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h, 144 UINT32 key); 145static void acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify, 146 void *context); 147static int acpi_toshiba_video_probe(device_t dev); 148static int acpi_toshiba_video_attach(device_t dev); 149 | 30 31#include "opt_acpi.h" 32#include <sys/param.h> 33#include <sys/kernel.h> 34#include <sys/module.h> 35#include <sys/bus.h> 36 37#include "acpi.h" --- 104 unchanged lines hidden (view full) --- 142static int hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg); 143static void hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h, 144 UINT32 key); 145static void acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify, 146 void *context); 147static int acpi_toshiba_video_probe(device_t dev); 148static int acpi_toshiba_video_attach(device_t dev); 149 |
150ACPI_SERIAL_DECL(toshiba, "ACPI Toshiba Extras"); 151 |
|
150/* Table of sysctl names and HCI functions to call. */ 151static struct { 152 char *name; 153 hci_fn_t *handler; 154} sysctl_table[] = { 155 /* name, handler */ 156 {"force_fan", hci_force_fan}, 157 {"video_output", hci_video_output}, --- 129 unchanged lines hidden (view full) --- 287 int function, error = 0; 288 hci_fn_t *handler; 289 290 sc = (struct acpi_toshiba_softc *)oidp->oid_arg1; 291 function = oidp->oid_arg2; 292 handler = sysctl_table[function].handler; 293 294 /* Get the current value from the appropriate function. */ | 152/* Table of sysctl names and HCI functions to call. */ 153static struct { 154 char *name; 155 hci_fn_t *handler; 156} sysctl_table[] = { 157 /* name, handler */ 158 {"force_fan", hci_force_fan}, 159 {"video_output", hci_video_output}, --- 129 unchanged lines hidden (view full) --- 289 int function, error = 0; 290 hci_fn_t *handler; 291 292 sc = (struct acpi_toshiba_softc *)oidp->oid_arg1; 293 function = oidp->oid_arg2; 294 handler = sysctl_table[function].handler; 295 296 /* Get the current value from the appropriate function. */ |
297 ACPI_SERIAL_BEGIN(toshiba); |
|
295 error = handler(sc->handle, HCI_GET, &arg); 296 if (error != 0) | 298 error = handler(sc->handle, HCI_GET, &arg); 299 if (error != 0) |
297 return (error); | 300 goto out; |
298 299 /* Send the current value to the user and return if no new value. */ 300 error = sysctl_handle_int(oidp, &arg, 0, req); 301 if (error != 0 || req->newptr == NULL) | 301 302 /* Send the current value to the user and return if no new value. */ 303 error = sysctl_handle_int(oidp, &arg, 0, req); 304 if (error != 0 || req->newptr == NULL) |
302 return (error); | 305 goto out; |
303 304 /* Set the new value via the appropriate function. */ 305 error = handler(sc->handle, HCI_SET, &arg); 306 | 306 307 /* Set the new value via the appropriate function. */ 308 error = handler(sc->handle, HCI_SET, &arg); 309 |
310out: 311 ACPI_SERIAL_END(toshiba); |
|
307 return (error); 308} 309 310static int 311hci_force_fan(ACPI_HANDLE h, int op, UINT32 *state) 312{ 313 int ret; 314 | 312 return (error); 313} 314 315static int 316hci_force_fan(ACPI_HANDLE h, int op, UINT32 *state) 317{ 318 int ret; 319 |
320 ACPI_SERIAL_ASSERT(toshiba); |
|
315 if (op == HCI_SET) { 316 if (*state < 0 || *state > 1) 317 return (EINVAL); 318 *state <<= HCI_FAN_SHIFT; 319 } 320 ret = hci_call(h, op, HCI_REG_FAN, state); 321 if (ret == 0 && op == HCI_GET) 322 *state >>= HCI_FAN_SHIFT; 323 return (ret); 324} 325 326static int 327hci_video_output(ACPI_HANDLE h, int op, UINT32 *video_output) 328{ 329 int ret; 330 ACPI_STATUS status; 331 | 321 if (op == HCI_SET) { 322 if (*state < 0 || *state > 1) 323 return (EINVAL); 324 *state <<= HCI_FAN_SHIFT; 325 } 326 ret = hci_call(h, op, HCI_REG_FAN, state); 327 if (ret == 0 && op == HCI_GET) 328 *state >>= HCI_FAN_SHIFT; 329 return (ret); 330} 331 332static int 333hci_video_output(ACPI_HANDLE h, int op, UINT32 *video_output) 334{ 335 int ret; 336 ACPI_STATUS status; 337 |
338 ACPI_SERIAL_ASSERT(toshiba); |
|
332 if (op == HCI_SET) { 333 if (*video_output < 1 || *video_output > 7) 334 return (EINVAL); 335 if (h == NULL) 336 return (ENXIO); 337 *video_output |= HCI_VIDEO_OUTPUT_FLAG; 338 status = acpi_SetInteger(h, METHOD_VIDEO, *video_output); 339 if (ACPI_SUCCESS(status)) --- 9 unchanged lines hidden (view full) --- 349 return (ret); 350} 351 352static int 353hci_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *brightness) 354{ 355 int ret; 356 | 339 if (op == HCI_SET) { 340 if (*video_output < 1 || *video_output > 7) 341 return (EINVAL); 342 if (h == NULL) 343 return (ENXIO); 344 *video_output |= HCI_VIDEO_OUTPUT_FLAG; 345 status = acpi_SetInteger(h, METHOD_VIDEO, *video_output); 346 if (ACPI_SUCCESS(status)) --- 9 unchanged lines hidden (view full) --- 356 return (ret); 357} 358 359static int 360hci_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *brightness) 361{ 362 int ret; 363 |
364 ACPI_SERIAL_ASSERT(toshiba); |
|
357 if (op == HCI_SET) { 358 if (*brightness < 0 || *brightness > HCI_LCD_BRIGHTNESS_MAX) 359 return (EINVAL); 360 *brightness <<= HCI_LCD_BRIGHTNESS_SHIFT; 361 } 362 ret = hci_call(h, op, HCI_REG_LCD_BRIGHTNESS, brightness); 363 if (ret == 0 && op == HCI_GET) 364 *brightness >>= HCI_LCD_BRIGHTNESS_SHIFT; 365 return (ret); 366} 367 368static int 369hci_lcd_backlight(ACPI_HANDLE h, int op, UINT32 *backlight) 370{ | 365 if (op == HCI_SET) { 366 if (*brightness < 0 || *brightness > HCI_LCD_BRIGHTNESS_MAX) 367 return (EINVAL); 368 *brightness <<= HCI_LCD_BRIGHTNESS_SHIFT; 369 } 370 ret = hci_call(h, op, HCI_REG_LCD_BRIGHTNESS, brightness); 371 if (ret == 0 && op == HCI_GET) 372 *brightness >>= HCI_LCD_BRIGHTNESS_SHIFT; 373 return (ret); 374} 375 376static int 377hci_lcd_backlight(ACPI_HANDLE h, int op, UINT32 *backlight) 378{ |
379 380 ACPI_SERIAL_ASSERT(toshiba); |
|
371 if (op == HCI_SET) { 372 if (*backlight < 0 || *backlight > 1) 373 return (EINVAL); 374 } 375 return (hci_call(h, op, HCI_REG_LCD_BACKLIGHT, backlight)); 376} 377 378static int 379hci_cpu_speed(ACPI_HANDLE h, int op, UINT32 *speed) 380{ 381 int ret; 382 | 381 if (op == HCI_SET) { 382 if (*backlight < 0 || *backlight > 1) 383 return (EINVAL); 384 } 385 return (hci_call(h, op, HCI_REG_LCD_BACKLIGHT, backlight)); 386} 387 388static int 389hci_cpu_speed(ACPI_HANDLE h, int op, UINT32 *speed) 390{ 391 int ret; 392 |
393 ACPI_SERIAL_ASSERT(toshiba); |
|
383 if (op == HCI_SET) { 384 if (*speed < 0 || *speed > HCI_CPU_SPEED_MAX) 385 return (EINVAL); 386 *speed <<= HCI_CPU_SPEED_SHIFT; 387 } 388 ret = hci_call(h, op, HCI_REG_CPU_SPEED, speed); 389 if (ret == 0 && op == HCI_GET) 390 *speed >>= HCI_CPU_SPEED_SHIFT; --- 4 unchanged lines hidden (view full) --- 395hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg) 396{ 397 ACPI_OBJECT_LIST args; 398 ACPI_BUFFER results; 399 ACPI_OBJECT obj[HCI_WORDS]; 400 ACPI_OBJECT *res; 401 int status, i, ret; 402 | 394 if (op == HCI_SET) { 395 if (*speed < 0 || *speed > HCI_CPU_SPEED_MAX) 396 return (EINVAL); 397 *speed <<= HCI_CPU_SPEED_SHIFT; 398 } 399 ret = hci_call(h, op, HCI_REG_CPU_SPEED, speed); 400 if (ret == 0 && op == HCI_GET) 401 *speed >>= HCI_CPU_SPEED_SHIFT; --- 4 unchanged lines hidden (view full) --- 406hci_call(ACPI_HANDLE h, int op, int function, UINT32 *arg) 407{ 408 ACPI_OBJECT_LIST args; 409 ACPI_BUFFER results; 410 ACPI_OBJECT obj[HCI_WORDS]; 411 ACPI_OBJECT *res; 412 int status, i, ret; 413 |
414 ACPI_SERIAL_ASSERT(toshiba); |
|
403 status = ENXIO; 404 405 for (i = 0; i < HCI_WORDS; i++) { 406 obj[i].Type = ACPI_TYPE_INTEGER; 407 obj[i].Integer.Value = 0; 408 } 409 obj[HCI_REG_AX].Integer.Value = op; 410 obj[HCI_REG_BX].Integer.Value = function; --- 17 unchanged lines hidden (view full) --- 428 if (op == HCI_GET) 429 acpi_PkgInt32(res, HCI_REG_CX, arg); 430 status = 0; 431 } else if (function == HCI_REG_SYSTEM_EVENT && op == HCI_GET && 432 ret == HCI_NOT_SUPPORTED) { 433 /* 434 * Sometimes system events are disabled without us requesting 435 * it. This workaround attempts to re-enable them. | 415 status = ENXIO; 416 417 for (i = 0; i < HCI_WORDS; i++) { 418 obj[i].Type = ACPI_TYPE_INTEGER; 419 obj[i].Integer.Value = 0; 420 } 421 obj[HCI_REG_AX].Integer.Value = op; 422 obj[HCI_REG_BX].Integer.Value = function; --- 17 unchanged lines hidden (view full) --- 440 if (op == HCI_GET) 441 acpi_PkgInt32(res, HCI_REG_CX, arg); 442 status = 0; 443 } else if (function == HCI_REG_SYSTEM_EVENT && op == HCI_GET && 444 ret == HCI_NOT_SUPPORTED) { 445 /* 446 * Sometimes system events are disabled without us requesting 447 * it. This workaround attempts to re-enable them. |
448 * 449 * XXX This call probably shouldn't be recursive. Queueing 450 * a task via AcpiOsQueueForExecution() might be better. |
|
436 */ 437 i = 1; 438 hci_call(h, HCI_SET, HCI_REG_SYSTEM_EVENT, &i); 439 } 440 441end: 442 if (results.Pointer != NULL) 443 AcpiOsFree(results.Pointer); --- 5 unchanged lines hidden (view full) --- 449 * Perform a few actions based on the keypress. Users can extend this 450 * functionality by reading the keystrokes we send to devd(8). 451 */ 452static void 453hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h, UINT32 key) 454{ 455 UINT32 arg; 456 | 451 */ 452 i = 1; 453 hci_call(h, HCI_SET, HCI_REG_SYSTEM_EVENT, &i); 454 } 455 456end: 457 if (results.Pointer != NULL) 458 AcpiOsFree(results.Pointer); --- 5 unchanged lines hidden (view full) --- 464 * Perform a few actions based on the keypress. Users can extend this 465 * functionality by reading the keystrokes we send to devd(8). 466 */ 467static void 468hci_key_action(struct acpi_toshiba_softc *sc, ACPI_HANDLE h, UINT32 key) 469{ 470 UINT32 arg; 471 |
472 ACPI_SERIAL_ASSERT(toshiba); |
|
457 switch (key) { 458 case FN_F6_RELEASE: 459 /* Decrease LCD brightness. */ 460 hci_lcd_brightness(h, HCI_GET, &arg); 461 if (arg-- == 0) 462 arg = 0; 463 else 464 hci_lcd_brightness(h, HCI_SET, &arg); --- 31 unchanged lines hidden (view full) --- 496acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify, void *context) 497{ 498 struct acpi_toshiba_softc *sc; 499 UINT32 key; 500 501 sc = (struct acpi_toshiba_softc *)context; 502 503 if (notify == 0x80) { | 473 switch (key) { 474 case FN_F6_RELEASE: 475 /* Decrease LCD brightness. */ 476 hci_lcd_brightness(h, HCI_GET, &arg); 477 if (arg-- == 0) 478 arg = 0; 479 else 480 hci_lcd_brightness(h, HCI_SET, &arg); --- 31 unchanged lines hidden (view full) --- 512acpi_toshiba_notify(ACPI_HANDLE h, UINT32 notify, void *context) 513{ 514 struct acpi_toshiba_softc *sc; 515 UINT32 key; 516 517 sc = (struct acpi_toshiba_softc *)context; 518 519 if (notify == 0x80) { |
520 ACPI_SERIAL_BEGIN(toshiba); |
|
504 while (hci_call(h, HCI_GET, HCI_REG_SYSTEM_EVENT, &key) == 0) { 505 hci_key_action(sc, h, key); 506 acpi_UserNotify("TOSHIBA", h, (uint8_t)key); 507 } | 521 while (hci_call(h, HCI_GET, HCI_REG_SYSTEM_EVENT, &key) == 0) { 522 hci_key_action(sc, h, key); 523 acpi_UserNotify("TOSHIBA", h, (uint8_t)key); 524 } |
525 ACPI_SERIAL_END(toshiba); |
|
508 } else 509 device_printf(sc->dev, "unknown notify: 0x%x\n", notify); 510} 511 512/* 513 * Toshiba video pseudo-device to provide the DSSX method. 514 * 515 * HID Model --- 29 unchanged lines hidden --- | 526 } else 527 device_printf(sc->dev, "unknown notify: 0x%x\n", notify); 528} 529 530/* 531 * Toshiba video pseudo-device to provide the DSSX method. 532 * 533 * HID Model --- 29 unchanged lines hidden --- |