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