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