blob: eab9c4213b49625a800c42b581b0e6931cb9c39a [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
Len Brown4be44fc2005-08-05 00:44:28 -040076static int acpi_video_bus_add(struct acpi_device *device);
77static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Thomas Renninger1ba90e32007-07-23 14:44:41 +020079static const struct acpi_device_id video_device_ids[] = {
80 {ACPI_VIDEO_HID, 0},
81 {"", 0},
82};
83MODULE_DEVICE_TABLE(acpi, video_device_ids);
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050086 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020088 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .ops = {
90 .add = acpi_video_bus_add,
91 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040092 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040096 u8 multihead:1; /* can switch video heads */
97 u8 rom:1; /* can retrieve a video rom */
98 u8 post:1; /* can configure the head to */
99 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400103 u8 _DOS:1; /*Enable/Disable output switching */
104 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
105 u8 _ROM:1; /*Get ROM Data */
106 u8 _GPD:1; /*Get POST Device */
107 u8 _SPD:1; /*Set POST Device */
108 u8 _VPO:1; /*Video POST Options */
109 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
Len Brown4be44fc2005-08-05 00:44:28 -0400112struct acpi_video_device_attrib {
113 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100114 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400115 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100116 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400117 u32 bios_can_detect:1; /*BIOS can detect the device */
118 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
119 the VGA device. */
120 u32 pipe_id:3; /*For VGA multiple-head devices. */
121 u32 reserved:10; /*Must be 0 */
122 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123};
124
125struct acpi_video_enumerated_device {
126 union {
127 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400128 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 } value;
130 struct acpi_video_device *bind_info;
131};
132
133struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400134 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400135 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400137 u8 attached_count;
138 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500141 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400142 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800143 struct input_dev *input;
144 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
147struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400148 u8 crt:1;
149 u8 lcd:1;
150 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500151 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400152 u8 bios:1;
153 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500154 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155};
156
157struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 u8 _ADR:1; /*Return the unique ID */
159 u8 _BCL:1; /*Query list of brightness control levels supported */
160 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800161 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400162 u8 _DDC:1; /*Return the EDID for this device */
163 u8 _DCS:1; /*Return status of output device */
164 u8 _DGS:1; /*Query graphics state */
165 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166};
167
168struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400169 int curr;
170 int count;
171 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172};
173
174struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400175 unsigned long device_id;
176 struct acpi_video_device_flags flags;
177 struct acpi_video_device_cap cap;
178 struct list_head entry;
179 struct acpi_video_bus *video;
180 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800182 struct backlight_device *backlight;
Zhang Rui702ed512008-01-17 15:51:22 +0800183 struct thermal_cooling_device *cdev;
Luming Yu23b0f012007-05-09 21:07:05 +0800184 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185};
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* bus */
188static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
189static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400190 .open = acpi_video_bus_info_open_fs,
191 .read = seq_read,
192 .llseek = seq_lseek,
193 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
196static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
197static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400198 .open = acpi_video_bus_ROM_open_fs,
199 .read = seq_read,
200 .llseek = seq_lseek,
201 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
Len Brown4be44fc2005-08-05 00:44:28 -0400204static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
205 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400207 .open = acpi_video_bus_POST_info_open_fs,
208 .read = seq_read,
209 .llseek = seq_lseek,
210 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211};
212
213static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
214static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400215 .open = acpi_video_bus_POST_open_fs,
216 .read = seq_read,
217 .llseek = seq_lseek,
218 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
222static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400223 .open = acpi_video_bus_DOS_open_fs,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227};
228
229/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400230static int acpi_video_device_info_open_fs(struct inode *inode,
231 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400233 .open = acpi_video_device_info_open_fs,
234 .read = seq_read,
235 .llseek = seq_lseek,
236 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239static int acpi_video_device_state_open_fs(struct inode *inode,
240 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400242 .open = acpi_video_device_state_open_fs,
243 .read = seq_read,
244 .llseek = seq_lseek,
245 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246};
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248static int acpi_video_device_brightness_open_fs(struct inode *inode,
249 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400251 .open = acpi_video_device_brightness_open_fs,
252 .read = seq_read,
253 .llseek = seq_lseek,
254 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255};
256
Len Brown4be44fc2005-08-05 00:44:28 -0400257static int acpi_video_device_EDID_open_fs(struct inode *inode,
258 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400260 .open = acpi_video_device_EDID_open_fs,
261 .read = seq_read,
262 .llseek = seq_lseek,
263 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264};
265
Len Brown4be44fc2005-08-05 00:44:28 -0400266static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 "motherboard VGA device",
268 "PCI VGA device",
269 "AGP VGA device",
270 "UNKNOWN",
271};
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
274static void acpi_video_device_rebind(struct acpi_video_bus *video);
275static void acpi_video_device_bind(struct acpi_video_bus *video,
276 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400278static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800279static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
280 int level);
281static int acpi_video_device_lcd_get_level_current(
282 struct acpi_video_device *device,
283 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400284static int acpi_video_get_next_level(struct acpi_video_device *device,
285 u32 level_current, u32 event);
286static void acpi_video_switch_brightness(struct acpi_video_device *device,
287 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800288static int acpi_video_device_get_state(struct acpi_video_device *device,
289 unsigned long *state);
290static int acpi_video_output_get(struct output_device *od);
291static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Yu Luming2f3d0002006-11-11 02:40:34 +0800293/*backlight device sysfs support*/
294static int acpi_video_get_brightness(struct backlight_device *bd)
295{
296 unsigned long cur_level;
297 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100298 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800299 acpi_video_device_lcd_get_level_current(vd, &cur_level);
300 return (int) cur_level;
301}
302
303static int acpi_video_set_brightness(struct backlight_device *bd)
304{
Richard Purdie599a52d2007-02-10 23:07:48 +0000305 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800306 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100307 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800308 acpi_video_device_lcd_set_level(vd, request_level);
309 return 0;
310}
311
Richard Purdie599a52d2007-02-10 23:07:48 +0000312static struct backlight_ops acpi_backlight_ops = {
313 .get_brightness = acpi_video_get_brightness,
314 .update_status = acpi_video_set_brightness,
315};
316
Luming Yu23b0f012007-05-09 21:07:05 +0800317/*video output device sysfs support*/
318static int acpi_video_output_get(struct output_device *od)
319{
320 unsigned long state;
321 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700322 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800323 acpi_video_device_get_state(vd, &state);
324 return (int)state;
325}
326
327static int acpi_video_output_set(struct output_device *od)
328{
329 unsigned long state = od->request_state;
330 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700331 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800332 return acpi_video_device_set_state(vd, state);
333}
334
335static struct output_properties acpi_output_properties = {
336 .set_state = acpi_video_output_set,
337 .get_status = acpi_video_output_get,
338};
Zhang Rui702ed512008-01-17 15:51:22 +0800339
340
341/* thermal cooling device callbacks */
342static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
343{
344 struct acpi_device *device = cdev->devdata;
345 struct acpi_video_device *video = acpi_driver_data(device);
346
347 return sprintf(buf, "%d\n", video->brightness->count - 3);
348}
349
350static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
351{
352 struct acpi_device *device = cdev->devdata;
353 struct acpi_video_device *video = acpi_driver_data(device);
354 unsigned long level;
355 int state;
356
357 acpi_video_device_lcd_get_level_current(video, &level);
358 for (state = 2; state < video->brightness->count; state++)
359 if (level == video->brightness->levels[state])
360 return sprintf(buf, "%d\n",
361 video->brightness->count - state - 1);
362
363 return -EINVAL;
364}
365
366static int
367video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
368{
369 struct acpi_device *device = cdev->devdata;
370 struct acpi_video_device *video = acpi_driver_data(device);
371 int level;
372
373 if ( state >= video->brightness->count - 2)
374 return -EINVAL;
375
376 state = video->brightness->count - state;
377 level = video->brightness->levels[state -1];
378 return acpi_video_device_lcd_set_level(video, level);
379}
380
381static struct thermal_cooling_device_ops video_cooling_ops = {
382 .get_max_state = video_get_max_state,
383 .get_cur_state = video_get_cur_state,
384 .set_cur_state = video_set_cur_state,
385};
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387/* --------------------------------------------------------------------------
388 Video Management
389 -------------------------------------------------------------------------- */
390
391/* device */
392
393static int
Len Brown4be44fc2005-08-05 00:44:28 -0400394acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400397
398 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Patrick Mocheld550d982006-06-27 00:41:40 -0400400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
403static int
Len Brown4be44fc2005-08-05 00:44:28 -0400404acpi_video_device_get_state(struct acpi_video_device *device,
405 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Len Brown4be44fc2005-08-05 00:44:28 -0400407 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Patrick Mochel90130262006-05-19 16:54:48 -0400409 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Patrick Mocheld550d982006-06-27 00:41:40 -0400411 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414static int
Len Brown4be44fc2005-08-05 00:44:28 -0400415acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Len Brown4be44fc2005-08-05 00:44:28 -0400417 int status;
418 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
419 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400420 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400424 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429static int
Len Brown4be44fc2005-08-05 00:44:28 -0400430acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
431 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Len Brown4be44fc2005-08-05 00:44:28 -0400433 int status;
434 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
435 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 *levels = NULL;
439
Patrick Mochel90130262006-05-19 16:54:48 -0400440 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400442 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400443 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500444 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400445 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 status = -EFAULT;
447 goto err;
448 }
449
450 *levels = obj;
451
Patrick Mocheld550d982006-06-27 00:41:40 -0400452 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800455 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Patrick Mocheld550d982006-06-27 00:41:40 -0400457 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
460static int
Len Brown4be44fc2005-08-05 00:44:28 -0400461acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400463 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400464 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
465 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400470 if (device->cap._BCM)
471 status = acpi_evaluate_object(device->dev->handle, "_BCM",
472 &args, NULL);
473 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400474 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
477static int
Len Brown4be44fc2005-08-05 00:44:28 -0400478acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
479 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400481 if (device->cap._BQC)
482 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
483 level);
484 *level = device->brightness->curr;
485 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
488static int
Len Brown4be44fc2005-08-05 00:44:28 -0400489acpi_video_device_EDID(struct acpi_video_device *device,
490 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Len Brown4be44fc2005-08-05 00:44:28 -0400492 int status;
493 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
494 union acpi_object *obj;
495 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
496 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 *edid = NULL;
500
501 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400502 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (length == 128)
504 arg0.integer.value = 1;
505 else if (length == 256)
506 arg0.integer.value = 2;
507 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Patrick Mochel90130262006-05-19 16:54:48 -0400510 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400512 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200514 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 if (obj && obj->type == ACPI_TYPE_BUFFER)
517 *edid = obj;
518 else {
Len Brown64684632006-06-26 23:41:38 -0400519 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 status = -EFAULT;
521 kfree(obj);
522 }
523
Patrick Mocheld550d982006-06-27 00:41:40 -0400524 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527/* bus */
528
529static int
Len Brown4be44fc2005-08-05 00:44:28 -0400530acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Len Brown4be44fc2005-08-05 00:44:28 -0400532 int status;
533 unsigned long tmp;
534 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
535 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 arg0.integer.value = option;
539
Patrick Mochel90130262006-05-19 16:54:48 -0400540 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400542 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Patrick Mocheld550d982006-06-27 00:41:40 -0400544 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545}
546
547static int
Len Brown4be44fc2005-08-05 00:44:28 -0400548acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 int status;
551
Patrick Mochel90130262006-05-19 16:54:48 -0400552 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Patrick Mocheld550d982006-06-27 00:41:40 -0400554 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557static int
Len Brown4be44fc2005-08-05 00:44:28 -0400558acpi_video_bus_POST_options(struct acpi_video_bus *video,
559 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Len Brown4be44fc2005-08-05 00:44:28 -0400561 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Patrick Mochel90130262006-05-19 16:54:48 -0400563 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 *options &= 3;
565
Patrick Mocheld550d982006-06-27 00:41:40 -0400566 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569/*
570 * Arg:
571 * video : video bus device pointer
572 * bios_flag :
573 * 0. The system BIOS should NOT automatically switch(toggle)
574 * the active display output.
575 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100576 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 * 2. The _DGS value should be locked.
578 * 3. The system BIOS should not automatically switch (toggle) the
579 * active display output, but instead generate the display switch
580 * event notify code.
581 * lcd_flag :
582 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100583 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100585 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * Return Value:
587 * -1 wrong arg.
588 */
589
590static int
Len Brown4be44fc2005-08-05 00:44:28 -0400591acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Len Brown4be44fc2005-08-05 00:44:28 -0400593 acpi_integer status = 0;
594 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
595 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Len Brown4be44fc2005-08-05 00:44:28 -0400598 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 status = -1;
600 goto Failed;
601 }
602 arg0.integer.value = (lcd_flag << 2) | bios_flag;
603 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400604 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Len Brown4be44fc2005-08-05 00:44:28 -0400606 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400607 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
610/*
611 * Arg:
612 * device : video output device (LCD, CRT, ..)
613 *
614 * Return Value:
615 * None
616 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100617 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 * device.
619 */
620
Len Brown4be44fc2005-08-05 00:44:28 -0400621static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 acpi_handle h_dummy1;
624 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800625 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 union acpi_object *obj = NULL;
627 struct acpi_video_device_brightness *br = NULL;
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
William Lee Irwin III98934de2007-12-12 03:56:55 -0800630 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Patrick Mochel90130262006-05-19 16:54:48 -0400632 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 device->cap._ADR = 1;
634 }
Patrick Mochel90130262006-05-19 16:54:48 -0400635 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400636 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
Patrick Mochel90130262006-05-19 16:54:48 -0400638 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400639 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800641 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
642 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400643 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400644 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
Patrick Mochel90130262006-05-19 16:54:48 -0400646 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 device->cap._DCS = 1;
648 }
Patrick Mochel90130262006-05-19 16:54:48 -0400649 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 device->cap._DGS = 1;
651 }
Patrick Mochel90130262006-05-19 16:54:48 -0400652 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 device->cap._DSS = 1;
654 }
655
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400656 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400658 if (obj->package.count >= 2) {
659 int count = 0;
660 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400661
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400662 br = kzalloc(sizeof(*br), GFP_KERNEL);
663 if (!br) {
664 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400666 br->levels = kmalloc(obj->package.count *
667 sizeof *(br->levels), GFP_KERNEL);
668 if (!br->levels)
669 goto out;
670
671 for (i = 0; i < obj->package.count; i++) {
672 o = (union acpi_object *)&obj->package.
673 elements[i];
674 if (o->type != ACPI_TYPE_INTEGER) {
675 printk(KERN_ERR PREFIX "Invalid data\n");
676 continue;
677 }
678 br->levels[count] = (u32) o->integer.value;
679
680 if (br->levels[count] > max_level)
681 max_level = br->levels[count];
682 count++;
683 }
684 out:
685 if (count < 2) {
686 kfree(br->levels);
687 kfree(br);
688 } else {
689 br->count = count;
690 device->brightness = br;
691 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
692 "found %d brightness levels\n",
693 count));
694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400697
698 } else {
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500702 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400704 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800705 unsigned long tmp;
Zhang Rui702ed512008-01-17 15:51:22 +0800706 int result;
Yu Luming2f3d0002006-11-11 02:40:34 +0800707 static int count = 0;
708 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800709 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
710 if (!name)
711 return;
712
Yu Luming2f3d0002006-11-11 02:40:34 +0800713 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800714 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800715 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000716 NULL, device, &acpi_backlight_ops);
717 device->backlight->props.max_brightness = max_level;
718 device->backlight->props.brightness = (int)tmp;
719 backlight_update_status(device->backlight);
Yu Luming2f3d0002006-11-11 02:40:34 +0800720 kfree(name);
Zhang Rui702ed512008-01-17 15:51:22 +0800721
722 device->cdev = thermal_cooling_device_register("LCD",
723 device->dev, &video_cooling_ops);
724 if (device->cdev) {
725 printk(KERN_INFO PREFIX
726 "%s is registered as cooling_device%d\n",
727 device->dev->dev.bus_id, device->cdev->id);
728 result = sysfs_create_link(&device->dev->dev.kobj,
729 &device->cdev->device.kobj,
730 "thermal_cooling");
731 if (result)
732 printk(KERN_ERR PREFIX "Create sysfs link\n");
733 result = sysfs_create_link(&device->cdev->device.kobj,
734 &device->dev->dev.kobj,
735 "device");
736 if (result)
737 printk(KERN_ERR PREFIX "Create sysfs link\n");
738 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800739 }
Luming Yu23b0f012007-05-09 21:07:05 +0800740 if (device->cap._DCS && device->cap._DSS){
741 static int count = 0;
742 char *name;
743 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
744 if (!name)
745 return;
746 sprintf(name, "acpi_video%d", count++);
747 device->output_dev = video_output_register(name,
748 NULL, device, &acpi_output_properties);
749 kfree(name);
750 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400751 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752}
753
754/*
755 * Arg:
756 * device : video output device (VGA)
757 *
758 * Return Value:
759 * None
760 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100761 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 */
763
Len Brown4be44fc2005-08-05 00:44:28 -0400764static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
Len Brown4be44fc2005-08-05 00:44:28 -0400766 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
William Lee Irwin III98934de2007-12-12 03:56:55 -0800768 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400769 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 video->cap._DOS = 1;
771 }
Patrick Mochel90130262006-05-19 16:54:48 -0400772 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 video->cap._DOD = 1;
774 }
Patrick Mochel90130262006-05-19 16:54:48 -0400775 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 video->cap._ROM = 1;
777 }
Patrick Mochel90130262006-05-19 16:54:48 -0400778 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 video->cap._GPD = 1;
780 }
Patrick Mochel90130262006-05-19 16:54:48 -0400781 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 video->cap._SPD = 1;
783 }
Patrick Mochel90130262006-05-19 16:54:48 -0400784 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 video->cap._VPO = 1;
786 }
787}
788
789/*
790 * Check whether the video bus device has required AML method to
791 * support the desired features
792 */
793
Len Brown4be44fc2005-08-05 00:44:28 -0400794static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Len Brown4be44fc2005-08-05 00:44:28 -0400796 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 /* Since there is no HID, CID and so on for VGA driver, we have
803 * to check well known required nodes.
804 */
805
Julius Volz98fb8fe2007-02-20 16:38:40 +0100806 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400807 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 video->flags.multihead = 1;
809 status = 0;
810 }
811
Julius Volz98fb8fe2007-02-20 16:38:40 +0100812 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400813 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 video->flags.rom = 1;
815 status = 0;
816 }
817
Julius Volz98fb8fe2007-02-20 16:38:40 +0100818 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400819 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 video->flags.post = 1;
821 status = 0;
822 }
823
Patrick Mocheld550d982006-06-27 00:41:40 -0400824 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
827/* --------------------------------------------------------------------------
828 FS Interface (/proc)
829 -------------------------------------------------------------------------- */
830
Len Brown4be44fc2005-08-05 00:44:28 -0400831static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833/* video devices */
834
Len Brown4be44fc2005-08-05 00:44:28 -0400835static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200837 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (!dev)
841 goto end;
842
843 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
844 seq_printf(seq, "type: ");
845 if (dev->flags.crt)
846 seq_printf(seq, "CRT\n");
847 else if (dev->flags.lcd)
848 seq_printf(seq, "LCD\n");
849 else if (dev->flags.tvout)
850 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500851 else if (dev->flags.dvi)
852 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 else
854 seq_printf(seq, "UNKNOWN\n");
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Len Brown4be44fc2005-08-05 00:44:28 -0400858 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400859 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860}
861
862static int
Len Brown4be44fc2005-08-05 00:44:28 -0400863acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
865 return single_open(file, acpi_video_device_info_seq_show,
866 PDE(inode)->data);
867}
868
Len Brown4be44fc2005-08-05 00:44:28 -0400869static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Len Brown4be44fc2005-08-05 00:44:28 -0400871 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200872 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400873 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 if (!dev)
877 goto end;
878
879 status = acpi_video_device_get_state(dev, &state);
880 seq_printf(seq, "state: ");
881 if (ACPI_SUCCESS(status))
882 seq_printf(seq, "0x%02lx\n", state);
883 else
884 seq_printf(seq, "<not supported>\n");
885
886 status = acpi_video_device_query(dev, &state);
887 seq_printf(seq, "query: ");
888 if (ACPI_SUCCESS(status))
889 seq_printf(seq, "0x%02lx\n", state);
890 else
891 seq_printf(seq, "<not supported>\n");
892
Len Brown4be44fc2005-08-05 00:44:28 -0400893 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400894 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895}
896
897static int
Len Brown4be44fc2005-08-05 00:44:28 -0400898acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900 return single_open(file, acpi_video_device_state_seq_show,
901 PDE(inode)->data);
902}
903
904static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400905acpi_video_device_write_state(struct file *file,
906 const char __user * buffer,
907 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Len Brown4be44fc2005-08-05 00:44:28 -0400909 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200910 struct seq_file *m = file->private_data;
911 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400912 char str[12] = { 0 };
913 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400917 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400920 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 str[count] = 0;
923 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400924 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 status = acpi_video_device_set_state(dev, state);
927
928 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400929 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Patrick Mocheld550d982006-06-27 00:41:40 -0400931 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
934static int
Len Brown4be44fc2005-08-05 00:44:28 -0400935acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200937 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400938 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 if (!dev || !dev->brightness) {
942 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
945
946 seq_printf(seq, "levels: ");
947 for (i = 0; i < dev->brightness->count; i++)
948 seq_printf(seq, " %d", dev->brightness->levels[i]);
949 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
950
Patrick Mocheld550d982006-06-27 00:41:40 -0400951 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
954static int
Len Brown4be44fc2005-08-05 00:44:28 -0400955acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
957 return single_open(file, acpi_video_device_brightness_seq_show,
958 PDE(inode)->data);
959}
960
961static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400962acpi_video_device_write_brightness(struct file *file,
963 const char __user * buffer,
964 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200966 struct seq_file *m = file->private_data;
967 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100968 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400969 unsigned int level = 0;
970 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Thomas Renninger59d399d2005-11-08 05:27:00 -0500973 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400974 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400977 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 str[count] = 0;
980 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Julius Volz98fb8fe2007-02-20 16:38:40 +0100985 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 for (i = 0; i < dev->brightness->count; i++)
987 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400988 if (ACPI_SUCCESS
989 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 dev->brightness->curr = level;
991 break;
992 }
993
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Len Brown4be44fc2005-08-05 00:44:28 -0400997static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200999 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001000 int status;
1001 int i;
1002 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 if (!dev)
1006 goto out;
1007
Len Brown4be44fc2005-08-05 00:44:28 -04001008 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001010 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012
1013 if (ACPI_FAILURE(status)) {
1014 goto out;
1015 }
1016
1017 if (edid && edid->type == ACPI_TYPE_BUFFER) {
1018 for (i = 0; i < edid->buffer.length; i++)
1019 seq_putc(seq, edid->buffer.pointer[i]);
1020 }
1021
Len Brown4be44fc2005-08-05 00:44:28 -04001022 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 if (!edid)
1024 seq_printf(seq, "<not supported>\n");
1025 else
1026 kfree(edid);
1027
Patrick Mocheld550d982006-06-27 00:41:40 -04001028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029}
1030
1031static int
Len Brown4be44fc2005-08-05 00:44:28 -04001032acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
1034 return single_open(file, acpi_video_device_EDID_seq_show,
1035 PDE(inode)->data);
1036}
1037
Len Brown4be44fc2005-08-05 00:44:28 -04001038static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Len Brown4be44fc2005-08-05 00:44:28 -04001040 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 struct acpi_video_device *vid_dev;
1042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001045 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001047 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001049 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 if (!acpi_device_dir(device)) {
1052 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001053 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001055 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 acpi_device_dir(device)->owner = THIS_MODULE;
1057 }
1058
1059 /* 'info' [R] */
1060 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1061 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001062 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 else {
1064 entry->proc_fops = &acpi_video_device_info_fops;
1065 entry->data = acpi_driver_data(device);
1066 entry->owner = THIS_MODULE;
1067 }
1068
1069 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001070 entry =
1071 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1072 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001074 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001076 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 entry->data = acpi_driver_data(device);
1079 entry->owner = THIS_MODULE;
1080 }
1081
1082 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001083 entry =
1084 create_proc_entry("brightness", 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_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 entry->data = acpi_driver_data(device);
1092 entry->owner = THIS_MODULE;
1093 }
1094
1095 /* 'EDID' [R] */
1096 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1097 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001098 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 else {
1100 entry->proc_fops = &acpi_video_device_EDID_fops;
1101 entry->data = acpi_driver_data(device);
1102 entry->owner = THIS_MODULE;
1103 }
1104
Patrick Mocheld550d982006-06-27 00:41:40 -04001105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Len Brown4be44fc2005-08-05 00:44:28 -04001108static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
1110 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001112 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001114 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 if (acpi_device_dir(device)) {
1117 remove_proc_entry("info", acpi_device_dir(device));
1118 remove_proc_entry("state", acpi_device_dir(device));
1119 remove_proc_entry("brightness", acpi_device_dir(device));
1120 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001121 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 acpi_device_dir(device) = NULL;
1123 }
1124
Patrick Mocheld550d982006-06-27 00:41:40 -04001125 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001129static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001131 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 if (!video)
1135 goto end;
1136
1137 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001138 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001140 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001142 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Len Brown4be44fc2005-08-05 00:44:28 -04001144 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001145 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Len Brown4be44fc2005-08-05 00:44:28 -04001148static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Len Brown4be44fc2005-08-05 00:44:28 -04001150 return single_open(file, acpi_video_bus_info_seq_show,
1151 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Len Brown4be44fc2005-08-05 00:44:28 -04001154static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001156 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 if (!video)
1160 goto end;
1161
1162 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1163 seq_printf(seq, "<TODO>\n");
1164
Len Brown4be44fc2005-08-05 00:44:28 -04001165 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001166 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Len Brown4be44fc2005-08-05 00:44:28 -04001169static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
1171 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1172}
1173
Len Brown4be44fc2005-08-05 00:44:28 -04001174static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001176 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001177 unsigned long options;
1178 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 if (!video)
1182 goto end;
1183
1184 status = acpi_video_bus_POST_options(video, &options);
1185 if (ACPI_SUCCESS(status)) {
1186 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001187 printk(KERN_WARNING PREFIX
1188 "The motherboard VGA device is not listed as a possible POST device.\n");
1189 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001190 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001193 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (options & 2)
1195 seq_printf(seq, " <PCI video>");
1196 if (options & 4)
1197 seq_printf(seq, " <AGP video>");
1198 seq_putc(seq, '\n');
1199 } else
1200 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001201 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
1205static int
Len Brown4be44fc2005-08-05 00:44:28 -04001206acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Len Brown4be44fc2005-08-05 00:44:28 -04001208 return single_open(file, acpi_video_bus_POST_info_seq_show,
1209 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
Len Brown4be44fc2005-08-05 00:44:28 -04001212static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001214 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001215 int status;
1216 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 if (!video)
1220 goto end;
1221
Len Brown4be44fc2005-08-05 00:44:28 -04001222 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 if (!ACPI_SUCCESS(status)) {
1224 seq_printf(seq, "<not supported>\n");
1225 goto end;
1226 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001227 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Len Brown4be44fc2005-08-05 00:44:28 -04001229 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
Len Brown4be44fc2005-08-05 00:44:28 -04001233static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001235 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Len Brown4be44fc2005-08-05 00:44:28 -04001238 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Patrick Mocheld550d982006-06-27 00:41:40 -04001240 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Len Brown4be44fc2005-08-05 00:44:28 -04001243static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
Len Brown4be44fc2005-08-05 00:44:28 -04001245 return single_open(file, acpi_video_bus_POST_seq_show,
1246 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Len Brown4be44fc2005-08-05 00:44:28 -04001249static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1252}
1253
1254static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001255acpi_video_bus_write_POST(struct file *file,
1256 const char __user * buffer,
1257 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Len Brown4be44fc2005-08-05 00:44:28 -04001259 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001260 struct seq_file *m = file->private_data;
1261 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001262 char str[12] = { 0 };
1263 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001267 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269 status = acpi_video_bus_POST_options(video, &options);
1270 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001271 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001274 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 str[count] = 0;
1277 opt = strtoul(str, NULL, 0);
1278 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001279 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Julius Volz98fb8fe2007-02-20 16:38:40 +01001281 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 options |= 1;
1283
1284 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001285 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001287 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 }
1290
Patrick Mocheld550d982006-06-27 00:41:40 -04001291 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
1294static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001295acpi_video_bus_write_DOS(struct file *file,
1296 const char __user * buffer,
1297 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Len Brown4be44fc2005-08-05 00:44:28 -04001299 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001300 struct seq_file *m = file->private_data;
1301 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001302 char str[12] = { 0 };
1303 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001307 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001310 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 str[count] = 0;
1313 opt = strtoul(str, NULL, 0);
1314 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001315 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Len Brown4be44fc2005-08-05 00:44:28 -04001317 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Patrick Mocheld550d982006-06-27 00:41:40 -04001322 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
Len Brown4be44fc2005-08-05 00:44:28 -04001325static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Len Brown4be44fc2005-08-05 00:44:28 -04001327 struct proc_dir_entry *entry = NULL;
1328 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001331 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 if (!acpi_device_dir(device)) {
1334 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001335 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001337 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 video->dir = acpi_device_dir(device);
1339 acpi_device_dir(device)->owner = THIS_MODULE;
1340 }
1341
1342 /* 'info' [R] */
1343 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1344 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001345 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 else {
1347 entry->proc_fops = &acpi_video_bus_info_fops;
1348 entry->data = acpi_driver_data(device);
1349 entry->owner = THIS_MODULE;
1350 }
1351
1352 /* 'ROM' [R] */
1353 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1354 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001355 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 else {
1357 entry->proc_fops = &acpi_video_bus_ROM_fops;
1358 entry->data = acpi_driver_data(device);
1359 entry->owner = THIS_MODULE;
1360 }
1361
1362 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001363 entry =
1364 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001366 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 else {
1368 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1369 entry->data = acpi_driver_data(device);
1370 entry->owner = THIS_MODULE;
1371 }
1372
1373 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001374 entry =
1375 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1376 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001378 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001380 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 entry->data = acpi_driver_data(device);
1383 entry->owner = THIS_MODULE;
1384 }
1385
1386 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001387 entry =
1388 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1389 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001391 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001393 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 entry->data = acpi_driver_data(device);
1396 entry->owner = THIS_MODULE;
1397 }
1398
Patrick Mocheld550d982006-06-27 00:41:40 -04001399 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
Len Brown4be44fc2005-08-05 00:44:28 -04001402static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
Len Brown4be44fc2005-08-05 00:44:28 -04001404 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001407 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 if (acpi_device_dir(device)) {
1410 remove_proc_entry("info", acpi_device_dir(device));
1411 remove_proc_entry("ROM", acpi_device_dir(device));
1412 remove_proc_entry("POST_info", acpi_device_dir(device));
1413 remove_proc_entry("POST", acpi_device_dir(device));
1414 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001415 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 acpi_device_dir(device) = NULL;
1417 }
1418
Patrick Mocheld550d982006-06-27 00:41:40 -04001419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
1422/* --------------------------------------------------------------------------
1423 Driver Interface
1424 -------------------------------------------------------------------------- */
1425
1426/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001427static struct acpi_video_device_attrib*
1428acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1429{
1430 int count;
1431
1432 for(count = 0; count < video->attached_count; count++)
1433 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1434 return &(video->attached_array[count].value.attrib);
1435 return NULL;
1436}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438static int
Len Brown4be44fc2005-08-05 00:44:28 -04001439acpi_video_bus_get_one_device(struct acpi_device *device,
1440 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Len Brown4be44fc2005-08-05 00:44:28 -04001442 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001443 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001444 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001445 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001448 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Len Brown4be44fc2005-08-05 00:44:28 -04001450 status =
1451 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 if (ACPI_SUCCESS(status)) {
1453
Burman Yan36bcbec2006-12-19 12:56:11 -08001454 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001456 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1459 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1460 acpi_driver_data(device) = data;
1461
1462 data->device_id = device_id;
1463 data->video = video;
1464 data->dev = device;
1465
Rui Zhang82cae992007-01-03 23:40:53 -05001466 attribute = acpi_video_get_device_attr(video, device_id);
1467
1468 if((attribute != NULL) && attribute->device_id_scheme) {
1469 switch (attribute->display_type) {
1470 case ACPI_VIDEO_DISPLAY_CRT:
1471 data->flags.crt = 1;
1472 break;
1473 case ACPI_VIDEO_DISPLAY_TV:
1474 data->flags.tvout = 1;
1475 break;
1476 case ACPI_VIDEO_DISPLAY_DVI:
1477 data->flags.dvi = 1;
1478 break;
1479 case ACPI_VIDEO_DISPLAY_LCD:
1480 data->flags.lcd = 1;
1481 break;
1482 default:
1483 data->flags.unknown = 1;
1484 break;
1485 }
1486 if(attribute->bios_can_detect)
1487 data->flags.bios = 1;
1488 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 acpi_video_device_bind(video, data);
1492 acpi_video_device_find_cap(data);
1493
Patrick Mochel90130262006-05-19 16:54:48 -04001494 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001495 ACPI_DEVICE_NOTIFY,
1496 acpi_video_device_notify,
1497 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 if (ACPI_FAILURE(status)) {
1499 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001500 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001501 if(data->brightness)
1502 kfree(data->brightness->levels);
1503 kfree(data->brightness);
1504 kfree(data);
1505 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 }
1507
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001508 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001510 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 acpi_video_device_add_fs(device);
1513
Patrick Mocheld550d982006-06-27 00:41:40 -04001514 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
1516
Patrick Mocheld550d982006-06-27 00:41:40 -04001517 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
1520/*
1521 * Arg:
1522 * video : video bus device
1523 *
1524 * Return:
1525 * none
1526 *
1527 * Enumerate the video device list of the video bus,
1528 * bind the ids with the corresponding video devices
1529 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001530 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Len Brown4be44fc2005-08-05 00:44:28 -04001532static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001534 struct acpi_video_device *dev;
1535
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001536 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001537
1538 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001539 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001540
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001541 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
1544/*
1545 * Arg:
1546 * video : video bus device
1547 * device : video output device under the video
1548 * bus
1549 *
1550 * Return:
1551 * none
1552 *
1553 * Bind the ids with the corresponding video devices
1554 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001555 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557static void
Len Brown4be44fc2005-08-05 00:44:28 -04001558acpi_video_device_bind(struct acpi_video_bus *video,
1559 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
Len Brown4be44fc2005-08-05 00:44:28 -04001561 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563#define IDS_VAL(i) video->attached_array[i].value.int_val
1564#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001565
1566 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1567 i < video->attached_count; i++) {
1568 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 IDS_BIND(i) = device;
1570 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1571 }
1572 }
1573#undef IDS_VAL
1574#undef IDS_BIND
1575}
1576
1577/*
1578 * Arg:
1579 * video : video bus device
1580 *
1581 * Return:
1582 * < 0 : error
1583 *
1584 * Call _DOD to enumerate all devices attached to display adapter
1585 *
Len Brown4be44fc2005-08-05 00:44:28 -04001586 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1589{
Len Brown4be44fc2005-08-05 00:44:28 -04001590 int status;
1591 int count;
1592 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001594 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1595 union acpi_object *dod = NULL;
1596 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Patrick Mochel90130262006-05-19 16:54:48 -04001598 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001600 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001601 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 }
1603
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001604 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001606 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 status = -EFAULT;
1608 goto out;
1609 }
1610
1611 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001612 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Len Brown4be44fc2005-08-05 00:44:28 -04001614 active_device_list = kmalloc((1 +
1615 dod->package.count) *
1616 sizeof(struct
1617 acpi_video_enumerated_device),
1618 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 if (!active_device_list) {
1621 status = -ENOMEM;
1622 goto out;
1623 }
1624
1625 count = 0;
1626 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001627 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
1629 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001630 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001631 active_device_list[i].value.int_val =
1632 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 }
1634 active_device_list[i].value.int_val = obj->integer.value;
1635 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001636 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1637 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 count++;
1639 }
1640 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1641
Jesper Juhl6044ec82005-11-07 01:01:32 -08001642 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 video->attached_array = active_device_list;
1645 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001646 out:
Len Brown02438d82006-06-30 03:19:10 -04001647 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001648 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
1651/*
1652 * Arg:
1653 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001654 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 *
1656 * Return:
1657 * < 0 : error
1658 *
1659 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001660 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001662 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Len Brown4be44fc2005-08-05 00:44:28 -04001664static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001666 struct list_head *node;
Len Brown4be44fc2005-08-05 00:44:28 -04001667 struct acpi_video_device *dev = NULL;
1668 struct acpi_video_device *dev_next = NULL;
1669 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 unsigned long state;
1671 int status = 0;
1672
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001673 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001675 list_for_each(node, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001676 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001678 if (state & 0x2) {
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001679 dev_next = container_of(node->next,
1680 struct acpi_video_device, entry);
1681 dev_prev = container_of(node->prev,
1682 struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 goto out;
1684 }
1685 }
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 dev_next = container_of(node->next, struct acpi_video_device, entry);
1688 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001689
1690 out:
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001691 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001692
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 switch (event) {
1694 case ACPI_VIDEO_NOTIFY_CYCLE:
1695 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1696 acpi_video_device_set_state(dev, 0);
1697 acpi_video_device_set_state(dev_next, 0x80000001);
1698 break;
1699 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1700 acpi_video_device_set_state(dev, 0);
1701 acpi_video_device_set_state(dev_prev, 0x80000001);
1702 default:
1703 break;
1704 }
1705
Patrick Mocheld550d982006-06-27 00:41:40 -04001706 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707}
1708
Len Brown4be44fc2005-08-05 00:44:28 -04001709static int
1710acpi_video_get_next_level(struct acpi_video_device *device,
1711 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001713 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001714 max = max_below = 0;
1715 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001716 /* Find closest level to level_current */
1717 for (i = 0; i < device->brightness->count; i++) {
1718 l = device->brightness->levels[i];
1719 if (abs(l - level_current) < abs(delta)) {
1720 delta = l - level_current;
1721 if (!delta)
1722 break;
1723 }
1724 }
1725 /* Ajust level_current to closest available level */
1726 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001727 for (i = 0; i < device->brightness->count; i++) {
1728 l = device->brightness->levels[i];
1729 if (l < min)
1730 min = l;
1731 if (l > max)
1732 max = l;
1733 if (l < min_above && l > level_current)
1734 min_above = l;
1735 if (l > max_below && l < level_current)
1736 max_below = l;
1737 }
1738
1739 switch (event) {
1740 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1741 return (level_current < max) ? min_above : min;
1742 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1743 return (level_current < max) ? min_above : max;
1744 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1745 return (level_current > min) ? max_below : min;
1746 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1747 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1748 return 0;
1749 default:
1750 return level_current;
1751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752}
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754static void
Len Brown4be44fc2005-08-05 00:44:28 -04001755acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
1757 unsigned long level_current, level_next;
1758 acpi_video_device_lcd_get_level_current(device, &level_current);
1759 level_next = acpi_video_get_next_level(device, level_current, event);
1760 acpi_video_device_lcd_set_level(device, level_next);
1761}
1762
1763static int
Len Brown4be44fc2005-08-05 00:44:28 -04001764acpi_video_bus_get_devices(struct acpi_video_bus *video,
1765 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Len Brown4be44fc2005-08-05 00:44:28 -04001767 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001768 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 acpi_video_device_enumerate(video);
1771
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001772 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
1774 status = acpi_video_bus_get_one_device(dev, video);
1775 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001776 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 continue;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001780 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781}
1782
Len Brown4be44fc2005-08-05 00:44:28 -04001783static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
Karol Kozimor031ec772005-07-30 04:18:00 -04001785 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 struct acpi_video_bus *video;
1787
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001790 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 video = device->video;
1793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 acpi_video_device_remove_fs(device->dev);
1795
Patrick Mochel90130262006-05-19 16:54:48 -04001796 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001797 ACPI_DEVICE_NOTIFY,
1798 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001799 backlight_device_unregister(device->backlight);
Zhang Rui702ed512008-01-17 15:51:22 +08001800 if (device->cdev) {
1801 sysfs_remove_link(&device->dev->dev.kobj,
1802 "thermal_cooling");
1803 sysfs_remove_link(&device->cdev->device.kobj,
1804 "device");
1805 thermal_cooling_device_unregister(device->cdev);
1806 device->cdev = NULL;
1807 }
Luming Yu23b0f012007-05-09 21:07:05 +08001808 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001809
Patrick Mocheld550d982006-06-27 00:41:40 -04001810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
Len Brown4be44fc2005-08-05 00:44:28 -04001813static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
Len Brown4be44fc2005-08-05 00:44:28 -04001815 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001816 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001818 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001820 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001822 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001823 if (ACPI_FAILURE(status))
1824 printk(KERN_WARNING PREFIX
1825 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001827 if (dev->brightness) {
1828 kfree(dev->brightness->levels);
1829 kfree(dev->brightness);
1830 }
1831 list_del(&dev->entry);
1832 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 }
1834
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001835 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001836
Patrick Mocheld550d982006-06-27 00:41:40 -04001837 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
1839
1840/* acpi_video interface */
1841
Len Brown4be44fc2005-08-05 00:44:28 -04001842static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
Zhang Ruia21101c2007-09-14 11:46:22 +08001844 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
Len Brown4be44fc2005-08-05 00:44:28 -04001847static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
1849 return acpi_video_bus_DOS(video, 0, 1);
1850}
1851
Len Brown4be44fc2005-08-05 00:44:28 -04001852static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001854 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001855 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001856 struct input_dev *input;
1857 int keycode;
1858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001860 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001862 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001863 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001866 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001868 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001869 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 break;
1871
Julius Volz98fb8fe2007-02-20 16:38:40 +01001872 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 * connector. */
1874 acpi_video_device_enumerate(video);
1875 acpi_video_device_rebind(video);
1876 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001877 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001878 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 break;
1880
Len Brown4be44fc2005-08-05 00:44:28 -04001881 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001882 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001883 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001884 keycode = KEY_SWITCHVIDEOMODE;
1885 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001886 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001887 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001888 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001889 keycode = KEY_VIDEO_NEXT;
1890 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001891 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001893 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001894 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 break;
1896
1897 default:
Luming Yue9dab192007-08-20 18:23:53 +08001898 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001900 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 break;
1902 }
1903
Luming Yue9dab192007-08-20 18:23:53 +08001904 input_report_key(input, keycode, 1);
1905 input_sync(input);
1906 input_report_key(input, keycode, 0);
1907 input_sync(input);
1908
Patrick Mocheld550d982006-06-27 00:41:40 -04001909 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911
Len Brown4be44fc2005-08-05 00:44:28 -04001912static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001914 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001915 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001916 struct acpi_video_bus *bus;
1917 struct input_dev *input;
1918 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001921 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001923 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001924 bus = video_device->video;
1925 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
1927 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001928 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001929 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_CYCLE;
1932 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001933 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001934 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001935 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001936 keycode = KEY_BRIGHTNESSUP;
1937 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001938 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001939 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001940 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001941 keycode = KEY_BRIGHTNESSDOWN;
1942 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001943 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Luming Yue9dab192007-08-20 18:23:53 +08001944 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001945 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001946 keycode = KEY_BRIGHTNESS_ZERO;
1947 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001948 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1949 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001950 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001951 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 break;
1953 default:
Luming Yue9dab192007-08-20 18:23:53 +08001954 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001956 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 break;
1958 }
Luming Yue9dab192007-08-20 18:23:53 +08001959
1960 input_report_key(input, keycode, 1);
1961 input_sync(input);
1962 input_report_key(input, keycode, 0);
1963 input_sync(input);
1964
Patrick Mocheld550d982006-06-27 00:41:40 -04001965 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
Zhang Ruie6d9da12007-08-25 02:23:31 -04001968static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001969static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001971 acpi_status status;
1972 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001973 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001974 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Burman Yan36bcbec2006-12-19 12:56:11 -08001976 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001978 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Zhang Ruie6d9da12007-08-25 02:23:31 -04001980 /* a hack to fix the duplicate name "VID" problem on T61 */
1981 if (!strcmp(device->pnp.bus_id, "VID")) {
1982 if (instance)
1983 device->pnp.bus_id[3] = '0' + instance;
1984 instance ++;
1985 }
1986
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001987 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1989 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1990 acpi_driver_data(device) = video;
1991
1992 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001993 error = acpi_video_bus_check(video);
1994 if (error)
1995 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001997 error = acpi_video_bus_add_fs(device);
1998 if (error)
1999 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05002001 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 INIT_LIST_HEAD(&video->video_device_list);
2003
2004 acpi_video_bus_get_devices(video, device);
2005 acpi_video_bus_start_devices(video);
2006
Patrick Mochel90130262006-05-19 16:54:48 -04002007 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002008 ACPI_DEVICE_NOTIFY,
2009 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 if (ACPI_FAILURE(status)) {
2011 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04002012 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002013 error = -ENODEV;
2014 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 }
2016
Luming Yue9dab192007-08-20 18:23:53 +08002017 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002018 if (!input) {
2019 error = -ENOMEM;
2020 goto err_uninstall_notify;
2021 }
Luming Yue9dab192007-08-20 18:23:53 +08002022
2023 snprintf(video->phys, sizeof(video->phys),
2024 "%s/video/input0", acpi_device_hid(video->device));
2025
2026 input->name = acpi_device_name(video->device);
2027 input->phys = video->phys;
2028 input->id.bustype = BUS_HOST;
2029 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05002030 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08002031 input->evbit[0] = BIT(EV_KEY);
2032 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
2033 set_bit(KEY_VIDEO_NEXT, input->keybit);
2034 set_bit(KEY_VIDEO_PREV, input->keybit);
2035 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
2036 set_bit(KEY_BRIGHTNESSUP, input->keybit);
2037 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
2038 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
2039 set_bit(KEY_DISPLAY_OFF, input->keybit);
2040 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08002041
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002042 error = input_register_device(input);
2043 if (error)
2044 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08002045
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002047 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2048 video->flags.multihead ? "yes" : "no",
2049 video->flags.rom ? "yes" : "no",
2050 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002052 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002054 err_free_input_dev:
2055 input_free_device(input);
2056 err_uninstall_notify:
2057 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2058 acpi_video_bus_notify);
2059 err_stop_video:
2060 acpi_video_bus_stop_devices(video);
2061 acpi_video_bus_put_devices(video);
2062 kfree(video->attached_array);
2063 acpi_video_bus_remove_fs(device);
2064 err_free_video:
2065 kfree(video);
2066 acpi_driver_data(device) = NULL;
2067
2068 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
Len Brown4be44fc2005-08-05 00:44:28 -04002071static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
Len Brown4be44fc2005-08-05 00:44:28 -04002073 acpi_status status = 0;
2074 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002078 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002080 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 acpi_video_bus_stop_devices(video);
2083
Patrick Mochel90130262006-05-19 16:54:48 -04002084 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002085 ACPI_DEVICE_NOTIFY,
2086 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088 acpi_video_bus_put_devices(video);
2089 acpi_video_bus_remove_fs(device);
2090
Luming Yue9dab192007-08-20 18:23:53 +08002091 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002092 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 kfree(video);
2094
Patrick Mocheld550d982006-06-27 00:41:40 -04002095 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
Len Brown4be44fc2005-08-05 00:44:28 -04002098static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
Len Brown4be44fc2005-08-05 00:44:28 -04002100 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002104 acpi_dbg_level = 0xFFFFFFFF;
2105 acpi_dbg_layer = 0x08000000;
2106 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2109 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002110 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 acpi_video_dir->owner = THIS_MODULE;
2112
2113 result = acpi_bus_register_driver(&acpi_video_bus);
2114 if (result < 0) {
2115 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002116 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118
Patrick Mocheld550d982006-06-27 00:41:40 -04002119 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
Len Brown4be44fc2005-08-05 00:44:28 -04002122static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 acpi_bus_unregister_driver(&acpi_video_bus);
2126
2127 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2128
Patrick Mocheld550d982006-06-27 00:41:40 -04002129 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132module_init(acpi_video_init);
2133module_exit(acpi_video_exit);