blob: 74ff0faeab57988be2222af3225aa07c8ff02fa8 [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
Zhang Rui8a681a42008-01-25 14:47:49 +080075static int brightness_switch_enabled = 1;
76module_param(brightness_switch_enabled, bool, 0644);
77
Len Brown4be44fc2005-08-05 00:44:28 -040078static int acpi_video_bus_add(struct acpi_device *device);
79static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Thomas Renninger1ba90e32007-07-23 14:44:41 +020081static const struct acpi_device_id video_device_ids[] = {
82 {ACPI_VIDEO_HID, 0},
83 {"", 0},
84};
85MODULE_DEVICE_TABLE(acpi, video_device_ids);
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050088 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020090 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .ops = {
92 .add = acpi_video_bus_add,
93 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040094 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070095};
96
97struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040098 u8 multihead:1; /* can switch video heads */
99 u8 rom:1; /* can retrieve a video rom */
100 u8 post:1; /* can configure the head to */
101 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102};
103
104struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400105 u8 _DOS:1; /*Enable/Disable output switching */
106 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
107 u8 _ROM:1; /*Get ROM Data */
108 u8 _GPD:1; /*Get POST Device */
109 u8 _SPD:1; /*Set POST Device */
110 u8 _VPO:1; /*Video POST Options */
111 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114struct acpi_video_device_attrib {
115 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100116 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400117 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100118 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400119 u32 bios_can_detect:1; /*BIOS can detect the device */
120 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
121 the VGA device. */
122 u32 pipe_id:3; /*For VGA multiple-head devices. */
123 u32 reserved:10; /*Must be 0 */
124 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127struct acpi_video_enumerated_device {
128 union {
129 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400130 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 } value;
132 struct acpi_video_device *bind_info;
133};
134
135struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400136 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400137 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u8 attached_count;
140 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500143 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400144 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800145 struct input_dev *input;
146 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400150 u8 crt:1;
151 u8 lcd:1;
152 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500153 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400154 u8 bios:1;
155 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500156 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157};
158
159struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400160 u8 _ADR:1; /*Return the unique ID */
161 u8 _BCL:1; /*Query list of brightness control levels supported */
162 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800163 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400164 u8 _DDC:1; /*Return the EDID for this device */
165 u8 _DCS:1; /*Return status of output device */
166 u8 _DGS:1; /*Query graphics state */
167 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168};
169
170struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400171 int curr;
172 int count;
173 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
176struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400177 unsigned long device_id;
178 struct acpi_video_device_flags flags;
179 struct acpi_video_device_cap cap;
180 struct list_head entry;
181 struct acpi_video_bus *video;
182 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800184 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800185 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186};
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* bus */
189static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
190static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400191 .open = acpi_video_bus_info_open_fs,
192 .read = seq_read,
193 .llseek = seq_lseek,
194 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195};
196
197static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
198static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400199 .open = acpi_video_bus_ROM_open_fs,
200 .read = seq_read,
201 .llseek = seq_lseek,
202 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203};
204
Len Brown4be44fc2005-08-05 00:44:28 -0400205static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
206 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 .open = acpi_video_bus_POST_info_open_fs,
209 .read = seq_read,
210 .llseek = seq_lseek,
211 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212};
213
214static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
215static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400216 .open = acpi_video_bus_POST_open_fs,
217 .read = seq_read,
218 .llseek = seq_lseek,
219 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
223static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400224 .open = acpi_video_bus_DOS_open_fs,
225 .read = seq_read,
226 .llseek = seq_lseek,
227 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228};
229
230/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400231static int acpi_video_device_info_open_fs(struct inode *inode,
232 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400234 .open = acpi_video_device_info_open_fs,
235 .read = seq_read,
236 .llseek = seq_lseek,
237 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238};
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240static int acpi_video_device_state_open_fs(struct inode *inode,
241 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400243 .open = acpi_video_device_state_open_fs,
244 .read = seq_read,
245 .llseek = seq_lseek,
246 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247};
248
Len Brown4be44fc2005-08-05 00:44:28 -0400249static int acpi_video_device_brightness_open_fs(struct inode *inode,
250 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 .open = acpi_video_device_brightness_open_fs,
253 .read = seq_read,
254 .llseek = seq_lseek,
255 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258static int acpi_video_device_EDID_open_fs(struct inode *inode,
259 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400261 .open = acpi_video_device_EDID_open_fs,
262 .read = seq_read,
263 .llseek = seq_lseek,
264 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
266
Len Brown4be44fc2005-08-05 00:44:28 -0400267static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 "motherboard VGA device",
269 "PCI VGA device",
270 "AGP VGA device",
271 "UNKNOWN",
272};
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
275static void acpi_video_device_rebind(struct acpi_video_bus *video);
276static void acpi_video_device_bind(struct acpi_video_bus *video,
277 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800279static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
280 int level);
281static int acpi_video_device_lcd_get_level_current(
282 struct acpi_video_device *device,
283 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400284static int acpi_video_get_next_level(struct acpi_video_device *device,
285 u32 level_current, u32 event);
286static void acpi_video_switch_brightness(struct acpi_video_device *device,
287 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800288static int acpi_video_device_get_state(struct acpi_video_device *device,
289 unsigned long *state);
290static int acpi_video_output_get(struct output_device *od);
291static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Yu Luming2f3d0002006-11-11 02:40:34 +0800293/*backlight device sysfs support*/
294static int acpi_video_get_brightness(struct backlight_device *bd)
295{
296 unsigned long cur_level;
297 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100298 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800299 acpi_video_device_lcd_get_level_current(vd, &cur_level);
300 return (int) cur_level;
301}
302
303static int acpi_video_set_brightness(struct backlight_device *bd)
304{
Richard Purdie599a52d2007-02-10 23:07:48 +0000305 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800306 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100307 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800308 acpi_video_device_lcd_set_level(vd, request_level);
309 return 0;
310}
311
Richard Purdie599a52d2007-02-10 23:07:48 +0000312static struct backlight_ops acpi_backlight_ops = {
313 .get_brightness = acpi_video_get_brightness,
314 .update_status = acpi_video_set_brightness,
315};
316
Luming Yu23b0f012007-05-09 21:07:05 +0800317/*video output device sysfs support*/
318static int acpi_video_output_get(struct output_device *od)
319{
320 unsigned long state;
321 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700322 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800323 acpi_video_device_get_state(vd, &state);
324 return (int)state;
325}
326
327static int acpi_video_output_set(struct output_device *od)
328{
329 unsigned long state = od->request_state;
330 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700331 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800332 return acpi_video_device_set_state(vd, state);
333}
334
335static struct output_properties acpi_output_properties = {
336 .set_state = acpi_video_output_set,
337 .get_status = acpi_video_output_get,
338};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/* --------------------------------------------------------------------------
340 Video Management
341 -------------------------------------------------------------------------- */
342
343/* device */
344
345static int
Len Brown4be44fc2005-08-05 00:44:28 -0400346acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Len Brown4be44fc2005-08-05 00:44:28 -0400348 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400349
350 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Patrick Mocheld550d982006-06-27 00:41:40 -0400352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355static int
Len Brown4be44fc2005-08-05 00:44:28 -0400356acpi_video_device_get_state(struct acpi_video_device *device,
357 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Patrick Mochel90130262006-05-19 16:54:48 -0400361 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Patrick Mocheld550d982006-06-27 00:41:40 -0400363 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366static int
Len Brown4be44fc2005-08-05 00:44:28 -0400367acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Len Brown4be44fc2005-08-05 00:44:28 -0400369 int status;
370 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
371 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400372 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400376 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Patrick Mocheld550d982006-06-27 00:41:40 -0400378 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381static int
Len Brown4be44fc2005-08-05 00:44:28 -0400382acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
383 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Len Brown4be44fc2005-08-05 00:44:28 -0400385 int status;
386 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
387 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 *levels = NULL;
391
Patrick Mochel90130262006-05-19 16:54:48 -0400392 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400394 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400395 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500396 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400397 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 status = -EFAULT;
399 goto err;
400 }
401
402 *levels = obj;
403
Patrick Mocheld550d982006-06-27 00:41:40 -0400404 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800407 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Patrick Mocheld550d982006-06-27 00:41:40 -0400409 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
412static int
Len Brown4be44fc2005-08-05 00:44:28 -0400413acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400415 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400416 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
417 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400422 if (device->cap._BCM)
423 status = acpi_evaluate_object(device->dev->handle, "_BCM",
424 &args, NULL);
425 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
429static int
Len Brown4be44fc2005-08-05 00:44:28 -0400430acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
431 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400433 if (device->cap._BQC)
434 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
435 level);
436 *level = device->brightness->curr;
437 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440static int
Len Brown4be44fc2005-08-05 00:44:28 -0400441acpi_video_device_EDID(struct acpi_video_device *device,
442 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Len Brown4be44fc2005-08-05 00:44:28 -0400444 int status;
445 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
446 union acpi_object *obj;
447 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
448 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 *edid = NULL;
452
453 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400454 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (length == 128)
456 arg0.integer.value = 1;
457 else if (length == 256)
458 arg0.integer.value = 2;
459 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400460 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Patrick Mochel90130262006-05-19 16:54:48 -0400462 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400464 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200466 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 if (obj && obj->type == ACPI_TYPE_BUFFER)
469 *edid = obj;
470 else {
Len Brown64684632006-06-26 23:41:38 -0400471 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 status = -EFAULT;
473 kfree(obj);
474 }
475
Patrick Mocheld550d982006-06-27 00:41:40 -0400476 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479/* bus */
480
481static int
Len Brown4be44fc2005-08-05 00:44:28 -0400482acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Len Brown4be44fc2005-08-05 00:44:28 -0400484 int status;
485 unsigned long tmp;
486 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
487 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 arg0.integer.value = option;
491
Patrick Mochel90130262006-05-19 16:54:48 -0400492 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400494 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Patrick Mocheld550d982006-06-27 00:41:40 -0400496 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499static int
Len Brown4be44fc2005-08-05 00:44:28 -0400500acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 int status;
503
Patrick Mochel90130262006-05-19 16:54:48 -0400504 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Patrick Mocheld550d982006-06-27 00:41:40 -0400506 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
509static int
Len Brown4be44fc2005-08-05 00:44:28 -0400510acpi_video_bus_POST_options(struct acpi_video_bus *video,
511 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Len Brown4be44fc2005-08-05 00:44:28 -0400513 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Patrick Mochel90130262006-05-19 16:54:48 -0400515 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 *options &= 3;
517
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521/*
522 * Arg:
523 * video : video bus device pointer
524 * bios_flag :
525 * 0. The system BIOS should NOT automatically switch(toggle)
526 * the active display output.
527 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100528 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 * 2. The _DGS value should be locked.
530 * 3. The system BIOS should not automatically switch (toggle) the
531 * active display output, but instead generate the display switch
532 * event notify code.
533 * lcd_flag :
534 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100535 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100537 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 * Return Value:
539 * -1 wrong arg.
540 */
541
542static int
Len Brown4be44fc2005-08-05 00:44:28 -0400543acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Len Brown4be44fc2005-08-05 00:44:28 -0400545 acpi_integer status = 0;
546 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
547 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 status = -1;
552 goto Failed;
553 }
554 arg0.integer.value = (lcd_flag << 2) | bios_flag;
555 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400556 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Len Brown4be44fc2005-08-05 00:44:28 -0400558 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400559 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
562/*
563 * Arg:
564 * device : video output device (LCD, CRT, ..)
565 *
566 * Return Value:
567 * None
568 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100569 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 * device.
571 */
572
Len Brown4be44fc2005-08-05 00:44:28 -0400573static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 acpi_handle h_dummy1;
576 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800577 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 union acpi_object *obj = NULL;
579 struct acpi_video_device_brightness *br = NULL;
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
William Lee Irwin III98934de2007-12-12 03:56:55 -0800582 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Patrick Mochel90130262006-05-19 16:54:48 -0400584 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 device->cap._ADR = 1;
586 }
Patrick Mochel90130262006-05-19 16:54:48 -0400587 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400588 device->cap._BCL = 1;
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, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400591 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
594 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400596 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Patrick Mochel90130262006-05-19 16:54:48 -0400598 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 device->cap._DCS = 1;
600 }
Patrick Mochel90130262006-05-19 16:54:48 -0400601 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 device->cap._DGS = 1;
603 }
Patrick Mochel90130262006-05-19 16:54:48 -0400604 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 device->cap._DSS = 1;
606 }
607
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400608 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400610 if (obj->package.count >= 2) {
611 int count = 0;
612 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400613
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400614 br = kzalloc(sizeof(*br), GFP_KERNEL);
615 if (!br) {
616 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400618 br->levels = kmalloc(obj->package.count *
619 sizeof *(br->levels), GFP_KERNEL);
620 if (!br->levels)
621 goto out;
622
623 for (i = 0; i < obj->package.count; i++) {
624 o = (union acpi_object *)&obj->package.
625 elements[i];
626 if (o->type != ACPI_TYPE_INTEGER) {
627 printk(KERN_ERR PREFIX "Invalid data\n");
628 continue;
629 }
630 br->levels[count] = (u32) o->integer.value;
631
632 if (br->levels[count] > max_level)
633 max_level = br->levels[count];
634 count++;
635 }
636 out:
637 if (count < 2) {
638 kfree(br->levels);
639 kfree(br);
640 } else {
641 br->count = count;
642 device->brightness = br;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "found %d brightness levels\n",
645 count));
646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400649
650 } else {
651 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500654 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400656 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800657 unsigned long tmp;
658 static int count = 0;
659 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800660 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
661 if (!name)
662 return;
663
Yu Luming2f3d0002006-11-11 02:40:34 +0800664 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800665 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800666 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000667 NULL, device, &acpi_backlight_ops);
668 device->backlight->props.max_brightness = max_level;
669 device->backlight->props.brightness = (int)tmp;
670 backlight_update_status(device->backlight);
671
Yu Luming2f3d0002006-11-11 02:40:34 +0800672 kfree(name);
673 }
Luming Yu23b0f012007-05-09 21:07:05 +0800674 if (device->cap._DCS && device->cap._DSS){
675 static int count = 0;
676 char *name;
677 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
678 if (!name)
679 return;
680 sprintf(name, "acpi_video%d", count++);
681 device->output_dev = video_output_register(name,
682 NULL, device, &acpi_output_properties);
683 kfree(name);
684 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400685 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
688/*
689 * Arg:
690 * device : video output device (VGA)
691 *
692 * Return Value:
693 * None
694 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100695 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 */
697
Len Brown4be44fc2005-08-05 00:44:28 -0400698static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Len Brown4be44fc2005-08-05 00:44:28 -0400700 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
William Lee Irwin III98934de2007-12-12 03:56:55 -0800702 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400703 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 video->cap._DOS = 1;
705 }
Patrick Mochel90130262006-05-19 16:54:48 -0400706 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 video->cap._DOD = 1;
708 }
Patrick Mochel90130262006-05-19 16:54:48 -0400709 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 video->cap._ROM = 1;
711 }
Patrick Mochel90130262006-05-19 16:54:48 -0400712 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 video->cap._GPD = 1;
714 }
Patrick Mochel90130262006-05-19 16:54:48 -0400715 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 video->cap._SPD = 1;
717 }
Patrick Mochel90130262006-05-19 16:54:48 -0400718 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 video->cap._VPO = 1;
720 }
721}
722
723/*
724 * Check whether the video bus device has required AML method to
725 * support the desired features
726 */
727
Len Brown4be44fc2005-08-05 00:44:28 -0400728static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Len Brown4be44fc2005-08-05 00:44:28 -0400730 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400734 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 /* Since there is no HID, CID and so on for VGA driver, we have
737 * to check well known required nodes.
738 */
739
Julius Volz98fb8fe2007-02-20 16:38:40 +0100740 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400741 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 video->flags.multihead = 1;
743 status = 0;
744 }
745
Julius Volz98fb8fe2007-02-20 16:38:40 +0100746 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400747 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 video->flags.rom = 1;
749 status = 0;
750 }
751
Julius Volz98fb8fe2007-02-20 16:38:40 +0100752 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400753 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 video->flags.post = 1;
755 status = 0;
756 }
757
Patrick Mocheld550d982006-06-27 00:41:40 -0400758 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
761/* --------------------------------------------------------------------------
762 FS Interface (/proc)
763 -------------------------------------------------------------------------- */
764
Len Brown4be44fc2005-08-05 00:44:28 -0400765static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767/* video devices */
768
Len Brown4be44fc2005-08-05 00:44:28 -0400769static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200771 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 if (!dev)
775 goto end;
776
777 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
778 seq_printf(seq, "type: ");
779 if (dev->flags.crt)
780 seq_printf(seq, "CRT\n");
781 else if (dev->flags.lcd)
782 seq_printf(seq, "LCD\n");
783 else if (dev->flags.tvout)
784 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500785 else if (dev->flags.dvi)
786 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 else
788 seq_printf(seq, "UNKNOWN\n");
789
Len Brown4be44fc2005-08-05 00:44:28 -0400790 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Len Brown4be44fc2005-08-05 00:44:28 -0400792 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400793 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
796static int
Len Brown4be44fc2005-08-05 00:44:28 -0400797acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
799 return single_open(file, acpi_video_device_info_seq_show,
800 PDE(inode)->data);
801}
802
Len Brown4be44fc2005-08-05 00:44:28 -0400803static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Len Brown4be44fc2005-08-05 00:44:28 -0400805 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200806 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400807 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
810 if (!dev)
811 goto end;
812
813 status = acpi_video_device_get_state(dev, &state);
814 seq_printf(seq, "state: ");
815 if (ACPI_SUCCESS(status))
816 seq_printf(seq, "0x%02lx\n", state);
817 else
818 seq_printf(seq, "<not supported>\n");
819
820 status = acpi_video_device_query(dev, &state);
821 seq_printf(seq, "query: ");
822 if (ACPI_SUCCESS(status))
823 seq_printf(seq, "0x%02lx\n", state);
824 else
825 seq_printf(seq, "<not supported>\n");
826
Len Brown4be44fc2005-08-05 00:44:28 -0400827 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400828 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
831static int
Len Brown4be44fc2005-08-05 00:44:28 -0400832acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834 return single_open(file, acpi_video_device_state_seq_show,
835 PDE(inode)->data);
836}
837
838static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400839acpi_video_device_write_state(struct file *file,
840 const char __user * buffer,
841 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Len Brown4be44fc2005-08-05 00:44:28 -0400843 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200844 struct seq_file *m = file->private_data;
845 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400846 char str[12] = { 0 };
847 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400851 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400854 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
856 str[count] = 0;
857 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400858 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 status = acpi_video_device_set_state(dev, state);
861
862 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Patrick Mocheld550d982006-06-27 00:41:40 -0400865 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
868static int
Len Brown4be44fc2005-08-05 00:44:28 -0400869acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200871 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400872 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (!dev || !dev->brightness) {
876 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400877 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 }
879
880 seq_printf(seq, "levels: ");
881 for (i = 0; i < dev->brightness->count; i++)
882 seq_printf(seq, " %d", dev->brightness->levels[i]);
883 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
884
Patrick Mocheld550d982006-06-27 00:41:40 -0400885 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
888static int
Len Brown4be44fc2005-08-05 00:44:28 -0400889acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 return single_open(file, acpi_video_device_brightness_seq_show,
892 PDE(inode)->data);
893}
894
895static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400896acpi_video_device_write_brightness(struct file *file,
897 const char __user * buffer,
898 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200900 struct seq_file *m = file->private_data;
901 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100902 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400903 unsigned int level = 0;
904 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Thomas Renninger59d399d2005-11-08 05:27:00 -0500907 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400908 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400911 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 str[count] = 0;
914 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400917 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Julius Volz98fb8fe2007-02-20 16:38:40 +0100919 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 for (i = 0; i < dev->brightness->count; i++)
921 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400922 if (ACPI_SUCCESS
923 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 dev->brightness->curr = level;
925 break;
926 }
927
Patrick Mocheld550d982006-06-27 00:41:40 -0400928 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Len Brown4be44fc2005-08-05 00:44:28 -0400931static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200933 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400934 int status;
935 int i;
936 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (!dev)
940 goto out;
941
Len Brown4be44fc2005-08-05 00:44:28 -0400942 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400944 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946
947 if (ACPI_FAILURE(status)) {
948 goto out;
949 }
950
951 if (edid && edid->type == ACPI_TYPE_BUFFER) {
952 for (i = 0; i < edid->buffer.length; i++)
953 seq_putc(seq, edid->buffer.pointer[i]);
954 }
955
Len Brown4be44fc2005-08-05 00:44:28 -0400956 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (!edid)
958 seq_printf(seq, "<not supported>\n");
959 else
960 kfree(edid);
961
Patrick Mocheld550d982006-06-27 00:41:40 -0400962 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
965static int
Len Brown4be44fc2005-08-05 00:44:28 -0400966acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
968 return single_open(file, acpi_video_device_EDID_seq_show,
969 PDE(inode)->data);
970}
971
Len Brown4be44fc2005-08-05 00:44:28 -0400972static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Len Brown4be44fc2005-08-05 00:44:28 -0400974 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 struct acpi_video_device *vid_dev;
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400979 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200981 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 if (!acpi_device_dir(device)) {
986 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400987 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400989 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 acpi_device_dir(device)->owner = THIS_MODULE;
991 }
992
993 /* 'info' [R] */
994 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
995 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400996 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 else {
998 entry->proc_fops = &acpi_video_device_info_fops;
999 entry->data = acpi_driver_data(device);
1000 entry->owner = THIS_MODULE;
1001 }
1002
1003 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001004 entry =
1005 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1006 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001008 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001010 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 entry->data = acpi_driver_data(device);
1013 entry->owner = THIS_MODULE;
1014 }
1015
1016 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001017 entry =
1018 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1019 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001021 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001023 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 entry->data = acpi_driver_data(device);
1026 entry->owner = THIS_MODULE;
1027 }
1028
1029 /* 'EDID' [R] */
1030 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1031 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001032 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 else {
1034 entry->proc_fops = &acpi_video_device_EDID_fops;
1035 entry->data = acpi_driver_data(device);
1036 entry->owner = THIS_MODULE;
1037 }
1038
Patrick Mocheld550d982006-06-27 00:41:40 -04001039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
Len Brown4be44fc2005-08-05 00:44:28 -04001042static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
1044 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001046 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001048 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 if (acpi_device_dir(device)) {
1051 remove_proc_entry("info", acpi_device_dir(device));
1052 remove_proc_entry("state", acpi_device_dir(device));
1053 remove_proc_entry("brightness", acpi_device_dir(device));
1054 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001055 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 acpi_device_dir(device) = NULL;
1057 }
1058
Patrick Mocheld550d982006-06-27 00:41:40 -04001059 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001063static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001065 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 if (!video)
1069 goto end;
1070
1071 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001072 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001074 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001076 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Len Brown4be44fc2005-08-05 00:44:28 -04001078 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001079 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
Len Brown4be44fc2005-08-05 00:44:28 -04001082static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Len Brown4be44fc2005-08-05 00:44:28 -04001084 return single_open(file, acpi_video_bus_info_seq_show,
1085 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
Len Brown4be44fc2005-08-05 00:44:28 -04001088static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001090 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (!video)
1094 goto end;
1095
1096 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1097 seq_printf(seq, "<TODO>\n");
1098
Len Brown4be44fc2005-08-05 00:44:28 -04001099 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001100 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Len Brown4be44fc2005-08-05 00:44:28 -04001103static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
1105 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1106}
1107
Len Brown4be44fc2005-08-05 00:44:28 -04001108static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001110 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001111 unsigned long options;
1112 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 if (!video)
1116 goto end;
1117
1118 status = acpi_video_bus_POST_options(video, &options);
1119 if (ACPI_SUCCESS(status)) {
1120 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001121 printk(KERN_WARNING PREFIX
1122 "The motherboard VGA device is not listed as a possible POST device.\n");
1123 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001124 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
1126 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001127 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 if (options & 2)
1129 seq_printf(seq, " <PCI video>");
1130 if (options & 4)
1131 seq_printf(seq, " <AGP video>");
1132 seq_putc(seq, '\n');
1133 } else
1134 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001135 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
1139static int
Len Brown4be44fc2005-08-05 00:44:28 -04001140acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141{
Len Brown4be44fc2005-08-05 00:44:28 -04001142 return single_open(file, acpi_video_bus_POST_info_seq_show,
1143 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Len Brown4be44fc2005-08-05 00:44:28 -04001146static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001148 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001149 int status;
1150 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 if (!video)
1154 goto end;
1155
Len Brown4be44fc2005-08-05 00:44:28 -04001156 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 if (!ACPI_SUCCESS(status)) {
1158 seq_printf(seq, "<not supported>\n");
1159 goto end;
1160 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001161 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Len Brown4be44fc2005-08-05 00:44:28 -04001163 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001164 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165}
1166
Len Brown4be44fc2005-08-05 00:44:28 -04001167static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001169 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Len Brown4be44fc2005-08-05 00:44:28 -04001172 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Patrick Mocheld550d982006-06-27 00:41:40 -04001174 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Len Brown4be44fc2005-08-05 00:44:28 -04001177static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
Len Brown4be44fc2005-08-05 00:44:28 -04001179 return single_open(file, acpi_video_bus_POST_seq_show,
1180 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181}
1182
Len Brown4be44fc2005-08-05 00:44:28 -04001183static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
1185 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1186}
1187
1188static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001189acpi_video_bus_write_POST(struct file *file,
1190 const char __user * buffer,
1191 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Len Brown4be44fc2005-08-05 00:44:28 -04001193 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001194 struct seq_file *m = file->private_data;
1195 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001196 char str[12] = { 0 };
1197 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001201 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 status = acpi_video_bus_POST_options(video, &options);
1204 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001205 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001208 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 str[count] = 0;
1211 opt = strtoul(str, NULL, 0);
1212 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001213 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Julius Volz98fb8fe2007-02-20 16:38:40 +01001215 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 options |= 1;
1217
1218 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001219 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001221 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 }
1224
Patrick Mocheld550d982006-06-27 00:41:40 -04001225 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
1228static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001229acpi_video_bus_write_DOS(struct file *file,
1230 const char __user * buffer,
1231 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Len Brown4be44fc2005-08-05 00:44:28 -04001233 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001234 struct seq_file *m = file->private_data;
1235 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001236 char str[12] = { 0 };
1237 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001241 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 str[count] = 0;
1247 opt = strtoul(str, NULL, 0);
1248 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001249 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Len Brown4be44fc2005-08-05 00:44:28 -04001251 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001254 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
Len Brown4be44fc2005-08-05 00:44:28 -04001259static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
Len Brown4be44fc2005-08-05 00:44:28 -04001261 struct proc_dir_entry *entry = NULL;
1262 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001265 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 if (!acpi_device_dir(device)) {
1268 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001269 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001271 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 video->dir = acpi_device_dir(device);
1273 acpi_device_dir(device)->owner = THIS_MODULE;
1274 }
1275
1276 /* 'info' [R] */
1277 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1278 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001279 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 else {
1281 entry->proc_fops = &acpi_video_bus_info_fops;
1282 entry->data = acpi_driver_data(device);
1283 entry->owner = THIS_MODULE;
1284 }
1285
1286 /* 'ROM' [R] */
1287 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1288 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001289 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 else {
1291 entry->proc_fops = &acpi_video_bus_ROM_fops;
1292 entry->data = acpi_driver_data(device);
1293 entry->owner = THIS_MODULE;
1294 }
1295
1296 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001297 entry =
1298 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001300 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 else {
1302 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1303 entry->data = acpi_driver_data(device);
1304 entry->owner = THIS_MODULE;
1305 }
1306
1307 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001308 entry =
1309 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1310 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001312 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001314 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 entry->data = acpi_driver_data(device);
1317 entry->owner = THIS_MODULE;
1318 }
1319
1320 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001321 entry =
1322 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1323 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001325 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001327 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 entry->data = acpi_driver_data(device);
1330 entry->owner = THIS_MODULE;
1331 }
1332
Patrick Mocheld550d982006-06-27 00:41:40 -04001333 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
Len Brown4be44fc2005-08-05 00:44:28 -04001336static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Len Brown4be44fc2005-08-05 00:44:28 -04001338 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001341 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 if (acpi_device_dir(device)) {
1344 remove_proc_entry("info", acpi_device_dir(device));
1345 remove_proc_entry("ROM", acpi_device_dir(device));
1346 remove_proc_entry("POST_info", acpi_device_dir(device));
1347 remove_proc_entry("POST", acpi_device_dir(device));
1348 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001349 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 acpi_device_dir(device) = NULL;
1351 }
1352
Patrick Mocheld550d982006-06-27 00:41:40 -04001353 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
1356/* --------------------------------------------------------------------------
1357 Driver Interface
1358 -------------------------------------------------------------------------- */
1359
1360/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001361static struct acpi_video_device_attrib*
1362acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1363{
1364 int count;
1365
1366 for(count = 0; count < video->attached_count; count++)
1367 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1368 return &(video->attached_array[count].value.attrib);
1369 return NULL;
1370}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
1372static int
Len Brown4be44fc2005-08-05 00:44:28 -04001373acpi_video_bus_get_one_device(struct acpi_device *device,
1374 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Len Brown4be44fc2005-08-05 00:44:28 -04001376 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001377 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001378 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001379 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001382 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Len Brown4be44fc2005-08-05 00:44:28 -04001384 status =
1385 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if (ACPI_SUCCESS(status)) {
1387
Burman Yan36bcbec2006-12-19 12:56:11 -08001388 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001390 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1393 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1394 acpi_driver_data(device) = data;
1395
1396 data->device_id = device_id;
1397 data->video = video;
1398 data->dev = device;
1399
Rui Zhang82cae992007-01-03 23:40:53 -05001400 attribute = acpi_video_get_device_attr(video, device_id);
1401
1402 if((attribute != NULL) && attribute->device_id_scheme) {
1403 switch (attribute->display_type) {
1404 case ACPI_VIDEO_DISPLAY_CRT:
1405 data->flags.crt = 1;
1406 break;
1407 case ACPI_VIDEO_DISPLAY_TV:
1408 data->flags.tvout = 1;
1409 break;
1410 case ACPI_VIDEO_DISPLAY_DVI:
1411 data->flags.dvi = 1;
1412 break;
1413 case ACPI_VIDEO_DISPLAY_LCD:
1414 data->flags.lcd = 1;
1415 break;
1416 default:
1417 data->flags.unknown = 1;
1418 break;
1419 }
1420 if(attribute->bios_can_detect)
1421 data->flags.bios = 1;
1422 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001424
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 acpi_video_device_bind(video, data);
1426 acpi_video_device_find_cap(data);
1427
Patrick Mochel90130262006-05-19 16:54:48 -04001428 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001429 ACPI_DEVICE_NOTIFY,
1430 acpi_video_device_notify,
1431 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 if (ACPI_FAILURE(status)) {
1433 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001434 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001435 if(data->brightness)
1436 kfree(data->brightness->levels);
1437 kfree(data->brightness);
1438 kfree(data);
1439 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001442 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001444 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 acpi_video_device_add_fs(device);
1447
Patrick Mocheld550d982006-06-27 00:41:40 -04001448 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450
Patrick Mocheld550d982006-06-27 00:41:40 -04001451 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
1454/*
1455 * Arg:
1456 * video : video bus device
1457 *
1458 * Return:
1459 * none
1460 *
1461 * Enumerate the video device list of the video bus,
1462 * bind the ids with the corresponding video devices
1463 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001464 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Len Brown4be44fc2005-08-05 00:44:28 -04001466static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001468 struct acpi_video_device *dev;
1469
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001470 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001471
1472 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001473 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001474
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001475 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476}
1477
1478/*
1479 * Arg:
1480 * video : video bus device
1481 * device : video output device under the video
1482 * bus
1483 *
1484 * Return:
1485 * none
1486 *
1487 * Bind the ids with the corresponding video devices
1488 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001489 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491static void
Len Brown4be44fc2005-08-05 00:44:28 -04001492acpi_video_device_bind(struct acpi_video_bus *video,
1493 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Len Brown4be44fc2005-08-05 00:44:28 -04001495 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497#define IDS_VAL(i) video->attached_array[i].value.int_val
1498#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001499
1500 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1501 i < video->attached_count; i++) {
1502 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 IDS_BIND(i) = device;
1504 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1505 }
1506 }
1507#undef IDS_VAL
1508#undef IDS_BIND
1509}
1510
1511/*
1512 * Arg:
1513 * video : video bus device
1514 *
1515 * Return:
1516 * < 0 : error
1517 *
1518 * Call _DOD to enumerate all devices attached to display adapter
1519 *
Len Brown4be44fc2005-08-05 00:44:28 -04001520 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1523{
Len Brown4be44fc2005-08-05 00:44:28 -04001524 int status;
1525 int count;
1526 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001528 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1529 union acpi_object *dod = NULL;
1530 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Patrick Mochel90130262006-05-19 16:54:48 -04001532 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001534 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001535 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 }
1537
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001538 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001540 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 status = -EFAULT;
1542 goto out;
1543 }
1544
1545 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001546 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Len Brown4be44fc2005-08-05 00:44:28 -04001548 active_device_list = kmalloc((1 +
1549 dod->package.count) *
1550 sizeof(struct
1551 acpi_video_enumerated_device),
1552 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554 if (!active_device_list) {
1555 status = -ENOMEM;
1556 goto out;
1557 }
1558
1559 count = 0;
1560 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001561 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001564 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001565 active_device_list[i].value.int_val =
1566 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 }
1568 active_device_list[i].value.int_val = obj->integer.value;
1569 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001570 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1571 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 count++;
1573 }
1574 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1575
Jesper Juhl6044ec82005-11-07 01:01:32 -08001576 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 video->attached_array = active_device_list;
1579 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001580 out:
Len Brown02438d82006-06-30 03:19:10 -04001581 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001582 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Len Brown4be44fc2005-08-05 00:44:28 -04001585static int
1586acpi_video_get_next_level(struct acpi_video_device *device,
1587 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001589 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001590 max = max_below = 0;
1591 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001592 /* Find closest level to level_current */
1593 for (i = 0; i < device->brightness->count; i++) {
1594 l = device->brightness->levels[i];
1595 if (abs(l - level_current) < abs(delta)) {
1596 delta = l - level_current;
1597 if (!delta)
1598 break;
1599 }
1600 }
1601 /* Ajust level_current to closest available level */
1602 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001603 for (i = 0; i < device->brightness->count; i++) {
1604 l = device->brightness->levels[i];
1605 if (l < min)
1606 min = l;
1607 if (l > max)
1608 max = l;
1609 if (l < min_above && l > level_current)
1610 min_above = l;
1611 if (l > max_below && l < level_current)
1612 max_below = l;
1613 }
1614
1615 switch (event) {
1616 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1617 return (level_current < max) ? min_above : min;
1618 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1619 return (level_current < max) ? min_above : max;
1620 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1621 return (level_current > min) ? max_below : min;
1622 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1623 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1624 return 0;
1625 default:
1626 return level_current;
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630static void
Len Brown4be44fc2005-08-05 00:44:28 -04001631acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
1633 unsigned long level_current, level_next;
1634 acpi_video_device_lcd_get_level_current(device, &level_current);
1635 level_next = acpi_video_get_next_level(device, level_current, event);
1636 acpi_video_device_lcd_set_level(device, level_next);
1637}
1638
1639static int
Len Brown4be44fc2005-08-05 00:44:28 -04001640acpi_video_bus_get_devices(struct acpi_video_bus *video,
1641 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Len Brown4be44fc2005-08-05 00:44:28 -04001643 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001644 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 acpi_video_device_enumerate(video);
1647
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001648 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 status = acpi_video_bus_get_one_device(dev, video);
1651 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001652 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 continue;
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001656 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Len Brown4be44fc2005-08-05 00:44:28 -04001659static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Karol Kozimor031ec772005-07-30 04:18:00 -04001661 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 struct acpi_video_bus *video;
1663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001666 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 video = device->video;
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 acpi_video_device_remove_fs(device->dev);
1671
Patrick Mochel90130262006-05-19 16:54:48 -04001672 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001673 ACPI_DEVICE_NOTIFY,
1674 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001675 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001676 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001677
Patrick Mocheld550d982006-06-27 00:41:40 -04001678 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Len Brown4be44fc2005-08-05 00:44:28 -04001681static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Len Brown4be44fc2005-08-05 00:44:28 -04001683 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001684 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001686 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001688 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001690 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001691 if (ACPI_FAILURE(status))
1692 printk(KERN_WARNING PREFIX
1693 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001695 if (dev->brightness) {
1696 kfree(dev->brightness->levels);
1697 kfree(dev->brightness);
1698 }
1699 list_del(&dev->entry);
1700 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001703 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001704
Patrick Mocheld550d982006-06-27 00:41:40 -04001705 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
1708/* acpi_video interface */
1709
Len Brown4be44fc2005-08-05 00:44:28 -04001710static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711{
Zhang Ruia21101c2007-09-14 11:46:22 +08001712 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Len Brown4be44fc2005-08-05 00:44:28 -04001715static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 return acpi_video_bus_DOS(video, 0, 1);
1718}
1719
Len Brown4be44fc2005-08-05 00:44:28 -04001720static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001722 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001723 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001724 struct input_dev *input;
1725 int keycode;
1726
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001728 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001730 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001731 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001734 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001736 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001737 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 break;
1739
Julius Volz98fb8fe2007-02-20 16:38:40 +01001740 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 * connector. */
1742 acpi_video_device_enumerate(video);
1743 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001744 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001745 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 break;
1747
Len Brown4be44fc2005-08-05 00:44:28 -04001748 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001749 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001750 keycode = KEY_SWITCHVIDEOMODE;
1751 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001752 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001753 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001754 keycode = KEY_VIDEO_NEXT;
1755 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001756 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001757 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001758 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 break;
1760
1761 default:
Luming Yue9dab192007-08-20 18:23:53 +08001762 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001764 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 break;
1766 }
1767
Zhang Rui7761f632008-01-25 14:48:12 +08001768 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001769 input_report_key(input, keycode, 1);
1770 input_sync(input);
1771 input_report_key(input, keycode, 0);
1772 input_sync(input);
1773
Patrick Mocheld550d982006-06-27 00:41:40 -04001774 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Len Brown4be44fc2005-08-05 00:44:28 -04001777static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001779 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001780 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001781 struct acpi_video_bus *bus;
1782 struct input_dev *input;
1783 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001786 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001788 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001789 bus = video_device->video;
1790 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001793 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001794 if (brightness_switch_enabled)
1795 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001796 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001797 keycode = KEY_BRIGHTNESS_CYCLE;
1798 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001799 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001800 if (brightness_switch_enabled)
1801 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001802 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001803 keycode = KEY_BRIGHTNESSUP;
1804 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001805 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001806 if (brightness_switch_enabled)
1807 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001808 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001809 keycode = KEY_BRIGHTNESSDOWN;
1810 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001811 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001812 if (brightness_switch_enabled)
1813 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001814 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001815 keycode = KEY_BRIGHTNESS_ZERO;
1816 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001817 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001818 if (brightness_switch_enabled)
1819 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001820 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001821 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 break;
1823 default:
Luming Yue9dab192007-08-20 18:23:53 +08001824 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001826 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 break;
1828 }
Luming Yue9dab192007-08-20 18:23:53 +08001829
Zhang Rui7761f632008-01-25 14:48:12 +08001830 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001831 input_report_key(input, keycode, 1);
1832 input_sync(input);
1833 input_report_key(input, keycode, 0);
1834 input_sync(input);
1835
Patrick Mocheld550d982006-06-27 00:41:40 -04001836 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837}
1838
Zhang Ruie6d9da12007-08-25 02:23:31 -04001839static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001840static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001842 acpi_status status;
1843 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001844 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001845 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
Burman Yan36bcbec2006-12-19 12:56:11 -08001847 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001849 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Zhang Ruie6d9da12007-08-25 02:23:31 -04001851 /* a hack to fix the duplicate name "VID" problem on T61 */
1852 if (!strcmp(device->pnp.bus_id, "VID")) {
1853 if (instance)
1854 device->pnp.bus_id[3] = '0' + instance;
1855 instance ++;
1856 }
1857
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001858 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1860 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1861 acpi_driver_data(device) = video;
1862
1863 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001864 error = acpi_video_bus_check(video);
1865 if (error)
1866 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001868 error = acpi_video_bus_add_fs(device);
1869 if (error)
1870 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001872 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 INIT_LIST_HEAD(&video->video_device_list);
1874
1875 acpi_video_bus_get_devices(video, device);
1876 acpi_video_bus_start_devices(video);
1877
Patrick Mochel90130262006-05-19 16:54:48 -04001878 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001879 ACPI_DEVICE_NOTIFY,
1880 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 if (ACPI_FAILURE(status)) {
1882 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001883 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001884 error = -ENODEV;
1885 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
1887
Luming Yue9dab192007-08-20 18:23:53 +08001888 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001889 if (!input) {
1890 error = -ENOMEM;
1891 goto err_uninstall_notify;
1892 }
Luming Yue9dab192007-08-20 18:23:53 +08001893
1894 snprintf(video->phys, sizeof(video->phys),
1895 "%s/video/input0", acpi_device_hid(video->device));
1896
1897 input->name = acpi_device_name(video->device);
1898 input->phys = video->phys;
1899 input->id.bustype = BUS_HOST;
1900 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001901 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001902 input->evbit[0] = BIT(EV_KEY);
1903 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1904 set_bit(KEY_VIDEO_NEXT, input->keybit);
1905 set_bit(KEY_VIDEO_PREV, input->keybit);
1906 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1907 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1908 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1909 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1910 set_bit(KEY_DISPLAY_OFF, input->keybit);
1911 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001912
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001913 error = input_register_device(input);
1914 if (error)
1915 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001918 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1919 video->flags.multihead ? "yes" : "no",
1920 video->flags.rom ? "yes" : "no",
1921 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001923 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001925 err_free_input_dev:
1926 input_free_device(input);
1927 err_uninstall_notify:
1928 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1929 acpi_video_bus_notify);
1930 err_stop_video:
1931 acpi_video_bus_stop_devices(video);
1932 acpi_video_bus_put_devices(video);
1933 kfree(video->attached_array);
1934 acpi_video_bus_remove_fs(device);
1935 err_free_video:
1936 kfree(video);
1937 acpi_driver_data(device) = NULL;
1938
1939 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
Len Brown4be44fc2005-08-05 00:44:28 -04001942static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
Len Brown4be44fc2005-08-05 00:44:28 -04001944 acpi_status status = 0;
1945 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001949 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001951 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
1953 acpi_video_bus_stop_devices(video);
1954
Patrick Mochel90130262006-05-19 16:54:48 -04001955 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001956 ACPI_DEVICE_NOTIFY,
1957 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 acpi_video_bus_put_devices(video);
1960 acpi_video_bus_remove_fs(device);
1961
Luming Yue9dab192007-08-20 18:23:53 +08001962 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08001963 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 kfree(video);
1965
Patrick Mocheld550d982006-06-27 00:41:40 -04001966 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
Len Brown4be44fc2005-08-05 00:44:28 -04001969static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
Len Brown4be44fc2005-08-05 00:44:28 -04001971 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 /*
Len Brown4be44fc2005-08-05 00:44:28 -04001975 acpi_dbg_level = 0xFFFFFFFF;
1976 acpi_dbg_layer = 0x08000000;
1977 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
1980 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001981 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 acpi_video_dir->owner = THIS_MODULE;
1983
1984 result = acpi_bus_register_driver(&acpi_video_bus);
1985 if (result < 0) {
1986 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001987 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989
Patrick Mocheld550d982006-06-27 00:41:40 -04001990 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991}
1992
Len Brown4be44fc2005-08-05 00:44:28 -04001993static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 acpi_bus_unregister_driver(&acpi_video_bus);
1997
1998 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
1999
Patrick Mocheld550d982006-06-27 00:41:40 -04002000 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
2003module_init(acpi_video_init);
2004module_exit(acpi_video_exit);