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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/proc_fs.h> |
| 34 | #include <linux/seq_file.h> |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 35 | #include <linux/input.h> |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 36 | #include <linux/backlight.h> |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 37 | #include <linux/thermal.h> |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 38 | #include <linux/video_output.h> |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 39 | #include <linux/sort.h> |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 40 | #include <linux/pci.h> |
| 41 | #include <linux/pci_ids.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/uaccess.h> |
Len Brown | eb27cae | 2009-07-06 23:40:19 -0400 | [diff] [blame] | 44 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi_bus.h> |
| 46 | #include <acpi/acpi_drivers.h> |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 47 | #include <linux/suspend.h> |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 48 | #include <acpi/video.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 50 | #define PREFIX "ACPI: " |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define ACPI_VIDEO_CLASS "video" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_VIDEO_BUS_NAME "Video Bus" |
| 54 | #define ACPI_VIDEO_DEVICE_NAME "Video Device" |
| 55 | #define ACPI_VIDEO_NOTIFY_SWITCH 0x80 |
| 56 | #define ACPI_VIDEO_NOTIFY_PROBE 0x81 |
| 57 | #define ACPI_VIDEO_NOTIFY_CYCLE 0x82 |
| 58 | #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 |
| 59 | #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 |
| 60 | |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 61 | #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85 |
| 62 | #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86 |
| 63 | #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87 |
| 64 | #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88 |
| 65 | #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 67 | #define MAX_NAME_LEN 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define _COMPONENT ACPI_VIDEO_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 70 | ACPI_MODULE_NAME("video"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 72 | MODULE_AUTHOR("Bruno Ducrot"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 73 | MODULE_DESCRIPTION("ACPI Video Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | MODULE_LICENSE("GPL"); |
| 75 | |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 76 | static int brightness_switch_enabled = 1; |
| 77 | module_param(brightness_switch_enabled, bool, 0644); |
| 78 | |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 79 | /* |
| 80 | * By default, we don't allow duplicate ACPI video bus devices |
| 81 | * under the same VGA controller |
| 82 | */ |
| 83 | static int allow_duplicates; |
| 84 | module_param(allow_duplicates, bool, 0644); |
| 85 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 86 | static int register_count = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | static int acpi_video_bus_add(struct acpi_device *device); |
| 88 | static int acpi_video_bus_remove(struct acpi_device *device, int type); |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 89 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 91 | static const struct acpi_device_id video_device_ids[] = { |
| 92 | {ACPI_VIDEO_HID, 0}, |
| 93 | {"", 0}, |
| 94 | }; |
| 95 | MODULE_DEVICE_TABLE(acpi, video_device_ids); |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static struct acpi_driver acpi_video_bus = { |
Len Brown | c2b6705b | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 98 | .name = "video", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .class = ACPI_VIDEO_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 100 | .ids = video_device_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | .ops = { |
| 102 | .add = acpi_video_bus_add, |
| 103 | .remove = acpi_video_bus_remove, |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 104 | .notify = acpi_video_bus_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | struct acpi_video_bus_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | u8 multihead:1; /* can switch video heads */ |
| 110 | u8 rom:1; /* can retrieve a video rom */ |
| 111 | u8 post:1; /* can configure the head to */ |
| 112 | u8 reserved:5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct acpi_video_bus_cap { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | u8 _DOS:1; /*Enable/Disable output switching */ |
| 117 | u8 _DOD:1; /*Enumerate all devices attached to display adapter */ |
| 118 | u8 _ROM:1; /*Get ROM Data */ |
| 119 | u8 _GPD:1; /*Get POST Device */ |
| 120 | u8 _SPD:1; /*Set POST Device */ |
| 121 | u8 _VPO:1; /*Video POST Options */ |
| 122 | u8 reserved:2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | struct acpi_video_device_attrib { |
| 126 | u32 display_index:4; /* A zero-based instance of the Display */ |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 127 | u32 display_port_attachment:4; /*This field differentiates the display type */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | u32 display_type:4; /*Describe the specific type in use */ |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 129 | u32 vendor_specific:4; /*Chipset Vendor Specific */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | u32 bios_can_detect:1; /*BIOS can detect the device */ |
| 131 | u32 depend_on_vga:1; /*Non-VGA output device whose power is related to |
| 132 | the VGA device. */ |
| 133 | u32 pipe_id:3; /*For VGA multiple-head devices. */ |
| 134 | u32 reserved:10; /*Must be 0 */ |
| 135 | u32 device_id_scheme:1; /*Device ID Scheme */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct acpi_video_enumerated_device { |
| 139 | union { |
| 140 | u32 int_val; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | struct acpi_video_device_attrib attrib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } value; |
| 143 | struct acpi_video_device *bind_info; |
| 144 | }; |
| 145 | |
| 146 | struct acpi_video_bus { |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 147 | struct acpi_device *device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | u8 dos_setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | struct acpi_video_enumerated_device *attached_array; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | u8 attached_count; |
| 151 | struct acpi_video_bus_cap cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | struct acpi_video_bus_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | struct list_head video_device_list; |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 154 | struct mutex device_list_lock; /* protects video_device_list */ |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 155 | #ifdef CONFIG_ACPI_PROCFS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | struct proc_dir_entry *dir; |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 157 | #endif |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 158 | struct input_dev *input; |
| 159 | char phys[32]; /* for input device */ |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 160 | struct notifier_block pm_nb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | struct acpi_video_device_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | u8 crt:1; |
| 165 | u8 lcd:1; |
| 166 | u8 tvout:1; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 167 | u8 dvi:1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | u8 bios:1; |
| 169 | u8 unknown:1; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 170 | u8 reserved:2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | struct acpi_video_device_cap { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | u8 _ADR:1; /*Return the unique ID */ |
| 175 | u8 _BCL:1; /*Query list of brightness control levels supported */ |
| 176 | u8 _BCM:1; /*Set the brightness level */ |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 177 | u8 _BQC:1; /* Get current brightness level */ |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 178 | u8 _BCQ:1; /* Some buggy BIOS uses _BCQ instead of _BQC */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | u8 _DDC:1; /*Return the EDID for this device */ |
| 180 | u8 _DCS:1; /*Return status of output device */ |
| 181 | u8 _DGS:1; /*Query graphics state */ |
| 182 | u8 _DSS:1; /*Device state set */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 185 | struct acpi_video_brightness_flags { |
| 186 | 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] | 187 | u8 _BCL_reversed:1; /* _BCL package is in a reversed order*/ |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 188 | u8 _BCL_use_index:1; /* levels in _BCL are index values */ |
| 189 | u8 _BCM_use_index:1; /* input of _BCM is an index value */ |
| 190 | u8 _BQC_use_index:1; /* _BQC returns an index value */ |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 191 | }; |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | struct acpi_video_device_brightness { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | int curr; |
| 195 | int count; |
| 196 | int *levels; |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 197 | struct acpi_video_brightness_flags flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | struct acpi_video_device { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | unsigned long device_id; |
| 202 | struct acpi_video_device_flags flags; |
| 203 | struct acpi_video_device_cap cap; |
| 204 | struct list_head entry; |
| 205 | struct acpi_video_bus *video; |
| 206 | struct acpi_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | struct acpi_video_device_brightness *brightness; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 208 | struct backlight_device *backlight; |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 209 | struct thermal_cooling_device *cooling_dev; |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 210 | struct output_device *output_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 213 | #ifdef CONFIG_ACPI_PROCFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* bus */ |
| 215 | static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file); |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 216 | static const struct file_operations acpi_video_bus_info_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 217 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | .open = acpi_video_bus_info_open_fs, |
| 219 | .read = seq_read, |
| 220 | .llseek = seq_lseek, |
| 221 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file); |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 225 | static const struct file_operations acpi_video_bus_ROM_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 226 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | .open = acpi_video_bus_ROM_open_fs, |
| 228 | .read = seq_read, |
| 229 | .llseek = seq_lseek, |
| 230 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | static int acpi_video_bus_POST_info_open_fs(struct inode *inode, |
| 234 | struct file *file); |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 235 | static const struct file_operations acpi_video_bus_POST_info_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 236 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | .open = acpi_video_bus_POST_info_open_fs, |
| 238 | .read = seq_read, |
| 239 | .llseek = seq_lseek, |
| 240 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file); |
Len Brown | c07c9a7 | 2009-04-04 03:33:45 -0400 | [diff] [blame] | 244 | static ssize_t acpi_video_bus_write_POST(struct file *file, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 245 | const char __user *buffer, size_t count, loff_t *data); |
| 246 | static const struct file_operations acpi_video_bus_POST_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 247 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | .open = acpi_video_bus_POST_open_fs, |
| 249 | .read = seq_read, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 250 | .write = acpi_video_bus_write_POST, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | .llseek = seq_lseek, |
| 252 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file); |
Len Brown | c07c9a7 | 2009-04-04 03:33:45 -0400 | [diff] [blame] | 256 | static ssize_t acpi_video_bus_write_DOS(struct file *file, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 257 | const char __user *buffer, size_t count, loff_t *data); |
| 258 | static const struct file_operations acpi_video_bus_DOS_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 259 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | .open = acpi_video_bus_DOS_open_fs, |
| 261 | .read = seq_read, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 262 | .write = acpi_video_bus_write_DOS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | .llseek = seq_lseek, |
| 264 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | /* device */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | static int acpi_video_device_info_open_fs(struct inode *inode, |
| 269 | struct file *file); |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 270 | static const struct file_operations acpi_video_device_info_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 271 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | .open = acpi_video_device_info_open_fs, |
| 273 | .read = seq_read, |
| 274 | .llseek = seq_lseek, |
| 275 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | static int acpi_video_device_state_open_fs(struct inode *inode, |
| 279 | struct file *file); |
Len Brown | c07c9a7 | 2009-04-04 03:33:45 -0400 | [diff] [blame] | 280 | static ssize_t acpi_video_device_write_state(struct file *file, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 281 | const char __user *buffer, size_t count, loff_t *data); |
| 282 | static const struct file_operations acpi_video_device_state_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 283 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | .open = acpi_video_device_state_open_fs, |
| 285 | .read = seq_read, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 286 | .write = acpi_video_device_write_state, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | .llseek = seq_lseek, |
| 288 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | }; |
| 290 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | static int acpi_video_device_brightness_open_fs(struct inode *inode, |
| 292 | struct file *file); |
Len Brown | c07c9a7 | 2009-04-04 03:33:45 -0400 | [diff] [blame] | 293 | static ssize_t acpi_video_device_write_brightness(struct file *file, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 294 | const char __user *buffer, size_t count, loff_t *data); |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 295 | static const struct file_operations acpi_video_device_brightness_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 296 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | .open = acpi_video_device_brightness_open_fs, |
| 298 | .read = seq_read, |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 299 | .write = acpi_video_device_write_brightness, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | .llseek = seq_lseek, |
| 301 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 304 | static int acpi_video_device_EDID_open_fs(struct inode *inode, |
| 305 | struct file *file); |
Jan Engelhardt | 070d8eb | 2009-01-12 00:07:55 +0100 | [diff] [blame] | 306 | static const struct file_operations acpi_video_device_EDID_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 307 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | .open = acpi_video_device_EDID_open_fs, |
| 309 | .read = seq_read, |
| 310 | .llseek = seq_lseek, |
| 311 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | }; |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 313 | #endif /* CONFIG_ACPI_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Jan Engelhardt | b7171ae | 2009-01-12 00:08:19 +0100 | [diff] [blame] | 315 | static const char device_decode[][30] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | "motherboard VGA device", |
| 317 | "PCI VGA device", |
| 318 | "AGP VGA device", |
| 319 | "UNKNOWN", |
| 320 | }; |
| 321 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data); |
| 323 | static void acpi_video_device_rebind(struct acpi_video_bus *video); |
| 324 | static void acpi_video_device_bind(struct acpi_video_bus *video, |
| 325 | struct acpi_video_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | static int acpi_video_device_enumerate(struct acpi_video_bus *video); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 327 | static int acpi_video_device_lcd_set_level(struct acpi_video_device *device, |
| 328 | int level); |
| 329 | static int acpi_video_device_lcd_get_level_current( |
| 330 | struct acpi_video_device *device, |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 331 | unsigned long long *level, int init); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | static int acpi_video_get_next_level(struct acpi_video_device *device, |
| 333 | u32 level_current, u32 event); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 334 | static int acpi_video_switch_brightness(struct acpi_video_device *device, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | int event); |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 336 | static int acpi_video_device_get_state(struct acpi_video_device *device, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 337 | unsigned long long *state); |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 338 | static int acpi_video_output_get(struct output_device *od); |
| 339 | 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] | 340 | |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 341 | /*backlight device sysfs support*/ |
| 342 | static int acpi_video_get_brightness(struct backlight_device *bd) |
| 343 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 344 | unsigned long long cur_level; |
Matthew Garrett | 38531e6 | 2007-12-26 02:03:26 +0000 | [diff] [blame] | 345 | int i; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 346 | struct acpi_video_device *vd = |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 347 | (struct acpi_video_device *)bl_get_data(bd); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 348 | |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 349 | if (acpi_video_device_lcd_get_level_current(vd, &cur_level, 0)) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 350 | return -EINVAL; |
Matthew Garrett | 38531e6 | 2007-12-26 02:03:26 +0000 | [diff] [blame] | 351 | for (i = 2; i < vd->brightness->count; i++) { |
| 352 | if (vd->brightness->levels[i] == cur_level) |
| 353 | /* The first two entries are special - see page 575 |
| 354 | of the ACPI spec 3.0 */ |
| 355 | return i-2; |
| 356 | } |
| 357 | return 0; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static int acpi_video_set_brightness(struct backlight_device *bd) |
| 361 | { |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 362 | int request_level = bd->props.brightness + 2; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 363 | struct acpi_video_device *vd = |
Richard Purdie | 655bfd7 | 2007-07-09 12:17:24 +0100 | [diff] [blame] | 364 | (struct acpi_video_device *)bl_get_data(bd); |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 365 | |
| 366 | return acpi_video_device_lcd_set_level(vd, |
| 367 | vd->brightness->levels[request_level]); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 368 | } |
| 369 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 370 | static struct backlight_ops acpi_backlight_ops = { |
| 371 | .get_brightness = acpi_video_get_brightness, |
| 372 | .update_status = acpi_video_set_brightness, |
| 373 | }; |
| 374 | |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 375 | /*video output device sysfs support*/ |
| 376 | static int acpi_video_output_get(struct output_device *od) |
| 377 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 378 | unsigned long long state; |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 379 | struct acpi_video_device *vd = |
tonyj@suse.de | 6004342 | 2007-08-07 22:28:47 -0700 | [diff] [blame] | 380 | (struct acpi_video_device *)dev_get_drvdata(&od->dev); |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 381 | acpi_video_device_get_state(vd, &state); |
| 382 | return (int)state; |
| 383 | } |
| 384 | |
| 385 | static int acpi_video_output_set(struct output_device *od) |
| 386 | { |
| 387 | unsigned long state = od->request_state; |
| 388 | struct acpi_video_device *vd= |
tonyj@suse.de | 6004342 | 2007-08-07 22:28:47 -0700 | [diff] [blame] | 389 | (struct acpi_video_device *)dev_get_drvdata(&od->dev); |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 390 | return acpi_video_device_set_state(vd, state); |
| 391 | } |
| 392 | |
| 393 | static struct output_properties acpi_output_properties = { |
| 394 | .set_state = acpi_video_output_set, |
| 395 | .get_status = acpi_video_output_get, |
| 396 | }; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 397 | |
| 398 | |
| 399 | /* thermal cooling device callbacks */ |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 400 | 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] | 401 | long *state) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 402 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 403 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 404 | struct acpi_video_device *video = acpi_driver_data(device); |
| 405 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 406 | *state = video->brightness->count - 3; |
| 407 | return 0; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 408 | } |
| 409 | |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 410 | 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] | 411 | long *state) |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 412 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 413 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 414 | struct acpi_video_device *video = acpi_driver_data(device); |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 415 | unsigned long long level; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 416 | int offset; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 417 | |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 418 | if (acpi_video_device_lcd_get_level_current(video, &level, 0)) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 419 | return -EINVAL; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 420 | for (offset = 2; offset < video->brightness->count; offset++) |
| 421 | if (level == video->brightness->levels[offset]) { |
| 422 | *state = video->brightness->count - offset - 1; |
| 423 | return 0; |
| 424 | } |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 425 | |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | |
| 429 | static int |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 430 | 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] | 431 | { |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 432 | struct acpi_device *device = cooling_dev->devdata; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 433 | struct acpi_video_device *video = acpi_driver_data(device); |
| 434 | int level; |
| 435 | |
| 436 | if ( state >= video->brightness->count - 2) |
| 437 | return -EINVAL; |
| 438 | |
| 439 | state = video->brightness->count - state; |
| 440 | level = video->brightness->levels[state -1]; |
| 441 | return acpi_video_device_lcd_set_level(video, level); |
| 442 | } |
| 443 | |
| 444 | static struct thermal_cooling_device_ops video_cooling_ops = { |
| 445 | .get_max_state = video_get_max_state, |
| 446 | .get_cur_state = video_get_cur_state, |
| 447 | .set_cur_state = video_set_cur_state, |
| 448 | }; |
| 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* -------------------------------------------------------------------------- |
| 451 | Video Management |
| 452 | -------------------------------------------------------------------------- */ |
| 453 | |
| 454 | /* device */ |
| 455 | |
| 456 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | acpi_video_device_get_state(struct acpi_video_device *device, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 458 | unsigned long long *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 462 | status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 464 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | acpi_video_device_set_state(struct acpi_video_device *device, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 470 | int status; |
| 471 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 472 | struct acpi_object_list args = { 1, &arg0 }; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 473 | unsigned long long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | arg0.integer.value = state; |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 477 | status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 479 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 483 | acpi_video_device_lcd_query_levels(struct acpi_video_device *device, |
| 484 | union acpi_object **levels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | int status; |
| 487 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 488 | union acpi_object *obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | *levels = NULL; |
| 492 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 493 | status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (!ACPI_SUCCESS(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 495 | return status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | obj = (union acpi_object *)buffer.pointer; |
Adrian Bunk | 6665bda | 2006-03-11 10:12:00 -0500 | [diff] [blame] | 497 | if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 498 | printk(KERN_ERR PREFIX "Invalid _BCL data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | status = -EFAULT; |
| 500 | goto err; |
| 501 | } |
| 502 | |
| 503 | *levels = obj; |
| 504 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 505 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 507 | err: |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 508 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 510 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | 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] | 515 | { |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 516 | int status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 518 | struct acpi_object_list args = { 1, &arg0 }; |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 519 | int state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | arg0.integer.value = level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 523 | status = acpi_evaluate_object(device->dev->handle, "_BCM", |
| 524 | &args, NULL); |
| 525 | if (ACPI_FAILURE(status)) { |
| 526 | ACPI_ERROR((AE_INFO, "Evaluating _BCM failed")); |
| 527 | return -EIO; |
| 528 | } |
| 529 | |
Alexey Starikovskiy | 4500ca8 | 2007-09-03 16:29:58 +0400 | [diff] [blame] | 530 | device->brightness->curr = level; |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 531 | for (state = 2; state < device->brightness->count; state++) |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 532 | if (level == device->brightness->levels[state]) { |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 533 | if (device->backlight) |
| 534 | device->backlight->props.brightness = state - 2; |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 535 | return 0; |
| 536 | } |
Zhang Rui | 9e6dada | 2008-12-31 10:58:48 +0800 | [diff] [blame] | 537 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 538 | ACPI_ERROR((AE_INFO, "Current brightness invalid")); |
| 539 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 542 | /* |
| 543 | * For some buggy _BQC methods, we need to add a constant value to |
| 544 | * the _BQC return value to get the actual current brightness level |
| 545 | */ |
| 546 | |
| 547 | static int bqc_offset_aml_bug_workaround; |
| 548 | static int __init video_set_bqc_offset(const struct dmi_system_id *d) |
| 549 | { |
| 550 | bqc_offset_aml_bug_workaround = 9; |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static struct dmi_system_id video_dmi_table[] __initdata = { |
| 555 | /* |
| 556 | * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121 |
| 557 | */ |
| 558 | { |
| 559 | .callback = video_set_bqc_offset, |
| 560 | .ident = "Acer Aspire 5720", |
| 561 | .matches = { |
| 562 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 563 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5720"), |
| 564 | }, |
| 565 | }, |
Len Brown | 5afc4ab | 2009-05-07 21:11:56 -0400 | [diff] [blame] | 566 | { |
| 567 | .callback = video_set_bqc_offset, |
| 568 | .ident = "Acer Aspire 5710Z", |
| 569 | .matches = { |
| 570 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 571 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5710Z"), |
| 572 | }, |
| 573 | }, |
Zhang Rui | 34ac272 | 2009-05-26 23:35:34 -0400 | [diff] [blame] | 574 | { |
| 575 | .callback = video_set_bqc_offset, |
| 576 | .ident = "eMachines E510", |
| 577 | .matches = { |
| 578 | DMI_MATCH(DMI_BOARD_VENDOR, "EMACHINES"), |
| 579 | DMI_MATCH(DMI_PRODUCT_NAME, "eMachines E510"), |
| 580 | }, |
| 581 | }, |
Zhang Rui | 93bcece | 2009-05-19 15:08:41 -0400 | [diff] [blame] | 582 | { |
| 583 | .callback = video_set_bqc_offset, |
| 584 | .ident = "Acer Aspire 5315", |
| 585 | .matches = { |
| 586 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 587 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5315"), |
| 588 | }, |
| 589 | }, |
Zhang Rui | 152a4e6 | 2009-06-22 11:31:18 +0800 | [diff] [blame] | 590 | { |
| 591 | .callback = video_set_bqc_offset, |
| 592 | .ident = "Acer Aspire 7720", |
| 593 | .matches = { |
| 594 | DMI_MATCH(DMI_BOARD_VENDOR, "Acer"), |
| 595 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 7720"), |
| 596 | }, |
| 597 | }, |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 598 | {} |
| 599 | }; |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 602 | acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 603 | unsigned long long *level, int init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 605 | acpi_status status = AE_OK; |
Vladimir Serbinenko | 4e231fa | 2009-06-24 15:17:36 +0800 | [diff] [blame] | 606 | int i; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 607 | |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 608 | if (device->cap._BQC || device->cap._BCQ) { |
| 609 | char *buf = device->cap._BQC ? "_BQC" : "_BCQ"; |
| 610 | |
| 611 | status = acpi_evaluate_integer(device->dev->handle, buf, |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 612 | NULL, level); |
| 613 | if (ACPI_SUCCESS(status)) { |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 614 | if (device->brightness->flags._BQC_use_index) { |
| 615 | if (device->brightness->flags._BCL_reversed) |
| 616 | *level = device->brightness->count |
| 617 | - 3 - (*level); |
| 618 | *level = device->brightness->levels[*level + 2]; |
| 619 | |
| 620 | } |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 621 | *level += bqc_offset_aml_bug_workaround; |
Vladimir Serbinenko | 4e231fa | 2009-06-24 15:17:36 +0800 | [diff] [blame] | 622 | for (i = 2; i < device->brightness->count; i++) |
| 623 | if (device->brightness->levels[i] == *level) { |
| 624 | device->brightness->curr = *level; |
| 625 | return 0; |
| 626 | } |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 627 | if (!init) { |
| 628 | /* |
| 629 | * BQC returned an invalid level. |
| 630 | * Stop using it. |
| 631 | */ |
| 632 | ACPI_WARNING((AE_INFO, |
| 633 | "%s returned an invalid level", |
| 634 | buf)); |
| 635 | device->cap._BQC = device->cap._BCQ = 0; |
| 636 | } |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 637 | } else { |
| 638 | /* Fixme: |
| 639 | * should we return an error or ignore this failure? |
| 640 | * dev->brightness->curr is a cached value which stores |
| 641 | * the correct current backlight level in most cases. |
| 642 | * ACPI video backlight still works w/ buggy _BQC. |
| 643 | * http://bugzilla.kernel.org/show_bug.cgi?id=12233 |
| 644 | */ |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 645 | ACPI_WARNING((AE_INFO, "Evaluating %s failed", buf)); |
| 646 | device->cap._BQC = device->cap._BCQ = 0; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
Alexey Starikovskiy | 4500ca8 | 2007-09-03 16:29:58 +0400 | [diff] [blame] | 650 | *level = device->brightness->curr; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 651 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | acpi_video_device_EDID(struct acpi_video_device *device, |
| 656 | union acpi_object **edid, ssize_t length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | int status; |
| 659 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 660 | union acpi_object *obj; |
| 661 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 662 | struct acpi_object_list args = { 1, &arg0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | *edid = NULL; |
| 666 | |
| 667 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 668 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | if (length == 128) |
| 670 | arg0.integer.value = 1; |
| 671 | else if (length == 256) |
| 672 | arg0.integer.value = 2; |
| 673 | else |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 674 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 676 | status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 678 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 680 | obj = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | if (obj && obj->type == ACPI_TYPE_BUFFER) |
| 683 | *edid = obj; |
| 684 | else { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 685 | printk(KERN_ERR PREFIX "Invalid _DDC data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | status = -EFAULT; |
| 687 | kfree(obj); |
| 688 | } |
| 689 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 690 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* bus */ |
| 694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | /* |
| 696 | * Arg: |
| 697 | * video : video bus device pointer |
| 698 | * bios_flag : |
| 699 | * 0. The system BIOS should NOT automatically switch(toggle) |
| 700 | * the active display output. |
| 701 | * 1. The system BIOS should automatically switch (toggle) the |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 702 | * active display output. No switch event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | * 2. The _DGS value should be locked. |
| 704 | * 3. The system BIOS should not automatically switch (toggle) the |
| 705 | * active display output, but instead generate the display switch |
| 706 | * event notify code. |
| 707 | * lcd_flag : |
| 708 | * 0. The system BIOS should automatically control the brightness level |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 709 | * of the LCD when the power changes from AC to DC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | * 1. The system BIOS should NOT automatically control the brightness |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 711 | * level of the LCD when the power changes from AC to DC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | * Return Value: |
| 713 | * -1 wrong arg. |
| 714 | */ |
| 715 | |
| 716 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 717 | 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] | 718 | { |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 719 | u64 status = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 721 | struct acpi_object_list args = { 1, &arg0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 724 | 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] | 725 | status = -1; |
| 726 | goto Failed; |
| 727 | } |
| 728 | arg0.integer.value = (lcd_flag << 2) | bios_flag; |
| 729 | video->dos_setting = arg0.integer.value; |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 730 | acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | Failed: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 733 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | /* |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 737 | * Simple comparison function used to sort backlight levels. |
| 738 | */ |
| 739 | |
| 740 | static int |
| 741 | acpi_video_cmp_level(const void *a, const void *b) |
| 742 | { |
| 743 | return *(int *)a - *(int *)b; |
| 744 | } |
| 745 | |
| 746 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | * Arg: |
| 748 | * device : video output device (LCD, CRT, ..) |
| 749 | * |
| 750 | * Return Value: |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 751 | * Maximum brightness level |
| 752 | * |
| 753 | * Allocate and initialize device->brightness. |
| 754 | */ |
| 755 | |
| 756 | static int |
| 757 | acpi_video_init_brightness(struct acpi_video_device *device) |
| 758 | { |
| 759 | union acpi_object *obj = NULL; |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 760 | int i, max_level = 0, count = 0, level_ac_battery = 0; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 761 | unsigned long long level, level_old; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 762 | union acpi_object *o; |
| 763 | struct acpi_video_device_brightness *br = NULL; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 764 | int result = -EINVAL; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 765 | |
| 766 | if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { |
| 767 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " |
| 768 | "LCD brightness level\n")); |
| 769 | goto out; |
| 770 | } |
| 771 | |
| 772 | if (obj->package.count < 2) |
| 773 | goto out; |
| 774 | |
| 775 | br = kzalloc(sizeof(*br), GFP_KERNEL); |
| 776 | if (!br) { |
| 777 | printk(KERN_ERR "can't allocate memory\n"); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 778 | result = -ENOMEM; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 779 | goto out; |
| 780 | } |
| 781 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 782 | br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels), |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 783 | GFP_KERNEL); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 784 | if (!br->levels) { |
| 785 | result = -ENOMEM; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 786 | goto out_free; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 787 | } |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 788 | |
| 789 | for (i = 0; i < obj->package.count; i++) { |
| 790 | o = (union acpi_object *)&obj->package.elements[i]; |
| 791 | if (o->type != ACPI_TYPE_INTEGER) { |
| 792 | printk(KERN_ERR PREFIX "Invalid data\n"); |
| 793 | continue; |
| 794 | } |
| 795 | br->levels[count] = (u32) o->integer.value; |
| 796 | |
| 797 | if (br->levels[count] > max_level) |
| 798 | max_level = br->levels[count]; |
| 799 | count++; |
| 800 | } |
| 801 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 802 | /* |
| 803 | * some buggy BIOS don't export the levels |
| 804 | * when machine is on AC/Battery in _BCL package. |
| 805 | * In this case, the first two elements in _BCL packages |
| 806 | * are also supported brightness levels that OS should take care of. |
| 807 | */ |
Zhang Rui | 90af2cf | 2009-04-14 11:02:18 +0800 | [diff] [blame] | 808 | for (i = 2; i < count; i++) { |
| 809 | if (br->levels[i] == br->levels[0]) |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 810 | level_ac_battery++; |
Zhang Rui | 90af2cf | 2009-04-14 11:02:18 +0800 | [diff] [blame] | 811 | if (br->levels[i] == br->levels[1]) |
| 812 | level_ac_battery++; |
| 813 | } |
Zhang Rui | 935e5f2 | 2008-12-11 16:24:52 -0500 | [diff] [blame] | 814 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 815 | if (level_ac_battery < 2) { |
| 816 | level_ac_battery = 2 - level_ac_battery; |
| 817 | br->flags._BCL_no_ac_battery_levels = 1; |
| 818 | for (i = (count - 1 + level_ac_battery); i >= 2; i--) |
| 819 | br->levels[i] = br->levels[i - level_ac_battery]; |
| 820 | count += level_ac_battery; |
| 821 | } else if (level_ac_battery > 2) |
| 822 | ACPI_ERROR((AE_INFO, "Too many duplicates in _BCL package\n")); |
| 823 | |
Zhang Rui | d80fb99 | 2009-03-18 16:27:14 +0800 | [diff] [blame] | 824 | /* Check if the _BCL package is in a reversed order */ |
| 825 | if (max_level == br->levels[2]) { |
| 826 | br->flags._BCL_reversed = 1; |
| 827 | sort(&br->levels[2], count - 2, sizeof(br->levels[2]), |
| 828 | acpi_video_cmp_level, NULL); |
| 829 | } else if (max_level != br->levels[count - 1]) |
| 830 | ACPI_ERROR((AE_INFO, |
| 831 | "Found unordered _BCL package\n")); |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 832 | |
| 833 | br->count = count; |
| 834 | device->brightness = br; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 835 | |
| 836 | /* Check the input/output of _BQC/_BCL/_BCM */ |
| 837 | if ((max_level < 100) && (max_level <= (count - 2))) |
| 838 | br->flags._BCL_use_index = 1; |
| 839 | |
| 840 | /* |
| 841 | * _BCM is always consistent with _BCL, |
| 842 | * at least for all the laptops we have ever seen. |
| 843 | */ |
| 844 | br->flags._BCM_use_index = br->flags._BCL_use_index; |
| 845 | |
| 846 | /* _BQC uses INDEX while _BCL uses VALUE in some laptops */ |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 847 | br->curr = level = max_level; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 848 | |
| 849 | if (!device->cap._BQC) |
| 850 | goto set_level; |
| 851 | |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 852 | result = acpi_video_device_lcd_get_level_current(device, &level_old, 1); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 853 | if (result) |
| 854 | goto out_free_levels; |
| 855 | |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 856 | /* |
| 857 | * Set the level to maximum and check if _BQC uses indexed value |
| 858 | */ |
| 859 | result = acpi_video_device_lcd_set_level(device, max_level); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 860 | if (result) |
| 861 | goto out_free_levels; |
| 862 | |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 863 | result = acpi_video_device_lcd_get_level_current(device, &level, 0); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 864 | if (result) |
| 865 | goto out_free_levels; |
| 866 | |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 867 | br->flags._BQC_use_index = (level == max_level ? 0 : 1); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 868 | |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 869 | if (!br->flags._BQC_use_index) { |
| 870 | /* |
| 871 | * Set the backlight to the initial state. |
| 872 | * On some buggy laptops, _BQC returns an uninitialized value |
| 873 | * when invoked for the first time, i.e. level_old is invalid. |
| 874 | * set the backlight to max_level in this case |
| 875 | */ |
| 876 | for (i = 2; i < br->count; i++) |
| 877 | if (level_old == br->levels[i]) |
| 878 | level = level_old; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 879 | goto set_level; |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 880 | } |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 881 | |
| 882 | if (br->flags._BCL_reversed) |
| 883 | level_old = (br->count - 1) - level_old; |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 884 | level = br->levels[level_old]; |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 885 | |
| 886 | set_level: |
Zhang Rui | 90c53ca | 2009-08-31 12:39:54 -0400 | [diff] [blame] | 887 | result = acpi_video_device_lcd_set_level(device, level); |
Zhang Rui | e047cca | 2009-04-09 14:24:35 +0800 | [diff] [blame] | 888 | if (result) |
| 889 | goto out_free_levels; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 890 | |
Zhang Rui | d32f694 | 2009-03-18 16:27:12 +0800 | [diff] [blame] | 891 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 892 | "found %d brightness levels\n", count - 2)); |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 893 | kfree(obj); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 894 | return result; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 895 | |
| 896 | out_free_levels: |
| 897 | kfree(br->levels); |
| 898 | out_free: |
| 899 | kfree(br); |
| 900 | out: |
| 901 | device->brightness = NULL; |
| 902 | kfree(obj); |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 903 | return result; |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Arg: |
| 908 | * device : video output device (LCD, CRT, ..) |
| 909 | * |
| 910 | * Return Value: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | * None |
| 912 | * |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 913 | * Find out all required AML methods defined under the output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | * device. |
| 915 | */ |
| 916 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 917 | static void acpi_video_device_find_cap(struct acpi_video_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | acpi_handle h_dummy1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 921 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | device->cap._ADR = 1; |
| 923 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 924 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 925 | device->cap._BCL = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 927 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 928 | device->cap._BCM = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 930 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1))) |
| 931 | device->cap._BQC = 1; |
Zhang Rui | c60d638 | 2009-03-18 16:27:18 +0800 | [diff] [blame] | 932 | else if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCQ", |
| 933 | &h_dummy1))) { |
| 934 | printk(KERN_WARNING FW_BUG "_BCQ is used instead of _BQC\n"); |
| 935 | device->cap._BCQ = 1; |
| 936 | } |
| 937 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 938 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 939 | device->cap._DDC = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 941 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | device->cap._DCS = 1; |
| 943 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 944 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | device->cap._DGS = 1; |
| 946 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 947 | if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | device->cap._DSS = 1; |
| 949 | } |
| 950 | |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 951 | if (acpi_video_backlight_support()) { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 952 | struct backlight_properties props; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 953 | int result; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 954 | static int count = 0; |
| 955 | char *name; |
Zhang Rui | 1a7c618 | 2009-03-18 16:27:16 +0800 | [diff] [blame] | 956 | |
| 957 | result = acpi_video_init_brightness(device); |
| 958 | if (result) |
| 959 | return; |
Julia Lawall | aeb834d | 2010-04-27 14:06:04 -0700 | [diff] [blame] | 960 | name = kasprintf(GFP_KERNEL, "acpi_video%d", count); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 961 | if (!name) |
| 962 | return; |
Julia Lawall | aeb834d | 2010-04-27 14:06:04 -0700 | [diff] [blame] | 963 | count++; |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 964 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 965 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 966 | props.max_brightness = device->brightness->count - 3; |
| 967 | device->backlight = backlight_device_register(name, NULL, device, |
| 968 | &acpi_backlight_ops, |
| 969 | &props); |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 970 | kfree(name); |
Zhang Rui | e01ce79 | 2009-07-29 08:53:29 +0800 | [diff] [blame] | 971 | if (IS_ERR(device->backlight)) |
| 972 | return; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 973 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 974 | /* |
| 975 | * Save current brightness level in case we have to restore it |
| 976 | * before acpi_video_device_lcd_set_level() is called next time. |
| 977 | */ |
| 978 | device->backlight->props.brightness = |
| 979 | acpi_video_get_brightness(device->backlight); |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 980 | |
Zhang Rui | 056c308 | 2009-06-22 11:31:14 +0800 | [diff] [blame] | 981 | result = sysfs_create_link(&device->backlight->dev.kobj, |
| 982 | &device->dev->dev.kobj, "device"); |
| 983 | if (result) |
| 984 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
| 985 | |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 986 | device->cooling_dev = thermal_cooling_device_register("LCD", |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 987 | device->dev, &video_cooling_ops); |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 988 | if (IS_ERR(device->cooling_dev)) { |
Dmitry Torokhov | 4b4fe3b | 2009-08-08 00:26:25 -0700 | [diff] [blame] | 989 | /* |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 990 | * Set cooling_dev to NULL so we don't crash trying to |
Dmitry Torokhov | 4b4fe3b | 2009-08-08 00:26:25 -0700 | [diff] [blame] | 991 | * free it. |
| 992 | * Also, why the hell we are returning early and |
| 993 | * not attempt to register video output if cooling |
| 994 | * device registration failed? |
| 995 | * -- dtor |
| 996 | */ |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 997 | device->cooling_dev = NULL; |
Thomas Sujith | 43ff39f | 2008-02-15 18:29:18 -0500 | [diff] [blame] | 998 | return; |
Dmitry Torokhov | 4b4fe3b | 2009-08-08 00:26:25 -0700 | [diff] [blame] | 999 | } |
Thomas Sujith | 43ff39f | 2008-02-15 18:29:18 -0500 | [diff] [blame] | 1000 | |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 1001 | dev_info(&device->dev->dev, "registered as cooling_device%d\n", |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 1002 | device->cooling_dev->id); |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 1003 | result = sysfs_create_link(&device->dev->dev.kobj, |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 1004 | &device->cooling_dev->device.kobj, |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 1005 | "thermal_cooling"); |
| 1006 | if (result) |
| 1007 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 1008 | result = sysfs_create_link(&device->cooling_dev->device.kobj, |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 1009 | &device->dev->dev.kobj, "device"); |
| 1010 | if (result) |
| 1011 | printk(KERN_ERR PREFIX "Create sysfs link\n"); |
| 1012 | |
Yu Luming | 2f3d000 | 2006-11-11 02:40:34 +0800 | [diff] [blame] | 1013 | } |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 1014 | |
| 1015 | if (acpi_video_display_switch_support()) { |
| 1016 | |
| 1017 | if (device->cap._DCS && device->cap._DSS) { |
| 1018 | static int count; |
| 1019 | char *name; |
Julia Lawall | aeb834d | 2010-04-27 14:06:04 -0700 | [diff] [blame] | 1020 | name = kasprintf(GFP_KERNEL, "acpi_video%d", count); |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 1021 | if (!name) |
| 1022 | return; |
Julia Lawall | aeb834d | 2010-04-27 14:06:04 -0700 | [diff] [blame] | 1023 | count++; |
Thomas Renninger | c3d6de6 | 2008-08-01 17:37:55 +0200 | [diff] [blame] | 1024 | device->output_dev = video_output_register(name, |
| 1025 | NULL, device, &acpi_output_properties); |
| 1026 | kfree(name); |
| 1027 | } |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 1028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * Arg: |
| 1033 | * device : video output device (VGA) |
| 1034 | * |
| 1035 | * Return Value: |
| 1036 | * None |
| 1037 | * |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1038 | * Find out all required AML methods defined under the video bus device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | */ |
| 1040 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1041 | static void acpi_video_bus_find_cap(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1043 | acpi_handle h_dummy1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1045 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | video->cap._DOS = 1; |
| 1047 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1048 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | video->cap._DOD = 1; |
| 1050 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1051 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | video->cap._ROM = 1; |
| 1053 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1054 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | video->cap._GPD = 1; |
| 1056 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1057 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | video->cap._SPD = 1; |
| 1059 | } |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1060 | if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | video->cap._VPO = 1; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | * Check whether the video bus device has required AML method to |
| 1067 | * support the desired features |
| 1068 | */ |
| 1069 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1070 | static int acpi_video_bus_check(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1072 | acpi_status status = -ENOENT; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 1073 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
| 1075 | if (!video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1076 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 1078 | dev = acpi_get_pci_dev(video->device->handle); |
Thomas Renninger | 22c13f9 | 2008-08-01 17:37:54 +0200 | [diff] [blame] | 1079 | if (!dev) |
| 1080 | return -ENODEV; |
Alexander Chiang | 1e4cffe | 2009-06-10 19:56:00 +0000 | [diff] [blame] | 1081 | pci_dev_put(dev); |
Thomas Renninger | 22c13f9 | 2008-08-01 17:37:54 +0200 | [diff] [blame] | 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | /* Since there is no HID, CID and so on for VGA driver, we have |
| 1084 | * to check well known required nodes. |
| 1085 | */ |
| 1086 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1087 | /* Does this device support video switching? */ |
Stefan Bader | 3a1151e | 2009-08-21 11:03:05 +0200 | [diff] [blame] | 1088 | if (video->cap._DOS || video->cap._DOD) { |
| 1089 | if (!video->cap._DOS) { |
| 1090 | printk(KERN_WARNING FW_BUG |
| 1091 | "ACPI(%s) defines _DOD but not _DOS\n", |
| 1092 | acpi_device_bid(video->device)); |
| 1093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | video->flags.multihead = 1; |
| 1095 | status = 0; |
| 1096 | } |
| 1097 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1098 | /* Does this device support retrieving a video ROM? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1099 | if (video->cap._ROM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | video->flags.rom = 1; |
| 1101 | status = 0; |
| 1102 | } |
| 1103 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1104 | /* Does this device support configuring which video device to POST? */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1105 | if (video->cap._GPD && video->cap._SPD && video->cap._VPO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | video->flags.post = 1; |
| 1107 | status = 0; |
| 1108 | } |
| 1109 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1110 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | /* -------------------------------------------------------------------------- |
| 1114 | FS Interface (/proc) |
| 1115 | -------------------------------------------------------------------------- */ |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1116 | #ifdef CONFIG_ACPI_PROCFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1118 | static struct proc_dir_entry *acpi_video_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* video devices */ |
| 1121 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1122 | static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1124 | struct acpi_video_device *dev = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | if (!dev) |
| 1128 | goto end; |
| 1129 | |
| 1130 | seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id); |
| 1131 | seq_printf(seq, "type: "); |
| 1132 | if (dev->flags.crt) |
| 1133 | seq_printf(seq, "CRT\n"); |
| 1134 | else if (dev->flags.lcd) |
| 1135 | seq_printf(seq, "LCD\n"); |
| 1136 | else if (dev->flags.tvout) |
| 1137 | seq_printf(seq, "TVOUT\n"); |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1138 | else if (dev->flags.dvi) |
| 1139 | seq_printf(seq, "DVI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | else |
| 1141 | seq_printf(seq, "UNKNOWN\n"); |
| 1142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1143 | seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1145 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1146 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1150 | acpi_video_device_info_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | { |
| 1152 | return single_open(file, acpi_video_device_info_seq_show, |
| 1153 | PDE(inode)->data); |
| 1154 | } |
| 1155 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1156 | static int |
| 1157 | acpi_video_device_query(struct acpi_video_device *device, |
| 1158 | unsigned long long *state) |
| 1159 | { |
| 1160 | int status; |
| 1161 | |
| 1162 | status = acpi_evaluate_integer(device->dev->handle, "_DGS", |
| 1163 | NULL, state); |
| 1164 | |
| 1165 | return status; |
| 1166 | } |
| 1167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1168 | static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1170 | int status; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1171 | struct acpi_video_device *dev = seq->private; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1172 | unsigned long long state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | if (!dev) |
| 1176 | goto end; |
| 1177 | |
| 1178 | status = acpi_video_device_get_state(dev, &state); |
| 1179 | seq_printf(seq, "state: "); |
| 1180 | if (ACPI_SUCCESS(status)) |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1181 | seq_printf(seq, "0x%02llx\n", state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | else |
| 1183 | seq_printf(seq, "<not supported>\n"); |
| 1184 | |
| 1185 | status = acpi_video_device_query(dev, &state); |
| 1186 | seq_printf(seq, "query: "); |
| 1187 | if (ACPI_SUCCESS(status)) |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1188 | seq_printf(seq, "0x%02llx\n", state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | else |
| 1190 | seq_printf(seq, "<not supported>\n"); |
| 1191 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1192 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1197 | acpi_video_device_state_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | { |
| 1199 | return single_open(file, acpi_video_device_state_seq_show, |
| 1200 | PDE(inode)->data); |
| 1201 | } |
| 1202 | |
| 1203 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1204 | acpi_video_device_write_state(struct file *file, |
| 1205 | const char __user * buffer, |
| 1206 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1208 | int status; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1209 | struct seq_file *m = file->private_data; |
| 1210 | struct acpi_video_device *dev = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1211 | char str[12] = { 0 }; |
| 1212 | u32 state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
Arjan van de Ven | 52a2b11 | 2009-10-01 15:48:40 -0700 | [diff] [blame] | 1215 | if (!dev || count >= sizeof(str)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1216 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (copy_from_user(str, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1219 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | str[count] = 0; |
| 1222 | state = simple_strtoul(str, NULL, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1223 | state &= ((1ul << 31) | (1ul << 30) | (1ul << 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | status = acpi_video_device_set_state(dev, state); |
| 1226 | |
| 1227 | if (status) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1228 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1230 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1234 | acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1236 | struct acpi_video_device *dev = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1237 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (!dev || !dev->brightness) { |
| 1241 | seq_printf(seq, "<not supported>\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1242 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | seq_printf(seq, "levels: "); |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 1246 | for (i = 2; i < dev->brightness->count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | seq_printf(seq, " %d", dev->brightness->levels[i]); |
| 1248 | seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr); |
| 1249 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1250 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1254 | acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | { |
| 1256 | return single_open(file, acpi_video_device_brightness_seq_show, |
| 1257 | PDE(inode)->data); |
| 1258 | } |
| 1259 | |
| 1260 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1261 | acpi_video_device_write_brightness(struct file *file, |
| 1262 | const char __user * buffer, |
| 1263 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1265 | struct seq_file *m = file->private_data; |
| 1266 | struct acpi_video_device *dev = m->private; |
Danny Baumann | c88c578 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 1267 | char str[5] = { 0 }; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1268 | unsigned int level = 0; |
| 1269 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
Arjan van de Ven | 52a2b11 | 2009-10-01 15:48:40 -0700 | [diff] [blame] | 1272 | if (!dev || !dev->brightness || count >= sizeof(str)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1273 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | if (copy_from_user(str, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1276 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | str[count] = 0; |
| 1279 | level = simple_strtoul(str, NULL, 0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | if (level > 100) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1282 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1284 | /* validate through the list of available levels */ |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 1285 | for (i = 2; i < dev->brightness->count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | if (level == dev->brightness->levels[i]) { |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 1287 | if (!acpi_video_device_lcd_set_level(dev, level)) |
| 1288 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | break; |
| 1290 | } |
| 1291 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 1292 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1295 | static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1297 | struct acpi_video_device *dev = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1298 | int status; |
| 1299 | int i; |
| 1300 | union acpi_object *edid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (!dev) |
| 1304 | goto out; |
| 1305 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1306 | status = acpi_video_device_EDID(dev, &edid, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1308 | status = acpi_video_device_EDID(dev, &edid, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | if (ACPI_FAILURE(status)) { |
| 1312 | goto out; |
| 1313 | } |
| 1314 | |
| 1315 | if (edid && edid->type == ACPI_TYPE_BUFFER) { |
| 1316 | for (i = 0; i < edid->buffer.length; i++) |
| 1317 | seq_putc(seq, edid->buffer.pointer[i]); |
| 1318 | } |
| 1319 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1320 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | if (!edid) |
| 1322 | seq_printf(seq, "<not supported>\n"); |
| 1323 | else |
| 1324 | kfree(edid); |
| 1325 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1326 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1330 | acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | { |
| 1332 | return single_open(file, acpi_video_device_EDID_seq_show, |
| 1333 | PDE(inode)->data); |
| 1334 | } |
| 1335 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1336 | static int acpi_video_device_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1338 | struct proc_dir_entry *entry, *device_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | struct acpi_video_device *vid_dev; |
| 1340 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1341 | vid_dev = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | if (!vid_dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1343 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1345 | device_dir = proc_mkdir(acpi_device_bid(device), |
| 1346 | vid_dev->video->dir); |
| 1347 | if (!device_dir) |
| 1348 | return -ENOMEM; |
| 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | /* 'info' [R] */ |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1351 | entry = proc_create_data("info", S_IRUGO, device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1352 | &acpi_video_device_info_fops, acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1354 | goto err_remove_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | |
| 1356 | /* 'state' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1357 | entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR, |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1358 | device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1359 | &acpi_video_device_state_fops, |
| 1360 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1362 | goto err_remove_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* 'brightness' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1365 | entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR, |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1366 | device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1367 | &acpi_video_device_brightness_fops, |
| 1368 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1370 | goto err_remove_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | /* 'EDID' [R] */ |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1373 | entry = proc_create_data("EDID", S_IRUGO, device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1374 | &acpi_video_device_EDID_fops, |
| 1375 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1377 | goto err_remove_brightness; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1379 | acpi_device_dir(device) = device_dir; |
| 1380 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1381 | return 0; |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1382 | |
| 1383 | err_remove_brightness: |
| 1384 | remove_proc_entry("brightness", device_dir); |
| 1385 | err_remove_state: |
| 1386 | remove_proc_entry("state", device_dir); |
| 1387 | err_remove_info: |
| 1388 | remove_proc_entry("info", device_dir); |
| 1389 | err_remove_dir: |
| 1390 | remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); |
| 1391 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1394 | static int acpi_video_device_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | { |
| 1396 | struct acpi_video_device *vid_dev; |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1397 | struct proc_dir_entry *device_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1399 | vid_dev = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1401 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1403 | device_dir = acpi_device_dir(device); |
| 1404 | if (device_dir) { |
| 1405 | remove_proc_entry("info", device_dir); |
| 1406 | remove_proc_entry("state", device_dir); |
| 1407 | remove_proc_entry("brightness", device_dir); |
| 1408 | remove_proc_entry("EDID", device_dir); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1409 | remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | acpi_device_dir(device) = NULL; |
| 1411 | } |
| 1412 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1413 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | /* video bus */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1417 | static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1419 | struct acpi_video_bus *video = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | |
| 1422 | if (!video) |
| 1423 | goto end; |
| 1424 | |
| 1425 | seq_printf(seq, "Switching heads: %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1426 | video->flags.multihead ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | seq_printf(seq, "Video ROM: %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1428 | video->flags.rom ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | seq_printf(seq, "Device to be POSTed on boot: %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1430 | video->flags.post ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1432 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1433 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1436 | static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1438 | return single_open(file, acpi_video_bus_info_seq_show, |
| 1439 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1442 | static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1444 | struct acpi_video_bus *video = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | if (!video) |
| 1448 | goto end; |
| 1449 | |
Harvey Harrison | 96b2dd1 | 2008-03-05 18:24:51 -0800 | [diff] [blame] | 1450 | printk(KERN_INFO PREFIX "Please implement %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | seq_printf(seq, "<TODO>\n"); |
| 1452 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1453 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1454 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1457 | static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
| 1459 | return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data); |
| 1460 | } |
| 1461 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1462 | static int |
| 1463 | acpi_video_bus_POST_options(struct acpi_video_bus *video, |
| 1464 | unsigned long long *options) |
| 1465 | { |
| 1466 | int status; |
| 1467 | |
| 1468 | status = acpi_evaluate_integer(video->device->handle, "_VPO", |
| 1469 | NULL, options); |
| 1470 | *options &= 3; |
| 1471 | |
| 1472 | return status; |
| 1473 | } |
| 1474 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1475 | static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1477 | struct acpi_video_bus *video = seq->private; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1478 | unsigned long long options; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1479 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | |
| 1482 | if (!video) |
| 1483 | goto end; |
| 1484 | |
| 1485 | status = acpi_video_bus_POST_options(video, &options); |
| 1486 | if (ACPI_SUCCESS(status)) { |
| 1487 | if (!(options & 1)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1488 | printk(KERN_WARNING PREFIX |
| 1489 | "The motherboard VGA device is not listed as a possible POST device.\n"); |
| 1490 | printk(KERN_WARNING PREFIX |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1491 | "This indicates a BIOS bug. Please contact the manufacturer.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 1493 | printk(KERN_WARNING "%llx\n", options); |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1494 | seq_printf(seq, "can POST: <integrated video>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | if (options & 2) |
| 1496 | seq_printf(seq, " <PCI video>"); |
| 1497 | if (options & 4) |
| 1498 | seq_printf(seq, " <AGP video>"); |
| 1499 | seq_putc(seq, '\n'); |
| 1500 | } else |
| 1501 | seq_printf(seq, "<not supported>\n"); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1502 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1503 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1507 | acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1509 | return single_open(file, acpi_video_bus_POST_info_seq_show, |
| 1510 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1513 | static int |
| 1514 | acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id) |
| 1515 | { |
| 1516 | int status; |
| 1517 | |
| 1518 | status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id); |
| 1519 | |
| 1520 | return status; |
| 1521 | } |
| 1522 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1523 | static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1525 | struct acpi_video_bus *video = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1526 | int status; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1527 | unsigned long long id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (!video) |
| 1531 | goto end; |
| 1532 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1533 | status = acpi_video_bus_get_POST(video, &id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | if (!ACPI_SUCCESS(status)) { |
| 1535 | seq_printf(seq, "<not supported>\n"); |
| 1536 | goto end; |
| 1537 | } |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1538 | seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1540 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1541 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1544 | static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1546 | struct acpi_video_bus *video = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1549 | seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1551 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1554 | static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1556 | return single_open(file, acpi_video_bus_POST_seq_show, |
| 1557 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1560 | static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | { |
| 1562 | return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data); |
| 1563 | } |
| 1564 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1565 | static int |
| 1566 | acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option) |
| 1567 | { |
| 1568 | int status; |
| 1569 | unsigned long long tmp; |
| 1570 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
| 1571 | struct acpi_object_list args = { 1, &arg0 }; |
| 1572 | |
| 1573 | |
| 1574 | arg0.integer.value = option; |
| 1575 | |
| 1576 | status = acpi_evaluate_integer(video->device->handle, "_SPD", |
| 1577 | &args, &tmp); |
| 1578 | if (ACPI_SUCCESS(status)) |
| 1579 | status = tmp ? (-EINVAL) : (AE_OK); |
| 1580 | |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1585 | acpi_video_bus_write_POST(struct file *file, |
| 1586 | const char __user * buffer, |
| 1587 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1589 | int status; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1590 | struct seq_file *m = file->private_data; |
| 1591 | struct acpi_video_bus *video = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1592 | char str[12] = { 0 }; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1593 | unsigned long long opt, options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Arjan van de Ven | 52a2b11 | 2009-10-01 15:48:40 -0700 | [diff] [blame] | 1596 | if (!video || count >= sizeof(str)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1597 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
| 1599 | status = acpi_video_bus_POST_options(video, &options); |
| 1600 | if (!ACPI_SUCCESS(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1601 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | |
| 1603 | if (copy_from_user(str, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1604 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | |
| 1606 | str[count] = 0; |
| 1607 | opt = strtoul(str, NULL, 0); |
| 1608 | if (opt > 3) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1609 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 1611 | /* just in case an OEM 'forgot' the motherboard... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | options |= 1; |
| 1613 | |
| 1614 | if (options & (1ul << opt)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1615 | status = acpi_video_bus_set_POST(video, opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | if (!ACPI_SUCCESS(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1617 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
| 1619 | } |
| 1620 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1621 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1625 | acpi_video_bus_write_DOS(struct file *file, |
| 1626 | const char __user * buffer, |
| 1627 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1629 | int status; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1630 | struct seq_file *m = file->private_data; |
| 1631 | struct acpi_video_bus *video = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1632 | char str[12] = { 0 }; |
| 1633 | unsigned long opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | |
Arjan van de Ven | 52a2b11 | 2009-10-01 15:48:40 -0700 | [diff] [blame] | 1636 | if (!video || count >= sizeof(str)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1637 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (copy_from_user(str, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1640 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
| 1642 | str[count] = 0; |
| 1643 | opt = strtoul(str, NULL, 0); |
| 1644 | if (opt > 7) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1645 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1647 | status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
| 1649 | if (!ACPI_SUCCESS(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1650 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1652 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1655 | static int acpi_video_bus_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1657 | struct acpi_video_bus *video = acpi_driver_data(device); |
| 1658 | struct proc_dir_entry *device_dir; |
| 1659 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1661 | device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir); |
| 1662 | if (!device_dir) |
| 1663 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | /* 'info' [R] */ |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1666 | entry = proc_create_data("info", S_IRUGO, device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1667 | &acpi_video_bus_info_fops, |
| 1668 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1670 | goto err_remove_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
| 1672 | /* 'ROM' [R] */ |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1673 | entry = proc_create_data("ROM", S_IRUGO, device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1674 | &acpi_video_bus_ROM_fops, |
| 1675 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1677 | goto err_remove_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | |
| 1679 | /* 'POST_info' [R] */ |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1680 | entry = proc_create_data("POST_info", S_IRUGO, device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1681 | &acpi_video_bus_POST_info_fops, |
| 1682 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1684 | goto err_remove_rom; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
| 1686 | /* 'POST' [R/W] */ |
Linus Torvalds | 08acd4f | 2008-04-30 11:52:52 -0700 | [diff] [blame] | 1687 | entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR, |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1688 | device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1689 | &acpi_video_bus_POST_fops, |
| 1690 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1692 | goto err_remove_post_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | |
| 1694 | /* 'DOS' [R/W] */ |
Linus Torvalds | 08acd4f | 2008-04-30 11:52:52 -0700 | [diff] [blame] | 1695 | entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR, |
Alexey Dobriyan | e0066c4e | 2008-05-01 04:10:02 +0400 | [diff] [blame] | 1696 | device_dir, |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1697 | &acpi_video_bus_DOS_fops, |
| 1698 | acpi_driver_data(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | if (!entry) |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1700 | goto err_remove_post; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1702 | video->dir = acpi_device_dir(device) = device_dir; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1703 | return 0; |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1704 | |
| 1705 | err_remove_post: |
| 1706 | remove_proc_entry("POST", device_dir); |
| 1707 | err_remove_post_info: |
| 1708 | remove_proc_entry("POST_info", device_dir); |
| 1709 | err_remove_rom: |
| 1710 | remove_proc_entry("ROM", device_dir); |
| 1711 | err_remove_info: |
| 1712 | remove_proc_entry("info", device_dir); |
| 1713 | err_remove_dir: |
| 1714 | remove_proc_entry(acpi_device_bid(device), acpi_video_dir); |
| 1715 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1718 | static int acpi_video_bus_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | { |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1720 | struct proc_dir_entry *device_dir = acpi_device_dir(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | |
Dmitry Torokhov | 251cb0b | 2007-11-05 11:43:34 -0500 | [diff] [blame] | 1722 | if (device_dir) { |
| 1723 | remove_proc_entry("info", device_dir); |
| 1724 | remove_proc_entry("ROM", device_dir); |
| 1725 | remove_proc_entry("POST_info", device_dir); |
| 1726 | remove_proc_entry("POST", device_dir); |
| 1727 | remove_proc_entry("DOS", device_dir); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1728 | remove_proc_entry(acpi_device_bid(device), acpi_video_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | acpi_device_dir(device) = NULL; |
| 1730 | } |
| 1731 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1732 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | } |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 1734 | #else |
| 1735 | static inline int acpi_video_device_add_fs(struct acpi_device *device) |
| 1736 | { |
| 1737 | return 0; |
| 1738 | } |
| 1739 | static inline int acpi_video_device_remove_fs(struct acpi_device *device) |
| 1740 | { |
| 1741 | return 0; |
| 1742 | } |
| 1743 | static inline int acpi_video_bus_add_fs(struct acpi_device *device) |
| 1744 | { |
| 1745 | return 0; |
| 1746 | } |
| 1747 | static inline int acpi_video_bus_remove_fs(struct acpi_device *device) |
| 1748 | { |
| 1749 | return 0; |
| 1750 | } |
| 1751 | #endif /* CONFIG_ACPI_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
| 1753 | /* -------------------------------------------------------------------------- |
| 1754 | Driver Interface |
| 1755 | -------------------------------------------------------------------------- */ |
| 1756 | |
| 1757 | /* device interface */ |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1758 | static struct acpi_video_device_attrib* |
| 1759 | acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id) |
| 1760 | { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1761 | struct acpi_video_enumerated_device *ids; |
| 1762 | int i; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1763 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1764 | for (i = 0; i < video->attached_count; i++) { |
| 1765 | ids = &video->attached_array[i]; |
| 1766 | if ((ids->value.int_val & 0xffff) == device_id) |
| 1767 | return &ids->value.attrib; |
| 1768 | } |
| 1769 | |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1770 | return NULL; |
| 1771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | |
| 1773 | static int |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1774 | acpi_video_get_device_type(struct acpi_video_bus *video, |
| 1775 | unsigned long device_id) |
| 1776 | { |
| 1777 | struct acpi_video_enumerated_device *ids; |
| 1778 | int i; |
| 1779 | |
| 1780 | for (i = 0; i < video->attached_count; i++) { |
| 1781 | ids = &video->attached_array[i]; |
| 1782 | if ((ids->value.int_val & 0xffff) == device_id) |
| 1783 | return ids->value.int_val; |
| 1784 | } |
| 1785 | |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
| 1789 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1790 | acpi_video_bus_get_one_device(struct acpi_device *device, |
| 1791 | struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 1793 | unsigned long long device_id; |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1794 | int status, device_type; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1795 | struct acpi_video_device *data; |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1796 | struct acpi_video_device_attrib* attribute; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
| 1798 | if (!device || !video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1799 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1801 | status = |
| 1802 | acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | if (ACPI_SUCCESS(status)) { |
| 1804 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1805 | data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | if (!data) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1807 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); |
| 1810 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1811 | device->driver_data = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
| 1813 | data->device_id = device_id; |
| 1814 | data->video = video; |
| 1815 | data->dev = device; |
| 1816 | |
Rui Zhang | 82cae99 | 2007-01-03 23:40:53 -0500 | [diff] [blame] | 1817 | attribute = acpi_video_get_device_attr(video, device_id); |
| 1818 | |
| 1819 | if((attribute != NULL) && attribute->device_id_scheme) { |
| 1820 | switch (attribute->display_type) { |
| 1821 | case ACPI_VIDEO_DISPLAY_CRT: |
| 1822 | data->flags.crt = 1; |
| 1823 | break; |
| 1824 | case ACPI_VIDEO_DISPLAY_TV: |
| 1825 | data->flags.tvout = 1; |
| 1826 | break; |
| 1827 | case ACPI_VIDEO_DISPLAY_DVI: |
| 1828 | data->flags.dvi = 1; |
| 1829 | break; |
| 1830 | case ACPI_VIDEO_DISPLAY_LCD: |
| 1831 | data->flags.lcd = 1; |
| 1832 | break; |
| 1833 | default: |
| 1834 | data->flags.unknown = 1; |
| 1835 | break; |
| 1836 | } |
| 1837 | if(attribute->bios_can_detect) |
| 1838 | data->flags.bios = 1; |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 1839 | } else { |
| 1840 | /* Check for legacy IDs */ |
| 1841 | device_type = acpi_video_get_device_type(video, |
| 1842 | device_id); |
| 1843 | /* Ignore bits 16 and 18-20 */ |
| 1844 | switch (device_type & 0xffe2ffff) { |
| 1845 | case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR: |
| 1846 | data->flags.crt = 1; |
| 1847 | break; |
| 1848 | case ACPI_VIDEO_DISPLAY_LEGACY_PANEL: |
| 1849 | data->flags.lcd = 1; |
| 1850 | break; |
| 1851 | case ACPI_VIDEO_DISPLAY_LEGACY_TV: |
| 1852 | data->flags.tvout = 1; |
| 1853 | break; |
| 1854 | default: |
| 1855 | data->flags.unknown = 1; |
| 1856 | } |
| 1857 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | acpi_video_device_bind(video, data); |
| 1860 | acpi_video_device_find_cap(data); |
| 1861 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1862 | status = acpi_install_notify_handler(device->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1863 | ACPI_DEVICE_NOTIFY, |
| 1864 | acpi_video_device_notify, |
| 1865 | data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | if (ACPI_FAILURE(status)) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 1867 | printk(KERN_ERR PREFIX |
| 1868 | "Error installing notify handler\n"); |
Yu, Luming | 973bf49 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 1869 | if(data->brightness) |
| 1870 | kfree(data->brightness->levels); |
| 1871 | kfree(data->brightness); |
| 1872 | kfree(data); |
| 1873 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1876 | mutex_lock(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | list_add_tail(&data->entry, &video->video_device_list); |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1878 | mutex_unlock(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
| 1880 | acpi_video_device_add_fs(device); |
| 1881 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1882 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1885 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /* |
| 1889 | * Arg: |
| 1890 | * video : video bus device |
| 1891 | * |
| 1892 | * Return: |
| 1893 | * none |
| 1894 | * |
| 1895 | * Enumerate the video device list of the video bus, |
| 1896 | * bind the ids with the corresponding video devices |
| 1897 | * under the video bus. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1898 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1900 | static void acpi_video_device_rebind(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | { |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1902 | struct acpi_video_device *dev; |
| 1903 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1904 | mutex_lock(&video->device_list_lock); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1905 | |
| 1906 | list_for_each_entry(dev, &video->video_device_list, entry) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1907 | acpi_video_device_bind(video, dev); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 1908 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 1909 | mutex_unlock(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | /* |
| 1913 | * Arg: |
| 1914 | * video : video bus device |
| 1915 | * device : video output device under the video |
| 1916 | * bus |
| 1917 | * |
| 1918 | * Return: |
| 1919 | * none |
| 1920 | * |
| 1921 | * Bind the ids with the corresponding video devices |
| 1922 | * under the video bus. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1923 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
| 1925 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1926 | acpi_video_device_bind(struct acpi_video_bus *video, |
| 1927 | struct acpi_video_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1929 | struct acpi_video_enumerated_device *ids; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1930 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1932 | for (i = 0; i < video->attached_count; i++) { |
| 1933 | ids = &video->attached_array[i]; |
| 1934 | if (device->device_id == (ids->value.int_val & 0xffff)) { |
| 1935 | ids->bind_info = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i)); |
| 1937 | } |
| 1938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /* |
| 1942 | * Arg: |
| 1943 | * video : video bus device |
| 1944 | * |
| 1945 | * Return: |
| 1946 | * < 0 : error |
| 1947 | * |
| 1948 | * Call _DOD to enumerate all devices attached to display adapter |
| 1949 | * |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1950 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | static int acpi_video_device_enumerate(struct acpi_video_bus *video) |
| 1953 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1954 | int status; |
| 1955 | int count; |
| 1956 | int i; |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1957 | struct acpi_video_enumerated_device *active_list; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1958 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 1959 | union acpi_object *dod = NULL; |
| 1960 | union acpi_object *obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 1962 | status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | if (!ACPI_SUCCESS(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1964 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1965 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1968 | dod = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 1970 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | status = -EFAULT; |
| 1972 | goto out; |
| 1973 | } |
| 1974 | |
| 1975 | 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] | 1976 | dod->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1978 | active_list = kcalloc(1 + dod->package.count, |
| 1979 | sizeof(struct acpi_video_enumerated_device), |
| 1980 | GFP_KERNEL); |
| 1981 | if (!active_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | status = -ENOMEM; |
| 1983 | goto out; |
| 1984 | } |
| 1985 | |
| 1986 | count = 0; |
| 1987 | for (i = 0; i < dod->package.count; i++) { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1988 | obj = &dod->package.elements[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | |
| 1990 | if (obj->type != ACPI_TYPE_INTEGER) { |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1991 | printk(KERN_ERR PREFIX |
| 1992 | "Invalid _DOD data in element %d\n", i); |
| 1993 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 1995 | |
| 1996 | active_list[count].value.int_val = obj->integer.value; |
| 1997 | active_list[count].bind_info = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1998 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i, |
| 1999 | (int)obj->integer.value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | count++; |
| 2001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 2003 | kfree(video->attached_array); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2004 | |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 2005 | video->attached_array = active_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | video->attached_count = count; |
Dmitry Torokhov | 78eed02 | 2007-11-05 11:43:33 -0500 | [diff] [blame] | 2007 | |
| 2008 | out: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 2009 | kfree(buffer.pointer); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2010 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2013 | static int |
| 2014 | acpi_video_get_next_level(struct acpi_video_device *device, |
| 2015 | u32 level_current, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | { |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 2017 | int min, max, min_above, max_below, i, l, delta = 255; |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 2018 | max = max_below = 0; |
| 2019 | min = min_above = 255; |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 2020 | /* Find closest level to level_current */ |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 2021 | for (i = 2; i < device->brightness->count; i++) { |
Alexey Starikovskiy | 63f0edf | 2007-09-03 16:30:08 +0400 | [diff] [blame] | 2022 | l = device->brightness->levels[i]; |
| 2023 | if (abs(l - level_current) < abs(delta)) { |
| 2024 | delta = l - level_current; |
| 2025 | if (!delta) |
| 2026 | break; |
| 2027 | } |
| 2028 | } |
| 2029 | /* Ajust level_current to closest available level */ |
| 2030 | level_current += delta; |
Zhao Yakui | 0a3db1c | 2009-02-02 11:33:41 +0800 | [diff] [blame] | 2031 | for (i = 2; i < device->brightness->count; i++) { |
Thomas Tuttle | f471518 | 2006-12-19 12:56:14 -0800 | [diff] [blame] | 2032 | l = device->brightness->levels[i]; |
| 2033 | if (l < min) |
| 2034 | min = l; |
| 2035 | if (l > max) |
| 2036 | max = l; |
| 2037 | if (l < min_above && l > level_current) |
| 2038 | min_above = l; |
| 2039 | if (l > max_below && l < level_current) |
| 2040 | max_below = l; |
| 2041 | } |
| 2042 | |
| 2043 | switch (event) { |
| 2044 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: |
| 2045 | return (level_current < max) ? min_above : min; |
| 2046 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: |
| 2047 | return (level_current < max) ? min_above : max; |
| 2048 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: |
| 2049 | return (level_current > min) ? max_below : min; |
| 2050 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: |
| 2051 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: |
| 2052 | return 0; |
| 2053 | default: |
| 2054 | return level_current; |
| 2055 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2058 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2059 | acpi_video_switch_brightness(struct acpi_video_device *device, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 2061 | unsigned long long level_current, level_next; |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2062 | int result = -EINVAL; |
| 2063 | |
Zhang Rui | 28c32e9 | 2009-07-13 10:33:24 +0800 | [diff] [blame] | 2064 | /* no warning message if acpi_backlight=vendor is used */ |
| 2065 | if (!acpi_video_backlight_support()) |
| 2066 | return 0; |
| 2067 | |
Julia Jomantaite | 469778c | 2008-06-23 22:50:42 +0100 | [diff] [blame] | 2068 | if (!device->brightness) |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2069 | goto out; |
| 2070 | |
| 2071 | result = acpi_video_device_lcd_get_level_current(device, |
Matthew Garrett | 70287db | 2010-02-16 16:53:50 -0500 | [diff] [blame] | 2072 | &level_current, 0); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2073 | if (result) |
| 2074 | goto out; |
| 2075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | level_next = acpi_video_get_next_level(device, level_current, event); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2077 | |
Zhang Rui | 24450c7 | 2009-03-18 16:27:10 +0800 | [diff] [blame] | 2078 | result = acpi_video_device_lcd_set_level(device, level_next); |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2079 | |
Matthew Garrett | 3634274 | 2009-07-14 17:06:03 +0100 | [diff] [blame] | 2080 | if (!result) |
| 2081 | backlight_force_update(device->backlight, |
| 2082 | BACKLIGHT_UPDATE_HOTKEY); |
| 2083 | |
Zhang Rui | c8890f9 | 2009-03-18 16:27:08 +0800 | [diff] [blame] | 2084 | out: |
| 2085 | if (result) |
| 2086 | printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); |
| 2087 | |
| 2088 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Matthew Garrett | e92a716 | 2010-01-12 14:17:03 -0500 | [diff] [blame] | 2091 | int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, |
| 2092 | void **edid) |
| 2093 | { |
| 2094 | struct acpi_video_bus *video; |
| 2095 | struct acpi_video_device *video_device; |
| 2096 | union acpi_object *buffer = NULL; |
| 2097 | acpi_status status; |
| 2098 | int i, length; |
| 2099 | |
| 2100 | if (!device || !acpi_driver_data(device)) |
| 2101 | return -EINVAL; |
| 2102 | |
| 2103 | video = acpi_driver_data(device); |
| 2104 | |
| 2105 | for (i = 0; i < video->attached_count; i++) { |
| 2106 | video_device = video->attached_array[i].bind_info; |
| 2107 | length = 256; |
| 2108 | |
| 2109 | if (!video_device) |
| 2110 | continue; |
| 2111 | |
| 2112 | if (type) { |
| 2113 | switch (type) { |
| 2114 | case ACPI_VIDEO_DISPLAY_CRT: |
| 2115 | if (!video_device->flags.crt) |
| 2116 | continue; |
| 2117 | break; |
| 2118 | case ACPI_VIDEO_DISPLAY_TV: |
| 2119 | if (!video_device->flags.tvout) |
| 2120 | continue; |
| 2121 | break; |
| 2122 | case ACPI_VIDEO_DISPLAY_DVI: |
| 2123 | if (!video_device->flags.dvi) |
| 2124 | continue; |
| 2125 | break; |
| 2126 | case ACPI_VIDEO_DISPLAY_LCD: |
| 2127 | if (!video_device->flags.lcd) |
| 2128 | continue; |
| 2129 | break; |
| 2130 | } |
| 2131 | } else if (video_device->device_id != device_id) { |
| 2132 | continue; |
| 2133 | } |
| 2134 | |
| 2135 | status = acpi_video_device_EDID(video_device, &buffer, length); |
| 2136 | |
| 2137 | if (ACPI_FAILURE(status) || !buffer || |
| 2138 | buffer->type != ACPI_TYPE_BUFFER) { |
| 2139 | length = 128; |
| 2140 | status = acpi_video_device_EDID(video_device, &buffer, |
| 2141 | length); |
| 2142 | if (ACPI_FAILURE(status) || !buffer || |
| 2143 | buffer->type != ACPI_TYPE_BUFFER) { |
| 2144 | continue; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | *edid = buffer->buffer.pointer; |
| 2149 | return length; |
| 2150 | } |
| 2151 | |
| 2152 | return -ENODEV; |
| 2153 | } |
| 2154 | EXPORT_SYMBOL(acpi_video_get_edid); |
| 2155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2157 | acpi_video_bus_get_devices(struct acpi_video_bus *video, |
| 2158 | struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2160 | int status = 0; |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2161 | struct acpi_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | |
| 2163 | acpi_video_device_enumerate(video); |
| 2164 | |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2165 | list_for_each_entry(dev, &device->children, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
| 2167 | status = acpi_video_bus_get_one_device(dev, video); |
| 2168 | if (ACPI_FAILURE(status)) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 2169 | printk(KERN_WARNING PREFIX |
Andi Kleen | cfa806f | 2010-07-20 15:18:36 -0700 | [diff] [blame] | 2170 | "Cant attach device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | continue; |
| 2172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2174 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2177 | 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] | 2178 | { |
Karol Kozimor | 031ec77 | 2005-07-30 04:18:00 -0400 | [diff] [blame] | 2179 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
| 2181 | if (!device || !device->video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2182 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | acpi_video_device_remove_fs(device->dev); |
| 2185 | |
Patrick Mochel | 9013026 | 2006-05-19 16:54:48 -0400 | [diff] [blame] | 2186 | status = acpi_remove_notify_handler(device->dev->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2187 | ACPI_DEVICE_NOTIFY, |
| 2188 | acpi_video_device_notify); |
Andi Kleen | cfa806f | 2010-07-20 15:18:36 -0700 | [diff] [blame] | 2189 | if (ACPI_FAILURE(status)) { |
| 2190 | printk(KERN_WARNING PREFIX |
| 2191 | "Cant remove video notify handler\n"); |
| 2192 | } |
Keith Packard | e29b3ee | 2009-08-06 15:57:54 -0700 | [diff] [blame] | 2193 | if (device->backlight) { |
| 2194 | sysfs_remove_link(&device->backlight->dev.kobj, "device"); |
| 2195 | backlight_device_unregister(device->backlight); |
| 2196 | device->backlight = NULL; |
| 2197 | } |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 2198 | if (device->cooling_dev) { |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 2199 | sysfs_remove_link(&device->dev->dev.kobj, |
| 2200 | "thermal_cooling"); |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 2201 | sysfs_remove_link(&device->cooling_dev->device.kobj, |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 2202 | "device"); |
Dmitry Torokhov | 4a703a8 | 2009-08-29 23:03:16 -0400 | [diff] [blame] | 2203 | thermal_cooling_device_unregister(device->cooling_dev); |
| 2204 | device->cooling_dev = NULL; |
Zhang Rui | 702ed51 | 2008-01-17 15:51:22 +0800 | [diff] [blame] | 2205 | } |
Luming Yu | 23b0f01 | 2007-05-09 21:07:05 +0800 | [diff] [blame] | 2206 | video_output_unregister(device->output_dev); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2207 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2208 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2211 | static int acpi_video_bus_put_devices(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2213 | int status; |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2214 | struct acpi_video_device *dev, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 2216 | mutex_lock(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2218 | list_for_each_entry_safe(dev, next, &video->video_device_list, entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2220 | status = acpi_video_bus_put_one_device(dev); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2221 | if (ACPI_FAILURE(status)) |
| 2222 | printk(KERN_WARNING PREFIX |
| 2223 | "hhuuhhuu bug in acpi video driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2225 | if (dev->brightness) { |
| 2226 | kfree(dev->brightness->levels); |
| 2227 | kfree(dev->brightness); |
| 2228 | } |
| 2229 | list_del(&dev->entry); |
| 2230 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 2233 | mutex_unlock(&video->device_list_lock); |
Dmitry Torokhov | ff102ea | 2007-11-05 11:43:31 -0500 | [diff] [blame] | 2234 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2235 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /* acpi_video interface */ |
| 2239 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2240 | static int acpi_video_bus_start_devices(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | { |
Zhang Rui | a21101c | 2007-09-14 11:46:22 +0800 | [diff] [blame] | 2242 | return acpi_video_bus_DOS(video, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2245 | static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | { |
| 2247 | return acpi_video_bus_DOS(video, 0, 1); |
| 2248 | } |
| 2249 | |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 2250 | static void acpi_video_bus_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | { |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 2252 | struct acpi_video_bus *video = acpi_driver_data(device); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2253 | struct input_dev *input; |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 2254 | int keycode = 0; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | if (!video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2257 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2259 | input = video->input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
| 2261 | switch (event) { |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 2262 | case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | * most likely via hotkey. */ |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 2264 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2265 | keycode = KEY_SWITCHVIDEOMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | break; |
| 2267 | |
Julius Volz | 98fb8fe | 2007-02-20 16:38:40 +0100 | [diff] [blame] | 2268 | case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | * connector. */ |
| 2270 | acpi_video_device_enumerate(video); |
| 2271 | acpi_video_device_rebind(video); |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 2272 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2273 | keycode = KEY_SWITCHVIDEOMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | break; |
| 2275 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2276 | case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */ |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2277 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2278 | keycode = KEY_SWITCHVIDEOMODE; |
| 2279 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2280 | case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */ |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2281 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2282 | keycode = KEY_VIDEO_NEXT; |
| 2283 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2284 | case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */ |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 2285 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2286 | keycode = KEY_VIDEO_PREV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | break; |
| 2288 | |
| 2289 | default: |
| 2290 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2291 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | |
Zhang Rui | 7761f63 | 2008-01-25 14:48:12 +0800 | [diff] [blame] | 2295 | acpi_notifier_call_chain(device, event, 0); |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 2296 | |
| 2297 | if (keycode) { |
| 2298 | input_report_key(input, keycode, 1); |
| 2299 | input_sync(input); |
| 2300 | input_report_key(input, keycode, 0); |
| 2301 | input_sync(input); |
| 2302 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2303 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2304 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2307 | 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] | 2308 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 2309 | struct acpi_video_device *video_device = data; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2310 | struct acpi_device *device = NULL; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2311 | struct acpi_video_bus *bus; |
| 2312 | struct input_dev *input; |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 2313 | int keycode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | if (!video_device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2316 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 2318 | device = video_device->dev; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2319 | bus = video_device->video; |
| 2320 | input = bus->input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | |
| 2322 | switch (event) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2323 | case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */ |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 2324 | if (brightness_switch_enabled) |
| 2325 | acpi_video_switch_brightness(video_device, event); |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2326 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2327 | keycode = KEY_BRIGHTNESS_CYCLE; |
| 2328 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2329 | case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */ |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 2330 | if (brightness_switch_enabled) |
| 2331 | acpi_video_switch_brightness(video_device, event); |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2332 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2333 | keycode = KEY_BRIGHTNESSUP; |
| 2334 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2335 | case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */ |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 2336 | if (brightness_switch_enabled) |
| 2337 | acpi_video_switch_brightness(video_device, event); |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2338 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2339 | keycode = KEY_BRIGHTNESSDOWN; |
| 2340 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2341 | case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */ |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 2342 | if (brightness_switch_enabled) |
| 2343 | acpi_video_switch_brightness(video_device, event); |
Len Brown | 25c87f7 | 2007-08-25 01:44:01 -0400 | [diff] [blame] | 2344 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2345 | keycode = KEY_BRIGHTNESS_ZERO; |
| 2346 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2347 | case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */ |
Zhang Rui | 8a681a4 | 2008-01-25 14:47:49 +0800 | [diff] [blame] | 2348 | if (brightness_switch_enabled) |
| 2349 | acpi_video_switch_brightness(video_device, event); |
Len Brown | 14e04fb | 2007-08-23 15:20:26 -0400 | [diff] [blame] | 2350 | acpi_bus_generate_proc_event(device, event, 0); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2351 | keycode = KEY_DISPLAY_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | break; |
| 2353 | default: |
| 2354 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2355 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | break; |
| 2357 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2358 | |
Zhang Rui | 7761f63 | 2008-01-25 14:48:12 +0800 | [diff] [blame] | 2359 | acpi_notifier_call_chain(device, event, 0); |
Matthew Garrett | 17c452f | 2009-12-11 17:40:46 -0500 | [diff] [blame] | 2360 | |
| 2361 | if (keycode) { |
| 2362 | input_report_key(input, keycode, 1); |
| 2363 | input_sync(input); |
| 2364 | input_report_key(input, keycode, 0); |
| 2365 | input_sync(input); |
| 2366 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2367 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2368 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2371 | static int acpi_video_resume(struct notifier_block *nb, |
| 2372 | unsigned long val, void *ign) |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 2373 | { |
| 2374 | struct acpi_video_bus *video; |
| 2375 | struct acpi_video_device *video_device; |
| 2376 | int i; |
| 2377 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2378 | switch (val) { |
| 2379 | case PM_HIBERNATION_PREPARE: |
| 2380 | case PM_SUSPEND_PREPARE: |
| 2381 | case PM_RESTORE_PREPARE: |
| 2382 | return NOTIFY_DONE; |
| 2383 | } |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 2384 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2385 | video = container_of(nb, struct acpi_video_bus, pm_nb); |
| 2386 | |
| 2387 | dev_info(&video->device->dev, "Restoring backlight state\n"); |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 2388 | |
| 2389 | for (i = 0; i < video->attached_count; i++) { |
| 2390 | video_device = video->attached_array[i].bind_info; |
| 2391 | if (video_device && video_device->backlight) |
| 2392 | acpi_video_set_brightness(video_device->backlight); |
| 2393 | } |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2394 | |
| 2395 | return NOTIFY_OK; |
Matthew Garrett | 863c149 | 2008-02-04 23:31:24 -0800 | [diff] [blame] | 2396 | } |
| 2397 | |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 2398 | static acpi_status |
| 2399 | acpi_video_bus_match(acpi_handle handle, u32 level, void *context, |
| 2400 | void **return_value) |
| 2401 | { |
| 2402 | struct acpi_device *device = context; |
| 2403 | struct acpi_device *sibling; |
| 2404 | int result; |
| 2405 | |
| 2406 | if (handle == device->handle) |
| 2407 | return AE_CTRL_TERMINATE; |
| 2408 | |
| 2409 | result = acpi_bus_get_device(handle, &sibling); |
| 2410 | if (result) |
| 2411 | return AE_OK; |
| 2412 | |
| 2413 | if (!strcmp(acpi_device_name(sibling), ACPI_VIDEO_BUS_NAME)) |
| 2414 | return AE_ALREADY_EXISTS; |
| 2415 | |
| 2416 | return AE_OK; |
| 2417 | } |
| 2418 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2419 | static int instance; |
| 2420 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2421 | static int acpi_video_bus_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | { |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2423 | struct acpi_video_bus *video; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2424 | struct input_dev *input; |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2425 | int error; |
Zhang Rui | c504f8c | 2009-12-30 15:59:23 +0800 | [diff] [blame] | 2426 | acpi_status status; |
| 2427 | |
| 2428 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, |
| 2429 | device->parent->handle, 1, |
| 2430 | acpi_video_bus_match, NULL, |
| 2431 | device, NULL); |
| 2432 | if (status == AE_ALREADY_EXISTS) { |
| 2433 | printk(KERN_WARNING FW_BUG |
| 2434 | "Duplicate ACPI video bus devices for the" |
| 2435 | " same VGA controller, please try module " |
| 2436 | "parameter \"video.allow_duplicates=1\"" |
| 2437 | "if the current driver doesn't work.\n"); |
| 2438 | if (!allow_duplicates) |
| 2439 | return -ENODEV; |
| 2440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 2442 | video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | if (!video) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2444 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
Zhang Rui | e6d9da1 | 2007-08-25 02:23:31 -0400 | [diff] [blame] | 2446 | /* a hack to fix the duplicate name "VID" problem on T61 */ |
| 2447 | if (!strcmp(device->pnp.bus_id, "VID")) { |
| 2448 | if (instance) |
| 2449 | device->pnp.bus_id[3] = '0' + instance; |
| 2450 | instance ++; |
| 2451 | } |
Zhao Yakui | f3b39f1 | 2009-02-02 22:55:01 -0500 | [diff] [blame] | 2452 | /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */ |
| 2453 | if (!strcmp(device->pnp.bus_id, "VGA")) { |
| 2454 | if (instance) |
| 2455 | device->pnp.bus_id[3] = '0' + instance; |
| 2456 | instance++; |
| 2457 | } |
Zhang Rui | e6d9da1 | 2007-08-25 02:23:31 -0400 | [diff] [blame] | 2458 | |
Patrick Mochel | e6afa0d | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 2459 | video->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); |
| 2461 | strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 2462 | device->driver_data = video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | |
| 2464 | acpi_video_bus_find_cap(video); |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2465 | error = acpi_video_bus_check(video); |
| 2466 | if (error) |
| 2467 | goto err_free_video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2469 | error = acpi_video_bus_add_fs(device); |
| 2470 | if (error) |
| 2471 | goto err_free_video; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
Dmitry Torokhov | bbac81f | 2007-11-05 11:43:32 -0500 | [diff] [blame] | 2473 | mutex_init(&video->device_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | INIT_LIST_HEAD(&video->video_device_list); |
| 2475 | |
| 2476 | acpi_video_bus_get_devices(video, device); |
| 2477 | acpi_video_bus_start_devices(video); |
| 2478 | |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2479 | video->input = input = input_allocate_device(); |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2480 | if (!input) { |
| 2481 | error = -ENOMEM; |
Bjorn Helgaas | 7015558 | 2009-04-07 15:37:11 +0000 | [diff] [blame] | 2482 | goto err_stop_video; |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2483 | } |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2484 | |
| 2485 | snprintf(video->phys, sizeof(video->phys), |
| 2486 | "%s/video/input0", acpi_device_hid(video->device)); |
| 2487 | |
| 2488 | input->name = acpi_device_name(video->device); |
| 2489 | input->phys = video->phys; |
| 2490 | input->id.bustype = BUS_HOST; |
| 2491 | input->id.product = 0x06; |
Dmitry Torokhov | 91c05c6 | 2007-11-05 11:43:29 -0500 | [diff] [blame] | 2492 | input->dev.parent = &device->dev; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2493 | input->evbit[0] = BIT(EV_KEY); |
| 2494 | set_bit(KEY_SWITCHVIDEOMODE, input->keybit); |
| 2495 | set_bit(KEY_VIDEO_NEXT, input->keybit); |
| 2496 | set_bit(KEY_VIDEO_PREV, input->keybit); |
| 2497 | set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit); |
| 2498 | set_bit(KEY_BRIGHTNESSUP, input->keybit); |
| 2499 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); |
| 2500 | set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); |
| 2501 | set_bit(KEY_DISPLAY_OFF, input->keybit); |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2502 | |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2503 | error = input_register_device(input); |
| 2504 | if (error) |
| 2505 | goto err_free_input_dev; |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | 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] | 2508 | ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), |
| 2509 | video->flags.multihead ? "yes" : "no", |
| 2510 | video->flags.rom ? "yes" : "no", |
| 2511 | video->flags.post ? "yes" : "no"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2513 | video->pm_nb.notifier_call = acpi_video_resume; |
| 2514 | video->pm_nb.priority = 0; |
| 2515 | register_pm_notifier(&video->pm_nb); |
| 2516 | |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2517 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2519 | err_free_input_dev: |
| 2520 | input_free_device(input); |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2521 | err_stop_video: |
| 2522 | acpi_video_bus_stop_devices(video); |
| 2523 | acpi_video_bus_put_devices(video); |
| 2524 | kfree(video->attached_array); |
| 2525 | acpi_video_bus_remove_fs(device); |
| 2526 | err_free_video: |
| 2527 | kfree(video); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 2528 | device->driver_data = NULL; |
Dmitry Torokhov | f51e839 | 2007-11-05 11:43:30 -0500 | [diff] [blame] | 2529 | |
| 2530 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2533 | static int acpi_video_bus_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2535 | struct acpi_video_bus *video = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | |
| 2538 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2539 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 2541 | video = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
Rafael J. Wysocki | ac7729d | 2010-04-05 01:43:51 +0200 | [diff] [blame] | 2543 | unregister_pm_notifier(&video->pm_nb); |
| 2544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | acpi_video_bus_stop_devices(video); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | acpi_video_bus_put_devices(video); |
| 2547 | acpi_video_bus_remove_fs(device); |
| 2548 | |
Luming Yu | e9dab19 | 2007-08-20 18:23:53 +0800 | [diff] [blame] | 2549 | input_unregister_device(video->input); |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 2550 | kfree(video->attached_array); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | kfree(video); |
| 2552 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2553 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2556 | static int __init intel_opregion_present(void) |
| 2557 | { |
| 2558 | #if defined(CONFIG_DRM_I915) || defined(CONFIG_DRM_I915_MODULE) |
| 2559 | struct pci_dev *dev = NULL; |
| 2560 | u32 address; |
| 2561 | |
| 2562 | for_each_pci_dev(dev) { |
| 2563 | if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 2564 | continue; |
| 2565 | if (dev->vendor != PCI_VENDOR_ID_INTEL) |
| 2566 | continue; |
| 2567 | pci_read_config_dword(dev, 0xfc, &address); |
| 2568 | if (!address) |
| 2569 | continue; |
| 2570 | return 1; |
| 2571 | } |
| 2572 | #endif |
| 2573 | return 0; |
| 2574 | } |
| 2575 | |
| 2576 | int acpi_video_register(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 2578 | int result = 0; |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2579 | if (register_count) { |
| 2580 | /* |
| 2581 | * if the function of acpi_video_register is already called, |
| 2582 | * don't register the acpi_vide_bus again and return no error. |
| 2583 | */ |
| 2584 | return 0; |
| 2585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 2587 | #ifdef CONFIG_ACPI_PROCFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); |
| 2589 | if (!acpi_video_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2590 | return -ENODEV; |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 2591 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | |
| 2593 | result = acpi_bus_register_driver(&acpi_video_bus); |
| 2594 | if (result < 0) { |
| 2595 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2596 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2599 | /* |
| 2600 | * When the acpi_video_bus is loaded successfully, increase |
| 2601 | * the counter reference. |
| 2602 | */ |
| 2603 | register_count = 1; |
| 2604 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2605 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2607 | EXPORT_SYMBOL(acpi_video_register); |
| 2608 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2609 | void acpi_video_unregister(void) |
| 2610 | { |
| 2611 | if (!register_count) { |
| 2612 | /* |
| 2613 | * If the acpi video bus is already unloaded, don't |
| 2614 | * unload it again and return directly. |
| 2615 | */ |
| 2616 | return; |
| 2617 | } |
| 2618 | acpi_bus_unregister_driver(&acpi_video_bus); |
| 2619 | |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 2620 | #ifdef CONFIG_ACPI_PROCFS |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2621 | remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); |
Zhang Rui | 6e37c65 | 2010-07-15 10:46:43 +0800 | [diff] [blame] | 2622 | #endif |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2623 | |
| 2624 | register_count = 0; |
| 2625 | |
| 2626 | return; |
| 2627 | } |
| 2628 | EXPORT_SYMBOL(acpi_video_unregister); |
| 2629 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2630 | /* |
| 2631 | * This is kind of nasty. Hardware using Intel chipsets may require |
| 2632 | * the video opregion code to be run first in order to initialise |
| 2633 | * state before any ACPI video calls are made. To handle this we defer |
| 2634 | * registration of the video class until the opregion code has run. |
| 2635 | */ |
| 2636 | |
| 2637 | static int __init acpi_video_init(void) |
| 2638 | { |
Zhang Rui | 45cb50e | 2009-04-24 12:13:18 -0400 | [diff] [blame] | 2639 | dmi_check_system(video_dmi_table); |
| 2640 | |
Matthew Garrett | 74a365b | 2009-03-19 21:35:39 +0000 | [diff] [blame] | 2641 | if (intel_opregion_present()) |
| 2642 | return 0; |
| 2643 | |
| 2644 | return acpi_video_register(); |
| 2645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2647 | static void __exit acpi_video_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | { |
Zhao Yakui | 86e437f | 2009-06-16 11:23:13 +0800 | [diff] [blame] | 2649 | acpi_video_unregister(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 2651 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
| 2654 | module_init(acpi_video_init); |
| 2655 | module_exit(acpi_video_exit); |