blob: 87ae791781ab4e24fd8c4214a159006a0a8af9c1 [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 = {
Len Brown4be44fc2005-08-05 00:44:28 -0400193 .open = acpi_video_bus_info_open_fs,
194 .read = seq_read,
195 .llseek = seq_lseek,
196 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
200static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 .open = acpi_video_bus_ROM_open_fs,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
208 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400210 .open = acpi_video_bus_POST_info_open_fs,
211 .read = seq_read,
212 .llseek = seq_lseek,
213 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
217static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 .open = acpi_video_bus_POST_open_fs,
219 .read = seq_read,
220 .llseek = seq_lseek,
221 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
225static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400226 .open = acpi_video_bus_DOS_open_fs,
227 .read = seq_read,
228 .llseek = seq_lseek,
229 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400233static int acpi_video_device_info_open_fs(struct inode *inode,
234 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400236 .open = acpi_video_device_info_open_fs,
237 .read = seq_read,
238 .llseek = seq_lseek,
239 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240};
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242static int acpi_video_device_state_open_fs(struct inode *inode,
243 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400245 .open = acpi_video_device_state_open_fs,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249};
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static int acpi_video_device_brightness_open_fs(struct inode *inode,
252 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400254 .open = acpi_video_device_brightness_open_fs,
255 .read = seq_read,
256 .llseek = seq_lseek,
257 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260static int acpi_video_device_EDID_open_fs(struct inode *inode,
261 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400263 .open = acpi_video_device_EDID_open_fs,
264 .read = seq_read,
265 .llseek = seq_lseek,
266 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 "motherboard VGA device",
271 "PCI VGA device",
272 "AGP VGA device",
273 "UNKNOWN",
274};
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
277static void acpi_video_device_rebind(struct acpi_video_bus *video);
278static void acpi_video_device_bind(struct acpi_video_bus *video,
279 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800281static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
282 int level);
283static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device *device,
285 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400286static int acpi_video_get_next_level(struct acpi_video_device *device,
287 u32 level_current, u32 event);
288static void acpi_video_switch_brightness(struct acpi_video_device *device,
289 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800290static int acpi_video_device_get_state(struct acpi_video_device *device,
291 unsigned long *state);
292static int acpi_video_output_get(struct output_device *od);
293static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Yu Luming2f3d0002006-11-11 02:40:34 +0800295/*backlight device sysfs support*/
296static int acpi_video_get_brightness(struct backlight_device *bd)
297{
298 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000299 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800300 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100301 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800302 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000303 for (i = 2; i < vd->brightness->count; i++) {
304 if (vd->brightness->levels[i] == cur_level)
305 /* The first two entries are special - see page 575
306 of the ACPI spec 3.0 */
307 return i-2;
308 }
309 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800310}
311
312static int acpi_video_set_brightness(struct backlight_device *bd)
313{
Matthew Garrett38531e62007-12-26 02:03:26 +0000314 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800315 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100316 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000317 acpi_video_device_lcd_set_level(vd,
318 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800319 return 0;
320}
321
Richard Purdie599a52d2007-02-10 23:07:48 +0000322static struct backlight_ops acpi_backlight_ops = {
323 .get_brightness = acpi_video_get_brightness,
324 .update_status = acpi_video_set_brightness,
325};
326
Luming Yu23b0f012007-05-09 21:07:05 +0800327/*video output device sysfs support*/
328static int acpi_video_output_get(struct output_device *od)
329{
330 unsigned long state;
331 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700332 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800333 acpi_video_device_get_state(vd, &state);
334 return (int)state;
335}
336
337static int acpi_video_output_set(struct output_device *od)
338{
339 unsigned long state = od->request_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 return acpi_video_device_set_state(vd, state);
343}
344
345static struct output_properties acpi_output_properties = {
346 .set_state = acpi_video_output_set,
347 .get_status = acpi_video_output_get,
348};
Zhang Rui702ed512008-01-17 15:51:22 +0800349
350
351/* thermal cooling device callbacks */
352static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
353{
354 struct acpi_device *device = cdev->devdata;
355 struct acpi_video_device *video = acpi_driver_data(device);
356
357 return sprintf(buf, "%d\n", video->brightness->count - 3);
358}
359
360static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
361{
362 struct acpi_device *device = cdev->devdata;
363 struct acpi_video_device *video = acpi_driver_data(device);
364 unsigned long level;
365 int state;
366
367 acpi_video_device_lcd_get_level_current(video, &level);
368 for (state = 2; state < video->brightness->count; state++)
369 if (level == video->brightness->levels[state])
370 return sprintf(buf, "%d\n",
371 video->brightness->count - state - 1);
372
373 return -EINVAL;
374}
375
376static int
377video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
378{
379 struct acpi_device *device = cdev->devdata;
380 struct acpi_video_device *video = acpi_driver_data(device);
381 int level;
382
383 if ( state >= video->brightness->count - 2)
384 return -EINVAL;
385
386 state = video->brightness->count - state;
387 level = video->brightness->levels[state -1];
388 return acpi_video_device_lcd_set_level(video, level);
389}
390
391static struct thermal_cooling_device_ops video_cooling_ops = {
392 .get_max_state = video_get_max_state,
393 .get_cur_state = video_get_cur_state,
394 .set_cur_state = video_set_cur_state,
395};
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397/* --------------------------------------------------------------------------
398 Video Management
399 -------------------------------------------------------------------------- */
400
401/* device */
402
403static int
Len Brown4be44fc2005-08-05 00:44:28 -0400404acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
Len Brown4be44fc2005-08-05 00:44:28 -0400406 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400407
408 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Patrick Mocheld550d982006-06-27 00:41:40 -0400410 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413static int
Len Brown4be44fc2005-08-05 00:44:28 -0400414acpi_video_device_get_state(struct acpi_video_device *device,
415 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Len Brown4be44fc2005-08-05 00:44:28 -0400417 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Patrick Mochel90130262006-05-19 16:54:48 -0400419 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Patrick Mocheld550d982006-06-27 00:41:40 -0400421 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424static int
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Len Brown4be44fc2005-08-05 00:44:28 -0400427 int status;
428 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
429 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400430 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400434 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Patrick Mocheld550d982006-06-27 00:41:40 -0400436 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439static int
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
441 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Len Brown4be44fc2005-08-05 00:44:28 -0400443 int status;
444 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
445 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 *levels = NULL;
449
Patrick Mochel90130262006-05-19 16:54:48 -0400450 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400452 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400453 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500454 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400455 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 status = -EFAULT;
457 goto err;
458 }
459
460 *levels = obj;
461
Patrick Mocheld550d982006-06-27 00:41:40 -0400462 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800465 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Patrick Mocheld550d982006-06-27 00:41:40 -0400467 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
470static int
Len Brown4be44fc2005-08-05 00:44:28 -0400471acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400473 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400474 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
475 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400480 if (device->cap._BCM)
481 status = acpi_evaluate_object(device->dev->handle, "_BCM",
482 &args, NULL);
483 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400484 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487static int
Len Brown4be44fc2005-08-05 00:44:28 -0400488acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
489 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400491 if (device->cap._BQC)
492 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
493 level);
494 *level = device->brightness->curr;
495 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
498static int
Len Brown4be44fc2005-08-05 00:44:28 -0400499acpi_video_device_EDID(struct acpi_video_device *device,
500 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Len Brown4be44fc2005-08-05 00:44:28 -0400502 int status;
503 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
504 union acpi_object *obj;
505 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
506 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 *edid = NULL;
510
511 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400512 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (length == 128)
514 arg0.integer.value = 1;
515 else if (length == 256)
516 arg0.integer.value = 2;
517 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Patrick Mochel90130262006-05-19 16:54:48 -0400520 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400522 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200524 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 if (obj && obj->type == ACPI_TYPE_BUFFER)
527 *edid = obj;
528 else {
Len Brown64684632006-06-26 23:41:38 -0400529 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 status = -EFAULT;
531 kfree(obj);
532 }
533
Patrick Mocheld550d982006-06-27 00:41:40 -0400534 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537/* bus */
538
539static int
Len Brown4be44fc2005-08-05 00:44:28 -0400540acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 int status;
543 unsigned long tmp;
544 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
545 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 arg0.integer.value = option;
549
Patrick Mochel90130262006-05-19 16:54:48 -0400550 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400552 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Patrick Mocheld550d982006-06-27 00:41:40 -0400554 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557static int
Len Brown4be44fc2005-08-05 00:44:28 -0400558acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
560 int status;
561
Patrick Mochel90130262006-05-19 16:54:48 -0400562 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Patrick Mocheld550d982006-06-27 00:41:40 -0400564 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
567static int
Len Brown4be44fc2005-08-05 00:44:28 -0400568acpi_video_bus_POST_options(struct acpi_video_bus *video,
569 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Len Brown4be44fc2005-08-05 00:44:28 -0400571 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Patrick Mochel90130262006-05-19 16:54:48 -0400573 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 *options &= 3;
575
Patrick Mocheld550d982006-06-27 00:41:40 -0400576 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579/*
580 * Arg:
581 * video : video bus device pointer
582 * bios_flag :
583 * 0. The system BIOS should NOT automatically switch(toggle)
584 * the active display output.
585 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100586 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * 2. The _DGS value should be locked.
588 * 3. The system BIOS should not automatically switch (toggle) the
589 * active display output, but instead generate the display switch
590 * event notify code.
591 * lcd_flag :
592 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100593 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * Return Value:
597 * -1 wrong arg.
598 */
599
600static int
Len Brown4be44fc2005-08-05 00:44:28 -0400601acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Len Brown4be44fc2005-08-05 00:44:28 -0400603 acpi_integer status = 0;
604 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
605 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 status = -1;
610 goto Failed;
611 }
612 arg0.integer.value = (lcd_flag << 2) | bios_flag;
613 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400614 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400617 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
619
620/*
621 * Arg:
622 * device : video output device (LCD, CRT, ..)
623 *
624 * Return Value:
625 * None
626 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100627 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 * device.
629 */
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 acpi_handle h_dummy1;
634 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800635 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 union acpi_object *obj = NULL;
637 struct acpi_video_device_brightness *br = NULL;
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
William Lee Irwin III98934de2007-12-12 03:56:55 -0800640 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Patrick Mochel90130262006-05-19 16:54:48 -0400642 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 device->cap._ADR = 1;
644 }
Patrick Mochel90130262006-05-19 16:54:48 -0400645 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400646 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
Patrick Mochel90130262006-05-19 16:54:48 -0400648 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400649 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800651 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
652 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400653 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400654 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 }
Patrick Mochel90130262006-05-19 16:54:48 -0400656 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 device->cap._DCS = 1;
658 }
Patrick Mochel90130262006-05-19 16:54:48 -0400659 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 device->cap._DGS = 1;
661 }
Patrick Mochel90130262006-05-19 16:54:48 -0400662 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 device->cap._DSS = 1;
664 }
665
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400666 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400668 if (obj->package.count >= 2) {
669 int count = 0;
670 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400671
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400672 br = kzalloc(sizeof(*br), GFP_KERNEL);
673 if (!br) {
674 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400676 br->levels = kmalloc(obj->package.count *
677 sizeof *(br->levels), GFP_KERNEL);
678 if (!br->levels)
679 goto out;
680
681 for (i = 0; i < obj->package.count; i++) {
682 o = (union acpi_object *)&obj->package.
683 elements[i];
684 if (o->type != ACPI_TYPE_INTEGER) {
685 printk(KERN_ERR PREFIX "Invalid data\n");
686 continue;
687 }
688 br->levels[count] = (u32) o->integer.value;
689
690 if (br->levels[count] > max_level)
691 max_level = br->levels[count];
692 count++;
693 }
694 out:
695 if (count < 2) {
696 kfree(br->levels);
697 kfree(br);
698 } else {
699 br->count = count;
700 device->brightness = br;
701 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
702 "found %d brightness levels\n",
703 count));
704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400707
708 } else {
709 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
711
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500712 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Linus Torvalds797de7b2008-04-05 12:14:13 -0700714 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Zhang Rui702ed512008-01-17 15:51:22 +0800715 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800716 static int count = 0;
717 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800718 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
719 if (!name)
720 return;
721
Yu Luming2f3d0002006-11-11 02:40:34 +0800722 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800723 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000724 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000725 device->backlight->props.max_brightness = device->brightness->count-3;
726 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000727 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800728 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800729
730 device->cdev = thermal_cooling_device_register("LCD",
731 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500732 if (IS_ERR(device->cdev))
733 return;
734
Ingo Molnar48d3d822008-03-28 14:28:03 +0100735 if (device->cdev) {
736 printk(KERN_INFO PREFIX
737 "%s is registered as cooling_device%d\n",
738 device->dev->dev.bus_id, device->cdev->id);
739 result = sysfs_create_link(&device->dev->dev.kobj,
740 &device->cdev->device.kobj,
741 "thermal_cooling");
742 if (result)
743 printk(KERN_ERR PREFIX "Create sysfs link\n");
744 result = sysfs_create_link(&device->cdev->device.kobj,
745 &device->dev->dev.kobj,
746 "device");
747 if (result)
748 printk(KERN_ERR PREFIX "Create sysfs link\n");
749 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800750 }
Luming Yu23b0f012007-05-09 21:07:05 +0800751 if (device->cap._DCS && device->cap._DSS){
752 static int count = 0;
753 char *name;
754 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
755 if (!name)
756 return;
757 sprintf(name, "acpi_video%d", count++);
758 device->output_dev = video_output_register(name,
759 NULL, device, &acpi_output_properties);
760 kfree(name);
761 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400762 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
765/*
766 * Arg:
767 * device : video output device (VGA)
768 *
769 * Return Value:
770 * None
771 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100772 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 */
774
Len Brown4be44fc2005-08-05 00:44:28 -0400775static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Len Brown4be44fc2005-08-05 00:44:28 -0400777 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
William Lee Irwin III98934de2007-12-12 03:56:55 -0800779 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400780 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 video->cap._DOS = 1;
782 }
Patrick Mochel90130262006-05-19 16:54:48 -0400783 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 video->cap._DOD = 1;
785 }
Patrick Mochel90130262006-05-19 16:54:48 -0400786 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 video->cap._ROM = 1;
788 }
Patrick Mochel90130262006-05-19 16:54:48 -0400789 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 video->cap._GPD = 1;
791 }
Patrick Mochel90130262006-05-19 16:54:48 -0400792 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 video->cap._SPD = 1;
794 }
Patrick Mochel90130262006-05-19 16:54:48 -0400795 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 video->cap._VPO = 1;
797 }
798}
799
800/*
801 * Check whether the video bus device has required AML method to
802 * support the desired features
803 */
804
Len Brown4be44fc2005-08-05 00:44:28 -0400805static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Len Brown4be44fc2005-08-05 00:44:28 -0400807 acpi_status status = -ENOENT;
Len Brownf0d67522008-03-18 01:43:53 -0400808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400811 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 /* Since there is no HID, CID and so on for VGA driver, we have
814 * to check well known required nodes.
815 */
816
Julius Volz98fb8fe2007-02-20 16:38:40 +0100817 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400818 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 video->flags.multihead = 1;
820 status = 0;
821 }
822
Julius Volz98fb8fe2007-02-20 16:38:40 +0100823 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400824 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 video->flags.rom = 1;
826 status = 0;
827 }
828
Julius Volz98fb8fe2007-02-20 16:38:40 +0100829 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400830 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 video->flags.post = 1;
832 status = 0;
833 }
834
Patrick Mocheld550d982006-06-27 00:41:40 -0400835 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
838/* --------------------------------------------------------------------------
839 FS Interface (/proc)
840 -------------------------------------------------------------------------- */
841
Len Brown4be44fc2005-08-05 00:44:28 -0400842static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844/* video devices */
845
Len Brown4be44fc2005-08-05 00:44:28 -0400846static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200848 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 if (!dev)
852 goto end;
853
854 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
855 seq_printf(seq, "type: ");
856 if (dev->flags.crt)
857 seq_printf(seq, "CRT\n");
858 else if (dev->flags.lcd)
859 seq_printf(seq, "LCD\n");
860 else if (dev->flags.tvout)
861 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500862 else if (dev->flags.dvi)
863 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 else
865 seq_printf(seq, "UNKNOWN\n");
866
Len Brown4be44fc2005-08-05 00:44:28 -0400867 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Len Brown4be44fc2005-08-05 00:44:28 -0400869 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400870 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
872
873static int
Len Brown4be44fc2005-08-05 00:44:28 -0400874acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 return single_open(file, acpi_video_device_info_seq_show,
877 PDE(inode)->data);
878}
879
Len Brown4be44fc2005-08-05 00:44:28 -0400880static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
Len Brown4be44fc2005-08-05 00:44:28 -0400882 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200883 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400884 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 if (!dev)
888 goto end;
889
890 status = acpi_video_device_get_state(dev, &state);
891 seq_printf(seq, "state: ");
892 if (ACPI_SUCCESS(status))
893 seq_printf(seq, "0x%02lx\n", state);
894 else
895 seq_printf(seq, "<not supported>\n");
896
897 status = acpi_video_device_query(dev, &state);
898 seq_printf(seq, "query: ");
899 if (ACPI_SUCCESS(status))
900 seq_printf(seq, "0x%02lx\n", state);
901 else
902 seq_printf(seq, "<not supported>\n");
903
Len Brown4be44fc2005-08-05 00:44:28 -0400904 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
908static int
Len Brown4be44fc2005-08-05 00:44:28 -0400909acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
911 return single_open(file, acpi_video_device_state_seq_show,
912 PDE(inode)->data);
913}
914
915static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400916acpi_video_device_write_state(struct file *file,
917 const char __user * buffer,
918 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Len Brown4be44fc2005-08-05 00:44:28 -0400920 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200921 struct seq_file *m = file->private_data;
922 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400923 char str[12] = { 0 };
924 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400928 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400931 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 str[count] = 0;
934 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400935 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937 status = acpi_video_device_set_state(dev, state);
938
939 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Patrick Mocheld550d982006-06-27 00:41:40 -0400942 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
945static int
Len Brown4be44fc2005-08-05 00:44:28 -0400946acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200948 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400949 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (!dev || !dev->brightness) {
953 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400954 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 }
956
957 seq_printf(seq, "levels: ");
958 for (i = 0; i < dev->brightness->count; i++)
959 seq_printf(seq, " %d", dev->brightness->levels[i]);
960 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
961
Patrick Mocheld550d982006-06-27 00:41:40 -0400962 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
965static int
Len Brown4be44fc2005-08-05 00:44:28 -0400966acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
968 return single_open(file, acpi_video_device_brightness_seq_show,
969 PDE(inode)->data);
970}
971
972static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400973acpi_video_device_write_brightness(struct file *file,
974 const char __user * buffer,
975 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200977 struct seq_file *m = file->private_data;
978 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100979 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400980 unsigned int level = 0;
981 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Thomas Renninger59d399d2005-11-08 05:27:00 -0500984 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400985 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400988 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 str[count] = 0;
991 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Julius Volz98fb8fe2007-02-20 16:38:40 +0100996 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 for (i = 0; i < dev->brightness->count; i++)
998 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400999 if (ACPI_SUCCESS
1000 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 dev->brightness->curr = level;
1002 break;
1003 }
1004
Patrick Mocheld550d982006-06-27 00:41:40 -04001005 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
Len Brown4be44fc2005-08-05 00:44:28 -04001008static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001010 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001011 int status;
1012 int i;
1013 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 if (!dev)
1017 goto out;
1018
Len Brown4be44fc2005-08-05 00:44:28 -04001019 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001021 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023
1024 if (ACPI_FAILURE(status)) {
1025 goto out;
1026 }
1027
1028 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1029 for (i = 0; i < edid->buffer.length; i++)
1030 seq_putc(seq, edid->buffer.pointer[i]);
1031 }
1032
Len Brown4be44fc2005-08-05 00:44:28 -04001033 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (!edid)
1035 seq_printf(seq, "<not supported>\n");
1036 else
1037 kfree(edid);
1038
Patrick Mocheld550d982006-06-27 00:41:40 -04001039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
1042static int
Len Brown4be44fc2005-08-05 00:44:28 -04001043acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045 return single_open(file, acpi_video_device_EDID_seq_show,
1046 PDE(inode)->data);
1047}
1048
Len Brown4be44fc2005-08-05 00:44:28 -04001049static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001051 struct proc_dir_entry *entry, *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 struct acpi_video_device *vid_dev;
1053
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001054 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001056 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001058 device_dir = proc_mkdir(acpi_device_bid(device),
1059 vid_dev->video->dir);
1060 if (!device_dir)
1061 return -ENOMEM;
1062
1063 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 /* 'info' [R] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001066 entry = create_proc_entry("info", S_IRUGO, device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001068 goto err_remove_dir;
1069
1070 entry->proc_fops = &acpi_video_device_info_fops;
1071 entry->data = acpi_driver_data(device);
1072 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 /* 'state' [R/W] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001075 entry = create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1076 device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001078 goto err_remove_info;
1079
1080 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1081 entry->proc_fops = &acpi_video_device_state_fops;
1082 entry->data = acpi_driver_data(device);
1083 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 /* 'brightness' [R/W] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001086 entry = create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1087 device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001089 goto err_remove_state;
1090
1091 acpi_video_device_brightness_fops.write =
1092 acpi_video_device_write_brightness;
1093 entry->proc_fops = &acpi_video_device_brightness_fops;
1094 entry->data = acpi_driver_data(device);
1095 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* 'EDID' [R] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001098 entry = create_proc_entry("EDID", S_IRUGO, device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001100 goto err_remove_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001102 entry->proc_fops = &acpi_video_device_EDID_fops;
1103 entry->data = acpi_driver_data(device);
1104 entry->owner = THIS_MODULE;
1105
1106 acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001107 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001108
1109 err_remove_brightness:
1110 remove_proc_entry("brightness", device_dir);
1111 err_remove_state:
1112 remove_proc_entry("state", device_dir);
1113 err_remove_info:
1114 remove_proc_entry("info", device_dir);
1115 err_remove_dir:
1116 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1117 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Len Brown4be44fc2005-08-05 00:44:28 -04001120static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
1122 struct acpi_video_device *vid_dev;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001123 struct proc_dir_entry *device_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001125 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001127 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001129 device_dir = acpi_device_dir(device);
1130 if (device_dir) {
1131 remove_proc_entry("info", device_dir);
1132 remove_proc_entry("state", device_dir);
1133 remove_proc_entry("brightness", device_dir);
1134 remove_proc_entry("EDID", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001135 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 acpi_device_dir(device) = NULL;
1137 }
1138
Patrick Mocheld550d982006-06-27 00:41:40 -04001139 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140}
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001143static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001145 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 if (!video)
1149 goto end;
1150
1151 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001152 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001154 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001156 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Len Brown4be44fc2005-08-05 00:44:28 -04001158 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001159 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Len Brown4be44fc2005-08-05 00:44:28 -04001162static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Len Brown4be44fc2005-08-05 00:44:28 -04001164 return single_open(file, acpi_video_bus_info_seq_show,
1165 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
Len Brown4be44fc2005-08-05 00:44:28 -04001168static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001170 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 if (!video)
1174 goto end;
1175
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001176 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 seq_printf(seq, "<TODO>\n");
1178
Len Brown4be44fc2005-08-05 00:44:28 -04001179 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001180 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181}
1182
Len Brown4be44fc2005-08-05 00:44:28 -04001183static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
1185 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1186}
1187
Len Brown4be44fc2005-08-05 00:44:28 -04001188static int acpi_video_bus_POST_info_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;
Len Brown4be44fc2005-08-05 00:44:28 -04001191 unsigned long options;
1192 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 if (!video)
1196 goto end;
1197
1198 status = acpi_video_bus_POST_options(video, &options);
1199 if (ACPI_SUCCESS(status)) {
1200 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001201 printk(KERN_WARNING PREFIX
1202 "The motherboard VGA device is not listed as a possible POST device.\n");
1203 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001204 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001207 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 if (options & 2)
1209 seq_printf(seq, " <PCI video>");
1210 if (options & 4)
1211 seq_printf(seq, " <AGP video>");
1212 seq_putc(seq, '\n');
1213 } else
1214 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001215 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001216 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
1218
1219static int
Len Brown4be44fc2005-08-05 00:44:28 -04001220acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221{
Len Brown4be44fc2005-08-05 00:44:28 -04001222 return single_open(file, acpi_video_bus_POST_info_seq_show,
1223 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
Len Brown4be44fc2005-08-05 00:44:28 -04001226static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001228 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001229 int status;
1230 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (!video)
1234 goto end;
1235
Len Brown4be44fc2005-08-05 00:44:28 -04001236 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 if (!ACPI_SUCCESS(status)) {
1238 seq_printf(seq, "<not supported>\n");
1239 goto end;
1240 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001241 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Len Brown4be44fc2005-08-05 00:44:28 -04001243 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
Len Brown4be44fc2005-08-05 00:44:28 -04001247static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001249 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Len Brown4be44fc2005-08-05 00:44:28 -04001252 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Patrick Mocheld550d982006-06-27 00:41:40 -04001254 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Len Brown4be44fc2005-08-05 00:44:28 -04001257static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Len Brown4be44fc2005-08-05 00:44:28 -04001259 return single_open(file, acpi_video_bus_POST_seq_show,
1260 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
Len Brown4be44fc2005-08-05 00:44:28 -04001263static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264{
1265 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1266}
1267
1268static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001269acpi_video_bus_write_POST(struct file *file,
1270 const char __user * buffer,
1271 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
Len Brown4be44fc2005-08-05 00:44:28 -04001273 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001274 struct seq_file *m = file->private_data;
1275 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001276 char str[12] = { 0 };
1277 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001281 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283 status = acpi_video_bus_POST_options(video, &options);
1284 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001285 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001288 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290 str[count] = 0;
1291 opt = strtoul(str, NULL, 0);
1292 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001293 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Julius Volz98fb8fe2007-02-20 16:38:40 +01001295 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 options |= 1;
1297
1298 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001299 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001301 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 }
1304
Patrick Mocheld550d982006-06-27 00:41:40 -04001305 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
1308static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001309acpi_video_bus_write_DOS(struct file *file,
1310 const char __user * buffer,
1311 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
Len Brown4be44fc2005-08-05 00:44:28 -04001313 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001314 struct seq_file *m = file->private_data;
1315 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001316 char str[12] = { 0 };
1317 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001321 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001324 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 str[count] = 0;
1327 opt = strtoul(str, NULL, 0);
1328 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001329 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Len Brown4be44fc2005-08-05 00:44:28 -04001331 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001334 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Patrick Mocheld550d982006-06-27 00:41:40 -04001336 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Len Brown4be44fc2005-08-05 00:44:28 -04001339static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001341 struct acpi_video_bus *video = acpi_driver_data(device);
1342 struct proc_dir_entry *device_dir;
1343 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001345 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1346 if (!device_dir)
1347 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001349 device_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 /* 'info' [R] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001352 entry = create_proc_entry("info", S_IRUGO, device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001354 goto err_remove_dir;
1355
1356 entry->proc_fops = &acpi_video_bus_info_fops;
1357 entry->data = acpi_driver_data(device);
1358 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 /* 'ROM' [R] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001361 entry = create_proc_entry("ROM", S_IRUGO, device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001363 goto err_remove_info;
1364
1365 entry->proc_fops = &acpi_video_bus_ROM_fops;
1366 entry->data = acpi_driver_data(device);
1367 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 /* 'POST_info' [R] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001370 entry = create_proc_entry("POST_info", S_IRUGO, device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001372 goto err_remove_rom;
1373
1374 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1375 entry->data = acpi_driver_data(device);
1376 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 /* 'POST' [R/W] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001379 entry = create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1380 device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001382 goto err_remove_post_info;
1383
1384 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1385 entry->proc_fops = &acpi_video_bus_POST_fops;
1386 entry->data = acpi_driver_data(device);
1387 entry->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 /* 'DOS' [R/W] */
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001390 entry = create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1391 device_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 if (!entry)
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001393 goto err_remove_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001395 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1396 entry->proc_fops = &acpi_video_bus_DOS_fops;
1397 entry->data = acpi_driver_data(device);
1398 entry->owner = THIS_MODULE;
1399
1400 video->dir = acpi_device_dir(device) = device_dir;
Patrick Mocheld550d982006-06-27 00:41:40 -04001401 return 0;
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001402
1403 err_remove_post:
1404 remove_proc_entry("POST", device_dir);
1405 err_remove_post_info:
1406 remove_proc_entry("POST_info", device_dir);
1407 err_remove_rom:
1408 remove_proc_entry("ROM", device_dir);
1409 err_remove_info:
1410 remove_proc_entry("info", device_dir);
1411 err_remove_dir:
1412 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1413 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414}
1415
Len Brown4be44fc2005-08-05 00:44:28 -04001416static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001418 struct proc_dir_entry *device_dir = acpi_device_dir(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Dmitry Torokhov251cb0b2007-11-05 11:43:34 -05001420 if (device_dir) {
1421 remove_proc_entry("info", device_dir);
1422 remove_proc_entry("ROM", device_dir);
1423 remove_proc_entry("POST_info", device_dir);
1424 remove_proc_entry("POST", device_dir);
1425 remove_proc_entry("DOS", device_dir);
Len Brown4be44fc2005-08-05 00:44:28 -04001426 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 acpi_device_dir(device) = NULL;
1428 }
1429
Patrick Mocheld550d982006-06-27 00:41:40 -04001430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
1433/* --------------------------------------------------------------------------
1434 Driver Interface
1435 -------------------------------------------------------------------------- */
1436
1437/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001438static struct acpi_video_device_attrib*
1439acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1440{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001441 struct acpi_video_enumerated_device *ids;
1442 int i;
Rui Zhang82cae992007-01-03 23:40:53 -05001443
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001444 for (i = 0; i < video->attached_count; i++) {
1445 ids = &video->attached_array[i];
1446 if ((ids->value.int_val & 0xffff) == device_id)
1447 return &ids->value.attrib;
1448 }
1449
Rui Zhang82cae992007-01-03 23:40:53 -05001450 return NULL;
1451}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453static int
Len Brown4be44fc2005-08-05 00:44:28 -04001454acpi_video_bus_get_one_device(struct acpi_device *device,
1455 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Len Brown4be44fc2005-08-05 00:44:28 -04001457 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001458 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001459 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001460 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001463 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Len Brown4be44fc2005-08-05 00:44:28 -04001465 status =
1466 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 if (ACPI_SUCCESS(status)) {
1468
Burman Yan36bcbec2006-12-19 12:56:11 -08001469 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001471 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1474 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1475 acpi_driver_data(device) = data;
1476
1477 data->device_id = device_id;
1478 data->video = video;
1479 data->dev = device;
1480
Rui Zhang82cae992007-01-03 23:40:53 -05001481 attribute = acpi_video_get_device_attr(video, device_id);
1482
1483 if((attribute != NULL) && attribute->device_id_scheme) {
1484 switch (attribute->display_type) {
1485 case ACPI_VIDEO_DISPLAY_CRT:
1486 data->flags.crt = 1;
1487 break;
1488 case ACPI_VIDEO_DISPLAY_TV:
1489 data->flags.tvout = 1;
1490 break;
1491 case ACPI_VIDEO_DISPLAY_DVI:
1492 data->flags.dvi = 1;
1493 break;
1494 case ACPI_VIDEO_DISPLAY_LCD:
1495 data->flags.lcd = 1;
1496 break;
1497 default:
1498 data->flags.unknown = 1;
1499 break;
1500 }
1501 if(attribute->bios_can_detect)
1502 data->flags.bios = 1;
1503 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 acpi_video_device_bind(video, data);
1507 acpi_video_device_find_cap(data);
1508
Patrick Mochel90130262006-05-19 16:54:48 -04001509 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001510 ACPI_DEVICE_NOTIFY,
1511 acpi_video_device_notify,
1512 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (ACPI_FAILURE(status)) {
1514 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001515 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001516 if(data->brightness)
1517 kfree(data->brightness->levels);
1518 kfree(data->brightness);
1519 kfree(data);
1520 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001523 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001525 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 acpi_video_device_add_fs(device);
1528
Patrick Mocheld550d982006-06-27 00:41:40 -04001529 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
1531
Patrick Mocheld550d982006-06-27 00:41:40 -04001532 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
1535/*
1536 * Arg:
1537 * video : video bus device
1538 *
1539 * Return:
1540 * none
1541 *
1542 * Enumerate the video device list of the video bus,
1543 * bind the ids with the corresponding video devices
1544 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001545 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Len Brown4be44fc2005-08-05 00:44:28 -04001547static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001549 struct acpi_video_device *dev;
1550
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001551 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001552
1553 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001554 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001555
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001556 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
1559/*
1560 * Arg:
1561 * video : video bus device
1562 * device : video output device under the video
1563 * bus
1564 *
1565 * Return:
1566 * none
1567 *
1568 * Bind the ids with the corresponding video devices
1569 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001570 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572static void
Len Brown4be44fc2005-08-05 00:44:28 -04001573acpi_video_device_bind(struct acpi_video_bus *video,
1574 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001576 struct acpi_video_enumerated_device *ids;
Len Brown4be44fc2005-08-05 00:44:28 -04001577 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001579 for (i = 0; i < video->attached_count; i++) {
1580 ids = &video->attached_array[i];
1581 if (device->device_id == (ids->value.int_val & 0xffff)) {
1582 ids->bind_info = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1584 }
1585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586}
1587
1588/*
1589 * Arg:
1590 * video : video bus device
1591 *
1592 * Return:
1593 * < 0 : error
1594 *
1595 * Call _DOD to enumerate all devices attached to display adapter
1596 *
Len Brown4be44fc2005-08-05 00:44:28 -04001597 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1600{
Len Brown4be44fc2005-08-05 00:44:28 -04001601 int status;
1602 int count;
1603 int i;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001604 struct acpi_video_enumerated_device *active_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001605 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1606 union acpi_object *dod = NULL;
1607 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Patrick Mochel90130262006-05-19 16:54:48 -04001609 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001611 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001612 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 }
1614
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001615 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001617 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 status = -EFAULT;
1619 goto out;
1620 }
1621
1622 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001623 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001625 active_list = kcalloc(1 + dod->package.count,
1626 sizeof(struct acpi_video_enumerated_device),
1627 GFP_KERNEL);
1628 if (!active_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 status = -ENOMEM;
1630 goto out;
1631 }
1632
1633 count = 0;
1634 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001635 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 if (obj->type != ACPI_TYPE_INTEGER) {
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001638 printk(KERN_ERR PREFIX
1639 "Invalid _DOD data in element %d\n", i);
1640 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 }
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001642
1643 active_list[count].value.int_val = obj->integer.value;
1644 active_list[count].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001645 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1646 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 count++;
1648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Jesper Juhl6044ec82005-11-07 01:01:32 -08001650 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001651
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001652 video->attached_array = active_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 video->attached_count = count;
Dmitry Torokhov78eed022007-11-05 11:43:33 -05001654
1655 out:
Len Brown02438d82006-06-30 03:19:10 -04001656 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001657 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Len Brown4be44fc2005-08-05 00:44:28 -04001660static int
1661acpi_video_get_next_level(struct acpi_video_device *device,
1662 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001664 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001665 max = max_below = 0;
1666 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001667 /* Find closest level to level_current */
1668 for (i = 0; i < device->brightness->count; i++) {
1669 l = device->brightness->levels[i];
1670 if (abs(l - level_current) < abs(delta)) {
1671 delta = l - level_current;
1672 if (!delta)
1673 break;
1674 }
1675 }
1676 /* Ajust level_current to closest available level */
1677 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001678 for (i = 0; i < device->brightness->count; i++) {
1679 l = device->brightness->levels[i];
1680 if (l < min)
1681 min = l;
1682 if (l > max)
1683 max = l;
1684 if (l < min_above && l > level_current)
1685 min_above = l;
1686 if (l > max_below && l < level_current)
1687 max_below = l;
1688 }
1689
1690 switch (event) {
1691 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1692 return (level_current < max) ? min_above : min;
1693 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1694 return (level_current < max) ? min_above : max;
1695 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1696 return (level_current > min) ? max_below : min;
1697 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1698 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1699 return 0;
1700 default:
1701 return level_current;
1702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705static void
Len Brown4be44fc2005-08-05 00:44:28 -04001706acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707{
1708 unsigned long level_current, level_next;
1709 acpi_video_device_lcd_get_level_current(device, &level_current);
1710 level_next = acpi_video_get_next_level(device, level_current, event);
1711 acpi_video_device_lcd_set_level(device, level_next);
1712}
1713
1714static int
Len Brown4be44fc2005-08-05 00:44:28 -04001715acpi_video_bus_get_devices(struct acpi_video_bus *video,
1716 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Len Brown4be44fc2005-08-05 00:44:28 -04001718 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001719 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 acpi_video_device_enumerate(video);
1722
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001723 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 status = acpi_video_bus_get_one_device(dev, video);
1726 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001727 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 continue;
1729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001731 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Len Brown4be44fc2005-08-05 00:44:28 -04001734static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735{
Karol Kozimor031ec772005-07-30 04:18:00 -04001736 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 struct acpi_video_bus *video;
1738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001741 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 video = device->video;
1744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 acpi_video_device_remove_fs(device->dev);
1746
Patrick Mochel90130262006-05-19 16:54:48 -04001747 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001748 ACPI_DEVICE_NOTIFY,
1749 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001750 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001751 if (device->cdev) {
1752 sysfs_remove_link(&device->dev->dev.kobj,
1753 "thermal_cooling");
1754 sysfs_remove_link(&device->cdev->device.kobj,
1755 "device");
1756 thermal_cooling_device_unregister(device->cdev);
1757 device->cdev = NULL;
1758 }
Luming Yu23b0f012007-05-09 21:07:05 +08001759 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001760
Patrick Mocheld550d982006-06-27 00:41:40 -04001761 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762}
1763
Len Brown4be44fc2005-08-05 00:44:28 -04001764static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765{
Len Brown4be44fc2005-08-05 00:44:28 -04001766 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001767 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001769 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001771 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001773 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001774 if (ACPI_FAILURE(status))
1775 printk(KERN_WARNING PREFIX
1776 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001778 if (dev->brightness) {
1779 kfree(dev->brightness->levels);
1780 kfree(dev->brightness);
1781 }
1782 list_del(&dev->entry);
1783 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 }
1785
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001786 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001787
Patrick Mocheld550d982006-06-27 00:41:40 -04001788 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789}
1790
1791/* acpi_video interface */
1792
Len Brown4be44fc2005-08-05 00:44:28 -04001793static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
Zhang Ruia21101c2007-09-14 11:46:22 +08001795 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796}
1797
Len Brown4be44fc2005-08-05 00:44:28 -04001798static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
1800 return acpi_video_bus_DOS(video, 0, 1);
1801}
1802
Len Brown4be44fc2005-08-05 00:44:28 -04001803static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001805 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001806 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001807 struct input_dev *input;
1808 int keycode;
1809
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001811 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001813 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001814 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
1816 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001817 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001819 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001820 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 break;
1822
Julius Volz98fb8fe2007-02-20 16:38:40 +01001823 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 * connector. */
1825 acpi_video_device_enumerate(video);
1826 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001827 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001828 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 break;
1830
Len Brown4be44fc2005-08-05 00:44:28 -04001831 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001832 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001833 keycode = KEY_SWITCHVIDEOMODE;
1834 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001835 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001836 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001837 keycode = KEY_VIDEO_NEXT;
1838 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001839 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
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_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 break;
1843
1844 default:
Luming Yue9dab192007-08-20 18:23:53 +08001845 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001847 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 break;
1849 }
1850
Zhang Rui7761f632008-01-25 14:48:12 +08001851 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001852 input_report_key(input, keycode, 1);
1853 input_sync(input);
1854 input_report_key(input, keycode, 0);
1855 input_sync(input);
1856
Patrick Mocheld550d982006-06-27 00:41:40 -04001857 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858}
1859
Len Brown4be44fc2005-08-05 00:44:28 -04001860static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001862 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001863 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001864 struct acpi_video_bus *bus;
1865 struct input_dev *input;
1866 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001869 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001871 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001872 bus = video_device->video;
1873 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001876 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001877 if (brightness_switch_enabled)
1878 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001879 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001880 keycode = KEY_BRIGHTNESS_CYCLE;
1881 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001882 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001883 if (brightness_switch_enabled)
1884 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001885 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001886 keycode = KEY_BRIGHTNESSUP;
1887 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001888 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001889 if (brightness_switch_enabled)
1890 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001891 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001892 keycode = KEY_BRIGHTNESSDOWN;
1893 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001894 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001895 if (brightness_switch_enabled)
1896 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001897 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001898 keycode = KEY_BRIGHTNESS_ZERO;
1899 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001900 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001901 if (brightness_switch_enabled)
1902 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001903 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001904 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 break;
1906 default:
Luming Yue9dab192007-08-20 18:23:53 +08001907 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001909 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 break;
1911 }
Luming Yue9dab192007-08-20 18:23:53 +08001912
Zhang Rui7761f632008-01-25 14:48:12 +08001913 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001914 input_report_key(input, keycode, 1);
1915 input_sync(input);
1916 input_report_key(input, keycode, 0);
1917 input_sync(input);
1918
Patrick Mocheld550d982006-06-27 00:41:40 -04001919 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
Zhang Ruie6d9da12007-08-25 02:23:31 -04001922static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001923static int acpi_video_resume(struct acpi_device *device)
1924{
1925 struct acpi_video_bus *video;
1926 struct acpi_video_device *video_device;
1927 int i;
1928
1929 if (!device || !acpi_driver_data(device))
1930 return -EINVAL;
1931
1932 video = acpi_driver_data(device);
1933
1934 for (i = 0; i < video->attached_count; i++) {
1935 video_device = video->attached_array[i].bind_info;
1936 if (video_device && video_device->backlight)
1937 acpi_video_set_brightness(video_device->backlight);
1938 }
1939 return AE_OK;
1940}
1941
Len Brown4be44fc2005-08-05 00:44:28 -04001942static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001944 acpi_status status;
1945 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001946 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001947 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Burman Yan36bcbec2006-12-19 12:56:11 -08001949 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001951 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Zhang Ruie6d9da12007-08-25 02:23:31 -04001953 /* a hack to fix the duplicate name "VID" problem on T61 */
1954 if (!strcmp(device->pnp.bus_id, "VID")) {
1955 if (instance)
1956 device->pnp.bus_id[3] = '0' + instance;
1957 instance ++;
1958 }
1959
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001960 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1962 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1963 acpi_driver_data(device) = video;
1964
1965 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001966 error = acpi_video_bus_check(video);
1967 if (error)
1968 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001970 error = acpi_video_bus_add_fs(device);
1971 if (error)
1972 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001974 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 INIT_LIST_HEAD(&video->video_device_list);
1976
1977 acpi_video_bus_get_devices(video, device);
1978 acpi_video_bus_start_devices(video);
1979
Patrick Mochel90130262006-05-19 16:54:48 -04001980 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001981 ACPI_DEVICE_NOTIFY,
1982 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 if (ACPI_FAILURE(status)) {
1984 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001985 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001986 error = -ENODEV;
1987 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989
Luming Yue9dab192007-08-20 18:23:53 +08001990 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001991 if (!input) {
1992 error = -ENOMEM;
1993 goto err_uninstall_notify;
1994 }
Luming Yue9dab192007-08-20 18:23:53 +08001995
1996 snprintf(video->phys, sizeof(video->phys),
1997 "%s/video/input0", acpi_device_hid(video->device));
1998
1999 input->name = acpi_device_name(video->device);
2000 input->phys = video->phys;
2001 input->id.bustype = BUS_HOST;
2002 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002003 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002004 input->evbit[0] = BIT(EV_KEY);
2005 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2006 set_bit(KEY_VIDEO_NEXT, input->keybit);
2007 set_bit(KEY_VIDEO_PREV, input->keybit);
2008 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2009 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2010 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2011 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2012 set_bit(KEY_DISPLAY_OFF, input->keybit);
2013 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002014
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002015 error = input_register_device(input);
2016 if (error)
2017 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002020 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2021 video->flags.multihead ? "yes" : "no",
2022 video->flags.rom ? "yes" : "no",
2023 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002025 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002027 err_free_input_dev:
2028 input_free_device(input);
2029 err_uninstall_notify:
2030 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2031 acpi_video_bus_notify);
2032 err_stop_video:
2033 acpi_video_bus_stop_devices(video);
2034 acpi_video_bus_put_devices(video);
2035 kfree(video->attached_array);
2036 acpi_video_bus_remove_fs(device);
2037 err_free_video:
2038 kfree(video);
2039 acpi_driver_data(device) = NULL;
2040
2041 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042}
2043
Len Brown4be44fc2005-08-05 00:44:28 -04002044static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
Len Brown4be44fc2005-08-05 00:44:28 -04002046 acpi_status status = 0;
2047 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002051 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002053 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 acpi_video_bus_stop_devices(video);
2056
Patrick Mochel90130262006-05-19 16:54:48 -04002057 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002058 ACPI_DEVICE_NOTIFY,
2059 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 acpi_video_bus_put_devices(video);
2062 acpi_video_bus_remove_fs(device);
2063
Luming Yue9dab192007-08-20 18:23:53 +08002064 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002065 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 kfree(video);
2067
Patrick Mocheld550d982006-06-27 00:41:40 -04002068 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
Len Brown4be44fc2005-08-05 00:44:28 -04002071static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
Len Brown4be44fc2005-08-05 00:44:28 -04002073 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
2076 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002077 acpi_dbg_level = 0xFFFFFFFF;
2078 acpi_dbg_layer = 0x08000000;
2079 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2082 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002083 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 acpi_video_dir->owner = THIS_MODULE;
2085
2086 result = acpi_bus_register_driver(&acpi_video_bus);
2087 if (result < 0) {
2088 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002089 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
2091
Patrick Mocheld550d982006-06-27 00:41:40 -04002092 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093}
2094
Len Brown4be44fc2005-08-05 00:44:28 -04002095static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098 acpi_bus_unregister_driver(&acpi_video_bus);
2099
2100 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2101
Patrick Mocheld550d982006-06-27 00:41:40 -04002102 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
2105module_init(acpi_video_init);
2106module_exit(acpi_video_exit);