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.
529 * Some machines report wrong key events on the acpi-bus, suppress
532 * events, in this case acpi-video is considered the canonical source
535 * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb
556 * Some machines change the brightness themselves when a brightness
577 unsigned long long level; in acpi_video_bqc_value_to_level() local
579 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
585 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
586 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
587 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
589 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
592 level = bqc_value; in acpi_video_bqc_value_to_level()
595 level += bqc_offset_aml_bug_workaround; in acpi_video_bqc_value_to_level()
597 return level; in acpi_video_bqc_value_to_level()
602 unsigned long long *level, bool raw) in acpi_video_device_lcd_get_level_current() argument
607 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
608 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
610 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
611 NULL, level); in acpi_video_device_lcd_get_level_current()
622 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
625 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
626 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
627 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
631 * BQC returned an invalid level. in acpi_video_device_lcd_get_level_current()
635 "%s returned an invalid level", in acpi_video_device_lcd_get_level_current()
637 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
642 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
643 * the correct current backlight level in most cases. in acpi_video_device_lcd_get_level_current()
648 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
652 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
670 return -ENODEV; in acpi_video_device_EDID()
676 return -EINVAL; in acpi_video_device_EDID()
678 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
680 return -ENODEV; in acpi_video_device_EDID()
684 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
688 status = -EFAULT; in acpi_video_device_EDID()
710 * 0. The system BIOS should automatically control the brightness level
712 * - the power changes from AC to DC (ACPI appendix B)
713 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
714 * 1. The system BIOS should NOT automatically control the brightness
715 * level of the LCD when:
716 * - the power changes from AC to DC (ACPI appendix B)
717 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
719 * -EINVAL wrong arg.
727 if (!video->cap._DOS) in acpi_video_bus_DOS()
731 return -EINVAL; in acpi_video_bus_DOS()
732 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
733 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
736 return -EIO; in acpi_video_bus_DOS()
748 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
754 * We do this by changing the level first and then read out the current
755 * brightness level, if the value does not match, find out if it is using
761 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
763 unsigned long long level; in acpi_video_bqc_quirk() local
771 * Some systems always report current brightness level as maximum in acpi_video_bqc_quirk()
775 * If the _BCL package ordering is descending, the first level in acpi_video_bqc_quirk()
776 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
777 * matches the number of steps, we might confuse a returned level to in acpi_video_bqc_quirk()
784 * returned level = 100 in acpi_video_bqc_quirk()
786 * In this case 100 means the level, not the index, and _BCM failed. in acpi_video_bqc_quirk()
788 * level 0 is also 100, so we assume _BQC is indexed, when it's not. in acpi_video_bqc_quirk()
793 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
795 * would flash to 90% and then slowly down to the desired level (20). in acpi_video_bqc_quirk()
797 * The solution is simple; test anything other than the first level in acpi_video_bqc_quirk()
801 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
808 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
812 if (level != test_level) { in acpi_video_bqc_quirk()
814 if (level < br->count) { in acpi_video_bqc_quirk()
815 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
816 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
817 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
818 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
821 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
822 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
839 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device->handle, in acpi_video_get_levels()
842 "LCD brightness level\n")); in acpi_video_get_levels()
843 result = -ENODEV; in acpi_video_get_levels()
847 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
848 result = -EINVAL; in acpi_video_get_levels()
855 result = -ENOMEM; in acpi_video_get_levels()
864 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
865 sizeof(*br->levels), in acpi_video_get_levels()
867 if (!br->levels) { in acpi_video_get_levels()
868 result = -ENOMEM; in acpi_video_get_levels()
872 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
873 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
874 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
878 value = (u32) o->integer.value; in acpi_video_get_levels()
881 && br->levels[count - 1] == value) in acpi_video_get_levels()
884 br->levels[count] = value; in acpi_video_get_levels()
886 if (br->levels[count] > max_level) in acpi_video_get_levels()
887 max_level = br->levels[count]; in acpi_video_get_levels()
895 * are also supported brightness levels that OS should take care of. in acpi_video_get_levels()
898 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
900 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
905 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
906 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
907 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
908 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
909 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
915 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
916 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
917 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
918 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
919 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
921 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
925 br->count = count; in acpi_video_get_levels()
944 * Maximum brightness level
946 * Allocate and initialize device->brightness.
953 unsigned long long level, level_old; in acpi_video_init_brightness() local
957 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
960 device->brightness = br; in acpi_video_init_brightness()
963 br->curr = level = max_level; in acpi_video_init_brightness()
965 if (!device->cap._BQC) in acpi_video_init_brightness()
980 if (!device->cap._BQC) in acpi_video_init_brightness()
983 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
987 * level_old is invalid (no matter whether it's a level in acpi_video_init_brightness()
990 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
991 if (level == br->levels[i]) in acpi_video_init_brightness()
993 if (i == br->count || !level) in acpi_video_init_brightness()
994 level = max_level; in acpi_video_init_brightness()
997 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
1002 "found %d brightness levels\n", in acpi_video_init_brightness()
1003 br->count - ACPI_VIDEO_FIRST_LEVEL)); in acpi_video_init_brightness()
1007 kfree(br->levels); in acpi_video_init_brightness()
1009 device->brightness = NULL; in acpi_video_init_brightness()
1026 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
1027 device->cap._ADR = 1; in acpi_video_device_find_cap()
1028 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
1029 device->cap._BCL = 1; in acpi_video_device_find_cap()
1030 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
1031 device->cap._BCM = 1; in acpi_video_device_find_cap()
1032 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
1033 device->cap._BQC = 1; in acpi_video_device_find_cap()
1034 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
1036 device->cap._BCQ = 1; in acpi_video_device_find_cap()
1039 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
1040 device->cap._DDC = 1; in acpi_video_device_find_cap()
1055 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1056 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1057 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1058 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1059 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1060 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1061 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1062 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1063 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1064 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1065 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1066 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1076 acpi_status status = -ENOENT; in acpi_video_bus_check()
1080 return -EINVAL; in acpi_video_bus_check()
1082 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1084 return -ENODEV; in acpi_video_bus_check()
1093 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1094 if (!video->cap._DOS) { in acpi_video_bus_check()
1097 acpi_device_bid(video->device)); in acpi_video_bus_check()
1099 video->flags.multihead = 1; in acpi_video_bus_check()
1104 if (video->cap._ROM) { in acpi_video_bus_check()
1105 video->flags.rom = 1; in acpi_video_bus_check()
1110 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1111 video->flags.post = 1; in acpi_video_bus_check()
1119 * --------------------------------------------------------------------------
1121 * --------------------------------------------------------------------------
1131 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1132 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1133 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1134 return &ids->value.attrib; in acpi_video_get_device_attr()
1147 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1148 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1149 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1150 return ids->value.int_val; in acpi_video_get_device_type()
1166 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1173 return -ENOMEM; in acpi_video_bus_get_one_device()
1177 device->driver_data = data; in acpi_video_bus_get_one_device()
1179 data->device_id = device_id; in acpi_video_bus_get_one_device()
1180 data->video = video; in acpi_video_bus_get_one_device()
1181 data->dev = device; in acpi_video_bus_get_one_device()
1182 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1187 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1188 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1190 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1193 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1196 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1199 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1202 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1205 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1206 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1210 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1213 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1216 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1219 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1222 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1229 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1230 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1231 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1252 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1254 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1257 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1280 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1281 ids = &video->attached_array[i]; in acpi_video_device_bind()
1282 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1283 ids->bind_info = device; in acpi_video_device_bind()
1291 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1299 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1302 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1303 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1304 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1332 if (!video->cap._DOD) in acpi_video_device_enumerate()
1335 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1342 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1344 status = -EFAULT; in acpi_video_device_enumerate()
1349 dod->package.count)); in acpi_video_device_enumerate()
1351 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1355 status = -ENOMEM; in acpi_video_device_enumerate()
1360 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1361 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1363 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1369 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1372 (int)obj->integer.value)); in acpi_video_device_enumerate()
1376 kfree(video->attached_array); in acpi_video_device_enumerate()
1378 video->attached_array = active_list; in acpi_video_device_enumerate()
1379 video->attached_count = count; in acpi_video_device_enumerate()
1393 /* Find closest level to level_current */ in acpi_video_get_next_level()
1394 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1395 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1396 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1397 delta = l - level_current; in acpi_video_get_next_level()
1402 /* Ajust level_current to closest available level */ in acpi_video_get_next_level()
1404 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1405 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1437 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1438 int result = -EINVAL; in acpi_video_switch_brightness()
1441 if (!device->backlight) in acpi_video_switch_brightness()
1444 if (!device->brightness) in acpi_video_switch_brightness()
1458 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1463 printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); in acpi_video_switch_brightness()
1476 return -EINVAL; in acpi_video_get_edid()
1480 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1481 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1487 if (!video_device->cap._DDC) in acpi_video_get_edid()
1493 if (!video_device->flags.crt) in acpi_video_get_edid()
1497 if (!video_device->flags.tvout) in acpi_video_get_edid()
1501 if (!video_device->flags.dvi) in acpi_video_get_edid()
1505 if (!video_device->flags.lcd) in acpi_video_get_edid()
1509 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1516 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1521 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1526 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1530 return -ENODEV; in acpi_video_get_edid()
1548 list_for_each_entry(dev, &device->children, node) { in acpi_video_bus_get_devices()
1552 dev_err(&dev->dev, "Can't attach device\n"); in acpi_video_bus_get_devices()
1555 video->child_count++; in acpi_video_bus_get_devices()
1564 * preform any automatic brightness change on receiving a notification.
1584 if (!video || !video->input) in acpi_video_bus_notify()
1587 input = video->input; in acpi_video_bus_notify()
1638 video_device->switch_brightness_event = event; in brightness_switch_event()
1639 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1653 device = video_device->dev; in acpi_video_device_notify()
1654 bus = video_device->video; in acpi_video_device_notify()
1655 input = bus->input; in acpi_video_device_notify()
1658 if (video_device->backlight) in acpi_video_device_notify()
1659 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1666 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ in acpi_video_device_notify()
1670 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ in acpi_video_device_notify()
1674 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ in acpi_video_device_notify()
1678 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ in acpi_video_device_notify()
1720 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1722 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1723 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1724 if (video_device && video_device->brightness) in acpi_video_resume()
1726 video_device->brightness->curr); in acpi_video_resume()
1733 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1740 if (handle == device->handle) in acpi_video_bus_match()
1775 acpi_get_parent(device->dev->handle, &acpi_parent); in acpi_video_dev_register_backlight()
1779 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1786 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1787 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1793 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1794 device->backlight = NULL; in acpi_video_dev_register_backlight()
1799 * Save current brightness level in case we have to restore it in acpi_video_dev_register_backlight()
1802 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1803 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1805 device->cooling_dev = thermal_cooling_device_register("LCD", in acpi_video_dev_register_backlight()
1806 device->dev, &video_cooling_ops); in acpi_video_dev_register_backlight()
1807 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1812 * -- dtor in acpi_video_dev_register_backlight()
1814 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1818 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1819 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1820 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1821 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1825 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1826 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1836 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1837 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1838 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1841 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1851 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1856 return dev->flags.lcd; in acpi_video_should_register_backlight()
1864 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1872 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1873 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1877 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1879 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1881 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1882 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1883 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1888 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1889 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1890 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1892 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1893 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1894 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1895 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1897 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1898 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1899 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1900 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1901 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1910 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1913 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1915 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1916 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1918 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1920 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1928 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1930 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1933 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1935 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1944 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1946 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1954 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1955 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1957 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1958 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1959 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1960 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1961 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1962 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1963 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1964 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1965 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1966 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1967 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1968 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1969 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1970 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1976 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1977 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1979 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1987 video->input = NULL; in acpi_video_bus_add_notify_handler()
1994 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
1995 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
1997 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
2005 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2006 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
2008 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
2011 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
2012 video->input = NULL; in acpi_video_bus_remove_notify_handler()
2019 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
2020 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
2021 list_del(&dev->entry); in acpi_video_bus_put_devices()
2024 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
2038 device->parent->handle, 1, in acpi_video_bus_add()
2048 return -ENODEV; in acpi_video_bus_add()
2053 return -ENOMEM; in acpi_video_bus_add()
2056 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2058 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2062 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2064 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2068 video->device = device; in acpi_video_bus_add()
2071 device->driver_data = video; in acpi_video_bus_add()
2078 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2079 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2085 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2087 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2088 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2089 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2091 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2101 kfree(video->attached_array); in acpi_video_bus_add()
2104 device->driver_data = NULL; in acpi_video_bus_add()
2115 return -EINVAL; in acpi_video_bus_remove()
2124 list_del(&video->entry); in acpi_video_bus_remove()
2127 kfree(video->attached_array); in acpi_video_bus_remove()
2135 if (dev->device == 0x00D1) in is_i740()
2137 if (dev->device == 0x7000) in is_i740()
2149 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2151 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2164 /* Check if the chassis-type indicates there is no builtin LCD panel */
2211 if (only_lcd == -1) { in acpi_video_register()
2288 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()