Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 2 | * video.c - ACPI Video Driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> |
| 5 | * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org> |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 6 | * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/list.h> |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 29 | #include <linux/input.h> |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 30 | #include <linux/backlight.h> |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 31 | #include <linux/thermal.h> |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 32 | #include <linux/sort.h> |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 33 | #include <linux/pci.h> |
| 34 | #include <linux/pci_ids.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Len Brown | eb27cae | 2009-07-06 23:40:19 -0400 | [diff] [blame] | 36 | #include <linux/dmi.h> |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 37 | #include <linux/suspend.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 38 | #include <linux/acpi.h> |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 39 | #include <acpi/video.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 40 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Hans de Goede | 14ca7a47 | 2015-06-16 16:27:47 +0200 | [diff] [blame] | 42 | #define PREFIX "ACPI: " |
Rafael J. Wysocki | 8c5bd7a | 2013-07-18 02:08:06 +0200 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define ACPI_VIDEO_BUS_NAME "Video Bus" |
| 45 | #define ACPI_VIDEO_DEVICE_NAME "Video Device" |
| 46 | #define ACPI_VIDEO_NOTIFY_SWITCH 0x80 |
| 47 | #define ACPI_VIDEO_NOTIFY_PROBE 0x81 |
| 48 | #define ACPI_VIDEO_NOTIFY_CYCLE 0x82 |
| 49 | #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 |
| 50 | #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 |
| 51 | |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 52 | #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85 |
| 53 | #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86 |
| 54 | #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87 |
| 55 | #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88 |
| 56 | #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 58 | #define MAX_NAME_LEN 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define _COMPONENT ACPI_VIDEO_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 61 | ACPI_MODULE_NAME("video"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 63 | MODULE_AUTHOR("Bruno Ducrot"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 64 | MODULE_DESCRIPTION("ACPI Video Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | MODULE_LICENSE("GPL"); |
| 66 | |
Rafael J. Wysocki | 2843768 | 2014-07-14 19:35:45 +0200 | [diff] [blame] | 67 | static bool brightness_switch_enabled = 1; |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 68 | module_param(brightness_switch_enabled, bool, 0644); |
| 69 | |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 70 | /* |
| 71 | * By default, we don't allow duplicate ACPI video bus devices |
| 72 | * under the same VGA controller |
| 73 | */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 74 | static bool allow_duplicates; |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 75 | module_param(allow_duplicates, bool, 0644); |
| 76 | |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 77 | static int disable_backlight_sysfs_if = -1; |
| 78 | module_param(disable_backlight_sysfs_if, int, 0444); |
| 79 | |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 80 | static int register_count; |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 81 | static DEFINE_MUTEX(register_count_mutex); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 82 | static struct mutex video_list_lock; |
| 83 | static struct list_head video_bus_head; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | static int acpi_video_bus_add(struct acpi_device *device); |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 85 | static int acpi_video_bus_remove(struct acpi_device *device); |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 86 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event); |
Hans de Goede | 93a291d | 2015-06-16 16:27:52 +0200 | [diff] [blame] | 87 | void acpi_video_detect_exit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 89 | static const struct acpi_device_id video_device_ids[] = { |
| 90 | {ACPI_VIDEO_HID, 0}, |
| 91 | {"", 0}, |
| 92 | }; |
| 93 | MODULE_DEVICE_TABLE(acpi, video_device_ids); |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static struct acpi_driver acpi_video_bus = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 96 | .name = "video", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | .class = ACPI_VIDEO_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 98 | .ids = video_device_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .ops = { |
| 100 | .add = acpi_video_bus_add, |
| 101 | .remove = acpi_video_bus_remove, |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 102 | .notify = acpi_video_bus_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct acpi_video_bus_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | u8 multihead:1; /* can switch video heads */ |
| 108 | u8 rom:1; /* can retrieve a video rom */ |
| 109 | u8 post:1; /* can configure the head to */ |
| 110 | u8 reserved:5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct acpi_video_bus_cap { |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 114 | u8 _DOS:1; /* Enable/Disable output switching */ |
| 115 | u8 _DOD:1; /* Enumerate all devices attached to display adapter */ |
| 116 | u8 _ROM:1; /* Get ROM Data */ |
| 117 | u8 _GPD:1; /* Get POST Device */ |
| 118 | u8 _SPD:1; /* Set POST Device */ |
| 119 | u8 _VPO:1; /* Video POST Options */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | u8 reserved:2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | struct acpi_video_device_attrib { |
| 124 | u32 display_index:4; /* A zero-based instance of the Display */ |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 125 | u32 display_port_attachment:4; /* This field differentiates the display type */ |
| 126 | u32 display_type:4; /* Describe the specific type in use */ |
| 127 | u32 vendor_specific:4; /* Chipset Vendor Specific */ |
| 128 | u32 bios_can_detect:1; /* BIOS can detect the device */ |
| 129 | u32 depend_on_vga:1; /* Non-VGA output device whose power is related to |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | the VGA device. */ |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 131 | u32 pipe_id:3; /* For VGA multiple-head devices. */ |
| 132 | u32 reserved:10; /* Must be 0 */ |
| 133 | u32 device_id_scheme:1; /* Device ID Scheme */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | struct acpi_video_enumerated_device { |
| 137 | union { |
| 138 | u32 int_val; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | struct acpi_video_device_attrib attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } value; |
| 141 | struct acpi_video_device *bind_info; |
| 142 | }; |
| 143 | |
| 144 | struct acpi_video_bus { |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 145 | struct acpi_device *device; |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 146 | bool backlight_registered; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | u8 dos_setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | struct acpi_video_enumerated_device *attached_array; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | u8 attached_count; |
Aaron Lu | b4df463 | 2014-12-15 16:01:29 +0800 | [diff] [blame] | 150 | u8 child_count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | struct acpi_video_bus_cap cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | struct acpi_video_bus_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | struct list_head video_device_list; |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 154 | struct mutex device_list_lock; /* protects video_device_list */ |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 155 | struct list_head entry; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 156 | struct input_dev *input; |
| 157 | char phys[32]; /* for input device */ |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 158 | struct notifier_block pm_nb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct acpi_video_device_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | u8 crt:1; |
| 163 | u8 lcd:1; |
| 164 | u8 tvout:1; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 165 | u8 dvi:1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | u8 bios:1; |
| 167 | u8 unknown:1; |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 168 | u8 notify:1; |
| 169 | u8 reserved:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | struct acpi_video_device_cap { |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 173 | u8 _ADR:1; /* Return the unique ID */ |
| 174 | u8 _BCL:1; /* Query list of brightness control levels supported */ |
| 175 | u8 _BCM:1; /* Set the brightness level */ |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 176 | u8 _BQC:1; /* Get current brightness level */ |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 177 | u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */ |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 178 | u8 _DDC:1; /* Return the EDID for this device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 181 | struct acpi_video_brightness_flags { |
| 182 | u8 _BCL_no_ac_battery_levels:1; /* no AC/Battery levels in _BCL */ |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 183 | u8 _BCL_reversed:1; /* _BCL package is in a reversed order */ |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 184 | u8 _BQC_use_index:1; /* _BQC returns an index value */ |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 185 | }; |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | struct acpi_video_device_brightness { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | int curr; |
| 189 | int count; |
| 190 | int *levels; |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 191 | struct acpi_video_brightness_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | struct acpi_video_device { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | unsigned long device_id; |
| 196 | struct acpi_video_device_flags flags; |
| 197 | struct acpi_video_device_cap cap; |
| 198 | struct list_head entry; |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 199 | struct delayed_work switch_brightness_work; |
| 200 | int switch_brightness_event; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | struct acpi_video_bus *video; |
| 202 | struct acpi_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | struct acpi_video_device_brightness *brightness; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 204 | struct backlight_device *backlight; |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 205 | struct thermal_cooling_device *cooling_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 208 | static const char device_decode[][30] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | "motherboard VGA device", |
| 210 | "PCI VGA device", |
| 211 | "AGP VGA device", |
| 212 | "UNKNOWN", |
| 213 | }; |
| 214 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data); |
| 216 | static void acpi_video_device_rebind(struct acpi_video_bus *video); |
| 217 | static void acpi_video_device_bind(struct acpi_video_bus *video, |
| 218 | struct acpi_video_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | static int acpi_video_device_enumerate(struct acpi_video_bus *video); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 220 | static int acpi_video_device_lcd_set_level(struct acpi_video_device *device, |
| 221 | int level); |
| 222 | static int acpi_video_device_lcd_get_level_current( |
| 223 | struct acpi_video_device *device, |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 224 | unsigned long long *level, bool raw); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | static int acpi_video_get_next_level(struct acpi_video_device *device, |
| 226 | u32 level_current, u32 event); |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 227 | static void acpi_video_switch_brightness(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 229 | /* backlight device sysfs support */ |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 230 | static int acpi_video_get_brightness(struct backlight_device *bd) |
| 231 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 232 | unsigned long long cur_level; |
Matthew Garrett | 38531e6 | 2007-12-26 02:03:26 +0000 | [diff] [blame] | 233 | int i; |
Felipe Contreras | 7c364e7 | 2013-08-03 22:15:21 +0200 | [diff] [blame] | 234 | struct acpi_video_device *vd = bl_get_data(bd); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 235 | |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 236 | if (acpi_video_device_lcd_get_level_current(vd, &cur_level, false)) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 237 | return -EINVAL; |
Matthew Garrett | 38531e6 | 2007-12-26 02:03:26 +0000 | [diff] [blame] | 238 | for (i = 2; i < vd->brightness->count; i++) { |
| 239 | if (vd->brightness->levels[i] == cur_level) |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 240 | /* |
| 241 | * The first two entries are special - see page 575 |
| 242 | * of the ACPI spec 3.0 |
| 243 | */ |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 244 | return i - 2; |
Matthew Garrett | 38531e6 | 2007-12-26 02:03:26 +0000 | [diff] [blame] | 245 | } |
| 246 | return 0; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static int acpi_video_set_brightness(struct backlight_device *bd) |
| 250 | { |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 251 | int request_level = bd->props.brightness + 2; |
Felipe Contreras | 7c364e7 | 2013-08-03 22:15:21 +0200 | [diff] [blame] | 252 | struct acpi_video_device *vd = bl_get_data(bd); |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 253 | |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 254 | cancel_delayed_work(&vd->switch_brightness_work); |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 255 | return acpi_video_device_lcd_set_level(vd, |
| 256 | vd->brightness->levels[request_level]); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 257 | } |
| 258 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 259 | static const struct backlight_ops acpi_backlight_ops = { |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 260 | .get_brightness = acpi_video_get_brightness, |
| 261 | .update_status = acpi_video_set_brightness, |
| 262 | }; |
| 263 | |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 264 | /* thermal cooling device callbacks */ |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 265 | static int video_get_max_state(struct thermal_cooling_device *cooling_dev, unsigned |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 266 | long *state) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 267 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 268 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 269 | struct acpi_video_device *video = acpi_driver_data(device); |
| 270 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 271 | *state = video->brightness->count - 3; |
| 272 | return 0; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 273 | } |
| 274 | |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 275 | static int video_get_cur_state(struct thermal_cooling_device *cooling_dev, unsigned |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 276 | long *state) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 277 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 278 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 279 | struct acpi_video_device *video = acpi_driver_data(device); |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 280 | unsigned long long level; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 281 | int offset; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 282 | |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 283 | if (acpi_video_device_lcd_get_level_current(video, &level, false)) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 284 | return -EINVAL; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 285 | for (offset = 2; offset < video->brightness->count; offset++) |
| 286 | if (level == video->brightness->levels[offset]) { |
| 287 | *state = video->brightness->count - offset - 1; |
| 288 | return 0; |
| 289 | } |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 290 | |
| 291 | return -EINVAL; |
| 292 | } |
| 293 | |
| 294 | static int |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 295 | video_set_cur_state(struct thermal_cooling_device *cooling_dev, unsigned long state) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 296 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 297 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 298 | struct acpi_video_device *video = acpi_driver_data(device); |
| 299 | int level; |
| 300 | |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 301 | if (state >= video->brightness->count - 2) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 302 | return -EINVAL; |
| 303 | |
| 304 | state = video->brightness->count - state; |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 305 | level = video->brightness->levels[state - 1]; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 306 | return acpi_video_device_lcd_set_level(video, level); |
| 307 | } |
| 308 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 309 | static const struct thermal_cooling_device_ops video_cooling_ops = { |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 310 | .get_max_state = video_get_max_state, |
| 311 | .get_cur_state = video_get_cur_state, |
| 312 | .set_cur_state = video_set_cur_state, |
| 313 | }; |
| 314 | |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 315 | /* |
| 316 | * -------------------------------------------------------------------------- |
| 317 | * Video Management |
| 318 | * -------------------------------------------------------------------------- |
| 319 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | acpi_video_device_lcd_query_levels(struct acpi_video_device *device, |
| 323 | union acpi_object **levels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | int status; |
| 326 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 327 | union acpi_object *obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | *levels = NULL; |
| 331 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 332 | status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (!ACPI_SUCCESS(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 334 | return status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | obj = (union acpi_object *)buffer.pointer; |
Adrian Bunk | 6665bda | 2006-03-11 10:12:00 -0500 | [diff] [blame] | 336 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 337 | printk(KERN_ERR PREFIX "Invalid _BCL data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | status = -EFAULT; |
| 339 | goto err; |
| 340 | } |
| 341 | |
| 342 | *levels = obj; |
| 343 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 344 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 346 | err: |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 347 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 349 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 355 | int status; |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 356 | int state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 358 | status = acpi_execute_simple_method(device->dev->handle, |
| 359 | "_BCM", level); |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 360 | if (ACPI_FAILURE(status)) { |
| 361 | ACPI_ERROR((AE_INFO, "Evaluating _BCM failed")); |
| 362 | return -EIO; |
| 363 | } |
| 364 | |
Alexey Starikovskiy | 4500ca8 | 2007-09-03 16:29:58 +0400 | [diff] [blame] | 365 | device->brightness->curr = level; |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 366 | for (state = 2; state < device->brightness->count; state++) |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 367 | if (level == device->brightness->levels[state]) { |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 368 | if (device->backlight) |
| 369 | device->backlight->props.brightness = state - 2; |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 370 | return 0; |
| 371 | } |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 372 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 373 | ACPI_ERROR((AE_INFO, "Current brightness invalid")); |
| 374 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 377 | /* |
| 378 | * For some buggy _BQC methods, we need to add a constant value to |
| 379 | * the _BQC return value to get the actual current brightness level |
| 380 | */ |
| 381 | |
| 382 | static int bqc_offset_aml_bug_workaround; |
Hans de Goede | 7ee33ba | 2015-06-16 16:27:53 +0200 | [diff] [blame] | 383 | static int video_set_bqc_offset(const struct dmi_system_id *d) |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 384 | { |
| 385 | bqc_offset_aml_bug_workaround = 9; |
| 386 | return 0; |
| 387 | } |
| 388 | |
Hans de Goede | 7ee33ba | 2015-06-16 16:27:53 +0200 | [diff] [blame] | 389 | static int video_disable_backlight_sysfs_if( |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 390 | const struct dmi_system_id *d) |
| 391 | { |
| 392 | if (disable_backlight_sysfs_if == -1) |
| 393 | disable_backlight_sysfs_if = 1; |
| 394 | return 0; |
| 395 | } |
| 396 | |
Hans de Goede | 7ee33ba | 2015-06-16 16:27:53 +0200 | [diff] [blame] | 397 | static struct dmi_system_id video_dmi_table[] = { |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 398 | /* |
| 399 | * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121 |
| 400 | */ |
| 401 | { |
| 402 | .callback = video_set_bqc_offset, |
| 403 | .ident = "Acer Aspire 5720", |
| 404 | .matches = { |
| 405 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 406 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"), |
| 407 | }, |
| 408 | }, |
Len Brown | 5afc4ab | 2009-05-07 21:11:56 -0400 | [diff] [blame] | 409 | { |
| 410 | .callback = video_set_bqc_offset, |
| 411 | .ident = "Acer Aspire 5710Z", |
| 412 | .matches = { |
| 413 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 414 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"), |
| 415 | }, |
| 416 | }, |
Zhang Rui | 34ac272 | 2009-05-26 23:35:34 -0400 | [diff] [blame] | 417 | { |
| 418 | .callback = video_set_bqc_offset, |
| 419 | .ident = "eMachines E510", |
| 420 | .matches = { |
| 421 | DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"), |
| 422 | DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"), |
| 423 | }, |
| 424 | }, |
Zhang Rui | 93bcece | 2009-05-19 15:08:41 -0400 | [diff] [blame] | 425 | { |
| 426 | .callback = video_set_bqc_offset, |
| 427 | .ident = "Acer Aspire 5315", |
| 428 | .matches = { |
| 429 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 430 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"), |
| 431 | }, |
| 432 | }, |
Zhang Rui | 152a4e6 | 2009-06-22 11:31:18 +0800 | [diff] [blame] | 433 | { |
| 434 | .callback = video_set_bqc_offset, |
| 435 | .ident = "Acer Aspire 7720", |
| 436 | .matches = { |
| 437 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 438 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"), |
| 439 | }, |
| 440 | }, |
Hans de Goede | 5f24079 | 2014-08-28 10:20:46 +0200 | [diff] [blame] | 441 | |
| 442 | /* |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 443 | * Some machines have a broken acpi-video interface for brightness |
| 444 | * control, but still need an acpi_video_device_lcd_set_level() call |
| 445 | * on resume to turn the backlight power on. We Enable backlight |
| 446 | * control on these systems, but do not register a backlight sysfs |
| 447 | * as brightness control does not work. |
| 448 | */ |
| 449 | { |
| 450 | /* https://bugs.freedesktop.org/show_bug.cgi?id=82634 */ |
| 451 | .callback = video_disable_backlight_sysfs_if, |
| 452 | .ident = "Toshiba Portege R830", |
| 453 | .matches = { |
| 454 | DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), |
| 455 | DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R830"), |
| 456 | }, |
| 457 | }, |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 458 | {} |
| 459 | }; |
| 460 | |
Danny Baumann | 994fa63 | 2013-03-19 16:22:52 +0000 | [diff] [blame] | 461 | static unsigned long long |
| 462 | acpi_video_bqc_value_to_level(struct acpi_video_device *device, |
| 463 | unsigned long long bqc_value) |
| 464 | { |
| 465 | unsigned long long level; |
| 466 | |
| 467 | if (device->brightness->flags._BQC_use_index) { |
| 468 | /* |
| 469 | * _BQC returns an index that doesn't account for |
| 470 | * the first 2 items with special meaning, so we need |
| 471 | * to compensate for that by offsetting ourselves |
| 472 | */ |
| 473 | if (device->brightness->flags._BCL_reversed) |
| 474 | bqc_value = device->brightness->count - 3 - bqc_value; |
| 475 | |
| 476 | level = device->brightness->levels[bqc_value + 2]; |
| 477 | } else { |
| 478 | level = bqc_value; |
| 479 | } |
| 480 | |
| 481 | level += bqc_offset_aml_bug_workaround; |
| 482 | |
| 483 | return level; |
| 484 | } |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 488 | unsigned long long *level, bool raw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 490 | acpi_status status = AE_OK; |
Vladimir Serbinenko | 4e231fa | 2009-06-24 15:17:36 +0800 | [diff] [blame] | 491 | int i; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 492 | |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 493 | if (device->cap._BQC || device->cap._BCQ) { |
| 494 | char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; |
| 495 | |
| 496 | status = acpi_evaluate_integer(device->dev->handle, buf, |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 497 | NULL, level); |
| 498 | if (ACPI_SUCCESS(status)) { |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 499 | if (raw) { |
| 500 | /* |
| 501 | * Caller has indicated he wants the raw |
| 502 | * value returned by _BQC, so don't furtherly |
| 503 | * mess with the value. |
| 504 | */ |
| 505 | return 0; |
| 506 | } |
| 507 | |
Danny Baumann | 994fa63 | 2013-03-19 16:22:52 +0000 | [diff] [blame] | 508 | *level = acpi_video_bqc_value_to_level(device, *level); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 509 | |
Vladimir Serbinenko | 4e231fa | 2009-06-24 15:17:36 +0800 | [diff] [blame] | 510 | for (i = 2; i < device->brightness->count; i++) |
| 511 | if (device->brightness->levels[i] == *level) { |
| 512 | device->brightness->curr = *level; |
| 513 | return 0; |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 514 | } |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 515 | /* |
| 516 | * BQC returned an invalid level. |
| 517 | * Stop using it. |
| 518 | */ |
| 519 | ACPI_WARNING((AE_INFO, |
| 520 | "%s returned an invalid level", |
| 521 | buf)); |
| 522 | device->cap._BQC = device->cap._BCQ = 0; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 523 | } else { |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 524 | /* |
| 525 | * Fixme: |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 526 | * should we return an error or ignore this failure? |
| 527 | * dev->brightness->curr is a cached value which stores |
| 528 | * the correct current backlight level in most cases. |
| 529 | * ACPI video backlight still works w/ buggy _BQC. |
| 530 | * http://bugzilla.kernel.org/show_bug.cgi?id=12233 |
| 531 | */ |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 532 | ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf)); |
| 533 | device->cap._BQC = device->cap._BCQ = 0; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
Alexey Starikovskiy | 4500ca8 | 2007-09-03 16:29:58 +0400 | [diff] [blame] | 537 | *level = device->brightness->curr; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 538 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | acpi_video_device_EDID(struct acpi_video_device *device, |
| 543 | union acpi_object **edid, ssize_t length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 545 | int status; |
| 546 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 547 | union acpi_object *obj; |
| 548 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 549 | struct acpi_object_list args = { 1, &arg0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | *edid = NULL; |
| 553 | |
| 554 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 555 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | if (length == 128) |
| 557 | arg0.integer.value = 1; |
| 558 | else if (length == 256) |
| 559 | arg0.integer.value = 2; |
| 560 | else |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 561 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 563 | status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 565 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 567 | obj = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | if (obj && obj->type == ACPI_TYPE_BUFFER) |
| 570 | *edid = obj; |
| 571 | else { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 572 | printk(KERN_ERR PREFIX "Invalid _DDC data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | status = -EFAULT; |
| 574 | kfree(obj); |
| 575 | } |
| 576 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 577 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | /* bus */ |
| 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * Arg: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 584 | * video : video bus device pointer |
| 585 | * bios_flag : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | * 0. The system BIOS should NOT automatically switch(toggle) |
| 587 | * the active display output. |
| 588 | * 1. The system BIOS should automatically switch (toggle) the |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 589 | * active display output. No switch event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | * 2. The _DGS value should be locked. |
| 591 | * 3. The system BIOS should not automatically switch (toggle) the |
| 592 | * active display output, but instead generate the display switch |
| 593 | * event notify code. |
| 594 | * lcd_flag : |
| 595 | * 0. The system BIOS should automatically control the brightness level |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 596 | * of the LCD when the power changes from AC to DC |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 597 | * 1. The system BIOS should NOT automatically control the brightness |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 598 | * level of the LCD when the power changes from AC to DC. |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 599 | * Return Value: |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 600 | * -EINVAL wrong arg. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | */ |
| 602 | |
| 603 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 604 | acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 606 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Zhang Rui | b037384 | 2012-06-20 09:48:43 +0800 | [diff] [blame] | 608 | if (!video->cap._DOS) |
| 609 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 611 | if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) |
| 612 | return -EINVAL; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 613 | video->dos_setting = (lcd_flag << 2) | bios_flag; |
| 614 | status = acpi_execute_simple_method(video->device->handle, "_DOS", |
| 615 | (lcd_flag << 2) | bios_flag); |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 616 | if (ACPI_FAILURE(status)) |
| 617 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 619 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /* |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 623 | * Simple comparison function used to sort backlight levels. |
| 624 | */ |
| 625 | |
| 626 | static int |
| 627 | acpi_video_cmp_level(const void *a, const void *b) |
| 628 | { |
| 629 | return *(int *)a - *(int *)b; |
| 630 | } |
| 631 | |
| 632 | /* |
Aaron Lu | a50188d | 2013-04-22 14:08:32 +0200 | [diff] [blame] | 633 | * Decides if _BQC/_BCQ for this system is usable |
| 634 | * |
| 635 | * We do this by changing the level first and then read out the current |
| 636 | * brightness level, if the value does not match, find out if it is using |
| 637 | * index. If not, clear the _BQC/_BCQ capability. |
| 638 | */ |
| 639 | static int acpi_video_bqc_quirk(struct acpi_video_device *device, |
| 640 | int max_level, int current_level) |
| 641 | { |
| 642 | struct acpi_video_device_brightness *br = device->brightness; |
| 643 | int result; |
| 644 | unsigned long long level; |
| 645 | int test_level; |
| 646 | |
| 647 | /* don't mess with existing known broken systems */ |
| 648 | if (bqc_offset_aml_bug_workaround) |
| 649 | return 0; |
| 650 | |
| 651 | /* |
| 652 | * Some systems always report current brightness level as maximum |
| 653 | * through _BQC, we need to test another value for them. |
| 654 | */ |
Felipe Contreras | b3b301c | 2013-08-03 23:00:25 +0200 | [diff] [blame] | 655 | test_level = current_level == max_level ? br->levels[3] : max_level; |
Aaron Lu | a50188d | 2013-04-22 14:08:32 +0200 | [diff] [blame] | 656 | |
| 657 | result = acpi_video_device_lcd_set_level(device, test_level); |
| 658 | if (result) |
| 659 | return result; |
| 660 | |
| 661 | result = acpi_video_device_lcd_get_level_current(device, &level, true); |
| 662 | if (result) |
| 663 | return result; |
| 664 | |
| 665 | if (level != test_level) { |
| 666 | /* buggy _BQC found, need to find out if it uses index */ |
| 667 | if (level < br->count) { |
| 668 | if (br->flags._BCL_reversed) |
| 669 | level = br->count - 3 - level; |
| 670 | if (br->levels[level + 2] == test_level) |
| 671 | br->flags._BQC_use_index = 1; |
| 672 | } |
| 673 | |
| 674 | if (!br->flags._BQC_use_index) |
| 675 | device->cap._BQC = device->cap._BCQ = 0; |
| 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | |
| 682 | /* |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 683 | * Arg: |
| 684 | * device : video output device (LCD, CRT, ..) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | * |
| 686 | * Return Value: |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 687 | * Maximum brightness level |
| 688 | * |
| 689 | * Allocate and initialize device->brightness. |
| 690 | */ |
| 691 | |
| 692 | static int |
| 693 | acpi_video_init_brightness(struct acpi_video_device *device) |
| 694 | { |
| 695 | union acpi_object *obj = NULL; |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 696 | int i, max_level = 0, count = 0, level_ac_battery = 0; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 697 | unsigned long long level, level_old; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 698 | union acpi_object *o; |
| 699 | struct acpi_video_device_brightness *br = NULL; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 700 | int result = -EINVAL; |
Hans de Goede | bd8ba20 | 2014-02-13 16:32:51 +0100 | [diff] [blame] | 701 | u32 value; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 702 | |
| 703 | if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { |
| 704 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " |
| 705 | "LCD brightness level\n")); |
| 706 | goto out; |
| 707 | } |
| 708 | |
| 709 | if (obj->package.count < 2) |
| 710 | goto out; |
| 711 | |
| 712 | br = kzalloc(sizeof(*br), GFP_KERNEL); |
| 713 | if (!br) { |
| 714 | printk(KERN_ERR "can't allocate memory\n"); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 715 | result = -ENOMEM; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 716 | goto out; |
| 717 | } |
| 718 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 719 | br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels), |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 720 | GFP_KERNEL); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 721 | if (!br->levels) { |
| 722 | result = -ENOMEM; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 723 | goto out_free; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 724 | } |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 725 | |
| 726 | for (i = 0; i < obj->package.count; i++) { |
| 727 | o = (union acpi_object *)&obj->package.elements[i]; |
| 728 | if (o->type != ACPI_TYPE_INTEGER) { |
| 729 | printk(KERN_ERR PREFIX "Invalid data\n"); |
| 730 | continue; |
| 731 | } |
Hans de Goede | bd8ba20 | 2014-02-13 16:32:51 +0100 | [diff] [blame] | 732 | value = (u32) o->integer.value; |
| 733 | /* Skip duplicate entries */ |
| 734 | if (count > 2 && br->levels[count - 1] == value) |
| 735 | continue; |
| 736 | |
| 737 | br->levels[count] = value; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 738 | |
| 739 | if (br->levels[count] > max_level) |
| 740 | max_level = br->levels[count]; |
| 741 | count++; |
| 742 | } |
| 743 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 744 | /* |
| 745 | * some buggy BIOS don't export the levels |
| 746 | * when machine is on AC/Battery in _BCL package. |
| 747 | * In this case, the first two elements in _BCL packages |
| 748 | * are also supported brightness levels that OS should take care of. |
| 749 | */ |
Zhang Rui | 90af2cf | 2009-04-14 11:02:18 +0800 | [diff] [blame] | 750 | for (i = 2; i < count; i++) { |
| 751 | if (br->levels[i] == br->levels[0]) |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 752 | level_ac_battery++; |
Zhang Rui | 90af2cf | 2009-04-14 11:02:18 +0800 | [diff] [blame] | 753 | if (br->levels[i] == br->levels[1]) |
| 754 | level_ac_battery++; |
| 755 | } |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 756 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 757 | if (level_ac_battery < 2) { |
| 758 | level_ac_battery = 2 - level_ac_battery; |
| 759 | br->flags._BCL_no_ac_battery_levels = 1; |
| 760 | for (i = (count - 1 + level_ac_battery); i >= 2; i--) |
| 761 | br->levels[i] = br->levels[i - level_ac_battery]; |
| 762 | count += level_ac_battery; |
| 763 | } else if (level_ac_battery > 2) |
Colin Ian King | bf6787e | 2012-11-29 11:53:13 +0000 | [diff] [blame] | 764 | ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package")); |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 765 | |
Zhang Rui | d80fb99 | 2009-03-18 16:27:14 +0800 | [diff] [blame] | 766 | /* Check if the _BCL package is in a reversed order */ |
| 767 | if (max_level == br->levels[2]) { |
| 768 | br->flags._BCL_reversed = 1; |
| 769 | sort(&br->levels[2], count - 2, sizeof(br->levels[2]), |
| 770 | acpi_video_cmp_level, NULL); |
| 771 | } else if (max_level != br->levels[count - 1]) |
| 772 | ACPI_ERROR((AE_INFO, |
Colin Ian King | bf6787e | 2012-11-29 11:53:13 +0000 | [diff] [blame] | 773 | "Found unordered _BCL package")); |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 774 | |
| 775 | br->count = count; |
| 776 | device->brightness = br; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 777 | |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 778 | /* _BQC uses INDEX while _BCL uses VALUE in some laptops */ |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 779 | br->curr = level = max_level; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 780 | |
| 781 | if (!device->cap._BQC) |
| 782 | goto set_level; |
| 783 | |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 784 | result = acpi_video_device_lcd_get_level_current(device, |
| 785 | &level_old, true); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 786 | if (result) |
| 787 | goto out_free_levels; |
| 788 | |
Aaron Lu | a50188d | 2013-04-22 14:08:32 +0200 | [diff] [blame] | 789 | result = acpi_video_bqc_quirk(device, max_level, level_old); |
| 790 | if (result) |
| 791 | goto out_free_levels; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 792 | /* |
Aaron Lu | a50188d | 2013-04-22 14:08:32 +0200 | [diff] [blame] | 793 | * cap._BQC may get cleared due to _BQC is found to be broken |
| 794 | * in acpi_video_bqc_quirk, so check again here. |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 795 | */ |
Aaron Lu | a50188d | 2013-04-22 14:08:32 +0200 | [diff] [blame] | 796 | if (!device->cap._BQC) |
| 797 | goto set_level; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 798 | |
Aaron Lu | 545ef36 | 2013-11-15 14:39:12 +0800 | [diff] [blame] | 799 | level = acpi_video_bqc_value_to_level(device, level_old); |
| 800 | /* |
| 801 | * On some buggy laptops, _BQC returns an uninitialized |
| 802 | * value when invoked for the first time, i.e. |
| 803 | * level_old is invalid (no matter whether it's a level |
| 804 | * or an index). Set the backlight to max_level in this case. |
| 805 | */ |
| 806 | for (i = 2; i < br->count; i++) |
| 807 | if (level == br->levels[i]) |
| 808 | break; |
| 809 | if (i == br->count || !level) |
| 810 | level = max_level; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 811 | |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 812 | set_level: |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 813 | result = acpi_video_device_lcd_set_level(device, level); |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 814 | if (result) |
| 815 | goto out_free_levels; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 816 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 817 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 818 | "found %d brightness levels\n", count - 2)); |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 819 | kfree(obj); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 820 | return result; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 821 | |
| 822 | out_free_levels: |
| 823 | kfree(br->levels); |
| 824 | out_free: |
| 825 | kfree(br); |
| 826 | out: |
| 827 | device->brightness = NULL; |
| 828 | kfree(obj); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 829 | return result; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* |
| 833 | * Arg: |
| 834 | * device : video output device (LCD, CRT, ..) |
| 835 | * |
| 836 | * Return Value: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 837 | * None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | * |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 839 | * Find out all required AML methods defined under the output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | * device. |
| 841 | */ |
| 842 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | static void acpi_video_device_find_cap(struct acpi_video_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | { |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 845 | if (acpi_has_method(device->dev->handle, "_ADR")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | device->cap._ADR = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 847 | if (acpi_has_method(device->dev->handle, "_BCL")) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 848 | device->cap._BCL = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 849 | if (acpi_has_method(device->dev->handle, "_BCM")) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 850 | device->cap._BCM = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 851 | if (acpi_has_method(device->dev->handle, "_BQC")) { |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 852 | device->cap._BQC = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 853 | } else if (acpi_has_method(device->dev->handle, "_BCQ")) { |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 854 | printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n"); |
| 855 | device->cap._BCQ = 1; |
| 856 | } |
| 857 | |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 858 | if (acpi_has_method(device->dev->handle, "_DDC")) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 859 | device->cap._DDC = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /* |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 863 | * Arg: |
| 864 | * device : video output device (VGA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | * |
| 866 | * Return Value: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 867 | * None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | * |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 869 | * Find out all required AML methods defined under the video bus device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | */ |
| 871 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 872 | static void acpi_video_bus_find_cap(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 874 | if (acpi_has_method(video->device->handle, "_DOS")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | video->cap._DOS = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 876 | if (acpi_has_method(video->device->handle, "_DOD")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | video->cap._DOD = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 878 | if (acpi_has_method(video->device->handle, "_ROM")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | video->cap._ROM = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 880 | if (acpi_has_method(video->device->handle, "_GPD")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | video->cap._GPD = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 882 | if (acpi_has_method(video->device->handle, "_SPD")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | video->cap._SPD = 1; |
Jiang Liu | 952c63e | 2013-06-29 00:24:38 +0800 | [diff] [blame] | 884 | if (acpi_has_method(video->device->handle, "_VPO")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | video->cap._VPO = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | /* |
| 889 | * Check whether the video bus device has required AML method to |
| 890 | * support the desired features |
| 891 | */ |
| 892 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 893 | static int acpi_video_bus_check(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | acpi_status status = -ENOENT; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 896 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | if (!video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 899 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 901 | dev = acpi_get_pci_dev(video->device->handle); |
Thomas Renninger | 22c13f9 | 2008-08-01 17:37:54 +0200 | [diff] [blame] | 902 | if (!dev) |
| 903 | return -ENODEV; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 904 | pci_dev_put(dev); |
Thomas Renninger | 22c13f9 | 2008-08-01 17:37:54 +0200 | [diff] [blame] | 905 | |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 906 | /* |
| 907 | * Since there is no HID, CID and so on for VGA driver, we have |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | * to check well known required nodes. |
| 909 | */ |
| 910 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 911 | /* Does this device support video switching? */ |
Stefan Bader | 3a1151e | 2009-08-21 11:03:05 +0200 | [diff] [blame] | 912 | if (video->cap._DOS || video->cap._DOD) { |
| 913 | if (!video->cap._DOS) { |
| 914 | printk(KERN_WARNING FW_BUG |
| 915 | "ACPI(%s) defines _DOD but not _DOS\n", |
| 916 | acpi_device_bid(video->device)); |
| 917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | video->flags.multihead = 1; |
| 919 | status = 0; |
| 920 | } |
| 921 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 922 | /* Does this device support retrieving a video ROM? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | if (video->cap._ROM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | video->flags.rom = 1; |
| 925 | status = 0; |
| 926 | } |
| 927 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 928 | /* Does this device support configuring which video device to POST? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 929 | if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | video->flags.post = 1; |
| 931 | status = 0; |
| 932 | } |
| 933 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 934 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 937 | /* |
| 938 | * -------------------------------------------------------------------------- |
| 939 | * Driver Interface |
| 940 | * -------------------------------------------------------------------------- |
| 941 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
| 943 | /* device interface */ |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 944 | static struct acpi_video_device_attrib * |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 945 | acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id) |
| 946 | { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 947 | struct acpi_video_enumerated_device *ids; |
| 948 | int i; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 949 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 950 | for (i = 0; i < video->attached_count; i++) { |
| 951 | ids = &video->attached_array[i]; |
| 952 | if ((ids->value.int_val & 0xffff) == device_id) |
| 953 | return &ids->value.attrib; |
| 954 | } |
| 955 | |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 956 | return NULL; |
| 957 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | static int |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 960 | acpi_video_get_device_type(struct acpi_video_bus *video, |
| 961 | unsigned long device_id) |
| 962 | { |
| 963 | struct acpi_video_enumerated_device *ids; |
| 964 | int i; |
| 965 | |
| 966 | for (i = 0; i < video->attached_count; i++) { |
| 967 | ids = &video->attached_array[i]; |
| 968 | if ((ids->value.int_val & 0xffff) == device_id) |
| 969 | return ids->value.int_val; |
| 970 | } |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 976 | acpi_video_bus_get_one_device(struct acpi_device *device, |
| 977 | struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 979 | unsigned long long device_id; |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 980 | int status, device_type; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 981 | struct acpi_video_device *data; |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 982 | struct acpi_video_device_attrib *attribute; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 984 | status = |
| 985 | acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 986 | /* Some device omits _ADR, we skip them instead of fail */ |
| 987 | if (ACPI_FAILURE(status)) |
| 988 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 990 | data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL); |
| 991 | if (!data) |
| 992 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 994 | strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); |
| 995 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); |
| 996 | device->driver_data = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 998 | data->device_id = device_id; |
| 999 | data->video = video; |
| 1000 | data->dev = device; |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1001 | INIT_DELAYED_WORK(&data->switch_brightness_work, |
| 1002 | acpi_video_switch_brightness); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1004 | attribute = acpi_video_get_device_attr(video, device_id); |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1005 | |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 1006 | if (attribute && attribute->device_id_scheme) { |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1007 | switch (attribute->display_type) { |
| 1008 | case ACPI_VIDEO_DISPLAY_CRT: |
| 1009 | data->flags.crt = 1; |
| 1010 | break; |
| 1011 | case ACPI_VIDEO_DISPLAY_TV: |
| 1012 | data->flags.tvout = 1; |
| 1013 | break; |
| 1014 | case ACPI_VIDEO_DISPLAY_DVI: |
| 1015 | data->flags.dvi = 1; |
| 1016 | break; |
| 1017 | case ACPI_VIDEO_DISPLAY_LCD: |
| 1018 | data->flags.lcd = 1; |
| 1019 | break; |
| 1020 | default: |
| 1021 | data->flags.unknown = 1; |
| 1022 | break; |
| 1023 | } |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 1024 | if (attribute->bios_can_detect) |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1025 | data->flags.bios = 1; |
| 1026 | } else { |
| 1027 | /* Check for legacy IDs */ |
| 1028 | device_type = acpi_video_get_device_type(video, device_id); |
| 1029 | /* Ignore bits 16 and 18-20 */ |
| 1030 | switch (device_type & 0xffe2ffff) { |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 1031 | case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR: |
| 1032 | data->flags.crt = 1; |
| 1033 | break; |
| 1034 | case ACPI_VIDEO_DISPLAY_LEGACY_PANEL: |
| 1035 | data->flags.lcd = 1; |
| 1036 | break; |
| 1037 | case ACPI_VIDEO_DISPLAY_LEGACY_TV: |
| 1038 | data->flags.tvout = 1; |
| 1039 | break; |
| 1040 | default: |
| 1041 | data->flags.unknown = 1; |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1042 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1045 | acpi_video_device_bind(video, data); |
| 1046 | acpi_video_device_find_cap(data); |
| 1047 | |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1048 | mutex_lock(&video->device_list_lock); |
| 1049 | list_add_tail(&data->entry, &video->video_device_list); |
| 1050 | mutex_unlock(&video->device_list_lock); |
| 1051 | |
| 1052 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /* |
| 1056 | * Arg: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1057 | * video : video bus device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | * |
| 1059 | * Return: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1060 | * none |
| 1061 | * |
| 1062 | * Enumerate the video device list of the video bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | * bind the ids with the corresponding video devices |
| 1064 | * under the video bus. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1065 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1067 | static void acpi_video_device_rebind(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | { |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1069 | struct acpi_video_device *dev; |
| 1070 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1071 | mutex_lock(&video->device_list_lock); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1072 | |
| 1073 | list_for_each_entry(dev, &video->video_device_list, entry) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1074 | acpi_video_device_bind(video, dev); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1075 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1076 | mutex_unlock(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /* |
| 1080 | * Arg: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1081 | * video : video bus device |
| 1082 | * device : video output device under the video |
| 1083 | * bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | * |
| 1085 | * Return: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1086 | * none |
| 1087 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | * Bind the ids with the corresponding video devices |
| 1089 | * under the video bus. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1090 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1093 | acpi_video_device_bind(struct acpi_video_bus *video, |
| 1094 | struct acpi_video_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1096 | struct acpi_video_enumerated_device *ids; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1097 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1099 | for (i = 0; i < video->attached_count; i++) { |
| 1100 | ids = &video->attached_array[i]; |
| 1101 | if (device->device_id == (ids->value.int_val & 0xffff)) { |
| 1102 | ids->bind_info = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i)); |
| 1104 | } |
| 1105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Aaron Lu | 0b8db27 | 2014-09-30 14:10:17 +0800 | [diff] [blame] | 1108 | static bool acpi_video_device_in_dod(struct acpi_video_device *device) |
| 1109 | { |
| 1110 | struct acpi_video_bus *video = device->video; |
| 1111 | int i; |
| 1112 | |
Aaron Lu | b4df463 | 2014-12-15 16:01:29 +0800 | [diff] [blame] | 1113 | /* |
| 1114 | * If we have a broken _DOD or we have more than 8 output devices |
| 1115 | * under the graphics controller node that we can't proper deal with |
| 1116 | * in the operation region code currently, no need to test. |
| 1117 | */ |
| 1118 | if (!video->attached_count || video->child_count > 8) |
Aaron Lu | 0b8db27 | 2014-09-30 14:10:17 +0800 | [diff] [blame] | 1119 | return true; |
| 1120 | |
| 1121 | for (i = 0; i < video->attached_count; i++) { |
Aaron Lu | 35d0565 | 2014-12-01 02:09:18 +0100 | [diff] [blame] | 1122 | if ((video->attached_array[i].value.int_val & 0xfff) == |
| 1123 | (device->device_id & 0xfff)) |
Aaron Lu | 0b8db27 | 2014-09-30 14:10:17 +0800 | [diff] [blame] | 1124 | return true; |
| 1125 | } |
| 1126 | |
| 1127 | return false; |
| 1128 | } |
| 1129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | /* |
| 1131 | * Arg: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1132 | * video : video bus device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | * |
| 1134 | * Return: |
Felipe Contreras | 21fcb34 | 2013-08-01 18:43:59 -0500 | [diff] [blame] | 1135 | * < 0 : error |
| 1136 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | * Call _DOD to enumerate all devices attached to display adapter |
| 1138 | * |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1139 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | static int acpi_video_device_enumerate(struct acpi_video_bus *video) |
| 1142 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1143 | int status; |
| 1144 | int count; |
| 1145 | int i; |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1146 | struct acpi_video_enumerated_device *active_list; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1147 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1148 | union acpi_object *dod = NULL; |
| 1149 | union acpi_object *obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1151 | status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | if (!ACPI_SUCCESS(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1153 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1154 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1157 | dod = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1159 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | status = -EFAULT; |
| 1161 | goto out; |
| 1162 | } |
| 1163 | |
| 1164 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1165 | dod->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1167 | active_list = kcalloc(1 + dod->package.count, |
| 1168 | sizeof(struct acpi_video_enumerated_device), |
| 1169 | GFP_KERNEL); |
| 1170 | if (!active_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | status = -ENOMEM; |
| 1172 | goto out; |
| 1173 | } |
| 1174 | |
| 1175 | count = 0; |
| 1176 | for (i = 0; i < dod->package.count; i++) { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1177 | obj = &dod->package.elements[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (obj->type != ACPI_TYPE_INTEGER) { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1180 | printk(KERN_ERR PREFIX |
| 1181 | "Invalid _DOD data in element %d\n", i); |
| 1182 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1184 | |
| 1185 | active_list[count].value.int_val = obj->integer.value; |
| 1186 | active_list[count].bind_info = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1187 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i, |
| 1188 | (int)obj->integer.value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | count++; |
| 1190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 1192 | kfree(video->attached_array); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1193 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1194 | video->attached_array = active_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | video->attached_count = count; |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1196 | |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 1197 | out: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 1198 | kfree(buffer.pointer); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1199 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1202 | static int |
| 1203 | acpi_video_get_next_level(struct acpi_video_device *device, |
| 1204 | u32 level_current, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | { |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 1206 | int min, max, min_above, max_below, i, l, delta = 255; |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 1207 | max = max_below = 0; |
| 1208 | min = min_above = 255; |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 1209 | /* Find closest level to level_current */ |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 1210 | for (i = 2; i < device->brightness->count; i++) { |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 1211 | l = device->brightness->levels[i]; |
| 1212 | if (abs(l - level_current) < abs(delta)) { |
| 1213 | delta = l - level_current; |
| 1214 | if (!delta) |
| 1215 | break; |
| 1216 | } |
| 1217 | } |
| 1218 | /* Ajust level_current to closest available level */ |
| 1219 | level_current += delta; |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 1220 | for (i = 2; i < device->brightness->count; i++) { |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 1221 | l = device->brightness->levels[i]; |
| 1222 | if (l < min) |
| 1223 | min = l; |
| 1224 | if (l > max) |
| 1225 | max = l; |
| 1226 | if (l < min_above && l > level_current) |
| 1227 | min_above = l; |
| 1228 | if (l > max_below && l < level_current) |
| 1229 | max_below = l; |
| 1230 | } |
| 1231 | |
| 1232 | switch (event) { |
| 1233 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: |
| 1234 | return (level_current < max) ? min_above : min; |
| 1235 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: |
| 1236 | return (level_current < max) ? min_above : max; |
| 1237 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: |
| 1238 | return (level_current > min) ? max_below : min; |
| 1239 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: |
| 1240 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: |
| 1241 | return 0; |
| 1242 | default: |
| 1243 | return level_current; |
| 1244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1247 | static void |
| 1248 | acpi_video_switch_brightness(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | { |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1250 | struct acpi_video_device *device = container_of(to_delayed_work(work), |
| 1251 | struct acpi_video_device, switch_brightness_work); |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1252 | unsigned long long level_current, level_next; |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1253 | int event = device->switch_brightness_event; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1254 | int result = -EINVAL; |
| 1255 | |
Aaron Lu | fbc9fe1 | 2013-10-11 21:27:45 +0800 | [diff] [blame] | 1256 | /* no warning message if acpi_backlight=vendor or a quirk is used */ |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 1257 | if (!device->backlight) |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1258 | return; |
Zhang Rui | 28c32e9 | 2009-07-13 10:33:24 +0800 | [diff] [blame] | 1259 | |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 1260 | if (!device->brightness) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1261 | goto out; |
| 1262 | |
| 1263 | result = acpi_video_device_lcd_get_level_current(device, |
Danny Baumann | a89803d | 2013-03-19 16:22:50 +0000 | [diff] [blame] | 1264 | &level_current, |
| 1265 | false); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1266 | if (result) |
| 1267 | goto out; |
| 1268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | level_next = acpi_video_get_next_level(device, level_current, event); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1270 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 1271 | result = acpi_video_device_lcd_set_level(device, level_next); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1272 | |
Matthew Garrett | 3634274 | 2009-07-14 17:06:03 +0100 | [diff] [blame] | 1273 | if (!result) |
| 1274 | backlight_force_update(device->backlight, |
| 1275 | BACKLIGHT_UPDATE_HOTKEY); |
| 1276 | |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 1277 | out: |
| 1278 | if (result) |
| 1279 | printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1282 | int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, |
| 1283 | void **edid) |
| 1284 | { |
| 1285 | struct acpi_video_bus *video; |
| 1286 | struct acpi_video_device *video_device; |
| 1287 | union acpi_object *buffer = NULL; |
| 1288 | acpi_status status; |
| 1289 | int i, length; |
| 1290 | |
| 1291 | if (!device || !acpi_driver_data(device)) |
| 1292 | return -EINVAL; |
| 1293 | |
| 1294 | video = acpi_driver_data(device); |
| 1295 | |
| 1296 | for (i = 0; i < video->attached_count; i++) { |
| 1297 | video_device = video->attached_array[i].bind_info; |
| 1298 | length = 256; |
| 1299 | |
| 1300 | if (!video_device) |
| 1301 | continue; |
| 1302 | |
Zhang Rui | 8206955 | 2010-12-06 15:04:24 +0800 | [diff] [blame] | 1303 | if (!video_device->cap._DDC) |
| 1304 | continue; |
| 1305 | |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1306 | if (type) { |
| 1307 | switch (type) { |
| 1308 | case ACPI_VIDEO_DISPLAY_CRT: |
| 1309 | if (!video_device->flags.crt) |
| 1310 | continue; |
| 1311 | break; |
| 1312 | case ACPI_VIDEO_DISPLAY_TV: |
| 1313 | if (!video_device->flags.tvout) |
| 1314 | continue; |
| 1315 | break; |
| 1316 | case ACPI_VIDEO_DISPLAY_DVI: |
| 1317 | if (!video_device->flags.dvi) |
| 1318 | continue; |
| 1319 | break; |
| 1320 | case ACPI_VIDEO_DISPLAY_LCD: |
| 1321 | if (!video_device->flags.lcd) |
| 1322 | continue; |
| 1323 | break; |
| 1324 | } |
| 1325 | } else if (video_device->device_id != device_id) { |
| 1326 | continue; |
| 1327 | } |
| 1328 | |
| 1329 | status = acpi_video_device_EDID(video_device, &buffer, length); |
| 1330 | |
| 1331 | if (ACPI_FAILURE(status) || !buffer || |
| 1332 | buffer->type != ACPI_TYPE_BUFFER) { |
| 1333 | length = 128; |
| 1334 | status = acpi_video_device_EDID(video_device, &buffer, |
| 1335 | length); |
| 1336 | if (ACPI_FAILURE(status) || !buffer || |
| 1337 | buffer->type != ACPI_TYPE_BUFFER) { |
| 1338 | continue; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | *edid = buffer->buffer.pointer; |
| 1343 | return length; |
| 1344 | } |
| 1345 | |
| 1346 | return -ENODEV; |
| 1347 | } |
| 1348 | EXPORT_SYMBOL(acpi_video_get_edid); |
| 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1351 | acpi_video_bus_get_devices(struct acpi_video_bus *video, |
| 1352 | struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | { |
Igor Murzov | fba4e08 | 2012-10-13 04:41:25 +0400 | [diff] [blame] | 1354 | int status = 0; |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1355 | struct acpi_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
Igor Murzov | fba4e08 | 2012-10-13 04:41:25 +0400 | [diff] [blame] | 1357 | /* |
| 1358 | * There are systems where video module known to work fine regardless |
| 1359 | * of broken _DOD and ignoring returned value here doesn't cause |
| 1360 | * any issues later. |
| 1361 | */ |
| 1362 | acpi_video_device_enumerate(video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1364 | list_for_each_entry(dev, &device->children, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
| 1366 | status = acpi_video_bus_get_one_device(dev, video); |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 1367 | if (status) { |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1368 | dev_err(&dev->dev, "Can't attach device\n"); |
| 1369 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
Aaron Lu | b4df463 | 2014-12-15 16:01:29 +0800 | [diff] [blame] | 1371 | video->child_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1373 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | /* acpi_video interface */ |
| 1377 | |
Aaron Lu | efaa14c | 2013-07-16 13:08:05 +0800 | [diff] [blame] | 1378 | /* |
| 1379 | * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't |
| 1380 | * preform any automatic brightness change on receiving a notification. |
| 1381 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1382 | static int acpi_video_bus_start_devices(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | { |
Aaron Lu | efaa14c | 2013-07-16 13:08:05 +0800 | [diff] [blame] | 1384 | return acpi_video_bus_DOS(video, 0, |
Aaron Lu | fbc9fe1 | 2013-10-11 21:27:45 +0800 | [diff] [blame] | 1385 | acpi_osi_is_win8() ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1388 | static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | { |
Aaron Lu | efaa14c | 2013-07-16 13:08:05 +0800 | [diff] [blame] | 1390 | return acpi_video_bus_DOS(video, 0, |
Aaron Lu | fbc9fe1 | 2013-10-11 21:27:45 +0800 | [diff] [blame] | 1391 | acpi_osi_is_win8() ? 0 : 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 1394 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | { |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 1396 | struct acpi_video_bus *video = acpi_driver_data(device); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1397 | struct input_dev *input; |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 1398 | int keycode = 0; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1399 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1400 | if (!video || !video->input) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1401 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1403 | input = video->input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
| 1405 | switch (event) { |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1406 | case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | * most likely via hotkey. */ |
Luca Tettamanti | 8a37c65 | 2012-08-02 15:30:27 +0200 | [diff] [blame] | 1408 | keycode = KEY_SWITCHVIDEOMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | break; |
| 1410 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1411 | case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | * connector. */ |
| 1413 | acpi_video_device_enumerate(video); |
| 1414 | acpi_video_device_rebind(video); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1415 | keycode = KEY_SWITCHVIDEOMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1418 | case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */ |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1419 | keycode = KEY_SWITCHVIDEOMODE; |
| 1420 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1421 | case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */ |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1422 | keycode = KEY_VIDEO_NEXT; |
| 1423 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1424 | case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */ |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1425 | keycode = KEY_VIDEO_PREV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | break; |
| 1427 | |
| 1428 | default: |
| 1429 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1430 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | break; |
| 1432 | } |
| 1433 | |
Luca Tettamanti | 8a37c65 | 2012-08-02 15:30:27 +0200 | [diff] [blame] | 1434 | if (acpi_notifier_call_chain(device, event, 0)) |
| 1435 | /* Something vetoed the keypress. */ |
| 1436 | keycode = 0; |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 1437 | |
| 1438 | if (keycode) { |
| 1439 | input_report_key(input, keycode, 1); |
| 1440 | input_sync(input); |
| 1441 | input_report_key(input, keycode, 0); |
| 1442 | input_sync(input); |
| 1443 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1444 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1445 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1448 | static void brightness_switch_event(struct acpi_video_device *video_device, |
| 1449 | u32 event) |
| 1450 | { |
| 1451 | if (!brightness_switch_enabled) |
| 1452 | return; |
| 1453 | |
| 1454 | video_device->switch_brightness_event = event; |
| 1455 | schedule_delayed_work(&video_device->switch_brightness_work, HZ / 10); |
| 1456 | } |
| 1457 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1458 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1460 | struct acpi_video_device *video_device = data; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1461 | struct acpi_device *device = NULL; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1462 | struct acpi_video_bus *bus; |
| 1463 | struct input_dev *input; |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 1464 | int keycode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | if (!video_device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1467 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1469 | device = video_device->dev; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1470 | bus = video_device->video; |
| 1471 | input = bus->input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | switch (event) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1474 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1475 | brightness_switch_event(video_device, event); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1476 | keycode = KEY_BRIGHTNESS_CYCLE; |
| 1477 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1478 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1479 | brightness_switch_event(video_device, event); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1480 | keycode = KEY_BRIGHTNESSUP; |
| 1481 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1482 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1483 | brightness_switch_event(video_device, event); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1484 | keycode = KEY_BRIGHTNESSDOWN; |
| 1485 | break; |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 1486 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightness */ |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1487 | brightness_switch_event(video_device, event); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1488 | keycode = KEY_BRIGHTNESS_ZERO; |
| 1489 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1490 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ |
Linus Torvalds | 8ab58e8 | 2014-07-18 14:32:51 +0200 | [diff] [blame] | 1491 | brightness_switch_event(video_device, event); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1492 | keycode = KEY_DISPLAY_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | break; |
| 1494 | default: |
| 1495 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1496 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1499 | |
Zhang Rui | 7761f63 | 2008-01-25 14:48:12 +0800 | [diff] [blame] | 1500 | acpi_notifier_call_chain(device, event, 0); |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 1501 | |
| 1502 | if (keycode) { |
| 1503 | input_report_key(input, keycode, 1); |
| 1504 | input_sync(input); |
| 1505 | input_report_key(input, keycode, 0); |
| 1506 | input_sync(input); |
| 1507 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 1508 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1509 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1512 | static int acpi_video_resume(struct notifier_block *nb, |
| 1513 | unsigned long val, void *ign) |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 1514 | { |
| 1515 | struct acpi_video_bus *video; |
| 1516 | struct acpi_video_device *video_device; |
| 1517 | int i; |
| 1518 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1519 | switch (val) { |
| 1520 | case PM_HIBERNATION_PREPARE: |
| 1521 | case PM_SUSPEND_PREPARE: |
| 1522 | case PM_RESTORE_PREPARE: |
| 1523 | return NOTIFY_DONE; |
| 1524 | } |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 1525 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1526 | video = container_of(nb, struct acpi_video_bus, pm_nb); |
| 1527 | |
| 1528 | dev_info(&video->device->dev, "Restoring backlight state\n"); |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 1529 | |
| 1530 | for (i = 0; i < video->attached_count; i++) { |
| 1531 | video_device = video->attached_array[i].bind_info; |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 1532 | if (video_device && video_device->brightness) |
| 1533 | acpi_video_device_lcd_set_level(video_device, |
| 1534 | video_device->brightness->curr); |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 1535 | } |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1536 | |
| 1537 | return NOTIFY_OK; |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 1540 | static acpi_status |
| 1541 | acpi_video_bus_match(acpi_handle handle, u32 level, void *context, |
| 1542 | void **return_value) |
| 1543 | { |
| 1544 | struct acpi_device *device = context; |
| 1545 | struct acpi_device *sibling; |
| 1546 | int result; |
| 1547 | |
| 1548 | if (handle == device->handle) |
| 1549 | return AE_CTRL_TERMINATE; |
| 1550 | |
| 1551 | result = acpi_bus_get_device(handle, &sibling); |
| 1552 | if (result) |
| 1553 | return AE_OK; |
| 1554 | |
| 1555 | if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME)) |
| 1556 | return AE_ALREADY_EXISTS; |
| 1557 | |
| 1558 | return AE_OK; |
| 1559 | } |
| 1560 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1561 | static void acpi_video_dev_register_backlight(struct acpi_video_device *device) |
| 1562 | { |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1563 | struct backlight_properties props; |
| 1564 | struct pci_dev *pdev; |
| 1565 | acpi_handle acpi_parent; |
| 1566 | struct device *parent = NULL; |
| 1567 | int result; |
| 1568 | static int count; |
| 1569 | char *name; |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1570 | |
Aaron Lu | 0b8db27 | 2014-09-30 14:10:17 +0800 | [diff] [blame] | 1571 | /* |
| 1572 | * Do not create backlight device for video output |
| 1573 | * device that is not in the enumerated list. |
| 1574 | */ |
| 1575 | if (!acpi_video_device_in_dod(device)) { |
| 1576 | dev_dbg(&device->dev->dev, "not in _DOD list, ignore\n"); |
| 1577 | return; |
| 1578 | } |
| 1579 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1580 | result = acpi_video_init_brightness(device); |
| 1581 | if (result) |
| 1582 | return; |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 1583 | |
| 1584 | if (disable_backlight_sysfs_if > 0) |
| 1585 | return; |
| 1586 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1587 | name = kasprintf(GFP_KERNEL, "acpi_video%d", count); |
| 1588 | if (!name) |
| 1589 | return; |
| 1590 | count++; |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1591 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1592 | acpi_get_parent(device->dev->handle, &acpi_parent); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1593 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1594 | pdev = acpi_get_pci_dev(acpi_parent); |
| 1595 | if (pdev) { |
| 1596 | parent = &pdev->dev; |
| 1597 | pci_dev_put(pdev); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1598 | } |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1599 | |
| 1600 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 1601 | props.type = BACKLIGHT_FIRMWARE; |
| 1602 | props.max_brightness = device->brightness->count - 3; |
| 1603 | device->backlight = backlight_device_register(name, |
| 1604 | parent, |
| 1605 | device, |
| 1606 | &acpi_backlight_ops, |
| 1607 | &props); |
| 1608 | kfree(name); |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 1609 | if (IS_ERR(device->backlight)) { |
| 1610 | device->backlight = NULL; |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1611 | return; |
Hans de Goede | 654a182 | 2015-06-09 10:32:25 +0200 | [diff] [blame] | 1612 | } |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1613 | |
| 1614 | /* |
| 1615 | * Save current brightness level in case we have to restore it |
| 1616 | * before acpi_video_device_lcd_set_level() is called next time. |
| 1617 | */ |
| 1618 | device->backlight->props.brightness = |
| 1619 | acpi_video_get_brightness(device->backlight); |
| 1620 | |
| 1621 | device->cooling_dev = thermal_cooling_device_register("LCD", |
| 1622 | device->dev, &video_cooling_ops); |
| 1623 | if (IS_ERR(device->cooling_dev)) { |
| 1624 | /* |
| 1625 | * Set cooling_dev to NULL so we don't crash trying to free it. |
| 1626 | * Also, why the hell we are returning early and not attempt to |
| 1627 | * register video output if cooling device registration failed? |
| 1628 | * -- dtor |
| 1629 | */ |
| 1630 | device->cooling_dev = NULL; |
| 1631 | return; |
| 1632 | } |
| 1633 | |
| 1634 | dev_info(&device->dev->dev, "registered as cooling_device%d\n", |
| 1635 | device->cooling_dev->id); |
| 1636 | result = sysfs_create_link(&device->dev->dev.kobj, |
| 1637 | &device->cooling_dev->device.kobj, |
| 1638 | "thermal_cooling"); |
| 1639 | if (result) |
| 1640 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
| 1641 | result = sysfs_create_link(&device->cooling_dev->device.kobj, |
| 1642 | &device->dev->dev.kobj, "device"); |
| 1643 | if (result) |
| 1644 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Aaron Lu | dce4ec2 | 2014-10-28 14:35:59 +0800 | [diff] [blame] | 1647 | static void acpi_video_run_bcl_for_osi(struct acpi_video_bus *video) |
| 1648 | { |
| 1649 | struct acpi_video_device *dev; |
| 1650 | union acpi_object *levels; |
| 1651 | |
| 1652 | mutex_lock(&video->device_list_lock); |
| 1653 | list_for_each_entry(dev, &video->video_device_list, entry) { |
| 1654 | if (!acpi_video_device_lcd_query_levels(dev, &levels)) |
| 1655 | kfree(levels); |
| 1656 | } |
| 1657 | mutex_unlock(&video->device_list_lock); |
| 1658 | } |
| 1659 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1660 | static int acpi_video_bus_register_backlight(struct acpi_video_bus *video) |
| 1661 | { |
| 1662 | struct acpi_video_device *dev; |
| 1663 | |
Hans de Goede | 53a92ba | 2014-05-21 15:39:55 +0200 | [diff] [blame] | 1664 | if (video->backlight_registered) |
| 1665 | return 0; |
| 1666 | |
Aaron Lu | dce4ec2 | 2014-10-28 14:35:59 +0800 | [diff] [blame] | 1667 | acpi_video_run_bcl_for_osi(video); |
| 1668 | |
Hans de Goede | 3bd6bce | 2015-06-16 16:27:51 +0200 | [diff] [blame] | 1669 | if (acpi_video_get_backlight_type() != acpi_backlight_video) |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1670 | return 0; |
| 1671 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1672 | mutex_lock(&video->device_list_lock); |
| 1673 | list_for_each_entry(dev, &video->video_device_list, entry) |
| 1674 | acpi_video_dev_register_backlight(dev); |
| 1675 | mutex_unlock(&video->device_list_lock); |
| 1676 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1677 | video->backlight_registered = true; |
| 1678 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1679 | video->pm_nb.notifier_call = acpi_video_resume; |
| 1680 | video->pm_nb.priority = 0; |
| 1681 | return register_pm_notifier(&video->pm_nb); |
| 1682 | } |
| 1683 | |
| 1684 | static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device) |
| 1685 | { |
| 1686 | if (device->backlight) { |
| 1687 | backlight_device_unregister(device->backlight); |
| 1688 | device->backlight = NULL; |
| 1689 | } |
| 1690 | if (device->brightness) { |
| 1691 | kfree(device->brightness->levels); |
| 1692 | kfree(device->brightness); |
| 1693 | device->brightness = NULL; |
| 1694 | } |
| 1695 | if (device->cooling_dev) { |
| 1696 | sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling"); |
| 1697 | sysfs_remove_link(&device->cooling_dev->device.kobj, "device"); |
| 1698 | thermal_cooling_device_unregister(device->cooling_dev); |
| 1699 | device->cooling_dev = NULL; |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video) |
| 1704 | { |
| 1705 | struct acpi_video_device *dev; |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1706 | int error; |
| 1707 | |
| 1708 | if (!video->backlight_registered) |
| 1709 | return 0; |
| 1710 | |
| 1711 | error = unregister_pm_notifier(&video->pm_nb); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1712 | |
| 1713 | mutex_lock(&video->device_list_lock); |
| 1714 | list_for_each_entry(dev, &video->video_device_list, entry) |
| 1715 | acpi_video_dev_unregister_backlight(dev); |
| 1716 | mutex_unlock(&video->device_list_lock); |
| 1717 | |
Hans de Goede | 99678ed | 2014-05-15 13:22:33 +0200 | [diff] [blame] | 1718 | video->backlight_registered = false; |
| 1719 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1720 | return error; |
| 1721 | } |
| 1722 | |
| 1723 | static void acpi_video_dev_add_notify_handler(struct acpi_video_device *device) |
| 1724 | { |
| 1725 | acpi_status status; |
| 1726 | struct acpi_device *adev = device->dev; |
| 1727 | |
| 1728 | status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, |
| 1729 | acpi_video_device_notify, device); |
| 1730 | if (ACPI_FAILURE(status)) |
| 1731 | dev_err(&adev->dev, "Error installing notify handler\n"); |
| 1732 | else |
| 1733 | device->flags.notify = 1; |
| 1734 | } |
| 1735 | |
| 1736 | static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video) |
| 1737 | { |
| 1738 | struct input_dev *input; |
| 1739 | struct acpi_video_device *dev; |
| 1740 | int error; |
| 1741 | |
| 1742 | video->input = input = input_allocate_device(); |
| 1743 | if (!input) { |
| 1744 | error = -ENOMEM; |
| 1745 | goto out; |
| 1746 | } |
| 1747 | |
| 1748 | error = acpi_video_bus_start_devices(video); |
| 1749 | if (error) |
| 1750 | goto err_free_input; |
| 1751 | |
| 1752 | snprintf(video->phys, sizeof(video->phys), |
| 1753 | "%s/video/input0", acpi_device_hid(video->device)); |
| 1754 | |
| 1755 | input->name = acpi_device_name(video->device); |
| 1756 | input->phys = video->phys; |
| 1757 | input->id.bustype = BUS_HOST; |
| 1758 | input->id.product = 0x06; |
| 1759 | input->dev.parent = &video->device->dev; |
| 1760 | input->evbit[0] = BIT(EV_KEY); |
| 1761 | set_bit(KEY_SWITCHVIDEOMODE, input->keybit); |
| 1762 | set_bit(KEY_VIDEO_NEXT, input->keybit); |
| 1763 | set_bit(KEY_VIDEO_PREV, input->keybit); |
| 1764 | set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); |
| 1765 | set_bit(KEY_BRIGHTNESSUP, input->keybit); |
| 1766 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); |
| 1767 | set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); |
| 1768 | set_bit(KEY_DISPLAY_OFF, input->keybit); |
| 1769 | |
| 1770 | error = input_register_device(input); |
| 1771 | if (error) |
| 1772 | goto err_stop_dev; |
| 1773 | |
| 1774 | mutex_lock(&video->device_list_lock); |
| 1775 | list_for_each_entry(dev, &video->video_device_list, entry) |
| 1776 | acpi_video_dev_add_notify_handler(dev); |
| 1777 | mutex_unlock(&video->device_list_lock); |
| 1778 | |
| 1779 | return 0; |
| 1780 | |
| 1781 | err_stop_dev: |
| 1782 | acpi_video_bus_stop_devices(video); |
| 1783 | err_free_input: |
| 1784 | input_free_device(input); |
| 1785 | video->input = NULL; |
| 1786 | out: |
| 1787 | return error; |
| 1788 | } |
| 1789 | |
| 1790 | static void acpi_video_dev_remove_notify_handler(struct acpi_video_device *dev) |
| 1791 | { |
| 1792 | if (dev->flags.notify) { |
| 1793 | acpi_remove_notify_handler(dev->dev->handle, ACPI_DEVICE_NOTIFY, |
| 1794 | acpi_video_device_notify); |
| 1795 | dev->flags.notify = 0; |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video) |
| 1800 | { |
| 1801 | struct acpi_video_device *dev; |
| 1802 | |
| 1803 | mutex_lock(&video->device_list_lock); |
| 1804 | list_for_each_entry(dev, &video->video_device_list, entry) |
| 1805 | acpi_video_dev_remove_notify_handler(dev); |
| 1806 | mutex_unlock(&video->device_list_lock); |
| 1807 | |
| 1808 | acpi_video_bus_stop_devices(video); |
| 1809 | input_unregister_device(video->input); |
| 1810 | video->input = NULL; |
| 1811 | } |
| 1812 | |
| 1813 | static int acpi_video_bus_put_devices(struct acpi_video_bus *video) |
| 1814 | { |
| 1815 | struct acpi_video_device *dev, *next; |
| 1816 | |
| 1817 | mutex_lock(&video->device_list_lock); |
| 1818 | list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { |
| 1819 | list_del(&dev->entry); |
| 1820 | kfree(dev); |
| 1821 | } |
| 1822 | mutex_unlock(&video->device_list_lock); |
| 1823 | |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1827 | static int instance; |
| 1828 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1829 | static int acpi_video_bus_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | { |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1831 | struct acpi_video_bus *video; |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1832 | int error; |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 1833 | acpi_status status; |
| 1834 | |
| 1835 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, |
| 1836 | device->parent->handle, 1, |
| 1837 | acpi_video_bus_match, NULL, |
| 1838 | device, NULL); |
| 1839 | if (status == AE_ALREADY_EXISTS) { |
| 1840 | printk(KERN_WARNING FW_BUG |
| 1841 | "Duplicate ACPI video bus devices for the" |
| 1842 | " same VGA controller, please try module " |
| 1843 | "parameter \"video.allow_duplicates=1\"" |
| 1844 | "if the current driver doesn't work.\n"); |
| 1845 | if (!allow_duplicates) |
| 1846 | return -ENODEV; |
| 1847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1849 | video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | if (!video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1851 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
Zhang Rui | e6d9da1 | 2007-08-25 02:23:31 -0400 | [diff] [blame] | 1853 | /* a hack to fix the duplicate name "VID" problem on T61 */ |
| 1854 | if (!strcmp(device->pnp.bus_id, "VID")) { |
| 1855 | if (instance) |
| 1856 | device->pnp.bus_id[3] = '0' + instance; |
Felipe Contreras | 915ea7e | 2013-08-03 22:12:50 +0200 | [diff] [blame] | 1857 | instance++; |
Zhang Rui | e6d9da1 | 2007-08-25 02:23:31 -0400 | [diff] [blame] | 1858 | } |
Zhao Yakui | f3b39f1 | 2009-02-02 22:55:01 -0500 | [diff] [blame] | 1859 | /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */ |
| 1860 | if (!strcmp(device->pnp.bus_id, "VGA")) { |
| 1861 | if (instance) |
| 1862 | device->pnp.bus_id[3] = '0' + instance; |
| 1863 | instance++; |
| 1864 | } |
Zhang Rui | e6d9da1 | 2007-08-25 02:23:31 -0400 | [diff] [blame] | 1865 | |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1866 | video->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); |
| 1868 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1869 | device->driver_data = video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
| 1871 | acpi_video_bus_find_cap(video); |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1872 | error = acpi_video_bus_check(video); |
| 1873 | if (error) |
| 1874 | goto err_free_video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1876 | mutex_init(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | INIT_LIST_HEAD(&video->video_device_list); |
| 1878 | |
Igor Murzov | ea9f885 | 2012-03-30 21:32:08 +0400 | [diff] [blame] | 1879 | error = acpi_video_bus_get_devices(video, device); |
| 1880 | if (error) |
Aaron Lu | 91e13aa | 2013-04-25 02:47:49 +0000 | [diff] [blame] | 1881 | goto err_put_video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1884 | ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), |
| 1885 | video->flags.multihead ? "yes" : "no", |
| 1886 | video->flags.rom ? "yes" : "no", |
| 1887 | video->flags.post ? "yes" : "no"); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1888 | mutex_lock(&video_list_lock); |
| 1889 | list_add_tail(&video->entry, &video_bus_head); |
| 1890 | mutex_unlock(&video_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1892 | acpi_video_bus_register_backlight(video); |
| 1893 | acpi_video_bus_add_notify_handler(video); |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 1894 | |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1895 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1897 | err_put_video: |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1898 | acpi_video_bus_put_devices(video); |
| 1899 | kfree(video->attached_array); |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1900 | err_free_video: |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1901 | kfree(video); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1902 | device->driver_data = NULL; |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 1903 | |
| 1904 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 1907 | static int acpi_video_bus_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1909 | struct acpi_video_bus *video = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
| 1912 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1913 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1915 | video = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1917 | acpi_video_bus_remove_notify_handler(video); |
| 1918 | acpi_video_bus_unregister_backlight(video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | acpi_video_bus_put_devices(video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1921 | mutex_lock(&video_list_lock); |
| 1922 | list_del(&video->entry); |
| 1923 | mutex_unlock(&video_list_lock); |
| 1924 | |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 1925 | kfree(video->attached_array); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | kfree(video); |
| 1927 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1928 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Alan Cox | c6996bd | 2012-04-25 14:33:48 +0100 | [diff] [blame] | 1931 | static int __init is_i740(struct pci_dev *dev) |
| 1932 | { |
| 1933 | if (dev->device == 0x00D1) |
| 1934 | return 1; |
| 1935 | if (dev->device == 0x7000) |
| 1936 | return 1; |
| 1937 | return 0; |
| 1938 | } |
| 1939 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1940 | static int __init intel_opregion_present(void) |
| 1941 | { |
Alan Cox | c6996bd | 2012-04-25 14:33:48 +0100 | [diff] [blame] | 1942 | int opregion = 0; |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1943 | struct pci_dev *dev = NULL; |
| 1944 | u32 address; |
| 1945 | |
| 1946 | for_each_pci_dev(dev) { |
| 1947 | if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 1948 | continue; |
| 1949 | if (dev->vendor != PCI_VENDOR_ID_INTEL) |
| 1950 | continue; |
Alan Cox | c6996bd | 2012-04-25 14:33:48 +0100 | [diff] [blame] | 1951 | /* We don't want to poke around undefined i740 registers */ |
| 1952 | if (is_i740(dev)) |
| 1953 | continue; |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1954 | pci_read_config_dword(dev, 0xfc, &address); |
| 1955 | if (!address) |
| 1956 | continue; |
Alan Cox | c6996bd | 2012-04-25 14:33:48 +0100 | [diff] [blame] | 1957 | opregion = 1; |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1958 | } |
Alan Cox | c6996bd | 2012-04-25 14:33:48 +0100 | [diff] [blame] | 1959 | return opregion; |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
Rafael J. Wysocki | 8e5c2b7 | 2013-07-25 21:43:39 +0200 | [diff] [blame] | 1962 | int acpi_video_register(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1964 | int ret = 0; |
Chris Wilson | 28d6340 | 2015-03-01 10:41:38 +0000 | [diff] [blame] | 1965 | |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1966 | mutex_lock(®ister_count_mutex); |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 1967 | if (register_count) { |
| 1968 | /* |
Rafael J. Wysocki | 8e5c2b7 | 2013-07-25 21:43:39 +0200 | [diff] [blame] | 1969 | * if the function of acpi_video_register is already called, |
| 1970 | * don't register the acpi_vide_bus again and return no error. |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 1971 | */ |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1972 | goto leave; |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 1973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | |
Aaron Lu | 67b662e | 2013-10-11 21:27:44 +0800 | [diff] [blame] | 1975 | mutex_init(&video_list_lock); |
| 1976 | INIT_LIST_HEAD(&video_bus_head); |
| 1977 | |
Hans de Goede | 7ee33ba | 2015-06-16 16:27:53 +0200 | [diff] [blame] | 1978 | dmi_check_system(video_dmi_table); |
| 1979 | |
Chris Wilson | 28d6340 | 2015-03-01 10:41:38 +0000 | [diff] [blame] | 1980 | ret = acpi_bus_register_driver(&acpi_video_bus); |
| 1981 | if (ret) |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1982 | goto leave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 1984 | /* |
| 1985 | * When the acpi_video_bus is loaded successfully, increase |
| 1986 | * the counter reference. |
| 1987 | */ |
| 1988 | register_count = 1; |
| 1989 | |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1990 | leave: |
| 1991 | mutex_unlock(®ister_count_mutex); |
| 1992 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
Rafael J. Wysocki | 8e5c2b7 | 2013-07-25 21:43:39 +0200 | [diff] [blame] | 1994 | EXPORT_SYMBOL(acpi_video_register); |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 1995 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 1996 | void acpi_video_unregister(void) |
| 1997 | { |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 1998 | mutex_lock(®ister_count_mutex); |
| 1999 | if (register_count) { |
| 2000 | acpi_bus_unregister_driver(&acpi_video_bus); |
| 2001 | register_count = 0; |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2002 | } |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 2003 | mutex_unlock(®ister_count_mutex); |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2004 | } |
| 2005 | EXPORT_SYMBOL(acpi_video_unregister); |
| 2006 | |
Hans de Goede | 1b7f37e | 2014-05-17 10:48:01 +0200 | [diff] [blame] | 2007 | void acpi_video_unregister_backlight(void) |
| 2008 | { |
| 2009 | struct acpi_video_bus *video; |
| 2010 | |
Hans de Goede | 2a8b18e | 2015-06-16 16:27:54 +0200 | [diff] [blame] | 2011 | mutex_lock(®ister_count_mutex); |
| 2012 | if (register_count) { |
| 2013 | mutex_lock(&video_list_lock); |
| 2014 | list_for_each_entry(video, &video_bus_head, entry) |
| 2015 | acpi_video_bus_unregister_backlight(video); |
| 2016 | mutex_unlock(&video_list_lock); |
| 2017 | } |
| 2018 | mutex_unlock(®ister_count_mutex); |
Hans de Goede | 1b7f37e | 2014-05-17 10:48:01 +0200 | [diff] [blame] | 2019 | } |
Hans de Goede | 1b7f37e | 2014-05-17 10:48:01 +0200 | [diff] [blame] | 2020 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2021 | /* |
| 2022 | * This is kind of nasty. Hardware using Intel chipsets may require |
| 2023 | * the video opregion code to be run first in order to initialise |
| 2024 | * state before any ACPI video calls are made. To handle this we defer |
| 2025 | * registration of the video class until the opregion code has run. |
| 2026 | */ |
| 2027 | |
| 2028 | static int __init acpi_video_init(void) |
| 2029 | { |
Chris Wilson | 6e17cb1 | 2015-03-01 10:41:37 +0000 | [diff] [blame] | 2030 | /* |
| 2031 | * Let the module load even if ACPI is disabled (e.g. due to |
| 2032 | * a broken BIOS) so that i915.ko can still be loaded on such |
| 2033 | * old systems without an AcpiOpRegion. |
| 2034 | * |
| 2035 | * acpi_video_register() will report -ENODEV later as well due |
| 2036 | * to acpi_disabled when i915.ko tries to register itself afterwards. |
| 2037 | */ |
| 2038 | if (acpi_disabled) |
| 2039 | return 0; |
| 2040 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2041 | if (intel_opregion_present()) |
| 2042 | return 0; |
| 2043 | |
| 2044 | return acpi_video_register(); |
| 2045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2047 | static void __exit acpi_video_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | { |
Hans de Goede | 93a291d | 2015-06-16 16:27:52 +0200 | [diff] [blame] | 2049 | acpi_video_detect_exit(); |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2050 | acpi_video_unregister(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2052 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
| 2055 | module_init(acpi_video_init); |
| 2056 | module_exit(acpi_video_exit); |