• Home
  • Raw
  • Download

Lines Matching +full:default +full:- +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>
47 * By default, we don't allow duplicate ACPI video bus devices
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
572 * Some machines change the brightness themselves when a brightness
593 unsigned long long level; in acpi_video_bqc_value_to_level() local
595 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
601 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
602 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
603 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
605 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
608 level = bqc_value; in acpi_video_bqc_value_to_level()
611 level += bqc_offset_aml_bug_workaround; in acpi_video_bqc_value_to_level()
613 return level; in acpi_video_bqc_value_to_level()
618 unsigned long long *level, bool raw) in acpi_video_device_lcd_get_level_current() argument
623 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
624 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
626 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
627 NULL, level); in acpi_video_device_lcd_get_level_current()
638 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
641 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
642 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
643 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
647 * BQC returned an invalid level. in acpi_video_device_lcd_get_level_current()
651 "%s returned an invalid level", in acpi_video_device_lcd_get_level_current()
653 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
658 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
659 * the correct current backlight level in most cases. in acpi_video_device_lcd_get_level_current()
664 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
668 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
686 return -ENODEV; in acpi_video_device_EDID()
692 return -EINVAL; in acpi_video_device_EDID()
694 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
696 return -ENODEV; in acpi_video_device_EDID()
700 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
704 status = -EFAULT; in acpi_video_device_EDID()
726 * 0. The system BIOS should automatically control the brightness level
728 * - the power changes from AC to DC (ACPI appendix B)
729 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
730 * 1. The system BIOS should NOT automatically control the brightness
731 * level of the LCD when:
732 * - the power changes from AC to DC (ACPI appendix B)
733 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
735 * -EINVAL wrong arg.
743 if (!video->cap._DOS) in acpi_video_bus_DOS()
747 return -EINVAL; in acpi_video_bus_DOS()
748 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
749 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
752 return -EIO; in acpi_video_bus_DOS()
764 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
770 * We do this by changing the level first and then read out the current
771 * brightness level, if the value does not match, find out if it is using
777 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
779 unsigned long long level; in acpi_video_bqc_quirk() local
787 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
791 * If the _BCL package ordering is descending, the first level in acpi_video_bqc_quirk()
792 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
793 * matches the number of steps, we might confuse a returned level to in acpi_video_bqc_quirk()
800 * returned level = 100 in acpi_video_bqc_quirk()
802 * In this case 100 means the level, not the index, and _BCM failed. in acpi_video_bqc_quirk()
804 * level 0 is also 100, so we assume _BQC is indexed, when it's not. in acpi_video_bqc_quirk()
809 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
811 * would flash to 90% and then slowly down to the desired level (20). in acpi_video_bqc_quirk()
813 * The solution is simple; test anything other than the first level in acpi_video_bqc_quirk()
817 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
824 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
828 if (level != test_level) { in acpi_video_bqc_quirk()
830 if (level < br->count) { in acpi_video_bqc_quirk()
831 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
832 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
833 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
834 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
837 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
838 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
855 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device->handle, in acpi_video_get_levels()
858 "LCD brightness level\n")); in acpi_video_get_levels()
859 result = -ENODEV; in acpi_video_get_levels()
863 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
864 result = -EINVAL; in acpi_video_get_levels()
871 result = -ENOMEM; in acpi_video_get_levels()
880 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
881 sizeof(*br->levels), in acpi_video_get_levels()
883 if (!br->levels) { in acpi_video_get_levels()
884 result = -ENOMEM; in acpi_video_get_levels()
888 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
889 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
890 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
894 value = (u32) o->integer.value; in acpi_video_get_levels()
897 && br->levels[count - 1] == value) in acpi_video_get_levels()
900 br->levels[count] = value; in acpi_video_get_levels()
902 if (br->levels[count] > max_level) in acpi_video_get_levels()
903 max_level = br->levels[count]; in acpi_video_get_levels()
911 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
914 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
916 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
921 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
922 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
923 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
924 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
925 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
931 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
932 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
933 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
934 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
935 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
937 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
941 br->count = count; in acpi_video_get_levels()
960 * Maximum brightness level
962 * Allocate and initialize device->brightness.
969 unsigned long long level, level_old; in acpi_video_init_brightness() local
973 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
976 device->brightness = br; in acpi_video_init_brightness()
979 br->curr = level = max_level; in acpi_video_init_brightness()
981 if (!device->cap._BQC) in acpi_video_init_brightness()
996 if (!device->cap._BQC) in acpi_video_init_brightness()
999 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
1003 * level_old is invalid (no matter whether it's a level in acpi_video_init_brightness()
1006 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
1007 if (level == br->levels[i]) in acpi_video_init_brightness()
1009 if (i == br->count || !level) in acpi_video_init_brightness()
1010 level = max_level; in acpi_video_init_brightness()
1013 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
1018 "found %d brightness levels\n", in acpi_video_init_brightness()
1019 br->count - ACPI_VIDEO_FIRST_LEVEL)); in acpi_video_init_brightness()
1023 kfree(br->levels); in acpi_video_init_brightness()
1025 device->brightness = NULL; in acpi_video_init_brightness()
1042 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
1043 device->cap._ADR = 1; in acpi_video_device_find_cap()
1044 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
1045 device->cap._BCL = 1; in acpi_video_device_find_cap()
1046 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
1047 device->cap._BCM = 1; in acpi_video_device_find_cap()
1048 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
1049 device->cap._BQC = 1; in acpi_video_device_find_cap()
1050 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
1052 device->cap._BCQ = 1; in acpi_video_device_find_cap()
1055 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
1056 device->cap._DDC = 1; in acpi_video_device_find_cap()
1071 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1072 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1073 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1074 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1075 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1076 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1077 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1078 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1079 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1080 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1081 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1082 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1092 acpi_status status = -ENOENT; in acpi_video_bus_check()
1096 return -EINVAL; in acpi_video_bus_check()
1098 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1100 return -ENODEV; in acpi_video_bus_check()
1109 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1110 if (!video->cap._DOS) { in acpi_video_bus_check()
1113 acpi_device_bid(video->device)); in acpi_video_bus_check()
1115 video->flags.multihead = 1; in acpi_video_bus_check()
1120 if (video->cap._ROM) { in acpi_video_bus_check()
1121 video->flags.rom = 1; in acpi_video_bus_check()
1126 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1127 video->flags.post = 1; in acpi_video_bus_check()
1135 * --------------------------------------------------------------------------
1137 * --------------------------------------------------------------------------
1147 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1148 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1149 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1150 return &ids->value.attrib; in acpi_video_get_device_attr()
1163 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1164 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1165 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1166 return ids->value.int_val; in acpi_video_get_device_type()
1182 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1189 return -ENOMEM; in acpi_video_bus_get_one_device()
1193 device->driver_data = data; in acpi_video_bus_get_one_device()
1195 data->device_id = device_id; in acpi_video_bus_get_one_device()
1196 data->video = video; in acpi_video_bus_get_one_device()
1197 data->dev = device; in acpi_video_bus_get_one_device()
1198 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1203 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1204 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1206 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1209 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1212 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1215 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1217 default: in acpi_video_bus_get_one_device()
1218 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1221 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1222 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1226 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1229 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1232 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1235 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1237 default: in acpi_video_bus_get_one_device()
1238 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1245 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1246 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1247 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1268 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1270 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1273 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1296 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1297 ids = &video->attached_array[i]; in acpi_video_device_bind()
1298 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1299 ids->bind_info = device; in acpi_video_device_bind()
1307 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1315 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1318 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1319 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1320 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1348 if (!video->cap._DOD) in acpi_video_device_enumerate()
1351 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1358 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1360 status = -EFAULT; in acpi_video_device_enumerate()
1365 dod->package.count)); in acpi_video_device_enumerate()
1367 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1371 status = -ENOMEM; in acpi_video_device_enumerate()
1376 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1377 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1379 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1385 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1388 (int)obj->integer.value)); in acpi_video_device_enumerate()
1392 kfree(video->attached_array); in acpi_video_device_enumerate()
1394 video->attached_array = active_list; in acpi_video_device_enumerate()
1395 video->attached_count = count; in acpi_video_device_enumerate()
1409 /* Find closest level to level_current */ in acpi_video_get_next_level()
1410 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1411 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1412 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1413 delta = l - level_current; in acpi_video_get_next_level()
1418 /* Ajust level_current to closest available level */ in acpi_video_get_next_level()
1420 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1421 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1442 default: in acpi_video_get_next_level()
1453 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1454 int result = -EINVAL; in acpi_video_switch_brightness()
1457 if (!device->backlight) in acpi_video_switch_brightness()
1460 if (!device->brightness) in acpi_video_switch_brightness()
1474 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1479 printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); in acpi_video_switch_brightness()
1492 return -EINVAL; in acpi_video_get_edid()
1496 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1497 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1503 if (!video_device->cap._DDC) in acpi_video_get_edid()
1509 if (!video_device->flags.crt) in acpi_video_get_edid()
1513 if (!video_device->flags.tvout) in acpi_video_get_edid()
1517 if (!video_device->flags.dvi) in acpi_video_get_edid()
1521 if (!video_device->flags.lcd) in acpi_video_get_edid()
1525 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1532 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1537 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1542 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1546 return -ENODEV; in acpi_video_get_edid()
1564 list_for_each_entry(dev, &device->children, node) { in acpi_video_bus_get_devices()
1568 dev_err(&dev->dev, "Can't attach device\n"); in acpi_video_bus_get_devices()
1571 video->child_count++; in acpi_video_bus_get_devices()
1580 * preform any automatic brightness change on receiving a notification.
1600 if (!video || !video->input) in acpi_video_bus_notify()
1603 input = video->input; in acpi_video_bus_notify()
1628 default: in acpi_video_bus_notify()
1654 video_device->switch_brightness_event = event; in brightness_switch_event()
1655 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1669 device = video_device->dev; in acpi_video_device_notify()
1670 bus = video_device->video; in acpi_video_device_notify()
1671 input = bus->input; in acpi_video_device_notify()
1674 if (video_device->backlight) in acpi_video_device_notify()
1675 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1682 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1686 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1690 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1694 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1702 default: in acpi_video_device_notify()
1736 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1738 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1739 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1740 if (video_device && video_device->brightness) in acpi_video_resume()
1742 video_device->brightness->curr); in acpi_video_resume()
1749 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1756 if (handle == device->handle) in acpi_video_bus_match()
1791 if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) { in acpi_video_dev_register_backlight()
1794 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1802 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1803 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1809 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1810 device->backlight = NULL; in acpi_video_dev_register_backlight()
1815 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1818 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1819 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1821 device->cooling_dev = thermal_cooling_device_register("LCD", in acpi_video_dev_register_backlight()
1822 device->dev, &video_cooling_ops); in acpi_video_dev_register_backlight()
1823 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1828 * -- dtor in acpi_video_dev_register_backlight()
1830 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1834 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1835 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1836 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1837 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1841 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1842 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1852 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1853 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1854 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1857 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1867 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1872 return dev->flags.lcd; in acpi_video_should_register_backlight()
1880 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1888 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1889 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1893 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1895 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1897 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1898 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1899 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1904 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1905 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1906 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1908 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1909 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1910 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1911 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1913 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1914 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1915 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1916 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1917 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1926 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1929 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1931 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1932 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1934 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1936 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1944 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1946 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1949 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1951 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1960 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1962 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1970 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1971 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1973 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1974 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1975 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1976 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1977 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1978 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1979 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1980 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1981 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1982 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1983 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1984 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1985 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1986 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1992 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1993 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1995 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
2003 video->input = NULL; in acpi_video_bus_add_notify_handler()
2010 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
2011 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
2013 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
2021 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2022 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
2024 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2027 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
2028 video->input = NULL; in acpi_video_bus_remove_notify_handler()
2035 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
2036 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
2037 list_del(&dev->entry); in acpi_video_bus_put_devices()
2040 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
2054 device->parent->handle, 1, in acpi_video_bus_add()
2064 return -ENODEV; in acpi_video_bus_add()
2069 return -ENOMEM; in acpi_video_bus_add()
2072 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2074 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2078 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2080 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2084 video->device = device; in acpi_video_bus_add()
2087 device->driver_data = video; in acpi_video_bus_add()
2094 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2095 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2101 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2103 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2104 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2105 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2107 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2117 kfree(video->attached_array); in acpi_video_bus_add()
2120 device->driver_data = NULL; in acpi_video_bus_add()
2131 return -EINVAL; in acpi_video_bus_remove()
2140 list_del(&video->entry); in acpi_video_bus_remove()
2143 kfree(video->attached_array); in acpi_video_bus_remove()
2151 if (dev->device == 0x00D1) in is_i740()
2153 if (dev->device == 0x7000) in is_i740()
2165 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2167 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2180 /* Check if the chassis-type indicates there is no builtin LCD panel */
2227 if (only_lcd == -1) { in acpi_video_register()
2304 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()