acpi_panasonic.c (132611) | acpi_panasonic.c (133629) |
---|---|
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 132611 2004-07-24 20:40:02Z njl $"); | 30__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_panasonic.c 133629 2004-08-13 06:22:31Z 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> 38 --- 39 unchanged lines hidden (view full) --- 78 ACPI_HANDLE h, UINT32 key); 79static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, 80 void *context); 81 82static hkey_fn_t hkey_lcd_brightness_max; 83static hkey_fn_t hkey_lcd_brightness; 84static hkey_fn_t hkey_sound_mute; 85static int lcd_brightness_max = 255; | 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 --- 39 unchanged lines hidden (view full) --- 78 ACPI_HANDLE h, UINT32 key); 79static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, 80 void *context); 81 82static hkey_fn_t hkey_lcd_brightness_max; 83static hkey_fn_t hkey_lcd_brightness; 84static hkey_fn_t hkey_sound_mute; 85static int lcd_brightness_max = 255; |
86ACPI_SERIAL_DECL(panasonic, "ACPI Panasonic extras"); |
|
86 87/* Table of sysctl names and HKEY functions to call. */ 88static struct { 89 char *name; 90 hkey_fn_t *handler; 91} sysctl_table[] = { 92 /* name, handler */ 93 {"lcd_brightness_max", hkey_lcd_brightness_max}, --- 111 unchanged lines hidden (view full) --- 205 int function, error; 206 hkey_fn_t *handler; 207 208 sc = (struct acpi_panasonic_softc *)oidp->oid_arg1; 209 function = oidp->oid_arg2; 210 handler = sysctl_table[function].handler; 211 212 /* Get the current value from the appropriate function. */ | 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}, --- 111 unchanged lines hidden (view full) --- 206 int function, error; 207 hkey_fn_t *handler; 208 209 sc = (struct acpi_panasonic_softc *)oidp->oid_arg1; 210 function = oidp->oid_arg2; 211 handler = sysctl_table[function].handler; 212 213 /* Get the current value from the appropriate function. */ |
214 ACPI_SERIAL_BEGIN(panasonic); |
|
213 error = handler(sc->handle, HKEY_GET, &arg); 214 if (error != 0) | 215 error = handler(sc->handle, HKEY_GET, &arg); 216 if (error != 0) |
215 return (error); | 217 goto out; |
216 217 /* Send the current value to the user and return if no new value. */ 218 error = sysctl_handle_int(oidp, &arg, 0, req); 219 if (error != 0 || req->newptr == NULL) | 218 219 /* Send the current value to the user and return if no new value. */ 220 error = sysctl_handle_int(oidp, &arg, 0, req); 221 if (error != 0 || req->newptr == NULL) |
220 return (error); | 222 goto out; |
221 222 /* Set the new value via the appropriate function. */ 223 error = handler(sc->handle, HKEY_SET, &arg); | 223 224 /* Set the new value via the appropriate function. */ 225 error = handler(sc->handle, HKEY_SET, &arg); |
226 ACPI_SERIAL_END(panasonic); |
|
224 | 227 |
228out: |
|
225 return (error); 226} 227 228static ACPI_INTEGER 229acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index) 230{ 231 ACPI_BUFFER buf; 232 ACPI_OBJECT *res; 233 ACPI_INTEGER ret; 234 | 229 return (error); 230} 231 232static ACPI_INTEGER 233acpi_panasonic_sinf(ACPI_HANDLE h, ACPI_INTEGER index) 234{ 235 ACPI_BUFFER buf; 236 ACPI_OBJECT *res; 237 ACPI_INTEGER ret; 238 |
239 ACPI_SERIAL_ASSERT(panasonic); |
|
235 ret = -1; 236 buf.Length = ACPI_ALLOCATE_BUFFER; 237 buf.Pointer = NULL; 238 AcpiEvaluateObject(h, "SINF", NULL, &buf); 239 res = (ACPI_OBJECT *)buf.Pointer; 240 if (res->Type == ACPI_TYPE_PACKAGE) 241 ret = res->Package.Elements[index].Integer.Value; 242 AcpiOsFree(buf.Pointer); 243 244 return (ret); 245} 246 247static void 248acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, ACPI_INTEGER val) 249{ 250 ACPI_OBJECT_LIST args; 251 ACPI_OBJECT obj[2]; 252 | 240 ret = -1; 241 buf.Length = ACPI_ALLOCATE_BUFFER; 242 buf.Pointer = NULL; 243 AcpiEvaluateObject(h, "SINF", NULL, &buf); 244 res = (ACPI_OBJECT *)buf.Pointer; 245 if (res->Type == ACPI_TYPE_PACKAGE) 246 ret = res->Package.Elements[index].Integer.Value; 247 AcpiOsFree(buf.Pointer); 248 249 return (ret); 250} 251 252static void 253acpi_panasonic_sset(ACPI_HANDLE h, ACPI_INTEGER index, ACPI_INTEGER val) 254{ 255 ACPI_OBJECT_LIST args; 256 ACPI_OBJECT obj[2]; 257 |
258 ACPI_SERIAL_ASSERT(panasonic); |
|
253 obj[0].Type = ACPI_TYPE_INTEGER; 254 obj[0].Integer.Value = index; 255 obj[1].Type = ACPI_TYPE_INTEGER; 256 obj[1].Integer.Value = val; 257 args.Count = 2; 258 args.Pointer = obj; 259 AcpiEvaluateObject(h, "SSET", &args, NULL); 260} 261 262static int 263hkey_lcd_brightness_max(ACPI_HANDLE h, int op, UINT32 *val) 264{ 265 | 259 obj[0].Type = ACPI_TYPE_INTEGER; 260 obj[0].Integer.Value = index; 261 obj[1].Type = ACPI_TYPE_INTEGER; 262 obj[1].Integer.Value = val; 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{ 271 |
272 ACPI_SERIAL_ASSERT(panasonic); |
|
266 switch (op) { 267 case HKEY_SET: 268 if (*val < 0 || *val > 255) 269 return (EINVAL); 270 lcd_brightness_max = *val; 271 break; 272 case HKEY_GET: 273 *val = lcd_brightness_max; 274 break; 275 } 276 277 return (0); 278} 279 280static int 281hkey_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *val) 282{ 283 | 273 switch (op) { 274 case HKEY_SET: 275 if (*val < 0 || *val > 255) 276 return (EINVAL); 277 lcd_brightness_max = *val; 278 break; 279 case HKEY_GET: 280 *val = lcd_brightness_max; 281 break; 282 } 283 284 return (0); 285} 286 287static int 288hkey_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *val) 289{ 290 |
291 ACPI_SERIAL_ASSERT(panasonic); |
|
284 switch (op) { 285 case HKEY_SET: 286 if (*val < 0 || *val > lcd_brightness_max) 287 return (EINVAL); 288 acpi_panasonic_sset(h, HKEY_REG_LCD_BRIGHTNESS, *val); 289 break; 290 case HKEY_GET: 291 *val = acpi_panasonic_sinf(h, HKEY_REG_LCD_BRIGHTNESS); 292 break; 293 } 294 295 return (0); 296} 297 298static int 299hkey_sound_mute(ACPI_HANDLE h, int op, UINT32 *val) 300{ 301 | 292 switch (op) { 293 case HKEY_SET: 294 if (*val < 0 || *val > lcd_brightness_max) 295 return (EINVAL); 296 acpi_panasonic_sset(h, HKEY_REG_LCD_BRIGHTNESS, *val); 297 break; 298 case HKEY_GET: 299 *val = acpi_panasonic_sinf(h, HKEY_REG_LCD_BRIGHTNESS); 300 break; 301 } 302 303 return (0); 304} 305 306static int 307hkey_sound_mute(ACPI_HANDLE h, int op, UINT32 *val) 308{ 309 |
310 ACPI_SERIAL_ASSERT(panasonic); |
|
302 switch (op) { 303 case HKEY_SET: 304 if (*val != 0 && *val != 1) 305 return (EINVAL); 306 acpi_panasonic_sset(h, HKEY_REG_SOUND_MUTE, *val); 307 break; 308 case HKEY_GET: 309 *val = acpi_panasonic_sinf(h, HKEY_REG_SOUND_MUTE); --- 7 unchanged lines hidden (view full) --- 317acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 318 UINT32 *arg) 319{ 320 ACPI_BUFFER buf; 321 ACPI_OBJECT *res; 322 ACPI_INTEGER val; 323 int status; 324 | 311 switch (op) { 312 case HKEY_SET: 313 if (*val != 0 && *val != 1) 314 return (EINVAL); 315 acpi_panasonic_sset(h, HKEY_REG_SOUND_MUTE, *val); 316 break; 317 case HKEY_GET: 318 *val = acpi_panasonic_sinf(h, HKEY_REG_SOUND_MUTE); --- 7 unchanged lines hidden (view full) --- 326acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 327 UINT32 *arg) 328{ 329 ACPI_BUFFER buf; 330 ACPI_OBJECT *res; 331 ACPI_INTEGER val; 332 int status; 333 |
334 ACPI_SERIAL_ASSERT(panasonic); |
|
325 status = ENXIO; 326 327 buf.Length = ACPI_ALLOCATE_BUFFER; 328 buf.Pointer = NULL; 329 AcpiEvaluateObject(h, "HINF", NULL, &buf); 330 res = (ACPI_OBJECT *)buf.Pointer; 331 if (res->Type != ACPI_TYPE_INTEGER) { 332 device_printf(sc->dev, "HINF returned non-integer\n"); --- 17 unchanged lines hidden (view full) --- 350} 351 352static void 353acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 354 UINT32 key) 355{ 356 int arg; 357 | 335 status = ENXIO; 336 337 buf.Length = ACPI_ALLOCATE_BUFFER; 338 buf.Pointer = NULL; 339 AcpiEvaluateObject(h, "HINF", NULL, &buf); 340 res = (ACPI_OBJECT *)buf.Pointer; 341 if (res->Type != ACPI_TYPE_INTEGER) { 342 device_printf(sc->dev, "HINF returned non-integer\n"); --- 17 unchanged lines hidden (view full) --- 360} 361 362static void 363acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h, 364 UINT32 key) 365{ 366 int arg; 367 |
368 ACPI_SERIAL_ASSERT(panasonic); |
|
358 switch (key) { 359 case 1: 360 /* Decrease LCD brightness. */ 361 hkey_lcd_brightness(h, HKEY_GET, &arg); 362 arg -= lcd_brightness_max / HKEY_LCD_BRIGHTNESS_DIV; 363 if (arg < 0) 364 arg = 0; 365 else if (arg > lcd_brightness_max) --- 27 unchanged lines hidden (view full) --- 393{ 394 struct acpi_panasonic_softc *sc; 395 UINT32 key; 396 397 sc = (struct acpi_panasonic_softc *)context; 398 399 switch (notify) { 400 case 0x80: | 369 switch (key) { 370 case 1: 371 /* Decrease LCD brightness. */ 372 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) --- 27 unchanged lines hidden (view full) --- 404{ 405 struct acpi_panasonic_softc *sc; 406 UINT32 key; 407 408 sc = (struct acpi_panasonic_softc *)context; 409 410 switch (notify) { 411 case 0x80: |
412 ACPI_SERIAL_BEGIN(panasonic); |
|
401 if (acpi_panasonic_hkey_event(sc, h, &key) == 0) { 402 acpi_panasonic_hkey_action(sc, h, key); 403 acpi_UserNotify("Panasonic", h, (uint8_t)key); 404 } | 413 if (acpi_panasonic_hkey_event(sc, h, &key) == 0) { 414 acpi_panasonic_hkey_action(sc, h, key); 415 acpi_UserNotify("Panasonic", h, (uint8_t)key); 416 } |
417 ACPI_SERIAL_END(panasonic); |
|
405 break; 406 default: 407 device_printf(sc->dev, "unknown notify: %#x\n", notify); 408 break; 409 } 410} | 418 break; 419 default: 420 device_printf(sc->dev, "unknown notify: %#x\n", notify); 421 break; 422 } 423} |