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