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