Lines Matching +full:brightness +full:- +full:levels

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");
84 * the rest are all supported levels.
91 ACPI_VIDEO_FIRST_LEVEL, /* actual supported levels begin here */
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
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()
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()
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()
302 * --------------------------------------------------------------------------
304 * --------------------------------------------------------------------------
309 union acpi_object **levels) in acpi_video_device_lcd_query_levels() argument
316 *levels = NULL; in acpi_video_device_lcd_query_levels()
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()
328 *levels = obj; in acpi_video_device_lcd_query_levels()
344 status = acpi_execute_simple_method(device->dev->handle, 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
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()
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()
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()
591 acpi_handle_info(device->dev->handle, 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()
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()
629 return -EINVAL; in acpi_video_device_EDID()
633 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
635 return -ENODEV; in acpi_video_device_EDID()
639 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
642 acpi_handle_debug(device->dev->handle, in acpi_video_device_EDID()
644 status = -EFAULT; in acpi_video_device_EDID()
666 * 0. The system BIOS should automatically control the brightness level
668 * - the power changes from AC to DC (ACPI appendix B)
669 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
670 * 1. The system BIOS should NOT automatically control the brightness
672 * - the power changes from AC to DC (ACPI appendix B)
673 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
675 * -EINVAL wrong arg.
683 if (!video->cap._DOS) in acpi_video_bus_DOS()
687 return -EINVAL; in acpi_video_bus_DOS()
688 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
689 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
692 return -EIO; in acpi_video_bus_DOS()
698 * Simple comparison function used to sort backlight levels.
704 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
711 * brightness level, if the value does not match, find out if it is using
717 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
727 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
732 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
749 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
757 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
770 if (level < br->count) { in acpi_video_bqc_quirk()
771 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
772 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
773 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
774 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
777 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
778 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
795 if (ACPI_FAILURE(acpi_video_device_lcd_query_levels(device->handle, &obj))) { in acpi_video_get_levels()
796 acpi_handle_debug(device->handle, in acpi_video_get_levels()
797 "Could not query available LCD brightness level\n"); in acpi_video_get_levels()
798 result = -ENODEV; in acpi_video_get_levels()
802 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
803 result = -EINVAL; in acpi_video_get_levels()
809 result = -ENOMEM; in acpi_video_get_levels()
816 * special levels (see below) in acpi_video_get_levels()
818 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
819 sizeof(*br->levels), in acpi_video_get_levels()
821 if (!br->levels) { in acpi_video_get_levels()
822 result = -ENOMEM; in acpi_video_get_levels()
826 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
827 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
828 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
829 acpi_handle_info(device->handle, "Invalid data\n"); in acpi_video_get_levels()
832 value = (u32) o->integer.value; in acpi_video_get_levels()
835 && br->levels[count - 1] == value) in acpi_video_get_levels()
838 br->levels[count] = value; in acpi_video_get_levels()
840 if (br->levels[count] > max_level) in acpi_video_get_levels()
841 max_level = br->levels[count]; in acpi_video_get_levels()
846 * some buggy BIOS don't export the levels in acpi_video_get_levels()
849 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
852 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
854 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
859 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
860 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
861 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
862 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
863 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
866 acpi_handle_info(device->handle, in acpi_video_get_levels()
870 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
871 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
872 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
873 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
874 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
876 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
877 acpi_handle_info(device->handle, in acpi_video_get_levels()
880 br->count = count; in acpi_video_get_levels()
899 * Maximum brightness level
901 * Allocate and initialize device->brightness.
912 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
915 device->brightness = br; in acpi_video_init_brightness()
918 br->curr = level = max_level; in acpi_video_init_brightness()
920 if (!device->cap._BQC) in acpi_video_init_brightness()
935 if (!device->cap._BQC) in acpi_video_init_brightness()
945 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
946 if (level == br->levels[i]) in acpi_video_init_brightness()
948 if (i == br->count || !level) in acpi_video_init_brightness()
956 acpi_handle_debug(device->dev->handle, "found %d brightness levels\n", in acpi_video_init_brightness()
957 br->count - ACPI_VIDEO_FIRST_LEVEL); in acpi_video_init_brightness()
962 kfree(br->levels); in acpi_video_init_brightness()
964 device->brightness = NULL; in acpi_video_init_brightness()
981 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
982 device->cap._ADR = 1; in acpi_video_device_find_cap()
983 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
984 device->cap._BCL = 1; in acpi_video_device_find_cap()
985 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
986 device->cap._BCM = 1; in acpi_video_device_find_cap()
987 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
988 device->cap._BQC = 1; in acpi_video_device_find_cap()
989 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
990 acpi_handle_info(device->dev->handle, in acpi_video_device_find_cap()
992 device->cap._BCQ = 1; in acpi_video_device_find_cap()
995 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
996 device->cap._DDC = 1; in acpi_video_device_find_cap()
1011 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1012 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1013 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1014 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1015 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1016 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1017 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1018 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1019 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1020 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1021 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1022 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1032 acpi_status status = -ENOENT; in acpi_video_bus_check()
1036 return -EINVAL; in acpi_video_bus_check()
1038 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1040 return -ENODEV; in acpi_video_bus_check()
1049 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1050 if (!video->cap._DOS) { in acpi_video_bus_check()
1052 acpi_device_bid(video->device)); in acpi_video_bus_check()
1054 video->flags.multihead = 1; in acpi_video_bus_check()
1059 if (video->cap._ROM) { in acpi_video_bus_check()
1060 video->flags.rom = 1; in acpi_video_bus_check()
1065 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1066 video->flags.post = 1; in acpi_video_bus_check()
1074 * --------------------------------------------------------------------------
1076 * --------------------------------------------------------------------------
1086 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1087 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1088 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1089 return &ids->value.attrib; in acpi_video_get_device_attr()
1102 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1103 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1104 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1105 return ids->value.int_val; in acpi_video_get_device_type()
1120 status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1127 dev_dbg(&device->dev, "Cannot attach\n"); in acpi_video_bus_get_one_device()
1128 return -ENOMEM; in acpi_video_bus_get_one_device()
1134 data->device_id = device_id; in acpi_video_bus_get_one_device()
1135 data->video = video; in acpi_video_bus_get_one_device()
1136 data->dev = device; in acpi_video_bus_get_one_device()
1137 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1142 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1143 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1145 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1148 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1151 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1154 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1157 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1160 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1161 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1165 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1168 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1171 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1174 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1177 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1184 if (data->cap._BCM && data->cap._BCL) in acpi_video_bus_get_one_device()
1187 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1188 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1189 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1192 video->child_count++; in acpi_video_bus_get_one_device()
1212 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1214 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1217 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1240 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1241 ids = &video->attached_array[i]; in acpi_video_device_bind()
1242 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1243 ids->bind_info = device; in acpi_video_device_bind()
1244 acpi_handle_debug(video->device->handle, "%s: %d\n", in acpi_video_device_bind()
1252 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1260 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1263 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1264 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1265 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1293 if (!video->cap._DOD) in acpi_video_device_enumerate()
1296 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1298 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1305 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1306 acpi_handle_info(video->device->handle, "Invalid _DOD data\n"); in acpi_video_device_enumerate()
1307 status = -EFAULT; in acpi_video_device_enumerate()
1311 acpi_handle_debug(video->device->handle, "Found %d video heads in _DOD\n", in acpi_video_device_enumerate()
1312 dod->package.count); in acpi_video_device_enumerate()
1314 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1318 status = -ENOMEM; in acpi_video_device_enumerate()
1323 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1324 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1326 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1327 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1332 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1335 acpi_handle_debug(video->device->handle, in acpi_video_device_enumerate()
1337 (int)obj->integer.value); in acpi_video_device_enumerate()
1342 kfree(video->attached_array); in acpi_video_device_enumerate()
1344 video->attached_array = active_list; in acpi_video_device_enumerate()
1345 video->attached_count = count; in acpi_video_device_enumerate()
1360 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1361 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1362 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1363 delta = l - 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()
1403 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1404 int result = -EINVAL; in acpi_video_switch_brightness()
1407 if (!device->backlight) in acpi_video_switch_brightness()
1410 if (!device->brightness) in acpi_video_switch_brightness()
1424 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1429 acpi_handle_info(device->dev->handle, in acpi_video_switch_brightness()
1430 "Failed to switch brightness\n"); in acpi_video_switch_brightness()
1443 return -EINVAL; in acpi_video_get_edid()
1447 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1448 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1453 if (!video_device->cap._DDC) in acpi_video_get_edid()
1459 if (!video_device->flags.crt) in acpi_video_get_edid()
1463 if (!video_device->flags.tvout) in acpi_video_get_edid()
1467 if (!video_device->flags.dvi) in acpi_video_get_edid()
1471 if (!video_device->flags.lcd) in acpi_video_get_edid()
1475 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1479 for (length = 512; length > 0; length -= 128) { in acpi_video_get_edid()
1488 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1492 return -ENODEV; in acpi_video_get_edid()
1514 * perform any automatic brightness change on receiving a notification.
1535 if (!video || !video->input) in acpi_video_bus_notify()
1538 input = video->input; in acpi_video_bus_notify()
1564 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_video_bus_notify()
1587 video_device->switch_brightness_event = event; in brightness_switch_event()
1588 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1602 device = video_device->dev; in acpi_video_device_notify()
1603 bus = video_device->video; in acpi_video_device_notify()
1604 input = bus->input; in acpi_video_device_notify()
1607 if (video_device->backlight) in acpi_video_device_notify()
1608 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1615 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1619 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1623 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1627 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1666 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1668 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1669 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1670 if (video_device && video_device->brightness) in acpi_video_resume()
1672 video_device->brightness->curr); in acpi_video_resume()
1687 if (handle == device->handle) in acpi_video_bus_match()
1719 if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) { in acpi_video_dev_register_backlight()
1722 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1730 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1731 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1737 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1738 device->backlight = NULL; in acpi_video_dev_register_backlight()
1743 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1746 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1747 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1749 device->cooling_dev = thermal_cooling_device_register("LCD", device, in acpi_video_dev_register_backlight()
1751 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1756 * -- dtor in acpi_video_dev_register_backlight()
1758 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1762 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1763 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1764 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1765 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1770 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1771 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1779 union acpi_object *levels; in acpi_video_run_bcl_for_osi() local
1781 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1782 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1783 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1784 kfree(levels); in acpi_video_run_bcl_for_osi()
1786 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1796 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1801 return dev->flags.lcd; in acpi_video_should_register_backlight()
1809 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1815 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1816 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1820 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1822 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1824 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1825 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1826 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1831 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1832 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1833 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1835 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1836 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1837 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1838 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1840 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1841 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1842 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1843 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1844 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1853 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1856 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1858 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1859 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1861 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1863 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1871 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1873 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1876 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1878 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1887 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1889 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1897 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1898 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1900 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1901 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1902 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1903 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1904 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1905 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1906 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1907 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1908 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1909 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1910 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1911 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1912 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1913 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1919 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1920 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1922 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1930 video->input = NULL; in acpi_video_bus_add_notify_handler()
1937 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
1938 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
1940 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
1948 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1949 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
1951 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1954 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
1955 video->input = NULL; in acpi_video_bus_remove_notify_handler()
1962 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
1963 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
1964 list_del(&dev->entry); in acpi_video_bus_put_devices()
1967 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
1982 acpi_dev_parent(device)->handle, 1, in acpi_video_bus_add()
1992 return -ENODEV; in acpi_video_bus_add()
1997 return -ENOMEM; in acpi_video_bus_add()
2000 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2002 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2006 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2008 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2012 video->device = device; in acpi_video_bus_add()
2015 device->driver_data = video; in acpi_video_bus_add()
2022 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2023 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2031 * evaluated to have functional panel brightness control. in acpi_video_bus_add()
2035 pr_info("%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2037 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2038 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2039 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2041 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2045 * If backlight-type auto-detection is used then a native backlight may in acpi_video_bus_add()
2050 * Register the backlight now when not using auto-detection, so that in acpi_video_bus_add()
2051 * when the kernel cmdline or DMI-quirks are used the backlight will in acpi_video_bus_add()
2074 list_del(&video->entry); in acpi_video_bus_add()
2079 kfree(video->attached_array); in acpi_video_bus_add()
2082 device->driver_data = NULL; in acpi_video_bus_add()
2101 list_del(&video->entry); in acpi_video_bus_remove()
2108 kfree(video->attached_array); in acpi_video_bus_remove()
2114 if (dev->device == 0x00D1) in is_i740()
2116 if (dev->device == 0x7000) in is_i740()
2128 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2130 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2218 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()