blob: 59639c9c66664f5a3c0444f32484209fcca1ea3c [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>
Luming Yu23b0f012007-05-09 21:07:05 +080037#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/uaccess.h>
39
40#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
42
43#define ACPI_VIDEO_COMPONENT 0x08000000
44#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_VIDEO_BUS_NAME "Video Bus"
46#define ACPI_VIDEO_DEVICE_NAME "Video Device"
47#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48#define ACPI_VIDEO_NOTIFY_PROBE 0x81
49#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52
Thomas Tuttlef4715182006-12-19 12:56:14 -080053#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080061#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Rui Zhang82cae992007-01-03 23:40:53 -050063#define ACPI_VIDEO_DISPLAY_CRT 1
64#define ACPI_VIDEO_DISPLAY_TV 2
65#define ACPI_VIDEO_DISPLAY_DVI 3
66#define ACPI_VIDEO_DISPLAY_LCD 4
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050069ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brownf52fd662007-02-12 22:42:12 -050071MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050072MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073MODULE_LICENSE("GPL");
74
Len Brown4be44fc2005-08-05 00:44:28 -040075static int acpi_video_bus_add(struct acpi_device *device);
76static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Thomas Renninger1ba90e32007-07-23 14:44:41 +020078static const struct acpi_device_id video_device_ids[] = {
79 {ACPI_VIDEO_HID, 0},
80 {"", 0},
81};
82MODULE_DEVICE_TABLE(acpi, video_device_ids);
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050085 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020087 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .ops = {
89 .add = acpi_video_bus_add,
90 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040091 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040095 u8 multihead:1; /* can switch video heads */
96 u8 rom:1; /* can retrieve a video rom */
97 u8 post:1; /* can configure the head to */
98 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400102 u8 _DOS:1; /*Enable/Disable output switching */
103 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
104 u8 _ROM:1; /*Get ROM Data */
105 u8 _GPD:1; /*Get POST Device */
106 u8 _SPD:1; /*Set POST Device */
107 u8 _VPO:1; /*Video POST Options */
108 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111struct acpi_video_device_attrib {
112 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100113 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400114 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100115 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400116 u32 bios_can_detect:1; /*BIOS can detect the device */
117 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
118 the VGA device. */
119 u32 pipe_id:3; /*For VGA multiple-head devices. */
120 u32 reserved:10; /*Must be 0 */
121 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
124struct acpi_video_enumerated_device {
125 union {
126 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400127 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 } value;
129 struct acpi_video_device *bind_info;
130};
131
132struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400133 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400134 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400136 u8 attached_count;
137 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500140 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400141 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800142 struct input_dev *input;
143 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 u8 crt:1;
148 u8 lcd:1;
149 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500150 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400151 u8 bios:1;
152 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500153 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 _ADR:1; /*Return the unique ID */
158 u8 _BCL:1; /*Query list of brightness control levels supported */
159 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800160 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400161 u8 _DDC:1; /*Return the EDID for this device */
162 u8 _DCS:1; /*Return status of output device */
163 u8 _DGS:1; /*Query graphics state */
164 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
167struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 int curr;
169 int count;
170 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 unsigned long device_id;
175 struct acpi_video_device_flags flags;
176 struct acpi_video_device_cap cap;
177 struct list_head entry;
178 struct acpi_video_bus *video;
179 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800181 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800182 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* bus */
186static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
187static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400188 .open = acpi_video_bus_info_open_fs,
189 .read = seq_read,
190 .llseek = seq_lseek,
191 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
194static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
195static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 .open = acpi_video_bus_ROM_open_fs,
197 .read = seq_read,
198 .llseek = seq_lseek,
199 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
203 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 .open = acpi_video_bus_POST_info_open_fs,
206 .read = seq_read,
207 .llseek = seq_lseek,
208 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
211static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
212static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .open = acpi_video_bus_POST_open_fs,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
220static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 .open = acpi_video_bus_DOS_open_fs,
222 .read = seq_read,
223 .llseek = seq_lseek,
224 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
227/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400228static int acpi_video_device_info_open_fs(struct inode *inode,
229 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_device_info_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_video_device_state_open_fs(struct inode *inode,
238 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400240 .open = acpi_video_device_state_open_fs,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_video_device_brightness_open_fs(struct inode *inode,
247 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400249 .open = acpi_video_device_brightness_open_fs,
250 .read = seq_read,
251 .llseek = seq_lseek,
252 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255static int acpi_video_device_EDID_open_fs(struct inode *inode,
256 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400258 .open = acpi_video_device_EDID_open_fs,
259 .read = seq_read,
260 .llseek = seq_lseek,
261 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 "motherboard VGA device",
266 "PCI VGA device",
267 "AGP VGA device",
268 "UNKNOWN",
269};
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
272static void acpi_video_device_rebind(struct acpi_video_bus *video);
273static void acpi_video_device_bind(struct acpi_video_bus *video,
274 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400276static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800277static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
278 int level);
279static int acpi_video_device_lcd_get_level_current(
280 struct acpi_video_device *device,
281 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400282static int acpi_video_get_next_level(struct acpi_video_device *device,
283 u32 level_current, u32 event);
284static void acpi_video_switch_brightness(struct acpi_video_device *device,
285 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800286static int acpi_video_device_get_state(struct acpi_video_device *device,
287 unsigned long *state);
288static int acpi_video_output_get(struct output_device *od);
289static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Yu Luming2f3d0002006-11-11 02:40:34 +0800291/*backlight device sysfs support*/
292static int acpi_video_get_brightness(struct backlight_device *bd)
293{
294 unsigned long cur_level;
Matthew Garrett38531e62007-12-26 02:03:26 +0000295 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800296 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100297 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800298 acpi_video_device_lcd_get_level_current(vd, &cur_level);
Matthew Garrett38531e62007-12-26 02:03:26 +0000299 for (i = 2; i < vd->brightness->count; i++) {
300 if (vd->brightness->levels[i] == cur_level)
301 /* The first two entries are special - see page 575
302 of the ACPI spec 3.0 */
303 return i-2;
304 }
305 return 0;
Yu Luming2f3d0002006-11-11 02:40:34 +0800306}
307
308static int acpi_video_set_brightness(struct backlight_device *bd)
309{
Matthew Garrett38531e62007-12-26 02:03:26 +0000310 int request_level = bd->props.brightness+2;
Yu Luming2f3d0002006-11-11 02:40:34 +0800311 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100312 (struct acpi_video_device *)bl_get_data(bd);
Matthew Garrett38531e62007-12-26 02:03:26 +0000313 acpi_video_device_lcd_set_level(vd,
314 vd->brightness->levels[request_level]);
Yu Luming2f3d0002006-11-11 02:40:34 +0800315 return 0;
316}
317
Richard Purdie599a52d2007-02-10 23:07:48 +0000318static struct backlight_ops acpi_backlight_ops = {
319 .get_brightness = acpi_video_get_brightness,
320 .update_status = acpi_video_set_brightness,
321};
322
Luming Yu23b0f012007-05-09 21:07:05 +0800323/*video output device sysfs support*/
324static int acpi_video_output_get(struct output_device *od)
325{
326 unsigned long state;
327 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700328 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800329 acpi_video_device_get_state(vd, &state);
330 return (int)state;
331}
332
333static int acpi_video_output_set(struct output_device *od)
334{
335 unsigned long state = od->request_state;
336 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700337 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800338 return acpi_video_device_set_state(vd, state);
339}
340
341static struct output_properties acpi_output_properties = {
342 .set_state = acpi_video_output_set,
343 .get_status = acpi_video_output_get,
344};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345/* --------------------------------------------------------------------------
346 Video Management
347 -------------------------------------------------------------------------- */
348
349/* device */
350
351static int
Len Brown4be44fc2005-08-05 00:44:28 -0400352acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Len Brown4be44fc2005-08-05 00:44:28 -0400354 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400355
356 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Patrick Mocheld550d982006-06-27 00:41:40 -0400358 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
361static int
Len Brown4be44fc2005-08-05 00:44:28 -0400362acpi_video_device_get_state(struct acpi_video_device *device,
363 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Patrick Mochel90130262006-05-19 16:54:48 -0400367 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Patrick Mocheld550d982006-06-27 00:41:40 -0400369 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
372static int
Len Brown4be44fc2005-08-05 00:44:28 -0400373acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Len Brown4be44fc2005-08-05 00:44:28 -0400375 int status;
376 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
377 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400378 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400382 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Patrick Mocheld550d982006-06-27 00:41:40 -0400384 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
387static int
Len Brown4be44fc2005-08-05 00:44:28 -0400388acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
389 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Len Brown4be44fc2005-08-05 00:44:28 -0400391 int status;
392 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
393 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 *levels = NULL;
397
Patrick Mochel90130262006-05-19 16:54:48 -0400398 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400400 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400401 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500402 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400403 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 status = -EFAULT;
405 goto err;
406 }
407
408 *levels = obj;
409
Patrick Mocheld550d982006-06-27 00:41:40 -0400410 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800413 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Patrick Mocheld550d982006-06-27 00:41:40 -0400415 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
418static int
Len Brown4be44fc2005-08-05 00:44:28 -0400419acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400421 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400422 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
423 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400428 if (device->cap._BCM)
429 status = acpi_evaluate_object(device->dev->handle, "_BCM",
430 &args, NULL);
431 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400432 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
435static int
Len Brown4be44fc2005-08-05 00:44:28 -0400436acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
437 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400439 if (device->cap._BQC)
440 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
441 level);
442 *level = device->brightness->curr;
443 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
446static int
Len Brown4be44fc2005-08-05 00:44:28 -0400447acpi_video_device_EDID(struct acpi_video_device *device,
448 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Len Brown4be44fc2005-08-05 00:44:28 -0400450 int status;
451 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
452 union acpi_object *obj;
453 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
454 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 *edid = NULL;
458
459 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400460 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 if (length == 128)
462 arg0.integer.value = 1;
463 else if (length == 256)
464 arg0.integer.value = 2;
465 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400466 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Patrick Mochel90130262006-05-19 16:54:48 -0400468 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400470 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200472 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 if (obj && obj->type == ACPI_TYPE_BUFFER)
475 *edid = obj;
476 else {
Len Brown64684632006-06-26 23:41:38 -0400477 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 status = -EFAULT;
479 kfree(obj);
480 }
481
Patrick Mocheld550d982006-06-27 00:41:40 -0400482 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/* bus */
486
487static int
Len Brown4be44fc2005-08-05 00:44:28 -0400488acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Len Brown4be44fc2005-08-05 00:44:28 -0400490 int status;
491 unsigned long tmp;
492 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
493 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 arg0.integer.value = option;
497
Patrick Mochel90130262006-05-19 16:54:48 -0400498 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400500 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Patrick Mocheld550d982006-06-27 00:41:40 -0400502 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505static int
Len Brown4be44fc2005-08-05 00:44:28 -0400506acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 int status;
509
Patrick Mochel90130262006-05-19 16:54:48 -0400510 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Patrick Mocheld550d982006-06-27 00:41:40 -0400512 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515static int
Len Brown4be44fc2005-08-05 00:44:28 -0400516acpi_video_bus_POST_options(struct acpi_video_bus *video,
517 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Len Brown4be44fc2005-08-05 00:44:28 -0400519 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Patrick Mochel90130262006-05-19 16:54:48 -0400521 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 *options &= 3;
523
Patrick Mocheld550d982006-06-27 00:41:40 -0400524 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
527/*
528 * Arg:
529 * video : video bus device pointer
530 * bios_flag :
531 * 0. The system BIOS should NOT automatically switch(toggle)
532 * the active display output.
533 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100534 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 * 2. The _DGS value should be locked.
536 * 3. The system BIOS should not automatically switch (toggle) the
537 * active display output, but instead generate the display switch
538 * event notify code.
539 * lcd_flag :
540 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100541 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100543 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 * Return Value:
545 * -1 wrong arg.
546 */
547
548static int
Len Brown4be44fc2005-08-05 00:44:28 -0400549acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Len Brown4be44fc2005-08-05 00:44:28 -0400551 acpi_integer status = 0;
552 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
553 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 status = -1;
558 goto Failed;
559 }
560 arg0.integer.value = (lcd_flag << 2) | bios_flag;
561 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400562 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Len Brown4be44fc2005-08-05 00:44:28 -0400564 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400565 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568/*
569 * Arg:
570 * device : video output device (LCD, CRT, ..)
571 *
572 * Return Value:
573 * None
574 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100575 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 * device.
577 */
578
Len Brown4be44fc2005-08-05 00:44:28 -0400579static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 acpi_handle h_dummy1;
582 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800583 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 union acpi_object *obj = NULL;
585 struct acpi_video_device_brightness *br = NULL;
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
William Lee Irwin III98934de2007-12-12 03:56:55 -0800588 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Patrick Mochel90130262006-05-19 16:54:48 -0400590 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 device->cap._ADR = 1;
592 }
Patrick Mochel90130262006-05-19 16:54:48 -0400593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400594 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400597 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
600 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400601 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400602 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Patrick Mochel90130262006-05-19 16:54:48 -0400604 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 device->cap._DCS = 1;
606 }
Patrick Mochel90130262006-05-19 16:54:48 -0400607 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 device->cap._DGS = 1;
609 }
Patrick Mochel90130262006-05-19 16:54:48 -0400610 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 device->cap._DSS = 1;
612 }
613
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400614 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400616 if (obj->package.count >= 2) {
617 int count = 0;
618 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400619
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400620 br = kzalloc(sizeof(*br), GFP_KERNEL);
621 if (!br) {
622 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400624 br->levels = kmalloc(obj->package.count *
625 sizeof *(br->levels), GFP_KERNEL);
626 if (!br->levels)
627 goto out;
628
629 for (i = 0; i < obj->package.count; i++) {
630 o = (union acpi_object *)&obj->package.
631 elements[i];
632 if (o->type != ACPI_TYPE_INTEGER) {
633 printk(KERN_ERR PREFIX "Invalid data\n");
634 continue;
635 }
636 br->levels[count] = (u32) o->integer.value;
637
638 if (br->levels[count] > max_level)
639 max_level = br->levels[count];
640 count++;
641 }
642 out:
643 if (count < 2) {
644 kfree(br->levels);
645 kfree(br);
646 } else {
647 br->count = count;
648 device->brightness = br;
649 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
650 "found %d brightness levels\n",
651 count));
652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400655
656 } else {
657 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500660 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400662 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800663 static int count = 0;
664 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800665 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
666 if (!name)
667 return;
668
Yu Luming2f3d0002006-11-11 02:40:34 +0800669 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800670 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000671 NULL, device, &acpi_backlight_ops);
Matthew Garrett38531e62007-12-26 02:03:26 +0000672 device->backlight->props.max_brightness = device->brightness->count-3;
673 device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
Richard Purdie599a52d2007-02-10 23:07:48 +0000674 backlight_update_status(device->backlight);
675
Yu Luming2f3d0002006-11-11 02:40:34 +0800676 kfree(name);
677 }
Luming Yu23b0f012007-05-09 21:07:05 +0800678 if (device->cap._DCS && device->cap._DSS){
679 static int count = 0;
680 char *name;
681 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
682 if (!name)
683 return;
684 sprintf(name, "acpi_video%d", count++);
685 device->output_dev = video_output_register(name,
686 NULL, device, &acpi_output_properties);
687 kfree(name);
688 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400689 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
692/*
693 * Arg:
694 * device : video output device (VGA)
695 *
696 * Return Value:
697 * None
698 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100699 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Len Brown4be44fc2005-08-05 00:44:28 -0400704 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
William Lee Irwin III98934de2007-12-12 03:56:55 -0800706 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 video->cap._DOS = 1;
709 }
Patrick Mochel90130262006-05-19 16:54:48 -0400710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 video->cap._DOD = 1;
712 }
Patrick Mochel90130262006-05-19 16:54:48 -0400713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 video->cap._ROM = 1;
715 }
Patrick Mochel90130262006-05-19 16:54:48 -0400716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 video->cap._GPD = 1;
718 }
Patrick Mochel90130262006-05-19 16:54:48 -0400719 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 video->cap._SPD = 1;
721 }
Patrick Mochel90130262006-05-19 16:54:48 -0400722 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 video->cap._VPO = 1;
724 }
725}
726
727/*
728 * Check whether the video bus device has required AML method to
729 * support the desired features
730 */
731
Len Brown4be44fc2005-08-05 00:44:28 -0400732static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Len Brown4be44fc2005-08-05 00:44:28 -0400734 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400738 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 /* Since there is no HID, CID and so on for VGA driver, we have
741 * to check well known required nodes.
742 */
743
Julius Volz98fb8fe2007-02-20 16:38:40 +0100744 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400745 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 video->flags.multihead = 1;
747 status = 0;
748 }
749
Julius Volz98fb8fe2007-02-20 16:38:40 +0100750 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400751 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 video->flags.rom = 1;
753 status = 0;
754 }
755
Julius Volz98fb8fe2007-02-20 16:38:40 +0100756 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400757 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 video->flags.post = 1;
759 status = 0;
760 }
761
Patrick Mocheld550d982006-06-27 00:41:40 -0400762 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
765/* --------------------------------------------------------------------------
766 FS Interface (/proc)
767 -------------------------------------------------------------------------- */
768
Len Brown4be44fc2005-08-05 00:44:28 -0400769static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771/* video devices */
772
Len Brown4be44fc2005-08-05 00:44:28 -0400773static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200775 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 if (!dev)
779 goto end;
780
781 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
782 seq_printf(seq, "type: ");
783 if (dev->flags.crt)
784 seq_printf(seq, "CRT\n");
785 else if (dev->flags.lcd)
786 seq_printf(seq, "LCD\n");
787 else if (dev->flags.tvout)
788 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500789 else if (dev->flags.dvi)
790 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 else
792 seq_printf(seq, "UNKNOWN\n");
793
Len Brown4be44fc2005-08-05 00:44:28 -0400794 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Len Brown4be44fc2005-08-05 00:44:28 -0400796 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400797 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
800static int
Len Brown4be44fc2005-08-05 00:44:28 -0400801acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 return single_open(file, acpi_video_device_info_seq_show,
804 PDE(inode)->data);
805}
806
Len Brown4be44fc2005-08-05 00:44:28 -0400807static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
Len Brown4be44fc2005-08-05 00:44:28 -0400809 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200810 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400811 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 if (!dev)
815 goto end;
816
817 status = acpi_video_device_get_state(dev, &state);
818 seq_printf(seq, "state: ");
819 if (ACPI_SUCCESS(status))
820 seq_printf(seq, "0x%02lx\n", state);
821 else
822 seq_printf(seq, "<not supported>\n");
823
824 status = acpi_video_device_query(dev, &state);
825 seq_printf(seq, "query: ");
826 if (ACPI_SUCCESS(status))
827 seq_printf(seq, "0x%02lx\n", state);
828 else
829 seq_printf(seq, "<not supported>\n");
830
Len Brown4be44fc2005-08-05 00:44:28 -0400831 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400832 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
835static int
Len Brown4be44fc2005-08-05 00:44:28 -0400836acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 return single_open(file, acpi_video_device_state_seq_show,
839 PDE(inode)->data);
840}
841
842static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400843acpi_video_device_write_state(struct file *file,
844 const char __user * buffer,
845 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Len Brown4be44fc2005-08-05 00:44:28 -0400847 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200848 struct seq_file *m = file->private_data;
849 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400850 char str[12] = { 0 };
851 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400858 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 str[count] = 0;
861 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400862 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 status = acpi_video_device_set_state(dev, state);
865
866 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400867 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Patrick Mocheld550d982006-06-27 00:41:40 -0400869 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
871
872static int
Len Brown4be44fc2005-08-05 00:44:28 -0400873acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200875 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400876 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 if (!dev || !dev->brightness) {
880 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
884 seq_printf(seq, "levels: ");
885 for (i = 0; i < dev->brightness->count; i++)
886 seq_printf(seq, " %d", dev->brightness->levels[i]);
887 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
888
Patrick Mocheld550d982006-06-27 00:41:40 -0400889 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
892static int
Len Brown4be44fc2005-08-05 00:44:28 -0400893acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
895 return single_open(file, acpi_video_device_brightness_seq_show,
896 PDE(inode)->data);
897}
898
899static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400900acpi_video_device_write_brightness(struct file *file,
901 const char __user * buffer,
902 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200904 struct seq_file *m = file->private_data;
905 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100906 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400907 unsigned int level = 0;
908 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Thomas Renninger59d399d2005-11-08 05:27:00 -0500911 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400912 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 str[count] = 0;
918 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400921 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Julius Volz98fb8fe2007-02-20 16:38:40 +0100923 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 for (i = 0; i < dev->brightness->count; i++)
925 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400926 if (ACPI_SUCCESS
927 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 dev->brightness->curr = level;
929 break;
930 }
931
Patrick Mocheld550d982006-06-27 00:41:40 -0400932 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
Len Brown4be44fc2005-08-05 00:44:28 -0400935static int acpi_video_device_EDID_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 status;
939 int i;
940 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 if (!dev)
944 goto out;
945
Len Brown4be44fc2005-08-05 00:44:28 -0400946 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400948 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950
951 if (ACPI_FAILURE(status)) {
952 goto out;
953 }
954
955 if (edid && edid->type == ACPI_TYPE_BUFFER) {
956 for (i = 0; i < edid->buffer.length; i++)
957 seq_putc(seq, edid->buffer.pointer[i]);
958 }
959
Len Brown4be44fc2005-08-05 00:44:28 -0400960 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (!edid)
962 seq_printf(seq, "<not supported>\n");
963 else
964 kfree(edid);
965
Patrick Mocheld550d982006-06-27 00:41:40 -0400966 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967}
968
969static int
Len Brown4be44fc2005-08-05 00:44:28 -0400970acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
972 return single_open(file, acpi_video_device_EDID_seq_show,
973 PDE(inode)->data);
974}
975
Len Brown4be44fc2005-08-05 00:44:28 -0400976static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Len Brown4be44fc2005-08-05 00:44:28 -0400978 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 struct acpi_video_device *vid_dev;
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200985 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400987 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 if (!acpi_device_dir(device)) {
990 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400991 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 acpi_device_dir(device)->owner = THIS_MODULE;
995 }
996
997 /* 'info' [R] */
998 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
999 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001000 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 else {
1002 entry->proc_fops = &acpi_video_device_info_fops;
1003 entry->data = acpi_driver_data(device);
1004 entry->owner = THIS_MODULE;
1005 }
1006
1007 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001008 entry =
1009 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1010 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001012 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001014 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 entry->data = acpi_driver_data(device);
1017 entry->owner = THIS_MODULE;
1018 }
1019
1020 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001021 entry =
1022 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1023 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001025 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001027 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 entry->data = acpi_driver_data(device);
1030 entry->owner = THIS_MODULE;
1031 }
1032
1033 /* 'EDID' [R] */
1034 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1035 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001036 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 else {
1038 entry->proc_fops = &acpi_video_device_EDID_fops;
1039 entry->data = acpi_driver_data(device);
1040 entry->owner = THIS_MODULE;
1041 }
1042
Patrick Mocheld550d982006-06-27 00:41:40 -04001043 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Len Brown4be44fc2005-08-05 00:44:28 -04001046static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
1048 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001050 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001052 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
1054 if (acpi_device_dir(device)) {
1055 remove_proc_entry("info", acpi_device_dir(device));
1056 remove_proc_entry("state", acpi_device_dir(device));
1057 remove_proc_entry("brightness", acpi_device_dir(device));
1058 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001059 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 acpi_device_dir(device) = NULL;
1061 }
1062
Patrick Mocheld550d982006-06-27 00:41:40 -04001063 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001067static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001069 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 if (!video)
1073 goto end;
1074
1075 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001076 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001078 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001080 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
Len Brown4be44fc2005-08-05 00:44:28 -04001082 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001083 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
Len Brown4be44fc2005-08-05 00:44:28 -04001086static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Len Brown4be44fc2005-08-05 00:44:28 -04001088 return single_open(file, acpi_video_bus_info_seq_show,
1089 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090}
1091
Len Brown4be44fc2005-08-05 00:44:28 -04001092static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001094 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (!video)
1098 goto end;
1099
1100 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1101 seq_printf(seq, "<TODO>\n");
1102
Len Brown4be44fc2005-08-05 00:44:28 -04001103 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001104 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
Len Brown4be44fc2005-08-05 00:44:28 -04001107static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
1109 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1110}
1111
Len Brown4be44fc2005-08-05 00:44:28 -04001112static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001114 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001115 unsigned long options;
1116 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 if (!video)
1120 goto end;
1121
1122 status = acpi_video_bus_POST_options(video, &options);
1123 if (ACPI_SUCCESS(status)) {
1124 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001125 printk(KERN_WARNING PREFIX
1126 "The motherboard VGA device is not listed as a possible POST device.\n");
1127 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001128 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001131 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if (options & 2)
1133 seq_printf(seq, " <PCI video>");
1134 if (options & 4)
1135 seq_printf(seq, " <AGP video>");
1136 seq_putc(seq, '\n');
1137 } else
1138 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001139 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
1143static int
Len Brown4be44fc2005-08-05 00:44:28 -04001144acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Len Brown4be44fc2005-08-05 00:44:28 -04001146 return single_open(file, acpi_video_bus_POST_info_seq_show,
1147 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
Len Brown4be44fc2005-08-05 00:44:28 -04001150static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001152 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001153 int status;
1154 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 if (!video)
1158 goto end;
1159
Len Brown4be44fc2005-08-05 00:44:28 -04001160 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 if (!ACPI_SUCCESS(status)) {
1162 seq_printf(seq, "<not supported>\n");
1163 goto end;
1164 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001165 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Len Brown4be44fc2005-08-05 00:44:28 -04001167 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001168 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Len Brown4be44fc2005-08-05 00:44:28 -04001171static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001173 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Len Brown4be44fc2005-08-05 00:44:28 -04001176 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Patrick Mocheld550d982006-06-27 00:41:40 -04001178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Len Brown4be44fc2005-08-05 00:44:28 -04001181static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Len Brown4be44fc2005-08-05 00:44:28 -04001183 return single_open(file, acpi_video_bus_POST_seq_show,
1184 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Len Brown4be44fc2005-08-05 00:44:28 -04001187static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
1189 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1190}
1191
1192static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001193acpi_video_bus_write_POST(struct file *file,
1194 const char __user * buffer,
1195 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Len Brown4be44fc2005-08-05 00:44:28 -04001197 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001198 struct seq_file *m = file->private_data;
1199 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001200 char str[12] = { 0 };
1201 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001205 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207 status = acpi_video_bus_POST_options(video, &options);
1208 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001209 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001212 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 str[count] = 0;
1215 opt = strtoul(str, NULL, 0);
1216 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001217 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Julius Volz98fb8fe2007-02-20 16:38:40 +01001219 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 options |= 1;
1221
1222 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001223 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001225 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227 }
1228
Patrick Mocheld550d982006-06-27 00:41:40 -04001229 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
1232static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001233acpi_video_bus_write_DOS(struct file *file,
1234 const char __user * buffer,
1235 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Len Brown4be44fc2005-08-05 00:44:28 -04001237 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001238 struct seq_file *m = file->private_data;
1239 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001240 char str[12] = { 0 };
1241 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001245 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001248 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 str[count] = 0;
1251 opt = strtoul(str, NULL, 0);
1252 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001253 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Len Brown4be44fc2005-08-05 00:44:28 -04001255 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
1257 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001258 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Patrick Mocheld550d982006-06-27 00:41:40 -04001260 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
Len Brown4be44fc2005-08-05 00:44:28 -04001263static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264{
Len Brown4be44fc2005-08-05 00:44:28 -04001265 struct proc_dir_entry *entry = NULL;
1266 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001269 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 if (!acpi_device_dir(device)) {
1272 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001273 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001275 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 video->dir = acpi_device_dir(device);
1277 acpi_device_dir(device)->owner = THIS_MODULE;
1278 }
1279
1280 /* 'info' [R] */
1281 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1282 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001283 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 else {
1285 entry->proc_fops = &acpi_video_bus_info_fops;
1286 entry->data = acpi_driver_data(device);
1287 entry->owner = THIS_MODULE;
1288 }
1289
1290 /* 'ROM' [R] */
1291 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1292 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001293 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 else {
1295 entry->proc_fops = &acpi_video_bus_ROM_fops;
1296 entry->data = acpi_driver_data(device);
1297 entry->owner = THIS_MODULE;
1298 }
1299
1300 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001301 entry =
1302 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001304 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 else {
1306 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1307 entry->data = acpi_driver_data(device);
1308 entry->owner = THIS_MODULE;
1309 }
1310
1311 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001312 entry =
1313 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1314 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001316 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001318 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 entry->data = acpi_driver_data(device);
1321 entry->owner = THIS_MODULE;
1322 }
1323
1324 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001325 entry =
1326 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1327 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001329 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001331 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 entry->data = acpi_driver_data(device);
1334 entry->owner = THIS_MODULE;
1335 }
1336
Patrick Mocheld550d982006-06-27 00:41:40 -04001337 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
Len Brown4be44fc2005-08-05 00:44:28 -04001340static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Len Brown4be44fc2005-08-05 00:44:28 -04001342 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001345 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
1347 if (acpi_device_dir(device)) {
1348 remove_proc_entry("info", acpi_device_dir(device));
1349 remove_proc_entry("ROM", acpi_device_dir(device));
1350 remove_proc_entry("POST_info", acpi_device_dir(device));
1351 remove_proc_entry("POST", acpi_device_dir(device));
1352 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001353 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 acpi_device_dir(device) = NULL;
1355 }
1356
Patrick Mocheld550d982006-06-27 00:41:40 -04001357 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
1360/* --------------------------------------------------------------------------
1361 Driver Interface
1362 -------------------------------------------------------------------------- */
1363
1364/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001365static struct acpi_video_device_attrib*
1366acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1367{
1368 int count;
1369
1370 for(count = 0; count < video->attached_count; count++)
1371 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1372 return &(video->attached_array[count].value.attrib);
1373 return NULL;
1374}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376static int
Len Brown4be44fc2005-08-05 00:44:28 -04001377acpi_video_bus_get_one_device(struct acpi_device *device,
1378 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Len Brown4be44fc2005-08-05 00:44:28 -04001380 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001381 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001382 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001383 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001386 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Len Brown4be44fc2005-08-05 00:44:28 -04001388 status =
1389 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (ACPI_SUCCESS(status)) {
1391
Burman Yan36bcbec2006-12-19 12:56:11 -08001392 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001394 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1397 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1398 acpi_driver_data(device) = data;
1399
1400 data->device_id = device_id;
1401 data->video = video;
1402 data->dev = device;
1403
Rui Zhang82cae992007-01-03 23:40:53 -05001404 attribute = acpi_video_get_device_attr(video, device_id);
1405
1406 if((attribute != NULL) && attribute->device_id_scheme) {
1407 switch (attribute->display_type) {
1408 case ACPI_VIDEO_DISPLAY_CRT:
1409 data->flags.crt = 1;
1410 break;
1411 case ACPI_VIDEO_DISPLAY_TV:
1412 data->flags.tvout = 1;
1413 break;
1414 case ACPI_VIDEO_DISPLAY_DVI:
1415 data->flags.dvi = 1;
1416 break;
1417 case ACPI_VIDEO_DISPLAY_LCD:
1418 data->flags.lcd = 1;
1419 break;
1420 default:
1421 data->flags.unknown = 1;
1422 break;
1423 }
1424 if(attribute->bios_can_detect)
1425 data->flags.bios = 1;
1426 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 acpi_video_device_bind(video, data);
1430 acpi_video_device_find_cap(data);
1431
Patrick Mochel90130262006-05-19 16:54:48 -04001432 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001433 ACPI_DEVICE_NOTIFY,
1434 acpi_video_device_notify,
1435 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 if (ACPI_FAILURE(status)) {
1437 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001438 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001439 if(data->brightness)
1440 kfree(data->brightness->levels);
1441 kfree(data->brightness);
1442 kfree(data);
1443 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001446 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001448 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 acpi_video_device_add_fs(device);
1451
Patrick Mocheld550d982006-06-27 00:41:40 -04001452 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454
Patrick Mocheld550d982006-06-27 00:41:40 -04001455 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
1458/*
1459 * Arg:
1460 * video : video bus device
1461 *
1462 * Return:
1463 * none
1464 *
1465 * Enumerate the video device list of the video bus,
1466 * bind the ids with the corresponding video devices
1467 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001468 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Len Brown4be44fc2005-08-05 00:44:28 -04001470static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001472 struct acpi_video_device *dev;
1473
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001474 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001475
1476 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001477 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001478
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001479 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
1482/*
1483 * Arg:
1484 * video : video bus device
1485 * device : video output device under the video
1486 * bus
1487 *
1488 * Return:
1489 * none
1490 *
1491 * Bind the ids with the corresponding video devices
1492 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001493 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
1495static void
Len Brown4be44fc2005-08-05 00:44:28 -04001496acpi_video_device_bind(struct acpi_video_bus *video,
1497 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Len Brown4be44fc2005-08-05 00:44:28 -04001499 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501#define IDS_VAL(i) video->attached_array[i].value.int_val
1502#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001503
1504 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1505 i < video->attached_count; i++) {
1506 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 IDS_BIND(i) = device;
1508 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1509 }
1510 }
1511#undef IDS_VAL
1512#undef IDS_BIND
1513}
1514
1515/*
1516 * Arg:
1517 * video : video bus device
1518 *
1519 * Return:
1520 * < 0 : error
1521 *
1522 * Call _DOD to enumerate all devices attached to display adapter
1523 *
Len Brown4be44fc2005-08-05 00:44:28 -04001524 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1527{
Len Brown4be44fc2005-08-05 00:44:28 -04001528 int status;
1529 int count;
1530 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001532 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1533 union acpi_object *dod = NULL;
1534 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Patrick Mochel90130262006-05-19 16:54:48 -04001536 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001538 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001539 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001542 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001544 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 status = -EFAULT;
1546 goto out;
1547 }
1548
1549 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001550 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Len Brown4be44fc2005-08-05 00:44:28 -04001552 active_device_list = kmalloc((1 +
1553 dod->package.count) *
1554 sizeof(struct
1555 acpi_video_enumerated_device),
1556 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 if (!active_device_list) {
1559 status = -ENOMEM;
1560 goto out;
1561 }
1562
1563 count = 0;
1564 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001565 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001568 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001569 active_device_list[i].value.int_val =
1570 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 }
1572 active_device_list[i].value.int_val = obj->integer.value;
1573 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001574 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1575 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 count++;
1577 }
1578 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1579
Jesper Juhl6044ec82005-11-07 01:01:32 -08001580 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001581
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 video->attached_array = active_device_list;
1583 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001584 out:
Len Brown02438d82006-06-30 03:19:10 -04001585 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001586 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
1589/*
1590 * Arg:
1591 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001592 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 *
1594 * Return:
1595 * < 0 : error
1596 *
1597 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001598 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001600 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Len Brown4be44fc2005-08-05 00:44:28 -04001602static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001604 struct list_head *node;
Len Brown4be44fc2005-08-05 00:44:28 -04001605 struct acpi_video_device *dev = NULL;
1606 struct acpi_video_device *dev_next = NULL;
1607 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 unsigned long state;
1609 int status = 0;
1610
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001611 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001613 list_for_each(node, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001614 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001616 if (state & 0x2) {
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001617 dev_next = container_of(node->next,
1618 struct acpi_video_device, entry);
1619 dev_prev = container_of(node->prev,
1620 struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 goto out;
1622 }
1623 }
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 dev_next = container_of(node->next, struct acpi_video_device, entry);
1626 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001627
1628 out:
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001629 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001630
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 switch (event) {
1632 case ACPI_VIDEO_NOTIFY_CYCLE:
1633 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1634 acpi_video_device_set_state(dev, 0);
1635 acpi_video_device_set_state(dev_next, 0x80000001);
1636 break;
1637 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1638 acpi_video_device_set_state(dev, 0);
1639 acpi_video_device_set_state(dev_prev, 0x80000001);
1640 default:
1641 break;
1642 }
1643
Patrick Mocheld550d982006-06-27 00:41:40 -04001644 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Len Brown4be44fc2005-08-05 00:44:28 -04001647static int
1648acpi_video_get_next_level(struct acpi_video_device *device,
1649 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001651 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001652 max = max_below = 0;
1653 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001654 /* Find closest level to level_current */
1655 for (i = 0; i < device->brightness->count; i++) {
1656 l = device->brightness->levels[i];
1657 if (abs(l - level_current) < abs(delta)) {
1658 delta = l - level_current;
1659 if (!delta)
1660 break;
1661 }
1662 }
1663 /* Ajust level_current to closest available level */
1664 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001665 for (i = 0; i < device->brightness->count; i++) {
1666 l = device->brightness->levels[i];
1667 if (l < min)
1668 min = l;
1669 if (l > max)
1670 max = l;
1671 if (l < min_above && l > level_current)
1672 min_above = l;
1673 if (l > max_below && l < level_current)
1674 max_below = l;
1675 }
1676
1677 switch (event) {
1678 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1679 return (level_current < max) ? min_above : min;
1680 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1681 return (level_current < max) ? min_above : max;
1682 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1683 return (level_current > min) ? max_below : min;
1684 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1685 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1686 return 0;
1687 default:
1688 return level_current;
1689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692static void
Len Brown4be44fc2005-08-05 00:44:28 -04001693acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 unsigned long level_current, level_next;
1696 acpi_video_device_lcd_get_level_current(device, &level_current);
1697 level_next = acpi_video_get_next_level(device, level_current, event);
1698 acpi_video_device_lcd_set_level(device, level_next);
1699}
1700
1701static int
Len Brown4be44fc2005-08-05 00:44:28 -04001702acpi_video_bus_get_devices(struct acpi_video_bus *video,
1703 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Len Brown4be44fc2005-08-05 00:44:28 -04001705 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001706 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 acpi_video_device_enumerate(video);
1709
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001710 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 status = acpi_video_bus_get_one_device(dev, video);
1713 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001714 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 continue;
1716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001718 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719}
1720
Len Brown4be44fc2005-08-05 00:44:28 -04001721static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722{
Karol Kozimor031ec772005-07-30 04:18:00 -04001723 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 struct acpi_video_bus *video;
1725
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001728 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 video = device->video;
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 acpi_video_device_remove_fs(device->dev);
1733
Patrick Mochel90130262006-05-19 16:54:48 -04001734 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001735 ACPI_DEVICE_NOTIFY,
1736 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001737 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001738 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001739
Patrick Mocheld550d982006-06-27 00:41:40 -04001740 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Len Brown4be44fc2005-08-05 00:44:28 -04001743static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Len Brown4be44fc2005-08-05 00:44:28 -04001745 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001746 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001748 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001750 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001752 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001753 if (ACPI_FAILURE(status))
1754 printk(KERN_WARNING PREFIX
1755 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001757 if (dev->brightness) {
1758 kfree(dev->brightness->levels);
1759 kfree(dev->brightness);
1760 }
1761 list_del(&dev->entry);
1762 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 }
1764
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001765 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001766
Patrick Mocheld550d982006-06-27 00:41:40 -04001767 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
1770/* acpi_video interface */
1771
Len Brown4be44fc2005-08-05 00:44:28 -04001772static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
Zhang Ruia21101c2007-09-14 11:46:22 +08001774 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Len Brown4be44fc2005-08-05 00:44:28 -04001777static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
1779 return acpi_video_bus_DOS(video, 0, 1);
1780}
1781
Len Brown4be44fc2005-08-05 00:44:28 -04001782static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001784 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001785 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001786 struct input_dev *input;
1787 int keycode;
1788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001790 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001792 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001793 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001796 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001798 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001799 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 break;
1801
Julius Volz98fb8fe2007-02-20 16:38:40 +01001802 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * connector. */
1804 acpi_video_device_enumerate(video);
1805 acpi_video_device_rebind(video);
1806 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001807 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001808 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 break;
1810
Len Brown4be44fc2005-08-05 00:44:28 -04001811 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001812 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001813 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001814 keycode = KEY_SWITCHVIDEOMODE;
1815 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001816 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001817 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001818 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001819 keycode = KEY_VIDEO_NEXT;
1820 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001821 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001823 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001824 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 break;
1826
1827 default:
Luming Yue9dab192007-08-20 18:23:53 +08001828 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001830 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 break;
1832 }
1833
Luming Yue9dab192007-08-20 18:23:53 +08001834 input_report_key(input, keycode, 1);
1835 input_sync(input);
1836 input_report_key(input, keycode, 0);
1837 input_sync(input);
1838
Patrick Mocheld550d982006-06-27 00:41:40 -04001839 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840}
1841
Len Brown4be44fc2005-08-05 00:44:28 -04001842static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001844 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001845 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001846 struct acpi_video_bus *bus;
1847 struct input_dev *input;
1848 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001851 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001853 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001854 bus = video_device->video;
1855 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001858 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001859 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001860 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001861 keycode = KEY_BRIGHTNESS_CYCLE;
1862 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001863 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001864 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001865 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001866 keycode = KEY_BRIGHTNESSUP;
1867 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001868 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001869 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001870 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001871 keycode = KEY_BRIGHTNESSDOWN;
1872 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001873 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Luming Yue9dab192007-08-20 18:23:53 +08001874 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001875 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001876 keycode = KEY_BRIGHTNESS_ZERO;
1877 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001878 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1879 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001880 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001881 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 break;
1883 default:
Luming Yue9dab192007-08-20 18:23:53 +08001884 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001886 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 break;
1888 }
Luming Yue9dab192007-08-20 18:23:53 +08001889
1890 input_report_key(input, keycode, 1);
1891 input_sync(input);
1892 input_report_key(input, keycode, 0);
1893 input_sync(input);
1894
Patrick Mocheld550d982006-06-27 00:41:40 -04001895 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896}
1897
Zhang Ruie6d9da12007-08-25 02:23:31 -04001898static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001899static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001901 acpi_status status;
1902 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001903 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001904 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Burman Yan36bcbec2006-12-19 12:56:11 -08001906 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001908 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Zhang Ruie6d9da12007-08-25 02:23:31 -04001910 /* a hack to fix the duplicate name "VID" problem on T61 */
1911 if (!strcmp(device->pnp.bus_id, "VID")) {
1912 if (instance)
1913 device->pnp.bus_id[3] = '0' + instance;
1914 instance ++;
1915 }
1916
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001917 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1919 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1920 acpi_driver_data(device) = video;
1921
1922 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001923 error = acpi_video_bus_check(video);
1924 if (error)
1925 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001927 error = acpi_video_bus_add_fs(device);
1928 if (error)
1929 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001931 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 INIT_LIST_HEAD(&video->video_device_list);
1933
1934 acpi_video_bus_get_devices(video, device);
1935 acpi_video_bus_start_devices(video);
1936
Patrick Mochel90130262006-05-19 16:54:48 -04001937 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001938 ACPI_DEVICE_NOTIFY,
1939 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 if (ACPI_FAILURE(status)) {
1941 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001942 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001943 error = -ENODEV;
1944 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
1946
Luming Yue9dab192007-08-20 18:23:53 +08001947 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001948 if (!input) {
1949 error = -ENOMEM;
1950 goto err_uninstall_notify;
1951 }
Luming Yue9dab192007-08-20 18:23:53 +08001952
1953 snprintf(video->phys, sizeof(video->phys),
1954 "%s/video/input0", acpi_device_hid(video->device));
1955
1956 input->name = acpi_device_name(video->device);
1957 input->phys = video->phys;
1958 input->id.bustype = BUS_HOST;
1959 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001960 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001961 input->evbit[0] = BIT(EV_KEY);
1962 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1963 set_bit(KEY_VIDEO_NEXT, input->keybit);
1964 set_bit(KEY_VIDEO_PREV, input->keybit);
1965 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1966 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1967 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1968 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1969 set_bit(KEY_DISPLAY_OFF, input->keybit);
1970 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001971
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001972 error = input_register_device(input);
1973 if (error)
1974 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001975
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001977 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1978 video->flags.multihead ? "yes" : "no",
1979 video->flags.rom ? "yes" : "no",
1980 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001982 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001984 err_free_input_dev:
1985 input_free_device(input);
1986 err_uninstall_notify:
1987 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1988 acpi_video_bus_notify);
1989 err_stop_video:
1990 acpi_video_bus_stop_devices(video);
1991 acpi_video_bus_put_devices(video);
1992 kfree(video->attached_array);
1993 acpi_video_bus_remove_fs(device);
1994 err_free_video:
1995 kfree(video);
1996 acpi_driver_data(device) = NULL;
1997
1998 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999}
2000
Len Brown4be44fc2005-08-05 00:44:28 -04002001static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
Len Brown4be44fc2005-08-05 00:44:28 -04002003 acpi_status status = 0;
2004 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002008 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002010 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 acpi_video_bus_stop_devices(video);
2013
Patrick Mochel90130262006-05-19 16:54:48 -04002014 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002015 ACPI_DEVICE_NOTIFY,
2016 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
2018 acpi_video_bus_put_devices(video);
2019 acpi_video_bus_remove_fs(device);
2020
Luming Yue9dab192007-08-20 18:23:53 +08002021 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002022 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 kfree(video);
2024
Patrick Mocheld550d982006-06-27 00:41:40 -04002025 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
Len Brown4be44fc2005-08-05 00:44:28 -04002028static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
Len Brown4be44fc2005-08-05 00:44:28 -04002030 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002034 acpi_dbg_level = 0xFFFFFFFF;
2035 acpi_dbg_layer = 0x08000000;
2036 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2039 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002040 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 acpi_video_dir->owner = THIS_MODULE;
2042
2043 result = acpi_bus_register_driver(&acpi_video_bus);
2044 if (result < 0) {
2045 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002046 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 }
2048
Patrick Mocheld550d982006-06-27 00:41:40 -04002049 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
Len Brown4be44fc2005-08-05 00:44:28 -04002052static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 acpi_bus_unregister_driver(&acpi_video_bus);
2056
2057 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2058
Patrick Mocheld550d982006-06-27 00:41:40 -04002059 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
2062module_init(acpi_video_init);
2063module_exit(acpi_video_exit);