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