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