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>
53 static int disable_backlight_sysfs_if = -1;
58 static int report_key_events = -1;
61 "0: none, 1: output changes, 2: brightness changes, 3: all");
63 static int hw_changes_brightness = -1;
66 "Set this to 1 on buggy hw which changes the brightness itself when "
67 "a hotkey is pressed: -1: auto, 0: normal 1: hw-changes-brightness");
76 static int only_lcd = -1;
95 ACPI_VIDEO_AC_LEVEL, /* level when machine has full power */
96 ACPI_VIDEO_BATTERY_LEVEL, /* level when machine is on batteries */
135 u32 display_index:4; /* A zero-based instance of the Display */
140 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
142 u32 pipe_id:3; /* For VGA multiple-head devices. */
193 u8 _BCL:1; /* Query list of brightness control levels supported */
194 u8 _BCM:1; /* Set the brightness level */
195 u8 _BQC:1; /* Get current brightness level */
209 struct acpi_video_device_brightness *brightness; member
220 int level);
223 unsigned long long *level, bool raw);
236 return -EINVAL; in acpi_video_get_brightness()
237 for (i = ACPI_VIDEO_FIRST_LEVEL; i < vd->brightness->count; i++) { in acpi_video_get_brightness()
238 if (vd->brightness->levels[i] == cur_level) in acpi_video_get_brightness()
239 return i - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_get_brightness()
246 int request_level = bd->props.brightness + ACPI_VIDEO_FIRST_LEVEL; in acpi_video_set_brightness()
249 cancel_delayed_work(&vd->switch_brightness_work); in acpi_video_set_brightness()
251 vd->brightness->levels[request_level]); in acpi_video_set_brightness()
263 struct acpi_device *device = cooling_dev->devdata; in video_get_max_state()
266 *state = video->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in video_get_max_state()
273 struct acpi_device *device = cooling_dev->devdata; in video_get_cur_state()
275 unsigned long long level; in video_get_cur_state() local
278 if (acpi_video_device_lcd_get_level_current(video, &level, false)) in video_get_cur_state()
279 return -EINVAL; in video_get_cur_state()
280 for (offset = ACPI_VIDEO_FIRST_LEVEL; offset < video->brightness->count; in video_get_cur_state()
282 if (level == video->brightness->levels[offset]) { in video_get_cur_state()
283 *state = video->brightness->count - offset - 1; in video_get_cur_state()
287 return -EINVAL; in video_get_cur_state()
293 struct acpi_device *device = cooling_dev->devdata; in video_set_cur_state()
295 int level; in video_set_cur_state() local
297 if (state >= video->brightness->count - ACPI_VIDEO_FIRST_LEVEL) in video_set_cur_state()
298 return -EINVAL; in video_set_cur_state()
300 state = video->brightness->count - state; in video_set_cur_state()
301 level = video->brightness->levels[state - 1]; in video_set_cur_state()
302 return acpi_video_device_lcd_set_level(video, level); in video_set_cur_state()
312 * --------------------------------------------------------------------------
314 * --------------------------------------------------------------------------
332 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_lcd_query_levels()
334 status = -EFAULT; in acpi_video_device_lcd_query_levels()
349 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) in acpi_video_device_lcd_set_level() argument
354 status = acpi_execute_simple_method(device->dev->handle, in acpi_video_device_lcd_set_level()
355 "_BCM", level); in acpi_video_device_lcd_set_level()
358 return -EIO; in acpi_video_device_lcd_set_level()
361 device->brightness->curr = level; in acpi_video_device_lcd_set_level()
362 for (state = ACPI_VIDEO_FIRST_LEVEL; state < device->brightness->count; in acpi_video_device_lcd_set_level()
364 if (level == device->brightness->levels[state]) { in acpi_video_device_lcd_set_level()
365 if (device->backlight) in acpi_video_device_lcd_set_level()
366 device->backlight->props.brightness = in acpi_video_device_lcd_set_level()
367 state - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_device_lcd_set_level()
371 ACPI_ERROR((AE_INFO, "Current brightness invalid")); in acpi_video_device_lcd_set_level()
372 return -EINVAL; in acpi_video_device_lcd_set_level()
377 * the _BQC return value to get the actual current brightness level
390 if (disable_backlight_sysfs_if == -1) in video_disable_backlight_sysfs_if()
409 if (report_key_events == -1) in video_set_report_key_events()
410 report_key_events = (uintptr_t)id->driver_data; in video_set_report_key_events()
417 if (hw_changes_brightness == -1) in video_hw_changes_brightness()
468 * Some machines have a broken acpi-video interface for brightness
472 * as brightness control does not work.
545 * Some machines report wrong key events on the acpi-bus, suppress
548 * events, in this case acpi-video is considered the canonical source
551 * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb
581 * Some machines change the brightness themselves when a brightness
602 unsigned long long level; in acpi_video_bqc_value_to_level() local
604 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
610 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
611 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
612 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
614 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
617 level = bqc_value; in acpi_video_bqc_value_to_level()
620 level += bqc_offset_aml_bug_workaround; in acpi_video_bqc_value_to_level()
622 return level; in acpi_video_bqc_value_to_level()
627 unsigned long long *level, bool raw) in acpi_video_device_lcd_get_level_current() argument
632 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
633 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
635 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
636 NULL, level); in acpi_video_device_lcd_get_level_current()
647 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
650 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
651 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
652 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
656 * BQC returned an invalid level. in acpi_video_device_lcd_get_level_current()
660 "%s returned an invalid level", in acpi_video_device_lcd_get_level_current()
662 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
667 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
668 * the correct current backlight level in most cases. in acpi_video_device_lcd_get_level_current()
673 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
677 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
695 return -ENODEV; in acpi_video_device_EDID()
701 return -EINVAL; in acpi_video_device_EDID()
703 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
705 return -ENODEV; in acpi_video_device_EDID()
709 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
713 status = -EFAULT; in acpi_video_device_EDID()
735 * 0. The system BIOS should automatically control the brightness level
737 * - the power changes from AC to DC (ACPI appendix B)
738 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
739 * 1. The system BIOS should NOT automatically control the brightness
740 * level of the LCD when:
741 * - the power changes from AC to DC (ACPI appendix B)
742 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
744 * -EINVAL wrong arg.
752 if (!video->cap._DOS) in acpi_video_bus_DOS()
756 return -EINVAL; in acpi_video_bus_DOS()
757 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
758 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
761 return -EIO; in acpi_video_bus_DOS()
773 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
779 * We do this by changing the level first and then read out the current
780 * brightness level, if the value does not match, find out if it is using
786 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
788 unsigned long long level; in acpi_video_bqc_quirk() local
796 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
800 * If the _BCL package ordering is descending, the first level in acpi_video_bqc_quirk()
801 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
802 * matches the number of steps, we might confuse a returned level to in acpi_video_bqc_quirk()
809 * returned level = 100 in acpi_video_bqc_quirk()
811 * In this case 100 means the level, not the index, and _BCM failed. in acpi_video_bqc_quirk()
813 * level 0 is also 100, so we assume _BQC is indexed, when it's not. in acpi_video_bqc_quirk()
818 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
820 * would flash to 90% and then slowly down to the desired level (20). in acpi_video_bqc_quirk()
822 * The solution is simple; test anything other than the first level in acpi_video_bqc_quirk()
826 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
833 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
837 if (level != test_level) { in acpi_video_bqc_quirk()
839 if (level < br->count) { in acpi_video_bqc_quirk()
840 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
841 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
842 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
843 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
846 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
847 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
864 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device->handle, in acpi_video_get_levels()
867 "LCD brightness level\n")); in acpi_video_get_levels()
868 result = -ENODEV; in acpi_video_get_levels()
872 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
873 result = -EINVAL; in acpi_video_get_levels()
880 result = -ENOMEM; in acpi_video_get_levels()
889 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
890 sizeof(*br->levels), in acpi_video_get_levels()
892 if (!br->levels) { in acpi_video_get_levels()
893 result = -ENOMEM; in acpi_video_get_levels()
897 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
898 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
899 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
903 value = (u32) o->integer.value; in acpi_video_get_levels()
906 && br->levels[count - 1] == value) in acpi_video_get_levels()
909 br->levels[count] = value; in acpi_video_get_levels()
911 if (br->levels[count] > max_level) in acpi_video_get_levels()
912 max_level = br->levels[count]; in acpi_video_get_levels()
920 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
923 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
925 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
930 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
931 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
932 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
933 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
934 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
940 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
941 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
942 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
943 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
944 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
946 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
950 br->count = count; in acpi_video_get_levels()
969 * Maximum brightness level
971 * Allocate and initialize device->brightness.
978 unsigned long long level, level_old; in acpi_video_init_brightness() local
982 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
985 device->brightness = br; in acpi_video_init_brightness()
988 br->curr = level = max_level; in acpi_video_init_brightness()
990 if (!device->cap._BQC) in acpi_video_init_brightness()
1005 if (!device->cap._BQC) in acpi_video_init_brightness()
1008 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
1012 * level_old is invalid (no matter whether it's a level in acpi_video_init_brightness()
1015 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
1016 if (level == br->levels[i]) in acpi_video_init_brightness()
1018 if (i == br->count || !level) in acpi_video_init_brightness()
1019 level = max_level; in acpi_video_init_brightness()
1022 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
1027 "found %d brightness levels\n", in acpi_video_init_brightness()
1028 br->count - ACPI_VIDEO_FIRST_LEVEL)); in acpi_video_init_brightness()
1032 kfree(br->levels); in acpi_video_init_brightness()
1034 device->brightness = NULL; in acpi_video_init_brightness()
1051 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
1052 device->cap._ADR = 1; in acpi_video_device_find_cap()
1053 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
1054 device->cap._BCL = 1; in acpi_video_device_find_cap()
1055 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
1056 device->cap._BCM = 1; in acpi_video_device_find_cap()
1057 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
1058 device->cap._BQC = 1; in acpi_video_device_find_cap()
1059 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
1061 device->cap._BCQ = 1; in acpi_video_device_find_cap()
1064 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
1065 device->cap._DDC = 1; in acpi_video_device_find_cap()
1080 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1081 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1082 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1083 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1084 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1085 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1086 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1087 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1088 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1089 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1090 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1091 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1101 acpi_status status = -ENOENT; in acpi_video_bus_check()
1105 return -EINVAL; in acpi_video_bus_check()
1107 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1109 return -ENODEV; in acpi_video_bus_check()
1118 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1119 if (!video->cap._DOS) { in acpi_video_bus_check()
1122 acpi_device_bid(video->device)); in acpi_video_bus_check()
1124 video->flags.multihead = 1; in acpi_video_bus_check()
1129 if (video->cap._ROM) { in acpi_video_bus_check()
1130 video->flags.rom = 1; in acpi_video_bus_check()
1135 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1136 video->flags.post = 1; in acpi_video_bus_check()
1144 * --------------------------------------------------------------------------
1146 * --------------------------------------------------------------------------
1156 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1157 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1158 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1159 return &ids->value.attrib; in acpi_video_get_device_attr()
1172 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1173 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1174 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1175 return ids->value.int_val; in acpi_video_get_device_type()
1191 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1198 return -ENOMEM; in acpi_video_bus_get_one_device()
1202 device->driver_data = data; in acpi_video_bus_get_one_device()
1204 data->device_id = device_id; in acpi_video_bus_get_one_device()
1205 data->video = video; in acpi_video_bus_get_one_device()
1206 data->dev = device; in acpi_video_bus_get_one_device()
1207 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1212 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1213 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1215 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1218 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1221 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1224 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1227 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1230 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1231 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1235 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1238 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1241 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1244 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1247 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1254 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1255 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1256 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1277 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1279 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1282 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1305 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1306 ids = &video->attached_array[i]; in acpi_video_device_bind()
1307 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1308 ids->bind_info = device; in acpi_video_device_bind()
1316 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1324 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1327 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1328 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1329 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1357 if (!video->cap._DOD) in acpi_video_device_enumerate()
1360 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1367 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1369 status = -EFAULT; in acpi_video_device_enumerate()
1374 dod->package.count)); in acpi_video_device_enumerate()
1376 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1380 status = -ENOMEM; in acpi_video_device_enumerate()
1385 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1386 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1388 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1394 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1397 (int)obj->integer.value)); in acpi_video_device_enumerate()
1401 kfree(video->attached_array); in acpi_video_device_enumerate()
1403 video->attached_array = active_list; in acpi_video_device_enumerate()
1404 video->attached_count = count; in acpi_video_device_enumerate()
1418 /* Find closest level to level_current */ in acpi_video_get_next_level()
1419 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1420 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1421 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1422 delta = l - level_current; in acpi_video_get_next_level()
1427 /* Ajust level_current to closest available level */ in acpi_video_get_next_level()
1429 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1430 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1462 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1463 int result = -EINVAL; in acpi_video_switch_brightness()
1466 if (!device->backlight) in acpi_video_switch_brightness()
1469 if (!device->brightness) in acpi_video_switch_brightness()
1483 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1488 printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); in acpi_video_switch_brightness()
1501 return -EINVAL; in acpi_video_get_edid()
1505 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1506 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1512 if (!video_device->cap._DDC) in acpi_video_get_edid()
1518 if (!video_device->flags.crt) in acpi_video_get_edid()
1522 if (!video_device->flags.tvout) in acpi_video_get_edid()
1526 if (!video_device->flags.dvi) in acpi_video_get_edid()
1530 if (!video_device->flags.lcd) in acpi_video_get_edid()
1534 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1541 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1546 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1551 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1555 return -ENODEV; in acpi_video_get_edid()
1573 list_for_each_entry(dev, &device->children, node) { in acpi_video_bus_get_devices()
1577 dev_err(&dev->dev, "Can't attach device\n"); in acpi_video_bus_get_devices()
1580 video->child_count++; in acpi_video_bus_get_devices()
1589 * preform any automatic brightness change on receiving a notification.
1609 if (!video || !video->input) in acpi_video_bus_notify()
1612 input = video->input; in acpi_video_bus_notify()
1663 video_device->switch_brightness_event = event; in brightness_switch_event()
1664 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1678 device = video_device->dev; in acpi_video_device_notify()
1679 bus = video_device->video; in acpi_video_device_notify()
1680 input = bus->input; in acpi_video_device_notify()
1683 if (video_device->backlight) in acpi_video_device_notify()
1684 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1691 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1695 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1699 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1703 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1745 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1747 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1748 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1749 if (video_device && video_device->brightness) in acpi_video_resume()
1751 video_device->brightness->curr); in acpi_video_resume()
1758 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1765 if (handle == device->handle) in acpi_video_bus_match()
1800 if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) { in acpi_video_dev_register_backlight()
1803 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1811 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1812 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1818 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1819 device->backlight = NULL; in acpi_video_dev_register_backlight()
1824 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1827 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1828 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1830 device->cooling_dev = thermal_cooling_device_register("LCD", in acpi_video_dev_register_backlight()
1831 device->dev, &video_cooling_ops); in acpi_video_dev_register_backlight()
1832 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1837 * -- dtor in acpi_video_dev_register_backlight()
1839 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1843 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1844 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1845 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1846 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1850 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1851 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1861 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1862 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1863 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1866 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1876 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1881 return dev->flags.lcd; in acpi_video_should_register_backlight()
1889 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1897 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1898 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1902 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1904 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1906 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1907 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1908 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1913 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1914 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1915 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1917 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1918 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1919 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1920 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1922 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1923 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1924 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1925 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1926 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1935 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1938 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1940 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1941 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1943 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1945 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1953 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1955 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1958 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1960 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1969 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1971 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1979 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1980 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1982 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1983 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1984 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1985 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1986 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1987 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1988 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1989 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1990 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1991 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1992 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1993 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1994 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1995 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
2001 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
2002 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
2004 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
2012 video->input = NULL; in acpi_video_bus_add_notify_handler()
2019 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
2020 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
2022 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
2030 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2031 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
2033 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2036 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
2037 video->input = NULL; in acpi_video_bus_remove_notify_handler()
2044 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
2045 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
2046 list_del(&dev->entry); in acpi_video_bus_put_devices()
2049 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
2063 device->parent->handle, 1, in acpi_video_bus_add()
2073 return -ENODEV; in acpi_video_bus_add()
2078 return -ENOMEM; in acpi_video_bus_add()
2081 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2083 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2087 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2089 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2093 video->device = device; in acpi_video_bus_add()
2096 device->driver_data = video; in acpi_video_bus_add()
2103 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2104 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2110 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2112 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2113 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2114 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2116 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2126 kfree(video->attached_array); in acpi_video_bus_add()
2129 device->driver_data = NULL; in acpi_video_bus_add()
2140 return -EINVAL; in acpi_video_bus_remove()
2149 list_del(&video->entry); in acpi_video_bus_remove()
2152 kfree(video->attached_array); in acpi_video_bus_remove()
2160 if (dev->device == 0x00D1) in is_i740()
2162 if (dev->device == 0x7000) in is_i740()
2174 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2176 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2189 /* Check if the chassis-type indicates there is no builtin LCD panel */
2236 if (only_lcd == -1) { in acpi_video_register()
2313 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()