Lines Matching +full:dev +full:- +full:handle

1 /*-
2 * Copyright (c) 2002-2003 Taku YAMAMOTO <taku@cent.saitama-u.ac.jp>
42 #include <contrib/dev/acpica/include/acpi.h>
44 #include <dev/acpica/acpivar.h>
47 #include <dev/evdev/input.h>
48 #include <dev/evdev/evdev.h>
53 ACPI_HANDLE handle;
78 ACPI_HANDLE handle;
152 (((1 << DOD_HEAD_ID_BITS) - 1) << DOD_HEAD_ID_SHIFT)
201 * (the video "bus"). The 'video_output' lock protects per-output
277 if (device_find_child(parent, "acpi_video", -1) == NULL)
282 acpi_video_probe(device_t dev)
287 devh = acpi_get_handle(dev);
295 device_set_desc(dev, "ACPI video extension");
300 acpi_video_attach(device_t dev)
308 sc = device_get_softc(dev);
315 sc->evdev = evdev_alloc();
316 evdev_set_name(sc->evdev, device_get_desc(dev));
317 evdev_set_phys(sc->evdev, device_get_nameunit(dev));
318 evdev_set_id(sc->evdev, BUS_HOST, 0, 0, 1);
319 evdev_support_event(sc->evdev, EV_SYN);
320 evdev_support_event(sc->evdev, EV_KEY);
322 evdev_support_key(sc->evdev, acpi_video_evdev_map[i].key);
324 if (evdev_register(sc->evdev) != 0)
331 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
337 sc->device = dev;
338 sc->handle = acpi_get_handle(dev);
339 STAILQ_INIT(&sc->vid_outputs);
341 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
343 sc->vid_pwr_evh = EVENTHANDLER_REGISTER(power_profile_change,
354 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_OSPM |
363 acpi_video_detach(device_t dev)
368 sc = device_get_softc(dev);
370 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
371 EVENTHANDLER_DEREGISTER(power_profile_change, sc->vid_pwr_evh);
372 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
376 STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vn) {
382 evdev_free(sc->evdev);
389 acpi_video_resume(device_t dev)
395 sc = device_get_softc(dev);
400 STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vn) {
401 if ((vo->adr & DOD_DEVID_MASK_FULL) != DOD_DEVID_LCD &&
402 (vo->adr & DOD_DEVID_MASK) != DOD_DEVID_INTDFP)
405 if ((vo_get_device_status(vo->handle) & DCS_ACTIVE) == 0)
409 if (level != -1)
419 acpi_video_shutdown(device_t dev)
423 sc = device_get_softc(dev);
424 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
436 acpi_video_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
451 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
452 dss = vo_get_graphics_state(vo->handle);
453 dcs = vo_get_device_status(vo->handle);
461 lasthand = vo->handle;
471 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next)
472 vo->handle = NULL;
474 STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vo_tmp) {
475 if (vo->handle == NULL) {
476 STAILQ_REMOVE(&sc->vid_outputs, vo,
488 device_printf(sc->device, "unknown notify event 0x%x\n",
495 acpi_video_push_evdev_event(sc->evdev, notify);
515 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
516 if (vo->vo_levels != NULL && vo->vo_brightness == -1)
519 vo->vo_economy : vo->vo_fullpower);
526 acpi_video_bind_outputs_subr(ACPI_HANDLE handle, UINT32 adr, void *context)
534 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
535 if (vo->adr == adr) {
536 acpi_video_vo_bind(vo, handle);
543 vo->evdev = sc->evdev;
545 acpi_video_vo_bind(vo, handle);
546 STAILQ_INSERT_TAIL(&sc->vid_outputs, vo, vo_next);
555 vid_enum_outputs(sc->handle, acpi_video_bind_outputs_subr, sc);
583 desc = "TV/HDTV or Analog-Video Monitor";
606 if (vn->vo_unit.num != n)
616 vo->handle = NULL;
617 vo->adr = adr;
618 vo->vo_unit.num = n;
619 vo->vo_hasbqc = -1;
620 vo->vo_level = -1;
621 vo->vo_brightness = -1;
622 vo->vo_fullpower = -1; /* TODO: override with tunables */
623 vo->vo_economy = -1;
624 vo->vo_numlevels = 0;
625 vo->vo_levels = NULL;
628 vo->vo_fullpower = x;
631 vo->vo_economy = x;
633 sysctl_ctx_init(&vo->vo_sysctl_ctx);
639 vo->vo_sysctl_tree =
640 SYSCTL_ADD_NODE(&vo->vo_sysctl_ctx,
644 if (vo->vo_sysctl_tree != NULL) {
645 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
646 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
651 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
652 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
657 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
658 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
664 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
665 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
671 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
672 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
689 printf(" (Non-VGA output device whose power "
698 acpi_video_vo_bind(struct acpi_video_output *vo, ACPI_HANDLE handle)
702 if (vo->vo_levels != NULL) {
703 AcpiRemoveNotifyHandler(vo->handle, ACPI_DEVICE_NOTIFY,
705 AcpiOsFree(vo->vo_levels);
706 vo->vo_levels = NULL;
708 vo->handle = handle;
709 vo->vo_numlevels = vo_get_brightness_levels(handle, &vo->vo_levels);
710 if (vo->vo_numlevels >= 2) {
711 if (vo->vo_fullpower == -1 ||
712 acpi_video_vo_check_level(vo, vo->vo_fullpower) != 0) {
713 /* XXX - can't deal with rebinding... */
714 vo->vo_fullpower = vo->vo_levels[BCL_FULLPOWER];
716 if (vo->vo_economy == -1 ||
717 acpi_video_vo_check_level(vo, vo->vo_economy) != 0) {
718 /* XXX - see above. */
719 vo->vo_economy = vo->vo_levels[BCL_ECONOMY];
721 AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
733 if (vo->vo_sysctl_tree != NULL) {
734 vo->vo_sysctl_tree = NULL;
735 sysctl_ctx_free(&vo->vo_sysctl_ctx);
737 if (vo->vo_levels != NULL) {
738 AcpiRemoveNotifyHandler(vo->handle, ACPI_DEVICE_NOTIFY,
740 AcpiOsFree(vo->vo_levels);
743 switch (vo->adr & DOD_DEVID_MASK) {
745 if ((vo->adr & DOD_DEVID_MASK_FULL) == DOD_DEVID_LCD)
772 if (vo->vo_levels == NULL)
774 for (i = 0; i < vo->vo_numlevels; i++)
775 if (vo->vo_levels[i] == level)
781 acpi_video_vo_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
788 if (vo->handle != handle)
793 if (vo->vo_numlevels <= 3)
800 if (vo->vo_levels == NULL)
808 notify, acpi_name(handle));
815 for (i = 2; i < vo->vo_numlevels; i++)
816 if (vo->vo_levels[i] == level) {
817 new_level = vo->vo_numlevels > i + 1 ?
818 vo->vo_levels[i + 1] : vo->vo_levels[2];
824 for (i = 0; i < vo->vo_numlevels; i++) {
825 j = vo->vo_levels[i];
838 for (i = 0; i < vo->vo_numlevels; i++)
839 if (vo->vo_levels[i] == 0) {
845 acpi_pwr_switch_consumer(handle, ACPI_STATE_D3);
850 vo->vo_brightness = new_level;
853 acpi_video_push_evdev_event(vo->evdev, notify);
871 if (vo->handle == NULL)
874 state = (vo_get_device_status(vo->handle) & DCS_ACTIVE) ? 1 : 0;
876 if (err != 0 || req->newptr == NULL)
878 vo_set_device_state(vo->handle,
894 if (vo->handle == NULL) {
898 if (vo->vo_levels == NULL) {
904 vo->vo_economy : vo->vo_fullpower;
905 level = vo->vo_brightness;
906 if (level == -1)
910 if (err != 0 || req->newptr == NULL)
912 if (level < -1 || level > 100) {
917 if (level != -1 && (err = acpi_video_vo_check_level(vo, level)))
919 vo->vo_brightness = level;
920 vo_set_brightness(vo, (level == -1) ? preset : level);
935 if (vo->handle == NULL) {
939 if (vo->vo_levels == NULL) {
944 &vo->vo_economy : &vo->vo_fullpower;
947 if (err != 0 || req->newptr == NULL)
949 if (level < -1 || level > 100) {
953 if (level == -1) {
956 level = vo->vo_levels[i];
960 if (vo->vo_brightness == -1 && (power_profile_get_state() == arg2))
978 if (vo->vo_levels == NULL) {
982 if (req->newptr != NULL) {
986 err = sysctl_handle_opaque(oidp, vo->vo_levels,
987 vo->vo_numlevels * sizeof(*vo->vo_levels), req);
995 vid_set_switch_policy(ACPI_HANDLE handle, UINT32 policy)
999 status = acpi_SetInteger(handle, "_DOS", policy);
1001 printf("can't evaluate %s._DOS - %s\n",
1002 acpi_name(handle), AcpiFormatException(status));
1013 vid_enum_outputs_subr(ACPI_HANDLE handle, UINT32 level __unused,
1023 status = acpi_GetInteger(handle, "_ADR", &adr);
1027 for (i = 0; i < argset->dod_pkg->Package.Count; i++) {
1028 if (acpi_PkgInt32(argset->dod_pkg, i, &val) == 0 &&
1031 argset->callback(handle, val, argset->context);
1032 argset->count++;
1040 vid_enum_outputs(ACPI_HANDLE handle,
1051 status = AcpiEvaluateObject(handle, "_DOD", NULL, &dod_buf);
1054 printf("can't evaluate %s._DOD - %s\n",
1055 acpi_name(handle), AcpiFormatException(status));
1056 argset.count = -1;
1062 acpi_name(handle));
1063 argset.count = -1;
1067 argset.count = res->Package.Count;
1074 status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, handle, 1,
1077 printf("failed walking down %s - %s\n",
1078 acpi_name(handle), AcpiFormatException(status));
1086 vo_get_brightness_levels(ACPI_HANDLE handle, int **levelp)
1095 status = AcpiEvaluateObject(handle, "_BCL", NULL, &bcl_buf);
1098 printf("can't evaluate %s._BCL - %s\n",
1099 acpi_name(handle), AcpiFormatException(status));
1105 acpi_name(handle));
1108 num = res->Package.Count;
1135 switch (vo->vo_hasbqc) {
1137 case -1:
1138 status = acpi_GetInteger(vo->handle, "_BQC", level);
1139 if (vo->vo_hasbqc == 1)
1141 vo->vo_hasbqc = status != AE_NOT_FOUND;
1142 if (vo->vo_hasbqc == 1)
1146 KASSERT(vo->vo_hasbqc == 0,
1147 ("bad vo_hasbqc state %d", vo->vo_hasbqc));
1148 *level = vo->vo_level;
1163 printf("can't evaluate %s._BQC - %s\n", acpi_name(vo->handle),
1165 return (-1);
1168 return (-1);
1180 status = acpi_SetInteger(vo->handle, "_BCM", level);
1182 printf("can't evaluate %s._BCM - %s\n",
1183 acpi_name(vo->handle), AcpiFormatException(status));
1185 vo->vo_level = level;
1192 vo_get_device_status(ACPI_HANDLE handle)
1199 status = acpi_GetInteger(handle, "_DCS", &dcs);
1206 printf("can't evaluate %s._DCS - %s\n",
1207 acpi_name(handle), AcpiFormatException(status));
1217 vo_get_graphics_state(ACPI_HANDLE handle)
1223 status = acpi_GetInteger(handle, "_DGS", &dgs);
1230 printf("can't evaluate %s._DGS - %s\n",
1231 acpi_name(handle), AcpiFormatException(status));
1241 vo_set_device_state(ACPI_HANDLE handle, UINT32 state)
1246 status = acpi_SetInteger(handle, "_DSS", state);
1248 printf("can't evaluate %s._DSS - %s\n",
1249 acpi_name(handle), AcpiFormatException(status));