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