Lines Matching +full:brightness +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * video.c - ACPI Video Driver
7 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
52 static int report_key_events = -1;
55 "0: none, 1: output changes, 2: brightness changes, 3: all");
57 static int hw_changes_brightness = -1;
60 "Set this to 1 on buggy hw which changes the brightness itself when "
61 "a hotkey is pressed: -1: auto, 0: normal 1: hw-changes-brightness");
70 static int only_lcd = -1;
89 ACPI_VIDEO_AC_LEVEL, /* level when machine has full power */
90 ACPI_VIDEO_BATTERY_LEVEL, /* level when machine is on batteries */
128 u32 display_index:4; /* A zero-based instance of the Display */
133 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
135 u32 pipe_id:3; /* For VGA multiple-head devices. */
186 u8 _BCL:1; /* Query list of brightness control levels supported */
187 u8 _BCM:1; /* Set the brightness level */
188 u8 _BQC:1; /* Get current brightness level */
202 struct acpi_video_device_brightness *brightness; member
213 int level);
216 unsigned long long *level, bool raw);
229 return -EINVAL; in acpi_video_get_brightness()
230 for (i = ACPI_VIDEO_FIRST_LEVEL; i < vd->brightness->count; i++) { in acpi_video_get_brightness()
231 if (vd->brightness->levels[i] == cur_level) in acpi_video_get_brightness()
232 return i - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_get_brightness()
239 int request_level = bd->props.brightness + ACPI_VIDEO_FIRST_LEVEL; in acpi_video_set_brightness()
242 cancel_delayed_work(&vd->switch_brightness_work); in acpi_video_set_brightness()
244 vd->brightness->levels[request_level]); in acpi_video_set_brightness()
256 struct acpi_video_device *video = cooling_dev->devdata; in video_get_max_state()
258 *state = video->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in video_get_max_state()
265 struct acpi_video_device *video = cooling_dev->devdata; in video_get_cur_state()
266 unsigned long long level; in video_get_cur_state() local
269 if (acpi_video_device_lcd_get_level_current(video, &level, false)) in video_get_cur_state()
270 return -EINVAL; in video_get_cur_state()
271 for (offset = ACPI_VIDEO_FIRST_LEVEL; offset < video->brightness->count; in video_get_cur_state()
273 if (level == video->brightness->levels[offset]) { in video_get_cur_state()
274 *state = video->brightness->count - offset - 1; in video_get_cur_state()
278 return -EINVAL; in video_get_cur_state()
284 struct acpi_video_device *video = cooling_dev->devdata; in video_set_cur_state()
285 int level; in video_set_cur_state() local
287 if (state >= video->brightness->count - ACPI_VIDEO_FIRST_LEVEL) in video_set_cur_state()
288 return -EINVAL; in video_set_cur_state()
290 state = video->brightness->count - state; in video_set_cur_state()
291 level = video->brightness->levels[state - 1]; in video_set_cur_state()
292 return acpi_video_device_lcd_set_level(video, level); in video_set_cur_state()
302 * --------------------------------------------------------------------------
304 * --------------------------------------------------------------------------
322 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_lcd_query_levels()
324 status = -EFAULT; in acpi_video_device_lcd_query_levels()
339 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) in acpi_video_device_lcd_set_level() argument
344 status = acpi_execute_simple_method(device->dev->handle, in acpi_video_device_lcd_set_level()
345 "_BCM", level); in acpi_video_device_lcd_set_level()
347 acpi_handle_info(device->dev->handle, "_BCM evaluation failed\n"); in acpi_video_device_lcd_set_level()
348 return -EIO; in acpi_video_device_lcd_set_level()
351 device->brightness->curr = level; in acpi_video_device_lcd_set_level()
352 for (state = ACPI_VIDEO_FIRST_LEVEL; state < device->brightness->count; in acpi_video_device_lcd_set_level()
354 if (level == device->brightness->levels[state]) { in acpi_video_device_lcd_set_level()
355 if (device->backlight) in acpi_video_device_lcd_set_level()
356 device->backlight->props.brightness = in acpi_video_device_lcd_set_level()
357 state - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_device_lcd_set_level()
361 acpi_handle_info(device->dev->handle, "Current brightness invalid\n"); in acpi_video_device_lcd_set_level()
362 return -EINVAL; in acpi_video_device_lcd_set_level()
367 * the _BQC return value to get the actual current brightness level
391 if (report_key_events == -1) in video_set_report_key_events()
392 report_key_events = (uintptr_t)id->driver_data; in video_set_report_key_events()
399 if (hw_changes_brightness == -1) in video_hw_changes_brightness()
477 * Some machines report wrong key events on the acpi-bus, suppress
480 * events, in this case acpi-video is considered the canonical source
483 * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb
513 * Some machines change the brightness themselves when a brightness
534 unsigned long long level; in acpi_video_bqc_value_to_level() local
536 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
542 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
543 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
544 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
546 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
549 level = bqc_value; in acpi_video_bqc_value_to_level()
552 level += bqc_offset_aml_bug_workaround; in acpi_video_bqc_value_to_level()
554 return level; in acpi_video_bqc_value_to_level()
559 unsigned long long *level, bool raw) in acpi_video_device_lcd_get_level_current() argument
564 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
565 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
567 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
568 NULL, level); in acpi_video_device_lcd_get_level_current()
579 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
582 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
583 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
584 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
588 * BQC returned an invalid level. in acpi_video_device_lcd_get_level_current()
591 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
592 "%s returned an invalid level", buf); in acpi_video_device_lcd_get_level_current()
593 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
598 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
599 * the correct current backlight level in most cases. in acpi_video_device_lcd_get_level_current()
603 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
605 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
609 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
627 return -ENODEV; in acpi_video_device_EDID()
633 return -EINVAL; in acpi_video_device_EDID()
635 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
637 return -ENODEV; in acpi_video_device_EDID()
641 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
644 acpi_handle_info(device->dev->handle, "Invalid _DDC data\n"); in acpi_video_device_EDID()
645 status = -EFAULT; in acpi_video_device_EDID()
667 * 0. The system BIOS should automatically control the brightness level
669 * - the power changes from AC to DC (ACPI appendix B)
670 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
671 * 1. The system BIOS should NOT automatically control the brightness
672 * level of the LCD when:
673 * - the power changes from AC to DC (ACPI appendix B)
674 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
676 * -EINVAL wrong arg.
684 if (!video->cap._DOS) in acpi_video_bus_DOS()
688 return -EINVAL; in acpi_video_bus_DOS()
689 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
690 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
693 return -EIO; in acpi_video_bus_DOS()
705 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
711 * We do this by changing the level first and then read out the current
712 * brightness level, if the value does not match, find out if it is using
718 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
720 unsigned long long level; in acpi_video_bqc_quirk() local
728 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
732 * If the _BCL package ordering is descending, the first level in acpi_video_bqc_quirk()
733 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
734 * matches the number of steps, we might confuse a returned level to in acpi_video_bqc_quirk()
741 * returned level = 100 in acpi_video_bqc_quirk()
743 * In this case 100 means the level, not the index, and _BCM failed. in acpi_video_bqc_quirk()
745 * level 0 is also 100, so we assume _BQC is indexed, when it's not. in acpi_video_bqc_quirk()
750 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
752 * would flash to 90% and then slowly down to the desired level (20). in acpi_video_bqc_quirk()
754 * The solution is simple; test anything other than the first level in acpi_video_bqc_quirk()
758 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
765 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
769 if (level != test_level) { in acpi_video_bqc_quirk()
771 if (level < br->count) { in acpi_video_bqc_quirk()
772 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
773 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
774 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
775 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
778 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
779 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
796 if (ACPI_FAILURE(acpi_video_device_lcd_query_levels(device->handle, &obj))) { in acpi_video_get_levels()
797 acpi_handle_debug(device->handle, in acpi_video_get_levels()
798 "Could not query available LCD brightness level\n"); in acpi_video_get_levels()
799 result = -ENODEV; in acpi_video_get_levels()
803 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
804 result = -EINVAL; in acpi_video_get_levels()
810 result = -ENOMEM; in acpi_video_get_levels()
819 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
820 sizeof(*br->levels), in acpi_video_get_levels()
822 if (!br->levels) { in acpi_video_get_levels()
823 result = -ENOMEM; in acpi_video_get_levels()
827 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
828 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
829 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
830 acpi_handle_info(device->handle, "Invalid data\n"); in acpi_video_get_levels()
833 value = (u32) o->integer.value; in acpi_video_get_levels()
836 && br->levels[count - 1] == value) in acpi_video_get_levels()
839 br->levels[count] = value; in acpi_video_get_levels()
841 if (br->levels[count] > max_level) in acpi_video_get_levels()
842 max_level = br->levels[count]; in acpi_video_get_levels()
850 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
853 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
855 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
860 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
861 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
862 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
863 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
864 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
867 acpi_handle_info(device->handle, in acpi_video_get_levels()
871 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
872 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
873 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
874 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
875 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
877 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
878 acpi_handle_info(device->handle, in acpi_video_get_levels()
881 br->count = count; in acpi_video_get_levels()
900 * Maximum brightness level
902 * Allocate and initialize device->brightness.
909 unsigned long long level, level_old; in acpi_video_init_brightness() local
913 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
916 device->brightness = br; in acpi_video_init_brightness()
919 br->curr = level = max_level; in acpi_video_init_brightness()
921 if (!device->cap._BQC) in acpi_video_init_brightness()
936 if (!device->cap._BQC) in acpi_video_init_brightness()
939 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
943 * level_old is invalid (no matter whether it's a level in acpi_video_init_brightness()
946 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
947 if (level == br->levels[i]) in acpi_video_init_brightness()
949 if (i == br->count || !level) in acpi_video_init_brightness()
950 level = max_level; in acpi_video_init_brightness()
953 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
957 acpi_handle_debug(device->dev->handle, "found %d brightness levels\n", in acpi_video_init_brightness()
958 br->count - ACPI_VIDEO_FIRST_LEVEL); in acpi_video_init_brightness()
963 kfree(br->levels); in acpi_video_init_brightness()
965 device->brightness = NULL; in acpi_video_init_brightness()
982 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
983 device->cap._ADR = 1; in acpi_video_device_find_cap()
984 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
985 device->cap._BCL = 1; in acpi_video_device_find_cap()
986 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
987 device->cap._BCM = 1; in acpi_video_device_find_cap()
988 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
989 device->cap._BQC = 1; in acpi_video_device_find_cap()
990 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
991 acpi_handle_info(device->dev->handle, in acpi_video_device_find_cap()
993 device->cap._BCQ = 1; in acpi_video_device_find_cap()
996 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
997 device->cap._DDC = 1; in acpi_video_device_find_cap()
1012 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1013 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1014 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1015 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1016 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1017 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1018 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1019 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1020 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1021 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1022 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1023 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1033 acpi_status status = -ENOENT; in acpi_video_bus_check()
1037 return -EINVAL; in acpi_video_bus_check()
1039 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1041 return -ENODEV; in acpi_video_bus_check()
1050 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1051 if (!video->cap._DOS) { in acpi_video_bus_check()
1053 acpi_device_bid(video->device)); in acpi_video_bus_check()
1055 video->flags.multihead = 1; in acpi_video_bus_check()
1060 if (video->cap._ROM) { in acpi_video_bus_check()
1061 video->flags.rom = 1; in acpi_video_bus_check()
1066 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1067 video->flags.post = 1; in acpi_video_bus_check()
1075 * --------------------------------------------------------------------------
1077 * --------------------------------------------------------------------------
1087 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1088 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1089 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1090 return &ids->value.attrib; in acpi_video_get_device_attr()
1103 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1104 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1105 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1106 return ids->value.int_val; in acpi_video_get_device_type()
1121 status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1128 dev_dbg(&device->dev, "Cannot attach\n"); in acpi_video_bus_get_one_device()
1129 return -ENOMEM; in acpi_video_bus_get_one_device()
1135 data->device_id = device_id; in acpi_video_bus_get_one_device()
1136 data->video = video; in acpi_video_bus_get_one_device()
1137 data->dev = device; in acpi_video_bus_get_one_device()
1138 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1143 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1144 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1146 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1149 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1152 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1155 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1158 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1161 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1162 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1166 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1169 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1172 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1175 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1178 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1185 if (data->cap._BCM && data->cap._BCL) in acpi_video_bus_get_one_device()
1188 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1189 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1190 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1193 video->child_count++; in acpi_video_bus_get_one_device()
1213 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1215 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1218 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1241 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1242 ids = &video->attached_array[i]; in acpi_video_device_bind()
1243 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1244 ids->bind_info = device; in acpi_video_device_bind()
1245 acpi_handle_debug(video->device->handle, "%s: %d\n", in acpi_video_device_bind()
1253 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1261 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1264 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1265 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1266 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1294 if (!video->cap._DOD) in acpi_video_device_enumerate()
1297 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1299 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1306 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1307 acpi_handle_info(video->device->handle, "Invalid _DOD data\n"); in acpi_video_device_enumerate()
1308 status = -EFAULT; in acpi_video_device_enumerate()
1312 acpi_handle_debug(video->device->handle, "Found %d video heads in _DOD\n", in acpi_video_device_enumerate()
1313 dod->package.count); in acpi_video_device_enumerate()
1315 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1319 status = -ENOMEM; in acpi_video_device_enumerate()
1324 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1325 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1327 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1328 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1333 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1336 acpi_handle_debug(video->device->handle, in acpi_video_device_enumerate()
1338 (int)obj->integer.value); in acpi_video_device_enumerate()
1343 kfree(video->attached_array); in acpi_video_device_enumerate()
1345 video->attached_array = active_list; in acpi_video_device_enumerate()
1346 video->attached_count = count; in acpi_video_device_enumerate()
1360 /* Find closest level to level_current */ in acpi_video_get_next_level()
1361 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1362 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1363 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1364 delta = l - level_current; in acpi_video_get_next_level()
1369 /* Adjust level_current to closest available level */ in acpi_video_get_next_level()
1371 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1372 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1404 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1405 int result = -EINVAL; in acpi_video_switch_brightness()
1408 if (!device->backlight) in acpi_video_switch_brightness()
1411 if (!device->brightness) in acpi_video_switch_brightness()
1425 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1430 acpi_handle_info(device->dev->handle, in acpi_video_switch_brightness()
1431 "Failed to switch brightness\n"); in acpi_video_switch_brightness()
1444 return -EINVAL; in acpi_video_get_edid()
1448 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1449 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1455 if (!video_device->cap._DDC) in acpi_video_get_edid()
1461 if (!video_device->flags.crt) in acpi_video_get_edid()
1465 if (!video_device->flags.tvout) in acpi_video_get_edid()
1469 if (!video_device->flags.dvi) in acpi_video_get_edid()
1473 if (!video_device->flags.lcd) in acpi_video_get_edid()
1477 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1484 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1489 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1494 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1498 return -ENODEV; in acpi_video_get_edid()
1520 * perform any automatic brightness change on receiving a notification.
1541 if (!video || !video->input) in acpi_video_bus_notify()
1544 input = video->input; in acpi_video_bus_notify()
1570 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_video_bus_notify()
1593 video_device->switch_brightness_event = event; in brightness_switch_event()
1594 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1608 device = video_device->dev; in acpi_video_device_notify()
1609 bus = video_device->video; in acpi_video_device_notify()
1610 input = bus->input; in acpi_video_device_notify()
1613 if (video_device->backlight) in acpi_video_device_notify()
1614 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1621 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1625 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1629 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1633 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1672 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1674 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1675 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1676 if (video_device && video_device->brightness) in acpi_video_resume()
1678 video_device->brightness->curr); in acpi_video_resume()
1687 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1693 if (handle == device->handle) in acpi_video_bus_match()
1725 if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) { in acpi_video_dev_register_backlight()
1728 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1736 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1737 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1743 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1744 device->backlight = NULL; in acpi_video_dev_register_backlight()
1749 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1752 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1753 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1755 device->cooling_dev = thermal_cooling_device_register("LCD", device, in acpi_video_dev_register_backlight()
1757 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1762 * -- dtor in acpi_video_dev_register_backlight()
1764 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1768 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1769 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1770 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1771 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1776 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1777 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1787 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1788 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1789 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1792 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1802 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1807 return dev->flags.lcd; in acpi_video_should_register_backlight()
1815 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1821 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1822 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1826 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1828 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1830 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1831 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1832 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1837 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1838 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1839 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1841 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1842 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1843 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1844 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1846 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1847 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1848 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1849 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1850 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1859 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1862 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1864 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1865 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1867 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1869 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1877 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1879 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1882 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1884 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1893 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1895 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1903 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1904 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1906 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1907 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1908 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1909 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1910 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1911 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1912 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1913 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1914 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1915 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1916 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1917 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1918 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1919 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1925 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1926 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1928 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1936 video->input = NULL; in acpi_video_bus_add_notify_handler()
1943 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
1944 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
1946 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
1954 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1955 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
1957 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1960 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
1961 video->input = NULL; in acpi_video_bus_remove_notify_handler()
1968 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
1969 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
1970 list_del(&dev->entry); in acpi_video_bus_put_devices()
1973 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
1988 acpi_dev_parent(device)->handle, 1, in acpi_video_bus_add()
1998 return -ENODEV; in acpi_video_bus_add()
2003 return -ENOMEM; in acpi_video_bus_add()
2006 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2008 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2012 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2014 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2018 video->device = device; in acpi_video_bus_add()
2021 device->driver_data = video; in acpi_video_bus_add()
2028 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2029 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2037 * evaluated to have functional panel brightness control. in acpi_video_bus_add()
2041 pr_info("%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2043 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2044 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2045 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2047 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2051 * If backlight-type auto-detection is used then a native backlight may in acpi_video_bus_add()
2056 * Register the backlight now when not using auto-detection, so that in acpi_video_bus_add()
2057 * when the kernel cmdline or DMI-quirks are used the backlight will in acpi_video_bus_add()
2080 list_del(&video->entry); in acpi_video_bus_add()
2085 kfree(video->attached_array); in acpi_video_bus_add()
2088 device->driver_data = NULL; in acpi_video_bus_add()
2107 list_del(&video->entry); in acpi_video_bus_remove()
2114 kfree(video->attached_array); in acpi_video_bus_remove()
2120 if (dev->device == 0x00D1) in is_i740()
2122 if (dev->device == 0x7000) in is_i740()
2134 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2136 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2149 /* Check if the chassis-type indicates there is no builtin LCD panel */
2182 * 2.1 Report a desktop/server DMI chassis-type, or
2183 * 2.2 Are an ACPI-reduced-hardware platform (and thus won't use the EC for
2213 if (only_lcd == -1) in acpi_video_register()
2278 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()