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