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