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