blob: 64c889331f3bd97be35ca4eeb0153e50aae74111 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Tuttlef4715182006-12-19 12:56:14 -08006 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 Torokhovbbac81f2007-11-05 11:43:32 -050032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
Luming Yue9dab192007-08-20 18:23:53 +080035#include <linux/input.h>
Yu Luming2f3d0002006-11-11 02:40:34 +080036#include <linux/backlight.h>
Zhang Rui702ed512008-01-17 15:51:22 +080037#include <linux/thermal.h>
Luming Yu23b0f012007-05-09 21:07:05 +080038#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/uaccess.h>
40
41#include <acpi/acpi_bus.h>
42#include <acpi/acpi_drivers.h>
43
44#define ACPI_VIDEO_COMPONENT 0x08000000
45#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define ACPI_VIDEO_BUS_NAME "Video Bus"
47#define ACPI_VIDEO_DEVICE_NAME "Video Device"
48#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49#define ACPI_VIDEO_NOTIFY_PROBE 0x81
50#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53
Thomas Tuttlef4715182006-12-19 12:56:14 -080054#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Yu Luming2f3d0002006-11-11 02:40:34 +080060#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Rui Zhang82cae992007-01-03 23:40:53 -050062#define ACPI_VIDEO_DISPLAY_CRT 1
63#define ACPI_VIDEO_DISPLAY_TV 2
64#define ACPI_VIDEO_DISPLAY_DVI 3
65#define ACPI_VIDEO_DISPLAY_LCD 4
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050068ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Len Brownf52fd662007-02-12 22:42:12 -050070MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050071MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_LICENSE("GPL");
73
Zhang Rui8a681a42008-01-25 14:47:49 +080074static int brightness_switch_enabled = 1;
75module_param(brightness_switch_enabled, bool, 0644);
76
Len Brown4be44fc2005-08-05 00:44:28 -040077static int acpi_video_bus_add(struct acpi_device *device);
78static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080079static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Thomas Renninger1ba90e32007-07-23 14:44:41 +020081static const struct acpi_device_id video_device_ids[] = {
82 {ACPI_VIDEO_HID, 0},
83 {"", 0},
84};
85MODULE_DEVICE_TABLE(acpi, video_device_ids);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static struct acpi_driver acpi_video_bus = {
Len Brownc2b6705b2007-02-12 23:33:40 -050088 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020090 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .ops = {
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080094 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040095 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040099 u8 multihead:1; /* can switch video heads */
100 u8 rom:1; /* can retrieve a video rom */
101 u8 post:1; /* can configure the head to */
102 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400106 u8 _DOS:1; /*Enable/Disable output switching */
107 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM:1; /*Get ROM Data */
109 u8 _GPD:1; /*Get POST Device */
110 u8 _SPD:1; /*Set POST Device */
111 u8 _VPO:1; /*Video POST Options */
112 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113};
114
Len Brown4be44fc2005-08-05 00:44:28 -0400115struct acpi_video_device_attrib {
116 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100117 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400118 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100119 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 u32 bios_can_detect:1; /*BIOS can detect the device */
121 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
122 the VGA device. */
123 u32 pipe_id:3; /*For VGA multiple-head devices. */
124 u32 reserved:10; /*Must be 0 */
125 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128struct acpi_video_enumerated_device {
129 union {
130 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400131 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 } value;
133 struct acpi_video_device *bind_info;
134};
135
136struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400137 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400138 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u8 attached_count;
141 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400143 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500144 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400145 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800146 struct input_dev *input;
147 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148};
149
150struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400151 u8 crt:1;
152 u8 lcd:1;
153 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500154 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400155 u8 bios:1;
156 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500157 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
160struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400161 u8 _ADR:1; /*Return the unique ID */
162 u8 _BCL:1; /*Query list of brightness control levels supported */
163 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800164 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400165 u8 _DDC:1; /*Return the EDID for this device */
166 u8 _DCS:1; /*Return status of output device */
167 u8 _DGS:1; /*Query graphics state */
168 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169};
170
171struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400172 int curr;
173 int count;
174 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
177struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400178 unsigned long device_id;
179 struct acpi_video_device_flags flags;
180 struct acpi_video_device_cap cap;
181 struct list_head entry;
182 struct acpi_video_bus *video;
183 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800185 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800186 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800187 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* bus */
191static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700193 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400194 .open = acpi_video_bus_info_open_fs,
195 .read = seq_read,
196 .llseek = seq_lseek,
197 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198};
199
200static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
201static struct file_operations acpi_video_bus_ROM_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700202 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400203 .open = acpi_video_bus_ROM_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static struct file_operations acpi_video_bus_POST_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700212 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .open = acpi_video_bus_POST_info_open_fs,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
219static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
220static struct file_operations acpi_video_bus_POST_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700221 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .open = acpi_video_bus_POST_open_fs,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226};
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
229static struct file_operations acpi_video_bus_DOS_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700230 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_bus_DOS_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
237/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400238static int acpi_video_device_info_open_fs(struct inode *inode,
239 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static struct file_operations acpi_video_device_info_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700241 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400242 .open = acpi_video_device_info_open_fs,
243 .read = seq_read,
244 .llseek = seq_lseek,
245 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246};
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248static int acpi_video_device_state_open_fs(struct inode *inode,
249 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250static struct file_operations acpi_video_device_state_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700251 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400252 .open = acpi_video_device_state_open_fs,
253 .read = seq_read,
254 .llseek = seq_lseek,
255 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_video_device_brightness_open_fs(struct inode *inode,
259 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static struct file_operations acpi_video_device_brightness_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700261 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400262 .open = acpi_video_device_brightness_open_fs,
263 .read = seq_read,
264 .llseek = seq_lseek,
265 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266};
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268static int acpi_video_device_EDID_open_fs(struct inode *inode,
269 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270static struct file_operations acpi_video_device_EDID_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700271 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400272 .open = acpi_video_device_EDID_open_fs,
273 .read = seq_read,
274 .llseek = seq_lseek,
275 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 "motherboard VGA device",
280 "PCI VGA device",
281 "AGP VGA device",
282 "UNKNOWN",
283};
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
286static void acpi_video_device_rebind(struct acpi_video_bus *video);
287static void acpi_video_device_bind(struct acpi_video_bus *video,
288 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800290static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
291 int level);
292static int acpi_video_device_lcd_get_level_current(
293 struct acpi_video_device *device,
294 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400295static int acpi_video_get_next_level(struct acpi_video_device *device,
296 u32 level_current, u32 event);
297static void acpi_video_switch_brightness(struct acpi_video_device *device,
298 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800299static int acpi_video_device_get_state(struct acpi_video_device *device,
300 unsigned long *state);
301static int acpi_video_output_get(struct output_device *od);
302static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Yu Luming2f3d0002006-11-11 02:40:34 +0800304/*backlight device sysfs support*/
305static int acpi_video_get_brightness(struct backlight_device *bd)
306{
307 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000308 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800309 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100310 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800311 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000312 for (i = 2; i < vd->brightness->count; i++) {
313 if (vd->brightness->levels[i] == cur_level)
314 /* The first two entries are special - see page 575
315 of the ACPI spec 3.0 */
316 return i-2;
317 }
318 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800319}
320
321static int acpi_video_set_brightness(struct backlight_device *bd)
322{
Matthew Garrett38531e62007-12-26 02:03:26 +0000323 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800324 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100325 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000326 acpi_video_device_lcd_set_level(vd,
327 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800328 return 0;
329}
330
Richard Purdie599a52d2007-02-10 23:07:48 +0000331static struct backlight_ops acpi_backlight_ops = {
332 .get_brightness = acpi_video_get_brightness,
333 .update_status = acpi_video_set_brightness,
334};
335
Luming Yu23b0f012007-05-09 21:07:05 +0800336/*video output device sysfs support*/
337static int acpi_video_output_get(struct output_device *od)
338{
339 unsigned long state;
340 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700341 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800342 acpi_video_device_get_state(vd, &state);
343 return (int)state;
344}
345
346static int acpi_video_output_set(struct output_device *od)
347{
348 unsigned long state = od->request_state;
349 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700350 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800351 return acpi_video_device_set_state(vd, state);
352}
353
354static struct output_properties acpi_output_properties = {
355 .set_state = acpi_video_output_set,
356 .get_status = acpi_video_output_get,
357};
Zhang Rui702ed512008-01-17 15:51:22 +0800358
359
360/* thermal cooling device callbacks */
361static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
362{
363 struct acpi_device *device = cdev->devdata;
364 struct acpi_video_device *video = acpi_driver_data(device);
365
366 return sprintf(buf, "%d\n", video->brightness->count - 3);
367}
368
369static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
370{
371 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device);
373 unsigned long level;
374 int state;
375
376 acpi_video_device_lcd_get_level_current(video, &level);
377 for (state = 2; state < video->brightness->count; state++)
378 if (level == video->brightness->levels[state])
379 return sprintf(buf, "%d\n",
380 video->brightness->count - state - 1);
381
382 return -EINVAL;
383}
384
385static int
386video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
387{
388 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device);
390 int level;
391
392 if ( state >= video->brightness->count - 2)
393 return -EINVAL;
394
395 state = video->brightness->count - state;
396 level = video->brightness->levels[state -1];
397 return acpi_video_device_lcd_set_level(video, level);
398}
399
400static struct thermal_cooling_device_ops video_cooling_ops = {
401 .get_max_state = video_get_max_state,
402 .get_cur_state = video_get_cur_state,
403 .set_cur_state = video_set_cur_state,
404};
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/* --------------------------------------------------------------------------
407 Video Management
408 -------------------------------------------------------------------------- */
409
410/* device */
411
412static int
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Len Brown4be44fc2005-08-05 00:44:28 -0400415 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400416
417 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Patrick Mocheld550d982006-06-27 00:41:40 -0400419 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422static int
Len Brown4be44fc2005-08-05 00:44:28 -0400423acpi_video_device_get_state(struct acpi_video_device *device,
424 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Len Brown4be44fc2005-08-05 00:44:28 -0400426 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Patrick Mochel90130262006-05-19 16:54:48 -0400428 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Patrick Mocheld550d982006-06-27 00:41:40 -0400430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
433static int
Len Brown4be44fc2005-08-05 00:44:28 -0400434acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Len Brown4be44fc2005-08-05 00:44:28 -0400436 int status;
437 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
438 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400439 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400443 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Patrick Mocheld550d982006-06-27 00:41:40 -0400445 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448static int
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
450 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Len Brown4be44fc2005-08-05 00:44:28 -0400452 int status;
453 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
454 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 *levels = NULL;
458
Patrick Mochel90130262006-05-19 16:54:48 -0400459 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400462 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500463 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400464 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 status = -EFAULT;
466 goto err;
467 }
468
469 *levels = obj;
470
Patrick Mocheld550d982006-06-27 00:41:40 -0400471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Len Brown4be44fc2005-08-05 00:44:28 -0400473 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800474 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
479static int
Len Brown4be44fc2005-08-05 00:44:28 -0400480acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400482 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400483 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
484 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400489 if (device->cap._BCM)
490 status = acpi_evaluate_object(device->dev->handle, "_BCM",
491 &args, NULL);
492 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400493 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496static int
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
498 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400500 if (device->cap._BQC)
501 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
502 level);
503 *level = device->brightness->curr;
504 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507static int
Len Brown4be44fc2005-08-05 00:44:28 -0400508acpi_video_device_EDID(struct acpi_video_device *device,
509 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Len Brown4be44fc2005-08-05 00:44:28 -0400511 int status;
512 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
513 union acpi_object *obj;
514 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
515 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 *edid = NULL;
519
520 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (length == 128)
523 arg0.integer.value = 1;
524 else if (length == 256)
525 arg0.integer.value = 2;
526 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Patrick Mochel90130262006-05-19 16:54:48 -0400529 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200533 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 if (obj && obj->type == ACPI_TYPE_BUFFER)
536 *edid = obj;
537 else {
Len Brown64684632006-06-26 23:41:38 -0400538 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 status = -EFAULT;
540 kfree(obj);
541 }
542
Patrick Mocheld550d982006-06-27 00:41:40 -0400543 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546/* bus */
547
548static int
Len Brown4be44fc2005-08-05 00:44:28 -0400549acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551 int status;
552 unsigned long tmp;
553 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
554 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 arg0.integer.value = option;
558
Patrick Mochel90130262006-05-19 16:54:48 -0400559 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400561 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Patrick Mocheld550d982006-06-27 00:41:40 -0400563 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static int
Len Brown4be44fc2005-08-05 00:44:28 -0400567acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
569 int status;
570
Patrick Mochel90130262006-05-19 16:54:48 -0400571 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576static int
Len Brown4be44fc2005-08-05 00:44:28 -0400577acpi_video_bus_POST_options(struct acpi_video_bus *video,
578 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown4be44fc2005-08-05 00:44:28 -0400580 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Patrick Mochel90130262006-05-19 16:54:48 -0400582 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 *options &= 3;
584
Patrick Mocheld550d982006-06-27 00:41:40 -0400585 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
588/*
589 * Arg:
590 * video : video bus device pointer
591 * bios_flag :
592 * 0. The system BIOS should NOT automatically switch(toggle)
593 * the active display output.
594 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * 2. The _DGS value should be locked.
597 * 3. The system BIOS should not automatically switch (toggle) the
598 * active display output, but instead generate the display switch
599 * event notify code.
600 * lcd_flag :
601 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100602 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100604 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 * Return Value:
606 * -1 wrong arg.
607 */
608
609static int
Len Brown4be44fc2005-08-05 00:44:28 -0400610acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Len Brown4be44fc2005-08-05 00:44:28 -0400612 acpi_integer status = 0;
613 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
614 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 status = -1;
619 goto Failed;
620 }
621 arg0.integer.value = (lcd_flag << 2) | bios_flag;
622 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400623 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400626 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
629/*
630 * Arg:
631 * device : video output device (LCD, CRT, ..)
632 *
633 * Return Value:
Julia Jomantaite469778c2008-06-23 22:50:42 +0100634 * Maximum brightness level
635 *
636 * Allocate and initialize device->brightness.
637 */
638
639static int
640acpi_video_init_brightness(struct acpi_video_device *device)
641{
642 union acpi_object *obj = NULL;
643 int i, max_level = 0, count = 0;
644 union acpi_object *o;
645 struct acpi_video_device_brightness *br = NULL;
646
647 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
648 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
649 "LCD brightness level\n"));
650 goto out;
651 }
652
653 if (obj->package.count < 2)
654 goto out;
655
656 br = kzalloc(sizeof(*br), GFP_KERNEL);
657 if (!br) {
658 printk(KERN_ERR "can't allocate memory\n");
659 goto out;
660 }
661
662 br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
663 GFP_KERNEL);
664 if (!br->levels)
665 goto out_free;
666
667 for (i = 0; i < obj->package.count; i++) {
668 o = (union acpi_object *)&obj->package.elements[i];
669 if (o->type != ACPI_TYPE_INTEGER) {
670 printk(KERN_ERR PREFIX "Invalid data\n");
671 continue;
672 }
673 br->levels[count] = (u32) o->integer.value;
674
675 if (br->levels[count] > max_level)
676 max_level = br->levels[count];
677 count++;
678 }
679
680 if (count < 2)
681 goto out_free_levels;
682
683 br->count = count;
684 device->brightness = br;
685 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
686 kfree(obj);
687 return max_level;
688
689out_free_levels:
690 kfree(br->levels);
691out_free:
692 kfree(br);
693out:
694 device->brightness = NULL;
695 kfree(obj);
696 return 0;
697}
698
699/*
700 * Arg:
701 * device : video output device (LCD, CRT, ..)
702 *
703 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 * None
705 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100706 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 * device.
708 */
709
Len Brown4be44fc2005-08-05 00:44:28 -0400710static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 acpi_handle h_dummy1;
Yu Luming2f3d0002006-11-11 02:40:34 +0800713 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
William Lee Irwin III98934de2007-12-12 03:56:55 -0800716 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Patrick Mochel90130262006-05-19 16:54:48 -0400718 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 device->cap._ADR = 1;
720 }
Patrick Mochel90130262006-05-19 16:54:48 -0400721 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400722 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
Patrick Mochel90130262006-05-19 16:54:48 -0400724 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400725 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800727 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
728 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400729 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400730 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 }
Patrick Mochel90130262006-05-19 16:54:48 -0400732 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 device->cap._DCS = 1;
734 }
Patrick Mochel90130262006-05-19 16:54:48 -0400735 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 device->cap._DGS = 1;
737 }
Patrick Mochel90130262006-05-19 16:54:48 -0400738 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 device->cap._DSS = 1;
740 }
741
Julia Jomantaite469778c2008-06-23 22:50:42 +0100742 max_level = acpi_video_init_brightness(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Linus Torvalds797de7b2008-04-05 12:14:13 -0700744 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Zhang Rui702ed512008-01-17 15:51:22 +0800745 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800746 static int count = 0;
747 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800748 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
749 if (!name)
750 return;
751
Yu Luming2f3d0002006-11-11 02:40:34 +0800752 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800753 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000754 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000755 device->backlight->props.max_brightness = device->brightness->count-3;
756 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000757 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800758 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800759
760 device->cdev = thermal_cooling_device_register("LCD",
761 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500762 if (IS_ERR(device->cdev))
763 return;
764
Julia Lawall90300622008-04-11 10:09:24 +0800765 printk(KERN_INFO PREFIX
766 "%s is registered as cooling_device%d\n",
767 device->dev->dev.bus_id, device->cdev->id);
768 result = sysfs_create_link(&device->dev->dev.kobj,
769 &device->cdev->device.kobj,
770 "thermal_cooling");
771 if (result)
772 printk(KERN_ERR PREFIX "Create sysfs link\n");
773 result = sysfs_create_link(&device->cdev->device.kobj,
774 &device->dev->dev.kobj, "device");
775 if (result)
776 printk(KERN_ERR PREFIX "Create sysfs link\n");
777
Yu Luming2f3d0002006-11-11 02:40:34 +0800778 }
Luming Yu23b0f012007-05-09 21:07:05 +0800779 if (device->cap._DCS && device->cap._DSS){
780 static int count = 0;
781 char *name;
782 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
783 if (!name)
784 return;
785 sprintf(name, "acpi_video%d", count++);
786 device->output_dev = video_output_register(name,
787 NULL, device, &acpi_output_properties);
788 kfree(name);
789 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400790 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
792
793/*
794 * Arg:
795 * device : video output device (VGA)
796 *
797 * Return Value:
798 * None
799 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100800 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 */
802
Len Brown4be44fc2005-08-05 00:44:28 -0400803static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Len Brown4be44fc2005-08-05 00:44:28 -0400805 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
William Lee Irwin III98934de2007-12-12 03:56:55 -0800807 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400808 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 video->cap._DOS = 1;
810 }
Patrick Mochel90130262006-05-19 16:54:48 -0400811 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 video->cap._DOD = 1;
813 }
Patrick Mochel90130262006-05-19 16:54:48 -0400814 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 video->cap._ROM = 1;
816 }
Patrick Mochel90130262006-05-19 16:54:48 -0400817 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 video->cap._GPD = 1;
819 }
Patrick Mochel90130262006-05-19 16:54:48 -0400820 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 video->cap._SPD = 1;
822 }
Patrick Mochel90130262006-05-19 16:54:48 -0400823 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 video->cap._VPO = 1;
825 }
826}
827
828/*
829 * Check whether the video bus device has required AML method to
830 * support the desired features
831 */
832
Len Brown4be44fc2005-08-05 00:44:28 -0400833static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Len Brown4be44fc2005-08-05 00:44:28 -0400835 acpi_status status = -ENOENT;
Len Brownf0d67522008-03-18 01:43:53 -0400836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400839 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 /* Since there is no HID, CID and so on for VGA driver, we have
842 * to check well known required nodes.
843 */
844
Julius Volz98fb8fe2007-02-20 16:38:40 +0100845 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400846 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 video->flags.multihead = 1;
848 status = 0;
849 }
850
Julius Volz98fb8fe2007-02-20 16:38:40 +0100851 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400852 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 video->flags.rom = 1;
854 status = 0;
855 }
856
Julius Volz98fb8fe2007-02-20 16:38:40 +0100857 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400858 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 video->flags.post = 1;
860 status = 0;
861 }
862
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
866/* --------------------------------------------------------------------------
867 FS Interface (/proc)
868 -------------------------------------------------------------------------- */
869
Len Brown4be44fc2005-08-05 00:44:28 -0400870static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872/* video devices */
873
Len Brown4be44fc2005-08-05 00:44:28 -0400874static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200876 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 if (!dev)
880 goto end;
881
882 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
883 seq_printf(seq, "type: ");
884 if (dev->flags.crt)
885 seq_printf(seq, "CRT\n");
886 else if (dev->flags.lcd)
887 seq_printf(seq, "LCD\n");
888 else if (dev->flags.tvout)
889 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500890 else if (dev->flags.dvi)
891 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 else
893 seq_printf(seq, "UNKNOWN\n");
894
Len Brown4be44fc2005-08-05 00:44:28 -0400895 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Len Brown4be44fc2005-08-05 00:44:28 -0400897 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400898 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901static int
Len Brown4be44fc2005-08-05 00:44:28 -0400902acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
904 return single_open(file, acpi_video_device_info_seq_show,
905 PDE(inode)->data);
906}
907
Len Brown4be44fc2005-08-05 00:44:28 -0400908static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Len Brown4be44fc2005-08-05 00:44:28 -0400910 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200911 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400912 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 if (!dev)
916 goto end;
917
918 status = acpi_video_device_get_state(dev, &state);
919 seq_printf(seq, "state: ");
920 if (ACPI_SUCCESS(status))
921 seq_printf(seq, "0x%02lx\n", state);
922 else
923 seq_printf(seq, "<not supported>\n");
924
925 status = acpi_video_device_query(dev, &state);
926 seq_printf(seq, "query: ");
927 if (ACPI_SUCCESS(status))
928 seq_printf(seq, "0x%02lx\n", state);
929 else
930 seq_printf(seq, "<not supported>\n");
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400933 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
936static int
Len Brown4be44fc2005-08-05 00:44:28 -0400937acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
939 return single_open(file, acpi_video_device_state_seq_show,
940 PDE(inode)->data);
941}
942
943static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400944acpi_video_device_write_state(struct file *file,
945 const char __user * buffer,
946 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Len Brown4be44fc2005-08-05 00:44:28 -0400948 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200949 struct seq_file *m = file->private_data;
950 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400951 char str[12] = { 0 };
952 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400956 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400959 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 str[count] = 0;
962 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400963 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 status = acpi_video_device_set_state(dev, state);
966
967 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400968 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Patrick Mocheld550d982006-06-27 00:41:40 -0400970 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
972
973static int
Len Brown4be44fc2005-08-05 00:44:28 -0400974acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200976 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400977 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 if (!dev || !dev->brightness) {
981 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400982 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
984
985 seq_printf(seq, "levels: ");
986 for (i = 0; i < dev->brightness->count; i++)
987 seq_printf(seq, " %d", dev->brightness->levels[i]);
988 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
989
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991}
992
993static int
Len Brown4be44fc2005-08-05 00:44:28 -0400994acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
996 return single_open(file, acpi_video_device_brightness_seq_show,
997 PDE(inode)->data);
998}
999
1000static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001001acpi_video_device_write_brightness(struct file *file,
1002 const char __user * buffer,
1003 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001005 struct seq_file *m = file->private_data;
1006 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +01001007 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -04001008 unsigned int level = 0;
1009 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Thomas Renninger59d399d2005-11-08 05:27:00 -05001012 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001013 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001016 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 str[count] = 0;
1019 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -04001020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -04001022 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Julius Volz98fb8fe2007-02-20 16:38:40 +01001024 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 for (i = 0; i < dev->brightness->count; i++)
1026 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001027 if (ACPI_SUCCESS
1028 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 dev->brightness->curr = level;
1030 break;
1031 }
1032
Patrick Mocheld550d982006-06-27 00:41:40 -04001033 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
Len Brown4be44fc2005-08-05 00:44:28 -04001036static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001038 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001039 int status;
1040 int i;
1041 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 if (!dev)
1045 goto out;
1046
Len Brown4be44fc2005-08-05 00:44:28 -04001047 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001049 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051
1052 if (ACPI_FAILURE(status)) {
1053 goto out;
1054 }
1055
1056 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1057 for (i = 0; i < edid->buffer.length; i++)
1058 seq_putc(seq, edid->buffer.pointer[i]);
1059 }
1060
Len Brown4be44fc2005-08-05 00:44:28 -04001061 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if (!edid)
1063 seq_printf(seq, "<not supported>\n");
1064 else
1065 kfree(edid);
1066
Patrick Mocheld550d982006-06-27 00:41:40 -04001067 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068}
1069
1070static int
Len Brown4be44fc2005-08-05 00:44:28 -04001071acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
1073 return single_open(file, acpi_video_device_EDID_seq_show,
1074 PDE(inode)->data);
1075}
1076
Len Brown4be44fc2005-08-05 00:44:28 -04001077static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001079 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 struct acpi_video_device *vid_dev;
1081
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001082 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001084 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001086 device_dir = proc_mkdir(acpi_device_bid(device),
1087 vid_dev->video->dir);
1088 if (!device_dir)
1089 return -ENOMEM;
1090
1091 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001094 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001095 &acpi_video_device_info_fops, acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001097 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 /* 'state' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001100 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1101 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001102 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001103 &acpi_video_device_state_fops,
1104 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001106 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 /* 'brightness' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001109 acpi_video_device_brightness_fops.write =
1110 acpi_video_device_write_brightness;
1111 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001112 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001113 &acpi_video_device_brightness_fops,
1114 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001116 goto err_remove_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 /* 'EDID' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001119 entry = proc_create_data("EDID", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001120 &acpi_video_device_EDID_fops,
1121 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001123 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001125 acpi_device_dir(device) = device_dir;
1126
Patrick Mocheld550d982006-06-27 00:41:40 -04001127 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001128
1129 err_remove_brightness:
1130 remove_proc_entry("brightness", device_dir);
1131 err_remove_state:
1132 remove_proc_entry("state", device_dir);
1133 err_remove_info:
1134 remove_proc_entry("info", device_dir);
1135 err_remove_dir:
1136 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1137 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
Len Brown4be44fc2005-08-05 00:44:28 -04001140static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
1142 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001143 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001145 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001147 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001149 device_dir = acpi_device_dir(device);
1150 if (device_dir) {
1151 remove_proc_entry("info", device_dir);
1152 remove_proc_entry("state", device_dir);
1153 remove_proc_entry("brightness", device_dir);
1154 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001155 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 acpi_device_dir(device) = NULL;
1157 }
1158
Patrick Mocheld550d982006-06-27 00:41:40 -04001159 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001163static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001165 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 if (!video)
1169 goto end;
1170
1171 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001172 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001174 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001176 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Len Brown4be44fc2005-08-05 00:44:28 -04001178 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Len Brown4be44fc2005-08-05 00:44:28 -04001182static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Len Brown4be44fc2005-08-05 00:44:28 -04001184 return single_open(file, acpi_video_bus_info_seq_show,
1185 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Len Brown4be44fc2005-08-05 00:44:28 -04001188static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001190 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 if (!video)
1194 goto end;
1195
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001196 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 seq_printf(seq, "<TODO>\n");
1198
Len Brown4be44fc2005-08-05 00:44:28 -04001199 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001200 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Len Brown4be44fc2005-08-05 00:44:28 -04001203static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
1205 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1206}
1207
Len Brown4be44fc2005-08-05 00:44:28 -04001208static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001210 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001211 unsigned long options;
1212 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 if (!video)
1216 goto end;
1217
1218 status = acpi_video_bus_POST_options(video, &options);
1219 if (ACPI_SUCCESS(status)) {
1220 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001221 printk(KERN_WARNING PREFIX
1222 "The motherboard VGA device is not listed as a possible POST device.\n");
1223 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001224 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 }
1226 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001227 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 if (options & 2)
1229 seq_printf(seq, " <PCI video>");
1230 if (options & 4)
1231 seq_printf(seq, " <AGP video>");
1232 seq_putc(seq, '\n');
1233 } else
1234 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001235 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001236 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
1239static int
Len Brown4be44fc2005-08-05 00:44:28 -04001240acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Len Brown4be44fc2005-08-05 00:44:28 -04001242 return single_open(file, acpi_video_bus_POST_info_seq_show,
1243 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Len Brown4be44fc2005-08-05 00:44:28 -04001246static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001248 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001249 int status;
1250 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 if (!video)
1254 goto end;
1255
Len Brown4be44fc2005-08-05 00:44:28 -04001256 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (!ACPI_SUCCESS(status)) {
1258 seq_printf(seq, "<not supported>\n");
1259 goto end;
1260 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001261 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Len Brown4be44fc2005-08-05 00:44:28 -04001263 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001264 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Len Brown4be44fc2005-08-05 00:44:28 -04001267static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001269 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Len Brown4be44fc2005-08-05 00:44:28 -04001272 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Patrick Mocheld550d982006-06-27 00:41:40 -04001274 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
Len Brown4be44fc2005-08-05 00:44:28 -04001277static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278{
Len Brown4be44fc2005-08-05 00:44:28 -04001279 return single_open(file, acpi_video_bus_POST_seq_show,
1280 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Len Brown4be44fc2005-08-05 00:44:28 -04001283static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
1285 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1286}
1287
1288static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001289acpi_video_bus_write_POST(struct file *file,
1290 const char __user * buffer,
1291 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Len Brown4be44fc2005-08-05 00:44:28 -04001293 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001294 struct seq_file *m = file->private_data;
1295 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001296 char str[12] = { 0 };
1297 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001301 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 status = acpi_video_bus_POST_options(video, &options);
1304 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001305 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001308 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 str[count] = 0;
1311 opt = strtoul(str, NULL, 0);
1312 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001313 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Julius Volz98fb8fe2007-02-20 16:38:40 +01001315 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 options |= 1;
1317
1318 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001319 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001321 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 }
1324
Patrick Mocheld550d982006-06-27 00:41:40 -04001325 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001329acpi_video_bus_write_DOS(struct file *file,
1330 const char __user * buffer,
1331 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
Len Brown4be44fc2005-08-05 00:44:28 -04001333 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001334 struct seq_file *m = file->private_data;
1335 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001336 char str[12] = { 0 };
1337 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001341 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001344 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 str[count] = 0;
1347 opt = strtoul(str, NULL, 0);
1348 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001349 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Len Brown4be44fc2005-08-05 00:44:28 -04001351 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001354 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Patrick Mocheld550d982006-06-27 00:41:40 -04001356 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
Len Brown4be44fc2005-08-05 00:44:28 -04001359static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001361 struct acpi_video_bus *video = acpi_driver_data(device);
1362 struct proc_dir_entry *device_dir;
1363 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001365 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1366 if (!device_dir)
1367 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001369 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 /* 'info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001372 entry = proc_create_data("info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001373 &acpi_video_bus_info_fops,
1374 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001376 goto err_remove_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 /* 'ROM' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001379 entry = proc_create_data("ROM", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001380 &acpi_video_bus_ROM_fops,
1381 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001383 goto err_remove_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 /* 'POST_info' [R] */
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001386 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001387 &acpi_video_bus_POST_info_fops,
1388 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001390 goto err_remove_rom;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392 /* 'POST' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001393 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001394 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001395 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001396 &acpi_video_bus_POST_fops,
1397 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001399 goto err_remove_post_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
1401 /* 'DOS' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001402 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds08acd4f2008-04-30 11:52:52 -07001403 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
Alexey Dobriyane0066c4e2008-05-01 04:10:02 +04001404 device_dir,
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -07001405 &acpi_video_bus_DOS_fops,
1406 acpi_driver_data(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001408 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001410 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001411 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001412
1413 err_remove_post:
1414 remove_proc_entry("POST", device_dir);
1415 err_remove_post_info:
1416 remove_proc_entry("POST_info", device_dir);
1417 err_remove_rom:
1418 remove_proc_entry("ROM", device_dir);
1419 err_remove_info:
1420 remove_proc_entry("info", device_dir);
1421 err_remove_dir:
1422 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1423 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424}
1425
Len Brown4be44fc2005-08-05 00:44:28 -04001426static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001428 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001430 if (device_dir) {
1431 remove_proc_entry("info", device_dir);
1432 remove_proc_entry("ROM", device_dir);
1433 remove_proc_entry("POST_info", device_dir);
1434 remove_proc_entry("POST", device_dir);
1435 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001436 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 acpi_device_dir(device) = NULL;
1438 }
1439
Patrick Mocheld550d982006-06-27 00:41:40 -04001440 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
1443/* --------------------------------------------------------------------------
1444 Driver Interface
1445 -------------------------------------------------------------------------- */
1446
1447/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001448static struct acpi_video_device_attrib*
1449acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1450{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001451 struct acpi_video_enumerated_device *ids;
1452 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001453
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001454 for (i = 0; i < video->attached_count; i++) {
1455 ids = &video->attached_array[i];
1456 if ((ids->value.int_val & 0xffff) == device_id)
1457 return &ids->value.attrib;
1458 }
1459
Rui Zhang82cae992007-01-03 23:40:53 -05001460 return NULL;
1461}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463static int
Len Brown4be44fc2005-08-05 00:44:28 -04001464acpi_video_bus_get_one_device(struct acpi_device *device,
1465 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
Len Brown4be44fc2005-08-05 00:44:28 -04001467 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001468 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001469 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001470 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001473 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Len Brown4be44fc2005-08-05 00:44:28 -04001475 status =
1476 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 if (ACPI_SUCCESS(status)) {
1478
Burman Yan36bcbec2006-12-19 12:56:11 -08001479 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001481 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1484 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1485 acpi_driver_data(device) = data;
1486
1487 data->device_id = device_id;
1488 data->video = video;
1489 data->dev = device;
1490
Rui Zhang82cae992007-01-03 23:40:53 -05001491 attribute = acpi_video_get_device_attr(video, device_id);
1492
1493 if((attribute != NULL) && attribute->device_id_scheme) {
1494 switch (attribute->display_type) {
1495 case ACPI_VIDEO_DISPLAY_CRT:
1496 data->flags.crt = 1;
1497 break;
1498 case ACPI_VIDEO_DISPLAY_TV:
1499 data->flags.tvout = 1;
1500 break;
1501 case ACPI_VIDEO_DISPLAY_DVI:
1502 data->flags.dvi = 1;
1503 break;
1504 case ACPI_VIDEO_DISPLAY_LCD:
1505 data->flags.lcd = 1;
1506 break;
1507 default:
1508 data->flags.unknown = 1;
1509 break;
1510 }
1511 if(attribute->bios_can_detect)
1512 data->flags.bios = 1;
1513 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 acpi_video_device_bind(video, data);
1517 acpi_video_device_find_cap(data);
1518
Patrick Mochel90130262006-05-19 16:54:48 -04001519 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001520 ACPI_DEVICE_NOTIFY,
1521 acpi_video_device_notify,
1522 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (ACPI_FAILURE(status)) {
1524 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001525 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001526 if(data->brightness)
1527 kfree(data->brightness->levels);
1528 kfree(data->brightness);
1529 kfree(data);
1530 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
1532
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001533 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001535 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 acpi_video_device_add_fs(device);
1538
Patrick Mocheld550d982006-06-27 00:41:40 -04001539 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541
Patrick Mocheld550d982006-06-27 00:41:40 -04001542 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
1545/*
1546 * Arg:
1547 * video : video bus device
1548 *
1549 * Return:
1550 * none
1551 *
1552 * Enumerate the video device list of the video bus,
1553 * bind the ids with the corresponding video devices
1554 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001555 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Len Brown4be44fc2005-08-05 00:44:28 -04001557static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001559 struct acpi_video_device *dev;
1560
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001561 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001562
1563 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001564 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001565
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001566 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
1569/*
1570 * Arg:
1571 * video : video bus device
1572 * device : video output device under the video
1573 * bus
1574 *
1575 * Return:
1576 * none
1577 *
1578 * Bind the ids with the corresponding video devices
1579 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001580 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582static void
Len Brown4be44fc2005-08-05 00:44:28 -04001583acpi_video_device_bind(struct acpi_video_bus *video,
1584 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001586 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001587 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001589 for (i = 0; i < video->attached_count; i++) {
1590 ids = &video->attached_array[i];
1591 if (device->device_id == (ids->value.int_val & 0xffff)) {
1592 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1594 }
1595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
1598/*
1599 * Arg:
1600 * video : video bus device
1601 *
1602 * Return:
1603 * < 0 : error
1604 *
1605 * Call _DOD to enumerate all devices attached to display adapter
1606 *
Len Brown4be44fc2005-08-05 00:44:28 -04001607 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1610{
Len Brown4be44fc2005-08-05 00:44:28 -04001611 int status;
1612 int count;
1613 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001614 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001615 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1616 union acpi_object *dod = NULL;
1617 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Patrick Mochel90130262006-05-19 16:54:48 -04001619 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001621 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001622 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 }
1624
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001625 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001627 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 status = -EFAULT;
1629 goto out;
1630 }
1631
1632 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001633 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001635 active_list = kcalloc(1 + dod->package.count,
1636 sizeof(struct acpi_video_enumerated_device),
1637 GFP_KERNEL);
1638 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 status = -ENOMEM;
1640 goto out;
1641 }
1642
1643 count = 0;
1644 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001645 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001648 printk(KERN_ERR PREFIX
1649 "Invalid _DOD data in element %d\n", i);
1650 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001652
1653 active_list[count].value.int_val = obj->integer.value;
1654 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001655 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1656 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 count++;
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Jesper Juhl6044ec82005-11-07 01:01:32 -08001660 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001661
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001662 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001664
1665 out:
Len Brown02438d82006-06-30 03:19:10 -04001666 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001667 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Len Brown4be44fc2005-08-05 00:44:28 -04001670static int
1671acpi_video_get_next_level(struct acpi_video_device *device,
1672 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001674 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001675 max = max_below = 0;
1676 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001677 /* Find closest level to level_current */
1678 for (i = 0; i < device->brightness->count; i++) {
1679 l = device->brightness->levels[i];
1680 if (abs(l - level_current) < abs(delta)) {
1681 delta = l - level_current;
1682 if (!delta)
1683 break;
1684 }
1685 }
1686 /* Ajust level_current to closest available level */
1687 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001688 for (i = 0; i < device->brightness->count; i++) {
1689 l = device->brightness->levels[i];
1690 if (l < min)
1691 min = l;
1692 if (l > max)
1693 max = l;
1694 if (l < min_above && l > level_current)
1695 min_above = l;
1696 if (l > max_below && l < level_current)
1697 max_below = l;
1698 }
1699
1700 switch (event) {
1701 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1702 return (level_current < max) ? min_above : min;
1703 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1704 return (level_current < max) ? min_above : max;
1705 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1706 return (level_current > min) ? max_below : min;
1707 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1708 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1709 return 0;
1710 default:
1711 return level_current;
1712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715static void
Len Brown4be44fc2005-08-05 00:44:28 -04001716acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
1718 unsigned long level_current, level_next;
Julia Jomantaite469778c2008-06-23 22:50:42 +01001719 if (!device->brightness)
1720 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 acpi_video_device_lcd_get_level_current(device, &level_current);
1722 level_next = acpi_video_get_next_level(device, level_current, event);
1723 acpi_video_device_lcd_set_level(device, level_next);
1724}
1725
1726static int
Len Brown4be44fc2005-08-05 00:44:28 -04001727acpi_video_bus_get_devices(struct acpi_video_bus *video,
1728 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
Len Brown4be44fc2005-08-05 00:44:28 -04001730 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001731 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 acpi_video_device_enumerate(video);
1734
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001735 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 status = acpi_video_bus_get_one_device(dev, video);
1738 if (ACPI_FAILURE(status)) {
Zhang Ruid385c2a2008-06-14 01:01:18 -04001739 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
1740 "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 continue;
1742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001744 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Len Brown4be44fc2005-08-05 00:44:28 -04001747static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748{
Karol Kozimor031ec772005-07-30 04:18:00 -04001749 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 struct acpi_video_bus *video;
1751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001754 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 video = device->video;
1757
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 acpi_video_device_remove_fs(device->dev);
1759
Patrick Mochel90130262006-05-19 16:54:48 -04001760 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001761 ACPI_DEVICE_NOTIFY,
1762 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001763 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001764 if (device->cdev) {
1765 sysfs_remove_link(&device->dev->dev.kobj,
1766 "thermal_cooling");
1767 sysfs_remove_link(&device->cdev->device.kobj,
1768 "device");
1769 thermal_cooling_device_unregister(device->cdev);
1770 device->cdev = NULL;
1771 }
Luming Yu23b0f012007-05-09 21:07:05 +08001772 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001773
Patrick Mocheld550d982006-06-27 00:41:40 -04001774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Len Brown4be44fc2005-08-05 00:44:28 -04001777static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
Len Brown4be44fc2005-08-05 00:44:28 -04001779 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001780 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001782 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001784 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001786 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001787 if (ACPI_FAILURE(status))
1788 printk(KERN_WARNING PREFIX
1789 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001791 if (dev->brightness) {
1792 kfree(dev->brightness->levels);
1793 kfree(dev->brightness);
1794 }
1795 list_del(&dev->entry);
1796 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 }
1798
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001799 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001800
Patrick Mocheld550d982006-06-27 00:41:40 -04001801 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802}
1803
1804/* acpi_video interface */
1805
Len Brown4be44fc2005-08-05 00:44:28 -04001806static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807{
Zhang Ruia21101c2007-09-14 11:46:22 +08001808 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809}
1810
Len Brown4be44fc2005-08-05 00:44:28 -04001811static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 return acpi_video_bus_DOS(video, 0, 1);
1814}
1815
Len Brown4be44fc2005-08-05 00:44:28 -04001816static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001818 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001819 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001820 struct input_dev *input;
1821 int keycode;
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001824 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001826 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001827 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001830 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001832 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001833 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 break;
1835
Julius Volz98fb8fe2007-02-20 16:38:40 +01001836 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 * connector. */
1838 acpi_video_device_enumerate(video);
1839 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001840 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001841 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 break;
1843
Len Brown4be44fc2005-08-05 00:44:28 -04001844 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001845 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001846 keycode = KEY_SWITCHVIDEOMODE;
1847 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001848 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001849 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001850 keycode = KEY_VIDEO_NEXT;
1851 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001852 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001853 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001854 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 break;
1856
1857 default:
Luming Yue9dab192007-08-20 18:23:53 +08001858 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001860 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 break;
1862 }
1863
Zhang Rui7761f632008-01-25 14:48:12 +08001864 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001865 input_report_key(input, keycode, 1);
1866 input_sync(input);
1867 input_report_key(input, keycode, 0);
1868 input_sync(input);
1869
Patrick Mocheld550d982006-06-27 00:41:40 -04001870 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
Len Brown4be44fc2005-08-05 00:44:28 -04001873static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001875 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001876 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001877 struct acpi_video_bus *bus;
1878 struct input_dev *input;
1879 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001882 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001884 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001885 bus = video_device->video;
1886 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001889 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001890 if (brightness_switch_enabled)
1891 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001892 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001893 keycode = KEY_BRIGHTNESS_CYCLE;
1894 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001895 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001896 if (brightness_switch_enabled)
1897 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001898 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001899 keycode = KEY_BRIGHTNESSUP;
1900 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001901 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001902 if (brightness_switch_enabled)
1903 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001904 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001905 keycode = KEY_BRIGHTNESSDOWN;
1906 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001907 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001908 if (brightness_switch_enabled)
1909 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001910 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001911 keycode = KEY_BRIGHTNESS_ZERO;
1912 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001913 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001914 if (brightness_switch_enabled)
1915 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001916 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001917 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 break;
1919 default:
Luming Yue9dab192007-08-20 18:23:53 +08001920 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001922 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 break;
1924 }
Luming Yue9dab192007-08-20 18:23:53 +08001925
Zhang Rui7761f632008-01-25 14:48:12 +08001926 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001927 input_report_key(input, keycode, 1);
1928 input_sync(input);
1929 input_report_key(input, keycode, 0);
1930 input_sync(input);
1931
Patrick Mocheld550d982006-06-27 00:41:40 -04001932 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
Zhang Ruie6d9da12007-08-25 02:23:31 -04001935static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001936static int acpi_video_resume(struct acpi_device *device)
1937{
1938 struct acpi_video_bus *video;
1939 struct acpi_video_device *video_device;
1940 int i;
1941
1942 if (!device || !acpi_driver_data(device))
1943 return -EINVAL;
1944
1945 video = acpi_driver_data(device);
1946
1947 for (i = 0; i < video->attached_count; i++) {
1948 video_device = video->attached_array[i].bind_info;
1949 if (video_device && video_device->backlight)
1950 acpi_video_set_brightness(video_device->backlight);
1951 }
1952 return AE_OK;
1953}
1954
Len Brown4be44fc2005-08-05 00:44:28 -04001955static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001957 acpi_status status;
1958 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001959 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001960 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Burman Yan36bcbec2006-12-19 12:56:11 -08001962 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001964 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
Zhang Ruie6d9da12007-08-25 02:23:31 -04001966 /* a hack to fix the duplicate name "VID" problem on T61 */
1967 if (!strcmp(device->pnp.bus_id, "VID")) {
1968 if (instance)
1969 device->pnp.bus_id[3] = '0' + instance;
1970 instance ++;
1971 }
1972
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001973 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1975 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1976 acpi_driver_data(device) = video;
1977
1978 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001979 error = acpi_video_bus_check(video);
1980 if (error)
1981 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001983 error = acpi_video_bus_add_fs(device);
1984 if (error)
1985 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001987 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 INIT_LIST_HEAD(&video->video_device_list);
1989
1990 acpi_video_bus_get_devices(video, device);
1991 acpi_video_bus_start_devices(video);
1992
Patrick Mochel90130262006-05-19 16:54:48 -04001993 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001994 ACPI_DEVICE_NOTIFY,
1995 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 if (ACPI_FAILURE(status)) {
1997 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001998 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001999 error = -ENODEV;
2000 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 }
2002
Luming Yue9dab192007-08-20 18:23:53 +08002003 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002004 if (!input) {
2005 error = -ENOMEM;
2006 goto err_uninstall_notify;
2007 }
Luming Yue9dab192007-08-20 18:23:53 +08002008
2009 snprintf(video->phys, sizeof(video->phys),
2010 "%s/video/input0", acpi_device_hid(video->device));
2011
2012 input->name = acpi_device_name(video->device);
2013 input->phys = video->phys;
2014 input->id.bustype = BUS_HOST;
2015 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002016 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002017 input->evbit[0] = BIT(EV_KEY);
2018 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2019 set_bit(KEY_VIDEO_NEXT, input->keybit);
2020 set_bit(KEY_VIDEO_PREV, input->keybit);
2021 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2022 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2023 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2024 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2025 set_bit(KEY_DISPLAY_OFF, input->keybit);
2026 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002027
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002028 error = input_register_device(input);
2029 if (error)
2030 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002033 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2034 video->flags.multihead ? "yes" : "no",
2035 video->flags.rom ? "yes" : "no",
2036 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002038 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002040 err_free_input_dev:
2041 input_free_device(input);
2042 err_uninstall_notify:
2043 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2044 acpi_video_bus_notify);
2045 err_stop_video:
2046 acpi_video_bus_stop_devices(video);
2047 acpi_video_bus_put_devices(video);
2048 kfree(video->attached_array);
2049 acpi_video_bus_remove_fs(device);
2050 err_free_video:
2051 kfree(video);
2052 acpi_driver_data(device) = NULL;
2053
2054 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
Len Brown4be44fc2005-08-05 00:44:28 -04002057static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
Len Brown4be44fc2005-08-05 00:44:28 -04002059 acpi_status status = 0;
2060 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002064 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002066 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 acpi_video_bus_stop_devices(video);
2069
Patrick Mochel90130262006-05-19 16:54:48 -04002070 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002071 ACPI_DEVICE_NOTIFY,
2072 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 acpi_video_bus_put_devices(video);
2075 acpi_video_bus_remove_fs(device);
2076
Luming Yue9dab192007-08-20 18:23:53 +08002077 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002078 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 kfree(video);
2080
Patrick Mocheld550d982006-06-27 00:41:40 -04002081 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082}
2083
Len Brown4be44fc2005-08-05 00:44:28 -04002084static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Len Brown4be44fc2005-08-05 00:44:28 -04002086 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002090 acpi_dbg_level = 0xFFFFFFFF;
2091 acpi_dbg_layer = 0x08000000;
2092 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2095 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002096 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 acpi_video_dir->owner = THIS_MODULE;
2098
2099 result = acpi_bus_register_driver(&acpi_video_bus);
2100 if (result < 0) {
2101 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002102 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 }
2104
Patrick Mocheld550d982006-06-27 00:41:40 -04002105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
Len Brown4be44fc2005-08-05 00:44:28 -04002108static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
2111 acpi_bus_unregister_driver(&acpi_video_bus);
2112
2113 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2114
Patrick Mocheld550d982006-06-27 00:41:40 -04002115 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116}
2117
2118module_init(acpi_video_init);
2119module_exit(acpi_video_exit);