blob: 98f1d4e559818c723b79cb6f5278b97f0ebd17a7 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080062#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Rui Zhang82cae992007-01-03 23:40:53 -050064#define ACPI_VIDEO_DISPLAY_CRT 1
65#define ACPI_VIDEO_DISPLAY_TV 2
66#define ACPI_VIDEO_DISPLAY_DVI 3
67#define ACPI_VIDEO_DISPLAY_LCD 4
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050070ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Len Brownf52fd662007-02-12 22:42:12 -050072MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050073MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_LICENSE("GPL");
75
Zhang Rui8a681a42008-01-25 14:47:49 +080076static int brightness_switch_enabled = 1;
77module_param(brightness_switch_enabled, bool, 0644);
78
Len Brown4be44fc2005-08-05 00:44:28 -040079static int acpi_video_bus_add(struct acpi_device *device);
80static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080081static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Renninger1ba90e32007-07-23 14:44:41 +020083static const struct acpi_device_id video_device_ids[] = {
84 {ACPI_VIDEO_HID, 0},
85 {"", 0},
86};
87MODULE_DEVICE_TABLE(acpi, video_device_ids);
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050090 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020092 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .ops = {
94 .add = acpi_video_bus_add,
95 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080096 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040097 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
100struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400101 u8 multihead:1; /* can switch video heads */
102 u8 rom:1; /* can retrieve a video rom */
103 u8 post:1; /* can configure the head to */
104 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
107struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400108 u8 _DOS:1; /*Enable/Disable output switching */
109 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM:1; /*Get ROM Data */
111 u8 _GPD:1; /*Get POST Device */
112 u8 _SPD:1; /*Set POST Device */
113 u8 _VPO:1; /*Video POST Options */
114 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
Len Brown4be44fc2005-08-05 00:44:28 -0400117struct acpi_video_device_attrib {
118 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100119 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400120 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100121 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400122 u32 bios_can_detect:1; /*BIOS can detect the device */
123 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
124 the VGA device. */
125 u32 pipe_id:3; /*For VGA multiple-head devices. */
126 u32 reserved:10; /*Must be 0 */
127 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
130struct acpi_video_enumerated_device {
131 union {
132 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400133 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 } value;
135 struct acpi_video_device *bind_info;
136};
137
138struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400139 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 u8 attached_count;
143 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400145 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500146 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400147 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800148 struct input_dev *input;
149 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 u8 crt:1;
154 u8 lcd:1;
155 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500156 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 bios:1;
158 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500159 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
161
162struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400163 u8 _ADR:1; /*Return the unique ID */
164 u8 _BCL:1; /*Query list of brightness control levels supported */
165 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800166 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400167 u8 _DDC:1; /*Return the EDID for this device */
168 u8 _DCS:1; /*Return status of output device */
169 u8 _DGS:1; /*Query graphics state */
170 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 int curr;
175 int count;
176 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177};
178
179struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400180 unsigned long device_id;
181 struct acpi_video_device_flags flags;
182 struct acpi_video_device_cap cap;
183 struct list_head entry;
184 struct acpi_video_bus *video;
185 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800187 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800188 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800189 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192/* bus */
193static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
194static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .open = acpi_video_bus_info_open_fs,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
201static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
202static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 .open = acpi_video_bus_ROM_open_fs,
204 .read = seq_read,
205 .llseek = seq_lseek,
206 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
Len Brown4be44fc2005-08-05 00:44:28 -0400209static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
210 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400212 .open = acpi_video_bus_POST_info_open_fs,
213 .read = seq_read,
214 .llseek = seq_lseek,
215 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
218static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
219static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 .open = acpi_video_bus_POST_open_fs,
221 .read = seq_read,
222 .llseek = seq_lseek,
223 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
227static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400228 .open = acpi_video_bus_DOS_open_fs,
229 .read = seq_read,
230 .llseek = seq_lseek,
231 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400235static int acpi_video_device_info_open_fs(struct inode *inode,
236 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400238 .open = acpi_video_device_info_open_fs,
239 .read = seq_read,
240 .llseek = seq_lseek,
241 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242};
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244static int acpi_video_device_state_open_fs(struct inode *inode,
245 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400247 .open = acpi_video_device_state_open_fs,
248 .read = seq_read,
249 .llseek = seq_lseek,
250 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251};
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253static int acpi_video_device_brightness_open_fs(struct inode *inode,
254 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 .open = acpi_video_device_brightness_open_fs,
257 .read = seq_read,
258 .llseek = seq_lseek,
259 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262static int acpi_video_device_EDID_open_fs(struct inode *inode,
263 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 .open = acpi_video_device_EDID_open_fs,
266 .read = seq_read,
267 .llseek = seq_lseek,
268 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 "motherboard VGA device",
273 "PCI VGA device",
274 "AGP VGA device",
275 "UNKNOWN",
276};
277
Len Brown4be44fc2005-08-05 00:44:28 -0400278static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
279static void acpi_video_device_rebind(struct acpi_video_bus *video);
280static void acpi_video_device_bind(struct acpi_video_bus *video,
281 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800283static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
284 int level);
285static int acpi_video_device_lcd_get_level_current(
286 struct acpi_video_device *device,
287 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400288static int acpi_video_get_next_level(struct acpi_video_device *device,
289 u32 level_current, u32 event);
290static void acpi_video_switch_brightness(struct acpi_video_device *device,
291 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800292static int acpi_video_device_get_state(struct acpi_video_device *device,
293 unsigned long *state);
294static int acpi_video_output_get(struct output_device *od);
295static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Yu Luming2f3d0002006-11-11 02:40:34 +0800297/*backlight device sysfs support*/
298static int acpi_video_get_brightness(struct backlight_device *bd)
299{
300 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000301 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800302 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100303 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800304 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000305 for (i = 2; i < vd->brightness->count; i++) {
306 if (vd->brightness->levels[i] == cur_level)
307 /* The first two entries are special - see page 575
308 of the ACPI spec 3.0 */
309 return i-2;
310 }
311 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800312}
313
314static int acpi_video_set_brightness(struct backlight_device *bd)
315{
Matthew Garrett38531e62007-12-26 02:03:26 +0000316 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800317 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100318 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000319 acpi_video_device_lcd_set_level(vd,
320 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800321 return 0;
322}
323
Richard Purdie599a52d2007-02-10 23:07:48 +0000324static struct backlight_ops acpi_backlight_ops = {
325 .get_brightness = acpi_video_get_brightness,
326 .update_status = acpi_video_set_brightness,
327};
328
Luming Yu23b0f012007-05-09 21:07:05 +0800329/*video output device sysfs support*/
330static int acpi_video_output_get(struct output_device *od)
331{
332 unsigned long state;
333 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700334 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800335 acpi_video_device_get_state(vd, &state);
336 return (int)state;
337}
338
339static int acpi_video_output_set(struct output_device *od)
340{
341 unsigned long state = od->request_state;
342 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700343 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800344 return acpi_video_device_set_state(vd, state);
345}
346
347static struct output_properties acpi_output_properties = {
348 .set_state = acpi_video_output_set,
349 .get_status = acpi_video_output_get,
350};
Zhang Rui702ed512008-01-17 15:51:22 +0800351
352
353/* thermal cooling device callbacks */
354static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
355{
356 struct acpi_device *device = cdev->devdata;
357 struct acpi_video_device *video = acpi_driver_data(device);
358
359 return sprintf(buf, "%d\n", video->brightness->count - 3);
360}
361
362static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
363{
364 struct acpi_device *device = cdev->devdata;
365 struct acpi_video_device *video = acpi_driver_data(device);
366 unsigned long level;
367 int state;
368
369 acpi_video_device_lcd_get_level_current(video, &level);
370 for (state = 2; state < video->brightness->count; state++)
371 if (level == video->brightness->levels[state])
372 return sprintf(buf, "%d\n",
373 video->brightness->count - state - 1);
374
375 return -EINVAL;
376}
377
378static int
379video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
380{
381 struct acpi_device *device = cdev->devdata;
382 struct acpi_video_device *video = acpi_driver_data(device);
383 int level;
384
385 if ( state >= video->brightness->count - 2)
386 return -EINVAL;
387
388 state = video->brightness->count - state;
389 level = video->brightness->levels[state -1];
390 return acpi_video_device_lcd_set_level(video, level);
391}
392
393static struct thermal_cooling_device_ops video_cooling_ops = {
394 .get_max_state = video_get_max_state,
395 .get_cur_state = video_get_cur_state,
396 .set_cur_state = video_set_cur_state,
397};
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/* --------------------------------------------------------------------------
400 Video Management
401 -------------------------------------------------------------------------- */
402
403/* device */
404
405static int
Len Brown4be44fc2005-08-05 00:44:28 -0400406acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
Len Brown4be44fc2005-08-05 00:44:28 -0400408 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400409
410 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Patrick Mocheld550d982006-06-27 00:41:40 -0400412 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415static int
Len Brown4be44fc2005-08-05 00:44:28 -0400416acpi_video_device_get_state(struct acpi_video_device *device,
417 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Len Brown4be44fc2005-08-05 00:44:28 -0400419 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Patrick Mochel90130262006-05-19 16:54:48 -0400421 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
426static int
Len Brown4be44fc2005-08-05 00:44:28 -0400427acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Len Brown4be44fc2005-08-05 00:44:28 -0400429 int status;
430 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
431 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400432 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400436 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Patrick Mocheld550d982006-06-27 00:41:40 -0400438 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441static int
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
443 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 int status;
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 *levels = NULL;
451
Patrick Mochel90130262006-05-19 16:54:48 -0400452 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400454 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400455 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500456 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400457 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 status = -EFAULT;
459 goto err;
460 }
461
462 *levels = obj;
463
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Len Brown4be44fc2005-08-05 00:44:28 -0400466 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800467 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Patrick Mocheld550d982006-06-27 00:41:40 -0400469 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
472static int
Len Brown4be44fc2005-08-05 00:44:28 -0400473acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400475 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400476 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
477 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400482 if (device->cap._BCM)
483 status = acpi_evaluate_object(device->dev->handle, "_BCM",
484 &args, NULL);
485 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400486 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
488
489static int
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
491 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400493 if (device->cap._BQC)
494 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
495 level);
496 *level = device->brightness->curr;
497 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
500static int
Len Brown4be44fc2005-08-05 00:44:28 -0400501acpi_video_device_EDID(struct acpi_video_device *device,
502 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Len Brown4be44fc2005-08-05 00:44:28 -0400504 int status;
505 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
506 union acpi_object *obj;
507 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
508 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 *edid = NULL;
512
513 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400514 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (length == 128)
516 arg0.integer.value = 1;
517 else if (length == 256)
518 arg0.integer.value = 2;
519 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Patrick Mochel90130262006-05-19 16:54:48 -0400522 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400524 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200526 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 if (obj && obj->type == ACPI_TYPE_BUFFER)
529 *edid = obj;
530 else {
Len Brown64684632006-06-26 23:41:38 -0400531 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 status = -EFAULT;
533 kfree(obj);
534 }
535
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/* bus */
540
541static int
Len Brown4be44fc2005-08-05 00:44:28 -0400542acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Len Brown4be44fc2005-08-05 00:44:28 -0400544 int status;
545 unsigned long tmp;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 arg0.integer.value = option;
551
Patrick Mochel90130262006-05-19 16:54:48 -0400552 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400554 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Patrick Mocheld550d982006-06-27 00:41:40 -0400556 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559static int
Len Brown4be44fc2005-08-05 00:44:28 -0400560acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 int status;
563
Patrick Mochel90130262006-05-19 16:54:48 -0400564 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Patrick Mocheld550d982006-06-27 00:41:40 -0400566 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569static int
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_video_bus_POST_options(struct acpi_video_bus *video,
571 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Len Brown4be44fc2005-08-05 00:44:28 -0400573 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Patrick Mochel90130262006-05-19 16:54:48 -0400575 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *options &= 3;
577
Patrick Mocheld550d982006-06-27 00:41:40 -0400578 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581/*
582 * Arg:
583 * video : video bus device pointer
584 * bios_flag :
585 * 0. The system BIOS should NOT automatically switch(toggle)
586 * the active display output.
587 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100588 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 * 2. The _DGS value should be locked.
590 * 3. The system BIOS should not automatically switch (toggle) the
591 * active display output, but instead generate the display switch
592 * event notify code.
593 * lcd_flag :
594 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100595 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100597 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 * Return Value:
599 * -1 wrong arg.
600 */
601
602static int
Len Brown4be44fc2005-08-05 00:44:28 -0400603acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Len Brown4be44fc2005-08-05 00:44:28 -0400605 acpi_integer status = 0;
606 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
607 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Len Brown4be44fc2005-08-05 00:44:28 -0400610 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 status = -1;
612 goto Failed;
613 }
614 arg0.integer.value = (lcd_flag << 2) | bios_flag;
615 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400616 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400619 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
622/*
623 * Arg:
624 * device : video output device (LCD, CRT, ..)
625 *
626 * Return Value:
627 * None
628 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100629 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 * device.
631 */
632
Len Brown4be44fc2005-08-05 00:44:28 -0400633static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 acpi_handle h_dummy1;
636 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800637 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 union acpi_object *obj = NULL;
639 struct acpi_video_device_brightness *br = NULL;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
William Lee Irwin III98934de2007-12-12 03:56:55 -0800642 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Patrick Mochel90130262006-05-19 16:54:48 -0400644 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 device->cap._ADR = 1;
646 }
Patrick Mochel90130262006-05-19 16:54:48 -0400647 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400648 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
Patrick Mochel90130262006-05-19 16:54:48 -0400650 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400651 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800653 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
654 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400655 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400656 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
Patrick Mochel90130262006-05-19 16:54:48 -0400658 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 device->cap._DCS = 1;
660 }
Patrick Mochel90130262006-05-19 16:54:48 -0400661 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 device->cap._DGS = 1;
663 }
Patrick Mochel90130262006-05-19 16:54:48 -0400664 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 device->cap._DSS = 1;
666 }
667
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400668 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400670 if (obj->package.count >= 2) {
671 int count = 0;
672 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400673
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400674 br = kzalloc(sizeof(*br), GFP_KERNEL);
675 if (!br) {
676 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400678 br->levels = kmalloc(obj->package.count *
679 sizeof *(br->levels), GFP_KERNEL);
680 if (!br->levels)
681 goto out;
682
683 for (i = 0; i < obj->package.count; i++) {
684 o = (union acpi_object *)&obj->package.
685 elements[i];
686 if (o->type != ACPI_TYPE_INTEGER) {
687 printk(KERN_ERR PREFIX "Invalid data\n");
688 continue;
689 }
690 br->levels[count] = (u32) o->integer.value;
691
692 if (br->levels[count] > max_level)
693 max_level = br->levels[count];
694 count++;
695 }
696 out:
697 if (count < 2) {
698 kfree(br->levels);
699 kfree(br);
700 } else {
701 br->count = count;
702 device->brightness = br;
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "found %d brightness levels\n",
705 count));
706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
708 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400709
710 } else {
711 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500714 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Zhao Yakui7c0ea452008-03-11 16:56:47 +0800716 if (device->cap._BCL && device->cap._BCM && max_level > 0) {
Zhang Rui702ed512008-01-17 15:51:22 +0800717 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800718 static int count = 0;
719 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800720 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
721 if (!name)
722 return;
723
Yu Luming2f3d0002006-11-11 02:40:34 +0800724 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800725 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000726 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000727 device->backlight->props.max_brightness = device->brightness->count-3;
728 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000729 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800730 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800731
732 device->cdev = thermal_cooling_device_register("LCD",
733 device->dev, &video_cooling_ops);
Thomas Sujith43ff39f2008-02-15 18:29:18 -0500734 if (IS_ERR(device->cdev))
735 return;
736
Zhang Rui702ed512008-01-17 15:51:22 +0800737 if (device->cdev) {
738 printk(KERN_INFO PREFIX
739 "%s is registered as cooling_device%d\n",
740 device->dev->dev.bus_id, device->cdev->id);
741 result = sysfs_create_link(&device->dev->dev.kobj,
742 &device->cdev->device.kobj,
743 "thermal_cooling");
744 if (result)
745 printk(KERN_ERR PREFIX "Create sysfs link\n");
746 result = sysfs_create_link(&device->cdev->device.kobj,
747 &device->dev->dev.kobj,
748 "device");
749 if (result)
750 printk(KERN_ERR PREFIX "Create sysfs link\n");
751 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800752 }
Luming Yu23b0f012007-05-09 21:07:05 +0800753 if (device->cap._DCS && device->cap._DSS){
754 static int count = 0;
755 char *name;
756 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
757 if (!name)
758 return;
759 sprintf(name, "acpi_video%d", count++);
760 device->output_dev = video_output_register(name,
761 NULL, device, &acpi_output_properties);
762 kfree(name);
763 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
767/*
768 * Arg:
769 * device : video output device (VGA)
770 *
771 * Return Value:
772 * None
773 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100774 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 */
776
Len Brown4be44fc2005-08-05 00:44:28 -0400777static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Len Brown4be44fc2005-08-05 00:44:28 -0400779 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
William Lee Irwin III98934de2007-12-12 03:56:55 -0800781 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400782 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 video->cap._DOS = 1;
784 }
Patrick Mochel90130262006-05-19 16:54:48 -0400785 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 video->cap._DOD = 1;
787 }
Patrick Mochel90130262006-05-19 16:54:48 -0400788 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 video->cap._ROM = 1;
790 }
Patrick Mochel90130262006-05-19 16:54:48 -0400791 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 video->cap._GPD = 1;
793 }
Patrick Mochel90130262006-05-19 16:54:48 -0400794 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 video->cap._SPD = 1;
796 }
Patrick Mochel90130262006-05-19 16:54:48 -0400797 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 video->cap._VPO = 1;
799 }
800}
801
802/*
803 * Check whether the video bus device has required AML method to
804 * support the desired features
805 */
806
Len Brown4be44fc2005-08-05 00:44:28 -0400807static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Len Brown4be44fc2005-08-05 00:44:28 -0400809 acpi_status status = -ENOENT;
Len Brownf0d67522008-03-18 01:43:53 -0400810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400813 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 /* Since there is no HID, CID and so on for VGA driver, we have
816 * to check well known required nodes.
817 */
818
Julius Volz98fb8fe2007-02-20 16:38:40 +0100819 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400820 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 video->flags.multihead = 1;
822 status = 0;
823 }
824
Julius Volz98fb8fe2007-02-20 16:38:40 +0100825 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400826 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 video->flags.rom = 1;
828 status = 0;
829 }
830
Julius Volz98fb8fe2007-02-20 16:38:40 +0100831 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400832 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 video->flags.post = 1;
834 status = 0;
835 }
836
Patrick Mocheld550d982006-06-27 00:41:40 -0400837 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
839
840/* --------------------------------------------------------------------------
841 FS Interface (/proc)
842 -------------------------------------------------------------------------- */
843
Len Brown4be44fc2005-08-05 00:44:28 -0400844static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846/* video devices */
847
Len Brown4be44fc2005-08-05 00:44:28 -0400848static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200850 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 if (!dev)
854 goto end;
855
856 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
857 seq_printf(seq, "type: ");
858 if (dev->flags.crt)
859 seq_printf(seq, "CRT\n");
860 else if (dev->flags.lcd)
861 seq_printf(seq, "LCD\n");
862 else if (dev->flags.tvout)
863 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500864 else if (dev->flags.dvi)
865 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 else
867 seq_printf(seq, "UNKNOWN\n");
868
Len Brown4be44fc2005-08-05 00:44:28 -0400869 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
875static int
Len Brown4be44fc2005-08-05 00:44:28 -0400876acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 return single_open(file, acpi_video_device_info_seq_show,
879 PDE(inode)->data);
880}
881
Len Brown4be44fc2005-08-05 00:44:28 -0400882static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Len Brown4be44fc2005-08-05 00:44:28 -0400884 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200885 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400886 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 if (!dev)
890 goto end;
891
892 status = acpi_video_device_get_state(dev, &state);
893 seq_printf(seq, "state: ");
894 if (ACPI_SUCCESS(status))
895 seq_printf(seq, "0x%02lx\n", state);
896 else
897 seq_printf(seq, "<not supported>\n");
898
899 status = acpi_video_device_query(dev, &state);
900 seq_printf(seq, "query: ");
901 if (ACPI_SUCCESS(status))
902 seq_printf(seq, "0x%02lx\n", state);
903 else
904 seq_printf(seq, "<not supported>\n");
905
Len Brown4be44fc2005-08-05 00:44:28 -0400906 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400907 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
909
910static int
Len Brown4be44fc2005-08-05 00:44:28 -0400911acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912{
913 return single_open(file, acpi_video_device_state_seq_show,
914 PDE(inode)->data);
915}
916
917static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400918acpi_video_device_write_state(struct file *file,
919 const char __user * buffer,
920 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Len Brown4be44fc2005-08-05 00:44:28 -0400922 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200923 struct seq_file *m = file->private_data;
924 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400925 char str[12] = { 0 };
926 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400930 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400933 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935 str[count] = 0;
936 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400937 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 status = acpi_video_device_set_state(dev, state);
940
941 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400942 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Patrick Mocheld550d982006-06-27 00:41:40 -0400944 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
947static int
Len Brown4be44fc2005-08-05 00:44:28 -0400948acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200950 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400951 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 if (!dev || !dev->brightness) {
955 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400956 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958
959 seq_printf(seq, "levels: ");
960 for (i = 0; i < dev->brightness->count; i++)
961 seq_printf(seq, " %d", dev->brightness->levels[i]);
962 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
963
Patrick Mocheld550d982006-06-27 00:41:40 -0400964 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967static int
Len Brown4be44fc2005-08-05 00:44:28 -0400968acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 return single_open(file, acpi_video_device_brightness_seq_show,
971 PDE(inode)->data);
972}
973
974static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400975acpi_video_device_write_brightness(struct file *file,
976 const char __user * buffer,
977 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200979 struct seq_file *m = file->private_data;
980 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100981 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400982 unsigned int level = 0;
983 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Thomas Renninger59d399d2005-11-08 05:27:00 -0500986 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400987 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 str[count] = 0;
993 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400996 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Julius Volz98fb8fe2007-02-20 16:38:40 +0100998 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 for (i = 0; i < dev->brightness->count; i++)
1000 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -04001001 if (ACPI_SUCCESS
1002 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 dev->brightness->curr = level;
1004 break;
1005 }
1006
Patrick Mocheld550d982006-06-27 00:41:40 -04001007 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Len Brown4be44fc2005-08-05 00:44:28 -04001010static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001012 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001013 int status;
1014 int i;
1015 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 if (!dev)
1019 goto out;
1020
Len Brown4be44fc2005-08-05 00:44:28 -04001021 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001023 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
1025
1026 if (ACPI_FAILURE(status)) {
1027 goto out;
1028 }
1029
1030 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1031 for (i = 0; i < edid->buffer.length; i++)
1032 seq_putc(seq, edid->buffer.pointer[i]);
1033 }
1034
Len Brown4be44fc2005-08-05 00:44:28 -04001035 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (!edid)
1037 seq_printf(seq, "<not supported>\n");
1038 else
1039 kfree(edid);
1040
Patrick Mocheld550d982006-06-27 00:41:40 -04001041 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
1044static int
Len Brown4be44fc2005-08-05 00:44:28 -04001045acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
1047 return single_open(file, acpi_video_device_EDID_seq_show,
1048 PDE(inode)->data);
1049}
1050
Len Brown4be44fc2005-08-05 00:44:28 -04001051static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Len Brown4be44fc2005-08-05 00:44:28 -04001053 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 struct acpi_video_device *vid_dev;
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001058 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001060 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001062 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 if (!acpi_device_dir(device)) {
1065 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001066 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001068 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 acpi_device_dir(device)->owner = THIS_MODULE;
1070 }
1071
1072 /* 'info' [R] */
1073 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1074 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001075 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 else {
1077 entry->proc_fops = &acpi_video_device_info_fops;
1078 entry->data = acpi_driver_data(device);
1079 entry->owner = THIS_MODULE;
1080 }
1081
1082 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001083 entry =
1084 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1085 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001087 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001089 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 entry->data = acpi_driver_data(device);
1092 entry->owner = THIS_MODULE;
1093 }
1094
1095 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001096 entry =
1097 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1098 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001100 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001102 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 entry->data = acpi_driver_data(device);
1105 entry->owner = THIS_MODULE;
1106 }
1107
1108 /* 'EDID' [R] */
1109 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1110 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001111 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 else {
1113 entry->proc_fops = &acpi_video_device_EDID_fops;
1114 entry->data = acpi_driver_data(device);
1115 entry->owner = THIS_MODULE;
1116 }
1117
Patrick Mocheld550d982006-06-27 00:41:40 -04001118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Len Brown4be44fc2005-08-05 00:44:28 -04001121static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
1123 struct acpi_video_device *vid_dev;
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
1129 if (acpi_device_dir(device)) {
1130 remove_proc_entry("info", acpi_device_dir(device));
1131 remove_proc_entry("state", acpi_device_dir(device));
1132 remove_proc_entry("brightness", acpi_device_dir(device));
1133 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001134 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 acpi_device_dir(device) = NULL;
1136 }
1137
Patrick Mocheld550d982006-06-27 00:41:40 -04001138 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001142static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001144 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 if (!video)
1148 goto end;
1149
1150 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001151 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001153 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001155 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001158 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Len Brown4be44fc2005-08-05 00:44:28 -04001161static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Len Brown4be44fc2005-08-05 00:44:28 -04001163 return single_open(file, acpi_video_bus_info_seq_show,
1164 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Len Brown4be44fc2005-08-05 00:44:28 -04001167static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001169 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 if (!video)
1173 goto end;
1174
Harvey Harrison96b2dd12008-03-05 18:24:51 -08001175 printk(KERN_INFO PREFIX "Please implement %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 seq_printf(seq, "<TODO>\n");
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001179 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Len Brown4be44fc2005-08-05 00:44:28 -04001182static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
1184 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1185}
1186
Len Brown4be44fc2005-08-05 00:44:28 -04001187static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001189 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001190 unsigned long options;
1191 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 if (!video)
1195 goto end;
1196
1197 status = acpi_video_bus_POST_options(video, &options);
1198 if (ACPI_SUCCESS(status)) {
1199 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001200 printk(KERN_WARNING PREFIX
1201 "The motherboard VGA device is not listed as a possible POST device.\n");
1202 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001203 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 }
1205 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001206 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (options & 2)
1208 seq_printf(seq, " <PCI video>");
1209 if (options & 4)
1210 seq_printf(seq, " <AGP video>");
1211 seq_putc(seq, '\n');
1212 } else
1213 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001214 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
1218static int
Len Brown4be44fc2005-08-05 00:44:28 -04001219acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Len Brown4be44fc2005-08-05 00:44:28 -04001221 return single_open(file, acpi_video_bus_POST_info_seq_show,
1222 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Len Brown4be44fc2005-08-05 00:44:28 -04001225static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001227 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001228 int status;
1229 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (!video)
1233 goto end;
1234
Len Brown4be44fc2005-08-05 00:44:28 -04001235 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (!ACPI_SUCCESS(status)) {
1237 seq_printf(seq, "<not supported>\n");
1238 goto end;
1239 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001240 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Len Brown4be44fc2005-08-05 00:44:28 -04001242 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Len Brown4be44fc2005-08-05 00:44:28 -04001246static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001248 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Len Brown4be44fc2005-08-05 00:44:28 -04001251 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
Len Brown4be44fc2005-08-05 00:44:28 -04001256static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Len Brown4be44fc2005-08-05 00:44:28 -04001258 return single_open(file, acpi_video_bus_POST_seq_show,
1259 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260}
1261
Len Brown4be44fc2005-08-05 00:44:28 -04001262static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
1264 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1265}
1266
1267static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001268acpi_video_bus_write_POST(struct file *file,
1269 const char __user * buffer,
1270 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Len Brown4be44fc2005-08-05 00:44:28 -04001272 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001273 struct seq_file *m = file->private_data;
1274 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001275 char str[12] = { 0 };
1276 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001280 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 status = acpi_video_bus_POST_options(video, &options);
1283 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001284 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001287 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 str[count] = 0;
1290 opt = strtoul(str, NULL, 0);
1291 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001292 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Julius Volz98fb8fe2007-02-20 16:38:40 +01001294 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 options |= 1;
1296
1297 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001298 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001300 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 }
1303
Patrick Mocheld550d982006-06-27 00:41:40 -04001304 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001308acpi_video_bus_write_DOS(struct file *file,
1309 const char __user * buffer,
1310 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Len Brown4be44fc2005-08-05 00:44:28 -04001312 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001313 struct seq_file *m = file->private_data;
1314 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001315 char str[12] = { 0 };
1316 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001323 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 str[count] = 0;
1326 opt = strtoul(str, NULL, 0);
1327 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001328 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Len Brown4be44fc2005-08-05 00:44:28 -04001330 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001333 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Patrick Mocheld550d982006-06-27 00:41:40 -04001335 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Len Brown4be44fc2005-08-05 00:44:28 -04001338static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Matthew Garrett01195092008-01-17 03:39:36 +00001340 long device_id;
1341 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001342 struct proc_dir_entry *entry = NULL;
1343 struct acpi_video_bus *video;
Matthew Garrett01195092008-01-17 03:39:36 +00001344 struct device *dev;
1345
1346 status =
1347 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1348
1349 if (!ACPI_SUCCESS(status))
1350 return -ENODEV;
1351
1352 /* We need to attempt to determine whether the _ADR refers to a
1353 PCI device or not. There's no terribly good way to do this,
1354 so the best we can hope for is to assume that there'll never
1355 be a video device in the host bridge */
1356 if (device_id >= 0x10000) {
1357 /* It looks like a PCI device. Does it exist? */
1358 dev = acpi_get_physical_device(device->handle);
1359 } else {
1360 /* It doesn't look like a PCI device. Does its parent
1361 exist? */
1362 acpi_handle phandle;
1363 if (acpi_get_parent(device->handle, &phandle))
1364 return -ENODEV;
1365 dev = acpi_get_physical_device(phandle);
1366 }
1367 if (!dev)
1368 return -ENODEV;
1369 put_device(dev);
1370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001373 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 if (!acpi_device_dir(device)) {
1376 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001377 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001379 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 video->dir = acpi_device_dir(device);
1381 acpi_device_dir(device)->owner = THIS_MODULE;
1382 }
1383
1384 /* 'info' [R] */
1385 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1386 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001387 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 else {
1389 entry->proc_fops = &acpi_video_bus_info_fops;
1390 entry->data = acpi_driver_data(device);
1391 entry->owner = THIS_MODULE;
1392 }
1393
1394 /* 'ROM' [R] */
1395 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1396 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001397 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 else {
1399 entry->proc_fops = &acpi_video_bus_ROM_fops;
1400 entry->data = acpi_driver_data(device);
1401 entry->owner = THIS_MODULE;
1402 }
1403
1404 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001405 entry =
1406 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001408 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 else {
1410 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1411 entry->data = acpi_driver_data(device);
1412 entry->owner = THIS_MODULE;
1413 }
1414
1415 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001416 entry =
1417 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1418 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001420 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001422 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 entry->data = acpi_driver_data(device);
1425 entry->owner = THIS_MODULE;
1426 }
1427
1428 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001429 entry =
1430 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1431 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001433 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001435 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 entry->data = acpi_driver_data(device);
1438 entry->owner = THIS_MODULE;
1439 }
1440
Patrick Mocheld550d982006-06-27 00:41:40 -04001441 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442}
1443
Len Brown4be44fc2005-08-05 00:44:28 -04001444static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Len Brown4be44fc2005-08-05 00:44:28 -04001446 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001449 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 if (acpi_device_dir(device)) {
1452 remove_proc_entry("info", acpi_device_dir(device));
1453 remove_proc_entry("ROM", acpi_device_dir(device));
1454 remove_proc_entry("POST_info", acpi_device_dir(device));
1455 remove_proc_entry("POST", acpi_device_dir(device));
1456 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001457 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 acpi_device_dir(device) = NULL;
1459 }
1460
Patrick Mocheld550d982006-06-27 00:41:40 -04001461 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
1464/* --------------------------------------------------------------------------
1465 Driver Interface
1466 -------------------------------------------------------------------------- */
1467
1468/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001469static struct acpi_video_device_attrib*
1470acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1471{
1472 int count;
1473
1474 for(count = 0; count < video->attached_count; count++)
1475 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1476 return &(video->attached_array[count].value.attrib);
1477 return NULL;
1478}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480static int
Len Brown4be44fc2005-08-05 00:44:28 -04001481acpi_video_bus_get_one_device(struct acpi_device *device,
1482 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Len Brown4be44fc2005-08-05 00:44:28 -04001484 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001485 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001486 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001487 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001490 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Len Brown4be44fc2005-08-05 00:44:28 -04001492 status =
1493 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if (ACPI_SUCCESS(status)) {
1495
Burman Yan36bcbec2006-12-19 12:56:11 -08001496 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001498 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1501 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1502 acpi_driver_data(device) = data;
1503
1504 data->device_id = device_id;
1505 data->video = video;
1506 data->dev = device;
1507
Rui Zhang82cae992007-01-03 23:40:53 -05001508 attribute = acpi_video_get_device_attr(video, device_id);
1509
1510 if((attribute != NULL) && attribute->device_id_scheme) {
1511 switch (attribute->display_type) {
1512 case ACPI_VIDEO_DISPLAY_CRT:
1513 data->flags.crt = 1;
1514 break;
1515 case ACPI_VIDEO_DISPLAY_TV:
1516 data->flags.tvout = 1;
1517 break;
1518 case ACPI_VIDEO_DISPLAY_DVI:
1519 data->flags.dvi = 1;
1520 break;
1521 case ACPI_VIDEO_DISPLAY_LCD:
1522 data->flags.lcd = 1;
1523 break;
1524 default:
1525 data->flags.unknown = 1;
1526 break;
1527 }
1528 if(attribute->bios_can_detect)
1529 data->flags.bios = 1;
1530 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 acpi_video_device_bind(video, data);
1534 acpi_video_device_find_cap(data);
1535
Patrick Mochel90130262006-05-19 16:54:48 -04001536 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001537 ACPI_DEVICE_NOTIFY,
1538 acpi_video_device_notify,
1539 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (ACPI_FAILURE(status)) {
1541 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001542 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001543 if(data->brightness)
1544 kfree(data->brightness->levels);
1545 kfree(data->brightness);
1546 kfree(data);
1547 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001550 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001552 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554 acpi_video_device_add_fs(device);
1555
Patrick Mocheld550d982006-06-27 00:41:40 -04001556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 }
1558
Patrick Mocheld550d982006-06-27 00:41:40 -04001559 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
1562/*
1563 * Arg:
1564 * video : video bus device
1565 *
1566 * Return:
1567 * none
1568 *
1569 * Enumerate the video device list of the video bus,
1570 * bind the ids with the corresponding video devices
1571 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001572 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Len Brown4be44fc2005-08-05 00:44:28 -04001574static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001576 struct acpi_video_device *dev;
1577
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001578 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001579
1580 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001581 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001582
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001583 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
1586/*
1587 * Arg:
1588 * video : video bus device
1589 * device : video output device under the video
1590 * bus
1591 *
1592 * Return:
1593 * none
1594 *
1595 * Bind the ids with the corresponding video devices
1596 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001597 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599static void
Len Brown4be44fc2005-08-05 00:44:28 -04001600acpi_video_device_bind(struct acpi_video_bus *video,
1601 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
Len Brown4be44fc2005-08-05 00:44:28 -04001603 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605#define IDS_VAL(i) video->attached_array[i].value.int_val
1606#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001607
1608 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1609 i < video->attached_count; i++) {
1610 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 IDS_BIND(i) = device;
1612 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1613 }
1614 }
1615#undef IDS_VAL
1616#undef IDS_BIND
1617}
1618
1619/*
1620 * Arg:
1621 * video : video bus device
1622 *
1623 * Return:
1624 * < 0 : error
1625 *
1626 * Call _DOD to enumerate all devices attached to display adapter
1627 *
Len Brown4be44fc2005-08-05 00:44:28 -04001628 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
1630static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1631{
Len Brown4be44fc2005-08-05 00:44:28 -04001632 int status;
1633 int count;
1634 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001636 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1637 union acpi_object *dod = NULL;
1638 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Patrick Mochel90130262006-05-19 16:54:48 -04001640 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001642 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001643 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 }
1645
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001646 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001648 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 status = -EFAULT;
1650 goto out;
1651 }
1652
1653 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001654 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Len Brown4be44fc2005-08-05 00:44:28 -04001656 active_device_list = kmalloc((1 +
1657 dod->package.count) *
1658 sizeof(struct
1659 acpi_video_enumerated_device),
1660 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 if (!active_device_list) {
1663 status = -ENOMEM;
1664 goto out;
1665 }
1666
1667 count = 0;
1668 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001669 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001672 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001673 active_device_list[i].value.int_val =
1674 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 }
1676 active_device_list[i].value.int_val = obj->integer.value;
1677 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001678 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1679 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 count++;
1681 }
1682 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1683
Jesper Juhl6044ec82005-11-07 01:01:32 -08001684 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 video->attached_array = active_device_list;
1687 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001688 out:
Len Brown02438d82006-06-30 03:19:10 -04001689 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001690 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691}
1692
Len Brown4be44fc2005-08-05 00:44:28 -04001693static int
1694acpi_video_get_next_level(struct acpi_video_device *device,
1695 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001697 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001698 max = max_below = 0;
1699 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001700 /* Find closest level to level_current */
1701 for (i = 0; i < device->brightness->count; i++) {
1702 l = device->brightness->levels[i];
1703 if (abs(l - level_current) < abs(delta)) {
1704 delta = l - level_current;
1705 if (!delta)
1706 break;
1707 }
1708 }
1709 /* Ajust level_current to closest available level */
1710 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001711 for (i = 0; i < device->brightness->count; i++) {
1712 l = device->brightness->levels[i];
1713 if (l < min)
1714 min = l;
1715 if (l > max)
1716 max = l;
1717 if (l < min_above && l > level_current)
1718 min_above = l;
1719 if (l > max_below && l < level_current)
1720 max_below = l;
1721 }
1722
1723 switch (event) {
1724 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1725 return (level_current < max) ? min_above : min;
1726 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1727 return (level_current < max) ? min_above : max;
1728 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1729 return (level_current > min) ? max_below : min;
1730 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1731 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1732 return 0;
1733 default:
1734 return level_current;
1735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738static void
Len Brown4be44fc2005-08-05 00:44:28 -04001739acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
1741 unsigned long level_current, level_next;
1742 acpi_video_device_lcd_get_level_current(device, &level_current);
1743 level_next = acpi_video_get_next_level(device, level_current, event);
1744 acpi_video_device_lcd_set_level(device, level_next);
1745}
1746
1747static int
Len Brown4be44fc2005-08-05 00:44:28 -04001748acpi_video_bus_get_devices(struct acpi_video_bus *video,
1749 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750{
Len Brown4be44fc2005-08-05 00:44:28 -04001751 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001752 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
1754 acpi_video_device_enumerate(video);
1755
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001756 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
1758 status = acpi_video_bus_get_one_device(dev, video);
1759 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001760 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 continue;
1762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001764 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
Len Brown4be44fc2005-08-05 00:44:28 -04001767static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
Karol Kozimor031ec772005-07-30 04:18:00 -04001769 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 struct acpi_video_bus *video;
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001774 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
1776 video = device->video;
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 acpi_video_device_remove_fs(device->dev);
1779
Patrick Mochel90130262006-05-19 16:54:48 -04001780 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001781 ACPI_DEVICE_NOTIFY,
1782 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001783 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001784 if (device->cdev) {
1785 sysfs_remove_link(&device->dev->dev.kobj,
1786 "thermal_cooling");
1787 sysfs_remove_link(&device->cdev->device.kobj,
1788 "device");
1789 thermal_cooling_device_unregister(device->cdev);
1790 device->cdev = NULL;
1791 }
Luming Yu23b0f012007-05-09 21:07:05 +08001792 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001793
Patrick Mocheld550d982006-06-27 00:41:40 -04001794 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
Len Brown4be44fc2005-08-05 00:44:28 -04001797static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
Len Brown4be44fc2005-08-05 00:44:28 -04001799 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001800 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001802 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001804 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001806 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001807 if (ACPI_FAILURE(status))
1808 printk(KERN_WARNING PREFIX
1809 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001811 if (dev->brightness) {
1812 kfree(dev->brightness->levels);
1813 kfree(dev->brightness);
1814 }
1815 list_del(&dev->entry);
1816 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 }
1818
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001819 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001820
Patrick Mocheld550d982006-06-27 00:41:40 -04001821 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822}
1823
1824/* acpi_video interface */
1825
Len Brown4be44fc2005-08-05 00:44:28 -04001826static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
Zhang Ruia21101c2007-09-14 11:46:22 +08001828 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829}
1830
Len Brown4be44fc2005-08-05 00:44:28 -04001831static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
1833 return acpi_video_bus_DOS(video, 0, 1);
1834}
1835
Len Brown4be44fc2005-08-05 00:44:28 -04001836static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001838 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001839 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001840 struct input_dev *input;
1841 int keycode;
1842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001844 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001846 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001847 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001850 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001852 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001853 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 break;
1855
Julius Volz98fb8fe2007-02-20 16:38:40 +01001856 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 * connector. */
1858 acpi_video_device_enumerate(video);
1859 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001860 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001861 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 break;
1863
Len Brown4be44fc2005-08-05 00:44:28 -04001864 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001865 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001866 keycode = KEY_SWITCHVIDEOMODE;
1867 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001868 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001869 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001870 keycode = KEY_VIDEO_NEXT;
1871 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001872 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001873 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001874 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 break;
1876
1877 default:
Luming Yue9dab192007-08-20 18:23:53 +08001878 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001880 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 break;
1882 }
1883
Zhang Rui7761f632008-01-25 14:48:12 +08001884 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001885 input_report_key(input, keycode, 1);
1886 input_sync(input);
1887 input_report_key(input, keycode, 0);
1888 input_sync(input);
1889
Patrick Mocheld550d982006-06-27 00:41:40 -04001890 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891}
1892
Len Brown4be44fc2005-08-05 00:44:28 -04001893static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001895 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001896 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001897 struct acpi_video_bus *bus;
1898 struct input_dev *input;
1899 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001902 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001904 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001905 bus = video_device->video;
1906 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
1908 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001909 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001910 if (brightness_switch_enabled)
1911 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001912 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001913 keycode = KEY_BRIGHTNESS_CYCLE;
1914 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001915 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001916 if (brightness_switch_enabled)
1917 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001918 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001919 keycode = KEY_BRIGHTNESSUP;
1920 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001921 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001922 if (brightness_switch_enabled)
1923 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001924 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001925 keycode = KEY_BRIGHTNESSDOWN;
1926 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001927 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001928 if (brightness_switch_enabled)
1929 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001930 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001931 keycode = KEY_BRIGHTNESS_ZERO;
1932 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001933 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001934 if (brightness_switch_enabled)
1935 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001936 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001937 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 break;
1939 default:
Luming Yue9dab192007-08-20 18:23:53 +08001940 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001942 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 break;
1944 }
Luming Yue9dab192007-08-20 18:23:53 +08001945
Zhang Rui7761f632008-01-25 14:48:12 +08001946 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001947 input_report_key(input, keycode, 1);
1948 input_sync(input);
1949 input_report_key(input, keycode, 0);
1950 input_sync(input);
1951
Patrick Mocheld550d982006-06-27 00:41:40 -04001952 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953}
1954
Zhang Ruie6d9da12007-08-25 02:23:31 -04001955static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001956static int acpi_video_resume(struct acpi_device *device)
1957{
1958 struct acpi_video_bus *video;
1959 struct acpi_video_device *video_device;
1960 int i;
1961
1962 if (!device || !acpi_driver_data(device))
1963 return -EINVAL;
1964
1965 video = acpi_driver_data(device);
1966
1967 for (i = 0; i < video->attached_count; i++) {
1968 video_device = video->attached_array[i].bind_info;
1969 if (video_device && video_device->backlight)
1970 acpi_video_set_brightness(video_device->backlight);
1971 }
1972 return AE_OK;
1973}
1974
Len Brown4be44fc2005-08-05 00:44:28 -04001975static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001977 acpi_status status;
1978 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001979 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001980 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Burman Yan36bcbec2006-12-19 12:56:11 -08001982 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001984 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Zhang Ruie6d9da12007-08-25 02:23:31 -04001986 /* a hack to fix the duplicate name "VID" problem on T61 */
1987 if (!strcmp(device->pnp.bus_id, "VID")) {
1988 if (instance)
1989 device->pnp.bus_id[3] = '0' + instance;
1990 instance ++;
1991 }
1992
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001993 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1995 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1996 acpi_driver_data(device) = video;
1997
1998 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001999 error = acpi_video_bus_check(video);
2000 if (error)
2001 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002003 error = acpi_video_bus_add_fs(device);
2004 if (error)
2005 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002007 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 INIT_LIST_HEAD(&video->video_device_list);
2009
2010 acpi_video_bus_get_devices(video, device);
2011 acpi_video_bus_start_devices(video);
2012
Patrick Mochel90130262006-05-19 16:54:48 -04002013 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002014 ACPI_DEVICE_NOTIFY,
2015 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 if (ACPI_FAILURE(status)) {
2017 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04002018 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002019 error = -ENODEV;
2020 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 }
2022
Luming Yue9dab192007-08-20 18:23:53 +08002023 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002024 if (!input) {
2025 error = -ENOMEM;
2026 goto err_uninstall_notify;
2027 }
Luming Yue9dab192007-08-20 18:23:53 +08002028
2029 snprintf(video->phys, sizeof(video->phys),
2030 "%s/video/input0", acpi_device_hid(video->device));
2031
2032 input->name = acpi_device_name(video->device);
2033 input->phys = video->phys;
2034 input->id.bustype = BUS_HOST;
2035 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002036 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002037 input->evbit[0] = BIT(EV_KEY);
2038 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2039 set_bit(KEY_VIDEO_NEXT, input->keybit);
2040 set_bit(KEY_VIDEO_PREV, input->keybit);
2041 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2042 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2043 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2044 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2045 set_bit(KEY_DISPLAY_OFF, input->keybit);
2046 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002047
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002048 error = input_register_device(input);
2049 if (error)
2050 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002053 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2054 video->flags.multihead ? "yes" : "no",
2055 video->flags.rom ? "yes" : "no",
2056 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002058 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002060 err_free_input_dev:
2061 input_free_device(input);
2062 err_uninstall_notify:
2063 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2064 acpi_video_bus_notify);
2065 err_stop_video:
2066 acpi_video_bus_stop_devices(video);
2067 acpi_video_bus_put_devices(video);
2068 kfree(video->attached_array);
2069 acpi_video_bus_remove_fs(device);
2070 err_free_video:
2071 kfree(video);
2072 acpi_driver_data(device) = NULL;
2073
2074 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
Len Brown4be44fc2005-08-05 00:44:28 -04002077static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Len Brown4be44fc2005-08-05 00:44:28 -04002079 acpi_status status = 0;
2080 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002084 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002086 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088 acpi_video_bus_stop_devices(video);
2089
Patrick Mochel90130262006-05-19 16:54:48 -04002090 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002091 ACPI_DEVICE_NOTIFY,
2092 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 acpi_video_bus_put_devices(video);
2095 acpi_video_bus_remove_fs(device);
2096
Luming Yue9dab192007-08-20 18:23:53 +08002097 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002098 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 kfree(video);
2100
Patrick Mocheld550d982006-06-27 00:41:40 -04002101 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102}
2103
Len Brown4be44fc2005-08-05 00:44:28 -04002104static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
Len Brown4be44fc2005-08-05 00:44:28 -04002106 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002110 acpi_dbg_level = 0xFFFFFFFF;
2111 acpi_dbg_layer = 0x08000000;
2112 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
2114 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2115 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 acpi_video_dir->owner = THIS_MODULE;
2118
2119 result = acpi_bus_register_driver(&acpi_video_bus);
2120 if (result < 0) {
2121 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002122 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 }
2124
Patrick Mocheld550d982006-06-27 00:41:40 -04002125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
Len Brown4be44fc2005-08-05 00:44:28 -04002128static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 acpi_bus_unregister_driver(&acpi_video_bus);
2132
2133 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2134
Patrick Mocheld550d982006-06-27 00:41:40 -04002135 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138module_init(acpi_video_init);
2139module_exit(acpi_video_exit);