acpi_panasonic.c (134258) | acpi_panasonic.c (137365) |
---|---|
1/*- 2 * Copyright (c) 2003 OGAWA Takaya <t-ogawa@triaez.kaisei.org> 3 * Copyright (c) 2004 Yoshihiro TAKAHASHI <nyan@FreeBSD.org> 4 * All rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 OGAWA Takaya <t-ogawa@triaez.kaisei.org> 3 * Copyright (c) 2004 Yoshihiro TAKAHASHI <nyan@FreeBSD.org> 4 * All rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_panasonic.c 134258 2004-08-24 17:53:25Z njl $"); | 30__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_panasonic.c 137365 2004-11-07 23:18:23Z njl $"); |
31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/module.h> 37#include <sys/bus.h> | 31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/module.h> 37#include <sys/bus.h> |
38#include <sys/power.h> |
|
38 39#include "acpi.h" 40#include <dev/acpica/acpivar.h> 41 42/* Debug */ 43#undef ACPI_PANASONIC_DEBUG 44 45/* Operations */ 46#define HKEY_SET 0 47#define HKEY_GET 1 48 49/* Functions */ | 39 40#include "acpi.h" 41#include <dev/acpica/acpivar.h> 42 43/* Debug */ 44#undef ACPI_PANASONIC_DEBUG 45 46/* Operations */ 47#define HKEY_SET 0 48#define HKEY_GET 1 49 50/* Functions */ |
50#define HKEY_REG_LCD_BRIGHTNESS 0x04 | 51#define HKEY_REG_LCD_BRIGHTNESS_MAX_AC 0x02 52#define HKEY_REG_LCD_BRIGHTNESS_MIN_AC 0x03 53#define HKEY_REG_LCD_BRIGHTNESS_AC 0x04 54#define HKEY_REG_LCD_BRIGHTNESS_MAX_DC 0x05 55#define HKEY_REG_LCD_BRIGHTNESS_MIN_DC 0x06 56#define HKEY_REG_LCD_BRIGHTNESS_DC 0x07 |
51#define HKEY_REG_SOUND_MUTE 0x08 52 53/* Field definitions */ 54#define HKEY_LCD_BRIGHTNESS_BITS 4 55#define HKEY_LCD_BRIGHTNESS_DIV ((1 << HKEY_LCD_BRIGHTNESS_BITS) - 1) 56 57struct acpi_panasonic_softc { 58 device_t dev; 59 ACPI_HANDLE handle; 60 61 struct sysctl_ctx_list sysctl_ctx; 62 struct sysctl_oid *sysctl_tree; | 57#define HKEY_REG_SOUND_MUTE 0x08 58 59/* Field definitions */ 60#define HKEY_LCD_BRIGHTNESS_BITS 4 61#define HKEY_LCD_BRIGHTNESS_DIV ((1 << HKEY_LCD_BRIGHTNESS_BITS) - 1) 62 63struct acpi_panasonic_softc { 64 device_t dev; 65 ACPI_HANDLE handle; 66 67 struct sysctl_ctx_list sysctl_ctx; 68 struct sysctl_oid *sysctl_tree; |
69 70 eventhandler_tag power_evh; |
|
63}; 64 65/* Prototype for HKEY functions for getting/setting a value. */ 66typedef int hkey_fn_t(ACPI_HANDLE, int, UINT32 *); 67 68static int acpi_panasonic_probe(device_t dev); 69static int acpi_panasonic_attach(device_t dev); 70static int acpi_panasonic_detach(device_t dev); 71static int acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS); 72static ACPI_INTEGER acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index); 73static void acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, 74 ACPI_INTEGER val); 75static int acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, 76 ACPI_HANDLE h, UINT32 *arg); 77static void acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, 78 ACPI_HANDLE h, UINT32 key); 79static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, 80 void *context); | 71}; 72 73/* Prototype for HKEY functions for getting/setting a value. */ 74typedef int hkey_fn_t(ACPI_HANDLE, int, UINT32 *); 75 76static int acpi_panasonic_probe(device_t dev); 77static int acpi_panasonic_attach(device_t dev); 78static int acpi_panasonic_detach(device_t dev); 79static int acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS); 80static ACPI_INTEGER acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index); 81static void acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, 82 ACPI_INTEGER val); 83static int acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, 84 ACPI_HANDLE h, UINT32 *arg); 85static void acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, 86 ACPI_HANDLE h, UINT32 key); 87static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, 88 void *context); |
89static void acpi_panasonic_power_profile(void *arg); |
|
81 82static hkey_fn_t hkey_lcd_brightness_max; | 90 91static hkey_fn_t hkey_lcd_brightness_max; |
92static hkey_fn_t hkey_lcd_brightness_min; |
|
83static hkey_fn_t hkey_lcd_brightness; 84static hkey_fn_t hkey_sound_mute; | 93static hkey_fn_t hkey_lcd_brightness; 94static hkey_fn_t hkey_sound_mute; |
85static int lcd_brightness_max = 255; | |
86ACPI_SERIAL_DECL(panasonic, "ACPI Panasonic extras"); 87 88/* Table of sysctl names and HKEY functions to call. */ 89static struct { 90 char *name; 91 hkey_fn_t *handler; 92} sysctl_table[] = { 93 /* name, handler */ 94 {"lcd_brightness_max", hkey_lcd_brightness_max}, | 95ACPI_SERIAL_DECL(panasonic, "ACPI Panasonic extras"); 96 97/* Table of sysctl names and HKEY functions to call. */ 98static struct { 99 char *name; 100 hkey_fn_t *handler; 101} sysctl_table[] = { 102 /* name, handler */ 103 {"lcd_brightness_max", hkey_lcd_brightness_max}, |
104 {"lcd_brightness_min", hkey_lcd_brightness_min}, |
|
95 {"lcd_brightness", hkey_lcd_brightness}, 96 {"sound_mute", hkey_sound_mute}, 97 {NULL, NULL} 98}; 99 100static device_method_t acpi_panasonic_methods[] = { 101 DEVMETHOD(device_probe, acpi_panasonic_probe), 102 DEVMETHOD(device_attach, acpi_panasonic_attach), --- 70 unchanged lines hidden (view full) --- 173 acpi_panasonic_notify, sc); 174 if (ACPI_FAILURE(status)) { 175 device_printf(dev, "couldn't install notify handler - %s\n", 176 AcpiFormatException(status)); 177 sysctl_ctx_free(&sc->sysctl_ctx); 178 return (ENXIO); 179 } 180 | 105 {"lcd_brightness", hkey_lcd_brightness}, 106 {"sound_mute", hkey_sound_mute}, 107 {NULL, NULL} 108}; 109 110static device_method_t acpi_panasonic_methods[] = { 111 DEVMETHOD(device_probe, acpi_panasonic_probe), 112 DEVMETHOD(device_attach, acpi_panasonic_attach), --- 70 unchanged lines hidden (view full) --- 183 acpi_panasonic_notify, sc); 184 if (ACPI_FAILURE(status)) { 185 device_printf(dev, "couldn't install notify handler - %s\n", 186 AcpiFormatException(status)); 187 sysctl_ctx_free(&sc->sysctl_ctx); 188 return (ENXIO); 189 } 190 |
191 /* Install power profile event handler */ 192 sc->power_evh = EVENTHANDLER_REGISTER(power_profile_change, 193 acpi_panasonic_power_profile, sc->handle, 0); 194 |
|
181 return (0); 182} 183 184static int 185acpi_panasonic_detach(device_t dev) 186{ 187 struct acpi_panasonic_softc *sc; 188 189 sc = device_get_softc(dev); 190 | 195 return (0); 196} 197 198static int 199acpi_panasonic_detach(device_t dev) 200{ 201 struct acpi_panasonic_softc *sc; 202 203 sc = device_get_softc(dev); 204 |
205 /* Remove power profile event handler */ 206 EVENTHANDLER_DEREGISTER(power_profile_change, sc->power_evh); 207 |
|
191 /* Remove notify handler */ 192 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, 193 acpi_panasonic_notify); 194 195 /* Free sysctl tree */ 196 sysctl_ctx_free(&sc->sysctl_ctx); 197 198 return (0); --- 64 unchanged lines hidden (view full) --- 263 args.Count = 2; 264 args.Pointer = obj; 265 AcpiEvaluateObject(h, "SSET", &args, NULL); 266} 267 268static int 269hkey_lcd_brightness_max(ACPI_HANDLE h, int op, UINT32 *val) 270{ | 208 /* Remove notify handler */ 209 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY, 210 acpi_panasonic_notify); 211 212 /* Free sysctl tree */ 213 sysctl_ctx_free(&sc->sysctl_ctx); 214 215 return (0); --- 64 unchanged lines hidden (view full) --- 280 args.Count = 2; 281 args.Pointer = obj; 282 AcpiEvaluateObject(h, "SSET", &args, NULL); 283} 284 285static int 286hkey_lcd_brightness_max(ACPI_HANDLE h, int op, UINT32 *val) 287{ |
288 int reg; |
|
271 272 ACPI_SERIAL_ASSERT(panasonic); | 289 290 ACPI_SERIAL_ASSERT(panasonic); |
291 reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? 292 HKEY_REG_LCD_BRIGHTNESS_MAX_AC : HKEY_REG_LCD_BRIGHTNESS_MAX_DC; 293 |
|
273 switch (op) { 274 case HKEY_SET: | 294 switch (op) { 295 case HKEY_SET: |
275 if (*val < 0 || *val > 255) 276 return (EINVAL); 277 lcd_brightness_max = *val; | 296 return (EPERM); |
278 break; 279 case HKEY_GET: | 297 break; 298 case HKEY_GET: |
280 *val = lcd_brightness_max; | 299 *val = acpi_panasonic_sinf(h, reg); |
281 break; 282 } 283 284 return (0); 285} 286 287static int | 300 break; 301 } 302 303 return (0); 304} 305 306static int |
307hkey_lcd_brightness_min(ACPI_HANDLE h, int op, UINT32 *val) 308{ 309 int reg; 310 311 ACPI_SERIAL_ASSERT(panasonic); 312 reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? 313 HKEY_REG_LCD_BRIGHTNESS_MIN_AC : HKEY_REG_LCD_BRIGHTNESS_MIN_DC; 314 315 switch (op) { 316 case HKEY_SET: 317 return (EPERM); 318 break; 319 case HKEY_GET: 320 *val = acpi_panasonic_sinf(h, reg); 321 break; 322 } 323 324 return (0); 325} 326 327static int |
|
288hkey_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *val) 289{ | 328hkey_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *val) 329{ |
330 int reg; 331 UINT32 max, min; |
|
290 | 332 |
333 reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? 334 HKEY_REG_LCD_BRIGHTNESS_AC : HKEY_REG_LCD_BRIGHTNESS_DC; 335 |
|
291 ACPI_SERIAL_ASSERT(panasonic); 292 switch (op) { 293 case HKEY_SET: | 336 ACPI_SERIAL_ASSERT(panasonic); 337 switch (op) { 338 case HKEY_SET: |
294 if (*val < 0 || *val > lcd_brightness_max) | 339 hkey_lcd_brightness_max(h, HKEY_GET, &max); 340 hkey_lcd_brightness_min(h, HKEY_GET, &min); 341 if (*val < min || *val > max) |
295 return (EINVAL); | 342 return (EINVAL); |
296 acpi_panasonic_sset(h, HKEY_REG_LCD_BRIGHTNESS, *val); | 343 acpi_panasonic_sset(h, reg, *val); |
297 break; 298 case HKEY_GET: | 344 break; 345 case HKEY_GET: |
299 *val = acpi_panasonic_sinf(h, HKEY_REG_LCD_BRIGHTNESS); | 346 *val = acpi_panasonic_sinf(h, reg); |
300 break; 301 } 302 303 return (0); 304} 305 306static int 307hkey_sound_mute(ACPI_HANDLE h, int op, UINT32 *val) --- 50 unchanged lines hidden (view full) --- 358 359 return (status); 360} 361 362static void 363acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 364 UINT32 key) 365{ | 347 break; 348 } 349 350 return (0); 351} 352 353static int 354hkey_sound_mute(ACPI_HANDLE h, int op, UINT32 *val) --- 50 unchanged lines hidden (view full) --- 405 406 return (status); 407} 408 409static void 410acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 411 UINT32 key) 412{ |
366 int arg; | 413 int arg, max, min; |
367 368 ACPI_SERIAL_ASSERT(panasonic); 369 switch (key) { 370 case 1: 371 /* Decrease LCD brightness. */ | 414 415 ACPI_SERIAL_ASSERT(panasonic); 416 switch (key) { 417 case 1: 418 /* Decrease LCD brightness. */ |
419 hkey_lcd_brightness_max(h, HKEY_GET, &max); 420 hkey_lcd_brightness_min(h, HKEY_GET, &min); |
|
372 hkey_lcd_brightness(h, HKEY_GET, &arg); | 421 hkey_lcd_brightness(h, HKEY_GET, &arg); |
373 arg -= lcd_brightness_max / HKEY_LCD_BRIGHTNESS_DIV; 374 if (arg < 0) 375 arg = 0; 376 else if (arg > lcd_brightness_max) 377 arg = lcd_brightness_max; | 422 arg -= max / HKEY_LCD_BRIGHTNESS_DIV; 423 if (arg < min) 424 arg = min; 425 else if (arg > max) 426 arg = max; |
378 hkey_lcd_brightness(h, HKEY_SET, &arg); 379 break; 380 case 2: 381 /* Increase LCD brightness. */ | 427 hkey_lcd_brightness(h, HKEY_SET, &arg); 428 break; 429 case 2: 430 /* Increase LCD brightness. */ |
431 hkey_lcd_brightness_max(h, HKEY_GET, &max); 432 hkey_lcd_brightness_min(h, HKEY_GET, &min); |
|
382 hkey_lcd_brightness(h, HKEY_GET, &arg); | 433 hkey_lcd_brightness(h, HKEY_GET, &arg); |
383 arg += lcd_brightness_max / HKEY_LCD_BRIGHTNESS_DIV; 384 if (arg < 0) 385 arg = 0; 386 else if (arg > lcd_brightness_max) 387 arg = lcd_brightness_max; | 434 arg += max / HKEY_LCD_BRIGHTNESS_DIV; 435 if (arg < min) 436 arg = min; 437 else if (arg > max) 438 arg = max; |
388 hkey_lcd_brightness(h, HKEY_SET, &arg); 389 break; 390 case 4: 391 /* Toggle sound mute. */ 392 hkey_sound_mute(h, HKEY_GET, &arg); 393 if (arg) 394 arg = 0; 395 else --- 20 unchanged lines hidden (view full) --- 416 } 417 ACPI_SERIAL_END(panasonic); 418 break; 419 default: 420 device_printf(sc->dev, "unknown notify: %#x\n", notify); 421 break; 422 } 423} | 439 hkey_lcd_brightness(h, HKEY_SET, &arg); 440 break; 441 case 4: 442 /* Toggle sound mute. */ 443 hkey_sound_mute(h, HKEY_GET, &arg); 444 if (arg) 445 arg = 0; 446 else --- 20 unchanged lines hidden (view full) --- 467 } 468 ACPI_SERIAL_END(panasonic); 469 break; 470 default: 471 device_printf(sc->dev, "unknown notify: %#x\n", notify); 472 break; 473 } 474} |
475 476static void 477acpi_panasonic_power_profile(void *arg) 478{ 479 ACPI_HANDLE handle; 480 UINT32 brightness; 481 482 handle = (ACPI_HANDLE)arg; 483 484 /* Reset current brightness according to new power state. */ 485 ACPI_SERIAL_BEGIN(panasonic); 486 hkey_lcd_brightness(handle, HKEY_GET, &brightness); 487 hkey_lcd_brightness(handle, HKEY_SET, &brightness); 488 ACPI_SERIAL_END(panasonic); 489} |
|