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