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;
102 ACPI_VIDEO_AC_LEVEL, /* level when machine has full power */
103 ACPI_VIDEO_BATTERY_LEVEL, /* level when machine is on batteries */
142 u32 display_index:4; /* A zero-based instance of the Display */
147 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
149 u32 pipe_id:3; /* For VGA multiple-head devices. */
200 u8 _BCL:1; /* Query list of brightness control levels supported */
201 u8 _BCM:1; /* Set the brightness level */
202 u8 _BQC:1; /* Get current brightness level */
216 struct acpi_video_device_brightness *brightness; member
227 int level);
230 unsigned long long *level, bool raw);
243 return -EINVAL; in acpi_video_get_brightness()
244 for (i = ACPI_VIDEO_FIRST_LEVEL; i < vd->brightness->count; i++) { in acpi_video_get_brightness()
245 if (vd->brightness->levels[i] == cur_level) in acpi_video_get_brightness()
246 return i - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_get_brightness()
253 int request_level = bd->props.brightness + ACPI_VIDEO_FIRST_LEVEL; in acpi_video_set_brightness()
256 cancel_delayed_work(&vd->switch_brightness_work); in acpi_video_set_brightness()
258 vd->brightness->levels[request_level]); in acpi_video_set_brightness()
270 struct acpi_device *device = cooling_dev->devdata; in video_get_max_state()
273 *state = video->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in video_get_max_state()
280 struct acpi_device *device = cooling_dev->devdata; in video_get_cur_state()
282 unsigned long long level; in video_get_cur_state() local
285 if (acpi_video_device_lcd_get_level_current(video, &level, false)) in video_get_cur_state()
286 return -EINVAL; in video_get_cur_state()
287 for (offset = ACPI_VIDEO_FIRST_LEVEL; offset < video->brightness->count; in video_get_cur_state()
289 if (level == video->brightness->levels[offset]) { in video_get_cur_state()
290 *state = video->brightness->count - offset - 1; in video_get_cur_state()
294 return -EINVAL; in video_get_cur_state()
300 struct acpi_device *device = cooling_dev->devdata; in video_set_cur_state()
302 int level; in video_set_cur_state() local
304 if (state >= video->brightness->count - ACPI_VIDEO_FIRST_LEVEL) in video_set_cur_state()
305 return -EINVAL; in video_set_cur_state()
307 state = video->brightness->count - state; in video_set_cur_state()
308 level = video->brightness->levels[state - 1]; in video_set_cur_state()
309 return acpi_video_device_lcd_set_level(video, level); in video_set_cur_state()
319 * --------------------------------------------------------------------------
321 * --------------------------------------------------------------------------
339 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_lcd_query_levels()
341 status = -EFAULT; in acpi_video_device_lcd_query_levels()
356 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) in acpi_video_device_lcd_set_level() argument
361 status = acpi_execute_simple_method(device->dev->handle, in acpi_video_device_lcd_set_level()
362 "_BCM", level); in acpi_video_device_lcd_set_level()
364 acpi_handle_info(device->dev->handle, "_BCM evaluation failed\n"); in acpi_video_device_lcd_set_level()
365 return -EIO; in acpi_video_device_lcd_set_level()
368 device->brightness->curr = level; in acpi_video_device_lcd_set_level()
369 for (state = ACPI_VIDEO_FIRST_LEVEL; state < device->brightness->count; in acpi_video_device_lcd_set_level()
371 if (level == device->brightness->levels[state]) { in acpi_video_device_lcd_set_level()
372 if (device->backlight) in acpi_video_device_lcd_set_level()
373 device->backlight->props.brightness = in acpi_video_device_lcd_set_level()
374 state - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_device_lcd_set_level()
378 acpi_handle_info(device->dev->handle, "Current brightness invalid\n"); in acpi_video_device_lcd_set_level()
379 return -EINVAL; in acpi_video_device_lcd_set_level()
384 * the _BQC return value to get the actual current brightness level
408 if (report_key_events == -1) in video_set_report_key_events()
409 report_key_events = (uintptr_t)id->driver_data; in video_set_report_key_events()
416 if (hw_changes_brightness == -1) in video_hw_changes_brightness()
494 * Some machines report wrong key events on the acpi-bus, suppress
497 * events, in this case acpi-video is considered the canonical source
500 * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb
521 * Some machines change the brightness themselves when a brightness
542 unsigned long long level; in acpi_video_bqc_value_to_level() local
544 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
550 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
551 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
552 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
554 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
557 level = bqc_value; in acpi_video_bqc_value_to_level()
560 level += bqc_offset_aml_bug_workaround; in acpi_video_bqc_value_to_level()
562 return level; in acpi_video_bqc_value_to_level()
567 unsigned long long *level, bool raw) in acpi_video_device_lcd_get_level_current() argument
572 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
573 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
575 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
576 NULL, level); in acpi_video_device_lcd_get_level_current()
587 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
590 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
591 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
592 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
596 * BQC returned an invalid level. in acpi_video_device_lcd_get_level_current()
599 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
600 "%s returned an invalid level", buf); in acpi_video_device_lcd_get_level_current()
601 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
606 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
607 * the correct current backlight level in most cases. in acpi_video_device_lcd_get_level_current()
611 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
613 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
617 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
635 return -ENODEV; in acpi_video_device_EDID()
641 return -EINVAL; in acpi_video_device_EDID()
643 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
645 return -ENODEV; in acpi_video_device_EDID()
649 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
652 acpi_handle_info(device->dev->handle, "Invalid _DDC data\n"); in acpi_video_device_EDID()
653 status = -EFAULT; in acpi_video_device_EDID()
675 * 0. The system BIOS should automatically control the brightness level
677 * - the power changes from AC to DC (ACPI appendix B)
678 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
679 * 1. The system BIOS should NOT automatically control the brightness
680 * level of the LCD when:
681 * - the power changes from AC to DC (ACPI appendix B)
682 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
684 * -EINVAL wrong arg.
692 if (!video->cap._DOS) in acpi_video_bus_DOS()
696 return -EINVAL; in acpi_video_bus_DOS()
697 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
698 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
701 return -EIO; in acpi_video_bus_DOS()
713 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
719 * We do this by changing the level first and then read out the current
720 * brightness level, if the value does not match, find out if it is using
726 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
728 unsigned long long level; in acpi_video_bqc_quirk() local
736 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
740 * If the _BCL package ordering is descending, the first level in acpi_video_bqc_quirk()
741 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
742 * matches the number of steps, we might confuse a returned level to in acpi_video_bqc_quirk()
749 * returned level = 100 in acpi_video_bqc_quirk()
751 * In this case 100 means the level, not the index, and _BCM failed. in acpi_video_bqc_quirk()
753 * level 0 is also 100, so we assume _BQC is indexed, when it's not. in acpi_video_bqc_quirk()
758 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
760 * would flash to 90% and then slowly down to the desired level (20). in acpi_video_bqc_quirk()
762 * The solution is simple; test anything other than the first level in acpi_video_bqc_quirk()
766 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
773 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
777 if (level != test_level) { in acpi_video_bqc_quirk()
779 if (level < br->count) { in acpi_video_bqc_quirk()
780 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
781 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
782 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
783 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
786 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
787 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
804 if (ACPI_FAILURE(acpi_video_device_lcd_query_levels(device->handle, &obj))) { in acpi_video_get_levels()
805 acpi_handle_debug(device->handle, in acpi_video_get_levels()
806 "Could not query available LCD brightness level\n"); in acpi_video_get_levels()
807 result = -ENODEV; in acpi_video_get_levels()
811 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
812 result = -EINVAL; in acpi_video_get_levels()
818 result = -ENOMEM; in acpi_video_get_levels()
827 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
828 sizeof(*br->levels), in acpi_video_get_levels()
830 if (!br->levels) { in acpi_video_get_levels()
831 result = -ENOMEM; in acpi_video_get_levels()
835 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
836 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
837 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
838 acpi_handle_info(device->handle, "Invalid data\n"); in acpi_video_get_levels()
841 value = (u32) o->integer.value; in acpi_video_get_levels()
844 && br->levels[count - 1] == value) in acpi_video_get_levels()
847 br->levels[count] = value; in acpi_video_get_levels()
849 if (br->levels[count] > max_level) in acpi_video_get_levels()
850 max_level = br->levels[count]; in acpi_video_get_levels()
858 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
861 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
863 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
868 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
869 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
870 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
871 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
872 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
875 acpi_handle_info(device->handle, in acpi_video_get_levels()
879 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
880 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
881 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
882 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
883 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
885 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
886 acpi_handle_info(device->handle, in acpi_video_get_levels()
889 br->count = count; in acpi_video_get_levels()
908 * Maximum brightness level
910 * Allocate and initialize device->brightness.
917 unsigned long long level, level_old; in acpi_video_init_brightness() local
921 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
924 device->brightness = br; in acpi_video_init_brightness()
927 br->curr = level = max_level; in acpi_video_init_brightness()
929 if (!device->cap._BQC) in acpi_video_init_brightness()
944 if (!device->cap._BQC) in acpi_video_init_brightness()
947 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
951 * level_old is invalid (no matter whether it's a level in acpi_video_init_brightness()
954 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
955 if (level == br->levels[i]) in acpi_video_init_brightness()
957 if (i == br->count || !level) in acpi_video_init_brightness()
958 level = max_level; in acpi_video_init_brightness()
961 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
965 acpi_handle_debug(device->dev->handle, "found %d brightness levels\n", in acpi_video_init_brightness()
966 br->count - ACPI_VIDEO_FIRST_LEVEL); in acpi_video_init_brightness()
971 kfree(br->levels); in acpi_video_init_brightness()
973 device->brightness = NULL; in acpi_video_init_brightness()
990 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
991 device->cap._ADR = 1; in acpi_video_device_find_cap()
992 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
993 device->cap._BCL = 1; in acpi_video_device_find_cap()
994 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
995 device->cap._BCM = 1; in acpi_video_device_find_cap()
996 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
997 device->cap._BQC = 1; in acpi_video_device_find_cap()
998 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
999 acpi_handle_info(device->dev->handle, in acpi_video_device_find_cap()
1001 device->cap._BCQ = 1; in acpi_video_device_find_cap()
1004 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
1005 device->cap._DDC = 1; in acpi_video_device_find_cap()
1020 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1021 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1022 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1023 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1024 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1025 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1026 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1027 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1028 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1029 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1030 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1031 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1041 acpi_status status = -ENOENT; in acpi_video_bus_check()
1045 return -EINVAL; in acpi_video_bus_check()
1047 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1049 return -ENODEV; in acpi_video_bus_check()
1058 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1059 if (!video->cap._DOS) { in acpi_video_bus_check()
1061 acpi_device_bid(video->device)); in acpi_video_bus_check()
1063 video->flags.multihead = 1; in acpi_video_bus_check()
1068 if (video->cap._ROM) { in acpi_video_bus_check()
1069 video->flags.rom = 1; in acpi_video_bus_check()
1074 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1075 video->flags.post = 1; in acpi_video_bus_check()
1083 * --------------------------------------------------------------------------
1085 * --------------------------------------------------------------------------
1095 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1096 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1097 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1098 return &ids->value.attrib; in acpi_video_get_device_attr()
1111 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1112 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1113 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1114 return ids->value.int_val; in acpi_video_get_device_type()
1129 status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1136 dev_dbg(&device->dev, "Cannot attach\n"); in acpi_video_bus_get_one_device()
1137 return -ENOMEM; in acpi_video_bus_get_one_device()
1142 device->driver_data = data; in acpi_video_bus_get_one_device()
1144 data->device_id = device_id; in acpi_video_bus_get_one_device()
1145 data->video = video; in acpi_video_bus_get_one_device()
1146 data->dev = device; in acpi_video_bus_get_one_device()
1147 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1152 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1153 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1155 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1158 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1161 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1164 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1167 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1170 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1171 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1175 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1178 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1181 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1184 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1187 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1194 if (data->cap._BCM && data->cap._BCL) in acpi_video_bus_get_one_device()
1197 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1198 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1199 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1202 video->child_count++; in acpi_video_bus_get_one_device()
1222 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1224 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1227 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1250 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1251 ids = &video->attached_array[i]; in acpi_video_device_bind()
1252 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1253 ids->bind_info = device; in acpi_video_device_bind()
1254 acpi_handle_debug(video->device->handle, "%s: %d\n", in acpi_video_device_bind()
1262 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1270 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1273 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1274 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1275 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1303 if (!video->cap._DOD) in acpi_video_device_enumerate()
1306 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1308 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1315 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1316 acpi_handle_info(video->device->handle, "Invalid _DOD data\n"); in acpi_video_device_enumerate()
1317 status = -EFAULT; in acpi_video_device_enumerate()
1321 acpi_handle_debug(video->device->handle, "Found %d video heads in _DOD\n", in acpi_video_device_enumerate()
1322 dod->package.count); in acpi_video_device_enumerate()
1324 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1328 status = -ENOMEM; in acpi_video_device_enumerate()
1333 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1334 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1336 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1337 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1342 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1345 acpi_handle_debug(video->device->handle, in acpi_video_device_enumerate()
1347 (int)obj->integer.value); in acpi_video_device_enumerate()
1352 kfree(video->attached_array); in acpi_video_device_enumerate()
1354 video->attached_array = active_list; in acpi_video_device_enumerate()
1355 video->attached_count = count; in acpi_video_device_enumerate()
1369 /* Find closest level to level_current */ in acpi_video_get_next_level()
1370 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1371 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1372 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1373 delta = l - level_current; in acpi_video_get_next_level()
1378 /* Adjust level_current to closest available level */ in acpi_video_get_next_level()
1380 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1381 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1413 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1414 int result = -EINVAL; in acpi_video_switch_brightness()
1417 if (!device->backlight) in acpi_video_switch_brightness()
1420 if (!device->brightness) in acpi_video_switch_brightness()
1434 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1439 acpi_handle_info(device->dev->handle, in acpi_video_switch_brightness()
1440 "Failed to switch brightness\n"); in acpi_video_switch_brightness()
1453 return -EINVAL; in acpi_video_get_edid()
1457 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1458 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1464 if (!video_device->cap._DDC) in acpi_video_get_edid()
1470 if (!video_device->flags.crt) in acpi_video_get_edid()
1474 if (!video_device->flags.tvout) in acpi_video_get_edid()
1478 if (!video_device->flags.dvi) in acpi_video_get_edid()
1482 if (!video_device->flags.lcd) in acpi_video_get_edid()
1486 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1493 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1498 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1503 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1507 return -ENODEV; in acpi_video_get_edid()
1529 * perform any automatic brightness change on receiving a notification.
1549 if (!video || !video->input) in acpi_video_bus_notify()
1552 input = video->input; in acpi_video_bus_notify()
1578 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_video_bus_notify()
1601 video_device->switch_brightness_event = event; in brightness_switch_event()
1602 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1616 device = video_device->dev; in acpi_video_device_notify()
1617 bus = video_device->video; in acpi_video_device_notify()
1618 input = bus->input; in acpi_video_device_notify()
1621 if (video_device->backlight) in acpi_video_device_notify()
1622 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1629 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1633 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1637 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1641 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1680 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1682 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1683 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1684 if (video_device && video_device->brightness) in acpi_video_resume()
1686 video_device->brightness->curr); in acpi_video_resume()
1695 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1701 if (handle == device->handle) in acpi_video_bus_match()
1733 acpi_get_parent(device->dev->handle, &acpi_parent); in acpi_video_dev_register_backlight()
1737 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1744 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1745 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1751 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1752 device->backlight = NULL; in acpi_video_dev_register_backlight()
1757 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1760 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1761 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1763 device->cooling_dev = thermal_cooling_device_register("LCD", in acpi_video_dev_register_backlight()
1764 device->dev, &video_cooling_ops); in acpi_video_dev_register_backlight()
1765 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1770 * -- dtor in acpi_video_dev_register_backlight()
1772 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1776 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1777 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1778 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1779 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1784 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1785 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1795 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1796 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1797 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1800 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1810 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1815 return dev->flags.lcd; in acpi_video_should_register_backlight()
1823 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1829 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1830 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1834 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1836 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1838 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1839 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1840 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1845 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1846 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1847 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1849 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1850 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1851 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1852 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1854 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1855 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1856 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1857 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1858 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1867 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1870 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1872 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1873 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1875 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1877 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1885 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1887 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1890 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1892 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1901 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1903 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1911 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1912 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1914 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1915 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1916 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1917 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1918 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1919 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1920 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1921 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1922 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1923 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1924 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1925 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1926 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1927 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1933 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1934 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1936 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1944 video->input = NULL; in acpi_video_bus_add_notify_handler()
1951 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
1952 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
1954 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
1962 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1963 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
1965 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1968 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
1969 video->input = NULL; in acpi_video_bus_remove_notify_handler()
1976 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
1977 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
1978 list_del(&dev->entry); in acpi_video_bus_put_devices()
1981 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
1995 acpi_dev_parent(device)->handle, 1, in acpi_video_bus_add()
2005 return -ENODEV; in acpi_video_bus_add()
2010 return -ENOMEM; in acpi_video_bus_add()
2013 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2015 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2019 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2021 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2025 video->device = device; in acpi_video_bus_add()
2028 device->driver_data = video; in acpi_video_bus_add()
2035 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2036 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2042 pr_info("%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2044 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2045 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2046 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2048 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2062 kfree(video->attached_array); in acpi_video_bus_add()
2065 device->driver_data = NULL; in acpi_video_bus_add()
2076 return -EINVAL; in acpi_video_bus_remove()
2081 list_del(&video->entry); in acpi_video_bus_remove()
2088 kfree(video->attached_array); in acpi_video_bus_remove()
2101 if (dev->device == 0x00D1) in is_i740()
2103 if (dev->device == 0x7000) in is_i740()
2115 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2117 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2130 /* Check if the chassis-type indicates there is no builtin LCD panel */
2163 * 2.1 Report a desktop/server DMI chassis-type, or
2164 * 2.2 Are an ACPI-reduced-hardware platform (and thus won't use the EC for
2194 if (only_lcd == -1) in acpi_video_register()
2272 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()