Lines Matching +full:device +full:- +full:handle

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>
32 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
52 static int report_key_events = -1;
57 static int hw_changes_brightness = -1;
61 "a hotkey is pressed: -1: auto, 0: normal 1: hw-changes-brightness");
70 static int only_lcd = -1;
78 static int acpi_video_bus_add(struct acpi_device *device);
79 static void acpi_video_bus_remove(struct acpi_device *device);
80 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data);
121 u8 _GPD:1; /* Get POST Device */
122 u8 _SPD:1; /* Set POST Device */
128 u32 display_index:4; /* A zero-based instance of the Display */
132 u32 bios_can_detect:1; /* BIOS can detect the device */
133 u32 depend_on_vga:1; /* Non-VGA output device whose power is related to
134 the VGA device. */
135 u32 pipe_id:3; /* For VGA multiple-head devices. */
139 * The device ID might not actually follow the scheme described by this
157 struct acpi_device *device; member
169 char phys[32]; /* for input device */
190 u8 _DDC:1; /* Return the EDID for this device */
207 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
210 struct acpi_video_device *device);
212 static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
215 struct acpi_video_device *device,
217 static int acpi_video_get_next_level(struct acpi_video_device *device,
221 /* backlight device sysfs support */
229 return -EINVAL; in acpi_video_get_brightness()
230 for (i = ACPI_VIDEO_FIRST_LEVEL; i < vd->brightness->count; i++) { in acpi_video_get_brightness()
231 if (vd->brightness->levels[i] == cur_level) in acpi_video_get_brightness()
232 return i - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_get_brightness()
239 int request_level = bd->props.brightness + ACPI_VIDEO_FIRST_LEVEL; in acpi_video_set_brightness()
242 cancel_delayed_work(&vd->switch_brightness_work); in acpi_video_set_brightness()
244 vd->brightness->levels[request_level]); in acpi_video_set_brightness()
252 /* thermal cooling device callbacks */
256 struct acpi_video_device *video = cooling_dev->devdata; in video_get_max_state()
258 *state = video->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in video_get_max_state()
265 struct acpi_video_device *video = cooling_dev->devdata; in video_get_cur_state()
270 return -EINVAL; in video_get_cur_state()
271 for (offset = ACPI_VIDEO_FIRST_LEVEL; offset < video->brightness->count; in video_get_cur_state()
273 if (level == video->brightness->levels[offset]) { in video_get_cur_state()
274 *state = video->brightness->count - offset - 1; in video_get_cur_state()
278 return -EINVAL; in video_get_cur_state()
284 struct acpi_video_device *video = cooling_dev->devdata; in video_set_cur_state()
287 if (state >= video->brightness->count - ACPI_VIDEO_FIRST_LEVEL) in video_set_cur_state()
288 return -EINVAL; in video_set_cur_state()
290 state = video->brightness->count - state; in video_set_cur_state()
291 level = video->brightness->levels[state - 1]; in video_set_cur_state()
302 * --------------------------------------------------------------------------
304 * --------------------------------------------------------------------------
308 acpi_video_device_lcd_query_levels(acpi_handle handle, in acpi_video_device_lcd_query_levels() argument
318 status = acpi_evaluate_object(handle, "_BCL", NULL, &buffer); in acpi_video_device_lcd_query_levels()
322 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_lcd_query_levels()
323 acpi_handle_info(handle, "Invalid _BCL data\n"); in acpi_video_device_lcd_query_levels()
324 status = -EFAULT; in acpi_video_device_lcd_query_levels()
339 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) in acpi_video_device_lcd_set_level() argument
344 status = acpi_execute_simple_method(device->dev->handle, in acpi_video_device_lcd_set_level()
347 acpi_handle_info(device->dev->handle, "_BCM evaluation failed\n"); in acpi_video_device_lcd_set_level()
348 return -EIO; in acpi_video_device_lcd_set_level()
351 device->brightness->curr = level; in acpi_video_device_lcd_set_level()
352 for (state = ACPI_VIDEO_FIRST_LEVEL; state < device->brightness->count; in acpi_video_device_lcd_set_level()
354 if (level == device->brightness->levels[state]) { in acpi_video_device_lcd_set_level()
355 if (device->backlight) in acpi_video_device_lcd_set_level()
356 device->backlight->props.brightness = in acpi_video_device_lcd_set_level()
357 state - ACPI_VIDEO_FIRST_LEVEL; in acpi_video_device_lcd_set_level()
361 acpi_handle_info(device->dev->handle, "Current brightness invalid\n"); in acpi_video_device_lcd_set_level()
362 return -EINVAL; in acpi_video_device_lcd_set_level()
391 if (report_key_events == -1) in video_set_report_key_events()
392 report_key_events = (uintptr_t)id->driver_data; in video_set_report_key_events()
399 if (hw_changes_brightness == -1) in video_hw_changes_brightness()
450 * Some machine's _DOD IDs don't have bit 31(Device ID Scheme) set
451 * but the IDs actually follow the Device ID Scheme.
477 * Some machines report wrong key events on the acpi-bus, suppress
480 * events, in this case acpi-video is considered the canonical source
483 * vendor acpi/wmi driver or by using /lib/udev/hwdb.d/60-keyboard.hwdb
531 acpi_video_bqc_value_to_level(struct acpi_video_device *device, in acpi_video_bqc_value_to_level() argument
536 if (device->brightness->flags._BQC_use_index) { in acpi_video_bqc_value_to_level()
542 if (device->brightness->flags._BCL_reversed) in acpi_video_bqc_value_to_level()
543 bqc_value = device->brightness->count - in acpi_video_bqc_value_to_level()
544 ACPI_VIDEO_FIRST_LEVEL - 1 - bqc_value; in acpi_video_bqc_value_to_level()
546 level = device->brightness->levels[bqc_value + in acpi_video_bqc_value_to_level()
558 acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, in acpi_video_device_lcd_get_level_current() argument
564 if (device->cap._BQC || device->cap._BCQ) { in acpi_video_device_lcd_get_level_current()
565 char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; in acpi_video_device_lcd_get_level_current()
567 status = acpi_evaluate_integer(device->dev->handle, buf, in acpi_video_device_lcd_get_level_current()
579 *level = acpi_video_bqc_value_to_level(device, *level); in acpi_video_device_lcd_get_level_current()
582 i < device->brightness->count; i++) in acpi_video_device_lcd_get_level_current()
583 if (device->brightness->levels[i] == *level) { in acpi_video_device_lcd_get_level_current()
584 device->brightness->curr = *level; in acpi_video_device_lcd_get_level_current()
591 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
593 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
598 * dev->brightness->curr is a cached value which stores in acpi_video_device_lcd_get_level_current()
603 acpi_handle_info(device->dev->handle, in acpi_video_device_lcd_get_level_current()
605 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_device_lcd_get_level_current()
609 *level = device->brightness->curr; in acpi_video_device_lcd_get_level_current()
614 acpi_video_device_EDID(struct acpi_video_device *device, in acpi_video_device_EDID() argument
626 if (!device) in acpi_video_device_EDID()
627 return -ENODEV; in acpi_video_device_EDID()
633 return -EINVAL; in acpi_video_device_EDID()
635 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); in acpi_video_device_EDID()
637 return -ENODEV; in acpi_video_device_EDID()
641 if (obj && obj->type == ACPI_TYPE_BUFFER) in acpi_video_device_EDID()
644 acpi_handle_info(device->dev->handle, "Invalid _DDC data\n"); in acpi_video_device_EDID()
645 status = -EFAULT; in acpi_video_device_EDID()
656 * video : video bus device pointer
669 * - the power changes from AC to DC (ACPI appendix B)
670 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
673 * - the power changes from AC to DC (ACPI appendix B)
674 * - a brightness hotkey gets pressed (implied by Win7/8 backlight docs)
676 * -EINVAL wrong arg.
684 if (!video->cap._DOS) in acpi_video_bus_DOS()
688 return -EINVAL; in acpi_video_bus_DOS()
689 video->dos_setting = (lcd_flag << 2) | bios_flag; in acpi_video_bus_DOS()
690 status = acpi_execute_simple_method(video->device->handle, "_DOS", in acpi_video_bus_DOS()
693 return -EIO; in acpi_video_bus_DOS()
705 return *(int *)a - *(int *)b; in acpi_video_cmp_level()
715 static int acpi_video_bqc_quirk(struct acpi_video_device *device, in acpi_video_bqc_quirk() argument
718 struct acpi_video_device_brightness *br = device->brightness; in acpi_video_bqc_quirk()
733 * (br->levels[2]) is likely to be 0, and if the number of levels in acpi_video_bqc_quirk()
750 * xbacklight -set 10; xbacklight -set 20; in acpi_video_bqc_quirk()
758 ? br->levels[ACPI_VIDEO_FIRST_LEVEL + 1] in acpi_video_bqc_quirk()
761 result = acpi_video_device_lcd_set_level(device, test_level); in acpi_video_bqc_quirk()
765 result = acpi_video_device_lcd_get_level_current(device, &level, true); in acpi_video_bqc_quirk()
771 if (level < br->count) { in acpi_video_bqc_quirk()
772 if (br->flags._BCL_reversed) in acpi_video_bqc_quirk()
773 level = br->count - ACPI_VIDEO_FIRST_LEVEL - 1 - level; in acpi_video_bqc_quirk()
774 if (br->levels[level + ACPI_VIDEO_FIRST_LEVEL] == test_level) in acpi_video_bqc_quirk()
775 br->flags._BQC_use_index = 1; in acpi_video_bqc_quirk()
778 if (!br->flags._BQC_use_index) in acpi_video_bqc_quirk()
779 device->cap._BQC = device->cap._BCQ = 0; in acpi_video_bqc_quirk()
785 int acpi_video_get_levels(struct acpi_device *device, in acpi_video_get_levels() argument
796 if (ACPI_FAILURE(acpi_video_device_lcd_query_levels(device->handle, &obj))) { in acpi_video_get_levels()
797 acpi_handle_debug(device->handle, in acpi_video_get_levels()
799 result = -ENODEV; in acpi_video_get_levels()
803 if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) { in acpi_video_get_levels()
804 result = -EINVAL; in acpi_video_get_levels()
810 result = -ENOMEM; in acpi_video_get_levels()
819 br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
820 sizeof(*br->levels), in acpi_video_get_levels()
822 if (!br->levels) { in acpi_video_get_levels()
823 result = -ENOMEM; in acpi_video_get_levels()
827 for (i = 0; i < obj->package.count; i++) { in acpi_video_get_levels()
828 o = (union acpi_object *)&obj->package.elements[i]; in acpi_video_get_levels()
829 if (o->type != ACPI_TYPE_INTEGER) { in acpi_video_get_levels()
830 acpi_handle_info(device->handle, "Invalid data\n"); in acpi_video_get_levels()
833 value = (u32) o->integer.value; in acpi_video_get_levels()
836 && br->levels[count - 1] == value) in acpi_video_get_levels()
839 br->levels[count] = value; in acpi_video_get_levels()
841 if (br->levels[count] > max_level) in acpi_video_get_levels()
842 max_level = br->levels[count]; in acpi_video_get_levels()
853 if (br->levels[i] == br->levels[ACPI_VIDEO_AC_LEVEL]) in acpi_video_get_levels()
855 if (br->levels[i] == br->levels[ACPI_VIDEO_BATTERY_LEVEL]) in acpi_video_get_levels()
860 level_ac_battery = ACPI_VIDEO_FIRST_LEVEL - level_ac_battery; in acpi_video_get_levels()
861 br->flags._BCL_no_ac_battery_levels = 1; in acpi_video_get_levels()
862 for (i = (count - 1 + level_ac_battery); in acpi_video_get_levels()
863 i >= ACPI_VIDEO_FIRST_LEVEL; i--) in acpi_video_get_levels()
864 br->levels[i] = br->levels[i - level_ac_battery]; in acpi_video_get_levels()
867 acpi_handle_info(device->handle, in acpi_video_get_levels()
871 if (max_level == br->levels[ACPI_VIDEO_FIRST_LEVEL]) { in acpi_video_get_levels()
872 br->flags._BCL_reversed = 1; in acpi_video_get_levels()
873 sort(&br->levels[ACPI_VIDEO_FIRST_LEVEL], in acpi_video_get_levels()
874 count - ACPI_VIDEO_FIRST_LEVEL, in acpi_video_get_levels()
875 sizeof(br->levels[ACPI_VIDEO_FIRST_LEVEL]), in acpi_video_get_levels()
877 } else if (max_level != br->levels[count - 1]) in acpi_video_get_levels()
878 acpi_handle_info(device->handle, in acpi_video_get_levels()
881 br->count = count; in acpi_video_get_levels()
897 * device : video output device (LCD, CRT, ..)
902 * Allocate and initialize device->brightness.
906 acpi_video_init_brightness(struct acpi_video_device *device) in acpi_video_init_brightness() argument
913 result = acpi_video_get_levels(device->dev, &br, &max_level); in acpi_video_init_brightness()
916 device->brightness = br; in acpi_video_init_brightness()
919 br->curr = level = max_level; in acpi_video_init_brightness()
921 if (!device->cap._BQC) in acpi_video_init_brightness()
924 result = acpi_video_device_lcd_get_level_current(device, in acpi_video_init_brightness()
929 result = acpi_video_bqc_quirk(device, max_level, level_old); in acpi_video_init_brightness()
936 if (!device->cap._BQC) in acpi_video_init_brightness()
939 level = acpi_video_bqc_value_to_level(device, level_old); in acpi_video_init_brightness()
946 for (i = ACPI_VIDEO_FIRST_LEVEL; i < br->count; i++) in acpi_video_init_brightness()
947 if (level == br->levels[i]) in acpi_video_init_brightness()
949 if (i == br->count || !level) in acpi_video_init_brightness()
953 result = acpi_video_device_lcd_set_level(device, level); in acpi_video_init_brightness()
957 acpi_handle_debug(device->dev->handle, "found %d brightness levels\n", in acpi_video_init_brightness()
958 br->count - ACPI_VIDEO_FIRST_LEVEL); in acpi_video_init_brightness()
963 kfree(br->levels); in acpi_video_init_brightness()
965 device->brightness = NULL; in acpi_video_init_brightness()
971 * device : video output device (LCD, CRT, ..)
977 * device.
980 static void acpi_video_device_find_cap(struct acpi_video_device *device) in acpi_video_device_find_cap() argument
982 if (acpi_has_method(device->dev->handle, "_ADR")) in acpi_video_device_find_cap()
983 device->cap._ADR = 1; in acpi_video_device_find_cap()
984 if (acpi_has_method(device->dev->handle, "_BCL")) in acpi_video_device_find_cap()
985 device->cap._BCL = 1; in acpi_video_device_find_cap()
986 if (acpi_has_method(device->dev->handle, "_BCM")) in acpi_video_device_find_cap()
987 device->cap._BCM = 1; in acpi_video_device_find_cap()
988 if (acpi_has_method(device->dev->handle, "_BQC")) { in acpi_video_device_find_cap()
989 device->cap._BQC = 1; in acpi_video_device_find_cap()
990 } else if (acpi_has_method(device->dev->handle, "_BCQ")) { in acpi_video_device_find_cap()
991 acpi_handle_info(device->dev->handle, in acpi_video_device_find_cap()
993 device->cap._BCQ = 1; in acpi_video_device_find_cap()
996 if (acpi_has_method(device->dev->handle, "_DDC")) in acpi_video_device_find_cap()
997 device->cap._DDC = 1; in acpi_video_device_find_cap()
1002 * device : video output device (VGA)
1007 * Find out all required AML methods defined under the video bus device.
1012 if (acpi_has_method(video->device->handle, "_DOS")) in acpi_video_bus_find_cap()
1013 video->cap._DOS = 1; in acpi_video_bus_find_cap()
1014 if (acpi_has_method(video->device->handle, "_DOD")) in acpi_video_bus_find_cap()
1015 video->cap._DOD = 1; in acpi_video_bus_find_cap()
1016 if (acpi_has_method(video->device->handle, "_ROM")) in acpi_video_bus_find_cap()
1017 video->cap._ROM = 1; in acpi_video_bus_find_cap()
1018 if (acpi_has_method(video->device->handle, "_GPD")) in acpi_video_bus_find_cap()
1019 video->cap._GPD = 1; in acpi_video_bus_find_cap()
1020 if (acpi_has_method(video->device->handle, "_SPD")) in acpi_video_bus_find_cap()
1021 video->cap._SPD = 1; in acpi_video_bus_find_cap()
1022 if (acpi_has_method(video->device->handle, "_VPO")) in acpi_video_bus_find_cap()
1023 video->cap._VPO = 1; in acpi_video_bus_find_cap()
1027 * Check whether the video bus device has required AML method to
1033 acpi_status status = -ENOENT; in acpi_video_bus_check()
1037 return -EINVAL; in acpi_video_bus_check()
1039 dev = acpi_get_pci_dev(video->device->handle); in acpi_video_bus_check()
1041 return -ENODEV; in acpi_video_bus_check()
1049 /* Does this device support video switching? */ in acpi_video_bus_check()
1050 if (video->cap._DOS || video->cap._DOD) { in acpi_video_bus_check()
1051 if (!video->cap._DOS) { in acpi_video_bus_check()
1053 acpi_device_bid(video->device)); in acpi_video_bus_check()
1055 video->flags.multihead = 1; in acpi_video_bus_check()
1059 /* Does this device support retrieving a video ROM? */ in acpi_video_bus_check()
1060 if (video->cap._ROM) { in acpi_video_bus_check()
1061 video->flags.rom = 1; in acpi_video_bus_check()
1065 /* Does this device support configuring which video device to POST? */ in acpi_video_bus_check()
1066 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { in acpi_video_bus_check()
1067 video->flags.post = 1; in acpi_video_bus_check()
1075 * --------------------------------------------------------------------------
1077 * --------------------------------------------------------------------------
1080 /* device interface */
1087 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_attr()
1088 ids = &video->attached_array[i]; in acpi_video_get_device_attr()
1089 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_attr()
1090 return &ids->value.attrib; in acpi_video_get_device_attr()
1103 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_device_type()
1104 ids = &video->attached_array[i]; in acpi_video_get_device_type()
1105 if ((ids->value.int_val & 0xffff) == device_id) in acpi_video_get_device_type()
1106 return ids->value.int_val; in acpi_video_get_device_type()
1112 static int acpi_video_bus_get_one_device(struct acpi_device *device, void *arg) in acpi_video_bus_get_one_device() argument
1121 status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); in acpi_video_bus_get_one_device()
1128 dev_dbg(&device->dev, "Cannot attach\n"); in acpi_video_bus_get_one_device()
1129 return -ENOMEM; in acpi_video_bus_get_one_device()
1132 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); in acpi_video_bus_get_one_device()
1133 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); in acpi_video_bus_get_one_device()
1135 data->device_id = device_id; in acpi_video_bus_get_one_device()
1136 data->video = video; in acpi_video_bus_get_one_device()
1137 data->dev = device; in acpi_video_bus_get_one_device()
1138 INIT_DELAYED_WORK(&data->switch_brightness_work, in acpi_video_bus_get_one_device()
1143 if (attribute && (attribute->device_id_scheme || device_id_scheme)) { in acpi_video_bus_get_one_device()
1144 switch (attribute->display_type) { in acpi_video_bus_get_one_device()
1146 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1149 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1152 data->flags.dvi = 1; in acpi_video_bus_get_one_device()
1155 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1158 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1161 if (attribute->bios_can_detect) in acpi_video_bus_get_one_device()
1162 data->flags.bios = 1; in acpi_video_bus_get_one_device()
1166 /* Ignore bits 16 and 18-20 */ in acpi_video_bus_get_one_device()
1169 data->flags.crt = 1; in acpi_video_bus_get_one_device()
1172 data->flags.lcd = 1; in acpi_video_bus_get_one_device()
1175 data->flags.tvout = 1; in acpi_video_bus_get_one_device()
1178 data->flags.unknown = 1; in acpi_video_bus_get_one_device()
1185 if (data->cap._BCM && data->cap._BCL) in acpi_video_bus_get_one_device()
1188 mutex_lock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1189 list_add_tail(&data->entry, &video->video_device_list); in acpi_video_bus_get_one_device()
1190 mutex_unlock(&video->device_list_lock); in acpi_video_bus_get_one_device()
1193 video->child_count++; in acpi_video_bus_get_one_device()
1199 * video : video bus device
1204 * Enumerate the video device list of the video bus,
1213 mutex_lock(&video->device_list_lock); in acpi_video_device_rebind()
1215 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_device_rebind()
1218 mutex_unlock(&video->device_list_lock); in acpi_video_device_rebind()
1223 * video : video bus device
1224 * device : video output device under the video
1236 struct acpi_video_device *device) in acpi_video_device_bind() argument
1241 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_bind()
1242 ids = &video->attached_array[i]; in acpi_video_device_bind()
1243 if (device->device_id == (ids->value.int_val & 0xffff)) { in acpi_video_device_bind()
1244 ids->bind_info = device; in acpi_video_device_bind()
1245 acpi_handle_debug(video->device->handle, "%s: %d\n", in acpi_video_device_bind()
1251 static bool acpi_video_device_in_dod(struct acpi_video_device *device) in acpi_video_device_in_dod() argument
1253 struct acpi_video_bus *video = device->video; in acpi_video_device_in_dod()
1261 if (!video->attached_count || video->child_count > 8) in acpi_video_device_in_dod()
1264 for (i = 0; i < video->attached_count; i++) { in acpi_video_device_in_dod()
1265 if ((video->attached_array[i].value.int_val & 0xfff) == in acpi_video_device_in_dod()
1266 (device->device_id & 0xfff)) in acpi_video_device_in_dod()
1275 * video : video bus device
1294 if (!video->cap._DOD) in acpi_video_device_enumerate()
1297 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); in acpi_video_device_enumerate()
1299 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1306 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { in acpi_video_device_enumerate()
1307 acpi_handle_info(video->device->handle, "Invalid _DOD data\n"); in acpi_video_device_enumerate()
1308 status = -EFAULT; in acpi_video_device_enumerate()
1312 acpi_handle_debug(video->device->handle, "Found %d video heads in _DOD\n", in acpi_video_device_enumerate()
1313 dod->package.count); in acpi_video_device_enumerate()
1315 active_list = kcalloc(1 + dod->package.count, in acpi_video_device_enumerate()
1319 status = -ENOMEM; in acpi_video_device_enumerate()
1324 for (i = 0; i < dod->package.count; i++) { in acpi_video_device_enumerate()
1325 obj = &dod->package.elements[i]; in acpi_video_device_enumerate()
1327 if (obj->type != ACPI_TYPE_INTEGER) { in acpi_video_device_enumerate()
1328 acpi_handle_info(video->device->handle, in acpi_video_device_enumerate()
1333 active_list[count].value.int_val = obj->integer.value; in acpi_video_device_enumerate()
1336 acpi_handle_debug(video->device->handle, in acpi_video_device_enumerate()
1338 (int)obj->integer.value); in acpi_video_device_enumerate()
1343 kfree(video->attached_array); in acpi_video_device_enumerate()
1345 video->attached_array = active_list; in acpi_video_device_enumerate()
1346 video->attached_count = count; in acpi_video_device_enumerate()
1354 acpi_video_get_next_level(struct acpi_video_device *device, in acpi_video_get_next_level() argument
1361 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1362 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1363 if (abs(l - level_current) < abs(delta)) { in acpi_video_get_next_level()
1364 delta = l - level_current; in acpi_video_get_next_level()
1371 for (i = ACPI_VIDEO_FIRST_LEVEL; i < device->brightness->count; i++) { in acpi_video_get_next_level()
1372 l = device->brightness->levels[i]; in acpi_video_get_next_level()
1401 struct acpi_video_device *device = container_of(to_delayed_work(work), in acpi_video_switch_brightness() local
1404 int event = device->switch_brightness_event; in acpi_video_switch_brightness()
1405 int result = -EINVAL; in acpi_video_switch_brightness()
1408 if (!device->backlight) in acpi_video_switch_brightness()
1411 if (!device->brightness) in acpi_video_switch_brightness()
1414 result = acpi_video_device_lcd_get_level_current(device, in acpi_video_switch_brightness()
1420 level_next = acpi_video_get_next_level(device, level_current, event); in acpi_video_switch_brightness()
1422 result = acpi_video_device_lcd_set_level(device, level_next); in acpi_video_switch_brightness()
1425 backlight_force_update(device->backlight, in acpi_video_switch_brightness()
1430 acpi_handle_info(device->dev->handle, in acpi_video_switch_brightness()
1434 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, in acpi_video_get_edid() argument
1443 if (!device || !acpi_driver_data(device)) in acpi_video_get_edid()
1444 return -EINVAL; in acpi_video_get_edid()
1446 video = acpi_driver_data(device); in acpi_video_get_edid()
1448 for (i = 0; i < video->attached_count; i++) { in acpi_video_get_edid()
1449 video_device = video->attached_array[i].bind_info; in acpi_video_get_edid()
1455 if (!video_device->cap._DDC) in acpi_video_get_edid()
1461 if (!video_device->flags.crt) in acpi_video_get_edid()
1465 if (!video_device->flags.tvout) in acpi_video_get_edid()
1469 if (!video_device->flags.dvi) in acpi_video_get_edid()
1473 if (!video_device->flags.lcd) in acpi_video_get_edid()
1477 } else if (video_device->device_id != device_id) { in acpi_video_get_edid()
1484 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1489 buffer->type != ACPI_TYPE_BUFFER) { in acpi_video_get_edid()
1494 *edid = buffer->buffer.pointer; in acpi_video_get_edid()
1498 return -ENODEV; in acpi_video_get_edid()
1504 struct acpi_device *device) in acpi_video_bus_get_devices() argument
1513 return acpi_dev_for_each_child(device, acpi_video_bus_get_one_device, video); in acpi_video_bus_get_devices()
1534 static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) in acpi_video_bus_notify() argument
1536 struct acpi_device *device = data; in acpi_video_bus_notify() local
1537 struct acpi_video_bus *video = acpi_driver_data(device); in acpi_video_bus_notify()
1541 if (!video || !video->input) in acpi_video_bus_notify()
1544 input = video->input; in acpi_video_bus_notify()
1570 acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", in acpi_video_bus_notify()
1575 if (acpi_notifier_call_chain(device, event, 0)) in acpi_video_bus_notify()
1593 video_device->switch_brightness_event = event; in brightness_switch_event()
1594 schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); in brightness_switch_event()
1597 static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) in acpi_video_device_notify() argument
1600 struct acpi_device *device = NULL; in acpi_video_device_notify() local
1608 device = video_device->dev; in acpi_video_device_notify()
1609 bus = video_device->video; in acpi_video_device_notify()
1610 input = bus->input; in acpi_video_device_notify()
1613 if (video_device->backlight) in acpi_video_device_notify()
1614 backlight_force_update(video_device->backlight, in acpi_video_device_notify()
1616 acpi_notifier_call_chain(device, event, 0); in acpi_video_device_notify()
1637 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ in acpi_video_device_notify()
1642 acpi_handle_debug(handle, "Unsupported event [0x%x]\n", event); in acpi_video_device_notify()
1649 acpi_notifier_call_chain(device, event, 0); in acpi_video_device_notify()
1672 dev_info(&video->device->dev, "Restoring backlight state\n"); in acpi_video_resume()
1674 for (i = 0; i < video->attached_count; i++) { in acpi_video_resume()
1675 video_device = video->attached_array[i].bind_info; in acpi_video_resume()
1676 if (video_device && video_device->brightness) in acpi_video_resume()
1678 video_device->brightness->curr); in acpi_video_resume()
1687 acpi_video_bus_match(acpi_handle handle, u32 level, void *context, in acpi_video_bus_match() argument
1690 struct acpi_device *device = context; in acpi_video_bus_match() local
1693 if (handle == device->handle) in acpi_video_bus_match()
1696 sibling = acpi_fetch_acpi_dev(handle); in acpi_video_bus_match()
1706 static void acpi_video_dev_register_backlight(struct acpi_video_device *device) in acpi_video_dev_register_backlight() argument
1711 struct device *parent = NULL; in acpi_video_dev_register_backlight()
1716 result = acpi_video_init_brightness(device); in acpi_video_dev_register_backlight()
1725 if (ACPI_SUCCESS(acpi_get_parent(device->dev->handle, &acpi_parent))) { in acpi_video_dev_register_backlight()
1728 parent = &pdev->dev; in acpi_video_dev_register_backlight()
1736 device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1; in acpi_video_dev_register_backlight()
1737 device->backlight = backlight_device_register(name, in acpi_video_dev_register_backlight()
1739 device, in acpi_video_dev_register_backlight()
1743 if (IS_ERR(device->backlight)) { in acpi_video_dev_register_backlight()
1744 device->backlight = NULL; in acpi_video_dev_register_backlight()
1752 device->backlight->props.brightness = in acpi_video_dev_register_backlight()
1753 acpi_video_get_brightness(device->backlight); in acpi_video_dev_register_backlight()
1755 device->cooling_dev = thermal_cooling_device_register("LCD", device, in acpi_video_dev_register_backlight()
1757 if (IS_ERR(device->cooling_dev)) { in acpi_video_dev_register_backlight()
1761 * register video output if cooling device registration failed? in acpi_video_dev_register_backlight()
1762 * -- dtor in acpi_video_dev_register_backlight()
1764 device->cooling_dev = NULL; in acpi_video_dev_register_backlight()
1768 dev_info(&device->dev->dev, "registered as cooling_device%d\n", in acpi_video_dev_register_backlight()
1769 device->cooling_dev->id); in acpi_video_dev_register_backlight()
1770 result = sysfs_create_link(&device->dev->dev.kobj, in acpi_video_dev_register_backlight()
1771 &device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1776 result = sysfs_create_link(&device->cooling_dev->device.kobj, in acpi_video_dev_register_backlight()
1777 &device->dev->dev.kobj, "device"); in acpi_video_dev_register_backlight()
1787 mutex_lock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1788 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_run_bcl_for_osi()
1789 if (!acpi_video_device_lcd_query_levels(dev->dev->handle, &levels)) in acpi_video_run_bcl_for_osi()
1792 mutex_unlock(&video->device_list_lock); in acpi_video_run_bcl_for_osi()
1798 * Do not create backlight device for video output in acpi_video_should_register_backlight()
1799 * device that is not in the enumerated list. in acpi_video_should_register_backlight()
1802 dev_dbg(&dev->dev->dev, "not in _DOD list, ignore\n"); in acpi_video_should_register_backlight()
1807 return dev->flags.lcd; in acpi_video_should_register_backlight()
1815 if (video->backlight_registered) in acpi_video_bus_register_backlight()
1821 mutex_lock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1822 list_for_each_entry(dev, &video->video_device_list, entry) { in acpi_video_bus_register_backlight()
1826 mutex_unlock(&video->device_list_lock); in acpi_video_bus_register_backlight()
1828 video->backlight_registered = true; in acpi_video_bus_register_backlight()
1830 video->pm_nb.notifier_call = acpi_video_resume; in acpi_video_bus_register_backlight()
1831 video->pm_nb.priority = 0; in acpi_video_bus_register_backlight()
1832 return register_pm_notifier(&video->pm_nb); in acpi_video_bus_register_backlight()
1835 static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device) in acpi_video_dev_unregister_backlight() argument
1837 if (device->backlight) { in acpi_video_dev_unregister_backlight()
1838 backlight_device_unregister(device->backlight); in acpi_video_dev_unregister_backlight()
1839 device->backlight = NULL; in acpi_video_dev_unregister_backlight()
1841 if (device->brightness) { in acpi_video_dev_unregister_backlight()
1842 kfree(device->brightness->levels); in acpi_video_dev_unregister_backlight()
1843 kfree(device->brightness); in acpi_video_dev_unregister_backlight()
1844 device->brightness = NULL; in acpi_video_dev_unregister_backlight()
1846 if (device->cooling_dev) { in acpi_video_dev_unregister_backlight()
1847 sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); in acpi_video_dev_unregister_backlight()
1848 sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); in acpi_video_dev_unregister_backlight()
1849 thermal_cooling_device_unregister(device->cooling_dev); in acpi_video_dev_unregister_backlight()
1850 device->cooling_dev = NULL; in acpi_video_dev_unregister_backlight()
1859 if (!video->backlight_registered) in acpi_video_bus_unregister_backlight()
1862 error = unregister_pm_notifier(&video->pm_nb); in acpi_video_bus_unregister_backlight()
1864 mutex_lock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1865 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_unregister_backlight()
1867 mutex_unlock(&video->device_list_lock); in acpi_video_bus_unregister_backlight()
1869 video->backlight_registered = false; in acpi_video_bus_unregister_backlight()
1874 static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device) in acpi_video_dev_add_notify_handler() argument
1877 struct acpi_device *adev = device->dev; in acpi_video_dev_add_notify_handler()
1879 status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_add_notify_handler()
1880 acpi_video_device_notify, device); in acpi_video_dev_add_notify_handler()
1882 dev_err(&adev->dev, "Error installing notify handler\n"); in acpi_video_dev_add_notify_handler()
1884 device->flags.notify = 1; in acpi_video_dev_add_notify_handler()
1893 video->input = input = input_allocate_device(); in acpi_video_bus_add_notify_handler()
1895 error = -ENOMEM; in acpi_video_bus_add_notify_handler()
1903 snprintf(video->phys, sizeof(video->phys), in acpi_video_bus_add_notify_handler()
1904 "%s/video/input0", acpi_device_hid(video->device)); in acpi_video_bus_add_notify_handler()
1906 input->name = acpi_device_name(video->device); in acpi_video_bus_add_notify_handler()
1907 input->phys = video->phys; in acpi_video_bus_add_notify_handler()
1908 input->id.bustype = BUS_HOST; in acpi_video_bus_add_notify_handler()
1909 input->id.product = 0x06; in acpi_video_bus_add_notify_handler()
1910 input->dev.parent = &video->device->dev; in acpi_video_bus_add_notify_handler()
1911 input->evbit[0] = BIT(EV_KEY); in acpi_video_bus_add_notify_handler()
1912 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); in acpi_video_bus_add_notify_handler()
1913 set_bit(KEY_VIDEO_NEXT, input->keybit); in acpi_video_bus_add_notify_handler()
1914 set_bit(KEY_VIDEO_PREV, input->keybit); in acpi_video_bus_add_notify_handler()
1915 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); in acpi_video_bus_add_notify_handler()
1916 set_bit(KEY_BRIGHTNESSUP, input->keybit); in acpi_video_bus_add_notify_handler()
1917 set_bit(KEY_BRIGHTNESSDOWN, input->keybit); in acpi_video_bus_add_notify_handler()
1918 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); in acpi_video_bus_add_notify_handler()
1919 set_bit(KEY_DISPLAY_OFF, input->keybit); in acpi_video_bus_add_notify_handler()
1925 mutex_lock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1926 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_add_notify_handler()
1928 mutex_unlock(&video->device_list_lock); in acpi_video_bus_add_notify_handler()
1936 video->input = NULL; in acpi_video_bus_add_notify_handler()
1943 if (dev->flags.notify) { in acpi_video_dev_remove_notify_handler()
1944 acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, in acpi_video_dev_remove_notify_handler()
1946 dev->flags.notify = 0; in acpi_video_dev_remove_notify_handler()
1954 mutex_lock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1955 list_for_each_entry(dev, &video->video_device_list, entry) in acpi_video_bus_remove_notify_handler()
1957 mutex_unlock(&video->device_list_lock); in acpi_video_bus_remove_notify_handler()
1960 input_unregister_device(video->input); in acpi_video_bus_remove_notify_handler()
1961 video->input = NULL; in acpi_video_bus_remove_notify_handler()
1968 mutex_lock(&video->device_list_lock); in acpi_video_bus_put_devices()
1969 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { in acpi_video_bus_put_devices()
1970 list_del(&dev->entry); in acpi_video_bus_put_devices()
1973 mutex_unlock(&video->device_list_lock); in acpi_video_bus_put_devices()
1980 static int acpi_video_bus_add(struct acpi_device *device) in acpi_video_bus_add() argument
1988 acpi_dev_parent(device)->handle, 1, in acpi_video_bus_add()
1990 device, NULL); in acpi_video_bus_add()
1998 return -ENODEV; in acpi_video_bus_add()
2003 return -ENOMEM; in acpi_video_bus_add()
2006 if (!strcmp(device->pnp.bus_id, "VID")) { in acpi_video_bus_add()
2008 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2012 if (!strcmp(device->pnp.bus_id, "VGA")) { in acpi_video_bus_add()
2014 device->pnp.bus_id[3] = '0' + instance; in acpi_video_bus_add()
2018 video->device = device; in acpi_video_bus_add()
2019 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); in acpi_video_bus_add()
2020 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); in acpi_video_bus_add()
2021 device->driver_data = video; in acpi_video_bus_add()
2028 mutex_init(&video->device_list_lock); in acpi_video_bus_add()
2029 INIT_LIST_HEAD(&video->video_device_list); in acpi_video_bus_add()
2031 error = acpi_video_bus_get_devices(video, device); in acpi_video_bus_add()
2039 acpi_device_fix_up_power_children(device); in acpi_video_bus_add()
2041 pr_info("%s [%s] (multi-head: %s rom: %s post: %s)\n", in acpi_video_bus_add()
2042 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), in acpi_video_bus_add()
2043 video->flags.multihead ? "yes" : "no", in acpi_video_bus_add()
2044 video->flags.rom ? "yes" : "no", in acpi_video_bus_add()
2045 video->flags.post ? "yes" : "no"); in acpi_video_bus_add()
2047 list_add_tail(&video->entry, &video_bus_head); in acpi_video_bus_add()
2051 * If backlight-type auto-detection is used then a native backlight may in acpi_video_bus_add()
2053 * Therefor normally the userspace visible /sys/class/backlight device in acpi_video_bus_add()
2056 * Register the backlight now when not using auto-detection, so that in acpi_video_bus_add()
2057 * when the kernel cmdline or DMI-quirks are used the backlight will in acpi_video_bus_add()
2069 error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, in acpi_video_bus_add()
2080 list_del(&video->entry); in acpi_video_bus_add()
2085 kfree(video->attached_array); in acpi_video_bus_add()
2088 device->driver_data = NULL; in acpi_video_bus_add()
2093 static void acpi_video_bus_remove(struct acpi_device *device) in acpi_video_bus_remove() argument
2098 if (!device || !acpi_driver_data(device)) in acpi_video_bus_remove()
2101 video = acpi_driver_data(device); in acpi_video_bus_remove()
2103 acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, in acpi_video_bus_remove()
2107 list_del(&video->entry); in acpi_video_bus_remove()
2114 kfree(video->attached_array); in acpi_video_bus_remove()
2120 if (dev->device == 0x00D1) in is_i740()
2122 if (dev->device == 0x7000) in is_i740()
2134 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) in intel_opregion_present()
2136 if (dev->vendor != PCI_VENDOR_ID_INTEL) in intel_opregion_present()
2149 /* Check if the chassis-type indicates there is no builtin LCD panel */
2182 * 2.1 Report a desktop/server DMI chassis-type, or
2183 * 2.2 Are an ACPI-reduced-hardware platform (and thus won't use the EC for
2213 if (only_lcd == -1) in acpi_video_register()
2267 * state before any ACPI video calls are made. To handle this we defer
2278 * acpi_video_register() will report -ENODEV later as well due in acpi_video_init()