blob: b1a56bf682ae992befd4510cc59173a9a8507eaa [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);
Len Brown4be44fc2005-08-05 00:44:28 -0400279static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800280static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
281 int level);
282static int acpi_video_device_lcd_get_level_current(
283 struct acpi_video_device *device,
284 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400285static int acpi_video_get_next_level(struct acpi_video_device *device,
286 u32 level_current, u32 event);
287static void acpi_video_switch_brightness(struct acpi_video_device *device,
288 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800289static int acpi_video_device_get_state(struct acpi_video_device *device,
290 unsigned long *state);
291static int acpi_video_output_get(struct output_device *od);
292static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Yu Luming2f3d0002006-11-11 02:40:34 +0800294/*backlight device sysfs support*/
295static int acpi_video_get_brightness(struct backlight_device *bd)
296{
297 unsigned long cur_level;
298 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100299 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800300 acpi_video_device_lcd_get_level_current(vd, &cur_level);
301 return (int) cur_level;
302}
303
304static int acpi_video_set_brightness(struct backlight_device *bd)
305{
Richard Purdie599a52d2007-02-10 23:07:48 +0000306 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800307 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100308 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800309 acpi_video_device_lcd_set_level(vd, request_level);
310 return 0;
311}
312
Richard Purdie599a52d2007-02-10 23:07:48 +0000313static struct backlight_ops acpi_backlight_ops = {
314 .get_brightness = acpi_video_get_brightness,
315 .update_status = acpi_video_set_brightness,
316};
317
Luming Yu23b0f012007-05-09 21:07:05 +0800318/*video output device sysfs support*/
319static int acpi_video_output_get(struct output_device *od)
320{
321 unsigned long state;
322 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700323 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800324 acpi_video_device_get_state(vd, &state);
325 return (int)state;
326}
327
328static int acpi_video_output_set(struct output_device *od)
329{
330 unsigned long state = od->request_state;
331 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700332 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800333 return acpi_video_device_set_state(vd, state);
334}
335
336static struct output_properties acpi_output_properties = {
337 .set_state = acpi_video_output_set,
338 .get_status = acpi_video_output_get,
339};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340/* --------------------------------------------------------------------------
341 Video Management
342 -------------------------------------------------------------------------- */
343
344/* device */
345
346static int
Len Brown4be44fc2005-08-05 00:44:28 -0400347acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Len Brown4be44fc2005-08-05 00:44:28 -0400349 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400350
351 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Patrick Mocheld550d982006-06-27 00:41:40 -0400353 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356static int
Len Brown4be44fc2005-08-05 00:44:28 -0400357acpi_video_device_get_state(struct acpi_video_device *device,
358 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Len Brown4be44fc2005-08-05 00:44:28 -0400360 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Patrick Mochel90130262006-05-19 16:54:48 -0400362 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Patrick Mocheld550d982006-06-27 00:41:40 -0400364 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
366
367static int
Len Brown4be44fc2005-08-05 00:44:28 -0400368acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Len Brown4be44fc2005-08-05 00:44:28 -0400370 int status;
371 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
372 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400373 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400377 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Patrick Mocheld550d982006-06-27 00:41:40 -0400379 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382static int
Len Brown4be44fc2005-08-05 00:44:28 -0400383acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
384 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Len Brown4be44fc2005-08-05 00:44:28 -0400386 int status;
387 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
388 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 *levels = NULL;
392
Patrick Mochel90130262006-05-19 16:54:48 -0400393 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400395 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400396 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500397 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400398 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 status = -EFAULT;
400 goto err;
401 }
402
403 *levels = obj;
404
Patrick Mocheld550d982006-06-27 00:41:40 -0400405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Len Brown4be44fc2005-08-05 00:44:28 -0400407 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800408 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Patrick Mocheld550d982006-06-27 00:41:40 -0400410 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413static int
Len Brown4be44fc2005-08-05 00:44:28 -0400414acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400416 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400417 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
418 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400423 if (device->cap._BCM)
424 status = acpi_evaluate_object(device->dev->handle, "_BCM",
425 &args, NULL);
426 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400427 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
430static int
Len Brown4be44fc2005-08-05 00:44:28 -0400431acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
432 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400434 if (device->cap._BQC)
435 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
436 level);
437 *level = device->brightness->curr;
438 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441static int
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_video_device_EDID(struct acpi_video_device *device,
443 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 int status;
446 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
447 union acpi_object *obj;
448 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
449 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 *edid = NULL;
453
454 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400455 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 if (length == 128)
457 arg0.integer.value = 1;
458 else if (length == 256)
459 arg0.integer.value = 2;
460 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400461 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Patrick Mochel90130262006-05-19 16:54:48 -0400463 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400465 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200467 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 if (obj && obj->type == ACPI_TYPE_BUFFER)
470 *edid = obj;
471 else {
Len Brown64684632006-06-26 23:41:38 -0400472 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 status = -EFAULT;
474 kfree(obj);
475 }
476
Patrick Mocheld550d982006-06-27 00:41:40 -0400477 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480/* bus */
481
482static int
Len Brown4be44fc2005-08-05 00:44:28 -0400483acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Len Brown4be44fc2005-08-05 00:44:28 -0400485 int status;
486 unsigned long tmp;
487 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
488 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 arg0.integer.value = option;
492
Patrick Mochel90130262006-05-19 16:54:48 -0400493 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400495 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Patrick Mocheld550d982006-06-27 00:41:40 -0400497 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
500static int
Len Brown4be44fc2005-08-05 00:44:28 -0400501acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
503 int status;
504
Patrick Mochel90130262006-05-19 16:54:48 -0400505 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Patrick Mocheld550d982006-06-27 00:41:40 -0400507 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
510static int
Len Brown4be44fc2005-08-05 00:44:28 -0400511acpi_video_bus_POST_options(struct acpi_video_bus *video,
512 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Len Brown4be44fc2005-08-05 00:44:28 -0400514 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Patrick Mochel90130262006-05-19 16:54:48 -0400516 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 *options &= 3;
518
Patrick Mocheld550d982006-06-27 00:41:40 -0400519 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522/*
523 * Arg:
524 * video : video bus device pointer
525 * bios_flag :
526 * 0. The system BIOS should NOT automatically switch(toggle)
527 * the active display output.
528 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100529 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * 2. The _DGS value should be locked.
531 * 3. The system BIOS should not automatically switch (toggle) the
532 * active display output, but instead generate the display switch
533 * event notify code.
534 * lcd_flag :
535 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100536 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100538 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 * Return Value:
540 * -1 wrong arg.
541 */
542
543static int
Len Brown4be44fc2005-08-05 00:44:28 -0400544acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Len Brown4be44fc2005-08-05 00:44:28 -0400546 acpi_integer status = 0;
547 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
548 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Len Brown4be44fc2005-08-05 00:44:28 -0400551 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 status = -1;
553 goto Failed;
554 }
555 arg0.integer.value = (lcd_flag << 2) | bios_flag;
556 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400557 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400560 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563/*
564 * Arg:
565 * device : video output device (LCD, CRT, ..)
566 *
567 * Return Value:
568 * None
569 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100570 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * device.
572 */
573
Len Brown4be44fc2005-08-05 00:44:28 -0400574static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 acpi_handle h_dummy1;
577 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800578 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 union acpi_object *obj = NULL;
580 struct acpi_video_device_brightness *br = NULL;
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
William Lee Irwin III98934de2007-12-12 03:56:55 -0800583 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Patrick Mochel90130262006-05-19 16:54:48 -0400585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 device->cap._ADR = 1;
587 }
Patrick Mochel90130262006-05-19 16:54:48 -0400588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400589 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
Patrick Mochel90130262006-05-19 16:54:48 -0400591 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400592 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800594 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
595 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400597 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
Patrick Mochel90130262006-05-19 16:54:48 -0400599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 device->cap._DCS = 1;
601 }
Patrick Mochel90130262006-05-19 16:54:48 -0400602 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 device->cap._DGS = 1;
604 }
Patrick Mochel90130262006-05-19 16:54:48 -0400605 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 device->cap._DSS = 1;
607 }
608
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400609 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400611 if (obj->package.count >= 2) {
612 int count = 0;
613 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400614
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400615 br = kzalloc(sizeof(*br), GFP_KERNEL);
616 if (!br) {
617 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400619 br->levels = kmalloc(obj->package.count *
620 sizeof *(br->levels), GFP_KERNEL);
621 if (!br->levels)
622 goto out;
623
624 for (i = 0; i < obj->package.count; i++) {
625 o = (union acpi_object *)&obj->package.
626 elements[i];
627 if (o->type != ACPI_TYPE_INTEGER) {
628 printk(KERN_ERR PREFIX "Invalid data\n");
629 continue;
630 }
631 br->levels[count] = (u32) o->integer.value;
632
633 if (br->levels[count] > max_level)
634 max_level = br->levels[count];
635 count++;
636 }
637 out:
638 if (count < 2) {
639 kfree(br->levels);
640 kfree(br);
641 } else {
642 br->count = count;
643 device->brightness = br;
644 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
645 "found %d brightness levels\n",
646 count));
647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400650
651 } else {
652 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500655 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400657 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800658 unsigned long tmp;
659 static int count = 0;
660 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800661 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
662 if (!name)
663 return;
664
Yu Luming2f3d0002006-11-11 02:40:34 +0800665 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800666 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800667 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000668 NULL, device, &acpi_backlight_ops);
669 device->backlight->props.max_brightness = max_level;
670 device->backlight->props.brightness = (int)tmp;
671 backlight_update_status(device->backlight);
672
Yu Luming2f3d0002006-11-11 02:40:34 +0800673 kfree(name);
674 }
Luming Yu23b0f012007-05-09 21:07:05 +0800675 if (device->cap._DCS && device->cap._DSS){
676 static int count = 0;
677 char *name;
678 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
679 if (!name)
680 return;
681 sprintf(name, "acpi_video%d", count++);
682 device->output_dev = video_output_register(name,
683 NULL, device, &acpi_output_properties);
684 kfree(name);
685 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400686 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
689/*
690 * Arg:
691 * device : video output device (VGA)
692 *
693 * Return Value:
694 * None
695 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100696 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 */
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Len Brown4be44fc2005-08-05 00:44:28 -0400701 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
William Lee Irwin III98934de2007-12-12 03:56:55 -0800703 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400704 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 video->cap._DOS = 1;
706 }
Patrick Mochel90130262006-05-19 16:54:48 -0400707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 video->cap._DOD = 1;
709 }
Patrick Mochel90130262006-05-19 16:54:48 -0400710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 video->cap._ROM = 1;
712 }
Patrick Mochel90130262006-05-19 16:54:48 -0400713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 video->cap._GPD = 1;
715 }
Patrick Mochel90130262006-05-19 16:54:48 -0400716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 video->cap._SPD = 1;
718 }
Patrick Mochel90130262006-05-19 16:54:48 -0400719 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 video->cap._VPO = 1;
721 }
722}
723
724/*
725 * Check whether the video bus device has required AML method to
726 * support the desired features
727 */
728
Len Brown4be44fc2005-08-05 00:44:28 -0400729static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown4be44fc2005-08-05 00:44:28 -0400731 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 /* Since there is no HID, CID and so on for VGA driver, we have
738 * to check well known required nodes.
739 */
740
Julius Volz98fb8fe2007-02-20 16:38:40 +0100741 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400742 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 video->flags.multihead = 1;
744 status = 0;
745 }
746
Julius Volz98fb8fe2007-02-20 16:38:40 +0100747 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400748 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 video->flags.rom = 1;
750 status = 0;
751 }
752
Julius Volz98fb8fe2007-02-20 16:38:40 +0100753 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400754 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 video->flags.post = 1;
756 status = 0;
757 }
758
Patrick Mocheld550d982006-06-27 00:41:40 -0400759 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762/* --------------------------------------------------------------------------
763 FS Interface (/proc)
764 -------------------------------------------------------------------------- */
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768/* video devices */
769
Len Brown4be44fc2005-08-05 00:44:28 -0400770static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200772 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 if (!dev)
776 goto end;
777
778 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
779 seq_printf(seq, "type: ");
780 if (dev->flags.crt)
781 seq_printf(seq, "CRT\n");
782 else if (dev->flags.lcd)
783 seq_printf(seq, "LCD\n");
784 else if (dev->flags.tvout)
785 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500786 else if (dev->flags.dvi)
787 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 else
789 seq_printf(seq, "UNKNOWN\n");
790
Len Brown4be44fc2005-08-05 00:44:28 -0400791 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Len Brown4be44fc2005-08-05 00:44:28 -0400793 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400794 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
797static int
Len Brown4be44fc2005-08-05 00:44:28 -0400798acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
800 return single_open(file, acpi_video_device_info_seq_show,
801 PDE(inode)->data);
802}
803
Len Brown4be44fc2005-08-05 00:44:28 -0400804static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
Len Brown4be44fc2005-08-05 00:44:28 -0400806 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200807 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400808 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 if (!dev)
812 goto end;
813
814 status = acpi_video_device_get_state(dev, &state);
815 seq_printf(seq, "state: ");
816 if (ACPI_SUCCESS(status))
817 seq_printf(seq, "0x%02lx\n", state);
818 else
819 seq_printf(seq, "<not supported>\n");
820
821 status = acpi_video_device_query(dev, &state);
822 seq_printf(seq, "query: ");
823 if (ACPI_SUCCESS(status))
824 seq_printf(seq, "0x%02lx\n", state);
825 else
826 seq_printf(seq, "<not supported>\n");
827
Len Brown4be44fc2005-08-05 00:44:28 -0400828 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400829 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
832static int
Len Brown4be44fc2005-08-05 00:44:28 -0400833acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 return single_open(file, acpi_video_device_state_seq_show,
836 PDE(inode)->data);
837}
838
839static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400840acpi_video_device_write_state(struct file *file,
841 const char __user * buffer,
842 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Len Brown4be44fc2005-08-05 00:44:28 -0400844 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200845 struct seq_file *m = file->private_data;
846 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400847 char str[12] = { 0 };
848 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400855 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 str[count] = 0;
858 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400859 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 status = acpi_video_device_set_state(dev, state);
862
863 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400864 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Patrick Mocheld550d982006-06-27 00:41:40 -0400866 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
869static int
Len Brown4be44fc2005-08-05 00:44:28 -0400870acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200872 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400873 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 if (!dev || !dev->brightness) {
877 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400878 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
880
881 seq_printf(seq, "levels: ");
882 for (i = 0; i < dev->brightness->count; i++)
883 seq_printf(seq, " %d", dev->brightness->levels[i]);
884 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
885
Patrick Mocheld550d982006-06-27 00:41:40 -0400886 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
889static int
Len Brown4be44fc2005-08-05 00:44:28 -0400890acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
892 return single_open(file, acpi_video_device_brightness_seq_show,
893 PDE(inode)->data);
894}
895
896static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400897acpi_video_device_write_brightness(struct file *file,
898 const char __user * buffer,
899 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200901 struct seq_file *m = file->private_data;
902 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100903 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400904 unsigned int level = 0;
905 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Thomas Renninger59d399d2005-11-08 05:27:00 -0500908 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400909 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400912 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 str[count] = 0;
915 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400918 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Julius Volz98fb8fe2007-02-20 16:38:40 +0100920 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 for (i = 0; i < dev->brightness->count; i++)
922 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400923 if (ACPI_SUCCESS
924 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 dev->brightness->curr = level;
926 break;
927 }
928
Patrick Mocheld550d982006-06-27 00:41:40 -0400929 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
Len Brown4be44fc2005-08-05 00:44:28 -0400932static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200934 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400935 int status;
936 int i;
937 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 if (!dev)
941 goto out;
942
Len Brown4be44fc2005-08-05 00:44:28 -0400943 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400945 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 }
947
948 if (ACPI_FAILURE(status)) {
949 goto out;
950 }
951
952 if (edid && edid->type == ACPI_TYPE_BUFFER) {
953 for (i = 0; i < edid->buffer.length; i++)
954 seq_putc(seq, edid->buffer.pointer[i]);
955 }
956
Len Brown4be44fc2005-08-05 00:44:28 -0400957 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (!edid)
959 seq_printf(seq, "<not supported>\n");
960 else
961 kfree(edid);
962
Patrick Mocheld550d982006-06-27 00:41:40 -0400963 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964}
965
966static int
Len Brown4be44fc2005-08-05 00:44:28 -0400967acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
969 return single_open(file, acpi_video_device_EDID_seq_show,
970 PDE(inode)->data);
971}
972
Len Brown4be44fc2005-08-05 00:44:28 -0400973static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
Len Brown4be44fc2005-08-05 00:44:28 -0400975 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 struct acpi_video_device *vid_dev;
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400980 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200982 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400984 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 if (!acpi_device_dir(device)) {
987 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400988 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400990 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 acpi_device_dir(device)->owner = THIS_MODULE;
992 }
993
994 /* 'info' [R] */
995 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
996 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400997 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 else {
999 entry->proc_fops = &acpi_video_device_info_fops;
1000 entry->data = acpi_driver_data(device);
1001 entry->owner = THIS_MODULE;
1002 }
1003
1004 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001005 entry =
1006 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1007 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001009 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001011 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 entry->data = acpi_driver_data(device);
1014 entry->owner = THIS_MODULE;
1015 }
1016
1017 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001018 entry =
1019 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1020 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001022 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001024 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 entry->data = acpi_driver_data(device);
1027 entry->owner = THIS_MODULE;
1028 }
1029
1030 /* 'EDID' [R] */
1031 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1032 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001033 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 else {
1035 entry->proc_fops = &acpi_video_device_EDID_fops;
1036 entry->data = acpi_driver_data(device);
1037 entry->owner = THIS_MODULE;
1038 }
1039
Patrick Mocheld550d982006-06-27 00:41:40 -04001040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041}
1042
Len Brown4be44fc2005-08-05 00:44:28 -04001043static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
1045 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001047 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001049 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 if (acpi_device_dir(device)) {
1052 remove_proc_entry("info", acpi_device_dir(device));
1053 remove_proc_entry("state", acpi_device_dir(device));
1054 remove_proc_entry("brightness", acpi_device_dir(device));
1055 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001056 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 acpi_device_dir(device) = NULL;
1058 }
1059
Patrick Mocheld550d982006-06-27 00:41:40 -04001060 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001064static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001066 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 if (!video)
1070 goto end;
1071
1072 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001073 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001075 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001077 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Len Brown4be44fc2005-08-05 00:44:28 -04001079 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001080 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
Len Brown4be44fc2005-08-05 00:44:28 -04001083static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084{
Len Brown4be44fc2005-08-05 00:44:28 -04001085 return single_open(file, acpi_video_bus_info_seq_show,
1086 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Len Brown4be44fc2005-08-05 00:44:28 -04001089static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001091 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 if (!video)
1095 goto end;
1096
1097 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1098 seq_printf(seq, "<TODO>\n");
1099
Len Brown4be44fc2005-08-05 00:44:28 -04001100 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001101 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Len Brown4be44fc2005-08-05 00:44:28 -04001104static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
1106 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1107}
1108
Len Brown4be44fc2005-08-05 00:44:28 -04001109static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001111 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001112 unsigned long options;
1113 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 if (!video)
1117 goto end;
1118
1119 status = acpi_video_bus_POST_options(video, &options);
1120 if (ACPI_SUCCESS(status)) {
1121 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001122 printk(KERN_WARNING PREFIX
1123 "The motherboard VGA device is not listed as a possible POST device.\n");
1124 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001125 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
1127 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001128 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (options & 2)
1130 seq_printf(seq, " <PCI video>");
1131 if (options & 4)
1132 seq_printf(seq, " <AGP video>");
1133 seq_putc(seq, '\n');
1134 } else
1135 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001136 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
1140static int
Len Brown4be44fc2005-08-05 00:44:28 -04001141acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Len Brown4be44fc2005-08-05 00:44:28 -04001143 return single_open(file, acpi_video_bus_POST_info_seq_show,
1144 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Len Brown4be44fc2005-08-05 00:44:28 -04001147static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001149 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001150 int status;
1151 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 if (!video)
1155 goto end;
1156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 if (!ACPI_SUCCESS(status)) {
1159 seq_printf(seq, "<not supported>\n");
1160 goto end;
1161 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001162 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Len Brown4be44fc2005-08-05 00:44:28 -04001164 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001165 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
Len Brown4be44fc2005-08-05 00:44:28 -04001168static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001170 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Len Brown4be44fc2005-08-05 00:44:28 -04001173 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Patrick Mocheld550d982006-06-27 00:41:40 -04001175 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Len Brown4be44fc2005-08-05 00:44:28 -04001178static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Len Brown4be44fc2005-08-05 00:44:28 -04001180 return single_open(file, acpi_video_bus_POST_seq_show,
1181 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Len Brown4be44fc2005-08-05 00:44:28 -04001184static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
1186 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1187}
1188
1189static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001190acpi_video_bus_write_POST(struct file *file,
1191 const char __user * buffer,
1192 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193{
Len Brown4be44fc2005-08-05 00:44:28 -04001194 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001195 struct seq_file *m = file->private_data;
1196 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001197 char str[12] = { 0 };
1198 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001202 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 status = acpi_video_bus_POST_options(video, &options);
1205 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001206 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001209 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
1211 str[count] = 0;
1212 opt = strtoul(str, NULL, 0);
1213 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001214 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Julius Volz98fb8fe2007-02-20 16:38:40 +01001216 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 options |= 1;
1218
1219 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001220 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001222 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
1224 }
1225
Patrick Mocheld550d982006-06-27 00:41:40 -04001226 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227}
1228
1229static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001230acpi_video_bus_write_DOS(struct file *file,
1231 const char __user * buffer,
1232 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Len Brown4be44fc2005-08-05 00:44:28 -04001234 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001235 struct seq_file *m = file->private_data;
1236 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001237 char str[12] = { 0 };
1238 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001242 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001245 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 str[count] = 0;
1248 opt = strtoul(str, NULL, 0);
1249 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001250 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Len Brown4be44fc2005-08-05 00:44:28 -04001252 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001255 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Patrick Mocheld550d982006-06-27 00:41:40 -04001257 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
Len Brown4be44fc2005-08-05 00:44:28 -04001260static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Len Brown4be44fc2005-08-05 00:44:28 -04001262 struct proc_dir_entry *entry = NULL;
1263 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001266 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 if (!acpi_device_dir(device)) {
1269 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001270 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001272 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 video->dir = acpi_device_dir(device);
1274 acpi_device_dir(device)->owner = THIS_MODULE;
1275 }
1276
1277 /* 'info' [R] */
1278 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1279 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001280 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 else {
1282 entry->proc_fops = &acpi_video_bus_info_fops;
1283 entry->data = acpi_driver_data(device);
1284 entry->owner = THIS_MODULE;
1285 }
1286
1287 /* 'ROM' [R] */
1288 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1289 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001290 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 else {
1292 entry->proc_fops = &acpi_video_bus_ROM_fops;
1293 entry->data = acpi_driver_data(device);
1294 entry->owner = THIS_MODULE;
1295 }
1296
1297 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001298 entry =
1299 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001301 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 else {
1303 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1304 entry->data = acpi_driver_data(device);
1305 entry->owner = THIS_MODULE;
1306 }
1307
1308 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001309 entry =
1310 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1311 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001313 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001315 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 entry->data = acpi_driver_data(device);
1318 entry->owner = THIS_MODULE;
1319 }
1320
1321 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001322 entry =
1323 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1324 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001326 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001328 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 entry->data = acpi_driver_data(device);
1331 entry->owner = THIS_MODULE;
1332 }
1333
Patrick Mocheld550d982006-06-27 00:41:40 -04001334 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Len Brown4be44fc2005-08-05 00:44:28 -04001337static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Len Brown4be44fc2005-08-05 00:44:28 -04001339 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001342 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 if (acpi_device_dir(device)) {
1345 remove_proc_entry("info", acpi_device_dir(device));
1346 remove_proc_entry("ROM", acpi_device_dir(device));
1347 remove_proc_entry("POST_info", acpi_device_dir(device));
1348 remove_proc_entry("POST", acpi_device_dir(device));
1349 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001350 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 acpi_device_dir(device) = NULL;
1352 }
1353
Patrick Mocheld550d982006-06-27 00:41:40 -04001354 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
1357/* --------------------------------------------------------------------------
1358 Driver Interface
1359 -------------------------------------------------------------------------- */
1360
1361/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001362static struct acpi_video_device_attrib*
1363acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1364{
1365 int count;
1366
1367 for(count = 0; count < video->attached_count; count++)
1368 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1369 return &(video->attached_array[count].value.attrib);
1370 return NULL;
1371}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
1373static int
Len Brown4be44fc2005-08-05 00:44:28 -04001374acpi_video_bus_get_one_device(struct acpi_device *device,
1375 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Len Brown4be44fc2005-08-05 00:44:28 -04001377 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001378 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001379 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001380 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001383 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Len Brown4be44fc2005-08-05 00:44:28 -04001385 status =
1386 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 if (ACPI_SUCCESS(status)) {
1388
Burman Yan36bcbec2006-12-19 12:56:11 -08001389 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001391 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1394 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1395 acpi_driver_data(device) = data;
1396
1397 data->device_id = device_id;
1398 data->video = video;
1399 data->dev = device;
1400
Rui Zhang82cae992007-01-03 23:40:53 -05001401 attribute = acpi_video_get_device_attr(video, device_id);
1402
1403 if((attribute != NULL) && attribute->device_id_scheme) {
1404 switch (attribute->display_type) {
1405 case ACPI_VIDEO_DISPLAY_CRT:
1406 data->flags.crt = 1;
1407 break;
1408 case ACPI_VIDEO_DISPLAY_TV:
1409 data->flags.tvout = 1;
1410 break;
1411 case ACPI_VIDEO_DISPLAY_DVI:
1412 data->flags.dvi = 1;
1413 break;
1414 case ACPI_VIDEO_DISPLAY_LCD:
1415 data->flags.lcd = 1;
1416 break;
1417 default:
1418 data->flags.unknown = 1;
1419 break;
1420 }
1421 if(attribute->bios_can_detect)
1422 data->flags.bios = 1;
1423 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001425
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 acpi_video_device_bind(video, data);
1427 acpi_video_device_find_cap(data);
1428
Patrick Mochel90130262006-05-19 16:54:48 -04001429 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001430 ACPI_DEVICE_NOTIFY,
1431 acpi_video_device_notify,
1432 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (ACPI_FAILURE(status)) {
1434 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001435 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001436 if(data->brightness)
1437 kfree(data->brightness->levels);
1438 kfree(data->brightness);
1439 kfree(data);
1440 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 }
1442
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001443 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001445 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 acpi_video_device_add_fs(device);
1448
Patrick Mocheld550d982006-06-27 00:41:40 -04001449 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 }
1451
Patrick Mocheld550d982006-06-27 00:41:40 -04001452 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453}
1454
1455/*
1456 * Arg:
1457 * video : video bus device
1458 *
1459 * Return:
1460 * none
1461 *
1462 * Enumerate the video device list of the video bus,
1463 * bind the ids with the corresponding video devices
1464 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001465 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Len Brown4be44fc2005-08-05 00:44:28 -04001467static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001469 struct acpi_video_device *dev;
1470
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001471 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001472
1473 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001474 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001475
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001476 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
1479/*
1480 * Arg:
1481 * video : video bus device
1482 * device : video output device under the video
1483 * bus
1484 *
1485 * Return:
1486 * none
1487 *
1488 * Bind the ids with the corresponding video devices
1489 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001490 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492static void
Len Brown4be44fc2005-08-05 00:44:28 -04001493acpi_video_device_bind(struct acpi_video_bus *video,
1494 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
Len Brown4be44fc2005-08-05 00:44:28 -04001496 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498#define IDS_VAL(i) video->attached_array[i].value.int_val
1499#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001500
1501 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1502 i < video->attached_count; i++) {
1503 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 IDS_BIND(i) = device;
1505 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1506 }
1507 }
1508#undef IDS_VAL
1509#undef IDS_BIND
1510}
1511
1512/*
1513 * Arg:
1514 * video : video bus device
1515 *
1516 * Return:
1517 * < 0 : error
1518 *
1519 * Call _DOD to enumerate all devices attached to display adapter
1520 *
Len Brown4be44fc2005-08-05 00:44:28 -04001521 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1524{
Len Brown4be44fc2005-08-05 00:44:28 -04001525 int status;
1526 int count;
1527 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001529 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1530 union acpi_object *dod = NULL;
1531 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Patrick Mochel90130262006-05-19 16:54:48 -04001533 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001535 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001536 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
1538
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001539 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001541 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 status = -EFAULT;
1543 goto out;
1544 }
1545
1546 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001547 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Len Brown4be44fc2005-08-05 00:44:28 -04001549 active_device_list = kmalloc((1 +
1550 dod->package.count) *
1551 sizeof(struct
1552 acpi_video_enumerated_device),
1553 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 if (!active_device_list) {
1556 status = -ENOMEM;
1557 goto out;
1558 }
1559
1560 count = 0;
1561 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001562 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001565 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001566 active_device_list[i].value.int_val =
1567 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 }
1569 active_device_list[i].value.int_val = obj->integer.value;
1570 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001571 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1572 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 count++;
1574 }
1575 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1576
Jesper Juhl6044ec82005-11-07 01:01:32 -08001577 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 video->attached_array = active_device_list;
1580 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001581 out:
Len Brown02438d82006-06-30 03:19:10 -04001582 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001583 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
1586/*
1587 * Arg:
1588 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001589 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 *
1591 * Return:
1592 * < 0 : error
1593 *
1594 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001595 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001597 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Len Brown4be44fc2005-08-05 00:44:28 -04001599static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001601 struct list_head *node;
Len Brown4be44fc2005-08-05 00:44:28 -04001602 struct acpi_video_device *dev = NULL;
1603 struct acpi_video_device *dev_next = NULL;
1604 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 unsigned long state;
1606 int status = 0;
1607
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001608 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001610 list_for_each(node, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001611 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001613 if (state & 0x2) {
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001614 dev_next = container_of(node->next,
1615 struct acpi_video_device, entry);
1616 dev_prev = container_of(node->prev,
1617 struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 goto out;
1619 }
1620 }
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 dev_next = container_of(node->next, struct acpi_video_device, entry);
1623 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001624
1625 out:
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001626 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 switch (event) {
1629 case ACPI_VIDEO_NOTIFY_CYCLE:
1630 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1631 acpi_video_device_set_state(dev, 0);
1632 acpi_video_device_set_state(dev_next, 0x80000001);
1633 break;
1634 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1635 acpi_video_device_set_state(dev, 0);
1636 acpi_video_device_set_state(dev_prev, 0x80000001);
1637 default:
1638 break;
1639 }
1640
Patrick Mocheld550d982006-06-27 00:41:40 -04001641 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Len Brown4be44fc2005-08-05 00:44:28 -04001644static int
1645acpi_video_get_next_level(struct acpi_video_device *device,
1646 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001648 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001649 max = max_below = 0;
1650 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001651 /* Find closest level to level_current */
1652 for (i = 0; i < device->brightness->count; i++) {
1653 l = device->brightness->levels[i];
1654 if (abs(l - level_current) < abs(delta)) {
1655 delta = l - level_current;
1656 if (!delta)
1657 break;
1658 }
1659 }
1660 /* Ajust level_current to closest available level */
1661 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001662 for (i = 0; i < device->brightness->count; i++) {
1663 l = device->brightness->levels[i];
1664 if (l < min)
1665 min = l;
1666 if (l > max)
1667 max = l;
1668 if (l < min_above && l > level_current)
1669 min_above = l;
1670 if (l > max_below && l < level_current)
1671 max_below = l;
1672 }
1673
1674 switch (event) {
1675 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1676 return (level_current < max) ? min_above : min;
1677 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1678 return (level_current < max) ? min_above : max;
1679 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1680 return (level_current > min) ? max_below : min;
1681 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1682 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1683 return 0;
1684 default:
1685 return level_current;
1686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
1688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689static void
Len Brown4be44fc2005-08-05 00:44:28 -04001690acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
1692 unsigned long level_current, level_next;
1693 acpi_video_device_lcd_get_level_current(device, &level_current);
1694 level_next = acpi_video_get_next_level(device, level_current, event);
1695 acpi_video_device_lcd_set_level(device, level_next);
1696}
1697
1698static int
Len Brown4be44fc2005-08-05 00:44:28 -04001699acpi_video_bus_get_devices(struct acpi_video_bus *video,
1700 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
Len Brown4be44fc2005-08-05 00:44:28 -04001702 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001703 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 acpi_video_device_enumerate(video);
1706
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001707 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 status = acpi_video_bus_get_one_device(dev, video);
1710 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001711 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 continue;
1713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001715 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Len Brown4be44fc2005-08-05 00:44:28 -04001718static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Karol Kozimor031ec772005-07-30 04:18:00 -04001720 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 struct acpi_video_bus *video;
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001725 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 video = device->video;
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 acpi_video_device_remove_fs(device->dev);
1730
Patrick Mochel90130262006-05-19 16:54:48 -04001731 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001732 ACPI_DEVICE_NOTIFY,
1733 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001734 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001735 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001736
Patrick Mocheld550d982006-06-27 00:41:40 -04001737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738}
1739
Len Brown4be44fc2005-08-05 00:44:28 -04001740static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
Len Brown4be44fc2005-08-05 00:44:28 -04001742 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001743 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001745 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001747 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001749 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001750 if (ACPI_FAILURE(status))
1751 printk(KERN_WARNING PREFIX
1752 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001754 if (dev->brightness) {
1755 kfree(dev->brightness->levels);
1756 kfree(dev->brightness);
1757 }
1758 list_del(&dev->entry);
1759 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 }
1761
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001762 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001763
Patrick Mocheld550d982006-06-27 00:41:40 -04001764 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
1767/* acpi_video interface */
1768
Len Brown4be44fc2005-08-05 00:44:28 -04001769static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770{
Zhang Ruia21101c2007-09-14 11:46:22 +08001771 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772}
1773
Len Brown4be44fc2005-08-05 00:44:28 -04001774static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
1776 return acpi_video_bus_DOS(video, 0, 1);
1777}
1778
Len Brown4be44fc2005-08-05 00:44:28 -04001779static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001781 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001782 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001783 struct input_dev *input;
1784 int keycode;
1785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001787 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001789 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001790 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001793 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001795 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001796 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 break;
1798
Julius Volz98fb8fe2007-02-20 16:38:40 +01001799 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 * connector. */
1801 acpi_video_device_enumerate(video);
1802 acpi_video_device_rebind(video);
1803 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001804 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001805 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 break;
1807
Len Brown4be44fc2005-08-05 00:44:28 -04001808 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001809 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001810 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001811 keycode = KEY_SWITCHVIDEOMODE;
1812 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001813 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001814 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001815 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001816 keycode = KEY_VIDEO_NEXT;
1817 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001818 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 acpi_video_switch_output(video, 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_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 break;
1823
1824 default:
Luming Yue9dab192007-08-20 18:23:53 +08001825 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001827 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 break;
1829 }
1830
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
Len Brown4be44fc2005-08-05 00:44:28 -04001839static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001841 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001842 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001843 struct acpi_video_bus *bus;
1844 struct input_dev *input;
1845 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001848 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001850 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001851 bus = video_device->video;
1852 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
1854 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001855 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001856 if (brightness_switch_enabled)
1857 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001858 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001859 keycode = KEY_BRIGHTNESS_CYCLE;
1860 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001861 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001862 if (brightness_switch_enabled)
1863 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001864 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001865 keycode = KEY_BRIGHTNESSUP;
1866 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001867 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001868 if (brightness_switch_enabled)
1869 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001870 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001871 keycode = KEY_BRIGHTNESSDOWN;
1872 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001873 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001874 if (brightness_switch_enabled)
1875 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001876 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001877 keycode = KEY_BRIGHTNESS_ZERO;
1878 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001879 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001880 if (brightness_switch_enabled)
1881 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001882 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001883 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 break;
1885 default:
Luming Yue9dab192007-08-20 18:23:53 +08001886 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001888 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 break;
1890 }
Luming Yue9dab192007-08-20 18:23:53 +08001891
1892 input_report_key(input, keycode, 1);
1893 input_sync(input);
1894 input_report_key(input, keycode, 0);
1895 input_sync(input);
1896
Patrick Mocheld550d982006-06-27 00:41:40 -04001897 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898}
1899
Zhang Ruie6d9da12007-08-25 02:23:31 -04001900static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001901static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001903 acpi_status status;
1904 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001905 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001906 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Burman Yan36bcbec2006-12-19 12:56:11 -08001908 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001910 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Zhang Ruie6d9da12007-08-25 02:23:31 -04001912 /* a hack to fix the duplicate name "VID" problem on T61 */
1913 if (!strcmp(device->pnp.bus_id, "VID")) {
1914 if (instance)
1915 device->pnp.bus_id[3] = '0' + instance;
1916 instance ++;
1917 }
1918
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001919 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1921 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1922 acpi_driver_data(device) = video;
1923
1924 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001925 error = acpi_video_bus_check(video);
1926 if (error)
1927 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001929 error = acpi_video_bus_add_fs(device);
1930 if (error)
1931 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001933 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 INIT_LIST_HEAD(&video->video_device_list);
1935
1936 acpi_video_bus_get_devices(video, device);
1937 acpi_video_bus_start_devices(video);
1938
Patrick Mochel90130262006-05-19 16:54:48 -04001939 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001940 ACPI_DEVICE_NOTIFY,
1941 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 if (ACPI_FAILURE(status)) {
1943 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001944 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001945 error = -ENODEV;
1946 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 }
1948
Luming Yue9dab192007-08-20 18:23:53 +08001949 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001950 if (!input) {
1951 error = -ENOMEM;
1952 goto err_uninstall_notify;
1953 }
Luming Yue9dab192007-08-20 18:23:53 +08001954
1955 snprintf(video->phys, sizeof(video->phys),
1956 "%s/video/input0", acpi_device_hid(video->device));
1957
1958 input->name = acpi_device_name(video->device);
1959 input->phys = video->phys;
1960 input->id.bustype = BUS_HOST;
1961 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001962 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001963 input->evbit[0] = BIT(EV_KEY);
1964 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1965 set_bit(KEY_VIDEO_NEXT, input->keybit);
1966 set_bit(KEY_VIDEO_PREV, input->keybit);
1967 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1968 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1969 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1970 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1971 set_bit(KEY_DISPLAY_OFF, input->keybit);
1972 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001973
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001974 error = input_register_device(input);
1975 if (error)
1976 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001979 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1980 video->flags.multihead ? "yes" : "no",
1981 video->flags.rom ? "yes" : "no",
1982 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001984 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001986 err_free_input_dev:
1987 input_free_device(input);
1988 err_uninstall_notify:
1989 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1990 acpi_video_bus_notify);
1991 err_stop_video:
1992 acpi_video_bus_stop_devices(video);
1993 acpi_video_bus_put_devices(video);
1994 kfree(video->attached_array);
1995 acpi_video_bus_remove_fs(device);
1996 err_free_video:
1997 kfree(video);
1998 acpi_driver_data(device) = NULL;
1999
2000 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
Len Brown4be44fc2005-08-05 00:44:28 -04002003static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
Len Brown4be44fc2005-08-05 00:44:28 -04002005 acpi_status status = 0;
2006 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
2009 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002010 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002012 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 acpi_video_bus_stop_devices(video);
2015
Patrick Mochel90130262006-05-19 16:54:48 -04002016 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002017 ACPI_DEVICE_NOTIFY,
2018 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
2020 acpi_video_bus_put_devices(video);
2021 acpi_video_bus_remove_fs(device);
2022
Luming Yue9dab192007-08-20 18:23:53 +08002023 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002024 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 kfree(video);
2026
Patrick Mocheld550d982006-06-27 00:41:40 -04002027 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028}
2029
Len Brown4be44fc2005-08-05 00:44:28 -04002030static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031{
Len Brown4be44fc2005-08-05 00:44:28 -04002032 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002036 acpi_dbg_level = 0xFFFFFFFF;
2037 acpi_dbg_layer = 0x08000000;
2038 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
2040 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2041 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002042 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 acpi_video_dir->owner = THIS_MODULE;
2044
2045 result = acpi_bus_register_driver(&acpi_video_bus);
2046 if (result < 0) {
2047 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002048 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050
Patrick Mocheld550d982006-06-27 00:41:40 -04002051 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052}
2053
Len Brown4be44fc2005-08-05 00:44:28 -04002054static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
2057 acpi_bus_unregister_driver(&acpi_video_bus);
2058
2059 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2060
Patrick Mocheld550d982006-06-27 00:41:40 -04002061 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062}
2063
2064module_init(acpi_video_init);
2065module_exit(acpi_video_exit);