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