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