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